From 08923297e9ff89a3235461d311beda97bbfbf22b Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Tue, 4 Feb 2025 12:21:06 +0100
Subject: [PATCH 001/512] Only register_interop_behavior() for datetime & time
when they are imported
* Otherwise just loading polyglot has the heavy cost of loading datetime too.
* This way the interop behavior is defined regardless of whether `import polyglot` was done (without relying on polyglot to be loaded at startup).
---
.../builtins/modules/TimeModuleBuiltins.java | 7 +-
graalpython/lib-graalpython/_polyglot.py | 65 +-------------
.../lib-graalpython/_polyglot_datetime.py | 60 +++++++++++++
graalpython/lib-graalpython/_polyglot_time.py | 84 +++++++++++++++++++
graalpython/lib-python/3/datetime.py | 2 +
5 files changed, 153 insertions(+), 65 deletions(-)
create mode 100644 graalpython/lib-graalpython/_polyglot_datetime.py
create mode 100644 graalpython/lib-graalpython/_polyglot_time.py
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
index 46bd74525e..6eec222635 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -49,6 +49,7 @@
import java.util.List;
import java.util.TimeZone;
+import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import org.graalvm.nativeimage.ImageInfo;
import com.oracle.graal.python.annotations.ArgumentClinic;
@@ -153,6 +154,7 @@ public final class TimeModuleBuiltins extends PythonBuiltins {
public static final TruffleString T_DAYLIGHT = tsLiteral("daylight");
public static final TruffleString T_TIMEZONE = tsLiteral("timezone");
public static final TruffleString T_ALTZONE = tsLiteral("altzone");
+ public static final TruffleString T_POLYGLOT_TIME = tsLiteral("_polyglot_time");
@Override
protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFactories() {
@@ -192,6 +194,9 @@ public void postInitialize(Python3Core core) {
int rawOffsetSeconds = defaultTimeZone.getRawOffset() / -1000;
timeModule.setAttribute(T_TIMEZONE, rawOffsetSeconds);
timeModule.setAttribute(T_ALTZONE, rawOffsetSeconds - 3600);
+
+ // register_interop_behavior() for time.struct_time
+ AbstractImportNode.importModule(T_POLYGLOT_TIME);
}
@TruffleBoundary
diff --git a/graalpython/lib-graalpython/_polyglot.py b/graalpython/lib-graalpython/_polyglot.py
index caf9cebdc0..770575c8a8 100644
--- a/graalpython/lib-graalpython/_polyglot.py
+++ b/graalpython/lib-graalpython/_polyglot.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -37,9 +37,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-import datetime
import polyglot
-import time
def interop_type(foreign_class, allow_method_overwrites=False):
@@ -112,37 +110,6 @@ def wrapper(python_class):
setattr(polyglot, "interop_behavior", interop_behavior)
-def _date_time_tz(dt: datetime.datetime):
- if dt.tzinfo is not None:
- utcoffset = dt.tzinfo.utcoffset(dt)
- return utcoffset.days * 3600 * 24 + utcoffset.seconds
- raise polyglot.UnsupportedMessage
-
-
-def _struct_time_tz(st: time.struct_time):
- if st.tm_gmtoff is not None:
- return st.tm_gmtoff
- return st.tm_zone
-
-
-polyglot.register_interop_behavior(datetime.time,
- is_time=True, as_time=lambda d: (d.hour, d.minute, d.second, d.microsecond),
- is_time_zone=lambda t: t.tzinfo is not None, as_time_zone=_date_time_tz)
-
-polyglot.register_interop_behavior(datetime.date,
- is_date=True, as_date=lambda d: (d.year, d.month, d.day))
-
-polyglot.register_interop_behavior(datetime.datetime,
- is_date=True, as_date=lambda d: (d.year, d.month, d.day),
- is_time=True, as_time=lambda d: (d.hour, d.minute, d.second, d.microsecond),
- is_time_zone=lambda t: t.tzinfo is not None, as_time_zone=_date_time_tz)
-
-polyglot.register_interop_behavior(time.struct_time,
- is_date=True, as_date=lambda t: (t.tm_year, t.tm_mon, t.tm_mday),
- is_time=True, as_time=lambda t: (t.tm_hour, t.tm_min, t.tm_sec, 0),
- is_time_zone=lambda t: t.tm_zone is not None or t.tm_gmtoff is not None,
- as_time_zone=_struct_time_tz)
-
# loading arrow structures on demand
def __getattr__(name):
if name == "arrow":
@@ -153,33 +120,3 @@ def __getattr__(name):
setattr(polyglot, "__getattr__", __getattr__)
setattr(polyglot, "__path__", ".")
-
-# example extending time.struct_time using the decorator wrapper
-#
-# @polyglot.interop_behavior(time.struct_time)
-# class StructTimeInteropBehavior:
-# @staticmethod
-# def is_date(t):
-# return True
-#
-# @staticmethod
-# def as_date(t):
-# return t.tm_year, t.tm_mon, t.tm_mday
-#
-# @staticmethod
-# def is_time(t):
-# return True
-#
-# @staticmethod
-# def as_time(t):
-# return t.tm_hour, t.tm_min, t.tm_sec, 0
-#
-# @staticmethod
-# def is_time_zone(t):
-# return t.tm_zone is not None or t.tm_gmtoff is not None
-#
-# @staticmethod
-# def as_time_zone(t):
-# if t.tm_gmtoff is not None:
-# return t.tm_gmtoff
-# return t.tm_zone
diff --git a/graalpython/lib-graalpython/_polyglot_datetime.py b/graalpython/lib-graalpython/_polyglot_datetime.py
new file mode 100644
index 0000000000..80f73a74de
--- /dev/null
+++ b/graalpython/lib-graalpython/_polyglot_datetime.py
@@ -0,0 +1,60 @@
+# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# The Universal Permissive License (UPL), Version 1.0
+#
+# Subject to the condition set forth below, permission is hereby granted to any
+# person obtaining a copy of this software, associated documentation and/or
+# data (collectively the "Software"), free of charge and under any and all
+# copyright rights in the Software, and any and all patent rights owned or
+# freely licensable by each licensor hereunder covering either (i) the
+# unmodified Software as contributed to or provided by such licensor, or (ii)
+# the Larger Works (as defined below), to deal in both
+#
+# (a) the Software, and
+#
+# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+# one is included with the Software each a "Larger Work" to which the Software
+# is contributed by such licensors),
+#
+# without restriction, including without limitation the rights to copy, create
+# derivative works of, display, perform, and distribute the Software and make,
+# use, sell, offer for sale, import, export, have made, and have sold the
+# Software and the Larger Work(s), and to sublicense the foregoing rights on
+# either these or other terms.
+#
+# This license is subject to the following condition:
+#
+# The above copyright notice and either this complete permission notice or at a
+# minimum a reference to the UPL must be included in all copies or substantial
+# portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import datetime
+import polyglot
+
+def _date_time_tz(dt: datetime.datetime):
+ if dt.tzinfo is not None:
+ utcoffset = dt.tzinfo.utcoffset(dt)
+ return utcoffset.days * 3600 * 24 + utcoffset.seconds
+ raise polyglot.UnsupportedMessage
+
+
+polyglot.register_interop_behavior(datetime.time,
+ is_time=True, as_time=lambda d: (d.hour, d.minute, d.second, d.microsecond),
+ is_time_zone=lambda t: t.tzinfo is not None, as_time_zone=_date_time_tz)
+
+polyglot.register_interop_behavior(datetime.date,
+ is_date=True, as_date=lambda d: (d.year, d.month, d.day))
+
+polyglot.register_interop_behavior(datetime.datetime,
+ is_date=True, as_date=lambda d: (d.year, d.month, d.day),
+ is_time=True, as_time=lambda d: (d.hour, d.minute, d.second, d.microsecond),
+ is_time_zone=lambda t: t.tzinfo is not None, as_time_zone=_date_time_tz)
diff --git a/graalpython/lib-graalpython/_polyglot_time.py b/graalpython/lib-graalpython/_polyglot_time.py
new file mode 100644
index 0000000000..ed4dc0fc54
--- /dev/null
+++ b/graalpython/lib-graalpython/_polyglot_time.py
@@ -0,0 +1,84 @@
+# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# The Universal Permissive License (UPL), Version 1.0
+#
+# Subject to the condition set forth below, permission is hereby granted to any
+# person obtaining a copy of this software, associated documentation and/or
+# data (collectively the "Software"), free of charge and under any and all
+# copyright rights in the Software, and any and all patent rights owned or
+# freely licensable by each licensor hereunder covering either (i) the
+# unmodified Software as contributed to or provided by such licensor, or (ii)
+# the Larger Works (as defined below), to deal in both
+#
+# (a) the Software, and
+#
+# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+# one is included with the Software each a "Larger Work" to which the Software
+# is contributed by such licensors),
+#
+# without restriction, including without limitation the rights to copy, create
+# derivative works of, display, perform, and distribute the Software and make,
+# use, sell, offer for sale, import, export, have made, and have sold the
+# Software and the Larger Work(s), and to sublicense the foregoing rights on
+# either these or other terms.
+#
+# This license is subject to the following condition:
+#
+# The above copyright notice and either this complete permission notice or at a
+# minimum a reference to the UPL must be included in all copies or substantial
+# portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import time
+import polyglot
+
+
+def _struct_time_tz(st: time.struct_time):
+ if st.tm_gmtoff is not None:
+ return st.tm_gmtoff
+ return st.tm_zone
+
+
+polyglot.register_interop_behavior(time.struct_time,
+ is_date=True, as_date=lambda t: (t.tm_year, t.tm_mon, t.tm_mday),
+ is_time=True, as_time=lambda t: (t.tm_hour, t.tm_min, t.tm_sec, 0),
+ is_time_zone=lambda t: t.tm_zone is not None or t.tm_gmtoff is not None,
+ as_time_zone=_struct_time_tz)
+
+# example extending time.struct_time using the decorator wrapper
+#
+# @polyglot.interop_behavior(time.struct_time)
+# class StructTimeInteropBehavior:
+# @staticmethod
+# def is_date(t):
+# return True
+#
+# @staticmethod
+# def as_date(t):
+# return t.tm_year, t.tm_mon, t.tm_mday
+#
+# @staticmethod
+# def is_time(t):
+# return True
+#
+# @staticmethod
+# def as_time(t):
+# return t.tm_hour, t.tm_min, t.tm_sec, 0
+#
+# @staticmethod
+# def is_time_zone(t):
+# return t.tm_zone is not None or t.tm_gmtoff is not None
+#
+# @staticmethod
+# def as_time_zone(t):
+# if t.tm_gmtoff is not None:
+# return t.tm_gmtoff
+# return t.tm_zone
diff --git a/graalpython/lib-python/3/datetime.py b/graalpython/lib-python/3/datetime.py
index e284a733ef..c564969464 100644
--- a/graalpython/lib-python/3/datetime.py
+++ b/graalpython/lib-python/3/datetime.py
@@ -2642,3 +2642,5 @@ def _name_from_offset(delta):
# appropriate to maintain a single module level docstring and
# remove the following line.
from _datetime import __doc__
+
+import _polyglot_datetime # GraalPy change: register interop behavior on datetime as soon as datetime is defined
From 8bfdf1009e64b046eca9051381bafbd7bc668d85 Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Tue, 4 Feb 2025 12:27:08 +0100
Subject: [PATCH 002/512] Let PolyglotModuleBuiltins#postInitialize load
_polyglot.py and don't force to load polyglot at startup
---
.../src/com/oracle/graal/python/builtins/Python3Core.java | 3 ---
.../python/builtins/modules/PolyglotModuleBuiltins.java | 5 +++++
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
index 97405a14f7..3146f1acf9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
@@ -1083,9 +1083,6 @@ public void run() {
}
}
- // import polyglot decorators and special interop predefined behavior
- loadFile(toTruffleStringUncached("_polyglot"), getContext().getCoreHomeOrFail());
-
initialized = true;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
index a6656c2793..b414152f0d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
@@ -113,6 +113,7 @@
import com.oracle.graal.python.nodes.interop.InteropBehaviorMethod;
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.GetForeignObjectClassNode;
+import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
@@ -161,6 +162,7 @@ public final class PolyglotModuleBuiltins extends PythonBuiltins {
private static final TruffleString T_MODIFIABLE = tsLiteral("modifiable");
private static final TruffleString T_INVOKABLE = tsLiteral("invokable");
private static final TruffleString T_INTERNAL = tsLiteral("internal");
+ private static final TruffleString T_INTERNAL_POLYGLOT_MODULE = tsLiteral("_polyglot");
@Override
protected List> getNodeFactories() {
@@ -189,6 +191,9 @@ public void postInitialize(Python3Core core) {
super.postInitialize(core);
GetForeignObjectClassNode.getUncached().defineSingleTraitClasses(core.getContext());
+
+ // import polyglot decorators which are defined in Python code
+ AbstractImportNode.importModule(T_INTERNAL_POLYGLOT_MODULE);
}
@Builtin(name = "import_value", minNumOfPositionalArgs = 1, parameterNames = {"name"})
From 54b306398f2846076247a5dd03b0f3fe4232a894 Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Tue, 4 Feb 2025 13:34:39 +0100
Subject: [PATCH 003/512] Modules need to be under lib-graalpython/modules to
be found by import
---
.../freeze_modules.py | 8 +++++---
.../builtins/objects/module/FrozenModules.java | 14 ++++++++++----
.../lib-graalpython/{ => modules}/_polyglot.py | 0
.../{ => modules}/_polyglot_datetime.py | 0
.../{ => modules}/_polyglot_time.py | 0
5 files changed, 15 insertions(+), 7 deletions(-)
rename graalpython/lib-graalpython/{ => modules}/_polyglot.py (100%)
rename graalpython/lib-graalpython/{ => modules}/_polyglot_datetime.py (100%)
rename graalpython/lib-graalpython/{ => modules}/_polyglot_time.py (100%)
diff --git a/graalpython/com.oracle.graal.python.frozen/freeze_modules.py b/graalpython/com.oracle.graal.python.frozen/freeze_modules.py
index c08d654cd6..3da7439318 100644
--- a/graalpython/com.oracle.graal.python.frozen/freeze_modules.py
+++ b/graalpython/com.oracle.graal.python.frozen/freeze_modules.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2021, 2024, Oracle and/or its affiliates.
+# Copyright (c) 2021, 2025, Oracle and/or its affiliates.
# Copyright (C) 1996-2020 Python Software Foundation
#
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -105,13 +105,15 @@ def add_graalpython_core():
l.append("polyglot.arrow : polyglot.arrow = " + os.path.join(lib_graalpython, "modules/_polyglot_arrow.py"))
for name in [
"modules/_sysconfigdata",
+ "modules/_polyglot",
+ "modules/_polyglot_datetime",
+ "modules/_polyglot_time",
]:
modname = os.path.basename(name)
modpath = os.path.join(lib_graalpython, f"{name}.py")
l.append(f"{modname} : {modname} = {modpath}")
for name in [
"__graalpython__",
- "_polyglot",
"_sre",
"_sysconfig",
"_weakref",
@@ -495,7 +497,7 @@ def lower_camel_case(str):
# write frozen files
FROZEN_MODULES_HEADER = """/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/FrozenModules.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/FrozenModules.java
index ad7000fa5e..ba3867f90f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/FrozenModules.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/FrozenModules.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -218,8 +218,10 @@ private static final class Map {
private static final PythonFrozenModule FROZEN_ONLY = new PythonFrozenModule("FROZEN_ONLY", null, false);
private static final PythonFrozenModule POLYGLOT_ARROW = new PythonFrozenModule("POLYGLOT_ARROW", null, false);
private static final PythonFrozenModule _SYSCONFIGDATA = new PythonFrozenModule("_SYSCONFIGDATA", null, false);
+ private static final PythonFrozenModule _POLYGLOT = new PythonFrozenModule("_POLYGLOT", null, false);
+ private static final PythonFrozenModule _POLYGLOT_DATETIME = new PythonFrozenModule("_POLYGLOT_DATETIME", null, false);
+ private static final PythonFrozenModule _POLYGLOT_TIME = new PythonFrozenModule("_POLYGLOT_TIME", null, false);
private static final PythonFrozenModule GRAALPY___GRAALPYTHON__ = new PythonFrozenModule("GRAALPY___GRAALPYTHON__", null, false);
- private static final PythonFrozenModule GRAALPY__POLYGLOT = new PythonFrozenModule("GRAALPY__POLYGLOT", null, false);
private static final PythonFrozenModule GRAALPY__SRE = new PythonFrozenModule("GRAALPY__SRE", null, false);
private static final PythonFrozenModule GRAALPY__SYSCONFIG = new PythonFrozenModule("GRAALPY__SYSCONFIG", null, false);
private static final PythonFrozenModule GRAALPY__WEAKREF = new PythonFrozenModule("GRAALPY__WEAKREF", null, false);
@@ -595,10 +597,14 @@ public static final PythonFrozenModule lookup(String name) {
return Map.POLYGLOT_ARROW;
case "_sysconfigdata":
return Map._SYSCONFIGDATA;
+ case "_polyglot":
+ return Map._POLYGLOT;
+ case "_polyglot_datetime":
+ return Map._POLYGLOT_DATETIME;
+ case "_polyglot_time":
+ return Map._POLYGLOT_TIME;
case "graalpy.__graalpython__":
return Map.GRAALPY___GRAALPYTHON__;
- case "graalpy._polyglot":
- return Map.GRAALPY__POLYGLOT;
case "graalpy._sre":
return Map.GRAALPY__SRE;
case "graalpy._sysconfig":
diff --git a/graalpython/lib-graalpython/_polyglot.py b/graalpython/lib-graalpython/modules/_polyglot.py
similarity index 100%
rename from graalpython/lib-graalpython/_polyglot.py
rename to graalpython/lib-graalpython/modules/_polyglot.py
diff --git a/graalpython/lib-graalpython/_polyglot_datetime.py b/graalpython/lib-graalpython/modules/_polyglot_datetime.py
similarity index 100%
rename from graalpython/lib-graalpython/_polyglot_datetime.py
rename to graalpython/lib-graalpython/modules/_polyglot_datetime.py
diff --git a/graalpython/lib-graalpython/_polyglot_time.py b/graalpython/lib-graalpython/modules/_polyglot_time.py
similarity index 100%
rename from graalpython/lib-graalpython/_polyglot_time.py
rename to graalpython/lib-graalpython/modules/_polyglot_time.py
From cea4899d01c51068978b53293150877009fdd19e Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Tue, 4 Feb 2025 14:35:03 +0100
Subject: [PATCH 004/512] graalpy -v should not override Truffle log level
* It's a CPython-compatible flag and should only set the Python flag, not touch log levels.
* Otherwise `graalpy --log.level=FINE -v ...` is actually at INFO and not FINE level which is very confusing.
---
.../src/com/oracle/graal/python/shell/GraalPythonMain.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java b/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java
index f0a6328d1f..68ba6b5ccc 100644
--- a/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java
+++ b/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java
@@ -778,9 +778,6 @@ protected void launch(Builder contextBuilder) {
contextBuilder.option("python.IntMaxStrDigits", Integer.toString(intMaxStrDigits));
}
contextBuilder.option("python.DontWriteBytecodeFlag", Boolean.toString(dontWriteBytecode));
- if (verboseFlag) {
- contextBuilder.option("log.python.level", "INFO");
- }
contextBuilder.option("python.QuietFlag", Boolean.toString(quietFlag));
contextBuilder.option("python.NoUserSiteFlag", Boolean.toString(noUserSite));
contextBuilder.option("python.NoSiteFlag", Boolean.toString(noSite));
From 4c2f7e77c865c48eece12c9980c25adb23c6b9db Mon Sep 17 00:00:00 2001
From: Tim Felgentreff
Date: Mon, 10 Feb 2025 11:17:33 +0100
Subject: [PATCH 005/512] [GR-62055] Increase timeout for shared engine tests
since they are slow under jacoco.
---
.../engine/SharedEngineMultithreadingTestBase.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/engine/SharedEngineMultithreadingTestBase.java b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/engine/SharedEngineMultithreadingTestBase.java
index 3972dac6d0..6230ef9a34 100644
--- a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/engine/SharedEngineMultithreadingTestBase.java
+++ b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/engine/SharedEngineMultithreadingTestBase.java
@@ -117,7 +117,9 @@ protected static void submitAndWaitAll(ExecutorService service, Task[] tasks) th
boolean wasTimeout = false;
for (Future> future : futures) {
try {
- future.get(2, TimeUnit.MINUTES);
+ // Under coverage, some of these tests are almost 10x slower,
+ // so we go with a 15min timeout
+ future.get(15, TimeUnit.MINUTES);
} catch (TimeoutException e) {
wasTimeout = true;
}
From 32ca5355f5bdbd8781003cc8fd3eef1d20afb8b7 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff
Date: Mon, 10 Feb 2025 11:32:36 +0100
Subject: [PATCH 006/512] [GR-62058] Try harder to get coverage on windows
---
mx.graalpython/mx_graalpython.py | 53 ++++++++++++++++++++------------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py
index 7f98cfa7e3..7f00af0ec6 100644
--- a/mx.graalpython/mx_graalpython.py
+++ b/mx.graalpython/mx_graalpython.py
@@ -1563,6 +1563,30 @@ def graalpython_gate_runner(args, tasks):
"com.oracle.graal.python.test.advanced.ExclusionsTest"
])
+ if WIN32 and is_collecting_coverage():
+ mx.log("Ask for shutdown of any remaining graalpy.exe processes")
+ # On windows, the jacoco command can fail if the file is still locked
+ # by lingering test processes, so we try to give it a bit of a cleanup
+ mx.run([
+ 'taskkill.exe',
+ '/T', # with children
+ '/IM',
+ 'graalpy.exe',
+ ], nonZeroIsFatal=False)
+ time.sleep(2)
+ mx.log("Forcefully terminate any remaining graalpy.exe processes")
+ mx.run([
+ 'taskkill.exe',
+ '/F', # force
+ '/T', # with children
+ '/IM',
+ 'graalpy.exe',
+ ], nonZeroIsFatal=False)
+ # Forcefully killing processes on Windows does not release file
+ # locks immediately, so we still need to sleep for a bit in the
+ # hopes that the OS will release
+ time.sleep(8)
+
mx_gate.add_gate_runner(SUITE, graalpython_gate_runner)
@@ -2398,25 +2422,16 @@ def python_coverage(args):
'--strict-mode',
'--tags', args.tags,
] + jacoco_args, env=env)
- # On windows, the command can fail if the file is still locked by lingering test processes
- retries = 3 if WIN32 else 1
- while True:
- retval = mx.run_mx([
- '--strict-compliance',
- '--kill-with-sigquit',
- 'jacocoreport',
- '--format', 'lcov',
- '--omit-excluded',
- 'coverage',
- '--generic-paths',
- '--exclude-src-gen',
- ], env=env)
- if retval == 0:
- break
- retries -= 1
- if not retries:
- sys.exit("Failed to collect coverage report")
- time.sleep(10)
+ mx.run_mx([
+ '--strict-compliance',
+ '--kill-with-sigquit',
+ 'jacocoreport',
+ '--format', 'lcov',
+ '--omit-excluded',
+ 'coverage',
+ '--generic-paths',
+ '--exclude-src-gen',
+ ], env=env)
if args.mode == 'truffle':
executable = graalpy_standalone_jvm()
From 437b0938483977c2ef8e1b77a0d174c1e77cab23 Mon Sep 17 00:00:00 2001
From: Fengyun Liu
Date: Mon, 9 Dec 2024 16:39:48 +0100
Subject: [PATCH 007/512] Update overlay
---
ci.jsonnet | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ci.jsonnet b/ci.jsonnet
index 60791dfb90..0afcce4291 100644
--- a/ci.jsonnet
+++ b/ci.jsonnet
@@ -1 +1 @@
-{ "overlay": "bfb3f7fd7d0d4df846dad9d87dfa10d7a79dfd8b" }
+{ "overlay": "ac2b03008a765064fba41da97cbcd096f6d19809" }
From 378e4360cdf77473a6a96a77698bb2c3e2e3d649 Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Wed, 5 Feb 2025 13:22:01 +0100
Subject: [PATCH 008/512] Add test to track modules being imported during
startup
---
.../src/tests/test_startup.py | 90 +++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py b/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
new file mode 100644
index 0000000000..5e0fb21c8a
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
@@ -0,0 +1,90 @@
+# Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# The Universal Permissive License (UPL), Version 1.0
+#
+# Subject to the condition set forth below, permission is hereby granted to any
+# person obtaining a copy of this software, associated documentation and/or
+# data (collectively the "Software"), free of charge and under any and all
+# copyright rights in the Software, and any and all patent rights owned or
+# freely licensable by each licensor hereunder covering either (i) the
+# unmodified Software as contributed to or provided by such licensor, or (ii)
+# the Larger Works (as defined below), to deal in both
+#
+# (a) the Software, and
+#
+# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+# one is included with the Software each a "Larger Work" to which the Software
+# is contributed by such licensors),
+#
+# without restriction, including without limitation the rights to copy, create
+# derivative works of, display, perform, and distribute the Software and make,
+# use, sell, offer for sale, import, export, have made, and have sold the
+# Software and the Larger Work(s), and to sublicense the foregoing rights on
+# either these or other terms.
+#
+# This license is subject to the following condition:
+#
+# The above copyright notice and either this complete permission notice or at a
+# minimum a reference to the UPL must be included in all copies or substantial
+# portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import unittest
+import sys
+import re
+import subprocess
+import platform
+
+# Both lists should remain as small as possible to avoid adding overhead to startup
+expected_nosite_startup_modules = [
+ '_frozen_importlib',
+ '_frozen_importlib_external',
+ 'builtins',
+ '__graalpython__',
+ '_weakref',
+ 'unicodedata',
+ '_sre',
+ '_sysconfig',
+ 'java',
+ 'pip_hook',
+]
+
+expected_full_startup_modules = expected_nosite_startup_modules + [
+ '_abc',
+ 'types',
+ '_weakrefset',
+ '_py_abc',
+ 'abc',
+ 'stat',
+ '_collections_abc',
+ 'genericpath',
+ *(['_winapi', 'ntpath'] if platform.system() == 'Windows' else ['posixpath']),
+ 'os',
+ '_sitebuiltins',
+ '_io',
+ 'io',
+ 'site',
+]
+
+class StartupTests(unittest.TestCase):
+ @unittest.skipUnless(sys.implementation.name == 'graalpy', "GraalPy-specific test")
+ def test_startup_nosite(self):
+ result = subprocess.check_output([sys.executable, '--log.level=FINE', '-S', '-v', '-c', 'print("Hello")'], stderr=subprocess.STDOUT, text=True)
+ assert 'Hello' in result
+ imports = re.findall("import '(\S+)'", result)
+ self.assertEqual(expected_nosite_startup_modules, imports)
+
+ @unittest.skipUnless(sys.implementation.name == 'graalpy', "GraalPy-specific test")
+ def test_startup_full(self):
+ result = subprocess.check_output([sys.executable, '--log.level=FINE', '-v', '-c', 'print("Hello")'], stderr=subprocess.STDOUT, text=True)
+ assert 'Hello' in result
+ imports = re.findall("import '(\S+)'", result)
+ self.assertEqual(expected_full_startup_modules, imports)
From eeea32fbe692bf47f66624c5abcb1ba212d0ef21 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 12 Feb 2025 16:08:54 +0100
Subject: [PATCH 009/512] Fix int-to-double conversion in int.__pow__ with
negative exponent
Fixes #473
---
.../src/tests/test_int.py | 26 ++++++++++++++++++-
.../builtins/objects/ints/IntBuiltins.java | 16 ++++++------
2 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_int.py b/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
index e1b4104d77..897b2588b5 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,8 @@
import array
+from tests.util import assert_raises
+
BIG_NUMBER = 99999937497465632974931
class _NamedIntConstant(int):
@@ -118,6 +120,28 @@ def test_bigint_mul():
assert 99999937497465632974931 * (2**100) == 126764980791447734004805377032945185921379990352429056
+def test_pow():
+ assert 2 ** 10 == 1024
+ assert type(2 ** -1) is float
+ assert 2 ** -1 == 0.5
+ assert_raises(ValueError, pow, 2, 2, 0)
+
+ assert pow(2, 10, 1) == 0
+ assert pow(2, 10, 3) == 1
+ assert pow(2, 10, -3) == -2
+
+ assert 18446744073709551616 ** 2 == 340282366920938463463374607431768211456
+ assert type(18446744073709551616 ** -1) is float
+ assert 18446744073709551616 ** -1 == 5.421010862427522e-20
+ assert_raises(OverflowError, pow, 2**80000, -1)
+ assert_raises(OverflowError, pow, 2**80000, -(2**64))
+ assert_raises(ZeroDivisionError, pow, 0, -18446744073709551616)
+
+ assert_raises(ValueError, pow, 18446744073709551616, 2, 0)
+ assert pow(18446744073709551616, 2, 7) == 4
+ assert pow(18446744073709551616, 2, -3) == -2
+
+
def test_int_from_custom():
class CustomInt4():
def __int__(self):
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index e2a653ee65..e902954f4c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -1202,10 +1202,11 @@ PInt doPLPos(PInt left, long right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Shared("leftIsZero") @Cached InlinedConditionProfile leftIsZero,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- if (leftIsZero.profile(inliningTarget, left.isZero())) {
+ double leftDouble = PInt.doubleValueWithOverflow(this, left.getValue());
+ if (leftIsZero.profile(inliningTarget, leftDouble == 0.0)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
- return TrueDivNode.op(this, BigInteger.ONE, op(left.getValue(), -right));
+ return Math.pow(leftDouble, right);
}
@Specialization
@@ -1358,14 +1359,13 @@ private Object op(BigInteger left, BigInteger right) {
// we'll raise unless left is one of the shortcut values
return op(left, Long.MAX_VALUE);
}
- } else if (left.signum() == 0) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
} else {
- try {
- return Math.pow(left.longValueExact(), right.longValueExact());
- } catch (ArithmeticException e) {
- return Math.pow(left.doubleValue(), right.doubleValue());
+ double leftDouble = PInt.doubleValueWithOverflow(this, left);
+ double rightDouble = PInt.doubleValueWithOverflow(this, right);
+ if (leftDouble == 0.0) {
+ throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
+ return Math.pow(leftDouble, rightDouble);
}
}
From 9513ba0e62f5e9aa80edf3cb9ceda3945ed75a0a Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 12 Feb 2025 17:14:52 +0100
Subject: [PATCH 010/512] Increase precision of integer truediv
Fixes #474
---
.../oracle/graal/python/builtins/objects/ints/IntBuiltins.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index e902954f4c..576bf3526d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -601,7 +601,7 @@ static double doPP(PInt left, PInt right,
*/
@TruffleBoundary
private static double op(Node raisingNode, BigInteger a, BigInteger b) {
- final int precisionOfDouble = 17;
+ final int precisionOfDouble = 18;
if (fitsIntoDouble(a) && fitsIntoDouble(b)) {
return a.doubleValue() / b.doubleValue();
}
From 0fd8c5232d2eef5b7cab6a3ed5e5d8b9757e1063 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 12 Feb 2025 17:38:33 +0100
Subject: [PATCH 011/512] Handle corner case in int.to_bytes
Fixes #475
---
graalpython/com.oracle.graal.python.test/src/tests/test_int.py | 1 +
.../oracle/graal/python/builtins/objects/ints/IntBuiltins.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_int.py b/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
index 897b2588b5..625a9a8be9 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/test_int.py
@@ -800,6 +800,7 @@ def test_UnsignedLittleEndian(self):
def test_SpecialCases(self):
self.assertEqual((0).to_bytes(0, 'big'), b'')
+ self.assertEqual((-1).to_bytes(0, 'big', signed=True), b'')
self.assertEqual((1).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x01')
self.assertEqual((0).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x00')
self.assertEqual((-1).to_bytes(5, 'big', signed=True),
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index 576bf3526d..2e4ee5d9a8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -2651,7 +2651,7 @@ public static byte[] fromLong(long self, int byteCount, boolean isBigEndian, boo
index += delta;
}
- if (overflowProfile.profile(inliningTarget, !signed && number != 0 || (signed && bytes.length == 1 && bytes[0] != self) || (byteCount == 0 && self != 0))) {
+ if (overflowProfile.profile(inliningTarget, !signed && number != 0 || (signed && bytes.length == 1 && bytes[0] != self) || (byteCount == 0 && self != 0 && self != -1))) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.MESSAGE_INT_TO_BIG);
}
From 32323b8241d0e1d8e2b6fec7e485c198c8c6ac97 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Mon, 10 Feb 2025 16:55:14 +0100
Subject: [PATCH 012/512] Add nb_power slot
---
.../oracle/graal/python/annotations/Slot.java | 2 +
.../graal/python/processor/SlotsMapping.java | 2 +
.../src/tests/cpyext/test_tp_slots.py | 13 +-
.../builtins/modules/BuiltinFunctions.java | 25 +-
.../cext/PythonCextAbstractBuiltins.java | 16 +-
.../objects/cext/capi/PyProcsWrapper.java | 100 ++++++--
.../objects/cext/capi/SlotMethodDef.java | 16 +-
.../objects/cext/capi/ToNativeTypeNode.java | 1 -
.../cext/hpy/GraalHPyArithmeticNode.java | 64 +----
.../cext/hpy/GraalHPyContextFunctions.java | 9 +-
.../objects/complex/ComplexBuiltins.java | 7 +-
.../objects/floats/FloatBuiltins.java | 19 +-
.../foreign/ForeignNumberBuiltins.java | 34 ++-
.../builtins/objects/ints/IntBuiltins.java | 5 +-
.../objects/type/SpecialMethodSlot.java | 16 --
.../python/builtins/objects/type/TpSlots.java | 97 +++++---
.../slots/BuiltinSlotWrapperSignature.java | 2 +-
.../objects/type/slots/TpSlotBinaryOp.java | 67 ++---
.../objects/type/slots/TpSlotNbPower.java | 230 ++++++++++++++++++
.../graal/python/lib/CallBinaryOp1Node.java | 8 +-
.../graal/python/lib/CallTernaryOpNode.java | 132 ++++++++++
.../graal/python/lib/PyNumberAddNode.java | 6 +-
.../graal/python/lib/PyNumberAndNode.java | 4 +-
.../graal/python/lib/PyNumberDivmodNode.java | 4 +-
.../python/lib/PyNumberFloorDivideNode.java | 4 +-
.../graal/python/lib/PyNumberLshiftNode.java | 4 +-
.../lib/PyNumberMatrixMultiplyNode.java | 4 +-
.../python/lib/PyNumberMultiplyNode.java | 6 +-
.../graal/python/lib/PyNumberOrNode.java | 4 +-
.../graal/python/lib/PyNumberPowerNode.java | 109 +++++++++
.../python/lib/PyNumberRemainderNode.java | 4 +-
.../graal/python/lib/PyNumberRshiftNode.java | 4 +-
.../python/lib/PyNumberSubtractNode.java | 4 +-
.../python/lib/PyNumberTrueDivideNode.java | 4 +-
.../graal/python/lib/PyNumberXorNode.java | 4 +-
.../graal/python/lib/PySequenceConcat.java | 6 +-
.../graal/python/nodes/ErrorMessages.java | 2 +-
.../nodes/expression/BinaryArithmetic.java | 15 +-
38 files changed, 743 insertions(+), 310 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryOpNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
index bf54294c82..4d9f5c834d 100644
--- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
+++ b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
@@ -135,6 +135,8 @@ enum SlotKind {
nb_true_divide("__truediv__, __rtruediv__"),
/** foo @ bar */
nb_matrix_multiply("__matmul__, __rmatmul__"),
+ /** foo ** bar */
+ nb_power("__pow__, __rpow__"),
/** sequence length/size */
sq_length("__len__"),
/** sequence item: read element at index */
diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
index 14ed5b28f2..a9281af8b7 100644
--- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
+++ b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
@@ -56,6 +56,7 @@ static String getSlotBaseClass(Slot s) {
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
"TpSlotBinaryOp.TpSlotBinaryOpBuiltin";
+ case nb_power -> "TpSlotNbPower.TpSlotNbPowerBuiltin";
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
case sq_item, sq_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
@@ -77,6 +78,7 @@ static String getSlotNodeBaseClass(Slot s) {
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
"com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
+ case nb_power -> "com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode";
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
case sq_length, mp_length -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode";
case sq_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode";
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index 28af6b6bd9..0a7479f806 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -859,13 +859,12 @@ def __rmatmul__(self, other):
assert 2 % obj == 2
assert divmod(obj, 2) == (1, 1)
assert divmod(2, obj) == (0, 2)
- # TODO fix on graalpy
- # assert obj ** 2 == 9
- # assert 2 ** obj == 8
- # assert pow(obj, 2, 2) == 1
- # if isinstance(obj.delegate, int): # pow doesn't call __rpow__
- # assert pow(2, obj, 2) == 0
- # assert pow(2, 2, obj) == 1
+ assert obj ** 2 == 9
+ assert 2 ** obj == 8
+ assert pow(obj, 2, 2) == 1
+ if isinstance(obj.delegate, int): # pow doesn't call __rpow__
+ assert pow(2, obj, 2) == 0
+ assert pow(2, 2, obj) == 1
assert -obj == -3
assert +obj == 3
assert abs(obj) == 3
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 45dcd1c6a2..83bb3b2291 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -171,6 +171,7 @@
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyNumberDivmodNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyObjectAsciiNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectDir;
@@ -211,14 +212,10 @@
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode;
import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -2119,26 +2116,12 @@ private int getDebuggerSessionCount() {
@Builtin(name = J_POW, minNumOfPositionalArgs = 2, numOfPositionalOnlyArgs = 0, parameterNames = {"base", "exp", "mod"})
@GenerateNodeFactory
public abstract static class PowNode extends PythonTernaryBuiltinNode {
- @NeverDefault
- static BinaryOpNode binaryPow() {
- return BinaryArithmetic.Pow.create();
- }
-
- @NeverDefault
- static LookupAndCallTernaryNode ternaryPow() {
- return TernaryArithmetic.Pow.create();
- }
@Specialization
- Object binary(VirtualFrame frame, Object x, Object y, @SuppressWarnings("unused") PNone z,
- @Cached("binaryPow()") BinaryOpNode powNode) {
- return powNode.executeObject(frame, x, y);
- }
-
- @Specialization(guards = "!isPNone(z)")
Object ternary(VirtualFrame frame, Object x, Object y, Object z,
- @Cached("ternaryPow()") LookupAndCallTernaryNode powNode) {
- return powNode.execute(frame, x, y, z);
+ @Bind("this") Node inliningTarget,
+ @Cached PyNumberPowerNode power) {
+ return power.execute(frame, inliningTarget, x, y, z);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index d16ba20a8d..05d971d18c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -109,6 +109,7 @@
import com.oracle.graal.python.lib.PyNumberIndexNode;
import com.oracle.graal.python.lib.PyNumberLongNode;
import com.oracle.graal.python.lib.PyNumberMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectGetItem;
@@ -132,7 +133,6 @@
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
import com.oracle.graal.python.nodes.expression.LookupAndCallInplaceNode;
-import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
@@ -452,16 +452,10 @@ abstract static class PyNumber_Power extends CApiTernaryBuiltinNode {
@Child private LookupAndCallTernaryNode callNode;
@Specialization
- Object doGeneric(Object o1, Object o2, Object o3) {
- return ensureCallNode().execute(null, o1, o2, o3);
- }
-
- private LookupAndCallTernaryNode ensureCallNode() {
- if (callNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callNode = insert(TernaryArithmetic.Pow.create());
- }
- return callNode;
+ Object doGeneric(Object o1, Object o2, Object o3,
+ @Bind("this") Node inliningTarget,
+ @Cached PyNumberPowerNode powerNode) {
+ return powerNode.execute(null, inliningTarget, o1, o2, o3);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
index 5686c9aebc..66a8204fd9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
@@ -51,19 +51,21 @@
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformExceptionToNativeNode;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.ints.PInt;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotManaged;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.CallSlotBinaryOpNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.CallSlotDescrGet;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrSet.CallSlotDescrSet;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.CallManagedSlotGetAttrNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CallSlotNbBoolNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.CallSlotLenNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.CallSlotMpAssSubscriptNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.CallManagedSlotSetAttrNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.CallSlotSqAssItemNode;
@@ -300,63 +302,63 @@ protected String getSignature() {
@ExportLibrary(InteropLibrary.class)
public static final class BinaryOpSlotFuncWrapper extends TpSlotWrapper {
- private final BinaryOpSlot binaryOp;
+ private final ReversibleSlot binaryOp;
- public BinaryOpSlotFuncWrapper(TpSlotManaged delegate, BinaryOpSlot binaryOp) {
+ public BinaryOpSlotFuncWrapper(TpSlotManaged delegate, ReversibleSlot binaryOp) {
super(delegate);
this.binaryOp = binaryOp;
}
public static BinaryOpSlotFuncWrapper createAdd(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_ADD);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_ADD);
}
public static BinaryOpSlotFuncWrapper createSubtract(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_SUBTRACT);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_SUBTRACT);
}
public static BinaryOpSlotFuncWrapper createMultiply(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_MULTIPLY);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_MULTIPLY);
}
public static BinaryOpSlotFuncWrapper createRemainder(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_REMAINDER);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_REMAINDER);
}
public static BinaryOpSlotFuncWrapper createLShift(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_LSHIFT);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_LSHIFT);
}
public static BinaryOpSlotFuncWrapper createRShift(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_RSHIFT);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_RSHIFT);
}
public static BinaryOpSlotFuncWrapper createAnd(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_AND);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_AND);
}
public static BinaryOpSlotFuncWrapper createXor(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_XOR);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_XOR);
}
public static BinaryOpSlotFuncWrapper createOr(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_OR);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_OR);
}
public static BinaryOpSlotFuncWrapper createFloorDivide(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_FLOOR_DIVIDE);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_FLOOR_DIVIDE);
}
public static BinaryOpSlotFuncWrapper createTrueDivide(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_TRUE_DIVIDE);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_TRUE_DIVIDE);
}
public static BinaryOpSlotFuncWrapper createDivMod(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_DIVMOD);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_DIVMOD);
}
public static BinaryOpSlotFuncWrapper createMatrixMultiply(TpSlotManaged delegate) {
- return new BinaryOpSlotFuncWrapper(delegate, BinaryOpSlot.NB_MATRIX_MULTIPLY);
+ return new BinaryOpSlotFuncWrapper(delegate, ReversibleSlot.NB_MATRIX_MULTIPLY);
}
@ExportMessage
@@ -745,9 +747,9 @@ protected String getSignature() {
}
@ExportLibrary(InteropLibrary.class)
- public static final class TernaryFunctionWrapper extends PyProcsWrapper {
+ public static final class CallFunctionWrapper extends PyProcsWrapper {
- public TernaryFunctionWrapper(Object delegate) {
+ public CallFunctionWrapper(Object delegate) {
super(delegate);
}
@@ -755,7 +757,7 @@ public TernaryFunctionWrapper(Object delegate) {
static class Execute {
@Specialization(guards = "arguments.length == 3")
- static Object call(TernaryFunctionWrapper self, Object[] arguments,
+ static Object call(CallFunctionWrapper self, Object[] arguments,
@Bind("this") Node inliningTarget,
@Cached ExecutePositionalStarargsNode posStarargsNode,
@Cached ExpandKeywordStarargsNode expandKwargsNode,
@@ -779,7 +781,7 @@ static Object call(TernaryFunctionWrapper self, Object[] arguments,
Object result = callNode.execute(null, self.getDelegate(), pArgs, kwArgsArray);
return toNativeNode.execute(result);
} catch (Throwable t) {
- throw checkThrowableBeforeNative(t, "TernaryFunctionWrapper", self.getDelegate());
+ throw checkThrowableBeforeNative(t, "CallFunctionWrapper", self.getDelegate());
}
} catch (PException e) {
transformExceptionToNativeNode.execute(inliningTarget, e);
@@ -791,7 +793,7 @@ static Object call(TernaryFunctionWrapper self, Object[] arguments,
}
@Specialization(guards = "arguments.length != 3")
- static Object error(@SuppressWarnings("unused") TernaryFunctionWrapper self, Object[] arguments) throws ArityException {
+ static Object error(@SuppressWarnings("unused") CallFunctionWrapper self, Object[] arguments) throws ArityException {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw ArityException.create(3, 3, arguments.length);
}
@@ -803,6 +805,62 @@ protected String getSignature() {
}
}
+ @ExportLibrary(InteropLibrary.class)
+ public static final class NbPowerWrapper extends TpSlotWrapper {
+
+ public NbPowerWrapper(TpSlotManaged delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public TpSlotWrapper cloneWith(TpSlotManaged slot) {
+ return new NbPowerWrapper(slot);
+ }
+
+ @ExportMessage
+ static Object execute(NbPowerWrapper self, Object[] arguments,
+ @Bind("$node") Node inliningTarget,
+ @Cached NativeToPythonNode toJavaNode,
+ @Cached PythonToNativeNewRefNode toNativeNode,
+ @Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
+ @Cached GetClassNode vGetClassNode,
+ @Cached GetClassNode wGetClassNode,
+ @Cached IsSameTypeNode isSameTypeNode,
+ @Cached GetCachedTpSlotsNode wGetSlots,
+ @Cached TpSlotNbPower.CallSlotNbPowerNode callSlot,
+ @Cached GilNode gil) {
+ boolean mustRelease = gil.acquire();
+ CApiTiming.enter();
+ try {
+ try {
+ // convert args
+ Object v = toJavaNode.execute(arguments[0]);
+ Object w = toJavaNode.execute(arguments[1]);
+ Object z = toJavaNode.execute(arguments[2]);
+ Object vType = vGetClassNode.execute(inliningTarget, v);
+ Object wType = wGetClassNode.execute(inliningTarget, w);
+ TpSlots wSlots = wGetSlots.execute(inliningTarget, wType);
+ boolean sameTypes = isSameTypeNode.execute(inliningTarget, vType, wType);
+ Object result = callSlot.execute(null, inliningTarget, self.getSlot(), v, vType, w, wSlots.nb_power(), wType, z, sameTypes);
+ return toNativeNode.execute(result);
+ } catch (Throwable t) {
+ throw checkThrowableBeforeNative(t, "NbPowerWrapper", self.getDelegate());
+ }
+ } catch (PException e) {
+ transformExceptionToNativeNode.execute(inliningTarget, e);
+ return PythonContext.get(gil).getNativeNull();
+ } finally {
+ CApiTiming.exit(self.timing);
+ gil.release(mustRelease);
+ }
+ }
+
+ @Override
+ protected String getSignature() {
+ return "(POINTER,POINTER,POINTER):POINTER";
+ }
+ }
+
@ExportLibrary(InteropLibrary.class)
public static final class RichcmpFunctionWrapper extends PyProcsWrapper {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
index 1ecf3c2994..1b0fb038d6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
@@ -55,7 +55,6 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_subtract;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_true_divide;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_xor;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_power;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_as_number;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_call;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_hash;
@@ -85,7 +84,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEXT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___TRUFFLE_RICHCOMPARE__;
@@ -94,7 +92,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.HashfuncWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.InitWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.RichcmpFunctionWrapper;
-import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.TernaryFunctionWrapper;
+import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.CallFunctionWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.UnaryFuncLegacyWrapper;
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
import com.oracle.graal.python.builtins.objects.type.MethodsFlags;
@@ -103,7 +101,7 @@
import com.oracle.truffle.api.strings.TruffleString;
public enum SlotMethodDef {
- TP_CALL(PyTypeObject__tp_call, T___CALL__, TernaryFunctionWrapper::new),
+ TP_CALL(PyTypeObject__tp_call, T___CALL__, CallFunctionWrapper::new),
TP_HASH(PyTypeObject__tp_hash, T___HASH__, HashfuncWrapper::new),
TP_INIT(PyTypeObject__tp_init, T___INIT__, InitWrapper::new),
TP_ITER(PyTypeObject__tp_iter, T___ITER__, PyProcsWrapper.UnaryFuncLegacyWrapper::new),
@@ -116,7 +114,7 @@ public enum SlotMethodDef {
AM_AITER(PyAsyncMethods__am_aiter, T___AITER__, UnaryFuncLegacyWrapper::new, MethodsFlags.AM_AITER),
AM_ANEXT(PyAsyncMethods__am_anext, T___ANEXT__, PyProcsWrapper.UnaryFuncLegacyWrapper::new, MethodsFlags.AM_ANEXT),
// (mq) AM_SEND is an internal function and mostly called from within AWAIT, AITER, ANEXT.
- /*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, TernaryFunctionWrapper::new, MethodsFlags.AM_SEND), */
+ /*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, CallFunctionWrapper::new, MethodsFlags.AM_SEND), */
NB_INPLACE_ADD(PyNumberMethods__nb_inplace_add, T___IADD__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_ADD),
NB_INPLACE_AND(PyNumberMethods__nb_inplace_and, T___IAND__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_AND),
@@ -124,13 +122,12 @@ public enum SlotMethodDef {
NB_INPLACE_LSHIFT(PyNumberMethods__nb_inplace_lshift, T___ILSHIFT__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_LSHIFT),
NB_INPLACE_MULTIPLY(PyNumberMethods__nb_inplace_multiply, T___IMUL__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_MULTIPLY),
NB_INPLACE_OR(PyNumberMethods__nb_inplace_or, T___IOR__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_OR),
- NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, TernaryFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER),
+ NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER),
NB_INPLACE_REMAINDER(PyNumberMethods__nb_inplace_remainder, T___IMOD__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_REMAINDER),
NB_INPLACE_RSHIFT(PyNumberMethods__nb_inplace_rshift, T___IRSHIFT__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_RSHIFT),
NB_INPLACE_SUBTRACT(PyNumberMethods__nb_inplace_subtract, T___ISUB__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_SUBTRACT),
NB_INPLACE_TRUE_DIVIDE(PyNumberMethods__nb_inplace_true_divide, T___ITRUEDIV__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_TRUE_DIVIDE),
- NB_INPLACE_XOR(PyNumberMethods__nb_inplace_xor, T___IXOR__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_XOR),
- NB_POWER(PyNumberMethods__nb_power, T___POW__, TernaryFunctionWrapper::new, MethodsFlags.NB_POWER);
+ NB_INPLACE_XOR(PyNumberMethods__nb_inplace_xor, T___IXOR__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_XOR);
public final TruffleString methodName;
public final Function wrapperFactory;
@@ -174,8 +171,7 @@ public enum SlotMethodDef {
NB_INPLACE_RSHIFT,
NB_INPLACE_SUBTRACT,
NB_INPLACE_TRUE_DIVIDE,
- NB_INPLACE_XOR,
- NB_POWER);
+ NB_INPLACE_XOR);
}
private static void initGroup(CFields typeField, SlotMethodDef... slots) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index eeb0deee13..3d2ffcb5fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -163,7 +163,6 @@ private static Object allocatePyNumberMethods(PythonManagedClass obj, TpSlots sl
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_subtract, getSlot(obj, SlotMethodDef.NB_INPLACE_SUBTRACT));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_true_divide, getSlot(obj, SlotMethodDef.NB_INPLACE_TRUE_DIVIDE));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_xor, getSlot(obj, SlotMethodDef.NB_INPLACE_XOR));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_power, getSlot(obj, SlotMethodDef.NB_POWER));
return mem;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
index b8ee9ed5cf..1c01a5fdd6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,12 +44,10 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.function.PArguments;
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
import com.oracle.graal.python.nodes.expression.LookupAndCallInplaceNode;
-import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -179,66 +177,6 @@ public boolean isAdoptable() {
}
}
- public abstract static class HPyTernaryArithmeticNode extends Node {
-
- public abstract Object execute(Object arg0, Object arg1, Object arg2);
-
- @NeverDefault
- public static HPyTernaryArithmeticNode create(TernaryArithmetic operator) {
- return new HPyTernaryArithmeticCached(operator);
- }
-
- public static HPyTernaryArithmeticNode getUncached(TernaryArithmetic operator) {
- return HPyTernaryArithmeticUncached.UNCACHEDS[operator.ordinal()];
- }
- }
-
- private static final class HPyTernaryArithmeticCached extends HPyTernaryArithmeticNode {
- @Child private LookupAndCallTernaryNode opNode;
-
- private HPyTernaryArithmeticCached(TernaryArithmetic operator) {
- opNode = operator.create();
- }
-
- @Override
- public Object execute(Object arg0, Object arg1, Object arg2) {
- return opNode.execute(null, arg0, arg1, arg2);
- }
- }
-
- private static final class HPyTernaryArithmeticUncached extends HPyTernaryArithmeticNode {
- final TernaryArithmetic operator;
-
- public HPyTernaryArithmeticUncached(TernaryArithmetic operator) {
- this.operator = operator;
- }
-
- @TruffleBoundary
- @Override
- public Object execute(Object arg0, Object arg1, Object arg2) {
- Object[] pythonArguments = PArguments.create(3);
- PArguments.setArgument(pythonArguments, 0, arg0);
- PArguments.setArgument(pythonArguments, 1, arg1);
- PArguments.setArgument(pythonArguments, 2, arg2);
- RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
- return GenericInvokeNode.invokeUncached(callTarget, pythonArguments);
- }
-
- @Override
- public boolean isAdoptable() {
- return false;
- }
-
- private static final HPyTernaryArithmeticUncached[] UNCACHEDS;
- static {
- TernaryArithmetic[] values = TernaryArithmetic.values();
- UNCACHEDS = new HPyTernaryArithmeticUncached[values.length];
- for (int i = 0; i < values.length; i++) {
- UNCACHEDS[i] = new HPyTernaryArithmeticUncached(values[i]);
- }
- }
- }
-
public abstract static class HPyInplaceArithmeticNode extends Node {
public abstract Object execute(Object arg0, Object arg1, Object arg2);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
index dcbf20b84b..d988655d42 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
@@ -97,7 +97,6 @@
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.ReadUnicodeArrayNode;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyBinaryArithmeticNode;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyInplaceArithmeticNode;
-import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyTernaryArithmeticNode;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyUnaryArithmeticNode;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctionsFactory.GraalHPyASCIINodeGen;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctionsFactory.GraalHPyAbsoluteNodeGen;
@@ -312,6 +311,7 @@
import com.oracle.graal.python.lib.PyLongAsDoubleNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyObjectDelItem;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectGetAttrO;
@@ -345,7 +345,6 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
-import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
@@ -1021,13 +1020,13 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ar
@HPyContextFunction("ctx_Power")
@GenerateUncached
- @ImportStatic(TernaryArithmetic.class)
public abstract static class GraalHPyPower extends HPyQuaternaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1, Object arg2,
- @Cached(parameters = "Pow") HPyTernaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1, arg2);
+ @Bind("this") Node inliningTarget,
+ @Cached PyNumberPowerNode powerNode) {
+ return powerNode.execute(null, inliningTarget, arg0, arg1, arg2);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
index 1a2d47ab09..ae48d00b1a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
@@ -52,9 +52,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___NE__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___RPOW__;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ZeroDivisionError;
@@ -524,14 +522,11 @@ static Object doComplex(Object leftObj, Object rightObj,
}
}
- @Builtin(name = J___RPOW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3, reverseOperation = true)
- @Builtin(name = J___POW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @Slot(value = SlotKind.nb_power, isComplex = true)
@GenerateNodeFactory
abstract static class PowerNode extends PythonTernaryBuiltinNode {
@Specialization
- @InliningCutoff
static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unused") PNone mod,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexLeft,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
index eadc01ee34..385c5254f5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
@@ -40,10 +40,8 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___NE__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ROUND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUNC__;
import static com.oracle.graal.python.runtime.formatting.FormattingUtils.validateForFloat;
@@ -77,10 +75,10 @@
import com.oracle.graal.python.lib.PyFloatCheckNode;
import com.oracle.graal.python.lib.PyLongFromDoubleNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyObjectHashNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallVarargsNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -343,8 +341,7 @@ protected Object op(double a, double b) {
}
}
- @Builtin(name = J___RPOW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3, reverseOperation = true)
- @Builtin(name = J___POW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
+ @Slot(value = SlotKind.nb_power, isComplex = true)
@GenerateNodeFactory
public abstract static class PowNode extends PythonTernaryBuiltinNode {
protected abstract double executeDouble(VirtualFrame frame, double left, double right, PNone none) throws UnexpectedResultException;
@@ -398,7 +395,7 @@ private static double doOperation(Node inliningTarget, double left, double right
@InliningCutoff
static double doDD(VirtualFrame frame, double left, double right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
- @Shared("powCall") @Cached("create(Pow)") LookupAndCallTernaryNode callPow,
+ @Shared @Cached PyNumberPowerNode powerNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) throws UnexpectedResultException {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
return 1.0;
@@ -407,7 +404,7 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
CompilerDirectives.transferToInterpreterAndInvalidate();
// Negative numbers raised to fractional powers become complex.
PythonObjectFactory factory = PythonObjectFactory.getUncached();
- throw new UnexpectedResultException(callPow.execute(frame, factory.createComplex(left, 0), factory.createComplex(right, 0), none));
+ throw new UnexpectedResultException(powerNode.execute(frame, inliningTarget, factory.createComplex(left, 0), factory.createComplex(right, 0), none));
}
return Math.pow(left, right);
}
@@ -416,7 +413,7 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
@InliningCutoff
static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone none,
@Bind("this") Node inliningTarget,
- @Shared("powCall") @Cached("create(Pow)") LookupAndCallTernaryNode callPow,
+ @Shared @Cached PyNumberPowerNode powerNode,
@Exclusive @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
@@ -425,7 +422,7 @@ static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone
if (left < 0 && Double.isFinite(left) && Double.isFinite(right) && (right % 1 != 0)) {
// Negative numbers raised to fractional powers become complex.
PythonObjectFactory pof = factory.get(inliningTarget);
- return callPow.execute(frame, pof.createComplex(left, 0), pof.createComplex(right, 0), none);
+ return powerNode.execute(frame, inliningTarget, pof.createComplex(left, 0), pof.createComplex(right, 0), none);
}
return Math.pow(left, right);
}
@@ -435,7 +432,7 @@ static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone
static Object doGeneric(VirtualFrame frame, Object left, Object right, Object mod,
@Bind("this") Node inliningTarget,
@Cached CastToJavaDoubleNode castToJavaDoubleNode,
- @Shared("powCall") @Cached("create(Pow)") LookupAndCallTernaryNode callPow,
+ @Shared @Cached PyNumberPowerNode powerNode,
@Exclusive @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (!(mod instanceof PNone)) {
@@ -449,7 +446,7 @@ static Object doGeneric(VirtualFrame frame, Object left, Object right, Object mo
} catch (CannotCastException e) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, inliningTarget, callPow, factory, raiseNode);
+ return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, inliningTarget, powerNode, factory, raiseNode);
}
public static PowNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index fdc2923be2..86ef886d58 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -34,10 +34,8 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ROUND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUNC__;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
@@ -50,6 +48,7 @@
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
+import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
import com.oracle.graal.python.builtins.objects.foreign.ForeignObjectBuiltins.ForeignGetattrNode;
@@ -72,6 +71,7 @@
import com.oracle.graal.python.lib.PyNumberNegativeNode;
import com.oracle.graal.python.lib.PyNumberOrNode;
import com.oracle.graal.python.lib.PyNumberPositiveNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyNumberRemainderNode;
import com.oracle.graal.python.lib.PyNumberRshiftNode;
import com.oracle.graal.python.lib.PyNumberSubtractNode;
@@ -87,6 +87,7 @@
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
+import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
@@ -570,19 +571,26 @@ static Object doIt(VirtualFrame frame, Object left, Object right,
}
}
- @Builtin(name = J___POW__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_power, isComplex = true)
@GenerateNodeFactory
- abstract static class PowNode extends ForeignBinaryNode {
- PowNode() {
- super(BinaryArithmetic.Pow.create(), false);
- }
- }
+ abstract static class PowNode extends PythonTernaryBuiltinNode {
- @Builtin(name = J___RPOW__, minNumOfPositionalArgs = 2)
- @GenerateNodeFactory
- abstract static class RPowNode extends ForeignBinaryNode {
- RPowNode() {
- super(BinaryArithmetic.Pow.create(), true);
+ @Specialization
+ static Object doIt(VirtualFrame frame, Object v, Object w, Object z,
+ @Bind("this") Node inliningTarget,
+ @Cached UnboxNode unboxV,
+ @Cached UnboxNode unboxW,
+ @Cached UnboxNode unboxZ,
+ @Cached PyNumberPowerNode power) {
+ v = unboxV.execute(inliningTarget, v);
+ w = unboxW.execute(inliningTarget, w);
+ if (!(z instanceof PNone)) {
+ z = unboxZ.execute(inliningTarget, z);
+ }
+ if (v == null || w == null || z == null) {
+ return PNotImplemented.NOT_IMPLEMENTED;
+ }
+ return power.execute(frame, inliningTarget, v, w, z);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index e2a653ee65..aa0e2a7605 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -51,10 +51,8 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___NE__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ROUND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUFFLE_RICHCOMPARE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUNC__;
@@ -1085,8 +1083,7 @@ public static MulNode create() {
}
}
- @Builtin(name = J___RPOW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3, reverseOperation = true)
- @Builtin(name = J___POW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
+ @Slot(value = SlotKind.nb_power, isComplex = true)
@GenerateNodeFactory
@TypeSystemReference(PythonArithmeticTypes.class)
@ImportStatic(MathGuards.class)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
index 127007bb91..6e3969706a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
@@ -45,7 +45,6 @@
import static com.oracle.graal.python.builtins.objects.type.MethodsFlags.AM_AWAIT;
import static com.oracle.graal.python.builtins.objects.type.MethodsFlags.NB_INPLACE_ADD;
import static com.oracle.graal.python.builtins.objects.type.MethodsFlags.NB_INPLACE_MULTIPLY;
-import static com.oracle.graal.python.builtins.objects.type.MethodsFlags.NB_POWER;
import static com.oracle.graal.python.builtins.objects.type.MethodsFlags.SQ_CONTAINS;
import static com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot.Flags.NO_BUILTIN_DESCRIPTORS;
import static com.oracle.graal.python.nodes.HiddenAttr.METHODS_FLAGS;
@@ -78,11 +77,9 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEXT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NE__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ROUND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SET_NAME__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SUBCLASSCHECK__;
@@ -194,8 +191,6 @@ public enum SpecialMethodSlot {
Gt(T___GT__),
Ge(T___GE__),
- Pow(T___POW__, NB_POWER),
- RPow(T___RPOW__, NB_POWER),
Round(T___ROUND__),
IAdd(T___IADD__, NB_INPLACE_ADD),
@@ -250,7 +245,6 @@ static class Flags {
}
static {
- Pow.reverse = RPow;
assert checkFind();
assert checkReverseSlots();
}
@@ -876,16 +870,6 @@ public static SpecialMethodSlot findSpecialSlot(TruffleString name, TruffleStrin
return Round;
}
break;
- case 'p' * 26 + 'o': // po
- if (eqNode.execute(name, T___POW__, TS_ENCODING)) {
- return Pow;
- }
- break;
- case 'r' * 26 + 'p': // rp
- if (eqNode.execute(name, T___RPOW__, TS_ENCODING)) {
- return RPow;
- }
- break;
case 'i' * 26 + 'a': // ia
if (eqNode.execute(name, T___IADD__, TS_ENCODING)) {
return IAdd;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index 914fbec3ce..c984c2a92d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -65,6 +65,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEG__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___OR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POS__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RAND__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RDIVMOD__;
@@ -74,6 +75,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RMOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ROR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RRSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSUB__;
@@ -113,6 +115,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.GetAttrWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.InquiryWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.LenfuncWrapper;
+import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.NbPowerWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.ObjobjargWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.SetattrWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.SsizeargfuncSlotWrapper;
@@ -141,7 +144,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.TpSlotBinaryFuncBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.TpSlotSqConcat;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotBinaryOpBuiltin;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotBinaryOpPython;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotReversiblePython;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.TpSlotDescrGetBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrSet.TpSlotDescrSetBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrSet.TpSlotDescrSetPython;
@@ -151,6 +154,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.TpSlotLenBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.TpSlotMpAssSubscriptBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.TpSlotMpAssSubscriptPython;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower.TpSlotNbPowerBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.TpSlotSetAttrBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.TpSlotSetAttrPython;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin;
@@ -258,6 +262,7 @@ public record TpSlots(TpSlot nb_bool, //
TpSlot nb_true_divide, //
TpSlot nb_divmod, //
TpSlot nb_matrix_multiply, //
+ TpSlot nb_power, //
TpSlot sq_length, //
TpSlot sq_item, //
TpSlot sq_ass_item, //
@@ -422,7 +427,7 @@ public enum TpSlotMeta {
UnaryFuncWrapper::new),
NB_ADD(
TpSlots::nb_add,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_add,
@@ -430,7 +435,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createAdd),
NB_SUBTRACT(
TpSlots::nb_subtract,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_subtract,
@@ -438,7 +443,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createSubtract),
NB_MULTIPLY(
TpSlots::nb_multiply,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_multiply,
@@ -446,7 +451,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createMultiply),
NB_REMAINDER(
TpSlots::nb_remainder,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_remainder,
@@ -454,7 +459,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createRemainder),
NB_LSHIFT(
TpSlots::nb_lshift,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_lshift,
@@ -462,7 +467,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createLShift),
NB_RSHIFT(
TpSlots::nb_rshift,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_rshift,
@@ -470,7 +475,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createRShift),
NB_AND(
TpSlots::nb_and,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_and,
@@ -478,7 +483,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createAnd),
NB_XOR(
TpSlots::nb_xor,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_xor,
@@ -486,7 +491,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createXor),
NB_OR(
TpSlots::nb_or,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_or,
@@ -494,7 +499,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createOr),
NB_FLOOR_DIVIDE(
TpSlots::nb_floor_divide,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_floor_divide,
@@ -502,7 +507,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createFloorDivide),
NB_TRUE_DIVIDE(
TpSlots::nb_true_divide,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_true_divide,
@@ -510,7 +515,7 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createTrueDivide),
NB_DIVMOD(
TpSlots::nb_divmod,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_divmod,
@@ -518,12 +523,20 @@ public enum TpSlotMeta {
BinaryOpSlotFuncWrapper::createDivMod),
NB_MATRIX_MULTIPLY(
TpSlots::nb_matrix_multiply,
- TpSlotBinaryOpPython.class,
+ TpSlotReversiblePython.class,
TpSlotBinaryOpBuiltin.class,
TpSlotGroup.AS_NUMBER,
CFields.PyNumberMethods__nb_matrix_multiply,
PExternalFunctionWrapper.BINARYFUNC,
BinaryOpSlotFuncWrapper::createMatrixMultiply),
+ NB_POWER(
+ TpSlots::nb_power,
+ TpSlotReversiblePython.class,
+ TpSlotNbPowerBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_power,
+ PExternalFunctionWrapper.TERNARYFUNC,
+ NbPowerWrapper::new),
SQ_LENGTH(
TpSlots::sq_length,
TpSlotPythonSingle.class,
@@ -816,44 +829,47 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
TpSlotDef.withoutHPy(T___SET__, TpSlotDescrSetPython::create, PExternalFunctionWrapper.DESCR_SET), //
TpSlotDef.withoutHPy(T___DELETE__, TpSlotDescrSetPython::create, PExternalFunctionWrapper.DESCR_DELETE));
addSlotDef(s, TpSlotMeta.NB_ADD,
- TpSlotDef.withoutHPy(T___ADD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RADD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___ADD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RADD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_SUBTRACT,
- TpSlotDef.withoutHPy(T___SUB__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RSUB__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___SUB__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RSUB__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_MULTIPLY,
- TpSlotDef.withoutHPy(T___MUL__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RMUL__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___MUL__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RMUL__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_REMAINDER,
- TpSlotDef.withoutHPy(T___MOD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RMOD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___MOD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RMOD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_LSHIFT,
- TpSlotDef.withoutHPy(T___LSHIFT__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RLSHIFT__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___LSHIFT__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RLSHIFT__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_RSHIFT,
- TpSlotDef.withoutHPy(T___RSHIFT__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RRSHIFT__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___RSHIFT__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RRSHIFT__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_AND,
- TpSlotDef.withoutHPy(T___AND__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RAND__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___AND__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RAND__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_XOR,
- TpSlotDef.withoutHPy(T___XOR__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RXOR__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___XOR__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RXOR__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_OR,
- TpSlotDef.withoutHPy(T___OR__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___ROR__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___OR__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___ROR__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_FLOOR_DIVIDE,
- TpSlotDef.withoutHPy(T___FLOORDIV__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RFLOORDIV__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___FLOORDIV__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RFLOORDIV__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_TRUE_DIVIDE,
- TpSlotDef.withoutHPy(T___TRUEDIV__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RTRUEDIV__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___TRUEDIV__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RTRUEDIV__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_DIVMOD,
- TpSlotDef.withoutHPy(T___DIVMOD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RDIVMOD__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___DIVMOD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RDIVMOD__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_MATRIX_MULTIPLY,
- TpSlotDef.withoutHPy(T___MATMUL__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_L),
- TpSlotDef.withoutHPy(T___RMATMUL__, TpSlotBinaryOpPython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ TpSlotDef.withoutHPy(T___MATMUL__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_L),
+ TpSlotDef.withoutHPy(T___RMATMUL__, TpSlotReversiblePython::create, PExternalFunctionWrapper.BINARYFUNC_R));
+ addSlotDef(s, TpSlotMeta.NB_POWER,
+ TpSlotDef.withoutHPy(T___POW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC),
+ TpSlotDef.withoutHPy(T___RPOW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_BOOL, TpSlotDef.withSimpleFunction(T___BOOL__, PExternalFunctionWrapper.INQUIRY));
addSlotDef(s, TpSlotMeta.NB_INDEX, TpSlotDef.withSimpleFunction(T___INDEX__, PExternalFunctionWrapper.UNARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INT, TpSlotDef.withSimpleFunction(T___INT__, PExternalFunctionWrapper.UNARYFUNC));
@@ -1475,6 +1491,7 @@ public TpSlots build() {
get(TpSlotMeta.NB_TRUE_DIVIDE), //
get(TpSlotMeta.NB_DIVMOD), //
get(TpSlotMeta.NB_MATRIX_MULTIPLY), //
+ get(TpSlotMeta.NB_POWER), //
get(TpSlotMeta.SQ_LENGTH), //
get(TpSlotMeta.SQ_ITEM), //
get(TpSlotMeta.SQ_ASS_ITEM), //
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/BuiltinSlotWrapperSignature.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/BuiltinSlotWrapperSignature.java
index cafd60aae0..7821b0d686 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/BuiltinSlotWrapperSignature.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/BuiltinSlotWrapperSignature.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
index 3cc64a294f..462a7da957 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
@@ -49,6 +49,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___OR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RAND__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RDIVMOD__;
@@ -58,6 +59,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RMOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ROR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RRSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSUB__;
@@ -125,7 +127,7 @@ public class TpSlotBinaryOp {
private TpSlotBinaryOp() {
}
- public enum BinaryOpSlot {
+ public enum ReversibleSlot {
NB_ADD(T___ADD__, T___RADD__),
NB_SUBTRACT(T___SUB__, T___RSUB__),
NB_MULTIPLY(T___MUL__, T___RMUL__),
@@ -138,13 +140,14 @@ public enum BinaryOpSlot {
NB_FLOOR_DIVIDE(T___FLOORDIV__, T___RFLOORDIV__),
NB_TRUE_DIVIDE(T___TRUEDIV__, T___RTRUEDIV__),
NB_DIVMOD(T___DIVMOD__, T___RDIVMOD__),
- NB_MATRIX_MULTIPLY(T___MATMUL__, T___RMATMUL__);
+ NB_MATRIX_MULTIPLY(T___MATMUL__, T___RMATMUL__),
+ NB_POWER_BINARY(T___POW__, T___RPOW__);
- private static final BinaryOpSlot[] VALUES = values();
+ private static final ReversibleSlot[] VALUES = values();
private final TruffleString name;
private final TruffleString rname;
- BinaryOpSlot(TruffleString name, TruffleString rname) {
+ ReversibleSlot(TruffleString name, TruffleString rname) {
this.name = name;
this.rname = rname;
}
@@ -165,11 +168,12 @@ public TpSlot getSlotValue(TpSlots slots) {
case NB_TRUE_DIVIDE -> slots.nb_true_divide();
case NB_DIVMOD -> slots.nb_divmod();
case NB_MATRIX_MULTIPLY -> slots.nb_matrix_multiply();
+ case NB_POWER_BINARY -> slots.nb_power();
};
}
- public static BinaryOpSlot fromCallableNames(TruffleString[] names) {
- for (BinaryOpSlot op : VALUES) {
+ public static ReversibleSlot fromCallableNames(TruffleString[] names) {
+ for (ReversibleSlot op : VALUES) {
if (names[0].equals(op.name) && names[1].equals(op.rname)) {
return op;
}
@@ -234,24 +238,24 @@ public Object execute(VirtualFrame frame, Object self, Object other) {
public abstract static class BinaryOpBuiltinNode extends PythonBinaryBuiltinNode {
}
- public static final class TpSlotBinaryOpPython extends TpSlotPython {
- private final BinaryOpSlot op;
+ public static final class TpSlotReversiblePython extends TpSlotPython {
+ private final ReversibleSlot op;
private final TruffleWeakReference left;
private final TruffleWeakReference right;
private final TruffleWeakReference type;
- public TpSlotBinaryOpPython(BinaryOpSlot op, Object setattr, Object delattr, Object type) {
+ public TpSlotReversiblePython(ReversibleSlot op, Object left, Object right, Object type) {
this.op = op;
- this.left = asWeakRef(setattr);
- this.right = asWeakRef(delattr);
+ this.left = asWeakRef(left);
+ this.right = asWeakRef(right);
this.type = new TruffleWeakReference<>(type);
}
- public static TpSlotBinaryOpPython create(Object[] callables, TruffleString[] callableNames, Object type) {
+ public static TpSlotReversiblePython create(Object[] callables, TruffleString[] callableNames, Object type) {
assert callables.length == 2;
- BinaryOpSlot op = BinaryOpSlot.fromCallableNames(callableNames);
+ ReversibleSlot op = ReversibleSlot.fromCallableNames(callableNames);
assert op != null : "Unexpected callable names: " + Arrays.toString(callableNames);
- return new TpSlotBinaryOpPython(op, callables[0], callables[1], type);
+ return new TpSlotReversiblePython(op, callables[0], callables[1], type);
}
@Override
@@ -259,7 +263,7 @@ public TpSlotPython forNewType(Object klass) {
Object newLeft = LookupAttributeInMRONode.Dynamic.getUncached().execute(klass, op.name);
Object newRight = LookupAttributeInMRONode.Dynamic.getUncached().execute(klass, op.rname);
if (newLeft != getLeft() || newRight != getRight()) {
- return new TpSlotBinaryOpPython(op, newLeft, newRight, getType());
+ return new TpSlotReversiblePython(op, newLeft, newRight, getType());
}
return this;
}
@@ -288,27 +292,27 @@ public abstract static class CallSlotBinaryOpNode extends Node {
// This happens in CallBinaryOp1Node (cpython:binary_op1)
public abstract Object execute(VirtualFrame frame, Node inliningTarget, TpSlot slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes,
- BinaryOpSlot op);
+ ReversibleSlot op);
@SuppressWarnings("unused")
@Specialization(guards = "cachedSlot == slot", limit = "3")
static Object callCachedBuiltin(VirtualFrame frame, TpSlotBinaryOpBuiltin> slot, Object self,
- Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op,
+ Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op,
@Cached("slot") TpSlotBinaryOpBuiltin> cachedSlot,
@Cached("cachedSlot.createOpSlotNode()") BinaryOpBuiltinNode slotNode) {
return slotNode.execute(frame, self, other);
}
@Specialization
- static Object callPython(VirtualFrame frame, TpSlotBinaryOpPython slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op,
- @Cached(inline = false) CallBinaryOpPythonSlotNode callPython) {
+ static Object callPython(VirtualFrame frame, TpSlotReversiblePython slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op,
+ @Cached(inline = false) CallReversiblePythonSlotNode callPython) {
return callPython.execute(frame, slot, self, selfType, other, otherSlot, otherType, sameTypes, op);
}
@SuppressWarnings("unused")
@Specialization
static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self,
- Object selfType, Object arg, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op,
+ Object selfType, Object arg, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op,
@Exclusive @Cached GetThreadStateNode getThreadStateNode,
@Cached(inline = false) PythonToNativeNode selfToNativeNode,
@Cached(inline = false) PythonToNativeNode argToNativeNode,
@@ -344,7 +348,7 @@ static Object callHPy(VirtualFrame frame, Node inliningTarget, TpSlotHPyNative s
@Specialization(replaces = "callCachedBuiltin")
@InliningCutoff
static Object callGenericComplexBuiltin(VirtualFrame frame, Node inliningTarget, TpSlotBinaryOpBuiltin> slot,
- Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op,
+ Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op,
@Cached(inline = false) CallContext callContext,
@Cached InlinedConditionProfile isNullFrameProfile,
@Cached(inline = false) IndirectCallNode indirectCallNode) {
@@ -357,11 +361,12 @@ static Object callGenericComplexBuiltin(VirtualFrame frame, Node inliningTarget,
@GenerateUncached
@GenerateInline(false) // intentional explicit "data-class"
- abstract static class CallBinaryOpPythonSlotNode extends Node {
- public abstract Object execute(VirtualFrame frame, TpSlot slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op);
+ abstract static class CallReversiblePythonSlotNode extends Node {
+ public abstract Object execute(VirtualFrame frame, TpSlotReversiblePython slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes,
+ ReversibleSlot op);
@Specialization
- static Object callPython(VirtualFrame frame, TpSlotBinaryOpPython slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, BinaryOpSlot op,
+ static Object callPython(VirtualFrame frame, TpSlotReversiblePython slot, Object self, Object selfType, Object other, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op,
@Bind("this") Node inliningTarget,
@Cached IsSubtypeNode isSubtypeNode,
@Cached GetCachedTpSlotsNode getSelfSlotsNode,
@@ -371,11 +376,11 @@ static Object callPython(VirtualFrame frame, TpSlotBinaryOpPython slot, Object s
@Cached InlinedConditionProfile dispatchR2Profile,
@Cached BinaryPythonSlotDispatcherNode dispatcherNode) {
// Implements the logic of SLOT1BINFULL macro from CPython
- TpSlotBinaryOpPython otherSlotValue = null;
+ TpSlotReversiblePython otherSlotValue = null;
boolean doOther = false;
if (!sameTypes) {
- if (isBinOpWrapper(otherSlot, op)) {
- otherSlotValue = (TpSlotBinaryOpPython) otherSlot;
+ if (isSameReversibleWrapper(otherSlot, op)) {
+ otherSlotValue = (TpSlotReversiblePython) otherSlot;
doOther = true;
}
}
@@ -383,7 +388,7 @@ static Object callPython(VirtualFrame frame, TpSlotBinaryOpPython slot, Object s
TpSlots selfSlots = getSelfSlotsNode.execute(inliningTarget, selfType);
TpSlot selfSlotValue = op.getSlotValue(selfSlots);
// Note: the slot may be other's slot, not self's slot, so this test may not pass
- if (isBinOpWrapper(selfSlotValue, op)) {
+ if (isSameReversibleWrapper(selfSlotValue, op)) {
if (doOther && isSubtypeNode.execute(frame, otherType, selfType)) {
if (methodIsOverloaded(frame, inliningTarget, slot, otherSlotValue, neNode)) {
Object result = dispatchIfAvailable(frame, inliningTarget, dispatchR1Profile, dispatcherNode, other, self, otherSlotValue.getRight(), otherSlotValue.getType());
@@ -415,14 +420,14 @@ private static Object dispatchIfAvailable(VirtualFrame frame, Node inliningTarge
}
}
- static boolean isBinOpWrapper(TpSlot s, BinaryOpSlot op) {
+ static boolean isSameReversibleWrapper(TpSlot s, ReversibleSlot op) {
// Equivalent to CPython test: Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC
// We have multiple wrappers, because we cache state (MRO lookups) in the wrapper too
- return s instanceof TpSlotBinaryOpPython p && p.op == op;
+ return s instanceof TpSlotReversiblePython p && p.op == op;
}
static boolean methodIsOverloaded(VirtualFrame frame, Node inliningTarget,
- TpSlotBinaryOpPython leftSlot, TpSlotBinaryOpPython rightSlot, RichCompareCallablesNotEqual neNode) {
+ TpSlotReversiblePython leftSlot, TpSlotReversiblePython rightSlot, RichCompareCallablesNotEqual neNode) {
// CPython uses _PyObject_LookupAttr(Py_TYPE(x), name) as opposed to
// _PyType_Lookup(Py_TYPE(x), name). Moreover, we cache the MRO lookup results in the
// slot, CPython doesn't, presumably because the slot cannot (easily) hold the extra
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
new file mode 100644
index 0000000000..0272498c35
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.builtins.objects.type.slots;
+
+import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
+
+import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.builtins.Python3Core;
+import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.ExternalFunctionInvokeNode;
+import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper;
+import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode;
+import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
+import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode;
+import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
+import com.oracle.graal.python.builtins.objects.function.PArguments;
+import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.NodeFactoryUtils.WrapperNodeFactory;
+import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.TernaryPythonSlotDispatcherNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltin;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotCExtNative;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.CallReversiblePythonSlotNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotReversiblePython;
+import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
+import com.oracle.graal.python.runtime.ExecutionContext.CallContext;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.RootCallTarget;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NodeFactory;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.IndirectCallNode;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+import com.oracle.truffle.api.profiles.InlinedConditionProfile;
+import com.oracle.truffle.api.strings.TruffleString;
+
+public final class TpSlotNbPower {
+ private TpSlotNbPower() {
+ }
+
+ public abstract static class TpSlotNbPowerBuiltin extends TpSlotBuiltin {
+ private final int callTargetIndex = TpSlotBuiltinCallTargetRegistry.getNextCallTargetIndex();
+
+ private static final BuiltinSlotWrapperSignature SIGNATURE = BuiltinSlotWrapperSignature.of(2, "v", "w", "z");
+
+ protected TpSlotNbPowerBuiltin(NodeFactory nodeFactory) {
+ super(nodeFactory);
+ }
+
+ final PythonTernaryBuiltinNode createOpSlotNode() {
+ return createNode();
+ }
+
+ @Override
+ public void initialize(PythonLanguage language) {
+ RootCallTarget callTarget = createBuiltinCallTarget(language, SIGNATURE, getNodeFactory(), J___POW__);
+ language.setBuiltinSlotCallTarget(callTargetIndex, callTarget);
+ }
+
+ @Override
+ public PBuiltinFunction createBuiltin(Python3Core core, Object type, TruffleString tsName, PExternalFunctionWrapper wrapper) {
+ return switch (wrapper) {
+ case TERNARYFUNC -> createBuiltin(core, type, tsName, SIGNATURE, wrapper, getNodeFactory());
+ case TERNARYFUNC_R -> createRBuiltin(core, type, tsName);
+ default -> null;
+ };
+ }
+
+ private PBuiltinFunction createRBuiltin(Python3Core core, Object type, TruffleString tsName) {
+ var factory = WrapperNodeFactory.wrap(getNodeFactory(), SwapArgumentsNode.class, SwapArgumentsNode::new);
+ return createBuiltin(core, type, tsName, SIGNATURE, PExternalFunctionWrapper.TERNARYFUNC_R, factory);
+ }
+ }
+
+ static final class SwapArgumentsNode extends PythonTernaryBuiltinNode {
+ @Child private PythonTernaryBuiltinNode wrapped;
+
+ SwapArgumentsNode(PythonTernaryBuiltinNode wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public Object execute(VirtualFrame frame, Object self, Object w, Object z) {
+ return wrapped.execute(frame, w, self, z);
+ }
+ }
+
+ @GenerateInline
+ @GenerateCached(false)
+ @GenerateUncached
+ public abstract static class CallSlotNbPowerNode extends Node {
+ private static final CApiTiming C_API_TIMING = CApiTiming.create(true, "ternaryfunc");
+
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, TpSlot slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes);
+
+ @SuppressWarnings("unused")
+ @Specialization(guards = "cachedSlot == slot", limit = "3")
+ static Object callCachedBuiltin(VirtualFrame frame, TpSlotNbPowerBuiltin> slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes,
+ @Cached("slot") TpSlotNbPowerBuiltin> cachedSlot,
+ @Cached("cachedSlot.createOpSlotNode()") PythonTernaryBuiltinNode slotNode) {
+ return slotNode.execute(frame, v, w, z);
+ }
+
+ @Specialization
+ static Object callPython(VirtualFrame frame, TpSlotReversiblePython slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes,
+ @Cached(inline = false) CallNbPowerPythonNode callPython) {
+ return callPython.execute(frame, slot, v, vType, w, wSlot, wType, z, sameTypes);
+ }
+
+ @SuppressWarnings("unused")
+ @Specialization
+ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes,
+ @Cached GetThreadStateNode getThreadStateNode,
+ @Cached(inline = false) PythonToNativeNode vToNative,
+ @Cached(inline = false) PythonToNativeNode wToNative,
+ @Cached(inline = false) PythonToNativeNode zToNative,
+ @Cached ExternalFunctionInvokeNode externalInvokeNode,
+ @Cached(inline = false) NativeToPythonTransferNode toPythonNode,
+ @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) {
+ PythonContext ctx = PythonContext.get(inliningTarget);
+ PythonContext.PythonThreadState state = getThreadStateNode.execute(inliningTarget, ctx);
+ Object result = externalInvokeNode.call(frame, inliningTarget, state, C_API_TIMING, T___POW__, slot.callable,
+ vToNative.execute(v), wToNative.execute(w), zToNative.execute(z));
+ return checkResultNode.execute(state, T___POW__, toPythonNode.execute(result));
+ }
+
+ @SuppressWarnings("unused")
+ @Specialization(replaces = "callCachedBuiltin")
+ @InliningCutoff
+ static Object callGenericComplexBuiltin(VirtualFrame frame, Node inliningTarget, TpSlotNbPowerBuiltin> slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes,
+ @Cached(inline = false) CallContext callContext,
+ @Cached InlinedConditionProfile isNullFrameProfile,
+ @Cached(inline = false) IndirectCallNode indirectCallNode) {
+ Object[] arguments = PArguments.create(3);
+ PArguments.setArgument(arguments, 0, v);
+ PArguments.setArgument(arguments, 1, w);
+ PArguments.setArgument(arguments, 2, z);
+ return BuiltinDispatchers.callGenericBuiltin(frame, inliningTarget, slot.callTargetIndex, arguments, callContext, isNullFrameProfile, indirectCallNode);
+ }
+ }
+
+ @GenerateUncached
+ @GenerateInline(false) // intentional explicit "data-class"
+ abstract static class CallNbPowerPythonNode extends Node {
+ public abstract Object execute(VirtualFrame frame, TpSlotReversiblePython slot, Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes);
+
+ @Specialization
+ static Object callPythonAsBinary(VirtualFrame frame, TpSlotReversiblePython slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, @SuppressWarnings("unused") PNone z, boolean sameTypes,
+ @Cached CallReversiblePythonSlotNode callPython) {
+ return callPython.execute(frame, slot, v, vType, w, wSlot, wType, sameTypes, ReversibleSlot.NB_POWER_BINARY);
+ }
+
+ @Fallback
+ @SuppressWarnings("unused")
+ static Object callPythonAsTernary(VirtualFrame frame, TpSlotReversiblePython slot,
+ Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes,
+ @Bind("this") Node inliningTarget,
+ @Cached GetCachedTpSlotsNode getSelfSlotsNode,
+ @Cached TernaryPythonSlotDispatcherNode dispatcherNode,
+ @Cached InlinedBranchProfile notImplementedProfile) {
+ /*
+ * Three-arg power doesn't use __rpow__. But ternary_op can call this when the second
+ * argument's type uses slot_nb_power, so check before calling self.__pow__.
+ */
+ TpSlots selfSlots = getSelfSlotsNode.execute(inliningTarget, vType);
+ if (CallReversiblePythonSlotNode.isSameReversibleWrapper(selfSlots.nb_power(), ReversibleSlot.NB_POWER_BINARY)) {
+ return dispatcherNode.execute(frame, inliningTarget, slot.getLeft(), slot.getType(), v, w, z);
+ }
+ notImplementedProfile.enter(inliningTarget);
+ return PNotImplemented.NOT_IMPLEMENTED;
+ }
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
index 5da1edf36f..3071008a18 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.IsSameSlotNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.CallSlotBinaryOpNode;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
@@ -64,7 +64,7 @@
@GenerateCached(false)
public abstract class CallBinaryOp1Node extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV,
- Object w, Object classW, TpSlot slotW, BinaryOpSlot op);
+ Object w, Object classW, TpSlot slotW, ReversibleSlot op);
// CPython binary_op1 may end up calling SLOT1BINFULL - wrapper around the dunder methods, which
// duplicates some of the logic checking the right operand, its slot, and whether it is subtype.
@@ -86,7 +86,7 @@ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v
// we just try __rxxx__, again, without any subclass check.
@Specialization
- static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV, Object w, Object classW, TpSlot slotWIn, BinaryOpSlot op,
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV, Object w, Object classW, TpSlot slotWIn, ReversibleSlot op,
@Cached IsSameTypeNode isSameTypeNode,
@Cached IsSameSlotNode isSameSlotNode,
@Cached InlinedConditionProfile isSameTypeProfile,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryOpNode.java
new file mode 100644
index 0000000000..706e0e5fd5
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryOpNode.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.IsSameSlotNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower.CallSlotNbPowerNode;
+import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+import com.oracle.truffle.api.profiles.InlinedConditionProfile;
+
+@GenerateInline
+@GenerateCached(value = false)
+@GenerateUncached
+public abstract class CallTernaryOpNode extends Node {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV, Object w, Object classW, TpSlot slotW, Object z);
+
+ @Specialization
+ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV, Object w, Object classW, TpSlot slotWIn, Object z,
+ @Cached IsSameTypeNode isSameTypeNode,
+ @Cached IsSameSlotNode isSameSlotNode,
+ @Cached InlinedConditionProfile isSameTypeProfile,
+ @Cached InlinedConditionProfile isSameSlotProfile,
+ @Cached(inline = false) IsSubtypeNode isSubtypeNode,
+ @Cached InlinedBranchProfile wResultBranch,
+ @Cached InlinedBranchProfile vResultBranch,
+ @Cached InlinedBranchProfile wResult2Branch,
+ @Cached InlinedBranchProfile notImplementedBranch,
+ @Cached CallSlotNbPowerNode callSlotWNode,
+ @Cached CallSlotNbPowerNode callSlotVNode,
+ @Cached CallSlotNbPowerNode callSlotZNode,
+ @Cached GetClassNode getZClass,
+ @Cached GetCachedTpSlotsNode getZSlots) {
+ TpSlot slotW = null;
+ boolean sameTypes = isSameTypeProfile.profile(inliningTarget, isSameTypeNode.execute(inliningTarget, classW, classV));
+ if (!sameTypes) {
+ slotW = slotWIn;
+ if (isSameSlotProfile.profile(inliningTarget, slotV != null && slotW != null && isSameSlotNode.execute(inliningTarget, slotW, slotV))) {
+ slotW = null;
+ }
+ }
+
+ if (slotV != null) {
+ if (slotW != null && isSubtypeNode.execute(frame, classW, classV)) {
+ assert !sameTypes;
+ Object result = callSlotWNode.execute(frame, inliningTarget, slotW, v, classV, w, slotW, classW, z, false);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ wResultBranch.enter(inliningTarget);
+ return result;
+ }
+ slotW = null;
+ }
+ Object result = callSlotVNode.execute(frame, inliningTarget, slotV, v, classV, w, slotWIn, classW, z, sameTypes);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ vResultBranch.enter(inliningTarget);
+ return result;
+ }
+ }
+
+ if (slotW != null) {
+ assert !sameTypes;
+ Object result = callSlotWNode.execute(frame, inliningTarget, slotW, v, classV, w, slotW, classW, z, false);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ wResult2Branch.enter(inliningTarget);
+ return result;
+ }
+ }
+
+ if (z != PNone.NONE) {
+ Object classZ = getZClass.execute(inliningTarget, z);
+ TpSlot slotZ = getZSlots.execute(inliningTarget, classZ).nb_power();
+ if (slotZ != null) {
+ if ((slotV == null || !isSameSlotNode.execute(inliningTarget, slotZ, slotV)) && (slotW == null || !isSameSlotNode.execute(inliningTarget, slotZ, slotW))) {
+ return callSlotZNode.execute(frame, inliningTarget, slotZ, v, classV, w, slotWIn, classW, z, false);
+ }
+ }
+ }
+
+ notImplementedBranch.enter(inliningTarget);
+ return PNotImplemented.NOT_IMPLEMENTED;
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 483757851e..91ee5c1a5d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,7 +52,7 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
@@ -182,7 +182,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
TpSlot slotV = slotsV.nb_add();
TpSlot slotW = slotsW.nb_add();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_ADD);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_ADD);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
hasNbAddResult.enter(inliningTarget);
return result;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
index dbaef51dc7..6f8083ce72 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -94,7 +94,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_and();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_and();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_AND);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_AND);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
index cbb830c858..fdf765a769 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -84,7 +84,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_divmod();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_divmod();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_DIVMOD);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_DIVMOD);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
index 29e1cda87a..dbce52a051 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -122,7 +122,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_floor_divide();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_floor_divide();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_FLOOR_DIVIDE);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_FLOOR_DIVIDE);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
index 82ce4248ae..9a7f29497d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -102,7 +102,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_lshift();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_lshift();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_LSHIFT);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_LSHIFT);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
index fe1bcffd5e..2076c14976 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -82,7 +82,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_matrix_multiply();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_matrix_multiply();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_MATRIX_MULTIPLY);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_MATRIX_MULTIPLY);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index 2f58fa3bce..78ad860388 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,7 +45,7 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -138,7 +138,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
TpSlot slotV = slotsV.nb_multiply();
TpSlot slotW = slotsW.nb_multiply();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_MULTIPLY);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_MULTIPLY);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
hasNbMulResult.enter(inliningTarget);
return result;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
index deba1bad16..29a24b4396 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -93,7 +93,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_or();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_or();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_OR);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_OR);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
new file mode 100644
index 0000000000..08567bf55d
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(inlineByDefault = true)
+@GenerateUncached
+public abstract class PyNumberPowerNode extends BinaryOpNode {
+
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z);
+
+ @Override
+ public final Object executeObject(VirtualFrame frame, Object left, Object right) {
+ return executeCached(frame, left, right, PNone.NONE);
+ }
+
+ public final Object executeCached(VirtualFrame frame, Object v, Object w, Object z) {
+ return execute(frame, this, v, w, z);
+ }
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z,
+ @Cached GetClassNode getVClass,
+ @Cached GetClassNode getWClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Cached CallTernaryOpNode callTernaryOpNode,
+ @Cached PRaiseNode.Lazy raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_power();
+ TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_power();
+ Object result = callTernaryOpNode.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, z);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
+ }
+ return raiseNotSupported(inliningTarget, v, w, z, raiseNode);
+ }
+
+ @InliningCutoff
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Object z, PRaiseNode.Lazy raiseNode) {
+ if (z == PNone.NONE) {
+ return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "** or pow()", v, w);
+ } else {
+ return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, "** or pow()", v, w, z);
+ }
+ }
+
+ @NeverDefault
+ public static PyNumberPowerNode create() {
+ return PyNumberPowerNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
index fdfb76ca64..9d1f89d2ef 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
@@ -45,7 +45,7 @@
import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -99,7 +99,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_remainder();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_remainder();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_REMAINDER);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_REMAINDER);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
index 2bc00a6dff..cc39873f8d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
@@ -48,7 +48,7 @@
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
@@ -99,7 +99,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_rshift();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_rshift();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_RSHIFT);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_RSHIFT);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
index b9218bbf78..0711269403 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -128,7 +128,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_subtract();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_subtract();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_SUBTRACT);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_SUBTRACT);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
index 731a66d293..f759484415 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -111,7 +111,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_true_divide();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_true_divide();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_TRUE_DIVIDE);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_TRUE_DIVIDE);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
index 71a5de5032..06c67afdf1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
@@ -93,7 +93,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_xor();
TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_xor();
if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_XOR);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_XOR);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
index b428605f03..bcc4a7c448 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,7 +52,7 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -132,7 +132,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
TpSlot slotW = slotsW.nb_add();
if (slotV != null || slotW != null) {
hasNbAddSlot.enter(inliningTarget);
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, BinaryOpSlot.NB_ADD);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_ADD);
if (result != PNotImplemented.NOT_IMPLEMENTED) {
hasNbAddResult.enter(inliningTarget);
return result;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
index 3f8cfe2700..7804fc3b01 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
@@ -776,7 +776,7 @@ public abstract class ErrorMessages {
public static final TruffleString UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P = tsLiteral("unsupported operand type(s) for %s: '%p' and '%p'");
public static final TruffleString UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P_PRINT = cat(UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P,
tsLiteral(". Did you mean \"print(, file=)\"?"));
- public static final TruffleString UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P = tsLiteral("unsupported operand type(s) for %s(): '%p', '%p', '%p'");
+ public static final TruffleString UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P = tsLiteral("unsupported operand type(s) for %s: '%p', '%p', '%p'");
public static final TruffleString UNSUPPORTED_OPERAND_TYPES_FOR_S_PR_S_P_AND_P = tsLiteral("unsupported operand type(s) for %s or %s(): '%p' and '%p'");
public static final TruffleString UNSUPPORTED_SIZE_WAS = tsLiteral("unsupported %s size; was: %d");
public static final TruffleString UNSUPPORTED_STR_TYPE = tsLiteral("unsupported string type: %s");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
index e907bda862..6f5d23cdbc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
@@ -58,6 +58,7 @@
import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyNumberOrNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyNumberRemainderNode;
import com.oracle.graal.python.lib.PyNumberRshiftNode;
import com.oracle.graal.python.lib.PyNumberSubtractNode;
@@ -92,7 +93,7 @@ public enum BinaryArithmetic {
Or(PyNumberOrNode::create),
Xor(PyNumberXorNode::create),
MatMul(PyNumberMatrixMultiplyNode::create),
- Pow(BinaryArithmeticFactory.PowNodeGen::create),
+ Pow(PyNumberPowerNode::create),
DivMod(PyNumberDivmodNode::create);
interface CreateBinaryOp {
@@ -179,18 +180,6 @@ public static LookupAndCallBinaryNode createCallNode(SpecialMethodSlot slot, Sup
}
- public abstract static class PowNode extends BinaryArithmeticNode {
-
- public static final Supplier NOT_IMPLEMENTED = createHandler("** or pow()");
-
- @Specialization
- public static Object doGeneric(VirtualFrame frame, Object left, Object right,
- // TODO: ternary_op is not implemented (GR-<2????>)
- @Cached("createCallNode(Pow, NOT_IMPLEMENTED)") LookupAndCallBinaryNode callNode) {
- return callNode.executeObject(frame, left, right);
- }
- }
-
public abstract static class GenericBinaryArithmeticNode extends BinaryArithmeticNode {
private final SpecialMethodSlot slot;
From 9ae89627b6bd5246915047f1b566cd6e4597e264 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Fri, 24 Jan 2025 18:31:52 +0100
Subject: [PATCH 013/512] Replace PythonObjectFactory with node-less PFactory
---
.../asdl/asdl_java.py | 4 +-
.../asdl/java_file.py | 4 +-
.../graal/python/pegparser/sst/AliasTy.java | 2 +-
.../graal/python/pegparser/sst/ArgTy.java | 2 +-
.../python/pegparser/sst/ArgumentsTy.java | 2 +-
.../graal/python/pegparser/sst/BoolOpTy.java | 2 +-
.../graal/python/pegparser/sst/CmpOpTy.java | 2 +-
.../python/pegparser/sst/ComprehensionTy.java | 2 +-
.../python/pegparser/sst/ExceptHandlerTy.java | 2 +-
.../python/pegparser/sst/ExprContextTy.java | 2 +-
.../graal/python/pegparser/sst/ExprTy.java | 2 +-
.../graal/python/pegparser/sst/KeywordTy.java | 2 +-
.../python/pegparser/sst/MatchCaseTy.java | 2 +-
.../graal/python/pegparser/sst/ModTy.java | 2 +-
.../python/pegparser/sst/OperatorTy.java | 2 +-
.../graal/python/pegparser/sst/PatternTy.java | 2 +-
.../python/pegparser/sst/SSTreeVisitor.java | 2 +-
.../graal/python/pegparser/sst/StmtTy.java | 2 +-
.../python/pegparser/sst/TypeIgnoreTy.java | 2 +-
.../graal/python/pegparser/sst/UnaryOpTy.java | 2 +-
.../python/pegparser/sst/WithItemTy.java | 2 +-
.../builtin/modules/ConversionNodeTests.java | 3 +-
.../modules/DirFdConversionNodeTests.java | 15 +-
.../FileDescriptorConversionNodeTests.java | 15 +-
.../modules/PathConversionNodeTests.java | 29 +-
.../test/builtin/objects/dict/PDictTest.java | 11 +-
.../python/test/datatype/PRangeTests.java | 18 +-
.../util/CastToJavaUnsignedLongNodeTests.java | 11 +-
.../test/runtime/PythonModuleTests.java | 5 +-
.../oracle/graal/python/PythonLanguage.java | 47 +-
.../python/builtins/BoundBuiltinCallable.java | 6 +-
.../graal/python/builtins/Python3Core.java | 31 +-
.../builtins/PythonBuiltinClassType.java | 4 -
.../graal/python/builtins/PythonBuiltins.java | 32 +-
.../builtins/modules/ArrayModuleBuiltins.java | 56 +-
.../modules/AsyncioModuleBuiltins.java | 5 +-
.../modules/BinasciiModuleBuiltins.java | 29 +-
.../builtins/modules/BuiltinConstructors.java | 479 +++--
.../builtins/modules/BuiltinFunctions.java | 56 +-
.../builtins/modules/CmathModuleBuiltins.java | 110 +-
.../modules/CodecsModuleBuiltins.java | 56 +-
.../modules/CodecsTruffleModuleBuiltins.java | 45 +-
.../modules/CollectionsModuleBuiltins.java | 41 +-
.../modules/ContextvarsModuleBuiltins.java | 13 +-
.../builtins/modules/ErrnoModuleBuiltins.java | 5 +-
.../builtins/modules/FcntlModuleBuiltins.java | 13 +-
.../builtins/modules/GcModuleBuiltins.java | 17 +-
.../modules/GraalHPyDebugModuleBuiltins.java | 11 +-
.../GraalHPyUniversalModuleBuiltins.java | 3 +-
.../modules/GraalPythonModuleBuiltins.java | 49 +-
.../builtins/modules/ImpModuleBuiltins.java | 45 +-
.../modules/ItertoolsModuleBuiltins.java | 252 +--
.../modules/LocaleModuleBuiltins.java | 19 +-
.../modules/LsprofModuleBuiltins.java | 42 +-
.../builtins/modules/MMapModuleBuiltins.java | 10 +-
.../modules/MarshalModuleBuiltins.java | 89 +-
.../builtins/modules/MathModuleBuiltins.java | 69 +-
.../builtins/modules/NtModuleBuiltins.java | 11 +-
.../modules/PolyglotModuleBuiltins.java | 8 +-
.../builtins/modules/PosixModuleBuiltins.java | 824 ++++----
.../python/builtins/modules/Profiler.java | 62 +
.../builtins/modules/PwdModuleBuiltins.java | 42 +-
.../builtins/modules/QueueModuleBuiltins.java | 12 +-
.../modules/RandomModuleBuiltins.java | 12 +-
.../modules/ResourceModuleBuiltins.java | 15 +-
.../builtins/modules/SREModuleBuiltins.java | 7 +-
.../builtins/modules/SSLModuleBuiltins.java | 19 +-
.../modules/SelectModuleBuiltins.java | 21 +-
.../modules/SignalModuleBuiltins.java | 21 +-
.../modules/SocketModuleBuiltins.java | 151 +-
.../modules/StringModuleBuiltins.java | 18 +-
.../modules/StructModuleBuiltins.java | 28 +-
.../builtins/modules/SysModuleBuiltins.java | 107 +-
.../modules/ThreadModuleBuiltins.java | 37 +-
.../builtins/modules/TimeModuleBuiltins.java | 19 +-
.../modules/TokenizeModuleBuiltins.java | 14 +-
.../modules/WarningsModuleBuiltins.java | 51 +-
.../modules/WeakRefModuleBuiltins.java | 20 +-
.../modules/WinregModuleBuiltins.java | 9 +-
.../builtins/modules/ast/AstBuiltins.java | 9 +-
.../modules/ast/AstModuleBuiltins.java | 29 +-
.../python/builtins/modules/ast/AstState.java | 2 +-
.../builtins/modules/ast/AstTypeFactory.java | 19 +-
.../python/builtins/modules/ast/Obj2Sst.java | 2 +-
.../builtins/modules/ast/Sst2ObjVisitor.java | 152 +-
.../modules/ast/Sst2ObjVisitorBase.java | 32 +-
.../modules/bz2/BZ2CompressorBuiltins.java | 30 +-
.../modules/bz2/BZ2DecompressorBuiltins.java | 22 +-
.../modules/bz2/BZ2ModuleBuiltins.java | 19 +-
.../modules/cext/PythonCextBuiltins.java | 33 +-
.../modules/cext/PythonCextBytesBuiltins.java | 69 +-
.../cext/PythonCextCapsuleBuiltins.java | 9 +-
.../modules/cext/PythonCextClassBuiltins.java | 14 +-
.../cext/PythonCextComplexBuiltins.java | 9 +-
.../cext/PythonCextContextBuiltins.java | 17 +-
.../modules/cext/PythonCextDescrBuiltins.java | 9 +-
.../modules/cext/PythonCextDictBuiltins.java | 20 +-
.../modules/cext/PythonCextErrBuiltins.java | 16 +-
.../modules/cext/PythonCextFuncBuiltins.java | 16 +-
.../cext/PythonCextGenericAliasBuiltins.java | 11 +-
.../modules/cext/PythonCextIterBuiltins.java | 9 +-
.../modules/cext/PythonCextListBuiltins.java | 13 +-
.../modules/cext/PythonCextLongBuiltins.java | 19 +-
.../cext/PythonCextMethodBuiltins.java | 11 +-
.../cext/PythonCextNamespaceBuiltins.java | 19 +-
.../cext/PythonCextObjectBuiltins.java | 7 +-
.../cext/PythonCextPyStateBuiltins.java | 7 +-
.../cext/PythonCextPyThreadBuiltins.java | 8 +-
.../modules/cext/PythonCextSetBuiltins.java | 29 +-
.../cext/PythonCextStructSeqBuiltins.java | 17 +-
.../cext/PythonCextTracebackBuiltins.java | 12 +-
.../modules/cext/PythonCextTupleBuiltins.java | 9 +-
.../modules/cext/PythonCextTypeBuiltins.java | 21 +-
.../cext/PythonCextUnicodeBuiltins.java | 77 +-
.../cjkcodecs/CodecsCNModuleBuiltins.java | 27 +-
.../cjkcodecs/CodecsHKModuleBuiltins.java | 19 +-
.../CodecsISO2022ModuleBuiltins.java | 27 +-
.../cjkcodecs/CodecsJPModuleBuiltins.java | 49 +-
.../cjkcodecs/CodecsKRModuleBuiltins.java | 23 +-
.../cjkcodecs/CodecsTWModuleBuiltins.java | 19 +-
.../cjkcodecs/MultibyteCodecBuiltins.java | 23 +-
.../modules/cjkcodecs/MultibyteCodecUtil.java | 37 +-
.../cjkcodecs/MultibyteDecodeBuffer.java | 8 +-
.../cjkcodecs/MultibyteEncodeBuffer.java | 9 +-
.../MultibyteIncrementalDecoderBuiltins.java | 22 +-
.../MultibyteIncrementalEncoderBuiltins.java | 28 +-
.../MultibyteStreamReaderBuiltins.java | 10 +-
.../MultibyteStreamWriterBuiltins.java | 29 +-
.../MultibytecodecModuleBuiltins.java | 16 +-
.../builtins/modules/codecs/CharmapNodes.java | 18 +-
.../modules/codecs/ErrorHandlers.java | 77 +-
.../modules/csv/CSVModuleBuiltins.java | 16 +-
.../modules/csv/CSVReaderBuiltins.java | 7 +-
.../modules/ctypes/CArgObjectBuiltins.java | 9 +-
.../modules/ctypes/CDataBuiltins.java | 15 +-
.../modules/ctypes/CDataTypeBuiltins.java | 31 +-
.../ctypes/CDataTypeSequenceBuiltins.java | 11 +-
.../modules/ctypes/CFieldBuiltins.java | 61 +-
.../modules/ctypes/CtypesModuleBuiltins.java | 91 +-
.../builtins/modules/ctypes/CtypesNodes.java | 14 +-
.../ctypes/LazyPyCArrayTypeBuiltins.java | 23 +-
.../ctypes/LazyPyCSimpleTypeBuiltins.java | 49 +-
.../modules/ctypes/PyCArrayBuiltins.java | 21 +-
.../modules/ctypes/PyCArrayTypeBuiltins.java | 10 +-
.../modules/ctypes/PyCFuncPtrBuiltins.java | 15 +-
.../ctypes/PyCFuncPtrTypeBuiltins.java | 11 +-
.../modules/ctypes/PyCPointerBuiltins.java | 21 +-
.../ctypes/PyCPointerTypeBuiltins.java | 17 +-
.../modules/ctypes/PyCSimpleTypeBuiltins.java | 34 +-
.../modules/ctypes/PyCStructTypeBuiltins.java | 13 +-
.../modules/ctypes/StgDictBuiltins.java | 20 +-
.../ctypes/StructUnionTypeBuiltins.java | 25 +-
.../modules/ctypes/UnionTypeBuiltins.java | 17 +-
.../functools/FunctoolsModuleBuiltins.java | 11 +-
.../modules/functools/KeyWrapperBuiltins.java | 7 +-
.../functools/LruCacheWrapperBuiltins.java | 30 +-
.../builtins/modules/functools/PPartial.java | 17 +-
.../modules/functools/PartialBuiltins.java | 61 +-
.../modules/hashlib/DigestObject.java | 15 +-
.../modules/hashlib/DigestObjectBuiltins.java | 12 +-
.../hashlib/HashlibModuleBuiltins.java | 20 +-
.../hashlib/ShakeDigestObjectBuiltins.java | 9 +-
.../io/AbstractBufferedIOBuiltins.java | 29 +-
.../modules/io/BufferedRWPairBuiltins.java | 17 +-
.../modules/io/BufferedRandomBuiltins.java | 14 +-
.../modules/io/BufferedReaderBuiltins.java | 19 +-
.../io/BufferedReaderMixinBuiltins.java | 63 +-
.../modules/io/BufferedWriterBuiltins.java | 19 +-
.../modules/io/BufferedWriterNodes.java | 9 +-
.../builtins/modules/io/BytesIOBuiltins.java | 74 +-
.../builtins/modules/io/FileIOBuiltins.java | 57 +-
.../builtins/modules/io/IOBaseBuiltins.java | 13 +-
.../builtins/modules/io/IOModuleBuiltins.java | 87 +-
.../python/builtins/modules/io/IONodes.java | 37 +-
.../io/IncrementalNewlineDecoderBuiltins.java | 30 +-
.../python/builtins/modules/io/PBytesIO.java | 15 +-
.../modules/io/RawIOBaseBuiltins.java | 20 +-
.../builtins/modules/io/StringIOBuiltins.java | 14 +-
.../modules/io/TextIOWrapperBuiltins.java | 16 +-
.../modules/io/TextIOWrapperNodes.java | 24 +-
.../modules/json/JSONEncoderBuiltins.java | 11 +-
.../modules/json/JSONModuleBuiltins.java | 16 +-
.../modules/json/JSONScannerBuiltins.java | 34 +-
.../modules/lzma/LZMACompressorBuiltins.java | 17 +-
.../lzma/LZMADecompressorBuiltins.java | 21 +-
.../modules/lzma/LZMAModuleBuiltins.java | 29 +-
.../GraalPySemLockBuiltins.java | 9 +-
.../MultiprocessingGraalPyModuleBuiltins.java | 42 +-
.../MultiprocessingModuleBuiltins.java | 11 +-
.../multiprocessing/SemLockBuiltins.java | 11 +-
.../python/builtins/modules/pickle/PData.java | 13 +-
.../builtins/modules/pickle/PPickler.java | 28 +-
.../builtins/modules/pickle/PUnpickler.java | 26 +-
.../modules/pickle/PickleBufferBuiltins.java | 9 +-
.../modules/pickle/PickleModuleBuiltins.java | 52 +-
.../builtins/modules/pickle/PickleUtils.java | 9 +-
.../modules/pickle/PicklerBuiltins.java | 13 +-
.../pickle/PicklerMemoProxyBuiltins.java | 28 +-
.../builtins/modules/pickle/PicklerNodes.java | 31 +-
.../modules/pickle/UnpicklerBuiltins.java | 13 +-
.../pickle/UnpicklerMemoProxyBuiltins.java | 17 +-
.../builtins/modules/zlib/ZLibCompObject.java | 17 +-
.../modules/zlib/ZLibModuleBuiltins.java | 50 +-
.../modules/zlib/ZlibCompressBuiltins.java | 60 +-
.../modules/zlib/ZlibDecompressBuiltins.java | 83 +-
.../builtins/modules/zlib/ZlibNodes.java | 33 +-
.../objects/PythonAbstractObject.java | 5 +-
.../builtins/objects/array/ArrayBuiltins.java | 45 +-
.../python/builtins/objects/array/PArray.java | 6 +-
.../asyncio/AsyncGeneratorBuiltins.java | 28 +-
.../objects/bytes/ByteArrayBuiltins.java | 76 +-
.../builtins/objects/bytes/BytesBuiltins.java | 44 +-
.../objects/bytes/BytesCommonBuiltins.java | 180 +-
.../builtins/objects/bytes/BytesNodes.java | 33 +-
.../cext/capi/CApiMemberAccessNodes.java | 12 +-
.../builtins/objects/cext/capi/CExtNodes.java | 58 +-
.../cext/capi/ExternalFunctionNodes.java | 110 +-
.../objects/cext/capi/PThreadState.java | 5 +-
.../cext/capi/PyDateTimeCAPIWrapper.java | 5 +-
.../objects/cext/capi/ToNativeTypeNode.java | 9 +-
.../objects/cext/capi/UnicodeObjectNodes.java | 7 +-
.../capi/transitions/CApiTransitions.java | 6 +-
.../transitions/GetNativeWrapperNode.java | 7 +-
.../objects/cext/common/CExtCommonNodes.java | 32 +-
.../objects/cext/common/CExtContext.java | 7 +-
.../objects/cext/hpy/GraalHPyContext.java | 3 +-
.../cext/hpy/GraalHPyContextFunctions.java | 132 +-
.../cext/hpy/GraalHPyMemberAccessNodes.java | 12 +-
.../cext/hpy/GraalHPyNativeContext.java | 8 +-
.../objects/cext/hpy/GraalHPyNodes.java | 67 +-
.../cext/hpy/GraalHPyObjectBuiltins.java | 6 +-
.../cext/hpy/HPyExternalFunctionNodes.java | 48 +-
.../cext/hpy/jni/GraalHPyJNIContext.java | 23 +-
.../builtins/objects/code/CodeBuiltins.java | 82 +-
.../builtins/objects/code/CodeNodes.java | 20 +-
.../python/builtins/objects/code/PCode.java | 71 +-
.../objects/common/BufferStorageNodes.java | 16 +-
.../objects/common/KeywordsStorage.java | 4 +-
.../objects/common/SequenceStorageNodes.java | 26 +-
.../objects/complex/ComplexBuiltins.java | 81 +-
.../objects/contextvars/ContextBuiltins.java | 23 +-
.../contextvars/ContextIteratorBuiltins.java | 8 +-
.../contextvars/ContextVarBuiltins.java | 15 +-
.../objects/contextvars/PContextIterator.java | 13 +-
.../objects/contextvars/TokenBuiltins.java | 11 +-
.../builtins/objects/deque/DequeBuiltins.java | 36 +-
.../objects/deque/DequeIterBuiltins.java | 9 +-
.../objects/dict/DefaultDictBuiltins.java | 15 +-
.../builtins/objects/dict/DictBuiltins.java | 57 +-
.../objects/dict/DictValuesBuiltins.java | 17 +-
.../objects/dict/DictViewBuiltins.java | 67 +-
.../objects/enumerate/EnumerateBuiltins.java | 25 +-
.../objects/enumerate/PEnumerate.java | 9 +-
.../exception/BaseExceptionAttrNode.java | 14 +-
.../exception/BaseExceptionBuiltins.java | 34 +-
.../exception/BaseExceptionGroupBuiltins.java | 27 +-
.../objects/exception/ExceptionNodes.java | 19 +-
.../exception/ImportErrorBuiltins.java | 21 +-
.../objects/exception/OsErrorBuiltins.java | 23 +-
.../exception/PrepareExceptionNode.java | 7 +-
.../exception/StopIterationBuiltins.java | 6 +-
.../exception/SyntaxErrorBuiltins.java | 4 +-
.../objects/exception/SystemExitBuiltins.java | 14 +-
.../exception/UnicodeErrorBuiltins.java | 15 +-
.../objects/floats/FloatBuiltins.java | 37 +-
.../foreign/ForeignAbstractClassBuiltins.java | 19 +-
.../foreign/ForeignNumberBuiltins.java | 15 +-
.../foreign/ForeignObjectBuiltins.java | 9 +-
.../builtins/objects/frame/FrameBuiltins.java | 12 +-
.../function/AbstractFunctionBuiltins.java | 15 +-
.../function/BuiltinFunctionBuiltins.java | 13 +-
.../objects/function/FunctionBuiltins.java | 17 +-
.../function/MethodDescriptorBuiltins.java | 19 +-
.../objects/function/PBuiltinFunction.java | 9 +-
.../function/WrapperDescriptorBuiltins.java | 15 +-
.../generator/CommonGeneratorBuiltins.java | 12 +-
.../objects/generator/CoroutineBuiltins.java | 14 +-
.../objects/generator/GeneratorBuiltins.java | 19 +-
.../objects/generator/PGenerator.java | 8 +-
.../getsetdescriptor/GetSetDescriptor.java | 8 +-
.../MemberDescriptorBuiltins.java | 9 +-
.../builtins/objects/ints/IntBuiltins.java | 303 ++-
.../builtins/objects/ints/IntNodes.java | 8 +-
.../python/builtins/objects/ints/PInt.java | 13 +-
.../objects/iterator/IteratorBuiltins.java | 126 +-
.../objects/iterator/PBigRangeIterator.java | 9 +-
.../objects/iterator/PZipBuiltins.java | 17 +-
.../iterator/SentinelIteratorBuiltins.java | 11 +-
.../objects/itertools/AccumulateBuiltins.java | 37 +-
.../objects/itertools/ChainBuiltins.java | 28 +-
.../itertools/CombinationsBuiltins.java | 35 +-
.../objects/itertools/CompressBuiltins.java | 9 +-
.../objects/itertools/CountBuiltins.java | 13 +-
.../objects/itertools/CycleBuiltins.java | 31 +-
.../objects/itertools/DropwhileBuiltins.java | 9 +-
.../itertools/FilterfalseBuiltins.java | 9 +-
.../objects/itertools/GroupByBuiltins.java | 21 +-
.../objects/itertools/GrouperBuiltins.java | 16 +-
.../objects/itertools/IsliceBuiltins.java | 18 +-
.../objects/itertools/PTeeDataObject.java | 9 +-
.../objects/itertools/PairwiseBuiltins.java | 9 +-
.../itertools/PermutationsBuiltins.java | 31 +-
.../objects/itertools/ProductBuiltins.java | 34 +-
.../objects/itertools/RepeatBuiltins.java | 11 +-
.../objects/itertools/StarmapBuiltins.java | 11 +-
.../objects/itertools/TakewhileBuiltins.java | 13 +-
.../objects/itertools/TeeBuiltins.java | 30 +-
.../itertools/TeeDataObjectBuiltins.java | 17 +-
.../objects/itertools/ZipLongestBuiltins.java | 20 +-
.../builtins/objects/list/ListBuiltins.java | 48 +-
.../builtins/objects/map/MapBuiltins.java | 10 +-
.../mappingproxy/MappingproxyBuiltins.java | 7 +-
.../memoryview/MemoryViewBuiltins.java | 61 +-
.../method/AbstractMethodBuiltins.java | 14 +-
.../objects/method/ClassmethodBuiltins.java | 21 +-
.../method/InstancemethodBuiltins.java | 10 +-
.../objects/method/MethodBuiltins.java | 15 +-
.../objects/method/PDecoratedMethod.java | 11 +-
.../builtins/objects/mmap/MMapBuiltins.java | 102 +-
.../objects/module/ModuleBuiltins.java | 18 +-
.../builtins/objects/module/PythonModule.java | 10 +-
.../namespace/SimpleNamespaceBuiltins.java | 13 +-
.../objects/object/ObjectBuiltins.java | 7 +-
.../builtins/objects/object/ObjectNodes.java | 26 +-
.../ordereddict/OrderedDictBuiltins.java | 33 +-
.../ordereddict/OrderedDictItemsBuiltins.java | 15 +-
.../OrderedDictIteratorBuiltins.java | 18 +-
.../ordereddict/OrderedDictKeysBuiltins.java | 15 +-
.../OrderedDictValuesBuiltins.java | 15 +-
.../objects/posix/DirEntryBuiltins.java | 50 +-
.../posix/ScandirIteratorBuiltins.java | 8 +-
.../objects/property/PropertyBuiltins.java | 5 +-
.../objects/queue/SimpleQueueBuiltins.java | 9 +-
.../objects/random/RandomBuiltins.java | 11 +-
.../builtins/objects/range/RangeBuiltins.java | 72 +-
.../builtins/objects/range/RangeNodes.java | 12 +-
.../referencetype/ReferenceTypeBuiltins.java | 9 +-
.../objects/reversed/ReversedBuiltins.java | 29 +-
.../builtins/objects/set/BaseSetBuiltins.java | 32 +-
.../objects/set/FrozenSetBuiltins.java | 68 +-
.../builtins/objects/set/SetBuiltins.java | 61 +-
.../python/builtins/objects/set/SetNodes.java | 49 +-
.../builtins/objects/slice/PObjectSlice.java | 11 +-
.../builtins/objects/slice/SliceBuiltins.java | 39 +-
.../builtins/objects/slice/SliceNodes.java | 37 +-
.../objects/socket/SocketBuiltins.java | 171 +-
.../builtins/objects/socket/SocketNodes.java | 13 +-
.../builtins/objects/ssl/CertUtils.java | 65 +-
.../objects/ssl/MemoryBIOBuiltins.java | 15 +-
.../objects/ssl/SSLContextBuiltins.java | 53 +-
.../objects/ssl/SSLErrorBuiltins.java | 10 +-
.../objects/ssl/SSLSocketBuiltins.java | 33 +-
.../builtins/objects/str/StringBuiltins.java | 68 +-
.../builtins/objects/str/StringNodes.java | 11 +-
.../builtins/objects/str/StringUtils.java | 40 +-
.../objects/struct/StructBuiltins.java | 25 +-
.../builtins/objects/struct/StructNodes.java | 33 +-
.../struct/StructUnpackIteratorBuiltins.java | 11 +-
.../objects/superobject/SuperBuiltins.java | 11 +-
.../objects/thread/RLockBuiltins.java | 9 +-
.../objects/thread/ThreadLocalNodes.java | 11 +-
.../tokenize/TokenizerIterBuiltins.java | 9 +-
.../MaterializeLazyTracebackNode.java | 8 +-
.../objects/traceback/TracebackBuiltins.java | 14 +-
.../objects/tuple/StructSequence.java | 55 +-
.../builtins/objects/tuple/TupleBuiltins.java | 48 +-
.../objects/tuple/TupleGetterBuiltins.java | 11 +-
.../objects/type/PythonManagedClass.java | 6 +-
.../python/builtins/objects/type/TpSlots.java | 6 +-
.../builtins/objects/type/TypeBuiltins.java | 65 +-
.../builtins/objects/type/TypeNodes.java | 55 +-
.../builtins/objects/type/slots/TpSlot.java | 5 +-
.../objects/types/GenericAliasBuiltins.java | 37 +-
.../types/GenericAliasIteratorBuiltins.java | 15 +-
.../objects/types/GenericTypeNodes.java | 19 +-
.../objects/types/UnionTypeBuiltins.java | 23 +-
.../graal/python/compiler/Compiler.java | 5 +-
.../RaisePythonExceptionErrorCallback.java | 7 +-
.../python/lib/PyContextCopyCurrent.java | 8 +-
.../oracle/graal/python/lib/PyDictKeys.java | 10 +-
.../graal/python/lib/PyImportImport.java | 12 +-
.../graal/python/lib/PyIterNextNode.java | 11 +-
.../oracle/graal/python/lib/PyLongCopy.java | 9 +-
.../python/lib/PyLongFromDoubleNode.java | 10 +-
.../python/lib/PyLongFromUnicodeObject.java | 11 +-
.../python/lib/PyMemoryViewFromObject.java | 18 +-
.../graal/python/lib/PyNumberAddNode.java | 19 +-
.../graal/python/lib/PyObjectGetItem.java | 6 +-
.../graal/python/lib/PyObjectGetIter.java | 15 +-
.../graal/python/lib/PySequenceConcat.java | 17 +-
.../oracle/graal/python/lib/PySliceNew.java | 31 +-
.../python/lib/PyTraceBackPrintNode.java | 17 +-
.../python/lib/PyUnicodeAsEncodedString.java | 7 +-
.../lib/PyUnicodeFromEncodedObject.java | 10 +-
.../oracle/graal/python/nodes/PRaiseNode.java | 25 +-
.../python/nodes/WriteUnraisableNode.java | 10 +-
.../nodes/argument/ReadVarArgsNode.java | 13 +-
.../nodes/argument/ReadVarKeywordsNode.java | 12 +-
.../capsule/CreateArrowPyCapsuleNode.java | 9 +-
.../python/nodes/builtins/ListNodes.java | 69 +-
.../python/nodes/builtins/TupleNodes.java | 46 +-
.../bytecode/CopyDictWithoutKeysNode.java | 11 +-
.../nodes/bytecode/MakeFunctionNode.java | 14 +-
.../python/nodes/bytecode/MatchClassNode.java | 11 +-
.../python/nodes/bytecode/MatchKeysNode.java | 17 +-
.../PBytecodeGeneratorFunctionRootNode.java | 14 +-
.../nodes/bytecode/PBytecodeRootNode.java | 83 +-
.../nodes/bytecode/SetupAnnotationsNode.java | 24 +-
.../python/nodes/bytecode/UnpackExNode.java | 14 +-
.../exception/TopLevelExceptionHandler.java | 11 +-
.../expression/CastToListExpressionNode.java | 11 +-
.../nodes/frame/GetFrameLocalsNode.java | 11 +-
.../nodes/frame/MaterializeFrameNode.java | 26 +-
.../builtins/PythonVarargsBuiltinNode.java | 16 +-
.../python/nodes/object/DeleteDictNode.java | 10 +-
.../nodes/object/GetDictIfExistsNode.java | 12 +-
.../object/GetForeignObjectClassNode.java | 3 +-
.../nodes/object/GetOrCreateDictNode.java | 10 +-
.../nodes/object/GetRegisteredClassNode.java | 3 +-
.../nodes/statement/AbstractImportNode.java | 10 +-
.../nodes/util/CoerceToComplexNode.java | 19 +-
.../nodes/util/NarrowBigIntegerNode.java | 10 +-
.../graal/python/runtime/PythonContext.java | 33 +-
.../runtime/exception/ExceptionUtils.java | 14 +-
.../formatting/BytesFormatProcessor.java | 6 +-
.../runtime/formatting/FormatProcessor.java | 4 +-
.../graal/python/runtime/object/IDUtils.java | 15 +-
.../graal/python/runtime/object/PFactory.java | 1695 ++++++++++++++++
.../runtime/object/PythonObjectFactory.java | 1739 -----------------
.../object/PythonObjectSlowPathFactory.java | 97 -
.../oracle/graal/python/util/PythonUtils.java | 36 +-
mx.graalpython/copyrights/overrides | 2 +-
432 files changed, 7806 insertions(+), 7905 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/Profiler.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectSlowPathFactory.java
diff --git a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
index 77b684f9d4..465666c897 100755
--- a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
+++ b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -285,7 +285,7 @@ def visit_abstract_class(self, c: model.AbstractClass, emitter: java_file.Emitte
def visit_concrete_class(self, c: model.ConcreteClass, emitter: java_file.Emitter):
with emitter.define(f'public Object visit({c.full_name} node)', '@Override'):
- emitter.println(f'PythonObject o = factory.createPythonObject(state.{c.name.cls_field});')
+ emitter.println(f'PythonObject o = createPythonObject(state.{c.name.cls_field});')
for f in c.fields:
self.visit(f, emitter)
if c.outer_has_attributes or c.attributes:
diff --git a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/java_file.py b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/java_file.py
index 8119ee2fa9..8c37571e8b 100644
--- a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/java_file.py
+++ b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/java_file.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -42,7 +42,7 @@
from typing import Optional
HEADER = """/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/AliasTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/AliasTy.java
index cfd2343286..a492e85003 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/AliasTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/AliasTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgTy.java
index 0ace1cb17e..07c350cef1 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgumentsTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgumentsTy.java
index 1d783c4a0f..f73083ec50 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgumentsTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ArgumentsTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/BoolOpTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/BoolOpTy.java
index 0717d0a435..e62e44bcb0 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/BoolOpTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/BoolOpTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/CmpOpTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/CmpOpTy.java
index 1b881e99a0..2f154eb844 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/CmpOpTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/CmpOpTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ComprehensionTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ComprehensionTy.java
index 4beed845a8..f42a5e1427 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ComprehensionTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ComprehensionTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExceptHandlerTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExceptHandlerTy.java
index 9efab27d5d..6c0aa13c2f 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExceptHandlerTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExceptHandlerTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprContextTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprContextTy.java
index a4b09cfdfb..e6f4f850b1 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprContextTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprContextTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprTy.java
index 4612ccb74c..1fb5d88c9d 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ExprTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/KeywordTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/KeywordTy.java
index ef64367a15..32aeca4faf 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/KeywordTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/KeywordTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/MatchCaseTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/MatchCaseTy.java
index 1a883ad89d..f7f80b4fd7 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/MatchCaseTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/MatchCaseTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ModTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ModTy.java
index a0bd22ed37..6ea70dcabe 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ModTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/ModTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/OperatorTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/OperatorTy.java
index 43d5c410fa..15222bba8b 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/OperatorTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/OperatorTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/PatternTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/PatternTy.java
index 1dcbb13df8..4b6ff77335 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/PatternTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/PatternTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/SSTreeVisitor.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/SSTreeVisitor.java
index 8b22fd364b..9a48161b32 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/SSTreeVisitor.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/SSTreeVisitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StmtTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StmtTy.java
index 02b3cdcf05..ac67e6076c 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StmtTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StmtTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/TypeIgnoreTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/TypeIgnoreTy.java
index a66076b4ac..c5952df203 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/TypeIgnoreTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/TypeIgnoreTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/UnaryOpTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/UnaryOpTy.java
index b3805a57b9..03b2e2d6a6 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/UnaryOpTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/UnaryOpTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/WithItemTy.java b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/WithItemTy.java
index 69665b12cb..7a102ea40f 100644
--- a/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/WithItemTy.java
+++ b/graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/WithItemTy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/ConversionNodeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/ConversionNodeTests.java
index a8efa356d8..f8f223d639 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/ConversionNodeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/ConversionNodeTests.java
@@ -57,6 +57,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -96,7 +97,7 @@ public boolean isPythonInternal() {
}.getCallTarget();
try {
Object[] arguments = PArguments.create(1);
- PArguments.setGlobals(arguments, pythonContext.factory().createDict());
+ PArguments.setGlobals(arguments, PFactory.createDict(language));
PArguments.setException(arguments, PException.NO_EXCEPTION);
PArguments.setArgument(arguments, 0, arg);
PythonThreadState threadState = pythonContext.getThreadState(language);
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/DirFdConversionNodeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/DirFdConversionNodeTests.java
index c50c407a1d..df5386d0be 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/DirFdConversionNodeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/DirFdConversionNodeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,10 +52,11 @@
import org.junit.Before;
import org.junit.Test;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
public class DirFdConversionNodeTests extends ConversionNodeTests {
@@ -108,20 +109,20 @@ public void longTooSmall() {
@Test
public void pintFitsInt() {
- Assert.assertEquals(42, call(factory().createInt(BigInteger.valueOf(42))));
+ Assert.assertEquals(42, call(PFactory.createInt(PythonLanguage.get(null), BigInteger.valueOf(42))));
}
@Test
public void pintTooBig() {
expectPythonMessage("OverflowError: fd is greater than maximum", () -> {
- call(factory().createInt(BigInteger.ONE.shiftLeft(100)));
+ call(PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100)));
});
}
@Test
public void pintTooSmall() {
expectPythonMessage("OverflowError: fd is less than minimum", () -> {
- call(factory().createInt(BigInteger.ONE.shiftLeft(100).negate()));
+ call(PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100).negate()));
});
}
@@ -162,10 +163,6 @@ protected static int call(Object arg) {
return (int) result;
}
- private static PythonObjectFactory factory() {
- return PythonObjectFactory.getUncached();
- }
-
private static Object evalValue(String source) {
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
}
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/FileDescriptorConversionNodeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/FileDescriptorConversionNodeTests.java
index fcd75590d8..eeac46c197 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/FileDescriptorConversionNodeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/FileDescriptorConversionNodeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,10 +52,11 @@
import org.junit.Before;
import org.junit.Test;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
public class FileDescriptorConversionNodeTests extends ConversionNodeTests {
@@ -110,20 +111,20 @@ public void longTooSmall() {
@Test
public void pintFitsInt() {
- Assert.assertEquals(42, call(factory().createInt(BigInteger.valueOf(42))));
+ Assert.assertEquals(42, call(PFactory.createInt(PythonLanguage.get(null), BigInteger.valueOf(42))));
}
@Test
public void pintTooBig() {
expectPythonMessage("OverflowError: Python int too large to convert to Java int", () -> {
- call(factory().createInt(BigInteger.ONE.shiftLeft(100)));
+ call(PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100)));
});
}
@Test
public void pintTooSmall() {
expectPythonMessage("OverflowError: Python int too large to convert to Java int", () -> {
- call(factory().createInt(BigInteger.ONE.shiftLeft(100).negate()));
+ call(PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100).negate()));
});
}
@@ -166,10 +167,6 @@ protected static int call(Object arg) {
return (int) result;
}
- private static PythonObjectFactory factory() {
- return PythonObjectFactory.getUncached();
- }
-
private static Object evalValue(String source) {
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
}
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/PathConversionNodeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/PathConversionNodeTests.java
index 4e11a6859f..e42ef940fd 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/PathConversionNodeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/PathConversionNodeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,6 +59,7 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixFd;
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixPath;
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory;
@@ -67,7 +68,7 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.runtime.PosixSupportLibrary.Buffer;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
import com.oracle.graal.python.util.Function;
import com.oracle.truffle.api.strings.TruffleString;
@@ -123,7 +124,7 @@ public void noValueForbiddenWithoutFd() {
@Test
public void string() {
Assert.assertEquals("abc", callAndExpectPath(false, false, T_ABC, false));
- Assert.assertEquals("abc", callAndExpectPath(false, false, factory().createString(T_ABC), false));
+ Assert.assertEquals("abc", callAndExpectPath(false, false, PFactory.createString(PythonLanguage.get(null), T_ABC), false));
}
@Test
@@ -135,16 +136,16 @@ public void stringWithZero() {
@Test
public void bytes() {
- Assert.assertEquals("abc", callAndExpectPath(false, false, factory().createBytes("abc".getBytes()), true));
- Assert.assertEquals("abc", callAndExpectPath(false, true, factory().createBytes("abc".getBytes()), true));
- Assert.assertEquals("abc", callAndExpectPath(true, false, factory().createBytes("abc".getBytes()), true));
- Assert.assertEquals("abc", callAndExpectPath(true, true, factory().createBytes("abc".getBytes()), true));
+ Assert.assertEquals("abc", callAndExpectPath(false, false, PFactory.createBytes(PythonLanguage.get(null), "abc".getBytes()), true));
+ Assert.assertEquals("abc", callAndExpectPath(false, true, PFactory.createBytes(PythonLanguage.get(null), "abc".getBytes()), true));
+ Assert.assertEquals("abc", callAndExpectPath(true, false, PFactory.createBytes(PythonLanguage.get(null), "abc".getBytes()), true));
+ Assert.assertEquals("abc", callAndExpectPath(true, true, PFactory.createBytes(PythonLanguage.get(null), "abc".getBytes()), true));
}
@Test
public void bytesWithZero() {
expectPythonMessage("ValueError: fun: embedded null character in arg", () -> {
- call(false, false, factory().createBytes("a\0c".getBytes()));
+ call(false, false, PFactory.createBytes(PythonLanguage.get(null), "a\0c".getBytes()));
});
}
@@ -221,27 +222,27 @@ public void longForbidden() {
@Test
public void pintFitsInt() {
- Assert.assertEquals(42, callAndExpectFd(factory().createInt(BigInteger.valueOf(42))));
+ Assert.assertEquals(42, callAndExpectFd(PFactory.createInt(PythonLanguage.get(null), BigInteger.valueOf(42))));
}
@Test
public void pintTooBig() {
expectPythonMessage("OverflowError: fd is greater than maximum", () -> {
- call(false, true, factory().createInt(BigInteger.ONE.shiftLeft(100)));
+ call(false, true, PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100)));
});
}
@Test
public void pintTooSmall() {
expectPythonMessage("OverflowError: fd is less than minimum", () -> {
- call(false, true, factory().createInt(BigInteger.ONE.shiftLeft(100).negate()));
+ call(false, true, PFactory.createInt(PythonLanguage.get(null), BigInteger.ONE.shiftLeft(100).negate()));
});
}
@Test
public void pintForbidden() {
expectPythonMessage("TypeError: fun: arg should be string, bytes, os.PathLike or None, not int", () -> {
- call(true, false, factory().createInt(BigInteger.valueOf(42)));
+ call(true, false, PFactory.createInt(PythonLanguage.get(null), BigInteger.valueOf(42)));
});
}
@@ -386,10 +387,6 @@ protected static Object call(boolean nullable, boolean allowFd, Object arg) {
return call(arg, PosixModuleBuiltinsFactory.PathConversionNodeGen.create("fun", "arg", nullable, allowFd));
}
- private static PythonObjectFactory factory() {
- return PythonObjectFactory.getUncached();
- }
-
private static Object evalValue(String source) {
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
}
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/objects/dict/PDictTest.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/objects/dict/PDictTest.java
index 7219973429..30450f9d61 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/objects/dict/PDictTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/objects/dict/PDictTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,11 +48,12 @@
import org.junit.Before;
import org.junit.Test;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageDelItem;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
import com.oracle.graal.python.builtins.objects.dict.PDict;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
import com.oracle.truffle.api.strings.TruffleString;
@@ -82,7 +83,7 @@ static int length(PDict dict) {
@Test
public void economicMapStorageTransition() {
- PDict dict = PythonObjectFactory.getUncached().createDict();
+ PDict dict = PFactory.createDict(PythonLanguage.get(null));
dict.setItem(ts("key1"), 42);
dict.setItem(11, ts("abc"));
assertTrue(dict.getDictStorage() instanceof EconomicMapStorage);
@@ -91,7 +92,7 @@ public void economicMapStorageTransition() {
@Test
public void economicMapStorageSet() {
- PDict dict = PythonObjectFactory.getUncached().createDict();
+ PDict dict = PFactory.createDict(PythonLanguage.get(null));
dict.setItem(11, ts("abc"));
assertTrue(dict.getDictStorage() instanceof EconomicMapStorage);
@@ -103,7 +104,7 @@ public void economicMapStorageSet() {
@Test
public void economicMapStorageDel() {
- PDict dict = PythonObjectFactory.getUncached().createDict();
+ PDict dict = PFactory.createDict(PythonLanguage.get(null));
dict.setItem(11, ts("abc"));
dict.setItem(ts("key1"), 42);
dict.setItem(ts("key2"), 24);
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java
index 29ef1d1168..d8448fe7aa 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -37,7 +37,7 @@
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@@ -64,10 +64,10 @@ public void doInsert(Node child) {
public void loopWithOnlyStop() throws UnexpectedResultException {
PythonTests.enterContext();
try {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- PRange range = factory.createIntRange(10);
+ PythonLanguage language = PythonLanguage.get(null);
+ PRange range = PFactory.createIntRange(language, 10);
int index = 0;
- TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
+ TestRoot testRoot = new TestRoot(language);
Object iter = PyObjectGetIter.executeUncached(range);
GetNextNode next = GetNextNode.create();
testRoot.doInsert(next);
@@ -92,10 +92,10 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
public void loopWithStep() throws UnexpectedResultException {
PythonTests.enterContext();
try {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- PRange range = PythonObjectFactory.getUncached().createIntRange(0, 10, 2, 5);
+ PythonLanguage language = PythonLanguage.get(null);
+ PRange range = PFactory.createIntRange(language, 0, 10, 2, 5);
int index = 0;
- TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
+ TestRoot testRoot = new TestRoot(language);
Object iter = PyObjectGetIter.executeUncached(range);
GetNextNode next = GetNextNode.create();
testRoot.doInsert(next);
@@ -120,7 +120,7 @@ public void loopWithStep() throws UnexpectedResultException {
public void getItem() {
PythonTests.enterContext();
try {
- PIntRange range = PythonObjectFactory.getUncached().createIntRange(10);
+ PIntRange range = PFactory.createIntRange(PythonLanguage.get(null), 10);
assertEquals(3, range.getIntItemNormalized(3));
} finally {
PythonTests.closeContext();
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/nodes/util/CastToJavaUnsignedLongNodeTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/nodes/util/CastToJavaUnsignedLongNodeTests.java
index 97524bb859..7be63c54d2 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/nodes/util/CastToJavaUnsignedLongNodeTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/nodes/util/CastToJavaUnsignedLongNodeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,17 +50,16 @@
import org.junit.Before;
import org.junit.Test;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
public class CastToJavaUnsignedLongNodeTests {
- private static PythonObjectFactory factory = PythonObjectFactory.getUncached();
-
@Before
public void setUp() {
PythonTests.enterContext();
@@ -127,11 +126,11 @@ public void nonInteger() {
}
private static PInt makePInt(long l) {
- return factory.createInt(BigInteger.valueOf(l));
+ return PFactory.createInt(PythonLanguage.get(null), BigInteger.valueOf(l));
}
private static PInt makePInt(String hexString) {
- return factory.createInt(new BigInteger(hexString, 16));
+ return PFactory.createInt(PythonLanguage.get(null), new BigInteger(hexString, 16));
}
private static void expect(PythonBuiltinClassType errorType, Runnable test) {
diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/PythonModuleTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/PythonModuleTests.java
index d702d04fbf..ead733eca1 100644
--- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/PythonModuleTests.java
+++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/PythonModuleTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2022, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -47,6 +47,7 @@
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.test.PythonTests;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
@@ -91,7 +92,7 @@ public void tearDown() {
@Test
public void pythonModuleTest() {
- PythonModule module = context.factory().createPythonModule(tsLiteral("testModule"));
+ PythonModule module = PFactory.createPythonModule(context.getLanguage(), tsLiteral("testModule"));
assertEquals("testModule", module.getAttribute(T___NAME__).toString());
assertEquals("None", module.getAttribute(T___DOC__).toString());
assertEquals("None", module.getAttribute(T___PACKAGE__).toString());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
index db34ae3f50..c48c51e79d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
@@ -107,7 +107,7 @@
import com.oracle.graal.python.runtime.PythonImageBuildOptions;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.Function;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.Supplier;
@@ -127,6 +127,7 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Idempotent;
import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.instrumentation.AllocationReporter;
import com.oracle.truffle.api.instrumentation.ProvidedTags;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -440,6 +441,7 @@ private DescriptorCallTargets getOrCreateStructSeqNonBuiltinTargets(Descriptor d
@CompilationFinal(dimensions = 1) private volatile Object[] engineOptionsStorage;
@CompilationFinal private volatile OptionValues engineOptions;
+ @CompilationFinal private AllocationReporter allocationReporter;
/** For fast access to the PythonThreadState object by the owning thread. */
private final ContextThreadLocal threadState = locals.createContextThreadLocal(PythonContext.PythonThreadState::new);
@@ -521,6 +523,12 @@ protected PythonContext createContext(Env env) {
assert areOptionsCompatible(options, PythonOptions.createEngineOptions(env)) : "invalid engine options";
}
+ if (allocationReporter == null) {
+ allocationReporter = env.lookup(AllocationReporter.class);
+ } else {
+ assert allocationReporter == env.lookup(AllocationReporter.class);
+ }
+
return context;
}
@@ -534,6 +542,11 @@ public T getEngineOption(OptionKey key) {
}
}
+ public AllocationReporter getAllocationReporter() {
+ assert allocationReporter != null;
+ return allocationReporter;
+ }
+
@Override
protected OptionDescriptors getOptionDescriptors() {
return PythonOptions.DESCRIPTORS;
@@ -593,7 +606,7 @@ protected CallTarget parse(ParsingRequest request) {
}
if (MIME_TYPE_BYTECODE.equals(source.getMimeType())) {
byte[] bytes = source.getBytes().toByteArray();
- CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(bytes);
+ CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(context, bytes);
boolean internal = shouldMarkSourceInternal(context);
// The original file path should be passed as the name
String name = source.getName();
@@ -804,8 +817,8 @@ public Object execute(VirtualFrame frame) {
@Override
protected Object getLanguageView(PythonContext context, Object value) {
assert !(value instanceof PythonAbstractObject);
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
InteropLibrary interopLib = InteropLibrary.getFactory().getUncached(value);
+ PythonLanguage language = context.getLanguage();
try {
if (interopLib.isBoolean(value)) {
if (interopLib.asBoolean(value)) {
@@ -814,21 +827,21 @@ protected Object getLanguageView(PythonContext context, Object value) {
return context.getFalse();
}
} else if (interopLib.isString(value)) {
- return factory.createString(interopLib.asTruffleString(value).switchEncodingUncached(TS_ENCODING));
+ return PFactory.createString(language, interopLib.asTruffleString(value).switchEncodingUncached(TS_ENCODING));
} else if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
// TODO: (tfel) once the interop protocol allows us to
// distinguish fixed point from floating point reliably, we can
// remove this branch
- return factory.createInt(interopLib.asLong(value));
+ return PFactory.createInt(language, interopLib.asLong(value));
} else if (value instanceof Float || value instanceof Double) {
// TODO: (tfel) once the interop protocol allows us to
// distinguish fixed point from floating point reliably, we can
// remove this branch
- return factory.createFloat(interopLib.asDouble(value));
+ return PFactory.createFloat(language, interopLib.asDouble(value));
} else if (interopLib.fitsInLong(value)) {
- return factory.createInt(interopLib.asLong(value));
+ return PFactory.createInt(language, interopLib.asLong(value));
} else if (interopLib.fitsInDouble(value)) {
- return factory.createFloat(interopLib.asDouble(value));
+ return PFactory.createFloat(language, interopLib.asDouble(value));
} else {
return new ForeignLanguageView(value);
}
@@ -1054,13 +1067,19 @@ public Shape getBuiltinTypeInstanceShape(PythonBuiltinClassType type) {
Shape shape = builtinTypeInstanceShapes[ordinal];
if (shape == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- Shape.DerivedBuilder shapeBuilder = Shape.newBuilder(getEmptyShape()).addConstantProperty(HiddenAttr.getClassHiddenKey(), type, 0);
- if (!type.isBuiltinWithDict()) {
- shapeBuilder.shapeFlags(PythonObject.HAS_SLOTS_BUT_NO_DICT_FLAG);
- }
- shape = shapeBuilder.build();
- builtinTypeInstanceShapes[ordinal] = shape;
+ shape = createBuiltinShape(type, ordinal);
+ }
+ return shape;
+ }
+
+ private Shape createBuiltinShape(PythonBuiltinClassType type, int ordinal) {
+ Shape shape;
+ Shape.DerivedBuilder shapeBuilder = Shape.newBuilder(getEmptyShape()).addConstantProperty(HiddenAttr.getClassHiddenKey(), type, 0);
+ if (!type.isBuiltinWithDict()) {
+ shapeBuilder.shapeFlags(PythonObject.HAS_SLOTS_BUT_NO_DICT_FLAG);
}
+ shape = shapeBuilder.build();
+ builtinTypeInstanceShapes[ordinal] = shape;
return shape;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/BoundBuiltinCallable.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/BoundBuiltinCallable.java
index 833560df82..07f3c49918 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/BoundBuiltinCallable.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/BoundBuiltinCallable.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,8 +40,8 @@
*/
package com.oracle.graal.python.builtins;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.PythonLanguage;
public interface BoundBuiltinCallable {
- T boundToObject(PythonBuiltinClassType binding, PythonObjectFactory factory);
+ T boundToObject(PythonBuiltinClassType binding, PythonLanguage language);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
index 3146f1acf9..7d6dd23d65 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
@@ -59,9 +59,6 @@
import java.util.ServiceLoader;
import java.util.logging.Level;
-import com.oracle.graal.python.builtins.objects.foreign.ForeignExecutableBuiltins;
-import com.oracle.graal.python.builtins.objects.foreign.ForeignInstantiableBuiltins;
-import com.oracle.graal.python.builtins.objects.foreign.ForeignIterableBuiltins;
import org.graalvm.nativeimage.ImageInfo;
import com.oracle.graal.python.PythonLanguage;
@@ -264,6 +261,9 @@
import com.oracle.graal.python.builtins.objects.floats.PFloat;
import com.oracle.graal.python.builtins.objects.foreign.ForeignAbstractClassBuiltins;
import com.oracle.graal.python.builtins.objects.foreign.ForeignBooleanBuiltins;
+import com.oracle.graal.python.builtins.objects.foreign.ForeignExecutableBuiltins;
+import com.oracle.graal.python.builtins.objects.foreign.ForeignInstantiableBuiltins;
+import com.oracle.graal.python.builtins.objects.foreign.ForeignIterableBuiltins;
import com.oracle.graal.python.builtins.objects.foreign.ForeignNumberBuiltins;
import com.oracle.graal.python.builtins.objects.foreign.ForeignObjectBuiltins;
import com.oracle.graal.python.builtins.objects.frame.FrameBuiltins;
@@ -384,7 +384,7 @@
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.interop.PythonMapScope;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.Supplier;
import com.oracle.truffle.api.CallTarget;
@@ -396,6 +396,7 @@
import com.oracle.truffle.api.TruffleLanguage.Env;
import com.oracle.truffle.api.TruffleLogger;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.strings.TruffleString;
@@ -842,7 +843,6 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed,
private volatile boolean initialized;
private final PythonLanguage language;
- @CompilationFinal private PythonObjectSlowPathFactory objectFactory;
public Python3Core(PythonLanguage language, boolean isNativeSupportAllowed, boolean socketIOAllowed) {
this.language = language;
@@ -924,7 +924,6 @@ public final boolean isCoreInitialized() {
* Load the core library and prepare all builtin classes and modules.
*/
public final void initialize(PythonContext context) {
- objectFactory = new PythonObjectSlowPathFactory(context.getAllocationReporter(), context.getLanguage());
initializeJavaCore();
initializeImportlib();
context.applyModuleOptions();
@@ -1216,9 +1215,11 @@ private void initializeTypes() {
}
}
// now initialize well-known objects
- pyTrue = factory().createInt(PythonBuiltinClassType.Boolean, BigInteger.ONE);
- pyFalse = factory().createInt(PythonBuiltinClassType.Boolean, BigInteger.ZERO);
- pyNaN = factory().createFloat(Double.NaN);
+ PythonBuiltinClassType booleanType = PythonBuiltinClassType.Boolean;
+ Shape booleanShape = booleanType.getInstanceShape(getLanguage());
+ pyTrue = PFactory.createInt(getLanguage(), booleanType, booleanShape, BigInteger.ONE);
+ pyFalse = PFactory.createInt(getLanguage(), booleanType, booleanShape, BigInteger.ZERO);
+ pyNaN = PFactory.createFloat(getLanguage(), Double.NaN);
}
private void populateBuiltins() {
@@ -1247,7 +1248,7 @@ private void populateBuiltins() {
for (PythonBuiltinClassType klass : PythonBuiltinClassType.VALUES) {
wrapped.clear();
TpSlots.addOperatorsToBuiltin(wrapped, this, klass);
- PythonBuiltins.addFunctionsToModuleObject(wrapped, lookupType(klass), factory());
+ PythonBuiltins.addFunctionsToModuleObject(wrapped, lookupType(klass), getLanguage());
}
// core machinery
@@ -1269,7 +1270,7 @@ private void addBuiltinModule(TruffleString name, PythonModule module) {
private PythonModule createModule(TruffleString name, PythonBuiltins moduleBuiltins) {
PythonModule mod = builtinModules.get(name);
if (mod == null) {
- mod = factory().createPythonModule(name);
+ mod = PFactory.createPythonModule(getLanguage(), name);
if (moduleBuiltins != null) {
mod.setBuiltins(moduleBuiltins);
}
@@ -1280,7 +1281,7 @@ private PythonModule createModule(TruffleString name, PythonBuiltins moduleBuilt
private void addBuiltinsTo(PythonObject obj, PythonBuiltins builtinsForObj) {
builtinsForObj.addConstantsToModuleObject(obj);
- builtinsForObj.addFunctionsToModuleObject(obj, objectFactory);
+ builtinsForObj.addFunctionsToModuleObject(obj, getLanguage());
}
@TruffleBoundary
@@ -1306,7 +1307,7 @@ private void loadFile(TruffleString s, TruffleString prefix) {
PythonModule mod = lookupBuiltinModule(s);
if (mod == null) {
// use an anonymous module for the side-effects
- mod = factory().createPythonModule(T___ANONYMOUS__);
+ mod = PFactory.createPythonModule(getLanguage(), T___ANONYMOUS__);
}
loadFile(s, prefix, mod);
}
@@ -1324,10 +1325,6 @@ private void loadFile(TruffleString s, TruffleString prefix, PythonModule mod) {
GenericInvokeNode.getUncached().execute(callTarget, PArguments.withGlobals(mod));
}
- public final PythonObjectSlowPathFactory factory() {
- return objectFactory;
- }
-
public final PInt getTrue() {
return pyTrue;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
index 8d586cc758..07881f7807 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
@@ -173,7 +173,6 @@
import com.oracle.graal.python.builtins.objects.types.UnionTypeBuiltins;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.truffle.api.CompilerAsserts;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.interop.TruffleObject;
@@ -799,9 +798,6 @@ public String toString() {
}
public final Shape getInstanceShape(PythonLanguage lang) {
- if (name == null) {
- throw CompilerDirectives.shouldNotReachHere("incorrect use of Python builtin type marker");
- }
return lang.getBuiltinTypeInstanceShape(this);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java
index 89f6cc235b..4770b57d70 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -116,6 +116,7 @@
import java.util.Map.Entry;
import java.util.Set;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
@@ -125,7 +126,7 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.BiConsumer;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -173,7 +174,8 @@ public void initialize(Python3Core core) {
declaresExplicitSelf = true;
}
TruffleString tsName = toTruffleStringUncached(builtin.name());
- RootCallTarget callTarget = core.getLanguage().initBuiltinCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, factory, declaresExplicitSelf), factory.getNodeClass(),
+ PythonLanguage language = core.getLanguage();
+ RootCallTarget callTarget = language.initBuiltinCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, factory, declaresExplicitSelf), factory.getNodeClass(),
builtin.name());
Object builtinDoc = builtin.doc().isEmpty() ? PNone.NONE : toTruffleStringUncached(builtin.doc());
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
@@ -181,8 +183,8 @@ public void initialize(Python3Core core) {
assert !builtin.isGetter() && !builtin.isSetter() && !builtin.isClassmethod() && !builtin.isStaticmethod();
// we explicitly do not make these "staticmethods" here, since CPython also doesn't
// for builtin types
- PBuiltinFunction newFunc = core.factory().createBuiltinFunction(T___NEW__, constructsClass, numDefaults(builtin), flags, callTarget);
- PBuiltinMethod newMethod = core.factory().createBuiltinMethod(constructsClass, newFunc);
+ PBuiltinFunction newFunc = PFactory.createBuiltinFunction(language, T___NEW__, constructsClass, numDefaults(builtin), flags, callTarget);
+ PBuiltinMethod newMethod = PFactory.createBuiltinMethod(language, constructsClass, newFunc);
PythonBuiltinClass builtinClass = core.lookupType(constructsClass);
builtinClass.setAttributeUnsafe(T___NEW__, newMethod);
final Object currentBuiltinDoc = builtinClass.getAttribute(T___DOC__);
@@ -195,9 +197,9 @@ public void initialize(Python3Core core) {
// HACK: TODO: we should not see any slots here anymore once all are converted
// to slots, then we can make the slot field in PBuiltinFunction final, for now,
// we patch it in TpSlots#wrapBuiltinSlots
- function = core.factory().createWrapperDescriptor(tsName, null, numDefaults(builtin), flags, callTarget, null, null);
+ function = PFactory.createWrapperDescriptor(language, tsName, null, numDefaults(builtin), flags, callTarget, null, null);
} else {
- function = core.factory().createBuiltinFunction(tsName, null, numDefaults(builtin), flags, callTarget);
+ function = PFactory.createBuiltinFunction(language, tsName, null, numDefaults(builtin), flags, callTarget);
}
function.setAttribute(T___DOC__, builtinDoc);
BoundBuiltinCallable> callable = function;
@@ -205,12 +207,12 @@ public void initialize(Python3Core core) {
assert !builtin.isClassmethod() && !builtin.isStaticmethod();
PBuiltinFunction get = builtin.isGetter() ? function : null;
PBuiltinFunction set = builtin.isSetter() ? function : null;
- callable = core.factory().createGetSetDescriptor(get, set, tsName, null, builtin.allowsDelete());
+ callable = PFactory.createGetSetDescriptor(language, get, set, tsName, null, builtin.allowsDelete());
} else if (builtin.isClassmethod()) {
assert !builtin.isStaticmethod();
- callable = core.factory().createBuiltinClassmethodFromCallableObj(function);
+ callable = PFactory.createBuiltinClassmethodFromCallableObj(language, function);
} else if (builtin.isStaticmethod()) {
- callable = core.factory().createStaticmethodFromCallableObj(function);
+ callable = PFactory.createStaticmethodFromCallableObj(language, function);
}
builtinFunctions.put(toTruffleStringUncached(builtin.name()), callable);
}
@@ -294,18 +296,18 @@ void addConstantsToModuleObject(PythonObject obj) {
}
}
- void addFunctionsToModuleObject(PythonObject obj, PythonObjectSlowPathFactory factory) {
- addFunctionsToModuleObject(builtinFunctions, obj, factory);
+ void addFunctionsToModuleObject(PythonObject obj, PythonLanguage language) {
+ addFunctionsToModuleObject(builtinFunctions, obj, language);
}
- static void addFunctionsToModuleObject(Map> builtinFunctions, PythonObject obj, PythonObjectSlowPathFactory factory) {
+ static void addFunctionsToModuleObject(Map> builtinFunctions, PythonObject obj, PythonLanguage language) {
for (Entry> entry : builtinFunctions.entrySet()) {
Object value;
assert obj instanceof PythonModule || obj instanceof PythonBuiltinClass : "unexpected object while adding builtins";
if (obj instanceof PythonModule) {
- value = factory.createBuiltinMethod(obj, (PBuiltinFunction) entry.getValue());
+ value = PFactory.createBuiltinMethod(language, obj, (PBuiltinFunction) entry.getValue());
} else {
- value = entry.getValue().boundToObject(((PythonBuiltinClass) obj).getType(), factory);
+ value = entry.getValue().boundToObject(((PythonBuiltinClass) obj).getType(), language);
}
obj.setAttribute(entry.getKey(), value);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
index ce713d1aa2..fcf8ecaef9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -40,6 +40,7 @@
import java.nio.ByteOrder;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -59,6 +60,7 @@
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.builtins.objects.range.PIntRange;
import com.oracle.graal.python.builtins.objects.str.StringNodes.CastToTruffleStringCheckedNode;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.GetNextNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetIter;
@@ -74,7 +76,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.util.SplitArgsNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.BufferFormat;
@@ -169,21 +171,23 @@ abstract static class ArrayNodeInternal extends Node {
@Specialization(guards = "isNoValue(initializer)")
static PArray array(Node inliningTarget, Object cls, TruffleString typeCode, @SuppressWarnings("unused") PNone initializer,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
- return factory.createArray(cls, typeCode, format);
+ return PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format);
}
@Specialization
@InliningCutoff
static PArray arrayWithRangeInitializer(Node inliningTarget, Object cls, TruffleString typeCode, PIntRange range,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached ArrayNodes.PutValueNode putValueNode) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
PArray array;
try {
- array = factory.createArray(cls, typeCode, format, range.getIntLength());
+ array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format, range.getIntLength());
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
@@ -203,10 +207,11 @@ static PArray arrayWithRangeInitializer(Node inliningTarget, Object cls, Truffle
@Specialization
static PArray arrayWithBytesInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, PBytesLike bytes,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(inline = false) ArrayBuiltins.FromBytesNode fromBytesNode) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
- PArray array = factory.createArray(cls, typeCode, format);
+ PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format);
fromBytesNode.executeWithoutClinic(frame, array, bytes);
return array;
}
@@ -215,14 +220,15 @@ static PArray arrayWithBytesInitializer(VirtualFrame frame, Node inliningTarget,
@InliningCutoff
static PArray arrayWithStringInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, Object initializer,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(inline = false) ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
@Cached PRaiseNode.Lazy raise) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
if (format != BufferFormat.UNICODE) {
throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_USE_STR_TO_INITIALIZE_ARRAY, typeCode);
}
- PArray array = factory.createArray(cls, typeCode, format);
+ PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format);
fromUnicodeNode.execute(frame, array, initializer);
return array;
}
@@ -231,13 +237,14 @@ static PArray arrayWithStringInitializer(VirtualFrame frame, Node inliningTarget
@InliningCutoff
static PArray arrayArrayInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, PArray initializer,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached ArrayNodes.PutValueNode putValueNode,
@Cached ArrayNodes.GetValueNode getValueNode) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
try {
int length = initializer.getLength();
- PArray array = factory.createArray(cls, typeCode, format, length);
+ PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format, length);
for (int i = 0; i < length; i++) {
putValueNode.execute(frame, inliningTarget, array, i, getValueNode.execute(inliningTarget, initializer, i));
}
@@ -252,7 +259,8 @@ static PArray arrayArrayInitializer(VirtualFrame frame, Node inliningTarget, Obj
@InliningCutoff
static PArray arraySequenceInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, PSequence initializer,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached ArrayNodes.PutValueNode putValueNode,
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
@@ -260,7 +268,7 @@ static PArray arraySequenceInitializer(VirtualFrame frame, Node inliningTarget,
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, initializer);
int length = storage.length();
try {
- PArray array = factory.createArray(cls, typeCode, format, length);
+ PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format, length);
for (int i = 0; i < length; i++) {
putValueNode.execute(frame, inliningTarget, array, i, getItemNode.execute(inliningTarget, storage, i));
}
@@ -276,7 +284,8 @@ static PArray arraySequenceInitializer(VirtualFrame frame, Node inliningTarget,
static PArray arrayIteratorInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, Object initializer,
@Cached PyObjectGetIter getIter,
@Shared @Cached GetFormatCheckedNode getFormatCheckedNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached ArrayNodes.PutValueNode putValueNode,
@Cached(inline = false) GetNextNode nextNode,
@Cached IsBuiltinObjectProfile errorProfile,
@@ -285,7 +294,7 @@ static PArray arrayIteratorInitializer(VirtualFrame frame, Node inliningTarget,
Object iter = getIter.execute(frame, inliningTarget, initializer);
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
- PArray array = factory.createArray(cls, typeCode, format);
+ PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format);
int length = 0;
while (true) {
@@ -353,14 +362,14 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Exclusive @Cached PythonObjectFactory factory,
+ @Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
if (format == null) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_TYPECODE);
}
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format),
- factory, raiseNode);
+ getInstanceShape, raiseNode);
}
@Specialization(replaces = "reconstructCached")
@@ -373,19 +382,20 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Exclusive @Cached PythonObjectFactory factory,
+ @Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
if (format == null) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_TYPECODE);
}
- return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format, factory, raiseNode);
+ return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format, getInstanceShape,
+ raiseNode);
}
private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Object arrayType, TruffleString typeCode, int mformatCode, PBytes bytes, PyObjectCallMethodObjArgs callDecode,
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, IsSubtypeNode isSubtypeNode,
ArrayBuiltins.ByteSwapNode byteSwapNode, BufferFormat format,
- PythonObjectFactory factory, PRaiseNode.Lazy raiseNode) {
+ TypeNodes.GetInstanceShape getInstanceShape, PRaiseNode.Lazy raiseNode) {
if (!isSubtypeNode.execute(frame, arrayType, PythonBuiltinClassType.PArray)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.N_NOT_SUBTYPE_OF_ARRAY, arrayType);
}
@@ -393,11 +403,11 @@ private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Obj
if (machineFormat != null) {
PArray array;
if (machineFormat == MachineFormat.forFormat(format)) {
- array = factory.createArray(arrayType, typeCode, machineFormat.format);
+ array = PFactory.createArray(PythonLanguage.get(inliningTarget), arrayType, getInstanceShape.execute(arrayType), typeCode, machineFormat.format);
fromBytesNode.executeWithoutClinic(frame, array, bytes);
} else {
TruffleString newTypeCode = machineFormat.format == format ? typeCode : machineFormat.format.baseTypeCode;
- array = factory.createArray(arrayType, newTypeCode, machineFormat.format);
+ array = PFactory.createArray(PythonLanguage.get(inliningTarget), arrayType, getInstanceShape.execute(arrayType), newTypeCode, machineFormat.format);
if (machineFormat.unicodeEncoding != null) {
Object decoded = callDecode.execute(frame, inliningTarget, bytes, T_DECODE, machineFormat.unicodeEncoding);
fromUnicodeNode.execute(frame, array, decoded);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
index 86f6cdf903..b0b39be693 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
@@ -70,7 +70,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -253,9 +253,8 @@ public Object unregisterTask(VirtualFrame frame, PythonModule self, Object task,
@Override
public void postInitialize(Python3Core core) {
- PythonObjectSlowPathFactory factory = core.factory();
PythonModule self = core.lookupBuiltinModule(T__ASYNCIO);
- self.setAttribute(CURRENT_TASKS_ATTR, factory.createDict());
+ self.setAttribute(CURRENT_TASKS_ATTR, PFactory.createDict(core.getLanguage()));
Object weakref = AbstractImportNode.importModule(WEAKREF);
Object weakSetCls = PyObjectGetAttr.executeUncached(weakref, WEAKSET);
Object weakSet = CallNode.executeUncached(weakSetCls);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
index e4f0b202a0..0511a7b818 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
@@ -54,6 +54,7 @@
import java.util.Base64;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ClinicConverterFactory;
import com.oracle.graal.python.builtins.Builtin;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -195,10 +196,10 @@ abstract static class A2bBase64Node extends PythonBinaryClinicBuiltinNode {
PBytes doConvert(VirtualFrame frame, Object buffer, boolean strictMode,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
ByteSequenceStorage storage = b64decode(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), strictMode);
- return factory.createBytes(storage);
+ return PFactory.createBytes(language, storage);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -280,10 +281,10 @@ abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
PBytes a2b(VirtualFrame frame, Object buffer,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
byte[] bytes = a2b(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -325,7 +326,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class B2aBase64Node extends PythonClinicBuiltinNode {
@TruffleBoundary
- private PBytes b2a(byte[] data, int lenght, int newline, PythonObjectFactory factory) {
+ private PBytes b2a(byte[] data, int lenght, int newline, PythonLanguage language) {
ByteBuffer encoded;
try {
encoded = Base64.getEncoder().encode(ByteBuffer.wrap(data, 0, lenght));
@@ -335,18 +336,18 @@ private PBytes b2a(byte[] data, int lenght, int newline, PythonObjectFactory fac
if (newline != 0) {
byte[] encodedWithNL = Arrays.copyOf(encoded.array(), encoded.limit() + 1);
encodedWithNL[encodedWithNL.length - 1] = '\n';
- return factory.createBytes(encodedWithNL);
+ return PFactory.createBytes(language, encodedWithNL);
}
- return factory.createBytes(encoded.array(), encoded.limit());
+ return PFactory.createBytes(language, encoded.array(), encoded.limit());
}
@Specialization(limit = "3")
PBytes b2aBuffer(VirtualFrame frame, Object buffer, int newline,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
- return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), newline, factory);
+ return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), newline, language);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -371,28 +372,28 @@ static PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep
@Bind("this") Node inliningTarget,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (sep != PNone.NO_VALUE || bytesPerSep != 1) {
// TODO implement sep and bytes_per_sep
throw raiseNode.get(inliningTarget).raise(NotImplementedError);
}
try {
- return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), factory);
+ return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), language);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
}
@TruffleBoundary
- private static PBytes b2a(byte[] bytes, int length, PythonObjectFactory factory) {
+ private static PBytes b2a(byte[] bytes, int length, PythonLanguage language) {
byte[] output = new byte[length * 2];
for (int i = 0; i < length; i++) {
int v = bytes[i] & 0xff;
output[i * 2] = HEX_DIGITS[v >> 4];
output[i * 2 + 1] = HEX_DIGITS[v & 0xf];
}
- return factory.createBytes(output);
+ return PFactory.createBytes(language, output);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
index 90d03d8aae..985c7f9d0d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
@@ -98,6 +98,7 @@
import java.math.BigInteger;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -115,7 +116,6 @@
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.cell.PCell;
-import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
@@ -125,6 +125,7 @@
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CByteArrayWrapper;
import com.oracle.graal.python.builtins.objects.code.CodeNodes;
import com.oracle.graal.python.builtins.objects.code.PCode;
+import com.oracle.graal.python.builtins.objects.common.EmptyStorage;
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
@@ -159,7 +160,6 @@
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
-import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
@@ -232,8 +232,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.Assumption;
@@ -259,6 +258,7 @@
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.LoopNode;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
@@ -351,11 +351,18 @@ static Object dontCallBytes(VirtualFrame frame, Object cls, Object source, Objec
abstract static class CreateBytes extends PNodeWithContext {
abstract Object execute(Node inliningTarget, Object cls, byte[] bytes);
+ @Specialization(guards = "isBuiltinBytes(cls)")
+ static PBytes doBuiltin(@SuppressWarnings("unused") Object cls, byte[] bytes,
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, bytes);
+ }
+
@Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)")
static PBytes doManaged(@SuppressWarnings("unused") Node inliningTarget, Object cls, byte[] bytes,
@SuppressWarnings("unused") @Shared @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createBytes(cls, bytes);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createBytes(language, cls, getInstanceShape.execute(cls), bytes);
}
@Specialization(guards = "needsNativeAllocationNode.execute(inliningTarget, cls)")
@@ -371,6 +378,10 @@ static Object doNative(@SuppressWarnings("unused") Node inliningTarget, Object c
wrapper.free();
}
}
+
+ protected static boolean isBuiltinBytes(Object cls) {
+ return cls == PythonBuiltinClassType.PBytes;
+ }
}
}
@@ -391,9 +402,10 @@ static Object doNative(@SuppressWarnings("unused") Node inliningTarget, Object c
public abstract static class ByteArrayNode extends PythonBuiltinNode {
@Specialization
public PByteArray setEmpty(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BytesCommonBuiltins.InitNode
- return factory.createByteArray(cls, PythonUtils.EMPTY_BYTE_ARRAY);
+ return PFactory.createByteArray(language, cls, getInstanceShape.execute(cls), PythonUtils.EMPTY_BYTE_ARRAY);
}
// TODO: native allocation?
@@ -423,8 +435,9 @@ public static Object executeUncached(Object cls, double real, double imaginary)
@Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)", limit = "1")
static PComplex doManaged(@SuppressWarnings("unused") Node inliningTarget, Object cls, double real, double imaginary,
@SuppressWarnings("unused") @Cached NeedsNativeAllocationNode needsNativeAllocationNode,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(cls, real, imaginary);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createComplex(language, cls, getInstanceShape.execute(cls), real, imaginary);
}
@Fallback
@@ -493,10 +506,9 @@ Object complexFromDouble(VirtualFrame frame, Object cls, PFloat real, @SuppressW
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode isBuiltinObjectProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
return complexFromObject(frame, cls, real, imag, inliningTarget, createComplexNode, canBeDoubleNode, asDoubleNode, isComplexType, isResultComplexType, isPrimitiveProfile,
- isBuiltinObjectProfile, factory,
+ isBuiltinObjectProfile,
raiseNode);
}
@@ -524,10 +536,9 @@ Object complexFromLong(VirtualFrame frame, Object cls, PInt real, @SuppressWarni
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode complexCheck,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
return complexFromObject(frame, cls, real, imag, inliningTarget, createComplexNode, canBeDoubleNode, asDoubleNode, isComplexType, isResultComplexType, isPrimitiveProfile, complexCheck,
- factory, raiseNode);
+ raiseNode);
}
@Specialization(guards = {"isNoValue(imag)", "!isNoValue(number)", "!isString(number)"})
@@ -540,7 +551,6 @@ Object complexFromObject(VirtualFrame frame, Object cls, Object number, @Suppres
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode complexCheck,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
PComplex value = getComplexNumberFromObject(frame, number, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
@@ -554,7 +564,7 @@ Object complexFromObject(VirtualFrame frame, Object cls, Object number, @Suppres
if (complexCheck.execute(inliningTarget, value)) {
return value;
}
- return factory.createComplex(value.getReal(), value.getImag());
+ return PFactory.createComplex(PythonLanguage.get(inliningTarget), value.getReal(), value.getImag());
}
return createComplexNode.execute(inliningTarget, cls, value.getReal(), value.getImag());
}
@@ -901,21 +911,23 @@ public abstract static class DictionaryNode extends PythonBuiltinNode {
@Specialization(guards = "isBuiltinDict(cls)")
@SuppressWarnings("unused")
static PDict builtinDict(Object cls, Object[] args, PKeyword[] keywordArgs,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDict();
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language);
}
@Specialization(replaces = "builtinDict")
@SuppressWarnings("unused")
static PDict dict(Object cls, Object[] args, PKeyword[] keywordArgs,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile orderedProfile,
@Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ Shape shape = getInstanceShape.execute(cls);
if (orderedProfile.profile(inliningTarget, isSubtypeNode.execute(cls, PythonBuiltinClassType.POrderedDict))) {
- return factory.createOrderedDict(cls);
+ return PFactory.createOrderedDict(language, cls, shape);
}
- return factory.createDict(cls);
+ return PFactory.createDict(language, cls, shape, EmptyStorage.INSTANCE);
}
protected static boolean isBuiltinDict(Object cls) {
@@ -942,32 +954,36 @@ public abstract static class EnumerateNode extends PythonBuiltinNode {
static PEnumerate doNone(VirtualFrame frame, Object cls, Object iterable, @SuppressWarnings("unused") PNone keywordArg,
@Bind("this") Node inliningTarget,
@Shared("getIter") @Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEnumerate(cls, getIter.execute(frame, inliningTarget, iterable), 0);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createEnumerate(language, cls, getInstanceShape.execute(cls), getIter.execute(frame, inliningTarget, iterable), 0);
}
@Specialization
static PEnumerate doInt(VirtualFrame frame, Object cls, Object iterable, int start,
@Bind("this") Node inliningTarget,
@Shared("getIter") @Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEnumerate(cls, getIter.execute(frame, inliningTarget, iterable), start);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createEnumerate(language, cls, getInstanceShape.execute(cls), getIter.execute(frame, inliningTarget, iterable), start);
}
@Specialization
static PEnumerate doLong(VirtualFrame frame, Object cls, Object iterable, long start,
@Bind("this") Node inliningTarget,
@Shared("getIter") @Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEnumerate(cls, getIter.execute(frame, inliningTarget, iterable), start);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createEnumerate(language, cls, getInstanceShape.execute(cls), getIter.execute(frame, inliningTarget, iterable), start);
}
@Specialization
static PEnumerate doPInt(VirtualFrame frame, Object cls, Object iterable, PInt start,
@Bind("this") Node inliningTarget,
@Shared("getIter") @Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEnumerate(cls, getIter.execute(frame, inliningTarget, iterable), start);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createEnumerate(language, cls, getInstanceShape.execute(cls), getIter.execute(frame, inliningTarget, iterable), start);
}
static boolean isIntegerIndex(Object idx) {
@@ -990,35 +1006,35 @@ public abstract static class ReversedNode extends PythonBuiltinNode {
@Specialization
static PythonObject reversed(@SuppressWarnings("unused") Object cls, PIntRange range,
@Bind("this") Node inliningTarget,
- @Cached InlinedBranchProfile overflowProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached InlinedBranchProfile overflowProfile) {
int lstart = range.getIntStart();
int lstep = range.getIntStep();
int ulen = range.getIntLength();
try {
int new_stop = subtractExact(lstart, lstep);
int new_start = addExact(new_stop, multiplyExact(ulen, lstep));
- return factory.createIntRangeIterator(new_start, new_stop, negateExact(lstep), ulen);
+ return PFactory.createIntRangeIterator(language, new_start, new_stop, negateExact(lstep), ulen);
} catch (OverflowException e) {
overflowProfile.enter(inliningTarget);
- return handleOverflow(lstart, lstep, ulen, PythonContext.get(inliningTarget).factory());
+ return handleOverflow(language, lstart, lstep, ulen);
}
}
@TruffleBoundary
- private static PBigRangeIterator handleOverflow(int lstart, int lstep, int ulen, PythonObjectSlowPathFactory factory) {
+ private static PBigRangeIterator handleOverflow(PythonLanguage language, int lstart, int lstep, int ulen) {
BigInteger bstart = BigInteger.valueOf(lstart);
BigInteger bstep = BigInteger.valueOf(lstep);
BigInteger blen = BigInteger.valueOf(ulen);
BigInteger new_stop = bstart.subtract(bstep);
BigInteger new_start = new_stop.add(blen.multiply(bstep));
- return factory.createBigRangeIterator(new_start, new_stop, bstep.negate(), blen);
+ return PFactory.createBigRangeIterator(language, new_start, new_stop, bstep.negate(), blen);
}
@Specialization
@TruffleBoundary
- PythonObject reversed(@SuppressWarnings("unused") Object cls, PBigRange range) {
+ static PythonObject reversed(@SuppressWarnings("unused") Object cls, PBigRange range) {
BigInteger lstart = range.getBigIntegerStart();
BigInteger lstep = range.getBigIntegerStep();
BigInteger ulen = range.getBigIntegerLength();
@@ -1026,21 +1042,23 @@ PythonObject reversed(@SuppressWarnings("unused") Object cls, PBigRange range) {
BigInteger new_stop = lstart.subtract(lstep);
BigInteger new_start = new_stop.add(ulen.multiply(lstep));
- return getContext().factory().createBigRangeIterator(new_start, new_stop, lstep.negate(), ulen);
+ return PFactory.createBigRangeIterator(PythonLanguage.get(null), new_start, new_stop, lstep.negate(), ulen);
}
@Specialization
static PythonObject reversed(Object cls, PString value,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castToStringNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createStringReverseIterator(cls, castToStringNode.execute(inliningTarget, value));
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createStringReverseIterator(language, cls, getInstanceShape.execute(cls), castToStringNode.execute(inliningTarget, value));
}
@Specialization
static PythonObject reversed(Object cls, TruffleString value,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createStringReverseIterator(cls, value);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createStringReverseIterator(language, cls, getInstanceShape.execute(cls), value);
}
@Specialization(guards = {"!isString(sequence)", "!isPRange(sequence)"})
@@ -1052,7 +1070,8 @@ static Object reversed(VirtualFrame frame, Object cls, Object sequence,
@Cached PySequenceSizeNode pySequenceSizeNode,
@Cached InlinedConditionProfile noReversedProfile,
@Cached PySequenceCheckNode pySequenceCheck,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
Object sequenceKlass = getClassNode.execute(inliningTarget, sequence);
Object reversed = lookupReversed.execute(frame, sequenceKlass, sequence);
@@ -1061,7 +1080,7 @@ static Object reversed(VirtualFrame frame, Object cls, Object sequence,
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_ISNT_REVERSIBLE, sequence);
} else {
int lengthHint = pySequenceSizeNode.execute(frame, inliningTarget, sequence);
- return factory.createSequenceReverseIterator(cls, sequence, lengthHint);
+ return PFactory.createSequenceReverseIterator(language, cls, getInstanceShape.execute(cls), sequence, lengthHint);
}
} else {
return callReversed.executeObject(frame, reversed, sequence);
@@ -1145,19 +1164,22 @@ abstract static class NonPrimitiveFloatNode extends Node {
@Specialization(guards = {"!needsNativeAllocation", "isNoValue(obj)"})
@InliningCutoff
- Object floatFromNoneManagedSubclass(Object cls, PNone obj,
- @SuppressWarnings("unused") boolean needsNativeAllocation,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFloat(cls, PrimitiveFloatNode.floatFromNoValue(obj));
+ static Object floatFromNoneManagedSubclass(Object cls, PNone obj, @SuppressWarnings("unused") boolean needsNativeAllocation,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ Shape shape = getInstanceShape.execute(cls);
+ return PFactory.createFloat(language, cls, shape, PrimitiveFloatNode.floatFromNoValue(obj));
}
@Specialization(guards = "!needsNativeAllocation")
@InliningCutoff
- Object floatFromObjectManagedSubclass(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") boolean needsNativeAllocation,
+ static Object floatFromObjectManagedSubclass(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") boolean needsNativeAllocation,
@Bind("this") @SuppressWarnings("unused") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Shared @Cached PrimitiveFloatNode recursiveCallNode) {
- return factory.createFloat(cls, recursiveCallNode.execute(frame, inliningTarget, obj));
+ Shape shape = getInstanceShape.execute(cls);
+ return PFactory.createFloat(language, cls, shape, recursiveCallNode.execute(frame, inliningTarget, obj));
}
// logic similar to float_subtype_new(PyTypeObject *type, PyObject *x) from CPython
@@ -1195,8 +1217,9 @@ public abstract static class FrozenSetNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(arg)")
static PFrozenSet frozensetEmpty(Object cls, @SuppressWarnings("unused") PNone arg,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFrozenSet(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createFrozenSet(language, cls, getInstanceShape.execute(cls), EmptyStorage.INSTANCE);
}
@Specialization(guards = "isBuiltinClass.profileIsAnyBuiltinClass(inliningTarget, cls)")
@@ -1210,17 +1233,19 @@ static PFrozenSet frozensetIdentity(@SuppressWarnings("unused") Object cls, PFro
static PFrozenSet subFrozensetIdentity(Object cls, PFrozenSet arg,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared("isBuiltinProfile") @SuppressWarnings("unused") @Cached IsAnyBuiltinClassProfile isBuiltinClass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFrozenSet(cls, arg.getDictStorage());
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createFrozenSet(language, cls, getInstanceShape.execute(cls), arg.getDictStorage());
}
@Specialization(guards = {"!isNoValue(iterable)", "!isPFrozenSet(iterable)"})
static PFrozenSet frozensetIterable(VirtualFrame frame, Object cls, Object iterable,
@Bind("this") Node inliningTarget,
@Cached HashingCollectionNodes.GetClonedHashingStorageNode getHashingStorageNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
HashingStorage storage = getHashingStorageNode.doNoValue(frame, inliningTarget, iterable);
- return factory.createFrozenSet(cls, storage);
+ return PFactory.createFrozenSet(language, cls, getInstanceShape.execute(cls), storage);
}
}
@@ -1263,26 +1288,30 @@ abstract static class CreateIntSubclassNode extends Node {
@Specialization
static Object doSubclass(Object cls, int value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(cls, value);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createInt(language, cls, getInstanceShape.execute(cls), value);
}
@Specialization
static Object doSubclass(Object cls, long value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(cls, value);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createInt(language, cls, getInstanceShape.execute(cls), value);
}
@Specialization
static Object doSubclass(Object cls, boolean value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(cls, PInt.intValue(value));
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createInt(language, cls, getInstanceShape.execute(cls), PInt.intValue(value));
}
@Specialization
static Object doSubclass(Object cls, PInt value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(cls, value.getValue());
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createInt(language, cls, getInstanceShape.execute(cls), value.getValue());
}
}
@@ -1360,10 +1389,21 @@ public static boolean bool(VirtualFrame frame, @SuppressWarnings("unused") Objec
The argument must be an iterable if specified.""")
@GenerateNodeFactory
public abstract static class ListNode extends PythonVarargsBuiltinNode {
- @Specialization
+ @Specialization(guards = "isBuiltinList(cls)")
+ PList doBuiltin(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language);
+ }
+
+ @Fallback
protected PList constructList(Object cls, @SuppressWarnings("unused") Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
- @Cached PythonObjectFactory factory) {
- return factory.createList(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createList(language, cls, getInstanceShape.execute(cls));
+ }
+
+ protected static boolean isBuiltinList(Object cls) {
+ return cls == PythonBuiltinClassType.PList;
}
}
@@ -1441,22 +1481,24 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
@Specialization(guards = {"!self.needsNativeAllocation()"})
Object doManagedObject(VirtualFrame frame, PythonManagedClass self, Object[] varargs, PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached CheckExcessArgsNode checkExcessArgsNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
checkExcessArgsNode.execute(inliningTarget, self, varargs, kwargs);
if (self.isAbstractClass()) {
throw reportAbstractClass(frame, self);
}
- return factory.createPythonObject(self);
+ return PFactory.createPythonObject(language, self, getInstanceShape.execute(self));
}
@Specialization
static Object doBuiltinTypeType(PythonBuiltinClassType self, Object[] varargs, PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached CheckExcessArgsNode checkExcessArgsNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
checkExcessArgsNode.execute(inliningTarget, self, varargs, kwargs);
- return factory.createPythonObject(self);
+ return PFactory.createPythonObject(language, self, getInstanceShape.execute(self));
}
@Specialization(guards = "self.needsNativeAllocation()")
@@ -1536,87 +1578,87 @@ public abstract static class RangeNode extends PythonQuaternaryBuiltinNode {
@Specialization(guards = "isStop(start, stop, step)")
static Object doIntStop(Object cls, int stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doInt(cls, 0, stop, 1, inliningTarget, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, factory, raiseNode);
+ return doInt(cls, 0, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, raiseNode);
}
@Specialization(guards = "isStop(start, stop, step)")
static Object doPintStop(Object cls, PInt stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doPint(cls, factory.createInt(0), stop, factory.createInt(1), inliningTarget, lenOfRangeNode, factory, raiseNode);
+ return doPint(cls, PFactory.createInt(language, BigInteger.ZERO), stop, PFactory.createInt(language, BigInteger.ONE), inliningTarget, language, lenOfRangeNode, raiseNode);
}
@Specialization(guards = "isStop(start, stop, step)")
static Object doGenericStop(VirtualFrame frame, Object cls, Object stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doGeneric(frame, cls, 0, stop, 1, inliningTarget, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, factory, raiseNode);
+ return doGeneric(frame, cls, 0, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, raiseNode);
}
// start stop
@Specialization(guards = "isStartStop(start, stop, step)")
static Object doIntStartStop(Object cls, int start, int stop, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doInt(cls, start, stop, 1, inliningTarget, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, factory, raiseNode);
+ return doInt(cls, start, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, raiseNode);
}
@Specialization(guards = "isStartStop(start, stop, step)")
static Object doPintStartStop(Object cls, PInt start, PInt stop, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doPint(cls, start, stop, factory.createInt(1), inliningTarget, lenOfRangeNode, factory, raiseNode);
+ return doPint(cls, start, stop, PFactory.createInt(language, BigInteger.ONE), inliningTarget, language, lenOfRangeNode, raiseNode);
}
@Specialization(guards = "isStartStop(start, stop, step)")
static Object doGenericStartStop(VirtualFrame frame, Object cls, Object start, Object stop, @SuppressWarnings("unused") PNone step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doGeneric(frame, cls, start, stop, 1, inliningTarget, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, factory, raiseNode);
+ return doGeneric(frame, cls, start, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, raiseNode);
}
// start stop step
@Specialization
static Object doInt(@SuppressWarnings("unused") Object cls, int start, int stop, int step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNode,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (step == 0) {
throw raiseNode.get(inliningTarget).raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
}
try {
int len = lenOfRangeNode.executeInt(inliningTarget, start, stop, step);
- return factory.createIntRange(start, stop, step, len);
+ return PFactory.createIntRange(language, start, stop, step, len);
} catch (OverflowException e) {
exceptionProfile.enter(inliningTarget);
return createBigRangeNode.execute(inliningTarget, start, stop, step);
@@ -1626,26 +1668,26 @@ static Object doInt(@SuppressWarnings("unused") Object cls, int start, int stop,
@Specialization
static Object doPint(@SuppressWarnings("unused") Object cls, PInt start, PInt stop, PInt step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (step.isZero()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
}
BigInteger len = lenOfRangeNode.execute(inliningTarget, start.getValue(), stop.getValue(), step.getValue());
- return factory.createBigRange(start, stop, step, factory.createInt(len));
+ return PFactory.createBigRange(language, start, stop, step, PFactory.createInt(language, len));
}
@Specialization(guards = "isStartStopStep(start, stop, step)")
static Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object start, Object stop, Object step,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
Object lstart = indexNode.execute(frame, inliningTarget, start);
Object lstop = indexNode.execute(frame, inliningTarget, stop);
@@ -1655,7 +1697,7 @@ static Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object c
int istart = cast.execute(inliningTarget, lstart);
int istop = cast.execute(inliningTarget, lstop);
int istep = cast.execute(inliningTarget, lstep);
- return doInt(cls, istart, istop, istep, inliningTarget, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, factory, raiseNode);
+ return doInt(cls, istart, istop, istep, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, raiseNode);
} catch (PException e) {
e.expect(inliningTarget, OverflowError, overflowProfile);
return createBigRangeNode.execute(inliningTarget, lstart, lstop, lstep);
@@ -1683,11 +1725,21 @@ protected static boolean isStartStopStep(Object start, Object stop, Object step)
Build an unordered collection of unique elements.""")
@GenerateNodeFactory
public abstract static class SetNode extends PythonBuiltinNode {
+ @Specialization(guards = "isBuiltinSet(cls)")
+ public PSet setEmpty(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object arg,
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language);
+ }
- @Specialization
+ @Fallback
public PSet setEmpty(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
- return factory.createSet(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createSet(language, cls, getInstanceShape.execute(cls));
+ }
+
+ protected static boolean isBuiltinSet(Object cls) {
+ return cls == PythonBuiltinClassType.PSet;
}
}
@@ -1724,8 +1776,8 @@ static Object strNoArgs(Object cls, PNone arg, Object encoding, Object errors,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
@Exclusive @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
- @Shared @Cached PythonObjectFactory factory) {
- return asPString(cls, T_EMPTY_STRING, inliningTarget, isPrimitiveProfile, factory);
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return asPString(cls, T_EMPTY_STRING, inliningTarget, isPrimitiveProfile, getInstanceShape);
}
@Specialization(guards = {"!needsNativeAllocationNode.execute(inliningTarget, cls)", "!isNoValue(obj)", "isNoValue(encoding)", "isNoValue(errors)"}, limit = "1")
@@ -1736,13 +1788,13 @@ static Object strOneArg(VirtualFrame frame, Object cls, Object obj, @SuppressWar
@Exclusive @Cached InlinedConditionProfile isStringProfile,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Exclusive @Cached PyObjectStrAsObjectNode strNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
Object result = strNode.execute(frame, inliningTarget, obj);
// try to return a primitive if possible
assertNoJavaString(result);
if (isStringProfile.profile(inliningTarget, result instanceof TruffleString)) {
- return asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, factory);
+ return asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, getInstanceShape);
}
if (isPrimitiveProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PString)) {
@@ -1751,7 +1803,7 @@ static Object strOneArg(VirtualFrame frame, Object cls, Object obj, @SuppressWar
return result;
} else {
try {
- return asPString(cls, castToTruffleStringNode.execute(inliningTarget, result), inliningTarget, isPrimitiveProfile, factory);
+ return asPString(cls, castToTruffleStringNode.execute(inliningTarget, result), inliningTarget, isPrimitiveProfile, getInstanceShape);
} catch (CannotCastException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalStateException("asPstring result not castable to String");
@@ -1770,7 +1822,7 @@ static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encodi
@Exclusive @CachedLibrary("obj") PythonBufferAcquireLibrary acquireLib,
@Exclusive @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached("create(T_DECODE)") LookupAndCallTernaryNode callDecodeNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object buffer;
try {
@@ -1781,11 +1833,11 @@ static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encodi
try {
// TODO(fa): we should directly call '_codecs.decode'
// TODO don't copy, CPython creates a memoryview
- PBytes bytesObj = factory.createBytes(bufferLib.getCopiedByteArray(buffer));
+ PBytes bytesObj = PFactory.createBytes(PythonLanguage.get(inliningTarget), bufferLib.getCopiedByteArray(buffer));
Object en = encoding == PNone.NO_VALUE ? T_UTF8 : encoding;
Object result = assertNoJavaString(callDecodeNode.execute(frame, bytesObj, en, errors));
if (isStringProfile.profile(inliningTarget, result instanceof TruffleString)) {
- return asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, factory);
+ return asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, getInstanceShape);
} else if (isPStringProfile.profile(inliningTarget, result instanceof PString)) {
return result;
}
@@ -1830,7 +1882,7 @@ static Object doNativeSubclassEncodeErr(VirtualFrame frame, Object cls, Object o
@Exclusive @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached("create(T_DECODE)") LookupAndCallTernaryNode callDecodeNode,
@Shared @Cached(neverDefault = true) CExtNodes.StringSubtypeNew subtypeNew,
- @Shared @Cached PythonObjectFactory factory,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object buffer;
try {
@@ -1839,11 +1891,11 @@ static Object doNativeSubclassEncodeErr(VirtualFrame frame, Object cls, Object o
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
}
try {
- PBytes bytesObj = factory.createBytes(bufferLib.getCopiedByteArray(buffer));
+ PBytes bytesObj = PFactory.createBytes(PythonLanguage.get(inliningTarget), bufferLib.getCopiedByteArray(buffer));
Object en = encoding == PNone.NO_VALUE ? T_UTF8 : encoding;
Object result = assertNoJavaString(callDecodeNode.execute(frame, bytesObj, en, errors));
if (isStringProfile.profile(inliningTarget, result instanceof TruffleString)) {
- return subtypeNew.call(cls, asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, factory));
+ return subtypeNew.call(cls, asPString(cls, (TruffleString) result, inliningTarget, isPrimitiveProfile, getInstanceShape));
} else if (isPStringProfile.profile(inliningTarget, result instanceof PString)) {
return subtypeNew.call(cls, result);
}
@@ -1858,11 +1910,11 @@ protected static boolean isSubtypeOfString(VirtualFrame frame, IsSubtypeNode isS
}
private static Object asPString(Object cls, TruffleString str, Node inliningTarget, IsBuiltinClassExactProfile isPrimitiveProfile,
- PythonObjectFactory factory) {
+ TypeNodes.GetInstanceShape getInstanceShape) {
if (isPrimitiveProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PString)) {
return str;
} else {
- return factory.createString(cls, str);
+ return PFactory.createString(PythonLanguage.get(inliningTarget), cls, getInstanceShape.execute(cls), str);
}
}
@@ -1883,12 +1935,26 @@ public static StrNode create() {
@GenerateNodeFactory
public abstract static class TupleNode extends PythonBinaryBuiltinNode {
- @Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)")
+ @Specialization(guards = "isBuiltinTupleType(cls)")
+ static Object doBuiltin(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object iterable,
+ @Shared @Cached TupleNodes.ConstructTupleNode constructTupleNode) {
+ return constructTupleNode.execute(frame, iterable);
+ }
+
+ @Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)", replaces = "doBuiltin")
static PTuple constructTuple(VirtualFrame frame, Object cls, Object iterable,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
- @Cached TupleNodes.ConstructTupleNode constructTupleNode) {
- return constructTupleNode.execute(frame, cls, iterable);
+ @Shared @Cached TupleNodes.ConstructTupleNode constructTupleNode,
+ @Cached TypeNodes.IsSameTypeNode isSameTypeNode,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PTuple tuple = constructTupleNode.execute(frame, iterable);
+ if (isSameTypeNode.execute(inliningTarget, cls, PythonBuiltinClassType.PTuple)) {
+ return tuple;
+ } else {
+ return PFactory.createTuple(language, cls, getInstanceShape.execute(cls), tuple.getSequenceStorage());
+ }
}
// delegate to tuple_subtype_new(PyTypeObject *type, PyObject *x)
@@ -1902,6 +1968,10 @@ static Object doNative(@SuppressWarnings("unused") VirtualFrame frame, Object cl
return subtypeNew.call(cls, iterable);
}
+ protected static boolean isBuiltinTupleType(Object cls) {
+ return cls == PythonBuiltinClassType.PTuple;
+ }
+
protected static boolean isSubtypeOfTuple(VirtualFrame frame, IsSubtypeNode isSubtypeNode, Object cls) {
return isSubtypeNode.execute(frame, cls, PythonBuiltinClassType.PTuple);
}
@@ -1937,8 +2007,8 @@ static boolean isNoneOrEmptyPKeyword(Object value) {
static PZip zip(VirtualFrame frame, Object cls, Object[] args, @SuppressWarnings("unused") Object kw,
@Bind("this") Node inliningTarget,
@Exclusive @Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
- return zip(frame, inliningTarget, cls, args, false, getIter, factory);
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return zip(frame, inliningTarget, cls, args, false, getIter, getInstanceShape);
}
@Specialization(guards = "kw.length == 1")
@@ -1948,10 +2018,10 @@ static PZip zip(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kw,
@Exclusive @Cached PyObjectGetIter getIter,
@Cached PyObjectIsTrueNode isTrueNode,
@Cached InlinedConditionProfile profile,
- @Shared @Cached PythonObjectFactory factory,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (profile.profile(inliningTarget, eqNode.execute(kw[0].getName(), T_STRICT, TS_ENCODING))) {
- return zip(frame, inliningTarget, cls, args, isTrueNode.execute(frame, kw[0].getValue()), getIter, factory);
+ return zip(frame, inliningTarget, cls, args, isTrueNode.execute(frame, kw[0].getValue()), getIter, getInstanceShape);
}
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_IS_AN_INVALID_ARG_FOR_S, kw[0].getName(), T_ZIP);
}
@@ -1962,14 +2032,14 @@ static Object zip(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unu
throw raiseNode.raise(TypeError, ErrorMessages.S_TAKES_AT_MOST_ONE_KEYWORD_ARGUMENT_D_GIVEN, T_ZIP, kw.length);
}
- private static PZip zip(VirtualFrame frame, Node inliningTarget, Object cls, Object[] args, boolean strict, PyObjectGetIter getIter, PythonObjectFactory factory) {
+ private static PZip zip(VirtualFrame frame, Node inliningTarget, Object cls, Object[] args, boolean strict, PyObjectGetIter getIter, TypeNodes.GetInstanceShape getInstanceShape) {
Object[] iterables = new Object[args.length];
LoopNode.reportLoopCount(inliningTarget, args.length);
for (int i = 0; i < args.length; i++) {
Object item = args[i];
iterables[i] = getIter.execute(frame, inliningTarget, item);
}
- return factory.createZip(cls, iterables, strict);
+ return PFactory.createZip(PythonLanguage.get(inliningTarget), cls, getInstanceShape.execute(cls), iterables, strict);
}
}
@@ -1982,8 +2052,8 @@ public abstract static class FunctionNode extends PythonBuiltinNode {
@Specialization
static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, TruffleString name, @SuppressWarnings("unused") PNone defaultArgs,
@SuppressWarnings("unused") PNone closure,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFunction(name, code, globals, null);
+ @Bind PythonLanguage language) {
+ return PFactory.createFunction(language, name, code, globals, null);
}
@Specialization
@@ -1991,24 +2061,24 @@ static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PD
PTuple closure,
@Bind("this") Node inliningTarget,
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFunction(T_LAMBDA_NAME, code, globals, PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
+ @Bind PythonLanguage language) {
+ return PFactory.createFunction(language, T_LAMBDA_NAME, code, globals, PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
}
@Specialization
static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs,
@SuppressWarnings("unused") PNone closure,
@SuppressWarnings("unused") @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFunction(T_LAMBDA_NAME, code, globals, null);
+ @Bind PythonLanguage language) {
+ return PFactory.createFunction(language, T_LAMBDA_NAME, code, globals, null);
}
@Specialization
static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, TruffleString name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure,
@Bind("this") Node inliningTarget,
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFunction(name, code, globals, PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
+ @Bind PythonLanguage language) {
+ return PFactory.createFunction(language, name, code, globals, PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
}
@Specialization
@@ -2016,27 +2086,28 @@ static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PD
@SuppressWarnings("unused") PNone closure,
@Bind("this") Node inliningTarget,
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// TODO split defaults of positional args from kwDefaults
- return factory.createFunction(code.getName(), code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null, null);
+ return PFactory.createFunction(language, code.getName(), code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null, null);
}
@Specialization
static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, TruffleString name, PTuple defaultArgs, @SuppressWarnings("unused") PNone closure,
@Bind("this") Node inliningTarget,
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// TODO split defaults of positional args from kwDefaults
- return factory.createFunction(name, code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null, null);
+ return PFactory.createFunction(language, name, code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null, null);
}
@Specialization
static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, TruffleString name, PTuple defaultArgs, PTuple closure,
@Bind("this") Node inliningTarget,
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// TODO split defaults of positional args from kwDefaults
- return factory.createFunction(name, code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null, PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
+ return PFactory.createFunction(language, name, code, globals, getObjectArrayNode.execute(inliningTarget, defaultArgs), null,
+ PCell.toCellArray(getObjectArrayNode.execute(inliningTarget, closure)));
}
@Fallback
@@ -2198,34 +2269,14 @@ private IsAcceptableBaseNode ensureIsAcceptableBaseNode() {
The name must be a string; the optional doc argument can have any type.""")
@GenerateNodeFactory
public abstract static class ModuleNode extends PythonBuiltinNode {
- @Specialization
- @SuppressWarnings("unused")
- static Object doType(PythonBuiltinClass self, Object[] varargs, PKeyword[] kwargs,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createPythonModule(self.getType());
- }
-
- @Specialization(guards = "!isPythonBuiltinClass(self)")
- @SuppressWarnings("unused")
- static Object doManaged(PythonManagedClass self, Object[] varargs, PKeyword[] kwargs,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createPythonModule(self);
- }
@Specialization
@SuppressWarnings("unused")
- static Object doType(PythonBuiltinClassType self, Object[] varargs, PKeyword[] kwargs,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createPythonModule(self);
- }
-
- @Specialization(guards = "isTypeNode.execute(inliningTarget, self)", limit = "1")
- @SuppressWarnings("unused")
- static Object doNative(PythonAbstractNativeObject self, Object[] varargs, PKeyword[] kwargs,
+ static Object doGeneric(Object cls, Object[] varargs, PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
- @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createPythonModule(self);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createPythonModule(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2373,25 +2424,25 @@ static Object generator(Object args, Object kwargs,
@GenerateNodeFactory
public abstract static class MethodTypeNode extends PythonTernaryBuiltinNode {
@Specialization
- static Object method(Object cls, PFunction func, Object self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createMethod(cls, self, func);
+ static Object method(@SuppressWarnings("unused") Object cls, PFunction func, Object self,
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, self, func);
}
@Specialization
static Object methodBuiltin(@SuppressWarnings("unused") Object cls, PBuiltinFunction func, Object self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createMethod(self, func);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, self, func);
}
@Specialization
static Object methodGeneric(@SuppressWarnings("unused") Object cls, Object func, Object self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyCallableCheckNode callableCheck,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (callableCheck.execute(inliningTarget, func)) {
- return factory.createMethod(self, func);
+ return PFactory.createMethod(language, self, func);
} else {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.FIRST_ARG_MUST_BE_CALLABLE_S, "");
}
@@ -2402,9 +2453,9 @@ static Object methodGeneric(@SuppressWarnings("unused") Object cls, Object func,
@GenerateNodeFactory
public abstract static class BuiltinMethodTypeNode extends PythonBuiltinNode {
@Specialization
- Object method(Object cls, Object self, PBuiltinFunction func,
- @Cached PythonObjectFactory factory) {
- return factory.createBuiltinMethod(cls, self, func);
+ Object method(@SuppressWarnings("unused") Object cls, Object self, PBuiltinFunction func,
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, self, func);
}
}
@@ -2426,14 +2477,14 @@ static Object call(
public abstract static class TracebackTypeNode extends PythonClinicBuiltinNode {
@Specialization
static Object createTraceback(@SuppressWarnings("unused") Object cls, PTraceback next, PFrame pframe, int lasti, int lineno,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTracebackWithLasti(pframe, lineno, lasti, next);
+ @Bind PythonLanguage language) {
+ return PFactory.createTracebackWithLasti(language, pframe, lineno, lasti, next);
}
@Specialization
static Object createTraceback(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") PNone next, PFrame pframe, int lasti, int lineno,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTracebackWithLasti(pframe, lineno, lasti, null);
+ @Bind PythonLanguage language) {
+ return PFactory.createTracebackWithLasti(language, pframe, lineno, lasti, null);
}
@Specialization(guards = {"!isPTraceback(next)", "!isNone(next)"})
@@ -2544,10 +2595,10 @@ private Assumption getAssumption() {
@Specialization
Object newCell(@SuppressWarnings("unused") Object cls, Object contents,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile nonEmptyProfile) {
Assumption assumption = getAssumption();
- PCell cell = factory.createCell(assumption);
+ PCell cell = PFactory.createCell(language, assumption);
if (nonEmptyProfile.profile(inliningTarget, !isNoValue(contents))) {
cell.setRef(contents, assumption);
}
@@ -2575,27 +2626,28 @@ public final Object varArgExecute(VirtualFrame frame, Object self, Object[] argu
static Object doManaged(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached InlinedConditionProfile argsProfile) {
PTuple argsTuple;
if (argsProfile.profile(inliningTarget, args.length == 0)) {
argsTuple = null;
} else {
- argsTuple = factory.createTuple(args);
+ argsTuple = PFactory.createTuple(language, args);
}
- return factory.createBaseException(cls, null, argsTuple);
+ return PFactory.createBaseException(language, cls, getInstanceShape.execute(cls), null, argsTuple);
}
@Specialization(guards = "needsNativeAllocationNode.execute(inliningTarget, cls)", limit = "1")
static Object doNativeSubtype(Object cls, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PCallCapiFunction callCapiFunction,
@Cached PythonToNativeNode toNativeNode,
@Cached NativeToPythonTransferNode toPythonNode,
@Cached ExternalFunctionNodes.DefaultCheckFunctionResultNode checkFunctionResultNode) {
- Object argsTuple = args.length > 0 ? factory.createTuple(args) : factory.createEmptyTuple();
+ Object argsTuple = args.length > 0 ? PFactory.createTuple(language, args) : PFactory.createEmptyTuple(language);
Object nativeResult = callCapiFunction.call(NativeCAPISymbol.FUN_EXCEPTION_SUBTYPE_NEW, toNativeNode.execute(cls), toNativeNode.execute(argsTuple));
return toPythonNode.execute(checkFunctionResultNode.execute(PythonContext.get(inliningTarget), NativeCAPISymbol.FUN_EXCEPTION_SUBTYPE_NEW.getTsName(), nativeResult));
}
@@ -2608,8 +2660,9 @@ public abstract static class BaseExceptionGroupNode extends PythonTernaryBuiltin
@Specialization
static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Object exceptionsObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached CastToTruffleStringNode castToStringNode,
- @Cached PythonObjectFactory factory,
@Cached PySequenceCheckNode sequenceCheckNode,
@Cached TupleNodes.ConstructTupleNode toTupleNode,
@Cached SequenceStorageNodes.ToArrayNode toArrayNode,
@@ -2667,7 +2720,7 @@ static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Objec
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_NEST_BASE_EXCEPTIONS_IN_N, cls);
}
}
- return factory.createBaseExceptionGroup(cls, message, exceptions, new Object[]{messageObj, exceptionsObj});
+ return PFactory.createBaseExceptionGroup(language, cls, getInstanceShape.execute(cls), message, exceptions, new Object[]{messageObj, exceptionsObj});
}
}
@@ -2675,14 +2728,14 @@ static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Objec
@GenerateNodeFactory
public abstract static class MappingproxyNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "!isNoValue(obj)")
- static Object doMapping(Object klass, Object obj,
+ static Object doMapping(@SuppressWarnings("unused") Object cls, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyMappingCheckNode mappingCheckNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
// descrobject.c mappingproxy_check_mapping()
if (!(obj instanceof PList || obj instanceof PTuple) && mappingCheckNode.execute(inliningTarget, obj)) {
- return factory.createMappingproxy(klass, obj);
+ return PFactory.createMappingproxy(language, obj);
}
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "mappingproxy()", "mapping", obj);
}
@@ -2716,7 +2769,7 @@ public abstract static class GetSetDescriptorNode extends DescriptorNode {
@TruffleBoundary
Object call(@SuppressWarnings("unused") Object clazz, Object get, Object set, TruffleString name, Object owner) {
denyInstantiationAfterInitialization(T_GETSET_DESCRIPTOR);
- return PythonObjectFactory.getUncached().createGetSetDescriptor(ensure(get), ensure(set), name, owner);
+ return PFactory.createGetSetDescriptor(PythonLanguage.get(null), ensure(get), ensure(set), name, owner);
}
}
@@ -2728,7 +2781,7 @@ public abstract static class MemberDescriptorNode extends DescriptorNode {
@TruffleBoundary
Object doGeneric(@SuppressWarnings("unused") Object clazz, Object get, Object set, TruffleString name, Object owner) {
denyInstantiationAfterInitialization(T_MEMBER_DESCRIPTOR);
- return PythonObjectFactory.getUncached().createGetSetDescriptor(ensure(get), ensure(set), name, owner);
+ return PFactory.createGetSetDescriptor(PythonLanguage.get(null), ensure(get), ensure(set), name, owner);
}
}
@@ -2740,7 +2793,7 @@ public abstract static class WrapperDescriptorNode extends DescriptorNode {
@TruffleBoundary
Object doGeneric(@SuppressWarnings("unused") Object clazz, Object get, Object set, TruffleString name, Object owner) {
denyInstantiationAfterInitialization(T_WRAPPER_DESCRIPTOR);
- return PythonObjectFactory.getUncached().createGetSetDescriptor(ensure(get), ensure(set), name, owner);
+ return PFactory.createGetSetDescriptor(PythonLanguage.get(null), ensure(get), ensure(set), name, owner);
}
}
@@ -2818,10 +2871,21 @@ def cmeth(cls, arg):
super().cmeth(arg)""")
@GenerateNodeFactory
public abstract static class SuperInitNode extends PythonTernaryBuiltinNode {
- @Specialization
- static Object doObjectIndirect(Object self, @SuppressWarnings("unused") Object type, @SuppressWarnings("unused") Object object,
- @Cached PythonObjectFactory factory) {
- return factory.createSuperObject(self);
+ @Specialization(guards = "isBuiltinSuper(cls)")
+ static Object doBuiltin(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object type, @SuppressWarnings("unused") Object object,
+ @Bind PythonLanguage language) {
+ return PFactory.createSuperObject(language);
+ }
+
+ @Fallback
+ static Object doOther(Object cls, @SuppressWarnings("unused") Object type, @SuppressWarnings("unused") Object object,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createSuperObject(language, cls, getInstanceShape.execute(cls));
+ }
+
+ protected static boolean isBuiltinSuper(Object cls) {
+ return cls == PythonBuiltinClassType.Super;
}
}
@@ -2849,9 +2913,10 @@ It can be called either on the class (e.g. C.f()) or on an instance
@GenerateNodeFactory
public abstract static class ClassmethodNode extends PythonBinaryBuiltinNode {
@Specialization
- static Object doObjectIndirect(Object self, @SuppressWarnings("unused") Object callable,
- @Cached PythonObjectFactory factory) {
- return factory.createClassmethod(self);
+ static Object doObjectIndirect(Object cls, @SuppressWarnings("unused") Object callable,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createClassmethod(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2859,9 +2924,10 @@ static Object doObjectIndirect(Object self, @SuppressWarnings("unused") Object c
@GenerateNodeFactory
public abstract static class InstancemethodNode extends PythonBinaryBuiltinNode {
@Specialization
- static Object doObjectIndirect(Object self, @SuppressWarnings("unused") Object callable,
- @Cached PythonObjectFactory factory) {
- return factory.createInstancemethod(self);
+ static Object doObjectIndirect(Object cls, @SuppressWarnings("unused") Object callable,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createInstancemethod(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2887,9 +2953,10 @@ It can be called either on the class (e.g. C.f()) or on an instance
@GenerateNodeFactory
public abstract static class StaticmethodNode extends PythonBinaryBuiltinNode {
@Specialization
- static Object doObjectIndirect(Object self, @SuppressWarnings("unused") Object callable,
- @Cached PythonObjectFactory factory) {
- return factory.createStaticmethod(self);
+ static Object doObjectIndirect(Object cls, @SuppressWarnings("unused") Object callable,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createStaticmethod(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2906,7 +2973,8 @@ static PMap doit(VirtualFrame frame, Object cls, Object[] args, PKeyword[] keywo
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached InlinedLoopConditionProfile loopProfile,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "map()");
@@ -2914,7 +2982,7 @@ static PMap doit(VirtualFrame frame, Object cls, Object[] args, PKeyword[] keywo
if (args.length < 2) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MAP_MUST_HAVE_AT_LEAST_TWO_ARGUMENTS);
}
- PMap map = factory.createMap(cls);
+ PMap map = PFactory.createMap(language, cls, getInstanceShape.execute(cls));
map.setFunction(args[0]);
Object[] iterators = new Object[args.length - 1];
loopProfile.profileCounted(inliningTarget, iterators.length);
@@ -2962,9 +3030,10 @@ def x(self):
@GenerateNodeFactory
public abstract static class PropertyNode extends PythonVarargsBuiltinNode {
@Specialization
- static PProperty doit(Object self, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] keywords,
- @Cached PythonObjectFactory factory) {
- return factory.createProperty(self);
+ static PProperty doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] keywords,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createProperty(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2974,9 +3043,10 @@ static PProperty doit(Object self, @SuppressWarnings("unused") Object[] args, @S
@GenerateNodeFactory
public abstract static class SimpleNamespaceNode extends PythonVarargsBuiltinNode {
@Specialization
- static PSimpleNamespace doit(Object self, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] keywords,
- @Cached PythonObjectFactory factory) {
- return factory.createSimpleNamespace(self);
+ static PSimpleNamespace doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] keywords,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createSimpleNamespace(language, cls, getInstanceShape.execute(cls));
}
}
@@ -2985,8 +3055,9 @@ static PSimpleNamespace doit(Object self, @SuppressWarnings("unused") Object[] a
abstract static class GenericAliasNode extends PythonTernaryBuiltinNode {
@Specialization
static PGenericAlias doit(Object cls, Object origin, Object arguments,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, origin, arguments, false);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createGenericAlias(language, cls, getInstanceShape.execute(cls), origin, arguments, false);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 83bb3b2291..35ea14c64c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -247,7 +247,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -1036,18 +1036,17 @@ protected abstract Object executeInternal(VirtualFrame frame, Object source, Tru
Object doCompile(VirtualFrame frame, TruffleString expression, TruffleString filename, TruffleString mode, int flags, boolean dontInherit, int optimize,
int featureVersion,
@Shared @Cached ReadCallerFrameNode readCallerFrame,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (!dontInherit) {
PFrame fr = readCallerFrame.executeWith(frame, 0);
- PCode code = factory.createCode(fr.getTarget());
+ PCode code = PFactory.createCode(language, fr.getTarget());
flags |= code.getFlags() & PyCF_MASK;
}
- return compile(expression, filename, mode, flags, dontInherit, optimize, featureVersion, factory);
+ return compile(expression, filename, mode, flags, dontInherit, optimize, featureVersion);
}
@TruffleBoundary
- Object compile(TruffleString expression, TruffleString filename, TruffleString mode, int flags, @SuppressWarnings("unused") boolean dontInherit, int optimize, int featureVersion,
- PythonObjectFactory factory) {
+ Object compile(TruffleString expression, TruffleString filename, TruffleString mode, int flags, @SuppressWarnings("unused") boolean dontInherit, int optimize, int featureVersion) {
checkFlags(flags);
checkOptimize(optimize, optimize);
checkSource(expression);
@@ -1104,7 +1103,7 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
} else {
ct = getContext().getLanguage().cacheCode(filename, createCode);
}
- return wrapRootCallTarget((RootCallTarget) ct, factory);
+ return wrapRootCallTarget((RootCallTarget) ct);
}
@Specialization(limit = "3")
@@ -1123,7 +1122,6 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Shared @Cached ReadCallerFrameNode readCallerFrame,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (wSource instanceof PCode) {
return wSource;
@@ -1147,7 +1145,7 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
if (!dontInherit) {
PFrame fr = readCallerFrame.executeWith(frame, 0);
- PCode code = factory.createCode(fr.getTarget());
+ PCode code = PFactory.createCode(PythonLanguage.get(inliningTarget), fr.getTarget());
flags |= code.getFlags() & PyCF_MASK;
}
@@ -1155,20 +1153,20 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
ModTy mod = AstModuleBuiltins.obj2sst(context, wSource, getParserInputType(mode, flags));
Source source = PythonUtils.createFakeSource(filename);
RootCallTarget rootCallTarget = context.getLanguage(inliningTarget).compileForBytecodeInterpreter(context, mod, source, false, optimize, null, null, flags);
- return wrapRootCallTarget(rootCallTarget, factory);
+ return wrapRootCallTarget(rootCallTarget);
}
- TruffleString source = sourceAsString(frame, inliningTarget, wSource, filename, interopLib, acquireLib, bufferLib, handleDecodingErrorNode, asStrNode, switchEncodingNode, factory,
+ TruffleString source = sourceAsString(frame, inliningTarget, wSource, filename, interopLib, acquireLib, bufferLib, handleDecodingErrorNode, asStrNode, switchEncodingNode,
raiseNode, indirectCallData);
checkSource(source);
- return compile(source, filename, mode, flags, dontInherit, optimize, featureVersion, factory);
+ return compile(source, filename, mode, flags, dontInherit, optimize, featureVersion);
}
- private static PCode wrapRootCallTarget(RootCallTarget rootCallTarget, PythonObjectFactory factory) {
+ private static PCode wrapRootCallTarget(RootCallTarget rootCallTarget) {
RootNode rootNode = rootCallTarget.getRootNode();
if (rootNode instanceof PBytecodeRootNode) {
((PBytecodeRootNode) rootNode).triggerDeferredDeprecationWarnings();
}
- return factory.createCode(rootCallTarget);
+ return PFactory.createCode(PythonLanguage.get(null), rootCallTarget);
}
@TruffleBoundary
@@ -1214,7 +1212,7 @@ private InputType getParserInputType(TruffleString mode, int flags) {
// modeled after _Py_SourceAsString
TruffleString sourceAsString(VirtualFrame frame, Node inliningTarget, Object source, TruffleString filename, InteropLibrary interopLib, PythonBufferAcquireLibrary acquireLib,
PythonBufferAccessLibrary bufferLib, CodecsModuleBuiltins.HandleDecodingErrorNode handleDecodingErrorNode, PyObjectStrAsTruffleStringNode asStrNode,
- TruffleString.SwitchEncodingNode switchEncodingNode, PythonObjectFactory factory, PRaiseNode.Lazy raiseNode, IndirectCallData indirectCallData) {
+ TruffleString.SwitchEncodingNode switchEncodingNode, PRaiseNode.Lazy raiseNode, IndirectCallData indirectCallData) {
if (interopLib.isString(source)) {
try {
return switchEncodingNode.execute(interopLib.asTruffleString(source), TS_ENCODING);
@@ -1238,7 +1236,7 @@ TruffleString sourceAsString(VirtualFrame frame, Node inliningTarget, Object sou
CodecsModuleBuiltins.TruffleDecoder decoder = new CodecsModuleBuiltins.TruffleDecoder(pythonEncodingNameFromJavaName, charset, bytes, bytesLen, CodingErrorAction.REPORT);
if (!decoder.decodingStep(true)) {
try {
- handleDecodingErrorNode.execute(frame, decoder, T_STRICT, factory.createBytes(bytes, bytesLen));
+ handleDecodingErrorNode.execute(frame, decoder, T_STRICT, PFactory.createBytes(PythonLanguage.get(inliningTarget), bytes, bytesLen));
throw CompilerDirectives.shouldNotReachHere();
} catch (PException e) {
throw raiseInvalidSyntax(filename, "(unicode error) %s", asStrNode.execute(frame, inliningTarget, e.getEscapedException()));
@@ -1542,8 +1540,8 @@ static Object iter(VirtualFrame frame, Object object, @SuppressWarnings("unused"
static Object iter(Object callable, Object sentinel,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Cached PyCallableCheckNode callableCheck,
- @Cached PythonObjectFactory factory) {
- return factory.createSentinelIterator(callable, sentinel);
+ @Bind PythonLanguage language) {
+ return PFactory.createSentinelIterator(language, callable, sentinel);
}
@Fallback
@@ -2327,7 +2325,7 @@ abstract static class UpdateBasesNode extends Node {
@Specialization
static PTuple update(PTuple bases, Object[] arguments, int nargs,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PyObjectLookupAttr getMroEntries,
@Cached CallUnaryMethodNode callMroEntries,
@Cached PRaiseNode.Lazy raiseNode) {
@@ -2372,7 +2370,7 @@ static PTuple update(PTuple bases, Object[] arguments, int nargs,
if (newBases == null) {
return bases;
}
- return factory.createTuple(newBases.toArray());
+ return PFactory.createTuple(language, newBases.toArray());
}
}
@@ -2430,9 +2428,9 @@ private static Object buildJavaClass(Object namespace, TruffleString name, Objec
}
@InliningCutoff
- private static Object buildJavaClass(VirtualFrame frame, PythonLanguage language, PFunction function, Object[] arguments, PythonObjectFactory factory, CallDispatchNode callBody,
+ private static Object buildJavaClass(VirtualFrame frame, PythonLanguage language, PFunction function, Object[] arguments, CallDispatchNode callBody,
TruffleString name) {
- PDict ns = factory.createDict(new DynamicObjectStorage(language));
+ PDict ns = PFactory.createDict(language, new DynamicObjectStorage(language));
Object[] args = PArguments.create(0);
PArguments.setSpecialArgument(args, ns);
callBody.executeCall(frame, function, args);
@@ -2444,7 +2442,6 @@ protected Object doItNonFunction(VirtualFrame frame, Object function, Object[] a
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PythonObjectFactory factory,
@Cached CalculateMetaclassNode calculateMetaClass,
@Cached("create(T___PREPARE__)") GetAttributeNode getPrepare,
@Cached PyMappingCheckNode pyMappingCheckNode,
@@ -2470,15 +2467,16 @@ protected Object doItNonFunction(VirtualFrame frame, Object function, Object[] a
throw raise(PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NAME_NOT_STRING);
}
- Object[] basesArray = Arrays.copyOfRange(arguments, 1, arguments.length);
- PTuple origBases = factory.createTuple(basesArray);
-
- PythonContext ctx = PythonContext.get(calculateMetaClass);
+ PythonContext ctx = PythonContext.get(inliningTarget);
Env env = ctx.getEnv();
PythonLanguage language = ctx.getLanguage(inliningTarget);
+
+ Object[] basesArray = Arrays.copyOfRange(arguments, 1, arguments.length);
+ PTuple origBases = PFactory.createTuple(language, basesArray);
+
if (arguments.length == 2 && env.isHostObject(arguments[1]) && env.asHostObject(arguments[1]) instanceof Class>) {
// we want to subclass a Java class
- return buildJavaClass(frame, language, (PFunction) function, arguments, factory, callBody, name);
+ return buildJavaClass(frame, language, (PFunction) function, arguments, callBody, name);
}
class InitializeBuildClass {
@@ -2540,7 +2538,7 @@ class InitializeBuildClass {
ns = callPrep.execute(frame, prep, new Object[]{name, init.bases}, init.mkw);
} catch (PException p) {
p.expectAttributeError(inliningTarget, noAttributeProfile);
- ns = factory.createDict(new DynamicObjectStorage(language));
+ ns = PFactory.createDict(language, new DynamicObjectStorage(language));
}
if (!pyMappingCheckNode.execute(inliningTarget, ns)) {
throw raiseNoMapping(init.isClass, init.meta, ns);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
index fe32d28808..1fe9d7865d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2020 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -10,6 +10,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -29,7 +30,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CoerceToComplexNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -78,14 +79,14 @@ public void initialize(Python3Core core) {
addBuiltinConstant("tau", 2 * Math.PI);
addBuiltinConstant("inf", Double.POSITIVE_INFINITY);
addBuiltinConstant("nan", Double.NaN);
- addBuiltinConstant("infj", core.factory().createComplex(0, Double.POSITIVE_INFINITY));
- addBuiltinConstant("nanj", core.factory().createComplex(0, Double.NaN));
+ addBuiltinConstant("infj", PFactory.createComplex(core.getLanguage(), 0, Double.POSITIVE_INFINITY));
+ addBuiltinConstant("nanj", PFactory.createComplex(core.getLanguage(), 0, Double.NaN));
super.initialize(core);
}
- static PComplex specialValue(PythonObjectFactory factory, ComplexValue[][] table, double real, double imag) {
+ static PComplex specialValue(PythonLanguage language, ComplexValue[][] table, double real, double imag) {
ComplexValue v = specialValue(table, real, imag);
- return v == null ? null : v.toPComplex(factory);
+ return v == null ? null : v.toPComplex(language);
}
static ComplexValue specialValue(ComplexValue[][] table, double real, double imag) {
@@ -122,8 +123,8 @@ static class ComplexValue {
this.imag = imag;
}
- PComplex toPComplex(PythonObjectFactory factory) {
- return factory.createComplex(real, imag);
+ PComplex toPComplex(PythonLanguage language) {
+ return PFactory.createComplex(language, real, imag);
}
}
@@ -179,31 +180,31 @@ interface Op {
@Specialization
static PComplex doL(Node inliningTarget, long value, Op op,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(factory);
+ return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(language);
}
@Specialization
static PComplex doD(Node inliningTarget, double value, Op op,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(factory);
+ return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(language);
}
@Specialization
static PComplex doC(Node inliningTarget, PComplex value, Op op,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return op.compute(inliningTarget, value.getReal(), value.getImag(), raiseNode).toPComplex(factory);
+ return op.compute(inliningTarget, value.getReal(), value.getImag(), raiseNode).toPComplex(language);
}
@Specialization
static PComplex doGeneral(VirtualFrame frame, Node inliningTarget, Object value, Op op,
@Cached CoerceToComplexNode coerceToComplex,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- return doC(inliningTarget, coerceToComplex.execute(frame, inliningTarget, value), op, factory, raiseNode);
+ return doC(inliningTarget, coerceToComplex.execute(frame, inliningTarget, value), op, language, raiseNode);
}
}
@@ -312,21 +313,21 @@ abstract static class PolarNode extends PythonUnaryBuiltinNode {
@Specialization
static PTuple doL(long value,
- @Shared @Cached PythonObjectFactory factory) {
- return doD(value, factory);
+ @Bind PythonLanguage language) {
+ return doD(value, language);
}
@Specialization
static PTuple doD(double value,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{Math.abs(value), value < 0 ? Math.PI : 0});
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, new Object[]{Math.abs(value), value < 0 ? Math.PI : 0});
}
@Specialization
static PTuple doC(PComplex value,
@Shared @Cached ComplexBuiltins.AbsNode absNode,
- @Shared @Cached PythonObjectFactory factory) {
- return toPolar(value, absNode, factory);
+ @Bind PythonLanguage language) {
+ return toPolar(value, absNode, language);
}
@Specialization
@@ -334,13 +335,13 @@ static PTuple doGeneral(VirtualFrame frame, Object value,
@Bind("this") Node inliningTarget,
@Cached CoerceToComplexNode coerceToComplex,
@Shared @Cached ComplexBuiltins.AbsNode absNode,
- @Shared @Cached PythonObjectFactory factory) {
- return toPolar(coerceToComplex.execute(frame, inliningTarget, value), absNode, factory);
+ @Bind PythonLanguage language) {
+ return toPolar(coerceToComplex.execute(frame, inliningTarget, value), absNode, language);
}
- private static PTuple toPolar(PComplex value, ComplexBuiltins.AbsNode absNode, PythonObjectFactory factory) {
+ private static PTuple toPolar(PComplex value, ComplexBuiltins.AbsNode absNode, PythonLanguage language) {
double r = absNode.executeDouble(value);
- return factory.createTuple(new Object[]{r, Math.atan2(value.getImag(), value.getReal())});
+ return PFactory.createTuple(language, new Object[]{r, Math.atan2(value.getImag(), value.getReal())});
}
}
@@ -393,7 +394,7 @@ static PComplex doGeneral(VirtualFrame frame, Object r, Object phi,
@TruffleBoundary
private static PComplex rect(Node raisingNode, double r, double phi) {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
+ PythonLanguage language = PythonLanguage.get(null);
// deal with special values
if (!Double.isFinite(r) || !Double.isFinite(phi)) {
// need to raise an exception if r is a nonzero number and phi is infinite
@@ -408,14 +409,14 @@ private static PComplex rect(Node raisingNode, double r, double phi) {
double real = Math.copySign(Double.POSITIVE_INFINITY, Math.cos(phi));
double imag = Math.copySign(Double.POSITIVE_INFINITY, Math.sin(phi));
if (r > 0) {
- return factory.createComplex(real, imag);
+ return PFactory.createComplex(language, real, imag);
} else {
- return factory.createComplex(-real, -imag);
+ return PFactory.createComplex(language, -real, -imag);
}
}
- return specialValue(factory, SPECIAL_VALUES, r, phi);
+ return specialValue(language, SPECIAL_VALUES, r, phi);
}
- return factory.createComplex(r * Math.cos(phi), r * Math.sin(phi));
+ return PFactory.createComplex(language, r * Math.cos(phi), r * Math.sin(phi));
}
}
@@ -446,15 +447,15 @@ static LogNode create() {
@Specialization(guards = "isNoValue(y)")
PComplex doComplexNone(PComplex x, @SuppressWarnings("unused") PNone y,
- @Shared @Cached PythonObjectFactory factory) {
- return log(x, factory);
+ @Bind PythonLanguage language) {
+ return log(x, language);
}
@Specialization
PComplex doComplexComplex(VirtualFrame frame, PComplex x, PComplex y,
@Shared @Cached ComplexBuiltins.DivNode divNode,
- @Shared @Cached PythonObjectFactory factory) {
- return divNode.executeComplex(frame, log(x, factory), log(y, factory));
+ @Bind PythonLanguage language) {
+ return divNode.executeComplex(frame, log(x, language), log(y, language));
}
@Specialization(guards = "isNoValue(yObj)")
@@ -462,9 +463,9 @@ PComplex doGeneral(VirtualFrame frame, Object xObj, @SuppressWarnings("unused")
@Bind("this") Node inliningTarget,
@Shared @Cached CoerceToComplexNode coerceXToComplex,
// unused node to avoid mixing shared and non-shared inlined nodes
- @SuppressWarnings("unsued") @Shared @Cached CoerceToComplexNode coerceYToComplex,
- @Shared @Cached PythonObjectFactory factory) {
- return log(coerceXToComplex.execute(frame, inliningTarget, xObj), factory);
+ @SuppressWarnings("unused") @Shared @Cached CoerceToComplexNode coerceYToComplex,
+ @Bind PythonLanguage language) {
+ return log(coerceXToComplex.execute(frame, inliningTarget, xObj), language);
}
@Specialization(guards = "!isNoValue(yObj)")
@@ -473,20 +474,20 @@ PComplex doGeneral(VirtualFrame frame, Object xObj, Object yObj,
@Shared @Cached CoerceToComplexNode coerceXToComplex,
@Shared @Cached CoerceToComplexNode coerceYToComplex,
@Shared @Cached ComplexBuiltins.DivNode divNode,
- @Shared @Cached PythonObjectFactory factory) {
- PComplex x = log(coerceXToComplex.execute(frame, inliningTarget, xObj), factory);
- PComplex y = log(coerceYToComplex.execute(frame, inliningTarget, yObj), factory);
+ @Bind PythonLanguage language) {
+ PComplex x = log(coerceXToComplex.execute(frame, inliningTarget, xObj), language);
+ PComplex y = log(coerceYToComplex.execute(frame, inliningTarget, yObj), language);
return divNode.executeComplex(frame, x, y);
}
- private PComplex log(PComplex z, PythonObjectFactory factory) {
- PComplex r = specialValue(factory, SPECIAL_VALUES, z.getReal(), z.getImag());
+ private PComplex log(PComplex z, PythonLanguage language) {
+ PComplex r = specialValue(language, SPECIAL_VALUES, z.getReal(), z.getImag());
if (r != null) {
return r;
}
double real = computeRealPart(z.getReal(), z.getImag());
double imag = Math.atan2(z.getImag(), z.getReal());
- return factory.createComplex(real, imag);
+ return PFactory.createComplex(language, real, imag);
}
@TruffleBoundary
@@ -523,17 +524,17 @@ abstract static class Log10Node extends PythonUnaryBuiltinNode {
@Specialization
PComplex doComplex(VirtualFrame frame, PComplex z,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PComplex r = logNode.executeComplex(frame, z, PNone.NO_VALUE);
- return factory.createComplex(r.getReal() / LN_10, r.getImag() / LN_10);
+ return PFactory.createComplex(language, r.getReal() / LN_10, r.getImag() / LN_10);
}
@Specialization
PComplex doGeneral(VirtualFrame frame, Object zObj,
@Bind("this") Node inliningTarget,
@Cached CoerceToComplexNode coerceXToComplex,
- @Shared @Cached PythonObjectFactory factory) {
- return doComplex(frame, coerceXToComplex.execute(frame, inliningTarget, zObj), factory);
+ @Bind PythonLanguage language) {
+ return doComplex(frame, coerceXToComplex.execute(frame, inliningTarget, zObj), language);
}
}
@@ -1103,20 +1104,18 @@ abstract static class IsCloseNode extends PythonBuiltinNode {
@Specialization
static boolean doCCDD(PComplex a, PComplex b, double relTolObj, double absTolObj,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached AbsNode absNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return isClose(inliningTarget, a, b, relTolObj, absTolObj, factory, absNode, raiseNode);
+ return isClose(inliningTarget, a, b, relTolObj, absTolObj, absNode, raiseNode);
}
@Specialization
@SuppressWarnings("unused")
static boolean doCCNN(PComplex a, PComplex b, PNone relTolObj, PNone absTolObj,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached AbsNode absNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return isClose(inliningTarget, a, b, DEFAULT_REL_TOL, DEFAULT_ABS_TOL, factory, absNode, raiseNode);
+ return isClose(inliningTarget, a, b, DEFAULT_REL_TOL, DEFAULT_ABS_TOL, absNode, raiseNode);
}
@Specialization
@@ -1126,17 +1125,16 @@ static boolean doGeneral(VirtualFrame frame, Object aObj, Object bObj, Object re
@Cached CoerceToComplexNode coerceBToComplex,
@Cached PyFloatAsDoubleNode relAsDoubleNode,
@Cached PyFloatAsDoubleNode absAsDoubleNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached AbsNode absNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
PComplex a = coerceAToComplex.execute(frame, inliningTarget, aObj);
PComplex b = coerceBToComplex.execute(frame, inliningTarget, bObj);
double relTol = PGuards.isNoValue(relTolObj) ? DEFAULT_REL_TOL : relAsDoubleNode.execute(frame, inliningTarget, relTolObj);
double absTol = PGuards.isPNone(absTolObj) ? DEFAULT_ABS_TOL : absAsDoubleNode.execute(frame, inliningTarget, absTolObj);
- return isClose(inliningTarget, a, b, relTol, absTol, factory, absNode, raiseNode);
+ return isClose(inliningTarget, a, b, relTol, absTol, absNode, raiseNode);
}
- private static boolean isClose(Node inliningTarget, PComplex a, PComplex b, double relTol, double absTol, PythonObjectFactory factory, AbsNode absNode, PRaiseNode.Lazy raiseNode) {
+ private static boolean isClose(Node inliningTarget, PComplex a, PComplex b, double relTol, double absTol, AbsNode absNode, PRaiseNode.Lazy raiseNode) {
if (relTol < 0.0 || absTol < 0.0) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TOLERANCE_MUST_NON_NEGATIVE);
}
@@ -1147,7 +1145,7 @@ private static boolean isClose(Node inliningTarget, PComplex a, PComplex b, doub
Double.isInfinite(b.getReal()) || Double.isInfinite(b.getImag())) {
return false;
}
- PComplex diff = factory.createComplex(a.getReal() - b.getReal(), a.getImag() - b.getImag());
+ PComplex diff = PFactory.createComplex(PythonLanguage.get(inliningTarget), a.getReal() - b.getReal(), a.getImag() - b.getImag());
double len = absNode.executeDouble(diff);
return len <= absTol || len <= relTol * absNode.executeDouble(b) || len <= relTol * absNode.executeDouble(a);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
index a24567c5a2..21d8ae4162 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
@@ -96,6 +96,7 @@
import java.nio.charset.CodingErrorAction;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -151,7 +152,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.CharsetMapping;
@@ -646,13 +647,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = {"isString(self)"})
static Object encode(Object self, TruffleString encoding, TruffleString errors,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached CastToTruffleStringNode castStr,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
- @Cached CodecsEncodeToJavaBytesNode encode,
- @Cached PythonObjectFactory factory) {
+ @Cached CodecsEncodeToJavaBytesNode encode) {
TruffleString input = castStr.execute(inliningTarget, self);
- PBytes bytes = factory.createBytes(encode.execute(self, encoding, errors));
- return factory.createTuple(new Object[]{bytes, codePointLengthNode.execute(input, TS_ENCODING)});
+ PBytes bytes = PFactory.createBytes(language, encode.execute(self, encoding, errors));
+ return PFactory.createTuple(language, new Object[]{bytes, codePointLengthNode.execute(input, TS_ENCODING)});
}
@Fallback
@@ -683,6 +684,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static Object decode(VirtualFrame frame, Object input, TruffleString encoding, TruffleString errors, boolean finalData,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("input") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@@ -690,8 +692,7 @@ static Object decode(VirtualFrame frame, Object input, TruffleString encoding, T
@Cached NormalizeEncodingNameNode normalizeEncodingNameNode,
@Cached InternErrorAction internErrorAction,
@Cached HandleDecodingErrorNode errorHandler,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = acquireLib.acquireReadonly(input, frame, indirectCallData);
try {
int len = bufferLib.getBufferLength(buffer);
@@ -706,13 +707,13 @@ static Object decode(VirtualFrame frame, Object input, TruffleString encoding, T
try {
decoder = new TruffleDecoder(normalizedEncoding, charset, bytes, len, errorAction);
while (!decoder.decodingStep(finalData)) {
- errorHandler.execute(frame, decoder, internErrorAction.execute(inliningTarget, errors), factory.createBytes(bytes, len));
+ errorHandler.execute(frame, decoder, internErrorAction.execute(inliningTarget, errors), PFactory.createBytes(language, bytes, len));
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw raiseNode.raise(MemoryError);
}
- return factory.createTuple(new Object[]{decoder.getString(), decoder.getInputPosition()});
+ return PFactory.createTuple(language, new Object[]{decoder.getString(), decoder.getInputPosition()});
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -733,26 +734,26 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
Object decodeByteArray(byte[] bytes, TruffleString errors,
- @Shared @Cached PythonObjectFactory factory) {
- return decodeBytes(bytes, bytes.length, errors, factory);
+ @Bind PythonLanguage language) {
+ return decodeBytes(bytes, bytes.length, errors, language);
}
@Specialization(limit = "3")
Object decode(VirtualFrame frame, Object buffer, TruffleString errors,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory) {
+ @CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
try {
int len = bufferLib.getBufferLength(buffer);
- return decodeBytes(bufferLib.getInternalOrCopiedByteArray(buffer), len, errors, factory);
+ return decodeBytes(bufferLib.getInternalOrCopiedByteArray(buffer), len, errors, language);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
}
- private Object decodeBytes(byte[] bytes, int len, TruffleString errors, PythonObjectFactory factory) {
+ private Object decodeBytes(byte[] bytes, int len, TruffleString errors, PythonLanguage language) {
ByteArrayBuffer result = doDecode(bytes, len, errors);
- return factory.createTuple(new Object[]{factory.createBytes(result.getInternalBytes(), result.getLength()), len});
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, result.getInternalBytes(), result.getLength()), len});
}
@TruffleBoundary
@@ -885,8 +886,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
Object encode(PBytes data, @SuppressWarnings("unused") TruffleString errors,
@Bind("this") Node inliningTarget,
- @Cached GetInternalByteArrayNode getInternalByteArrayNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached GetInternalByteArrayNode getInternalByteArrayNode) {
byte[] bytes = getInternalByteArrayNode.execute(inliningTarget, data.getSequenceStorage());
int size = data.getSequenceStorage().length();
ByteArrayBuffer buffer = new ByteArrayBuffer();
@@ -917,8 +918,8 @@ Object encode(PBytes data, @SuppressWarnings("unused") TruffleString errors,
}
}
- return factory.createTuple(new Object[]{
- factory.createBytes(buffer.getByteArray()),
+ return PFactory.createTuple(language, new Object[]{
+ PFactory.createBytes(language, buffer.getByteArray()),
size
});
}
@@ -991,7 +992,7 @@ static PTuple lookup(VirtualFrame frame, Node inliningTarget, TruffleString enco
}
if (hasTruffleEncodingProfile.profile(inliningTarget, hasTruffleEncodingNormalized(normalizedEncoding))) {
PythonModule codecs = context.lookupBuiltinModule(T__CODECS_TRUFFLE);
- result = CodecsTruffleModuleBuiltins.codecsInfo(codecs, encoding, context, context.factory());
+ result = CodecsTruffleModuleBuiltins.codecsInfo(codecs, encoding, context);
} else {
Object[] searchPaths = getSearchPaths(context);
for (Object func : searchPaths) {
@@ -1510,12 +1511,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
Object doIt(VirtualFrame frame, TruffleString str, TruffleString errors, Object mapping,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
- @Cached PyUnicodeEncodeCharmapNode encodeCharmapNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PyUnicodeEncodeCharmapNode encodeCharmapNode) {
int len = codePointLengthNode.execute(str, TS_ENCODING);
- PBytes result = factory.createBytes(encodeCharmapNode.execute(frame, inliningTarget, str, errors, mapping));
- return factory.createTuple(new Object[]{result, len});
+ PBytes result = PFactory.createBytes(language, encodeCharmapNode.execute(frame, inliningTarget, str, errors, mapping));
+ return PFactory.createTuple(language, new Object[]{result, len});
}
}
@@ -1536,8 +1537,7 @@ Object doIt(VirtualFrame frame, Object data, TruffleString errors, Object mappin
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("data") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PyUnicodeDecodeCharmapNode pyUnicodeDecodeCharmapNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PyUnicodeDecodeCharmapNode pyUnicodeDecodeCharmapNode) {
Object dataBuffer = bufferAcquireLib.acquireReadonly(data, frame, context, context.getLanguage(inliningTarget), indirectCallData);
int len;
try {
@@ -1546,7 +1546,7 @@ Object doIt(VirtualFrame frame, Object data, TruffleString errors, Object mappin
bufferLib.release(dataBuffer, frame, indirectCallData);
}
TruffleString result = len == 0 ? T_EMPTY_STRING : pyUnicodeDecodeCharmapNode.execute(frame, data, errors, mapping);
- return factory.createTuple(new Object[]{result, len});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{result, len});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
index ef4afc8854..ffc8d512c0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
@@ -99,7 +99,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -158,15 +158,13 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
}
private static PythonClass initClass(TruffleString className, TruffleString superClassName, BuiltinDescr[] descrs, PythonModule codecsTruffleModule, PythonModule codecsModule,
- PythonLanguage language,
- PythonObjectFactory factory) {
+ PythonLanguage language) {
PythonAbstractClass superClass = (PythonAbstractClass) codecsModule.getAttribute(superClassName);
- return initClass(className, superClass, descrs, codecsTruffleModule, language, factory);
+ return initClass(className, superClass, descrs, codecsTruffleModule, language);
}
- private static PythonClass initClass(TruffleString className, PythonAbstractClass superClass, BuiltinDescr[] descrs, PythonModule codecsTruffleModule, PythonLanguage language,
- PythonObjectFactory factory) {
- PythonClass clazz = factory.createPythonClassAndFixupSlots(language, PythonBuiltinClassType.PythonClass, className, superClass, new PythonAbstractClass[]{superClass});
+ private static PythonClass initClass(TruffleString className, PythonAbstractClass superClass, BuiltinDescr[] descrs, PythonModule codecsTruffleModule, PythonLanguage language) {
+ PythonClass clazz = PFactory.createPythonClassAndFixupSlots(language, className, superClass, new PythonAbstractClass[]{superClass});
for (BuiltinDescr d : descrs) {
PythonUtils.createMethod(language, clazz, d.nodeFactory(), d.enclosingType ? clazz : null, 1);
}
@@ -180,36 +178,37 @@ private record BuiltinDescr(NodeFactory extends PythonBuiltinBaseNode> nodeFac
}
@TruffleBoundary
- static PTuple codecsInfo(PythonModule self, TruffleString encoding, PythonContext context, PythonObjectFactory factory) {
+ static PTuple codecsInfo(PythonModule self, TruffleString encoding, PythonContext context) {
PythonModule codecsModule = AbstractImportNode.importModule(T_CODECS);
CodecsTruffleModuleBuiltins codecsTruffleBuiltins = (CodecsTruffleModuleBuiltins) self.getBuiltins();
if (self.getAttribute(T_TRUFFLE_CODEC) instanceof PNone) {
- initCodecClasses(self, codecsModule, context, factory);
+ initCodecClasses(self, codecsModule, context);
}
+ PythonLanguage language = context.getLanguage();
// encode/decode methods for codecs.CodecInfo
- PythonObject truffleCodec = factory.createPythonObject(codecsTruffleBuiltins.truffleCodecClass);
+ PythonObject truffleCodec = createPythonObject(language, codecsTruffleBuiltins.truffleCodecClass);
truffleCodec.setAttribute(T_ATTR_ENCODING, encoding);
Object encodeMethod = PyObjectGetAttr.executeUncached(truffleCodec, T_ENCODE);
Object decodeMethod = PyObjectGetAttr.executeUncached(truffleCodec, T_DECODE);
// incrementalencoder factory function for codecs.CodecInfo
- PythonObject tie = factory.createPythonObject(codecsTruffleBuiltins.applyEncodingClass);
+ PythonObject tie = createPythonObject(language, codecsTruffleBuiltins.applyEncodingClass);
tie.setAttribute(T_ATTR_FN, codecsTruffleBuiltins.truffleIncrementalEncoderClass);
tie.setAttribute(T_ATTR_ENCODING, encoding);
// incrementaldecoder factory function for codecs.CodecInfo
- PythonObject tid = factory.createPythonObject(codecsTruffleBuiltins.applyEncodingClass);
+ PythonObject tid = createPythonObject(language, codecsTruffleBuiltins.applyEncodingClass);
tid.setAttribute(T_ATTR_FN, codecsTruffleBuiltins.truffleIncrementalDecoderClass);
tid.setAttribute(T_ATTR_ENCODING, encoding);
// streamwriter factory function for codecs.CodecInfo
- PythonObject sr = factory.createPythonObject(codecsTruffleBuiltins.applyEncodingClass);
+ PythonObject sr = createPythonObject(language, codecsTruffleBuiltins.applyEncodingClass);
sr.setAttribute(T_ATTR_FN, codecsTruffleBuiltins.truffleStreamReaderClass);
sr.setAttribute(T_ATTR_ENCODING, encoding);
// streamreader factory function for codecs.CodecInfo
- PythonObject sw = factory.createPythonObject(codecsTruffleBuiltins.applyEncodingClass);
+ PythonObject sw = createPythonObject(language, codecsTruffleBuiltins.applyEncodingClass);
sw.setAttribute(T_ATTR_FN, codecsTruffleBuiltins.truffleStreamWriterClass);
sw.setAttribute(T_ATTR_ENCODING, encoding);
@@ -218,6 +217,10 @@ static PTuple codecsInfo(PythonModule self, TruffleString encoding, PythonContex
return (PTuple) CallVarargsMethodNode.getUncached().execute(null, codecInfoClass, new Object[]{}, createCodecInfoArgs(encoding, encodeMethod, decodeMethod, tie, tid, sr, sw));
}
+ private static PythonObject createPythonObject(PythonLanguage language, PythonClass cls) {
+ return PFactory.createPythonObject(language, cls, cls.getInstanceShape());
+ }
+
private static PKeyword[] createCodecInfoArgs(TruffleString encoding, Object encodeMethod, Object decodeMethod, PythonObject tie, PythonObject tid, PythonObject sr, PythonObject sw) {
return new PKeyword[]{
new PKeyword(T_NAME, encoding),
@@ -234,7 +237,7 @@ private static PKeyword[] createCodecInfoArgs(TruffleString encoding, Object enc
* create classes based on types declared in lib/3/codes.py
*/
// @formatter:off
- private static void initCodecClasses(PythonModule codecsTruffleModule, PythonModule codecsModule, PythonContext context, PythonObjectFactory factory) {
+ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonModule codecsModule, PythonContext context) {
// TODO - the incremental codec and reader/writer won't work well with stateful
// encodings, like some of the CJK encodings
@@ -250,7 +253,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
new BuiltinDescr[]{
new BuiltinDescr(EncodeNodeFactory.getInstance(), false),
new BuiltinDescr(CodecDecodeNodeFactory.getInstance(), true)},
- codecsTruffleModule, language, factory);
+ codecsTruffleModule, language);
// class TruffleIncrementalEncoder(codecs.IncrementalEncoder):
// def __init__(self, encoding, *args, **kwargs):
@@ -262,7 +265,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
new BuiltinDescr[]{
new BuiltinDescr(CodecInitNodeFactory.getInstance(), false),
new BuiltinDescr(IncrementalEncodeNodeFactory.getInstance(), true)},
- codecsTruffleModule, codecsModule, language, factory);
+ codecsTruffleModule, codecsModule, language);
// class TruffleIncrementalDecoder(codecs.BufferedIncrementalDecoder):
// def __init__(self, encoding, *args, **kwargs):
@@ -274,7 +277,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
new BuiltinDescr[]{
new BuiltinDescr(CodecInitNodeFactory.getInstance(), false),
new BuiltinDescr(IncrementalDecodeNodeFactory.getInstance(), true)},
- codecsTruffleModule, codecsModule, language, factory);
+ codecsTruffleModule, codecsModule, language);
// class TruffleStreamWriter(codecs.StreamWriter):
// def __init__(self, encoding, *args, **kwargs):
@@ -286,7 +289,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
new BuiltinDescr[]{
new BuiltinDescr(CodecInitNodeFactory.getInstance(), false),
new BuiltinDescr(EncodeNodeFactory.getInstance(), true)},
- codecsTruffleModule, codecsModule, language, factory);
+ codecsTruffleModule, codecsModule, language);
// class TruffleStreamReader(codecs.StreamReader):
// def __init__(self, encoding, *args, **kwargs):
@@ -298,7 +301,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
new BuiltinDescr[]{
new BuiltinDescr(CodecInitNodeFactory.getInstance(), false),
new BuiltinDescr(StreamDecodeNodeFactory.getInstance(), true)},
- codecsTruffleModule, codecsModule, language, factory);
+ codecsTruffleModule, codecsModule, language);
// serves as factory function for CodecInfo-s incrementalencoder/decode and streamwriter/reader
// class apply_encoding:
@@ -306,7 +309,7 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
// return self.fn(self.encoding, *args, **kwargs)
codecsTruffleBuiltins.applyEncodingClass = initClass(T_APPLY_ENCODING, context.lookupType(PythonBuiltinClassType.PythonObject),
new BuiltinDescr[]{new BuiltinDescr(CallApplyNodeFactory.getInstance(), false)},
- codecsTruffleModule, language, factory);
+ codecsTruffleModule, language);
}
// @formatter:on
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
index 801772f68c..934e08654b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -59,6 +60,7 @@
import com.oracle.graal.python.builtins.objects.deque.PDequeIter;
import com.oracle.graal.python.builtins.objects.dict.PDefaultDict;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyNumberIndexNode;
import com.oracle.graal.python.nodes.BuiltinNames;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -69,8 +71,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -92,19 +93,12 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateNodeFactory
abstract static class DequeNode extends PythonVarargsBuiltinNode {
- @Override
- public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
- if (arguments.length >= 1) {
- return doGeneric(arguments[0], null, null);
- }
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw VarargsBuiltinDirectInvocationNotSupported.INSTANCE;
- }
-
@Specialization
@SuppressWarnings("unused")
- PDeque doGeneric(Object cls, Object[] args, PKeyword[] kwargs) {
- return factory().createDeque(cls);
+ PDeque doGeneric(Object cls, Object[] args, PKeyword[] kwargs,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createDeque(language, cls, getInstanceShape.execute(cls));
}
}
@@ -122,12 +116,12 @@ static PDequeIter doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Obje
@Cached PyNumberIndexNode toIndexNode,
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
@Cached DequeIterNextNode getNextNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!dequeProfile.profile(inliningTarget, deque instanceof PDeque)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
}
- PDequeIter dequeIter = factory.createDequeIter((PDeque) deque);
+ PDequeIter dequeIter = PFactory.createDequeIter(language, (PDeque) deque);
if (indexNoneProfile.profile(inliningTarget, indexObj != PNone.NO_VALUE)) {
int index = castToJavaIntExactNode.execute(inliningTarget, toIndexNode.execute(frame, inliningTarget, indexObj));
for (int i = 0; i < index; i++) {
@@ -151,12 +145,12 @@ static PDequeIter doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Obje
@Cached PyNumberIndexNode toIndexNode,
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
@Cached DequeIterNextNode getNextNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!dequeProfile.profile(inliningTarget, deque instanceof PDeque)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
}
- PDequeIter dequeIter = factory.createDequeRevIter((PDeque) deque);
+ PDequeIter dequeIter = PFactory.createDequeRevIter(language, (PDeque) deque);
if (indexNoneProfile.profile(inliningTarget, indexObj != PNone.NO_VALUE)) {
int index = castToJavaIntExactNode.execute(inliningTarget, toIndexNode.execute(frame, inliningTarget, indexObj));
for (int i = 0; i < index; i++) {
@@ -174,8 +168,9 @@ abstract static class DefaultDictNode extends PythonVarargsBuiltinNode {
@Specialization
@SuppressWarnings("unused")
PDefaultDict doGeneric(Object cls, Object[] args, PKeyword[] kwargs,
- @Cached PythonObjectFactory factory) {
- return factory.createDefaultDict(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createDefaultDict(language, cls, getInstanceShape.execute(cls));
}
}
@@ -190,9 +185,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- Object construct(Object cls, int index, Object doc,
- @Cached PythonObjectFactory factory) {
- return factory.createTupleGetter(cls, index, doc);
+ Object construct(@SuppressWarnings("unused") Object cls, int index, Object doc,
+ @Bind PythonLanguage language) {
+ return PFactory.createTupleGetter(language, index, doc);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
index 23dc550b09..33c5ff36ea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -60,7 +61,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -103,11 +104,11 @@ protected ArgumentClinicProvider getArgumentClinic() {
protected static Object constructDef(@SuppressWarnings("unused") Object cls, TruffleString name, Object def,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile noValueProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (noValueProfile.profile(inliningTarget, isNoValue(def))) {
def = PContextVar.NO_DEFAULT;
}
- return factory.createContextVar(name, def);
+ return PFactory.createContextVar(language, name, def);
}
}
@@ -116,8 +117,8 @@ protected static Object constructDef(@SuppressWarnings("unused") Object cls, Tru
public abstract static class ContextNode extends PythonUnaryBuiltinNode {
@Specialization
static Object construct(@SuppressWarnings("unused") Object cls,
- @Cached PythonObjectFactory factory) {
- return factory.createContextVarsContext();
+ @Bind PythonLanguage language) {
+ return PFactory.createContextVarsContext(language);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ErrnoModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ErrnoModuleBuiltins.java
index 2972ac9617..1d9a8d7fdf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ErrnoModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ErrnoModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
import com.oracle.graal.python.lib.PyObjectHashNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.strings.TruffleString;
@@ -75,7 +76,7 @@ public void initialize(Python3Core core) {
}
// publish the dictionary with mapping code -> string name
- PDict errorCode = core.factory().createDict(storage);
+ PDict errorCode = PFactory.createDict(core.getLanguage(), storage);
addBuiltinConstant("errorcode", errorCode);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
index 6e20c9bea8..c20cc0a987 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -79,8 +79,9 @@
import com.oracle.graal.python.runtime.PosixConstants.IntConstant;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
+import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -198,7 +199,8 @@ abstract static class IoctlNode extends PythonClinicBuiltinNode {
@Specialization
Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutateArg,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@@ -209,7 +211,6 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
@Cached GilNode gilNode,
@Cached PRaiseNode.Lazy raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached SysModuleBuiltins.AuditNode auditNode) {
auditNode.audit(inliningTarget, "fcnt.ioctl", fd, request, arg);
@@ -260,7 +261,7 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
if (writable && mutateArg) {
return ret;
} else {
- return factory.createBytes(ioctlArg, len);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}
} finally {
if (writeBack) {
@@ -289,7 +290,7 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
byte[] ioctlArg = new byte[len + 1];
copyToByteArrayNode.execute(stringArg, 0, ioctlArg, 0, len, utf8);
callIoctlBytes(frame, inliningTarget, fd, request, ioctlArg, true, posixLib, gilNode, constructAndRaiseNode);
- return factory.createBytes(ioctlArg, len);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}
// int arg
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GcModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GcModuleBuiltins.java
index c0664e86e4..d4c4585762 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GcModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GcModuleBuiltins.java
@@ -29,6 +29,7 @@
import java.lang.management.ManagementFactory;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -65,7 +66,7 @@
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -105,7 +106,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant("DEBUG_UNCOLLECTABLE", DEBUG_UNCOLLECTABLE);
addBuiltinConstant("DEBUG_SAVEALL", DEBUG_SAVEALL);
addBuiltinConstant("DEBUG_LEAK", DEBUG_LEAK);
- addBuiltinConstant(CALLBACKS, core.factory().createList());
+ addBuiltinConstant(CALLBACKS, PFactory.createList(core.getLanguage()));
super.initialize(core);
}
@@ -127,7 +128,7 @@ static long collect(VirtualFrame frame, PythonModule self, @SuppressWarnings("un
@Cached PyObjectGetAttr getAttr,
@Cached PyObjectGetIter getIter,
@Cached(neverDefault = true) PyIterNextNode next,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached CallBinaryMethodNode call,
@Cached GilNode gil,
@Cached GetThreadStateNode getThreadStateNode,
@@ -141,7 +142,7 @@ static long collect(VirtualFrame frame, PythonModule self, @SuppressWarnings("un
long res = 0;
if (cb != null) {
phase = START;
- info = factory.createDict(new PKeyword[]{
+ info = PFactory.createDict(language, new PKeyword[]{
new PKeyword(GENERATION, 2),
new PKeyword(COLLECTED, 0),
new PKeyword(UNCOLLECTABLE, 0),
@@ -161,7 +162,7 @@ static long collect(VirtualFrame frame, PythonModule self, @SuppressWarnings("un
}
if (phase != null) {
phase = STOP;
- info = factory.createDict(new PKeyword[]{
+ info = PFactory.createDict(language, new PKeyword[]{
new PKeyword(GENERATION, 2),
new PKeyword(COLLECTED, freedMemory),
new PKeyword(UNCOLLECTABLE, 0),
@@ -287,7 +288,7 @@ static PTuple count() {
count += cc;
}
}
- return PythonContext.get(null).factory().createTuple(new Object[]{count, 0, 0});
+ return PFactory.createTuple(PythonLanguage.get(null), new Object[]{count, 0, 0});
}
}
@@ -313,7 +314,7 @@ abstract static class GcGetReferentsNode extends PythonBuiltinNode {
static PList getReferents(@SuppressWarnings("unused") Object objects) {
// TODO: this is just a dummy implementation; for native objects, this should actually
// use 'tp_traverse'
- return PythonContext.get(null).factory().createList();
+ return PFactory.createList(PythonLanguage.get(null));
}
}
@@ -324,7 +325,7 @@ abstract static class GcGetReferrersNode extends PythonBuiltinNode {
@TruffleBoundary
static PList doGeneric(@SuppressWarnings("unused") Object objects) {
// dummy implementation
- return PythonContext.get(null).factory().createList();
+ return PFactory.createList(PythonLanguage.get(null));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
index 7fbf2ab87f..ed28573a80 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.Collections;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,6 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.PythonUtils.PrototypeNodeFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -135,11 +137,12 @@ public Object execute(VirtualFrame frame) {
@TruffleBoundary
static PBuiltinMethod createFunction(Python3Core core, PythonModule module) {
Builtin builtin = NotAvailable.class.getAnnotation(Builtin.class);
- RootCallTarget callTarget = core.getLanguage().createCachedCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, NotAvailable.NODE_FACTORY, false), NotAvailable.class,
+ PythonLanguage language = core.getLanguage();
+ RootCallTarget callTarget = language.createCachedCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, NotAvailable.NODE_FACTORY, false), NotAvailable.class,
builtin.name());
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
TruffleString name = PythonUtils.toTruffleStringUncached(builtin.name());
- PBuiltinFunction fun = core.factory().createBuiltinFunction(name, null, 0, flags, callTarget);
- return core.factory().createBuiltinMethod(module, fun);
+ PBuiltinFunction fun = PFactory.createBuiltinFunction(language, name, null, 0, flags, callTarget);
+ return PFactory.createBuiltinMethod(language, module, fun);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
index e6a9ceded9..339859f6a8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
@@ -78,6 +78,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -124,7 +125,7 @@ public void initialize(Python3Core core) {
@Override
public void postInitialize(Python3Core core) {
PythonModule module = core.lookupBuiltinModule(T_HPY_UNIVERSAL);
- module.setAttribute(T___ALL__, core.factory().createTuple(ALL_ARRAY));
+ module.setAttribute(T___ALL__, PFactory.createTuple(core.getLanguage(), ALL_ARRAY));
}
@Builtin(name = "load", parameterNames = {"name", "path", "spec", "debug", "mode"}, minNumOfPositionalArgs = 3)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
index 1e20104ca1..5bc287952d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -83,11 +83,6 @@
import java.util.List;
import java.util.logging.Level;
-import com.oracle.graal.python.nodes.arrow.ArrowArray;
-import com.oracle.graal.python.nodes.arrow.ArrowSchema;
-import com.oracle.graal.python.nodes.arrow.capsule.CreateArrowPyCapsuleNode;
-import com.oracle.graal.python.nodes.arrow.vector.VectorToArrowArrayNode;
-import com.oracle.graal.python.nodes.arrow.vector.VectorToArrowSchemaNode;
import org.graalvm.nativeimage.ImageInfo;
import com.oracle.graal.python.PythonLanguage;
@@ -141,6 +136,11 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.arrow.ArrowArray;
+import com.oracle.graal.python.nodes.arrow.ArrowSchema;
+import com.oracle.graal.python.nodes.arrow.capsule.CreateArrowPyCapsuleNode;
+import com.oracle.graal.python.nodes.arrow.vector.VectorToArrowArrayNode;
+import com.oracle.graal.python.nodes.arrow.vector.VectorToArrowSchemaNode;
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
import com.oracle.graal.python.nodes.call.CallNode;
@@ -166,7 +166,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonExitException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.NativePrimitiveSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
@@ -274,7 +274,7 @@ public void postInitialize(Python3Core core) {
mod.setAttribute(tsLiteral("capi_home"), capiHome);
mod.setAttribute(tsLiteral("jni_home"), context.getJNIHome());
Object[] arr = convertToObjectArray(PythonOptions.getExecutableList(context));
- PList executableList = PythonObjectFactory.getUncached().createList(arr);
+ PList executableList = PFactory.createList(language, arr);
mod.setAttribute(tsLiteral("executable_list"), executableList);
mod.setAttribute(tsLiteral("venvlauncher_command"), context.getOption(PythonOptions.VenvlauncherCommand));
mod.setAttribute(tsLiteral("ForeignType"), core.lookupType(PythonBuiltinClassType.ForeignObject));
@@ -441,15 +441,15 @@ public abstract static class ReadFileNode extends PythonUnaryBuiltinNode {
@Specialization
PBytes doString(VirtualFrame frame, Object filenameObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Cached TruffleString.EqualNode eqNode,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
TruffleString filename = castToTruffleStringNode.execute(inliningTarget, filenameObj);
- TruffleFile file = getContext().getPublicTruffleFileRelaxed(filename, PythonLanguage.T_DEFAULT_PYTHON_EXTENSIONS);
+ TruffleFile file = context.getPublicTruffleFileRelaxed(filename, PythonLanguage.T_DEFAULT_PYTHON_EXTENSIONS);
byte[] bytes = file.readAllBytes();
- return factory.createBytes(bytes);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), bytes);
} catch (Exception ex) {
ErrorAndMessagePair errAndMsg = OSErrorEnum.fromException(ex, eqNode);
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, errAndMsg.oserror.getNumber(), errAndMsg.message);
@@ -543,8 +543,8 @@ public abstract static class BuiltinNode extends PythonUnaryBuiltinNode {
@Specialization
public Object doIt(VirtualFrame frame, PFunction func,
@Bind("this") Node inliningTarget,
- @Cached PyObjectGetItem getItem,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @Cached PyObjectGetItem getItem) {
PFunction builtinFunc = convertToBuiltin(func);
PythonObject globals = func.getGlobals();
PythonModule builtinModule;
@@ -552,10 +552,10 @@ public Object doIt(VirtualFrame frame, PFunction func,
builtinModule = (PythonModule) globals;
} else {
TruffleString moduleName = (TruffleString) getItem.execute(frame, inliningTarget, globals, T___NAME__);
- builtinModule = getContext().lookupBuiltinModule(moduleName);
+ builtinModule = context.lookupBuiltinModule(moduleName);
assert builtinModule != null;
}
- return factory.createBuiltinMethod(builtinModule, builtinFunc);
+ return PFactory.createBuiltinMethod(context.getLanguage(inliningTarget), builtinModule, builtinFunc);
}
@TruffleBoundary
@@ -634,8 +634,8 @@ static Tool forBinary(String name, Object... targets) {
@Specialization
@TruffleBoundary
Object getToolPath() {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- Env env = getContext().getEnv();
+ PythonContext context = getContext();
+ Env env = context.getEnv();
LanguageInfo llvmInfo = env.getInternalLanguages().get(J_LLVM_LANGUAGE);
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
List toolchainPaths = toolchain.getPaths("PATH");
@@ -658,12 +658,12 @@ Object getToolPath() {
}
}
if (path != null) {
- storage.putUncached(toTruffleStringUncached(path), factory.createTuple(tool.targets));
+ storage.putUncached(toTruffleStringUncached(path), PFactory.createTuple(context.getLanguage(), tool.targets));
} else {
LOGGER.fine("Could not locate tool " + tool.name);
}
}
- return factory.createDict(storage);
+ return PFactory.createDict(context.getLanguage(), storage);
}
}
@@ -692,7 +692,8 @@ public abstract static class GetToolchainPathsNode extends PythonUnaryBuiltinNod
@Specialization
@TruffleBoundary
protected Object getToolPath(TruffleString tool) {
- Env env = getContext().getEnv();
+ PythonContext context = getContext();
+ Env env = context.getEnv();
LanguageInfo llvmInfo = env.getInternalLanguages().get(J_LLVM_LANGUAGE);
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
List toolPaths = toolchain.getPaths(tool.toJavaStringUncached());
@@ -703,7 +704,7 @@ protected Object getToolPath(TruffleString tool) {
for (int i = 0; i < pathNames.length; i++) {
pathNames[i] = toTruffleStringUncached(toolPaths.get(i).toString().replace("\\", "/"));
}
- return PythonObjectFactory.getUncached().createList(pathNames);
+ return PFactory.createList(context.getLanguage(), pathNames);
}
}
@@ -727,8 +728,8 @@ public abstract static class DetermineSystemToolchain extends PythonUnaryBuiltin
@Specialization
static PDict doGeneric(@SuppressWarnings("unused") Object unused,
- @Cached PythonObjectFactory factory) {
- return factory.createDict(fromToolchain());
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language, fromToolchain());
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
index a8de465698..ff40c6724b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
@@ -117,7 +117,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.RootCallTarget;
@@ -260,8 +260,6 @@ public abstract static class GetMagic extends PythonBuiltinNode {
MAGIC_NUMBER_BYTES[3] = '\n';
}
- @Child PythonObjectFactory factory = PythonObjectFactory.create(); // GR-47032
-
@Specialization(guards = "isSingleContext()")
PBytes runCachedSingleContext(
@Cached(value = "getMagicNumberPBytes()", weak = true) PBytes magicBytes) {
@@ -269,12 +267,13 @@ PBytes runCachedSingleContext(
}
@Specialization(replaces = "runCachedSingleContext")
- PBytes run() {
- return factory.createBytes(MAGIC_NUMBER_BYTES);
+ PBytes run(
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, MAGIC_NUMBER_BYTES);
}
protected PBytes getMagicNumberPBytes() {
- return factory.createBytes(MAGIC_NUMBER_BYTES);
+ return PFactory.createBytes(PythonLanguage.get(this), MAGIC_NUMBER_BYTES);
}
}
@@ -540,6 +539,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object run(VirtualFrame frame, TruffleString name, Object dataObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached TruffleString.EqualNode equalNode,
@@ -558,7 +558,7 @@ static Object run(VirtualFrame frame, TruffleString name, Object dataObj,
raiseFrozenError(frame, FROZEN_INVALID, name, constructAndRaiseNode.get(inliningTarget));
}
} else {
- FrozenResult result = findFrozen(PythonContext.get(inliningTarget), name, equalNode);
+ FrozenResult result = findFrozen(context, name, equalNode);
FrozenStatus status = result.status;
info = result.info;
raiseFrozenError(frame, status, name, constructAndRaiseNode.get(inliningTarget));
@@ -567,7 +567,7 @@ static Object run(VirtualFrame frame, TruffleString name, Object dataObj,
Object code = null;
try {
- code = MarshalModuleBuiltins.Marshal.load(info.data, info.size);
+ code = MarshalModuleBuiltins.Marshal.load(context, info.data, info.size);
} catch (MarshalError | NumberFormatException e) {
raiseFrozenError(frame, FROZEN_INVALID, name, constructAndRaiseNode.get(inliningTarget));
}
@@ -603,12 +603,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- Object run(VirtualFrame frame, TruffleString name, boolean withData,
+ static Object run(VirtualFrame frame, TruffleString name, boolean withData,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached MemoryViewNode memoryViewNode,
@Cached TruffleString.EqualNode equalNode,
- @Cached PConstructAndRaiseNode constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
- FrozenResult result = findFrozen(getContext(), name, equalNode);
+ @Cached PConstructAndRaiseNode constructAndRaiseNode) {
+ FrozenResult result = findFrozen(context, name, equalNode);
FrozenStatus status = result.status;
FrozenInfo info = result.info;
@@ -624,7 +625,7 @@ Object run(VirtualFrame frame, TruffleString name, boolean withData,
PMemoryView data = null;
if (withData) {
- data = memoryViewNode.execute(frame, factory.createBytes(info.data));
+ data = memoryViewNode.execute(frame, PFactory.createBytes(context.getLanguage(inliningTarget), info.data));
}
Object[] returnValues = new Object[]{
@@ -633,7 +634,7 @@ Object run(VirtualFrame frame, TruffleString name, boolean withData,
info.origName == null ? PNone.NONE : info.origName
};
- return factory.createTuple(returnValues);
+ return PFactory.createTuple(context.getLanguage(inliningTarget), returnValues);
}
}
@@ -689,13 +690,13 @@ public static PythonModule importFrozenModuleObject(Python3Core core, TruffleStr
}
}
- PCode code = (PCode) MarshalModuleBuiltins.Marshal.load(info.data, info.size);
+ PCode code = (PCode) MarshalModuleBuiltins.Marshal.load(core.getContext(), info.data, info.size);
- PythonModule module = globals == null ? core.factory().createPythonModule(name) : globals;
+ PythonModule module = globals == null ? PFactory.createPythonModule(core.getLanguage(), name) : globals;
if (info.isPackage) {
/* Set __path__ to the empty list */
- WriteAttributeToPythonObjectNode.getUncached().execute(module, T___PATH__, core.factory().createList());
+ WriteAttributeToPythonObjectNode.getUncached().execute(module, T___PATH__, PFactory.createList(core.getLanguage()));
}
RootCallTarget callTarget = CodeNodes.GetCodeCallTargetNode.executeUncached(code);
@@ -767,10 +768,10 @@ public abstract static class SourceHashNode extends PythonBinaryClinicBuiltinNod
@Specialization
static PBytes run(long magicNumber, Object sourceBuffer,
@Bind("this") Node inliningTarget,
- @Cached BytesNodes.HashBufferNode hashBufferNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached BytesNodes.HashBufferNode hashBufferNode) {
long sourceHash = hashBufferNode.execute(inliningTarget, sourceBuffer);
- return factory.createBytes(computeHash(magicNumber, sourceHash));
+ return PFactory.createBytes(language, computeHash(magicNumber, sourceHash));
}
@TruffleBoundary
@@ -814,8 +815,8 @@ public Object run(PCode code, TruffleString path) {
public abstract static class ExtensionSuffixesNode extends PythonBuiltinNode {
@Specialization
Object run(
- @Cached PythonObjectFactory factory) {
- return factory.createList(new Object[]{PythonContext.get(this).getSoAbi(), T_EXT_SO, T_EXT_PYD});
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language, new Object[]{PythonContext.get(this).getSoAbi(), T_EXT_SO, T_EXT_PYD});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
index c2182724a6..c7b724608d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
@@ -34,7 +34,6 @@
import static com.oracle.graal.python.nodes.ErrorMessages.MUST_BE_NON_NEGATIVE;
import static com.oracle.graal.python.nodes.ErrorMessages.NUMBER_IS_REQUIRED;
import static com.oracle.graal.python.nodes.ErrorMessages.STEP_FOR_ISLICE_MUST_BE;
-import static com.oracle.graal.python.nodes.ErrorMessages.S_EXPECTED_GOT_P;
import static com.oracle.graal.python.nodes.ErrorMessages.S_FOR_ISLICE_MUST_BE;
import static com.oracle.graal.python.nodes.ErrorMessages.S_MUST_BE_S;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___COPY__;
@@ -42,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -74,7 +74,6 @@
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
import com.oracle.graal.python.lib.PyCallableCheckNode;
-import com.oracle.graal.python.lib.PyLongAsIntNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
import com.oracle.graal.python.lib.PyObjectGetIter;
@@ -94,7 +93,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -124,59 +123,19 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateNodeFactory
public abstract static class AccumulateNode extends PythonBuiltinNode {
- @Specialization(guards = "isTypeNode.execute(inliningTarget, cls)")
- protected static PAccumulate construct(VirtualFrame frame, Object cls, Object iterable, @SuppressWarnings("unused") PNone func, @SuppressWarnings("unused") PNone initial,
- @Bind("this") Node inliningTarget,
- @Shared("getIter") @Cached PyObjectGetIter getIter,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return create(frame, inliningTarget, cls, iterable, null, null, getIter, factory);
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "!isNone(initial)"})
- protected static PAccumulate construct(VirtualFrame frame, Object cls, Object iterable, @SuppressWarnings("unused") PNone func, Object initial,
- @Bind("this") Node inliningTarget,
- @Shared("getIter") @Cached PyObjectGetIter getIter,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return create(frame, inliningTarget, cls, iterable, null, initial, getIter, factory);
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "!isNone(func)"})
- protected static PAccumulate construct(VirtualFrame frame, Object cls, Object iterable, Object func, @SuppressWarnings("unused") PNone initial,
- @Bind("this") Node inliningTarget,
- @Shared("getIter") @Cached PyObjectGetIter getIter,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return create(frame, inliningTarget, cls, iterable, func, null, getIter, factory);
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "!isNone(func)", "!isNone(initial)"})
+ @Specialization
protected static PAccumulate construct(VirtualFrame frame, Object cls, Object iterable, Object func, Object initial,
@Bind("this") Node inliningTarget,
- @Shared("getIter") @Cached PyObjectGetIter getIter,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return create(frame, inliningTarget, cls, iterable, func, initial, getIter, factory);
- }
-
- private static PAccumulate create(VirtualFrame frame, Node inliningTarget, Object cls, Object iterable, Object func, Object initial, PyObjectGetIter getIter, PythonObjectFactory factory) {
- PAccumulate self = factory.createAccumulate(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
+ @Cached PyObjectGetIter getIter) {
+ PAccumulate self = PFactory.createAccumulate(language, cls, getInstanceShape.execute(cls));
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
self.setFunc(func instanceof PNone ? null : func);
self.setTotal(null);
self.setInitial(initial instanceof PNone ? null : initial);
return self;
}
-
- @Specialization(guards = "!isTypeNode.execute(inliningTarget, cls)")
- @SuppressWarnings("unused")
- static Object notype(Object cls, Object iterable, Object func, Object initial,
- @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
- }
}
@Builtin(name = "combinations", minNumOfPositionalArgs = 3, constructsClass = PythonBuiltinClassType.PCombinations, parameterNames = {"cls", "iterable",
@@ -200,7 +159,8 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
@Cached LoopConditionProfile indicesLoopProfile,
@Cached InlinedConditionProfile wrongTypeProfile,
@Cached InlinedConditionProfile negativeProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -209,7 +169,7 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
}
- PCombinations self = factory.createCombinations(cls);
+ PCombinations self = PFactory.createCombinations(language, cls, getInstanceShape.execute(cls));
self.setPool(toArrayNode.execute(frame, iterable));
int[] indices = new int[r];
@@ -247,7 +207,8 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
@Cached ToArrayNode toArrayNode,
@Cached InlinedConditionProfile wrongTypeProfile,
@Cached InlinedConditionProfile negativeProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -255,7 +216,7 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
if (negativeProfile.profile(inliningTarget, r < 0)) {
throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
}
- PCombinationsWithReplacement self = factory.createCombinationsWithReplacement(cls);
+ PCombinationsWithReplacement self = PFactory.createCombinationsWithReplacement(language, cls, getInstanceShape.execute(cls));
self.setPool(toArrayNode.execute(frame, iterable));
self.setR(r);
@@ -283,12 +244,13 @@ static PCompress construct(VirtualFrame frame, Object cls, Object data, Object s
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
- PCompress self = factory.createCompress(cls);
+ PCompress self = PFactory.createCompress(language, cls, getInstanceShape.execute(cls));
self.setData(getIter.execute(frame, inliningTarget, data));
self.setSelectors(getIter.execute(frame, inliningTarget, selectors));
return self;
@@ -316,7 +278,8 @@ static PCycle construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -328,7 +291,7 @@ static PCycle construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "cycle", 1);
}
Object iterable = args[0];
- PCycle self = factory.createCycle(cls);
+ PCycle self = PFactory.createCycle(language, cls, getInstanceShape.execute(cls));
self.setSaved(new ArrayList<>());
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
self.setIndex(0);
@@ -348,7 +311,8 @@ static PDropwhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -361,7 +325,7 @@ static PDropwhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
}
Object predicate = args[0];
Object iterable = args[1];
- PDropwhile self = factory.createDropwhile(cls);
+ PDropwhile self = PFactory.createDropwhile(language, cls, getInstanceShape.execute(cls));
self.setPredicate(predicate);
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
self.setDoneDropping(false);
@@ -381,7 +345,8 @@ static PFilterfalse construct(VirtualFrame frame, Object cls, Object[] args, PKe
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -394,7 +359,7 @@ static PFilterfalse construct(VirtualFrame frame, Object cls, Object[] args, PKe
}
Object func = args[0];
Object sequence = args[1];
- PFilterfalse self = factory.createFilterfalse(cls);
+ PFilterfalse self = PFactory.createFilterfalse(language, cls, getInstanceShape.execute(cls));
self.setFunc(PGuards.isPNone(func) ? null : func);
self.setSequence(getIter.execute(frame, inliningTarget, sequence));
return self;
@@ -431,12 +396,13 @@ static PGroupBy construct(VirtualFrame frame, Object cls, Object iterable, Objec
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
- PGroupBy self = factory.createGroupBy(cls);
+ PGroupBy self = PFactory.createGroupBy(language, cls, getInstanceShape.execute(cls));
self.setKeyFunc(PGuards.isNone(key) ? null : key);
self.setIt(getIter.execute(frame, inliningTarget, iterable));
return self;
@@ -452,7 +418,7 @@ static PGrouper construct(Object cls, Object parent, Object tgtKey,
@Cached InlinedConditionProfile wrongTypeProfile,
@Cached InlinedConditionProfile isPGroupByProfile,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -460,7 +426,7 @@ static PGrouper construct(Object cls, Object parent, Object tgtKey,
if (!isPGroupByProfile.profile(inliningTarget, parent instanceof PGroupBy)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INCORRECT_USAGE_OF_INTERNAL_GROUPER);
}
- return factory.createGrouper((PGroupBy) parent, tgtKey);
+ return PFactory.createGrouper(language, (PGroupBy) parent, tgtKey);
}
}
@@ -475,7 +441,8 @@ static PTakewhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -488,7 +455,7 @@ static PTakewhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
}
Object predicate = args[0];
Object iterable = args[1];
- PTakewhile self = factory.createTakewhile(cls);
+ PTakewhile self = PFactory.createTakewhile(language, cls, getInstanceShape.execute(cls));
self.setPredicate(predicate);
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
return self;
@@ -514,8 +481,8 @@ static Object negativeN(Object iterable, int n,
@SuppressWarnings("unused")
@Specialization(guards = "n == 0")
static Object zeroN(Object iterable, int n,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, PythonUtils.EMPTY_OBJECT_ARRAY);
}
@Specialization(guards = "n > 0")
@@ -526,14 +493,14 @@ static Object tee(VirtualFrame frame, Object iterable, int n,
@Cached PyCallableCheckNode callableCheckNode,
@Cached CallVarargsMethodNode callNode,
@Cached InlinedBranchProfile notCallableProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object it = iterNode.execute(frame, iterable, PNone.NO_VALUE);
Object copyCallable = getAttrNode.execute(frame, inliningTarget, it, T___COPY__);
if (!callableCheckNode.execute(inliningTarget, copyCallable)) {
notCallableProfile.enter(inliningTarget);
// as in Tee.__NEW__()
- PTeeDataObject dataObj = factory.createTeeDataObject(it);
- it = factory.createTee(dataObj, 0);
+ PTeeDataObject dataObj = PFactory.createTeeDataObject(language, it);
+ it = PFactory.createTee(language, dataObj, 0);
}
// return tuple([it] + [it.__copy__() for i in range(1, n)])
@@ -544,7 +511,7 @@ static Object tee(VirtualFrame frame, Object iterable, int n,
for (int i = 1; i < n; i++) {
tupleObjs[i] = callNode.execute(frame, copyCallable, PythonUtils.EMPTY_OBJECT_ARRAY, PKeyword.EMPTY_KEYWORDS);
}
- return factory.createTuple(tupleObjs);
+ return PFactory.createTuple(language, tupleObjs);
}
}
@@ -558,12 +525,12 @@ PTeeDataObject construct(Object cls, Object[] arguments, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
@Cached IsTypeNode isTypeNode,
@Cached InlinedBranchProfile errorProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (!isTypeNode.execute(inliningTarget, cls)) {
errorProfile.enter(inliningTarget);
throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
- return factory.createTeeDataObject();
+ return PFactory.createTeeDataObject(language);
}
}
@@ -591,7 +558,8 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, Object
@Cached InlinedLoopConditionProfile indicesLoopProfile,
@Cached InlinedLoopConditionProfile cyclesLoopProfile,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -612,7 +580,7 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, Object
throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
}
}
- PPermutations self = factory.createPermutations(cls);
+ PPermutations self = PFactory.createPermutations(language, cls, getInstanceShape.execute(cls));
self.setPool(pool);
self.setR(r);
int n = pool.length;
@@ -664,8 +632,9 @@ static Object constructNoneRepeat(VirtualFrame frame, Object cls, Object[] itera
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached ToArrayNode toArrayNode,
@SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PProduct self = factory.createProduct(cls);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PProduct self = PFactory.createProduct(language, cls, getInstanceShape.execute(cls));
constructOneRepeat(frame, self, iterables, toArrayNode);
return self;
}
@@ -675,8 +644,9 @@ static Object constructOneRepeat(VirtualFrame frame, Object cls, Object[] iterab
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached ToArrayNode toArrayNode,
@SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PProduct self = factory.createProduct(cls);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PProduct self = PFactory.createProduct(language, cls, getInstanceShape.execute(cls));
constructOneRepeat(frame, self, iterables, toArrayNode);
return self;
}
@@ -687,7 +657,8 @@ static Object construct(VirtualFrame frame, Object cls, Object[] iterables, int
@Shared @Cached ToArrayNode toArrayNode,
@Cached InlinedLoopConditionProfile loopProfile,
@SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
Object[][] lists = unpackIterables(frame, iterables, toArrayNode);
Object[][] gears = new Object[lists.length * repeat][];
loopProfile.profileCounted(inliningTarget, repeat);
@@ -695,7 +666,7 @@ static Object construct(VirtualFrame frame, Object cls, Object[] iterables, int
for (int i = 0; loopProfile.inject(inliningTarget, i < repeat); i++) {
PythonUtils.arraycopy(lists, 0, gears, i * lists.length, lists.length);
}
- PProduct self = factory.createProduct(cls);
+ PProduct self = PFactory.createProduct(language, cls, getInstanceShape.execute(cls));
construct(self, gears);
return self;
}
@@ -704,8 +675,9 @@ static Object construct(VirtualFrame frame, Object cls, Object[] iterables, int
static Object constructNoRepeat(Object cls, @SuppressWarnings("unused") Object[] iterables, @SuppressWarnings("unused") int repeat,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PProduct self = factory.createProduct(cls);
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PProduct self = PFactory.createProduct(language, cls, getInstanceShape.execute(cls));
self.setGears(new Object[0][]);
self.setIndices(new int[0]);
self.setLst(null);
@@ -763,78 +735,25 @@ static Object construct(Object cls, Object iterables, Object repeat,
@Builtin(name = "repeat", minNumOfPositionalArgs = 2, parameterNames = {"$self", "object",
"times"}, constructsClass = PythonBuiltinClassType.PRepeat, doc = "repeat(object [,times]) -> create an iterator which returns the object\n" +
"for the specified number of times. If not specified, returns the object\nendlessly.")
- @ArgumentClinic(name = "times", defaultValue = "PNone.NONE", useDefaultForNone = true)
@GenerateNodeFactory
- public abstract static class RepeatNode extends PythonTernaryClinicBuiltinNode {
+ public abstract static class RepeatNode extends PythonTernaryBuiltinNode {
- @Override
- protected ArgumentClinicProvider getArgumentClinic() {
- return ItertoolsModuleBuiltinsClinicProviders.RepeatNodeClinicProviderGen.INSTANCE;
- }
-
- @Specialization(guards = "isTypeNode.execute(inliningTarget, cls)")
- static Object constructNone(Object cls, Object object, @SuppressWarnings("unused") PNone times,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PRepeat self = factory.createRepeat(cls);
- self.setElement(object);
- self.setCnt(-1);
- return self;
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "times < 0"})
- static Object constructNeg(Object cls, Object object, @SuppressWarnings("unused") int times,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PRepeat self = factory.createRepeat(cls);
- self.setElement(object);
- self.setCnt(0);
- return self;
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "times >= 0"})
- static Object construct(Object cls, Object object, int times,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PRepeat self = factory.createRepeat(cls);
- self.setElement(object);
- self.setCnt(times);
- return self;
- }
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "times >= 0"}, limit = "1")
- static Object construct(VirtualFrame frame, Object cls, Object object, long times,
+ @Specialization
+ static Object construct(VirtualFrame frame, Object cls, Object object, Object timesObj,
@Bind("this") Node inliningTarget,
- @Cached PyLongAsIntNode asIntNode,
- @SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PythonObjectFactory factory) {
- PRepeat self = factory.createRepeat(cls);
+ @Bind PythonLanguage language,
+ @Cached PyNumberAsSizeNode asSizeNode,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PRepeat self = PFactory.createRepeat(language, cls, getInstanceShape.execute(cls));
self.setElement(object);
- self.setCnt(asIntNode.execute(frame, inliningTarget, times));
+ if (timesObj != PNone.NONE) {
+ int times = asSizeNode.executeExact(frame, inliningTarget, timesObj);
+ self.setCnt(times > 0 ? times : 0);
+ } else {
+ self.setCnt(-1);
+ }
return self;
}
-
- @Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "!isNone(times)", "!isInt(times)", "!isLong(times)"})
- @SuppressWarnings("unused")
- static Object construct(Object cls, Object object, Object times,
- @Bind("this") Node inliningTarget,
- @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, S_EXPECTED_GOT_P, "integer", times);
- }
-
- @Specialization(guards = "!isTypeNode.execute(inliningTarget, cls)")
- @SuppressWarnings("unused")
- static Object notype(Object cls, Object object, Object times,
- @Bind("this") Node inliningTarget,
- @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
- }
-
}
@Builtin(name = "chain", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, constructsClass = PythonBuiltinClassType.PChain, doc = "Return a chain object whose .__next__() method returns elements from the\n" +
@@ -848,7 +767,8 @@ static PChain construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -856,8 +776,8 @@ static PChain construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "chain()");
}
- PChain self = factory.createChain(cls);
- self.setSource(getIter.execute(frame, inliningTarget, factory.createList(args)));
+ PChain self = PFactory.createChain(language, cls, getInstanceShape.execute(cls));
+ self.setSource(getIter.execute(frame, inliningTarget, PFactory.createList(language, args)));
self.setActive(PNone.NONE);
return self;
}
@@ -879,7 +799,8 @@ static Object construct(Object cls, Object start, Object step,
@Bind("this") Node inliningTarget,
@Cached PyNumberCheckNode checkNode,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -890,7 +811,7 @@ static Object construct(Object cls, Object start, Object step,
if (!checkNode.execute(inliningTarget, step)) {
throw raiseNode.get(inliningTarget).raise(TypeError, NUMBER_IS_REQUIRED);
}
- PCount self = factory.createCount(cls);
+ PCount self = PFactory.createCount(language, cls, getInstanceShape.execute(cls));
self.setCnt(start);
self.setStep(step);
return self;
@@ -908,7 +829,8 @@ static PStarmap construct(VirtualFrame frame, Object cls, Object[] args, PKeywor
@Cached(inline = false /* uncommon path */) TypeNodes.HasObjectInitNode hasObjectInitNode,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
@@ -921,7 +843,7 @@ static PStarmap construct(VirtualFrame frame, Object cls, Object[] args, PKeywor
}
Object fun = args[0];
Object iterable = args[1];
- PStarmap self = factory.createStarmap(cls);
+ PStarmap self = PFactory.createStarmap(language, cls, getInstanceShape.execute(cls));
self.setFun(fun);
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
return self;
@@ -952,7 +874,8 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
@Cached InlinedBranchProfile wrongTypeBranch,
@Cached InlinedBranchProfile wrongArgsBranch,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
wrongTypeBranch.enter(inliningTarget);
@@ -1022,7 +945,7 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
}
}
Object iterable = args[0];
- PIslice self = factory.createIslice(cls);
+ PIslice self = PFactory.createIslice(language, cls, getInstanceShape.execute(cls));
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
self.setNext(start);
self.setStop(stop);
@@ -1050,7 +973,8 @@ static Object construct(VirtualFrame frame, Object cls, Object[] args, Object fi
@Cached InlinedLoopConditionProfile loopProfile,
@Cached IsTypeNode isTypeNode,
@Cached InlinedBranchProfile errorProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
// Note: @Fallback or other @Specialization generate data-class
@@ -1063,7 +987,7 @@ static Object construct(VirtualFrame frame, Object cls, Object[] args, Object fi
fillValue = null;
}
- PZipLongest self = factory.createZipLongest(cls);
+ PZipLongest self = PFactory.createZipLongest(language, cls, getInstanceShape.execute(cls));
self.setFillValue(fillValue);
self.setNumActive(args.length);
@@ -1087,17 +1011,17 @@ static PPairwise construct(VirtualFrame frame, Object cls, Object iterable,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
@Cached IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
// Note: @Fallback or other @Specialization generate data-class
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
- PPairwise self = factory.createPairwise(cls);
+ PPairwise self = PFactory.createPairwise(language, cls, getInstanceShape.execute(cls));
self.setIterable(getIter.execute(frame, inliningTarget, iterable));
return self;
}
}
-
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
index 4bef0e0f31..67fce07408 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
import java.util.Locale;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -72,7 +73,7 @@
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.locale.LocaleUtils;
import com.oracle.graal.python.runtime.locale.PythonLocale;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -117,7 +118,7 @@ public abstract static class LocaleConvNode extends PythonBuiltinNode {
@TruffleBoundary
static PDict localeconv() {
PythonContext ctx = PythonContext.get(null);
- PythonObjectFactory factory = ctx.factory();
+ PythonLanguage language = ctx.getLanguage();
LinkedHashMap dict = new LinkedHashMap<>(20);
final PythonLocale currentPythonLocale = ctx.getCurrentLocale();
@@ -128,7 +129,7 @@ static PDict localeconv() {
dict.put("decimal_point", TruffleString.fromCodePointUncached(decimalFormatSymbols.getDecimalSeparator(), TS_ENCODING));
dict.put("thousands_sep", TruffleString.fromCodePointUncached(decimalFormatSymbols.getGroupingSeparator(), TS_ENCODING));
- dict.put("grouping", getDecimalFormatGrouping(factory, numericLocaleNumFormat));
+ dict.put("grouping", getDecimalFormatGrouping(language, numericLocaleNumFormat));
// LC_MONETARY
Locale monetaryLocale = currentPythonLocale.category(LC_MONETARY);
@@ -140,7 +141,7 @@ static PDict localeconv() {
dict.put("currency_symbol", toTruffleStringUncached(decimalFormatSymbols.getCurrencySymbol()));
dict.put("mon_decimal_point", TruffleString.fromCodePointUncached(decimalFormatSymbols.getMonetaryDecimalSeparator(), TS_ENCODING));
dict.put("mon_thousands_sep", TruffleString.fromCodePointUncached(decimalFormatSymbols.getGroupingSeparator(), TS_ENCODING));
- dict.put("mon_grouping", getDecimalFormatGrouping(factory, monetaryNumFormat));
+ dict.put("mon_grouping", getDecimalFormatGrouping(language, monetaryNumFormat));
// TODO: reasonable default, but not the current locale setting
dict.put("positive_sign", "");
dict.put("negative_sign", TruffleString.fromCodePointUncached(decimalFormatSymbols.getMinusSign(), TS_ENCODING));
@@ -153,21 +154,21 @@ static PDict localeconv() {
dict.put("p_sign_posn", PNone.NONE);
dict.put("n_sign_posn", PNone.NONE);
- return factory.createDictFromMap(dict);
+ return PFactory.createDictFromMap(language, dict);
}
private static DecimalFormatSymbols getDecimalFormatSymbols(Locale locale, NumberFormat numberFormat) {
return numberFormat instanceof DecimalFormat decimalFormat ? decimalFormat.getDecimalFormatSymbols() : new DecimalFormatSymbols(locale);
}
- private static PList getDecimalFormatGrouping(PythonObjectFactory factory, NumberFormat numberFormat) {
+ private static PList getDecimalFormatGrouping(PythonLanguage language, NumberFormat numberFormat) {
if (numberFormat instanceof DecimalFormat decimalFormat) {
// TODO: this does not support groupings with variable size groups like in India
// Possible approach: decimalFormat.toPattern() gives a generic pattern (e.g.,
// #,#00.0#) that would have to be parsed to extract the group sizes from it
- return factory.createList(new Object[]{decimalFormat.getGroupingSize(), 0});
+ return PFactory.createList(language, new Object[]{decimalFormat.getGroupingSize(), 0});
} else {
- return factory.createList();
+ return PFactory.createList(language);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
index 0c91bb9359..a8c503b1da 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
import java.util.Map;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -57,24 +58,21 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.list.PList;
-import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.tuple.StructSequence;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.InstrumentInfo;
import com.oracle.truffle.api.TruffleLanguage.Env;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
-import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.tools.profiler.CPUSampler;
import com.oracle.truffle.tools.profiler.CPUSampler.Payload;
@@ -138,14 +136,14 @@ abstract static class LsprofNew extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
Profiler doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs) {
- Env env = getContext().getEnv();
+ PythonContext context = getContext();
+ Env env = context.getEnv();
Map instruments = env.getInstruments();
InstrumentInfo instrumentInfo = instruments.get(CPUSamplerInstrument.ID);
if (instrumentInfo != null) {
CPUSampler sampler = env.lookup(instrumentInfo, CPUSampler.class);
if (sampler != null) {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- return factory.trace(new Profiler(cls, factory.getShape(cls), sampler));
+ return PFactory.createProfiler(context.getLanguage(), cls, TypeNodes.GetInstanceShape.executeUncached(cls), sampler);
}
}
throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.NotImplementedError, ErrorMessages.COVERAGE_TRACKER_NOT_AVAILABLE);
@@ -153,22 +151,6 @@ Profiler doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWa
}
}
-class Profiler extends PythonBuiltinObject {
- boolean subcalls;
- boolean builtins;
- double timeunit;
- Object externalTimer;
- double time;
- final CPUSampler sampler;
-
- public Profiler(Object cls, Shape instanceShape, CPUSampler sampler) {
- super(cls, instanceShape);
- this.sampler = sampler;
- this.sampler.setFilter(SourceSectionFilter.newBuilder().includeInternal(true).build());
- this.sampler.setPeriod(1);
- }
-}
-
@CoreFunctions(extendClasses = PythonBuiltinClassType.LsprofProfiler)
class ProfilerBuiltins extends PythonBuiltins {
@Override
@@ -291,23 +273,23 @@ static PList doit(Profiler self) {
}
self.sampler.close();
- return PythonObjectFactory.getUncached().createList(entries.toArray());
+ return PFactory.createList(PythonLanguage.get(null), entries.toArray());
}
private static void countNode(List entries, ProfilerNode node, double avgSampleTime) {
- PythonObjectSlowPathFactory factory = PythonContext.get(null).factory();
+ PythonLanguage language = PythonLanguage.get(null);
Collection> children = node.getChildren();
Object[] profilerEntry = getProfilerEntry(node, avgSampleTime);
Object[] calls = new Object[children.size()];
int callIdx = 0;
for (ProfilerNode childNode : children) {
countNode(entries, childNode, avgSampleTime);
- calls[callIdx++] = factory.createStructSeq(LsprofModuleBuiltins.PROFILER_SUBENTRY_DESC, getProfilerEntry(childNode, avgSampleTime));
+ calls[callIdx++] = PFactory.createStructSeq(language, LsprofModuleBuiltins.PROFILER_SUBENTRY_DESC, getProfilerEntry(childNode, avgSampleTime));
}
assert callIdx == calls.length;
profilerEntry = Arrays.copyOf(profilerEntry, 6);
- profilerEntry[profilerEntry.length - 1] = factory.createList(calls);
- entries.add(factory.createStructSeq(LsprofModuleBuiltins.PROFILER_ENTRY_DESC, profilerEntry));
+ profilerEntry[profilerEntry.length - 1] = PFactory.createList(language, calls);
+ entries.add(PFactory.createStructSeq(language, LsprofModuleBuiltins.PROFILER_ENTRY_DESC, profilerEntry));
}
private static Object[] getProfilerEntry(ProfilerNode node, double avgSampleTime) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
index e576c697c7..962926ddc9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -64,6 +64,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -75,7 +76,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -167,7 +168,7 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
@Cached SysModuleBuiltins.AuditNode auditNode,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupport,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (lengthIn < 0) {
throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MEM_MAPPED_LENGTH_MUST_BE_POSITIVE);
@@ -252,7 +253,8 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
- return factory.createMMap(PythonContext.get(inliningTarget), clazz, mmapHandle, dupFd, length, access);
+ PythonContext context = PythonContext.get(inliningTarget);
+ return PFactory.createMMap(context.getLanguage(inliningTarget), context, clazz, getInstanceShape.execute(clazz), mmapHandle, dupFd, length, access);
}
@Specialization(guards = "isIllegal(fd)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
index 32ddad0ee3..dbe0c43be8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -44,6 +44,7 @@
import java.util.HashMap;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -105,7 +106,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
@@ -158,19 +159,21 @@ protected static LookupAndCallBinaryNode createCallWriteNode() {
@Specialization
static Object doit(VirtualFrame frame, Object value, Object file, int version,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached("createCallWriteNode()") LookupAndCallBinaryNode callNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- Object savedState = IndirectCallContext.enter(frame, indirectCallData);
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ PythonContext.PythonThreadState threadState = context.getThreadState(language);
+ Object savedState = IndirectCallContext.enter(frame, threadState, indirectCallData);
try {
- return callNode.executeObject(frame, file, factory.createBytes(Marshal.dump(value, version, PythonContext.get(inliningTarget))));
+ return callNode.executeObject(frame, file, PFactory.createBytes(language, Marshal.dump(context, value, version)));
} catch (IOException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} catch (Marshal.MarshalError me) {
throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
} finally {
- IndirectCallContext.exit(frame, indirectCallData, savedState);
+ IndirectCallContext.exit(frame, threadState, savedState);
}
}
}
@@ -187,18 +190,20 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object doit(VirtualFrame frame, Object value, int version,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- Object savedState = IndirectCallContext.enter(frame, indirectCallData);
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ PythonContext.PythonThreadState threadState = context.getThreadState(language);
+ Object savedState = IndirectCallContext.enter(frame, threadState, indirectCallData);
try {
- return factory.createBytes(Marshal.dump(value, version, PythonContext.get(inliningTarget)));
+ return PFactory.createBytes(language, Marshal.dump(context, value, version));
} catch (IOException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} catch (Marshal.MarshalError me) {
throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
} finally {
- IndirectCallContext.exit(frame, indirectCallData, savedState);
+ IndirectCallContext.exit(frame, threadState, savedState);
}
}
}
@@ -214,6 +219,7 @@ protected static LookupAndCallBinaryNode createCallReadNode() {
@Specialization
static Object doit(VirtualFrame frame, Object file,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createCallReadNode()") LookupAndCallBinaryNode callNode,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferLib,
@Cached PRaiseNode.Lazy raiseNode) {
@@ -222,7 +228,7 @@ static Object doit(VirtualFrame frame, Object file,
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.READ_RETURNED_NOT_BYTES, buffer);
}
try {
- return Marshal.loadFile(file);
+ return Marshal.loadFile(context, file);
} catch (NumberFormatException e) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
} catch (Marshal.MarshalError me) {
@@ -239,11 +245,12 @@ abstract static class LoadsNode extends PythonUnaryClinicBuiltinNode {
@Specialization
static Object doit(VirtualFrame frame, Object buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- return Marshal.load(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
+ return Marshal.load(context, bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
} catch (NumberFormatException e) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
} catch (Marshal.MarshalError me) {
@@ -346,15 +353,15 @@ public final Throwable fillInStackTrace() {
}
@TruffleBoundary
- static byte[] dump(Object value, int version, Python3Core core) throws IOException, MarshalError {
- Marshal outMarshal = new Marshal(version, core.getTrue(), core.getFalse());
+ static byte[] dump(PythonContext context, Object value, int version) throws IOException, MarshalError {
+ Marshal outMarshal = new Marshal(context, version, context.getTrue(), context.getFalse());
outMarshal.writeObject(value);
return outMarshal.out.toByteArray();
}
@TruffleBoundary
- static Object load(byte[] ary, int length) throws NumberFormatException, MarshalError {
- Marshal inMarshal = new Marshal(ary, length);
+ static Object load(PythonContext context, byte[] ary, int length) throws NumberFormatException, MarshalError {
+ Marshal inMarshal = new Marshal(context, ary, length);
Object result = inMarshal.readObject();
if (result == null) {
throw new MarshalError(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_MARSHAL_DATA_NULL);
@@ -363,8 +370,8 @@ static Object load(byte[] ary, int length) throws NumberFormatException, Marshal
}
@TruffleBoundary
- static Object loadFile(Object file) throws NumberFormatException, MarshalError {
- Marshal inMarshal = new Marshal(file);
+ static Object loadFile(PythonContext context, Object file) throws NumberFormatException, MarshalError {
+ Marshal inMarshal = new Marshal(context, file);
Object result = inMarshal.readObject();
if (result == null) {
throw new MarshalError(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_MARSHAL_DATA_NULL);
@@ -387,7 +394,7 @@ static final class FileLikeInputStream extends InputStream {
this.fileLike = fileLike;
this.asSize = PyNumberAsSizeNode.getUncached();
this.singleByteStore = new ByteSequenceStorage(new byte[1]);
- this.buffer = PythonObjectFactory.getUncached().createByteArray(singleByteStore);
+ this.buffer = PFactory.createByteArray(PythonLanguage.get(null), singleByteStore);
}
@Override
@@ -418,7 +425,7 @@ public int read(byte[] b, int off, int len) {
}
}
- private static final PythonObjectFactory factory = PythonObjectFactory.getUncached();
+ private final PythonContext context;
final HashMap refMap;
final ArrayList refList;
final ByteArrayOutputStream out;
@@ -431,7 +438,8 @@ public int read(byte[] b, int off, int len) {
byte[] buffer = new byte[Long.BYTES];
int depth = 0;
- Marshal(int version, PInt pyTrue, PInt pyFalse) {
+ Marshal(PythonContext context, int version, PInt pyTrue, PInt pyFalse) {
+ this.context = context;
this.version = version;
this.pyTrue = pyTrue;
this.pyFalse = pyFalse;
@@ -441,7 +449,8 @@ public int read(byte[] b, int off, int len) {
this.refList = null;
}
- Marshal(byte[] in, int length) {
+ Marshal(PythonContext context, byte[] in, int length) {
+ this.context = context;
this.in = new ByteArrayInputStream(in, 0, length);
this.refList = new ArrayList<>();
this.version = -1;
@@ -451,7 +460,8 @@ public int read(byte[] b, int off, int len) {
this.refMap = null;
}
- Marshal(Object in) {
+ Marshal(PythonContext context, Object in) {
+ this.context = context;
this.in = new FileLikeInputStream(in);
this.refList = new ArrayList<>();
this.version = -1;
@@ -461,6 +471,10 @@ public int read(byte[] b, int off, int len) {
this.refMap = null;
}
+ private PythonLanguage getLanguage() {
+ return context.getLanguage();
+ }
+
private void writeByte(int v) {
out.write(v);
}
@@ -979,17 +993,17 @@ private Object readObject(int type, AddRefAndReturn addRef) throws NumberFormatE
case TYPE_BIG_INTEGER:
return readBigInteger();
case TYPE_LONG:
- return addRef.run(factory.createInt(readBigInteger()));
+ return addRef.run(PFactory.createInt(getLanguage(), readBigInteger()));
case TYPE_FLOAT:
return addRef.run(readDoubleString());
case TYPE_BINARY_FLOAT:
return addRef.run(readDouble());
case TYPE_COMPLEX:
- return addRef.run(factory.createComplex(readDoubleString(), readDoubleString()));
+ return addRef.run(PFactory.createComplex(getLanguage(), readDoubleString(), readDoubleString()));
case TYPE_BINARY_COMPLEX:
- return addRef.run(factory.createComplex(readDouble(), readDouble()));
+ return addRef.run(PFactory.createComplex(getLanguage(), readDouble(), readDouble()));
case TYPE_STRING:
- return addRef.run(factory.createBytes(readBytes()));
+ return addRef.run(PFactory.createBytes(getLanguage(), readBytes()));
case TYPE_ASCII_INTERNED:
return addRef.run(readAscii(readSize(), true));
case TYPE_ASCII:
@@ -1005,24 +1019,24 @@ private Object readObject(int type, AddRefAndReturn addRef) throws NumberFormatE
case TYPE_SMALL_TUPLE:
int smallTupleSize = readByteSize();
Object[] smallTupleItems = new Object[smallTupleSize];
- Object smallTuple = addRef.run(factory.createTuple(smallTupleItems));
+ Object smallTuple = addRef.run(PFactory.createTuple(getLanguage(), smallTupleItems));
readArray(smallTupleItems);
return smallTuple;
case TYPE_TUPLE:
int tupleSize = readSize();
Object[] tupleItems = new Object[tupleSize];
- Object tuple = addRef.run(factory.createTuple(tupleItems));
+ Object tuple = addRef.run(PFactory.createTuple(getLanguage(), tupleItems));
readArray(tupleItems);
return tuple;
case TYPE_LIST:
int listSize = readSize();
Object[] listItems = new Object[listSize];
- Object list = addRef.run(factory.createList(listItems));
+ Object list = addRef.run(PFactory.createList(getLanguage(), listItems));
readArray(listItems);
return list;
case TYPE_DICT:
HashingStorage store = PDict.createNewStorage(0);
- PDict dict = factory.createDict(store);
+ PDict dict = PFactory.createDict(getLanguage(), store);
addRef.run(dict);
while (true) {
Object key = readObject();
@@ -1042,9 +1056,9 @@ private Object readObject(int type, AddRefAndReturn addRef) throws NumberFormatE
HashingStorage setStore = EconomicMapStorage.create(setSz);
PBaseSet set;
if (type == TYPE_FROZENSET) {
- set = factory.createFrozenSet(setStore);
+ set = PFactory.createFrozenSet(getLanguage(), setStore);
} else {
- set = factory.createSet(setStore);
+ set = PFactory.createSet(getLanguage(), setStore);
}
addRef.run(set);
for (int i = 0; i < setSz; i++) {
@@ -1326,7 +1340,6 @@ private PCode readCode() {
// get a new ID every time we deserialize the same filename in the same context. We use
// slow-path context lookup, since this code is likely dominated by the deserialization
// time
- PythonContext context = PythonContext.get(null);
ByteBuffer.wrap(codeString).putLong(codeLen, context.getDeserializationId(fileName));
int firstLineNo = readInt();
byte[] lnoTab = readBytes();
@@ -1335,9 +1348,9 @@ private PCode readCode() {
}
@TruffleBoundary
- public static byte[] serializeCodeUnit(CodeUnit code) {
+ public static byte[] serializeCodeUnit(PythonContext context, CodeUnit code) {
try {
- Marshal marshal = new Marshal(CURRENT_VERSION, null, null);
+ Marshal marshal = new Marshal(context, CURRENT_VERSION, null, null);
marshal.writeCodeUnit(code);
return marshal.out.toByteArray();
} catch (IOException e) {
@@ -1348,9 +1361,9 @@ public static byte[] serializeCodeUnit(CodeUnit code) {
}
@TruffleBoundary
- public static CodeUnit deserializeCodeUnit(byte[] bytes) {
+ public static CodeUnit deserializeCodeUnit(PythonContext context, byte[] bytes) {
try {
- Marshal marshal = new Marshal(bytes, bytes.length);
+ Marshal marshal = new Marshal(context, bytes, bytes.length);
return marshal.readCodeUnit();
} catch (Marshal.MarshalError me) {
throw PRaiseNode.getUncached().raise(me.type, me.message, me.arguments);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
index 9266b8f0cd..4e98b5bb38 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -37,6 +37,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -82,7 +83,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.nodes.util.NarrowBigIntegerNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -362,8 +363,8 @@ static long factorialSmallInt(int value) {
@Specialization(guards = {"value >= SMALL_FACTORIALS.length"})
static PInt factorialInt(int value,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(factorialPart(1, value));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, factorialPart(1, value));
}
@Specialization(guards = {"value < 0"})
@@ -379,8 +380,8 @@ static long factorialSmallLong(long value) {
@Specialization(guards = {"value >= SMALL_FACTORIALS.length"})
static PInt factorialLong(long value,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(factorialPart(1, value));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, factorialPart(1, value));
}
@Fallback
@@ -439,26 +440,26 @@ private BigInteger calculateComb(BigInteger n, BigInteger k) {
@Specialization
PInt comb(long n, long k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculateComb(PInt.longToBigInteger(n), PInt.longToBigInteger(k)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculateComb(PInt.longToBigInteger(n), PInt.longToBigInteger(k)));
}
@Specialization
PInt comb(long n, PInt k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculateComb(PInt.longToBigInteger(n), k.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculateComb(PInt.longToBigInteger(n), k.getValue()));
}
@Specialization
PInt comb(PInt n, long k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculateComb(n.getValue(), PInt.longToBigInteger(k)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculateComb(n.getValue(), PInt.longToBigInteger(k)));
}
@Specialization
PInt comb(PInt n, PInt k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculateComb(n.getValue(), k.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculateComb(n.getValue(), k.getValue()));
}
@Specialization
@@ -510,26 +511,26 @@ private BigInteger calculatePerm(BigInteger n, BigInteger k) {
@Specialization
PInt perm(long n, long k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculatePerm(PInt.longToBigInteger(n), PInt.longToBigInteger(k)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculatePerm(PInt.longToBigInteger(n), PInt.longToBigInteger(k)));
}
@Specialization
PInt perm(long n, PInt k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculatePerm(PInt.longToBigInteger(n), k.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculatePerm(PInt.longToBigInteger(n), k.getValue()));
}
@Specialization
PInt perm(PInt n, long k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculatePerm(n.getValue(), PInt.longToBigInteger(k)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculatePerm(n.getValue(), PInt.longToBigInteger(k)));
}
@Specialization
PInt perm(PInt n, PInt k,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(calculatePerm(n.getValue(), k.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, calculatePerm(n.getValue(), k.getValue()));
}
@Specialization
@@ -701,12 +702,12 @@ public static double[] frexp(double value) {
@Specialization
static PTuple frexpD(double value,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] content = new Object[2];
double[] primContent = frexp(value);
content[0] = primContent[0];
content[1] = (int) primContent[1];
- return factory.createTuple(content);
+ return PFactory.createTuple(language, content);
}
@Override
@@ -839,17 +840,17 @@ protected ArgumentClinicProvider getArgumentClinic() {
public abstract static class ModfNode extends PythonUnaryClinicBuiltinNode {
@Specialization
static PTuple modfD(double value,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (!Double.isFinite(value)) {
if (Double.isInfinite(value)) {
- return factory.createTuple(new Object[]{Math.copySign(0., value), value});
+ return PFactory.createTuple(language, new Object[]{Math.copySign(0., value), value});
} else if (Double.isNaN(value)) {
- return factory.createTuple(new Object[]{value, value});
+ return PFactory.createTuple(language, new Object[]{value, value});
}
}
double fraction = value % 1;
double integral = value - fraction;
- return factory.createTuple(new Object[]{fraction, integral});
+ return PFactory.createTuple(language, new Object[]{fraction, integral});
}
@Override
@@ -1058,14 +1059,14 @@ static long gcd(long x, long y) {
@Specialization
static PInt gcd(long x, PInt y,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createInt(op(PInt.longToBigInteger(x), y.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(PInt.longToBigInteger(x), y.getValue()));
}
@Specialization
static PInt gcd(PInt x, long y,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createInt(op(x.getValue(), PInt.longToBigInteger(y)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(x.getValue(), PInt.longToBigInteger(y)));
}
@TruffleBoundary
@@ -1075,8 +1076,8 @@ private static BigInteger op(BigInteger x, BigInteger y) {
@Specialization
PInt gcd(PInt x, PInt y,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createInt(op(x.getValue(), y.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(x.getValue(), y.getValue()));
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/NtModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/NtModuleBuiltins.java
index 2f003dff72..738f1bb76d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/NtModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/NtModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -65,7 +66,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -123,12 +124,12 @@ abstract static class PathSplitRootNode extends PythonUnaryClinicBuiltinNode {
Object splitroot(PosixPath path) {
// TODO should call WINAPI PathCchSkipRoot
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
+ PythonLanguage language = PythonLanguage.get(null);
TruffleString pathString = PosixSupportLibrary.getUncached().getPathAsString(getPosixSupport(), path.value);
int len = pathString.codePointLengthUncached(TS_ENCODING);
int index = pathString.indexOfCodePointUncached(':', 0, len, TS_ENCODING);
if (index <= 0) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, pathString});
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, pathString});
} else {
index++;
int first = pathString.codePointAtIndexUncached(index, TS_ENCODING);
@@ -137,7 +138,7 @@ Object splitroot(PosixPath path) {
}
TruffleString root = pathString.substringUncached(0, index, TS_ENCODING, false);
TruffleString rest = pathString.substringUncached(index, len - index, TS_ENCODING, false);
- return factory.createTuple(new Object[]{root, rest});
+ return PFactory.createTuple(language, new Object[]{root, rest});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
index b414152f0d..2310c287c7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
@@ -119,7 +119,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ArrayBasedSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
@@ -632,15 +632,15 @@ public abstract static class GetRegisteredInteropBehaviorNode extends PythonUnar
PList get(PythonAbstractObject klass,
@Bind("this") Node inliningTarget,
@Cached TypeNodes.IsTypeNode isTypeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode raiseNode,
@Cached HiddenAttr.ReadNode readHiddenAttrNode) {
if (isTypeNode.execute(inliningTarget, klass)) {
Object value = readHiddenAttrNode.execute(inliningTarget, klass, HiddenAttr.HOST_INTEROP_BEHAVIOR, null);
if (value instanceof InteropBehavior behavior) {
- return factory.createList(behavior.getDefinedMethods());
+ return PFactory.createList(language, behavior.getDefinedMethods());
}
- return factory.createList();
+ return PFactory.createList(language);
}
throw raiseNode.raise(ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a type", klass);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
index 3b62e8c849..1855f6b7cc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
@@ -128,7 +128,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonExitException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
@@ -282,9 +282,10 @@ public void initialize(Python3Core core) {
haveFunctions.add(tsLiteral("HAVE_FTRUNCATE"));
haveFunctions.add(tsLiteral("MS_WINDOWS"));
}
- addBuiltinConstant("_have_functions", core.factory().createList(haveFunctions.toArray()));
- addBuiltinConstant("environ", core.factory().createDict());
- addBuiltinConstant("sysconf_names", core.factory().createDict());
+ PythonLanguage language = core.getLanguage();
+ addBuiltinConstant("_have_functions", PFactory.createList(language, haveFunctions.toArray()));
+ addBuiltinConstant("environ", PFactory.createDict(language));
+ addBuiltinConstant("sysconf_names", PFactory.createDict(language));
StructSequence.initType(core, STAT_RESULT_DESC);
StructSequence.initType(core, STATVFS_RESULT_DESC);
@@ -317,11 +318,12 @@ public void postInitialize(Python3Core core) {
PosixSupportLibrary posixLib = PosixSupportLibrary.getUncached();
Object posixSupport = core.getContext().getPosixSupport();
+ PythonLanguage language = core.getLanguage();
// fill the environ dictionary with the current environment
// TODO we should probably use PosixSupportLibrary to get environ
Map getenv = core.getContext().getEnv().getEnvironment();
- PDict environ = core.factory().createDict();
+ PDict environ = PFactory.createDict(language);
String pyenvLauncherKey = "__PYVENV_LAUNCHER__";
for (Entry entry : getenv.entrySet()) {
if (entry.getKey().equals("GRAAL_PYTHON_ARGS") && entry.getValue().endsWith("\013")) {
@@ -337,7 +339,7 @@ public void postInitialize(Python3Core core) {
}
key = toTruffleStringUncached(entry.getKey());
} else {
- key = core.factory().createBytes(entry.getKey().getBytes());
+ key = PFactory.createBytes(language, entry.getKey().getBytes());
}
if (pyenvLauncherKey.equals(entry.getKey())) {
// On Mac, the CPython launcher uses this env variable to specify the real Python
@@ -353,13 +355,13 @@ public void postInitialize(Python3Core core) {
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
val = value;
} else {
- val = core.factory().createBytes(value.toJavaStringUncached().getBytes());
+ val = PFactory.createBytes(language, value.toJavaStringUncached().getBytes());
}
} else {
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
val = toTruffleStringUncached(entry.getValue());
} else {
- val = core.factory().createBytes((entry.getValue().getBytes()));
+ val = PFactory.createBytes(language, (entry.getValue().getBytes()));
}
}
environ.setItem(key, val);
@@ -445,7 +447,8 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes, PBytes valueBytes,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
// Unlike in other posix builtins, we go through str -> bytes -> byte[] -> String
@@ -453,7 +456,7 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes, PBytes valueBytes,
// is subject to sys.audit.
byte[] name = toBytesNode.execute(nameBytes);
byte[] value = toBytesNode.execute(valueBytes);
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
Object nameOpaque = checkNull(inliningTarget, posixLib.createPathFromBytes(posixSupport, name), raiseNode);
Object valueOpaque = checkNull(inliningTarget, posixLib.createPathFromBytes(posixSupport, value), raiseNode);
checkEqualSign(inliningTarget, name, raiseNode);
@@ -493,18 +496,19 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone putenv(VirtualFrame frame, PBytes nameBytes,
+ static PNone putenv(VirtualFrame frame, PBytes nameBytes,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
byte[] name = toBytesNode.execute(nameBytes);
- Object nameOpaque = checkNull(inliningTarget, posixLib.createPathFromBytes(getPosixSupport(), name), raiseNode);
+ Object nameOpaque = checkNull(inliningTarget, posixLib.createPathFromBytes(context.getPosixSupport(), name), raiseNode);
auditNode.audit(inliningTarget, "os.unsetenv", nameBytes);
try {
- posixLib.unsetenv(getPosixSupport(), nameOpaque);
+ posixLib.unsetenv(context.getPosixSupport(), nameOpaque);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -532,28 +536,30 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object execvArgsList(VirtualFrame frame, PosixPath path, PList argv,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached ToArrayNode toArrayNode,
@Shared @Cached ObjectToOpaquePathNode toOpaquePathNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
+ execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, context.getPosixSupport(), toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
throw CompilerDirectives.shouldNotReachHere("execv should not return normally");
}
@Specialization
static Object execvArgsTuple(VirtualFrame frame, PosixPath path, PTuple argv,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached ToArrayNode toArrayNode,
@Shared @Cached ObjectToOpaquePathNode toOpaquePathNode,
@Shared @Cached AuditNode auditNode,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
+ execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, context.getPosixSupport(), toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
throw CompilerDirectives.shouldNotReachHere("execv should not return normally");
}
@@ -567,6 +573,7 @@ static Object execvInvalidArgs(VirtualFrame frame, PosixPath path, Object argv,
private static void execv(VirtualFrame frame, PosixPath path, Object argv, SequenceStorage argvStorage,
Node inliningTarget,
PosixSupportLibrary posixLib,
+ PosixSupport posixSupport,
SequenceStorageNodes.ToArrayNode toArrayNode,
ObjectToOpaquePathNode toOpaquePathNode,
SysModuleBuiltins.AuditNode auditNode,
@@ -587,7 +594,7 @@ private static void execv(VirtualFrame frame, PosixPath path, Object argv, Seque
gil.release(true);
try {
- posixLib.execv(PosixSupport.get(inliningTarget), path.value, opaqueArgs);
+ posixLib.execv(posixSupport, path.value, opaqueArgs);
} catch (PosixException e) {
gil.acquire();
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -602,8 +609,9 @@ private static void execv(VirtualFrame frame, PosixPath path, Object argv, Seque
@GenerateNodeFactory
public abstract static class GetPidNode extends PythonBuiltinNode {
@Specialization
- long getPid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.getpid(getPosixSupport());
+ static long getPid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getpid(context.getPosixSupport());
}
}
@@ -611,8 +619,9 @@ long getPid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
@GenerateNodeFactory
public abstract static class GetUidNode extends PythonBuiltinNode {
@Specialization
- long getUid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.getuid(getPosixSupport());
+ static long getUid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getuid(context.getPosixSupport());
}
}
@@ -620,8 +629,9 @@ long getUid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
@GenerateNodeFactory
public abstract static class GetEUidNode extends PythonBuiltinNode {
@Specialization
- long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
- return posixLib.geteuid(getPosixSupport());
+ static long getUid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.geteuid(context.getPosixSupport());
}
}
@@ -629,8 +639,9 @@ long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
@GenerateNodeFactory
public abstract static class GetGidNode extends PythonBuiltinNode {
@Specialization
- long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.getgid(getPosixSupport());
+ static long getGid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getgid(context.getPosixSupport());
}
}
@@ -638,8 +649,9 @@ long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
@GenerateNodeFactory
public abstract static class GetEGidNode extends PythonBuiltinNode {
@Specialization
- long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.getegid(getPosixSupport());
+ static long getGid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getegid(context.getPosixSupport());
}
}
@@ -647,8 +659,9 @@ long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
@GenerateNodeFactory
public abstract static class GetPpidNode extends PythonBuiltinNode {
@Specialization
- long getPpid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.getppid(getPosixSupport());
+ static long getPpid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getppid(context.getPosixSupport());
}
}
@@ -665,8 +678,8 @@ public abstract static class GetLoadAvgNode extends PythonBuiltinNode {
*/
@TruffleBoundary
@Specialization
- PTuple getloadavg(@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory) {
+ static PTuple getloadavg(@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language) {
double load = -1.0;
// (mq) without native call we can only obtain system load average for the last minute.
if (ManagementFactory.getOperatingSystemMXBean() != null) {
@@ -675,7 +688,7 @@ PTuple getloadavg(@Bind("this") Node inliningTarget,
if (load < 0) {
PRaiseNode.raiseUncached(inliningTarget, OSError);
}
- return factory.createTuple(new Object[]{load, load, load});
+ return PFactory.createTuple(language, new Object[]{load, load, load});
}
}
@@ -689,12 +702,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- long getPgid(VirtualFrame frame, long pid,
+ static long getPgid(VirtualFrame frame, long pid,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.getpgid(getPosixSupport(), pid);
+ return posixLib.getpgid(context.getPosixSupport(), pid);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -712,12 +726,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- Object setPgid(VirtualFrame frame, long pid, long pgid,
+ static Object setPgid(VirtualFrame frame, long pid, long pgid,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.setpgid(getPosixSupport(), pid, pgid);
+ posixLib.setpgid(context.getPosixSupport(), pid, pgid);
return PNone.NONE;
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -729,12 +744,13 @@ Object setPgid(VirtualFrame frame, long pid, long pgid,
@GenerateNodeFactory
public abstract static class SetPgrpdNode extends PythonBuiltinNode {
@Specialization
- Object getPpid(VirtualFrame frame,
+ static Object getPpid(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.setpgid(getPosixSupport(), 0, 0);
+ posixLib.setpgid(context.getPosixSupport(), 0, 0);
return PNone.NONE;
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -746,8 +762,9 @@ Object getPpid(VirtualFrame frame,
@GenerateNodeFactory
public abstract static class GetPgrpNode extends PythonBuiltinNode {
@Specialization
- long getPpid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
- return posixLib.getpgrp(getPosixSupport());
+ static long getPpid(@Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.getpgrp(context.getPosixSupport());
}
}
@@ -761,12 +778,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- long getSid(VirtualFrame frame, long pid,
+ static long getSid(VirtualFrame frame, long pid,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.getsid(getPosixSupport(), pid);
+ return posixLib.getsid(context.getPosixSupport(), pid);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -778,12 +796,13 @@ long getSid(VirtualFrame frame, long pid,
public abstract static class SetSidNode extends PythonBuiltinNode {
@Specialization
- Object setsid(VirtualFrame frame,
+ static Object setsid(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.setsid(getPosixSupport());
+ posixLib.setsid(context.getPosixSupport());
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -795,14 +814,14 @@ Object setsid(VirtualFrame frame,
@GenerateNodeFactory
abstract static class GetGroupsNode extends PythonBuiltinNode {
@Specialization
- Object getgroups(VirtualFrame frame,
+ static Object getgroups(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- long[] groups = posixLib.getgroups(getPosixSupport());
- return factory.createList(new LongSequenceStorage(groups));
+ long[] groups = posixLib.getgroups(context.getPosixSupport());
+ return PFactory.createList(context.getLanguage(inliningTarget), new LongSequenceStorage(groups));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -814,16 +833,16 @@ Object getgroups(VirtualFrame frame,
public abstract static class OpenPtyNode extends PythonBuiltinNode {
@Specialization
- Object openpty(VirtualFrame frame,
+ static Object openpty(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- OpenPtyResult result = posixLib.openpty(getPosixSupport());
- posixLib.setInheritable(getPosixSupport(), result.masterFd(), false);
- posixLib.setInheritable(getPosixSupport(), result.slaveFd(), false);
- return factory.createTuple(new int[]{result.masterFd(), result.slaveFd()});
+ OpenPtyResult result = posixLib.openpty(context.getPosixSupport());
+ posixLib.setInheritable(context.getPosixSupport(), result.masterFd(), false);
+ posixLib.setInheritable(context.getPosixSupport(), result.slaveFd(), false);
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new int[]{result.masterFd(), result.slaveFd()});
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -844,9 +863,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
+ static int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached InlinedBranchProfile errorProfile,
@Cached GilNode gil,
@@ -860,11 +880,11 @@ int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
try {
while (true) {
try {
- return posixLib.openat(getPosixSupport(), dirFd, path.value, fixedFlags, mode);
+ return posixLib.openat(context.getPosixSupport(), dirFd, path.value, fixedFlags, mode);
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
gil.acquire(); // need GIL to construct OSError
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
@@ -888,19 +908,19 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone close(VirtualFrame frame, int fd,
+ static PNone close(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- PythonContext ctx = getContext();
- if (ctx.getSharedMultiprocessingData().decrementFDRefCount(fd)) {
+ if (context.getSharedMultiprocessingData().decrementFDRefCount(fd)) {
return PNone.NONE;
}
gil.release(true);
try {
- posixLib.close(getPosixSupport(), fd);
+ posixLib.close(context.getPosixSupport(), fd);
} finally {
gil.acquire();
}
@@ -923,45 +943,46 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PBytes doRead(VirtualFrame frame, int fd, int length,
+ static PBytes doRead(VirtualFrame frame, int fd, int length,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile1,
@Cached InlinedBranchProfile errorProfile2,
@Cached GilNode gil,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
if (length < 0) {
int error = OSErrorEnum.EINVAL.getNumber();
- throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, error, posixLib.strerror(getPosixSupport(), error));
+ throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, error, posixLib.strerror(context.getPosixSupport(), error));
}
try {
- return read(fd, length, inliningTarget, posixLib, errorProfile1, gil, factory);
+ return read(fd, length, inliningTarget, posixLib, context.getPosixSupport(), errorProfile1, gil);
} catch (PosixException e) {
errorProfile2.enter(inliningTarget);
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
}
- public PBytes read(int fd, int length,
+ public static PBytes read(int fd, int length,
Node inliningTarget,
PosixSupportLibrary posixLib,
- InlinedBranchProfile errorProfile, GilNode gil, PythonObjectFactory factory) throws PosixException {
+ PosixSupport posixSupport,
+ InlinedBranchProfile errorProfile, GilNode gil) throws PosixException {
gil.release(true);
try {
while (true) {
try {
- Buffer result = posixLib.read(getPosixSupport(), fd, length);
+ Buffer result = posixLib.read(posixSupport, fd, length);
if (result.length > Integer.MAX_VALUE) {
// sanity check that it is safe to cast result.length to int, to be
// removed once we support large arrays
throw CompilerDirectives.shouldNotReachHere("Posix read() returned more bytes than requested");
}
- return factory.createBytes(result.data, 0, (int) result.length);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), result.data, (int) result.length);
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
throw e;
}
@@ -989,12 +1010,13 @@ static long doWrite(VirtualFrame frame, int fd, Object dataBuffer,
@Bind("this") Node inliningTarget,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("dataBuffer") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return write(fd, bufferLib.getInternalOrCopiedByteArray(dataBuffer), bufferLib.getBufferLength(dataBuffer), inliningTarget, posixLib, errorProfile, gil);
+ return write(fd, bufferLib.getInternalOrCopiedByteArray(dataBuffer), bufferLib.getBufferLength(dataBuffer), inliningTarget, posixLib, context.getPosixSupport(), errorProfile, gil);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} finally {
@@ -1003,13 +1025,13 @@ static long doWrite(VirtualFrame frame, int fd, Object dataBuffer,
}
public static long write(int fd, byte[] dataBytes,
- int dataLen, Node inliningTarget, PosixSupportLibrary posixLib,
+ int dataLen, Node inliningTarget, PosixSupportLibrary posixLib, PosixSupport posixSupport,
InlinedBranchProfile errorProfile, GilNode gil) throws PosixException {
gil.release(true);
try {
while (true) {
try {
- return posixLib.write(PosixSupport.get(inliningTarget), fd, new Buffer(dataBytes, dataLen));
+ return posixLib.write(posixSupport, fd, new Buffer(dataBytes, dataLen));
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
@@ -1036,12 +1058,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int dup(VirtualFrame frame, int fd,
+ static int dup(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.dup(getPosixSupport(), fd);
+ return posixLib.dup(context.getPosixSupport(), fd);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1061,19 +1084,20 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int dup2(VirtualFrame frame, int fd, int fd2, boolean inheritable,
+ static int dup2(VirtualFrame frame, int fd, int fd2, boolean inheritable,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
if (fd < 0 || fd2 < 0) {
// CPython does not set errno here and raises a 'random' OSError
// (possibly with errno=0 Success)
int error = OSErrorEnum.EINVAL.getNumber();
- throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, error, posixLib.strerror(getPosixSupport(), error));
+ throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, error, posixLib.strerror(context.getPosixSupport(), error));
}
try {
- return posixLib.dup2(getPosixSupport(), fd, fd2, inheritable);
+ return posixLib.dup2(context.getPosixSupport(), fd, fd2, inheritable);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1091,12 +1115,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean getInheritable(VirtualFrame frame, int fd,
+ static boolean getInheritable(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.getInheritable(getPosixSupport(), fd);
+ return posixLib.getInheritable(context.getPosixSupport(), fd);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1115,13 +1140,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone setInheritable(VirtualFrame frame, int fd, int inheritable,
+ static PNone setInheritable(VirtualFrame frame, int fd, int inheritable,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
// not sure why inheritable is not a boolean, but that is how they do it in CPython
- posixLib.setInheritable(getPosixSupport(), fd, inheritable != 0);
+ posixLib.setInheritable(context.getPosixSupport(), fd, inheritable != 0);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1134,23 +1160,23 @@ PNone setInheritable(VirtualFrame frame, int fd, int inheritable,
abstract static class PipeNode extends PythonBuiltinNode {
@Specialization
- PTuple pipe(VirtualFrame frame,
+ static PTuple pipe(VirtualFrame frame,
@Bind("this") Node inliningTarget,
@Cached GilNode gil,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
int[] pipe;
gil.release(true);
try {
- pipe = posixLib.pipe(getPosixSupport());
+ pipe = posixLib.pipe(context.getPosixSupport());
} catch (PosixException e) {
gil.acquire(); // need to acquire the gil to construct the OSError object
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} finally {
gil.acquire();
}
- return factory.createTuple(new Object[]{pipe[0], pipe[1]});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{pipe[0], pipe[1]});
}
}
@@ -1181,12 +1207,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- long lseek(VirtualFrame frame, int fd, long pos, int how,
+ static long lseek(VirtualFrame frame, int fd, long pos, int how,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.lseek(getPosixSupport(), fd, pos, mapPythonSeekWhenceToPosix(how));
+ return posixLib.lseek(context.getPosixSupport(), fd, pos, mapPythonSeekWhenceToPosix(how));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1207,8 +1234,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PNone ftruncate(VirtualFrame frame, int fd, long length,
@Bind("this") Node inliningTarget,
- @Bind("getPosixSupport()") PosixSupport posixSupport,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
@Cached InlinedBranchProfile errorProfile,
@@ -1218,7 +1245,7 @@ static PNone ftruncate(VirtualFrame frame, int fd, long length,
try {
gil.release(true);
try {
- posixLib.ftruncate(posixSupport, fd, length);
+ posixLib.ftruncate(context.getPosixSupport(), fd, length);
} finally {
gil.acquire();
}
@@ -1249,8 +1276,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PNone truncate(VirtualFrame frame, PosixPath path, long length,
@Bind("this") Node inliningTarget,
- @Bind("getPosixSupport()") PosixSupport posixSupport,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
@@ -1258,7 +1285,7 @@ static PNone truncate(VirtualFrame frame, PosixPath path, long length,
try {
gil.release(true);
try {
- posixLib.truncate(posixSupport, path.value, length);
+ posixLib.truncate(context.getPosixSupport(), path.value, length);
} finally {
gil.acquire();
}
@@ -1271,13 +1298,13 @@ static PNone truncate(VirtualFrame frame, PosixPath path, long length,
@Specialization
static PNone ftruncate(VirtualFrame frame, PosixFd fd, long length,
@Bind("this") Node inliningTarget,
- @Bind("getPosixSupport()") PosixSupport posixSupport,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
@Shared @Cached GilNode gil,
@Cached InlinedBranchProfile errorProfile,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
- return FtruncateNode.ftruncate(frame, fd.fd, length, inliningTarget, posixSupport, posixLib, auditNode, gil, errorProfile, constructAndRaiseNode);
+ return FtruncateNode.ftruncate(frame, fd.fd, length, inliningTarget, context, posixLib, auditNode, gil, errorProfile, constructAndRaiseNode);
}
}
@@ -1292,19 +1319,20 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone fsync(VirtualFrame frame, int fd,
+ static PNone fsync(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
while (true) {
try {
- posixLib.fsync(getPosixSupport(), fd);
+ posixLib.fsync(context.getPosixSupport(), fd);
return PNone.NONE;
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1324,12 +1352,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean getBlocking(VirtualFrame frame, int fd,
+ static boolean getBlocking(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.getBlocking(getPosixSupport(), fd);
+ return posixLib.getBlocking(context.getPosixSupport(), fd);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1348,12 +1377,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone setBlocking(VirtualFrame frame, int fd, boolean blocking,
+ static PNone setBlocking(VirtualFrame frame, int fd, boolean blocking,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.setBlocking(getPosixSupport(), fd, blocking);
+ posixLib.setBlocking(context.getPosixSupport(), fd, blocking);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1372,15 +1402,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple getTerminalSize(VirtualFrame frame, int fd,
+ static PTuple getTerminalSize(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
// TODO default value should be fileno(stdout)
try {
- int[] result = posixLib.getTerminalSize(getPosixSupport(), fd);
- return factory.createStructSeq(TERMINAL_SIZE_DESC, result[0], result[1]);
+ int[] result = posixLib.getTerminalSize(context.getPosixSupport(), fd);
+ return PFactory.createStructSeq(context.getLanguage(inliningTarget), TERMINAL_SIZE_DESC, result[0], result[1]);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1400,15 +1430,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple doStatPath(VirtualFrame frame, PosixPath path, int dirFd, boolean followSymlinks,
+ static PTuple doStatPath(VirtualFrame frame, PosixPath path, int dirFd, boolean followSymlinks,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared("positive") @Cached InlinedConditionProfile positiveLongProfile,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- long[] out = posixLib.fstatat(getPosixSupport(), dirFd, path.value, followSymlinks);
- return createStatResult(inliningTarget, factory, positiveLongProfile, out);
+ long[] out = posixLib.fstatat(context.getPosixSupport(), dirFd, path.value, followSymlinks);
+ return createStatResult(inliningTarget, context.getLanguage(inliningTarget), positiveLongProfile, out);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1429,15 +1459,15 @@ static PTuple doStatFdWithFollowSymlinks(VirtualFrame frame, PosixFd fd, int dir
}
@Specialization(guards = {"isDefault(dirFd)", "followSymlinks"})
- PTuple doStatFd(VirtualFrame frame, PosixFd fd, @SuppressWarnings("unused") int dirFd, @SuppressWarnings("unused") boolean followSymlinks,
+ static PTuple doStatFd(VirtualFrame frame, PosixFd fd, @SuppressWarnings("unused") int dirFd, @SuppressWarnings("unused") boolean followSymlinks,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared("positive") @Cached InlinedConditionProfile positiveLongProfile,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- long[] out = posixLib.fstat(getPosixSupport(), fd.fd);
- return createStatResult(inliningTarget, factory, positiveLongProfile, out);
+ long[] out = posixLib.fstat(context.getPosixSupport(), fd.fd);
+ return createStatResult(inliningTarget, context.getLanguage(inliningTarget), positiveLongProfile, out);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, fd.originalObject);
}
@@ -1460,16 +1490,16 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple doStatPath(VirtualFrame frame, PosixPath path, int dirFd,
+ static PTuple doStatPath(VirtualFrame frame, PosixPath path, int dirFd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile positiveLongProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
// TODO we used to return all zeros when the filename was equal to sys.executable
- long[] out = posixLib.fstatat(getPosixSupport(), dirFd, path.value, false);
- return createStatResult(inliningTarget, factory, positiveLongProfile, out);
+ long[] out = posixLib.fstatat(context.getPosixSupport(), dirFd, path.value, false);
+ return createStatResult(inliningTarget, context.getLanguage(inliningTarget), positiveLongProfile, out);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1487,21 +1517,21 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple doStatFd(VirtualFrame frame, int fd,
+ static PTuple doStatFd(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile positiveLongProfile,
@Cached InlinedBranchProfile errorProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
while (true) {
try {
- long[] out = posixLib.fstat(getPosixSupport(), fd);
- return createStatResult(inliningTarget, factory, positiveLongProfile, out);
+ long[] out = posixLib.fstat(context.getPosixSupport(), fd);
+ return createStatResult(inliningTarget, context.getLanguage(inliningTarget), positiveLongProfile, out);
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1510,12 +1540,12 @@ PTuple doStatFd(VirtualFrame frame, int fd,
}
}
- private static PTuple createStatvfsResult(Node inliningTarget, long[] out, InlinedConditionProfile positiveLongProfile, PythonObjectFactory factory) {
+ private static PTuple createStatvfsResult(Node inliningTarget, long[] out, InlinedConditionProfile positiveLongProfile, PythonLanguage language) {
Object[] res = new Object[out.length];
for (int i = 0; i < out.length; i++) {
- res[i] = PInt.createPythonIntFromUnsignedLong(inliningTarget, factory, positiveLongProfile, out[i]);
+ res[i] = PInt.createPythonIntFromUnsignedLong(inliningTarget, language, positiveLongProfile, out[i]);
}
- return factory.createStructSeq(STATVFS_RESULT_DESC, res);
+ return PFactory.createStructSeq(language, STATVFS_RESULT_DESC, res);
}
@Builtin(name = "statvfs", minNumOfPositionalArgs = 1, parameterNames = {"path"})
@@ -1529,24 +1559,24 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple doStatvfs(VirtualFrame frame, PosixFileHandle posixFileHandle,
+ static PTuple doStatvfs(VirtualFrame frame, PosixFileHandle posixFileHandle,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile posixPathProfile,
@Cached InlinedConditionProfile positiveLongProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
long[] out;
try {
if (posixPathProfile.profile(inliningTarget, posixFileHandle instanceof PosixPath)) {
- out = posixLib.statvfs(getPosixSupport(), ((PosixPath) posixFileHandle).value);
+ out = posixLib.statvfs(context.getPosixSupport(), ((PosixPath) posixFileHandle).value);
} else {
- out = posixLib.fstatvfs(getPosixSupport(), ((PosixFd) posixFileHandle).fd);
+ out = posixLib.fstatvfs(context.getPosixSupport(), ((PosixFd) posixFileHandle).fd);
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, posixFileHandle.originalObject);
}
- return createStatvfsResult(inliningTarget, out, positiveLongProfile, factory);
+ return createStatvfsResult(inliningTarget, out, positiveLongProfile, context.getLanguage(inliningTarget));
}
}
@@ -1556,19 +1586,19 @@ PTuple doStatvfs(VirtualFrame frame, PosixFileHandle posixFileHandle,
abstract static class FStatvfsNode extends PythonUnaryClinicBuiltinNode {
@Specialization
- PTuple doStatvfs(VirtualFrame frame, int fd,
+ static PTuple doStatvfs(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile positiveLongProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
long[] out;
try {
- out = posixLib.fstatvfs(getPosixSupport(), fd);
+ out = posixLib.fstatvfs(context.getPosixSupport(), fd);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, fd);
}
- return createStatvfsResult(inliningTarget, out, positiveLongProfile, factory);
+ return createStatvfsResult(inliningTarget, out, positiveLongProfile, context.getLanguage(inliningTarget));
}
@Override
@@ -1583,13 +1613,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
abstract static class UnameNode extends PythonBuiltinNode {
@Specialization
- PTuple uname(VirtualFrame frame,
+ static PTuple uname(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return factory.createStructSeq(UNAME_RESULT_DESC, posixLib.uname(getPosixSupport()));
+ return PFactory.createStructSeq(context.getLanguage(inliningTarget), UNAME_RESULT_DESC, posixLib.uname(context.getPosixSupport()));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1608,14 +1638,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone unlink(VirtualFrame frame, PosixPath path, int dirFd,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PNone unlink(VirtualFrame frame, PosixPath path, int dirFd,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.remove", path.originalObject, dirFdForAudit(dirFd));
try {
- posixLib.unlinkat(getPosixSupport(), dirFd, path.value, false);
+ posixLib.unlinkat(context.getPosixSupport(), dirFd, path.value, false);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1653,12 +1684,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone link(VirtualFrame frame, PosixPath src, PosixPath dst, int srcDirFd, int dstDirFd, boolean followSymlinks,
+ static PNone link(VirtualFrame frame, PosixPath src, PosixPath dst, int srcDirFd, int dstDirFd, boolean followSymlinks,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.linkat(getPosixSupport(), srcDirFd, src.value, dstDirFd, dst.value, followSymlinks ? AT_SYMLINK_FOLLOW.value : 0);
+ posixLib.linkat(context.getPosixSupport(), srcDirFd, src.value, dstDirFd, dst.value, followSymlinks ? AT_SYMLINK_FOLLOW.value : 0);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, src.originalObject, dst.originalObject);
}
@@ -1680,12 +1712,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone symlink(VirtualFrame frame, PosixPath src, PosixPath dst, @SuppressWarnings("unused") boolean targetIsDir, int dirFd,
+ static PNone symlink(VirtualFrame frame, PosixPath src, PosixPath dst, @SuppressWarnings("unused") boolean targetIsDir, int dirFd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.symlinkat(getPosixSupport(), src.value, dirFd, dst.value);
+ posixLib.symlinkat(context.getPosixSupport(), src.value, dirFd, dst.value);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, src.originalObject, dst.originalObject);
}
@@ -1706,14 +1739,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone mkdir(VirtualFrame frame, PosixPath path, int mode, int dirFd,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PNone mkdir(VirtualFrame frame, PosixPath path, int mode, int dirFd,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.mkdir", path.originalObject, mode, dirFdForAudit(dirFd));
try {
- posixLib.mkdirat(getPosixSupport(), dirFd, path.value, mode);
+ posixLib.mkdirat(context.getPosixSupport(), dirFd, path.value, mode);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1733,14 +1767,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone rmdir(VirtualFrame frame, PosixPath path, int dirFd,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PNone rmdir(VirtualFrame frame, PosixPath path, int dirFd,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.rmdir", path.originalObject, dirFdForAudit(dirFd));
try {
- posixLib.unlinkat(getPosixSupport(), dirFd, path.value, true);
+ posixLib.unlinkat(context.getPosixSupport(), dirFd, path.value, true);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1752,12 +1787,13 @@ PNone rmdir(VirtualFrame frame, PosixPath path, int dirFd,
@GenerateNodeFactory
abstract static class GetcwdNode extends PythonBuiltinNode {
@Specialization
- TruffleString getcwd(VirtualFrame frame,
+ static TruffleString getcwd(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.getPathAsString(getPosixSupport(), posixLib.getcwd(getPosixSupport()));
+ return posixLib.getPathAsString(context.getPosixSupport(), posixLib.getcwd(context.getPosixSupport()));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1768,13 +1804,14 @@ TruffleString getcwd(VirtualFrame frame,
@GenerateNodeFactory
abstract static class GetcwdbNode extends PythonBuiltinNode {
@Specialization
- PBytes getcwdb(VirtualFrame frame,
+ static PBytes getcwdb(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return opaquePathToBytes(posixLib.getcwd(getPosixSupport()), posixLib, getPosixSupport(), factory);
+ Object path = posixLib.getcwd(context.getPosixSupport());
+ return opaquePathToBytes(path, posixLib, context.getPosixSupport(), context.getLanguage(inliningTarget));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1792,12 +1829,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone chdirPath(VirtualFrame frame, PosixPath path,
+ static PNone chdirPath(VirtualFrame frame, PosixPath path,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.chdir(getPosixSupport(), path.value);
+ posixLib.chdir(context.getPosixSupport(), path.value);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
@@ -1805,12 +1843,13 @@ PNone chdirPath(VirtualFrame frame, PosixPath path,
}
@Specialization
- PNone chdirFd(VirtualFrame frame, PosixFd fd,
+ static PNone chdirFd(VirtualFrame frame, PosixFd fd,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.fchdir(getPosixSupport(), fd.fd);
+ posixLib.fchdir(context.getPosixSupport(), fd.fd);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, fd.originalObject);
}
@@ -1829,19 +1868,20 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone fchdir(VirtualFrame frame, int fd,
+ static PNone fchdir(VirtualFrame frame, int fd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
while (true) {
try {
- posixLib.fchdir(getPosixSupport(), fd);
+ posixLib.fchdir(context.getPosixSupport(), fd);
return PNone.NONE;
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1861,12 +1901,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean isatty(int fd,
+ static boolean isatty(int fd,
@Cached GilNode gil,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
gil.release(true);
try {
- return posixLib.isatty(getPosixSupport(), fd);
+ return posixLib.isatty(context.getPosixSupport(), fd);
} finally {
gil.acquire();
}
@@ -1906,30 +1947,30 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PScandirIterator scandirPath(VirtualFrame frame, PosixPath path,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PScandirIterator scandirPath(VirtualFrame frame, PosixPath path,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.scandir", path.originalObject == null ? PNone.NONE : path.originalObject);
try {
- return factory.createScandirIterator(getContext(), posixLib.opendir(getPosixSupport(), path.value), path, false);
+ return PFactory.createScandirIterator(context.getLanguage(inliningTarget), context, posixLib.opendir(context.getPosixSupport(), path.value), path, false);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
}
@Specialization
- PScandirIterator scandirFd(VirtualFrame frame, PosixFd fd,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PScandirIterator scandirFd(VirtualFrame frame, PosixFd fd,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.scandir", fd.originalObject);
- Object dirStream = dupAndFdopendir(frame, inliningTarget, posixLib, getPosixSupport(), fd, constructAndRaiseNode);
- return factory.createScandirIterator(getContext(), dirStream, fd, true);
+ Object dirStream = dupAndFdopendir(frame, inliningTarget, posixLib, context.getPosixSupport(), fd, constructAndRaiseNode);
+ return PFactory.createScandirIterator(context.getLanguage(inliningTarget), context, dirStream, fd, true);
}
}
@@ -1944,56 +1985,57 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PList listdirPath(VirtualFrame frame, PosixPath path,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PList listdirPath(VirtualFrame frame, PosixPath path,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.listdir", path.originalObject == null ? PNone.NONE : path.originalObject);
try {
- return listdir(frame, inliningTarget, posixLib.opendir(getPosixSupport(), path.value), path.wasBufferLike, false, posixLib, constructAndRaiseNode, factory);
+ return listdir(frame, inliningTarget, posixLib.opendir(context.getPosixSupport(), path.value), path.wasBufferLike, false, posixLib, constructAndRaiseNode,
+ context.getLanguage(inliningTarget), context.getPosixSupport());
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
}
}
@Specialization
- PList listdirFd(VirtualFrame frame, PosixFd fd,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PList listdirFd(VirtualFrame frame, PosixFd fd,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.listdir", fd.originalObject);
- Object dirStream = dupAndFdopendir(frame, inliningTarget, posixLib, getPosixSupport(), fd, constructAndRaiseNode);
- return listdir(frame, inliningTarget, dirStream, false, true, posixLib, constructAndRaiseNode, factory);
+ Object dirStream = dupAndFdopendir(frame, inliningTarget, posixLib, context.getPosixSupport(), fd, constructAndRaiseNode);
+ return listdir(frame, inliningTarget, dirStream, false, true, posixLib, constructAndRaiseNode, context.getLanguage(inliningTarget), context.getPosixSupport());
}
- private PList listdir(VirtualFrame frame, Node inliningTarget, Object dirStream, boolean produceBytes, boolean needsRewind, PosixSupportLibrary posixLib,
- PConstructAndRaiseNode.Lazy constructAndRaiseNode, PythonObjectFactory factory) {
+ private static PList listdir(VirtualFrame frame, Node inliningTarget, Object dirStream, boolean produceBytes, boolean needsRewind, PosixSupportLibrary posixLib,
+ PConstructAndRaiseNode.Lazy constructAndRaiseNode, PythonLanguage language, PosixSupport posixSupport) {
List list = new ArrayList<>();
try {
while (true) {
- Object dirEntry = posixLib.readdir(getPosixSupport(), dirStream);
+ Object dirEntry = posixLib.readdir(posixSupport, dirStream);
if (dirEntry == null) {
- return factory.createList(listToArray(list));
+ return PFactory.createList(language, listToArray(list));
}
- Object name = posixLib.dirEntryGetName(getPosixSupport(), dirEntry);
+ Object name = posixLib.dirEntryGetName(posixSupport, dirEntry);
if (produceBytes) {
- addToList(list, opaquePathToBytes(name, posixLib, getPosixSupport(), factory));
+ addToList(list, opaquePathToBytes(name, posixLib, posixSupport, language));
} else {
- addToList(list, posixLib.getPathAsString(getPosixSupport(), name));
+ addToList(list, posixLib.getPathAsString(posixSupport, name));
}
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} finally {
if (needsRewind) {
- posixLib.rewinddir(getPosixSupport(), dirStream);
+ posixLib.rewinddir(posixSupport, dirStream);
}
try {
- posixLib.closedir(getPosixSupport(), dirStream);
+ posixLib.closedir(posixSupport, dirStream);
} catch (PosixException e) {
// ignored (CPython does not check the return value of closedir)
}
@@ -2127,12 +2169,13 @@ static PNone utimensat(VirtualFrame frame, PosixPath path, Object times, Object
@Bind("this") Node inliningTarget,
@Shared @Cached UtimeArgsToTimespecNode timespecNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
long[] timespec = timespecNode.execute(frame, times, ns);
auditNode.audit(inliningTarget, "os.utime", path.originalObject, checkNone(times), checkNone(ns), dirFdForAudit(dirFd));
try {
- posixLib.utimensat(PosixSupport.get(inliningTarget), dirFd, path.value, timespec, followSymlinks);
+ posixLib.utimensat(context.getPosixSupport(), dirFd, path.value, timespec, followSymlinks);
} catch (PosixException e) {
// filename is intentionally not included, see CPython's os_utime_impl
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2145,12 +2188,13 @@ static PNone utimes(VirtualFrame frame, PosixPath path, Object times, Object ns,
@Bind("this") Node inliningTarget,
@Shared @Cached UtimeArgsToTimespecNode timespecNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Timeval[] timeval = timespecNode.toTimeval(frame, times, ns);
auditNode.audit(inliningTarget, "os.utime", path.originalObject, checkNone(times), checkNone(ns), dirFdForAudit(dirFd));
try {
- posixLib.utimes(PosixSupport.get(inliningTarget), path.value, timeval);
+ posixLib.utimes(context.getPosixSupport(), path.value, timeval);
} catch (PosixException e) {
// filename is intentionally not included, see CPython's os_utime_impl
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2163,12 +2207,13 @@ static PNone lutimes(VirtualFrame frame, PosixPath path, Object times, Object ns
@Bind("this") Node inliningTarget,
@Shared @Cached UtimeArgsToTimespecNode timespecNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Timeval[] timeval = timespecNode.toTimeval(frame, times, ns);
auditNode.audit(inliningTarget, "os.utime", path.originalObject, checkNone(times), checkNone(ns), dirFdForAudit(dirFd));
try {
- posixLib.lutimes(PosixSupport.get(inliningTarget), path.value, timeval);
+ posixLib.lutimes(context.getPosixSupport(), path.value, timeval);
} catch (PosixException e) {
// filename is intentionally not included, see CPython's os_utime_impl
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2195,12 +2240,13 @@ static PNone futimens(VirtualFrame frame, PosixFd fd, Object times, Object ns, i
@Bind("this") Node inliningTarget,
@Shared @Cached UtimeArgsToTimespecNode timespecNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
long[] timespec = timespecNode.execute(frame, times, ns);
auditNode.audit(inliningTarget, "os.utime", fd.originalObject, checkNone(times), checkNone(ns), dirFdForAudit(dirFd));
try {
- posixLib.futimens(PosixSupport.get(inliningTarget), fd.fd, timespec);
+ posixLib.futimens(context.getPosixSupport(), fd.fd, timespec);
} catch (PosixException e) {
// filename is intentionally not included, see CPython's os_utime_impl
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2213,12 +2259,13 @@ static PNone futimes(VirtualFrame frame, PosixFd fd, Object times, Object ns, in
@Bind("this") Node inliningTarget,
@Shared @Cached UtimeArgsToTimespecNode timespecNode,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Timeval[] timeval = timespecNode.toTimeval(frame, times, ns);
auditNode.audit(inliningTarget, "os.utime", fd.originalObject, checkNone(times), checkNone(ns), dirFdForAudit(dirFd));
try {
- posixLib.futimes(PosixSupport.get(inliningTarget), fd.fd, timeval);
+ posixLib.futimes(context.getPosixSupport(), fd.fd, timeval);
} catch (PosixException e) {
// filename is intentionally not included, see CPython's os_utime_impl
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2259,14 +2306,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone rename(VirtualFrame frame, PosixPath src, PosixPath dst, int srcDirFd, int dstDirFd,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ static PNone rename(VirtualFrame frame, PosixPath src, PosixPath dst, int srcDirFd, int dstDirFd,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.rename", src.originalObject, dst.originalObject, dirFdForAudit(srcDirFd), dirFdForAudit(dstDirFd));
try {
- posixLib.renameat(getPosixSupport(), srcDirFd, src.value, dstDirFd, dst.value);
+ posixLib.renameat(context.getPosixSupport(), srcDirFd, src.value, dstDirFd, dst.value);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, src.originalObject, dst.originalObject);
}
@@ -2306,9 +2354,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean access(PosixPath path, int mode, int dirFd, boolean effectiveIds, boolean followSymlinks,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.faccessat(getPosixSupport(), dirFd, path.value, mode, effectiveIds, followSymlinks);
+ static boolean access(PosixPath path, int mode, int dirFd, boolean effectiveIds, boolean followSymlinks,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.faccessat(context.getPosixSupport(), dirFd, path.value, mode, effectiveIds, followSymlinks);
}
}
@@ -2323,14 +2372,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone fchmod(VirtualFrame frame, int fd, int mode,
+ static PNone fchmod(VirtualFrame frame, int fd, int mode,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.chmod", fd, mode, -1);
try {
- posixLib.fchmod(getPosixSupport(), fd, mode);
+ posixLib.fchmod(context.getPosixSupport(), fd, mode);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, fd);
}
@@ -2355,12 +2405,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
static PNone chmodFollow(VirtualFrame frame, PosixPath path, int mode, int dirFd, boolean followSymlinks,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
auditNode.audit(inliningTarget, "os.chmod", path.originalObject, mode, dirFdForAudit(dirFd));
try {
- posixLib.fchmodat(PosixSupport.get(inliningTarget), dirFd, path.value, mode, followSymlinks);
+ posixLib.fchmodat(context.getPosixSupport(), dirFd, path.value, mode, followSymlinks);
} catch (PosixException e) {
// TODO CPython checks for ENOTSUP as well
if (e.getErrorCode() == OSErrorEnum.EOPNOTSUPP.getNumber() && !followSymlinks) {
@@ -2376,10 +2427,11 @@ static PNone chmodFollow(VirtualFrame frame, PosixPath path, int mode, int dirFd
}
@Specialization
- PNone chmodFollow(VirtualFrame frame, PosixFd fd, int mode, int dirFd, @SuppressWarnings("unused") boolean followSymlinks,
+ static PNone chmodFollow(VirtualFrame frame, PosixFd fd, int mode, int dirFd, @SuppressWarnings("unused") boolean followSymlinks,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
// unused node to avoid mixing shared and non-shared inlined nodes
@SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) {
@@ -2389,7 +2441,7 @@ PNone chmodFollow(VirtualFrame frame, PosixFd fd, int mode, int dirFd, @Suppress
// arguments is used, CPython's implementation of chmod simply ignores dir_fd and
// follow_symlinks if a fd is specified instead of a path.
try {
- posixLib.fchmod(getPosixSupport(), fd.fd, mode);
+ posixLib.fchmod(context.getPosixSupport(), fd.fd, mode);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, fd.originalObject);
}
@@ -2404,17 +2456,18 @@ PNone chmodFollow(VirtualFrame frame, PosixFd fd, int mode, int dirFd, @Suppress
@GenerateNodeFactory
abstract static class FChownNode extends PythonTernaryClinicBuiltinNode {
@Specialization
- Object chown(VirtualFrame frame, int fd, long uid, long gid,
+ static Object chown(VirtualFrame frame, int fd, long uid, long gid,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.chown", fd, uid, gid, -1);
try {
gil.release(true);
try {
- posixLib.fchown(getPosixSupport(), fd, uid, gid);
+ posixLib.fchown(context.getPosixSupport(), fd, uid, gid);
} finally {
gil.acquire();
}
@@ -2437,17 +2490,18 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class LChownNode extends PythonTernaryClinicBuiltinNode {
@Specialization
- Object chown(VirtualFrame frame, PosixPath path, long uid, long gid,
+ static Object chown(VirtualFrame frame, PosixPath path, long uid, long gid,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "os.chown", path.originalObject, uid, gid, -1);
try {
gil.release(true);
try {
- posixLib.fchownat(getPosixSupport(), AT_FDCWD.value, path.value, uid, gid, false);
+ posixLib.fchownat(context.getPosixSupport(), AT_FDCWD.value, path.value, uid, gid, false);
} finally {
gil.acquire();
}
@@ -2475,7 +2529,8 @@ abstract static class ChownNode extends PythonClinicBuiltinNode {
static Object chown(VirtualFrame frame, PosixPath path, long uid, long gid, int dirFd, boolean followSymlinks,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
// unused node to avoid mixing shared and non-shared inlined nodes
@@ -2484,7 +2539,7 @@ static Object chown(VirtualFrame frame, PosixPath path, long uid, long gid, int
try {
gil.release(true);
try {
- posixLib.fchownat(PosixSupport.get(inliningTarget), dirFd, path.value, uid, gid, followSymlinks);
+ posixLib.fchownat(context.getPosixSupport(), dirFd, path.value, uid, gid, followSymlinks);
} finally {
gil.acquire();
}
@@ -2498,7 +2553,8 @@ static Object chown(VirtualFrame frame, PosixPath path, long uid, long gid, int
static Object chown(VirtualFrame frame, PosixFd fd, long uid, long gid, int dirFd, boolean followSymlinks,
@Bind("this") Node inliningTarget,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
@@ -2512,7 +2568,7 @@ static Object chown(VirtualFrame frame, PosixFd fd, long uid, long gid, int dirF
try {
gil.release(true);
try {
- posixLib.fchown(PosixSupport.get(inliningTarget), fd.fd, uid, gid);
+ posixLib.fchown(context.getPosixSupport(), fd.fd, uid, gid);
} finally {
gil.acquire();
}
@@ -2541,18 +2597,18 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- Object readlinkAsBytes(VirtualFrame frame, PosixPath path, int dirFd,
+ static Object readlinkAsBytes(VirtualFrame frame, PosixPath path, int dirFd,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile wasBufferLikeProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- Object link = posixLib.readlinkat(getPosixSupport(), dirFd, path.value);
+ Object link = posixLib.readlinkat(context.getPosixSupport(), dirFd, path.value);
if (wasBufferLikeProfile.profile(inliningTarget, path.wasBufferLike)) {
- return opaquePathToBytes(link, posixLib, getPosixSupport(), factory);
+ return opaquePathToBytes(link, posixLib, context.getPosixSupport(), context.getLanguage(inliningTarget));
} else {
- return posixLib.getPathAsString(getPosixSupport(), link);
+ return posixLib.getPathAsString(context.getPosixSupport(), link);
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
@@ -2571,9 +2627,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- TruffleString getStrError(int code,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.strerror(getPosixSupport(), code);
+ static TruffleString getStrError(int code,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.strerror(context.getPosixSupport(), code);
}
}
@@ -2622,23 +2679,23 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PTuple waitpid(VirtualFrame frame, long pid, int options,
+ static PTuple waitpid(VirtualFrame frame, long pid, int options,
@Bind("this") Node inliningTarget,
@Cached GilNode gil,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
gil.release(true);
try {
while (true) {
try {
- long[] result = posixLib.waitpid(getPosixSupport(), pid, options);
- return factory.createTuple(new Object[]{result[0], result[1]});
+ long[] result = posixLib.waitpid(context.getPosixSupport(), pid, options);
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{result[0], result[1]});
} catch (PosixException e) {
errorProfile.enter(inliningTarget);
if (e.getErrorCode() == OSErrorEnum.EINTR.getNumber()) {
- PythonContext.triggerAsyncActions(this);
+ PythonContext.triggerAsyncActions(inliningTarget);
} else {
gil.acquire();
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -2658,12 +2715,13 @@ PTuple waitpid(VirtualFrame frame, long pid, int options,
abstract static class WaitstatusToExitcodeNode extends PythonUnaryBuiltinNode {
@Specialization
static int waitstatusToExitcode(VirtualFrame frame, Object statusObj,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached PyLongAsIntNode longAsInt,
@Cached PRaiseNode.Lazy raiseNode) {
int status = longAsInt.execute(frame, inliningTarget, statusObj);
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
if (posixLib.wifexited(posixSupport, status)) {
int exitcode = posixLib.wexitstatus(posixSupport, status);
if (exitcode < 0) {
@@ -2696,9 +2754,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean wcoredump(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wcoredump(getPosixSupport(), status);
+ static boolean wcoredump(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wcoredump(context.getPosixSupport(), status);
}
}
@@ -2712,9 +2771,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean wifcontinued(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wifcontinued(getPosixSupport(), status);
+ static boolean wifcontinued(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wifcontinued(context.getPosixSupport(), status);
}
}
@@ -2728,9 +2788,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean wifstopped(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wifstopped(getPosixSupport(), status);
+ static boolean wifstopped(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wifstopped(context.getPosixSupport(), status);
}
}
@@ -2744,9 +2805,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean wifsignaled(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wifsignaled(getPosixSupport(), status);
+ static boolean wifsignaled(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wifsignaled(context.getPosixSupport(), status);
}
}
@@ -2760,9 +2822,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- boolean wifexited(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wifexited(getPosixSupport(), status);
+ static boolean wifexited(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wifexited(context.getPosixSupport(), status);
}
}
@@ -2776,9 +2839,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int wexitstatus(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wexitstatus(getPosixSupport(), status);
+ static int wexitstatus(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wexitstatus(context.getPosixSupport(), status);
}
}
@@ -2793,8 +2857,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
int wtermsig(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wtermsig(getPosixSupport(), status);
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wtermsig(context.getPosixSupport(), status);
}
}
@@ -2808,9 +2873,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int wstopsig(int status,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
- return posixLib.wstopsig(getPosixSupport(), status);
+ static int wstopsig(int status,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib) {
+ return posixLib.wstopsig(context.getPosixSupport(), status);
}
}
@@ -2824,11 +2890,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int system(PBytes command,
+ static int system(PBytes command,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil) {
// Unlike in other posix builtins, we go through str -> bytes -> byte[] -> String
// conversions for emulated backend because the bytes version after fsencode conversion
@@ -2837,8 +2904,8 @@ int system(PBytes command,
byte[] bytes = toBytesNode.execute(command);
gil.release(true);
try {
- Object cmdOpaque = posixLib.createPathFromBytes(getPosixSupport(), bytes);
- return posixLib.system(getPosixSupport(), cmdOpaque);
+ Object cmdOpaque = posixLib.createPathFromBytes(context.getPosixSupport(), bytes);
+ return posixLib.system(context.getPosixSupport(), cmdOpaque);
} finally {
gil.acquire();
}
@@ -2851,11 +2918,12 @@ int system(PBytes command,
@TypeSystemReference(PythonArithmeticTypes.class)
abstract static class URandomNode extends PythonUnaryClinicBuiltinNode {
@Specialization(guards = "size >= 0")
- PBytes urandom(int size,
- @Cached PythonObjectFactory factory) {
+ static PBytes urandom(int size,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonContext context) {
byte[] bytes = new byte[size];
- nextBytes(getContext().getSecureRandom(), bytes);
- return factory.createBytes(bytes);
+ nextBytes(context.getSecureRandom(), bytes);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), bytes);
}
@Specialization(guards = "size < 0")
@@ -2943,12 +3011,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- int umask(VirtualFrame frame, int mask,
+ static int umask(VirtualFrame frame, int mask,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.umask(getPosixSupport(), mask);
+ return posixLib.umask(context.getPosixSupport(), mask);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -2959,12 +3028,13 @@ int umask(VirtualFrame frame, int mask,
@GenerateNodeFactory
abstract static class CtermId extends PythonBuiltinNode {
@Specialization
- TruffleString ctermid(VirtualFrame frame,
+ static TruffleString ctermid(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixLib.ctermid(getPosixSupport());
+ return posixLib.ctermid(context.getPosixSupport());
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -2982,14 +3052,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone kill(VirtualFrame frame, long pid, int signal,
+ static PNone kill(VirtualFrame frame, long pid, int signal,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "kill", pid, signal);
try {
- posixLib.kill(getPosixSupport(), pid, signal);
+ posixLib.kill(context.getPosixSupport(), pid, signal);
return PNone.NONE;
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -3010,14 +3081,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- PNone kill(VirtualFrame frame, long pid, int signal,
+ static PNone kill(VirtualFrame frame, long pid, int signal,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "killpg", pid, signal);
try {
- posixLib.killpg(getPosixSupport(), pid, signal);
+ posixLib.killpg(context.getPosixSupport(), pid, signal);
return PNone.NONE;
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -3044,7 +3116,7 @@ static Object doTrivial(VirtualFrame frame, Object value,
abstract static class RegisterAtForkNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
- Object register(Object before, Object afterInChild, Object afterInParent) {
+ static Object register(Object before, Object afterInChild, Object afterInParent) {
// TODO should we at least call multiprocessing.util.register_after_fork?
return PNone.NONE;
}
@@ -3064,15 +3136,15 @@ public abstract static class StringOrBytesToBytesNode extends Node {
@Specialization(guards = "isString(strObj)")
static PBytes doString(Node inliningTarget, Object strObj,
+ @Bind PythonLanguage language,
@Cached CastToTruffleStringNode castToStringNode,
@Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached(inline = false) TruffleString.CopyToByteArrayNode copyToByteArrayNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached(inline = false) TruffleString.CopyToByteArrayNode copyToByteArrayNode) {
TruffleString str = castToStringNode.execute(inliningTarget, strObj);
TruffleString utf8 = switchEncodingNode.execute(str, Encoding.UTF_8);
byte[] bytes = new byte[utf8.byteLength(Encoding.UTF_8)];
copyToByteArrayNode.execute(utf8, 0, bytes, 0, bytes.length, Encoding.UTF_8);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
@Specialization
@@ -3095,18 +3167,20 @@ abstract static class StringOrBytesToOpaquePathNode extends Node {
@Specialization(guards = "isString(strObj)")
static Object doString(Node inliningTarget, Object strObj,
@Cached CastToTruffleStringNode castToStringNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
TruffleString str = castToStringNode.execute(inliningTarget, strObj);
- return checkPath(inliningTarget, posixLib.createPathFromString(PosixSupport.get(inliningTarget), str), raiseNode);
+ return checkPath(inliningTarget, posixLib.createPathFromString(context.getPosixSupport(), str), raiseNode);
}
@Specialization
static Object doBytes(Node inliningTarget, PBytes bytes,
@Cached(inline = false) BytesNodes.ToBytesNode toBytesNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- return checkPath(inliningTarget, posixLib.createPathFromBytes(PosixSupport.get(inliningTarget), toBytesNode.execute(bytes)), raiseNode);
+ return checkPath(inliningTarget, posixLib.createPathFromBytes(context.getPosixSupport(), toBytesNode.execute(bytes)), raiseNode);
}
private static Object checkPath(Node inliningTarget, Object path, PRaiseNode.Lazy raiseNode) {
@@ -3260,10 +3334,10 @@ static int dirFdForAudit(int dirFd) {
return dirFd == AT_FDCWD.value ? -1 : dirFd;
}
- public static PTuple createStatResult(Node inliningTarget, PythonObjectFactory factory, InlinedConditionProfile positiveLongProfile, long[] out) {
+ public static PTuple createStatResult(Node inliningTarget, PythonLanguage language, InlinedConditionProfile positiveLongProfile, long[] out) {
Object[] res = new Object[16];
for (int i = 0; i < 7; i++) {
- res[i] = PInt.createPythonIntFromUnsignedLong(inliningTarget, factory, positiveLongProfile, out[i]);
+ res[i] = PInt.createPythonIntFromUnsignedLong(inliningTarget, language, positiveLongProfile, out[i]);
}
res[6] = out[6];
for (int i = 7; i < 10; i++) {
@@ -3271,9 +3345,9 @@ public static PTuple createStatResult(Node inliningTarget, PythonObjectFactory f
long nsFraction = out[i + 3];
res[i] = seconds;
res[i + 3] = seconds + nsFraction * 1.0e-9;
- res[i + 6] = factory.createInt(convertToNanoseconds(seconds, nsFraction));
+ res[i + 6] = PFactory.createInt(language, convertToNanoseconds(seconds, nsFraction));
}
- return factory.createStructSeq(STAT_RESULT_DESC, res);
+ return PFactory.createStructSeq(language, STAT_RESULT_DESC, res);
}
@TruffleBoundary
@@ -3284,14 +3358,14 @@ private static BigInteger convertToNanoseconds(long sec, long ns) {
return r.add(BigInteger.valueOf(ns));
}
- public static PBytes opaquePathToBytes(Object opaquePath, PosixSupportLibrary posixLib, Object posixSupport, PythonObjectFactory factory) {
+ public static PBytes opaquePathToBytes(Object opaquePath, PosixSupportLibrary posixLib, Object posixSupport, PythonLanguage language) {
Buffer buf = posixLib.getPathAsBytes(posixSupport, opaquePath);
if (buf.length > Integer.MAX_VALUE) {
// sanity check that it is safe to cast result.length to int, to be removed once
// we support large arrays
throw CompilerDirectives.shouldNotReachHere("Posix path cannot fit into a Java array");
}
- return factory.createBytes(buf.data, 0, (int) buf.length);
+ return PFactory.createBytes(language, buf.data, (int) buf.length);
}
// ------------------
@@ -3335,7 +3409,7 @@ static int doFdInt(int value) {
}
@Specialization
- int doFdLong(long value,
+ static int doFdLong(long value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
return longToFd(inliningTarget, value, raiseNode);
@@ -3343,7 +3417,7 @@ int doFdLong(long value,
@Specialization
@SuppressWarnings("truffle-static-method")
- int doFdPInt(PInt value,
+ static int doFdPInt(PInt value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached CastToJavaLongLossyNode castToLongNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
@@ -3352,7 +3426,7 @@ int doFdPInt(PInt value,
@Specialization(guards = {"!isPNone(value)", "!canBeInteger(value)"})
@SuppressWarnings("truffle-static-method")
- int doIndex(VirtualFrame frame, Object value,
+ static int doIndex(VirtualFrame frame, Object value,
@Bind("this") Node inliningTarget,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberIndexNode indexNode,
@@ -3404,9 +3478,10 @@ public PathConversionNode(String functionName, String argumentName, boolean null
@Specialization(guards = "nullable")
PosixFileHandle doNone(@SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- Object path = posixLib.createPathFromString(PosixSupport.get(inliningTarget), T_DOT);
+ Object path = posixLib.createPathFromString(context.getPosixSupport(), T_DOT);
return new PosixPath(null, checkPath(inliningTarget, path, raiseNode), false);
}
@@ -3440,10 +3515,11 @@ static PosixFileHandle doFdPInt(PInt value,
PosixFileHandle doUnicode(Object value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached CastToTruffleStringNode castToStringNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
TruffleString str = castToStringNode.execute(inliningTarget, value);
- Object path = posixLib.createPathFromString(PosixSupport.get(inliningTarget), str);
+ Object path = posixLib.createPathFromString(context.getPosixSupport(), str);
return new PosixPath(value, checkPath(inliningTarget, path, raiseNode), false);
}
@@ -3452,9 +3528,10 @@ PosixFileHandle doUnicode(Object value,
PosixFileHandle doBytes(PBytes value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached BytesNodes.ToBytesNode toByteArrayNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- Object path = posixLib.createPathFromBytes(PosixSupport.get(inliningTarget), toByteArrayNode.execute(value));
+ Object path = posixLib.createPathFromBytes(context.getPosixSupport(), toByteArrayNode.execute(value));
return new PosixPath(value, checkPath(inliningTarget, path, raiseNode), true);
}
@@ -3466,7 +3543,7 @@ PosixFileHandle doBuffer(VirtualFrame frame, Object value,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("value") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached WarningsModuleBuiltins.WarnNode warningNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
PythonLanguage language = context.getLanguage(inliningTarget);
@@ -3474,7 +3551,7 @@ PosixFileHandle doBuffer(VirtualFrame frame, Object value,
try {
warningNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
ErrorMessages.S_S_SHOULD_BE_S_NOT_P, functionNameWithColon, argumentName, getAllowedTypes(), value);
- Object path = posixLib.createPathFromBytes(PosixSupport.get(inliningTarget), bufferLib.getCopiedByteArray(value));
+ Object path = posixLib.createPathFromBytes(context.getPosixSupport(), bufferLib.getCopiedByteArray(value));
return new PosixPath(value, checkPath(inliningTarget, path, raiseNode), true);
} finally {
bufferLib.release(buffer, frame, context, language, indirectCallData);
@@ -3503,7 +3580,8 @@ PosixFileHandle doGeneric(VirtualFrame frame, Object value,
@Cached("create(T___FSPATH__)") LookupAndCallUnaryNode callFSPath,
@Exclusive @Cached BytesNodes.ToBytesNode toByteArrayNode,
@Exclusive @Cached CastToTruffleStringNode castToStringNode,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object pathObject = callFSPath.executeObject(frame, value);
if (pathObject == PNone.NO_VALUE) {
@@ -3513,10 +3591,10 @@ PosixFileHandle doGeneric(VirtualFrame frame, Object value,
// 'pathObject' replaces 'value' as the PosixPath.originalObject for auditing purposes
// by design
if (pathObject instanceof PBytes) {
- return doBytes((PBytes) pathObject, inliningTarget, toByteArrayNode, posixLib, raiseNode);
+ return doBytes((PBytes) pathObject, inliningTarget, toByteArrayNode, context, posixLib, raiseNode);
}
if (PGuards.isString(pathObject)) {
- return doUnicode(pathObject, inliningTarget, castToStringNode, posixLib, raiseNode);
+ return doUnicode(pathObject, inliningTarget, castToStringNode, context, posixLib, raiseNode);
}
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, value, pathObject);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/Profiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/Profiler.java
new file mode 100644
index 0000000000..50c8feed4a
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/Profiler.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.builtins.modules;
+
+import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
+import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
+import com.oracle.truffle.api.object.Shape;
+import com.oracle.truffle.tools.profiler.CPUSampler;
+
+public class Profiler extends PythonBuiltinObject {
+ boolean subcalls;
+ boolean builtins;
+ double timeunit;
+ Object externalTimer;
+ double time;
+ final CPUSampler sampler;
+
+ public Profiler(Object cls, Shape instanceShape, CPUSampler sampler) {
+ super(cls, instanceShape);
+ this.sampler = sampler;
+ this.sampler.setFilter(SourceSectionFilter.newBuilder().includeInternal(true).build());
+ this.sampler.setPeriod(1);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
index a79a3d1df3..30994df2cf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -75,7 +76,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.PwdResult;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -126,12 +127,12 @@ public void initialize(Python3Core core) {
StructSequence.initType(core, STRUCT_PASSWD_DESC);
}
- private static Object[] createPwuidObject(Node inliningTarget, PwdResult pwd, PythonObjectFactory factory, InlinedConditionProfile unsignedConversionProfile) {
+ private static Object[] createPwuidObject(Node inliningTarget, PwdResult pwd, PythonLanguage language, InlinedConditionProfile unsignedConversionProfile) {
return new Object[]{
pwd.name,
T_NOT_AVAILABLE,
- PInt.createPythonIntFromUnsignedLong(inliningTarget, factory, unsignedConversionProfile, pwd.uid),
- PInt.createPythonIntFromUnsignedLong(inliningTarget, factory, unsignedConversionProfile, pwd.gid),
+ PInt.createPythonIntFromUnsignedLong(inliningTarget, language, unsignedConversionProfile, pwd.uid),
+ PInt.createPythonIntFromUnsignedLong(inliningTarget, language, unsignedConversionProfile, pwd.gid),
/* gecos: */ T_EMPTY_STRING,
pwd.dir,
pwd.shell
@@ -144,13 +145,13 @@ public abstract static class GetpwuidNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doGetpwuid(VirtualFrame frame, Object uidObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached UidConversionNode uidConversionNode,
@Cached IsBuiltinObjectProfile classProfile,
@Cached GilNode gil,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile unsignedConversionProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
long uid;
try {
@@ -163,7 +164,6 @@ static Object doGetpwuid(VirtualFrame frame, Object uidObj,
}
PwdResult pwd;
try {
- PythonContext context = PythonContext.get(inliningTarget);
gil.release(true);
try {
pwd = posixLib.getpwuid(context.getPosixSupport(), uid);
@@ -176,7 +176,8 @@ static Object doGetpwuid(VirtualFrame frame, Object uidObj,
if (pwd == null) {
throw raiseUidNotFound(raiseNode.get(inliningTarget));
}
- return factory.createStructSeq(STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, factory, unsignedConversionProfile));
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ return PFactory.createStructSeq(language, STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, language, unsignedConversionProfile));
}
private static PException raiseUidNotFound(PRaiseNode raiseNode) {
@@ -197,12 +198,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object doGetpwname(VirtualFrame frame, TruffleString name,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached GilNode gil,
@Cached StringOrBytesToOpaquePathNode encodeFSDefault,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile unsignedConversionProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
// Note: CPython also takes only Strings, not bytes, and then encodes the String
// StringOrBytesToOpaquePathNode already checks for embedded '\0'
@@ -210,7 +212,6 @@ static Object doGetpwname(VirtualFrame frame, TruffleString name,
PwdResult pwd;
try {
gil.release(true);
- PythonContext context = PythonContext.get(inliningTarget);
try {
pwd = posixLib.getpwnam(context.getPosixSupport(), nameEncoded);
} finally {
@@ -222,7 +223,7 @@ static Object doGetpwname(VirtualFrame frame, TruffleString name,
if (pwd == null) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, ErrorMessages.GETPWNAM_NAME_NOT_FOUND, name);
}
- return factory.createStructSeq(STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, factory, unsignedConversionProfile));
+ return PFactory.createStructSeq(language, STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, context.getLanguage(inliningTarget), unsignedConversionProfile));
}
}
@@ -230,24 +231,25 @@ static Object doGetpwname(VirtualFrame frame, TruffleString name,
@GenerateNodeFactory
public abstract static class GetpwallNode extends PythonBuiltinNode {
@Specialization
- Object doGetpall(VirtualFrame frame,
+ static Object doGetpall(VirtualFrame frame,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile unsignedConversionProfile,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
// We cannot release the GIL, because the underlying POSIX calls are not thread safe
PwdResult[] entries;
try {
- entries = posixLib.getpwentries(getPosixSupport());
+ entries = posixLib.getpwentries(context.getPosixSupport());
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
+ PythonLanguage language = context.getLanguage(inliningTarget);
Object[] result = new Object[entries.length];
for (int i = 0; i < result.length; i++) {
- result[i] = factory.createStructSeq(STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, entries[i], factory, unsignedConversionProfile));
+ result[i] = PFactory.createStructSeq(language, STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, entries[i], language, unsignedConversionProfile));
}
- return factory.createList(result);
+ return PFactory.createList(language, result);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/QueueModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/QueueModuleBuiltins.java
index 60ac362574..f083fdd6c3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/QueueModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/QueueModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,16 +44,19 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.queue.PSimpleQueue;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.BuiltinNames;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -81,8 +84,9 @@ abstract static class SimpleQueueNode extends PythonUnaryBuiltinNode {
@Specialization
static PSimpleQueue doGeneric(Object cls,
- @Cached PythonObjectFactory factory) {
- return factory.createSimpleQueue(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createSimpleQueue(language, cls, getInstanceShape.execute(cls));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/RandomModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/RandomModuleBuiltins.java
index 810cc61d65..8c1acbb386 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/RandomModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/RandomModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -29,16 +29,19 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.random.PRandom;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -64,8 +67,9 @@ abstract static class PRandomNode extends PythonBuiltinNode {
@Specialization
PRandom random(VirtualFrame frame, Object cls, Object seed,
- @Cached PythonObjectFactory factory) {
- PRandom random = factory.createRandom(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ PRandom random = PFactory.createRandom(language, cls, getInstanceShape.execute(cls));
setSeed.executeObject(frame, random, seed != PNone.NO_VALUE ? seed : PNone.NONE);
return random;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
index 1fd1a2df14..44d8d756aa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -62,7 +63,8 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.RusageResult;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -159,10 +161,11 @@ abstract static class GetRuUsageNode extends PythonBuiltinNode {
@Specialization
static PTuple getruusage(VirtualFrame frame, int who,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
RusageResult rusage;
try {
rusage = posixLib.getrusage(posixSupport, who);
@@ -174,7 +177,7 @@ static PTuple getruusage(VirtualFrame frame, int who,
}
}
- return PythonObjectFactory.getUncached().createStructSeq(STRUCT_RUSAGE_DESC,
+ return PFactory.createStructSeq(context.getLanguage(inliningTarget), STRUCT_RUSAGE_DESC,
rusage.ru_utime(), rusage.ru_stime(),
rusage.ru_maxrss(), rusage.ru_ixrss(), rusage.ru_idrss(), rusage.ru_isrss(),
rusage.ru_minflt(), rusage.ru_majflt(), rusage.ru_nswap(), rusage.ru_inblock(), rusage.ru_oublock(),
@@ -196,9 +199,9 @@ static int getPageSize() {
abstract static class GetRLimitNode extends PythonBuiltinNode {
@Specialization
static PTuple getPageSize(@SuppressWarnings("unused") int which,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// dummy implementation - report "unrestricted" for everything
- return factory.createTuple(new Object[]{RLIM_INFINITY, RLIM_INFINITY});
+ return PFactory.createTuple(language, new Object[]{RLIM_INFINITY, RLIM_INFINITY});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
index f861d643f0..3f82f666a6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import org.graalvm.collections.EconomicMap;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -88,7 +89,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -582,7 +583,7 @@ static void check(VirtualFrame frame, Object input, boolean expectBytes,
@NeverDefault
protected PTuple getSupportedBinaryInputTypes() {
- return PythonObjectFactory.getUncached().createTuple(new Object[]{PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PByteArray, PythonBuiltinClassType.PMMap,
+ return PFactory.createTuple(PythonLanguage.get(null), new Object[]{PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PByteArray, PythonBuiltinClassType.PMMap,
PythonBuiltinClassType.PMemoryView, PythonBuiltinClassType.PArray});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
index e03d62c3fd..2260a423dd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -98,7 +98,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.TruffleLogger;
@@ -220,9 +220,8 @@ public void postInitialize(Python3Core core) {
super.postInitialize(core);
loadDefaults();
PythonModule module = core.lookupBuiltinModule(T__SSL);
- PythonObjectFactory factory = core.factory();
module.setAttribute(tsLiteral("OPENSSL_VERSION_NUMBER"), 0);
- PTuple versionInfo = factory.createTuple(new int[]{0, 0, 0, 0, 0});
+ PTuple versionInfo = PFactory.createTuple(core.getLanguage(), new int[]{0, 0, 0, 0, 0});
module.setAttribute(tsLiteral("OPENSSL_VERSION_INFO"), versionInfo);
module.setAttribute(tsLiteral("OPENSSL_VERSION"), toTruffleStringUncached("GraalVM JSSE"));
module.setAttribute(tsLiteral("_DEFAULT_CIPHERS"), T_DEFAULT_CIPHER_STRING);
@@ -310,13 +309,13 @@ abstract static class Txt2ObjNode extends PythonBinaryClinicBuiltinNode {
static Object txt2obj(TruffleString txt, boolean name,
@Bind("this") Node inliningTarget,
@Cached TruffleString.EqualNode equalNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
// TODO implement properly
if (equalNode.execute(T_OID_TLS_SERVER, txt, TS_ENCODING)) {
- return factory.createTuple(new Object[]{129, T_SERVER_AUTH, T_TLS_WEB_SERVER_AUTHENTICATION, txt});
+ return PFactory.createTuple(language, new Object[]{129, T_SERVER_AUTH, T_TLS_WEB_SERVER_AUTHENTICATION, txt});
} else if (equalNode.execute(T_OID_TLS_CLIENT, txt, TS_ENCODING)) {
- return factory.createTuple(new Object[]{130, T_CLIENT_AUTH, T_TLS_WEB_CLIENT_AUTHENTICATION, txt});
+ return PFactory.createTuple(language, new Object[]{130, T_CLIENT_AUTH, T_TLS_WEB_CLIENT_AUTHENTICATION, txt});
}
throw raiseNode.get(inliningTarget).raise(NotImplementedError);
}
@@ -389,11 +388,11 @@ abstract static class GetDefaultVerifyPathsNode extends PythonBuiltinNode {
@Specialization
Object getDefaultPaths(
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// there is no default location given by graalpython
// in case the env variables SSL_CERT_FILE or SSL_CERT_DIR
// are provided, ssl.py#get_default_verify_paths will take care of it
- return factory.createTuple(new Object[]{T_SSL_CERT_FILE, T_EMPTY_STRING, T_SSL_CERT_DIR, T_EMPTY_STRING});
+ return PFactory.createTuple(language, new Object[]{T_SSL_CERT_FILE, T_EMPTY_STRING, T_SSL_CERT_DIR, T_EMPTY_STRING});
}
}
@@ -438,7 +437,7 @@ private Object decode(TruffleFile file) throws PException {
if (!(cert instanceof X509Certificate)) {
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSL_ERR_DECODING_PEM_FILE_UNEXPECTED_S, cert.getClass().getName());
}
- return CertUtils.decodeCertificate(getContext().factory(), (X509Certificate) certs.get(0));
+ return CertUtils.decodeCertificate((X509Certificate) certs.get(0), PythonLanguage.get(null));
} catch (IOException | DecoderException ex) {
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSL_CANT_OPEN_FILE_S, ex.toString());
} catch (CertificateException | CRLException ex) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
index 1214db605d..6f41808631 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -74,7 +75,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.SelectResult;
import com.oracle.graal.python.runtime.PosixSupportLibrary.Timeval;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.util.ArrayBuilder;
import com.oracle.graal.python.util.IntArrayBuilder;
@@ -132,7 +133,7 @@ static PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object x
@Cached InlinedBranchProfile notSelectableBranch,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
ObjAndFDList readFDs = seq2set(frame, inliningTarget, rlist, sizeNode, asFileDescriptor, callGetItemNode, constructListNode, raiseNode);
ObjAndFDList writeFDs = seq2set(frame, inliningTarget, wlist, sizeNode, asFileDescriptor, callGetItemNode, constructListNode, raiseNode);
@@ -161,18 +162,18 @@ static PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object x
// GraalPython hack: if one of the channels is not selectable (can happen only in
// the emulated mode), we just return everything.
notSelectableBranch.enter(inliningTarget);
- return factory.createTuple(new Object[]{rlist, wlist, xlist});
+ return PFactory.createTuple(language, new Object[]{rlist, wlist, xlist});
}
- return factory.createTuple(new PList[]{
- toList(result.getReadFds(), readFDs, factory),
- toList(result.getWriteFds(), writeFDs, factory),
- toList(result.getErrorFds(), xFDs, factory)});
+ return PFactory.createTuple(language, new PList[]{
+ toList(result.getReadFds(), readFDs, language),
+ toList(result.getWriteFds(), writeFDs, language),
+ toList(result.getErrorFds(), xFDs, language)});
}
/**
* Also maps the returned FDs back to their original Python level objects.
*/
- private static PList toList(boolean[] result, ObjAndFDList fds, PythonObjectFactory factory) {
+ private static PList toList(boolean[] result, ObjAndFDList fds, PythonLanguage language) {
Object[] resultObjs = new Object[result.length];
int resultObjsIdx = 0;
for (int i = 0; i < fds.fds.length; i++) {
@@ -180,7 +181,7 @@ private static PList toList(boolean[] result, ObjAndFDList fds, PythonObjectFact
resultObjs[resultObjsIdx++] = fds.objects[i];
}
}
- return factory.createList(PythonUtils.arrayCopyOf(resultObjs, resultObjsIdx));
+ return PFactory.createList(language, PythonUtils.arrayCopyOf(resultObjs, resultObjsIdx));
}
private static ObjAndFDList seq2set(VirtualFrame frame, Node inliningTarget, Object sequence, PyObjectSizeNode sizeNode, PyObjectAsFileDescriptor asFileDescriptor,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
index 43b55adaa2..654b436933 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,6 +59,7 @@
import org.graalvm.nativeimage.ImageInfo;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -90,7 +91,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -241,7 +242,7 @@ public int frameIndex() {
abstract static class ValidSignalsNode extends PythonBuiltinNode {
@Specialization
static Object validSignals(
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int signalCount = 0;
for (int i = 0; i < Signals.SIGNAL_NAMES.length; i++) {
if (Signals.SIGNAL_NAMES[i] != null) {
@@ -256,7 +257,7 @@ static Object validSignals(
}
}
- return factory.createTuple(validSignals);
+ return PFactory.createTuple(language, validSignals);
}
}
@@ -464,14 +465,14 @@ Object doIt(VirtualFrame frame, PythonModule self, int which, Object seconds, Ob
@Bind("this") Node inliningTarget,
@Cached PyTimeFromObjectNode timeFromObjectNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ModuleData moduleData = self.getModuleState(ModuleData.class);
long usDelay = toMicroseconds(frame, inliningTarget, seconds, timeFromObjectNode);
long usInterval = toMicroseconds(frame, inliningTarget, interval, timeFromObjectNode);
if (which != ITIMER_REAL) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.EINVAL);
}
- PTuple resultTuple = GetitimerNode.createResultTuple(factory, moduleData);
+ PTuple resultTuple = GetitimerNode.createResultTuple(language, moduleData);
setitimer(moduleData, usDelay, usInterval);
return resultTuple;
}
@@ -532,18 +533,18 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object doIt(VirtualFrame frame, PythonModule self, int which,
@Bind("this") Node inliningTarget,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ModuleData moduleData = self.getModuleState(ModuleData.class);
if (which != ITIMER_REAL) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.EINVAL);
}
- return createResultTuple(factory, moduleData);
+ return createResultTuple(language, moduleData);
}
- static PTuple createResultTuple(PythonObjectFactory factory, ModuleData moduleData) {
+ static PTuple createResultTuple(PythonLanguage language, ModuleData moduleData) {
long oldInterval = moduleData.itimerInterval;
long oldDelay = getOldDelay(moduleData);
- return factory.createTuple(new Object[]{oldDelay / (double) SEC_TO_US, oldInterval / (double) SEC_TO_US});
+ return PFactory.createTuple(language, new Object[]{oldDelay / (double) SEC_TO_US, oldInterval / (double) SEC_TO_US});
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
index f9e39499f6..20a289e4ce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -67,6 +67,7 @@
import java.nio.ByteOrder;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -80,12 +81,12 @@
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
-import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.builtins.objects.socket.SocketNodes;
import com.oracle.graal.python.builtins.objects.socket.SocketNodes.IdnaFromStringOrBytesConverterNode;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyLongAsIntNode;
import com.oracle.graal.python.lib.PyLongAsLongNode;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -116,11 +117,11 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddr;
import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddrLibrary;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.TimeUtils;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -212,17 +213,10 @@ private void addConstant(PosixConstants.IntConstant constant) {
public abstract static class SocketNode extends PythonVarargsBuiltinNode {
// All the "real" work is done by __init__
@Specialization
- Object socket(Object cls) {
- return factory().createSocket(cls);
- }
-
- @Override
- public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
- if (self == PNone.NO_VALUE && arguments.length > 0) {
- return socket(arguments[0]);
- }
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw VarargsBuiltinDirectInvocationNotSupported.INSTANCE;
+ Object socket(Object cls,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createSocket(language, cls, getInstanceShape.execute(cls));
}
}
@@ -253,8 +247,9 @@ static Object set(VirtualFrame frame, PythonModule module, Object value,
@GenerateNodeFactory
public abstract static class GetHostnameNode extends PythonBuiltinNode {
@Specialization
- TruffleString doGeneric(VirtualFrame frame,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static TruffleString doGeneric(VirtualFrame frame,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
@@ -263,7 +258,7 @@ TruffleString doGeneric(VirtualFrame frame,
try {
gil.release(true);
try {
- return posixLib.getPathAsString(getPosixSupport(), posixLib.gethostname(getPosixSupport()));
+ return posixLib.getPathAsString(context.getPosixSupport(), posixLib.gethostname(context.getPosixSupport()));
} finally {
gil.acquire();
}
@@ -277,8 +272,9 @@ TruffleString doGeneric(VirtualFrame frame,
@GenerateNodeFactory
public abstract static class GetHostByAddrNode extends PythonUnaryBuiltinNode {
@Specialization
- Object doGeneric(VirtualFrame frame, Object ip,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object doGeneric(VirtualFrame frame, Object ip,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoCursorLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary sockAddrLibrary,
@Bind("this") Node inliningTarget,
@@ -288,8 +284,7 @@ Object doGeneric(VirtualFrame frame, Object ip,
@Cached SocketNodes.MakeIpAddrNode makeIpAddrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @Cached GilNode gil,
- @Cached PythonObjectFactory factory) {
+ @Cached GilNode gil) {
/*
* TODO this uses getnameinfo and getaddrinfo to emulate the legacy gethostbyaddr. We
* might want to use the legacy API in the future
@@ -298,8 +293,8 @@ Object doGeneric(VirtualFrame frame, Object ip,
UniversalSockAddr addr = setIpAddrNode.execute(frame, idnaConverter.execute(frame, ip), AF_UNSPEC.value);
int family = sockAddrLibrary.getFamily(addr);
try {
- Object[] getnameinfoResult = posixLib.getnameinfo(getPosixSupport(), addr, NI_NAMEREQD.value);
- TruffleString hostname = posixLib.getPathAsString(getPosixSupport(), getnameinfoResult[0]);
+ Object[] getnameinfoResult = posixLib.getnameinfo(context.getPosixSupport(), addr, NI_NAMEREQD.value);
+ TruffleString hostname = posixLib.getPathAsString(context.getPosixSupport(), getnameinfoResult[0]);
SequenceStorage storage = new ObjectSequenceStorage(5);
@@ -307,7 +302,7 @@ Object doGeneric(VirtualFrame frame, Object ip,
AddrInfoCursor cursor;
gil.release(true);
try {
- cursor = posixLib.getaddrinfo(getPosixSupport(), getnameinfoResult[0], posixLib.createPathFromString(getPosixSupport(), T_ZERO),
+ cursor = posixLib.getaddrinfo(context.getPosixSupport(), getnameinfoResult[0], posixLib.createPathFromString(context.getPosixSupport(), T_ZERO),
family, 0, 0, 0);
} finally {
gil.acquire();
@@ -323,7 +318,8 @@ Object doGeneric(VirtualFrame frame, Object ip,
} catch (GetAddrInfoException e1) {
// Ignore failing forward lookup and return at least the hostname
}
- return factory.createTuple(new Object[]{hostname, factory.createList(), factory.createList(storage)});
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ return PFactory.createTuple(language, new Object[]{hostname, PFactory.createList(language), PFactory.createList(language, storage)});
} catch (GetAddrInfoException e) {
// TODO convert error code from gaierror to herror
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketHError, new Object[]{1, e.getMessageAsTruffleString()});
@@ -340,21 +336,21 @@ protected static IdnaFromStringOrBytesConverterNode createIdnaConverter() {
@GenerateNodeFactory
public abstract static class GetHostByNameNode extends PythonUnaryBuiltinNode {
@Specialization
- TruffleString getHostByName(VirtualFrame frame, Object nameObj,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static TruffleString getHostByName(VirtualFrame frame, Object nameObj,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary addrLib,
@Bind("this") Node inliningTarget,
@Cached("createIdnaConverter()") IdnaFromStringOrBytesConverterNode idnaConverter,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached SocketNodes.SetIpAddrNode setIpAddrNode,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
byte[] name = idnaConverter.execute(frame, nameObj);
- auditNode.audit(inliningTarget, "socket.gethostbyname", factory.createTuple(new Object[]{nameObj}));
+ auditNode.audit(inliningTarget, "socket.gethostbyname", PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{nameObj}));
UniversalSockAddr addr = setIpAddrNode.execute(frame, name, AF_INET.value);
Inet4SockAddr inet4SockAddr = addrLib.asInet4SockAddr(addr);
try {
- return posixLib.getPathAsString(getPosixSupport(), posixLib.inet_ntop(getPosixSupport(), AF_INET.value, inet4SockAddr.getAddressAsBytes()));
+ return posixLib.getPathAsString(context.getPosixSupport(), posixLib.inet_ntop(context.getPosixSupport(), AF_INET.value, inet4SockAddr.getAddressAsBytes()));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -370,35 +366,36 @@ protected static IdnaFromStringOrBytesConverterNode createIdnaConverter() {
@GenerateNodeFactory
public abstract static class GetHostByNameExNode extends PythonUnaryBuiltinNode {
@Specialization
- Object get(VirtualFrame frame, Object nameObj,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object get(VirtualFrame frame, Object nameObj,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary addrLib,
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoCursorLib,
@Bind("this") Node inliningTarget,
@Cached("createIdnaConverter()") IdnaFromStringOrBytesConverterNode idnaConverter,
@Cached SysModuleBuiltins.AuditNode auditNode,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
byte[] name = idnaConverter.execute(frame, nameObj);
// The event name is really without the _ex, it's not a copy-paste error
- auditNode.audit(inliningTarget, "socket.gethostbyname", factory.createTuple(new Object[]{nameObj}));
+ auditNode.audit(inliningTarget, "socket.gethostbyname", PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{nameObj}));
/*
* TODO this uses getaddrinfo to emulate the legacy gethostbyname. It doesn't support
* aliases and multiple addresses. We might want to use the legacy gethostbyname_r API
* in the future
*/
try {
- AddrInfoCursor cursor = posixLib.getaddrinfo(getPosixSupport(), posixLib.createPathFromBytes(getPosixSupport(), name),
+ PosixSupport posixSupport = context.getPosixSupport();
+ AddrInfoCursor cursor = posixLib.getaddrinfo(posixSupport, posixLib.createPathFromBytes(posixSupport, name),
null, AF_INET.value, 0, 0, AI_CANONNAME.value);
try {
- TruffleString canonName = posixLib.getPathAsString(getPosixSupport(), addrInfoCursorLib.getCanonName(cursor));
+ TruffleString canonName = posixLib.getPathAsString(posixSupport, addrInfoCursorLib.getCanonName(cursor));
Inet4SockAddr inet4SockAddr = addrLib.asInet4SockAddr(addrInfoCursorLib.getSockAddr(cursor));
- TruffleString addr = posixLib.getPathAsString(getPosixSupport(), posixLib.inet_ntop(getPosixSupport(), AF_INET.value, inet4SockAddr.getAddressAsBytes()));
+ TruffleString addr = posixLib.getPathAsString(posixSupport, posixLib.inet_ntop(posixSupport, AF_INET.value, inet4SockAddr.getAddressAsBytes()));
// getaddrinfo doesn't support aliases
- PList aliases = factory.createList();
+ PList aliases = PFactory.createList(context.getLanguage(inliningTarget));
// we support just one address for now
- PList addrs = factory.createList(new Object[]{addr});
- return factory.createTuple(new Object[]{canonName, aliases, addrs});
+ PList addrs = PFactory.createList(context.getLanguage(inliningTarget), new Object[]{addr});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{canonName, aliases, addrs});
} finally {
addrInfoCursorLib.release(cursor);
}
@@ -424,7 +421,8 @@ public abstract static class GetServByNameNode extends PythonBinaryClinicBuiltin
static Object getServByName(TruffleString serviceName, Object protocolNameObj,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile noneProtocol,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoCursorLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary sockAddrLibrary,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@@ -454,7 +452,7 @@ static Object getServByName(TruffleString serviceName, Object protocolNameObj,
gil.release(true);
AddrInfoCursor cursor;
try {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
cursor = posixLib.getaddrinfo(posixSupport, null, posixLib.createPathFromString(posixSupport, serviceName), AF_INET.value, 0, protocol, 0);
} finally {
gil.acquire();
@@ -550,7 +548,8 @@ public abstract static class GetNameInfoNode extends PythonBinaryClinicBuiltinNo
@Specialization
static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoCursorLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary sockAddrLibrary,
@Cached GilNode gil,
@@ -560,7 +559,6 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached TruffleString.FromLongNode fromLongNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
SequenceStorage addr = sockaddr.getSequenceStorage();
int addrLen = addr.length();
@@ -593,7 +591,7 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
int family;
// TODO getaddrinfo lock?
gil.release(true);
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
try {
AddrInfoCursor cursor = posixLib.getaddrinfo(posixSupport, posixLib.createPathFromString(posixSupport, address),
posixLib.createPathFromString(posixSupport, fromLongNode.execute(port, TS_ENCODING, false)),
@@ -626,7 +624,7 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
Object[] getnameinfo = posixLib.getnameinfo(posixSupport, queryAddr, flags);
TruffleString host = posixLib.getPathAsString(posixSupport, getnameinfo[0]);
TruffleString service = posixLib.getPathAsString(posixSupport, getnameinfo[1]);
- return factory.createTuple(new Object[]{host, service});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{host, service});
} catch (GetAddrInfoException e) {
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessageAsTruffleString()});
}
@@ -655,7 +653,8 @@ public abstract static class GetAddrInfoNode extends PythonClinicBuiltinNode {
@Specialization
static Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObject, int family, int type, int proto, int flags,
@Bind("this") Node inliningTarget,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") AddrInfoCursorLibrary cursorLib,
@Cached InlinedExactClassProfile profile,
@Cached("createIdna()") IdnaFromStringOrBytesConverterNode idna,
@@ -668,10 +667,9 @@ static Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObje
@Cached SequenceStorageNodes.AppendNode appendNode,
@Cached TruffleString.FromLongNode fromLongNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object host = null;
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
if (hostObject != PNone.NONE) {
host = posixLib.createPathFromBytes(posixSupport, idna.execute(frame, hostObject));
}
@@ -712,10 +710,11 @@ static Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObje
if (cursorLib.getCanonName(cursor) != null) {
canonName = posixLib.getPathAsString(posixSupport, cursorLib.getCanonName(cursor));
}
- PTuple tuple = factory.createTuple(new Object[]{cursorLib.getFamily(cursor), cursorLib.getSockType(cursor), cursorLib.getProtocol(cursor), canonName, addr});
+ PTuple tuple = PFactory.createTuple(context.getLanguage(inliningTarget),
+ new Object[]{cursorLib.getFamily(cursor), cursorLib.getSockType(cursor), cursorLib.getProtocol(cursor), canonName, addr});
storage = appendNode.execute(inliningTarget, storage, tuple, SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
} while (cursorLib.next(cursor));
- return factory.createList(storage);
+ return PFactory.createList(context.getLanguage(inliningTarget), storage);
} finally {
cursorLib.release(cursor);
}
@@ -736,8 +735,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class CloseNode extends PythonUnaryBuiltinNode {
@Specialization
- Object close(VirtualFrame frame, Object fdObj,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object close(VirtualFrame frame, Object fdObj,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached GilNode gil,
@Cached PyLongAsIntNode asIntNode,
@@ -746,7 +746,7 @@ Object close(VirtualFrame frame, Object fdObj,
try {
gil.release(true);
try {
- posixLib.close(getPosixSupport(), fd);
+ posixLib.close(context.getPosixSupport(), fd);
} finally {
gil.acquire();
}
@@ -764,8 +764,9 @@ Object close(VirtualFrame frame, Object fdObj,
@GenerateNodeFactory
abstract static class DupNode extends PythonUnaryBuiltinNode {
@Specialization
- Object close(VirtualFrame frame, Object fdObj,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object close(VirtualFrame frame, Object fdObj,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached GilNode gil,
@Cached PyLongAsIntNode asIntNode,
@@ -774,12 +775,12 @@ Object close(VirtualFrame frame, Object fdObj,
try {
gil.release(true);
try {
- int dup = posixLib.dup(getPosixSupport(), fd);
+ int dup = posixLib.dup(context.getPosixSupport(), fd);
try {
- posixLib.setInheritable(getPosixSupport(), dup, false);
+ posixLib.setInheritable(context.getPosixSupport(), dup, false);
} catch (PosixException e1) {
try {
- posixLib.close(getPosixSupport(), dup);
+ posixLib.close(context.getPosixSupport(), dup);
} catch (PosixException e2) {
// ignore
}
@@ -801,15 +802,15 @@ abstract static class InetAtoNNode extends PythonUnaryClinicBuiltinNode {
@Specialization
static PBytes doConvert(TruffleString addr,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PythonObjectFactory factory,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
int converted = posixLib.inet_aton(posixSupport, posixLib.createPathFromString(posixSupport, addr));
byte[] bytes = new byte[4];
ByteArraySupport.bigEndian().putInt(bytes, 0, converted);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), bytes);
} catch (PosixSupportLibrary.InvalidAddressException e) {
throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.ILLEGAL_IP_ADDR_STRING_TO_INET_ATON);
}
@@ -830,7 +831,8 @@ static TruffleString doGeneric(VirtualFrame frame, Object addr,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("addr") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PRaiseNode.Lazy raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(addr, frame, indirectCallData);
try {
@@ -839,7 +841,7 @@ static TruffleString doGeneric(VirtualFrame frame, Object addr,
if (len != 4) {
throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.PACKED_IP_WRONG_LENGTH, "inet_ntoa");
}
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
Object result = posixLib.inet_ntoa(posixSupport, ByteArraySupport.bigEndian().getInt(bytes, 0));
return posixLib.getPathAsString(posixSupport, result);
} finally {
@@ -856,14 +858,14 @@ abstract static class InetPtoNNode extends PythonBinaryClinicBuiltinNode {
@Specialization
static PBytes doConvert(VirtualFrame frame, int family, TruffleString addr,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
byte[] bytes = posixLib.inet_pton(posixSupport, family, posixLib.createPathFromString(posixSupport, addr));
- return factory.createBytes(bytes);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), bytes);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} catch (PosixSupportLibrary.InvalidAddressException e) {
@@ -887,7 +889,8 @@ static TruffleString doGeneric(VirtualFrame frame, int family, Object obj,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("obj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(obj, frame, indirectCallData);
@@ -906,7 +909,7 @@ static TruffleString doGeneric(VirtualFrame frame, int family, Object obj,
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNKNOWN_ADDR_FAMILY, family);
}
try {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
Object result = posixLib.inet_ntop(posixSupport, family, bytes);
return posixLib.getPathAsString(posixSupport, result);
} catch (PosixException e) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StringModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StringModuleBuiltins.java
index 14abb5dd33..92086f7152 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StringModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StringModuleBuiltins.java
@@ -59,7 +59,7 @@
import com.oracle.graal.python.runtime.ExecutionContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -85,8 +85,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
PSequenceIterator formatterParser(VirtualFrame frame, TruffleString self,
- @Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PythonObjectFactory factory) {
+ @Cached("createFor(this)") IndirectCallData indirectCallData) {
TemplateFormatter formatter = new TemplateFormatter(self);
List parserList;
PythonContext context = PythonContext.get(this);
@@ -97,16 +96,16 @@ PSequenceIterator formatterParser(VirtualFrame frame, TruffleString self,
} finally {
ExecutionContext.IndirectCallContext.exit(frame, language, context, state);
}
- return parserListToIterator(parserList, factory);
+ return parserListToIterator(parserList, language);
}
}
- private static PSequenceIterator parserListToIterator(List parserList, PythonObjectFactory factory) {
+ private static PSequenceIterator parserListToIterator(List parserList, PythonLanguage language) {
Object[] tuples = new Object[parserList.size()];
for (int i = 0; i < tuples.length; i++) {
- tuples[i] = factory.createTuple(parserList.get(i));
+ tuples[i] = PFactory.createTuple(language, parserList.get(i));
}
- return factory.createSequenceIterator(factory.createList(tuples));
+ return PFactory.createSequenceIterator(language, PFactory.createList(language, tuples));
}
@Builtin(name = J_FORMATTER_FIELD_NAME_SPLIT, minNumOfPositionalArgs = 1, parameterNames = {"self"})
@@ -120,8 +119,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
Object formatterParser(VirtualFrame frame, TruffleString self,
- @Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PythonObjectFactory factory) {
+ @Cached("createFor(this)") IndirectCallData indirectCallData) {
TemplateFormatter formatter = new TemplateFormatter(self);
TemplateFormatter.FieldNameSplitResult result;
PythonContext context = PythonContext.get(this);
@@ -132,7 +130,7 @@ Object formatterParser(VirtualFrame frame, TruffleString self,
} finally {
ExecutionContext.IndirectCallContext.exit(frame, language, context, state);
}
- return factory.createTuple(new Object[]{result.first, parserListToIterator(result.parserList, factory)});
+ return PFactory.createTuple(language, new Object[]{result.first, parserListToIterator(result.parserList, language)});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
index 55787472b2..d70b4ad778 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
@@ -1,13 +1,10 @@
-/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2020 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
*/
package com.oracle.graal.python.builtins.modules;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARG_MUST_BE_STR_OR_BYTES;
-import static com.oracle.graal.python.nodes.ErrorMessages.BAD_CHR_IN_STRUCT_FMT;
-import static com.oracle.graal.python.nodes.ErrorMessages.REPEAT_COUNT_WITHOUT_FMT;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_BOOL;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_CHAR;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_DOUBLE;
@@ -52,7 +49,10 @@
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.T_LBL_VOID_PTR;
import static com.oracle.graal.python.nodes.BuiltinNames.J__STRUCT;
import static com.oracle.graal.python.nodes.BuiltinNames.T__STRUCT;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARG_MUST_BE_STR_OR_BYTES;
+import static com.oracle.graal.python.nodes.ErrorMessages.BAD_CHR_IN_STRUCT_FMT;
import static com.oracle.graal.python.nodes.ErrorMessages.EMBEDDED_NULL_CHARACTER;
+import static com.oracle.graal.python.nodes.ErrorMessages.REPEAT_COUNT_WITHOUT_FMT;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.StructError;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
@@ -63,6 +63,7 @@
import java.util.List;
import java.util.Set;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -80,7 +81,6 @@
import com.oracle.graal.python.builtins.objects.struct.FormatDef;
import com.oracle.graal.python.builtins.objects.struct.PStruct;
import com.oracle.graal.python.builtins.objects.struct.StructBuiltins;
-import com.oracle.graal.python.util.LRUCache;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -93,7 +93,8 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.graal.python.util.LRUCache;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -235,10 +236,9 @@ static PStruct struct(@SuppressWarnings("unused") Object cls, TruffleString form
@Bind("this") Node inliningTarget,
@Shared @Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @SuppressWarnings("unused") @Shared @Cached TruffleString.GetCodeRangeNode getCodeRangeNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @SuppressWarnings("unused") @Shared @Cached TruffleString.GetCodeRangeNode getCodeRangeNode) {
byte[] fmt = PythonUtils.getAsciiBytes(format, copyToByteArrayNode, switchEncodingNode);
- return factory.createStruct(createStructInternal(inliningTarget, fmt));
+ return PFactory.createStruct(PythonLanguage.get(inliningTarget), createStructInternal(inliningTarget, fmt));
}
@Specialization
@@ -247,18 +247,16 @@ static PStruct struct(Object cls, PString format,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Shared @Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @SuppressWarnings("unused") @Shared @Cached TruffleString.GetCodeRangeNode getCodeRangeNode,
- @Shared @Cached PythonObjectFactory factory) {
- return struct(cls, castToTruffleStringNode.execute(inliningTarget, format), inliningTarget, copyToByteArrayNode, switchEncodingNode, getCodeRangeNode, factory);
+ @SuppressWarnings("unused") @Shared @Cached TruffleString.GetCodeRangeNode getCodeRangeNode) {
+ return struct(cls, castToTruffleStringNode.execute(inliningTarget, format), inliningTarget, copyToByteArrayNode, switchEncodingNode, getCodeRangeNode);
}
@Specialization(limit = "1")
static PStruct struct(@SuppressWarnings("unused") Object cls, PBytes format,
@Bind("this") Node inliningTarget,
- @CachedLibrary("format") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory) {
+ @CachedLibrary("format") PythonBufferAccessLibrary bufferLib) {
byte[] fmt = bufferLib.getCopiedByteArray(format);
- return factory.createStruct(createStructInternal(inliningTarget, fmt));
+ return PFactory.createStruct(PythonLanguage.get(inliningTarget), createStructInternal(inliningTarget, fmt));
}
@Specialization(guards = {"!isPBytes(format)", "!isPString(format)", "!isAsciiTruffleString(format, getCodeRangeNode)"})
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
index d33bfc47fd..ef559ae7f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
@@ -230,7 +230,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.formatting.IntegerFormatter;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.CharsetMapping;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -507,8 +507,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
return SysModuleBuiltinsFactory.getFactories();
}
- protected static PSimpleNamespace makeImplementation(PythonObjectFactory factory, PTuple versionInfo, TruffleString gmultiarch) {
- final PSimpleNamespace ns = factory.createSimpleNamespace();
+ private static PSimpleNamespace makeImplementation(PythonLanguage language, PTuple versionInfo, TruffleString gmultiarch) {
+ final PSimpleNamespace ns = PFactory.createSimpleNamespace(language);
ns.setAttribute(tsLiteral("name"), T_GRAALPYTHON_ID);
/*- 'cache_tag' must match the format of mx.graalpython/mx_graalpython.py:graalpy_ext */
ns.setAttribute(T_CACHE_TAG, toTruffleStringUncached(J_GRAALPYTHON_ID +
@@ -522,6 +522,7 @@ protected static PSimpleNamespace makeImplementation(PythonObjectFactory factory
@Override
public void initialize(Python3Core core) {
+ PythonLanguage language = core.getLanguage();
StructSequence.initType(core, VERSION_INFO_DESC);
if (PythonOS.getPythonOS() == PLATFORM_WIN32) {
StructSequence.initType(core, WINDOWS_VER_DESC);
@@ -536,19 +537,18 @@ public void initialize(Python3Core core) {
addBuiltinConstant("abiflags", T_EMPTY_STRING);
addBuiltinConstant("byteorder", ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? T_LITTLE : T_BIG);
addBuiltinConstant("copyright", T_LICENSE);
- final PythonObjectFactory factory = PythonObjectFactory.getUncached();
- addBuiltinConstant(T_MODULES, factory.createDict());
- addBuiltinConstant("path", factory.createList());
- addBuiltinConstant("builtin_module_names", factory.createTuple(core.builtinModuleNames()));
+ addBuiltinConstant(T_MODULES, PFactory.createDict(language));
+ addBuiltinConstant("path", PFactory.createList(language));
+ addBuiltinConstant("builtin_module_names", PFactory.createTuple(language, core.builtinModuleNames()));
addBuiltinConstant("maxsize", MAXSIZE);
- final PTuple versionInfo = factory.createStructSeq(VERSION_INFO_DESC, PythonLanguage.MAJOR, PythonLanguage.MINOR, PythonLanguage.MICRO, PythonLanguage.RELEASE_LEVEL_STRING,
+ final PTuple versionInfo = PFactory.createStructSeq(language, VERSION_INFO_DESC, PythonLanguage.MAJOR, PythonLanguage.MINOR, PythonLanguage.MICRO, PythonLanguage.RELEASE_LEVEL_STRING,
PythonLanguage.RELEASE_SERIAL);
addBuiltinConstant("version_info", versionInfo);
addBuiltinConstant("api_version", PythonLanguage.API_VERSION);
addBuiltinConstant("version", toTruffleStringUncached(PythonLanguage.VERSION +
" (" + COMPILE_TIME + ")" +
"\n[Graal, " + Truffle.getRuntime().getName() + ", Java " + System.getProperty("java.version") + " (" + System.getProperty("os.arch") + ")]"));
- addBuiltinConstant("float_info", factory.createStructSeq(FLOAT_INFO_DESC,
+ addBuiltinConstant("float_info", PFactory.createStructSeq(language, FLOAT_INFO_DESC,
Double.MAX_VALUE, // DBL_MAX
Double.MAX_EXPONENT + 1, // DBL_MAX_EXP
308, // DBL_MIN_10_EXP
@@ -561,8 +561,8 @@ public void initialize(Python3Core core) {
2, // FLT_RADIX
1 // FLT_ROUNDS
));
- addBuiltinConstant("int_info", factory.createStructSeq(INT_INFO_DESC, 32, 4, INT_DEFAULT_MAX_STR_DIGITS, INT_MAX_STR_DIGITS_THRESHOLD));
- addBuiltinConstant("hash_info", factory.createStructSeq(HASH_INFO_DESC,
+ addBuiltinConstant("int_info", PFactory.createStructSeq(language, INT_INFO_DESC, 32, 4, INT_DEFAULT_MAX_STR_DIGITS, INT_MAX_STR_DIGITS_THRESHOLD));
+ addBuiltinConstant("hash_info", PFactory.createStructSeq(language, HASH_INFO_DESC,
64, // width
HASH_MODULUS, // modulus
HASH_INF, // inf
@@ -573,7 +573,7 @@ public void initialize(Python3Core core) {
0, // seed_bits
0 // cutoff
));
- addBuiltinConstant("thread_info", factory.createStructSeq(THREAD_INFO_DESC, PNone.NONE, PNone.NONE, PNone.NONE));
+ addBuiltinConstant("thread_info", PFactory.createStructSeq(language, THREAD_INFO_DESC, PNone.NONE, PNone.NONE, PNone.NONE));
addBuiltinConstant("maxunicode", IntegerFormatter.LIMIT_UNICODE.intValue() - 1);
PythonOS os = getPythonOS();
@@ -589,7 +589,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant(T_STDOUT, PNone.NONE);
addBuiltinConstant(T_STDERR, PNone.NONE);
- addBuiltinConstant("implementation", makeImplementation(factory, versionInfo, gmultiarch));
+ addBuiltinConstant("implementation", makeImplementation(language, versionInfo, gmultiarch));
addBuiltinConstant("hexversion", PythonLanguage.VERSION_HEX);
if (os == PLATFORM_WIN32) {
@@ -597,9 +597,9 @@ public void initialize(Python3Core core) {
}
addBuiltinConstant("float_repr_style", "short");
- addBuiltinConstant("meta_path", factory.createList());
- addBuiltinConstant("path_hooks", factory.createList());
- addBuiltinConstant("path_importer_cache", factory.createDict());
+ addBuiltinConstant("meta_path", PFactory.createList(language));
+ addBuiltinConstant("path_hooks", PFactory.createList(language));
+ addBuiltinConstant("path_importer_cache", PFactory.createDict(language));
// default prompt for interactive shell
addBuiltinConstant("ps1", ">>> ");
@@ -607,7 +607,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant("ps2", "... ");
// CPython builds for distros report empty strings too, because they are built from
// tarballs, not git
- addBuiltinConstant("_git", factory.createTuple(new Object[]{T_GRAALPYTHON_ID, T_EMPTY_STRING, T_EMPTY_STRING}));
+ addBuiltinConstant("_git", PFactory.createTuple(language, new Object[]{T_GRAALPYTHON_ID, T_EMPTY_STRING, T_EMPTY_STRING}));
if (PythonOS.getPythonOS() == PLATFORM_WIN32) {
addBuiltinConstant("_vpath", "");
@@ -623,12 +623,12 @@ public void postInitialize0(Python3Core core) {
super.postInitialize(core);
PythonModule sys = core.lookupBuiltinModule(T_SYS);
PythonContext context = core.getContext();
+ PythonLanguage language = core.getLanguage();
String[] args = context.getEnv().getApplicationArguments();
- final PythonObjectFactory factory = PythonObjectFactory.getUncached();
- sys.setAttribute(tsLiteral("argv"), factory.createList(convertToObjectArray(args)));
- sys.setAttribute(tsLiteral("orig_argv"), factory.createList(convertToObjectArray(PythonOptions.getOrigArgv(core.getContext()))));
+ sys.setAttribute(tsLiteral("argv"), PFactory.createList(language, convertToObjectArray(args)));
+ sys.setAttribute(tsLiteral("orig_argv"), PFactory.createList(language, convertToObjectArray(PythonOptions.getOrigArgv(core.getContext()))));
- sys.setAttribute(tsLiteral("stdlib_module_names"), createStdLibModulesSet(factory));
+ sys.setAttribute(tsLiteral("stdlib_module_names"), createStdLibModulesSet(language));
TruffleString prefix = context.getSysPrefix();
for (TruffleString name : SysModuleBuiltins.SYS_PREFIX_ATTRIBUTES) {
@@ -666,7 +666,7 @@ public void postInitialize0(Python3Core core) {
} else {
warnoptions = PythonUtils.EMPTY_OBJECT_ARRAY;
}
- sys.setAttribute(tsLiteral("warnoptions"), factory.createList(warnoptions));
+ sys.setAttribute(tsLiteral("warnoptions"), PFactory.createList(language, warnoptions));
Env env = context.getEnv();
TruffleString pythonPath = context.getOption(PythonOptions.PythonPath);
@@ -695,9 +695,9 @@ public void postInitialize0(Python3Core core) {
// include our native modules on the path
path[pathIdx++] = toTruffleStringUncached(capiHome + env.getFileNameSeparator() + "modules");
}
- PList sysPaths = factory.createList(path);
+ PList sysPaths = PFactory.createList(language, path);
sys.setAttribute(tsLiteral("path"), sysPaths);
- sys.setAttribute(tsLiteral("flags"), factory.createStructSeq(SysModuleBuiltins.FLAGS_DESC,
+ sys.setAttribute(tsLiteral("flags"), PFactory.createStructSeq(language, SysModuleBuiltins.FLAGS_DESC,
PInt.intValue(!context.getOption(PythonOptions.PythonOptimizeFlag)), // debug
PInt.intValue(context.getOption(PythonOptions.InspectFlag)), // inspect
PInt.intValue(context.getOption(PythonOptions.TerminalIsInteractive)), // interactive
@@ -723,18 +723,18 @@ public void postInitialize0(Python3Core core) {
sys.setAttribute(T___BREAKPOINTHOOK__, sys.getAttribute(T_BREAKPOINTHOOK));
}
- private static PFrozenSet createStdLibModulesSet(PythonObjectFactory factory) {
+ private static PFrozenSet createStdLibModulesSet(PythonLanguage language) {
EconomicMapStorage storage = EconomicMapStorage.create(STDLIB_MODULE_NAMES.length);
for (String s : STDLIB_MODULE_NAMES) {
storage.putUncachedWithJavaEq(s, PNone.NONE);
}
- return factory.createFrozenSet(storage);
+ return PFactory.createFrozenSet(language, storage);
}
/**
* Like {@link PythonUtils#toTruffleStringArrayUncached(String[])}, but creates an array of
* {@link Object}'s. The intended use of this method is in slow-path in calls to methods like
- * {@link PythonObjectFactory#createTuple(Object[])}.
+ * {@link PFactory#createTuple}.
*/
private static Object[] convertToObjectArray(String[] src) {
if (src == null) {
@@ -765,8 +765,8 @@ public void postInitialize(Python3Core core) {
@TruffleBoundary
static void initStd(Python3Core core) {
- PythonObjectFactory factory = core.factory();
PythonContext context = core.getContext();
+ PythonLanguage language = core.getLanguage();
// wrap std in/out/err
GraalPythonModuleBuiltins gp = (GraalPythonModuleBuiltins) core.lookupBuiltinModule(T___GRAALPYTHON__).getBuiltins();
@@ -779,35 +779,35 @@ static void initStd(Python3Core core) {
// Note that stdin is always buffered, this only applies to stdout and stderr
boolean buffering = !context.getOption(PythonOptions.UnbufferedIO);
- PFileIO stdinFileIO = factory.createFileIO(PythonBuiltinClassType.PFileIO);
+ PFileIO stdinFileIO = PFactory.createFileIO(language);
FileIOBuiltins.FileIOInit.internalInit(stdinFileIO, toTruffleStringUncached(""), 0, IOMode.RB);
- PBuffered stdinBuffer = factory.createBufferedReader(PythonBuiltinClassType.PBufferedReader);
- BufferedReaderBuiltins.BufferedReaderInit.internalInit(stdinBuffer, stdinFileIO, BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, factory, posixSupport, posixLib);
- setWrapper(T_STDIN, T___STDIN__, T_R, stdioEncoding, stdioError, stdinBuffer, sysModule, factory, true);
+ PBuffered stdinBuffer = PFactory.createBufferedReader(language);
+ BufferedReaderBuiltins.BufferedReaderInit.internalInit(stdinBuffer, stdinFileIO, BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, language, posixSupport, posixLib);
+ setWrapper(T_STDIN, T___STDIN__, T_R, stdioEncoding, stdioError, stdinBuffer, sysModule, language, true);
- PFileIO stdoutFileIO = factory.createFileIO(PythonBuiltinClassType.PFileIO);
+ PFileIO stdoutFileIO = PFactory.createFileIO(language);
FileIOBuiltins.FileIOInit.internalInit(stdoutFileIO, toTruffleStringUncached(""), 1, IOMode.WB);
- Object stdoutBuffer = createBufferedIO(buffering, factory, stdoutFileIO, posixSupport, posixLib);
- setWrapper(T_STDOUT, T___STDOUT__, T_W, stdioEncoding, stdioError, stdoutBuffer, sysModule, factory, buffering);
+ Object stdoutBuffer = createBufferedIO(buffering, language, stdoutFileIO, posixSupport, posixLib);
+ setWrapper(T_STDOUT, T___STDOUT__, T_W, stdioEncoding, stdioError, stdoutBuffer, sysModule, language, buffering);
- PFileIO stderr = factory.createFileIO(PythonBuiltinClassType.PFileIO);
+ PFileIO stderr = PFactory.createFileIO(language);
FileIOBuiltins.FileIOInit.internalInit(stderr, toTruffleStringUncached(""), 2, IOMode.WB);
- Object stderrBuffer = createBufferedIO(buffering, factory, stderr, posixSupport, posixLib);
- setWrapper(T_STDERR, T___STDERR__, T_W, stdioEncoding, T_BACKSLASHREPLACE, stderrBuffer, sysModule, factory, buffering);
+ Object stderrBuffer = createBufferedIO(buffering, language, stderr, posixSupport, posixLib);
+ setWrapper(T_STDERR, T___STDERR__, T_W, stdioEncoding, T_BACKSLASHREPLACE, stderrBuffer, sysModule, language, buffering);
}
- private static Object createBufferedIO(boolean buffering, PythonObjectFactory factory, PFileIO fileIo, Object posixSupport, PosixSupportLibrary posixLib) {
+ private static Object createBufferedIO(boolean buffering, PythonLanguage language, PFileIO fileIo, Object posixSupport, PosixSupportLibrary posixLib) {
if (!buffering) {
return fileIo;
}
- PBuffered writer = factory.createBufferedWriter(PythonBuiltinClassType.PBufferedWriter);
- BufferedWriterBuiltins.BufferedWriterInit.internalInit(writer, fileIo, BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, factory, posixSupport, posixLib);
+ PBuffered writer = PFactory.createBufferedWriter(language);
+ BufferedWriterBuiltins.BufferedWriterInit.internalInit(writer, fileIo, BufferedReaderBuiltins.DEFAULT_BUFFER_SIZE, language, posixSupport, posixLib);
return writer;
}
private static PTextIO setWrapper(TruffleString name, TruffleString specialName, TruffleString mode, TruffleString encoding, TruffleString error, Object buffer, PythonModule sysModule,
- PythonObjectFactory factory, boolean buffering) {
- PTextIO textIOWrapper = factory.createTextIO(PythonBuiltinClassType.PTextIOWrapper);
+ PythonLanguage language, boolean buffering) {
+ PTextIO textIOWrapper = PFactory.createTextIO(language);
TextIOWrapperInitNodeGen.getUncached().execute(null, null, textIOWrapper, buffer, encoding, error, PNone.NONE,
/* line_buffering */ buffering, /* write_through */ !buffering);
@@ -850,15 +850,15 @@ static PTuple run(VirtualFrame frame,
@Cached GetEscapedExceptionNode getEscapedExceptionNode,
@Cached GetCaughtExceptionNode getCaughtExceptionNode,
@Cached ExceptionNodes.GetTracebackNode getTracebackNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
AbstractTruffleException currentException = getCaughtExceptionNode.execute(frame);
assert currentException != PException.NO_EXCEPTION;
if (currentException == null) {
- return factory.createTuple(new PNone[]{PNone.NONE, PNone.NONE, PNone.NONE});
+ return PFactory.createTuple(language, new PNone[]{PNone.NONE, PNone.NONE, PNone.NONE});
} else {
Object exceptionObject = getEscapedExceptionNode.execute(inliningTarget, currentException);
Object traceback = getTracebackNode.execute(inliningTarget, exceptionObject);
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, exceptionObject), exceptionObject, traceback});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, exceptionObject), exceptionObject, traceback});
}
}
}
@@ -925,13 +925,13 @@ Object currentFrames(VirtualFrame frame,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
@Cached ReadCallerFrameNode readCallerFrameNode,
@Cached HashingStorageSetItem setHashingStorageItem,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
auditNode.audit(inliningTarget, "sys._current_frames");
if (!getLanguage().singleThreadedAssumption.isValid()) {
warnNode.warn(frame, RuntimeWarning, ErrorMessages.WARN_CURRENT_FRAMES_MULTITHREADED);
}
PFrame currentFrame = readCallerFrameNode.executeWith(frame, 0);
- PDict result = factory.createDict();
+ PDict result = PFactory.createDict(language);
result.setDictStorage(setHashingStorageItem.execute(frame, inliningTarget, result.getDictStorage(), PThread.getThreadId(Thread.currentThread()), currentFrame));
return result;
}
@@ -1222,11 +1222,11 @@ abstract static class GetAsyncgenHooks extends PythonBuiltinNode {
static Object setAsyncgenHooks(
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// TODO: use asyncgen_hooks object
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
Object firstiter = threadState.getAsyncgenFirstIter();
- return factory.createTuple(new Object[]{firstiter == null ? PNone.NONE : firstiter, PNone.NONE});
+ return PFactory.createTuple(language, new Object[]{firstiter == null ? PNone.NONE : firstiter, PNone.NONE});
}
}
@@ -2058,14 +2058,15 @@ abstract static class Getwindowsversion extends PythonBuiltinNode {
static int PLATFORM = 2;
@Specialization
- PTuple getVersion(@Cached PythonObjectFactory factory) {
+ PTuple getVersion(
+ @Bind PythonLanguage language) {
if (CACHED_VERSION_INFO == null) {
cacheVersion();
}
- return factory.createStructSeq(WINDOWS_VER_DESC,
+ return PFactory.createStructSeq(language, WINDOWS_VER_DESC,
CACHED_VERSION_INFO[0], CACHED_VERSION_INFO[1], CACHED_VERSION_INFO[2],
PLATFORM, T_EMPTY_STRING, 0, 0, 0, 1,
- factory.createTuple(CACHED_VERSION_INFO));
+ PFactory.createTuple(language, CACHED_VERSION_INFO));
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
index 8a50577f63..59a4cad38c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.lang.ref.WeakReference;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -62,6 +63,7 @@
import com.oracle.graal.python.builtins.objects.thread.PRLock;
import com.oracle.graal.python.builtins.objects.thread.PThread;
import com.oracle.graal.python.builtins.objects.thread.PThreadLocal;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.WriteUnraisableNode;
@@ -80,7 +82,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonThreadKillException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleThreadBuilder;
@@ -115,8 +117,9 @@ public void initialize(Python3Core core) {
abstract static class ThreadLocalNode extends PythonBuiltinNode {
@Specialization
PThreadLocal construct(Object cls, Object[] args, PKeyword[] keywordArgs,
- @Cached PythonObjectFactory factory) {
- return factory.createThreadLocal(cls, args, keywordArgs);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createThreadLocal(language, cls, getInstanceShape.execute(cls), args, keywordArgs);
}
}
@@ -126,8 +129,8 @@ public abstract static class AllocateLockNode extends PythonBinaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
PLock construct(Object self, Object unused,
- @Cached PythonObjectFactory factory) {
- return factory.createLock(PythonBuiltinClassType.PLock);
+ @Bind PythonLanguage language) {
+ return PFactory.createLock(language);
}
}
@@ -136,8 +139,9 @@ PLock construct(Object self, Object unused,
abstract static class ConstructLockNode extends PythonUnaryBuiltinNode {
@Specialization
PLock construct(Object cls,
- @Cached PythonObjectFactory factory) {
- return factory.createLock(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createLock(language, cls, getInstanceShape.execute(cls));
}
}
@@ -146,8 +150,9 @@ PLock construct(Object cls,
abstract static class ConstructRLockNode extends PythonUnaryBuiltinNode {
@Specialization
PRLock construct(Object cls,
- @Cached PythonObjectFactory factory) {
- return factory.createRLock(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createRLock(language, cls, getInstanceShape.execute(cls));
}
}
@@ -211,12 +216,11 @@ abstract static class StartNewThreadNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("try")
- long start(VirtualFrame frame, Object cls, Object callable, Object args, Object kwargs,
+ long start(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object callable, Object args, Object kwargs,
@Bind("this") Node inliningTarget,
@Cached CallNode callNode,
@Cached ExecutePositionalStarargsNode getArgsNode,
- @Cached ExpandKeywordStarargsNode getKwArgsNode,
- @Cached PythonObjectFactory factory) {
+ @Cached ExpandKeywordStarargsNode getKwArgsNode) {
PythonContext context = getContext();
TruffleLanguage.Env env = context.getEnv();
PythonModule threadModule = context.lookupBuiltinModule(T__THREAD);
@@ -252,7 +256,7 @@ long start(VirtualFrame frame, Object cls, Object callable, Object args, Object
}
}).context(env.getContext()).threadGroup(context.getThreadGroup());
- PThread pThread = factory.createPythonThread(cls, threadBuilder.build());
+ PThread pThread = PFactory.createPythonThread(PythonLanguage.get(inliningTarget), threadBuilder.build());
pThread.start();
return pThread.getId();
}
@@ -264,8 +268,9 @@ abstract static class SetSentinelNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
Object setSentinel() {
- PLock sentinelLock = PythonObjectFactory.getUncached().createLock();
- PythonContext.get(this).setSentinelLockWeakref(new WeakReference<>(sentinelLock));
+ PythonContext context = PythonContext.get(null);
+ PLock sentinelLock = PFactory.createLock(context.getLanguage());
+ context.setSentinelLockWeakref(new WeakReference<>(sentinelLock));
return sentinelLock;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
index 6eec222635..043be4b730 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
@@ -52,6 +52,7 @@
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import org.graalvm.nativeimage.ImageInfo;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -92,7 +93,7 @@
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonImageBuildOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleSafepoint;
@@ -185,9 +186,9 @@ public void postInitialize(Python3Core core) {
boolean hasDaylightSaving = !noDaylightSavingZone.equalsUncached(daylightSavingZone, TS_ENCODING);
if (hasDaylightSaving) {
- timeModule.setAttribute(T_TZNAME, core.factory().createTuple(new Object[]{noDaylightSavingZone, daylightSavingZone}));
+ timeModule.setAttribute(T_TZNAME, PFactory.createTuple(core.getLanguage(), new Object[]{noDaylightSavingZone, daylightSavingZone}));
} else {
- timeModule.setAttribute(T_TZNAME, core.factory().createTuple(new Object[]{noDaylightSavingZone}));
+ timeModule.setAttribute(T_TZNAME, PFactory.createTuple(core.getLanguage(), new Object[]{noDaylightSavingZone}));
}
timeModule.setAttribute(T_DAYLIGHT, PInt.intValue(hasDaylightSaving));
@@ -318,8 +319,8 @@ public abstract static class PythonGMTimeNode extends PythonBuiltinNode {
static PTuple gmtime(VirtualFrame frame, Object seconds,
@Bind("this") Node inliningTarget,
@Cached ToLongTime toLongTime,
- @Cached PythonObjectFactory factory) {
- return factory.createStructSeq(STRUCT_TIME_DESC, getTimeStruct(GMT, toLongTime.execute(frame, inliningTarget, seconds)));
+ @Bind PythonLanguage language) {
+ return PFactory.createStructSeq(language, STRUCT_TIME_DESC, getTimeStruct(GMT, toLongTime.execute(frame, inliningTarget, seconds)));
}
}
@@ -354,9 +355,9 @@ public abstract static class PythonLocalTimeNode extends PythonBinaryBuiltinNode
static PTuple localtime(VirtualFrame frame, PythonModule module, Object seconds,
@Bind("this") Node inliningTarget,
@Cached ToLongTime toLongTime,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ModuleState moduleState = module.getModuleState(ModuleState.class);
- return factory.createStructSeq(STRUCT_TIME_DESC, getTimeStruct(moduleState.currentZoneId, toLongTime.execute(frame, inliningTarget, seconds)));
+ return PFactory.createStructSeq(language, STRUCT_TIME_DESC, getTimeStruct(moduleState.currentZoneId, toLongTime.execute(frame, inliningTarget, seconds)));
}
}
@@ -1113,7 +1114,7 @@ static Object getClockInfo(TruffleString name,
@Bind("this") Node inliningTarget,
@Cached WriteAttributeToPythonObjectNode writeAttrNode,
@Cached TruffleString.EqualNode equalNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
final boolean adjustable;
final boolean monotonic;
@@ -1129,7 +1130,7 @@ static Object getClockInfo(TruffleString name,
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, UNKNOWN_CLOCK);
}
- final PSimpleNamespace ns = factory.createSimpleNamespace();
+ final PSimpleNamespace ns = PFactory.createSimpleNamespace(language);
writeAttrNode.execute(ns, T_ADJUSTABLE, adjustable);
writeAttrNode.execute(ns, T_IMPLEMENTATION, name);
writeAttrNode.execute(ns, T_MONOTONIC, monotonic);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TokenizeModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TokenizeModuleBuiltins.java
index 5edfab4e64..c7f3c99d29 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TokenizeModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TokenizeModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -53,7 +54,8 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -79,10 +81,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- static PTokenizerIter tokenizerIter(Object cls, TruffleString source,
- @Cached TruffleString.ToJavaStringNode toJavaStringNode,
- @Cached PythonObjectFactory factory) {
- return factory.createTokenizerIter(cls, toJavaStringNode.execute(source));
+ static PTokenizerIter tokenizerIter(@SuppressWarnings("unused") Object cls, TruffleString source,
+ @Bind PythonLanguage language,
+ @Cached TruffleString.ToJavaStringNode toJavaStringNode) {
+ return PFactory.createTokenizerIter(language, toJavaStringNode.execute(source));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
index 21648c3b82..469e070bb9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
@@ -122,8 +122,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.formatting.ErrorMessageFormatter;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -176,9 +175,9 @@ public void initialize(Python3Core core) {
// we need to copy the attrs, since they must still be available even if the user `del`s the
// attrs
addBuiltinConstant("_defaultaction", T_DEFAULT);
- PDict onceregistry = core.factory().createDict();
+ PDict onceregistry = PFactory.createDict(core.getLanguage());
addBuiltinConstant("_onceregistry", onceregistry);
- PList filters = initFilters(core.factory());
+ PList filters = initFilters(core.getLanguage());
addBuiltinConstant("filters", filters);
ModuleState moduleState = new ModuleState();
moduleState.filtersVersion = 0L;
@@ -189,18 +188,18 @@ public void initialize(Python3Core core) {
super.initialize(core);
}
- private static PTuple createFilter(PythonObjectSlowPathFactory factory, PythonBuiltinClassType cat, TruffleString id, Object mod) {
- return factory.createTuple(new Object[]{id, PNone.NONE, cat, mod, 0});
+ private static PTuple createFilter(PythonLanguage language, PythonBuiltinClassType cat, TruffleString id, Object mod) {
+ return PFactory.createTuple(language, new Object[]{id, PNone.NONE, cat, mod, 0});
}
// init_filters
- private static PList initFilters(PythonObjectSlowPathFactory factory) {
- return factory.createList(new Object[]{
- createFilter(factory, PythonBuiltinClassType.DeprecationWarning, T_DEFAULT, T___MAIN__),
- createFilter(factory, PythonBuiltinClassType.DeprecationWarning, T_IGNORE, PNone.NONE),
- createFilter(factory, PythonBuiltinClassType.PendingDeprecationWarning, T_IGNORE, PNone.NONE),
- createFilter(factory, PythonBuiltinClassType.ImportWarning, T_IGNORE, PNone.NONE),
- createFilter(factory, PythonBuiltinClassType.ResourceWarning, T_IGNORE, PNone.NONE)});
+ private static PList initFilters(PythonLanguage language) {
+ return PFactory.createList(language, new Object[]{
+ createFilter(language, PythonBuiltinClassType.DeprecationWarning, T_DEFAULT, T___MAIN__),
+ createFilter(language, PythonBuiltinClassType.DeprecationWarning, T_IGNORE, PNone.NONE),
+ createFilter(language, PythonBuiltinClassType.PendingDeprecationWarning, T_IGNORE, PNone.NONE),
+ createFilter(language, PythonBuiltinClassType.ImportWarning, T_IGNORE, PNone.NONE),
+ createFilter(language, PythonBuiltinClassType.ResourceWarning, T_IGNORE, PNone.NONE)});
}
static final class WarningsModuleNode extends Node {
@@ -210,7 +209,6 @@ static final class WarningsModuleNode extends Node {
@Child GetClassNode getClassNode;
@Child PyNumberAsSizeNode asSizeNode;
@Child PyObjectIsTrueNode isTrueNode;
- @Child PythonObjectFactory factory;
@Child IsSubClassNode isSubClassNode;
@Child GetOrCreateDictNode getDictNode;
@Child GetDictFromGlobalsNode getDictFromGlobalsNode;
@@ -387,15 +385,6 @@ private PRaiseNode getRaise() {
return raiseNode;
}
- private PythonObjectFactory getFactory() {
- if (factory == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- reportPolymorphicSpecialize();
- factory = insert(PythonObjectFactory.create());
- }
- return factory;
- }
-
private IsSubClassNode getIsSubClass() {
if (isSubClassNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -675,12 +664,12 @@ private TruffleString normalizeModule(TruffleString filename) {
}
@TruffleBoundary
- private static boolean updateRegistry(PythonObjectSlowPathFactory factory, PythonModule _warnings, PDict registry, Object text, Object category, boolean addZero) {
+ private static boolean updateRegistry(PythonLanguage language, PythonModule _warnings, PDict registry, Object text, Object category, boolean addZero) {
PTuple altKey;
if (addZero) {
- altKey = factory.createTuple(new Object[]{text, category, 0});
+ altKey = PFactory.createTuple(language, new Object[]{text, category, 0});
} else {
- altKey = factory.createTuple(new Object[]{text, category});
+ altKey = PFactory.createTuple(language, new Object[]{text, category});
}
return alreadyWarnedShouldSet(_warnings, registry, altKey);
}
@@ -794,7 +783,7 @@ private void warnExplicit(VirtualFrame frame, PythonModule warnings,
message = getCallNode().execute(frame, category, message);
}
- Object key = getFactory().createTuple(new Object[]{text, category, lineno});
+ Object key = PFactory.createTuple(PythonLanguage.get(this), new Object[]{text, category, lineno});
if (registry != null) {
if (alreadyWarnedShouldNotSet(frame, warnings, registry, key)) {
return;
@@ -845,13 +834,13 @@ private static void warnExplicitPart2(PythonContext context, Node node, PythonMo
if (action.equalsUncached(T_ONCE, TS_ENCODING)) {
if (registry == null) {
PDict currentRegistry = getOnceRegistry(node, context, warnings);
- alreadyWarned = updateRegistry(context.factory(), warnings, currentRegistry, text, category, false);
+ alreadyWarned = updateRegistry(context.getLanguage(), warnings, currentRegistry, text, category, false);
} else {
- alreadyWarned = updateRegistry(context.factory(), warnings, registry, text, category, false);
+ alreadyWarned = updateRegistry(context.getLanguage(), warnings, registry, text, category, false);
}
} else if (action.equalsUncached(T_MODULE, TS_ENCODING)) {
if (registry != null) {
- alreadyWarned = updateRegistry(context.factory(), warnings, registry, text, category, false);
+ alreadyWarned = updateRegistry(context.getLanguage(), warnings, registry, text, category, false);
}
} else if (!action.equalsUncached(T_DEFAULT, TS_ENCODING)) {
throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNRECOGNIZED_ACTION_IN_WARNINGS, action,
@@ -898,7 +887,7 @@ private void setupContext(VirtualFrame frame, int stackLevel, TruffleString[] fi
registry[0] = getDictGetItemNode().executeCached(frame, globals, T___WARNINGREGISTRY__);
if (registry[0] == null) {
- registry[0] = getFactory().createDict();
+ registry[0] = PFactory.createDict(PythonLanguage.get(this));
getSetItemNode().executeCached(frame, globals, T___WARNINGREGISTRY__, registry[0]);
}
Object moduleObj = getDictGetItemNode().executeCached(frame, globals, SpecialAttributeNames.T___NAME__);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
index 3c5412ca21..298854a1e0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -88,7 +89,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -259,7 +260,8 @@ static PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
@Exclusive @Cached GetClassNode getClassNode,
@Cached HiddenAttr.ReadNode readWeaklistNode,
@Cached HiddenAttr.WriteNode writeWeakListNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached HiddenAttr.ReadNode readQueueNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object obj = object;
@@ -281,7 +283,7 @@ static PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
return (PReferenceType) wr; // is must be a PReferenceType instance.
}
- PReferenceType ref = factory.createReferenceType(cls, obj, null, getWeakReferenceQueue(inliningTarget, readQueueNode));
+ PReferenceType ref = PFactory.createReferenceType(language, cls, getInstanceShape.execute(cls), obj, null, getWeakReferenceQueue(inliningTarget, readQueueNode));
writeWeakListNode.execute(inliningTarget, (PythonAbstractObject) obj, WEAKLIST, ref);
return ref;
}
@@ -290,8 +292,9 @@ static PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
static PReferenceType refTypeWithCallback(Object cls, Object object, Object callback,
@Bind("this") Node inliningTarget,
@Exclusive @Cached HiddenAttr.ReadNode readQueueNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createReferenceType(cls, object, callback, getWeakReferenceQueue(inliningTarget, readQueueNode));
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createReferenceType(language, cls, getInstanceShape.execute(cls), object, callback, getWeakReferenceQueue(inliningTarget, readQueueNode));
}
@Specialization
@@ -301,7 +304,8 @@ PReferenceType refType(Object cls, PythonAbstractNativeObject pythonObject, Obje
@Exclusive @Cached GetClassNode getClassNode,
@Cached IsBuiltinClassExactProfile profile,
@Cached GetMroNode getMroNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached HiddenAttr.ReadNode readQueueNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object actualCallback = callback instanceof PNone ? null : callback;
@@ -335,7 +339,7 @@ PReferenceType refType(Object cls, PythonAbstractNativeObject pythonObject, Obje
}
if (allowed) {
CApiTransitions.addNativeWeakRef(getContext(), pythonObject);
- return factory.createReferenceType(cls, pythonObject, actualCallback, getWeakReferenceQueue(inliningTarget, readQueueNode));
+ return PFactory.createReferenceType(language, cls, getInstanceShape.execute(cls), pythonObject, actualCallback, getWeakReferenceQueue(inliningTarget, readQueueNode));
} else {
return refType(cls, pythonObject, actualCallback, raiseNode.get(inliningTarget));
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java
index e72c7c79d2..49ab1f7d64 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -103,10 +104,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object openKey(VirtualFrame frame, Object key, Object subKey, Object reserved, Object access,
@Bind("this") Node inliningTarget,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (key instanceof Integer intKey) {
if (intKey == HKEY_CLASSES_ROOT) {
- return factory.createLock();
+ return PFactory.createLock(language);
}
}
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
index 446ae216fa..b67a26f384 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -74,7 +75,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -180,10 +181,10 @@ static Object doit(VirtualFrame frame, PythonObject self, Object ignored,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached PyObjectLookupAttr lookupAttr,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object clazz = getClassNode.execute(inliningTarget, self);
Object dict = lookupAttr.execute(frame, inliningTarget, self, T___DICT__);
- return factory.createTuple(new Object[]{clazz, factory.createTuple(EMPTY_OBJECT_ARRAY), dict});
+ return PFactory.createTuple(language, new Object[]{clazz, PFactory.createTuple(language, EMPTY_OBJECT_ARRAY), dict});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
index ac5040e41c..841d0e853d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,35 +45,36 @@
import static com.oracle.graal.python.builtins.modules.BuiltinFunctions.CompileNode.PyCF_TYPE_COMMENTS;
import static com.oracle.graal.python.nodes.ErrorMessages.EXPECTED_S_NODE_GOT_P;
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___MATCH_ARGS__;
-import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
-import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.pegparser.InputType;
import com.oracle.graal.python.pegparser.sst.ModTy;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.strings.TruffleString;
@CoreFunctions(defineModule = AstModuleBuiltins.J__AST, isEager = true)
@@ -98,7 +99,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant("PyCF_ALLOW_TOP_LEVEL_AWAIT", PyCF_ALLOW_TOP_LEVEL_AWAIT);
PythonBuiltinClass clsAst = core.lookupType(PythonBuiltinClassType.AST);
- PTuple emptyTuple = core.factory().createTuple(EMPTY_OBJECT_ARRAY);
+ PTuple emptyTuple = PFactory.createEmptyTuple(core.getLanguage());
clsAst.setAttribute(T__FIELDS, emptyTuple);
clsAst.setAttribute(T__ATTRIBUTES, emptyTuple);
clsAst.setAttribute(T___MATCH_ARGS__, emptyTuple);
@@ -108,7 +109,7 @@ public void initialize(Python3Core core) {
public void postInitialize(Python3Core core) {
super.postInitialize(core);
PythonModule astModule = core.lookupBuiltinModule(T__AST);
- AstTypeFactory astTypeFactory = new AstTypeFactory(core.getLanguage(), core.factory(), astModule);
+ AstTypeFactory astTypeFactory = new AstTypeFactory(core.getLanguage(), astModule);
AstState state = new AstState(astTypeFactory, core.lookupType(PythonBuiltinClassType.AST));
astModule.setModuleState(state);
}
@@ -116,18 +117,12 @@ public void postInitialize(Python3Core core) {
@Builtin(name = "AST", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, constructsClass = PythonBuiltinClassType.AST)
@GenerateNodeFactory
public abstract static class AstNode extends PythonVarargsBuiltinNode {
- @Override
- public final Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
- if (self == PNone.NO_VALUE && arguments.length > 0) {
- return factory().createPythonObject(arguments[0]);
- }
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw VarargsBuiltinDirectInvocationNotSupported.INSTANCE;
- }
@Specialization
- PythonObject generic(Object cls, @SuppressWarnings("unused") Object[] varargs, @SuppressWarnings("unused") PKeyword[] kwargs) {
- return factory().createPythonObject(cls);
+ static PythonObject generic(Object cls, @SuppressWarnings("unused") Object[] varargs, @SuppressWarnings("unused") PKeyword[] kwargs,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createPythonObject(language, cls, getInstanceShape.execute(cls));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstState.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstState.java
index b416484a6c..29ba5b10cb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstState.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstState.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstTypeFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstTypeFactory.java
index 89ed1bee7d..00bbb68146 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstTypeFactory.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstTypeFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,13 +49,12 @@
import static com.oracle.graal.python.util.PythonUtils.convertToObjectArray;
import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.strings.TruffleString;
/**
@@ -64,23 +63,21 @@
final class AstTypeFactory {
private final PythonLanguage language;
- private final PythonObjectFactory factory;
private final PythonModule astModule;
- AstTypeFactory(PythonLanguage language, PythonObjectFactory factory, PythonModule astModule) {
+ AstTypeFactory(PythonLanguage language, PythonModule astModule) {
this.language = language;
- this.factory = factory;
this.astModule = astModule;
}
PythonClass makeType(TruffleString name, PythonAbstractClass base, TruffleString[] fields, TruffleString[] attributes, TruffleString[] optional, TruffleString docString) {
- PythonClass newType = factory.createPythonClassAndFixupSlots(language, PythonBuiltinClassType.PythonClass, name, base, new PythonAbstractClass[]{base});
+ PythonClass newType = PFactory.createPythonClassAndFixupSlots(language, name, base, new PythonAbstractClass[]{base});
newType.setAttribute(T___MODULE__, T_AST);
newType.setAttribute(T___DOC__, docString);
- newType.setAttribute(T__FIELDS, factory.createTuple(convertToObjectArray(fields)));
- newType.setAttribute(T___MATCH_ARGS__, factory.createTuple(convertToObjectArray(fields)));
+ newType.setAttribute(T__FIELDS, PFactory.createTuple(language, convertToObjectArray(fields)));
+ newType.setAttribute(T___MATCH_ARGS__, PFactory.createTuple(language, convertToObjectArray(fields)));
if (attributes != null) {
- newType.setAttribute(T__ATTRIBUTES, factory.createTuple(convertToObjectArray(attributes)));
+ newType.setAttribute(T__ATTRIBUTES, PFactory.createTuple(language, convertToObjectArray(attributes)));
}
for (TruffleString n : optional) {
newType.setAttribute(n, PNone.NONE);
@@ -90,6 +87,6 @@ PythonClass makeType(TruffleString name, PythonAbstractClass base, TruffleString
}
PythonObject createSingleton(PythonClass cls) {
- return factory.createPythonObject(cls);
+ return PFactory.createPythonObject(language, cls, cls.getInstanceShape());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
index 0592423a9d..243cd7c5e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitor.java
index d21cebcb1c..e698ae2164 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -77,7 +77,7 @@ final class Sst2ObjVisitor extends Sst2ObjVisitorBase {
@Override
public Object visit(ModTy.Module node) {
- PythonObject o = factory.createPythonObject(state.clsModule);
+ PythonObject o = createPythonObject(state.clsModule);
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_TYPE_IGNORES, seq2List(node.typeIgnores));
return o;
@@ -85,21 +85,21 @@ public Object visit(ModTy.Module node) {
@Override
public Object visit(ModTy.Interactive node) {
- PythonObject o = factory.createPythonObject(state.clsInteractive);
+ PythonObject o = createPythonObject(state.clsInteractive);
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
return o;
}
@Override
public Object visit(ModTy.Expression node) {
- PythonObject o = factory.createPythonObject(state.clsExpression);
+ PythonObject o = createPythonObject(state.clsExpression);
o.setAttribute(AstState.T_F_BODY, visitNonNull(node.body));
return o;
}
@Override
public Object visit(ModTy.FunctionType node) {
- PythonObject o = factory.createPythonObject(state.clsFunctionType);
+ PythonObject o = createPythonObject(state.clsFunctionType);
o.setAttribute(AstState.T_F_ARGTYPES, seq2List(node.argTypes));
o.setAttribute(AstState.T_F_RETURNS, visitNonNull(node.returns));
return o;
@@ -107,7 +107,7 @@ public Object visit(ModTy.FunctionType node) {
@Override
public Object visit(StmtTy.FunctionDef node) {
- PythonObject o = factory.createPythonObject(state.clsFunctionDef);
+ PythonObject o = createPythonObject(state.clsFunctionDef);
o.setAttribute(AstState.T_F_NAME, visitNonNull(node.name));
o.setAttribute(AstState.T_F_ARGS, visitNonNull(node.args));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -120,7 +120,7 @@ public Object visit(StmtTy.FunctionDef node) {
@Override
public Object visit(StmtTy.AsyncFunctionDef node) {
- PythonObject o = factory.createPythonObject(state.clsAsyncFunctionDef);
+ PythonObject o = createPythonObject(state.clsAsyncFunctionDef);
o.setAttribute(AstState.T_F_NAME, visitNonNull(node.name));
o.setAttribute(AstState.T_F_ARGS, visitNonNull(node.args));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -133,7 +133,7 @@ public Object visit(StmtTy.AsyncFunctionDef node) {
@Override
public Object visit(StmtTy.ClassDef node) {
- PythonObject o = factory.createPythonObject(state.clsClassDef);
+ PythonObject o = createPythonObject(state.clsClassDef);
o.setAttribute(AstState.T_F_NAME, visitNonNull(node.name));
o.setAttribute(AstState.T_F_BASES, seq2List(node.bases));
o.setAttribute(AstState.T_F_KEYWORDS, seq2List(node.keywords));
@@ -145,7 +145,7 @@ public Object visit(StmtTy.ClassDef node) {
@Override
public Object visit(StmtTy.Return node) {
- PythonObject o = factory.createPythonObject(state.clsReturn);
+ PythonObject o = createPythonObject(state.clsReturn);
o.setAttribute(AstState.T_F_VALUE, visitNullable(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -153,7 +153,7 @@ public Object visit(StmtTy.Return node) {
@Override
public Object visit(StmtTy.Delete node) {
- PythonObject o = factory.createPythonObject(state.clsDelete);
+ PythonObject o = createPythonObject(state.clsDelete);
o.setAttribute(AstState.T_F_TARGETS, seq2List(node.targets));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -161,7 +161,7 @@ public Object visit(StmtTy.Delete node) {
@Override
public Object visit(StmtTy.Assign node) {
- PythonObject o = factory.createPythonObject(state.clsAssign);
+ PythonObject o = createPythonObject(state.clsAssign);
o.setAttribute(AstState.T_F_TARGETS, seq2List(node.targets));
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_TYPE_COMMENT, visitNullableStringOrByteArray(node.typeComment));
@@ -171,7 +171,7 @@ public Object visit(StmtTy.Assign node) {
@Override
public Object visit(StmtTy.AugAssign node) {
- PythonObject o = factory.createPythonObject(state.clsAugAssign);
+ PythonObject o = createPythonObject(state.clsAugAssign);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_OP, visitNonNull(node.op));
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
@@ -181,7 +181,7 @@ public Object visit(StmtTy.AugAssign node) {
@Override
public Object visit(StmtTy.AnnAssign node) {
- PythonObject o = factory.createPythonObject(state.clsAnnAssign);
+ PythonObject o = createPythonObject(state.clsAnnAssign);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_ANNOTATION, visitNonNull(node.annotation));
o.setAttribute(AstState.T_F_VALUE, visitNullable(node.value));
@@ -192,7 +192,7 @@ public Object visit(StmtTy.AnnAssign node) {
@Override
public Object visit(StmtTy.For node) {
- PythonObject o = factory.createPythonObject(state.clsFor);
+ PythonObject o = createPythonObject(state.clsFor);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_ITER, visitNonNull(node.iter));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -204,7 +204,7 @@ public Object visit(StmtTy.For node) {
@Override
public Object visit(StmtTy.AsyncFor node) {
- PythonObject o = factory.createPythonObject(state.clsAsyncFor);
+ PythonObject o = createPythonObject(state.clsAsyncFor);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_ITER, visitNonNull(node.iter));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -216,7 +216,7 @@ public Object visit(StmtTy.AsyncFor node) {
@Override
public Object visit(StmtTy.While node) {
- PythonObject o = factory.createPythonObject(state.clsWhile);
+ PythonObject o = createPythonObject(state.clsWhile);
o.setAttribute(AstState.T_F_TEST, visitNonNull(node.test));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_ORELSE, seq2List(node.orElse));
@@ -226,7 +226,7 @@ public Object visit(StmtTy.While node) {
@Override
public Object visit(StmtTy.If node) {
- PythonObject o = factory.createPythonObject(state.clsIf);
+ PythonObject o = createPythonObject(state.clsIf);
o.setAttribute(AstState.T_F_TEST, visitNonNull(node.test));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_ORELSE, seq2List(node.orElse));
@@ -236,7 +236,7 @@ public Object visit(StmtTy.If node) {
@Override
public Object visit(StmtTy.With node) {
- PythonObject o = factory.createPythonObject(state.clsWith);
+ PythonObject o = createPythonObject(state.clsWith);
o.setAttribute(AstState.T_F_ITEMS, seq2List(node.items));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_TYPE_COMMENT, visitNullableStringOrByteArray(node.typeComment));
@@ -246,7 +246,7 @@ public Object visit(StmtTy.With node) {
@Override
public Object visit(StmtTy.AsyncWith node) {
- PythonObject o = factory.createPythonObject(state.clsAsyncWith);
+ PythonObject o = createPythonObject(state.clsAsyncWith);
o.setAttribute(AstState.T_F_ITEMS, seq2List(node.items));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_TYPE_COMMENT, visitNullableStringOrByteArray(node.typeComment));
@@ -256,7 +256,7 @@ public Object visit(StmtTy.AsyncWith node) {
@Override
public Object visit(StmtTy.Match node) {
- PythonObject o = factory.createPythonObject(state.clsMatch);
+ PythonObject o = createPythonObject(state.clsMatch);
o.setAttribute(AstState.T_F_SUBJECT, visitNonNull(node.subject));
o.setAttribute(AstState.T_F_CASES, seq2List(node.cases));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -265,7 +265,7 @@ public Object visit(StmtTy.Match node) {
@Override
public Object visit(StmtTy.Raise node) {
- PythonObject o = factory.createPythonObject(state.clsRaise);
+ PythonObject o = createPythonObject(state.clsRaise);
o.setAttribute(AstState.T_F_EXC, visitNullable(node.exc));
o.setAttribute(AstState.T_F_CAUSE, visitNullable(node.cause));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -274,7 +274,7 @@ public Object visit(StmtTy.Raise node) {
@Override
public Object visit(StmtTy.Try node) {
- PythonObject o = factory.createPythonObject(state.clsTry);
+ PythonObject o = createPythonObject(state.clsTry);
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_HANDLERS, seq2List(node.handlers));
o.setAttribute(AstState.T_F_ORELSE, seq2List(node.orElse));
@@ -285,7 +285,7 @@ public Object visit(StmtTy.Try node) {
@Override
public Object visit(StmtTy.TryStar node) {
- PythonObject o = factory.createPythonObject(state.clsTryStar);
+ PythonObject o = createPythonObject(state.clsTryStar);
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
o.setAttribute(AstState.T_F_HANDLERS, seq2List(node.handlers));
o.setAttribute(AstState.T_F_ORELSE, seq2List(node.orElse));
@@ -296,7 +296,7 @@ public Object visit(StmtTy.TryStar node) {
@Override
public Object visit(StmtTy.Assert node) {
- PythonObject o = factory.createPythonObject(state.clsAssert);
+ PythonObject o = createPythonObject(state.clsAssert);
o.setAttribute(AstState.T_F_TEST, visitNonNull(node.test));
o.setAttribute(AstState.T_F_MSG, visitNullable(node.msg));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -305,7 +305,7 @@ public Object visit(StmtTy.Assert node) {
@Override
public Object visit(StmtTy.Import node) {
- PythonObject o = factory.createPythonObject(state.clsImport);
+ PythonObject o = createPythonObject(state.clsImport);
o.setAttribute(AstState.T_F_NAMES, seq2List(node.names));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -313,7 +313,7 @@ public Object visit(StmtTy.Import node) {
@Override
public Object visit(StmtTy.ImportFrom node) {
- PythonObject o = factory.createPythonObject(state.clsImportFrom);
+ PythonObject o = createPythonObject(state.clsImportFrom);
o.setAttribute(AstState.T_F_MODULE, visitNullable(node.module));
o.setAttribute(AstState.T_F_NAMES, seq2List(node.names));
o.setAttribute(AstState.T_F_LEVEL, visitNullable(node.level));
@@ -323,7 +323,7 @@ public Object visit(StmtTy.ImportFrom node) {
@Override
public Object visit(StmtTy.Global node) {
- PythonObject o = factory.createPythonObject(state.clsGlobal);
+ PythonObject o = createPythonObject(state.clsGlobal);
o.setAttribute(AstState.T_F_NAMES, seq2List(node.names));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -331,7 +331,7 @@ public Object visit(StmtTy.Global node) {
@Override
public Object visit(StmtTy.Nonlocal node) {
- PythonObject o = factory.createPythonObject(state.clsNonlocal);
+ PythonObject o = createPythonObject(state.clsNonlocal);
o.setAttribute(AstState.T_F_NAMES, seq2List(node.names));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -339,7 +339,7 @@ public Object visit(StmtTy.Nonlocal node) {
@Override
public Object visit(StmtTy.Expr node) {
- PythonObject o = factory.createPythonObject(state.clsExpr);
+ PythonObject o = createPythonObject(state.clsExpr);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -347,28 +347,28 @@ public Object visit(StmtTy.Expr node) {
@Override
public Object visit(StmtTy.Pass node) {
- PythonObject o = factory.createPythonObject(state.clsPass);
+ PythonObject o = createPythonObject(state.clsPass);
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
}
@Override
public Object visit(StmtTy.Break node) {
- PythonObject o = factory.createPythonObject(state.clsBreak);
+ PythonObject o = createPythonObject(state.clsBreak);
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
}
@Override
public Object visit(StmtTy.Continue node) {
- PythonObject o = factory.createPythonObject(state.clsContinue);
+ PythonObject o = createPythonObject(state.clsContinue);
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
}
@Override
public Object visit(ExprTy.BoolOp node) {
- PythonObject o = factory.createPythonObject(state.clsBoolOp);
+ PythonObject o = createPythonObject(state.clsBoolOp);
o.setAttribute(AstState.T_F_OP, visitNonNull(node.op));
o.setAttribute(AstState.T_F_VALUES, seq2List(node.values));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -377,7 +377,7 @@ public Object visit(ExprTy.BoolOp node) {
@Override
public Object visit(ExprTy.NamedExpr node) {
- PythonObject o = factory.createPythonObject(state.clsNamedExpr);
+ PythonObject o = createPythonObject(state.clsNamedExpr);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -386,7 +386,7 @@ public Object visit(ExprTy.NamedExpr node) {
@Override
public Object visit(ExprTy.BinOp node) {
- PythonObject o = factory.createPythonObject(state.clsBinOp);
+ PythonObject o = createPythonObject(state.clsBinOp);
o.setAttribute(AstState.T_F_LEFT, visitNonNull(node.left));
o.setAttribute(AstState.T_F_OP, visitNonNull(node.op));
o.setAttribute(AstState.T_F_RIGHT, visitNonNull(node.right));
@@ -396,7 +396,7 @@ public Object visit(ExprTy.BinOp node) {
@Override
public Object visit(ExprTy.UnaryOp node) {
- PythonObject o = factory.createPythonObject(state.clsUnaryOp);
+ PythonObject o = createPythonObject(state.clsUnaryOp);
o.setAttribute(AstState.T_F_OP, visitNonNull(node.op));
o.setAttribute(AstState.T_F_OPERAND, visitNonNull(node.operand));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -405,7 +405,7 @@ public Object visit(ExprTy.UnaryOp node) {
@Override
public Object visit(ExprTy.Lambda node) {
- PythonObject o = factory.createPythonObject(state.clsLambda);
+ PythonObject o = createPythonObject(state.clsLambda);
o.setAttribute(AstState.T_F_ARGS, visitNonNull(node.args));
o.setAttribute(AstState.T_F_BODY, visitNonNull(node.body));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -414,7 +414,7 @@ public Object visit(ExprTy.Lambda node) {
@Override
public Object visit(ExprTy.IfExp node) {
- PythonObject o = factory.createPythonObject(state.clsIfExp);
+ PythonObject o = createPythonObject(state.clsIfExp);
o.setAttribute(AstState.T_F_TEST, visitNonNull(node.test));
o.setAttribute(AstState.T_F_BODY, visitNonNull(node.body));
o.setAttribute(AstState.T_F_ORELSE, visitNonNull(node.orElse));
@@ -424,7 +424,7 @@ public Object visit(ExprTy.IfExp node) {
@Override
public Object visit(ExprTy.Dict node) {
- PythonObject o = factory.createPythonObject(state.clsDict);
+ PythonObject o = createPythonObject(state.clsDict);
o.setAttribute(AstState.T_F_KEYS, seq2List(node.keys));
o.setAttribute(AstState.T_F_VALUES, seq2List(node.values));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -433,7 +433,7 @@ public Object visit(ExprTy.Dict node) {
@Override
public Object visit(ExprTy.Set node) {
- PythonObject o = factory.createPythonObject(state.clsSet);
+ PythonObject o = createPythonObject(state.clsSet);
o.setAttribute(AstState.T_F_ELTS, seq2List(node.elements));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -441,7 +441,7 @@ public Object visit(ExprTy.Set node) {
@Override
public Object visit(ExprTy.ListComp node) {
- PythonObject o = factory.createPythonObject(state.clsListComp);
+ PythonObject o = createPythonObject(state.clsListComp);
o.setAttribute(AstState.T_F_ELT, visitNonNull(node.element));
o.setAttribute(AstState.T_F_GENERATORS, seq2List(node.generators));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -450,7 +450,7 @@ public Object visit(ExprTy.ListComp node) {
@Override
public Object visit(ExprTy.SetComp node) {
- PythonObject o = factory.createPythonObject(state.clsSetComp);
+ PythonObject o = createPythonObject(state.clsSetComp);
o.setAttribute(AstState.T_F_ELT, visitNonNull(node.element));
o.setAttribute(AstState.T_F_GENERATORS, seq2List(node.generators));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -459,7 +459,7 @@ public Object visit(ExprTy.SetComp node) {
@Override
public Object visit(ExprTy.DictComp node) {
- PythonObject o = factory.createPythonObject(state.clsDictComp);
+ PythonObject o = createPythonObject(state.clsDictComp);
o.setAttribute(AstState.T_F_KEY, visitNonNull(node.key));
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_GENERATORS, seq2List(node.generators));
@@ -469,7 +469,7 @@ public Object visit(ExprTy.DictComp node) {
@Override
public Object visit(ExprTy.GeneratorExp node) {
- PythonObject o = factory.createPythonObject(state.clsGeneratorExp);
+ PythonObject o = createPythonObject(state.clsGeneratorExp);
o.setAttribute(AstState.T_F_ELT, visitNonNull(node.element));
o.setAttribute(AstState.T_F_GENERATORS, seq2List(node.generators));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -478,7 +478,7 @@ public Object visit(ExprTy.GeneratorExp node) {
@Override
public Object visit(ExprTy.Await node) {
- PythonObject o = factory.createPythonObject(state.clsAwait);
+ PythonObject o = createPythonObject(state.clsAwait);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -486,7 +486,7 @@ public Object visit(ExprTy.Await node) {
@Override
public Object visit(ExprTy.Yield node) {
- PythonObject o = factory.createPythonObject(state.clsYield);
+ PythonObject o = createPythonObject(state.clsYield);
o.setAttribute(AstState.T_F_VALUE, visitNullable(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -494,7 +494,7 @@ public Object visit(ExprTy.Yield node) {
@Override
public Object visit(ExprTy.YieldFrom node) {
- PythonObject o = factory.createPythonObject(state.clsYieldFrom);
+ PythonObject o = createPythonObject(state.clsYieldFrom);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -502,7 +502,7 @@ public Object visit(ExprTy.YieldFrom node) {
@Override
public Object visit(ExprTy.Compare node) {
- PythonObject o = factory.createPythonObject(state.clsCompare);
+ PythonObject o = createPythonObject(state.clsCompare);
o.setAttribute(AstState.T_F_LEFT, visitNonNull(node.left));
o.setAttribute(AstState.T_F_OPS, seq2List(node.ops));
o.setAttribute(AstState.T_F_COMPARATORS, seq2List(node.comparators));
@@ -512,7 +512,7 @@ public Object visit(ExprTy.Compare node) {
@Override
public Object visit(ExprTy.Call node) {
- PythonObject o = factory.createPythonObject(state.clsCall);
+ PythonObject o = createPythonObject(state.clsCall);
o.setAttribute(AstState.T_F_FUNC, visitNonNull(node.func));
o.setAttribute(AstState.T_F_ARGS, seq2List(node.args));
o.setAttribute(AstState.T_F_KEYWORDS, seq2List(node.keywords));
@@ -522,7 +522,7 @@ public Object visit(ExprTy.Call node) {
@Override
public Object visit(ExprTy.FormattedValue node) {
- PythonObject o = factory.createPythonObject(state.clsFormattedValue);
+ PythonObject o = createPythonObject(state.clsFormattedValue);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_CONVERSION, visitNonNull(node.conversion));
o.setAttribute(AstState.T_F_FORMAT_SPEC, visitNullable(node.formatSpec));
@@ -532,7 +532,7 @@ public Object visit(ExprTy.FormattedValue node) {
@Override
public Object visit(ExprTy.JoinedStr node) {
- PythonObject o = factory.createPythonObject(state.clsJoinedStr);
+ PythonObject o = createPythonObject(state.clsJoinedStr);
o.setAttribute(AstState.T_F_VALUES, seq2List(node.values));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -540,7 +540,7 @@ public Object visit(ExprTy.JoinedStr node) {
@Override
public Object visit(ExprTy.Constant node) {
- PythonObject o = factory.createPythonObject(state.clsConstant);
+ PythonObject o = createPythonObject(state.clsConstant);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_KIND, visitNullableStringOrByteArray(node.kind));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -549,7 +549,7 @@ public Object visit(ExprTy.Constant node) {
@Override
public Object visit(ExprTy.Attribute node) {
- PythonObject o = factory.createPythonObject(state.clsAttribute);
+ PythonObject o = createPythonObject(state.clsAttribute);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_ATTR, visitNonNull(node.attr));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
@@ -559,7 +559,7 @@ public Object visit(ExprTy.Attribute node) {
@Override
public Object visit(ExprTy.Subscript node) {
- PythonObject o = factory.createPythonObject(state.clsSubscript);
+ PythonObject o = createPythonObject(state.clsSubscript);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_SLICE, visitNonNull(node.slice));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
@@ -569,7 +569,7 @@ public Object visit(ExprTy.Subscript node) {
@Override
public Object visit(ExprTy.Starred node) {
- PythonObject o = factory.createPythonObject(state.clsStarred);
+ PythonObject o = createPythonObject(state.clsStarred);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -578,7 +578,7 @@ public Object visit(ExprTy.Starred node) {
@Override
public Object visit(ExprTy.Name node) {
- PythonObject o = factory.createPythonObject(state.clsName);
+ PythonObject o = createPythonObject(state.clsName);
o.setAttribute(AstState.T_F_ID, visitNonNull(node.id));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -587,7 +587,7 @@ public Object visit(ExprTy.Name node) {
@Override
public Object visit(ExprTy.List node) {
- PythonObject o = factory.createPythonObject(state.clsList);
+ PythonObject o = createPythonObject(state.clsList);
o.setAttribute(AstState.T_F_ELTS, seq2List(node.elements));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -596,7 +596,7 @@ public Object visit(ExprTy.List node) {
@Override
public Object visit(ExprTy.Tuple node) {
- PythonObject o = factory.createPythonObject(state.clsTuple);
+ PythonObject o = createPythonObject(state.clsTuple);
o.setAttribute(AstState.T_F_ELTS, seq2List(node.elements));
o.setAttribute(AstState.T_F_CTX, visitNonNull(node.context));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -605,7 +605,7 @@ public Object visit(ExprTy.Tuple node) {
@Override
public Object visit(ExprTy.Slice node) {
- PythonObject o = factory.createPythonObject(state.clsSlice);
+ PythonObject o = createPythonObject(state.clsSlice);
o.setAttribute(AstState.T_F_LOWER, visitNullable(node.lower));
o.setAttribute(AstState.T_F_UPPER, visitNullable(node.upper));
o.setAttribute(AstState.T_F_STEP, visitNullable(node.step));
@@ -715,7 +715,7 @@ public Object visitNonNull(CmpOpTy v) {
@Override
public Object visit(ComprehensionTy node) {
- PythonObject o = factory.createPythonObject(state.clsComprehensionTy);
+ PythonObject o = createPythonObject(state.clsComprehensionTy);
o.setAttribute(AstState.T_F_TARGET, visitNonNull(node.target));
o.setAttribute(AstState.T_F_ITER, visitNonNull(node.iter));
o.setAttribute(AstState.T_F_IFS, seq2List(node.ifs));
@@ -725,7 +725,7 @@ public Object visit(ComprehensionTy node) {
@Override
public Object visit(ExceptHandlerTy.ExceptHandler node) {
- PythonObject o = factory.createPythonObject(state.clsExceptHandler);
+ PythonObject o = createPythonObject(state.clsExceptHandler);
o.setAttribute(AstState.T_F_TYPE, visitNullable(node.type));
o.setAttribute(AstState.T_F_NAME, visitNullable(node.name));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -735,7 +735,7 @@ public Object visit(ExceptHandlerTy.ExceptHandler node) {
@Override
public Object visit(ArgumentsTy node) {
- PythonObject o = factory.createPythonObject(state.clsArgumentsTy);
+ PythonObject o = createPythonObject(state.clsArgumentsTy);
o.setAttribute(AstState.T_F_POSONLYARGS, seq2List(node.posOnlyArgs));
o.setAttribute(AstState.T_F_ARGS, seq2List(node.args));
o.setAttribute(AstState.T_F_VARARG, visitNullable(node.varArg));
@@ -748,7 +748,7 @@ public Object visit(ArgumentsTy node) {
@Override
public Object visit(ArgTy node) {
- PythonObject o = factory.createPythonObject(state.clsArgTy);
+ PythonObject o = createPythonObject(state.clsArgTy);
o.setAttribute(AstState.T_F_ARG, visitNonNull(node.arg));
o.setAttribute(AstState.T_F_ANNOTATION, visitNullable(node.annotation));
o.setAttribute(AstState.T_F_TYPE_COMMENT, visitNullableStringOrByteArray(node.typeComment));
@@ -758,7 +758,7 @@ public Object visit(ArgTy node) {
@Override
public Object visit(KeywordTy node) {
- PythonObject o = factory.createPythonObject(state.clsKeywordTy);
+ PythonObject o = createPythonObject(state.clsKeywordTy);
o.setAttribute(AstState.T_F_ARG, visitNullable(node.arg));
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -767,7 +767,7 @@ public Object visit(KeywordTy node) {
@Override
public Object visit(AliasTy node) {
- PythonObject o = factory.createPythonObject(state.clsAliasTy);
+ PythonObject o = createPythonObject(state.clsAliasTy);
o.setAttribute(AstState.T_F_NAME, visitNonNull(node.name));
o.setAttribute(AstState.T_F_ASNAME, visitNullable(node.asName));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -776,7 +776,7 @@ public Object visit(AliasTy node) {
@Override
public Object visit(WithItemTy node) {
- PythonObject o = factory.createPythonObject(state.clsWithItemTy);
+ PythonObject o = createPythonObject(state.clsWithItemTy);
o.setAttribute(AstState.T_F_CONTEXT_EXPR, visitNonNull(node.contextExpr));
o.setAttribute(AstState.T_F_OPTIONAL_VARS, visitNullable(node.optionalVars));
return o;
@@ -784,7 +784,7 @@ public Object visit(WithItemTy node) {
@Override
public Object visit(MatchCaseTy node) {
- PythonObject o = factory.createPythonObject(state.clsMatchCaseTy);
+ PythonObject o = createPythonObject(state.clsMatchCaseTy);
o.setAttribute(AstState.T_F_PATTERN, visitNonNull(node.pattern));
o.setAttribute(AstState.T_F_GUARD, visitNullable(node.guard));
o.setAttribute(AstState.T_F_BODY, seq2List(node.body));
@@ -793,7 +793,7 @@ public Object visit(MatchCaseTy node) {
@Override
public Object visit(PatternTy.MatchValue node) {
- PythonObject o = factory.createPythonObject(state.clsMatchValue);
+ PythonObject o = createPythonObject(state.clsMatchValue);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -801,7 +801,7 @@ public Object visit(PatternTy.MatchValue node) {
@Override
public Object visit(PatternTy.MatchSingleton node) {
- PythonObject o = factory.createPythonObject(state.clsMatchSingleton);
+ PythonObject o = createPythonObject(state.clsMatchSingleton);
o.setAttribute(AstState.T_F_VALUE, visitNonNull(node.value));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -809,7 +809,7 @@ public Object visit(PatternTy.MatchSingleton node) {
@Override
public Object visit(PatternTy.MatchSequence node) {
- PythonObject o = factory.createPythonObject(state.clsMatchSequence);
+ PythonObject o = createPythonObject(state.clsMatchSequence);
o.setAttribute(AstState.T_F_PATTERNS, seq2List(node.patterns));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -817,7 +817,7 @@ public Object visit(PatternTy.MatchSequence node) {
@Override
public Object visit(PatternTy.MatchMapping node) {
- PythonObject o = factory.createPythonObject(state.clsMatchMapping);
+ PythonObject o = createPythonObject(state.clsMatchMapping);
o.setAttribute(AstState.T_F_KEYS, seq2List(node.keys));
o.setAttribute(AstState.T_F_PATTERNS, seq2List(node.patterns));
o.setAttribute(AstState.T_F_REST, visitNullable(node.rest));
@@ -827,7 +827,7 @@ public Object visit(PatternTy.MatchMapping node) {
@Override
public Object visit(PatternTy.MatchClass node) {
- PythonObject o = factory.createPythonObject(state.clsMatchClass);
+ PythonObject o = createPythonObject(state.clsMatchClass);
o.setAttribute(AstState.T_F_CLS, visitNonNull(node.cls));
o.setAttribute(AstState.T_F_PATTERNS, seq2List(node.patterns));
o.setAttribute(AstState.T_F_KWD_ATTRS, seq2List(node.kwdAttrs));
@@ -838,7 +838,7 @@ public Object visit(PatternTy.MatchClass node) {
@Override
public Object visit(PatternTy.MatchStar node) {
- PythonObject o = factory.createPythonObject(state.clsMatchStar);
+ PythonObject o = createPythonObject(state.clsMatchStar);
o.setAttribute(AstState.T_F_NAME, visitNullable(node.name));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -846,7 +846,7 @@ public Object visit(PatternTy.MatchStar node) {
@Override
public Object visit(PatternTy.MatchAs node) {
- PythonObject o = factory.createPythonObject(state.clsMatchAs);
+ PythonObject o = createPythonObject(state.clsMatchAs);
o.setAttribute(AstState.T_F_PATTERN, visitNullable(node.pattern));
o.setAttribute(AstState.T_F_NAME, visitNullable(node.name));
fillSourceRangeAttributes(o, node.getSourceRange());
@@ -855,7 +855,7 @@ public Object visit(PatternTy.MatchAs node) {
@Override
public Object visit(PatternTy.MatchOr node) {
- PythonObject o = factory.createPythonObject(state.clsMatchOr);
+ PythonObject o = createPythonObject(state.clsMatchOr);
o.setAttribute(AstState.T_F_PATTERNS, seq2List(node.patterns));
fillSourceRangeAttributes(o, node.getSourceRange());
return o;
@@ -863,7 +863,7 @@ public Object visit(PatternTy.MatchOr node) {
@Override
public Object visit(TypeIgnoreTy.TypeIgnore node) {
- PythonObject o = factory.createPythonObject(state.clsTypeIgnore);
+ PythonObject o = createPythonObject(state.clsTypeIgnore);
o.setAttribute(AstState.T_F_LINENO, visitNonNull(node.lineNo));
o.setAttribute(AstState.T_F_TAG, visitNonNullStringOrByteArray(node.tag));
return o;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitorBase.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitorBase.java
index 9d106b646d..fe054561f2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitorBase.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Sst2ObjVisitorBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,15 +46,17 @@
import static com.oracle.graal.python.builtins.modules.ast.AstState.T_F_LINENO;
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.object.PythonObject;
+import com.oracle.graal.python.builtins.objects.type.PythonClass;
import com.oracle.graal.python.pegparser.sst.CmpOpTy;
import com.oracle.graal.python.pegparser.sst.ConstantValue;
import com.oracle.graal.python.pegparser.sst.SSTNode;
import com.oracle.graal.python.pegparser.sst.SSTreeVisitor;
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.strings.TruffleString;
@@ -63,10 +65,10 @@
*/
abstract class Sst2ObjVisitorBase implements SSTreeVisitor {
- final PythonObjectFactory factory;
+ final PythonLanguage language;
Sst2ObjVisitorBase() {
- factory = PythonObjectFactory.getUncached();
+ language = PythonLanguage.get(null);
}
static int visitNullable(int i) {
@@ -106,11 +108,11 @@ Object visitNonNullStringOrByteArray(Object o) {
return toTruffleStringUncached((String) o);
}
assert o instanceof byte[];
- return factory.createBytes((byte[]) o);
+ return PFactory.createBytes(language, (byte[]) o);
}
final Object visitNonNull(ConstantValue v) {
- return PythonUtils.pythonObjectFromConstantValue(v, factory);
+ return PythonUtils.pythonObjectFromConstantValue(v);
}
abstract Object visitNonNull(CmpOpTy op);
@@ -121,41 +123,45 @@ final Object visitNonNull(SSTNode node) {
final PList seq2List(String[] seq) {
if (seq == null || seq.length == 0) {
- return factory.createList();
+ return PFactory.createList(language);
}
Object[] objs = new Object[seq.length];
for (int i = 0; i < objs.length; ++i) {
objs[i] = visitNullable(seq[i]);
}
- return factory.createList(objs);
+ return PFactory.createList(language, objs);
}
final PList seq2List(CmpOpTy[] seq) {
if (seq == null || seq.length == 0) {
- return factory.createList();
+ return PFactory.createList(language);
}
Object[] objs = new Object[seq.length];
for (int i = 0; i < objs.length; ++i) {
objs[i] = visitNullable(seq[i]);
}
- return factory.createList(objs);
+ return PFactory.createList(language, objs);
}
final PList seq2List(SSTNode[] seq) {
if (seq == null || seq.length == 0) {
- return factory.createList();
+ return PFactory.createList(language);
}
Object[] objs = new Object[seq.length];
for (int i = 0; i < objs.length; ++i) {
objs[i] = visitNullable(seq[i]);
}
- return factory.createList(objs);
+ return PFactory.createList(language, objs);
}
- static final void fillSourceRangeAttributes(PythonObject o, SourceRange sourceRange) {
+ static void fillSourceRangeAttributes(PythonObject o, SourceRange sourceRange) {
o.setAttribute(T_F_LINENO, sourceRange.startLine);
o.setAttribute(T_F_COL_OFFSET, sourceRange.startColumn);
o.setAttribute(T_F_END_LINENO, sourceRange.endLine);
o.setAttribute(T_F_END_COL_OFFSET, sourceRange.endColumn);
}
+
+ protected PythonObject createPythonObject(PythonClass cls) {
+ return PFactory.createPythonObject(language, cls, cls.getInstanceShape());
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
index f63ae127f2..28865aeb0d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,7 +71,7 @@
import com.oracle.graal.python.runtime.NFIBz2Support;
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -134,24 +134,25 @@ static Object err(Object self, Object compresslevel,
abstract static class CompressNode extends PythonBinaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
- PBytes doNativeBytes(BZ2Object.BZ2Compressor self, PBytesLike data,
+ static PBytes doNativeBytes(BZ2Object.BZ2Compressor self, PBytesLike data,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached SequenceStorageNodes.GetInternalByteArrayNode toBytes,
- @Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress) {
byte[] bytes = toBytes.execute(inliningTarget, data.getSequenceStorage());
int len = data.getSequenceStorage().length();
- return factory.createBytes(compress.compress(self, PythonContext.get(this), bytes, len));
+ return PFactory.createBytes(context.getLanguage(inliningTarget), compress.compress(self, context, bytes, len));
}
@Specialization(guards = {"!self.isFlushed()"})
- PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Compressor self, Object data,
+ static PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Compressor self, Object data,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached BytesNodes.ToBytesNode toBytes,
- @Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress) {
byte[] bytes = toBytes.execute(frame, data);
int len = bytes.length;
- return factory.createBytes(compress.compress(self, PythonContext.get(this), bytes, len));
+ return PFactory.createBytes(context.getLanguage(inliningTarget), compress.compress(self, context, bytes, len));
}
@SuppressWarnings("unused")
@@ -167,11 +168,12 @@ static PNone error(BZ2Object.BZ2Compressor self, Object data,
abstract static class FlushNode extends PythonUnaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
- PBytes doit(BZ2Object.BZ2Compressor self,
- @Cached Bz2Nodes.Bz2NativeCompress compress,
- @Cached PythonObjectFactory factory) {
+ static PBytes doit(BZ2Object.BZ2Compressor self,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @Cached Bz2Nodes.Bz2NativeCompress compress) {
self.setFlushed();
- return factory.createBytes(compress.flush(self, PythonContext.get(this)));
+ return PFactory.createBytes(context.getLanguage(inliningTarget), compress.flush(self, context));
}
@SuppressWarnings("unused")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
index 502e057287..e33951bfd7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -66,11 +67,10 @@
import com.oracle.graal.python.runtime.NFIBz2Support;
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -118,26 +118,26 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = {"!self.isEOF()"})
static PBytes doNativeBytes(BZ2Object.BZ2Decompressor self, PBytesLike data, int maxLength,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached SequenceStorageNodes.GetInternalByteArrayNode toBytes,
- @Exclusive @Cached Bz2Nodes.Bz2NativeDecompress decompress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached Bz2Nodes.Bz2NativeDecompress decompress) {
synchronized (self) {
byte[] bytes = toBytes.execute(inliningTarget, data.getSequenceStorage());
int len = data.getSequenceStorage().length();
- return factory.createBytes(decompress.execute(inliningTarget, self, bytes, len, maxLength));
+ return PFactory.createBytes(language, decompress.execute(inliningTarget, self, bytes, len, maxLength));
}
}
@Specialization(guards = {"!self.isEOF()"})
static PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Decompressor self, Object data, int maxLength,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached BytesNodes.ToBytesNode toBytes,
- @Exclusive @Cached Bz2Nodes.Bz2NativeDecompress decompress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached Bz2Nodes.Bz2NativeDecompress decompress) {
synchronized (self) {
byte[] bytes = toBytes.execute(frame, data);
int len = bytes.length;
- return factory.createBytes(decompress.execute(inliningTarget, self, bytes, len, maxLength));
+ return PFactory.createBytes(language, decompress.execute(inliningTarget, self, bytes, len, maxLength));
}
}
@@ -154,8 +154,8 @@ static Object err(BZ2Object.BZ2Decompressor self, PBytesLike data, int maxLength
abstract static class UnusedDataNode extends PythonUnaryBuiltinNode {
@Specialization
static PBytes doit(BZ2Object.BZ2Decompressor self,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(self.getUnusedData());
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, self.getUnusedData());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2ModuleBuiltins.java
index 4d72367d0d..37253013fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -52,8 +53,8 @@
import com.oracle.graal.python.nodes.BuiltinNames;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -76,10 +77,10 @@ public void initialize(Python3Core core) {
@GenerateNodeFactory
public abstract static class BZ2CompressorNode extends PythonBuiltinNode {
@Specialization
- static BZ2Object.BZ2Compressor doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ static BZ2Object.BZ2Compressor doNew(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object arg,
+ @Bind PythonLanguage language) {
// data filled in subsequent __init__ call - see BZ2CompressorBuiltins.InitNode
- return factory.createBZ2Compressor(cls);
+ return PFactory.createBZ2Compressor(language);
}
}
@@ -87,10 +88,10 @@ static BZ2Object.BZ2Compressor doNew(Object cls, @SuppressWarnings("unused") Obj
@GenerateNodeFactory
public abstract static class BZ2DecompressorNode extends PythonBuiltinNode {
@Specialization
- static BZ2Object.BZ2Decompressor doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ static BZ2Object.BZ2Decompressor doNew(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object arg,
+ @Bind PythonLanguage language) {
// data filled in subsequent __init__ call - see BZ2DecompressorBuiltins.InitNode
- return factory.createBZ2Decompressor(cls);
+ return PFactory.createBZ2Decompressor(language);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
index a1e959050a..b44f6287df 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
@@ -190,7 +190,7 @@
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.NativeByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
@@ -205,7 +205,6 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -253,26 +252,26 @@ public abstract static class PromoteBorrowedValue extends Node {
@Specialization
static PString doString(TruffleString str,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createString(str);
+ @Bind PythonLanguage language) {
+ return PFactory.createString(language, str);
}
@Specialization
static PythonBuiltinObject doInteger(int i,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(i);
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, i);
}
@Specialization
static PythonBuiltinObject doLong(long i,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(i);
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, i);
}
@Specialization(guards = "!isNaN(d)")
static PythonBuiltinObject doDouble(double d,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createFloat(d);
+ @Bind PythonLanguage language) {
+ return PFactory.createFloat(language, d);
}
static boolean isNaN(double d) {
@@ -298,12 +297,12 @@ public static PException checkThrowableBeforeNative(Throwable t, String where1,
CompilerDirectives.transferToInterpreter();
PythonContext context = PythonContext.get(null);
context.ensureGilAfterFailure();
- PBaseException newException = context.factory().createBaseException(RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, EMPTY_OBJECT_ARRAY);
+ PBaseException newException = PFactory.createBaseException(context.getLanguage(), RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, EMPTY_OBJECT_ARRAY);
throw ExceptionUtils.wrapJavaException(soe, null, newException);
}
if (t instanceof OutOfMemoryError oome) {
CompilerDirectives.transferToInterpreter();
- PBaseException newException = PythonContext.get(null).factory().createBaseException(MemoryError);
+ PBaseException newException = PFactory.createBaseException(PythonLanguage.get(null), MemoryError);
throw ExceptionUtils.wrapJavaException(oome, null, newException);
}
// everything else: log and convert to PException (SystemError)
@@ -1143,14 +1142,14 @@ private static Object[] collect(MroSequenceStorage mro, int idx) {
abstract static class PyFrame_New extends CApiQuaternaryBuiltinNode {
@Specialization
static Object newFrame(Object threadState, PCode code, PythonObject globals, Object locals,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object frameLocals;
if (locals == null || PGuards.isPNone(locals)) {
- frameLocals = factory.createDict();
+ frameLocals = PFactory.createDict(language);
} else {
frameLocals = locals;
}
- return factory.createPFrame(threadState, code, globals, frameLocals);
+ return PFactory.createPFrame(language, threadState, code, globals, frameLocals);
}
}
@@ -1171,7 +1170,7 @@ static Object wrap(Object bufferStructPointer, Object ownerObj, long lenObj,
@Cached CastToJavaIntExactNode castToIntNode,
@Cached TruffleString.CodePointLengthNode lengthNode,
@Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int ndim = castToIntNode.execute(inliningTarget, ndimObj);
int itemsize = castToIntNode.execute(inliningTarget, itemsizeObj);
int len = castToIntNode.execute(inliningTarget, lenObj);
@@ -1202,7 +1201,7 @@ static Object wrap(Object bufferStructPointer, Object ownerObj, long lenObj,
if (!lib.isNull(bufferStructPointer)) {
bufferLifecycleManager = new NativeBufferLifecycleManager.NativeBufferLifecycleManagerFromType(bufferStructPointer);
}
- return factory.createMemoryView(PythonContext.get(inliningTarget), bufferLifecycleManager, buffer, owner, len, readonly, itemsize,
+ return PFactory.createMemoryView(language, PythonContext.get(inliningTarget), bufferLifecycleManager, buffer, owner, len, readonly, itemsize,
BufferFormat.forMemoryView(format, lengthNode, atIndexNode), format, ndim, bufPointer, 0, shape, strides, suboffsets, flags);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
index e146727e9e..f3d47b9596 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -58,6 +58,7 @@
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.BytesNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
@@ -97,7 +98,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.nodes.util.CastToByteNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
@@ -217,26 +218,26 @@ abstract static class PyTruffleBytes_FromStringAndSize extends CApiBinaryBuiltin
@Specialization
static Object doGeneric(PythonNativeWrapper object, long size,
+ @Bind PythonLanguage language,
@Cached NativeToPythonNode asPythonObjectNode,
- @Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode) {
byte[] ary = getByteArrayNode.execute(null, asPythonObjectNode.execute(object));
if (size >= 0 && size < ary.length) {
// cast to int is guaranteed because of 'size < ary.length'
- return factory.createBytes(Arrays.copyOf(ary, (int) size));
+ return PFactory.createBytes(language, Arrays.copyOf(ary, (int) size));
} else {
- return factory.createBytes(ary);
+ return PFactory.createBytes(language, ary);
}
}
@Specialization(guards = "!isNativeWrapper(nativePointer)")
static Object doNativePointer(Object nativePointer, long size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached GetByteArrayNode getByteArrayNode,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- return factory.createBytes(getByteArrayNode.execute(inliningTarget, nativePointer, size));
+ return PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, nativePointer, size));
} catch (InteropException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
@@ -250,26 +251,26 @@ static Object doNativePointer(Object nativePointer, long size,
abstract static class PyTruffleByteArray_FromStringAndSize extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(PythonNativeWrapper object, long size,
+ @Bind PythonLanguage language,
@Cached NativeToPythonNode asPythonObjectNode,
- @Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode) {
byte[] ary = getByteArrayNode.execute(null, asPythonObjectNode.execute(object));
if (size >= 0 && size < ary.length) {
// cast to int is guaranteed because of 'size < ary.length'
- return factory.createByteArray(Arrays.copyOf(ary, (int) size));
+ return PFactory.createByteArray(language, Arrays.copyOf(ary, (int) size));
} else {
- return factory.createByteArray(ary);
+ return PFactory.createByteArray(language, ary);
}
}
@Specialization(guards = "!isNativeWrapper(nativePointer)")
static Object doNativePointer(Object nativePointer, long size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached GetByteArrayNode getByteArrayNode,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- return factory.createByteArray(getByteArrayNode.execute(inliningTarget, nativePointer, size));
+ return PFactory.createByteArray(language, getByteArrayNode.execute(inliningTarget, nativePointer, size));
} catch (InteropException e) {
return raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
@@ -312,23 +313,23 @@ abstract static class PyTruffle_Bytes_EmptyWithCapacity extends CApiUnaryBuiltin
@Specialization
static PBytes doInt(int size,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(new byte[size]);
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, new byte[size]);
}
@Specialization(rewriteOn = OverflowException.class)
static PBytes doLong(long size,
- @Shared @Cached PythonObjectFactory factory) throws OverflowException {
- return doInt(PInt.intValueExact(size), factory);
+ @Bind PythonLanguage language) throws OverflowException {
+ return doInt(PInt.intValueExact(size), language);
}
@Specialization(replaces = "doLong")
static PBytes doLongOvf(long size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
try {
- return doInt(PInt.intValueExact(size), factory);
+ return doInt(PInt.intValueExact(size), language);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
}
@@ -336,17 +337,17 @@ static PBytes doLongOvf(long size,
@Specialization(rewriteOn = OverflowException.class)
static PBytes doPInt(PInt size,
- @Shared @Cached PythonObjectFactory factory) throws OverflowException {
- return doInt(size.intValueExact(), factory);
+ @Bind PythonLanguage language) throws OverflowException {
+ return doInt(size.intValueExact(), language);
}
@Specialization(replaces = "doPInt")
static PBytes doPIntOvf(PInt size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
try {
- return doInt(size.intValueExact(), factory);
+ return doInt(size.intValueExact(), language);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
}
@@ -358,23 +359,23 @@ abstract static class PyTruffle_ByteArray_EmptyWithCapacity extends CApiUnaryBui
@Specialization
static PByteArray doInt(int size,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createByteArray(new byte[size]);
+ @Bind PythonLanguage language) {
+ return PFactory.createByteArray(language, new byte[size]);
}
@Specialization(rewriteOn = OverflowException.class)
static PByteArray doLong(long size,
- @Shared @Cached PythonObjectFactory factory) throws OverflowException {
- return doInt(PInt.intValueExact(size), factory);
+ @Bind PythonLanguage language) throws OverflowException {
+ return doInt(PInt.intValueExact(size), language);
}
@Specialization(replaces = "doLong")
static PByteArray doLongOvf(long size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
try {
- return doInt(PInt.intValueExact(size), factory);
+ return doInt(PInt.intValueExact(size), language);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
}
@@ -382,17 +383,17 @@ static PByteArray doLongOvf(long size,
@Specialization(rewriteOn = OverflowException.class)
static PByteArray doPInt(PInt size,
- @Shared @Cached PythonObjectFactory factory) throws OverflowException {
- return doInt(size.intValueExact(), factory);
+ @Bind PythonLanguage language) throws OverflowException {
+ return doInt(size.intValueExact(), language);
}
@Specialization(replaces = "doPInt")
static PByteArray doPIntOvf(PInt size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
try {
- return doInt(size.intValueExact(), factory);
+ return doInt(size.intValueExact(), language);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
index 456e9f832f..410ef50f24 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import static com.oracle.graal.python.nodes.ErrorMessages.PY_CAPSULE_IMPORT_S_IS_NOT_VALID;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiTernaryBuiltinNode;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.StringLiterals;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
@@ -100,12 +101,12 @@ public abstract static class PyCapsuleNewNode extends Node {
@Specialization
static PyCapsule doGeneric(Node inliningTarget, Object pointer, Object namePtr, Object destructor,
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (interopLibrary.isNull(pointer)) {
throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT);
}
- PyCapsule capsule = factory.createCapsuleNativeName(pointer, interopLibrary.isNull(namePtr) ? null : namePtr);
+ PyCapsule capsule = PFactory.createCapsuleNativeName(language, pointer, interopLibrary.isNull(namePtr) ? null : namePtr);
if (!interopLibrary.isNull(destructor)) {
capsule.registerDestructor(destructor);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
index 65c58365f9..a7a603d441 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,13 +44,13 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObject;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
@@ -63,10 +63,10 @@ abstract static class PyInstanceMethod_New extends CApiUnaryBuiltinNode {
@Specialization
static Object staticmethod(Object func,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
checkNonNullArg(inliningTarget, func, raiseNode);
- PDecoratedMethod res = factory.createInstancemethod(PythonBuiltinClassType.PInstancemethod);
+ PDecoratedMethod res = PFactory.createInstancemethod(language);
res.setCallable(func);
return res;
}
@@ -77,12 +77,12 @@ abstract static class PyMethod_New extends CApiBinaryBuiltinNode {
@Specialization
static Object methodNew(Object func, Object self,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
checkNonNullArg(inliningTarget, func, self, raiseNode);
// Note: CPython also constructs the object directly, without running the constructor or
// checking the inputs
- return factory.createMethod(self, func);
+ return PFactory.createMethod(language, self, func);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
index 6797e32c2e..cf805f5aca 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___FLOAT__;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.ComplexNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -173,8 +174,8 @@ abstract static class PyComplex_FromDoubles extends CApiBinaryBuiltinNode {
@Specialization
static PComplex asDouble(double r, double i,
- @Cached PythonObjectFactory factory) {
- return factory.createComplex(r, i);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, r, i);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
index f586ef8607..b131a49166 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
@@ -50,6 +50,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.VoidNoReturn;
import static com.oracle.graal.python.runtime.exception.ExceptionUtils.printPythonLikeStackTrace;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
@@ -65,7 +66,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -134,15 +135,15 @@ abstract static class PyContextVar_Set extends CApiBinaryBuiltinNode {
static Object doGeneric(Object var, Object val,
@Bind("this") Node inliningTarget,
@Bind PythonContext pythonContext,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (!(var instanceof PContextVar pvar)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
}
- PythonContext.PythonThreadState threadState = pythonContext.getThreadState(pythonContext.getLanguage(inliningTarget));
+ PythonLanguage language = pythonContext.getLanguage(inliningTarget);
+ PythonContext.PythonThreadState threadState = pythonContext.getThreadState(language);
Object oldValue = pvar.getValue(threadState);
pvar.setValue(threadState, val);
- return factory.createContextVarsToken(pvar, oldValue);
+ return PFactory.createContextVarsToken(language, pvar, oldValue);
}
}
@@ -160,8 +161,8 @@ static Object doGeneric(
abstract static class PyContext_Copy extends CApiUnaryBuiltinNode {
@Specialization
static Object doGeneric(PContextVarsContext context,
- @Cached PythonObjectFactory factory) {
- return factory.copyContextVarsContext(context);
+ @Bind PythonLanguage language) {
+ return PFactory.copyContextVarsContext(language, context);
}
}
@@ -169,8 +170,8 @@ static Object doGeneric(PContextVarsContext context,
abstract static class PyContext_New extends CApiNullaryBuiltinNode {
@Specialization
static Object doGeneric(
- @Cached PythonObjectFactory factory) {
- return factory.createContextVarsContext();
+ @Bind PythonLanguage language) {
+ return PFactory.createContextVarsContext(language);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java
index ff8493c9e0..9d174eb562 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyTypeObject;
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.isClassOrStaticMethod;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi6BuiltinNode;
@@ -58,7 +59,7 @@
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextTypeBuiltins.CreateGetSetNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextTypeBuiltins.NewClassMethodNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
@@ -94,14 +95,14 @@ abstract static class PyTruffleDescr_NewClassMethod extends CApi7BuiltinNode {
static Object doNativeCallable(Object methodDefPtr, TruffleString name, Object doc, int flags, Object wrapper, Object methObj, Object type,
@Bind("this") Node inliningTarget,
@Cached NewClassMethodNode newClassMethodNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object func = newClassMethodNode.execute(inliningTarget, methodDefPtr, name, methObj, flags, wrapper, type, doc);
if (!isClassOrStaticMethod(flags)) {
/*
* NewClassMethodNode only wraps method with METH_CLASS and METH_STATIC set but we
* need to do so here.
*/
- func = factory.createClassmethodFromCallableObj(func);
+ func = PFactory.createClassmethodFromCallableObj(language, func);
}
return func;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
index 8804ab75a9..9edf930793 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
@@ -62,6 +62,7 @@
import java.util.logging.Level;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi5BuiltinNode;
@@ -110,7 +111,7 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
@@ -135,8 +136,9 @@ public final class PythonCextDictBuiltins {
abstract static class PyDict_New extends CApiNullaryBuiltinNode {
@Specialization
- static Object run(@Cached PythonObjectFactory factory) {
- return factory.createDict();
+ static Object run(
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language);
}
}
@@ -288,8 +290,8 @@ abstract static class PyDict_Copy extends CApiUnaryBuiltinNode {
static Object copy(PDict dict,
@Bind("this") Node inliningTarget,
@Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory) {
- return factory.createDict(copyNode.execute(inliningTarget, dict.getDictStorage()));
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language, copyNode.execute(inliningTarget, dict.getDictStorage()));
}
@Fallback
@@ -488,8 +490,8 @@ abstract static class PyDict_Keys extends CApiUnaryBuiltinNode {
@Specialization
static Object keys(PDict dict,
@Cached ConstructListNode listNode,
- @Cached PythonObjectFactory factory) {
- return listNode.execute(null, factory.createDictKeysView(dict));
+ @Bind PythonLanguage language) {
+ return listNode.execute(null, PFactory.createDictKeysView(language, dict));
}
@Fallback
@@ -503,8 +505,8 @@ abstract static class PyDict_Values extends CApiUnaryBuiltinNode {
@Specialization
static Object values(PDict dict,
@Cached ConstructListNode listNode,
- @Cached PythonObjectFactory factory) {
- return listNode.execute(null, factory.createDictValuesView(dict));
+ @Bind PythonLanguage language) {
+ return listNode.execute(null, PFactory.createDictValuesView(language, dict));
}
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
index eebc9919a0..407591b9e2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
@@ -124,7 +124,7 @@
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -336,6 +336,7 @@ abstract static class PyErr_NewException extends CApiTernaryBuiltinNode {
@Specialization
static Object newEx(TruffleString name, Object base, Object dict,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached HashingStorageGetItem getItem,
@Cached TruffleString.IndexOfCodePointNode indexOfCodepointNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@@ -345,13 +346,12 @@ static Object newEx(TruffleString name, Object base, Object dict,
@Cached InlinedBranchProfile notDotProfile,
@Cached InlinedBranchProfile notModuleProfile,
@Cached InlinedConditionProfile baseProfile,
- @Cached PythonObjectFactory.Lazy factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (base == PNone.NO_VALUE) {
base = PythonErrorType.Exception;
}
if (dict == PNone.NO_VALUE) {
- dict = factory.get(inliningTarget).createDict();
+ dict = PFactory.createDict(language);
}
int length = codePointLengthNode.execute(name, TS_ENCODING);
int dotIdx = indexOfCodepointNode.execute(name, '.', 0, length, TS_ENCODING);
@@ -367,7 +367,7 @@ static Object newEx(TruffleString name, Object base, Object dict,
if (baseProfile.profile(inliningTarget, base instanceof PTuple)) {
bases = (PTuple) base;
} else {
- bases = factory.get(inliningTarget).createTuple(new Object[]{base});
+ bases = PFactory.createTuple(language, new Object[]{base});
}
return typeNode.execute(null, PythonBuiltinClassType.PythonClass, substringNode.execute(name, dotIdx + 1, length - dotIdx - 1, TS_ENCODING, false), bases, dict,
PKeyword.EMPTY_KEYWORDS);
@@ -381,12 +381,12 @@ abstract static class PyErr_NewExceptionWithDoc extends CApiQuaternaryBuiltinNod
static Object raise(TruffleString name, Object doc, Object base, Object dict,
@Cached PyErr_NewException newExNode,
@Cached WriteAttributeToObjectNode writeAtrrNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (base == PNone.NO_VALUE) {
base = PythonErrorType.Exception;
}
if (dict == PNone.NO_VALUE) {
- dict = factory.createDict();
+ dict = PFactory.createDict(language);
}
Object ex = newExNode.execute(name, base, dict);
if (doc != PNone.NO_VALUE) {
@@ -406,7 +406,7 @@ Object info(
@Cached ExceptionNodes.GetTracebackNode getTracebackNode,
@Cached InlinedBranchProfile noExceptionProfile,
@Cached GetEscapedExceptionNode getEscapedExceptionNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
AbstractTruffleException currentException = getCaughtExceptionNode.executeFromNative();
if (currentException == null) {
noExceptionProfile.enter(inliningTarget);
@@ -415,7 +415,7 @@ Object info(
assert currentException != PException.NO_EXCEPTION;
Object exception = getEscapedExceptionNode.execute(inliningTarget, currentException);
Object traceback = noneToNativeNull(inliningTarget, getTracebackNode.execute(inliningTarget, exception));
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, exception), exception, traceback});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, exception), exception, traceback});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFuncBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFuncBuiltins.java
index 0aeeef07f6..9835b61b3a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFuncBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFuncBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,7 +47,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___DOC__;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
@@ -56,10 +56,10 @@
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.strings.TruffleString;
@@ -69,8 +69,8 @@ public final class PythonCextFuncBuiltins {
abstract static class PyStaticMethod_New extends CApiUnaryBuiltinNode {
@Specialization
static Object staticmethod(Object func,
- @Cached PythonObjectFactory factory) {
- PDecoratedMethod res = factory.createStaticmethod(PythonBuiltinClassType.PStaticmethod);
+ @Bind PythonLanguage language) {
+ PDecoratedMethod res = PFactory.createStaticmethod(language);
res.setCallable(func);
return res;
}
@@ -80,8 +80,8 @@ static Object staticmethod(Object func,
abstract static class PyClassMethod_New extends CApiUnaryBuiltinNode {
@Specialization
static Object staticmethod(Object callable,
- @Cached PythonObjectFactory factory) {
- return factory.createClassmethodFromCallableObj(callable);
+ @Bind PythonLanguage language) {
+ return PFactory.createClassmethodFromCallableObj(language, callable);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextGenericAliasBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextGenericAliasBuiltins.java
index 0b54f33287..bb8895a010 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextGenericAliasBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextGenericAliasBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,10 +44,11 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObject;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Specialization;
public final class PythonCextGenericAliasBuiltins {
@@ -56,8 +57,8 @@ public final class PythonCextGenericAliasBuiltins {
abstract static class Py_GenericAlias extends CApiBinaryBuiltinNode {
@Specialization
static Object genericAlias(Object origin, Object args,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(origin, args);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, origin, args);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextIterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextIterBuiltins.java
index e9eeca74f2..b08b938c62 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextIterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextIterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,13 +45,14 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObject;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.IterNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
import com.oracle.graal.python.lib.PyIterCheckNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
@@ -73,8 +74,8 @@ static int check(Object obj,
abstract static class PySeqIter_New extends CApiUnaryBuiltinNode {
@Specialization
static PSequenceIterator call(Object seq,
- @Cached PythonObjectFactory factory) {
- return factory.createSequenceIterator(seq);
+ @Bind PythonLanguage language) {
+ return PFactory.createSequenceIterator(language, seq);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
index 6fdcfc1802..4e3c3b4657 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
@@ -56,6 +56,7 @@
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
@@ -81,14 +82,12 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.builtins.ListNodes.AppendNode;
import com.oracle.graal.python.nodes.builtins.TupleNodes.ConstructTupleNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
-import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
@@ -106,14 +105,14 @@ static Object newListError(long size,
@SuppressWarnings("unused")
@Specialization(guards = "size == 0")
static Object newEmptyList(long size,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createList(PythonUtils.EMPTY_OBJECT_ARRAY);
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language);
}
@Specialization(guards = "size > 0")
static Object newList(long size,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createList(array(size));
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language, array(size));
}
private static Object[] array(long size) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
index 9b935668c4..168e515605 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
@@ -59,6 +59,7 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi5BuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
@@ -84,7 +85,7 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -275,16 +276,16 @@ static long doSignedLong(long n) {
@Specialization(guards = "!isInteger(pointer)", limit = "2")
static Object doPointer(Object pointer,
@CachedLibrary("pointer") InteropLibrary lib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// We capture the native pointer at the time when we create the wrapper if it exists.
if (lib.isPointer(pointer)) {
try {
- return factory.createNativeVoidPtr(pointer, lib.asPointer(pointer));
+ return PFactory.createNativeVoidPtr(language, pointer, lib.asPointer(pointer));
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
- return factory.createNativeVoidPtr(pointer);
+ return PFactory.createNativeVoidPtr(language, pointer);
}
}
@@ -308,23 +309,23 @@ static Object doUnsignedLongPositive(long n) {
@Specialization(guards = "n < 0")
static Object doUnsignedLongNegative(long n,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(convertToBigInteger(n));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, convertToBigInteger(n));
}
@Specialization(guards = "!isInteger(pointer)", limit = "2")
static Object doPointer(Object pointer,
@CachedLibrary("pointer") InteropLibrary lib,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// We capture the native pointer at the time when we create the wrapper if it exists.
if (lib.isPointer(pointer)) {
try {
- return factory.createNativeVoidPtr(pointer, lib.asPointer(pointer));
+ return PFactory.createNativeVoidPtr(language, pointer, lib.asPointer(pointer));
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
- return factory.createNativeVoidPtr(pointer);
+ return PFactory.createNativeVoidPtr(language, pointer);
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java
index 5529b70771..3860972a83 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___MODULE__;
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___NAME__;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi9BuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -60,7 +61,7 @@
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -90,7 +91,7 @@ final Object execute(Node inliningTarget, Object methodDefPtr, TruffleString nam
@Specialization
static Object doNativeCallable(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, Object flags, int wrapper, Object self, Object module, Object cls, Object doc,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached CreateFunctionNode createFunctionNode,
@Cached HiddenAttr.WriteNode writeHiddenAttrNode,
@Cached(inline = false) WriteAttributeToPythonObjectNode writeAttrNode) {
@@ -102,9 +103,9 @@ static Object doNativeCallable(Node inliningTarget, Object methodDefPtr, Truffle
writeAttrNode.execute(func, T___DOC__, doc);
PBuiltinMethod method;
if (cls != PNone.NO_VALUE) {
- method = factory.createBuiltinMethod(self, func, cls);
+ method = PFactory.createBuiltinMethod(language, self, func, cls);
} else {
- method = factory.createBuiltinMethod(self, func);
+ method = PFactory.createBuiltinMethod(language, self, func);
}
writeAttrNode.execute(method, T___MODULE__, module);
return method;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java
index 85cb7bd4f3..3973656710 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
import static com.oracle.graal.python.nodes.truffle.TruffleStringMigrationHelpers.assertNoJavaString;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.namespace.PSimpleNamespace;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -77,16 +78,15 @@ static Object impDict(PDict dict,
@Shared("itNext") @Cached HashingStorageIteratorNext itNext,
@Shared("itKey") @Cached HashingStorageIteratorKey itKey,
@Shared("itVal") @Cached HashingStorageIteratorValue itValue,
- @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) {
HashingStorage storage = dict.getDictStorage();
- return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, dyLib, factory);
+ return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, dyLib);
}
private static Object impl(Node inliningTarget, HashingStorage storage, HashingStorageGetIterator getIterator, HashingStorageIteratorNext itNext,
HashingStorageIteratorKey itKey, HashingStorageIteratorValue itValue,
- DynamicObjectLibrary dyLib, PythonObjectFactory factory) {
- PSimpleNamespace ns = factory.createSimpleNamespace();
+ DynamicObjectLibrary dyLib) {
+ PSimpleNamespace ns = PFactory.createSimpleNamespace(PythonLanguage.get(inliningTarget));
HashingStorageNodes.HashingStorageIterator it = getIterator.execute(inliningTarget, storage);
while (itNext.execute(inliningTarget, storage, it)) {
Object key = itKey.execute(inliningTarget, storage, it);
@@ -104,10 +104,9 @@ static Object impGeneric(Object dict,
@Shared("itNext") @Cached HashingStorageIteratorNext itNext,
@Shared("itKey") @Cached HashingStorageIteratorKey itKey,
@Shared("itVal") @Cached HashingStorageIteratorValue itValue,
- @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) {
HashingStorage hs = initNode.execute(null, dict, PKeyword.EMPTY_KEYWORDS);
- return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, dyLib, factory);
+ return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, dyLib);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
index c1e8add19d..bb596034d9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
@@ -64,6 +64,7 @@
import java.io.PrintWriter;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.BytesNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.FormatNode;
@@ -135,7 +136,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ArrayBasedSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
@@ -538,12 +539,12 @@ static Object bytes(Object obj,
@Specialization(guards = "isNoValue(obj)")
static Object bytesNoValue(@SuppressWarnings("unused") Object obj,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
/*
* Note: CPython calls PyBytes_FromString("") but we do not directly have it.
* Therefore, we directly create the bytes object with string "" here.
*/
- return factory.createBytes(BytesUtils.NULL_STRING);
+ return PFactory.createBytes(language, BytesUtils.NULL_STRING);
}
protected static boolean hasBytes(Node inliningTarget, Object obj, PyObjectLookupAttr lookupAttrNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyStateBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyStateBuiltins.java
index 3993c3c00d..36a161c79b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyStateBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyStateBuiltins.java
@@ -72,7 +72,7 @@
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ThreadLocalAction;
@@ -150,12 +150,11 @@ abstract static class PyThreadState_GetDict extends CApiNullaryBuiltinNode {
@TruffleBoundary
static PDict get(
@Bind("this") Node inliningTarget,
- @Bind PythonContext context,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context) {
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
PDict threadStateDict = threadState.getDict();
if (threadStateDict == null) {
- threadStateDict = factory.createDict();
+ threadStateDict = PFactory.createDict(context.getLanguage());
threadState.setDict(threadStateDict);
}
return threadStateDict;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyThreadBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyThreadBuiltins.java
index df9a34215a..1c813ea024 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyThreadBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPyThreadBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,7 +49,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Void;
import static com.oracle.graal.python.builtins.objects.ints.PInt.intValue;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiNullaryBuiltinNode;
@@ -58,7 +58,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor;
import com.oracle.graal.python.builtins.objects.thread.PLock;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
@@ -77,7 +77,7 @@ abstract static class PyThread_allocate_lock extends CApiNullaryBuiltinNode {
long allocate() {
CApiContext context = getCApiContext();
long id = context.lockId.incrementAndGet() ^ LOCK_MASK;
- PLock lock = PythonObjectFactory.getUncached().createLock(PythonBuiltinClassType.PLock);
+ PLock lock = PFactory.createLock(PythonLanguage.get(null));
context.locks.put(id, lock);
return id;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
index 6b9cc18e71..c887fbe379 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import static com.oracle.graal.python.nodes.ErrorMessages.EXPECTED_S_NOT_P;
import static com.oracle.graal.python.nodes.ErrorMessages.NATIVE_S_SUBTYPES_NOT_IMPLEMENTED;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.FrozenSetNode;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
@@ -79,7 +80,7 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.truffle.PythonTypes;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -96,13 +97,13 @@ abstract static class PySet_New extends CApiUnaryBuiltinNode {
@Specialization(guards = {"!isNone(iterable)", "!isNoValue(iterable)"})
static Object newSet(Object iterable,
@Cached ConstructSetNode constructSetNode) {
- return constructSetNode.executeWith(null, iterable);
+ return constructSetNode.execute(null, iterable);
}
@Specialization
static Object newSet(@SuppressWarnings("unused") PNone iterable,
- @Cached PythonObjectFactory factory) {
- return factory.createSet();
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language);
}
}
@@ -143,9 +144,8 @@ static Object nextEntry(PSet set, long pos,
@Shared @Cached HashingStorageIteratorNext itNext,
@Shared @Cached HashingStorageIteratorKey itKey,
@Shared @Cached HashingStorageIteratorKeyHash itKeyHash,
- @Shared @Cached InlinedLoopConditionProfile loopProfile,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
- return next(inliningTarget, (int) pos, set.getDictStorage(), getIterator, itNext, itKey, itKeyHash, loopProfile, factory);
+ @Shared @Cached InlinedLoopConditionProfile loopProfile) {
+ return next(inliningTarget, (int) pos, set.getDictStorage(), getIterator, itNext, itKey, itKeyHash, loopProfile);
}
@Specialization(guards = "pos < size(inliningTarget, set, sizeNode)")
@@ -156,9 +156,8 @@ static Object nextEntry(PFrozenSet set, long pos,
@Shared @Cached HashingStorageIteratorNext itNext,
@Shared @Cached HashingStorageIteratorKey itKey,
@Shared @Cached HashingStorageIteratorKeyHash itKeyHash,
- @Shared @Cached InlinedLoopConditionProfile loopProfile,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
- return next(inliningTarget, (int) pos, set.getDictStorage(), getIterator, itNext, itKey, itKeyHash, loopProfile, factory);
+ @Shared @Cached InlinedLoopConditionProfile loopProfile) {
+ return next(inliningTarget, (int) pos, set.getDictStorage(), getIterator, itNext, itKey, itKeyHash, loopProfile);
}
@Specialization(guards = {"isPSet(set) || isPFrozenSet(set)", "pos >= size(inliningTarget, set, sizeNode)"})
@@ -198,7 +197,7 @@ protected int size(Node inliningTarget, Object set, PyObjectSizeNode sizeNode) {
private static Object next(Node inliningTarget, int pos, HashingStorage storage, HashingStorageGetIterator getIterator,
HashingStorageIteratorNext itNext, HashingStorageIteratorKey itKey, HashingStorageIteratorKeyHash itKeyHash,
- InlinedLoopConditionProfile loopProfile, PythonObjectFactory.Lazy factory) {
+ InlinedLoopConditionProfile loopProfile) {
HashingStorageIterator it = getIterator.execute(inliningTarget, storage);
loopProfile.profileCounted(inliningTarget, pos);
for (int i = 0; loopProfile.inject(inliningTarget, i <= pos); i++) {
@@ -208,7 +207,7 @@ private static Object next(Node inliningTarget, int pos, HashingStorage storage,
}
Object key = itKey.execute(inliningTarget, storage, it);
long hash = itKeyHash.execute(null, inliningTarget, storage, it);
- return factory.get(inliningTarget).createTuple(new Object[]{key, hash});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{key, hash});
}
}
@@ -237,8 +236,8 @@ static Object newFrozenSet(Object iterable,
@SuppressWarnings("unused")
@Specialization
static Object newFrozenSet(PNone iterable,
- @Cached PythonObjectFactory factory) {
- return factory.createFrozenSet(PythonBuiltinClassType.PFrozenSet);
+ @Bind PythonLanguage language) {
+ return PFactory.createFrozenSet(language);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
index 3e8a392940..19fd093562 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -68,6 +68,7 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.tuple.StructSequence;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.BuiltinNames;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -76,7 +77,8 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -136,10 +138,10 @@ Object doGeneric(TruffleString typeName, TruffleString typeDoc, Object fields, i
@Cached ReadAttributeFromObjectNode readTypeBuiltinNode,
@CachedLibrary(limit = "1") DynamicObjectLibrary dylib,
@Cached CallNode callTypeNewNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object typeBuiltin = readTypeBuiltinNode.execute(getCore().getBuiltins(), BuiltinNames.T_TYPE);
- PTuple bases = factory.createTuple(new Object[]{PythonBuiltinClassType.PTuple});
- PDict namespace = factory.createDict(new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, typeDoc)});
+ PTuple bases = PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PTuple});
+ PDict namespace = PFactory.createDict(language, new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, typeDoc)});
Object cls = callTypeNewNode.executeWithoutFrame(typeBuiltin, typeName, bases, namespace);
initNode.execute(cls, fields, nInSequence);
if (cls instanceof PythonClass) {
@@ -157,7 +159,8 @@ static Object doGeneric(Object cls,
@Bind("this") Node inliningTarget,
@Cached("createForceType()") ReadAttributeFromObjectNode readRealSizeNode,
@Cached CastToJavaIntExactNode castToIntNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
try {
Object realSizeObj = readRealSizeNode.execute(cls, StructSequence.T_N_FIELDS);
@@ -167,7 +170,7 @@ static Object doGeneric(Object cls,
int realSize = castToIntNode.execute(inliningTarget, realSizeObj);
Object[] values = new Object[realSize];
Arrays.fill(values, PNone.NO_VALUE); // Initialize to C NULL
- return factory.createTuple(cls, values);
+ return PFactory.createTuple(language, cls, getInstanceShape.execute(cls), new ObjectSequenceStorage(values));
}
} catch (CannotCastException e) {
throw CompilerDirectives.shouldNotReachHere("attribute 'n_fields' is expected to be a Java int");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTracebackBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTracebackBuiltins.java
index ada7ed0b0c..556612a663 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTracebackBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTracebackBuiltins.java
@@ -46,6 +46,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyFrameObject;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Void;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiTernaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
@@ -56,7 +57,7 @@
import com.oracle.graal.python.builtins.objects.traceback.MaterializeLazyTracebackNode;
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
@@ -72,8 +73,8 @@ abstract static class _PyTraceback_Add extends CApiTernaryBuiltinNode {
static Object tbHere(TruffleString funcname, TruffleString filename, int lineno,
@Cached PyCode_NewEmpty newCode,
@Cached PyTraceBack_Here pyTraceBackHereNode,
- @Cached PythonObjectFactory factory) {
- PFrame frame = factory.createPFrame(null, newCode.execute(filename, funcname, lineno), factory.createDict(), factory.createDict());
+ @Bind PythonLanguage language) {
+ PFrame frame = PFactory.createPFrame(language, null, newCode.execute(filename, funcname, lineno), PFactory.createDict(language), PFactory.createDict(language));
pyTraceBackHereNode.execute(frame);
return PNone.NONE;
}
@@ -85,8 +86,7 @@ abstract static class PyTraceBack_Here extends CApiUnaryBuiltinNode {
static int tbHere(PFrame frame,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
- @Cached MaterializeLazyTracebackNode materializeLazyTracebackNode,
- @Cached PythonObjectFactory factory) {
+ @Cached MaterializeLazyTracebackNode materializeLazyTracebackNode) {
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
AbstractTruffleException currentException = threadState.getCurrentException();
if (currentException != null) {
@@ -94,7 +94,7 @@ static int tbHere(PFrame frame,
if (threadState.getCurrentTraceback() != null) {
currentTraceback = materializeLazyTracebackNode.execute(inliningTarget, threadState.getCurrentTraceback());
}
- PTraceback newTraceback = factory.createTraceback(frame, frame.getLine(), currentTraceback);
+ PTraceback newTraceback = PFactory.createTraceback(PythonLanguage.get(inliningTarget), frame, frame.getLine(), currentTraceback);
threadState.setCurrentTraceback(new LazyTraceback(newTraceback));
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
index b1ae9aa248..94356e0df5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_ssize_t;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
@@ -68,7 +69,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.builtins.TupleNodes.GetNativeTupleStorage;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
@@ -86,7 +87,7 @@ abstract static class PyTuple_New extends CApiUnaryBuiltinNode {
@Specialization
static PTuple doGeneric(long longSize,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode,
@Cached CStructAccess.AllocateNode alloc) {
int size = (int) longSize;
@@ -99,7 +100,7 @@ static PTuple doGeneric(long longSize,
*/
Object mem = alloc.alloc((longSize + 1) * CStructAccess.POINTER_SIZE);
NativeObjectSequenceStorage storage = NativeObjectSequenceStorage.create(mem, size, size, true);
- return factory.createTuple(storage);
+ return PFactory.createTuple(language, storage);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
index 2d0d418396..d7cc998246 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
@@ -103,7 +103,7 @@
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
import com.oracle.graal.python.util.Function;
import com.oracle.graal.python.util.PythonUtils;
@@ -190,7 +190,7 @@ abstract static class PyTruffle_Compute_Mro extends CApiBinaryBuiltinNode {
@TruffleBoundary
static Object doIt(PythonNativeClass self, TruffleString className) {
PythonAbstractClass[] doSlowPath = TypeNodes.ComputeMroNode.doSlowPath(self);
- return PythonObjectFactory.getUncached().createTuple(new MroSequenceStorage(className, doSlowPath));
+ return PFactory.createTuple(PythonLanguage.get(null), new MroSequenceStorage(className, doSlowPath));
}
}
@@ -208,7 +208,7 @@ abstract static class PyTruffle_NewTypeDict extends CApiUnaryBuiltinNode {
static PDict doGeneric(PythonNativeClass nativeClass) {
PythonLanguage language = PythonLanguage.get(null);
NativeTypeDictStorage nativeTypeStore = new NativeTypeDictStorage(language.getEmptyShape());
- PDict dict = PythonObjectFactory.getUncached().createDict(new DynamicObjectStorage(nativeTypeStore));
+ PDict dict = PFactory.createDict(language, new DynamicObjectStorage(nativeTypeStore));
HiddenAttr.WriteNode.executeUncached(dict, HiddenAttr.INSTANCESHAPE, language.getShapeForClass(nativeClass));
return dict;
}
@@ -269,7 +269,7 @@ abstract static class NewClassMethodNode extends Node {
@Specialization(guards = "isClassOrStaticMethod(flags)")
static Object classOrStatic(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, int flags, int wrapper, Object type, Object doc,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached HiddenAttr.WriteNode writeHiddenAttrNode,
@Cached(inline = false) WriteAttributeToPythonObjectNode writeAttrNode,
@Exclusive @Cached CreateFunctionNode createFunctionNode) {
@@ -277,9 +277,9 @@ static Object classOrStatic(Node inliningTarget, Object methodDefPtr, TruffleStr
writeHiddenAttrNode.execute(inliningTarget, func, METHOD_DEF_PTR, methodDefPtr);
PythonObject function;
if ((flags & METH_CLASS) != 0) {
- function = factory.createClassmethodFromCallableObj(func);
+ function = PFactory.createClassmethodFromCallableObj(language, func);
} else {
- function = factory.createStaticmethodFromCallableObj(func);
+ function = PFactory.createStaticmethodFromCallableObj(language, func);
}
writeAttrNode.execute(function, T___NAME__, name);
writeAttrNode.execute(function, T___DOC__, doc);
@@ -358,7 +358,7 @@ public static int addMember(Object clazz, PDict tpDict, TruffleString memberName
}
// create member descriptor
- GetSetDescriptor memberDescriptor = PythonObjectFactory.getUncached().createMemberDescriptor(getterObject, setterObject, memberName, clazz);
+ GetSetDescriptor memberDescriptor = PFactory.createMemberDescriptor(language, getterObject, setterObject, memberName, clazz);
WriteAttributeToPythonObjectNode.getUncached().execute(memberDescriptor, SpecialAttributeNames.T___DOC__, memberDoc);
// add member descriptor to tp_dict
@@ -376,7 +376,6 @@ abstract static class CreateGetSetNode extends Node {
@Specialization
@TruffleBoundary
static GetSetDescriptor createGetSet(Node inliningTarget, TruffleString name, Object cls, Object getter, Object setter, Object doc, Object closure,
- @Cached(inline = false) PythonObjectFactory factory,
@CachedLibrary(limit = "2") InteropLibrary interopLibrary) {
assert !(doc instanceof CArrayWrapper);
// note: 'doc' may be NULL; in this case, we would store 'None'
@@ -385,7 +384,7 @@ static GetSetDescriptor createGetSet(Node inliningTarget, TruffleString name, Ob
if (!interopLibrary.isNull(getter)) {
RootCallTarget getterCT = getterCallTarget(name, language);
getter = EnsureExecutableNode.executeUncached(getter, PExternalFunctionWrapper.GETTER);
- get = factory.createBuiltinFunction(name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(getter, closure), 0, getterCT);
+ get = PFactory.createBuiltinFunction(language, name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(getter, closure), 0, getterCT);
}
PBuiltinFunction set = null;
@@ -393,11 +392,11 @@ static GetSetDescriptor createGetSet(Node inliningTarget, TruffleString name, Ob
if (hasSetter) {
RootCallTarget setterCT = setterCallTarget(name, language);
setter = EnsureExecutableNode.executeUncached(setter, PExternalFunctionWrapper.SETTER);
- set = factory.createBuiltinFunction(name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(setter, closure), 0, setterCT);
+ set = PFactory.createBuiltinFunction(language, name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(setter, closure), 0, setterCT);
}
// create get-set descriptor
- GetSetDescriptor descriptor = factory.createGetSetDescriptor(get, set, name, cls, hasSetter);
+ GetSetDescriptor descriptor = PFactory.createGetSetDescriptor(language, get, set, name, cls, hasSetter);
WriteAttributeToPythonObjectNode.executeUncached(descriptor, T___DOC__, doc);
return descriptor;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
index a5b8e9a05d..4dbf93ba44 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
@@ -84,6 +84,7 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.ChrNode;
@@ -103,6 +104,7 @@
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
+import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.UnicodeFromFormatNode;
import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.UnicodeObjectNodes.UnicodeAsWideCharNode;
@@ -149,7 +151,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -316,8 +318,7 @@ static Object withPString(PString str,
@Cached StringNodes.IsInternedStringNode isInternedStringNode,
@Cached StringNodes.InternStringNode internNode,
@Cached HashingStorageGetItem getItem,
- @Cached HashingStorageSetItem setItem,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached HashingStorageSetItem setItem) {
if (!unicodeCheckExactNode.execute(inliningTarget, str)) {
return getNativeNull(inliningTarget);
}
@@ -330,10 +331,11 @@ static Object withPString(PString str,
return str;
}
TruffleString ts = cast.execute(inliningTarget, str);
- PDict dict = getCApiContext(inliningTarget).getInternedUnicode();
+ CApiContext cApiContext = getCApiContext(inliningTarget);
+ PDict dict = cApiContext.getInternedUnicode();
if (dict == null) {
- dict = factory.get(inliningTarget).createDict();
- getCApiContext(inliningTarget).setInternedUnicode(dict);
+ dict = PFactory.createDict(cApiContext.getContext().getLanguage(internNode));
+ cApiContext.setInternedUnicode(dict);
}
Object interned = getItem.execute(inliningTarget, dict.getDictStorage(), ts);
if (interned == null) {
@@ -692,8 +694,8 @@ static int doGeneric(Object type, long lindex,
abstract static class PyTruffleUnicode_New extends CApiQuaternaryBuiltinNode {
@Specialization
static Object doGeneric(Object ptr, long elements, long elementSize, int isAscii,
- @Cached PythonObjectFactory factory) {
- return factory.createString(new NativeCharSequence(ptr, (int) elements, (int) elementSize, isAscii != 0));
+ @Bind PythonLanguage language) {
+ return PFactory.createString(language, new NativeCharSequence(ptr, (int) elements, (int) elementSize, isAscii != 0));
}
}
@@ -709,17 +711,12 @@ private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNo
};
}
- private static PString asPString(TruffleString ts, SwitchEncodingNode switchEncodingNode, PythonObjectFactory factory) {
- return factory.createString(switchEncodingNode.execute(ts, TS_ENCODING));
- }
-
@Specialization(guards = "ptrLib.isPointer(ptr)")
static Object doNative(Object ptr, long byteLength, int kind,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared("ptrLib") @CachedLibrary(limit = "1") InteropLibrary ptrLib,
@Cached FromNativePointerNode fromNativePointerNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
int iByteLength = PInt.intValueExact(byteLength);
@@ -730,7 +727,7 @@ static Object doNative(Object ptr, long byteLength, int kind,
* For now, we use ISO-8859-1 and UTF-16 but that's not entirely correct.
*/
TruffleString ts = fromNativePointerNode.execute(ptr, 0, iByteLength, srcEncoding, true);
- return asPString(ts, switchEncodingNode, factory);
+ return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(MemoryError);
}
@@ -743,13 +740,12 @@ static Object doManaged(Object ptr, long byteLength, int kind,
@Cached GetByteArrayNode getByteArrayNode,
@Cached FromByteArrayNode fromByteArrayNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
byte[] ucsBytes = getByteArrayNode.execute(inliningTarget, ptr, byteLength);
TruffleString ts = fromByteArrayNode.execute(ucsBytes, srcEncoding);
- return asPString(ts, switchEncodingNode, factory);
+ return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (InteropException e) {
/*
* This means that we cannot read the array-like foreign object or the foreign
@@ -774,23 +770,18 @@ private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNo
};
}
- private static PString asPString(TruffleString ts, SwitchEncodingNode switchEncodingNode, PythonObjectFactory factory) {
- return factory.createString(switchEncodingNode.execute(ts, TS_ENCODING));
- }
-
@Specialization(guards = "ptrLib.isPointer(ptr)")
static Object doNative(Object ptr, long byteLength, int kind,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared("ptrLib") @CachedLibrary(limit = "1") InteropLibrary ptrLib,
@Cached FromNativePointerNode fromNativePointerNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
int iByteLength = PInt.intValueExact(byteLength);
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
TruffleString ts = fromNativePointerNode.execute(ptr, 0, iByteLength, srcEncoding, true);
- return asPString(ts, switchEncodingNode, factory);
+ return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(MemoryError);
}
@@ -803,13 +794,12 @@ static Object doManaged(Object ptr, long byteLength, int kind,
@Cached GetByteArrayNode getByteArrayNode,
@Cached FromByteArrayNode fromByteArrayNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
byte[] ucsBytes = getByteArrayNode.execute(inliningTarget, ptr, byteLength);
TruffleString ts = fromByteArrayNode.execute(ucsBytes, srcEncoding);
- return asPString(ts, switchEncodingNode, factory);
+ return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (InteropException e) {
/*
* This means that we cannot read the array-like foreign object or the foreign
@@ -826,8 +816,8 @@ static Object doManaged(Object ptr, long byteLength, int kind,
abstract static class PyUnicode_FromString extends CApiUnaryBuiltinNode {
@Specialization
static PString run(TruffleString str,
- @Cached PythonObjectFactory factory) {
- return factory.createString(str);
+ @Bind PythonLanguage language) {
+ return PFactory.createString(language, str);
}
@Specialization
@@ -859,12 +849,12 @@ abstract static class PyTruffleUnicode_DecodeUTF8Stateful extends CApiQuaternary
@Specialization
static Object doUtf8Decode(Object cByteArray, long size, TruffleString errors, int reportConsumed,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- PBytes bytes = factory.createBytes(getByteArrayNode.execute(inliningTarget, cByteArray, size));
+ PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
return decode.call(null, bytes, T_UTF8, errors, reportConsumed == 0);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
@@ -880,12 +870,12 @@ abstract static class PyTruffleUnicode_DecodeUTF16Stateful extends CApi5BuiltinN
@Specialization
static Object decode(Object cByteArray, long size, TruffleString errors, int byteorder, int reportConsumed,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- PBytes bytes = factory.createBytes(getByteArrayNode.execute(inliningTarget, cByteArray, size));
+ PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
TruffleString encoding;
if (byteorder == 0) {
encoding = T_UTF_16;
@@ -909,12 +899,12 @@ abstract static class PyTruffleUnicode_DecodeUTF32Stateful extends CApi5BuiltinN
@Specialization
static Object decode(Object cByteArray, long size, TruffleString errors, int byteorder, int reportConsumed,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- PBytes bytes = factory.createBytes(getByteArrayNode.execute(inliningTarget, cByteArray, size));
+ PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
TruffleString encoding;
if (byteorder == 0) {
encoding = T_UTF_32;
@@ -948,10 +938,9 @@ abstract static class PyUnicode_EncodeFSDefault extends CApiUnaryBuiltinNode {
static PBytes fromObject(Object s,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castStr,
- @Cached EncodeNativeStringNode encode,
- @Cached PythonObjectFactory factory) {
+ @Cached EncodeNativeStringNode encode) {
byte[] array = encode.execute(StandardCharsets.UTF_8, castStr.execute(inliningTarget, s), T_REPLACE);
- return factory.createBytes(array);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), array);
}
}
@@ -973,10 +962,9 @@ abstract static class PyUnicode_FromWideChar extends CApiBinaryBuiltinNode {
Object doInt(Object arr, long size,
@Bind("this") Node inliningTarget,
@Cached ReadUnicodeArrayNode readArray,
- @Cached TruffleString.FromIntArrayUTF32Node fromArray,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.FromIntArrayUTF32Node fromArray) {
assert TS_ENCODING == Encoding.UTF_32 : "needs switch_encoding otherwise";
- return factory.createString(fromArray.execute(readArray.execute(inliningTarget, arr, castToInt(size), CStructs.wchar_t.size())));
+ return PFactory.createString(PythonLanguage.get(inliningTarget), fromArray.execute(readArray.execute(inliningTarget, arr, castToInt(size), CStructs.wchar_t.size())));
}
}
@@ -989,16 +977,14 @@ protected NativeEncoderNode(Charset charset) {
@Specialization(guards = "isNoValue(errors)")
Object doUnicode(Object s, @SuppressWarnings("unused") PNone errors,
- @Shared("encodeNode") @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Shared @Cached PythonObjectFactory factory) {
- return doUnicode(s, T_STRICT, encodeNativeStringNode, factory);
+ @Shared("encodeNode") @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return doUnicode(s, T_STRICT, encodeNativeStringNode);
}
@Specialization
Object doUnicode(Object s, TruffleString errors,
- @Shared("encodeNode") @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeNativeStringNode.execute(charset, s, errors));
+ @Shared("encodeNode") @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return PFactory.createBytes(PythonLanguage.get(this), encodeNativeStringNode.execute(charset, s, errors));
}
@Fallback
@@ -1194,11 +1180,10 @@ static Object doit(Object encoding, Object object, long length, long start, long
@Bind("this") Node inliningTarget,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CallNode callNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
PBytes bytes;
try {
- bytes = factory.createBytes(getByteArrayNode.execute(inliningTarget, object, length));
+ bytes = PFactory.createBytes(PythonLanguage.get(inliningTarget), getByteArrayNode.execute(inliningTarget, object, length));
} catch (InteropException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
index 0b9fb8aaaf..2a7e28741d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -103,15 +104,15 @@ public void initialize(Python3Core core) {
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_CN);
- registerCodec("gb2312", 0, CodecType.STATELESS, 0, MappingType.DECONLY, MAPPING_LIST, CODEC_LIST, codec, factory);
- registerCodec("gbk", 1, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("gb18030", 2, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("hz", 3, CodecType.STATEFUL, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("gbkext", -1, null, 1, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("gbcommon", -1, null, 2, MappingType.ENCONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("gb18030ext", -1, null, 3, MappingType.ENCDEC, MAPPING_LIST, null, codec, factory);
+ registerCodec("gb2312", 0, CodecType.STATELESS, 0, MappingType.DECONLY, MAPPING_LIST, CODEC_LIST, codec, language);
+ registerCodec("gbk", 1, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("gb18030", 2, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("hz", 3, CodecType.STATEFUL, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("gbkext", -1, null, 1, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("gbcommon", -1, null, 2, MappingType.ENCONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("gb18030ext", -1, null, 3, MappingType.ENCDEC, MAPPING_LIST, null, codec, language);
}
@Builtin(name = "getcodec", minNumOfPositionalArgs = 1)
@@ -124,7 +125,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -136,8 +137,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
index 59f6e9f429..79329e4033 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -99,11 +100,11 @@ public void initialize(Python3Core core) {
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_HK);
- registerCodec("big5hkscs", 0, CodecType.STATELESS_WINIT, 0, MappingType.DECONLY, MAPPING_LIST, CODEC_LIST, codec, factory);
- registerCodec("big5hkscs_bmp", -1, null, 1, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, factory);
- registerCodec("big5hkscs_nonbmp", -1, null, 2, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, factory);
+ registerCodec("big5hkscs", 0, CodecType.STATELESS_WINIT, 0, MappingType.DECONLY, MAPPING_LIST, CODEC_LIST, codec, language);
+ registerCodec("big5hkscs_bmp", -1, null, 1, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, language);
+ registerCodec("big5hkscs_nonbmp", -1, null, 2, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, language);
}
@Builtin(name = "getcodec", minNumOfPositionalArgs = 1)
@@ -116,7 +117,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -128,8 +129,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
index 883ea00440..fdf58b9d1e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -65,7 +66,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -99,16 +100,16 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_ISO2022);
int i = 0;
- registerCodec("iso2022_kr", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp_1", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp_2", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp_2004", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp_3", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("iso2022_jp_ext", i, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, factory);
+ registerCodec("iso2022_kr", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp_1", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp_2", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp_2004", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp_3", i++, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("iso2022_jp_ext", i, CodecType.ISO2022, -1, null, null, CODEC_LIST, codec, language);
}
@Override
@@ -126,7 +127,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -138,8 +139,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
index 4d1e9d09a1..7555de5d80 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -108,29 +109,29 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_JP);
int i = 0;
- registerCodec("shift_jis", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("cp932", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("euc_jp", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("shift_jis_2004", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("euc_jis_2004", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("euc_jisx0213", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("shift_jisx0213", i, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
+ registerCodec("shift_jis", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("cp932", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("euc_jp", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("shift_jis_2004", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("euc_jis_2004", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("euc_jisx0213", i++, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("shift_jisx0213", i, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
i = 0;
- registerCodec("jisx0208", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0212", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisxcommon", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_1_bmp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_2_bmp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_bmp", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_1_emp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_2_emp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_emp", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("jisx0213_pair", -1, null, i++, MappingType.ENCDEC, MAPPING_LIST, null, codec, factory);
- registerCodec("cp932ext", -1, null, i, MappingType.ENCDEC, MAPPING_LIST, null, codec, factory);
+ registerCodec("jisx0208", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0212", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisxcommon", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_1_bmp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_2_bmp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_bmp", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_1_emp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_2_emp", -1, null, i++, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_emp", -1, null, i++, MappingType.ENCONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("jisx0213_pair", -1, null, i++, MappingType.ENCDEC, MAPPING_LIST, null, codec, language);
+ registerCodec("cp932ext", -1, null, i, MappingType.ENCDEC, MAPPING_LIST, null, codec, language);
}
@Override
@@ -148,7 +149,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -160,8 +161,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
index 70d50acc4e..25f99a0321 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -96,14 +97,14 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_KR);
- registerCodec("euc_kr", 0, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("cp949", 1, CodecType.STATELESS, 1, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, factory);
- registerCodec("johab", 2, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
+ registerCodec("euc_kr", 0, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("cp949", 1, CodecType.STATELESS, 1, MappingType.ENCONLY, MAPPING_LIST, CODEC_LIST, codec, language);
+ registerCodec("johab", 2, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
- registerCodec("ksx1001", -1, null, 0, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
- registerCodec("cp949ext", -1, null, 2, MappingType.DECONLY, MAPPING_LIST, null, codec, factory);
+ registerCodec("ksx1001", -1, null, 0, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
+ registerCodec("cp949ext", -1, null, 2, MappingType.DECONLY, MAPPING_LIST, null, codec, language);
}
@Override
@@ -121,7 +122,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -133,8 +134,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
index 0f82419396..8a71f69d73 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -94,11 +95,11 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule codec = core.lookupBuiltinModule(T__CODECS_TW);
- registerCodec("big5", 0, CodecType.STATELESS, 0, MappingType.ENCDEC, MAPPING_LIST, CODEC_LIST, codec, factory);
- registerCodec("cp950", 1, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, factory);
- registerCodec("cp950ext", -1, null, 1, MappingType.ENCDEC, MAPPING_LIST, null, codec, factory);
+ registerCodec("big5", 0, CodecType.STATELESS, 0, MappingType.ENCDEC, MAPPING_LIST, CODEC_LIST, codec, language);
+ registerCodec("cp950", 1, CodecType.STATELESS, -1, null, null, CODEC_LIST, codec, language);
+ registerCodec("cp950ext", -1, null, 1, MappingType.ENCDEC, MAPPING_LIST, null, codec, language);
}
@Override
@@ -116,7 +117,7 @@ static Object getcodec(Object encoding,
@Cached TruffleString.EqualNode isEqual,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
@@ -128,8 +129,8 @@ static Object getcodec(Object encoding,
throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
- PyCapsule codecobj = factory.createCapsuleJavaName(codec, PyMultibyteCodec_CAPSULE_NAME);
- return createCodec(inliningTarget, codecobj, factory, raiseNode);
+ PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
+ return createCodec(inliningTarget, codecobj, raiseNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
index 6995a40711..126804b23c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -64,7 +65,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -119,16 +120,16 @@ static Object ts(VirtualFrame frame, MultibyteCodecObject self, TruffleString uc
@Exclusive @Cached MultibyteCodecUtil.EncodeNode encodeNode,
@Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared @Cached TruffleString.EqualNode isEqual,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
TruffleString errorcb = internalErrorCallback(errors, isEqual);
MultibyteCodecState state = self.codec.encinit(errorcb);
int datalen = codePointLengthNode.execute(ucvt, TS_ENCODING);
- PBytes r = encodeEmptyInput(datalen, MBENC_FLUSH | MBENC_RESET, factory);
+ PBytes r = encodeEmptyInput(inliningTarget, datalen, MBENC_FLUSH | MBENC_RESET);
if (r == null) {
MultibyteEncodeBuffer buf = new MultibyteEncodeBuffer(ucvt);
- r = encodeNode.execute(frame, inliningTarget, self.codec, state, buf, errorcb, MBENC_FLUSH | MBENC_RESET, factory);
+ r = encodeNode.execute(frame, inliningTarget, self.codec, state, buf, errorcb, MBENC_FLUSH | MBENC_RESET);
}
- return factory.createTuple(new Object[]{r, datalen});
+ return PFactory.createTuple(language, new Object[]{r, datalen});
}
@Specialization(guards = "!isTruffleString(input)")
@@ -140,7 +141,7 @@ static Object notTS(VirtualFrame frame, MultibyteCodecObject self, Object input,
@Exclusive @Cached MultibyteCodecUtil.EncodeNode encodeNode,
@Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared @Cached TruffleString.EqualNode isEqual,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object ucvt = input;
if (!unicodeCheck.execute(inliningTarget, input)) {
@@ -151,7 +152,7 @@ static Object notTS(VirtualFrame frame, MultibyteCodecObject self, Object input,
}
TruffleString str = toTruffleStringNode.execute(inliningTarget, ucvt);
- return ts(frame, self, str, errors, inliningTarget, encodeNode, codePointLengthNode, isEqual, factory);
+ return ts(frame, self, str, errors, inliningTarget, encodeNode, codePointLengthNode, isEqual, language);
}
}
@@ -186,13 +187,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
Object decode(VirtualFrame frame, MultibyteCodecObject self, byte[] input, TruffleString errors,
@Cached MultibyteCodecUtil.DecodeErrorNode decodeErrorNode,
@Cached TruffleString.EqualNode isEqual,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int datalen = input.length;
TruffleString errorcb = internalErrorCallback(errors, isEqual);
if (datalen == 0) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, 0});
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, 0});
}
MultibyteDecodeBuffer buf = new MultibyteDecodeBuffer(input);
MultibyteCodecState state = self.codec.decinit(errorcb);
@@ -205,7 +206,7 @@ Object decode(VirtualFrame frame, MultibyteCodecObject self, byte[] input, Truff
}
}
- return factory.createTuple(new Object[]{buf.toTString(), datalen});
+ return PFactory.createTuple(language, new Object[]{buf.toTString(), datalen});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
index b48118e590..207f24926a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,6 +71,7 @@
import java.nio.CharBuffer;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.codecs.CodecsRegistry.PyCodecLookupErrorNode;
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -86,7 +87,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -170,7 +171,7 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
MultibyteCodecState state,
MultibyteEncodeBuffer buf, Object errors, int e,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached BaseExceptionAttrNode attrNode,
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getArray,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@@ -233,10 +234,10 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
/* use cached exception object if available */
if (buf.excobj == null) {
- buf.excobj = factory.createBaseException(UnicodeEncodeError);
+ buf.excobj = PFactory.createBaseException(language, UnicodeEncodeError);
TruffleString encoding = codec.encoding;
Object[] args = new Object[]{encoding, buf.toTString(), start, end, reason};
- buf.excobj.setArgs(factory.createTuple(args));
+ buf.excobj.setArgs(PFactory.createTuple(language, args));
buf.excobj.setExceptionAttributes(args);
} else {
attrNode.execute(buf.excobj, start, IDX_START, UNICODE_ERROR_ATTR_FACTORY);
@@ -277,11 +278,10 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
if (isUnicode) {
TruffleString str = toTString.execute(inliningTarget, tobj);
int datalen = codePointLengthNode.execute(str, TS_ENCODING);
- retstr = encodeEmptyInput(datalen, MBENC_FLUSH, factory);
+ retstr = encodeEmptyInput(inliningTarget, datalen, MBENC_FLUSH);
if (retstr == null) {
MultibyteEncodeBuffer tmpbuf = new MultibyteEncodeBuffer(str);
- retstr = encodeNode.execute(frame, inliningTarget, codec, state, tmpbuf, ERROR_STRICT, MBENC_FLUSH,
- factory);
+ retstr = encodeNode.execute(frame, inliningTarget, codec, state, tmpbuf, ERROR_STRICT, MBENC_FLUSH);
}
} else {
retstr = (PBytes) tobj;
@@ -326,7 +326,7 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
// MultibyteCodecState state,
MultibyteDecodeBuffer buf, TruffleString errors, int e,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached BaseExceptionAttrNode attrNode,
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getArray,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@@ -368,11 +368,11 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
/* use cached exception object if available */
if (buf.excobj == null) {
- buf.excobj = factory.createBaseException(UnicodeDecodeError);
- PBytes inbuf = buf.createPBytes(factory);
+ buf.excobj = PFactory.createBaseException(language, UnicodeDecodeError);
+ PBytes inbuf = PFactory.createBytes(language, buf.inputBuffer.array(), buf.getInpos());
TruffleString encoding = codec.encoding;
Object[] args = new Object[]{encoding, inbuf, buf.getInpos(), start, end, reason};
- buf.excobj.setArgs(factory.createTuple(args));
+ buf.excobj.setArgs(PFactory.createTuple(language, args));
buf.excobj.setExceptionAttributes(args);
} else {
attrNode.execute(buf.excobj, start, IDX_START, UNICODE_ERROR_ATTR_FACTORY);
@@ -426,10 +426,9 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
}
}
- protected static PBytes encodeEmptyInput(int len, int flags,
- PythonObjectFactory factory) {
+ protected static PBytes encodeEmptyInput(Node inliningTarget, int len, int flags) {
if (len == 0 && (flags & MBENC_RESET) == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(PythonLanguage.get(inliningTarget));
}
return null;
}
@@ -438,18 +437,16 @@ protected static PBytes encodeEmptyInput(int len, int flags,
@GenerateCached(false)
abstract static class EncodeNode extends Node {
- abstract PBytes execute(VirtualFrame frame, Node inliningTarget, MultibyteCodec codec, MultibyteCodecState state, MultibyteEncodeBuffer buf, Object errors, int flags,
- PythonObjectFactory factory);
+ abstract PBytes execute(VirtualFrame frame, Node inliningTarget, MultibyteCodec codec, MultibyteCodecState state, MultibyteEncodeBuffer buf, Object errors, int flags);
// multibytecodec_encode
@Specialization
static PBytes encode(VirtualFrame frame, Node inliningTarget, MultibyteCodec codec, MultibyteCodecState state, MultibyteEncodeBuffer buf, Object errors, int flags,
- PythonObjectFactory factory,
@Cached(inline = false) EncodeErrorNode encodeErrorNode,
@Cached PRaiseNode.Lazy raiseNode) {
// if (buf.inlen == 0 && (flags & MBENC_RESET) == 0) {
- // return factory.createBytes(EMPTY_BYTE_ARRAY);
+ // return PFactory.createBytes(language, EMPTY_BYTE_ARRAY);
// }
if (buf.getInlen() > (MAXSIZE - 16) / 2) {
@@ -486,7 +483,7 @@ static PBytes encode(VirtualFrame frame, Node inliningTarget, MultibyteCodec cod
}
}
- return buf.createPBytes(factory);
+ return buf.createPBytes();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
index 20edfb8590..94672160ec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,10 +48,8 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -102,10 +100,6 @@ protected boolean isFull() {
return !inputBuffer.hasRemaining();
}
- protected PBytes createPBytes(PythonObjectFactory factory) {
- return factory.createBytes(inputBuffer.array(), getInpos());
- }
-
@TruffleBoundary
protected void replaceInbuf(byte[] inbuf) {
inputBuffer = ByteBuffer.wrap(inbuf);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
index 39e1b48d56..34f298cf23 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,10 +46,11 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -138,8 +139,8 @@ protected void expandOutputBuffer(int esize, Node raisingNode) {
}
@TruffleBoundary
- protected PBytes createPBytes(PythonObjectFactory factory) {
- outobj = factory.createBytes(outputBuffer.array(), outputBuffer.position());
+ protected PBytes createPBytes() {
+ outobj = PFactory.createBytes(PythonLanguage.get(null), outputBuffer.array(), outputBuffer.position());
return outobj;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
index 236c749107..8e471c805d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -54,9 +54,11 @@
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.UnicodeError;
+import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -67,6 +69,7 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -79,7 +82,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -108,14 +111,15 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyObjectGetAttr getAttr,
@Cached TruffleString.EqualNode isEqual,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) { // "|s:IncrementalDecoder"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
errors = castToStringNode.execute(inliningTarget, err);
}
- MultibyteIncrementalDecoderObject self = factory.createMultibyteIncrementalDecoderObject(type);
+ MultibyteIncrementalDecoderObject self = PFactory.createMultibyteIncrementalDecoderObject(language, type, getInstanceShape.execute(type));
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
@@ -240,12 +244,12 @@ abstract static class GetStateNode extends PythonUnaryBuiltinNode {
@Specialization
static Object getstate(MultibyteIncrementalDecoderObject self,
@Bind("this") Node inliningTarget,
- @Cached HiddenAttr.WriteNode writeHiddenAttrNode,
- @Cached PythonObjectFactory factory) {
- PBytes buffer = factory.createBytes(Arrays.copyOf(self.pending, self.pendingsize));
- PInt statelong = factory.createInt(0);
+ @Bind PythonLanguage language,
+ @Cached HiddenAttr.WriteNode writeHiddenAttrNode) {
+ PBytes buffer = PFactory.createBytes(language, Arrays.copyOf(self.pending, self.pendingsize));
+ PInt statelong = PFactory.createInt(language, BigInteger.ZERO);
writeHiddenAttrNode.execute(inliningTarget, statelong, HiddenAttr.DECODER_OBJECT, self.state);
- return factory.createTuple(new Object[]{buffer, statelong});
+ return PFactory.createTuple(language, new Object[]{buffer, statelong});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
index 8b13e3d60d..5302fc7ae5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -65,6 +65,7 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -74,6 +75,7 @@
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.ints.IntNodes;
import com.oracle.graal.python.builtins.objects.ints.PInt;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
import com.oracle.graal.python.lib.PyUnicodeCheckNode;
@@ -87,7 +89,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -122,7 +124,8 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyObjectGetAttr getAttr,
@Cached TruffleString.EqualNode isEqual,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) { // "|s:IncrementalEncoder"
TruffleString errors = null;
@@ -130,7 +133,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
errors = castToStringNode.execute(inliningTarget, err);
}
- MultibyteIncrementalEncoderObject self = factory.createMultibyteIncrementalEncoderObject(type);
+ MultibyteIncrementalEncoderObject self = PFactory.createMultibyteIncrementalEncoderObject(language, type, getInstanceShape.execute(type));
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
@@ -159,13 +162,11 @@ static PNone init(@SuppressWarnings("unused") MultibyteIncrementalEncoderObject
@SuppressWarnings("truffle-inlining") // footprint reduction 44 -> 25
protected abstract static class EncodeStatefulNode extends Node {
- abstract Object execute(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Object unistr, int end,
- PythonObjectFactory factory);
+ abstract Object execute(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Object unistr, int end);
// encoder_encode_stateful
@Specialization
static Object ts(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, TruffleString ucvt, int end,
- PythonObjectFactory factory,
@Bind("this") Node inliningTarget,
@Exclusive @Cached MultibyteCodecUtil.EncodeNode encodeNode,
@Shared @Cached TruffleString.ConcatNode concatNode,
@@ -183,12 +184,11 @@ static Object ts(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Truffl
int datalen = codePointLengthNode.execute(inbuf, TS_ENCODING);
PBytes r;
try {
- r = encodeEmptyInput(datalen, MBENC_FLUSH | MBENC_RESET, factory);
+ r = encodeEmptyInput(inliningTarget, datalen, MBENC_FLUSH | MBENC_RESET);
if (r == null) {
MultibyteEncodeBuffer buf = new MultibyteEncodeBuffer(inbuf);
r = encodeNode.execute(frame, inliningTarget, ctx.codec, ctx.state, buf,
- ctx.errors, end != 0 ? MBENC_FLUSH | MBENC_RESET : 0,
- factory);
+ ctx.errors, end != 0 ? MBENC_FLUSH | MBENC_RESET : 0);
if (buf.getInpos() < datalen) {
if (datalen - buf.getInpos() > MAXENCPENDING) {
/* normal codecs can't reach here */
@@ -208,7 +208,6 @@ static Object ts(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Truffl
@Specialization(guards = "!isTruffleString(unistr)")
static Object notTS(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Object unistr, int end,
- PythonObjectFactory factory,
@Bind("this") Node inliningTarget,
@Cached PyObjectStrAsObjectNode strNode,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@@ -226,7 +225,7 @@ static Object notTS(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Obj
}
}
TruffleString str = toTruffleStringNode.execute(inliningTarget, ucvt);
- return ts(frame, ctx, str, end, factory, inliningTarget, encodeNode, concatNode, codePointLengthNode, substringNode, raiseNode);
+ return ts(frame, ctx, str, end, inliningTarget, encodeNode, concatNode, codePointLengthNode, substringNode, raiseNode);
}
}
@@ -244,9 +243,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object encode(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Object unistr, int end,
- @Cached EncodeStatefulNode encodeStatefulNode,
- @Cached PythonObjectFactory factory) {
- return encodeStatefulNode.execute(frame, ctx, unistr, end, factory);
+ @Cached EncodeStatefulNode encodeStatefulNode) {
+ return encodeStatefulNode.execute(frame, ctx, unistr, end);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
index 3603962382..02e9cf81ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -106,7 +107,8 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object stream,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyObjectGetAttr getAttr,
@Cached TruffleString.EqualNode isEqual,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) { // "O|s:StreamReader"
TruffleString errors = null;
@@ -114,7 +116,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object stream,
errors = castToStringNode.execute(inliningTarget, err);
}
- MultibyteStreamReaderObject self = factory.createMultibyteStreamReaderObject(type);
+ MultibyteStreamReaderObject self = PFactory.createMultibyteStreamReaderObject(language, type, getInstanceShape.execute(type));
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_IS_UNEXPECTED_TYPE);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
index 22cabe1b6c..f00753fc89 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltins;
@@ -62,6 +63,7 @@
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -71,7 +73,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
@@ -104,14 +106,15 @@ static Object mbstreamwriterNew(VirtualFrame frame, Object type, Object stream,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyObjectGetAttr getAttr,
@Cached TruffleString.EqualNode isEqual,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) { // "O|s:StreamWriter"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
errors = castToStringNode.execute(inliningTarget, err);
}
- MultibyteStreamWriterObject self = factory.createMultibyteStreamWriterObject(type);
+ MultibyteStreamWriterObject self = PFactory.createMultibyteStreamWriterObject(language, type, getInstanceShape.execute(type));
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
@@ -147,10 +150,9 @@ abstract static class WriteNode extends PythonBinaryBuiltinNode {
static Object write(VirtualFrame frame, MultibyteStreamWriterObject self, Object strobj,
@Bind("this") Node inliningTarget,
@Cached MultibyteIncrementalEncoderBuiltins.EncodeStatefulNode encodeStatefulNode,
- @Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectCallMethodObjArgs callMethod) {
// mbstreamwriter_iwrite
- Object str = encodeStatefulNode.execute(frame, self, strobj, 0, factory);
+ Object str = encodeStatefulNode.execute(frame, self, strobj, 0);
callMethod.execute(frame, inliningTarget, self.stream, WRITE, str);
return PNone.NONE;
}
@@ -167,15 +169,14 @@ static Object writelines(VirtualFrame frame, MultibyteStreamWriterObject self, P
@Cached MultibyteIncrementalEncoderBuiltins.EncodeStatefulNode encodeStatefulNode,
@Cached SequenceNodes.GetSequenceStorageNode getStorage,
@Cached SequenceStorageNodes.GetItemNode getItem,
- @Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectCallMethodObjArgs callMethod) {
SequenceStorage sq = getStorage.execute(inliningTarget, lines);
for (int i = 0; i < sq.length(); i++) {
/* length can be changed even within this loop */
Object strobj = getItem.execute(sq, i);
// mbstreamwriter_iwrite
- Object str = encodeStatefulNode.execute(frame, self, strobj, 0, factory);
+ Object str = encodeStatefulNode.execute(frame, self, strobj, 0);
callMethod.execute(frame, inliningTarget, self.stream, WRITE, str);
}
return PNone.NONE;
@@ -199,18 +200,16 @@ static Object reset(VirtualFrame frame, MultibyteStreamWriterObject self,
@Bind("this") Node inliningTarget,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
- @Cached MultibyteCodecUtil.EncodeNode encodeNode,
- @Cached PythonObjectFactory factory) {
+ @Cached MultibyteCodecUtil.EncodeNode encodeNode) {
if (self.pending == null) {
return PNone.NONE;
}
int datalen = codePointLengthNode.execute(self.pending, TS_ENCODING);
- PBytes pwrt = encodeEmptyInput(datalen, MBENC_FLUSH | MBENC_RESET, factory);
+ PBytes pwrt = encodeEmptyInput(inliningTarget, datalen, MBENC_FLUSH | MBENC_RESET);
if (pwrt == null) {
MultibyteEncodeBuffer buf = new MultibyteEncodeBuffer(self.pending);
pwrt = encodeNode.execute(frame, inliningTarget, self.codec, self.state, buf,
- self.errors, MBENC_FLUSH | MBENC_RESET,
- factory);
+ self.errors, MBENC_FLUSH | MBENC_RESET);
}
/*
* some pending buffer can be truncated when UnicodeEncodeError is raised on 'strict'
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
index e4dfad8bc4..2ad485b8a1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,10 +50,10 @@
import java.nio.charset.Charset;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.modules.cjkcodecs.DBCSMap.MappingType;
import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteCodec.CodecType;
@@ -62,7 +62,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.CharsetMapping;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -99,7 +99,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
protected static void registerCodec(String name, int cidx, CodecType ct, int midx, MappingType mt,
DBCSMap[] maps, MultibyteCodec[] codecs,
- PythonModule codec, PythonObjectFactory factory) {
+ PythonModule codec, PythonLanguage language) {
TruffleString tsName = toTruffleStringUncached(name);
TruffleString normalizedEncoding = CharsetMapping.normalizeUncached(tsName);
Charset charset = CharsetMapping.getCharsetNormalized(normalizedEncoding);
@@ -110,7 +110,7 @@ protected static void registerCodec(String name, int cidx, CodecType ct, int mid
if (midx != -1) {
DBCSMap h = maps[midx] = new DBCSMap(name, tsName, charset, mt);
codec.setAttribute(toTruffleStringUncached(h.charsetMapName),
- factory.createCapsuleJavaName(h, PyMultibyteCodec_CAPSULE_NAME));
+ PFactory.createCapsuleJavaName(language, h, PyMultibyteCodec_CAPSULE_NAME));
}
}
}
@@ -127,13 +127,11 @@ abstract static class CreateCodecNode extends PythonUnaryBuiltinNode {
@Specialization
static Object createCodec(PyCapsule arg,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- return createCodec(inliningTarget, arg, factory, raiseNode);
+ return createCodec(inliningTarget, arg, raiseNode);
}
static Object createCodec(Node inliningTarget, PyCapsule arg,
- PythonObjectFactory factory,
PRaiseNode.Lazy raiseNode) {
if (!PyCapsule.capsuleJavaNameIs(arg, PyMultibyteCodec_CAPSULE_NAME)) {
throw raiseNode.get(inliningTarget).raise(ValueError, ARGUMENT_TYPE_INVALID);
@@ -141,7 +139,7 @@ static Object createCodec(Node inliningTarget, PyCapsule arg,
MultibyteCodec codec;
codec = (MultibyteCodec) arg.getPointer();
codec.codecinit();
- return factory.createMultibyteCodecObject(PythonBuiltinClassType.MultibyteCodec, codec);
+ return PFactory.createMultibyteCodecObject(PythonLanguage.get(inliningTarget), codec);
}
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
index 3d876912c4..548ef01be4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
@@ -83,7 +83,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ByteArrayBuilder;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -120,8 +120,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, TruffleString map,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@Cached(inline = false) TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached(inline = false) HashingStorageSetItem setItemNode,
- @Cached PRaiseNode.Lazy raiseNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached PRaiseNode.Lazy raiseNode) {
int len = Math.min(codePointLengthNode.execute(map, TS_ENCODING), 256);
if (len == 0) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
@@ -134,12 +133,12 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, TruffleString map,
Arrays.fill(level1, (byte) 0xFF);
Arrays.fill(level2, (byte) 0xFF);
if (codePointAtIndexNode.execute(map, 0, TS_ENCODING, ErrorHandling.BEST_EFFORT) != 0) {
- return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode, factory);
+ return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode);
}
for (int i = 1; i < len; ++i) {
int cp = codePointAtIndexNode.execute(map, i, TS_ENCODING, ErrorHandling.BEST_EFFORT);
if (cp == 0 || cp > 0xFFFF) {
- return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode, factory);
+ return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode);
}
if (cp == 0xFFFE) {
continue;
@@ -154,7 +153,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, TruffleString map,
}
}
if (count2 >= 0xFF || count3 >= 0xFF) {
- return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode, factory);
+ return doDict(frame, inliningTarget, map, len, codePointAtIndexNode, setItemNode);
}
byte[] level23 = new byte[16 * count2 + 128 * count3];
@@ -176,17 +175,16 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, TruffleString map,
int i3 = 128 * (level23[i2] & 0xFF) + o3;
level23[l3Start + i3] = (byte) i;
}
- return factory.createEncodingMap(count2, count3, level1, level23);
+ return PFactory.createEncodingMap(PythonLanguage.get(inliningTarget), count2, count3, level1, level23);
}
- private static Object doDict(VirtualFrame frame, Node inliningTarget, TruffleString map, int len, TruffleString.CodePointAtIndexNode codePointAtIndexNode, HashingStorageSetItem setItemNode,
- PythonObjectFactory factory) {
+ private static Object doDict(VirtualFrame frame, Node inliningTarget, TruffleString map, int len, TruffleString.CodePointAtIndexNode codePointAtIndexNode, HashingStorageSetItem setItemNode) {
HashingStorage store = PDict.createNewStorage(len);
for (int i = 0; i < len; ++i) {
int cp = codePointAtIndexNode.execute(map, i, TS_ENCODING, ErrorHandling.BEST_EFFORT);
store = setItemNode.execute(frame, inliningTarget, store, cp, i);
}
- return factory.createDict(store);
+ return PFactory.createDict(PythonLanguage.get(inliningTarget), store);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
index 4b7db4d338..3c893aaced 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
@@ -60,6 +60,7 @@
import java.nio.ByteOrder;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.codecs.CodecsRegistry.PyCodecLookupErrorNode;
@@ -91,7 +92,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -284,19 +285,19 @@ abstract static class IgnoreErrorHandlerNode extends ErrorHandlerBaseNode {
@Specialization(guards = "isDecode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doDecodeException(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PyUnicodeDecodeErrorGetEndNode getEndNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, getEndNode.execute(inliningTarget, exception)});
+ @Cached PyUnicodeDecodeErrorGetEndNode getEndNode) {
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, getEndNode.execute(inliningTarget, exception)});
}
@Specialization(guards = "isEncodeOrTranslate(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncodeOrTranslateException(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, getEndNode.execute(inliningTarget, exception)});
+ @Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode) {
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, getEndNode.execute(inliningTarget, exception)});
}
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
@@ -317,27 +318,27 @@ abstract static class ReplaceErrorHandlerNode extends ErrorHandlerBaseNode {
@Specialization(guards = "isDecode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doDecodeException(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PyUnicodeDecodeErrorGetEndNode getEndNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{T_REPLACEMENT, getEndNode.execute(inliningTarget, exception)});
+ @Cached PyUnicodeDecodeErrorGetEndNode getEndNode) {
+ return PFactory.createTuple(language, new Object[]{T_REPLACEMENT, getEndNode.execute(inliningTarget, exception)});
}
@Specialization(guards = "isEncodeOrTranslate(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncodeOrTranslateException(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
- @Cached TruffleString.RepeatNode repeatNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.RepeatNode repeatNode) {
TruffleString replacement = isEncode(inliningTarget, exception, pyObjectTypeCheck) ? T_QUESTIONMARK : T_REPLACEMENT;
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
int n = end - start;
// CPython raises SystemError for negative values, we return an empty string
TruffleString result = n < 1 ? T_EMPTY_STRING : repeatNode.execute(replacement, n, TS_ENCODING);
- return factory.createTuple(new Object[]{result, end});
+ return PFactory.createTuple(language, new Object[]{result, end});
}
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
@@ -356,14 +357,14 @@ abstract static class XmlCharRefReplaceErrorHandlerNode extends ErrorHandlerBase
@Specialization(guards = "isEncode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncode(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetObjectNode getObjectNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
- @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
TruffleString src = getObjectNode.execute(inliningTarget, exception);
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
@@ -377,7 +378,7 @@ static Object doEncode(PBaseException exception,
pos = appendXmlCharRefReplacement(replacement, pos, codePointAtIndexNode.execute(src, i, TS_ENCODING, ErrorHandling.BEST_EFFORT));
}
TruffleString resultAscii = fromByteArrayNode.execute(replacement, Encoding.US_ASCII, false);
- return factory.createTuple(new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
+ return PFactory.createTuple(language, new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
}
@Specialization(guards = "!isEncode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
@@ -396,6 +397,7 @@ abstract static class BackslashReplaceErrorHandlerNode extends ErrorHandlerBaseN
@Specialization(guards = "isDecode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doDecodeException(VirtualFrame frame, PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeDecodeErrorGetObjectNode getObjectNode,
@@ -404,13 +406,12 @@ static Object doDecodeException(VirtualFrame frame, PBaseException exception,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
- @Cached @Shared TruffleString.SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached @Shared TruffleString.SwitchEncodingNode switchEncodingNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
Object object = getObjectNode.execute(inliningTarget, exception);
if (start >= end) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, end});
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, end});
}
byte[] replacement = new byte[4 * (end - start)];
int pos = 0;
@@ -424,25 +425,25 @@ static Object doDecodeException(VirtualFrame frame, PBaseException exception,
accessLib.release(srcBuf, frame, indirectCallData);
}
TruffleString resultAscii = fromByteArrayNode.execute(replacement, Encoding.US_ASCII, false);
- return factory.createTuple(new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
+ return PFactory.createTuple(language, new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
}
@Specialization(guards = "isEncodeOrTranslate(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncodeOrTranslateException(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetObjectNode getObjectNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
- @Cached @Shared TruffleString.SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached @Shared TruffleString.SwitchEncodingNode switchEncodingNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
TruffleString src = getObjectNode.execute(inliningTarget, exception);
if (start >= end) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, end});
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, end});
}
int len = 0;
for (int i = start; i < end; ++i) {
@@ -462,7 +463,7 @@ static Object doEncodeOrTranslateException(PBaseException exception,
pos = BytesUtils.unicodeNonAsciiEscape(cp, pos, replacement, true);
}
TruffleString resultAscii = fromByteArrayNode.execute(replacement, Encoding.US_ASCII, false);
- return factory.createTuple(new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
+ return PFactory.createTuple(language, new Object[]{switchEncodingNode.execute(resultAscii, TS_ENCODING), end});
}
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
@@ -481,6 +482,7 @@ abstract static class NameReplaceErrorHandlerNode extends ErrorHandlerBaseNode {
@Specialization(guards = "isEncode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncode(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetObjectNode getObjectNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@@ -491,13 +493,12 @@ static Object doEncode(PBaseException exception,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
- @Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleStringBuilder.ToStringNode toStringNode) {
TruffleString src = getObjectNode.execute(inliningTarget, exception);
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
if (start >= end) {
- return factory.createTuple(new Object[]{T_EMPTY_STRING, start});
+ return PFactory.createTuple(language, new Object[]{T_EMPTY_STRING, start});
}
TruffleStringBuilder tsb = TruffleStringBuilder.create(TS_ENCODING);
byte[] buf = new byte[1 + 1 + 8]; // \UNNNNNNNN
@@ -515,7 +516,7 @@ static Object doEncode(PBaseException exception,
appendStringNode.execute(tsb, switchEncodingNode.execute(fromByteArrayNode.execute(buf, 0, len, Encoding.US_ASCII, true), TS_ENCODING));
}
}
- return factory.createTuple(new Object[]{toStringNode.execute(tsb), end});
+ return PFactory.createTuple(language, new Object[]{toStringNode.execute(tsb), end});
}
@Specialization(guards = "!isEncode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
@@ -534,6 +535,7 @@ abstract static class SurrogatePassErrorHandlerNode extends ErrorHandlerBaseNode
@Specialization(guards = "isEncode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncode(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Exclusive @Cached PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetObjectNode getObjectNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@@ -541,7 +543,6 @@ static Object doEncode(PBaseException exception,
@Cached PyUnicodeEncodeErrorGetEncodingNode getEncodingNode,
@Exclusive @Cached GetStandardEncodingNode getStandardEncodingNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
@@ -552,7 +553,7 @@ static Object doEncode(PBaseException exception,
throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
}
if (start >= end) {
- return factory.createTuple(new Object[]{factory.createBytes(new byte[0]), end});
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, new byte[0]), end});
}
byte[] result = new byte[encoding.byteLength * (end - start)];
int pos = 0;
@@ -564,12 +565,13 @@ static Object doEncode(PBaseException exception,
encodeCodepoint(encoding, result, pos, cp);
pos += encoding.byteLength;
}
- return factory.createTuple(new Object[]{factory.createBytes(result), end});
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, result), end});
}
@Specialization(guards = "isDecode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doDecode(VirtualFrame frame, PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@SuppressWarnings("unused") @Exclusive @Cached PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeDecodeErrorGetObjectNode getObjectNode,
@@ -580,7 +582,6 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached TruffleString.FromCodePointNode fromCodePointNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
getEndNode.execute(inliningTarget, exception); // called for side effects only
@@ -600,7 +601,7 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
if (!isSurrogate(cp)) {
throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
}
- return factory.createTuple(new Object[]{fromCodePointNode.execute(cp, TS_ENCODING, true), start + encoding.byteLength});
+ return PFactory.createTuple(language, new Object[]{fromCodePointNode.execute(cp, TS_ENCODING, true), start + encoding.byteLength});
} finally {
accessLib.release(srcBuf, frame, indirectCallData);
}
@@ -671,18 +672,18 @@ abstract static class SurrogateEscapeErrorHandlerNode extends ErrorHandlerBaseNo
@Specialization(guards = "isEncode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doEncode(PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@SuppressWarnings("unused") @Exclusive @Cached PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeEncodeOrTranslateErrorGetObjectNode getObjectNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
TruffleString src = getObjectNode.execute(inliningTarget, exception);
if (start >= end) {
- return factory.createTuple(new Object[]{factory.createBytes(new byte[0]), end});
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, new byte[0]), end});
}
byte[] result = new byte[end - start];
int pos = 0;
@@ -693,12 +694,13 @@ static Object doEncode(PBaseException exception,
}
result[pos++] = (byte) (cp - 0xdc00);
}
- return factory.createTuple(new Object[]{factory.createBytes(result), end});
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, result), end});
}
@Specialization(guards = "isDecode(inliningTarget, exception, pyObjectTypeCheck)", limit = "1")
static Object doDecode(VirtualFrame frame, PBaseException exception,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@SuppressWarnings("unused") @Exclusive @Cached PyObjectTypeCheck pyObjectTypeCheck,
@Cached PyUnicodeDecodeErrorGetObjectNode getObjectNode,
@@ -708,7 +710,6 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
@@ -729,7 +730,7 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
if (consumed == 0) {
throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
}
- return factory.createTuple(new Object[]{toStringNode.execute(tsb), start + consumed});
+ return PFactory.createTuple(language, new Object[]{toStringNode.execute(tsb), start + consumed});
} finally {
accessLib.release(srcBuf, frame, indirectCallData);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
index efd9e7d425..3361d93597 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
@@ -56,6 +56,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -69,6 +70,7 @@
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyCallableCheckNode;
import com.oracle.graal.python.lib.PyDictDelItem;
import com.oracle.graal.python.lib.PyDictGetItem;
@@ -91,7 +93,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -146,7 +148,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant("QUOTE_ALL", QUOTE_ALL.ordinal());
addBuiltinConstant("QUOTE_NONNUMERIC", QUOTE_NONNUMERIC.ordinal());
addBuiltinConstant("QUOTE_NONE", QUOTE_NONE.ordinal());
- addBuiltinConstant(T__DIALECTS, core.factory().createDict());
+ addBuiltinConstant(T__DIALECTS, PFactory.createDict(core.getLanguage()));
super.initialize(core);
}
@@ -262,10 +264,10 @@ static Object createReader(VirtualFrame frame, Object csvfile, Object dialectObj
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
@Cached CallNode callNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object inputIter = getIter.execute(frame, inliningTarget, csvfile);
CSVDialect dialect = (CSVDialect) callNode.execute(frame, PythonBuiltinClassType.CSVDialect, new Object[]{dialectObj}, kwargs);
- return factory.createCSVReader(PythonBuiltinClassType.CSVReader, inputIter, dialect);
+ return PFactory.createCSVReader(language, inputIter, dialect);
}
}
@@ -278,14 +280,14 @@ static Object createReader(VirtualFrame frame, Object outputFile, Object dialect
@Cached CallNode callNode,
@Cached PyObjectLookupAttr lookupAttr,
@Cached PyCallableCheckNode checkCallable,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object write = lookupAttr.execute(frame, inliningTarget, outputFile, T_WRITE);
if (write == PNone.NO_VALUE || !checkCallable.execute(inliningTarget, write)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_MUST_HAVE_WRITE_METHOD, "argument 1");
}
CSVDialect dialect = (CSVDialect) callNode.execute(frame, PythonBuiltinClassType.CSVDialect, new Object[]{dialectObj}, kwargs);
- return factory.createCSVWriter(PythonBuiltinClassType.CSVWriter, write, dialect);
+ return PFactory.createCSVWriter(language, write, dialect);
}
}
@@ -529,7 +531,7 @@ private static Object createCSVDialect(Node raisingNode, PythonBuiltinClassType
int quoteCharCodePoint = TruffleString.EqualNode.getUncached().execute(quoteChar, T_NOT_SET, TS_ENCODING) ? NOT_SET_CODEPOINT
: TruffleString.CodePointAtIndexNode.getUncached().execute(quoteChar, 0, TS_ENCODING);
- return PythonObjectFactory.getUncached().createCSVDialect(cls, delimiter, delimiterCodePoint, doubleQuote,
+ return PFactory.createCSVDialect(PythonLanguage.get(null), cls, TypeNodes.GetInstanceShape.executeUncached(cls), delimiter, delimiterCodePoint, doubleQuote,
escapeChar, escapeCharCodePoint, lineTerminator, quoteChar, quoteCharCodePoint, quoting,
skipInitialSpace, strict);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
index 8a843a5c27..8ee12c5684 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
@@ -57,6 +57,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -130,9 +131,9 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
@Cached CastToTruffleStringNode castToStringNode,
@Cached GetClassNode getClassNode,
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
- PList fields = factory.createList();
+ PList fields = PFactory.createList(language);
CSVModuleBuiltins csvModuleBuiltins = (CSVModuleBuiltins) PythonContext.get(inliningTarget).lookupBuiltinModule(T__CSV).getBuiltins();
self.parseReset();
do {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CArgObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CArgObjectBuiltins.java
index 79144207e7..4207cd1891 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CArgObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CArgObjectBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
@@ -162,9 +163,9 @@ abstract static class ParamFuncNode extends Node {
@Specialization
static PyCArgObject paramFunc(CDataObject self, StgDictObject stgDict,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached(inline = false) TruffleString.CodePointAtIndexNode codePointAtIndexNode) {
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
switch (stgDict.paramfunc) {
// Corresponds to PyCArrayType_paramfunc
case PyCArrayTypeParamFunc -> {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
index a7deaae0c6..6381bad907 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,6 +59,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -86,7 +87,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
@@ -169,12 +170,12 @@ protected abstract static class BaseReduceNode extends PythonUnaryBuiltinNode {
@Specialization
static Object reduce(VirtualFrame frame, CDataObject self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached("create(T___DICT__)") GetAttributeNode getAttributeNode,
@Cached ReadAttributeFromPythonObjectNode readAttrNode,
@Cached PointerNodes.ReadBytesNode readBytesNode,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
StgDictObject stgDict = pyObjectStgDictNode.execute(inliningTarget, self);
if ((stgDict.flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER)) != 0) {
@@ -182,17 +183,17 @@ static Object reduce(VirtualFrame frame, CDataObject self,
}
Object dict = getAttributeNode.executeObject(frame, self);
Object[] t1 = new Object[]{dict, null};
- t1[1] = factory.createBytes(readBytesNode.execute(inliningTarget, self.b_ptr, self.b_size));
+ t1[1] = PFactory.createBytes(language, readBytesNode.execute(inliningTarget, self.b_ptr, self.b_size));
Object clazz = getClassNode.execute(inliningTarget, self);
- Object[] t2 = new Object[]{clazz, factory.createTuple(t1)};
+ Object[] t2 = new Object[]{clazz, PFactory.createTuple(language, t1)};
PythonModule ctypes = PythonContext.get(inliningTarget).lookupBuiltinModule(T__CTYPES);
Object unpickle = readAttrNode.execute(ctypes, T_UNPICKLE, null);
if (unpickle == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, toTruffleStringUncached("unpickle isn't supported yet."));
}
- Object[] t3 = new Object[]{unpickle, factory.createTuple(t2)};
- return factory.createTuple(t3); // "O(O(NN))"
+ Object[] t3 = new Object[]{unpickle, PFactory.createTuple(language, t2)};
+ return PFactory.createTuple(language, t3); // "O(O(NN))"
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
index 7e848296df..878c21408f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -60,6 +60,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -99,7 +100,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -420,6 +421,7 @@ protected abstract static class PyCDataSetNode extends Node {
@Specialization
static void PyCData_set(VirtualFrame frame, CDataObject dst, Object type, FieldSet setfunc, Object value, int index, int size, Pointer ptr,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached SetFuncNode setFuncNode,
@Cached CallNode callNode,
@Cached PyTypeCheck pyTypeCheck,
@@ -429,14 +431,13 @@ static void PyCData_set(VirtualFrame frame, CDataObject dst, Object type, FieldS
@Cached KeepRefNode keepRefNode,
@Cached PointerNodes.MemcpyNode memcpyNode,
@Cached PointerNodes.WritePointerNode writePointerNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, dst)) {
throw raiseNode.get(inliningTarget).raise(TypeError, NOT_A_CTYPE_INSTANCE);
}
Object result = PyCDataSetInternal(frame, inliningTarget, type, setfunc, value, size, ptr,
- factory,
+ language,
pyTypeCheck,
setFuncNode,
callNode,
@@ -455,7 +456,7 @@ static void PyCData_set(VirtualFrame frame, CDataObject dst, Object type, FieldS
*/
// corresponds to _PyCData_set
static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object type, FieldSet setfunc, Object value, int size, Pointer ptr,
- PythonObjectFactory factory,
+ PythonLanguage language,
PyTypeCheck pyTypeCheck,
SetFuncNode setFuncNode,
CallNode callNode,
@@ -480,7 +481,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
if (PGuards.isPTuple(value)) {
Object ob = callNode.execute(frame, type, value);
return PyCDataSetInternal(frame, inliningTarget, type, setfunc, ob, size, ptr,
- factory,
+ language,
pyTypeCheck,
setFuncNode,
callNode,
@@ -501,7 +502,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
if (isInstanceNode.executeWith(frame, value, type)) {
memcpyNode.execute(inliningTarget, ptr, src.b_ptr, size);
- return GetKeepedObjects(src, factory);
+ return GetKeepedObjects(src, language);
}
if (pyTypeCheck.isPyCPointerTypeObject(inliningTarget, type) && pyTypeCheck.isArrayObject(inliningTarget, value)) {
@@ -516,7 +517,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
writePointerNode.execute(inliningTarget, ptr, src.b_ptr);
- Object keep = GetKeepedObjects(src, factory);
+ Object keep = GetKeepedObjects(src, language);
/*
* We are assigning an array object to a field which represents a pointer. This has
@@ -525,7 +526,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
* it's object list. So we create a tuple, containing b_objects list PLUS the array
* itself, and return that!
*/
- return factory.createTuple(new Object[]{keep, value});
+ return PFactory.createTuple(language, new Object[]{keep, value});
}
throw raiseNode.get(inliningTarget).raise(TypeError, INCOMPATIBLE_TYPES_P_INSTANCE_INSTEAD_OF_P_INSTANCE, value, type);
}
@@ -536,14 +537,14 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
* Code to keep needed objects alive
*/
- protected static CDataObject PyCData_GetContainer(CDataObject leaf, PythonObjectFactory factory) {
+ protected static CDataObject PyCData_GetContainer(CDataObject leaf, PythonLanguage language) {
CDataObject self = leaf;
while (self.b_base != null) {
self = self.b_base;
}
if (self.b_objects == null) {
if (self.b_length != 0) {
- self.b_objects = factory.createDict();
+ self.b_objects = PFactory.createDict(language);
} else {
self.b_objects = PNone.NONE;
}
@@ -551,8 +552,8 @@ protected static CDataObject PyCData_GetContainer(CDataObject leaf, PythonObject
return self;
}
- static Object GetKeepedObjects(CDataObject target, PythonObjectFactory factory) {
- return PyCData_GetContainer(target, factory).b_objects;
+ static Object GetKeepedObjects(CDataObject target, PythonLanguage language) {
+ return PyCData_GetContainer(target, language).b_objects;
}
/*
@@ -585,13 +586,13 @@ static void none(CDataObject target, int index, PNone keep) {
@Specialization(guards = "!isNone(keep)")
static void KeepRef(VirtualFrame frame, Node inliningTarget, CDataObject target, int index, Object keep,
+ @Bind PythonLanguage language,
@Cached(inline = false) TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached(inline = false) TruffleStringBuilder.ToStringNode toStringNode,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached HashingStorageSetItem setItem,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- CDataObject ob = PyCData_GetContainer(target, factory);
+ CDataObject ob = PyCData_GetContainer(target, language);
if (!PGuards.isDict(ob.b_objects)) {
ob.b_objects = keep;
return;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
index b760db1fc6..1602d3d3ed 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
@@ -56,6 +56,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -116,9 +117,9 @@ static Object PyCArrayType_from_ctype(VirtualFrame frame, Object itemtype, int l
@Cached IsTypeNode isTypeNode,
@Cached GetNameNode getNameNode,
@Cached SimpleTruffleStringFormatNode simpleFormatNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
- Object key = factory.createTuple(new Object[]{itemtype, length});
+ Object key = PFactory.createTuple(language, new Object[]{itemtype, length});
CtypesThreadState ctypes = CtypesThreadState.get(context, context.getLanguage(inliningTarget));
Object result = getItem.execute(frame, inliningTarget, ctypes.cache, key);
if (result != null) {
@@ -129,8 +130,8 @@ static Object PyCArrayType_from_ctype(VirtualFrame frame, Object itemtype, int l
throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_A_TYPE_OBJECT);
}
TruffleString name = simpleFormatNode.format("%s_Array_%d", getNameNode.execute(inliningTarget, itemtype), length);
- PDict dict = factory.createDict(new PKeyword[]{new PKeyword(T__LENGTH_, length), new PKeyword(T__TYPE_, itemtype)});
- PTuple tuple = factory.createTuple(new Object[]{PyCArray});
+ PDict dict = PFactory.createDict(language, new PKeyword[]{new PKeyword(T__LENGTH_, length), new PKeyword(T__TYPE_, itemtype)});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{PyCArray});
result = callNode.execute(frame, PyCArrayType, name, tuple, dict);
HashingStorage newStorage = setItem.execute(frame, inliningTarget, ctypes.cache, key, result);
assert newStorage == ctypes.cache;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
index c5d71e14c5..593e499b8d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -237,14 +238,15 @@ TruffleString PyCField_repr(CFieldObject self,
@SuppressWarnings("fallthrough")
abstract static class PyCFieldFromDesc extends Node {
- abstract CFieldObject execute(Node inliningTarget, Object desc, int index, int bitsize, int pack, boolean big_endian, int[] props, PythonObjectFactory factory);
+ abstract CFieldObject execute(Node inliningTarget, Object desc, int index, int bitsize, int pack, boolean big_endian, int[] props);
@Specialization
- static CFieldObject PyCField_FromDesc(Node inliningTarget, Object desc, int index, int bitsize, int pack, boolean big_endian, int[] props, PythonObjectFactory factory,
+ static CFieldObject PyCField_FromDesc(Node inliningTarget, Object desc, int index, int bitsize, int pack, boolean big_endian, int[] props,
+ @Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PRaiseNode.Lazy raiseNode) {
- CFieldObject self = factory.createCFieldObject(PythonBuiltinClassType.CField);
+ CFieldObject self = PFactory.createCFieldObject(language);
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, desc);
if (dict == null) {
throw raiseNode.get(inliningTarget).raise(TypeError, HAS_NO_STGINFO);
@@ -559,8 +561,7 @@ static Object f_set_sw(VirtualFrame frame, @SuppressWarnings("unused") FieldSet
@SuppressWarnings("unused")
static Object O_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, Object value, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached PointerNodes.WritePointerNode writePointerNode) {
writePointerNode.execute(inliningTarget, ptr, Pointer.pythonObject(value));
return PNone.NONE;
}
@@ -692,14 +693,14 @@ static Object z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Specialization(guards = "setfunc == Z_set")
static Object Z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, Object value, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Exclusive @Cached CastToTruffleStringNode toString,
@Exclusive @Cached PyLongCheckNode longCheckNode,
@Exclusive @Cached PointerNodes.PointerFromLongNode pointerFromLongNode,
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
- @Shared @Cached PythonObjectFactory factory) { // CTYPES_UNICODE
+ @Exclusive @Cached PRaiseNode.Lazy raiseNode) { // CTYPES_UNICODE
if (value == PNone.NONE) {
writePointerNode.execute(inliningTarget, ptr, Pointer.NULL);
return PNone.NONE;
@@ -719,7 +720,7 @@ static Object Z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
/* ptr is a char**, we need to add the indirection */
Pointer valuePtr = Pointer.bytes(bytes);
writePointerNode.execute(inliningTarget, ptr, valuePtr);
- return createPyMemCapsule(valuePtr, factory);
+ return createPyMemCapsule(valuePtr, context, inliningTarget);
}
@Specialization(guards = "setfunc == P_set")
@@ -751,9 +752,9 @@ static Object error(VirtualFrame frame, FieldSet setfunc, Pointer ptr, Object va
private static final byte[] CTYPES_CFIELD_CAPSULE_NAME_PYMEM = PyCapsule.capsuleName("_ctypes/cfield.c pymem");
- private static PyCapsule createPyMemCapsule(Pointer pointer, PythonObjectFactory factory) {
- PyCapsule capsule = factory.createCapsuleJavaName(pointer, CTYPES_CFIELD_CAPSULE_NAME_PYMEM);
- new PointerReference(capsule, pointer, PythonContext.get(factory).getSharedFinalizer());
+ private static PyCapsule createPyMemCapsule(Pointer pointer, PythonContext context, Node inliningTarget) {
+ PyCapsule capsule = PFactory.createCapsuleJavaName(context.getLanguage(inliningTarget), pointer, CTYPES_CFIELD_CAPSULE_NAME_PYMEM);
+ new PointerReference(capsule, pointer, context.getSharedFinalizer());
return capsule;
}
}
@@ -879,21 +880,21 @@ static Object l_get_sw(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr
@Specialization(guards = "getfunc == L_get")
static Object L_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PointerNodes.ReadLongNode readLongNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached PointerNodes.ReadLongNode readLongNode) {
long val = readLongNode.execute(inliningTarget, ptr);
// GET_BITFIELD(val, size);
- return val < 0 ? factory.createInt(PInt.longToUnsignedBigInteger(val)) : val;
+ return val < 0 ? PFactory.createInt(language, PInt.longToUnsignedBigInteger(val)) : val;
}
@Specialization(guards = "getfunc == L_get_sw")
static Object L_get_sw(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PointerNodes.ReadLongNode readLongNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached PointerNodes.ReadLongNode readLongNode) {
long val = SWAP_8(readLongNode.execute(inliningTarget, ptr));
// GET_BITFIELD(val, size);
- return val < 0 ? factory.createInt(PInt.longToUnsignedBigInteger(val)) : val;
+ return val < 0 ? PFactory.createInt(language, PInt.longToUnsignedBigInteger(val)) : val;
}
@Specialization(guards = "getfunc == d_get")
@@ -942,9 +943,9 @@ static Object O_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @
@Specialization(guards = "getfunc == c_get")
static Object c_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
- @Shared @Cached PointerNodes.ReadByteNode readByteNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(new byte[]{readByteNode.execute(inliningTarget, ptr)});
+ @Bind PythonLanguage language,
+ @Shared @Cached PointerNodes.ReadByteNode readByteNode) {
+ return PFactory.createBytes(language, new byte[]{readByteNode.execute(inliningTarget, ptr)});
}
@Specialization(guards = "getfunc == u_get")
@@ -973,17 +974,17 @@ static Object U_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, i
@Specialization(guards = "getfunc == s_get")
static Object s_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached PointerNodes.StrLenNode strLenNode,
- @Shared @Cached PointerNodes.ReadBytesNode readBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(readBytesNode.execute(inliningTarget, ptr, strLenNode.execute(inliningTarget, ptr, size)));
+ @Shared @Cached PointerNodes.ReadBytesNode readBytesNode) {
+ return PFactory.createBytes(language, readBytesNode.execute(inliningTarget, ptr, strLenNode.execute(inliningTarget, ptr, size)));
}
@Specialization(guards = "getfunc == z_get")
static Object z_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached PointerNodes.ReadPointerNode readPointerNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PointerNodes.StrLenNode strLenNode,
@Shared @Cached PointerNodes.ReadBytesNode readBytesNode) {
// ptr is a char**, we need to deref it to get char*
@@ -992,7 +993,7 @@ static Object z_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @
return PNone.NONE;
}
byte[] bytes = readBytesNode.execute(inliningTarget, valuePtr, strLenNode.execute(inliningTarget, valuePtr));
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
@Specialization(guards = "getfunc == Z_get")
@@ -1015,9 +1016,9 @@ static Object Z_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @
@Specialization(guards = "getfunc == P_get")
static Object P_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached PointerNodes.ReadPointerNode readPointerNode,
- @Cached PointerNodes.GetPointerValueAsObjectNode getPointerValueAsObjectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached PointerNodes.GetPointerValueAsObjectNode getPointerValueAsObjectNode) {
Pointer valuePtr = readPointerNode.execute(inliningTarget, ptr);
if (valuePtr.isNull()) {
return 0L;
@@ -1025,9 +1026,9 @@ static Object P_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @
Object p = getPointerValueAsObjectNode.execute(inliningTarget, valuePtr);
if (p instanceof Long) {
long val = (long) p;
- return val < 0 ? factory.createInt(PInt.longToUnsignedBigInteger(val)) : val;
+ return val < 0 ? PFactory.createInt(language, PInt.longToUnsignedBigInteger(val)) : val;
}
- return factory.createNativeVoidPtr(p);
+ return PFactory.createNativeVoidPtr(language, p);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
index fb56f967a4..5c3bd3442d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
@@ -169,8 +169,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -242,7 +241,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void initialize(Python3Core core) {
super.initialize(core);
- addBuiltinConstant("_pointer_type_cache", core.factory().createDict());
+ addBuiltinConstant("_pointer_type_cache", PFactory.createDict(core.getLanguage()));
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
addBuiltinConstant("FUNCFLAG_STDCALL", FUNCFLAG_STDCALL);
}
@@ -259,11 +258,11 @@ public void initialize(Python3Core core) {
@Override
public void postInitialize(Python3Core core) {
super.postInitialize(core);
- PythonObjectFactory factory = core.factory();
+ PythonLanguage language = core.getLanguage();
PythonModule ctypesModule = core.lookupBuiltinModule(T__CTYPES);
- ctypesModule.setAttribute(tsLiteral("_string_at_addr"), factory.createNativeVoidPtr(StringAtFunction.create()));
- ctypesModule.setAttribute(tsLiteral("_cast_addr"), factory.createNativeVoidPtr(CastFunction.create()));
- ctypesModule.setAttribute(tsLiteral("_wstring_at_addr"), factory.createNativeVoidPtr(WStringAtFunction.create()));
+ ctypesModule.setAttribute(tsLiteral("_string_at_addr"), PFactory.createNativeVoidPtr(language, StringAtFunction.create()));
+ ctypesModule.setAttribute(tsLiteral("_cast_addr"), PFactory.createNativeVoidPtr(language, CastFunction.create()));
+ ctypesModule.setAttribute(tsLiteral("_wstring_at_addr"), PFactory.createNativeVoidPtr(language, WStringAtFunction.create()));
int rtldLocal = RTLD_LOCAL.getValueIfDefined();
ctypesModule.setAttribute(tsLiteral("RTLD_LOCAL"), rtldLocal);
ctypesModule.setAttribute(tsLiteral("RTLD_GLOBAL"), RTLD_GLOBAL.getValueIfDefined());
@@ -297,9 +296,9 @@ public void postInitialize(Python3Core core) {
}
if (handle != null) {
NativeFunction memmove = MemMoveFunction.create(handle, context);
- ctypesModule.setAttribute(tsLiteral("_memmove_addr"), factory.createNativeVoidPtr(memmove, memmove.adr));
+ ctypesModule.setAttribute(tsLiteral("_memmove_addr"), PFactory.createNativeVoidPtr(language, memmove, memmove.adr));
NativeFunction memset = MemSetFunction.create(handle, context);
- ctypesModule.setAttribute(tsLiteral("_memset_addr"), factory.createNativeVoidPtr(memset, memset.adr));
+ ctypesModule.setAttribute(tsLiteral("_memset_addr"), PFactory.createNativeVoidPtr(language, memset, memset.adr));
}
// If handle == null, and we don't set the attributes, ctypes module is going to fail in
// __init__.py on importing those attributes from _ctypes. This way the failure will happen
@@ -510,9 +509,9 @@ static Object POINTER(VirtualFrame frame, Object cls,
@Cached GetNameNode getNameNode,
@Cached CastToTruffleStringNode toTruffleStringNode,
@Cached SimpleTruffleStringFormatNode formatNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- CtypesThreadState ctypes = CtypesThreadState.get(context, context.getLanguage(inliningTarget));
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ CtypesThreadState ctypes = CtypesThreadState.get(context, language);
Object result = getItem.execute(frame, inliningTarget, ctypes.ptrtype_cache, cls);
if (result != null) {
return result;
@@ -521,13 +520,13 @@ static Object POINTER(VirtualFrame frame, Object cls,
if (PGuards.isString(cls)) {
TruffleString name = toTruffleStringNode.execute(inliningTarget, cls);
TruffleString buf = formatNode.format("LP_%s", name);
- Object[] args = new Object[]{buf, PyCPointer, factory.createDict()};
+ Object[] args = new Object[]{buf, PyCPointer, PFactory.createDict(language)};
result = callNode.execute(frame, PyCPointerType, args, PKeyword.EMPTY_KEYWORDS);
- key = factory.createNativeVoidPtr(result);
+ key = PFactory.createNativeVoidPtr(language, result);
} else if (isTypeNode.execute(inliningTarget, cls)) {
TruffleString buf = formatNode.format("LP_%s", getNameNode.execute(inliningTarget, cls));
- PTuple bases = factory.createTuple(new Object[]{PyCPointer});
- Object[] args = new Object[]{buf, bases, factory.createDict(new PKeyword[]{new PKeyword(T__TYPE_, cls)})};
+ PTuple bases = PFactory.createTuple(language, new Object[]{PyCPointer});
+ Object[] args = new Object[]{buf, bases, PFactory.createDict(language, new PKeyword[]{new PKeyword(T__TYPE_, cls)})};
result = callNode.execute(frame, PyCPointerType, args, PKeyword.EMPTY_KEYWORDS);
key = cls;
} else {
@@ -588,7 +587,7 @@ static Object buffer_info(Object arg,
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, arg);
if (dict == null) {
@@ -602,7 +601,7 @@ static Object buffer_info(Object arg,
shape[i] = dict.shape[i];
}
- return factory.createTuple(new Object[]{dict.format, dict.ndim, factory.createTuple(shape)});
+ return PFactory.createTuple(language, new Object[]{dict.format, dict.ndim, PFactory.createTuple(language, shape)});
}
}
@@ -712,10 +711,10 @@ static Object py_dl_open(PythonModule self, TruffleString name, int m,
@Bind("this") Node inliningTarget,
@Cached AuditNode auditNode) {
PythonContext context = PythonContext.get(inliningTarget);
- PythonObjectSlowPathFactory factory = context.factory();
+ PythonLanguage language = context.getLanguage(inliningTarget);
auditNode.audit(inliningTarget, "ctypes.dlopen", name);
if (name.isEmpty()) {
- return factory.createNativeVoidPtr(((CtypesModuleBuiltins) self.getBuiltins()).rtldDefault);
+ return PFactory.createNativeVoidPtr(language, ((CtypesModuleBuiltins) self.getBuiltins()).rtldDefault);
}
// The loaded library can link against libpython, so we have to make sure it is loaded
@@ -731,7 +730,7 @@ static Object py_dl_open(PythonModule self, TruffleString name, int m,
long adr = PyObjectHashNode.executeUncached(handler);
handle = new DLHandler(handler, adr, name.toJavaStringUncached(), true);
registerAddress(context, handle.adr, handle);
- return factory.createNativeVoidPtr(handle);
+ return PFactory.createNativeVoidPtr(language, handle);
} else if (context.getEnv().isNativeAccessAllowed()) {
CtypesThreadState ctypes = CtypesThreadState.get(context, context.getLanguage());
/*-
@@ -741,7 +740,7 @@ static Object py_dl_open(PythonModule self, TruffleString name, int m,
if (!eqNode.execute(name, MACOS_Security_LIB, TS_ENCODING) && !eqNode.execute(name, MACOS_CoreFoundation_LIB, TS_ENCODING)) {
handle = loadNFILibrary(context, ctypes.backendType, name.toJavaStringUncached(), mode);
registerAddress(context, handle.adr, handle);
- return factory.createNativeVoidPtr(handle, handle.adr);
+ return PFactory.createNativeVoidPtr(language, handle, handle.adr);
}
}
} catch (Exception e) {
@@ -777,11 +776,11 @@ protected abstract static class CtypesDlSymNode extends PNodeWithContext {
@Specialization
static Object ctypes_dlsym(VirtualFrame frame, Pointer handlePtr, Object n, PythonBuiltinClassType error,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached CtypesNodes.HandleFromPointerNode handleFromPointerNode,
@Cached PyObjectHashNode hashNode,
@Cached CastToJavaStringNode asString,
@CachedLibrary(limit = "1") InteropLibrary ilib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
DLHandler handle = handleFromPointerNode.getDLHandler(inliningTarget, handlePtr);
String name = asString.execute(n);
@@ -794,12 +793,12 @@ static Object ctypes_dlsym(VirtualFrame frame, Pointer handlePtr, Object n, Pyth
long adr = isManaged ? hashNode.execute(frame, inliningTarget, sym) : ilib.asPointer(sym);
sym = isManaged ? CallLLVMFunction.create(sym, ilib) : sym;
NativeFunction func = new NativeFunction(sym, adr, name, isManaged);
- registerAddress(PythonContext.get(inliningTarget), adr, func);
+ registerAddress(context, adr, func);
// PyLong_FromVoidPtr(ptr);
if (!isManaged) {
- return factory.createNativeVoidPtr(func, adr);
+ return PFactory.createNativeVoidPtr(context.getLanguage(inliningTarget), func, adr);
} else {
- return factory.createNativeVoidPtr(func);
+ return PFactory.createNativeVoidPtr(context.getLanguage(inliningTarget), func);
}
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
throw raiseNode.get(inliningTarget).raise(error, e);
@@ -973,12 +972,12 @@ Object doit(CDataObject obj, int offset,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetClassNode getClassNode,
@Cached PyTypeCheck pyTypeCheck,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
return error(null, obj, offset, inliningTarget, getClassNode, raiseNode);
}
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.tag = 'P';
parg.pffi_type = FFIType.ffi_type_pointer;
parg.obj = obj;
@@ -1036,15 +1035,15 @@ protected abstract static class AddressOfNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doit(CDataObject obj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
@Cached AuditNode auditNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
return error(obj, raiseNode.get(inliningTarget));
}
auditNode.audit(inliningTarget, "ctypes.addressof", obj);
- return factory.createNativeVoidPtr(obj.b_ptr);
+ return PFactory.createNativeVoidPtr(language, obj.b_ptr);
}
@Fallback
@@ -1208,7 +1207,7 @@ Object _ctypes_callproc(VirtualFrame frame, NativeFunction pProc, Object[] argar
if (mode == BackendMode.NFI) {
result = callNativeFunction(inliningTarget, pProc, avalues, atypes, rtype, ilib, raiseNode);
} else {
- result = callManagedFunction(inliningTarget, pProc, avalues, ilib, raiseNode);
+ result = callManagedFunction(inliningTarget, pProc, avalues, ilib);
if (mode == BackendMode.INTRINSIC) {
/*
* We don't want result conversion for functions implemented in Java, they
@@ -1221,7 +1220,7 @@ Object _ctypes_callproc(VirtualFrame frame, NativeFunction pProc, Object[] argar
return getResultNode.execute(frame, restype, rtype, result, checker);
}
- static Object callManagedFunction(Node inliningTarget, NativeFunction pProc, Object[] argarray, InteropLibrary ilib, PRaiseNode.Lazy raiseNode) {
+ static Object callManagedFunction(Node inliningTarget, NativeFunction pProc, Object[] argarray, InteropLibrary ilib) {
try {
return ilib.execute(pProc.sym, argarray);
} catch (PException e) {
@@ -1815,9 +1814,9 @@ protected abstract static class CastFunctionNode extends Node {
@Specialization
Object cast(Pointer ptr, Pointer srcObj, Pointer ctypeObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached HashingStorageSetItem setItem,
@Cached PyTypeCheck pyTypeCheck,
- @Cached PythonObjectFactory factory,
@Cached CallNode callNode,
@Cached CastCheckPtrTypeNode castCheckPtrTypeNode,
@Cached PointerNodes.ReadPythonObject readPythonObject,
@@ -1838,16 +1837,16 @@ Object cast(Pointer ptr, Pointer srcObj, Pointer ctypeObj,
* PyCData_GetContainer will initialize src.b_objects, we need this so it can be
* shared
*/
- PyCData_GetContainer(cdata, factory);
+ PyCData_GetContainer(cdata, language);
if (cdata.b_objects == null) {
- cdata.b_objects = factory.createDict();
+ cdata.b_objects = PFactory.createDict(language);
}
result.b_objects = cdata.b_objects;
if (PGuards.isDict(result.b_objects)) {
// PyLong_FromVoidPtr((void *)src);
PDict dict = (PDict) result.b_objects;
- Object index = factory.createNativeVoidPtr(cdata);
+ Object index = PFactory.createNativeVoidPtr(language, cdata);
dict.setDictStorage(setItem.execute(null, inliningTarget, dict.getDictStorage(), index, cdata));
}
}
@@ -1887,10 +1886,10 @@ protected abstract static class MemmoveNode extends Node {
@Specialization
static Object memmove(Node inliningTarget, Pointer destPtr, Pointer srcPtr, long size,
- @Cached PointerNodes.MemcpyNode memcpyNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached PointerNodes.MemcpyNode memcpyNode) {
memcpyNode.execute(inliningTarget, destPtr, srcPtr, (int) size);
- return factory.createNativeVoidPtr(destPtr);
+ return PFactory.createNativeVoidPtr(language, destPtr);
}
}
@@ -1949,9 +1948,9 @@ protected abstract static class MemsetNode extends Node {
@Specialization
static Object memset(Node inliningTarget, Pointer ptr, int value, long size,
+ @Bind PythonLanguage language,
@Cached PointerNodes.WriteLongNode writeLongNode,
- @Cached PointerNodes.WriteByteNode writeByteNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached PointerNodes.WriteByteNode writeByteNode) {
byte b = (byte) value;
long fill = 0;
for (int i = 0; i < Long.BYTES * 8; i += 8) {
@@ -1969,7 +1968,7 @@ static Object memset(Node inliningTarget, Pointer ptr, int value, long size,
for (; i < size; i++) {
writeByteNode.execute(inliningTarget, ptr.withOffset(i), b);
}
- return factory.createNativeVoidPtr(ptr);
+ return PFactory.createNativeVoidPtr(language, ptr);
}
}
@@ -2027,15 +2026,15 @@ protected abstract static class StringAtFunctionNode extends Node {
@Specialization
static Object string_at(Pointer ptr, int size,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PointerNodes.ReadBytesNode read,
@Cached PointerNodes.StrLenNode strLenNode,
@Cached AuditNode auditNode) {
- auditNode.audit(inliningTarget, "ctypes.string_at", factory.createNativeVoidPtr(ptr), size);
+ auditNode.audit(inliningTarget, "ctypes.string_at", PFactory.createNativeVoidPtr(language, ptr), size);
if (size == -1) {
size = strLenNode.execute(inliningTarget, ptr);
}
- return factory.createBytes(read.execute(inliningTarget, ptr, size));
+ return PFactory.createBytes(language, read.execute(inliningTarget, ptr, size));
}
}
@@ -2070,13 +2069,13 @@ protected abstract static class WStringAtFunctionNode extends Node {
@Specialization
static TruffleString wstring_at(Pointer ptr, int size,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached AuditNode auditNode,
@Cached PointerNodes.ReadBytesNode read,
@Cached PointerNodes.WCsLenNode wCsLenNode,
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
- auditNode.audit(inliningTarget, "ctypes.wstring_at", factory.createNativeVoidPtr(ptr), size);
+ auditNode.audit(inliningTarget, "ctypes.wstring_at", PFactory.createNativeVoidPtr(language, ptr), size);
if (size == -1) {
size = wCsLenNode.execute(inliningTarget, ptr);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
index 6b706257f4..b01f95d28b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -57,6 +57,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.truffle.api.strings.TruffleString.Encoding.US_ASCII;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonOS;
import com.oracle.graal.python.builtins.modules.ctypes.FFIType.FFI_TYPES;
@@ -66,6 +67,7 @@
import com.oracle.graal.python.builtins.objects.cext.common.NativePointer;
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
import com.oracle.graal.python.lib.PyObjectTypeCheck;
@@ -73,9 +75,10 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -344,12 +347,13 @@ public abstract static class CreateCDataObjectNode extends Node {
@Specialization
static CDataObject doCreate(Node inliningTarget, Object type, Pointer pointer, int size, boolean needsfree,
@Cached(inline = false) IsSubtypeNode isSubtypeNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
+ @Bind PythonLanguage language) {
CDataObject result;
if (isSubtypeNode.execute(type, PyCFuncPtr)) {
- result = factory.createPyCFuncPtrObject(type, pointer, size, needsfree);
+ result = PFactory.createPyCFuncPtrObject(language, type, getInstanceShape.execute(type), pointer, size, needsfree);
} else {
- result = factory.createCDataObject(type, pointer, size, needsfree);
+ result = PFactory.createCDataObject(language, type, getInstanceShape.execute(type), pointer, size, needsfree);
}
if (needsfree) {
new PointerReference(result, pointer, PythonContext.get(inliningTarget).getSharedFinalizer());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
index d5ba1bf969..d9910ce92a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -76,9 +76,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -133,10 +131,9 @@ private static void createGetSet(PythonLanguage language, Object type, NodeFacto
l -> new BuiltinFunctionRootNode(l, builtin, factory, true),
factory.getNodeClass(),
builtin.name());
- PythonObjectSlowPathFactory f = PythonContext.get(null).factory();
int flags = PBuiltinFunction.getFlags(builtin, rawCallTarget);
- PBuiltinFunction getter = f.createBuiltinFunction(name, type, 1, flags, rawCallTarget);
- GetSetDescriptor callable = f.createGetSetDescriptor(getter, getter, name, type, false);
+ PBuiltinFunction getter = PFactory.createBuiltinFunction(language, name, type, 1, flags, rawCallTarget);
+ GetSetDescriptor callable = PFactory.createGetSetDescriptor(language, getter, getter, name, type, false);
callable.setAttribute(T___DOC__, toTruffleStringUncached(builtin.doc()));
WriteAttributeToObjectNode.getUncached(true).execute(type, name, callable);
}
@@ -147,10 +144,10 @@ abstract static class CharArrayRawNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(value)")
static PBytes doGet(CDataObject self, @SuppressWarnings("unused") PNone value,
+ @Bind PythonLanguage language,
@Bind("this") Node inliningTarget,
- @Cached PointerNodes.ReadBytesNode read,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(read.execute(inliningTarget, self.b_ptr, self.b_size));
+ @Cached PointerNodes.ReadBytesNode read) {
+ return PFactory.createBytes(language, read.execute(inliningTarget, self.b_ptr, self.b_size));
}
@Specialization(limit = "3")
@@ -183,10 +180,10 @@ abstract static class CharArrayValueNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(value)")
static PBytes doGet(CDataObject self, @SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PointerNodes.StrLenNode strLenNode,
- @Cached PointerNodes.ReadBytesNode read,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(read.execute(inliningTarget, self.b_ptr, strLenNode.execute(inliningTarget, self.b_ptr)));
+ @Cached PointerNodes.ReadBytesNode read) {
+ return PFactory.createBytes(language, read.execute(inliningTarget, self.b_ptr, strLenNode.execute(inliningTarget, self.b_ptr)));
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
index cf3d3e988d..6ad818bd6a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -77,15 +77,13 @@
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -102,28 +100,28 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
}
@TruffleBoundary
- protected static void addCVoidPFromParam(PythonObjectSlowPathFactory factory, PythonLanguage language, Object type) {
+ protected static void addCVoidPFromParam(PythonLanguage language, Object type) {
NodeFactory rawFactory = CVoidPFromParamNodeFactory.getInstance();
Builtin rawNodeBuiltin = CVoidPFromParamNode.class.getAnnotation(Builtin.class);
- addClassMethod(factory, language, type, rawFactory, rawNodeBuiltin);
+ addClassMethod(language, type, rawFactory, rawNodeBuiltin);
}
@TruffleBoundary
- protected static void addCCharPFromParam(PythonObjectSlowPathFactory factory, PythonLanguage language, Object type) {
+ protected static void addCCharPFromParam(PythonLanguage language, Object type) {
NodeFactory rawFactory = CCharPFromParamNodeFactory.getInstance();
Builtin rawNodeBuiltin = CCharPFromParamNode.class.getAnnotation(Builtin.class);
- addClassMethod(factory, language, type, rawFactory, rawNodeBuiltin);
+ addClassMethod(language, type, rawFactory, rawNodeBuiltin);
}
@TruffleBoundary
- protected static void addCWCharPFromParam(PythonObjectSlowPathFactory factory, PythonLanguage language, Object type) {
+ protected static void addCWCharPFromParam(PythonLanguage language, Object type) {
NodeFactory rawFactory = CWCharPFromParamNodeFactory.getInstance();
Builtin rawNodeBuiltin = CWCharPFromParamNode.class.getAnnotation(Builtin.class);
- addClassMethod(factory, language, type, rawFactory, rawNodeBuiltin);
+ addClassMethod(language, type, rawFactory, rawNodeBuiltin);
}
@TruffleBoundary
- private static void addClassMethod(PythonObjectSlowPathFactory objectFactory, PythonLanguage language, Object type, NodeFactory extends PythonBuiltinBaseNode> nodeFactory, Builtin builtin) {
+ private static void addClassMethod(PythonLanguage language, Object type, NodeFactory extends PythonBuiltinBaseNode> nodeFactory, Builtin builtin) {
TruffleString name = toTruffleStringUncached(builtin.name());
Object builtinDoc = PNone.NONE;
RootCallTarget callTarget = language.createCachedCallTarget(
@@ -131,8 +129,8 @@ private static void addClassMethod(PythonObjectSlowPathFactory objectFactory, Py
nodeFactory.getNodeClass(),
builtin.name());
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
- PBuiltinFunction function = objectFactory.createBuiltinFunction(name, type, 1, flags, callTarget);
- PDecoratedMethod classMethod = objectFactory.createClassmethodFromCallableObj(function);
+ PBuiltinFunction function = PFactory.createBuiltinFunction(language, name, type, 1, flags, callTarget);
+ PDecoratedMethod classMethod = PFactory.createClassmethodFromCallableObj(language, function);
function.setAttribute(T___DOC__, builtinDoc);
WriteAttributeToObjectNode.getUncached(true).execute(type, name, classMethod);
}
@@ -159,10 +157,9 @@ static Object c_wchar_p_from_param(VirtualFrame frame, Object type, Object value
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached CWCharPFromParamNode cwCharPFromParamNode,
@Cached PyObjectLookupAttr lookupAttr,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (PGuards.isString(value)) {
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(PythonLanguage.get(inliningTarget));
parg.pffi_type = ffi_type_pointer;
parg.tag = 'Z';
parg.valuePointer = Pointer.allocate(parg.pffi_type, parg.pffi_type.size);
@@ -220,9 +217,9 @@ static Object voidPtr(@SuppressWarnings("unused") Object type, Object value,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached PyLongCheckNode longCheckNode,
@Exclusive @Cached SetFuncNode setFuncNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
/* int, long */
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'P';
parg.valuePointer = Pointer.allocate(parg.pffi_type, parg.pffi_type.size);
@@ -234,9 +231,9 @@ static Object voidPtr(@SuppressWarnings("unused") Object type, Object value,
@Specialization
static Object bytes(@SuppressWarnings("unused") Object type, PBytes value,
@Exclusive @Cached SetFuncNode setFuncNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
/* bytes */
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'z';
parg.valuePointer = Pointer.allocate(parg.pffi_type, parg.pffi_type.size);
@@ -248,9 +245,9 @@ static Object bytes(@SuppressWarnings("unused") Object type, PBytes value,
@Specialization
static Object string(@SuppressWarnings("unused") Object type, TruffleString value,
@Exclusive @Cached SetFuncNode setFuncNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
/* unicode */
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'Z';
parg.valuePointer = Pointer.allocate(parg.pffi_type, parg.pffi_type.size);
@@ -269,7 +266,7 @@ static Object c_void_p_from_param(VirtualFrame frame, Object type, Object value,
@Cached CVoidPFromParamNode cVoidPFromParamNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached PyObjectLookupAttr lookupAttr,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
/* c_void_p instance (or subclass) */
boolean res = isInstanceNode.executeWith(frame, value, type);
@@ -292,7 +289,7 @@ static Object c_void_p_from_param(VirtualFrame frame, Object type, Object value,
}
/* function pointer */
if (value instanceof PyCFuncPtrObject func && pyTypeCheck.isPyCFuncPtrObject(inliningTarget, value)) {
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'P';
parg.valuePointer = func.b_ptr;
@@ -305,7 +302,7 @@ static Object c_void_p_from_param(VirtualFrame frame, Object type, Object value,
int code = codePointAtIndexNode.execute((TruffleString) stgd.proto, 0, TS_ENCODING);
/* c_char_p, c_wchar_p */
if (code == 'z' || code == 'Z') {
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'Z';
parg.obj = value;
@@ -338,8 +335,8 @@ static Object none(Object type, PNone value) {
@Specialization
static Object bytes(@SuppressWarnings("unused") Object type, PBytes value,
@Cached SetFuncNode setFuncNode,
- @Cached PythonObjectFactory factory) {
- PyCArgObject parg = factory.createCArgObject();
+ @Bind PythonLanguage language) {
+ PyCArgObject parg = PFactory.createCArgObject(language);
parg.pffi_type = ffi_type_pointer;
parg.tag = 'z';
parg.valuePointer = Pointer.allocate(parg.pffi_type, parg.pffi_type.size);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
index 1fba2fa8cd..43c604be2f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
@@ -58,6 +58,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -292,14 +293,14 @@ static Object doInt(CDataObject self, int index,
static Object doSlice(CDataObject self, PSlice slice,
@CachedLibrary("self") PythonBufferAccessLibrary bufferLib,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached PyCDataGetNode pyCDataGetNode,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached SliceUnpack sliceUnpack,
@Cached AdjustIndices adjustIndices,
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
- @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
StgDictObject stgdict = pyObjectStgDictNode.execute(inliningTarget, self);
assert stgdict != null : "Cannot be NULL for array object instances";
Object proto = stgdict.proto;
@@ -313,17 +314,17 @@ static Object doSlice(CDataObject self, PSlice slice,
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
if (slicelen <= 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
- if (sliceInfo.step == 1) {
- return factory.createBytes(ptr, sliceInfo.start, slicelen);
+ if (sliceInfo.start == 0 && sliceInfo.step == 1) {
+ return PFactory.createBytes(language, ptr, slicelen);
}
byte[] dest = new byte[slicelen];
for (int cur = sliceInfo.start, i = 0; i < slicelen; cur += sliceInfo.step, i++) {
dest[i] = ptr[cur];
}
- return factory.createBytes(dest);
+ return PFactory.createBytes(language, dest);
}
if (itemdict.getfunc == FieldDesc.u.getfunc) { // CTYPES_UNICODE
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
@@ -349,7 +350,7 @@ static Object doSlice(CDataObject self, PSlice slice,
for (int cur = sliceInfo.start, i = 0; i < slicelen; cur += sliceInfo.step, i++) {
np[i] = doInt(self, cur, inliningTarget, pyCDataGetNode, pyObjectStgDictNode);
}
- return factory.createList(np);
+ return PFactory.createList(language, np);
}
@Specialization(guards = "!isPSlice(item)", replaces = "doInt")
@@ -392,8 +393,8 @@ static int Array_length(CDataObject self) {
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
index d86a887fd2..c50d24a0b9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -82,7 +82,7 @@
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -120,7 +120,7 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
@Cached SetDictNode setDict,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
/*
* create the new instance (which is a class, since we are a metatype!)
@@ -151,7 +151,7 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
throw raiseNode.get(inliningTarget).raise(AttributeError, CLASS_MUST_DEFINE_A_TYPE_ATTRIBUTE);
}
- StgDictObject stgdict = factory.createStgDictObject(PythonBuiltinClassType.StgDict);
+ StgDictObject stgdict = PFactory.createStgDictObject(language);
StgDictObject itemdict = pyTypeStgDictNode.execute(inliningTarget, type_attr);
if (itemdict == null) {
@@ -193,7 +193,7 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
/* replace the class dict by our updated spam dict */
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
addAllToOtherNode.execute(frame, inliningTarget, resDict.getDictStorage(), stgdict);
setDict.execute(inliningTarget, (PythonObject) result, stgdict);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
index 710ced01fa..8ffc0a903e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -84,6 +84,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -134,7 +135,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -262,7 +263,7 @@ static Object error(@SuppressWarnings("unused") Object type, @SuppressWarnings("
}
static CThunkObject CThunkObjectNew(int nArgs) {
- CThunkObject p = PythonObjectFactory.getUncached().createCThunkObject(PythonBuiltinClassType.CThunkObject, nArgs);
+ CThunkObject p = PFactory.createCThunkObject(PythonLanguage.get(null), nArgs);
p.pcl_write = null;
p.pcl_exec = null;
@@ -415,19 +416,19 @@ protected abstract static class PointerArgTypesNode extends PythonBinaryBuiltinN
@Specialization(guards = {"isNoValue(value)", "self.argtypes != null"})
static Object PyCFuncPtr_get_argtypes(PyCFuncPtrObject self, @SuppressWarnings("unused") PNone value,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(self.argtypes);
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, self.argtypes);
}
@Specialization(guards = {"isNoValue(value)", "self.argtypes == null"})
static Object PyCFuncPtr_get_argtypes(PyCFuncPtrObject self, @SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
StgDictObject dict = pyObjectStgDictNode.execute(inliningTarget, self);
assert dict != null : "Cannot be NULL for PyCFuncPtrObject instances";
if (dict.argtypes != null) {
- return factory.createTuple(dict.argtypes);
+ return PFactory.createTuple(language, dict.argtypes);
} else {
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
index b0e2a51ef0..6a289c5bfc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -77,7 +78,7 @@
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -127,9 +128,9 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
@Cached PyCallableCheckNode callableCheck,
@Cached HashingStorageGetItem getItem,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
- StgDictObject stgdict = factory.createStgDictObject(PythonBuiltinClassType.StgDict);
+ StgDictObject stgdict = PFactory.createStgDictObject(language);
stgdict.paramfunc = CArgObjectBuiltins.PyCFuncPtrTypeParamFunc;
/*
@@ -147,7 +148,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
/* replace the class dict by our updated storage dict */
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
addAllToOtherNode.execute(frame, inliningTarget, resDict.getDictStorage(), stgdict);
setDict.execute(inliningTarget, result, stgdict);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
index fe771d6fd5..d03ce6ebfd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
@@ -61,6 +61,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -132,13 +133,13 @@ abstract static class PointerSetContentsNode extends Node {
@Specialization
static void set(VirtualFrame frame, Node inliningTarget, CDataObject self, Object value,
+ @Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
@Cached PRaiseNode.Lazy raiseNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached(inline = false) IsInstanceNode isInstanceNode,
@Cached KeepRefNode keepRefNode,
- @Cached PointerNodes.WritePointerNode writePointerNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached PointerNodes.WritePointerNode writePointerNode) {
if (value == null) {
throw raiseNode.get(inliningTarget).raise(TypeError, POINTER_DOES_NOT_SUPPORT_ITEM_DELETION);
}
@@ -162,7 +163,7 @@ static void set(VirtualFrame frame, Node inliningTarget, CDataObject self, Objec
*/
keepRefNode.execute(frame, inliningTarget, self, 1, value);
- Object keep = GetKeepedObjects(dst, factory);
+ Object keep = GetKeepedObjects(dst, language);
keepRefNode.execute(frame, inliningTarget, self, 0, keep);
}
}
@@ -332,6 +333,7 @@ static Object doInt(CDataObject self, int index,
@Specialization(limit = "1")
static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary("self") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached PyCDataGetNode pyCDataGetNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
@@ -340,7 +342,6 @@ static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
/*
* Since pointers have no length, and we want to apply different semantics to negative
@@ -387,16 +388,16 @@ static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
if (len <= 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
- if (step == 1) {
- return factory.createBytes(ptr, start, len);
+ if (start == 0 && step == 1) {
+ return PFactory.createBytes(language, ptr, len);
}
byte[] dest = new byte[len];
for (int cur = start, i = 0; i < len; cur += step, i++) {
dest[i] = ptr[cur];
}
- return factory.createBytes(dest);
+ return PFactory.createBytes(language, dest);
}
if (itemdict.getfunc == FieldDesc.u.getfunc) { // CTYPES_UNICODE
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
@@ -419,7 +420,7 @@ static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
for (int cur = start, i = 0; i < len; cur += step, i++) {
np[i] = PointerGetItemNode.Pointer_item(self, cur, inliningTarget, pyCDataGetNode, pyTypeStgDictNode, pyObjectStgDictNode, readPointerNode, raiseNode);
}
- return factory.createList(np);
+ return PFactory.createList(language, np);
}
@Specialization(guards = "!isPSlice(item)", replaces = "doInt")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
index 7bfb019725..885b2586f8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -84,7 +85,7 @@
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -128,13 +129,13 @@ static Object PyCPointerType_new(VirtualFrame frame, Object type, Object[] args,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
@Cached StringUtils.SimpleTruffleStringFormatNode formatNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
/*
* stgdict items size, align, length contain info about pointers itself, stgdict.proto
* has info about the pointed to type!
*/
- StgDictObject stgdict = factory.createStgDictObject(PythonBuiltinClassType.StgDict);
+ StgDictObject stgdict = PFactory.createStgDictObject(language);
stgdict.size = StgDictObject.VOID_PTR_SIZE;
stgdict.align = FieldDesc.P.pffi_type.alignment;
stgdict.length = 1;
@@ -168,7 +169,7 @@ static Object PyCPointerType_new(VirtualFrame frame, Object type, Object[] args,
/* replace the class dict by our updated spam dict */
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
addAllToOtherNode.execute(frame, inliningTarget, resDict.getDictStorage(), stgdict);
setDict.execute(inliningTarget, result, stgdict);
@@ -185,7 +186,6 @@ protected abstract static class FromParamNode extends PythonBinaryBuiltinNode {
/* _byref consumes a refcount to its argument */
static PyCArgObject byref(Node inliningTarget, Object obj,
PyTypeCheck pyTypeCheck,
- PythonObjectFactory factory,
PRaiseNode.Lazy raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, EXPECTED_CDATA_INSTANCE);
@@ -193,7 +193,7 @@ static PyCArgObject byref(Node inliningTarget, Object obj,
CDataObject cdata = (CDataObject) obj;
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(PythonLanguage.get(inliningTarget));
parg.tag = 'P';
parg.pffi_type = ffi_type_pointer;
parg.obj = cdata;
@@ -217,7 +217,6 @@ static Object PyCPointerType_from_param(VirtualFrame frame, Object type, Object
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CDataTypeFromParamNode fromParamNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
StgDictObject typedict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
/*
@@ -225,7 +224,7 @@ static Object PyCPointerType_from_param(VirtualFrame frame, Object type, Object
* byref().
*/
if (isInstanceNode.executeWith(frame, value, typedict.proto)) {
- return byref(inliningTarget, value, pyTypeCheck, factory, raiseNode);
+ return byref(inliningTarget, value, pyTypeCheck, raiseNode);
}
if (pyTypeCheck.isPointerObject(inliningTarget, value) || pyTypeCheck.isArrayObject(inliningTarget, value)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
index 56265f5393..fefdf623ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
@@ -42,7 +42,6 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PyCSimpleType;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SimpleCData;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StgDict;
import static com.oracle.graal.python.builtins.modules.ctypes.CDataTypeBuiltins.J_FROM_PARAM;
import static com.oracle.graal.python.builtins.modules.ctypes.CDataTypeBuiltins.T__AS_PARAMETER_;
import static com.oracle.graal.python.builtins.modules.ctypes.CtypesModuleBuiltins.TYPEFLAG_ISPOINTER;
@@ -95,8 +94,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -153,7 +151,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.EqualNode eqNode,
@Cached TruffleString.FromCharArrayUTF16Node fromCharArrayNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
/*
@@ -186,7 +184,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
throw raiseNode.get(inliningTarget).raise(ValueError, TYPE_S_NOT_SUPPORTED, proto_str);
}
- StgDictObject stgdict = factory.createStgDictObject(StgDict);
+ StgDictObject stgdict = PFactory.createStgDictObject(language);
stgdict.ffi_type_pointer = fmt.pffi_type;
stgdict.align = fmt.pffi_type.alignment;
@@ -204,7 +202,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
/* replace the class dict by our updated spam dict */
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
addAllToOtherNode.execute(frame, inliningTarget, resDict.getDictStorage(), stgdict);
setDict.execute(inliningTarget, (PythonObject) result, stgdict);
@@ -214,18 +212,16 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
* PyCSimpleType_from_param generic method.
*/
PythonContext context = PythonContext.get(inliningTarget);
- PythonObjectSlowPathFactory slowPathFactory = context.factory();
if (getBaseClassNode.execute(inliningTarget, result) == context.lookupType(SimpleCData)) {
- PythonLanguage language = context.getLanguage();
if (eqNode.execute(T_LOWER_Z, proto_str, TS_ENCODING)) { /* c_char_p */
- LazyPyCSimpleTypeBuiltins.addCCharPFromParam(slowPathFactory, language, result);
+ LazyPyCSimpleTypeBuiltins.addCCharPFromParam(language, result);
stgdict.flags |= TYPEFLAG_ISPOINTER;
} else if (eqNode.execute(T_UPPER_Z, proto_str, TS_ENCODING)) { /* c_wchar_p */
- LazyPyCSimpleTypeBuiltins.addCWCharPFromParam(slowPathFactory, language, result);
+ LazyPyCSimpleTypeBuiltins.addCWCharPFromParam(language, result);
stgdict.flags |= TYPEFLAG_ISPOINTER;
} else if (eqNode.execute(T_UPPER_P, proto_str, TS_ENCODING)) { /* c_void_p */
- LazyPyCSimpleTypeBuiltins.addCVoidPFromParam(slowPathFactory, language, result);
+ LazyPyCSimpleTypeBuiltins.addCVoidPFromParam(language, result);
stgdict.flags |= TYPEFLAG_ISPOINTER;
} else if (eqNode.execute(T_LOWER_S, proto_str, TS_ENCODING) ||
eqNode.execute(T_UPPER_X, proto_str, TS_ENCODING) ||
@@ -241,8 +237,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
toTruffleStringNode,
getDict,
setDict,
- addAllToOtherNode,
- factory);
+ addAllToOtherNode);
StgDictObject sw_dict = pyTypeStgDictNode.execute(inliningTarget, swapped);
setAttrString.execute(frame, inliningTarget, result, T_CTYPE_BE, swapped);
setAttrString.execute(frame, inliningTarget, result, T_CTYPE_LE, result);
@@ -262,8 +257,7 @@ private static Object CreateSwappedType(VirtualFrame frame, Node inliningTarget,
CastToTruffleStringNode toString,
GetDictIfExistsNode getDict,
SetDictNode setDict,
- HashingStorageAddAllToOther addAllToOther,
- PythonObjectFactory factory) {
+ HashingStorageAddAllToOther addAllToOther) {
int argsLen = args.length;
Object[] swapped_args = new Object[argsLen];
TruffleString suffix = toString.execute(inliningTarget, internStringNode.execute(inliningTarget, T__BE));
@@ -277,7 +271,8 @@ private static Object CreateSwappedType(VirtualFrame frame, Node inliningTarget,
* create the new instance (which is a class, since we are a metatype!)
*/
Object result = typeNew.execute(frame, type, swapped_args[0], swapped_args[1], swapped_args[2], kwds);
- StgDictObject stgdict = factory.createStgDictObject(StgDict);
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
+ StgDictObject stgdict = PFactory.createStgDictObject(language);
stgdict.ffi_type_pointer = fmt.pffi_type;
stgdict.align = fmt.pffi_type.alignment;
stgdict.length = 0;
@@ -290,7 +285,7 @@ private static Object CreateSwappedType(VirtualFrame frame, Node inliningTarget,
/* replace the class dict by our updated spam dict */
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
addAllToOther.execute(frame, inliningTarget, resDict.getDictStorage(), stgdict);
setDict.execute(inliningTarget, (PythonObject) result, stgdict);
@@ -314,7 +309,6 @@ static Object PyCSimpleType_from_param(VirtualFrame frame, Object type, Object v
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectLookupAttr lookupAsParam,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
/*
* If the value is already an instance of the requested type, we can use it as is
@@ -333,7 +327,7 @@ static Object PyCSimpleType_from_param(VirtualFrame frame, Object type, Object v
FieldDesc fd = FFIType._ctypes_get_fielddesc(code);
assert fd != null;
- PyCArgObject parg = factory.createCArgObject();
+ PyCArgObject parg = PFactory.createCArgObject(PythonLanguage.get(inliningTarget));
parg.tag = code;
parg.pffi_type = fd.pffi_type;
parg.valuePointer = Pointer.allocate(parg.pffi_type, dict.size);
@@ -347,7 +341,7 @@ static Object PyCSimpleType_from_param(VirtualFrame frame, Object type, Object v
Object as_parameter = lookupAsParam.execute(frame, inliningTarget, value, T__AS_PARAMETER_);
if (as_parameter != PNone.NO_VALUE) {
// Py_EnterRecursiveCall("while processing _as_parameter_"); TODO
- Object r = PyCSimpleType_from_param(frame, type, as_parameter, inliningTarget, setFuncNode, isInstanceNode, pyTypeStgDictNode, lookupAsParam, codePointAtIndexNode, factory, raiseNode);
+ Object r = PyCSimpleType_from_param(frame, type, as_parameter, inliningTarget, setFuncNode, isInstanceNode, pyTypeStgDictNode, lookupAsParam, codePointAtIndexNode, raiseNode);
// Py_LeaveRecursiveCall();
return r;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCStructTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCStructTypeBuiltins.java
index 04d9ba26cb..fcdcb1ddeb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCStructTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCStructTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,7 +59,6 @@
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.SetAttrBuiltinNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -92,13 +91,12 @@ protected abstract static class SetattrNode extends SetAttrBuiltinNode {
void doStringKey(VirtualFrame frame, Object object, TruffleString key, Object value,
@Shared @Cached TypeBuiltins.SetattrNode typeSetAttr,
@Shared @Cached TruffleString.EqualNode equalNode,
- @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict) {
// CPython just delegates to "PyType_Type.tp_setattro" with the comment:
/* XXX Should we disallow deleting _fields_? */
typeSetAttr.executeSetAttr(frame, object, key, value);
if (equalNode.execute(key, StructUnionTypeBuiltins.T__FIELDS_, TS_ENCODING)) {
- updateStgDict.execute(frame, object, value, true, factory);
+ updateStgDict.execute(frame, object, value, true);
}
}
@@ -109,10 +107,9 @@ void doGeneric(VirtualFrame frame, Object object, Object keyObject, Object value
@Cached CastToTruffleStringCheckedNode castKeyToStringNode,
@Shared @Cached TypeBuiltins.SetattrNode typeSetAttr,
@Shared @Cached TruffleString.EqualNode equalNode,
- @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict) {
TruffleString key = castKeyToStringNode.cast(inliningTarget, keyObject, ATTR_NAME_MUST_BE_STRING, keyObject);
- doStringKey(frame, object, key, value, typeSetAttr, equalNode, updateStgDict, factory);
+ doStringKey(frame, object, key, value, typeSetAttr, equalNode, updateStgDict);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
index 5d7f407ed3..5be831605e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
@@ -90,7 +90,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -171,12 +171,12 @@ Object doit(VirtualFrame frame, StgDictObject self,
@SuppressWarnings("truffle-inlining") // footprint reduction 112 -> 94
protected abstract static class MakeFieldsNode extends PNodeWithContext {
- abstract void execute(VirtualFrame frame, Object type, CFieldObject descr, int index, int offset, PythonObjectFactory factory);
+ abstract void execute(VirtualFrame frame, Object type, CFieldObject descr, int index, int offset);
@TruffleBoundary
- private void executeBoundary(Object type, CFieldObject descr, int index, int offset, PythonObjectFactory factory) {
+ private void executeBoundary(Object type, CFieldObject descr, int index, int offset) {
// recursive calls are done as boundary calls to avoid too many deopts
- execute(null, type, descr, index, offset, factory);
+ execute(null, type, descr, index, offset);
}
/*
@@ -185,7 +185,7 @@ private void executeBoundary(Object type, CFieldObject descr, int index, int off
* into type.
*/
@Specialization
- static void MakeFields(VirtualFrame frame, Object type, CFieldObject descr, int index, int offset, PythonObjectFactory factory,
+ static void MakeFields(VirtualFrame frame, Object type, CFieldObject descr, int index, int offset,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetAttrO getAttributeNode,
@@ -220,13 +220,13 @@ static void MakeFields(VirtualFrame frame, Object type, CFieldObject descr, int
if (fdescr.anonymous != 0) {
Object state = IndirectCallContext.enter(frame, language, context, indirectCallData);
try {
- recursiveNode.executeBoundary(type, fdescr, index + fdescr.index, offset + fdescr.offset, context.factory());
+ recursiveNode.executeBoundary(type, fdescr, index + fdescr.index, offset + fdescr.offset);
} finally {
IndirectCallContext.exit(frame, language, context, state);
}
continue;
}
- CFieldObject new_descr = factory.createCFieldObject(CField);
+ CFieldObject new_descr = PFactory.createCFieldObject(language);
// assert (Py_TYPE(new_descr) == PythonBuiltinClassType.CField);
new_descr.size = fdescr.size;
new_descr.offset = fdescr.offset + offset;
@@ -305,13 +305,13 @@ static StgDictObject PyObject_stgdict(Node inliningTarget, Object self,
@SuppressWarnings("truffle-inlining") // footprint reduction 132 -> 115
protected abstract static class MakeAnonFieldsNode extends Node {
- abstract void execute(VirtualFrame frame, Object type, PythonObjectFactory factory);
+ abstract void execute(VirtualFrame frame, Object type);
/*
* Iterate over the names in the type's _anonymous_ attribute, if present,
*/
@Specialization
- static void MakeAnonFields(VirtualFrame frame, Object type, PythonObjectFactory factory,
+ static void MakeAnonFields(VirtualFrame frame, Object type,
@Bind("this") Node inliningTarget,
@Cached PySequenceCheckNode sequenceCheckNode,
@Cached PyObjectSizeNode sizeNode,
@@ -338,7 +338,7 @@ static void MakeAnonFields(VirtualFrame frame, Object type, PythonObjectFactory
descr.anonymous = 1;
/* descr is in the field descriptor. */
- makeFieldsNode.execute(frame, type, descr, descr.index, descr.offset, factory);
+ makeFieldsNode.execute(frame, type, descr, descr.index, descr.offset);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
index ec38eb8b2a..76692aed21 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -66,6 +66,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -104,7 +105,7 @@
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -148,6 +149,7 @@ protected boolean isStruct() {
@Specialization
protected Object StructUnionTypeNew(VirtualFrame frame, Object type, Object[] args, PKeyword[] kwds,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
@Cached HashingStorageGetItem getItemResDict,
@Cached HashingStorageGetItem getItemStgDict,
@@ -156,8 +158,7 @@ protected Object StructUnionTypeNew(VirtualFrame frame, Object type, Object[] ar
@Cached GetDictIfExistsNode getDict,
@Cached SetDictNode setDict,
@Cached GetBaseClassNode getBaseClassNode,
- @Cached PyObjectSetAttr setFieldsAttributeNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectSetAttr setFieldsAttributeNode) {
/*
* create the new instance (which is a class, since we are a metatype!)
*/
@@ -165,13 +166,13 @@ protected Object StructUnionTypeNew(VirtualFrame frame, Object type, Object[] ar
PDict resDict = getDict.execute(result);
if (resDict == null) {
- resDict = factory.createDictFixedStorage((PythonObject) result);
+ resDict = PFactory.createDictFixedStorage(language, (PythonObject) result);
}
if (getItemResDict.hasKey(inliningTarget, resDict.getDictStorage(), T__ABSTRACT_)) {
return result;
}
- StgDictObject dict = factory.createStgDictObject(PythonBuiltinClassType.StgDict);
+ StgDictObject dict = PFactory.createStgDictObject(language);
if (!isStruct()) {
dict.flags |= TYPEFLAG_HASUNION;
}
@@ -205,7 +206,7 @@ protected Object StructUnionTypeNew(VirtualFrame frame, Object type, Object[] ar
@ImportStatic(StructUnionTypeBuiltins.class)
@SuppressWarnings("truffle-inlining") // footprint reduction 292 -> 275
protected abstract static class PyCStructUnionTypeUpdateStgDict extends Node {
- abstract void execute(VirtualFrame frame, Object type, Object fields, boolean isStruct, PythonObjectFactory factory);
+ abstract void execute(VirtualFrame frame, Object type, Object fields, boolean isStruct);
/*
* Retrieve the (optional) _pack_ attribute from a type, the _fields_ attribute, and create
@@ -213,7 +214,7 @@ protected abstract static class PyCStructUnionTypeUpdateStgDict extends Node {
*/
@SuppressWarnings("fallthrough")
@Specialization
- static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, Object fields, boolean isStruct, PythonObjectFactory factory,
+ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, Object fields, boolean isStruct,
@Bind("this") Node inliningTarget,
@Cached PyTypeCheck pyTypeCheck,
@Cached GetInternalObjectArrayNode getArray,
@@ -321,7 +322,6 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
for (int idx = 0; idx < len + 1; idx++) {
stgdict.ffi_type_pointer.elements[idx] = new FFIType();
}
-
*/
ffi_ofs = 0;
}
@@ -412,7 +412,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
CFieldObject prop;
if (isStruct) {
int[] props = new int[]{field_size, bitofs, size, offset, align};
- prop = cFieldFromDesc.execute(inliningTarget, desc, i, bitsize, pack, big_endian, props, factory);
+ prop = cFieldFromDesc.execute(inliningTarget, desc, i, bitsize, pack, big_endian, props);
field_size = props[0];
bitofs = props[1];
size = props[2];
@@ -426,7 +426,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
offset = 0;
align = 0;
int[] props = new int[]{field_size, bitofs, size, offset, align};
- prop = cFieldFromDesc.execute(inliningTarget, desc, i, bitsize, pack, big_endian, props, factory);
+ prop = cFieldFromDesc.execute(inliningTarget, desc, i, bitsize, pack, big_endian, props);
field_size = props[0];
bitofs = props[1];
size = props[2];
@@ -516,7 +516,6 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
fieldsError();
}
Object desc = tuple[1];
-
StgDictObject dict = pyTypeStgDictNode.execute(desc);
if (dict == null) {
throw raise(TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
@@ -612,7 +611,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
}
stgdict.flags |= DICTFLAG_FINAL;
- makeAnonFieldsNode.execute(frame, type, factory);
+ makeAnonFieldsNode.execute(frame, type);
}
static void fieldsError(PRaiseNode raiseNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
index 4b494e6811..2f7f6f3093 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -61,7 +61,6 @@
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -102,10 +101,9 @@ static void doStringKey(VirtualFrame frame, Object object, TruffleString key, Ob
@Exclusive @Cached ObjectNodes.GenericSetAttrNode genericSetAttrNode,
@Shared @Cached WriteAttributeToObjectNode write,
@Shared @Cached TruffleString.EqualNode equalNode,
- @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict) {
genericSetAttrNode.execute(inliningTarget, frame, object, key, value, write);
- updateStgDictIfNecessary(frame, object, key, value, equalNode, updateStgDict, factory);
+ updateStgDictIfNecessary(frame, object, key, value, equalNode, updateStgDict);
}
// @Exclusive to address warning
@@ -118,17 +116,16 @@ static void doGenericKey(VirtualFrame frame, Object object, Object keyObject, Ob
@Exclusive @Cached ObjectNodes.GenericSetAttrNode genericSetAttrNode,
@Shared @Cached WriteAttributeToObjectNode write,
@Shared @Cached TruffleString.EqualNode equalNode,
- @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PyCStructUnionTypeUpdateStgDict updateStgDict) {
TruffleString key = GenericSetAttrNode.castAttributeKey(inliningTarget, keyObject, castKeyNode, raiseNode);
genericSetAttrNode.execute(inliningTarget, frame, object, key, value, write);
- updateStgDictIfNecessary(frame, object, key, value, equalNode, updateStgDict, factory);
+ updateStgDictIfNecessary(frame, object, key, value, equalNode, updateStgDict);
}
private static void updateStgDictIfNecessary(VirtualFrame frame, Object object, TruffleString key, Object value,
- EqualNode equalNode, PyCStructUnionTypeUpdateStgDict updateStgDict, PythonObjectFactory factory) {
+ EqualNode equalNode, PyCStructUnionTypeUpdateStgDict updateStgDict) {
if (equalNode.execute(key, StructUnionTypeBuiltins.T__FIELDS_, TS_ENCODING)) {
- updateStgDict.execute(frame, object, value, false, factory);
+ updateStgDict.execute(frame, object, value, false);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
index 80fa1baef0..3c0ca89832 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -65,7 +66,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -100,7 +101,7 @@ public void initialize(Python3Core core) {
"\n" + //
"cache_info_type: namedtuple class with the fields:\n" + //
" hits misses currsize maxsize\n");
- core.lookupBuiltinModule(T_FUNCTOOLS).setModuleState(core.factory().createPythonObject(PythonObject));
+ core.lookupBuiltinModule(T_FUNCTOOLS).setModuleState(PFactory.createPythonObject(core.getLanguage(), PythonObject, PythonObject.getInstanceShape(core.getLanguage())));
}
// functools.reduce(function, iterable[, initializer])
@@ -172,8 +173,8 @@ Object doReduce(VirtualFrame frame, Object function, Object sequence, Object ini
public abstract static class CmpToKeyNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doConvert(Object myCmp,
- @Cached PythonObjectFactory factory) {
- return factory.createKeyWrapper(myCmp);
+ @Bind PythonLanguage language) {
+ return PFactory.createKeyWrapper(language, myCmp);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
index 7dc439de6a..22456534d6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -63,7 +64,7 @@
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
@@ -174,8 +175,8 @@ BinaryComparisonNode createCmp() {
public abstract static class KWCallNode extends PythonBinaryBuiltinNode {
@Specialization
static Object call(PKeyWrapper self, Object obj,
- @Cached PythonObjectFactory factory) {
- final PKeyWrapper keyWrapper = factory.createKeyWrapper(self.getCmp());
+ @Bind PythonLanguage language) {
+ final PKeyWrapper keyWrapper = PFactory.createKeyWrapper(language, self.getCmp());
keyWrapper.setObject(obj);
return keyWrapper;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
index 99a8b38fa2..9d540461cd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -56,6 +56,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -71,6 +72,7 @@
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.DescrGetBuiltinNode;
import com.oracle.graal.python.lib.PyCallableCheckNode;
import com.oracle.graal.python.lib.PyIndexCheckNode;
@@ -93,7 +95,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -147,7 +149,7 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
@Cached PyCallableCheckNode callableCheck,
@Cached PyIndexCheckNode indexCheck,
@Cached PyNumberAsSizeNode numberAsSize,
- @Cached PythonObjectFactory factory,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!callableCheck.execute(inliningTarget, func)) {
@@ -175,7 +177,8 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
throw raiseNode.get(inliningTarget).raise(TypeError, MAXSIZE_SHOULD_BE_INTEGER_OR_NONE);
}
- LruCacheObject obj = factory.createLruCacheObject(type);
+ PythonContext context = PythonContext.get(inliningTarget);
+ LruCacheObject obj = PFactory.createLruCacheObject(context.getLanguage(inliningTarget), type, getInstanceShape.execute(type));
obj.root.prev = obj.root;
obj.root.next = obj.root;
@@ -187,7 +190,7 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
obj.misses = obj.hits = 0;
obj.maxsize = maxsize;
- obj.kwdMark = PythonContext.get(inliningTarget).lookupBuiltinModule(T_FUNCTOOLS).getModuleState(Object.class);
+ obj.kwdMark = context.lookupBuiltinModule(T_FUNCTOOLS).getModuleState(Object.class);
obj.cacheInfoType = cache_info_type;
// obj.dict = null;
@@ -288,8 +291,7 @@ static Object lruCacheMakeKey(Object kwdMark, Object[] args, PKeyword[] kwds, in
Node inliningTarget,
GetClassNode getClassNode,
PyUnicodeCheckExactNode unicodeCheckExact,
- PyLongCheckExactNode longCheckExact,
- PythonObjectFactory factory) {
+ PyLongCheckExactNode longCheckExact) {
int kwdsSize = kwds.length;
/* short path, key will match args anyway, which is a tuple */
if (typed == 0 && kwdsSize == 0) {
@@ -303,7 +305,7 @@ static Object lruCacheMakeKey(Object kwdMark, Object[] args, PKeyword[] kwds, in
}
}
- return factory.createTuple(args);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), args);
}
int argsLen = args.length;
int keySize = args.length;
@@ -338,7 +340,7 @@ static Object lruCacheMakeKey(Object kwdMark, Object[] args, PKeyword[] kwds, in
}
}
assert (keyPos == keySize);
- return factory.createTuple(keyArray);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), keyArray);
}
// infinite_lru_cache_wrapper
@@ -531,10 +533,9 @@ static Object cachedLruCacheWrapper(VirtualFrame frame, LruCacheObject self, Obj
@Cached PyUnicodeCheckExactNode unicodeCheckExact,
@Cached PyLongCheckExactNode longCheckExact,
@Cached ObjectHashMap.RemoveNode popItem,
- @Cached InlinedConditionProfile profile,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile profile) {
Object key = lruCacheMakeKey(self.kwdMark, args, kwds, self.typed,
- inliningTarget, getClassNode, unicodeCheckExact, longCheckExact, factory);
+ inliningTarget, getClassNode, unicodeCheckExact, longCheckExact);
long hash = hashNode.execute(frame, inliningTarget, key);
Object cached = getItem.execute(frame, inliningTarget, self.cache, key, hash);
if (profile.profile(inliningTarget, self.isInfinite())) {
@@ -582,12 +583,11 @@ abstract static class GetNode extends DescrGetBuiltinNode {
@Specialization
static Object getmethod(LruCacheObject self, Object obj, @SuppressWarnings("unused") Object type,
@Bind("this") Node inliningTarget,
- @Cached InlinedConditionProfile objIsNoneProfile,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile objIsNoneProfile) {
if (objIsNoneProfile.profile(inliningTarget, obj instanceof PNone)) {
return self;
}
- return factory.createMethod(obj, self);
+ return PFactory.createMethod(PythonLanguage.get(inliningTarget), obj, self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PPartial.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PPartial.java
index 9dfdb02743..7cc36b701b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PPartial.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PPartial.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.modules.functools;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageCopy;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
@@ -47,7 +48,7 @@
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
@@ -76,9 +77,9 @@ public Object[] getArgs() {
return args;
}
- public PTuple getArgsTuple(PythonObjectFactory factory) {
+ public PTuple getArgsTuple(PythonLanguage language) {
if (argsTuple == null) {
- this.argsTuple = factory.createTuple(args);
+ this.argsTuple = PFactory.createTuple(language, args);
}
return argsTuple;
}
@@ -92,16 +93,16 @@ public PDict getKw() {
return kw;
}
- public PDict getOrCreateKw(PythonObjectFactory factory) {
+ public PDict getOrCreateKw(PythonLanguage language) {
if (kw == null) {
- kw = factory.createDict();
+ kw = PFactory.createDict(language);
}
return kw;
}
- public PDict getKwCopy(Node inliningTarget, PythonObjectFactory factory, HashingStorageCopy copyNode) {
+ public PDict getKwCopy(Node inliningTarget, PythonLanguage language, HashingStorageCopy copyNode) {
assert kw != null;
- return factory.createDict(copyNode.execute(inliningTarget, kw.getDictStorage()));
+ return PFactory.createDict(language, copyNode.execute(inliningTarget, kw.getDictStorage()));
}
public boolean hasKw(Node inliningTarget, HashingStorageLen lenNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
index ec3601c9e1..b7bfb230c8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -60,6 +60,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -104,7 +105,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -176,19 +177,20 @@ static Object createFromPartialWoDictWoKw(Object cls, Object[] args, PKeyword[]
@Exclusive @Cached InlinedConditionProfile hasArgsProfile,
@Exclusive @Cached InlinedConditionProfile hasKeywordsProfile,
@Exclusive @SuppressWarnings("unused") @Cached HashingStorageLen lenNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
assert args[0] instanceof PPartial;
final PPartial function = (PPartial) args[0];
Object[] funcArgs = getNewPartialArgs(function, args, inliningTarget, hasArgsProfile, 1);
PDict funcKwDict;
if (hasKeywordsProfile.profile(inliningTarget, keywords.length > 0)) {
- funcKwDict = factory.createDict(keywords);
+ funcKwDict = PFactory.createDict(language, keywords);
} else {
- funcKwDict = factory.createDict();
+ funcKwDict = PFactory.createDict(language);
}
- return factory.createPartial(cls, function.getFn(), funcArgs, funcKwDict);
+ return PFactory.createPartial(language, cls, getInstanceShape.execute(cls), function.getFn(), funcArgs, funcKwDict);
}
@Specialization(guards = {"atLeastOneArg(args)", "isPartialWithoutDict(inliningTarget, getDict, args, lenNode, true)", "!withKeywords(keywords)"}, limit = "1")
@@ -198,11 +200,12 @@ static Object createFromPartialWoDictWKw(Object cls, Object[] args, @SuppressWar
@Exclusive @Cached InlinedConditionProfile hasArgsProfile,
@Exclusive @SuppressWarnings("unused") @Cached HashingStorageLen lenNode,
@Exclusive @Cached HashingStorageCopy copyNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
assert args[0] instanceof PPartial;
final PPartial function = (PPartial) args[0];
Object[] funcArgs = getNewPartialArgs(function, args, inliningTarget, hasArgsProfile, 1);
- return factory.createPartial(cls, function.getFn(), funcArgs, function.getKwCopy(inliningTarget, factory, copyNode));
+ return PFactory.createPartial(language, cls, getInstanceShape.execute(cls), function.getFn(), funcArgs, function.getKwCopy(inliningTarget, language, copyNode));
}
@Specialization(guards = {"atLeastOneArg(args)", "isPartialWithoutDict(inliningTarget, getDict, args, lenNode, true)", "withKeywords(keywords)"}, limit = "1")
@@ -214,16 +217,17 @@ static Object createFromPartialWoDictWKwKw(VirtualFrame frame, Object cls, Objec
@Exclusive @SuppressWarnings("unused") @Cached HashingStorageLen lenNode,
@Exclusive @Cached HashingStorageCopy copyHashingStorageNode,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) {
assert args[0] instanceof PPartial;
final PPartial function = (PPartial) args[0];
Object[] funcArgs = getNewPartialArgs(function, args, inliningTarget, hasArgsProfile, 1);
HashingStorage storage = copyHashingStorageNode.execute(inliningTarget, function.getKw().getDictStorage());
- PDict result = factory.createDict(storage);
+ PDict result = PFactory.createDict(language, storage);
addAllToOtherNode.execute(frame, inliningTarget, initNode.execute(frame, PNone.NO_VALUE, keywords), result);
- return factory.createPartial(cls, function.getFn(), funcArgs, result);
+ return PFactory.createPartial(language, cls, getInstanceShape.execute(cls), function.getFn(), funcArgs, result);
}
@Specialization(guards = {"atLeastOneArg(args)", "!isPartialWithoutDict(getDict, args)"}, limit = "1")
@@ -232,7 +236,8 @@ static Object createGeneric(Object cls, Object[] args, PKeyword[] keywords,
@SuppressWarnings("unused") @Exclusive @Cached GetDictIfExistsNode getDict,
@Exclusive @Cached InlinedConditionProfile hasKeywordsProfile,
@Cached PyCallableCheckNode callableCheckNode,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
Object function = args[0];
if (!callableCheckNode.execute(inliningTarget, function)) {
@@ -242,11 +247,11 @@ static Object createGeneric(Object cls, Object[] args, PKeyword[] keywords,
final Object[] funcArgs = PythonUtils.arrayCopyOfRange(args, 1, args.length);
PDict funcKwDict;
if (hasKeywordsProfile.profile(inliningTarget, keywords.length > 0)) {
- funcKwDict = factory.createDict(keywords);
+ funcKwDict = PFactory.createDict(language, keywords);
} else {
- funcKwDict = factory.createDict();
+ funcKwDict = PFactory.createDict(language);
}
- return factory.createPartial(cls, function, funcArgs, funcKwDict);
+ return PFactory.createPartial(language, cls, getInstanceShape.execute(cls), function, funcArgs, funcKwDict);
}
@Specialization(guards = "!atLeastOneArg(args)")
@@ -271,8 +276,8 @@ static Object doGet(PPartial self) {
public abstract static class PartialArgsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doGet(PPartial self,
- @Cached PythonObjectFactory factory) {
- return self.getArgsTuple(factory);
+ @Bind PythonLanguage language) {
+ return self.getArgsTuple(language);
}
}
@@ -307,8 +312,8 @@ static Object setDict(@SuppressWarnings("unused") PPartial self, Object mapping,
public abstract static class PartialKeywordsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doGet(PPartial self,
- @Cached PythonObjectFactory factory) {
- return self.getOrCreateKw(factory);
+ @Bind PythonLanguage language) {
+ return self.getOrCreateKw(language);
}
}
@@ -321,7 +326,7 @@ static Object reduce(PPartial self,
@Cached GetClassNode getClassNode,
@Cached GetDictIfExistsNode getDictIfExistsNode,
@Cached GetOrCreateDictNode getOrCreateDictNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
final PDict dict;
if (self.getShape().getPropertyCount() > 0) {
dict = getOrCreateDictNode.execute(inliningTarget, self);
@@ -329,9 +334,9 @@ static Object reduce(PPartial self,
dict = getDictIfExistsNode.execute(self);
}
final Object type = getClassNode.execute(inliningTarget, self);
- final PTuple fnTuple = factory.createTuple(new Object[]{self.getFn()});
- final PTuple argsTuple = factory.createTuple(new Object[]{self.getFn(), self.getArgsTuple(factory), self.getKw(), (dict != null) ? dict : PNone.NONE});
- return factory.createTuple(new Object[]{type, fnTuple, argsTuple});
+ final PTuple fnTuple = PFactory.createTuple(language, new Object[]{self.getFn()});
+ final PTuple argsTuple = PFactory.createTuple(language, new Object[]{self.getFn(), self.getArgsTuple(language), self.getKw(), (dict != null) ? dict : PNone.NONE});
+ return PFactory.createTuple(language, new Object[]{type, fnTuple, argsTuple});
}
}
@@ -352,7 +357,7 @@ static Object setState(VirtualFrame frame, PPartial self, PTuple state,
@Cached PyTupleGetItem getItemNode,
@Cached TupleNodes.ConstructTupleNode constructTupleNode,
@Cached HashingStorageCopy copyStorageNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (state.getSequenceStorage().length() != 4) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
@@ -381,9 +386,9 @@ static Object setState(VirtualFrame frame, PPartial self, PTuple state,
final PDict fnKwargsDict;
if (fnKwargs == PNone.NONE) {
- fnKwargsDict = factory.createDict();
+ fnKwargsDict = PFactory.createDict(language);
} else if (!dictCheckExactNode.execute(inliningTarget, fnKwargs)) {
- fnKwargsDict = factory.createDict(copyStorageNode.execute(inliningTarget, ((PDict) fnKwargs).getDictStorage()));
+ fnKwargsDict = PFactory.createDict(language, copyStorageNode.execute(inliningTarget, ((PDict) fnKwargs).getDictStorage()));
} else {
fnKwargsDict = (PDict) fnKwargs;
}
@@ -544,8 +549,8 @@ public static TruffleString repr(VirtualFrame frame, PPartial partial,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObject.java
index 38f3faef1e..180a253237 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,9 +44,10 @@
import javax.crypto.Mac;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.Shape;
@@ -199,7 +200,7 @@ private PythonBuiltinClassType determineMainDigestType() {
*/
abstract void update(byte[] data, int length);
- abstract DigestObject copy(PythonObjectFactory factory) throws CloneNotSupportedException;
+ abstract DigestObject copy() throws CloneNotSupportedException;
abstract int getDigestLength();
@@ -263,8 +264,8 @@ private static final class MessageDigestObject extends DigestObjectBase {
@Override
@TruffleBoundary
- DigestObject copy(PythonObjectFactory factory) throws CloneNotSupportedException {
- return factory.createDigestObject(getType(), getAlgorithm(), digest.clone());
+ DigestObject copy() throws CloneNotSupportedException {
+ return PFactory.createDigestObject(PythonLanguage.get(null), getType(), getAlgorithm(), digest.clone());
}
@Override
@@ -302,8 +303,8 @@ private static final class MacDigestObject extends DigestObjectBase {
@Override
@TruffleBoundary
- DigestObject copy(PythonObjectFactory factory) throws CloneNotSupportedException {
- return factory.createDigestObject(getType(), getAlgorithm(), mac.clone());
+ DigestObject copy() throws CloneNotSupportedException {
+ return PFactory.createDigestObject(PythonLanguage.get(null), getType(), getAlgorithm(), mac.clone());
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
index 80ed174aa8..a8678ca506 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -59,7 +60,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -89,10 +90,9 @@ abstract static class CopyNode extends PythonUnaryBuiltinNode {
@Specialization
static DigestObject copy(DigestObject self,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
- return self.copy(factory);
+ return self.copy();
} catch (CloneNotSupportedException e) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError);
}
@@ -104,8 +104,8 @@ static DigestObject copy(DigestObject self,
abstract static class DigestNode extends PythonUnaryBuiltinNode {
@Specialization
static PBytes digest(DigestObject self,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(self.digest());
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, self.digest());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
index 0ff93cf187..9dff6e5708 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -60,6 +60,7 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -87,7 +88,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -158,10 +159,11 @@ public void initialize(Python3Core core) {
for (var digest : DIGEST_ALGORITHMS) {
algos.putUncachedWithJavaEq(digest, PNone.NONE);
}
- addBuiltinConstant("openssl_md_meth_names", core.factory().createFrozenSet(algos));
+ PythonLanguage language = core.getLanguage();
+ addBuiltinConstant("openssl_md_meth_names", PFactory.createFrozenSet(language, algos));
EconomicMapStorage storage = EconomicMapStorage.create();
- addBuiltinConstant(J_CONSTRUCTORS, core.factory().createMappingproxy(core.factory().createDict(storage)));
+ addBuiltinConstant(J_CONSTRUCTORS, PFactory.createMappingproxy(language, PFactory.createDict(language, storage)));
core.lookupBuiltinModule(T_HASHLIB).setModuleState(storage);
super.initialize(core);
}
@@ -283,14 +285,13 @@ static Object hmacNewFromFunction(VirtualFrame frame, PythonModule self, Object
@Shared("concatStr") @Cached TruffleString.ConcatNode concatStr,
@Shared("acquireLib") @CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@Shared("bufferLib") @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
// cast guaranteed in our initialize
EconomicMapStorage constructors = self.getModuleState(EconomicMapStorage.class);
Object name = getItemNode.execute(frame, inliningTarget, constructors, digestmod);
if (name != null) {
assert name instanceof TruffleString; // guaranteed in our initialize
- return hmacNew(self, key, msg, name, inliningTarget, castStr, castJStr, concatStr, acquireLib, bufferLib, factory, raiseNode);
+ return hmacNew(self, key, msg, name, inliningTarget, castStr, castJStr, concatStr, acquireLib, bufferLib, raiseNode);
} else {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError);
}
@@ -304,7 +305,6 @@ static Object hmacNew(@SuppressWarnings("unused") PythonModule self, Object keyO
@Shared("concatStr") @Cached TruffleString.ConcatNode concatStr,
@Shared("acquireLib") @CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@Shared("bufferLib") @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
TruffleString digestmod = castStr.execute(inliningTarget, digestmodObj);
Object key;
@@ -326,7 +326,8 @@ static Object hmacNew(@SuppressWarnings("unused") PythonModule self, Object keyO
byte[] msgBytes = msg == null ? null : bufferLib.getInternalOrCopiedByteArray(msg);
int msgLen = msg == null ? 0 : bufferLib.getBufferLength(msg);
Mac mac = createMac(digestmod, bufferLib.getInternalOrCopiedByteArray(key), bufferLib.getBufferLength(key), msgBytes, msgLen);
- return factory.createDigestObject(PythonBuiltinClassType.HashlibHmac, castJStr.execute(concatStr.execute(HMAC_PREFIX, digestmod, TS_ENCODING, true)), mac);
+ return PFactory.createDigestObject(PythonLanguage.get(inliningTarget), PythonBuiltinClassType.HashlibHmac,
+ castJStr.execute(concatStr.execute(HMAC_PREFIX, digestmod, TS_ENCODING, true)), mac);
} catch (InvalidKeyException | NoSuchAlgorithmException e) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError, e);
} finally {
@@ -362,7 +363,6 @@ abstract static class CreateDigestNode extends Node {
@Specialization
static Object doIt(VirtualFrame frame, Node inliningTarget, PythonBuiltinClassType type, String pythonName, String javaName, Object value,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached(inline = false) PythonObjectFactory factory,
@CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Cached PRaiseNode.Lazy raise) {
@@ -383,7 +383,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, PythonBuiltinClassTy
} catch (NoSuchAlgorithmException e) {
throw raise.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError, e);
}
- return factory.createDigestObject(type, pythonName, digest);
+ return PFactory.createDigestObject(PythonLanguage.get(inliningTarget), type, pythonName, digest);
} finally {
if (buffer != null) {
bufferLib.release(buffer, frame, indirectCallData);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
index 1d736b68e4..268a976356 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -94,12 +95,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PBytes digest(DigestObject self, int length,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (self.getDigestLength() != length) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFAULT_DIGEST_LENGTHS);
}
- return factory.createBytes(self.digest());
+ return PFactory.createBytes(language, self.digest());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
index e1d5232967..10d38fa1fc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import static com.oracle.graal.python.nodes.ErrorMessages.IO_UNINIT;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.modules.io.BufferedIONodes.RawTellIgnoreErrorNode;
@@ -66,8 +67,9 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -85,25 +87,26 @@ abstract class AbstractBufferedIOBuiltins extends PythonBuiltins {
@GenerateCached(false)
public abstract static class BufferedInitNode extends PNodeWithContext {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize, PythonObjectFactory factory);
+ public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize);
@Specialization(guards = "bufferSize > 0")
- static void bufferedInit(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize, PythonObjectFactory factory,
- @Cached RawTellIgnoreErrorNode rawTellNode) {
- init(self, bufferSize, factory);
+ static void bufferedInit(VirtualFrame frame, Node inliningTarget, PBuffered self, int bufferSize,
+ @Cached RawTellIgnoreErrorNode rawTellNode,
+ @Bind PythonLanguage language) {
+ init(self, bufferSize, language);
rawTellNode.execute(frame, inliningTarget, self);
}
@SuppressWarnings("unused")
@Specialization(guards = "bufferSize <= 0")
- static void bufferSizeError(PBuffered self, int bufferSize, PythonObjectFactory factory,
+ static void bufferSizeError(PBuffered self, int bufferSize,
@Cached(inline = false) PRaiseNode raiseNode) {
throw raiseNode.raise(ValueError, BUF_SIZE_POS);
}
- private static void init(PBuffered self, int bufferSize, PythonObjectFactory factory) {
+ private static void init(PBuffered self, int bufferSize, PythonLanguage language) {
self.initBuffer(bufferSize);
- self.setLock(factory.createLock());
+ self.setLock(PFactory.createLock(language));
self.setOwner(0);
int n;
for (n = bufferSize - 1; (n & 1) != 0; n >>= 1) {
@@ -112,10 +115,10 @@ private static void init(PBuffered self, int bufferSize, PythonObjectFactory fac
self.setBufferMask(mask);
}
- public static void internalInit(PBuffered self, int bufferSize, PythonObjectFactory factory,
+ public static void internalInit(PBuffered self, int bufferSize, PythonLanguage language,
Object posixSupport,
PosixSupportLibrary posixLib) {
- init(self, bufferSize, factory);
+ init(self, bufferSize, language);
try {
FileIOBuiltins.TellNode.internalTell(self.getFileIORaw(), posixSupport, posixLib);
} catch (PosixException e) {
@@ -216,13 +219,13 @@ public final PException raiseEAGAIN(TruffleString message, int written) {
@Specialization
static PException raise(Node node, Object errno, TruffleString message, int written,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] args = new Object[]{
errno,
message,
written
};
- PBaseException exception = factory.createBaseException(BlockingIOError, factory.createTuple(args));
+ PBaseException exception = PFactory.createBaseException(language, BlockingIOError, PFactory.createTuple(language, args));
final Object[] attrs = OS_ERROR_ATTR_FACTORY.create();
attrs[OsErrorBuiltins.IDX_ERRNO] = errno;
attrs[OsErrorBuiltins.IDX_STRERROR] = message;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
index 9cd72d1105..4a6189b539 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,8 +41,6 @@
package com.oracle.graal.python.builtins.modules.io;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedRWPair;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedReader;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedWriter;
import static com.oracle.graal.python.builtins.modules.io.IONodes.J_CLOSE;
import static com.oracle.graal.python.builtins.modules.io.IONodes.J_CLOSED;
import static com.oracle.graal.python.builtins.modules.io.IONodes.J_FLUSH;
@@ -75,6 +73,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -91,7 +90,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.IsNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
@@ -128,13 +127,13 @@ static PNone doInit(VirtualFrame frame, PRWPair self, Object reader, Object writ
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkWritableNode,
@Cached BufferedReaderBuiltins.BufferedReaderInit initReaderNode,
@Cached BufferedWriterBuiltins.BufferedWriterInit initWriterNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
checkReadableNode.checkReadable(frame, inliningTarget, reader);
checkWritableNode.checkWriteable(frame, inliningTarget, writer);
- self.setReader(factory.createBufferedReader(PBufferedReader));
- initReaderNode.execute(frame, inliningTarget, self.getReader(), reader, bufferSize, factory);
- self.setWriter(factory.createBufferedWriter(PBufferedWriter));
- initWriterNode.execute(frame, inliningTarget, self.getWriter(), writer, bufferSize, factory);
+ self.setReader(PFactory.createBufferedReader(language));
+ initReaderNode.execute(frame, inliningTarget, self.getReader(), reader, bufferSize);
+ self.setWriter(PFactory.createBufferedWriter(language));
+ initWriterNode.execute(frame, inliningTarget, self.getWriter(), writer, bufferSize);
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRandomBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRandomBuiltins.java
index ac9a19e585..cdb5be4fa2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRandomBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRandomBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,7 +52,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -74,10 +73,10 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateInline
public abstract static class BufferedRandomInit extends Node {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
+ public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize);
@Specialization
- static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
+ static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize,
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkSeekableNode,
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkWritableNode,
@@ -90,7 +89,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Obje
checkReadableNode.checkReadable(frame, inliningTarget, raw);
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
self.setRaw(raw, isFileIO(self, raw, PBufferedRandom, inliningTarget, getSelfClass, getRawClass));
- bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
+ bufferedInitNode.execute(frame, inliningTarget, self, bufferSize);
self.resetRead();
self.resetWrite();
self.setPos(0);
@@ -107,10 +106,9 @@ public abstract static class InitNode extends PythonBuiltinNode {
static Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
@Bind("this") Node inliningTarget,
@Cached InitBufferSizeNode initBufferSizeNode,
- @Cached BufferedRandomInit init,
- @Cached PythonObjectFactory factory) {
+ @Cached BufferedRandomInit init) {
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
- init.execute(frame, inliningTarget, self, raw, size, factory);
+ init.execute(frame, inliningTarget, self, raw, size);
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderBuiltins.java
index 38ae3204f9..959fc33fc2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -56,7 +57,6 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -78,10 +78,10 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateCached(false)
public abstract static class BufferedReaderInit extends Node {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
+ public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize);
@Specialization
- static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
+ static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize,
@Cached IOBaseBuiltins.CheckBoolMethodHelperNode checkReadableNode,
@Cached BufferedInitNode bufferedInitNode,
@Cached GetPythonObjectClassNode getSelfClass,
@@ -90,17 +90,17 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PBuffered self, Obje
self.setDetached(false);
checkReadableNode.checkReadable(frame, inliningTarget, raw);
self.setRaw(raw, isFileIO(self, raw, PBufferedReader, inliningTarget, getSelfClass, getRawClass));
- bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
+ bufferedInitNode.execute(frame, inliningTarget, self, bufferSize);
self.resetRead();
self.setOK(true);
}
- public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, PythonObjectFactory factory,
+ public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, PythonLanguage language,
Object posixSupport,
PosixSupportLibrary posixLib) {
self.setDetached(false);
self.setRaw(raw, true);
- BufferedInitNode.internalInit(self, bufferSize, factory, posixSupport, posixLib);
+ BufferedInitNode.internalInit(self, bufferSize, language, posixSupport, posixLib);
self.resetRead();
self.setOK(true);
}
@@ -114,10 +114,9 @@ public abstract static class InitNode extends PythonBuiltinNode {
static Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
@Bind("this") Node inliningTarget,
@Cached InitBufferSizeNode initBufferSizeNode,
- @Cached BufferedReaderInit init,
- @Cached PythonObjectFactory factory) {
+ @Cached BufferedReaderInit init) {
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
- init.execute(frame, inliningTarget, self, raw, size, factory);
+ init.execute(frame, inliningTarget, self, raw, size);
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
index e8f374a893..6e9a6459af 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,6 +71,7 @@
import java.io.ByteArrayOutputStream;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -96,12 +97,11 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -136,13 +136,13 @@ abstract static class RawReadNode extends PNodeWithContext {
// This is the spec way
@Specialization
static byte[] bufferedreaderRawRead(VirtualFrame frame, Node inliningTarget, PBuffered self, int len,
+ @Bind PythonLanguage language,
@Cached(inline = false) BytesNodes.ToBytesNode toBytes,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached PyObjectCallMethodObjArgs callMethodReadInto,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached InlinedConditionProfile osError,
@Cached PRaiseNode.Lazy lazyRaiseNode) {
- PByteArray memobj = factory.createByteArray(new byte[len]);
+ PByteArray memobj = PFactory.createByteArray(language, new byte[len]);
// TODO _PyIO_trap_eintr [GR-23297]
Object res = callMethodReadInto.execute(frame, inliningTarget, self.getRaw(), T_READINTO, memobj);
if (res == PNone.NONE) {
@@ -250,9 +250,9 @@ public static boolean isReadFast(PBuffered self, int size) {
@Specialization(guards = {"self.isOK()", "size == 0"})
Object empty(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
checkIsClosedNode.execute(frame, self);
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
/*
@@ -272,9 +272,9 @@ public static byte[] bufferedreaderReadFast(PBuffered self, int size) {
@Specialization(guards = {"self.isOK()", "size > 0", "isReadFast(self, size)"})
Object readFast(VirtualFrame frame, PBuffered self, int size,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
checkIsClosedNode.execute(frame, self);
- return factory.createBytes(bufferedreaderReadFast(self, size));
+ return PFactory.createBytes(language, bufferedreaderReadFast(self, size));
}
/**
@@ -284,17 +284,17 @@ Object readFast(VirtualFrame frame, PBuffered self, int size,
@SuppressWarnings("truffle-static-method") // checkIsClosedNode
Object bufferedreaderReadGeneric(VirtualFrame frame, PBuffered self, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached EnterBufferedNode lock,
@Cached RawReadNode rawReadNode,
@Cached FillBufferNode fillBufferNode,
- @Exclusive @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode) {
checkIsClosedNode.execute(frame, self);
try {
lock.enter(inliningTarget, self);
int currentSize = safeDowncast(self);
if (size <= currentSize) {
- return factory.createBytes(bufferedreaderReadFast(self, size));
+ return PFactory.createBytes(language, bufferedreaderReadFast(self, size));
}
byte[] res = new byte[size];
int remaining = size;
@@ -328,7 +328,7 @@ If we had readv() we could do this in one pass. */
if (r == 0 || r == -2) {
/* EOF occurred */
if (r == 0 || written > 0) {
- return factory.createBytes(PythonUtils.arrayCopyOf(res, written));
+ return PFactory.createBytes(language, PythonUtils.arrayCopyOf(res, written));
}
return PNone.NONE;
}
@@ -347,7 +347,7 @@ reads, which could block indefinitely (e.g. on a socket).
if (r == 0 || r == -2) {
/* EOF occurred */
if (r == 0 || written > 0) {
- return factory.createBytes(PythonUtils.arrayCopyOf(res, written));
+ return PFactory.createBytes(language, PythonUtils.arrayCopyOf(res, written));
}
return PNone.NONE;
}
@@ -369,7 +369,7 @@ reads, which could block indefinitely (e.g. on a socket).
}
}
- return factory.createBytes(res);
+ return PFactory.createBytes(language, res);
} finally {
EnterBufferedNode.leave(self);
}
@@ -384,6 +384,7 @@ reads, which could block indefinitely (e.g. on a socket).
@SuppressWarnings("truffle-static-method") // checkIsClosedNode
Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached EnterBufferedNode lock,
@Exclusive @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
@Cached("create(T_READALL)") LookupAttributeInMRONode readallAttr,
@@ -393,7 +394,6 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
@Cached GetClassNode getClassNode,
@Cached PyObjectCallMethodObjArgs callMethod,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
checkIsClosedNode.execute(frame, self);
try {
@@ -426,9 +426,9 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
byte[] res = new byte[data.length + bytesLen];
PythonUtils.arraycopy(data, 0, res, 0, data.length);
bufferLib.readIntoByteArray(tmp, 0, res, data.length, bytesLen);
- return factory.createBytes(res);
+ return PFactory.createBytes(language, res);
}
- return factory.createBytes(data);
+ return PFactory.createBytes(language, data);
} else {
return tmp;
}
@@ -456,7 +456,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
if (currentSize == 0) {
return r;
} else {
- return factory.createBytes(toByteArray(chunks));
+ return PFactory.createBytes(language, toByteArray(chunks));
}
}
currentSize += dataLen;
@@ -490,10 +490,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "self.isOK()")
static PBytes doit(VirtualFrame frame, PBuffered self, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached EnterBufferedNode lock,
@Cached("create(T_READ)") CheckIsClosedNode checkIsClosedNode,
- @Cached RawReadNode rawReadNode,
- @Cached PythonObjectFactory factory) {
+ @Cached RawReadNode rawReadNode) {
checkIsClosedNode.execute(frame, self);
int n = size;
if (n < 0) {
@@ -501,7 +501,7 @@ static PBytes doit(VirtualFrame frame, PBuffered self, int size,
}
if (n == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
/*- Return up to n bytes. If at least one byte is buffered, we
only return buffered bytes. Otherwise, we do one raw read. */
@@ -510,13 +510,13 @@ static PBytes doit(VirtualFrame frame, PBuffered self, int size,
if (have > 0) {
n = have < n ? have : n;
byte[] b = ReadNode.bufferedreaderReadFast(self, n);
- return factory.createBytes(b);
+ return PFactory.createBytes(language, b);
}
try {
lock.enter(inliningTarget, self);
self.resetRead(); // _bufferedreader_reset_buf
byte[] fill = rawReadNode.execute(frame, inliningTarget, self, n);
- return factory.createBytes(fill == BLOCKED ? PythonUtils.EMPTY_BYTE_ARRAY : fill);
+ return PFactory.createBytes(language, fill == BLOCKED ? PythonUtils.EMPTY_BYTE_ARRAY : fill);
} finally {
EnterBufferedNode.leave(self);
}
@@ -748,12 +748,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "self.isOK()")
static PBytes doit(VirtualFrame frame, PBuffered self, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("create(T_READLINE)") CheckIsClosedNode checkIsClosedNode,
- @Cached BufferedReadlineNode readlineNode,
- @Cached PythonObjectFactory factory) {
+ @Cached BufferedReadlineNode readlineNode) {
checkIsClosedNode.execute(frame, self);
byte[] res = readlineNode.execute(frame, inliningTarget, self, size);
- return factory.createBytes(res);
+ return PFactory.createBytes(language, res);
}
}
@@ -796,18 +796,18 @@ static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, Node inliningTarget
@Specialization(guards = "self.isOK()")
static Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached EnterBufferedNode lock,
@Cached("create(T_PEEK)") CheckIsClosedNode checkIsClosedNode,
@Cached FillBufferNode fillBufferNode,
- @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
- @Cached PythonObjectFactory factory) {
+ @Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode) {
checkIsClosedNode.execute(frame, self);
try {
lock.enter(inliningTarget, self);
if (self.isWritable()) {
flushAndRewindUnlockedNode.execute(frame, inliningTarget, self);
}
- return factory.createBytes(bufferedreaderPeekUnlocked(frame, inliningTarget, self, fillBufferNode));
+ return PFactory.createBytes(language, bufferedreaderPeekUnlocked(frame, inliningTarget, self, fillBufferNode));
} finally {
EnterBufferedNode.leave(self);
}
@@ -824,14 +824,13 @@ static PBytes doit(VirtualFrame frame, PBuffered self,
@Bind("this") Node inliningTarget,
@Cached("create(T_READLINE)") CheckIsClosedNode checkIsClosedNode,
@Cached BufferedReadlineNode readlineNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
checkIsClosedNode.execute(frame, self);
byte[] line = readlineNode.execute(frame, inliningTarget, self, -1);
if (line.length == 0) {
throw raiseNode.get(inliningTarget).raiseStopIteration();
}
- return factory.createBytes(line);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), line);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterBuiltins.java
index ac47b999fe..4e591c1e93 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.modules.io.IOBaseBuiltins.CheckBoolMethodHelperNode;
@@ -54,7 +55,6 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -76,10 +76,10 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateCached(false)
public abstract static class BufferedWriterInit extends Node {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory);
+ public abstract void execute(VirtualFrame frame, Node inliningTarget, PBuffered self, Object raw, int bufferSize);
@Specialization
- static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize, PythonObjectFactory factory,
+ static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored, PBuffered self, Object raw, int bufferSize,
@Bind("this") Node inliningTarget,
@Cached CheckBoolMethodHelperNode checkWritableNode,
@Cached BufferedInitNode bufferedInitNode,
@@ -89,18 +89,18 @@ static void doInit(VirtualFrame frame, @SuppressWarnings("unused") Node ignored,
self.setDetached(false);
checkWritableNode.checkWriteable(frame, inliningTarget, raw);
self.setRaw(raw, isFileIO(self, raw, PBufferedWriter, inliningTarget, getSelfClass, getRawClass));
- bufferedInitNode.execute(frame, inliningTarget, self, bufferSize, factory);
+ bufferedInitNode.execute(frame, inliningTarget, self, bufferSize);
self.resetWrite();
self.setPos(0);
self.setOK(true);
}
- public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, PythonObjectFactory factory,
+ public static void internalInit(PBuffered self, PFileIO raw, int bufferSize, PythonLanguage language,
Object posixSupport,
PosixSupportLibrary posixLib) {
self.setDetached(false);
self.setRaw(raw, true);
- BufferedInitNode.internalInit(self, bufferSize, factory, posixSupport, posixLib);
+ BufferedInitNode.internalInit(self, bufferSize, language, posixSupport, posixLib);
self.resetWrite();
self.setPos(0);
self.setOK(true);
@@ -116,10 +116,9 @@ public abstract static class InitNode extends PythonBuiltinNode {
static Object doIt(VirtualFrame frame, PBuffered self, Object raw, Object bufferSize,
@Bind("this") Node inliningTarget,
@Cached InitBufferSizeNode initBufferSizeNode,
- @Cached BufferedWriterInit init,
- @Cached PythonObjectFactory factory) {
+ @Cached BufferedWriterInit init) {
int size = initBufferSizeNode.execute(frame, inliningTarget, bufferSize);
- init.execute(frame, inliningTarget, self, raw, size, factory);
+ init.execute(frame, inliningTarget, self, raw, size);
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
index baebfde434..af283f1837 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OSError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -63,7 +64,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -223,11 +224,11 @@ abstract static class RawWriteNode extends PNodeWithContext {
*/
@Specialization
static int bufferedwriterRawWrite(VirtualFrame frame, Node inliningTarget, PBuffered self, byte[] buf, int len,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached PRaiseNode.Lazy lazyRaiseNode) {
- PBytes memobj = factory.createBytes(buf, len);
+ PBytes memobj = PFactory.createBytes(language, buf, len);
Object res = callMethod.execute(frame, inliningTarget, self.getRaw(), T_WRITE, memobj);
if (res == PNone.NONE) {
/*
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
index a04992337d..f5d34eac5f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,7 +41,6 @@
package com.oracle.graal.python.builtins.modules.io;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBytesIOBuf;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_CUR;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_END;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_SET;
@@ -82,6 +81,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -114,7 +114,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.ArrayBuilder;
import com.oracle.graal.python.util.PythonUtils;
@@ -204,9 +204,9 @@ static PNone init(VirtualFrame frame, PBytesIO self, Object initvalue,
static PBytes readBytes(PBytesIO self, int size,
PythonBufferAccessLibrary bufferLib,
- PythonObjectFactory factory) {
+ PythonLanguage language) {
if (size == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
assert (size <= self.getStringSize());
@@ -214,10 +214,10 @@ static PBytes readBytes(PBytesIO self, int size,
if (self.getPos() == 0 && bufferLib.hasInternalByteArray(buffer) && self.getExports() == 0 && size > bufferLib.getBufferLength(buffer) / 2) {
self.incPos(size);
self.markEscaped();
- return factory.createBytes(bufferLib.getInternalByteArray(buffer), size);
+ return PFactory.createBytes(language, bufferLib.getInternalByteArray(buffer), size);
}
- PBytes output = factory.createBytes(bufferLib.getCopyOfRange(buffer, self.getPos(), self.getPos() + size));
+ PBytes output = PFactory.createBytes(language, bufferLib.getCopyOfRange(buffer, self.getPos(), self.getPos() + size));
self.incPos(size);
return output;
}
@@ -234,8 +234,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "self.hasBuf()")
static Object read(PBytesIO self, int len,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) {
int size = len;
/* adjust invalid sizes */
int n = self.getStringSize() - self.getPos();
@@ -245,7 +245,7 @@ static Object read(PBytesIO self, int len,
size = 0;
}
}
- return readBytes(self, size, bufferLib, factory);
+ return readBytes(self, size, bufferLib, language);
}
}
@@ -311,10 +311,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "self.hasBuf()")
Object readline(PBytesIO self, int size,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) {
int n = scanEOL(self, size, bufferLib);
- return readBytes(self, n, bufferLib, factory);
+ return readBytes(self, n, bufferLib, language);
}
}
@@ -330,8 +330,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "self.hasBuf()")
static Object readlines(PBytesIO self, int maxsize,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) {
ArrayBuilder result = new ArrayBuilder<>();
int n;
@@ -341,7 +341,7 @@ static Object readlines(PBytesIO self, int maxsize,
int size = 0;
while ((n = scanEOL(self, -1, buf)) != 0) {
self.incPos(n);
- PBytes line = factory.createBytes(PythonUtils.arrayCopyOfRange(buf, cur, cur + n));
+ PBytes line = PFactory.createBytes(language, PythonUtils.arrayCopyOfRange(buf, cur, cur + n));
result.add(line);
size += n;
if (maxsize > 0 && size >= maxsize) {
@@ -349,7 +349,7 @@ static Object readlines(PBytesIO self, int maxsize,
}
cur += n;
}
- return factory.createList(result.toArray(new Object[0]));
+ return PFactory.createList(language, result.toArray(new Object[0]));
}
}
@@ -397,15 +397,15 @@ abstract static class TruncateNode extends ClosedCheckPythonBinaryBuiltinNode {
@Specialization(guards = "self.hasBuf()")
static Object truncate(PBytesIO self, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
self.checkExports(inliningTarget, raiseNode);
if (size < 0) {
throw raiseNode.get(inliningTarget).raise(ValueError, NEGATIVE_SIZE_VALUE_D, size);
}
if (size < self.getStringSize()) {
- self.unshareAndResize(bufferLib, factory, size, true);
+ self.unshareAndResize(bufferLib, language, size, true);
self.setStringSize(size);
}
return size;
@@ -414,20 +414,20 @@ static Object truncate(PBytesIO self, int size,
@Specialization(guards = "self.hasBuf()")
static Object truncate(PBytesIO self, @SuppressWarnings("unused") PNone size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return truncate(self, self.getPos(), inliningTarget, bufferLib, factory, raiseNode);
+ return truncate(self, self.getPos(), inliningTarget, language, bufferLib, raiseNode);
}
@Specialization(guards = {"self.hasBuf()", "!isPNone(size)"})
static Object truncate(VirtualFrame frame, PBytesIO self, Object size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- return truncate(self, asSizeNode.executeExact(frame, inliningTarget, size), inliningTarget, bufferLib, factory, raiseNode);
+ return truncate(self, asSizeNode.executeExact(frame, inliningTarget, size), inliningTarget, language, bufferLib, raiseNode);
}
}
@@ -438,10 +438,10 @@ abstract static class WriteNode extends ClosedCheckPythonBinaryBuiltinNode {
@Specialization(guards = "self.hasBuf()", limit = "3")
static Object doWrite(VirtualFrame frame, PBytesIO self, Object b,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("b") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkExports(inliningTarget, raiseNode);
Object buffer = acquireLib.acquireReadonly(b, frame, indirectCallData);
@@ -452,7 +452,7 @@ static Object doWrite(VirtualFrame frame, PBytesIO self, Object b,
}
int pos = self.getPos();
int endpos = pos + len;
- self.unshareAndResize(bufferLib, factory, endpos, false);
+ self.unshareAndResize(bufferLib, language, endpos, false);
bufferLib.readIntoBuffer(buffer, 0, self.getBuf(), pos, len, bufferLib);
self.setPos(endpos);
if (endpos > self.getStringSize()) {
@@ -599,12 +599,12 @@ abstract static class GetBufferNode extends ClosedCheckPythonUnaryBuiltinNode {
static Object doit(VirtualFrame frame, PBytesIO self,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyMemoryViewFromObject memoryViewNode,
- @Cached SequenceStorageNodes.SetLenNode setLenNode,
- @Cached PythonObjectFactory factory) {
- self.unshareIfNecessary(bufferLib, factory);
+ @Cached SequenceStorageNodes.SetLenNode setLenNode) {
+ self.unshareIfNecessary(bufferLib, language);
setLenNode.execute(inliningTarget, self.getBuf().getSequenceStorage(), self.getStringSize());
- PBytesIOBuffer buf = factory.createBytesIOBuf(PBytesIOBuf, self);
+ PBytesIOBuffer buf = PFactory.createBytesIOBuf(language, self);
return memoryViewNode.execute(frame, buf);
}
}
@@ -614,12 +614,12 @@ static Object doit(VirtualFrame frame, PBytesIO self,
abstract static class GetValueNode extends ClosedCheckPythonUnaryBuiltinNode {
@Specialization(guards = "self.hasBuf()")
static Object doCopy(PBytesIO self,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) {
if (bufferLib.hasInternalByteArray(self.getBuf()) && self.getExports() == 0) {
self.markEscaped();
}
- return factory.createBytes(bufferLib.getInternalOrCopiedByteArray(self.getBuf()), self.getStringSize());
+ return PFactory.createBytes(language, bufferLib.getInternalOrCopiedByteArray(self.getBuf()), self.getStringSize());
}
}
@@ -629,12 +629,12 @@ abstract static class GetStateNode extends ClosedCheckPythonUnaryBuiltinNode {
@Specialization(guards = "self.hasBuf()")
static Object doit(VirtualFrame frame, PBytesIO self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetValueNode getValueNode,
- @Cached GetOrCreateDictNode getDict,
- @Cached PythonObjectFactory factory) {
+ @Cached GetOrCreateDictNode getDict) {
Object initValue = getValueNode.execute(frame, self);
Object[] state = new Object[]{initValue, self.getPos(), getDict.execute(inliningTarget, self)};
- return factory.createTuple(state);
+ return PFactory.createTuple(language, state);
}
}
@@ -775,14 +775,14 @@ abstract static class IternextNode extends ClosedCheckPythonUnaryBuiltinNode {
@Specialization(guards = "self.hasBuf()")
static Object doit(PBytesIO self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
int n = scanEOL(self, -1, bufferLib);
if (n == 0) {
throw raiseNode.get(inliningTarget).raiseStopIteration();
}
- return readBytes(self, n, bufferLib, factory);
+ return readBytes(self, n, bufferLib, language);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
index 08cb8802bc..85aa552c4b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
@@ -106,6 +106,7 @@
import java.io.ByteArrayOutputStream;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -152,7 +153,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -311,7 +312,8 @@ public static void internalInit(PFileIO self, TruffleString name, int fd, IOMode
@Specialization(guards = {"!isBadMode(mode)", "!isInvalidMode(mode)"})
static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object nameobj, IONodes.IOMode mode, boolean closefd, Object opener,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached(inline = false) CallNode callOpener,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
@@ -350,10 +352,9 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
try {
boolean fdIsOwn = false;
- PythonContext ctxt = PythonContext.get(inliningTarget);
if (fd >= 0) {
self.setCloseFD(closefd);
- self.setFD(fd, ctxt);
+ self.setFD(fd, context);
} else {
self.setCloseFD(true);
if (errorProfile.profile(inliningTarget, !closefd)) {
@@ -361,14 +362,14 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
}
if (opener instanceof PNone) {
- self.setFD(open(frame, name, flags, 0666, ctxt, inliningTarget, posixLib, gil, exceptionProfile, raiseNode, constructAndRaiseNode), ctxt);
+ self.setFD(open(frame, name, flags, 0666, context, inliningTarget, posixLib, gil, exceptionProfile, raiseNode, constructAndRaiseNode), context);
} else {
Object fdobj = callOpener.execute(frame, opener, nameobj, flags);
if (!indexCheckNode.execute(inliningTarget, fdobj)) {
throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_INT_FROM_OPENER);
}
- self.setFD(asSizeNode.executeExact(frame, inliningTarget, fdobj), ctxt);
+ self.setFD(asSizeNode.executeExact(frame, inliningTarget, fdobj), context);
if (self.getFD() < 0) {
/*
* The opener returned a negative but didn't set an exception. See issue
@@ -378,7 +379,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
}
}
try {
- posixLib.setInheritable(ctxt.getPosixSupport(), self.getFD(), false);
+ posixLib.setInheritable(context.getPosixSupport(), self.getFD(), false);
} catch (PosixException e) {
exceptionProfile1.enter(inliningTarget);
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -390,7 +391,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
long[] fstatResult;
gil.release(true);
try {
- fstatResult = posixLib.fstat(ctxt.getPosixSupport(), self.getFD());
+ fstatResult = posixLib.fstat(context.getPosixSupport(), self.getFD());
} finally {
gil.acquire();
}
@@ -428,7 +429,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
try {
gil.release(true);
try {
- long res = posixLib.lseek(ctxt.getPosixSupport(), self.getFD(), 0, mapPythonSeekWhenceToPosix(SEEK_END));
+ long res = posixLib.lseek(context.getPosixSupport(), self.getFD(), 0, mapPythonSeekWhenceToPosix(SEEK_END));
self.setSeekable(res >= 0 ? 1 : 0);
} finally {
gil.acquire();
@@ -513,22 +514,21 @@ static Object readall(VirtualFrame frame, PFileIO self, @SuppressWarnings("unuse
@Specialization(guards = {"!self.isClosed()", "self.isReadable()", "size == 0"})
static Object none(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") int size,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEmptyBytes();
+ @Bind PythonLanguage language) {
+ return PFactory.createEmptyBytes(language);
}
@Specialization(guards = {"!self.isClosed()", "self.isReadable()", "size >= 0"})
static Object read(VirtualFrame frame, PFileIO self, int size,
@Bind("this") Node inliningTarget,
- @Cached PosixModuleBuiltins.ReadNode posixRead,
@Cached InlinedBranchProfile readErrorProfile,
@Cached InlinedBranchProfile readErrorProfile2,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- return posixRead.read(self.getFD(), size, inliningTarget, posixLib, readErrorProfile, gil, factory);
+ return PosixModuleBuiltins.ReadNode.read(self.getFD(), size, inliningTarget, posixLib, context.getPosixSupport(), readErrorProfile, gil);
} catch (PosixException e) {
if (e.getErrorCode() == EAGAIN.getNumber()) {
readErrorProfile2.enter(inliningTarget);
@@ -558,14 +558,13 @@ abstract static class ReadallNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "!self.isClosed()")
static Object readall(VirtualFrame frame, PFileIO self,
@Bind("this") Node inliningTarget,
- @Cached PosixModuleBuiltins.ReadNode posixRead,
@Cached InlinedBranchProfile readErrorProfile,
@Cached SequenceStorageNodes.GetInternalByteArrayNode getBytes,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile multipleReadsProfile,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
int bufsize = SMALLCHUNK;
boolean mayBeQuick = false;
@@ -591,7 +590,7 @@ static Object readall(VirtualFrame frame, PFileIO self,
int bytesRead = 0;
PBytes b;
try {
- b = posixRead.read(self.getFD(), bufsize, inliningTarget, posixLib, readErrorProfile, gil, factory);
+ b = PosixModuleBuiltins.ReadNode.read(self.getFD(), bufsize, inliningTarget, posixLib, context.getPosixSupport(), readErrorProfile, gil);
bytesRead = b.getSequenceStorage().length();
if (bytesRead == 0 || (mayBeQuick && bytesRead == bufsize - 1)) {
return b;
@@ -619,7 +618,7 @@ static Object readall(VirtualFrame frame, PFileIO self,
int n;
try {
- b = posixRead.read(self.getFD(), bufsize - bytesRead, inliningTarget, posixLib, readErrorProfile, gil, factory);
+ b = PosixModuleBuiltins.ReadNode.read(self.getFD(), bufsize - bytesRead, inliningTarget, posixLib, context.getPosixSupport(), readErrorProfile, gil);
/*
* PosixModuleBuiltins#ReadNode creates PBytes with exact size;
*/
@@ -642,7 +641,7 @@ static Object readall(VirtualFrame frame, PFileIO self,
bytesRead += n;
}
- return factory.createBytes(toByteArray(result));
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), toByteArray(result));
}
@Specialization(guards = "self.isClosed()")
@@ -662,19 +661,18 @@ static Object readinto(VirtualFrame frame, PFileIO self, Object buffer,
@Bind("this") Node inliningTarget,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PosixModuleBuiltins.ReadNode posixRead,
@Cached InlinedBranchProfile readErrorProfile,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
int size = bufferLib.getBufferLength(buffer);
if (size == 0) {
return 0;
}
try {
- PBytes data = posixRead.read(self.getFD(), size, inliningTarget, posixLib, readErrorProfile, gil, factory);
+ PBytes data = PosixModuleBuiltins.ReadNode.read(self.getFD(), size, inliningTarget, posixLib, context.getPosixSupport(), readErrorProfile, gil);
int n = bufferLib.getBufferLength(data);
bufferLib.readIntoBuffer(data, 0, buffer, 0, n, bufferLib);
return n;
@@ -717,8 +715,9 @@ public abstract static class WriteNode extends PythonBinaryClinicBuiltinNode {
@Specialization(limit = "3")
static Object write(VirtualFrame frame, PFileIO self, Object buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedBranchProfile errorProfile,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@@ -732,7 +731,7 @@ static Object write(VirtualFrame frame, PFileIO self, Object buffer,
}
try {
return PosixModuleBuiltins.WriteNode.write(self.getFD(), bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer),
- inliningTarget, posixLib, errorProfile, gil);
+ inliningTarget, posixLib, context.getPosixSupport(), errorProfile, gil);
} catch (PosixException e) {
if (e.getErrorCode() == EAGAIN.getNumber()) {
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
index c6fe4327e0..6535c80d7d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
@@ -87,6 +87,7 @@
import java.io.ByteArrayOutputStream;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -118,7 +119,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.IsNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ArrayBuilder;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
@@ -480,13 +481,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PBytes readline(VirtualFrame frame, Object self, int limit,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyObjectLookupAttr lookupPeek,
@Cached CallNode callPeek,
@Cached PyObjectCallMethodObjArgs callRead,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached InlinedConditionProfile hasPeek,
@Cached InlinedConditionProfile isBytes,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
/* For backwards compatibility, a (slowish) readline(). */
Object peek = lookupPeek.execute(frame, inliningTarget, self, T_PEEK);
@@ -528,7 +529,7 @@ static PBytes readline(VirtualFrame frame, Object self, int limit,
}
}
- return factory.createBytes(toByteArray(buffer));
+ return PFactory.createBytes(language, toByteArray(buffer));
}
}
@@ -544,12 +545,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object withHint(VirtualFrame frame, Object self, int hintIn,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetNextNode next,
@Cached InlinedConditionProfile isNegativeHintProfile,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached PyObjectGetIter getIter,
- @Cached PyObjectSizeNode sizeNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectSizeNode sizeNode) {
int hint = isNegativeHintProfile.profile(inliningTarget, hintIn <= 0) ? Integer.MAX_VALUE : hintIn;
int length = 0;
Object iterator = getIter.execute(frame, inliningTarget, self);
@@ -568,7 +569,7 @@ static Object withHint(VirtualFrame frame, Object self, int hintIn,
break;
}
}
- return factory.createList(list.toArray(new Object[0]));
+ return PFactory.createList(language, list.toArray(new Object[0]));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
index 6cc698da4d..9a7709f4fd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -75,6 +75,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -88,6 +89,7 @@
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectSetAttr;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -103,7 +105,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -154,8 +156,9 @@ public void initialize(Python3Core core) {
public abstract static class IOBaseNode extends PythonBuiltinNode {
@Specialization
static PythonObject doGeneric(Object cls,
- @Cached PythonObjectFactory factory) {
- return factory.createPythonObject(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createPythonObject(language, cls, getInstanceShape.execute(cls));
}
}
@@ -164,9 +167,10 @@ static PythonObject doGeneric(Object cls,
public abstract static class FileIONode extends PythonBuiltinNode {
@Specialization
static PFileIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see FileIOBuiltins.InitNode
- return factory.createFileIO(cls);
+ return PFactory.createFileIO(language, cls, getInstanceShape.execute(cls));
}
}
@@ -175,9 +179,10 @@ static PFileIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class BufferedReaderNode extends PythonBuiltinNode {
@Specialization
static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BufferedReaderBuiltins.InitNode
- return factory.createBufferedReader(cls);
+ return PFactory.createBufferedReader(language, cls, getInstanceShape.execute(cls));
}
}
@@ -186,9 +191,10 @@ static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class BufferedWriterNode extends PythonBuiltinNode {
@Specialization
static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BufferedWriterBuiltins.InitNode
- return factory.createBufferedWriter(cls);
+ return PFactory.createBufferedWriter(language, cls, getInstanceShape.execute(cls));
}
}
@@ -197,9 +203,10 @@ static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class BufferedRWPairNode extends PythonBuiltinNode {
@Specialization
static PRWPair doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BufferedRWPairBuiltins.InitNode
- return factory.createRWPair(cls);
+ return PFactory.createRWPair(language, cls, getInstanceShape.execute(cls));
}
}
@@ -208,9 +215,10 @@ static PRWPair doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class BufferedRandomNode extends PythonBuiltinNode {
@Specialization
static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BufferedRandomBuiltins.InitNode
- return factory.createBufferedRandom(cls);
+ return PFactory.createBufferedRandom(language, cls, getInstanceShape.execute(cls));
}
}
@@ -219,9 +227,10 @@ static PBuffered doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class TextIOWrapperNode extends PythonBuiltinNode {
@Specialization
static PTextIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see TextIOWrapperBuiltins.InitNode
- return factory.createTextIO(cls);
+ return PFactory.createTextIO(language, cls, getInstanceShape.execute(cls));
}
}
@@ -230,10 +239,11 @@ static PTextIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class BytesIONode extends PythonBuiltinNode {
@Specialization
static PBytesIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see BytesIONodeBuiltins.InitNode
- PBytesIO bytesIO = factory.createBytesIO(cls);
- bytesIO.setBuf(factory.createByteArray(PythonUtils.EMPTY_BYTE_ARRAY));
+ PBytesIO bytesIO = PFactory.createBytesIO(language, cls, getInstanceShape.execute(cls));
+ bytesIO.setBuf(PFactory.createByteArray(language, PythonUtils.EMPTY_BYTE_ARRAY));
return bytesIO;
}
}
@@ -243,9 +253,10 @@ static PBytesIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class StringIONode extends PythonBuiltinNode {
@Specialization
static PStringIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see StringIONodeBuiltins.InitNode
- return factory.createStringIO(cls);
+ return PFactory.createStringIO(language, cls, getInstanceShape.execute(cls));
}
}
@@ -254,19 +265,19 @@ static PStringIO doNew(Object cls, @SuppressWarnings("unused") Object arg,
public abstract static class IncrementalNewlineDecoderNode extends PythonBuiltinNode {
@Specialization
static PNLDecoder doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see
// IncrementalNewlineDecoderBuiltins.InitNode
- return factory.createNLDecoder(cls);
+ return PFactory.createNLDecoder(language, cls, getInstanceShape.execute(cls));
}
}
private static PFileIO createFileIO(VirtualFrame frame, Node inliningTarget, Object file, IONodes.IOMode mode, boolean closefd, Object opener,
- PythonObjectFactory factory,
FileIOBuiltins.FileIOInit initFileIO) {
/* Create the Raw file stream */
mode.text = mode.universal = false; // FileIO doesn't recognize those.
- PFileIO fileIO = factory.createFileIO(PythonBuiltinClassType.PFileIO);
+ PFileIO fileIO = PFactory.createFileIO(PythonLanguage.get(inliningTarget));
initFileIO.execute(frame, inliningTarget, fileIO, file, mode, closefd, opener);
return fileIO;
}
@@ -285,9 +296,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PFileIO openCode(VirtualFrame frame, TruffleString path,
@Bind("this") Node inliningTarget,
- @Cached FileIOBuiltins.FileIOInit initFileIO,
- @Cached PythonObjectFactory factory) {
- return createFileIO(frame, inliningTarget, path, IOMode.RB, true, PNone.NONE, factory, initFileIO);
+ @Cached FileIOBuiltins.FileIOInit initFileIO) {
+ return createFileIO(frame, inliningTarget, path, IOMode.RB, true, PNone.NONE, initFileIO);
}
}
@@ -319,9 +329,9 @@ protected static Object openText(VirtualFrame frame, Object file, IONodes.IOMode
@Cached PyObjectSetAttr setAttrNode,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, factory, initFileIO);
+ PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, initFileIO);
Object result = fileIO;
try {
/* buffering */
@@ -359,11 +369,11 @@ protected static Object openText(VirtualFrame frame, Object file, IONodes.IOMode
/* wraps into a buffered file */
- PBuffered buffer = createBufferedIO.execute(frame, inliningTarget, fileIO, buffering, factory, mode);
+ PBuffered buffer = createBufferedIO.execute(frame, inliningTarget, fileIO, buffering, mode);
result = buffer;
/* wraps into a TextIOWrapper */
- PTextIO wrapper = factory.createTextIO(PTextIOWrapper);
+ PTextIO wrapper = PFactory.createTextIO(language);
initTextIO.execute(frame, inliningTarget, wrapper, buffer, encoding,
errors == PNone.NONE ? T_STRICT : (TruffleString) errors,
newline, line_buffering, false);
@@ -385,9 +395,8 @@ protected static PFileIO openBinaryNoBuf(VirtualFrame frame, Object file, IONode
@SuppressWarnings("unused") PNone newline,
boolean closefd, Object opener,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached FileIOBuiltins.FileIOInit initFileIO,
- @Shared @Cached PythonObjectFactory factory) {
- return createFileIO(frame, inliningTarget, file, mode, closefd, opener, factory, initFileIO);
+ @Exclusive @Cached FileIOBuiltins.FileIOInit initFileIO) {
+ return createFileIO(frame, inliningTarget, file, mode, closefd, opener, initFileIO);
}
@Specialization(guards = {"!isXRWA(mode)", "!isUnknown(mode)", "!isTB(mode)", "isValidUniveral(mode)", "isBinary(mode)", "bufferingValue == 1"})
@@ -402,10 +411,9 @@ protected static Object openBinaryB1(VirtualFrame frame, Object file, IONodes.IO
@Exclusive @Cached IONodes.CreateBufferedIONode createBufferedIO,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
warnNode.warnEx(frame, RuntimeWarning, LINE_BUFFERING_ISNT_SUPPORTED, 1);
- return openBinary(frame, file, mode, bufferingValue, encoding, errors, newline, closefd, opener, inliningTarget, initFileIO, createBufferedIO, posixLib, callClose, factory, raiseNode);
+ return openBinary(frame, file, mode, bufferingValue, encoding, errors, newline, closefd, opener, inliningTarget, initFileIO, createBufferedIO, posixLib, callClose, raiseNode);
}
@Specialization(guards = {"!isXRWA(mode)", "!isUnknown(mode)", "!isTB(mode)", "isValidUniveral(mode)", "isBinary(mode)", "bufferingValue != 1", "bufferingValue != 0"})
@@ -419,9 +427,8 @@ protected static Object openBinary(VirtualFrame frame, Object file, IONodes.IOMo
@Exclusive @Cached IONodes.CreateBufferedIONode createBufferedIO,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, factory, initFileIO);
+ PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, initFileIO);
try {
/* buffering */
boolean isatty = false;
@@ -455,7 +462,7 @@ protected static Object openBinary(VirtualFrame frame, Object file, IONodes.IOMo
/* wraps into a buffered file */
/* if binary, returns the buffered file */
- return createBufferedIO.execute(frame, inliningTarget, fileIO, buffering, factory, mode);
+ return createBufferedIO.execute(frame, inliningTarget, fileIO, buffering, mode);
} catch (PException e) {
callClose.execute(frame, inliningTarget, fileIO, T_CLOSE);
throw e;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
index 717ce49df3..57b90112fd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,9 +41,6 @@
package com.oracle.graal.python.builtins.modules.io;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.DeprecationWarning;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedRandom;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedReader;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PBufferedWriter;
import static com.oracle.graal.python.nodes.ErrorMessages.EMBEDDED_NULL_CHARACTER;
import static com.oracle.graal.python.nodes.ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P;
import static com.oracle.graal.python.nodes.ErrorMessages.INVALID_MODE_S;
@@ -53,6 +50,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ClinicConverterFactory;
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -67,7 +65,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -467,7 +465,7 @@ public static CastOpenNameNode create() {
@GenerateCached(false)
@GenerateInline
public abstract static class CreateBufferedIONode extends Node {
- public abstract PBuffered execute(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, PythonObjectFactory factory, IONodes.IOMode mode);
+ public abstract PBuffered execute(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, IONodes.IOMode mode);
protected static boolean isRandom(IONodes.IOMode mode) {
return mode.updating;
@@ -482,26 +480,29 @@ protected static boolean isReading(IONodes.IOMode mode) {
}
@Specialization(guards = "isRandom(mode)")
- static PBuffered createRandom(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, PythonObjectFactory factory, @SuppressWarnings("unused") IONodes.IOMode mode,
- @Cached BufferedRandomBuiltins.BufferedRandomInit initBuffered) {
- PBuffered buffer = factory.createBufferedRandom(PBufferedRandom);
- initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering, factory);
+ static PBuffered createRandom(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, @SuppressWarnings("unused") IONodes.IOMode mode,
+ @Cached BufferedRandomBuiltins.BufferedRandomInit initBuffered,
+ @Bind PythonLanguage language) {
+ PBuffered buffer = PFactory.createBufferedRandom(language);
+ initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering);
return buffer;
}
@Specialization(guards = {"!isRandom(mode)", "isWriting(mode)"})
- static PBuffered createWriter(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, PythonObjectFactory factory, @SuppressWarnings("unused") IONodes.IOMode mode,
- @Cached BufferedWriterBuiltins.BufferedWriterInit initBuffered) {
- PBuffered buffer = factory.createBufferedWriter(PBufferedWriter);
- initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering, factory);
+ static PBuffered createWriter(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, @SuppressWarnings("unused") IONodes.IOMode mode,
+ @Cached BufferedWriterBuiltins.BufferedWriterInit initBuffered,
+ @Bind PythonLanguage language) {
+ PBuffered buffer = PFactory.createBufferedWriter(language);
+ initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering);
return buffer;
}
@Specialization(guards = {"!isRandom(mode)", "!isWriting(mode)", "isReading(mode)"})
- static PBuffered createWriter(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, PythonObjectFactory factory, @SuppressWarnings("unused") IONodes.IOMode mode,
- @Cached BufferedReaderBuiltins.BufferedReaderInit initBuffered) {
- PBuffered buffer = factory.createBufferedReader(PBufferedReader);
- initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering, factory);
+ static PBuffered createWriter(VirtualFrame frame, Node inliningTarget, PFileIO fileIO, int buffering, @SuppressWarnings("unused") IONodes.IOMode mode,
+ @Cached BufferedReaderBuiltins.BufferedReaderInit initBuffered,
+ @Bind PythonLanguage language) {
+ PBuffered buffer = PFactory.createBufferedReader(language);
+ initBuffered.execute(frame, inliningTarget, buffer, fileIO, buffering);
return buffer;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
index 02f0006ced..0010e47da7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -62,6 +62,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -82,11 +83,10 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -284,20 +284,20 @@ abstract static class GetStateNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "!self.hasDecoder()")
static Object noDecoder(PNLDecoder self,
- @Shared @Cached PythonObjectFactory factory) {
- PBytes buffer = factory.createEmptyBytes();
+ @Bind PythonLanguage language) {
+ PBytes buffer = PFactory.createEmptyBytes(language);
int flag = self.isPendingCR() ? 1 : 0;
- return factory.createTuple(new Object[]{buffer, flag});
+ return PFactory.createTuple(language, new Object[]{buffer, flag});
}
@Specialization(guards = "self.hasDecoder()")
static Object withDecoder(VirtualFrame frame, PNLDecoder self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached PyObjectCallMethodObjArgs callMethod,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object state = callMethod.execute(frame, inliningTarget, self.getDecoder(), T_GETSTATE);
if (!(state instanceof PTuple)) {
@@ -312,7 +312,7 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self,
if (self.isPendingCR()) {
flag |= 1;
}
- return factory.createTuple(new Object[]{objects[0], flag});
+ return PFactory.createTuple(language, new Object[]{objects[0], flag});
}
}
@@ -339,11 +339,11 @@ static Object noDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
@Specialization(guards = "self.hasDecoder()")
static Object withDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@Exclusive @Cached PyIndexCheckNode indexCheckNode,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
@Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object[] objects = getObjectArrayNode.execute(inliningTarget, state);
if (objects.length != 2 || !indexCheckNode.execute(inliningTarget, objects[1])) {
@@ -352,7 +352,7 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
int flag = asSizeNode.executeExact(frame, inliningTarget, objects[1]);
self.setPendingCR((flag & 1) != 0);
flag >>= 1;
- PTuple tuple = factory.createTuple(new Object[]{objects[0], flag});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{objects[0], flag});
return callMethod.execute(frame, inliningTarget, self.getDecoder(), T_SETSTATE, tuple);
}
@@ -388,7 +388,7 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self,
abstract static class NewlineNode extends PythonBuiltinNode {
@Specialization
static Object newline(PNLDecoder self,
- @Cached PythonObjectFactory factory) {
+ @Bind("this") Node inliningTarget) {
switch (self.getSeenNewline()) {
case SEEN_CR:
return T_CR;
@@ -397,13 +397,13 @@ static Object newline(PNLDecoder self,
case SEEN_CRLF:
return T_CRLF;
case SEEN_CR | SEEN_LF:
- return factory.createTuple(new Object[]{T_CR, T_NEWLINE});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{T_CR, T_NEWLINE});
case SEEN_CR | SEEN_CRLF:
- return factory.createTuple(new Object[]{T_CR, T_CRLF});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{T_CR, T_CRLF});
case SEEN_LF | SEEN_CRLF:
- return factory.createTuple(new Object[]{T_NEWLINE, T_CRLF});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{T_NEWLINE, T_CRLF});
case SEEN_CR | SEEN_LF | SEEN_CRLF:
- return factory.createTuple(new Object[]{T_CR, T_NEWLINE, T_CRLF});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{T_CR, T_NEWLINE, T_CRLF});
default:
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
index b0efce23a8..9b5a9a650f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,13 +42,14 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.BufferError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
import com.oracle.graal.python.builtins.objects.memoryview.BufferLifecycleManager;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
@@ -120,14 +121,14 @@ public void markEscaped() {
* it without copying the first time the program asks for the whole contents. So that a sequence
* of writes followed by one getvalue call doesn't have to copy the whole buffer at the end.
*/
- public void unshareIfNecessary(PythonBufferAccessLibrary bufferLib, PythonObjectFactory factory) {
+ public void unshareIfNecessary(PythonBufferAccessLibrary bufferLib, PythonLanguage language) {
if (escaped || getExports() != 0) {
- buf = factory.createByteArray(bufferLib.getCopiedByteArray(buf));
+ buf = PFactory.createByteArray(language, bufferLib.getCopiedByteArray(buf));
escaped = false;
}
}
- public void unshareAndResize(PythonBufferAccessLibrary bufferLib, PythonObjectFactory factory, int size, boolean truncate) {
+ public void unshareAndResize(PythonBufferAccessLibrary bufferLib, PythonLanguage language, int size, boolean truncate) {
int origLength = bufferLib.getBufferLength(getBuf());
int alloc;
if (truncate && size < origLength / 2) {
@@ -135,7 +136,7 @@ public void unshareAndResize(PythonBufferAccessLibrary bufferLib, PythonObjectFa
alloc = size;
} else if (size < origLength) {
/* Within allocated size; quick exit */
- unshareIfNecessary(bufferLib, factory);
+ unshareIfNecessary(bufferLib, language);
return;
} else if (size <= origLength * 1.125) {
/* Moderate upsize; overallocate similar to list_resize() */
@@ -150,7 +151,7 @@ public void unshareAndResize(PythonBufferAccessLibrary bufferLib, PythonObjectFa
}
byte[] newBuf = new byte[alloc];
bufferLib.readIntoByteArray(getBuf(), 0, newBuf, 0, Math.min(stringSize, size));
- setBuf(factory.createByteArray(newBuf));
+ setBuf(PFactory.createByteArray(language, newBuf));
escaped = false;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
index 58547e96d5..ee5e07aa9f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,6 +59,7 @@
import java.io.ByteArrayOutputStream;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -121,24 +122,24 @@ static Object readall(VirtualFrame frame, Object self, @SuppressWarnings("unused
@Specialization(guards = "size >= 0")
static Object read(VirtualFrame frame, Object self, int size,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached BytesNodes.ToBytesNode toBytes,
@Exclusive @Cached PyObjectCallMethodObjArgs callMethodReadInto,
- @Cached PyNumberAsSizeNode asSizeNode,
- @Cached PythonObjectFactory factory) {
- PByteArray b = factory.createByteArray(new byte[size]);
+ @Cached PyNumberAsSizeNode asSizeNode) {
+ PByteArray b = PFactory.createByteArray(language, new byte[size]);
Object res = callMethodReadInto.execute(frame, inliningTarget, self, T_READINTO, b);
if (res == PNone.NONE) {
return res;
}
int n = asSizeNode.executeExact(frame, inliningTarget, res, ValueError);
if (n == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
byte[] bytes = toBytes.execute(b);
if (n < size) {
- return factory.createBytes(PythonUtils.arrayCopyOf(bytes, n));
+ return PFactory.createBytes(language, PythonUtils.arrayCopyOf(bytes, n));
}
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
}
@@ -157,7 +158,6 @@ static Object readall(VirtualFrame frame, Object self,
@Cached InlinedConditionProfile chunksSize0Profile,
@Cached InlinedCountingConditionProfile bytesLen0Profile,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
ByteArrayOutputStream chunks = createOutputStream();
while (true) {
@@ -180,7 +180,7 @@ static Object readall(VirtualFrame frame, Object self,
append(chunks, bytes, bytesLen);
}
- return factory.createBytes(toByteArray(chunks));
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), toByteArray(chunks));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
index b3be129689..1f0ef51ac2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,7 +40,6 @@
*/
package com.oracle.graal.python.builtins.modules.io;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PIncrementalNewlineDecoder;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_CUR;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_END;
import static com.oracle.graal.python.builtins.modules.io.BufferedIOUtil.SEEK_SET;
@@ -87,6 +86,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -117,7 +117,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
@@ -283,7 +283,7 @@ static PNone init(VirtualFrame frame, PStringIO self, TruffleString initialValue
@Cached TruffleStringBuilder.ToStringNode toStringNode,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached IONodes.ToTruffleStringNode toTruffleStringNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
TruffleString newline;
@@ -317,7 +317,7 @@ static PNone init(VirtualFrame frame, PStringIO self, TruffleString initialValue
}
if (self.isReadUniversal()) {
- Object incDecoder = factory.createNLDecoder(PIncrementalNewlineDecoder);
+ Object incDecoder = PFactory.createNLDecoder(language);
initNode.execute(frame, incDecoder, self.getDecoder(), self.isReadTranslate(), PNone.NO_VALUE);
self.setDecoder(incDecoder);
}
@@ -632,11 +632,11 @@ static Object doit(VirtualFrame frame, PStringIO self,
@Bind("this") Node inliningTarget,
@Cached GetValueNode getValueNode,
@Cached GetOrCreateDictNode getDict,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object initValue = getValueNode.execute(frame, self);
Object readnl = self.getReadNewline() == null ? PNone.NONE : self.getReadNewline();
Object[] state = new Object[]{initValue, readnl, self.getPos(), getDict.execute(inliningTarget, self)};
- return factory.createTuple(state);
+ return PFactory.createTuple(language, state);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
index 9961cdefa9..2374247068 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
@@ -129,6 +129,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -166,7 +167,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
@@ -678,7 +679,6 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
checkClosedNode.execute(frame, self);
if (!self.isSeekable()) {
@@ -758,7 +758,7 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
self.clearSnapshot();
/* Restore the decoder to its state from the safe start point. */
- decoderSetStateNode.execute(frame, inliningTarget, self, cookie, factory);
+ decoderSetStateNode.execute(frame, inliningTarget, self, cookie);
if (cookie.charsToSkip != 0) {
/* Just like _read_chunk, feed the decoder and save a snapshot. */
@@ -892,6 +892,7 @@ static Object didntMove(VirtualFrame frame, PTextIO self,
})
static Object tell(VirtualFrame frame, PTextIO self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached TextIOWrapperNodes.WriteFlushNode writeFlushNode,
@Cached TextIOWrapperNodes.DecoderSetStateNode decoderSetStateNode,
@Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@@ -906,7 +907,6 @@ static Object tell(VirtualFrame frame, PTextIO self,
@Exclusive @Cached PyLongAsLongNode asLongNode,
@Cached PyObjectSizeNode sizeNode,
@CachedLibrary(limit = "2") InteropLibrary isString,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
PTextIO.CookieType cookie = getCookie(frame, inliningTarget, self, writeFlushNode, callMethodFlush, callMethodTell, asLongNode);
byte[] snapshotNextInput = self.getSnapshotNextInput();
@@ -921,8 +921,8 @@ static Object tell(VirtualFrame frame, PTextIO self,
assert (skipBack <= nextInputLength);
while (skipBytes > 0) {
/* Decode up to temptative start point */
- decoderSetStateNode.execute(frame, inliningTarget, self, cookie, factory);
- PBytes in = factory.createBytes(snapshotNextInput, skipBytes);
+ decoderSetStateNode.execute(frame, inliningTarget, self, cookie);
+ PBytes in = PFactory.createBytes(language, snapshotNextInput, skipBytes);
int charsDecoded = decoderDecode(frame, inliningTarget, self, in, callMethodDecode, toString, codePointLengthNode);
if (charsDecoded <= decodedCharsUsed) {
Object[] state = decoderGetstate(frame, inliningTarget, self, savedState, getObjectArrayNode, callMethodGetState, callMethodSetState, raiseNode);
@@ -945,7 +945,7 @@ static Object tell(VirtualFrame frame, PTextIO self,
}
if (skipBytes <= 0) {
skipBytes = 0;
- decoderSetStateNode.execute(frame, inliningTarget, self, cookie, factory);
+ decoderSetStateNode.execute(frame, inliningTarget, self, cookie);
}
/* Note our initial start point. */
@@ -962,7 +962,7 @@ static Object tell(VirtualFrame frame, PTextIO self,
int charsDecoded = 0;
byte[] input = PythonUtils.arrayCopyOfRange(snapshotNextInput, skipBytes, nextInputLength);
while (input.length > 0) {
- PBytes start = factory.createBytes(input, 1);
+ PBytes start = PFactory.createBytes(language, input, 1);
int n = decoderDecode(frame, inliningTarget, self, start, callMethodDecode, toString, codePointLengthNode);
/* We got n chars for 1 byte */
charsDecoded += n;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
index 9d0e636a58..a614ee75ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
@@ -42,7 +42,6 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.EncodingWarning;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IOUnsupportedOperation;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PIncrementalNewlineDecoder;
import static com.oracle.graal.python.builtins.modules.CodecsTruffleModuleBuiltins.T_INCREMENTALDECODER;
import static com.oracle.graal.python.builtins.modules.CodecsTruffleModuleBuiltins.T_INCREMENTALENCODER;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_CLOSED;
@@ -77,6 +76,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.CodecsTruffleModuleBuiltins;
import com.oracle.graal.python.builtins.modules.CodecsTruffleModuleBuiltins.MakeIncrementalcodecNode;
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
@@ -100,7 +100,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -199,10 +199,10 @@ static void nothingTodo(@SuppressWarnings("unused") PTextIO self) {
@Specialization(guards = "self.hasPendingBytes()")
static void writeflush(VirtualFrame frame, Node inliningTarget, PTextIO self,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PyObjectCallMethodObjArgs callMethod) {
byte[] pending = self.getAndClearPendingBytes();
- PBytes b = factory.createBytes(pending);
+ PBytes b = PFactory.createBytes(language, pending);
callMethod.execute(frame, inliningTarget, self.getBuffer(), T_WRITE, b);
// TODO: check _PyIO_trap_eintr
}
@@ -631,10 +631,10 @@ static TruffleString decodeGeneric(VirtualFrame frame, Object decoder, Object o,
@GenerateCached(false)
protected abstract static class DecoderSetStateNode extends Node {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, PTextIO self, PTextIO.CookieType cookie, PythonObjectFactory factory);
+ public abstract void execute(VirtualFrame frame, Node inliningTarget, PTextIO self, PTextIO.CookieType cookie);
@Specialization(guards = "!self.hasDecoder()")
- static void nothing(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") PTextIO.CookieType cookie, @SuppressWarnings("unused") PythonObjectFactory factory) {
+ static void nothing(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") PTextIO.CookieType cookie) {
// nothing to do.
}
@@ -650,15 +650,16 @@ protected static boolean isAtInit(PTextIO.CookieType cookie) {
}
@Specialization(guards = {"self.hasDecoder()", "isAtInit(cookie)"})
- static void atInit(VirtualFrame frame, Node inliningTarget, PTextIO self, @SuppressWarnings("unused") PTextIO.CookieType cookie, @SuppressWarnings("unused") PythonObjectFactory factory,
+ static void atInit(VirtualFrame frame, Node inliningTarget, PTextIO self, @SuppressWarnings("unused") PTextIO.CookieType cookie,
@Exclusive @Cached PyObjectCallMethodObjArgs callMethodReset) {
callMethodReset.execute(frame, inliningTarget, self.getDecoder(), T_RESET);
}
@Specialization(guards = {"self.hasDecoder()", "!isAtInit(cookie)"})
- static void decoderSetstate(VirtualFrame frame, Node inliningTarget, PTextIO self, PTextIO.CookieType cookie, PythonObjectFactory factory,
+ static void decoderSetstate(VirtualFrame frame, Node inliningTarget, PTextIO self, PTextIO.CookieType cookie,
+ @Bind PythonLanguage language,
@Exclusive @Cached PyObjectCallMethodObjArgs callMethodSetState) {
- PTuple tuple = factory.createTuple(new Object[]{factory.createEmptyBytes(), cookie.decFlags});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{PFactory.createEmptyBytes(language), cookie.decFlags});
callMethodSetState.execute(frame, inliningTarget, self.getDecoder(), T_SETSTATE, tuple);
}
@@ -747,15 +748,14 @@ static void setDecoder(VirtualFrame frame, Node inliningTarget, PTextIO self, Ob
@Cached(inline = false) MakeIncrementalcodecNode makeIncrementalcodecNode,
@Cached InlinedConditionProfile isTrueProfile,
@Cached PyObjectCallMethodObjArgs callMethodReadable,
- @Cached PyObjectIsTrueNode isTrueNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached PyObjectIsTrueNode isTrueNode) {
Object res = callMethodReadable.execute(frame, inliningTarget, self.getBuffer(), T_READABLE);
if (isTrueProfile.profile(inliningTarget, !isTrueNode.execute(frame, res))) {
return;
}
Object decoder = makeIncrementalcodecNode.execute(frame, codecInfo, errors, T_INCREMENTALDECODER);
if (self.isReadUniversal()) {
- PNLDecoder incDecoder = factory.createNLDecoder(PIncrementalNewlineDecoder);
+ PNLDecoder incDecoder = PFactory.createNLDecoder(PythonLanguage.get(inliningTarget));
IncrementalNewlineDecoderBuiltins.InitNode.internalInit(incDecoder, decoder, self.isReadTranslate());
self.setDecoder(incDecoder);
} else {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
index 5aa6922398..59cc6e6a1d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2020 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -21,6 +21,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -62,12 +63,12 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.formatting.FloatFormatter;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -108,8 +109,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
protected PTuple call(PJSONEncoder self, Object obj, @SuppressWarnings("unused") int indent,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{jsonEncode(self, obj)});
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, new Object[]{jsonEncode(self, obj)});
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
index 7a24558a6f..2de099ac51 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
@@ -12,6 +12,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -25,6 +26,7 @@
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
import com.oracle.graal.python.builtins.objects.str.StringNodes.CastToJavaStringCheckedNode;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -36,7 +38,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -94,11 +96,11 @@ protected ArgumentClinicProvider getArgumentClinic() {
Object call(Object string, int end, boolean strict,
@Bind("this") Node inliningTarget,
@Cached CastToJavaStringCheckedNode castString,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
IntRef nextIdx = new IntRef();
TruffleString result = JSONScannerBuiltins.scanStringUnicode(castString.cast(inliningTarget, string, ErrorMessages.FIRST_ARG_MUST_BE_STRING_NOT_P, string), end, strict, nextIdx,
this);
- return factory.createTuple(new Object[]{result, nextIdx.value});
+ return PFactory.createTuple(language, new Object[]{result, nextIdx.value});
}
}
@@ -189,7 +191,8 @@ public abstract static class MakeScanner extends PythonBinaryBuiltinNode {
@Specialization
public PJSONScanner doNew(VirtualFrame frame, Object cls, Object context,
@Cached PyObjectIsTrueNode castStrict,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
boolean strict = castStrict.execute(frame, getStrict.execute(frame, context));
Object objectHook = getObjectHook.execute(frame, context);
@@ -197,7 +200,7 @@ public PJSONScanner doNew(VirtualFrame frame, Object cls, Object context,
Object parseFloat = getParseFloat.execute(frame, context);
Object parseInt = getParseInt.execute(frame, context);
Object parseConstant = getParseConstant.execute(frame, context);
- return factory.createJSONScanner(cls, strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant);
+ return PFactory.createJSONScanner(language, cls, getInstanceShape.execute(cls), strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant);
}
}
@@ -241,7 +244,8 @@ PJSONEncoder doNew(Object cls, Object markers, Object defaultFn, Object encoder,
}
}
}
- return getContext().factory().createJSONEncoder(cls, markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode);
+ return PFactory.createJSONEncoder(PythonLanguage.get(null), cls, TypeNodes.GetInstanceShape.executeUncached(cls),
+ markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
index 97146e249d..48838a024b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
@@ -38,18 +38,15 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.truffle.api.CompilerAsserts;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
-import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
@CoreFunctions(extendClasses = PythonBuiltinClassType.JSONScanner)
@@ -78,11 +75,6 @@ public abstract static class CallScannerNode extends PythonTernaryClinicBuiltinN
@Child private CallUnaryMethodNode callParseConstant = CallUnaryMethodNode.create();
@Child private CallUnaryMethodNode callObjectHook = CallUnaryMethodNode.create();
@Child private CallUnaryMethodNode callObjectPairsHook = CallUnaryMethodNode.create();
- @Child private PythonObjectFactory factory = PythonObjectFactory.create();
-
- @CompilationFinal private Shape tupleInstanceShape;
- @CompilationFinal private Shape listInstanceShape;
- @CompilationFinal private Shape dictInstanceShape;
@Override
protected ArgumentClinicProvider getArgumentClinic() {
@@ -92,21 +84,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
protected PTuple call(PJSONScanner self, TruffleString string, int idx,
@Cached TruffleString.ToJavaStringNode toJavaStringNode) {
- if (tupleInstanceShape == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- tupleInstanceShape = PythonLanguage.get(this).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PTuple);
- }
- if (listInstanceShape == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- listInstanceShape = PythonLanguage.get(this).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PList);
- }
- if (dictInstanceShape == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- dictInstanceShape = PythonLanguage.get(this).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PDict);
- }
IntRef nextIdx = new IntRef();
Object result = scanOnceUnicode(self, toJavaStringNode.execute(string), idx, nextIdx);
- return factory.createTuple(new Object[]{result, nextIdx.value});
+ return PFactory.createTuple(PythonLanguage.get(this), new Object[]{result, nextIdx.value});
}
@TruffleBoundary
@@ -120,6 +100,8 @@ private Object parseObjectUnicode(PJSONScanner scanner, String string, int start
*/
boolean hasPairsHook = scanner.objectPairsHook != PNone.NONE;
+ PythonLanguage language = PythonLanguage.get(null);
+
int idx = start;
int length = string.length();
@@ -161,7 +143,7 @@ private Object parseObjectUnicode(PJSONScanner scanner, String string, int start
idx = nextIdx.value;
if (hasPairsHook) {
- listStorage.insertItem(listStorage.length(), factory.createTuple(PythonBuiltinClassType.PTuple, tupleInstanceShape, new Object[]{key, val}));
+ listStorage.insertItem(listStorage.length(), PFactory.createTuple(language, new Object[]{key, val}));
} else {
HashingStorage newStorage = HashingStorageSetItem.executeUncached(mapStorage, key, val);
assert newStorage == mapStorage;
@@ -186,11 +168,11 @@ private Object parseObjectUnicode(PJSONScanner scanner, String string, int start
nextIdx.value = idx + 1;
if (hasPairsHook) {
- return callObjectPairsHook.executeObject(scanner.objectPairsHook, factory.createList(PythonBuiltinClassType.PList, listInstanceShape, listStorage));
+ return callObjectPairsHook.executeObject(scanner.objectPairsHook, PFactory.createList(language, listStorage));
}
/* if object_hook is not None: rval = object_hook(rval) */
- PDict rval = factory.createDict(PythonBuiltinClassType.PDict, dictInstanceShape, mapStorage);
+ PDict rval = PFactory.createDict(language, mapStorage);
if (scanner.objectHook != PNone.NONE) {
return callObjectHook.executeObject(scanner.objectHook, rval);
}
@@ -242,7 +224,7 @@ private Object parseArrayUnicode(PJSONScanner scanner, String string, int start,
throw decodeError(this, string, length - 1, ErrorMessages.EXPECTING_VALUE);
}
nextIdx.value = idx + 1;
- return factory.createList(PythonBuiltinClassType.PList, listInstanceShape, storage);
+ return PFactory.createList(PythonLanguage.get(null), storage);
}
private static int skipWhitespace(String string, int start, int length) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
index 295b43080d..d5644b074a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.ClinicConverterFactory;
@@ -78,7 +79,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
import com.oracle.truffle.api.dsl.Bind;
@@ -178,11 +179,11 @@ abstract static class CompressNode extends PythonBinaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
static PBytes doBytes(VirtualFrame frame, LZMACompressor self, Object data,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetArrayAndLengthHelperNode getArrayAndLengthHelperNode,
- @Cached LZMANodes.CompressNode compress,
- @Cached PythonObjectFactory factory) {
+ @Cached LZMANodes.CompressNode compress) {
ArrayAndLength aal = getArrayAndLengthHelperNode.execute(frame, inliningTarget, data);
- return factory.createBytes(compress.compress(inliningTarget, self, PythonContext.get(inliningTarget), aal.array, aal.length));
+ return PFactory.createBytes(language, compress.compress(inliningTarget, self, PythonContext.get(inliningTarget), aal.array, aal.length));
}
@SuppressWarnings("unused")
@@ -226,10 +227,10 @@ abstract static class FlushNode extends PythonUnaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
static PBytes doit(LZMACompressor self,
@Bind("this") Node inliningTarget,
- @Cached LZMANodes.CompressNode compress,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached LZMANodes.CompressNode compress) {
self.setFlushed();
- return factory.createBytes(compress.flush(inliningTarget, self, PythonContext.get(inliningTarget)));
+ return PFactory.createBytes(language, compress.flush(inliningTarget, self, PythonContext.get(inliningTarget)));
}
@SuppressWarnings("unused")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
index c86554b75e..17983e6658 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -56,6 +56,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -78,7 +79,7 @@
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -205,24 +206,24 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = {"!self.isEOF()"})
static PBytes doBytes(LZMADecompressor self, PBytesLike data, int maxLength,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached SequenceStorageNodes.GetInternalByteArrayNode toBytes,
- @Exclusive @Cached LZMANodes.DecompressNode decompress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached LZMANodes.DecompressNode decompress) {
byte[] bytes = toBytes.execute(inliningTarget, data.getSequenceStorage());
int len = data.getSequenceStorage().length();
- return factory.createBytes(decompress.execute(inliningTarget, self, bytes, len, maxLength));
+ return PFactory.createBytes(language, decompress.execute(inliningTarget, self, bytes, len, maxLength));
}
@Specialization(guards = {"!self.isEOF()"})
static PBytes doObject(VirtualFrame frame, LZMADecompressor self, Object data, int maxLength,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached BytesNodes.ToBytesNode toBytes,
- @Exclusive @Cached LZMANodes.DecompressNode decompress,
- @Shared @Cached PythonObjectFactory factory) {
+ @Exclusive @Cached LZMANodes.DecompressNode decompress) {
byte[] bytes = toBytes.execute(frame, data);
int len = bytes.length;
- return factory.createBytes(decompress.execute(inliningTarget, self, bytes, len, maxLength));
+ return PFactory.createBytes(language, decompress.execute(inliningTarget, self, bytes, len, maxLength));
}
@SuppressWarnings("unused")
@@ -282,8 +283,8 @@ abstract static class UnusedDataNode extends PythonUnaryBuiltinNode {
@Specialization
static PBytes doUnusedData(LZMADecompressor self,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(self.getUnusedData());
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, self.getUnusedData());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
index 045ee97e5d..7574a24ee4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -80,6 +80,7 @@
import org.graalvm.shadowed.org.tukaani.xz.XZ;
import org.graalvm.shadowed.org.tukaani.xz.XZOutputStream;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -88,6 +89,7 @@
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -97,7 +99,8 @@
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.runtime.NFILZMASupport;
import com.oracle.graal.python.runtime.NativeLibrary;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -262,27 +265,27 @@ public void postInitialize(Python3Core c) {
@Builtin(name = "LZMACompressor", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, constructsClass = PLZMACompressor)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class LZMACompressorNode extends PythonBuiltinNode {
@Specialization
LZMAObject doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see LZMACompressorBuiltins.InitNode
- return factory.createLZMACompressor(cls, getContext().getNFILZMASupport().isAvailable());
+ PythonContext context = getContext();
+ return PFactory.createLZMACompressor(context.getLanguage(this), cls, getInstanceShape.execute(cls), context.getNFILZMASupport().isAvailable());
}
}
@Builtin(name = "LZMADecompressor", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, constructsClass = PLZMADecompressor)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class LZMADecompressorNode extends PythonBuiltinNode {
@Specialization
LZMAObject doNew(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PythonObjectFactory factory) {
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
// data filled in subsequent __init__ call - see LZMADecompressorBuiltins.InitNode
- return factory.createLZMADecompressor(cls, getContext().getNFILZMASupport().isAvailable());
+ PythonContext context = getContext();
+ return PFactory.createLZMADecompressor(context.getLanguage(this), cls, getInstanceShape.execute(cls), context.getNFILZMASupport().isAvailable());
}
}
@@ -308,8 +311,8 @@ abstract static class EncodeFilterPropertiesNode extends PythonUnaryBuiltinNode
@Specialization
static PBytes encode(VirtualFrame frame, Object filter,
@Cached LZMANodes.EncodeFilterProperties encodeFilterProperties,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeFilterProperties.execute(frame, filter));
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, encodeFilterProperties.execute(frame, filter));
}
}
@@ -321,12 +324,12 @@ abstract static class DecodeFilterPropertiesNode extends PythonBinaryBuiltinNode
@Specialization
static PDict encode(VirtualFrame frame, Object id, Object encodedProps,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached CastToJavaLongLossyNode toLong,
@Cached BytesNodes.ToBytesNode toBytes,
- @Cached LZMANodes.DecodeFilterProperties decodeFilterProperties,
- @Cached PythonObjectFactory factory) {
+ @Cached LZMANodes.DecodeFilterProperties decodeFilterProperties) {
byte[] bytes = toBytes.execute(frame, encodedProps);
- PDict dict = factory.createDict();
+ PDict dict = PFactory.createDict(language);
decodeFilterProperties.execute(frame, toLong.execute(inliningTarget, id), bytes, dict);
return dict;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
index 45a533e723..41e7a60abf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.List;
import java.util.concurrent.Semaphore;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.SharedMultiprocessingData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -240,7 +241,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object doEnter(@SuppressWarnings("unused") Object handle, int kind, @SuppressWarnings("unused") Object maxvalue, TruffleString name,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SharedMultiprocessingData multiprocessing = PythonContext.get(inliningTarget).getSharedMultiprocessingData();
Semaphore semaphore = multiprocessing.getNamedSemaphore(name);
if (semaphore == null) {
@@ -248,7 +249,7 @@ static Object doEnter(@SuppressWarnings("unused") Object handle, int kind, @Supp
// provided handle
semaphore = newSemaphore();
}
- return factory.createGraalPySemLock(PythonBuiltinClassType.PGraalPySemLock, name, kind, semaphore);
+ return PFactory.createGraalPySemLock(language, name, kind, semaphore);
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
index 308f2b859b..86d2466c87 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -64,6 +64,7 @@
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.thread.PThread;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectSizeNode;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -85,7 +86,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.Timeval;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.SharedMultiprocessingData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.ArrayBuilder;
@@ -118,7 +119,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Override
public void initialize(Python3Core core) {
// TODO: add necessary entries to the dict
- addBuiltinConstant("flags", core.factory().createDict());
+ addBuiltinConstant("flags", PFactory.createDict(core.getLanguage()));
super.initialize(core);
}
@@ -133,7 +134,8 @@ abstract static class SemLockNode extends PythonClinicBuiltinNode {
@Specialization
static PGraalPySemLock construct(Object cls, int kind, int value, @SuppressWarnings("unused") int maxValue, TruffleString name, boolean unlink,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (kind != PGraalPySemLock.RECURSIVE_MUTEX && kind != PGraalPySemLock.SEMAPHORE) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.UNRECOGNIZED_KIND);
@@ -152,7 +154,7 @@ static PGraalPySemLock construct(Object cls, int kind, int value, @SuppressWarni
multiprocessing.putNamedSemaphore(name, semaphore);
}
}
- return factory.createGraalPySemLock(cls, name, kind, semaphore);
+ return PFactory.createGraalPySemLock(language, cls, getInstanceShape.execute(cls), name, kind, semaphore);
}
@TruffleBoundary
@@ -218,13 +220,13 @@ long getTid(
abstract static class WaitTidNode extends PythonBinaryBuiltinNode {
@Specialization
PTuple waittid(long id, @SuppressWarnings("unused") int options,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
long tid = convertTid(id);
// TODO implement for options - WNOHANG and 0
final SharedMultiprocessingData multiprocessing = getContext().getSharedMultiprocessingData();
Thread thread = multiprocessing.getChildContextThread(tid);
if (thread != null && thread.isAlive()) {
- return factory.createTuple(new Object[]{0, 0, 0});
+ return PFactory.createTuple(language, new Object[]{0, 0, 0});
}
PythonContext.ChildContextData data = multiprocessing.getChildContextData(tid);
@@ -234,7 +236,7 @@ PTuple waittid(long id, @SuppressWarnings("unused") int options,
* clean it. See popen_truffleprocess that calls the _waittid builtin.
*/
multiprocessing.removeChildContextData(tid);
- return factory.createTuple(new Object[]{id, data.wasSignaled() ? data.getExitCode() : 0, data.getExitCode()});
+ return PFactory.createTuple(language, new Object[]{id, data.wasSignaled() ? data.getExitCode() : 0, data.getExitCode()});
}
}
@@ -274,7 +276,7 @@ abstract static class PipeNode extends PythonBuiltinNode {
@Specialization
PTuple pipe(@Cached GilNode gil,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int[] pipe;
PythonContext ctx = getContext();
SharedMultiprocessingData sharedData = ctx.getSharedMultiprocessingData();
@@ -286,7 +288,7 @@ PTuple pipe(@Cached GilNode gil,
} finally {
gil.acquire();
}
- return factory.createTuple(new Object[]{pipe[0], pipe[1]});
+ return PFactory.createTuple(language, new Object[]{pipe[0], pipe[1]});
}
}
@@ -327,8 +329,8 @@ Object doWrite(long fd, PBytes data,
public abstract static class ReadNode extends PythonBinaryBuiltinNode {
@Specialization
Object doReadInt(int fd, @SuppressWarnings("unused") Object length,
- @Shared @Cached GilNode gil,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached GilNode gil) {
SharedMultiprocessingData sharedData = getContext().getSharedMultiprocessingData();
gil.release(true);
try {
@@ -336,9 +338,9 @@ Object doReadInt(int fd, @SuppressWarnings("unused") Object length,
throw PRaiseNode.raiseUncached(this, OSError, ErrorMessages.BAD_FILE_DESCRIPTOR);
});
if (data == PNone.NONE) {
- return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY, 0, 0);
+ return PFactory.createEmptyBytes(language);
}
- return factory.createBytes((byte[]) data);
+ return PFactory.createBytes(language, (byte[]) data);
} finally {
gil.acquire();
}
@@ -346,9 +348,9 @@ Object doReadInt(int fd, @SuppressWarnings("unused") Object length,
@Specialization
Object doReadLong(long fd, Object length,
- @Shared @Cached GilNode gil,
- @Shared @Cached PythonObjectFactory factory) {
- return doReadInt((int) fd, length, gil, factory);
+ @Bind PythonLanguage language,
+ @Shared @Cached GilNode gil) {
+ return doReadInt((int) fd, length, language, gil);
}
}
@@ -394,6 +396,7 @@ abstract static class SelectNode extends PythonBuiltinNode {
@Specialization
Object doGeneric(VirtualFrame frame, Object multiprocessingFdsList, Object multiprocessingObjsList, Object posixFileObjsList, Object timeoutObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PosixModuleBuiltins.FileDescriptorConversionNode fdConvertor,
@Cached PyObjectSizeNode sizeNode,
@Cached PyObjectGetItem getItem,
@@ -402,8 +405,7 @@ Object doGeneric(VirtualFrame frame, Object multiprocessingFdsList, Object multi
@Cached CastToJavaIntLossyNode castToJava,
@Cached CastToJavaDoubleNode castToDouble,
@Cached GilNode gil,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
PythonContext context = getContext();
SharedMultiprocessingData sharedData = context.getSharedMultiprocessingData();
@@ -443,7 +445,7 @@ Object doGeneric(VirtualFrame frame, Object multiprocessingFdsList, Object multi
}
}
- return factory.createList(result.toArray(new Object[0]));
+ return PFactory.createList(language, result.toArray(new Object[0]));
} catch (PosixSupportLibrary.PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} finally {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
index 3b290b2982..503ec392a6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,12 +45,14 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -61,7 +63,7 @@
import com.oracle.graal.python.runtime.PosixSupport;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -92,7 +94,8 @@ static PSemLock construct(VirtualFrame frame, Object cls, int kind, int value, i
@Bind("this") Node inliningTarget,
@Bind("getPosixSupport()") PosixSupport posixSupport,
@CachedLibrary("posixSupport") PosixSupportLibrary posixLib,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
if (kind != PGraalPySemLock.RECURSIVE_MUTEX && kind != PGraalPySemLock.SEMAPHORE) {
@@ -117,7 +120,7 @@ static PSemLock construct(VirtualFrame frame, Object cls, int kind, int value, i
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
}
- return factory.createSemLock(cls, handle, kind, maxValue, name);
+ return PFactory.createSemLock(language, cls, getInstanceShape.execute(cls), handle, kind, maxValue, name);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
index 2834d0b355..6b25b671de 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -55,6 +56,7 @@
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.thread.PThread;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
@@ -71,7 +73,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.UnsupportedPosixFeatureException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -362,7 +364,8 @@ static Object rebuild(VirtualFrame frame, Object cls, @SuppressWarnings("unused"
@Bind("this") Node inliningTarget,
@Bind("getPosixSupport()") PosixSupport posixSupport,
@CachedLibrary("posixSupport") PosixSupportLibrary posixLib,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Object posixName = posixLib.createPathFromString(posixSupport, name);
long handle;
@@ -371,7 +374,7 @@ static Object rebuild(VirtualFrame frame, Object cls, @SuppressWarnings("unused"
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
- return factory.createSemLock(cls, handle, kind, maxValue, name);
+ return PFactory.createSemLock(language, cls, getInstanceShape.execute(cls), handle, kind, maxValue, name);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
index ec3f3c30a2..61a1f25b8f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.modules.pickle;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -47,7 +48,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
@@ -155,7 +156,7 @@ public abstract static class PDataPopTupleNode extends PDataBaseNode {
@Specialization
static PTuple popTuple(PData self, int start,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
int len, i, j;
@@ -168,7 +169,7 @@ static PTuple popTuple(PData self, int start,
items[j] = self.data[i];
}
self.size = start;
- return factory.createTuple(items);
+ return PFactory.createTuple(language, items);
}
public static PDataPopTupleNode create() {
@@ -183,7 +184,7 @@ public abstract static class PDataPopListNode extends PDataBaseNode {
@Specialization
public PList popList(PData self, int start,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int len, i, j;
len = self.size - start;
@@ -192,7 +193,7 @@ public PList popList(PData self, int start,
items[j] = self.data[i];
}
self.size = start;
- return factory.createList(items);
+ return PFactory.createList(language, items);
}
public static PDataPopListNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
index 5331ccbf86..673b820c03 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
@@ -65,6 +65,7 @@
import org.graalvm.collections.Pair;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
@@ -107,7 +108,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.Consumer;
import com.oracle.graal.python.util.NumericSupport;
@@ -353,9 +354,9 @@ public void commitFrame() {
frameStart = -1;
}
- public PBytes getString(PythonObjectFactory factory) {
+ public PBytes getString(PythonLanguage language) {
commitFrame();
- return factory.createBytes(outputBuffer, outputLen);
+ return PFactory.createBytes(language, outputBuffer, outputLen);
}
// inner nodes
@@ -528,7 +529,7 @@ protected void writeBytes(VirtualFrame frame, PPickler pickler, byte[] header, i
if (pld == null) {
// TODO: It would be better to use a memoryview with a linked original string if
// this is possible.
- pld = factory().createBytes(data, 0, dataSize);
+ pld = PFactory.createBytes(PythonLanguage.get(this), data, dataSize);
}
getCallNode().execute(frame, pickler.write, pld);
// Reinitialize the buffer for subsequent calls to _Pickler_Write.
@@ -543,9 +544,9 @@ protected void writeBytes(VirtualFrame frame, PPickler pickler, byte[] header, i
protected PTuple createTuple(Object... items) {
if (items.length == 0) {
- return factory().createEmptyTuple();
+ return PFactory.createEmptyTuple(PythonLanguage.get(this));
}
- return factory().createTuple(items);
+ return PFactory.createTuple(PythonLanguage.get(this), items);
}
protected void fastSaveEnter(PPickler pickler, Object obj) {
@@ -570,10 +571,11 @@ public abstract static class FlushToFileNode extends BasePickleWriteNode {
public abstract void execute(VirtualFrame frame, PPickler pickler);
@Specialization
- public void flush(VirtualFrame frame, PPickler pickler) {
+ public void flush(VirtualFrame frame, PPickler pickler,
+ @Bind PythonLanguage language) {
assert pickler.write != null;
// This will commit the frame first
- PBytes output = pickler.getString(factory());
+ PBytes output = pickler.getString(language);
call(frame, pickler.write, output);
}
}
@@ -1054,7 +1056,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
callable = callStarArgsAndKwArgs(frame, st.partial, newargs, kwargs);
save(frame, pickler, callable, 0);
- save(frame, pickler, factory().createEmptyTuple(), 0);
+ save(frame, pickler, PFactory.createEmptyTuple(PythonLanguage.get(this)), 0);
write(pickler, PickleUtils.OPCODE_REDUCE);
}
} else if (useNewobj) {
@@ -1110,7 +1112,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
// Save the class and its __new__ arguments
save(frame, pickler, cls, 0);
- newargtup = getItem(frame, argtup, factory().createIntSlice(1, argtupSize, 1));
+ newargtup = getItem(frame, argtup, PFactory.createIntSlice(PythonLanguage.get(this), 1, argtupSize, 1));
save(frame, pickler, newargtup, 0);
write(pickler, PickleUtils.OPCODE_NEWOBJ);
} else {
@@ -1738,7 +1740,7 @@ private void saveBytearrayData(VirtualFrame frame, PPickler pickler, Object obj,
memoPut(pickler, obj);
}
- private void saveBytearray(VirtualFrame frame, PythonContext ctx, PPickler pickler, Object obj, IndirectCallData indirectCallData) {
+ private void saveBytearray(VirtualFrame frame, Node inliningTarget, PythonContext ctx, PPickler pickler, Object obj, IndirectCallData indirectCallData) {
Object buffer = getBufferAcquireLibrary().acquireReadonly(obj, frame, indirectCallData);
try {
if (pickler.proto < 5) {
@@ -1750,7 +1752,7 @@ private void saveBytearray(VirtualFrame frame, PythonContext ctx, PPickler pickl
reduceValue = createTuple(byteArrayClass, createTuple());
} else {
byte[] bytes = getBufferLibrary().getCopiedByteArray(buffer);
- reduceValue = createTuple(byteArrayClass, createTuple(factory().createBytes(bytes)));
+ reduceValue = createTuple(byteArrayClass, createTuple(PFactory.createBytes(ctx.getLanguage(inliningTarget), bytes)));
}
// save_reduce() will memoize the object automatically.
@@ -2026,7 +2028,7 @@ void saveGeneric(VirtualFrame frame, PPickler pickler, Object objArg, int persSa
saveTuple(frame, pickler, obj);
return;
} else if (isBuiltinClass(type, PythonBuiltinClassType.PByteArray)) {
- saveBytearray(frame, ctx, pickler, obj, indirectCallData);
+ saveBytearray(frame, inliningTarget, ctx, pickler, obj, indirectCallData);
return;
} else if (obj instanceof PPickleBuffer buffer) {
savePicklebuffer(frame, pickler, buffer);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
index f3e125de7b..f655fa1a01 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
@@ -130,6 +130,7 @@
import org.graalvm.collections.Pair;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.buffer.BufferFlags;
@@ -168,6 +169,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.NumericSupport;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -442,7 +444,7 @@ protected PythonBufferAccessLibrary getBufferAccessLibrary() {
}
public Object createMemoryViewFromBytes(VirtualFrame frame, byte[] bytes, int n) {
- return ensureMemoryViewNode().execute(frame, factory().createByteArray(bytes, n));
+ return ensureMemoryViewNode().execute(frame, PFactory.createByteArray(PythonLanguage.get(this), bytes, n));
}
public Object createMemoryView(VirtualFrame frame, Object obj) {
@@ -946,7 +948,7 @@ private void loadCountedBinBytes(VirtualFrame frame, PUnpickler self, int nbytes
byte[] buffer = new byte[size];
readInto(frame, self, buffer);
- Object bytes = factory().createBytes(buffer);
+ Object bytes = PFactory.createBytes(PythonLanguage.get(this), buffer);
pDataPush(self, bytes);
}
@@ -960,7 +962,7 @@ private void loadCountedByteArray(VirtualFrame frame, PUnpickler self) {
byte[] buffer = new byte[size];
readInto(frame, self, buffer);
- Object bytearray = factory().createByteArray(buffer);
+ Object bytearray = PFactory.createByteArray(PythonLanguage.get(this), buffer);
pDataPush(self, bytearray);
}
@@ -1008,7 +1010,7 @@ private void loadCountedBinString(VirtualFrame frame, PUnpickler self, int nbyte
// Convert Python 2.x strings to bytes if the *encoding* given to the Unpickler was
// 'bytes'. Otherwise, convert them to unicode.
- final PBytes bytes = factory().createBytes(s.getBytes(size), size);
+ final PBytes bytes = PFactory.createBytes(PythonLanguage.get(this), s.getBytes(size), size);
if (ensureTsEqualNode().execute(self.encoding, T_CODEC_BYTES, TS_ENCODING)) {
obj = bytes;
} else {
@@ -1037,7 +1039,11 @@ private void loadString(VirtualFrame frame, PUnpickler self) {
// Use the PyBytes API to decode the string, since that is what is used to encode, and
// then coerce the result to Unicode.
- bytes = escapeDecode(frame, factory(), s, pStart, len);
+ if (len == 0) {
+ bytes = PFactory.createEmptyBytes(PythonLanguage.get(this));
+ } else {
+ bytes = escapeDecode(frame, PythonUtils.arrayCopyOfRange(s, pStart, pStart + len));
+ }
// Leave the Python 2.x strings as bytes if the *encoding* given to the Unpickler was
// 'bytes'. Otherwise, convert them to unicode.
@@ -1093,7 +1099,7 @@ private void loadTuple(PUnpickler self) {
}
private void loadEmptyList(PUnpickler self) {
- pDataPush(self, factory().createList());
+ pDataPush(self, PFactory.createList(PythonLanguage.get(this)));
}
private void loadList(PUnpickler self) {
@@ -1103,7 +1109,7 @@ private void loadList(PUnpickler self) {
}
private void loadEmptyDict(PUnpickler self) {
- pDataPush(self, factory().createDict());
+ pDataPush(self, PFactory.createDict(PythonLanguage.get(this)));
}
private void loadDict(VirtualFrame frame, PUnpickler self) {
@@ -1125,11 +1131,11 @@ private void loadDict(VirtualFrame frame, PUnpickler self) {
}
self.stack.clear(i);
- pDataPush(self, factory().createDict(storage));
+ pDataPush(self, PFactory.createDict(PythonLanguage.get(this), storage));
}
private void loadEmptySet(PUnpickler self) {
- pDataPush(self, factory().createSet());
+ pDataPush(self, PFactory.createSet(PythonLanguage.get(this)));
}
private void loadAddItems(VirtualFrame frame, PUnpickler self) {
@@ -1168,7 +1174,7 @@ private void loadAddItems(VirtualFrame frame, PUnpickler self) {
private void loadFrozenSet(VirtualFrame frame, PUnpickler self) {
int i = marker(self);
Object items = pDataPopTuple(self, i);
- Object frozenset = factory().createFrozenSet(getClonedHashingStorage(frame, items));
+ Object frozenset = PFactory.createFrozenSet(PythonLanguage.get(this), getClonedHashingStorage(frame, items));
pDataPush(self, frozenset);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
index 6f588766b2..6c64e33abb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.BufferFormat;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -84,7 +85,7 @@ Object raw(VirtualFrame frame, PPickleBuffer self,
@Bind("this") Node inliningTarget,
@Cached PyMemoryViewFromObject memoryViewFromObject,
@Cached MemoryViewNodes.ReleaseNode releaseNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
final Object view = self.getView();
if (view == null) {
@@ -98,7 +99,7 @@ Object raw(VirtualFrame frame, PPickleBuffer self,
}
int[] shape = new int[]{mv.getLength()};
int[] strides = new int[]{1};
- return factory.createMemoryView(getContext(), mv.getLifecycleManager(), mv.getBuffer(), mv.getOwner(), mv.getLength(),
+ return PFactory.createMemoryView(language, getContext(), mv.getLifecycleManager(), mv.getBuffer(), mv.getOwner(), mv.getLength(),
mv.isReadOnly(), 1, BufferFormat.UINT_8, BufferFormat.T_UINT_8_TYPE_CODE, 1,
mv.getBufferPointer(), mv.getOffset(), shape, strides,
null, PMemoryView.FLAG_C | PMemoryView.FLAG_FORTRAN);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
index 891068b1dc..4f7a0a56c9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -56,6 +57,7 @@
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.nodes.HiddenAttr;
@@ -66,7 +68,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -99,11 +101,11 @@ public void postInitialize(Python3Core core) {
abstract static class ConstructPickleBufferNode extends PythonBinaryBuiltinNode {
@Specialization(limit = "3")
static PPickleBuffer construct(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object object,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @CachedLibrary("object") PythonBufferAcquireLibrary acquireLib,
- @Cached PythonObjectFactory factory) {
+ @CachedLibrary("object") PythonBufferAcquireLibrary acquireLib) {
Object buffer = acquireLib.acquire(object, BufferFlags.PyBUF_FULL_RO, frame, indirectCallData);
- return factory.createPickleBuffer(buffer);
+ return PFactory.createPickleBuffer(language, buffer);
}
}
@@ -112,8 +114,9 @@ static PPickleBuffer construct(VirtualFrame frame, @SuppressWarnings("unused") O
abstract static class ConstructPicklerNode extends PythonVarargsBuiltinNode {
@Specialization
PPickler construct(Object cls, @SuppressWarnings("unused") Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
- @Cached PythonObjectFactory factory) {
- return factory.createPickler(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createPickler(language, cls, getInstanceShape.execute(cls));
}
}
@@ -122,8 +125,9 @@ PPickler construct(Object cls, @SuppressWarnings("unused") Object[] arguments, @
abstract static class ConstructPicklerMemoProxyNode extends PythonBinaryBuiltinNode {
@Specialization
PPicklerMemoProxy construct(Object cls, PPickler pickler,
- @Cached PythonObjectFactory factory) {
- return factory.createPicklerMemoProxy(pickler, cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createPicklerMemoProxy(language, pickler, cls, getInstanceShape.execute(cls));
}
}
@@ -132,8 +136,9 @@ PPicklerMemoProxy construct(Object cls, PPickler pickler,
abstract static class ConstructUnpicklerMemoProxyNode extends PythonBinaryBuiltinNode {
@Specialization
PUnpicklerMemoProxy construct(Object cls, PUnpickler unpickler,
- @Cached PythonObjectFactory factory) {
- return factory.createUnpicklerMemoProxy(unpickler, cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createUnpicklerMemoProxy(language, unpickler, cls, getInstanceShape.execute(cls));
}
}
@@ -142,8 +147,9 @@ PUnpicklerMemoProxy construct(Object cls, PUnpickler unpickler,
abstract static class ConstructUnpicklerNode extends PythonVarargsBuiltinNode {
@Specialization
PUnpickler construct(Object cls, @SuppressWarnings("unused") Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
- @Cached PythonObjectFactory factory) {
- return factory.createUnpickler(cls);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createUnpickler(language, cls, getInstanceShape.execute(cls));
}
}
@@ -163,12 +169,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object dump(VirtualFrame frame, @SuppressWarnings("unused") PythonModule self, Object obj, Object file, int protocol, boolean fixImports, Object bufferCallback,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PPickler.DumpNode dumpNode,
@Cached PPickler.FlushToFileNode flushToFileNode,
@Cached PyObjectLookupAttr lookup,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- PPickler pickler = factory.createPickler();
+ PPickler pickler = PFactory.createPickler(language);
pickler.setProtocol(inliningTarget, raiseNode, protocol, fixImports);
pickler.setOutputStream(frame, inliningTarget, raiseNode, lookup, file);
pickler.setBufferCallback(inliningTarget, raiseNode, bufferCallback);
@@ -193,14 +199,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object dump(VirtualFrame frame, @SuppressWarnings("unused") PythonModule self, Object obj, int protocol, boolean fixImports, Object bufferCallback,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PPickler.DumpNode dumpNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- PPickler pickler = factory.createPickler();
+ PPickler pickler = PFactory.createPickler(language);
pickler.setProtocol(inliningTarget, raiseNode, protocol, fixImports);
pickler.setBufferCallback(inliningTarget, raiseNode, bufferCallback);
dumpNode.execute(frame, pickler, obj);
- return pickler.getString(factory);
+ return pickler.getString(language);
}
}
@@ -220,12 +226,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object load(VirtualFrame frame, @SuppressWarnings("unused") PythonModule self, Object file, @SuppressWarnings("unused") boolean fixImports, TruffleString encoding, TruffleString errors,
Object buffers,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PUnpickler.LoadNode loadNode,
@Cached PyObjectLookupAttr lookup,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
- PUnpickler unpickler = factory.createUnpickler();
+ PUnpickler unpickler = PFactory.createUnpickler(language);
unpickler.setInputStream(frame, inliningTarget, raiseNode, lookup, file);
unpickler.setInputEncoding(encoding, errors);
unpickler.setBuffers(frame, inliningTarget, getIter, buffers);
@@ -251,12 +257,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object loads(VirtualFrame frame, @SuppressWarnings("unused") PythonModule self, Object buffer, boolean fixImports, TruffleString encoding, TruffleString errors, Object buffers,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached PUnpickler.LoadNode loadNode,
- @Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectGetIter getIter) {
try {
- PUnpickler unpickler = factory.createUnpickler();
+ PUnpickler unpickler = PFactory.createUnpickler(language);
byte[] data = bufferLib.getCopiedByteArray(buffer);
unpickler.setStringInput(data, data.length);
unpickler.setInputEncoding(encoding, errors);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
index 6fcdb97251..3efa079792 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import org.graalvm.collections.Pair;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.bytes.ByteArrayBuffer;
@@ -60,7 +61,7 @@
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.StringLiterals;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -373,9 +374,9 @@ public static Pair initMethodRef(VirtualFrame frame, Node inlini
}
}
- public static Object reconstructMethod(PythonObjectFactory factory, Object func, Object self) {
+ public static Object reconstructMethod(PythonLanguage language, Object func, Object self) {
if (self != null) {
- return factory.createMethod(self, func);
+ return PFactory.createMethod(language, self, func);
}
return func;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
index 5d1039854d..0fd7fffb30 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -84,7 +85,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -244,8 +245,8 @@ Object set(VirtualFrame frame, PPickler self, Object value,
public abstract static class PicklerMemoNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(none)")
static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
- @Cached PythonObjectFactory factory) {
- return factory.createPicklerMemoProxy(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createPicklerMemoProxy(language, self);
}
@Specialization(guards = {"!isNoValue(obj)", "!isDeleteMarker(obj)"})
@@ -291,13 +292,13 @@ public abstract static class PicklerPersistentIdNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(none)")
static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
final Object persFunc = self.getPersFunc();
if (persFunc == null) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_ID);
}
- return PickleUtils.reconstructMethod(factory, persFunc, self.getPersFuncSelf());
+ return PickleUtils.reconstructMethod(language, persFunc, self.getPersFuncSelf());
}
@Specialization(guards = {"!isNoValue(obj)", "!isDeleteMarker(obj)"})
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerMemoProxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerMemoProxyBuiltins.java
index 98b6472d35..b8243bd187 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerMemoProxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerMemoProxyBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.LinkedHashMap;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -55,10 +56,9 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -82,16 +82,16 @@ Object clear(PPicklerMemoProxy self) {
}
@TruffleBoundary
- public static PDict picklerMemoCopyImpl(PythonContext context, MemoTable memoTable) {
- PythonObjectFactory factory = context.factory();
+ public static PDict picklerMemoCopyImpl(MemoTable memoTable) {
+ PythonLanguage language = PythonLanguage.get(null);
LinkedHashMap copy = new LinkedHashMap<>();
MemoIterator iterator = memoTable.iterator();
while (iterator.advance()) {
copy.put(System.identityHashCode(iterator.key()),
- factory.createTuple(new Object[]{iterator.value(), iterator.key()}));
+ PFactory.createTuple(language, new Object[]{iterator.value(), iterator.key()}));
}
- return factory.createDictFromMapGeneric(copy);
+ return PFactory.createDictFromMapGeneric(language, copy);
}
@Builtin(name = "copy", minNumOfPositionalArgs = 1, parameterNames = {"$self"})
@@ -100,7 +100,7 @@ public abstract static class PicklerMemoProxyCopyNode extends PythonUnaryBuiltin
@Specialization
Object copy(PPicklerMemoProxy self) {
final MemoTable memoTable = self.getPickler().getMemo();
- return picklerMemoCopyImpl(getContext(), memoTable);
+ return picklerMemoCopyImpl(memoTable);
}
}
@@ -108,12 +108,12 @@ Object copy(PPicklerMemoProxy self) {
@GenerateNodeFactory
public abstract static class PicklerMemoProxyReduceNode extends PythonUnaryBuiltinNode {
@Specialization
- Object reduce(PPicklerMemoProxy self,
- @Cached PythonObjectFactory factory) {
+ static Object reduce(PPicklerMemoProxy self,
+ @Bind PythonLanguage language) {
final MemoTable memoTable = self.getPickler().getMemo();
- final PDict dictMemoCopy = picklerMemoCopyImpl(getContext(), memoTable);
- final PTuple dictArgs = factory.createTuple(new Object[]{dictMemoCopy});
- return factory.createTuple(new Object[]{PythonBuiltinClassType.PDict, dictArgs});
+ final PDict dictMemoCopy = picklerMemoCopyImpl(memoTable);
+ final PTuple dictArgs = PFactory.createTuple(language, new Object[]{dictMemoCopy});
+ return PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PDict, dictArgs});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
index 6d2c6b00a5..74c5c9e9ec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
@@ -57,10 +57,9 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
-import com.oracle.graal.python.lib.PyLongFromUnicodeObject;
-import com.oracle.graal.python.lib.PyObjectSetItem;
import org.graalvm.collections.Pair;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
@@ -83,10 +82,12 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.lib.PyIterCheckNode;
import com.oracle.graal.python.lib.PyIterNextNode;
+import com.oracle.graal.python.lib.PyLongFromUnicodeObject;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode;
+import com.oracle.graal.python.lib.PyObjectSetItem;
import com.oracle.graal.python.lib.PyObjectSizeNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.HiddenAttr;
@@ -103,7 +104,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -126,7 +127,6 @@ abstract static class BasePickleNode extends Node {
@SuppressWarnings("FieldMayBeFinal") @Child private PyIterNextNode getNextNode = PyIterNextNode.create();
@Child CastToTruffleStringNode toStringNode = CastToTruffleStringNode.create();
- @Child private PythonObjectFactory objectFactory;
@Child private HiddenAttr.ReadNode readHiddenAttributeNode;
@Child private IsBuiltinObjectProfile errProfile;
@Child private InlineIsBuiltinClassProfile isBuiltinClassProfile;
@@ -318,14 +318,6 @@ protected HashingStorageIteratorValue ensureHashingStorageIteratorValue() {
return hashingStorageItValue;
}
- protected final PythonObjectFactory factory() {
- if (objectFactory == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- objectFactory = insert(PythonObjectFactory.create());
- }
- return objectFactory;
- }
-
protected int length(VirtualFrame frame, Object object) {
if (sizeNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -367,15 +359,15 @@ protected CodecsModuleBuiltins.CodecsEscapeDecodeNode ensureEscapeDecodeNode() {
}
protected Object unicodeRawDecodeEscape(VirtualFrame frame, byte[] bytes, int len) {
- return decode(frame, factory().createBytes(bytes, 0, len), T_CODEC_RAW_UNICODE_ESCAPE);
+ return decode(frame, PFactory.createBytes(PythonLanguage.get(this), bytes, len), T_CODEC_RAW_UNICODE_ESCAPE);
}
protected Object decodeASCII(VirtualFrame frame, byte[] bytes, int len, TruffleString errors) {
- return decode(frame, factory().createBytes(bytes, 0, len), T_CODEC_ASCII, errors);
+ return decode(frame, PFactory.createBytes(PythonLanguage.get(this), bytes, len), T_CODEC_ASCII, errors);
}
protected Object decodeUTF8(VirtualFrame frame, ByteArrayView bytes, int len, TruffleString errors) {
- return decode(frame, factory().createBytes(bytes.getBytes(len), 0, len), T_UTF8, errors);
+ return decode(frame, PFactory.createBytes(PythonLanguage.get(this), bytes.getBytes(len), len), T_UTF8, errors);
}
protected Object decode(VirtualFrame frame, Object value, TruffleString encoding) {
@@ -386,13 +378,6 @@ protected Object decode(VirtualFrame frame, Object value, TruffleString encoding
return getItem(frame, ensureCodecsDecodeNode().call(frame, value, encoding, errors, false), 0);
}
- protected Object escapeDecode(VirtualFrame frame, PythonObjectFactory factory, byte[] data, int offset, int len) {
- if (len == 0) {
- return factory.createEmptyBytes();
- }
- return escapeDecode(frame, PythonUtils.arrayCopyOfRange(data, offset, offset + len));
- }
-
protected Object escapeDecode(VirtualFrame frame, byte[] data) {
return getItem(frame, ensureEscapeDecodeNode().execute(frame, data, T_ERRORS_STRICT), 0);
}
@@ -683,7 +668,7 @@ protected Pair get2To3Mapping(VirtualFrame frame,
private Pair getMapping(VirtualFrame frame, PDict nameMapping, PDict importMapping,
TruffleString nameMappingLabel, TruffleString importMappingLabel, TruffleString moduleName, TruffleString globalName) {
- Object key = factory().createTuple(new Object[]{moduleName, globalName});
+ Object key = PFactory.createTuple(PythonLanguage.get(this), new Object[]{moduleName, globalName});
Object item = getDictItem(frame, nameMapping, key);
if (item != null) {
if (!(item instanceof PTuple) || length(frame, item) != 2) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
index 76f15c478e..051c0a9d16 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -162,13 +163,13 @@ public abstract static class UnpicklerPersistentLoadNode extends PythonBuiltinNo
@Specialization(guards = "isNoValue(none)")
static Object get(PUnpickler self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
final Object persFunc = self.getPersFunc();
if (persFunc == null) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_LOAD);
}
- return PickleUtils.reconstructMethod(factory, persFunc, self.getPersFuncSelf());
+ return PickleUtils.reconstructMethod(language, persFunc, self.getPersFuncSelf());
}
@Specialization(guards = "!isNoValue(obj)")
@@ -193,8 +194,8 @@ static Object set(PUnpickler self, Object obj,
public abstract static class UnpicklerMemoNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(none)")
static Object get(PUnpickler self, @SuppressWarnings("unused") PNone none,
- @Cached PythonObjectFactory factory) {
- return factory.createUnpicklerMemoProxy(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createUnpicklerMemoProxy(language, self);
}
@Specialization(guards = {"!isNoValue(obj)", "!isDeleteMarker(obj)"})
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerMemoProxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerMemoProxyBuiltins.java
index 9e01a285b2..3785edba87 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerMemoProxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerMemoProxyBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -54,7 +55,7 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -86,8 +87,8 @@ public abstract static class UnpicklerMemoProxyCopyNode extends PythonUnaryBuilt
Object copy(PUnpicklerMemoProxy self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageSetItem setItem,
- @Cached PythonObjectFactory factory) {
- return factory.createDict(self.getUnpickler().copyMemoToHashingStorage(inliningTarget, setItem));
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language, self.getUnpickler().copyMemoToHashingStorage(inliningTarget, setItem));
}
}
@@ -98,10 +99,10 @@ public abstract static class UnpicklerMemoProxyReduceNode extends PythonUnaryBui
Object reduce(PUnpicklerMemoProxy self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageSetItem setItem,
- @Cached PythonObjectFactory factory) {
- final PDict dictMemoCopy = factory.createDict(self.getUnpickler().copyMemoToHashingStorage(inliningTarget, setItem));
- final PTuple constructorArgs = factory.createTuple(new Object[]{dictMemoCopy});
- return factory.createTuple(new Object[]{PythonBuiltinClassType.PDict, constructorArgs});
+ @Bind PythonLanguage language) {
+ final PDict dictMemoCopy = PFactory.createDict(language, self.getUnpickler().copyMemoToHashingStorage(inliningTarget, setItem));
+ final PTuple constructorArgs = PFactory.createTuple(language, new Object[]{dictMemoCopy});
+ return PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PDict, constructorArgs});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
index 2254eba7f8..c68a766994 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,8 +40,6 @@
*/
package com.oracle.graal.python.builtins.modules.zlib;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ZlibCompress;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ZlibDecompress;
import static com.oracle.graal.python.builtins.modules.zlib.ZLibModuleBuiltins.MAX_WBITS;
import static com.oracle.graal.python.builtins.objects.bytes.BytesUtils.mask;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ZLibError;
@@ -51,12 +49,13 @@
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.runtime.NFIZlibSupport;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
@@ -77,7 +76,7 @@ public ZLibCompObject(Object cls, Shape instanceShape) {
this.unconsumedTail = null;
}
- // Note: some IDEs mark this class as inaccessible in PythonObjectFactory, but changing this to
+ // Note: some IDEs mark this class as inaccessible in PFactory, but changing this to
// public will cause a warning: [this-escape] possible 'this' escape before subclass is fully
// initialized
protected static class NativeZlibCompObject extends ZLibCompObject {
@@ -176,7 +175,7 @@ public void setInflaterInput(byte[] data, int length, Node node) {
}
@TruffleBoundary
- public ZLibCompObject copyCompressObj(PythonObjectFactory factory) {
+ public ZLibCompObject copyCompressObj() {
assert canCopy;
Deflater deflater = new Deflater(level, wbits < 0 || wbits > (MAX_WBITS + 9));
@@ -184,7 +183,7 @@ public ZLibCompObject copyCompressObj(PythonObjectFactory factory) {
if (zdict.length > 0) {
deflater.setDictionary(zdict);
}
- ZLibCompObject obj = factory.createJavaZLibCompObject(ZlibCompress, deflater, level, wbits, strategy, zdict);
+ ZLibCompObject obj = PFactory.createJavaZLibCompObjectCompress(PythonLanguage.get(null), deflater, level, wbits, strategy, zdict);
if (inputData != null) {
// feed the new copy of deflater the same input data
((JavaZlibCompObject) obj).setDeflaterInput(inputData, inputLen);
@@ -194,14 +193,14 @@ public ZLibCompObject copyCompressObj(PythonObjectFactory factory) {
}
@TruffleBoundary
- public ZLibCompObject copyDecompressObj(PythonObjectFactory factory, Node node) {
+ public ZLibCompObject copyDecompressObj(Node node) {
assert canCopy;
boolean isRAW = wbits < 0;
Inflater inflater = new Inflater(isRAW || wbits > (MAX_WBITS + 9));
if (isRAW && zdict.length > 0) {
inflater.setDictionary(zdict);
}
- ZLibCompObject obj = factory.createJavaZLibCompObject(ZlibDecompress, inflater, wbits, zdict);
+ ZLibCompObject obj = PFactory.createJavaZLibCompObjectDecompress(PythonLanguage.get(null), inflater, wbits, zdict);
if (inputData != null) {
try {
((JavaZlibCompObject) obj).setInflaterInput(inputData, inputLen, node);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
index 8c7166019e..eaadef3527 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,8 +41,6 @@
package com.oracle.graal.python.builtins.modules.zlib;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ZlibCompress;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ZlibDecompress;
import static com.oracle.graal.python.builtins.modules.zlib.ZlibNodes.Z_OK;
import static com.oracle.graal.python.nodes.ErrorMessages.EXPECTED_BYTESLIKE_GOT_P;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
@@ -59,6 +57,7 @@
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ClinicConverterFactory;
import com.oracle.graal.python.annotations.ClinicConverterFactory.UseDefaultForNone;
@@ -92,9 +91,8 @@
import com.oracle.graal.python.runtime.NFIZlibSupport;
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -510,15 +508,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PBytes compress(VirtualFrame frame, Object buffer, int level, int wbits,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached CompressInnerNode innerNode,
- @Cached PythonObjectFactory factory) {
+ @Cached CompressInnerNode innerNode) {
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
byte[] resultArray = innerNode.execute(inliningTarget, bytes, len, level, wbits);
- return factory.createBytes(resultArray);
+ return PFactory.createBytes(language, resultArray);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -574,10 +572,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PBytes decompress(VirtualFrame frame, Object buffer, int wbits, int bufsize,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached DecompressInnerNode innerNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
if (bufsize < 0) {
@@ -586,7 +584,7 @@ static PBytes decompress(VirtualFrame frame, Object buffer, int wbits, int bufsi
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
byte[] resultArray = innerNode.execute(inliningTarget, bytes, len, wbits, bufsize);
- return factory.createBytes(resultArray);
+ return PFactory.createBytes(language, resultArray);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -667,10 +665,10 @@ protected static boolean isValidWBitRange(int wbits) {
@Specialization(guards = {"method == DEFLATED", "useNative()"})
static Object doNative(int level, int method, int wbits, int memLevel, int strategy, byte[] zdict,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached NativeLibrary.InvokeNativeFunction createCompObject,
@Cached NativeLibrary.InvokeNativeFunction compressObjInit,
- @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling,
- @Cached PythonObjectFactory factory) {
+ @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
NFIZlibSupport zlibSupport = PythonContext.get(inliningTarget).getNFIZlibSupport();
Object zst = zlibSupport.createCompObject(createCompObject);
@@ -684,7 +682,7 @@ static Object doNative(int level, int method, int wbits, int memLevel, int strat
if (err != Z_OK) {
errorHandling.execute(inliningTarget, zst, err, zlibSupport, true);
}
- return factory.createNativeZLibCompObject(ZlibCompress, zst, zlibSupport);
+ return PFactory.createNativeZLibCompObjectCompress(language, zst, zlibSupport);
}
/**
@@ -703,7 +701,7 @@ static Object doJava(int level, @SuppressWarnings("unused") int method, int wbit
if (zdict.length > 0) {
deflater.setDictionary(zdict);
}
- return PythonObjectFactory.getUncached().createJavaZLibCompObject(ZlibCompress, deflater, level, wbits, strategy, zdict);
+ return PFactory.createJavaZLibCompObjectCompress(PythonLanguage.get(null), deflater, level, wbits, strategy, zdict);
}
@SuppressWarnings("unused")
@@ -742,30 +740,30 @@ protected static boolean isValidWBitRange(int wbits) {
}
@Specialization(guards = {"useNative()"})
- Object doNative(int wbits, byte[] zdict,
+ static Object doNative(int wbits, byte[] zdict,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached NativeLibrary.InvokeNativeFunction createCompObject,
@Cached NativeLibrary.InvokeNativeFunction decompressObjInit,
- @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling,
- @Cached PythonObjectFactory factory) {
- NFIZlibSupport zlibSupport = PythonContext.get(this).getNFIZlibSupport();
+ @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
+ NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
Object zst = zlibSupport.createCompObject(createCompObject);
int err;
if (zdict.length > 0) {
- err = zlibSupport.decompressObjInitWithDict(zst, wbits, PythonContext.get(this).getEnv().asGuestValue(zdict), zdict.length, decompressObjInit);
+ err = zlibSupport.decompressObjInitWithDict(zst, wbits, context.getEnv().asGuestValue(zdict), zdict.length, decompressObjInit);
} else {
err = zlibSupport.decompressObjInit(zst, wbits, decompressObjInit);
}
if (err != Z_OK) {
errorHandling.execute(inliningTarget, zst, err, zlibSupport, true);
}
- return factory.createNativeZLibCompObject(ZlibDecompress, zst, zlibSupport);
+ return PFactory.createNativeZLibCompObjectDecompress(context.getLanguage(inliningTarget), zst, zlibSupport);
}
- @CompilerDirectives.TruffleBoundary
+ @TruffleBoundary
@Specialization(guards = {"!useNative()", "isValidWBitRange(wbits)"})
- Object doJava(int wbits, byte[] zdict) {
+ static Object doJava(int wbits, byte[] zdict) {
// wbits < 0: generate a RAW stream, i.e., no wrapping
// wbits 25..31: gzip container, i.e., no wrapping
// Otherwise: wrap stream with zlib header and trailer
@@ -774,10 +772,10 @@ Object doJava(int wbits, byte[] zdict) {
if (isRAW && zdict.length > 0) {
inflater.setDictionary(zdict);
}
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- ZLibCompObject obj = factory.createJavaZLibCompObject(ZlibDecompress, inflater, wbits, zdict);
- obj.setUnusedData(factory.createEmptyBytes());
- obj.setUnconsumedTail(factory.createEmptyBytes());
+ PythonLanguage language = PythonLanguage.get(null);
+ ZLibCompObject obj = PFactory.createJavaZLibCompObjectDecompress(language, inflater, wbits, zdict);
+ obj.setUnusedData(PFactory.createEmptyBytes(language));
+ obj.setUnconsumedTail(PFactory.createEmptyBytes(language));
return obj;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
index 689b562d9f..7c35370221 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -74,12 +75,11 @@
import com.oracle.graal.python.runtime.NFIZlibSupport;
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -105,10 +105,10 @@ abstract static class CompressNode extends PythonBinaryClinicBuiltinNode {
@Specialization
static PBytes compress(VirtualFrame frame, ZLibCompObject self, Object buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached CompressInnerNode innerNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
if (!self.isInitialized()) {
@@ -116,7 +116,7 @@ static PBytes compress(VirtualFrame frame, ZLibCompObject self, Object buffer,
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
- return factory.createBytes(innerNode.execute(inliningTarget, self, bytes, len));
+ return PFactory.createBytes(language, innerNode.execute(inliningTarget, self, bytes, len));
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -153,42 +153,43 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateCached(false)
abstract static class BaseCopyNode extends PNodeWithContext {
- public abstract Object execute(Node inliningTarget, ZLibCompObject self, PythonContext ctxt, PythonObjectFactory factory);
+ public abstract Object execute(Node inliningTarget, ZLibCompObject self);
@Specialization(guards = "self.isInitialized()")
- static Object doNative(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static Object doNative(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self,
+ @Bind PythonContext context,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction createCompObject,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction compressObjCopy,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction deallocateStream,
@Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
synchronized (self) {
assert self.isInitialized();
- NFIZlibSupport zlibSupport = ctxt.getNFIZlibSupport();
+ NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
Object zstNewCopy = zlibSupport.createCompObject(createCompObject);
int err = zlibSupport.compressObjCopy(self.getZst(), zstNewCopy, compressObjCopy);
if (err != Z_OK) {
zlibSupport.deallocateStream(zstNewCopy, deallocateStream);
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
}
- return factory.createNativeZLibCompObject(ZlibCompress, zstNewCopy, zlibSupport);
+ return PFactory.createNativeZLibCompObjectCompress(context.getLanguage(inliningTarget), zstNewCopy, zlibSupport);
}
}
@Specialization(guards = {"self.isInitialized()", "self.canCopy()"})
- static Object doJava(ZLibCompObject.JavaZlibCompObject self, @SuppressWarnings("unused") PythonContext ctxt, PythonObjectFactory factory) {
- return self.copyCompressObj(factory);
+ static Object doJava(ZLibCompObject.JavaZlibCompObject self) {
+ return self.copyCompressObj();
}
@SuppressWarnings("unused")
@Specialization(guards = {"self.isInitialized()", "!self.canCopy()"})
- static PNone error(ZLibCompObject.JavaZlibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static PNone error(ZLibCompObject.JavaZlibCompObject self,
@Cached.Shared @Cached(inline = false) PRaiseNode raise) {
throw raise.raise(NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
}
@SuppressWarnings("unused")
@Specialization(guards = "!self.isInitialized()")
- static PNone error(ZLibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static PNone error(ZLibCompObject self,
@Cached.Shared @Cached(inline = false) PRaiseNode raise) {
throw raise.raise(ValueError, ErrorMessages.INCONSISTENT_STREAM_STATE);
}
@@ -200,9 +201,8 @@ abstract static class CopyNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doit(ZLibCompObject self,
@Bind("this") Node inliningTarget,
- @Cached BaseCopyNode copyNode,
- @Cached PythonObjectFactory factory) {
- return copyNode.execute(inliningTarget, self, PythonContext.get(inliningTarget), factory);
+ @Cached BaseCopyNode copyNode) {
+ return copyNode.execute(inliningTarget, self);
}
}
@@ -217,9 +217,8 @@ abstract static class DeepCopyNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doit(ZLibCompObject self, @SuppressWarnings("unused") Object memo,
@Bind("this") Node inliningTarget,
- @Cached BaseCopyNode copyNode,
- @Cached PythonObjectFactory factory) {
- return copyNode.execute(inliningTarget, self, PythonContext.get(inliningTarget), factory);
+ @Cached BaseCopyNode copyNode) {
+ return copyNode.execute(inliningTarget, self);
}
}
@@ -237,8 +236,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@SuppressWarnings("unused")
@Specialization(guards = "mode == Z_NO_FLUSH")
static PBytes empty(ZLibCompObject self, int mode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEmptyBytes();
+ @Bind PythonLanguage language) {
+ return PFactory.createEmptyBytes(language);
}
@Specialization(guards = {"mode != Z_NO_FLUSH", "self.isInitialized()"})
@@ -248,16 +247,15 @@ static PBytes doit(ZLibCompObject.NativeZlibCompObject self, int mode,
@Cached ZlibNodes.GetNativeBufferNode getBuffer,
@Cached NativeLibrary.InvokeNativeFunction getIsInitialised,
@Cached ZlibNodes.NativeDeallocation processDeallocation,
- @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
synchronized (self) {
assert self.isInitialized();
- PythonContext ctxt = PythonContext.get(inliningTarget);
- NFIZlibSupport zlibSupport = ctxt.getNFIZlibSupport();
+ PythonContext context = PythonContext.get(inliningTarget);
+ NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
Object lastInput;
if (self.lastInput == null) {
// all previous input data has been processed or nothing has been compressed.
- lastInput = ctxt.getEnv().asGuestValue(PythonUtils.EMPTY_BYTE_ARRAY);
+ lastInput = context.getEnv().asGuestValue(PythonUtils.EMPTY_BYTE_ARRAY);
} else {
// pass the last data input to continue processing.
// all other needed info, e.g. size and offset, about the last data input is
@@ -268,18 +266,18 @@ static PBytes doit(ZLibCompObject.NativeZlibCompObject self, int mode,
if (err != Z_OK) {
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
}
- byte[] resultArray = getBuffer.getOutputBuffer(inliningTarget, self.getZst(), ctxt);
+ byte[] resultArray = getBuffer.getOutputBuffer(inliningTarget, self.getZst(), context);
if (zlibSupport.getIsInitialised(self.getZst(), getIsInitialised) == 0) {
- processDeallocation.execute(inliningTarget, self, ctxt, factory, true);
+ processDeallocation.execute(inliningTarget, self, context, true);
}
- return factory.createBytes(resultArray);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), resultArray);
}
}
@Specialization(guards = {"mode != Z_NO_FLUSH", "self.isInitialized()"})
static PBytes doit(ZLibCompObject.JavaZlibCompObject self, int mode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(ZlibNodes.JavaCompressNode.execute(self, mode));
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, ZlibNodes.JavaCompressNode.execute(self, mode));
}
@SuppressWarnings("unused")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
index 52e0aa4467..eec33b9332 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -76,11 +77,10 @@
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -111,10 +111,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PBytes decompress(VirtualFrame frame, ZLibCompObject self, Object buffer, int maxLength,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached DecompressInnerNode innerNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
if (!self.isInitialized()) {
@@ -125,7 +125,7 @@ static PBytes decompress(VirtualFrame frame, ZLibCompObject self, Object buffer,
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
- return factory.createBytes(innerNode.execute(frame, inliningTarget, self, bytes, len, maxLength));
+ return PFactory.createBytes(language, innerNode.execute(frame, inliningTarget, self, bytes, len, maxLength));
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -146,9 +146,8 @@ static byte[] doNative(Node inliningTarget, ZLibCompObject.NativeZlibCompObject
@Specialization
static byte[] doJava(VirtualFrame frame, Node inliningTarget, ZLibCompObject.JavaZlibCompObject self, byte[] bytes, int length, int maxLength,
- @Cached(inline = false) BytesNodes.ToBytesNode toBytes,
- @Cached(inline = false) PythonObjectFactory factory) {
- return ZlibNodes.JavaDecompressor.execute(frame, self, bytes, length, maxLength, DEF_BUF_SIZE, inliningTarget, factory, toBytes);
+ @Cached(inline = false) BytesNodes.ToBytesNode toBytes) {
+ return ZlibNodes.JavaDecompressor.execute(frame, self, bytes, length, maxLength, DEF_BUF_SIZE, inliningTarget, toBytes);
}
}
}
@@ -157,44 +156,45 @@ static byte[] doJava(VirtualFrame frame, Node inliningTarget, ZLibCompObject.Jav
@GenerateCached(false)
abstract static class BaseCopyNode extends PNodeWithContext {
- public abstract Object execute(Node inliningTarget, ZLibCompObject self, PythonContext ctxt, PythonObjectFactory factory);
+ public abstract Object execute(Node inliningTarget, ZLibCompObject self);
@Specialization(guards = "self.isInitialized()")
- static Object doNative(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static Object doNative(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self,
+ @Bind PythonContext context,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction createCompObject,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction decompressObjCopy,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction deallocateStream,
@Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
synchronized (self) {
assert self.isInitialized();
- NFIZlibSupport zlibSupport = ctxt.getNFIZlibSupport();
+ NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
Object zstNewCopy = zlibSupport.createCompObject(createCompObject);
int err = zlibSupport.decompressObjCopy(self.getZst(), zstNewCopy, decompressObjCopy);
if (err != Z_OK) {
zlibSupport.deallocateStream(zstNewCopy, deallocateStream);
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
}
- ZLibCompObject copy = factory.createNativeZLibCompObject(ZlibDecompress, zstNewCopy, zlibSupport);
+ ZLibCompObject copy = PFactory.createNativeZLibCompObjectDecompress(context.getLanguage(inliningTarget), zstNewCopy, zlibSupport);
copy.setEof(self.isEof());
return copy;
}
}
@Specialization(guards = {"self.isInitialized()", "self.canCopy()"})
- static Object doJava(Node inliningTarget, ZLibCompObject.JavaZlibCompObject self, @SuppressWarnings("unused") PythonContext ctxt, PythonObjectFactory factory) {
- return self.copyDecompressObj(factory, inliningTarget);
+ static Object doJava(Node inliningTarget, ZLibCompObject.JavaZlibCompObject self) {
+ return self.copyDecompressObj(inliningTarget);
}
@SuppressWarnings("unused")
@Specialization(guards = {"self.isInitialized()", "!self.canCopy()"})
- static PNone error(ZLibCompObject.JavaZlibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static PNone error(ZLibCompObject.JavaZlibCompObject self,
@Cached.Shared @Cached(inline = false) PRaiseNode raise) {
throw raise.raise(NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
}
@SuppressWarnings("unused")
@Specialization(guards = "!self.isInitialized()")
- static PNone error(ZLibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
+ static PNone error(ZLibCompObject self,
@Cached.Shared @Cached(inline = false) PRaiseNode raise) {
throw raise.raise(ValueError, INCONSISTENT_STREAM_STATE);
}
@@ -206,9 +206,8 @@ abstract static class CopyNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doit(ZLibCompObject self,
@Bind("this") Node inliningTarget,
- @Cached BaseCopyNode copyNode,
- @Cached PythonObjectFactory factory) {
- return copyNode.execute(inliningTarget, self, PythonContext.get(inliningTarget), factory);
+ @Cached BaseCopyNode copyNode) {
+ return copyNode.execute(inliningTarget, self);
}
}
@@ -223,9 +222,8 @@ abstract static class DeepCopyNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doit(ZLibCompObject self, @SuppressWarnings("unused") Object memo,
@Bind("this") Node inliningTarget,
- @Cached BaseCopyNode copyNode,
- @Cached PythonObjectFactory factory) {
- return copyNode.execute(inliningTarget, self, PythonContext.get(inliningTarget), factory);
+ @Cached BaseCopyNode copyNode) {
+ return copyNode.execute(inliningTarget, self);
}
}
@@ -242,57 +240,56 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = {"length > 0", "!self.isEof()", "self.isInitialized()"})
static PBytes doit(ZLibCompObject.NativeZlibCompObject self, int length,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached NativeLibrary.InvokeNativeFunction decompressObjFlush,
@Cached ZlibNodes.GetNativeBufferNode getBuffer,
@Cached NativeLibrary.InvokeNativeFunction getIsInitialised,
@Cached ZlibNodes.NativeDeallocation processDeallocation,
- @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
synchronized (self) {
- PythonContext ctxt = PythonContext.get(inliningTarget);
assert self.isInitialized();
- NFIZlibSupport zlibSupport = ctxt.getNFIZlibSupport();
+ NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
int err = zlibSupport.decompressObjFlush(self.getZst(), length, decompressObjFlush);
if (err != Z_OK) {
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
}
- byte[] resultArray = getBuffer.getOutputBuffer(inliningTarget, self.getZst(), ctxt);
+ byte[] resultArray = getBuffer.getOutputBuffer(inliningTarget, self.getZst(), context);
if (zlibSupport.getIsInitialised(self.getZst(), getIsInitialised) == 0) {
- processDeallocation.execute(inliningTarget, self, ctxt, factory, false);
+ processDeallocation.execute(inliningTarget, self, context, false);
}
- return factory.createBytes(resultArray);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), resultArray);
}
}
@Specialization(guards = {"length > 0", "!self.isEof()", "self.isInitialized()"})
PBytes doit(VirtualFrame frame, ZLibCompObject.JavaZlibCompObject self, int length,
- @Cached BytesNodes.ToBytesNode toBytes,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached BytesNodes.ToBytesNode toBytes) {
byte[] res;
try {
byte[] bytes = toBytes.execute(self.getUnconsumedTail());
- res = ZlibNodes.JavaDecompressor.execute(frame, self, bytes, bytes.length, 0, length, this, factory, toBytes);
+ res = ZlibNodes.JavaDecompressor.execute(frame, self, bytes, bytes.length, 0, length, this, toBytes);
} catch (PException e) {
// CPython ignores errors here
res = PythonUtils.EMPTY_BYTE_ARRAY;
}
self.setUninitialized();
- return factory.createBytes(res);
+ return PFactory.createBytes(language, res);
}
@SuppressWarnings("unused")
@Specialization(guards = {"length > 0", "self.isEof() || !self.isInitialized()"})
static PBytes empty(ZLibCompObject.JavaZlibCompObject self, int length,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
self.setUninitialized();
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
@SuppressWarnings("unused")
@Specialization(guards = {"length > 0", "self.isEof() || !self.isInitialized()"})
static PBytes empty(ZLibCompObject.NativeZlibCompObject self, int length,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createEmptyBytes();
+ @Bind PythonLanguage language) {
+ return PFactory.createEmptyBytes(language);
}
@SuppressWarnings("unused")
@@ -309,11 +306,11 @@ abstract static class UnusedDataNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.isInitialized()")
static PBytes doit(ZLibCompObject.NativeZlibCompObject self,
@Bind("this") Node inliningTarget,
- @Cached ZlibNodes.GetNativeBufferNode getBuffer,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @Cached ZlibNodes.GetNativeBufferNode getBuffer) {
synchronized (self) {
assert self.isInitialized();
- return factory.createBytes(getBuffer.getUnusedDataBuffer(inliningTarget, self.getZst(), PythonContext.get(inliningTarget)));
+ return PFactory.createBytes(context.getLanguage(inliningTarget), getBuffer.getUnusedDataBuffer(inliningTarget, self.getZst(), context));
}
}
@@ -334,11 +331,11 @@ abstract static class UnconsumedTailNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.isInitialized()")
static PBytes doit(ZLibCompObject.NativeZlibCompObject self,
@Bind("this") Node inliningTarget,
- @Cached ZlibNodes.GetNativeBufferNode getBuffer,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @Cached ZlibNodes.GetNativeBufferNode getBuffer) {
synchronized (self) {
assert self.isInitialized();
- return factory.createBytes(getBuffer.getUnconsumedTailBuffer(inliningTarget, self.getZst(), PythonContext.get(inliningTarget)));
+ return PFactory.createBytes(context.getLanguage(inliningTarget), getBuffer.getUnconsumedTailBuffer(inliningTarget, self.getZst(), context));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
index 77dd75769d..2b4a974768 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -73,6 +73,7 @@
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
@@ -82,7 +83,7 @@
import com.oracle.graal.python.runtime.NFIZlibSupport;
import com.oracle.graal.python.runtime.NativeLibrary;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -469,10 +470,10 @@ void fallback(Object zst, int function, int err, NFIZlibSupport zlibSupport, boo
@GenerateCached(false)
public abstract static class NativeDeallocation extends PNodeWithContext {
- public abstract void execute(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext context, PythonObjectFactory factory, boolean isCompressObj);
+ public abstract void execute(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext context, boolean isCompressObj);
@Specialization(guards = "isCompressObj")
- static void doCompressObj(ZLibCompObject.NativeZlibCompObject self, PythonContext context, @SuppressWarnings("unused") PythonObjectFactory factory,
+ static void doCompressObj(ZLibCompObject.NativeZlibCompObject self, PythonContext context,
@SuppressWarnings("unused") boolean isCompressObj,
@Shared @Cached(inline = false) NativeLibrary.InvokeNativeFunction deallocateStream) {
context.getNFIZlibSupport().deallocateStream(self.getZst(), deallocateStream);
@@ -481,15 +482,16 @@ static void doCompressObj(ZLibCompObject.NativeZlibCompObject self, PythonContex
}
@Specialization(guards = "!isCompressObj")
- static void doDecompressObj(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext context, PythonObjectFactory factory,
+ static void doDecompressObj(Node inliningTarget, ZLibCompObject.NativeZlibCompObject self, PythonContext context,
@SuppressWarnings("unused") boolean isCompressObj,
@Cached GetNativeBufferNode getUnusedDataBuffer,
@Cached GetNativeBufferNode getUnconsumedBuffer,
@Shared @Cached(inline = false) NativeLibrary.InvokeNativeFunction deallocateStream) {
byte[] unusedData = getUnusedDataBuffer.getUnusedDataBuffer(inliningTarget, self.getZst(), context);
- self.setUnusedData(factory.createBytes(unusedData));
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ self.setUnusedData(PFactory.createBytes(language, unusedData));
byte[] unconsumed = getUnconsumedBuffer.getUnconsumedTailBuffer(inliningTarget, self.getZst(), context);
- self.setUnconsumedTail(factory.createBytes(unconsumed));
+ self.setUnconsumedTail(PFactory.createBytes(language, unconsumed));
context.getNFIZlibSupport().deallocateStream(self.getZst(), deallocateStream);
self.setEof(true);
self.markReleased();
@@ -594,35 +596,36 @@ private static byte[] createByteArray(ZLibCompObject.JavaZlibCompObject self, In
}
public static byte[] execute(VirtualFrame frame, ZLibCompObject.JavaZlibCompObject self, byte[] bytes, int length, int maxLength, int bufSize,
- Node nodeForRaise, PythonObjectFactory factory, BytesNodes.ToBytesNode toBytesNode) {
+ Node inliningTarget, BytesNodes.ToBytesNode toBytesNode) {
Inflater inflater = (Inflater) self.stream;
- byte[] result = createByteArray(self, inflater, bytes, length, maxLength, bufSize, nodeForRaise);
+ byte[] result = createByteArray(self, inflater, bytes, length, maxLength, bufSize, inliningTarget);
self.setEof(isFinished(inflater));
byte[] unusedDataBytes = toBytesNode.execute(frame, self.getUnusedData());
int unconsumedTailLen = self.getUnconsumedTail().getSequenceStorage().length();
- saveUnconsumedInput(self, bytes, length, unusedDataBytes, unconsumedTailLen, factory);
+ saveUnconsumedInput(self, bytes, length, unusedDataBytes, unconsumedTailLen, inliningTarget);
return result;
}
private static void saveUnconsumedInput(ZLibCompObject.JavaZlibCompObject self, byte[] data, int length,
- byte[] unusedDataBytes, int unconsumedTailLen, PythonObjectFactory factory) {
+ byte[] unusedDataBytes, int unconsumedTailLen, Node inliningTarget) {
Inflater inflater = (Inflater) self.stream;
int unusedLen = getRemaining(inflater);
byte[] tail = PythonUtils.arrayCopyOfRange(data, length - unusedLen, length);
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
if (self.isEof()) {
if (unconsumedTailLen > 0) {
- self.setUnconsumedTail(factory.createEmptyBytes());
+ self.setUnconsumedTail(PFactory.createEmptyBytes(language));
}
if (unusedDataBytes.length > 0 && tail.length > 0) {
byte[] newUnusedData = new byte[unusedDataBytes.length + tail.length];
PythonUtils.arraycopy(unusedDataBytes, 0, newUnusedData, 0, unusedDataBytes.length);
PythonUtils.arraycopy(tail, 0, newUnusedData, unusedDataBytes.length, tail.length);
- self.setUnusedData(factory.createBytes(newUnusedData));
+ self.setUnusedData(PFactory.createBytes(language, newUnusedData));
} else if (tail.length > 0) {
- self.setUnusedData(factory.createBytes(tail));
+ self.setUnusedData(PFactory.createBytes(language, tail));
}
} else {
- self.setUnconsumedTail(factory.createBytes(tail));
+ self.setUnconsumedTail(PFactory.createBytes(language, tail));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
index bc9233c76e..6152dda06f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
@@ -153,7 +153,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
@@ -1592,7 +1592,6 @@ public boolean hasMetaParents(
@ExportMessage
public Object getMetaParents(
@Bind("$node") Node inliningTarget,
- @Exclusive @Cached PythonObjectFactory factory,
@Exclusive @Cached TypeNodes.IsTypeNode isTypeNode,
@Exclusive @Cached TypeNodes.GetBaseClassesNode getBaseClassNode,
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
@@ -1601,7 +1600,7 @@ public Object getMetaParents(
if (isTypeNode.execute(inliningTarget, this)) {
var bases = getBaseClassNode.execute(inliningTarget, this);
if (bases.length > 0) {
- return factory.createTuple(bases);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), bases);
}
}
throw UnsupportedMessageException.create();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
index 329a6cbf18..0710f48b4d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
@@ -63,6 +63,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -125,7 +126,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -178,11 +179,11 @@ abstract static class ConcatNode extends SqConcatBuiltinNode {
@Specialization(guards = "left.getFormat() == right.getFormat()")
Object concat(PArray left, PArray right,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
int newLength = PythonUtils.addExact(left.getLength(), right.getLength());
int itemShift = left.getItemSizeShift();
- PArray newArray = factory.createArray(left.getFormatString(), left.getFormat(), newLength);
+ PArray newArray = PFactory.createArray(language, left.getFormatString(), left.getFormat(), newLength);
bufferLib.readIntoBuffer(left.getBuffer(), 0, newArray.getBuffer(), 0, left.getLength() << itemShift, bufferLib);
bufferLib.readIntoBuffer(right.getBuffer(), 0, newArray.getBuffer(), left.getLength() << itemShift, right.getLength() << itemShift, bufferLib);
return newArray;
@@ -232,7 +233,7 @@ static PArray concat(PArray self, int valueIn,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Cached InlinedBranchProfile negativeSize,
@Cached InlinedLoopConditionProfile loopProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int value = valueIn;
if (value < 0) {
negativeSize.enter(inliningTarget);
@@ -240,7 +241,7 @@ static PArray concat(PArray self, int valueIn,
}
try {
int newLength = Math.max(PythonUtils.multiplyExact(self.getLength(), value), 0);
- PArray newArray = factory.createArray(self.getFormatString(), self.getFormat(), newLength);
+ PArray newArray = PFactory.createArray(language, self.getFormatString(), self.getFormat(), newLength);
int segmentLength = self.getBytesLength();
loopProfile.profileCounted(inliningTarget, value);
for (int i = 0; loopProfile.inject(inliningTarget, i < value); i++) {
@@ -601,13 +602,13 @@ static Object doSlice(PArray self, PSlice slice,
@Exclusive @Cached InlinedConditionProfile simpleStepProfile,
@Cached SliceNodes.SliceUnpack sliceUnpack,
@Cached SliceNodes.AdjustIndices adjustIndices,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PSlice.SliceInfo sliceInfo = adjustIndices.execute(inliningTarget, self.getLength(), sliceUnpack.execute(inliningTarget, slice));
int itemShift = itemShiftProfile.profile(inliningTarget, (byte) self.getItemSizeShift());
int itemsize = self.getItemSize();
PArray newArray;
try {
- newArray = factory.createArray(self.getFormatString(), self.getFormat(), sliceInfo.sliceLength);
+ newArray = PFactory.createArray(language, self.getFormatString(), self.getFormat(), sliceInfo.sliceLength);
} catch (OverflowException e) {
// It's a slice of existing array, the length cannot overflow
throw CompilerDirectives.shouldNotReachHere();
@@ -782,8 +783,8 @@ abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object getitem(PArray self,
- @Cached PythonObjectFactory factory) {
- return factory.createArrayIterator(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createArrayIterator(language, self);
}
}
@@ -814,14 +815,14 @@ static Object reduceLegacy(VirtualFrame frame, PArray self, @SuppressWarnings("u
@Cached @Exclusive GetClassNode getClassNode,
@Cached @Exclusive PyObjectLookupAttr lookupDict,
@Cached ToListNode toListNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object cls = getClassNode.execute(inliningTarget, self);
Object dict = lookupDict.execute(frame, inliningTarget, self, T___DICT__);
if (dict == PNone.NO_VALUE) {
dict = PNone.NONE;
}
- PTuple args = factory.createTuple(new Object[]{self.getFormatString(), toListNode.execute(frame, self)});
- return factory.createTuple(new Object[]{cls, args, dict});
+ PTuple args = PFactory.createTuple(language, new Object[]{self.getFormatString(), toListNode.execute(frame, self)});
+ return PFactory.createTuple(language, new Object[]{cls, args, dict});
}
@Specialization(guards = "protocol >= 3")
@@ -831,7 +832,7 @@ static Object reduce(VirtualFrame frame, PArray self, @SuppressWarnings("unused"
@Cached @Exclusive PyObjectLookupAttr lookupDict,
@Cached PyObjectGetAttr getReconstructor,
@Cached ToBytesNode toBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule arrayModule = PythonContext.get(inliningTarget).lookupBuiltinModule(T_ARRAY);
PArray.MachineFormat mformat = PArray.MachineFormat.forFormat(self.getFormat());
assert mformat != null;
@@ -841,8 +842,8 @@ static Object reduce(VirtualFrame frame, PArray self, @SuppressWarnings("unused"
dict = PNone.NONE;
}
Object reconstructor = getReconstructor.execute(frame, inliningTarget, arrayModule, T_ARRAY_RECONSTRUCTOR);
- PTuple args = factory.createTuple(new Object[]{cls, self.getFormatString(), mformat.code, toBytesNode.execute(frame, self)});
- return factory.createTuple(new Object[]{reconstructor, args, dict});
+ PTuple args = PFactory.createTuple(language, new Object[]{cls, self.getFormatString(), mformat.code, toBytesNode.execute(frame, self)});
+ return PFactory.createTuple(language, new Object[]{reconstructor, args, dict});
}
}
@@ -873,8 +874,8 @@ abstract static class BufferInfoNode extends PythonUnaryBuiltinNode {
@Specialization
static Object bufferinfo(PArray self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached ArrayNodes.EnsureNativeStorageNode ensureNativeStorageNode,
- @Cached PythonObjectFactory factory,
@CachedLibrary(limit = "1") InteropLibrary lib) {
Object nativePointer = ensureNativeStorageNode.execute(inliningTarget, self).getPtr();
if (!(nativePointer instanceof Long)) {
@@ -885,7 +886,7 @@ static Object bufferinfo(PArray self,
throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError);
}
}
- return factory.createTuple(new Object[]{nativePointer, self.getLength()});
+ return PFactory.createTuple(language, new Object[]{nativePointer, self.getLength()});
}
}
@@ -1274,10 +1275,10 @@ abstract static class ToBytesNode extends PythonUnaryBuiltinNode {
@Specialization
Object tobytes(PArray self,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
byte[] bytes = new byte[self.getBytesLength()];
bufferLib.readIntoByteArray(self.getBuffer(), 0, bytes, 0, bytes.length);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
}
@@ -1320,9 +1321,9 @@ abstract static class ToFileNode extends PythonBinaryBuiltinNode {
@Specialization
static Object tofile(VirtualFrame frame, PArray self, Object file,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PythonObjectFactory factory) {
+ @Cached PyObjectCallMethodObjArgs callMethod) {
if (self.getLength() > 0) {
int remaining = self.getBytesLength();
int blocksize = 64 * 1024;
@@ -1335,7 +1336,7 @@ static Object tofile(VirtualFrame frame, PArray self, Object file,
buffer = new byte[blocksize];
}
bufferLib.readIntoByteArray(self.getBuffer(), i * blocksize, buffer, 0, buffer.length);
- callMethod.execute(frame, inliningTarget, file, T_WRITE, factory.createBytes(buffer));
+ callMethod.execute(frame, inliningTarget, file, T_WRITE, PFactory.createBytes(language, buffer));
remaining -= blocksize;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
index 68462f32e7..87c31b135b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -86,11 +86,11 @@ public PArray(Object clazz, Shape instanceShape, TruffleString formatString, Buf
this.storage = new ByteSequenceStorage(EMPTY_BYTE_ARRAY);
}
- public PArray(Object clazz, Shape instanceShape, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
+ public PArray(Object clazz, Shape instanceShape, TruffleString formatString, BufferFormat format, int byteSize) {
super(clazz, instanceShape);
this.formatString = formatString;
this.format = format;
- this.storage = new ByteSequenceStorage(new byte[PythonUtils.multiplyExact(length, format.bytesize)]);
+ this.storage = new ByteSequenceStorage(new byte[byteSize]);
}
public BufferFormat getFormat() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGeneratorBuiltins.java
index 021f85aff3..07e0fca228 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGeneratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGeneratorBuiltins.java
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -58,7 +59,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -93,9 +94,8 @@ public abstract static class GetCode extends PythonUnaryBuiltinNode {
@Specialization
static Object getCode(PAsyncGen self,
@Bind("this") Node inliningTarget,
- @Cached InlinedConditionProfile hasCodeProfile,
- @Cached PythonObjectFactory.Lazy factory) {
- return self.getOrCreateCode(inliningTarget, hasCodeProfile, factory);
+ @Cached InlinedConditionProfile hasCodeProfile) {
+ return self.getOrCreateCode(inliningTarget, hasCodeProfile);
}
}
@@ -136,9 +136,9 @@ static Object aSend(VirtualFrame frame, PAsyncGen self, Object sent,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached CallUnaryMethodNode callFirstIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
callHooks(frame, self, context.getThreadState(context.getLanguage(inliningTarget)), callFirstIter);
- return factory.createAsyncGeneratorASend(self, sent);
+ return PFactory.createAsyncGeneratorASend(language, self, sent);
}
}
@@ -152,9 +152,9 @@ static Object athrow(VirtualFrame frame, PAsyncGen self, Object arg1, Object arg
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached CallUnaryMethodNode callFirstIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
callHooks(frame, self, context.getThreadState(context.getLanguage(inliningTarget)), callFirstIter);
- return factory.createAsyncGeneratorAThrow(self, arg1, arg2, arg3);
+ return PFactory.createAsyncGeneratorAThrow(language, self, arg1, arg2, arg3);
}
}
@@ -175,9 +175,9 @@ static Object aNext(VirtualFrame frame, PAsyncGen self,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached CallUnaryMethodNode callFirstIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
callHooks(frame, self, context.getThreadState(context.getLanguage(inliningTarget)), callFirstIter);
- return factory.createAsyncGeneratorASend(self, PNone.NONE);
+ return PFactory.createAsyncGeneratorASend(language, self, PNone.NONE);
}
}
@@ -189,9 +189,9 @@ Object aClose(VirtualFrame frame, PAsyncGen self,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached CallUnaryMethodNode callFirstIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
callHooks(frame, self, context.getThreadState(context.getLanguage(inliningTarget)), callFirstIter);
- return factory.createAsyncGeneratorAThrow(self, null, PNone.NO_VALUE, PNone.NO_VALUE);
+ return PFactory.createAsyncGeneratorAThrow(language, self, null, PNone.NO_VALUE, PNone.NO_VALUE);
}
}
@@ -200,8 +200,8 @@ Object aClose(VirtualFrame frame, PAsyncGen self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
index 381fc26369..a50c5fc9f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -78,7 +79,6 @@
import com.oracle.graal.python.builtins.objects.slice.SliceNodes;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.MpAssSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode;
@@ -106,7 +106,7 @@
import com.oracle.graal.python.nodes.util.CastToByteNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -203,9 +203,7 @@ abstract static class GetitemNode extends SqItemBuiltinNode {
static Object doInt(Object self, int key,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Cached BytesNodes.GetBytesStorage getBytesStorage,
- @Cached PRaiseNode.Lazy raiseNode,
- @Cached SequenceStorageSqItemNode sqItemNode,
- @Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
+ @Cached SequenceStorageSqItemNode sqItemNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
return sqItemNode.execute(inliningTarget, storage, key, ErrorMessages.BYTEARRAY_OUT_OF_BOUNDS);
}
@@ -226,7 +224,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
throw raiseNonIntIndex(inliningTarget, raiseNode, idx);
}
return subscriptNode.execute(frame, inliningTarget, getBytesStorage.execute(inliningTarget, self), idx,
- ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PythonObjectFactory::createByteArray);
+ ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PFactory::createByteArray);
}
@InliningCutoff
@@ -302,6 +300,7 @@ static void doSliceSequence(VirtualFrame frame, PByteArray self, PSlice slice, P
@Specialization(guards = {"!isNoValue(value)", "bufferAcquireLib.hasBuffer(value)"}, limit = "3")
static void doSliceBuffer(VirtualFrame frame, PByteArray self, PSlice slice, Object value,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("value") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@@ -311,12 +310,11 @@ static void doSliceBuffer(VirtualFrame frame, PByteArray self, PSlice slice, Obj
@Cached @Shared SliceNodes.CoerceToIntSlice sliceCast,
@Cached @Shared SliceNodes.SliceUnpack unpack,
@Cached @Shared SliceNodes.AdjustIndices adjustIndices,
- @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(value, frame, indirectCallData);
try {
// TODO avoid copying if possible. Note that it is possible that value is self
- PBytes bytes = factory.createBytes(bufferLib.getCopiedByteArray(value));
+ PBytes bytes = PFactory.createBytes(language, bufferLib.getCopiedByteArray(value));
doSliceSequence(frame, self, slice, bytes, inliningTarget, differentLenProfile, getSequenceStorageNode, setItemSliceNode, sliceCast, unpack, adjustIndices, raiseNode);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
@@ -445,11 +443,11 @@ static PByteArray add(PByteArray self, PBytesLike other,
@Specialization(guards = "!isBytes(other)", limit = "3")
static PByteArray add(VirtualFrame frame, PByteArray self, Object other,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("other") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
Object buffer;
try {
@@ -460,7 +458,7 @@ static PByteArray add(VirtualFrame frame, PByteArray self, Object other,
try {
self.checkCanResize(inliningTarget, raiseNode);
// TODO avoid copying
- PBytes bytes = factory.createBytes(bufferLib.getCopiedByteArray(buffer));
+ PBytes bytes = PFactory.createBytes(language, bufferLib.getCopiedByteArray(buffer));
SequenceStorage res = concatNode.execute(self.getSequenceStorage(), bytes.getSequenceStorage());
updateSequenceStorage(self, res);
return self;
@@ -640,6 +638,7 @@ static PNone doBytes(VirtualFrame frame, PByteArray self, PBytesLike source,
@Specialization(guards = "!isBytes(source)", limit = "3")
static PNone doGeneric(VirtualFrame frame, PByteArray self, Object source,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("source") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@@ -647,7 +646,6 @@ static PNone doGeneric(VirtualFrame frame, PByteArray self, Object source,
@Cached BytesNodes.IterableToByteNode iterableToByteNode,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached("createExtend()") @Shared SequenceStorageNodes.ExtendNode extendNode,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
byte[] b;
@@ -667,7 +665,7 @@ static PNone doGeneric(VirtualFrame frame, PByteArray self, Object source,
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_EXTEND_BYTEARRAY_WITH_P, source);
}
}
- PByteArray bytes = factory.createByteArray(b);
+ PByteArray bytes = PFactory.createByteArray(language, b);
extend(frame, self, bytes, b.length, extendNode);
return PNone.NONE;
}
@@ -691,10 +689,12 @@ public abstract static class CopyNode extends PythonBuiltinNode {
@Specialization
static PByteArray copy(PByteArray byteArray,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetClassNode getClassNode,
- @Cached SequenceStorageNodes.ToByteArrayNode toByteArray,
- @Cached PythonObjectFactory factory) {
- return factory.createByteArray(getClassNode.execute(inliningTarget, byteArray), toByteArray.execute(inliningTarget, byteArray.getSequenceStorage()));
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
+ @Cached SequenceStorageNodes.ToByteArrayNode toByteArray) {
+ Object cls = getClassNode.execute(inliningTarget, byteArray);
+ return PFactory.createByteArray(language, cls, getInstanceShape.execute(cls), toByteArray.execute(inliningTarget, byteArray.getSequenceStorage()));
}
}
@@ -735,28 +735,24 @@ static PNone clear(VirtualFrame frame, PByteArray byteArray,
@GenerateNodeFactory
public abstract static class FromHexNode extends PythonBinaryClinicBuiltinNode {
- @Specialization(guards = "isBuiltinBytesType(inliningTarget, cls, isSameType)")
- static PByteArray doBytes(Object cls, TruffleString str,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("isSameType") @Cached IsSameTypeNode isSameType,
+ @Specialization(guards = "isBuiltinByteArrayType(cls)")
+ static PByteArray doBytes(@SuppressWarnings("unused") Object cls, TruffleString str,
@Shared("hexToBytes") @Cached HexStringToBytesNode hexStringToBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createByteArray(cls, hexStringToBytesNode.execute(str));
+ @Bind PythonLanguage language) {
+ return PFactory.createByteArray(language, hexStringToBytesNode.execute(str));
}
- @Specialization(guards = "!isBuiltinBytesType(inliningTarget, cls, isSameType)")
+ @Specialization(guards = "!isBuiltinByteArrayType(cls)")
static Object doGeneric(VirtualFrame frame, Object cls, TruffleString str,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("isSameType") @Cached IsSameTypeNode isSameType,
@Cached CallNode callNode,
@Shared("hexToBytes") @Cached HexStringToBytesNode hexStringToBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
- PByteArray byteArray = factory.createByteArray(hexStringToBytesNode.execute(str));
+ @Bind PythonLanguage language) {
+ PByteArray byteArray = PFactory.createByteArray(language, hexStringToBytesNode.execute(str));
return callNode.execute(frame, cls, byteArray);
}
- protected static boolean isBuiltinBytesType(Node inliningTarget, Object cls, IsSameTypeNode isSameTypeNode) {
- return isSameTypeNode.execute(inliningTarget, PythonBuiltinClassType.PBytes, cls);
+ protected static boolean isBuiltinByteArrayType(Object cls) {
+ return cls == PythonBuiltinClassType.PByteArray;
}
@Override
@@ -773,11 +769,11 @@ public abstract static class TranslateNode extends BytesNodes.BaseTranslateNode
@Specialization
static PByteArray translate(VirtualFrame frame, PByteArray self, Object table, Object delete,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile isLenTable256Profile,
@Cached InlinedBranchProfile hasTable,
@Cached InlinedBranchProfile hasDelete,
@Cached BytesNodes.ToBytesNode toBytesNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
byte[] bTable = null;
if (table != PNone.NONE) {
@@ -800,9 +796,9 @@ static PByteArray translate(VirtualFrame frame, PByteArray self, Object table, O
} else if (bDelete != null) {
result = delete(bSelf, bDelete);
} else {
- return factory.createByteArray(bSelf);
+ return PFactory.createByteArray(language, bSelf);
}
- return factory.createByteArray(result.array);
+ return PFactory.createByteArray(language, result.array);
}
}
@@ -819,22 +815,22 @@ public static int alloc(PByteArray byteArray) {
}
}
- protected static Object commonReduce(int proto, byte[] bytes, int len, Object clazz, Object dict,
- PythonObjectFactory factory, TruffleStringBuilder.AppendCodePointNode appendCodePointNode, TruffleStringBuilder.ToStringNode toStringNode) {
+ static Object commonReduce(int proto, byte[] bytes, int len, Object clazz, Object dict,
+ PythonLanguage language, TruffleStringBuilder.AppendCodePointNode appendCodePointNode, TruffleStringBuilder.ToStringNode toStringNode) {
TruffleStringBuilder sb = TruffleStringBuilder.create(TS_ENCODING);
BytesUtils.repr(sb, bytes, len, appendCodePointNode);
TruffleString str = toStringNode.execute(sb);
Object contents;
if (proto < 3) {
- contents = factory.createTuple(new Object[]{str, T_LATIN_1});
+ contents = PFactory.createTuple(language, new Object[]{str, T_LATIN_1});
} else {
if (len > 0) {
- contents = factory.createTuple(new Object[]{str, len});
+ contents = PFactory.createTuple(language, new Object[]{str, len});
} else {
- contents = factory.createTuple(new Object[0]);
+ contents = PFactory.createTuple(language, new Object[0]);
}
}
- return factory.createTuple(new Object[]{clazz, contents, dict});
+ return PFactory.createTuple(language, new Object[]{clazz, contents, dict});
}
@Builtin(name = J___REDUCE__, minNumOfPositionalArgs = 1)
@@ -844,17 +840,17 @@ protected abstract static class ReduceNode extends PythonUnaryBuiltinNode {
@Specialization
static Object reduce(VirtualFrame frame, PByteArray self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached SequenceStorageNodes.GetInternalByteArrayNode getBytes,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetStateNode getStateNode,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
- @Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleStringBuilder.ToStringNode toStringNode) {
byte[] bytes = getBytes.execute(inliningTarget, self.getSequenceStorage());
int len = self.getSequenceStorage().length();
Object state = getStateNode.execute(frame, inliningTarget, self);
Object clazz = getClassNode.execute(inliningTarget, self);
- return commonReduce(2, bytes, len, clazz, state, factory, appendCodePointNode, toStringNode);
+ return commonReduce(2, bytes, len, clazz, state, language, appendCodePointNode, toStringNode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
index 0bea205499..f2f0b369ec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
@@ -40,6 +40,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -54,7 +55,6 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.SequenceStorageSqItemNode;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode;
import com.oracle.graal.python.lib.PyBytesCheckExactNode;
@@ -70,7 +70,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -123,9 +123,7 @@ abstract static class GetitemNode extends SqItemBuiltinNode {
static Object doInt(Object self, int key,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Cached BytesNodes.GetBytesStorage getBytesStorage,
- @Cached PRaiseNode.Lazy raiseNode,
- @Cached SequenceStorageSqItemNode sqItemNode,
- @Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
+ @Cached SequenceStorageSqItemNode sqItemNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
return sqItemNode.execute(inliningTarget, storage, key, ErrorMessages.BYTES_OUT_OF_BOUNDS);
}
@@ -146,7 +144,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
throw raiseNonIntIndex(inliningTarget, raiseNode, idx);
}
return subscriptNode.execute(frame, inliningTarget, getBytesStorage.execute(inliningTarget, self), idx,
- ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PythonObjectFactory::createBytes);
+ ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PFactory::createBytes);
}
@InliningCutoff
@@ -174,11 +172,11 @@ public abstract static class TranslateNode extends BytesNodes.BaseTranslateNode
@Specialization
static Object translate(VirtualFrame frame, Object self, Object table, Object delete,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile isLenTable256Profile,
@Cached InlinedBranchProfile hasTable,
@Cached InlinedBranchProfile hasDelete,
@Cached BytesNodes.ToBytesNode toBytesNode,
- @Cached PythonObjectFactory factory,
@Cached PyBytesCheckExactNode checkExactNode,
@Cached PRaiseNode.Lazy raiseNode) {
byte[] bTable = null;
@@ -202,12 +200,12 @@ static Object translate(VirtualFrame frame, Object self, Object table, Object de
} else if (bDelete != null) {
result = delete(bSelf, bDelete);
} else if (!checkExactNode.execute(inliningTarget, self)) {
- return factory.createBytes(bSelf);
+ return PFactory.createBytes(language, bSelf);
} else {
return self;
}
if (result.changed || !checkExactNode.execute(inliningTarget, self)) {
- return factory.createBytes(result.array);
+ return PFactory.createBytes(language, result.array);
}
return self;
}
@@ -219,28 +217,24 @@ static Object translate(VirtualFrame frame, Object self, Object table, Object de
@GenerateNodeFactory
public abstract static class FromHexNode extends PythonBinaryClinicBuiltinNode {
- @Specialization(guards = "isBuiltinBytesType(inliningTarget, cls, isSameType)")
- static PBytes doBytes(Object cls, TruffleString str,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("isSameType") @Cached TypeNodes.IsSameTypeNode isSameType,
+ @Specialization(guards = "isBuiltinBytesType(cls)")
+ static PBytes doBytes(@SuppressWarnings("unused") Object cls, TruffleString str,
@Shared("hexToBytes") @Cached BytesNodes.HexStringToBytesNode hexStringToBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBytes(cls, hexStringToBytesNode.execute(str));
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, hexStringToBytesNode.execute(str));
}
- @Specialization(guards = "!isBuiltinBytesType(inliningTarget, cls, isSameType)")
+ @Specialization(guards = "!isBuiltinBytesType(cls)")
static Object doGeneric(VirtualFrame frame, Object cls, TruffleString str,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Shared("isSameType") @Cached TypeNodes.IsSameTypeNode isSameType,
@Cached CallNode callNode,
@Shared("hexToBytes") @Cached BytesNodes.HexStringToBytesNode hexStringToBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
- PBytes bytes = factory.createBytes(hexStringToBytesNode.execute(str));
+ @Bind PythonLanguage language) {
+ PBytes bytes = PFactory.createBytes(language, hexStringToBytesNode.execute(str));
return callNode.execute(frame, cls, bytes);
}
- protected static boolean isBuiltinBytesType(Node inliningTarget, Object cls, TypeNodes.IsSameTypeNode isSameTypeNode) {
- return isSameTypeNode.execute(inliningTarget, PythonBuiltinClassType.PBytes, cls);
+ protected static boolean isBuiltinBytesType(Object cls) {
+ return cls == PythonBuiltinClassType.PBytes;
}
@Override
@@ -362,13 +356,13 @@ abstract static class BytesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object bytes(Object self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached PyBytesCheckExactNode check,
- @Cached BytesNodes.GetBytesStorage getBytesStorage,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached BytesNodes.GetBytesStorage getBytesStorage) {
if (check.execute(inliningTarget, self)) {
return self;
} else {
- return factory.get(inliningTarget).createBytes(getBytesStorage.execute(inliningTarget, self));
+ return PFactory.createBytes(language, getBytesStorage.execute(inliningTarget, self));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
index 6b02e3723a..ddd6c980a9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
@@ -133,7 +133,7 @@
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.formatting.BytesFormatProcessor;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
@@ -277,10 +277,9 @@ static PBytesLike join(VirtualFrame frame, Object self, Object iterable,
@Cached GetBytesStorage getBytesStorage,
@Cached SequenceStorageNodes.ToByteArrayNode toByteArrayNode,
@Cached BytesNodes.BytesJoinNode bytesJoinNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] res = bytesJoinNode.execute(frame, inliningTarget, toByteArrayNode.execute(inliningTarget, getBytesStorage.execute(inliningTarget, self)), iterable);
- return create.execute(inliningTarget, factory, self, res);
+ return create.execute(inliningTarget, self, res);
}
}
@@ -292,10 +291,9 @@ public abstract static class ConcatNode extends SqConcatBuiltinNode {
static PBytesLike add(PBytesLike self, PBytesLike other,
@Bind("this") Node node,
@Cached("createWithOverflowError()") @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Cached @Exclusive BytesNodes.CreateBytesNode create,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached @Exclusive BytesNodes.CreateBytesNode create) {
SequenceStorage res = concatNode.execute(self.getSequenceStorage(), other.getSequenceStorage());
- return create.execute(node, factory, self, res);
+ return create.execute(node, self, res);
}
@Specialization(limit = "3")
@@ -307,7 +305,6 @@ static PBytesLike add(VirtualFrame frame, Object self, Object other,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached("createWithOverflowError()") @Shared SequenceStorageNodes.ConcatNode concatNode,
@Cached @Exclusive BytesNodes.CreateBytesNode create,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object buffer;
try {
@@ -319,7 +316,7 @@ static PBytesLike add(VirtualFrame frame, Object self, Object other,
// TODO avoid copying
byte[] bytes = bufferLib.getCopiedByteArray(buffer);
SequenceStorage res = concatNode.execute(getBytesStorage.execute(inliningTarget, self), new ByteSequenceStorage(bytes));
- return create.execute(inliningTarget, factory, self, res);
+ return create.execute(inliningTarget, self, res);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -334,10 +331,9 @@ static PBytesLike mul(VirtualFrame frame, Object self, int times,
@Bind("this") Node inliningTarget,
@Cached GetBytesStorage getBytesStorage,
@Cached("createWithOverflowError()") SequenceStorageNodes.RepeatNode repeatNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
SequenceStorage res = repeatNode.execute(frame, getBytesStorage.execute(inliningTarget, self), times);
- return create.execute(inliningTarget, factory, self, res);
+ return create.execute(inliningTarget, self, res);
}
}
@@ -372,8 +368,7 @@ static Object mod(VirtualFrame frame, Object self, Object right,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached BytesNodes.CreateBytesNode create,
- @Cached TupleBuiltins.GetItemNode getTupleItemNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TupleBuiltins.GetItemNode getTupleItemNode) {
Object buffer = acquireLib.acquireReadonly(self, frame, indirectCallData);
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
@@ -382,7 +377,7 @@ static Object mod(VirtualFrame frame, Object self, Object right,
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
try {
byte[] data = formatter.format(right);
- return create.execute(inliningTarget, factory, self, data);
+ return create.execute(inliningTarget, self, data);
} finally {
IndirectCallContext.exit(frame, indirectCallData, savedState);
}
@@ -427,8 +422,8 @@ boolean contains(VirtualFrame frame, Object self, Object other,
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static PSequenceIterator contains(Object self,
- @Cached PythonObjectFactory factory) {
- return factory.createSequenceIterator(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createSequenceIterator(language, self);
}
}
@@ -624,6 +619,7 @@ public abstract static class PartitionAbstractNode extends PythonBinaryBuiltinNo
@SuppressWarnings("truffle-static-method") // TODO: inh
PTuple partition(VirtualFrame frame, Object self, Object sep,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("sep") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@@ -631,7 +627,6 @@ PTuple partition(VirtualFrame frame, Object self, Object sep,
@Cached InlinedConditionProfile notFound,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached BytesNodes.CreateBytesNode createBytesNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
@@ -646,28 +641,28 @@ PTuple partition(VirtualFrame frame, Object self, Object sep,
int idx = BytesNodes.FindNode.find(bytes, len, sepBytes, 0, bytes.length, isRight());
PBytesLike first, second, third;
if (notFound.profile(inliningTarget, idx == -1)) {
- second = createBytesNode.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ second = createBytesNode.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
if (isRight()) {
- third = createBytesNode.execute(inliningTarget, factory, self, bytes);
- first = createBytesNode.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ third = createBytesNode.execute(inliningTarget, self, bytes);
+ first = createBytesNode.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
} else {
- first = createBytesNode.execute(inliningTarget, factory, self, bytes);
- third = createBytesNode.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ first = createBytesNode.execute(inliningTarget, self, bytes);
+ third = createBytesNode.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
} else {
- second = createBytesNode.execute(inliningTarget, factory, self, sepBytes);
+ second = createBytesNode.execute(inliningTarget, self, sepBytes);
if (idx == 0) {
- first = createBytesNode.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
- third = createBytesNode.execute(inliningTarget, factory, self, Arrays.copyOfRange(bytes, lenSep, len));
+ first = createBytesNode.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ third = createBytesNode.execute(inliningTarget, self, Arrays.copyOfRange(bytes, lenSep, len));
} else if (idx == len - 1) {
- first = createBytesNode.execute(inliningTarget, factory, self, Arrays.copyOfRange(bytes, 0, len - lenSep));
- third = createBytesNode.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ first = createBytesNode.execute(inliningTarget, self, Arrays.copyOfRange(bytes, 0, len - lenSep));
+ third = createBytesNode.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
} else {
- first = createBytesNode.execute(inliningTarget, factory, self, Arrays.copyOfRange(bytes, 0, idx));
- third = createBytesNode.execute(inliningTarget, factory, self, Arrays.copyOfRange(bytes, idx + lenSep, len));
+ first = createBytesNode.execute(inliningTarget, self, Arrays.copyOfRange(bytes, 0, idx));
+ third = createBytesNode.execute(inliningTarget, self, Arrays.copyOfRange(bytes, idx + lenSep, len));
}
}
- return factory.createTuple(new Object[]{first, second, third});
+ return PFactory.createTuple(language, new Object[]{first, second, third});
} finally {
bufferLib.release(sepBuffer, frame, indirectCallData);
}
@@ -1211,7 +1206,6 @@ PBytesLike bytes(VirtualFrame frame, Object self, Object widthObj, Object fillOb
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Cached InlinedBranchProfile hasFill,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
int width = asSizeNode.executeExact(frame, inliningTarget, widthObj);
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
@@ -1226,9 +1220,9 @@ PBytesLike bytes(VirtualFrame frame, Object self, Object widthObj, Object fillOb
}
}
if (checkSkip(len, width)) {
- return create.execute(inliningTarget, factory, self, copyNode.execute(inliningTarget, storage));
+ return create.execute(inliningTarget, self, copyNode.execute(inliningTarget, storage));
}
- return create.execute(inliningTarget, factory, self, make(bufferLib.getCopiedByteArray(self), len, width, fillByte));
+ return create.execute(inliningTarget, self, make(bufferLib.getCopiedByteArray(self), len, width, fillByte));
}
protected String methodName() {
@@ -1339,8 +1333,7 @@ static PBytesLike replace(Object self, Object substrBuffer, Object replacementBu
@Cached InlinedConditionProfile selfSubAreEmpty,
@Cached InlinedConditionProfile selfIsEmpty,
@Cached InlinedConditionProfile subIsEmpty,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
try {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
@@ -1349,16 +1342,16 @@ static PBytesLike replace(Object self, Object substrBuffer, Object replacementBu
byte[] replacementBytes = bufferLib.getCopiedByteArray(replacementBuffer);
int maxcount = count < 0 ? Integer.MAX_VALUE : count;
if (selfSubAreEmpty.profile(inliningTarget, len == 0 && subBytes.length == 0)) {
- return create.execute(inliningTarget, factory, self, replacementBytes);
+ return create.execute(inliningTarget, self, replacementBytes);
}
if (selfIsEmpty.profile(inliningTarget, len == 0)) {
- return create.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ return create.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
if (subIsEmpty.profile(inliningTarget, subBytes.length == 0)) {
- return create.execute(inliningTarget, factory, self, replaceWithEmptySub(bytes, len, replacementBytes, maxcount));
+ return create.execute(inliningTarget, self, replaceWithEmptySub(bytes, len, replacementBytes, maxcount));
}
byte[] newBytes = replace(bytes, len, subBytes, replacementBytes, maxcount);
- return create.execute(inliningTarget, factory, self, newBytes);
+ return create.execute(inliningTarget, self, newBytes);
} finally {
bufferLib.release(substrBuffer);
bufferLib.release(replacementBuffer);
@@ -1437,13 +1430,12 @@ abstract static class LowerNode extends PythonUnaryBuiltinNode {
static PBytesLike replace(Object self,
@Bind("this") Node node,
@Cached BytesNodes.ToBytesNode toBytes,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] bytes = toBytes.execute(null, self);
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = toLower(bytes[i]);
}
- return create.execute(node, factory, self, bytes);
+ return create.execute(node, self, bytes);
}
}
@@ -1455,13 +1447,12 @@ abstract static class UpperNode extends PythonUnaryBuiltinNode {
static PBytesLike replace(Object self,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.ToBytesNode toBytes,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] bytes = toBytes.execute(null, self);
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = toUpper(bytes[i]);
}
- return create.execute(inliningTarget, factory, self, bytes);
+ return create.execute(inliningTarget, self, bytes);
}
}
@@ -1608,10 +1599,10 @@ PList whitespace(Object self, @SuppressWarnings("unused") byte[] sep, int maxspl
@Shared("toBytes") @Cached SequenceStorageNodes.GetInternalByteArrayNode selfToBytesNode,
@Shared("append") @Cached ListNodes.AppendNode appendNode,
@Shared("create") @Cached BytesNodes.CreateBytesNode createBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
byte[] splitBs = selfToBytesNode.execute(inliningTarget, storage);
- return getBytesResult(splitWhitespace(splitBs, storage.length(), adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, factory);
+ return getBytesResult(splitWhitespace(splitBs, storage.length(), adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, language);
}
@Specialization(guards = {"!isWhitespace(sep)", "isSingleSep(sep)"})
@@ -1621,10 +1612,10 @@ PList single(Object self, byte[] sep, int maxsplit,
@Shared("toBytes") @Cached SequenceStorageNodes.GetInternalByteArrayNode selfToBytesNode,
@Shared("append") @Cached ListNodes.AppendNode appendNode,
@Shared("create") @Cached BytesNodes.CreateBytesNode createBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
byte[] splitBs = selfToBytesNode.execute(inliningTarget, storage);
- return getBytesResult(splitSingle(splitBs, storage.length(), sep[0], adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, factory);
+ return getBytesResult(splitSingle(splitBs, storage.length(), sep[0], adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, language);
}
@Specialization(guards = {"!isWhitespace(sep)", "!isEmptySep(sep)", "!isSingleSep(sep)"})
@@ -1634,10 +1625,10 @@ PList split(Object self, byte[] sep, int maxsplit,
@Shared("toBytes") @Cached SequenceStorageNodes.GetInternalByteArrayNode selfToBytesNode,
@Shared("append") @Cached ListNodes.AppendNode appendNode,
@Shared("create") @Cached BytesNodes.CreateBytesNode createBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
byte[] splitBs = selfToBytesNode.execute(inliningTarget, storage);
- return getBytesResult(splitDelimiter(splitBs, storage.length(), sep, adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, factory);
+ return getBytesResult(splitDelimiter(splitBs, storage.length(), sep, adjustMaxSplit(maxsplit)), appendNode, self, inliningTarget, createBytesNode, language);
}
@SuppressWarnings("unused")
@@ -1648,11 +1639,11 @@ static PList error(Object bytes, byte[] sep, int maxsplit,
}
private static PList getBytesResult(List bytes, ListNodes.AppendNode appendNode, Object self, Node inliningTarget, BytesNodes.CreateBytesNode createBytesNode,
- PythonObjectFactory factory) {
- PList result = factory.createList();
+ PythonLanguage language) {
+ PList result = PFactory.createList(language);
Iterator it = iterator(bytes);
while (hasNext(it)) {
- appendNode.execute(result, createBytesNode.execute(inliningTarget, factory, self, next(it)));
+ appendNode.execute(result, createBytesNode.execute(inliningTarget, self, next(it)));
}
return result;
}
@@ -1864,14 +1855,14 @@ public abstract static class SplitLinesNode extends PythonBinaryBuiltinNode {
@Specialization
static PList doSplitlines(Object self, Object keependsObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedBranchProfile isPNoneProfile,
@Cached InlinedBranchProfile isBooleanProfile,
@Cached InlinedConditionProfile keependsProfile,
@Cached CastToJavaIntExactNode cast,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached ListNodes.AppendNode appendNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
boolean keepends;
if (keependsObj instanceof Boolean b) {
isBooleanProfile.enter(inliningTarget);
@@ -1884,7 +1875,7 @@ static PList doSplitlines(Object self, Object keependsObj,
}
keepends = keependsProfile.profile(inliningTarget, keepends);
byte[] bytes = toBytesNode.execute(null, self);
- PList list = factory.createList();
+ PList list = PFactory.createList(language);
int sliceStart = 0;
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == '\n' || bytes[i] == '\r') {
@@ -1896,14 +1887,14 @@ static PList doSplitlines(Object self, Object keependsObj,
sliceEnd = i + 1;
}
byte[] slice = copySlice(bytes, sliceStart, sliceEnd);
- appendNode.execute(list, create.execute(inliningTarget, factory, self, slice));
+ appendNode.execute(list, create.execute(inliningTarget, self, slice));
sliceStart = i + 1;
}
}
// Process the remaining part if any
if (sliceStart != bytes.length) {
byte[] slice = copySlice(bytes, sliceStart, bytes.length);
- appendNode.execute(list, create.execute(inliningTarget, factory, self, slice));
+ appendNode.execute(list, create.execute(inliningTarget, self, slice));
}
return list;
}
@@ -1922,10 +1913,9 @@ abstract static class AStripNode extends PythonBinaryBuiltinNode {
PBytesLike strip(VirtualFrame frame, Object self, @SuppressWarnings("unused") PNone bytes,
@Bind("this") Node node,
@Shared("createByte") @Cached BytesNodes.CreateBytesNode create,
- @Shared("toByteSelf") @Cached BytesNodes.ToBytesNode toBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("toByteSelf") @Cached BytesNodes.ToBytesNode toBytesNode) {
byte[] bs = toBytesNode.execute(frame, self);
- return create.execute(node, factory, self, getResultBytes(bs, findIndex(bs)));
+ return create.execute(node, self, getResultBytes(bs, findIndex(bs)));
}
@Specialization(guards = "!isPNone(object)")
@@ -1935,14 +1925,13 @@ PBytesLike strip(VirtualFrame frame, Object self, Object object,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared("createByte") @Cached BytesNodes.CreateBytesNode create,
- @Shared("toByteSelf") @Cached BytesNodes.ToBytesNode selfToBytesNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared("toByteSelf") @Cached BytesNodes.ToBytesNode selfToBytesNode) {
Object buffer = bufferAcquireLib.acquireReadonly(object, frame, indirectCallData);
try {
byte[] stripBs = bufferLib.getInternalOrCopiedByteArray(buffer);
int stripBsLen = bufferLib.getBufferLength(buffer);
byte[] bs = selfToBytesNode.execute(frame, self);
- return create.execute(node, factory, self, getResultBytes(bs, findIndex(bs, stripBs, stripBsLen)));
+ return create.execute(node, self, getResultBytes(bs, findIndex(bs, stripBs, stripBsLen)));
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -2080,8 +2069,8 @@ public abstract static class MakeTransNode extends PythonBuiltinNode {
@Specialization
static PBytes maketrans(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object from, Object to,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached BytesNodes.ToBytesNode toByteNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
byte[] fromB = toByteNode.execute(frame, from);
byte[] toB = toByteNode.execute(frame, to);
@@ -2099,7 +2088,7 @@ static PBytes maketrans(VirtualFrame frame, @SuppressWarnings("unused") Object c
table[value < 0 ? value + 256 : value] = toB[i];
}
- return factory.createBytes(table);
+ return PFactory.createBytes(language, table);
}
}
@@ -2112,17 +2101,16 @@ abstract static class CapitalizeNode extends PythonUnaryBuiltinNode {
static PBytesLike capitalize(Object self,
@Bind("this") Node inliningTarget,
@Cached ToBytesNode toBytesNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] b = toBytesNode.execute(null, self);
if (b.length == 0) {
- return create.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ return create.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
b[0] = toUpper(b[0]);
for (int i = 1; i < b.length; i++) {
b[i] = toLower(b[i]);
}
- return create.execute(inliningTarget, factory, self, b);
+ return create.execute(inliningTarget, self, b);
}
}
@@ -2134,11 +2122,10 @@ abstract static class TitleNode extends PythonUnaryBuiltinNode {
static PBytesLike title(Object self,
@Bind("this") Node inliningTarget,
@Cached ToBytesNode toBytesNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] b = toBytesNode.execute(null, self);
if (b.length == 0) {
- return create.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ return create.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
boolean previousIsCased = false;
@@ -2160,7 +2147,7 @@ static PBytesLike title(Object self,
b[i] = c;
}
- return create.execute(inliningTarget, factory, self, b);
+ return create.execute(inliningTarget, self, b);
}
}
@@ -2172,11 +2159,10 @@ abstract static class SwapCaseNode extends PythonUnaryBuiltinNode {
static PBytesLike swapcase(Object self,
@Bind("this") Node inliningTarget,
@Cached ToBytesNode toBytesNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
byte[] b = toBytesNode.execute(null, self);
if (b.length == 0) {
- return create.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ return create.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
for (int i = 0; i < b.length; i++) {
if (BytesUtils.isUpper(b[i])) {
@@ -2185,7 +2171,7 @@ static PBytesLike swapcase(Object self,
b[i] = toUpper(b[i]);
}
}
- return create.execute(inliningTarget, factory, self, b);
+ return create.execute(inliningTarget, self, b);
}
}
@@ -2205,12 +2191,11 @@ static PBytesLike expandtabs(Object self, int tabsize,
@Cached GetBytesStorage getBytesStorage,
@Cached GetInternalByteArrayNode getInternalByteArrayNode,
@Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
if (len == 0) {
- return create.execute(inliningTarget, factory, self, PythonUtils.EMPTY_BYTE_ARRAY);
+ return create.execute(inliningTarget, self, PythonUtils.EMPTY_BYTE_ARRAY);
}
int max = SysModuleBuiltins.MAXSIZE;
byte[] b = getInternalByteArrayNode.execute(inliningTarget, storage);
@@ -2264,7 +2249,7 @@ static PBytesLike expandtabs(Object self, int tabsize,
}
}
- return create.execute(inliningTarget, factory, self, q);
+ return create.execute(inliningTarget, self, q);
}
@Override
@@ -2283,10 +2268,9 @@ static PBytesLike zfill(Object self, int width,
@Bind("this") Node inliningTarget,
@Cached GetBytesStorage getBytesStorage,
@Cached GetInternalByteArrayNode getInternalByteArrayNode,
- @Cached BytesNodes.CreateBytesNode create,
- @Cached PythonObjectFactory factory) {
+ @Cached BytesNodes.CreateBytesNode create) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
- return create.execute(inliningTarget, factory, self, zfill(getInternalByteArrayNode.execute(inliningTarget, storage), storage.length(), width));
+ return create.execute(inliningTarget, self, zfill(getInternalByteArrayNode.execute(inliningTarget, storage), storage.length(), width));
}
private static byte[] zfill(byte[] self, int len, int width) {
@@ -2361,9 +2345,9 @@ public abstract static class GetNewargsNode extends PythonUnaryBuiltinNode {
@Specialization
static PTuple doBytes(Object self,
@Bind("this") Node inliningTarget,
- @Cached GetBytesStorage getBytesStorage,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{factory.createBytes(getBytesStorage.execute(inliningTarget, self))});
+ @Bind PythonLanguage language,
+ @Cached GetBytesStorage getBytesStorage) {
+ return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, getBytesStorage.execute(inliningTarget, self))});
}
}
@@ -2377,8 +2361,7 @@ static PBytesLike remove(VirtualFrame frame, Object self, Object prefix,
@CachedLibrary(limit = "1") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached BytesNodes.CreateBytesNode create,
- @Cached InlinedConditionProfile profile,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile profile) {
Object selfBuffer = bufferAcquireLib.acquireReadonly(self, frame, indirectCallData);
Object prefixBuffer = bufferAcquireLib.acquireReadonly(prefix, frame, indirectCallData);
@@ -2394,15 +2377,15 @@ static PBytesLike remove(VirtualFrame frame, Object self, Object prefix,
for (int i = 0; i < selfBsLen; i++) {
if (i < prefixBsLen) {
if (selfBs[i] != prefixBs[i]) {
- return create.execute(node, factory, self, selfBs);
+ return create.execute(node, self, selfBs);
}
} else {
result[j++] = selfBs[i];
}
}
- return create.execute(node, factory, self, result);
+ return create.execute(node, self, result);
}
- return create.execute(node, factory, self, selfBs);
+ return create.execute(node, self, selfBs);
} finally {
bufferLib.release(selfBuffer, frame, indirectCallData);
bufferLib.release(prefixBuffer, frame, indirectCallData);
@@ -2420,8 +2403,7 @@ static PBytesLike remove(VirtualFrame frame, Object self, Object suffix,
@CachedLibrary(limit = "1") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached BytesNodes.CreateBytesNode create,
- @Cached InlinedConditionProfile profile,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile profile) {
Object selfBuffer = bufferAcquireLib.acquireReadonly(self, frame, indirectCallData);
Object suffixBuffer = bufferAcquireLib.acquireReadonly(suffix, frame, indirectCallData);
try {
@@ -2436,15 +2418,15 @@ static PBytesLike remove(VirtualFrame frame, Object self, Object suffix,
for (int i = selfBsLen - 1, j = 1; i >= 0; i--, j++) {
if (i >= selfBsLen - suffixBsLen) {
if (selfBs[i] != suffixBs[suffixBsLen - j]) {
- return create.execute(node, factory, self, selfBs);
+ return create.execute(node, self, selfBs);
}
} else {
result[result.length - k++] = selfBs[i];
}
}
- return create.execute(node, factory, self, result);
+ return create.execute(node, self, result);
}
- return create.execute(node, factory, self, selfBs);
+ return create.execute(node, self, selfBs);
} finally {
bufferLib.release(selfBuffer, frame, indirectCallData);
bufferLib.release(suffixBuffer, frame, indirectCallData);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
index c384cd4a50..dfceba80ec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
@@ -58,6 +58,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ClinicConverterFactory;
import com.oracle.graal.python.annotations.ClinicConverterFactory.ArgumentIndex;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -98,7 +99,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.NativeByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -135,33 +136,37 @@ public abstract class BytesNodes {
@GenerateCached(false)
public abstract static class CreateBytesNode extends Node {
- public final PBytesLike execute(Node inliningTarget, PythonObjectFactory factory, Object basedOn, byte[] bytes) {
- return execute(inliningTarget, factory, basedOn, new ByteSequenceStorage(bytes));
+ public final PBytesLike execute(Node inliningTarget, Object basedOn, byte[] bytes) {
+ return execute(inliningTarget, basedOn, new ByteSequenceStorage(bytes));
}
- public abstract PBytesLike execute(Node inliningTarget, PythonObjectFactory factory, Object basedOn, SequenceStorage bytes);
+ public abstract PBytesLike execute(Node inliningTarget, Object basedOn, SequenceStorage bytes);
@Specialization
- static PBytesLike bytes(PythonObjectFactory factory, @SuppressWarnings("unused") PBytes basedOn, SequenceStorage bytes) {
- return factory.createBytes(bytes);
+ static PBytesLike bytes(@SuppressWarnings("unused") PBytes basedOn, SequenceStorage bytes,
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, bytes);
}
@Specialization
- static PBytesLike bytearray(PythonObjectFactory factory, @SuppressWarnings("unused") PByteArray basedOn, SequenceStorage bytes) {
- return factory.createByteArray(bytes);
+ static PBytesLike bytearray(@SuppressWarnings("unused") PByteArray basedOn, SequenceStorage bytes,
+ @Bind PythonLanguage language) {
+ return PFactory.createByteArray(language, bytes);
}
@Specialization(guards = "checkBytes.execute(inliningTarget, basedOn)")
- static PBytesLike bytes(@SuppressWarnings("unused") Node inliningTarget, PythonObjectFactory factory, @SuppressWarnings("unused") Object basedOn, SequenceStorage bytes,
- @SuppressWarnings("unused") @Shared @Cached PyBytesCheckNode checkBytes) {
- return factory.createBytes(bytes);
+ static PBytesLike bytes(@SuppressWarnings("unused") Node inliningTarget, @SuppressWarnings("unused") Object basedOn, SequenceStorage bytes,
+ @SuppressWarnings("unused") @Shared @Cached PyBytesCheckNode checkBytes,
+ @Bind PythonLanguage language) {
+ return PFactory.createBytes(language, bytes);
}
@Specialization(guards = "!checkBytes.execute(inliningTarget, basedOn)")
- static PBytesLike bytearray(@SuppressWarnings("unused") Node inliningTarget, PythonObjectFactory factory, @SuppressWarnings("unused") Object basedOn, SequenceStorage bytes,
- @SuppressWarnings("unused") @Shared @Cached PyBytesCheckNode checkBytes) {
+ static PBytesLike bytearray(@SuppressWarnings("unused") Node inliningTarget, @SuppressWarnings("unused") Object basedOn, SequenceStorage bytes,
+ @SuppressWarnings("unused") @Shared @Cached PyBytesCheckNode checkBytes,
+ @Bind PythonLanguage language) {
assert PyByteArrayCheckNode.executeUncached(basedOn);
- return factory.createByteArray(bytes);
+ return PFactory.createByteArray(language, bytes);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
index ab5b24922a..f060fadafc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -86,7 +86,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils.PrototypeNodeFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -279,7 +279,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Ob
l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(ReadMemberNodeGen.create(type, offset, asPythonObjectNode)), true),
ReadMemberNode.class, BUILTIN.name(), type, offset);
int flags = PBuiltinFunction.getFlags(BUILTIN, callTarget);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, owner, 0, flags, callTarget);
+ return PFactory.createBuiltinFunction(language, propertyName, owner, 0, flags, callTarget);
}
}
@@ -305,7 +305,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(ReadOnlyMemberNodeGen.create(propertyName)), true),
ReadOnlyMemberNode.class, BUILTIN.name());
int flags = PBuiltinFunction.getFlags(BUILTIN, builtinCt);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, builtinCt);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, builtinCt);
}
}
@@ -329,7 +329,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(BadMemberDescrNodeGen.create()), true),
BadMemberDescrNode.class, BUILTIN.name());
int flags = PBuiltinFunction.getFlags(BUILTIN, builtinCt);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, builtinCt);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, builtinCt);
}
}
@@ -638,7 +638,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Ob
l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(WriteMemberNodeGen.create(type, offset)), true),
WriteMemberNode.class, BUILTIN.name(), type, offset);
int flags = PBuiltinFunction.getFlags(BUILTIN, callTarget);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, owner, 0, flags, callTarget);
+ return PFactory.createBuiltinFunction(language, propertyName, owner, 0, flags, callTarget);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
index 37563cd761..d875b2524b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
@@ -185,7 +185,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.graal.python.util.Function;
@@ -405,8 +405,8 @@ static PInt doBoolNativeWrapper(Node inliningTarget, PrimitiveNativeWrapper obje
@Specialization(guards = {"!isMaterialized(object)", "object.isInt()"})
static PInt doIntNativeWrapper(PrimitiveNativeWrapper object,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- PInt materializedInt = factory.createInt(object.getInt());
+ @Bind PythonLanguage language) {
+ PInt materializedInt = PFactory.createInt(language, object.getInt());
object.setMaterializedObject(materializedInt);
materializedInt.setNativeWrapper(object);
return materializedInt;
@@ -414,8 +414,8 @@ static PInt doIntNativeWrapper(PrimitiveNativeWrapper object,
@Specialization(guards = {"!isMaterialized(object)", "object.isLong()"})
static PInt doLongNativeWrapper(PrimitiveNativeWrapper object,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- PInt materializedInt = factory.createInt(object.getLong());
+ @Bind PythonLanguage language) {
+ PInt materializedInt = PFactory.createInt(language, object.getLong());
object.setMaterializedObject(materializedInt);
materializedInt.setNativeWrapper(object);
return materializedInt;
@@ -423,8 +423,8 @@ static PInt doLongNativeWrapper(PrimitiveNativeWrapper object,
@Specialization(guards = {"!isMaterialized(object)", "object.isDouble()", "!isNaN(object)"})
static PFloat doDoubleNativeWrapper(PrimitiveNativeWrapper object,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- PFloat materializedInt = factory.createFloat(object.getDouble());
+ @Bind PythonLanguage language) {
+ PFloat materializedInt = PFactory.createFloat(language, object.getDouble());
materializedInt.setNativeWrapper(object);
object.setMaterializedObject(materializedInt);
return materializedInt;
@@ -690,45 +690,45 @@ static PComplex doPComplex(PComplex value) {
@Specialization
static PComplex doBoolean(boolean value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value ? 1.0 : 0.0, 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value ? 1.0 : 0.0, 0.0);
}
@Specialization
static PComplex doInt(int value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value, 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value, 0.0);
}
@Specialization
static PComplex doLong(long value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value, 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value, 0.0);
}
@Specialization
PComplex doDouble(double value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value, 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value, 0.0);
}
@Specialization
static PComplex doPInt(PInt value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value.doubleValue(), 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value.doubleValue(), 0.0);
}
@Specialization
static PComplex doPFloat(PFloat value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(value.getValue(), 0.0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, value.getValue(), 0.0);
}
@Specialization(replaces = {"doPComplex", "doBoolean", "doInt", "doLong", "doDouble", "doPInt", "doPFloat"})
static PComplex runGeneric(Node inliningTarget, Object value,
@Cached PyFloatAsDoubleNode asDoubleNode,
@Cached(inline = false) LookupAndCallUnaryDynamicNode callComplex,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object result = callComplex.executeObject(value, T___COMPLEX__);
// TODO(fa) according to CPython's 'PyComplex_AsCComplex', they still allow subclasses
@@ -740,7 +740,7 @@ static PComplex runGeneric(Node inliningTarget, Object value,
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, value);
}
} else {
- return factory.createComplex(asDoubleNode.execute(null, inliningTarget, value), 0.0);
+ return PFactory.createComplex(language, asDoubleNode.execute(null, inliningTarget, value), 0.0);
}
}
}
@@ -1714,7 +1714,7 @@ public abstract static class CreateModuleNode extends MultiPhaseExtensionModuleI
@TruffleBoundary
static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object moduleDefWrapper, Object library,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached CStructAccess.ReadPointerNode readPointer,
@Cached CStructAccess.ReadI64Node readI64,
@CachedLibrary(limit = "3") InteropLibrary interopLib,
@@ -1815,7 +1815,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
((PythonModule) module).setNativeModuleDef(moduleDef);
}
} else {
- PythonModule pythonModule = factory.createPythonModule(mName);
+ PythonModule pythonModule = PFactory.createPythonModule(language, mName);
pythonModule.setNativeModuleDef(moduleDef);
module = pythonModule;
}
@@ -1827,7 +1827,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
if (fun == null) {
break;
}
- PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
+ PBuiltinMethod method = PFactory.createBuiltinMethod(language, module, fun);
writeAttrToMethodNode.execute(method, SpecialAttributeNames.T___MODULE__, mName);
writeAttrNode.execute(module, fun.getName(), method);
}
@@ -1954,7 +1954,7 @@ static PBuiltinFunction doIt(Node inliningTarget, Object methodDef, int element,
@Cached(inline = false) CStructAccess.ReadPointerNode readPointerNode,
@Cached(inline = false) CStructAccess.ReadI32Node readI32Node,
@Cached(inline = false) FromCharPointerNode fromCharPointerNode,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached EnsureExecutableNode ensureCallableNode,
@Cached HiddenAttr.WriteNode writeHiddenAttrNode,
@Cached(inline = false) WriteAttributeToPythonObjectNode writeAttributeToPythonObjectNode) {
@@ -1978,7 +1978,7 @@ static PBuiltinFunction doIt(Node inliningTarget, Object methodDef, int element,
RootCallTarget callTarget = PExternalFunctionWrapper.getOrCreateCallTarget(sig, PythonLanguage.get(inliningTarget), methodName, true, CExtContext.isMethStatic(flags));
mlMethObj = ensureCallableNode.execute(inliningTarget, mlMethObj, sig);
PKeyword[] kwDefaults = ExternalFunctionNodes.createKwDefaults(mlMethObj);
- PBuiltinFunction function = factory.createBuiltinFunction(methodName, null, PythonUtils.EMPTY_OBJECT_ARRAY, kwDefaults, flags, callTarget);
+ PBuiltinFunction function = PFactory.createBuiltinFunction(language, methodName, null, PythonUtils.EMPTY_OBJECT_ARRAY, kwDefaults, flags, callTarget);
writeHiddenAttrNode.execute(inliningTarget, function, METHOD_DEF_PTR, methodDef);
// write doc string; we need to directly write to the storage otherwise it is disallowed
@@ -2107,7 +2107,7 @@ static PythonObject doPythonCallable(TruffleString name, PythonNativeWrapper cal
}
doArgAndResultConversion = true;
}
- PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, managedCallable, type, flags, signature, language, context.factory(), doArgAndResultConversion);
+ PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, managedCallable, type, flags, signature, language, doArgAndResultConversion);
return function != null ? function : castToPythonObject(managedCallable);
}
@@ -2118,7 +2118,7 @@ static PBuiltinFunction doPyCFunctionWrapper(TruffleString name, PyCFunctionWrap
assert !(delegate instanceof PythonAbstractObject);
PythonContext context = PythonContext.get(null);
PythonLanguage language = context.getLanguage();
- return PExternalFunctionWrapper.createWrapperFunction(name, delegate, type, flags, signature, language, context.factory(), false);
+ return PExternalFunctionWrapper.createWrapperFunction(name, delegate, type, flags, signature, language, false);
}
@Specialization(guards = {"!isNativeWrapper(callable)"})
@@ -2167,7 +2167,7 @@ static PythonObject doNativeCallableWithWrapper(TruffleString name, Object calla
resolvedCallable = callable;
}
PythonLanguage language = context.getLanguage();
- PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, resolvedCallable, type, flags, signature, language, context.factory(), doArgAndResultConversion);
+ PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, resolvedCallable, type, flags, signature, language, doArgAndResultConversion);
return function != null ? function : castToPythonObject(resolvedCallable);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
index 18528ad4a6..6e118171d4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -126,7 +126,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
@@ -187,22 +187,6 @@ public static PKeyword[] createKwDefaults(Object callable, Object closure) {
return new PKeyword[]{new PKeyword(KW_CALLABLE, callable), new PKeyword(KW_CLOSURE, closure)};
}
- public static Object tryGetHiddenCallable(PBuiltinFunction function) {
- if (function.getFunctionRootNode() instanceof MethodDescriptorRoot) {
- return getHiddenCallable(function.getKwDefaults());
- }
- return null;
- }
-
- public static Object getHiddenCallable(PKeyword[] kwDefaults) {
- if (kwDefaults.length >= KEYWORDS_HIDDEN_CALLABLE.length) {
- PKeyword kwDefault = kwDefaults[0];
- assert KW_CALLABLE.equalsUncached(kwDefault.getName(), TS_ENCODING) : "invalid keyword defaults";
- return kwDefault.getValue();
- }
- throw CompilerDirectives.shouldNotReachHere();
- }
-
public abstract static class FinishArgNode extends PNodeWithContext {
public abstract void execute(Object value);
@@ -627,9 +611,9 @@ static RootCallTarget getOrCreateCallTarget(PExternalFunctionWrapper sig, Python
}
public static PBuiltinFunction createWrapperFunction(TruffleString name, Object callable, Object enclosingType, int flags, int sig,
- PythonLanguage language, PythonObjectFactory factory, boolean doArgAndResultConversion) {
+ PythonLanguage language, boolean doArgAndResultConversion) {
return createWrapperFunction(name, callable, enclosingType, flags, PExternalFunctionWrapper.fromValue(sig),
- language, factory, doArgAndResultConversion);
+ language, doArgAndResultConversion);
}
/**
@@ -644,14 +628,12 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
* {@link RootCallTarget}, and (3) a {@link BuiltinMethodDescriptor}.
* @param enclosingType The type the function belongs to (needed for checking of
* {@code self}).
- * @param factory Just an instance of {@link PythonObjectFactory} to create the function
- * object.
* @return A {@link PBuiltinFunction} implementing the semantics of the specified slot
* wrapper.
*/
@TruffleBoundary
public static PBuiltinFunction createWrapperFunction(TruffleString name, Object callable, Object enclosingType, int flags, PExternalFunctionWrapper sig, PythonLanguage language,
- PythonObjectFactory factory, boolean doArgAndResultConversion) {
+ boolean doArgAndResultConversion) {
LOGGER.finer(() -> PythonUtils.formatJString("ExternalFunctions.createWrapperFunction(%s, %s)", name, callable));
assert !isClosurePointer(PythonContext.get(null), callable, InteropLibrary.getUncached(callable));
if (flags < 0) {
@@ -718,24 +700,23 @@ public static PBuiltinFunction createWrapperFunction(TruffleString name, Object
case FASTCALL:
case FASTCALL_WITH_KEYWORDS:
case METHOD:
- return factory.createBuiltinFunction(name, type, defaults, kwDefaults, flags, callTarget);
+ return PFactory.createBuiltinFunction(language, name, type, defaults, kwDefaults, flags, callTarget);
}
- return factory.createWrapperDescriptor(name, type, defaults, kwDefaults, flags, callTarget, slot, sig);
+ return PFactory.createWrapperDescriptor(language, name, type, defaults, kwDefaults, flags, callTarget, slot, sig);
}
/**
- * {@link #createWrapperFunction(TruffleString, Object, Object, int, PExternalFunctionWrapper, PythonLanguage, PythonObjectFactory, boolean)}.
+ * {@link #createWrapperFunction(TruffleString, Object, Object, int, PExternalFunctionWrapper, PythonLanguage, boolean)}.
*/
@TruffleBoundary
- public static PBuiltinFunction createWrapperFunction(TruffleString name, TpSlotCExtNative slot, Object enclosingType, PExternalFunctionWrapper sig, PythonLanguage language,
- PythonObjectFactory factory) {
+ public static PBuiltinFunction createWrapperFunction(TruffleString name, TpSlotCExtNative slot, Object enclosingType, PExternalFunctionWrapper sig, PythonLanguage language) {
RootCallTarget callTarget = getOrCreateCallTarget(sig, language, name, true, false);
if (callTarget == null) {
return null;
}
var kwDefaults = ExternalFunctionNodes.createKwDefaults(slot.getCallable());
Object[] defaults = PBuiltinFunction.generateDefaults(sig.numDefaults);
- return factory.createWrapperDescriptor(name, enclosingType, defaults, kwDefaults, 0, callTarget, slot, sig);
+ return PFactory.createWrapperDescriptor(language, name, enclosingType, defaults, kwDefaults, 0, callTarget, slot, sig);
}
private static boolean isClosurePointer(PythonContext context, Object callable, InteropLibrary lib) {
@@ -1129,7 +1110,6 @@ protected final Object readSelf(VirtualFrame frame) {
public static final class MethKeywordsRoot extends MethodDescriptorRoot {
private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self"), true, true);
- @Child private PythonObjectFactory factory;
@Child private ReadVarArgsNode readVarargsNode;
@Child private ReadVarKeywordsNode readKwargsNode;
@Child private CreateArgsTupleNode createArgsTupleNode;
@@ -1143,7 +1123,6 @@ public MethKeywordsRoot(PythonLanguage language, TruffleString name, boolean isS
public MethKeywordsRoot(PythonLanguage language, TruffleString name, boolean isStatic, PExternalFunctionWrapper provider) {
super(language, name, isStatic, provider);
- this.factory = PythonObjectFactory.create();
this.readVarargsNode = ReadVarArgsNode.create(true);
this.readKwargsNode = ReadVarKeywordsNode.create(PythonUtils.EMPTY_TRUFFLESTRING_ARRAY);
this.createArgsTupleNode = CreateArgsTupleNodeGen.create();
@@ -1155,7 +1134,8 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
Object self = readSelf(frame);
Object[] args = readVarargsNode.executeObjectArray(frame);
PKeyword[] kwargs = readKwargsNode.executePKeyword(frame);
- return new Object[]{self, createArgsTupleNode.execute(factory, args, seenNativeArgsTupleStorage), factory.createDict(kwargs)};
+ PythonLanguage language = getLanguage(PythonLanguage.class);
+ return new Object[]{self, createArgsTupleNode.execute(language, args, seenNativeArgsTupleStorage), PFactory.createDict(language, kwargs)};
}
@Override
@@ -1177,7 +1157,6 @@ public Signature getSignature() {
public static final class MethVarargsRoot extends MethodDescriptorRoot {
private static final Signature SIGNATURE = createSignature(false, 1, tsArray("self"), true, true);
- @Child private PythonObjectFactory factory;
@Child private ReadVarArgsNode readVarargsNode;
@Child private CreateArgsTupleNode createArgsTupleNode;
@Child private ReleaseNativeSequenceStorageNode freeNode;
@@ -1190,7 +1169,6 @@ public MethVarargsRoot(PythonLanguage language, TruffleString name, boolean isSt
public MethVarargsRoot(PythonLanguage language, TruffleString name, boolean isStatic, PExternalFunctionWrapper provider) {
super(language, name, isStatic, provider);
- this.factory = PythonObjectFactory.create();
this.readVarargsNode = ReadVarArgsNode.create(true);
this.createArgsTupleNode = CreateArgsTupleNodeGen.create();
this.freeNode = ReleaseNativeSequenceStorageNodeGen.create();
@@ -1200,7 +1178,7 @@ public MethVarargsRoot(PythonLanguage language, TruffleString name, boolean isSt
protected Object[] prepareCArguments(VirtualFrame frame) {
Object self = readSelf(frame);
Object[] args = readVarargsNode.executeObjectArray(frame);
- return new Object[]{self, createArgsTupleNode.execute(factory, args, seenNativeArgsTupleStorage)};
+ return new Object[]{self, createArgsTupleNode.execute(getLanguage(PythonLanguage.class), args, seenNativeArgsTupleStorage)};
}
@Override
@@ -1358,7 +1336,6 @@ public Signature getSignature() {
public static final class MethFastcallWithKeywordsRoot extends MethodDescriptorRoot {
private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self"), true, true);
- @Child private PythonObjectFactory factory;
@Child private ReadVarArgsNode readVarargsNode;
@Child private ReadVarKeywordsNode readKwargsNode;
@@ -1368,7 +1345,6 @@ public MethFastcallWithKeywordsRoot(PythonLanguage language, TruffleString name,
public MethFastcallWithKeywordsRoot(PythonLanguage language, TruffleString name, boolean isStatic, PExternalFunctionWrapper provider) {
super(language, name, isStatic, provider);
- this.factory = PythonObjectFactory.create();
this.readVarargsNode = ReadVarArgsNode.create(true);
this.readKwargsNode = ReadVarKeywordsNode.create(PythonUtils.EMPTY_TRUFFLESTRING_ARRAY);
}
@@ -1388,7 +1364,7 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
fastcallKwnames[i] = kwargs[i].getName();
fastcallArgs[args.length + i] = kwargs[i].getValue();
}
- kwnamesTuple = factory.createTuple(fastcallKwnames);
+ kwnamesTuple = PFactory.createTuple(PythonLanguage.get(this), fastcallKwnames);
}
return new Object[]{self, new CPyObjectArrayWrapper(fastcallArgs), args.length, kwnamesTuple};
}
@@ -1410,7 +1386,6 @@ public Signature getSignature() {
public static final class MethMethodRoot extends MethodDescriptorRoot {
private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self", "cls"), true, true);
- @Child private PythonObjectFactory factory;
@Child private ReadIndexedArgumentNode readClsNode;
@Child private ReadVarArgsNode readVarargsNode;
@Child private ReadVarKeywordsNode readKwargsNode;
@@ -1421,7 +1396,6 @@ public MethMethodRoot(PythonLanguage language, TruffleString name, boolean isSta
public MethMethodRoot(PythonLanguage language, TruffleString name, boolean isStatic, PExternalFunctionWrapper provider) {
super(language, name, isStatic, provider);
- this.factory = PythonObjectFactory.create();
this.readClsNode = ReadIndexedArgumentNode.create(1);
this.readVarargsNode = ReadVarArgsNode.create(true);
this.readKwargsNode = ReadVarKeywordsNode.create(PythonUtils.EMPTY_TRUFFLESTRING_ARRAY);
@@ -1440,7 +1414,7 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
fastcallKwnames[i] = kwargs[i].getName();
fastcallArgs[args.length + i] = kwargs[i].getValue();
}
- return new Object[]{self, cls, new CPyObjectArrayWrapper(fastcallArgs), args.length, factory.createTuple(fastcallKwnames)};
+ return new Object[]{self, cls, new CPyObjectArrayWrapper(fastcallArgs), args.length, PFactory.createTuple(PythonLanguage.get(this), fastcallKwnames)};
}
@Override
@@ -2183,43 +2157,43 @@ private ReadIndexedArgumentNode ensureReadArgNode() {
*/
@GenerateInline(false)
abstract static class CreateArgsTupleNode extends Node {
- public abstract PTuple execute(PythonObjectFactory factory, Object[] args, boolean eagerNative);
+ public abstract PTuple execute(PythonLanguage language, Object[] args, boolean eagerNative);
@Specialization(guards = {"args.length == cachedLen", "cachedLen <= 8", "!eagerNative"}, limit = "1")
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL)
- static PTuple doCachedLen(PythonObjectFactory factory, Object[] args, @SuppressWarnings("unused") boolean eagerNative,
+ static PTuple doCachedLen(PythonLanguage language, Object[] args, @SuppressWarnings("unused") boolean eagerNative,
@Cached("args.length") int cachedLen,
@Cached("createMaterializeNodes(args.length)") MaterializePrimitiveNode[] materializePrimitiveNodes) {
for (int i = 0; i < cachedLen; i++) {
- args[i] = materializePrimitiveNodes[i].execute(factory, args[i]);
+ args[i] = materializePrimitiveNodes[i].execute(language, args[i]);
}
- return factory.createTuple(args);
+ return PFactory.createTuple(language, args);
}
@Specialization(guards = {"args.length == cachedLen", "cachedLen <= 8", "eagerNative"}, limit = "1", replaces = "doCachedLen")
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL)
- static PTuple doCachedLenEagerNative(PythonObjectFactory factory, Object[] args, @SuppressWarnings("unused") boolean eagerNative,
+ static PTuple doCachedLenEagerNative(PythonLanguage language, Object[] args, @SuppressWarnings("unused") boolean eagerNative,
@Bind("this") Node inliningTarget,
@Cached("args.length") int cachedLen,
@Cached("createMaterializeNodes(args.length)") MaterializePrimitiveNode[] materializePrimitiveNodes,
@Exclusive @Cached StorageToNativeNode storageToNativeNode) {
for (int i = 0; i < cachedLen; i++) {
- args[i] = materializePrimitiveNodes[i].execute(factory, args[i]);
+ args[i] = materializePrimitiveNodes[i].execute(language, args[i]);
}
- return factory.createTuple(storageToNativeNode.execute(inliningTarget, args, cachedLen, true));
+ return PFactory.createTuple(language, storageToNativeNode.execute(inliningTarget, args, cachedLen, true));
}
@Specialization(replaces = {"doCachedLen", "doCachedLenEagerNative"})
- static PTuple doGeneric(PythonObjectFactory factory, Object[] args, boolean eagerNative,
+ static PTuple doGeneric(PythonLanguage language, Object[] args, boolean eagerNative,
@Bind("this") Node inliningTarget,
@Cached MaterializePrimitiveNode materializePrimitiveNode,
@Exclusive @Cached StorageToNativeNode storageToNativeNode) {
int n = args.length;
for (int i = 0; i < n; i++) {
- args[i] = materializePrimitiveNode.execute(factory, args[i]);
+ args[i] = materializePrimitiveNode.execute(language, args[i]);
}
SequenceStorage storage;
if (eagerNative) {
@@ -2227,7 +2201,7 @@ static PTuple doGeneric(PythonObjectFactory factory, Object[] args, boolean eage
} else {
storage = new ObjectSequenceStorage(args);
}
- return factory.createTuple(storage);
+ return PFactory.createTuple(language, storage);
}
static MaterializePrimitiveNode[] createMaterializeNodes(int length) {
@@ -2237,14 +2211,6 @@ static MaterializePrimitiveNode[] createMaterializeNodes(int length) {
}
return materializePrimitiveNodes;
}
-
- static PythonToNativeNode[] createPythonToNativeNodes(int length) {
- PythonToNativeNode[] pythonToNativeNodes = new PythonToNativeNode[length];
- for (int i = 0; i < length; i++) {
- pythonToNativeNodes[i] = PythonToNativeNodeGen.create();
- }
- return pythonToNativeNodes;
- }
}
@GenerateInline(false)
@@ -2292,38 +2258,34 @@ static void doObjectGeneric(NativeObjectSequenceStorage storage,
@GenerateInline(false)
abstract static class MaterializePrimitiveNode extends Node {
- public abstract Object execute(PythonObjectFactory factory, Object object);
+ public abstract Object execute(PythonLanguage language, Object object);
// NOTE: Booleans don't need to be materialized because they are singletons.
@Specialization
- static PInt doInteger(PythonObjectFactory factory, int i) {
- return factory.createInt(i);
+ static PInt doInteger(PythonLanguage language, int i) {
+ return PFactory.createInt(language, i);
}
@Specialization(replaces = "doInteger")
- static PInt doLong(PythonObjectFactory factory, long l) {
- return factory.createInt(l);
+ static PInt doLong(PythonLanguage language, long l) {
+ return PFactory.createInt(language, l);
}
@Specialization
- static PFloat doDouble(PythonObjectFactory factory, double d) {
- return factory.createFloat(d);
+ static PFloat doDouble(PythonLanguage language, double d) {
+ return PFactory.createFloat(language, d);
}
@Specialization
- static PString doString(PythonObjectFactory factory, TruffleString s) {
- return factory.createString(s);
+ static PString doString(PythonLanguage language, TruffleString s) {
+ return PFactory.createString(language, s);
}
- @Specialization(guards = "!needsMaterialization(object)")
- static Object doObject(@SuppressWarnings("unused") PythonObjectFactory factory, Object object) {
+ @Fallback
+ static Object doObject(@SuppressWarnings("unused") PythonLanguage language, Object object) {
return object;
}
-
- static boolean needsMaterialization(Object object) {
- return object instanceof Integer || object instanceof Long || PGuards.isDouble(object) || object instanceof TruffleString;
- }
}
// roughly equivalent to _Py_CheckFunctionResult in Objects/call.c
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java
index aecabf4b00..cf70e5c5be 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -108,7 +109,7 @@ private static Object allocateCLayout(PythonThreadState threadState) {
PythonContext pythonContext = PythonContext.get(null);
PDict threadStateDict = threadState.getDict();
if (threadStateDict == null) {
- threadStateDict = pythonContext.factory().createDict();
+ threadStateDict = PFactory.createDict(pythonContext.getLanguage());
threadState.setDict(threadStateDict);
}
writePtrNode.write(ptr, CFields.PyThreadState__dict, toNative.execute(threadStateDict));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java
index 159a961e19..88dba50a3c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -61,6 +61,7 @@
import com.oracle.graal.python.lib.PyObjectSetAttr;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.strings.TruffleString;
@@ -118,7 +119,7 @@ public static PyCapsule initWrapper(PythonContext context, CApiContext capiConte
Object pointerObject = allocatePyDatetimeCAPI(datetimeModule);
- PyCapsule capsule = context.factory().createCapsuleJavaName(pointerObject, T_PYDATETIME_CAPSULE_NAME);
+ PyCapsule capsule = PFactory.createCapsuleJavaName(context.getLanguage(), pointerObject, T_PYDATETIME_CAPSULE_NAME);
PyObjectSetAttr.executeUncached(datetimeModule, T_DATETIME_CAPI, capsule);
assert PyObjectGetAttr.executeUncached(datetimeModule, T_DATETIME_CAPI) != context.getNativeNull();
return capsule;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index 3d2ffcb5fa..2be40e1b3d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -55,6 +55,7 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_vectorcall_offset;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_weaklistoffset;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.ctypes.StgDictObject;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -101,7 +102,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.strings.TruffleString;
@@ -204,7 +205,7 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem, boolean hea
GetTypeFlagsNode getTypeFlagsNode = GetTypeFlagsNodeGen.getUncached();
PythonContext ctx = PythonContext.get(null);
- PythonObjectFactory factory = ctx.factory();
+ PythonLanguage language = ctx.getLanguage();
Object nullValue = ctx.getNativeNull();
// make this object immortal
@@ -331,11 +332,11 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem, boolean hea
writePtrNode.write(mem, CFields.PyTypeObject__tp_free, lookup(clazz, PyTypeObject__tp_free, HiddenAttr.FREE));
writePtrNode.write(mem, CFields.PyTypeObject__tp_clear, lookup(clazz, PyTypeObject__tp_clear, HiddenAttr.CLEAR));
if (clazz.basesTuple == null) {
- clazz.basesTuple = factory.createTuple(GetBaseClassesNode.executeUncached(clazz));
+ clazz.basesTuple = PFactory.createTuple(language, GetBaseClassesNode.executeUncached(clazz));
}
writePtrNode.write(mem, CFields.PyTypeObject__tp_bases, toNative.execute(clazz.basesTuple));
if (clazz.mroStore == null) {
- clazz.mroStore = factory.createTuple(GetMroStorageNode.executeUncached(clazz));
+ clazz.mroStore = PFactory.createTuple(language, GetMroStorageNode.executeUncached(clazz));
}
writePtrNode.write(mem, CFields.PyTypeObject__tp_mro, toNative.execute(clazz.mroStore));
writePtrNode.write(mem, CFields.PyTypeObject__tp_cache, nullValue);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/UnicodeObjectNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/UnicodeObjectNodes.java
index b1437841b9..5e6d3be1bf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/UnicodeObjectNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/UnicodeObjectNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,10 +42,11 @@
import java.nio.ByteOrder;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.builtins.objects.str.StringNodes.StringMaterializeNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -93,7 +94,7 @@ static PBytes doUnicode(TruffleString s, long elementSize, ByteOrder byteOrder)
} else {
throw new RuntimeException("unsupported wchar size; was: " + elementSize);
}
- return PythonObjectFactory.getUncached().createBytes(getBytes(s, encoding));
+ return PFactory.createBytes(PythonLanguage.get(null), getBytes(s, encoding));
}
private static byte[] getBytes(TruffleString s, TruffleString.Encoding encoding) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
index 5e86231f34..b2c0b9a338 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -104,7 +104,7 @@
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage.StorageType;
@@ -566,7 +566,7 @@ private static void processPyCapsuleReference(PyCapsuleReference reference) {
LOGGER.fine(() -> PythonUtils.formatJString("releasing %s", reference.toString()));
if (reference.data.getDestructor() != null) {
// Our capsule is dead, so create a temporary copy that doesn't have a reference anymore
- PyCapsule capsule = PythonObjectFactory.getUncached().createCapsule(reference.data);
+ PyCapsule capsule = PFactory.createCapsule(PythonLanguage.get(null), reference.data);
PCallCapiFunction.callUncached(NativeCAPISymbol.FUN_PY_TRUFFLE_CAPSULE_CALL_DESTRUCTOR, PythonToNativeNode.executeUncached(capsule), capsule.getDestructor());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/GetNativeWrapperNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/GetNativeWrapperNode.java
index 5e40dfd0f5..61b8ee5b88 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/GetNativeWrapperNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/GetNativeWrapperNode.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.cext.capi.transitions;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -61,7 +62,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -88,9 +89,9 @@ public static PythonNativeWrapper executeUncached(Object value) {
@Specialization
static PythonAbstractObjectNativeWrapper doString(TruffleString str,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached InlinedConditionProfile noWrapperProfile) {
- return PythonObjectNativeWrapper.wrap(factory.createString(str), inliningTarget, noWrapperProfile);
+ return PythonObjectNativeWrapper.wrap(PFactory.createString(language, str), inliningTarget, noWrapperProfile);
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
index 738bcc3494..06659c2b69 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
@@ -105,7 +105,7 @@
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.exception.PythonExitException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CallTarget;
@@ -610,9 +610,10 @@ private static PException raiseNullButNoError(Node node, TruffleString name, Tru
@TruffleBoundary
private static PException raiseResultWithError(Node node, TruffleString name, AbstractTruffleException currentException, TruffleString resultWithErrorMessage) {
- PBaseException sysExc = PythonObjectFactory.getUncached().createBaseException(SystemError, resultWithErrorMessage, new Object[]{name});
+ PythonLanguage language = PythonLanguage.get(null);
+ PBaseException sysExc = PFactory.createBaseException(language, SystemError, resultWithErrorMessage, new Object[]{name});
sysExc.setCause(GetEscapedExceptionNode.executeUncached(currentException));
- throw PRaiseNode.raiseExceptionObject(node, sysExc, PythonOptions.isPExceptionWithJavaStacktrace(PythonLanguage.get(null)));
+ throw PRaiseNode.raiseExceptionObject(node, sysExc, PythonOptions.isPExceptionWithJavaStacktrace(language));
}
}
@@ -1125,29 +1126,8 @@ static long doUnsignedLongPositive(long n) {
@Specialization(guards = "n < 0")
static Object doUnsignedLongNegative(long n,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createInt(PInt.longToUnsignedBigInteger(n));
- }
-
- @Specialization(replaces = {"doUnsignedIntPositive", "doUnsignedInt", "doUnsignedLongPositive", "doUnsignedLongNegative"})
- static Object doGeneric(Object n,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- if (n instanceof Integer) {
- int i = (int) n;
- if (i >= 0) {
- return i;
- } else {
- return doUnsignedInt(i);
- }
- } else if (n instanceof Long) {
- long l = (long) n;
- if (l >= 0) {
- return l;
- } else {
- return doUnsignedLongNegative(l, factory);
- }
- }
- throw CompilerDirectives.shouldNotReachHere();
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, PInt.longToUnsignedBigInteger(n));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java
index 84a7b7b4fa..31306784eb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.io.IOException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ImportException;
import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes;
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
@@ -58,7 +59,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -211,7 +212,7 @@ protected static PException reportImportError(RuntimeException e, TruffleString
@TruffleBoundary
public static PException wrapJavaException(Throwable e, Node raisingNode) {
TruffleString message = toTruffleStringUncached(e.getMessage());
- PBaseException excObject = PythonObjectFactory.getUncached().createBaseException(SystemError, message != null ? message : toTruffleStringUncached(e.toString()),
+ PBaseException excObject = PFactory.createBaseException(PythonLanguage.get(null), SystemError, message != null ? message : toTruffleStringUncached(e.toString()),
PythonUtils.EMPTY_OBJECT_ARRAY);
return ExceptionUtils.wrapJavaException(e, raisingNode, excObject);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
index 5be72a0746..0fdb508249 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
@@ -95,6 +95,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.PythonOptions.HPyBackendMode;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonSystemThreadTask;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
@@ -532,7 +533,7 @@ public void doRun() {
PythonLanguage language = pythonContext.getLanguage();
GraalHPyContext hPyContext = pythonContext.getHPyContext();
RootCallTarget callTarget = hPyContext.getReferenceCleanerCallTarget();
- PDict dummyGlobals = pythonContext.factory().createDict();
+ PDict dummyGlobals = PFactory.createDict(language);
boolean isLoggable = LOGGER.isLoggable(Level.FINE);
/*
* Intentionally retrieve the thread state every time since this will kill the thread if
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
index d988655d42..1927550d25 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
@@ -302,6 +302,7 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
import com.oracle.graal.python.lib.PyCallableCheckNode;
@@ -358,7 +359,7 @@
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.graal.python.util.CharsetMapping;
@@ -382,6 +383,7 @@
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.profiles.InlinedExactClassProfile;
@@ -1380,9 +1382,9 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ar
public abstract static class GraalHPyDictNew extends HPyUnaryContextFunction {
@Specialization
- static Object doGeneric(@SuppressWarnings("unused") Object hpyContext,
- @Cached PythonObjectFactory factory) {
- return factory.createDict();
+ static Object doGeneric(GraalHPyContext hpyContext,
+ @Bind("this") Node inliningTarget) {
+ return PFactory.createDict(hpyContext.getContext().getLanguage(inliningTarget));
}
}
@@ -1391,14 +1393,14 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext,
public abstract static class GraalHPyListNew extends HPyBinaryContextFunction {
@Specialization
- static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, long len,
- @Cached PythonObjectFactory factory,
+ static Object doGeneric(GraalHPyContext hpyContext, long len,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
try {
Object[] data = new Object[PInt.intValueExact(len)];
// TODO(fa) maybe this should be NO_VALUE (representing native 'NULL')
Arrays.fill(data, PNone.NONE);
- return factory.createList(data);
+ return PFactory.createList(hpyContext.getContext().getLanguage(inliningTarget), data);
} catch (OverflowException e) {
throw raiseNode.raise(PythonBuiltinClassType.MemoryError);
}
@@ -1769,10 +1771,10 @@ static Object doGeneric(GraalHPyContext hpyContext, Object object,
public abstract static class GraalHPyUnicodeAsUTF8String extends HPyBinaryContextFunction {
@Specialization
- static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object unicodeObject,
- @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeNativeStringNode.execute(StandardCharsets.UTF_8, unicodeObject, T_STRICT));
+ static PBytes doGeneric(GraalHPyContext hpyContext, Object unicodeObject,
+ @Bind("this") Node inliningTarget,
+ @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), encodeNativeStringNode.execute(StandardCharsets.UTF_8, unicodeObject, T_STRICT));
}
}
@@ -1781,10 +1783,10 @@ static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object un
public abstract static class GraalHPyUnicodeAsLatin1String extends HPyBinaryContextFunction {
@Specialization
- static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object unicodeObject,
- @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeNativeStringNode.execute(StandardCharsets.ISO_8859_1, unicodeObject, T_STRICT));
+ static PBytes doGeneric(GraalHPyContext hpyContext, Object unicodeObject,
+ @Bind("this") Node inliningTarget,
+ @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), encodeNativeStringNode.execute(StandardCharsets.ISO_8859_1, unicodeObject, T_STRICT));
}
}
@@ -1793,10 +1795,10 @@ static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object un
public abstract static class GraalHPyUnicodeAsASCIIString extends HPyBinaryContextFunction {
@Specialization
- static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object unicodeObject,
- @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeNativeStringNode.execute(StandardCharsets.US_ASCII, unicodeObject, T_STRICT));
+ static PBytes doGeneric(GraalHPyContext hpyContext, Object unicodeObject,
+ @Bind("this") Node inliningTarget,
+ @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), encodeNativeStringNode.execute(StandardCharsets.US_ASCII, unicodeObject, T_STRICT));
}
}
@@ -1804,10 +1806,10 @@ static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object un
@GenerateUncached
public abstract static class GraalHPyUnicodeEncodeFSDefault extends HPyBinaryContextFunction {
@Specialization
- static PBytes doGeneric(@SuppressWarnings("unused") Object hpyContext, Object unicodeObject,
- @Cached EncodeNativeStringNode encodeNativeStringNode,
- @Cached PythonObjectFactory factory) {
- return factory.createBytes(encodeNativeStringNode.execute(getFSDefaultCharset(), unicodeObject, T_STRICT));
+ static PBytes doGeneric(GraalHPyContext hpyContext, Object unicodeObject,
+ @Bind("this") Node inliningTarget,
+ @Cached EncodeNativeStringNode encodeNativeStringNode) {
+ return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), encodeNativeStringNode.execute(getFSDefaultCharset(), unicodeObject, T_STRICT));
}
@TruffleBoundary
@@ -2037,8 +2039,7 @@ static PBytes doGeneric(GraalHPyContext hpyContext, Object charPtr,
@Cached CastToJavaIntExactNode castToJavaIntNode,
@Cached(parameters = "hpyContext") HPyCallHelperFunctionNode callHelperNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.ReadI8ArrayNode readI8ArrayNode,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
int size;
try {
size = castToJavaIntNode.execute(inliningTarget, callHelperNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_STRLEN, charPtr));
@@ -2046,7 +2047,7 @@ static PBytes doGeneric(GraalHPyContext hpyContext, Object charPtr,
throw raiseNode.raise(OverflowError, ErrorMessages.BYTE_STR_IS_TOO_LARGE);
}
byte[] bytes = readI8ArrayNode.execute(hpyContext, charPtr, 0, size);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), bytes);
}
}
@@ -2056,21 +2057,22 @@ public abstract static class GraalHPyBytesFromStringAndSize extends HPyTernaryCo
@Specialization
static PBytes doGeneric(GraalHPyContext hpyContext, Object charPtr, long lsize,
+ @Bind("this") Node inliningTarget,
@Cached(parameters = "hpyContext") GraalHPyCAccess.IsNullNode isNullNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.ReadI8ArrayNode readI8ArrayNode,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
if (isNullNode.execute(hpyContext, charPtr)) {
throw raiseNode.raise(ValueError, ErrorMessages.NULL_CHAR_PASSED);
}
if (lsize < 0) {
throw raiseNode.raise(SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
}
+ PythonLanguage language = hpyContext.getContext().getLanguage(inliningTarget);
if (lsize == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
byte[] bytes = readI8ArrayNode.execute(hpyContext, charPtr, 0, lsize);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
}
@@ -2300,7 +2302,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object type, Object dataOutV
@Bind("this") Node inliningTarget,
@Cached IsTypeNode isTypeNode,
@Cached PRaiseNode.Lazy raiseNode,
- @Cached PythonObjectFactory factory,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(parameters = "hpyContext") GraalHPyCAccess.AllocateNode allocateNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.WritePointerNode writePointerNode,
@Cached InlinedExactClassProfile classProfile) {
@@ -2335,7 +2337,8 @@ static Object doGeneric(GraalHPyContext hpyContext, Object type, Object dataOutV
}
int builtinShape = GraalHPyDef.getBuiltinShapeFromHiddenAttribute(profiledTypeObject);
- PythonObject pythonObject = createFromBuiltinShape(builtinShape, profiledTypeObject, dataPtr, factory);
+ PythonLanguage language = hpyContext.getContext().getLanguage(inliningTarget);
+ PythonObject pythonObject = createFromBuiltinShape(builtinShape, profiledTypeObject, dataPtr, language, getInstanceShape);
if (destroyFunc != null) {
hpyContext.createHandleReference(pythonObject, dataPtr, destroyFunc != PNone.NO_VALUE ? destroyFunc : null);
@@ -2347,15 +2350,16 @@ static Object doGeneric(GraalHPyContext hpyContext, Object type, Object dataOutV
return pythonObject;
}
- static PythonObject createFromBuiltinShape(int builtinShape, Object type, Object dataPtr, PythonObjectFactory factory) {
+ static PythonObject createFromBuiltinShape(int builtinShape, Object type, Object dataPtr, PythonLanguage language, TypeNodes.GetInstanceShape getInstanceShape) {
+ Shape shape = getInstanceShape.execute(type);
PythonObject result = switch (builtinShape) {
- case HPyType_BUILTIN_SHAPE_LEGACY, HPyType_BUILTIN_SHAPE_OBJECT -> factory.createPythonHPyObject(type, dataPtr);
+ case HPyType_BUILTIN_SHAPE_LEGACY, HPyType_BUILTIN_SHAPE_OBJECT -> PFactory.createPythonHPyObject(language, type, shape, dataPtr);
case HPyType_BUILTIN_SHAPE_TYPE -> throw CompilerDirectives.shouldNotReachHere("built-in shape type not yet implemented");
- case HPyType_BUILTIN_SHAPE_LONG -> factory.createInt(type, BigInteger.ZERO);
- case HPyType_BUILTIN_SHAPE_FLOAT -> factory.createFloat(type, 0.0);
- case HPyType_BUILTIN_SHAPE_UNICODE -> factory.createString(type, T_EMPTY_STRING);
- case HPyType_BUILTIN_SHAPE_TUPLE -> factory.createEmptyTuple(type);
- case HPyType_BUILTIN_SHAPE_LIST -> factory.createList(type);
+ case HPyType_BUILTIN_SHAPE_LONG -> PFactory.createInt(language, type, shape, BigInteger.ZERO);
+ case HPyType_BUILTIN_SHAPE_FLOAT -> PFactory.createFloat(language, type, shape, 0.0);
+ case HPyType_BUILTIN_SHAPE_UNICODE -> PFactory.createString(language, type, shape, T_EMPTY_STRING);
+ case HPyType_BUILTIN_SHAPE_TUPLE -> PFactory.createEmptyTuple(language, type, shape);
+ case HPyType_BUILTIN_SHAPE_LIST -> PFactory.createList(language, type, shape);
default -> throw CompilerDirectives.shouldNotReachHere(INVALID_BUILT_IN_SHAPE);
};
if (builtinShape != HPyType_BUILTIN_SHAPE_LEGACY && builtinShape != HPyType_BUILTIN_SHAPE_OBJECT) {
@@ -2395,7 +2399,7 @@ public abstract static class GraalHPyTypeGenericNew extends HPy5ContextFunction
@SuppressWarnings("unused")
static Object doGeneric(GraalHPyContext hpyContext, Object type, Object args, long nargs, Object kw,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(parameters = "hpyContext") GraalHPyCAccess.AllocateNode allocateNode,
@Cached InlinedExactClassProfile classProfile) {
@@ -2418,7 +2422,8 @@ static Object doGeneric(GraalHPyContext hpyContext, Object type, Object args, lo
}
int builtinShape = GraalHPyDef.getBuiltinShapeFromHiddenAttribute(profiledTypeObject);
- PythonObject pythonObject = GraalHPyNew.createFromBuiltinShape(builtinShape, type, dataPtr, factory);
+ PythonLanguage language = hpyContext.getContext().getLanguage(inliningTarget);
+ PythonObject pythonObject = GraalHPyNew.createFromBuiltinShape(builtinShape, type, dataPtr, language, getInstanceShape);
if (destroyFunc != null) {
hpyContext.createHandleReference(pythonObject, dataPtr, destroyFunc != PNone.NO_VALUE ? destroyFunc : null);
@@ -2607,8 +2612,7 @@ public abstract static class GraalHPyTupleFromArray extends HPyTernaryContextFun
static Object doGeneric(GraalHPyContext hpyContext, Object arrayPtr, long nelements,
@Bind("this") Node inliningTarget,
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
- @Cached(parameters = "hpyContext") GraalHPyCAccess.ReadHPyArrayNode readHPyArrayNode,
- @Cached PythonObjectFactory factory) {
+ @Cached(parameters = "hpyContext") GraalHPyCAccess.ReadHPyArrayNode readHPyArrayNode) {
int n;
try {
n = castToJavaIntExactNode.execute(inliningTarget, nelements);
@@ -2618,7 +2622,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object arrayPtr, long neleme
}
Object[] elements = readHPyArrayNode.execute(hpyContext, arrayPtr, 0, n);
- return factory.createTuple(elements);
+ return PFactory.createTuple(hpyContext.getContext().getLanguage(inliningTarget), elements);
}
}
@@ -2677,10 +2681,9 @@ boolean isTupleBuilder() {
}
@Specialization
- Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object builderHandle,
+ Object doGeneric(GraalHPyContext hpyContext, Object builderHandle,
@Bind("this") Node inliningTarget,
- @Cached HPyCloseAndGetHandleNode closeAndGetHandleNode,
- @Cached PythonObjectFactory factory) {
+ @Cached HPyCloseAndGetHandleNode closeAndGetHandleNode) {
ObjectSequenceStorage builder = cast(closeAndGetHandleNode.execute(inliningTarget, builderHandle));
if (builder == null) {
/*
@@ -2689,7 +2692,8 @@ Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object builderHa
*/
throw CompilerDirectives.shouldNotReachHere("invalid builder object");
}
- return isTupleBuilder() ? factory.createTuple(builder) : factory.createList(builder);
+ PythonLanguage language = hpyContext.getContext().getLanguage(inliningTarget);
+ return isTupleBuilder() ? PFactory.createTuple(language, builder) : PFactory.createList(language, builder);
}
static ObjectSequenceStorage cast(Object object) {
@@ -3039,8 +3043,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object namePtr, Object docPt
@Cached HashingStorageGetItem getHashingStorageItem,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached CallNode callTypeConstructorNode,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
TruffleString doc;
if (!isNullNode.execute(hpyContext, docPtr)) {
doc = fromCharPointerNode.execute(docPtr);
@@ -3049,7 +3052,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object namePtr, Object docPt
}
return createNewExceptionWithDoc(inliningTarget, namePtr, base, dictObj, doc, fromCharPointerNode, indexOfCodepointNode, codepointLengthNode, substringNode,
getHashingStorageItem,
- setHashingStorageItem, callTypeConstructorNode, raiseNode, factory);
+ setHashingStorageItem, callTypeConstructorNode, raiseNode);
}
static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Object base, Object dictObj, TruffleString doc,
@@ -3060,8 +3063,7 @@ static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Obj
HashingStorageGetItem getHashingStorageItem,
HashingStorageSetItem setHashingStorageItem,
CallNode callTypeConstructorNode,
- PRaiseNode raiseNode,
- PythonObjectFactory factory) {
+ PRaiseNode raiseNode) {
TruffleString name = fromCharPointerNode.execute(namePtr);
int len = codepointLengthNode.execute(name, TS_ENCODING);
@@ -3073,11 +3075,12 @@ static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Obj
if (base == PNone.NO_VALUE) {
base = PythonBuiltinClassType.Exception;
}
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
PDict dict;
HashingStorage dictStorage;
if (dictObj == PNone.NO_VALUE) {
dictStorage = new DynamicObjectStorage(PythonLanguage.get(inliningTarget));
- dict = factory.createDict(dictStorage);
+ dict = PFactory.createDict(language, dictStorage);
} else {
if (!(dictObj instanceof PDict)) {
/*
@@ -3102,7 +3105,7 @@ static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Obj
if (base instanceof PTuple) {
bases = (PTuple) base;
} else {
- bases = factory.createTuple(new Object[]{base});
+ bases = PFactory.createTuple(language, new Object[]{base});
}
return callTypeConstructorNode.executeWithoutFrame(PythonBuiltinClassType.PythonClass, substringNode.execute(name, dotIdx + 1, len - dotIdx - 1, TS_ENCODING, false), bases, dict);
@@ -3123,11 +3126,10 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object na
@Cached HashingStorageGetItem getHashingStorageItem,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached CallNode callTypeConstructorNode,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
return GraalHPyNewExceptionWithDoc.createNewExceptionWithDoc(inliningTarget, namePtr, base, dictObj, null, fromCharPointerNode, indexOfCodepointNode,
codepointLengthNode,
- substringNode, getHashingStorageItem, setHashingStorageItem, callTypeConstructorNode, raiseNode, factory);
+ substringNode, getHashingStorageItem, setHashingStorageItem, callTypeConstructorNode, raiseNode);
}
}
@@ -3343,13 +3345,12 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object di
@GenerateUncached
public abstract static class GraalHPyDictCopy extends HPyBinaryContextFunction {
@Specialization
- static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object dictObj,
+ static Object doGeneric(GraalHPyContext hpyContext, Object dictObj,
@Bind("this") Node inliningTarget,
@Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (dictObj instanceof PDict dict) {
- return factory.createDict(copyNode.execute(inliningTarget, dict.getDictStorage()));
+ return PFactory.createDict(hpyContext.getContext().getLanguage(inliningTarget), copyNode.execute(inliningTarget, dict.getDictStorage()));
}
throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
@@ -3369,9 +3370,9 @@ public abstract static class GraalHPyCapsuleNew extends HPyQuaternaryContextFunc
@Specialization
static PyCapsule doGeneric(GraalHPyContext hpyContext, Object pointer, Object namePtr, Object dtorPtr,
+ @Bind("this") Node inliningTarget,
@Cached(parameters = "hpyContext") GraalHPyCAccess.ReadPointerNode readPointerNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.IsNullNode isNullNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode raiseNode) {
if (isNullNode.execute(hpyContext, pointer)) {
throw raiseNode.raise(ValueError, ErrorMessages.HPYCAPSULE_NEW_NULL_PTR_ERROR);
@@ -3384,7 +3385,7 @@ static PyCapsule doGeneric(GraalHPyContext hpyContext, Object pointer, Object na
throw raiseNode.raise(ValueError, ErrorMessages.INVALID_HPYCAPSULE_DESTRUCTOR);
}
}
- PyCapsule capsule = factory.createCapsuleNativeName(pointer, namePtr);
+ PyCapsule capsule = PFactory.createCapsuleNativeName(hpyContext.getContext().getLanguage(inliningTarget), pointer, namePtr);
if (hpyDestructor != null) {
capsule.registerDestructor(hpyDestructor);
}
@@ -3533,8 +3534,7 @@ public abstract static class GraalHPyContextVarSet extends HPyTernaryContextFunc
@Specialization
static Object doGeneric(GraalHPyContext hpyContext, Object var, Object val,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PRaiseNode raiseNode) {
if (!(var instanceof PContextVar contextVar)) {
throw raiseNode.raise(TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
}
@@ -3542,7 +3542,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object var, Object val,
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
Object oldValue = contextVar.getValue(threadState);
contextVar.setValue(threadState, val);
- return factory.createContextVarsToken(contextVar, oldValue);
+ return PFactory.createContextVarsToken(hpyContext.getContext().getLanguage(inliningTarget), contextVar, oldValue);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
index c14fca967e..de9a964821 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -107,7 +107,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectExactProfile;
import com.oracle.graal.python.nodes.object.IsNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils.PrototypeNodeFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -326,7 +326,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
l -> new BuiltinFunctionRootNode(l, builtin, new PrototypeNodeFactory<>(HPyReadMemberNodeGen.create(offset, type, asPythonObjectNode)), true),
HPyReadMemberNode.class, builtin.name(), type, offset);
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, callTarget);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, callTarget);
}
}
@@ -351,7 +351,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
RootCallTarget builtinCt = language.createCachedCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, new PrototypeNodeFactory<>(HPyReadOnlyMemberNodeGen.create(propertyName)), true),
HPyReadOnlyMemberNode.class, builtin.name());
int flags = PBuiltinFunction.getFlags(builtin, builtinCt);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, builtinCt);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, builtinCt);
}
}
@@ -374,7 +374,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
RootCallTarget builtinCt = language.createCachedCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, new PrototypeNodeFactory<>(HPyBadMemberDescrNodeGen.create()), true),
HPyBadMemberDescrNode.class, builtin.name());
int flags = PBuiltinFunction.getFlags(builtin, builtinCt);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, builtinCt);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, builtinCt);
}
}
@@ -641,7 +641,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Tr
l -> new BuiltinFunctionRootNode(l, builtin, new PrototypeNodeFactory<>(HPyWriteMemberNodeGen.create(type, offset)), true),
HPyWriteMemberNode.class, builtin.name(), type, offset);
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
- return PythonObjectFactory.getUncached().createBuiltinFunction(propertyName, null, 0, flags, callTarget);
+ return PFactory.createBuiltinFunction(language, propertyName, null, 0, flags, callTarget);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
index 7575f0d193..9de14d1240 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import java.io.IOException;
import java.io.PrintStream;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ApiInitException;
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ImportException;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyCAccess.AllocateNode;
@@ -86,6 +87,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.interop.ArityException;
@@ -222,11 +224,11 @@ public static PException checkThrowableBeforeNative(Throwable t, String where1,
CompilerDirectives.transferToInterpreter();
PythonContext context = PythonContext.get(null);
context.ensureGilAfterFailure();
- PBaseException newException = context.factory().createBaseException(RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, EMPTY_OBJECT_ARRAY);
+ PBaseException newException = PFactory.createBaseException(context.getLanguage(), RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, EMPTY_OBJECT_ARRAY);
throw ExceptionUtils.wrapJavaException(soe, null, newException);
}
if (t instanceof OutOfMemoryError oome) {
- PBaseException newException = PythonContext.get(null).factory().createBaseException(MemoryError);
+ PBaseException newException = PFactory.createBaseException(PythonLanguage.get(null), MemoryError);
throw ExceptionUtils.wrapJavaException(oome, null, newException);
}
// everything else: log and convert to PException (SystemError)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
index 30eb5a37ce..fbf5f3b277 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
@@ -156,7 +156,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
@@ -397,7 +397,6 @@ public abstract static class GraalHPyModuleCreate extends Node {
@Specialization
static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spec, Object moduleDefPtr,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
@Cached(parameters = "context") GraalHPyCAccess.ReadPointerNode readPointerNode,
@Cached(parameters = "context") GraalHPyCAccess.IsNullNode isNullNode,
@Cached(parameters = "context") GraalHPyCAccess.ReadGenericNode readGenericNode,
@@ -413,6 +412,8 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
@CachedLibrary(limit = "1") InteropLibrary createLib,
@Cached PRaiseNode raiseNode) {
+ PythonLanguage language = context.getContext().getLanguage();
+
TruffleString mDoc;
long size;
Object docPtr = readPointerNode.read(context, moduleDefPtr, GraalHPyCField.HPyModuleDef__doc);
@@ -509,7 +510,7 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
throw raiseNode.raise(SystemError, ErrorMessages.HPY_MOD_CREATE_RETURNED_BUILTIN_MOD);
}
} else {
- PythonModule pmodule = factory.createPythonModule(mName);
+ PythonModule pmodule = PFactory.createPythonModule(language, mName);
pmodule.setNativeModuleDef(executeSlots);
module = pmodule;
}
@@ -517,7 +518,7 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
// process HPy methods
for (Object methodDef : methodDefs) {
PBuiltinFunction fun = addFunctionNode.execute(context, null, methodDef);
- PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
+ PBuiltinMethod method = PFactory.createBuiltinMethod(language, module, fun);
writeAttrToMethodNode.execute(method, SpecialAttributeNames.T___MODULE__, mName);
writeAttrNode.execute(module, fun.getName(), method);
}
@@ -529,7 +530,7 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
if (fun == null) {
break;
}
- PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
+ PBuiltinMethod method = PFactory.createBuiltinMethod(language, module, fun);
writeAttrToMethodNode.execute(method, SpecialAttributeNames.T___MODULE__, mName);
writeAttrNode.execute(module, fun.getName(), method);
}
@@ -671,7 +672,6 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object enclosingType, Obje
@Cached(parameters = "context") GraalHPyCAccess.ReadGenericNode readGenericNode,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached HPyAttachFunctionTypeNode attachFunctionTypeNode,
- @Cached PythonObjectFactory factory,
@Cached WriteAttributeToPythonObjectNode writeAttributeToPythonObjectNode,
@Cached PRaiseNode raiseNode) {
@@ -695,7 +695,7 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object enclosingType, Obje
methodFunctionPointer = attachFunctionTypeNode.execute(context, methodFunctionPointer, signature.getLLVMFunctionType());
PythonLanguage language = context.getContext().getLanguage(inliningTarget);
- PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(language, context, signature, methodName, methodFunctionPointer, enclosingType, factory);
+ PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(language, context, signature, methodName, methodFunctionPointer, enclosingType);
// write doc string; we need to directly write to the storage otherwise it is
// disallowed writing to builtin types.
@@ -730,10 +730,8 @@ static GetSetDescriptor doGeneric(GraalHPyContext context, Object owner, Object
@Cached(parameters = "context") GraalHPyCAccess.ReadPointerNode readPointerNode,
@Cached(parameters = "context") GraalHPyCAccess.IsNullNode isNullNode,
@Cached FromCharPointerNode fromCharPointerNode,
- @Cached PythonObjectFactory factory,
@Cached EnsureExecutableNode ensureExecutableNode,
- @Cached WriteAttributeToPythonObjectNode writeDocNode,
- @Cached PRaiseNode raiseNode) {
+ @Cached WriteAttributeToPythonObjectNode writeDocNode) {
// compute offset of name and read name pointer
long nameOffset = GraalHPyCAccess.ReadPointerNode.getElementPtr(context, i, HPyContextSignatureType.PyGetSetDef, GraalHPyCField.PyGetSetDef__name);
@@ -766,21 +764,22 @@ static GetSetDescriptor doGeneric(GraalHPyContext context, Object owner, Object
*/
Object closurePtr = context.nativeToInteropPointer(readPointerNode.execute(context, legacyGetSetDef, closureOffset));
- PythonLanguage lang = context.getContext().getLanguage(inliningTarget);
+ PythonLanguage language = context.getContext().getLanguage(inliningTarget);
PBuiltinFunction getterObject = null;
if (!isNullNode.execute(context, getterFunPtr)) {
Object getterFunInteropPtr = ensureExecutableNode.execute(inliningTarget, context.nativeToInteropPointer(getterFunPtr), PExternalFunctionWrapper.GETTER);
- getterObject = HPyLegacyGetSetDescriptorGetterRoot.createLegacyFunction(context, lang, owner, getSetDescrName, getterFunInteropPtr, closurePtr);
+ getterObject = HPyLegacyGetSetDescriptorGetterRoot.createLegacyFunction(language, owner, getSetDescrName, getterFunInteropPtr, closurePtr);
}
PBuiltinFunction setterObject = null;
boolean hasSetter = !isNullNode.execute(context, setterFunPtr);
if (hasSetter) {
Object setterFunInteropPtr = ensureExecutableNode.execute(inliningTarget, context.nativeToInteropPointer(setterFunPtr), PExternalFunctionWrapper.SETTER);
- setterObject = HPyLegacyGetSetDescriptorSetterRoot.createLegacyFunction(context, lang, owner, getSetDescrName, setterFunInteropPtr, closurePtr);
+ setterObject = HPyLegacyGetSetDescriptorSetterRoot.createLegacyFunction(language, owner, getSetDescrName, setterFunInteropPtr, closurePtr);
}
- GetSetDescriptor getSetDescriptor = factory.createGetSetDescriptor(getterObject, setterObject, getSetDescrName, owner, hasSetter);
+ context.getContext().getLanguage(inliningTarget);
+ GetSetDescriptor getSetDescriptor = PFactory.createGetSetDescriptor(language, getterObject, setterObject, getSetDescrName, owner, hasSetter);
writeDocNode.execute(getSetDescriptor, SpecialAttributeNames.T___DOC__, getSetDescrDoc);
return getSetDescriptor;
}
@@ -920,7 +919,6 @@ static HPyProperty doIt(GraalHPyContext context, Object enclosingType, Object me
@Cached(parameters = "context") GraalHPyCAccess.IsNullNode isNullNode,
@Cached(parameters = "context") GraalHPyCAccess.ReadGenericNode readGenericNode,
@Cached FromCharPointerNode fromCharPointerNode,
- @Cached PythonObjectFactory factory,
@Cached WriteAttributeToPythonObjectNode writeDocNode) {
// computes offsets like '&(memberDefArrPtr[i].name)'
@@ -958,7 +956,7 @@ static HPyProperty doIt(GraalHPyContext context, Object enclosingType, Object me
}
// create a property
- GetSetDescriptor memberDescriptor = factory.createMemberDescriptor(getterObject, setterObject, name, enclosingType);
+ GetSetDescriptor memberDescriptor = PFactory.createMemberDescriptor(language, getterObject, setterObject, name, enclosingType);
writeDocNode.execute(memberDescriptor, SpecialAttributeNames.T___DOC__, memberDoc);
return new HPyProperty(name, memberDescriptor);
}
@@ -989,7 +987,6 @@ static HPyProperty doIt(GraalHPyContext context, PythonClass enclosingType, Obje
@Cached(parameters = "context") GraalHPyCAccess.ReadGenericNode readGenericNode,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached TruffleString.EqualNode equalNode,
- @Cached PythonObjectFactory factory,
@Cached WriteAttributeToPythonObjectNode writeDocNode) {
TruffleString name = fromCharPointerNode.execute(readPointerNode.read(context, memberDef, GraalHPyCField.HPyDef__member__name));
@@ -1018,7 +1015,7 @@ static HPyProperty doIt(GraalHPyContext context, PythonClass enclosingType, Obje
}
// create member descriptor
- GetSetDescriptor memberDescriptor = factory.createMemberDescriptor(getterObject, setterObject, name, enclosingType);
+ GetSetDescriptor memberDescriptor = PFactory.createMemberDescriptor(language, getterObject, setterObject, name, enclosingType);
writeDocNode.execute(memberDescriptor, SpecialAttributeNames.T___DOC__, memberDoc);
return new HPyProperty(name, memberDescriptor);
}
@@ -1047,11 +1044,11 @@ public abstract static class HPyCreateGetSetDescriptorNode extends PNodeWithCont
@Specialization
static GetSetDescriptor doIt(GraalHPyContext context, Object type, Object memberDef,
+ @Bind("this") Node inliningTarget,
@Cached(parameters = "context") GraalHPyCAccess.ReadPointerNode readPointerNode,
@Cached(parameters = "context") GraalHPyCAccess.IsNullNode isNullNode,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached HPyAttachFunctionTypeNode attachFunctionTypeNode,
- @Cached PythonObjectFactory factory,
@Cached WriteAttributeToPythonObjectNode writeDocNode) {
TruffleString name = fromCharPointerNode.execute(readPointerNode.read(context, memberDef, GraalHPyCField.HPyDef__getset__name));
@@ -1093,7 +1090,8 @@ static GetSetDescriptor doIt(GraalHPyContext context, Object type, Object member
setterObject = null;
}
- GetSetDescriptor getSetDescriptor = factory.createGetSetDescriptor(getterObject, setterObject, name, type, !hasSetter);
+ PythonLanguage language = context.getContext().getLanguage(inliningTarget);
+ GetSetDescriptor getSetDescriptor = PFactory.createGetSetDescriptor(language, getterObject, setterObject, name, type, !hasSetter);
writeDocNode.execute(getSetDescriptor, SpecialAttributeNames.T___DOC__, memberDoc);
return getSetDescriptor;
}
@@ -1148,7 +1146,6 @@ public abstract static class HPyCreateSlotNode extends PNodeWithContext {
static Object doIt(GraalHPyContext context, PythonClass enclosingType, TpSlots.Builder tpSlotsBuilder, Object slotDef,
@Bind("this") Node inliningTarget,
@Cached HPyReadSlotNode readSlotNode,
- @Cached PythonObjectFactory factory,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached PRaiseNode raiseNode) {
@@ -1193,7 +1190,7 @@ static Object doIt(GraalHPyContext context, PythonClass enclosingType, TpSlots.B
Object enclosingTypeForFun = HPY_TP_NEW.equals(slot) ? null : enclosingType;
PythonLanguage language = context.getContext().getLanguage(inliningTarget);
- Object function = HPyExternalFunctionNodes.createWrapperFunction(language, context, slotWrapper, null, null, methodNameStr, slotData.impl(), enclosingTypeForFun, factory);
+ Object function = HPyExternalFunctionNodes.createWrapperFunction(language, context, slotWrapper, null, null, methodNameStr, slotData.impl(), enclosingTypeForFun);
property = new HPyProperty(methodName, function, property);
}
}
@@ -1246,7 +1243,6 @@ static boolean doIt(GraalHPyContext context, Object enclosingType, TpSlots.Build
@Cached ReadPropertyNode readPropertyNode,
@Cached WritePropertyNode writePropertyNode,
@CachedLibrary(limit = "1") InteropLibrary lib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
// computes '&(slotDefArrPtr[i].slot)'
@@ -1327,7 +1323,7 @@ static boolean doIt(GraalHPyContext context, Object enclosingType, TpSlots.Build
callable = interopPFuncPtr;
}
PythonLanguage lang = context.getContext().getLanguage(inliningTarget);
- method = PExternalFunctionWrapper.createWrapperFunction(attributeKey, callable, enclosingType, 0, slot.getSignature(), lang, factory, true);
+ method = PExternalFunctionWrapper.createWrapperFunction(attributeKey, callable, enclosingType, 0, slot.getSignature(), lang, true);
}
writeAttributeToObjectNode.execute(enclosingType, attributeKey, method);
} else {
@@ -2238,8 +2234,8 @@ static long doUnsignedLongPositive(long n, @SuppressWarnings("unused") boolean s
@Specialization(guards = {"!signed", "n < 0"})
static Object doUnsignedLongNegative(long n, @SuppressWarnings("unused") boolean signed,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(convertToBigInteger(n));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, convertToBigInteger(n));
}
@TruffleBoundary
@@ -2249,8 +2245,8 @@ private static BigInteger convertToBigInteger(long n) {
@Specialization
static Object doPointer(PythonNativeObject n, @SuppressWarnings("unused") boolean signed,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createNativeVoidPtr(n.getPtr());
+ @Bind PythonLanguage language) {
+ return PFactory.createNativeVoidPtr(language, n.getPtr());
}
}
@@ -2296,7 +2292,6 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
@Cached(parameters = "context") HPyAsCharPointerNode asCharPointerNode,
@Cached HPyTypeSplitNameNode splitName,
@Cached FromCharPointerNode fromCharPointerNode,
- @Cached PythonObjectFactory factory,
@Cached IsTypeNode isTypeNode,
@Cached HasSameConstructorNode hasSameConstructorNode,
@Cached CStructAccess.ReadI64Node getMetaSizeNode,
@@ -2314,6 +2309,7 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
@Cached PRaiseNode raiseNode) {
try {
+ PythonLanguage language = context.getContext().getLanguage(inliningTarget);
// the name as given by the specification
TruffleString specName = fromCharPointerNode.execute(readPointerNode.read(context, typeSpec, GraalHPyCField.HPyType_Spec__name), false);
@@ -2327,15 +2323,15 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
Object doc = readPointerNode.read(context, typeSpec, GraalHPyCField.HPyType_Spec__doc);
if (!isNullNode.execute(context, doc)) {
TruffleString docString = fromCharPointerNode.execute(doc);
- namespace = factory.createDict(new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, docString)});
+ namespace = PFactory.createDict(language, new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, docString)});
} else {
- namespace = factory.createDict();
+ namespace = PFactory.createDict(language);
}
HPyTypeSpecParam[] typeSpecParams = extractTypeSpecParams(context, typeSpecParamArray);
// extract bases from type spec params
- PTuple bases = extractBases(typeSpecParams, factory);
+ PTuple bases = extractBases(typeSpecParams, language);
// extract metaclass from type spec params
Object metatype = getMetatype(typeSpecParams, raiseNode);
@@ -2500,7 +2496,6 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
*/
// Lookup the inherited constructor and pass it to the HPy decorator.
Object inheritedConstructor = lookupNewNode.execute(baseClass);
- PythonLanguage language = context.getContext().getLanguage(inliningTarget);
PBuiltinFunction constructorDecorator = HPyObjectNewNode.createBuiltinFunction(language, inheritedConstructor, builtinShape);
writeAttributeToObjectNode.execute(newType, SpecialMethodNames.T___NEW__, constructorDecorator);
}
@@ -2565,11 +2560,11 @@ private static HPyTypeSpecParam[] extractTypeSpecParams(GraalHPyContext context,
* @return The bases tuple or {@code null} in case of an error.
*/
@TruffleBoundary
- private static PTuple extractBases(HPyTypeSpecParam[] typeSpecParams, PythonObjectFactory factory) {
+ private static PTuple extractBases(HPyTypeSpecParam[] typeSpecParams, PythonLanguage language) {
// if there are no type spec params, no bases have been explicitly specified
if (typeSpecParams == null) {
- return factory.createEmptyTuple();
+ return PFactory.createEmptyTuple(language);
}
ArrayList basesList = new ArrayList<>();
@@ -2594,7 +2589,7 @@ private static PTuple extractBases(HPyTypeSpecParam[] typeSpecParams, PythonObje
assert false : "unknown type spec param kind";
}
}
- return factory.createTuple(basesList.toArray());
+ return PFactory.createTuple(language, basesList.toArray());
}
/**
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyObjectBuiltins.java
index 574b5642a3..393b2965ce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyObjectBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -68,7 +68,7 @@
import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -286,7 +286,7 @@ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Ob
}
RootCallTarget callTarget = language.createCachedCallTarget(l -> new HPyObjectNewNode(language, builtinShape), HPyObjectNewNode.class, builtinShape);
int flags = CExtContext.METH_KEYWORDS | CExtContext.METH_VARARGS;
- return PythonObjectFactory.getUncached().createBuiltinFunction(SpecialMethodNames.T___NEW__, null, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(superConstructor), flags, callTarget);
+ return PFactory.createBuiltinFunction(language, SpecialMethodNames.T___NEW__, null, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(superConstructor), flags, callTarget);
}
public static Object getDecoratedSuperConstructor(PBuiltinFunction builtinFunction) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
index d61f11be8e..a51505dd58 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
@@ -101,7 +101,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
@@ -160,14 +160,10 @@ public static PKeyword[] createKwDefaults(Object callable, Object closure, Graal
* @param name The name of the method.
* @param callable The native function pointer.
* @param enclosingType The type the function belongs to (needed for checking of {@code self}).
- * @param factory Just an instance of {@link PythonObjectFactory} to create the function object.
- * We could also use the uncached version but this way, the allocations are reported
- * for the caller.
* @return A {@link PBuiltinFunction} that accepts the given signature.
*/
@TruffleBoundary
- static PBuiltinFunction createWrapperFunction(PythonLanguage language, GraalHPyContext context, HPyFuncSignature signature, TruffleString name, Object callable, Object enclosingType,
- PythonObjectFactory factory) {
+ static PBuiltinFunction createWrapperFunction(PythonLanguage language, GraalHPyContext context, HPyFuncSignature signature, TruffleString name, Object callable, Object enclosingType) {
assert InteropLibrary.getUncached(callable).isExecutable(callable) : "object is not callable";
RootCallTarget callTarget = language.createCachedCallTarget(l -> createRootNode(l, signature, name), signature, name, true);
@@ -180,7 +176,7 @@ static PBuiltinFunction createWrapperFunction(PythonLanguage language, GraalHPyC
defaults = PythonUtils.EMPTY_OBJECT_ARRAY;
}
int flags = HPyFuncSignature.getFlags(signature);
- return factory.createBuiltinFunction(name, enclosingType, defaults, createKwDefaults(callable, context), flags, callTarget);
+ return PFactory.createBuiltinFunction(language, name, enclosingType, defaults, createKwDefaults(callable, context), flags, callTarget);
}
private static PRootNode createRootNode(PythonLanguage language, HPyFuncSignature signature, TruffleString name) {
@@ -230,13 +226,11 @@ private static PRootNode createRootNode(PythonLanguage language, HPyFuncSignatur
* @param name The name of the method.
* @param callable The native function pointer.
* @param enclosingType The type the function belongs to (needed for checking of {@code self}).
- * @param factory Just an instance of {@link PythonObjectFactory} to create the function object.
* @return A {@link PBuiltinFunction} implementing the semantics of the specified slot wrapper.
*/
@TruffleBoundary
public static PBuiltinFunction createWrapperFunction(PythonLanguage language, GraalHPyContext context, HPySlotWrapper wrapper, TpSlotHPyNative slot, PExternalFunctionWrapper legacySlotWrapper,
- TruffleString name, Object callable, Object enclosingType,
- PythonObjectFactory factory) {
+ TruffleString name, Object callable, Object enclosingType) {
assert InteropLibrary.getUncached(callable).isExecutable(callable) : "object is not callable";
RootCallTarget callTarget = language.createCachedCallTarget(l -> createSlotRootNode(l, wrapper, name), wrapper, name);
Object[] defaults;
@@ -257,7 +251,7 @@ public static PBuiltinFunction createWrapperFunction(PythonLanguage language, Gr
kwDefaults = createKwDefaults(callable, context);
}
- return factory.createWrapperDescriptor(name, enclosingType, defaults, kwDefaults, 0, callTarget, slot, legacySlotWrapper);
+ return PFactory.createWrapperDescriptor(language, name, enclosingType, defaults, kwDefaults, 0, callTarget, slot, legacySlotWrapper);
}
private static PRootNode createSlotRootNode(PythonLanguage language, HPySlotWrapper wrapper, TruffleString name) {
@@ -625,7 +619,6 @@ static final class HPyMethKeywordsRoot extends HPyMethodDescriptorRootNode {
@Child private ReadVarArgsNode readVarargsNode;
@Child private ReadVarKeywordsNode readKwargsNode;
- @Child private PythonObjectFactory factory;
@TruffleBoundary
public HPyMethKeywordsRoot(PythonLanguage language, TruffleString name) {
@@ -685,11 +678,7 @@ private PKeyword[] getKwargs(VirtualFrame frame) {
}
private PTuple getKwnamesTuple(TruffleString[] kwnames) {
- if (factory == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- factory = insert(PythonObjectFactory.create());
- }
- return factory.createTuple(kwnames);
+ return PFactory.createTuple(PythonLanguage.get(this), kwnames);
}
@Override
@@ -1352,8 +1341,7 @@ public static PBuiltinFunction createFunction(GraalHPyContext hpyContext, Object
PythonContext pythonContext = hpyContext.getContext();
PythonLanguage lang = pythonContext.getLanguage();
RootCallTarget callTarget = lang.createCachedCallTarget(l -> new HPyGetSetDescriptorGetterRootNode(l, propertyName), HPyGetSetDescriptorGetterRootNode.class, propertyName);
- PythonObjectFactory factory = pythonContext.getCore().factory();
- return factory.createBuiltinFunction(propertyName, enclosingType, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(target, closure, hpyContext), 0, callTarget);
+ return PFactory.createBuiltinFunction(lang, propertyName, enclosingType, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(target, closure, hpyContext), 0, callTarget);
}
}
@@ -1391,16 +1379,14 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
}
@TruffleBoundary
- public static PBuiltinFunction createLegacyFunction(GraalHPyContext context, PythonLanguage lang, Object owner, TruffleString propertyName, Object target, Object closure) {
- PythonContext pythonContext = context.getContext();
- PythonObjectFactory factory = pythonContext.factory();
+ public static PBuiltinFunction createLegacyFunction(PythonLanguage lang, Object owner, TruffleString propertyName, Object target, Object closure) {
RootCallTarget rootCallTarget = lang.createCachedCallTarget(l -> new HPyLegacyGetSetDescriptorGetterRoot(l, propertyName, PExternalFunctionWrapper.GETTER),
HPyLegacyGetSetDescriptorGetterRoot.class, propertyName);
if (rootCallTarget == null) {
throw CompilerDirectives.shouldNotReachHere("Calling non-native get descriptor functions is not support in HPy");
}
target = EnsureExecutableNode.executeUncached(target, PExternalFunctionWrapper.GETTER);
- return factory.createBuiltinFunction(propertyName, owner, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(target, closure), 0, rootCallTarget);
+ return PFactory.createBuiltinFunction(lang, propertyName, owner, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(target, closure), 0, rootCallTarget);
}
}
@@ -1440,8 +1426,7 @@ public static PBuiltinFunction createFunction(GraalHPyContext hpyContext, Object
PythonContext pythonContext = hpyContext.getContext();
PythonLanguage lang = pythonContext.getLanguage();
RootCallTarget callTarget = lang.createCachedCallTarget(l -> new HPyGetSetDescriptorSetterRootNode(l, propertyName), HPyGetSetDescriptorSetterRootNode.class, propertyName);
- PythonObjectFactory factory = pythonContext.factory();
- return factory.createBuiltinFunction(propertyName, enclosingType, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(target, closure, hpyContext), 0, callTarget);
+ return PFactory.createBuiltinFunction(lang, propertyName, enclosingType, PythonUtils.EMPTY_OBJECT_ARRAY, createKwDefaults(target, closure, hpyContext), 0, callTarget);
}
}
@@ -1476,16 +1461,14 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
}
@TruffleBoundary
- public static PBuiltinFunction createLegacyFunction(GraalHPyContext context, PythonLanguage lang, Object owner, TruffleString propertyName, Object target, Object closure) {
- PythonContext pythonContext = context.getContext();
- PythonObjectFactory factory = pythonContext.factory();
+ public static PBuiltinFunction createLegacyFunction(PythonLanguage lang, Object owner, TruffleString propertyName, Object target, Object closure) {
RootCallTarget rootCallTarget = lang.createCachedCallTarget(l -> new HPyLegacyGetSetDescriptorSetterRoot(l, propertyName, PExternalFunctionWrapper.SETTER),
HPyLegacyGetSetDescriptorSetterRoot.class, propertyName);
if (rootCallTarget == null) {
throw CompilerDirectives.shouldNotReachHere("Calling non-native get descriptor functions is not support in HPy");
}
target = EnsureExecutableNode.executeUncached(target, PExternalFunctionWrapper.SETTER);
- return factory.createBuiltinFunction(propertyName, owner, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(target, closure), 0, rootCallTarget);
+ return PFactory.createBuiltinFunction(lang, propertyName, owner, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(target, closure), 0, rootCallTarget);
}
}
@@ -1776,7 +1759,6 @@ static final class HPyMethCallRoot extends HPyMethodDescriptorRootNode {
@Child private ReadVarArgsNode readVarargsNode;
@Child private ReadVarKeywordsNode readKwargsNode;
- @Child private PythonObjectFactory factory;
@TruffleBoundary
public HPyMethCallRoot(PythonLanguage language, TruffleString name) {
@@ -1860,11 +1842,7 @@ private PKeyword[] getKwargs(VirtualFrame frame) {
}
private PTuple getKwnamesTuple(TruffleString[] kwnames) {
- if (factory == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- factory = insert(PythonObjectFactory.create());
- }
- return factory.createTuple(kwnames);
+ return PFactory.createTuple(PythonLanguage.get(this), kwnames);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
index 26be2d9259..1a703b622c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
@@ -172,6 +172,7 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
import com.oracle.graal.python.lib.PyLongAsDoubleNode;
@@ -197,7 +198,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.PythonOptions.HPyBackendMode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
@@ -243,7 +244,6 @@ public final class GraalHPyJNIContext extends GraalHPyNativeContext {
private static boolean jniBackendLoaded = false;
- private final PythonObjectSlowPathFactory slowPathFactory;
private final int[] counts;
private final int[] ctypeSizes;
@@ -271,7 +271,6 @@ public final class GraalHPyJNIContext extends GraalHPyNativeContext {
public GraalHPyJNIContext(GraalHPyContext context, boolean traceUpcalls) {
super(context, traceUpcalls);
assert !PythonImageBuildOptions.WITHOUT_JNI;
- this.slowPathFactory = context.getContext().factory();
this.counts = traceUpcalls ? new int[HPyJNIUpcall.VALUES.length] : null;
this.ctypeSizes = new int[HPyContextSignatureType.values().length];
this.cfieldOffsets = new int[GraalHPyCField.values().length];
@@ -1245,6 +1244,7 @@ public static long expectPointer(Object value) {
}
private long createHPyObject(long typeHandle, long dataOutVar) {
+ PythonLanguage language = context.getContext().getLanguage();
Object type = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(typeHandle));
PythonObject pythonObject;
@@ -1257,7 +1257,7 @@ private long createHPyObject(long typeHandle, long dataOutVar) {
long basicSize = clazz.getBasicSize();
if (basicSize == -1) {
// create the managed Python object
- pythonObject = slowPathFactory.createPythonObject(clazz, clazz.getInstanceShape());
+ pythonObject = PFactory.createPythonObject(language, clazz, clazz.getInstanceShape());
} else {
/*
* Since this is a JNI upcall method, we know that (1) we are not running in some
@@ -1269,7 +1269,7 @@ private long createHPyObject(long typeHandle, long dataOutVar) {
if (dataOutVar != 0) {
UNSAFE.putAddress(dataOutVar, dataPtr);
}
- pythonObject = slowPathFactory.createPythonHPyObject(clazz, dataPtr);
+ pythonObject = PFactory.createPythonHPyObject(language, clazz, clazz.getInstanceShape(), dataPtr);
Object destroyFunc = clazz.getHPyDestroyFunc();
context.createHandleReference(pythonObject, dataPtr, destroyFunc != PNone.NO_VALUE ? destroyFunc : null);
}
@@ -1283,7 +1283,7 @@ private long createHPyObject(long typeHandle, long dataOutVar) {
return HPyRaiseNodeGen.getUncached().raiseIntWithoutFrame(context, 0, PythonBuiltinClassType.TypeError, ErrorMessages.HPY_NEW_ARG_1_MUST_BE_A_TYPE);
}
// TODO(fa): this should actually call __new__
- pythonObject = slowPathFactory.createPythonObject(type);
+ pythonObject = PFactory.createPythonObject(language, type, TypeNodes.GetInstanceShape.executeUncached(type));
}
return GraalHPyBoxing.boxHandle(context.getHPyHandleForObject(pythonObject));
}
@@ -1363,7 +1363,7 @@ public long ctxUnicodeFromJCharArray(char[] arr) {
public long ctxDictNew() {
increment(HPyJNIUpcall.HPyDictNew);
- PDict dict = slowPathFactory.createDict();
+ PDict dict = PFactory.createDict(context.getContext().getLanguage());
return GraalHPyBoxing.boxHandle(context.getHPyHandleForObject(dict));
}
@@ -1373,7 +1373,7 @@ public long ctxListNew(long llen) {
int len = CastToJavaIntExactNode.executeUncached(llen);
Object[] data = new Object[len];
Arrays.fill(data, PNone.NONE);
- PList list = slowPathFactory.createList(data);
+ PList list = PFactory.createList(context.getContext().getLanguage(), data);
return GraalHPyBoxing.boxHandle(context.getHPyHandleForObject(list));
} catch (PException e) {
HPyTransformExceptionToNativeNode.executeUncached(context, e);
@@ -1399,10 +1399,11 @@ public long ctxSequenceFromArray(long[] hItems, boolean steal, boolean create_li
}
}
Object result;
+ PythonLanguage language = context.getContext().getLanguage();
if (create_list) {
- result = slowPathFactory.createList(objects);
+ result = PFactory.createList(language, objects);
} else {
- result = slowPathFactory.createTuple(objects);
+ result = PFactory.createTuple(language, objects);
}
return GraalHPyBoxing.boxHandle(context.getHPyHandleForObject(result));
}
@@ -1521,7 +1522,7 @@ public long ctxCapsuleNew(long pointer, long name, long destructor) {
} else {
hpyDestructor = 0;
}
- PyCapsule result = slowPathFactory.createCapsuleNativeName(pointer, new NativePointer(name));
+ PyCapsule result = PFactory.createCapsuleNativeName(context.getContext().getLanguage(), pointer, new NativePointer(name));
if (hpyDestructor != 0) {
result.registerDestructor(hpyDestructor);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java
index 013bdc4b46..6637816761 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -39,6 +39,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -63,8 +64,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -92,9 +92,8 @@ public abstract static class GetFreeVarsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
@Bind("this") Node inliningTarget,
- @Cached InternStringNode internStringNode,
- @Cached PythonObjectFactory factory) {
- return internStrings(inliningTarget, self.getFreeVars(), internStringNode, factory);
+ @Cached InternStringNode internStringNode) {
+ return internStrings(inliningTarget, self.getFreeVars(), internStringNode);
}
}
@@ -104,9 +103,8 @@ public abstract static class GetCellVarsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
@Bind("this") Node inliningTarget,
- @Cached InternStringNode internStringNode,
- @Cached PythonObjectFactory factory) {
- return internStrings(inliningTarget, self.getCellVars(), internStringNode, factory);
+ @Cached InternStringNode internStringNode) {
+ return internStrings(inliningTarget, self.getCellVars(), internStringNode);
}
}
@@ -215,8 +213,8 @@ static Object get(PCode self) {
public abstract static class GetCodeNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
- @Cached PythonObjectFactory factory) {
- return self.co_code(factory);
+ @Bind PythonLanguage language) {
+ return self.co_code(language);
}
}
@@ -226,9 +224,8 @@ public abstract static class GetConstsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
@Bind("this") Node inliningTarget,
- @Cached InternStringNode internStringNode,
- @Cached PythonObjectFactory factory) {
- return internStrings(inliningTarget, self.getConstants(), internStringNode, factory);
+ @Cached InternStringNode internStringNode) {
+ return internStrings(inliningTarget, self.getConstants(), internStringNode);
}
}
@@ -238,9 +235,8 @@ public abstract static class GetNamesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
@Bind("this") Node inliningTarget,
- @Cached InternStringNode internStringNode,
- @Cached PythonObjectFactory factory) {
- return internStrings(inliningTarget, self.getNames(), internStringNode, factory);
+ @Cached InternStringNode internStringNode) {
+ return internStrings(inliningTarget, self.getNames(), internStringNode);
}
}
@@ -250,9 +246,8 @@ public abstract static class GetVarNamesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
@Bind("this") Node inliningTarget,
- @Cached InternStringNode internStringNode,
- @Cached PythonObjectFactory factory) {
- return internStrings(inliningTarget, self.getVarnames(), internStringNode, factory);
+ @Cached InternStringNode internStringNode) {
+ return internStrings(inliningTarget, self.getVarnames(), internStringNode);
}
}
@@ -263,13 +258,13 @@ static Object get(PCode self,
public abstract static class GetLineTableNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PCode self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
byte[] linetable = self.getLinetable();
if (linetable == null) {
// TODO: this is for the moment undefined (see co_code)
linetable = PythonUtils.EMPTY_BYTE_ARRAY;
}
- return factory.createBytes(linetable);
+ return PFactory.createBytes(language, linetable);
}
}
@@ -279,9 +274,9 @@ abstract static class GetExceptionTableNode extends PythonUnaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object get(PCode self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// We store our exception table together with the bytecode, not in this field
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
}
@@ -296,7 +291,7 @@ private static final class IteratorData {
@Specialization
@TruffleBoundary
static Object lines(PCode self) {
- PythonObjectFactory factory = PythonContext.get(null).factory();
+ PythonLanguage language = PythonLanguage.get(null);
PTuple tuple;
CodeUnit co = self.getCodeUnit();
if (co != null) {
@@ -308,15 +303,15 @@ static Object lines(PCode self) {
co.iterateBytecode((int bci, OpCodes op, int oparg, byte[] followingArgs) -> {
int nextStart = bci + op.length();
if (map.startLineMap[bci] != data.line || nextStart == co.code.length) {
- lines.add(factory.createTuple(new int[]{data.start, nextStart, data.line}));
+ lines.add(PFactory.createTuple(language, new int[]{data.start, nextStart, data.line}));
data.line = map.startLineMap[bci];
data.start = nextStart;
}
});
}
- tuple = factory.createTuple(lines.toArray());
+ tuple = PFactory.createTuple(language, lines.toArray());
} else {
- tuple = factory.createEmptyTuple();
+ tuple = PFactory.createEmptyTuple(language);
}
return PyObjectGetIter.executeUncached(tuple);
}
@@ -329,7 +324,7 @@ abstract static class CoPositionsNode extends PythonUnaryBuiltinNode {
@Specialization
@TruffleBoundary
Object positions(PCode self) {
- PythonObjectFactory factory = PythonContext.get(null).factory();
+ PythonLanguage language = PythonLanguage.get(null);
PTuple tuple;
CodeUnit co = self.getCodeUnit();
if (co != null) {
@@ -338,13 +333,13 @@ Object positions(PCode self) {
if (map != null && map.startLineMap.length > 0) {
byte[] bytecode = co.code;
for (int i = 0; i < bytecode.length;) {
- lines.add(factory.createTuple(new int[]{map.startLineMap[i], map.endLineMap[i], map.startColumnMap[i], map.endColumnMap[i]}));
+ lines.add(PFactory.createTuple(language, new int[]{map.startLineMap[i], map.endLineMap[i], map.startColumnMap[i], map.endColumnMap[i]}));
i += OpCodes.fromOpCode(bytecode[i]).length();
}
}
- tuple = factory.createTuple(lines.toArray());
+ tuple = PFactory.createTuple(language, lines.toArray());
} else {
- tuple = factory.createEmptyTuple();
+ tuple = PFactory.createEmptyTuple(language);
}
return PyObjectGetIter.executeUncached(tuple);
}
@@ -405,17 +400,17 @@ public abstract static class CodeHashNode extends PythonUnaryBuiltinNode {
@Specialization
static long hash(VirtualFrame frame, PCode self,
@Bind("this") Node inliningTarget,
- @Cached PyObjectHashNode hashNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached PyObjectHashNode hashNode) {
long h, h0, h1, h2, h3, h4, h5, h6;
h0 = hashNode.execute(frame, inliningTarget, self.co_name());
- h1 = hashNode.execute(frame, inliningTarget, self.co_code(factory));
- h2 = hashNode.execute(frame, inliningTarget, self.co_consts(factory));
- h3 = hashNode.execute(frame, inliningTarget, self.co_names(factory));
- h4 = hashNode.execute(frame, inliningTarget, self.co_varnames(factory));
- h5 = hashNode.execute(frame, inliningTarget, self.co_freevars(factory));
- h6 = hashNode.execute(frame, inliningTarget, self.co_cellvars(factory));
+ h1 = hashNode.execute(frame, inliningTarget, self.co_code(language));
+ h2 = hashNode.execute(frame, inliningTarget, self.co_consts(language));
+ h3 = hashNode.execute(frame, inliningTarget, self.co_names(language));
+ h4 = hashNode.execute(frame, inliningTarget, self.co_varnames(language));
+ h5 = hashNode.execute(frame, inliningTarget, self.co_freevars(language));
+ h6 = hashNode.execute(frame, inliningTarget, self.co_cellvars(language));
h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6 ^
self.co_argcount() ^ self.co_posonlyargcount() ^ self.co_kwonlyargcount() ^
@@ -509,9 +504,10 @@ private static boolean hasStrings(Object[] values) {
return false;
}
- private static PTuple internStrings(Node inliningTarget, Object[] values, InternStringNode internStringNode, PythonObjectFactory factory) {
+ private static PTuple internStrings(Node inliningTarget, Object[] values, InternStringNode internStringNode) {
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
if (values == null) {
- return factory.createEmptyTuple();
+ return PFactory.createEmptyTuple(language);
}
Object[] result;
if (!hasStrings(values)) {
@@ -526,6 +522,6 @@ private static PTuple internStrings(Node inliningTarget, Object[] values, Intern
}
}
}
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
index 5b0bf0374b..1869dc930c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
@@ -59,7 +59,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.Supplier;
import com.oracle.truffle.api.CallTarget;
@@ -143,19 +143,18 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
parameterNames,
kwOnlyNames);
} else {
- ct = create().deserializeForBytecodeInterpreter(language, codedata, cellvars, freevars);
+ ct = create().deserializeForBytecodeInterpreter(context, codedata, cellvars, freevars);
signature = ((PRootNode) ct.getRootNode()).getSignature();
}
if (filename != null) {
context.setCodeFilename(ct, filename);
}
- PythonObjectFactory factory = context.factory();
- return factory.createCode(ct, signature, nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars, filename, name, qualname, firstlineno, linetable);
+ return PFactory.createCode(language, ct, signature, nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars, filename, name, qualname, firstlineno, linetable);
}
@SuppressWarnings("static-method")
- private RootCallTarget deserializeForBytecodeInterpreter(PythonLanguage language, byte[] data, TruffleString[] cellvars, TruffleString[] freevars) {
- CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(data);
+ private RootCallTarget deserializeForBytecodeInterpreter(PythonContext context, byte[] data, TruffleString[] cellvars, TruffleString[] freevars) {
+ CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(context, data);
if (cellvars != null && !Arrays.equals(code.cellvars, cellvars) || freevars != null && !Arrays.equals(code.freevars, freevars)) {
code = new CodeUnit(code.name, code.qualname, code.argCount, code.kwOnlyArgCount, code.positionalOnlyArgCount, code.stacksize, code.code,
code.srcOffsetTable, code.flags, code.names, code.varnames,
@@ -165,9 +164,9 @@ private RootCallTarget deserializeForBytecodeInterpreter(PythonLanguage language
code.outputCanQuicken, code.variableShouldUnbox,
code.generalizeInputsMap, code.generalizeVarsMap);
}
- RootNode rootNode = PBytecodeRootNode.create(language, code, PythonUtils.createFakeSource());
+ RootNode rootNode = PBytecodeRootNode.create(context.getLanguage(), code, PythonUtils.createFakeSource());
if (code.isGeneratorOrCoroutine()) {
- rootNode = new PBytecodeGeneratorFunctionRootNode(language, rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
+ rootNode = new PBytecodeGeneratorFunctionRootNode(context.getLanguage(), rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
}
return PythonUtils.getOrCreateCallTarget(rootNode);
}
@@ -183,12 +182,11 @@ public static PCode createCode(PythonContext context, int flags, byte[] codedata
return context.getEnv().parsePublic(source);
};
- PythonObjectFactory factory = context.factory();
if (context.isCoreInitialized() || isNotAModule) {
- return factory.createCode(createCode, flags, firstlineno, lnotab, filename);
+ return PFactory.createCode(language, createCode, flags, firstlineno, lnotab, filename);
} else {
RootCallTarget ct = (RootCallTarget) language.cacheCode(filename, createCode);
- return factory.createCode(ct, flags, firstlineno, lnotab, filename);
+ return PFactory.createCode(language, ct, flags, firstlineno, lnotab, filename);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java
index 90dfe41bac..fed0025ac1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -68,7 +68,7 @@
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
@@ -527,31 +527,28 @@ public Object[] getConstants() {
@TruffleBoundary
private static Object convertConstantToPythonSpace(RootNode rootNode, Object o) {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- if (o instanceof CodeUnit) {
- CodeUnit code = ((CodeUnit) o);
- PBytecodeRootNode bytecodeRootNode = PBytecodeRootNode.create(PythonLanguage.get(rootNode), code, getSourceSection(rootNode).getSource());
- return factory.createCode(bytecodeRootNode.getCallTarget(), bytecodeRootNode.getSignature(), code);
+ PythonLanguage language = PythonLanguage.get(null);
+ if (o instanceof CodeUnit code) {
+ PBytecodeRootNode bytecodeRootNode = PBytecodeRootNode.create(language, code, getSourceSection(rootNode).getSource());
+ return PFactory.createCode(language, bytecodeRootNode.getCallTarget(), bytecodeRootNode.getSignature(), code);
} else if (o instanceof BigInteger) {
- return factory.createInt((BigInteger) o);
+ return PFactory.createInt(language, (BigInteger) o);
} else if (o instanceof int[]) {
- return factory.createTuple((int[]) o);
+ return PFactory.createTuple(language, (int[]) o);
} else if (o instanceof long[]) {
- return factory.createTuple(new LongSequenceStorage((long[]) o));
+ return PFactory.createTuple(language, new LongSequenceStorage((long[]) o));
} else if (o instanceof double[]) {
- return factory.createTuple(new DoubleSequenceStorage((double[]) o));
+ return PFactory.createTuple(language, new DoubleSequenceStorage((double[]) o));
} else if (o instanceof boolean[]) {
- return factory.createTuple(new BoolSequenceStorage((boolean[]) o));
+ return PFactory.createTuple(language, new BoolSequenceStorage((boolean[]) o));
} else if (o instanceof byte[]) {
- return factory.createBytes((byte[]) o);
- } else if (o instanceof TruffleString[]) {
- TruffleString[] strings = (TruffleString[]) o;
+ return PFactory.createBytes(language, (byte[]) o);
+ } else if (o instanceof TruffleString[] strings) {
Object[] array = new Object[strings.length];
System.arraycopy(strings, 0, array, 0, strings.length);
- return factory.createTuple(array);
- } else if (o instanceof Object[]) {
- Object[] objects = (Object[]) o;
- return factory.createTuple(objects.clone());
+ return PFactory.createTuple(language, array);
+ } else if (o instanceof Object[] objects) {
+ return PFactory.createTuple(language, objects.clone());
}
// Ensure no conversion is missing
assert !IsForeignObjectNode.executeUncached(o) : o;
@@ -709,20 +706,20 @@ public String toDisassembledString(boolean quickened) {
return J_EMPTY_STRING;
}
- private static PTuple createTuple(Object[] array, PythonObjectFactory factory) {
+ private static PTuple createTuple(PythonLanguage language, Object[] array) {
Object[] data = array;
if (data == null) {
data = PythonUtils.EMPTY_OBJECT_ARRAY;
}
- return factory.createTuple(data);
+ return PFactory.createTuple(language, data);
}
- private static PBytes createBytes(byte[] array, PythonObjectFactory factory) {
+ private static PBytes createBytes(byte[] array, PythonLanguage language) {
byte[] bytes = array;
if (bytes == null) {
bytes = PythonUtils.EMPTY_BYTE_ARRAY;
}
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
public TruffleString co_name() {
@@ -743,32 +740,32 @@ public TruffleString co_filename() {
return fName;
}
- public PBytes co_code(PythonObjectFactory factory) {
- return createBytes(this.getCodestring(), factory);
+ public PBytes co_code(PythonLanguage language) {
+ return createBytes(this.getCodestring(), language);
}
- public PBytes co_lnotab(PythonObjectFactory factory) {
- return createBytes(this.getLinetable(), factory);
+ public PBytes co_lnotab(PythonLanguage language) {
+ return createBytes(this.getLinetable(), language);
}
- public PTuple co_consts(PythonObjectFactory factory) {
- return createTuple(this.getConstants(), factory);
+ public PTuple co_consts(PythonLanguage language) {
+ return createTuple(language, this.getConstants());
}
- public PTuple co_names(PythonObjectFactory factory) {
- return createTuple(this.getNames(), factory);
+ public PTuple co_names(PythonLanguage language) {
+ return createTuple(language, this.getNames());
}
- public PTuple co_varnames(PythonObjectFactory factory) {
- return createTuple(this.getVarnames(), factory);
+ public PTuple co_varnames(PythonLanguage language) {
+ return createTuple(language, this.getVarnames());
}
- public PTuple co_freevars(PythonObjectFactory factory) {
- return createTuple(this.getFreeVars(), factory);
+ public PTuple co_freevars(PythonLanguage language) {
+ return createTuple(language, this.getFreeVars());
}
- public PTuple co_cellvars(PythonObjectFactory factory) {
- return createTuple(this.getCellVars(), factory);
+ public PTuple co_cellvars(PythonLanguage language) {
+ return createTuple(language, this.getCellVars());
}
public int co_argcount() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
index 70c5e1110e..3e1e1ee89c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
@@ -45,6 +45,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.ints.PInt;
@@ -58,8 +59,9 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.BufferFormat;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -125,12 +127,12 @@ static long unpackSignedLong(@SuppressWarnings("unused") BufferFormat format, Ob
@Specialization(guards = "format == UINT_64")
static Object unpackUnsignedLong(Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object buffer, int offset,
+ @Bind PythonLanguage language,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached InlinedConditionProfile needsPIntProfile,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile needsPIntProfile) {
long signedLong = bufferLib.readLong(buffer, offset);
if (needsPIntProfile.profile(inliningTarget, signedLong < 0)) {
- return factory.createInt(PInt.longToUnsignedBigInteger(signedLong));
+ return PFactory.createInt(language, PInt.longToUnsignedBigInteger(signedLong));
} else {
return signedLong;
}
@@ -156,9 +158,9 @@ static boolean unpackBoolean(@SuppressWarnings("unused") BufferFormat format, Ob
@Specialization(guards = "format == CHAR")
static PBytes unpackChar(@SuppressWarnings("unused") BufferFormat format, Object buffer, int offset,
- @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createBytes(new byte[]{bufferLib.readByte(buffer, offset)});
+ @Bind PythonLanguage language,
+ @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib) {
+ return PFactory.createBytes(language, new byte[]{bufferLib.readByte(buffer, offset)});
}
@Specialization(guards = "format == UNICODE")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/KeywordsStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/KeywordsStorage.java
index 39f4671f52..2008765880 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/KeywordsStorage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/KeywordsStorage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -68,7 +68,7 @@ public class KeywordsStorage extends HashingStorage {
final PKeyword[] keywords;
- protected KeywordsStorage(PKeyword[] keywords) {
+ public KeywordsStorage(PKeyword[] keywords) {
this.keywords = keywords;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index deadffaff8..3406fd3255 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -43,6 +43,7 @@
import java.lang.reflect.Array;
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
@@ -112,7 +113,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.native_memory.NativeBuffer;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ArrayBasedSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage;
@@ -193,7 +194,7 @@ private static Object getItem(Node inliningTarget, SequenceStorage storage, int
@FunctionalInterface
public interface StorageWrapperFactory {
- Object create(PythonObjectFactory factory, SequenceStorage newStorage);
+ Object create(PythonLanguage language, SequenceStorage newStorage);
}
@GenerateInline
@@ -215,7 +216,7 @@ abstract Object executeImpl(VirtualFrame frame, Node inliningTarget, SequenceSto
@Specialization(guards = "!isPSlice(idx)")
static Object doNonSlice(VirtualFrame frame, Node inliningTarget, SequenceStorage storage, Object idx,
- TruffleString indexBoundsErrorMessage, StorageWrapperFactory wrapperFactory,
+ TruffleString indexBoundsErrorMessage, @SuppressWarnings("unused") StorageWrapperFactory wrapperFactory,
@Cached PyNumberAsSizeNode numberAsSizeNode,
@Cached InlinedConditionProfile negativeIndexProfile,
@Cached PRaiseNode.Lazy raiseNode,
@@ -229,15 +230,15 @@ static Object doNonSlice(VirtualFrame frame, Node inliningTarget, SequenceStorag
@Specialization
static Object doSlice(VirtualFrame frame, Node inliningTarget, SequenceStorage storage, PSlice slice,
- @SuppressWarnings("unused") TruffleString indexBoundsErrorMessage, StorageWrapperFactory wrapperFactory,
- @Cached(inline = false) PythonObjectFactory factory,
+ TruffleString indexBoundsErrorMessage, StorageWrapperFactory wrapperFactory,
+ @Bind PythonLanguage language,
@Cached CoerceToIntSlice sliceCast,
@Cached(inline = false) ComputeIndices compute,
@Cached(inline = false) GetItemSliceNode getItemSliceNode,
@Cached LenOfRangeNode sliceLen) {
SliceInfo info = compute.execute(frame, sliceCast.execute(inliningTarget, slice), storage.length());
SequenceStorage newStorage = getItemSliceNode.execute(storage, info.start, info.stop, info.step, sliceLen.len(inliningTarget, info));
- return wrapperFactory.create(factory, newStorage);
+ return wrapperFactory.create(language, newStorage);
}
}
@@ -404,9 +405,9 @@ public abstract static class GetItemNode extends NormalizingNode {
@Child private GetItemScalarNode getItemScalarNode;
@Child private GetItemSliceNode getItemSliceNode;
- private final BiFunction factoryMethod;
+ private final BiFunction factoryMethod;
- public GetItemNode(NormalizeIndexNode normalizeIndexNode, BiFunction factoryMethod) {
+ public GetItemNode(NormalizeIndexNode normalizeIndexNode, BiFunction factoryMethod) {
super(normalizeIndexNode);
this.factoryMethod = factoryMethod;
}
@@ -462,13 +463,12 @@ protected Object doScalarGeneric(VirtualFrame frame, SequenceStorage storage, Ob
@SuppressWarnings("truffle-static-method")
protected Object doSlice(VirtualFrame frame, SequenceStorage storage, PSlice slice,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
@Cached CoerceToIntSlice sliceCast,
@Cached ComputeIndices compute,
@Cached LenOfRangeNode sliceLen) {
SliceInfo info = compute.execute(frame, sliceCast.execute(inliningTarget, slice), storage.length());
if (factoryMethod != null) {
- return factoryMethod.apply(getGetItemSliceNode().execute(storage, info.start, info.stop, info.step, sliceLen.len(inliningTarget, info)), factory);
+ return factoryMethod.apply(getGetItemSliceNode().execute(storage, info.start, info.stop, info.step, sliceLen.len(inliningTarget, info)), PythonLanguage.get(inliningTarget));
}
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalStateException();
@@ -506,18 +506,18 @@ public static GetItemNode create() {
}
@NeverDefault
- public static GetItemNode create(NormalizeIndexNode normalizeIndexNode, BiFunction factoryMethod) {
+ public static GetItemNode create(NormalizeIndexNode normalizeIndexNode, BiFunction factoryMethod) {
return GetItemNodeGen.create(normalizeIndexNode, factoryMethod);
}
@NeverDefault
public static SequenceStorageNodes.GetItemNode createForList() {
- return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forList(), (s, f) -> f.createList(s));
+ return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forList(), (s, l) -> PFactory.createList(l, s));
}
@NeverDefault
public static SequenceStorageNodes.GetItemNode createForTuple() {
- return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forTuple(), (s, f) -> f.createTuple(s));
+ return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forTuple(), (s, l) -> PFactory.createTuple(l, s));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
index ae48d00b1a..c24a8823e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
@@ -60,6 +60,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -101,14 +102,13 @@
import com.oracle.graal.python.runtime.formatting.ComplexFormatter;
import com.oracle.graal.python.runtime.formatting.InternalFormat;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -213,13 +213,12 @@ abstract static class ComplexNode extends PythonUnaryBuiltinNode {
static Object complex(Object self,
@Bind("this") Node inliningTarget,
@Cached PyComplexCheckExactNode check,
- @Cached ToComplexValueNode toComplexValueNode,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached ToComplexValueNode toComplexValueNode) {
if (check.execute(inliningTarget, self)) {
return self;
} else {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
- return factory.get(inliningTarget).createComplex(c.real, c.imag);
+ return PFactory.createComplex(PythonLanguage.get(inliningTarget), c.real, c.imag);
}
}
}
@@ -380,14 +379,14 @@ public static AbsNode create() {
abstract static class AddNode extends BinaryOpBuiltinNode {
@Specialization
static PComplex doInt(PComplex left, int right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createComplex(left.getReal() + right, left.getImag());
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, left.getReal() + right, left.getImag());
}
@Specialization
static PComplex doDouble(PComplex left, double right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createComplex(left.getReal() + right, left.getImag());
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, left.getReal() + right, left.getImag());
}
@Specialization
@@ -396,13 +395,13 @@ static Object doGeneric(Object leftObj, Object rightObj,
@Cached ToComplexValueNode toComplexLeft,
@Cached ToComplexValueNode toComplexRight,
@Cached InlinedConditionProfile notImplementedProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
if (notImplementedProfile.profile(inliningTarget, left == null || right == null)) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- return factory.createComplex(left.getReal() + right.getReal(), left.getImag() + right.getImag());
+ return PFactory.createComplex(language, left.getReal() + right.getReal(), left.getImag() + right.getImag());
}
}
@@ -425,7 +424,7 @@ static Object doComplex(Object leftObj, Object rightObj,
@Cached InlinedConditionProfile notImplementedProfile,
@Cached InlinedConditionProfile topConditionProfile,
@Cached InlinedConditionProfile zeroDivisionProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
@@ -453,16 +452,16 @@ static Object doComplex(Object leftObj, Object rightObj,
real = (left.getReal() * ratio + left.getImag()) / denom;
imag = (left.getImag() * ratio - left.getReal()) / denom;
}
- return factory.createComplex(real, imag);
+ return PFactory.createComplex(language, real, imag);
}
- static PComplex doubleDivComplex(double left, PComplex right, PythonObjectFactory factory) {
+ static PComplex doubleDivComplex(double left, PComplex right, PythonLanguage language) {
double oprealSq = right.getReal() * right.getReal();
double opimagSq = right.getImag() * right.getImag();
double realPart = right.getReal() * left;
double imagPart = right.getImag() * left;
double denom = oprealSq + opimagSq;
- return factory.createComplex(realPart / denom, -imagPart / denom);
+ return PFactory.createComplex(language, realPart / denom, -imagPart / denom);
}
}
@@ -475,14 +474,14 @@ static Object doComplex(Object leftObj, Object rightObj,
@Cached ToComplexValueNode toComplexLeft,
@Cached ToComplexValueNode toComplexRight,
@Cached InlinedConditionProfile notImplementedProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
if (notImplementedProfile.profile(inliningTarget, left == null || right == null)) {
return PNotImplemented.NOT_IMPLEMENTED;
}
ComplexValue res = multiply(left, right);
- return factory.createComplex(res.getReal(), res.getImag());
+ return PFactory.createComplex(language, res.getReal(), res.getImag());
}
static ComplexValue multiply(ComplexValue left, ComplexValue right) {
@@ -496,14 +495,14 @@ static ComplexValue multiply(ComplexValue left, ComplexValue right) {
@Slot(value = SlotKind.nb_subtract, isComplex = true)
abstract static class SubNode extends BinaryOpBuiltinNode {
static PComplex doComplex(PComplex left, double right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createComplex(left.getReal() - right, left.getImag());
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, left.getReal() - right, left.getImag());
}
@Specialization
static PComplex doComplex(PComplex left, int right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createComplex(left.getReal() - right, left.getImag());
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, left.getReal() - right, left.getImag());
}
@Specialization
@@ -512,13 +511,13 @@ static Object doComplex(Object leftObj, Object rightObj,
@Cached ToComplexValueNode toComplexLeft,
@Cached ToComplexValueNode toComplexRight,
@Cached InlinedConditionProfile notImplementedProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
if (notImplementedProfile.profile(inliningTarget, left == null || right == null)) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- return factory.createComplex(left.getReal() - right.getReal(), left.getImag() - right.getImag());
+ return PFactory.createComplex(language, left.getReal() - right.getReal(), left.getImag() - right.getImag());
}
}
@@ -537,7 +536,7 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
@Cached InlinedBranchProfile smallPositiveProfile,
@Cached InlinedBranchProfile smallNegativeProfile,
@Cached InlinedBranchProfile complexProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
@@ -547,24 +546,24 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
PComplex result;
if (right.getReal() == 0.0 && right.getImag() == 0.0) {
rightZeroProfile.enter(inliningTarget);
- result = factory.createComplex(1.0, 0.0);
+ result = PFactory.createComplex(language, 1.0, 0.0);
} else if (left.getReal() == 0.0 && left.getImag() == 0.0) {
leftZeroProfile.enter(inliningTarget);
if (right.getImag() != 0.0 || right.getReal() < 0.0) {
throw PRaiseNode.raiseUncached(inliningTarget, ZeroDivisionError, ErrorMessages.COMPLEX_ZERO_TO_NEGATIVE_POWER);
}
- result = factory.createComplex(0.0, 0.0);
+ result = PFactory.createComplex(language, 0.0, 0.0);
} else if (right.getImag() == 0.0 && right.getReal() == (int) right.getReal() && right.getReal() < 100 && right.getReal() > -100) {
if (right.getReal() >= 0) {
smallPositiveProfile.enter(inliningTarget);
- result = complexToSmallPositiveIntPower(left, (int) right.getReal(), factory);
+ result = complexToSmallPositiveIntPower(left, (int) right.getReal(), language);
} else {
smallNegativeProfile.enter(inliningTarget);
- result = DivNode.doubleDivComplex(1.0, complexToSmallPositiveIntPower(left, -(int) right.getReal(), factory), factory);
+ result = DivNode.doubleDivComplex(1.0, complexToSmallPositiveIntPower(left, -(int) right.getReal(), language), language);
}
} else {
complexProfile.enter(inliningTarget);
- result = complexToComplexBoundary(left.getReal(), left.getImag(), right.getReal(), right.getImag(), factory);
+ result = complexToComplexBoundary(left.getReal(), left.getImag(), right.getReal(), right.getImag(), language);
}
if (Double.isInfinite(result.getReal()) || Double.isInfinite(result.getImag())) {
throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.COMPLEX_EXPONENTIATION);
@@ -580,7 +579,7 @@ static Object error(Object left, Object right, Object mod,
throw raiseNode.raise(ValueError, ErrorMessages.COMPLEX_MODULO);
}
- private static PComplex complexToSmallPositiveIntPower(ComplexValue x, long n, PythonObjectFactory factory) {
+ private static PComplex complexToSmallPositiveIntPower(ComplexValue x, long n, PythonLanguage language) {
long mask = 1;
ComplexValue r = new ComplexValue(1.0, 0.0);
ComplexValue p = x;
@@ -591,11 +590,11 @@ private static PComplex complexToSmallPositiveIntPower(ComplexValue x, long n, P
mask <<= 1;
p = MulNode.multiply(p, p);
}
- return factory.createComplex(r.getReal(), r.getImag());
+ return PFactory.createComplex(language, r.getReal(), r.getImag());
}
@TruffleBoundary
- private static PComplex complexToComplexBoundary(double leftRead, double leftImag, double rightReal, double rightImag, PythonObjectFactory factory) {
+ private static PComplex complexToComplexBoundary(double leftRead, double leftImag, double rightReal, double rightImag, PythonLanguage language) {
PComplex result;
double vabs = Math.hypot(leftRead, leftImag);
double len = Math.pow(vabs, rightReal);
@@ -605,7 +604,7 @@ private static PComplex complexToComplexBoundary(double leftRead, double leftIma
len /= Math.exp(at * rightImag);
phase += rightImag * Math.log(vabs);
}
- result = factory.createComplex(len * Math.cos(phase), len * Math.sin(phase));
+ result = PFactory.createComplex(language, len * Math.cos(phase), len * Math.sin(phase));
return result;
}
}
@@ -806,9 +805,9 @@ abstract static class NegNode extends PythonUnaryBuiltinNode {
static PComplex neg(Object self,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
- return factory.createComplex(-c.getReal(), -c.getImag());
+ return PFactory.createComplex(language, -c.getReal(), -c.getImag());
}
}
@@ -819,9 +818,9 @@ abstract static class PosNode extends PythonUnaryBuiltinNode {
static PComplex pos(Object self,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
- return factory.createComplex(c.getReal(), c.getImag());
+ return PFactory.createComplex(language, c.getReal(), c.getImag());
}
}
@@ -832,9 +831,9 @@ abstract static class GetNewArgsNode extends PythonUnaryBuiltinNode {
static PTuple get(Object self,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
- return factory.createTuple(new Object[]{c.getReal(), c.getImag()});
+ return PFactory.createTuple(language, new Object[]{c.getReal(), c.getImag()});
}
}
@@ -893,9 +892,9 @@ abstract static class ConjugateNode extends PythonUnaryBuiltinNode {
static PComplex hash(Object self,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
- return factory.createComplex(c.getReal(), -c.getImag());
+ return PFactory.createComplex(language, c.getReal(), -c.getImag());
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
index 9e10d1ea1d..c63dbeaa3a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -64,7 +65,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -110,8 +111,8 @@ Object get(PContextVarsContext self, Object key,
public abstract static class Iter extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PContextVarsContext self,
- @Cached PythonObjectFactory factory) {
- return factory.createContextIterator(self, PContextIterator.ItemKind.KEYS);
+ @Bind PythonLanguage language) {
+ return PFactory.createContextIterator(language, self, PContextIterator.ItemKind.KEYS);
}
}
@@ -120,8 +121,8 @@ static Object iter(PContextVarsContext self,
public abstract static class Keys extends PythonUnaryBuiltinNode {
@Specialization
static Object keys(PContextVarsContext self,
- @Cached PythonObjectFactory factory) {
- return factory.createContextIterator(self, PContextIterator.ItemKind.KEYS);
+ @Bind PythonLanguage language) {
+ return PFactory.createContextIterator(language, self, PContextIterator.ItemKind.KEYS);
}
}
@@ -130,8 +131,8 @@ static Object keys(PContextVarsContext self,
public abstract static class Values extends PythonUnaryBuiltinNode {
@Specialization
static Object values(PContextVarsContext self,
- @Cached PythonObjectFactory factory) {
- return factory.createContextIterator(self, PContextIterator.ItemKind.VALUES);
+ @Bind PythonLanguage language) {
+ return PFactory.createContextIterator(language, self, PContextIterator.ItemKind.VALUES);
}
}
@@ -140,8 +141,8 @@ static Object values(PContextVarsContext self,
public abstract static class Items extends PythonUnaryBuiltinNode {
@Specialization
static Object items(PContextVarsContext self,
- @Cached PythonObjectFactory factory) {
- return factory.createContextIterator(self, PContextIterator.ItemKind.ITEMS);
+ @Bind PythonLanguage language) {
+ return PFactory.createContextIterator(language, self, PContextIterator.ItemKind.ITEMS);
}
}
@@ -169,8 +170,8 @@ static Object get(VirtualFrame frame, PContextVarsContext self, Object fun, Obje
public abstract static class Copy extends PythonUnaryBuiltinNode {
@Specialization
static Object doCopy(PContextVarsContext self,
- @Cached PythonObjectFactory factory) {
- PContextVarsContext ret = factory.createContextVarsContext();
+ @Bind PythonLanguage language) {
+ PContextVarsContext ret = PFactory.createContextVarsContext(language);
ret.contextVarValues = self.contextVarValues;
return ret;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
index fa79001cd4..cb57c10bfd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -52,7 +53,6 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -82,9 +82,9 @@ public abstract static class Next extends PythonUnaryBuiltinNode {
@Specialization
static Object next(PContextIterator self,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
- Object next = self.next(factory);
+ Object next = self.next(language);
if (next == null) {
throw raiseNode.get(inliningTarget).raiseStopIteration();
} else {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
index 8afad6b55f..9ed2bcdb6f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -58,7 +59,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -101,12 +102,12 @@ public abstract static class SetNode extends PythonBinaryBuiltinNode {
@Specialization
static Object set(PContextVar self, Object value,
@Bind("this") Node inliningTarget,
- @Bind PythonContext context,
- @Cached PythonObjectFactory factory) {
- PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
+ @Bind PythonContext context) {
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ PythonContext.PythonThreadState threadState = context.getThreadState(language);
Object oldValue = self.getValue(threadState);
self.setValue(threadState, value);
- return factory.createContextVarsToken(self, oldValue);
+ return PFactory.createContextVarsToken(language, self, oldValue);
}
}
@@ -150,8 +151,8 @@ static boolean isToken(Object obj) {
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextIterator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextIterator.java
index 17ab98a5e3..401b98a7f3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextIterator.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextIterator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,8 +40,9 @@
*/
package com.oracle.graal.python.builtins.objects.contextvars;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.object.Shape;
@@ -51,14 +52,14 @@ public enum ItemKind {
VALUES,
ITEMS;
- public Object apply(Hamt.Entry item, PythonObjectFactory factory) {
+ public Object apply(Hamt.Entry item, PythonLanguage language) {
switch (this) {
case KEYS:
return item.key;
case VALUES:
return item.value;
case ITEMS:
- return factory.createTuple(new Object[]{item.key, item.value});
+ return PFactory.createTuple(language, new Object[]{item.key, item.value});
default:
throw CompilerDirectives.shouldNotReachHere("null ItemKind in PHamtIterator");
}
@@ -76,8 +77,8 @@ public PContextIterator(Object cls, Shape instanceShape, PContextVarsContext ctx
}
// can return null
- public Object next(PythonObjectFactory factory) {
+ public Object next(PythonLanguage language) {
Hamt.Entry item = it.next();
- return item == null ? null : kind.apply(item, factory);
+ return item == null ? null : kind.apply(item, language);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/TokenBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/TokenBuiltins.java
index 231f12ad28..8b7d248873 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/TokenBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/TokenBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -54,8 +55,8 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -101,8 +102,8 @@ public void postInitialize(Python3Core core) {
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
index afaec0767f..b9ad4d96ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
@@ -77,6 +77,7 @@
import java.util.Iterator;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -95,6 +96,7 @@
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode;
@@ -124,7 +126,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -290,9 +292,11 @@ public abstract static class DequeCopyNode extends PythonUnaryBuiltinNode {
@Specialization
static PDeque doGeneric(PDeque self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
- PDeque copy = factory.createDeque(getClassNode.execute(inliningTarget, self));
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ Object cls = getClassNode.execute(inliningTarget, self);
+ PDeque copy = PFactory.createDeque(language, cls, getInstanceShape.execute(cls));
copy.setMaxLength(self.getMaxLength());
copy.addAll(self);
return copy;
@@ -720,7 +724,7 @@ public abstract static class DequeAddNode extends SqConcatBuiltinNode {
@Specialization
@TruffleBoundary
static PDeque doDeque(PDeque self, PDeque other) {
- PDeque newDeque = PythonObjectFactory.getUncached().createDeque();
+ PDeque newDeque = PFactory.createDeque(PythonLanguage.get(null));
newDeque.setMaxLength(self.getMaxLength());
newDeque.addAll(self);
newDeque.addAll(other);
@@ -790,7 +794,7 @@ public abstract static class DequeMulNode extends SqRepeatBuiltinNode {
@Specialization
@TruffleBoundary
PDeque doGeneric(PDeque self, int n) {
- PDeque newDeque = PythonObjectFactory.getUncached().createDeque();
+ PDeque newDeque = PFactory.createDeque(PythonLanguage.get(null));
newDeque.setMaxLength(self.getMaxLength());
newDeque.addAll(self);
return DequeInplaceMulNode.doGeneric(this, newDeque, n);
@@ -858,8 +862,8 @@ public abstract static class DequeIterNode extends PythonUnaryBuiltinNode {
@Specialization
static PDequeIter doGeneric(PDeque self,
- @Cached PythonObjectFactory factory) {
- return factory.createDequeIter(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createDequeIter(language, self);
}
}
@@ -870,8 +874,8 @@ public abstract static class DequeReversedNode extends PythonUnaryBuiltinNode {
@Specialization
static PDequeIter doGeneric(PDeque self,
- @Cached PythonObjectFactory factory) {
- return factory.createDequeRevIter(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createDequeRevIter(language, self);
}
}
@@ -890,7 +894,7 @@ TruffleString repr(PDeque self) {
Node outerNode = ref.set(this);
try {
Object[] items = self.data.toArray();
- PList asList = PythonObjectFactory.getUncached().createList(items);
+ PList asList = PFactory.createList(PythonLanguage.get(null), items);
int maxLength = self.getMaxLength();
TruffleStringBuilder sb = TruffleStringBuilder.create(TS_ENCODING);
sb.appendStringUncached(GetNameNode.executeUncached(GetPythonObjectClassNode.executeUncached(self)));
@@ -919,16 +923,16 @@ Object doGeneric(VirtualFrame frame, PDeque self,
@Cached PyObjectGetIter getIter,
@Cached PyObjectGetStateNode getStateNode,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object clazz = getClassNode.execute(inliningTarget, self);
Object state = getStateNode.execute(frame, inliningTarget, self);
Object it = getIter.execute(frame, inliningTarget, self);
- PTuple emptyTuple = factory.createEmptyTuple();
+ PTuple emptyTuple = PFactory.createEmptyTuple(language);
int maxLength = self.getMaxLength();
if (maxLength != -1) {
- return factory.createTuple(new Object[]{clazz, factory.createTuple(new Object[]{emptyTuple, maxLength}), state, it});
+ return PFactory.createTuple(language, new Object[]{clazz, PFactory.createTuple(language, new Object[]{emptyTuple, maxLength}), state, it});
}
- return factory.createTuple(new Object[]{clazz, emptyTuple, state, it});
+ return PFactory.createTuple(language, new Object[]{clazz, emptyTuple, state, it});
}
}
@@ -1069,8 +1073,8 @@ static Object doCmp(VirtualFrame frame, Object self, Object other,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
index 66e8f2e586..4f247352db 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import java.util.List;
import java.util.NoSuchElementException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -60,7 +61,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -137,9 +138,9 @@ public abstract static class DequeIterReduceNode extends PythonUnaryBuiltinNode
static PTuple doGeneric(PDequeIter self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object clazz = getClassNode.execute(inliningTarget, self);
- return factory.createTuple(new Object[]{clazz, factory.createTuple(new Object[]{self.deque, self.deque.getSize() - self.lengthHint()})});
+ return PFactory.createTuple(language, new Object[]{clazz, PFactory.createTuple(language, new Object[]{self.deque, self.deque.getSize() - self.lengthHint()})});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
index eefa3beb93..808dfc44b6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -75,7 +76,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -124,11 +125,11 @@ static Object reduce(VirtualFrame frame, PDefaultDict self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
final Object defaultFactory = self.getDefaultFactory();
- PTuple args = (defaultFactory == PNone.NONE) ? factory.createEmptyTuple() : factory.createTuple(new Object[]{defaultFactory});
- Object iter = getIter.execute(frame, inliningTarget, factory.createDictItemsView(self));
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args, PNone.NONE, PNone.NONE, iter});
+ PTuple args = (defaultFactory == PNone.NONE) ? PFactory.createEmptyTuple(language) : PFactory.createTuple(language, new Object[]{defaultFactory});
+ Object iter = getIter.execute(frame, inliningTarget, PFactory.createDictItemsView(language, self));
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args, PNone.NONE, PNone.NONE, iter});
}
}
@@ -140,8 +141,8 @@ public abstract static class CopyNode extends PythonUnaryBuiltinNode {
static PDefaultDict copy(@SuppressWarnings("unused") VirtualFrame frame, PDefaultDict self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory) {
- return factory.createDefaultDict(self.getDefaultFactory(), copyNode.execute(inliningTarget, self.getDictStorage()));
+ @Bind PythonLanguage language) {
+ return PFactory.createDefaultDict(language, self.getDefaultFactory(), copyNode.execute(inliningTarget, self.getDictStorage()));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
index 3a23d26d0b..d831723eb7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -236,14 +237,14 @@ static Object popItem(Object dict,
@Bind("this") Node inliningTarget,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStoragePop popNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
var storage = getStorageNode.execute(inliningTarget, dict);
Object[] result = popNode.execute(inliningTarget, storage, dict);
if (result == null) {
throw raiseNode.get(inliningTarget).raise(KeyError, ErrorMessages.IS_EMPTY, "popitem(): dictionary");
}
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
}
@@ -254,14 +255,14 @@ public abstract static class KeysNode extends PythonUnaryBuiltinNode {
@Specialization
static PDictView keys(PDict self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictKeysView(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createDictKeysView(language, self);
}
@Fallback
static PDictView foreign(Object self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictKeysView(self, new ForeignHashingStorage(self));
+ @Bind PythonLanguage language) {
+ return PFactory.createDictKeysView(language, self, new ForeignHashingStorage(self));
}
}
@@ -272,14 +273,14 @@ public abstract static class ItemsNode extends PythonUnaryBuiltinNode {
@Specialization
static PDictView items(PDict self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictItemsView(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createDictItemsView(language, self);
}
@Fallback
static PDictView foreign(Object self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictItemsView(self, new ForeignHashingStorage(self));
+ @Bind PythonLanguage language) {
+ return PFactory.createDictItemsView(language, self, new ForeignHashingStorage(self));
}
}
@@ -382,9 +383,9 @@ static Object run(Object self,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetIterator getIterator,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
var storage = getStorageNode.execute(inliningTarget, self);
- return factory.createDictKeyIterator(getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictKeyIterator(language, getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
@@ -397,9 +398,9 @@ static Object run(Object self,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetReverseIterator getReverseIterator,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
var storage = getStorageNode.execute(inliningTarget, self);
- return factory.createDictKeyIterator(getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictKeyIterator(language, getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
@@ -468,9 +469,9 @@ static PDict copy(Object dict,
@Bind("this") Node inliningTarget,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
var storage = getStorageNode.execute(inliningTarget, dict);
- return factory.createDict(copyNode.execute(inliningTarget, storage));
+ return PFactory.createDict(language, copyNode.execute(inliningTarget, storage));
}
}
@@ -499,14 +500,14 @@ public abstract static class ValuesNode extends PythonUnaryBuiltinNode {
@Specialization
static PDictView values(PDict self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictValuesView(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createDictValuesView(language, self);
}
@Fallback
static PDictView foreign(Object self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDictValuesView(self, new ForeignHashingStorage(self));
+ @Bind PythonLanguage language) {
+ return PFactory.createDictValuesView(language, self, new ForeignHashingStorage(self));
}
}
@@ -561,13 +562,13 @@ static Object error(Object self, Object[] args, PKeyword[] kwargs,
public abstract static class FromKeysNode extends PythonTernaryBuiltinNode {
@Specialization(guards = "isBuiltinDict(inliningTarget, cls, isSameTypeNode)", limit = "1")
- static Object doKeys(VirtualFrame frame, Object cls, Object iterable, Object value,
+ static Object doKeys(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object iterable, Object value,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Cached IsSameTypeNode isSameTypeNode,
@Cached HashingCollectionNodes.GetClonedHashingStorageNode getHashingStorageNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage s = getHashingStorageNode.execute(frame, inliningTarget, iterable, value);
- return factory.createDict(cls, s);
+ return PFactory.createDict(language, s);
}
@Fallback
@@ -609,9 +610,9 @@ static PDict or(VirtualFrame frame, Object self, Object other,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStorageCopy copyNode,
@Cached DictNodes.UpdateNode updateNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
var storage = getStorageNode.execute(inliningTarget, self);
- PDict merged = factory.createDict(copyNode.execute(inliningTarget, storage));
+ PDict merged = PFactory.createDict(language, copyNode.execute(inliningTarget, storage));
updateNode.execute(frame, merged, other);
return merged;
}
@@ -639,8 +640,8 @@ Object or(VirtualFrame frame, Object self, Object other,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java
index e442eb1674..010b4831f3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -30,6 +30,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -45,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -68,8 +69,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class MappingNode extends PythonUnaryBuiltinNode {
@Specialization
static Object mapping(PDictView self,
- @Cached PythonObjectFactory factory) {
- return factory.createMappingproxy(self.getWrappedDict());
+ @Bind PythonLanguage language) {
+ return PFactory.createMappingproxy(language, self.getWrappedDict());
}
}
@@ -93,9 +94,9 @@ static Object doPDictValuesView(PDictValuesView self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetIterator getIterator,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictValueIterator(getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictValueIterator(language, getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
@@ -107,9 +108,9 @@ static Object doPDictValuesView(PDictValuesView self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetReverseIterator getReverseIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictValueIterator(getReverseIter.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictValueIterator(language, getReverseIter.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictViewBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictViewBuiltins.java
index e93012e83c..f605099833 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictViewBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictViewBuiltins.java
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.truffle.api.CompilerDirectives;
@@ -131,8 +132,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class MappingNode extends PythonUnaryBuiltinNode {
@Specialization
static Object mapping(PDictView self,
- @Cached PythonObjectFactory factory) {
- return factory.createMappingproxy(self.getWrappedDict());
+ @Bind PythonLanguage language) {
+ return PFactory.createMappingproxy(language, self.getWrappedDict());
}
}
@@ -156,9 +157,9 @@ static Object getKeysViewIter(@SuppressWarnings("unused") PDictKeysView self,
@Bind("this") Node inliningTarget,
@Shared("len") @Cached HashingStorageLen lenNode,
@Shared("getit") @Cached HashingStorageGetIterator getIterator,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictKeyIterator(getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictKeyIterator(language, getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
@Specialization
@@ -166,9 +167,9 @@ static Object getItemsViewIter(PDictItemsView self,
@Bind("this") Node inliningTarget,
@Shared("len") @Cached HashingStorageLen lenNode,
@Shared("getit") @Cached HashingStorageGetIterator getIterator,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictItemIterator(getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictItemIterator(language, getIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
@@ -180,9 +181,9 @@ static Object getReversedKeysViewIter(PDictKeysView self,
@Bind("this") Node inliningTarget,
@Shared @Cached HashingStorageLen lenNode,
@Shared @Cached HashingStorageGetReverseIterator getReverseIterator,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictKeyIterator(getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictKeyIterator(language, getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
@Specialization
@@ -190,9 +191,9 @@ static Object getReversedItemsViewIter(PDictItemsView self,
@Bind("this") Node inliningTarget,
@Shared @Cached HashingStorageLen lenNode,
@Shared @Cached HashingStorageGetReverseIterator getReverseIterator,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getWrappedStorage();
- return factory.createDictItemIterator(getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
+ return PFactory.createDictItemIterator(language, getReverseIterator.execute(inliningTarget, storage), storage, lenNode.execute(inliningTarget, storage));
}
}
@@ -441,18 +442,18 @@ abstract static class SubNode extends BinaryOpBuiltinNode {
static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PBaseSet other,
@Bind("this") Node inliningTarget,
@Shared("diff") @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = diffNode.execute(frame, inliningTarget, self.getWrappedStorage(), other.getDictStorage());
- return factory.createSet(storage);
+ return PFactory.createSet(language, storage);
}
@Specialization
static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PDictKeysView other,
@Bind("this") Node inliningTarget,
@Shared("diff") @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = diffNode.execute(frame, inliningTarget, self.getWrappedStorage(), other.getWrappedStorage());
- return factory.createSet(storage);
+ return PFactory.createSet(language, storage);
}
@Specialization
@@ -460,11 +461,11 @@ static PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, Object other,
@Bind("this") Node inliningTarget,
@Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode,
@Shared("diff") @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage left = self.getWrappedStorage();
- HashingStorage right = constructSetNode.executeWith(frame, other).getDictStorage();
+ HashingStorage right = constructSetNode.execute(frame, other).getDictStorage();
HashingStorage storage = diffNode.execute(frame, inliningTarget, left, right);
- return factory.createSet(storage);
+ return PFactory.createSet(language, storage);
}
@Specialization
@@ -472,10 +473,10 @@ static PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PBaseSet ot
@Bind("this") Node inliningTarget,
@Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode,
@Shared("diff") @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
- PSet selfSet = constructSetNode.executeWith(frame, self);
+ @Bind PythonLanguage language) {
+ PSet selfSet = constructSetNode.execute(frame, self);
HashingStorage storage = diffNode.execute(frame, inliningTarget, selfSet.getDictStorage(), other.getDictStorage());
- return factory.createSet(storage);
+ return PFactory.createSet(language, storage);
}
@Specialization
@@ -483,11 +484,11 @@ static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other,
@Bind("this") Node inliningTarget,
@Shared("constrSet") @Cached SetNodes.ConstructSetNode constructSetNode,
@Shared("diff") @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
- HashingStorage left = constructSetNode.executeWith(frame, self).getDictStorage();
- HashingStorage right = constructSetNode.executeWith(frame, other).getDictStorage();
+ @Bind PythonLanguage language) {
+ HashingStorage left = constructSetNode.execute(frame, self).getDictStorage();
+ HashingStorage right = constructSetNode.execute(frame, other).getDictStorage();
HashingStorage storage = diffNode.execute(frame, inliningTarget, left, right);
- return factory.createSet(storage);
+ return PFactory.createSet(language, storage);
}
}
@@ -509,7 +510,7 @@ static HashingStorage doSet(PBaseSet obj) {
@Fallback
static HashingStorage doOther(VirtualFrame frame, Object obj,
@Cached SetNodes.ConstructSetNode constructSetNode) {
- return constructSetNode.executeWith(frame, obj).getDictStorage();
+ return constructSetNode.execute(frame, obj).getDictStorage();
}
}
@@ -533,7 +534,7 @@ static HashingStorage doSet(Node inliningTarget, PBaseSet obj,
@Fallback
static HashingStorage doOther(VirtualFrame frame, Object obj,
@Cached SetNodes.ConstructSetNode constructSetNode) {
- return constructSetNode.executeWith(frame, obj).getDictStorage();
+ return constructSetNode.execute(frame, obj).getDictStorage();
}
}
@@ -546,10 +547,10 @@ static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other,
@Bind("this") Node inliningTarget,
@Cached GetStorageForBinopNode getStorage,
@Cached HashingStorageIntersect intersectNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage left = getStorage.execute(frame, inliningTarget, self);
HashingStorage right = getStorage.execute(frame, inliningTarget, other);
- return factory.createSet(intersectNode.execute(frame, inliningTarget, left, right));
+ return PFactory.createSet(language, intersectNode.execute(frame, inliningTarget, left, right));
}
}
@@ -562,10 +563,10 @@ static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other,
@Bind("this") Node inliningTarget,
@Cached GetCopiedStorageForBinopNode getStorage,
@Cached HashingStorageAddAllToOther addAllToOther,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage left = getStorage.execute(frame, inliningTarget, self);
HashingStorage right = getStorage.execute(frame, inliningTarget, other);
- return factory.createSet(addAllToOther.execute(frame, inliningTarget, left, right));
+ return PFactory.createSet(language, addAllToOther.execute(frame, inliningTarget, left, right));
}
}
@@ -578,10 +579,10 @@ static PBaseSet doGeneric(VirtualFrame frame, Object self, Object other,
@Bind("this") Node inliningTarget,
@Cached GetStorageForBinopNode getStorage,
@Cached HashingStorageXor xor,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage left = getStorage.execute(frame, inliningTarget, self);
HashingStorage right = getStorage.execute(frame, inliningTarget, other);
- return factory.createSet(xor.execute(frame, inliningTarget, left, right));
+ return PFactory.createSet(language, xor.execute(frame, inliningTarget, left, right));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/EnumerateBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/EnumerateBuiltins.java
index 57f9e9dd34..1238532ef2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/EnumerateBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/EnumerateBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -32,6 +32,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -42,7 +43,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -67,12 +68,12 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doNext(VirtualFrame frame, PEnumerate self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile bigIntIndexProfile,
- @Cached GetNextNode next,
- @Cached PythonObjectFactory factory) {
- Object index = self.getAndIncrementIndex(inliningTarget, factory, bigIntIndexProfile);
+ @Cached GetNextNode next) {
+ Object index = self.getAndIncrementIndex(inliningTarget, language, bigIntIndexProfile);
Object nextValue = next.execute(frame, self.getDecoratedIterator());
- return factory.createTuple((new Object[]{index, nextValue}));
+ return PFactory.createTuple(language, (new Object[]{index, nextValue}));
}
}
@@ -92,13 +93,13 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
@Specialization
static Object reduce(PEnumerate self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile bigIntIndexProfile,
- @Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Cached GetClassNode getClassNode) {
Object iterator = self.getDecoratedIterator();
Object index = self.getIndex(inliningTarget, bigIntIndexProfile);
- PTuple contents = factory.createTuple(new Object[]{iterator, index});
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), contents});
+ PTuple contents = PFactory.createTuple(language, new Object[]{iterator, index});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), contents});
}
}
@@ -107,8 +108,8 @@ static Object reduce(PEnumerate self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/PEnumerate.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/PEnumerate.java
index 88d62ba68c..4cc18fb6e4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/PEnumerate.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/enumerate/PEnumerate.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -25,9 +25,10 @@
*/
package com.oracle.graal.python.builtins.objects.enumerate;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -53,10 +54,10 @@ public Object getDecoratedIterator() {
return iterator;
}
- public Object getAndIncrementIndex(Node inliningTarget, PythonObjectFactory factory, InlinedConditionProfile bigIntIndexProfile) {
+ public Object getAndIncrementIndex(Node inliningTarget, PythonLanguage language, InlinedConditionProfile bigIntIndexProfile) {
if (bigIntIndexProfile.profile(inliningTarget, bigIndex != null)) {
PInt idx = bigIndex;
- bigIndex = factory.createInt(bigIndex.inc());
+ bigIndex = PFactory.createInt(language, bigIndex.inc());
return idx;
}
return index++;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionAttrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionAttrNode.java
index 727aa9aa65..15bd3afcaa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionAttrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionAttrNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,7 +44,6 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.nodes.PGuards;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -59,11 +58,7 @@
@SuppressWarnings("truffle-inlining") // footprint reduction 36 -> 20
public abstract class BaseExceptionAttrNode extends Node {
public interface StorageFactory {
- Object[] create(Object[] args, PythonObjectFactory factory);
-
- default Object[] create(Object[] args) {
- return create(args, null);
- }
+ Object[] create(Object[] args);
default Object[] create() {
return create(null);
@@ -99,13 +94,12 @@ abstract static class EnsureAttrStorageNode extends Node {
static Object[] ensure(PBaseException self, StorageFactory storageFactory,
@Bind("this") Node inliningTarget,
@Cached ExceptionNodes.GetArgsNode getArgsNode,
- @Cached SequenceStorageNodes.GetInternalObjectArrayNode getInternalObjectArrayNode,
- @Cached PythonObjectFactory factory) {
+ @Cached SequenceStorageNodes.GetInternalObjectArrayNode getInternalObjectArrayNode) {
Object[] attributes = self.getExceptionAttributes();
if (attributes == null) {
PTuple argsTuple = getArgsNode.execute(inliningTarget, self);
Object[] args = getInternalObjectArrayNode.execute(inliningTarget, argsTuple.getSequenceStorage());
- attributes = storageFactory.create(args, factory);
+ attributes = storageFactory.create(args);
self.setExceptionAttributes(attributes);
}
return attributes;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
index aa6f045310..dd9ab9aa4d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -93,7 +94,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.nodes.util.SplitArgsNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
@@ -151,20 +152,22 @@ static Object doNoArguments(PBaseException self, @SuppressWarnings("unused") Obj
}
@Specialization(guards = {"args.length != 0", "keywords.length == 0"})
- Object doWithArguments(PBaseException self, Object[] args, @SuppressWarnings("unused") PKeyword[] keywords) {
- self.setArgs(factory().createTuple(args));
+ Object doWithArguments(PBaseException self, Object[] args, @SuppressWarnings("unused") PKeyword[] keywords,
+ @Bind PythonLanguage language) {
+ self.setArgs(PFactory.createTuple(language, args));
return PNone.NONE;
}
@Specialization(replaces = {"doNoArguments", "doWithArguments"})
- Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords) {
+ Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords,
+ @Bind PythonLanguage language) {
if (keywords.length != 0) {
throw raise(TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
}
if (args.length == 0) {
self.setArgs(null);
} else {
- self.setArgs(factory().createTuple(args));
+ self.setArgs(PFactory.createTuple(language, args));
}
return PNone.NONE;
}
@@ -172,14 +175,15 @@ Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords) {
@Specialization
Object doNative(PythonAbstractNativeObject self, Object[] args, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
- @Cached ExceptionNodes.SetArgsNode setArgsNode) {
+ @Cached ExceptionNodes.SetArgsNode setArgsNode,
+ @Bind PythonLanguage language) {
if (keywords.length != 0) {
throw raise(TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
}
if (args.length == 0) {
- setArgsNode.execute(inliningTarget, self, factory().createEmptyTuple());
+ setArgsNode.execute(inliningTarget, self, PFactory.createEmptyTuple(language));
} else {
- setArgsNode.execute(inliningTarget, self, factory().createTuple(args));
+ setArgsNode.execute(inliningTarget, self, PFactory.createTuple(language, args));
}
return PNone.NONE;
}
@@ -202,9 +206,9 @@ static Object args(VirtualFrame frame, Object self, Object value,
@Cached CastToListNode castToList,
@Cached SequenceStorageNodes.CopyInternalArrayNode copy,
@Cached ExceptionNodes.SetArgsNode setArgsNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PList list = castToList.execute(frame, value);
- setArgsNode.execute(inliningTarget, self, factory.createTuple(copy.execute(inliningTarget, list.getSequenceStorage())));
+ setArgsNode.execute(inliningTarget, self, PFactory.createTuple(language, copy.execute(inliningTarget, list.getSequenceStorage())));
return PNone.NONE;
}
}
@@ -397,11 +401,11 @@ static Object reduce(VirtualFrame frame, Object self,
@Cached GetClassNode getClassNode,
@Cached ExceptionNodes.GetArgsNode argsNode,
@Cached DictNode dictNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object clazz = getClassNode.execute(inliningTarget, self);
PTuple args = argsNode.execute(inliningTarget, self);
Object dict = dictNode.execute(frame, self, PNone.NO_VALUE);
- return factory.createTuple(new Object[]{clazz, args, dict});
+ return PFactory.createTuple(language, new Object[]{clazz, args, dict});
}
}
@@ -536,14 +540,14 @@ Object addNote(VirtualFrame frame, Object self, Object note,
@Cached PyObjectLookupAttr lookupAttr,
@Cached PyObjectSetAttr setAttr,
@Cached ListNodes.AppendNode appendNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, note)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOTE_MUST_BE_A_STR_NOT_P, note);
}
Object notes = lookupAttr.execute(frame, inliningTarget, self, T___NOTES__);
if (notes == PNone.NO_VALUE) {
- notes = factory.createList();
+ notes = PFactory.createList(language);
setAttr.execute(frame, inliningTarget, self, T___NOTES__, notes);
}
if (notes instanceof PList notesList) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
index 6f59828fca..3192501836 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
@@ -88,8 +88,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -116,12 +115,12 @@ public void postInitialize(Python3Core core) {
private static void createExceptionGroupType(Python3Core core) {
PythonModule builtins = core.getBuiltins();
+ PythonLanguage language = core.getLanguage();
Object typeBuiltin = builtins.getAttribute(T_TYPE);
- PythonObjectSlowPathFactory factory = core.factory();
- PTuple bases = factory.createTuple(new Object[]{PythonBuiltinClassType.PBaseExceptionGroup, PythonBuiltinClassType.Exception});
+ PTuple bases = PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PBaseExceptionGroup, PythonBuiltinClassType.Exception});
EconomicMapStorage dictStorage = EconomicMapStorage.create(1);
dictStorage.putUncachedWithJavaEq(T___MODULE__, T_BUILTINS);
- PDict dict = factory.createDict(dictStorage);
+ PDict dict = PFactory.createDict(language, dictStorage);
Object exceptionGroupType = CallNode.executeUncached(typeBuiltin, T_EXCEPTION_GROUP, bases, dict);
builtins.setAttribute(T_EXCEPTION_GROUP, exceptionGroupType);
}
@@ -166,8 +165,8 @@ static TruffleString message(PBaseExceptionGroup self) {
abstract static class ExceptionsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object exceptions(PBaseExceptionGroup self,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(self.getExceptions());
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, self.getExceptions());
}
}
@@ -188,8 +187,7 @@ private static PBaseExceptionGroup subset(Node inliningTarget, PBaseExceptionGro
if (exceptions.length == 0) {
return null;
}
- PythonObjectSlowPathFactory factory = PythonContext.get(inliningTarget).factory();
- Object egObj = PyObjectCallMethodObjArgs.executeUncached(orig, T_DERIVE, factory.createTuple(exceptions));
+ Object egObj = PyObjectCallMethodObjArgs.executeUncached(orig, T_DERIVE, PFactory.createTuple(PythonLanguage.get(null), exceptions));
if (!(egObj instanceof PBaseExceptionGroup eg)) {
throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.DERIVE_MUST_RETURN_AN_INSTANCE_OF_BASE_EXCEPTION_GROUP);
}
@@ -257,7 +255,7 @@ private static boolean splitCheckMatch(Object exception, MatcherType matcherType
private record SplitResult(Object match, Object rest) {
static final SplitResult EMPTY = new SplitResult(null, null);
- };
+ }
@TruffleBoundary
private static SplitResult splitRecursive(Node inliningTarget, Object exception, MatcherType matcherType, Object matcherValue, boolean constructRest) {
@@ -310,8 +308,7 @@ abstract static class SplitNode extends PythonBinaryBuiltinNode {
@Specialization
static Object split(VirtualFrame frame, PBaseExceptionGroup self, Object matcherValue,
@Bind("this") Node inliningTarget,
- @Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PythonObjectFactory factory) {
+ @Cached("createFor(this)") IndirectCallData indirectCallData) {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
Object state = IndirectCallContext.enter(frame, language, context, indirectCallData);
@@ -327,7 +324,7 @@ static Object split(VirtualFrame frame, PBaseExceptionGroup self, Object matcher
}
Object match = result.match != null ? result.match : PNone.NONE;
Object rest = result.rest != null ? result.rest : PNone.NONE;
- return factory.createTuple(new Object[]{match, rest});
+ return PFactory.createTuple(language, new Object[]{match, rest});
}
}
@@ -360,8 +357,8 @@ static Object subgroup(VirtualFrame frame, PBaseExceptionGroup self, Object matc
abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
index 263294cf73..4a8bbdadcb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.IllegalFormatException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
@@ -62,11 +63,11 @@
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.formatting.ErrorMessageFormatter;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -382,17 +383,17 @@ private static String getFormattedMessage(TruffleString format, Object... args)
@Specialization
static PTuple doManaged(Node inliningTarget, PBaseException self,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile nullArgsProfile,
@Cached InlinedConditionProfile hasMessageFormat,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode) {
PTuple args = self.getArgs();
if (nullArgsProfile.profile(inliningTarget, args == null)) {
if (hasMessageFormat.profile(inliningTarget, !self.hasMessageFormat())) {
- args = factory.createEmptyTuple();
+ args = PFactory.createEmptyTuple(language);
} else {
// lazily format the exception message:
- args = factory.createTuple(new Object[]{fromJavaStringNode.execute(getFormattedMessage(self.getMessageFormat(), self.getMessageArgs()), TS_ENCODING)});
+ args = PFactory.createTuple(language, new Object[]{fromJavaStringNode.execute(getFormattedMessage(self.getMessageFormat(), self.getMessageArgs()), TS_ENCODING)});
}
self.setArgs(args);
}
@@ -408,7 +409,7 @@ static PTuple doNative(@SuppressWarnings("unused") Node inliningTarget, PythonAb
@Specialization
static PTuple doInterop(AbstractTruffleException exception,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode) {
assert IsForeignObjectNode.executeUncached(exception);
@@ -422,9 +423,9 @@ static PTuple doInterop(AbstractTruffleException exception,
}
if (interop.hasMetaObject(exception)) {
- return factory.createTuple(new Object[]{concat(getMetaObjectName(exception), message)});
+ return PFactory.createTuple(language, new Object[]{concat(getMetaObjectName(exception), message)});
} else {
- return factory.createTuple(new Object[]{message});
+ return PFactory.createTuple(language, new Object[]{message});
}
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
index f3a69f4d82..5622884d95 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -70,7 +71,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
import com.oracle.graal.python.nodes.util.SplitArgsNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -94,7 +95,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
protected static final int IDX_PATH = 2;
public static final int IMPORT_ERR_NUM_ATTRS = IDX_PATH + 1;
- public static final BaseExceptionAttrNode.StorageFactory IMPORT_ERROR_ATTR_FACTORY = (args, factory) -> {
+ public static final BaseExceptionAttrNode.StorageFactory IMPORT_ERROR_ATTR_FACTORY = (args) -> {
Object[] attrs = new Object[IMPORT_ERR_NUM_ATTRS];
if (args.length == 1) {
attrs[IDX_MSG] = args[0];
@@ -136,7 +137,7 @@ Object init(PBaseException self, Object[] args, PKeyword[] kwargs,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode,
@Cached TruffleString.EqualNode equalNode) {
baseExceptionInitNode.execute(self, args);
- Object[] attrs = IMPORT_ERROR_ATTR_FACTORY.create(args, null);
+ Object[] attrs = IMPORT_ERROR_ATTR_FACTORY.create(args);
for (PKeyword kw : kwargs) {
TruffleString kwName = kw.getName();
if (equalNode.execute(kwName, NAME, TS_ENCODING)) {
@@ -186,7 +187,7 @@ Object generic(PBaseException self, Object value,
@GenerateNodeFactory
public abstract static class ImportErrorReduceNode extends PythonUnaryBuiltinNode {
private static Object getState(Node inliningTarget, PBaseException self, GetDictIfExistsNode getDictIfExistsNode, HashingStorageSetItem setHashingStorageItem,
- HashingStorageCopy copyStorageNode, BaseExceptionAttrNode attrNode, PythonObjectFactory factory) {
+ HashingStorageCopy copyStorageNode, BaseExceptionAttrNode attrNode, PythonLanguage language) {
PDict dict = getDictIfExistsNode.execute(self);
final Object name = attrNode.get(self, IDX_NAME, IMPORT_ERROR_ATTR_FACTORY);
final Object path = attrNode.get(self, IDX_PATH, IMPORT_ERROR_ATTR_FACTORY);
@@ -198,7 +199,7 @@ private static Object getState(Node inliningTarget, PBaseException self, GetDict
if (path != null) {
storage = setHashingStorageItem.execute(inliningTarget, storage, T_PATH, path);
}
- return factory.createDict(storage);
+ return PFactory.createDict(language, storage);
} else if (dict != null) {
return dict;
} else {
@@ -215,14 +216,14 @@ static Object reduce(PBaseException self,
@Cached ExceptionNodes.GetArgsNode getArgsNode,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached HashingStorageCopy copyStorageNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object clazz = getClassNode.execute(inliningTarget, self);
Object args = getArgsNode.execute(inliningTarget, self);
- Object state = getState(inliningTarget, self, getDictIfExistsNode, setHashingStorageItem, copyStorageNode, attrNode, factory);
+ Object state = getState(inliningTarget, self, getDictIfExistsNode, setHashingStorageItem, copyStorageNode, attrNode, language);
if (state == PNone.NONE) {
- return factory.createTuple(new Object[]{clazz, args});
+ return PFactory.createTuple(language, new Object[]{clazz, args});
}
- return factory.createTuple(new Object[]{clazz, args, state});
+ return PFactory.createTuple(language, new Object[]{clazz, args, state});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
index ba106fac08..0ce7bf5ca3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -62,6 +62,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -76,6 +77,7 @@
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyArgCheckPositionalNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
@@ -91,7 +93,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
@@ -117,7 +119,7 @@ public final class OsErrorBuiltins extends PythonBuiltins {
public static final int IDX_WRITTEN = 5;
public static final int OS_ERR_NUM_ATTRS = IDX_WRITTEN + 1;
- public static final BaseExceptionAttrNode.StorageFactory OS_ERROR_ATTR_FACTORY = (args, factory) -> {
+ public static final BaseExceptionAttrNode.StorageFactory OS_ERROR_ATTR_FACTORY = (args) -> {
final Object[] attrs = new Object[OS_ERR_NUM_ATTRS];
attrs[IDX_WRITTEN] = -1;
return attrs;
@@ -273,7 +275,8 @@ static Object newCData(VirtualFrame frame, Object subType, Object[] args, PKeywo
@Cached PyNumberAsSizeNode pyNumberAsSizeNode,
@Cached PyArgCheckPositionalNode checkPositionalNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
Object type = subType;
Object[] parsedArgs = new Object[IDX_WRITTEN + 1];
@@ -295,11 +298,11 @@ static Object newCData(VirtualFrame frame, Object subType, Object[] args, PKeywo
}
}
- PBaseException self = factory.createBaseException(type);
+ PBaseException self = PFactory.createBaseException(language, type, getInstanceShape.execute(type));
if (!osErrorUseInit(frame, inliningTarget, core, type, getAttr)) {
osErrorInit(frame, inliningTarget, self, type, args, parsedArgs, pyNumberCheckNode, pyNumberAsSizeNode, baseInitNode);
} else {
- self.setArgs(factory.createEmptyTuple());
+ self.setArgs(PFactory.createEmptyTuple(language));
}
return self;
}
@@ -472,7 +475,7 @@ static Object reduce(PBaseException self,
@Cached GetClassNode getClassNode,
@Cached GetDictIfExistsNode getDictNode,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PTuple args = getArgsNode.execute(inliningTarget, self);
final Object filename = attrNode.get(self, IDX_FILENAME, OS_ERROR_ATTR_FACTORY);
final Object filename2 = attrNode.get(self, IDX_FILENAME2, OS_ERROR_ATTR_FACTORY);
@@ -488,15 +491,15 @@ static Object reduce(PBaseException self,
argData[3] = PNone.NONE;
argData[4] = filename2;
}
- args = factory.createTuple(argData);
+ args = PFactory.createTuple(language, argData);
}
final Object type = getClassNode.execute(inliningTarget, self);
final PDict dict = getDictNode.execute(self);
if (dict != null) {
- return factory.createTuple(new Object[]{type, args, dict});
+ return PFactory.createTuple(language, new Object[]{type, args, dict});
} else {
- return factory.createTuple(new Object[]{type, args});
+ return PFactory.createTuple(language, new Object[]{type, args});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
index 68ea9891c9..6eb9abba49 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -172,7 +173,7 @@ private static PBaseException handleInstanceNotAnException(Object type, Object i
* Instead of throwing the exception here, we replace the created exception with it. This is
* done to match CPython's behavior of `generator.throw`
*/
- return PythonObjectFactory.getUncached().createBaseException(TypeError, ErrorMessages.CALLING_N_SHOULD_HAVE_RETURNED_AN_INSTANCE_OF_BASE_EXCEPTION_NOT_P, new Object[]{type, instance});
+ return PFactory.createBaseException(PythonLanguage.get(null), TypeError, ErrorMessages.CALLING_N_SHOULD_HAVE_RETURNED_AN_INSTANCE_OF_BASE_EXCEPTION_NOT_P, new Object[]{type, instance});
}
private static void checkExceptionClass(Object type, IsSubtypeNode isSubtypeNode, PRaiseNode raiseNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/StopIterationBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/StopIterationBuiltins.java
index 2a4b436cbf..44b13078b1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/StopIterationBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/StopIterationBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -64,7 +64,7 @@
@CoreFunctions(extendClasses = PythonBuiltinClassType.StopIteration)
public final class StopIterationBuiltins extends PythonBuiltins {
- public static final BaseExceptionAttrNode.StorageFactory STOP_ITERATION_ATTR_FACTORY = (args, factory) -> new Object[]{(args != null && args.length > 0) ? args[0] : PNone.NONE};
+ public static final BaseExceptionAttrNode.StorageFactory STOP_ITERATION_ATTR_FACTORY = (args) -> new Object[]{(args != null && args.length > 0) ? args[0] : PNone.NONE};
@Override
protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFactories() {
@@ -94,7 +94,7 @@ public final Object varArgExecute(VirtualFrame frame, Object self, Object[] argu
static Object init(PBaseException self, Object[] args,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode) {
baseExceptionInitNode.execute(self, args);
- self.setExceptionAttributes(STOP_ITERATION_ATTR_FACTORY.create(args, null));
+ self.setExceptionAttributes(STOP_ITERATION_ATTR_FACTORY.create(args));
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
index e929e4184f..76c04f6394 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -94,7 +94,7 @@ public final class SyntaxErrorBuiltins extends PythonBuiltins {
public static final int IDX_PRINT_FILE_AND_LINE = 7;
public static final int SYNTAX_ERR_NUM_ATTRS = IDX_PRINT_FILE_AND_LINE + 1;
- public static final BaseExceptionAttrNode.StorageFactory SYNTAX_ERROR_ATTR_FACTORY = (args, factory) -> new Object[SYNTAX_ERR_NUM_ATTRS];
+ public static final BaseExceptionAttrNode.StorageFactory SYNTAX_ERROR_ATTR_FACTORY = (args) -> new Object[SYNTAX_ERR_NUM_ATTRS];
@Override
protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFactories() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SystemExitBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SystemExitBuiltins.java
index 79b59ad75d..d1cbdc2a64 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SystemExitBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SystemExitBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -51,7 +52,7 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -65,7 +66,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
return SystemExitBuiltinsFactory.getFactories();
}
- public static final BaseExceptionAttrNode.StorageFactory SYSTEM_EXIT_ATTR_FACTORY = (args, factory) -> {
+ public static final BaseExceptionAttrNode.StorageFactory SYSTEM_EXIT_ATTR_FACTORY = (args) -> {
Object code;
switch (args.length) {
case 0:
@@ -75,7 +76,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
code = args[0];
break;
default:
- code = factory.createTuple(args);
+ code = PFactory.createTuple(PythonLanguage.get(null), args);
}
return new Object[]{code};
};
@@ -85,10 +86,9 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
public abstract static class InitNode extends PythonBuiltinNode {
@Specialization
static Object initNoArgs(PBaseException self, Object[] args,
- @Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode,
- @Cached PythonObjectFactory factory) {
+ @Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode) {
baseExceptionInitNode.execute(self, args);
- self.setExceptionAttributes(SYSTEM_EXIT_ATTR_FACTORY.create(args, factory));
+ self.setExceptionAttributes(SYSTEM_EXIT_ATTR_FACTORY.create(args));
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
index ed6fa8973d..9420fe0832 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -60,7 +61,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -84,7 +85,7 @@ public final class UnicodeErrorBuiltins extends PythonBuiltins {
public static final int IDX_REASON = 4;
public static final int UNICODE_ERR_NUM_ATTRS = IDX_REASON + 1;
- public static final BaseExceptionAttrNode.StorageFactory UNICODE_ERROR_ATTR_FACTORY = (args, factory) -> new Object[UNICODE_ERR_NUM_ATTRS];
+ public static final BaseExceptionAttrNode.StorageFactory UNICODE_ERROR_ATTR_FACTORY = (args) -> new Object[UNICODE_ERR_NUM_ATTRS];
@Override
protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFactories() {
@@ -115,11 +116,11 @@ public abstract static class GetArgAsBytesNode extends PNodeWithContext {
@Specialization
@TruffleBoundary
static PBytes doString(TruffleString value,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// TODO GR-37601: cbasca cPython works directly with bytes while we have Java strings
// which are encoded, here we decode using the system encoding but this might not be the
// correct / ideal case
- return factory.createBytes(value.toJavaStringUncached().getBytes());
+ return PFactory.createBytes(language, value.toJavaStringUncached().getBytes());
}
@Specialization
@@ -131,11 +132,11 @@ static PBytes doBytes(PBytes value) {
static PBytes doOther(VirtualFrame frame, Object value,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
final byte[] buffer = bufferLib.getInternalOrCopiedByteArray(value);
final int bufferLength = bufferLib.getBufferLength(value);
- return factory.createBytes(buffer, 0, bufferLength);
+ return PFactory.createBytes(language, buffer, bufferLength);
} finally {
bufferLib.release(value, frame, indirectCallData);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
index 385c5254f5..8d15d6345f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
@@ -54,6 +54,7 @@
import java.nio.ByteOrder;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -95,7 +96,7 @@
import com.oracle.graal.python.runtime.formatting.FloatFormatter;
import com.oracle.graal.python.runtime.formatting.InternalFormat;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -403,8 +404,8 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
if (left < 0 && Double.isFinite(left) && Double.isFinite(right) && (right % 1 != 0)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
// Negative numbers raised to fractional powers become complex.
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- throw new UnexpectedResultException(powerNode.execute(frame, inliningTarget, factory.createComplex(left, 0), factory.createComplex(right, 0), none));
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
+ throw new UnexpectedResultException(powerNode.execute(frame, inliningTarget, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none));
}
return Math.pow(left, right);
}
@@ -414,15 +415,14 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone none,
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberPowerNode powerNode,
- @Exclusive @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
return 1.0;
}
if (left < 0 && Double.isFinite(left) && Double.isFinite(right) && (right % 1 != 0)) {
// Negative numbers raised to fractional powers become complex.
- PythonObjectFactory pof = factory.get(inliningTarget);
- return powerNode.execute(frame, inliningTarget, pof.createComplex(left, 0), pof.createComplex(right, 0), none);
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
+ return powerNode.execute(frame, inliningTarget, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none);
}
return Math.pow(left, right);
}
@@ -433,7 +433,6 @@ static Object doGeneric(VirtualFrame frame, Object left, Object right, Object mo
@Bind("this") Node inliningTarget,
@Cached CastToJavaDoubleNode castToJavaDoubleNode,
@Shared @Cached PyNumberPowerNode powerNode,
- @Exclusive @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (!(mod instanceof PNone)) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.POW_3RD_ARG_NOT_ALLOWED_UNLESS_INTEGERS);
@@ -446,7 +445,7 @@ static Object doGeneric(VirtualFrame frame, Object left, Object right, Object mo
} catch (CannotCastException e) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, inliningTarget, powerNode, factory, raiseNode);
+ return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, inliningTarget, powerNode, raiseNode);
}
public static PowNode create() {
@@ -467,12 +466,12 @@ protected Object op(double left, double right) {
@Slot(value = SlotKind.nb_divmod, isComplex = true)
@GenerateNodeFactory
abstract static class DivModNode extends AbstractNumericBinaryBuiltin {
- @Child private PythonObjectFactory factory = PythonObjectFactory.create();
@Override
protected PTuple op(double left, double right) {
raiseDivisionByZero(right == 0);
- return factory.createTuple(new Object[]{Math.floor(left / right), ModNode.mod(left, right)});
+ PythonLanguage language = PythonLanguage.get(this);
+ return PFactory.createTuple(language, new Object[]{Math.floor(left / right), ModNode.mod(left, right)});
}
}
@@ -700,11 +699,11 @@ static Object round(VirtualFrame frame, Object x, Object n,
@Specialization
static Object round(Object xObj, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached CastToJavaDoubleNode cast,
@Cached InlinedConditionProfile nanProfile,
@Cached InlinedConditionProfile infProfile,
@Cached InlinedConditionProfile isLongProfile,
- @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
double x = castToDoubleChecked(inliningTarget, xObj, cast);
if (nanProfile.profile(inliningTarget, Double.isNaN(x))) {
@@ -715,7 +714,7 @@ static Object round(Object xObj, @SuppressWarnings("unused") PNone none,
}
double result = round(x, 0, inliningTarget, raiseNode);
if (isLongProfile.profile(inliningTarget, result > Long.MAX_VALUE || result < Long.MIN_VALUE)) {
- return factory.get(inliningTarget).createInt(toBigInteger(result));
+ return PFactory.createInt(language, toBigInteger(result));
} else {
return (long) result;
}
@@ -963,10 +962,10 @@ abstract static class AsIntegerRatio extends PythonUnaryBuiltinNode {
@Specialization
static PTuple get(Object selfObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached CastToJavaDoubleNode cast,
@Cached InlinedConditionProfile nanProfile,
@Cached InlinedConditionProfile infProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
double self = castToDoubleChecked(inliningTarget, selfObj, cast);
if (nanProfile.profile(inliningTarget, Double.isNaN(self))) {
@@ -1007,11 +1006,11 @@ static PTuple get(Object selfObj,
}
// count the ratio
- return factory.createTuple(countIt(mantissa, exponent));
+ return PFactory.createTuple(language, countIt(language, mantissa, exponent));
}
@TruffleBoundary
- private static Object[] countIt(double mantissa, int exponent) {
+ private static Object[] countIt(PythonLanguage language, double mantissa, int exponent) {
double m = mantissa;
int e = exponent;
for (int i = 0; i < 300 && Double.compare(m, Math.floor(m)) != 0; i++) {
@@ -1030,8 +1029,7 @@ private static Object[] countIt(double mantissa, int exponent) {
if (numerator.bitLength() < Long.SIZE && denominator.bitLength() < Long.SIZE) {
return new Object[]{numerator.longValue(), denominator.longValue()};
}
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- return new Object[]{factory.createInt(numerator), factory.createInt(denominator)};
+ return new Object[]{PFactory.createInt(language, numerator), PFactory.createInt(language, denominator)};
}
}
@@ -1097,11 +1095,10 @@ protected Object op(double value) {
@Builtin(name = J___GETNEWARGS__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
abstract static class GetNewArgsNode extends AbstractNumericUnaryBuiltin {
- @Child private PythonObjectFactory factory = PythonObjectFactory.create();
-
@Override
protected Object op(double self) {
- return factory.createTuple(new Object[]{factory.createFloat(self)});
+ PythonLanguage language = PythonLanguage.get(this);
+ return PFactory.createTuple(language, new Object[]{PFactory.createFloat(language, self)});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignAbstractClassBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignAbstractClassBuiltins.java
index 48cfd68373..cbc0b82c5f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignAbstractClassBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignAbstractClassBuiltins.java
@@ -26,6 +26,12 @@
package com.oracle.graal.python.builtins.objects.foreign;
+import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___BASES__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INSTANCECHECK__;
+
+import java.util.List;
+
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -34,9 +40,9 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.GilNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.util.PythonUtils;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -45,11 +51,6 @@
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
-import java.util.List;
-
-import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___BASES__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INSTANCECHECK__;
-
/*
* NOTE: We are not using IndirectCallContext here in this file
* because it seems unlikely that these interop messages would call back to Python
@@ -68,8 +69,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class BasesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object getBases(Object self,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
+ @Bind PythonLanguage language) {
+ return PFactory.createEmptyTuple(language);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index 86ef886d58..127f6073b4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -93,7 +94,7 @@
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -170,13 +171,13 @@ long doLong(Object obj,
@Specialization(guards = {"!lib.fitsInLong(obj)", "lib.fitsInBigInteger(obj)"})
PInt doBigInt(Object obj,
+ @Bind PythonLanguage language,
@Shared @CachedLibrary(limit = "3") InteropLibrary lib,
- @Shared @Cached(inline = false) GilNode gil,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Shared @Cached(inline = false) GilNode gil) {
assert !lib.isBoolean(obj);
gil.release(true);
try {
- return factory.createInt(lib.asBigInteger(obj));
+ return PFactory.createInt(language, lib.asBigInteger(obj));
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} finally {
@@ -667,10 +668,10 @@ protected EqNode() {
abstract static class IndexNode extends PythonUnaryBuiltinNode {
@Specialization(limit = "3")
protected static Object doIt(Object object,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode,
@CachedLibrary("object") InteropLibrary lib,
- @Cached GilNode gil,
- @Cached PythonObjectFactory factory) {
+ @Cached GilNode gil) {
assert !lib.isBoolean(object);
gil.release(true);
try {
@@ -693,7 +694,7 @@ protected static Object doIt(Object object,
if (lib.fitsInBigInteger(object)) {
try {
var big = lib.asBigInteger(object);
- return factory.createInt(big);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), big);
} catch (UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalStateException("foreign value claims to be a big integer but isn't");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
index ea386f7fed..6f2172be6a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
@@ -68,7 +68,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -89,6 +89,7 @@
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
/*
@@ -276,8 +277,8 @@ protected Object doIt(Object object,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "3") InteropLibrary lib,
@Cached GilNode gil,
- @Cached PythonObjectFactory.Lazy factory) {
- if (lib.hasMembers(object)) {
+ @Cached InlinedConditionProfile profile) {
+ if (profile.profile(inliningTarget, lib.hasMembers(object))) {
gil.release(true);
try {
return lib.getMembers(object);
@@ -288,7 +289,7 @@ protected Object doIt(Object object,
gil.acquire();
}
} else {
- return factory.get(inliningTarget).createList();
+ return PFactory.createList(PythonLanguage.get(inliningTarget));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
index e2e34ad12c..17fad7107d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
@@ -30,6 +30,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -59,7 +60,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.RootCallTarget;
@@ -110,8 +111,7 @@ public abstract static class GetGlobalsNode extends PythonBuiltinNode {
public abstract Object execute(VirtualFrame frame, PFrame self);
@Specialization
- Object get(VirtualFrame curFrame, PFrame self,
- @Cached PythonObjectFactory factory) {
+ Object get(VirtualFrame curFrame, PFrame self) {
PythonObject globals = self.getGlobals();
if (globals instanceof PythonModule) {
if (getDictNode == null) {
@@ -120,7 +120,7 @@ Object get(VirtualFrame curFrame, PFrame self,
}
return getDictNode.execute(curFrame, globals, PNone.NO_VALUE);
} else {
- return globals != null ? globals : factory.createDict();
+ return globals != null ? globals : PFactory.createDict(PythonLanguage.get(this));
}
}
@@ -274,10 +274,10 @@ public abstract static class GetCodeNode extends PythonBuiltinNode {
@Specialization
static PCode get(PFrame self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
RootCallTarget ct = self.getTarget();
assert ct != null;
- return factory.createCode(ct);
+ return PFactory.createCode(language, ct);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
index 0582591478..a3263bbdb2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -71,7 +72,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -83,6 +84,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.strings.TruffleStringBuilder;
@@ -119,12 +121,12 @@ protected Object doIt(VirtualFrame frame, PBuiltinFunction self, Object[] argume
public abstract static class GetClosureNode extends PythonBuiltinNode {
@Specialization(guards = "!isBuiltinFunction(self)")
Object getClosure(PFunction self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PCell[] closure = self.getClosure();
if (closure == null) {
return PNone.NONE;
}
- return factory.createTuple(closure);
+ return PFactory.createTuple(language, closure);
}
@SuppressWarnings("unused")
@@ -221,10 +223,11 @@ static Object getModule(PFunction self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Cached ReadAttributeFromObjectNode readObject,
@Shared @Cached WriteAttributeToObjectNode writeObject,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached InlinedBranchProfile createAnnotations) {
Object annotations = readObject.execute(self, T___ANNOTATIONS__);
if (annotations == PNone.NO_VALUE) {
- annotations = factory.get(inliningTarget).createDict();
+ createAnnotations.enter(inliningTarget);
+ annotations = PFactory.createDict(PythonLanguage.get(inliningTarget));
writeObject.execute(self, T___ANNOTATIONS__, annotations);
}
return annotations;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
index 2a98c32ba2..eee179f311 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -41,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -59,7 +60,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -133,11 +134,11 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
Object doBuiltinFunc(VirtualFrame frame, PBuiltinFunction func,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttr,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = getContext().getBuiltins();
Object getattr = getAttr.execute(frame, inliningTarget, builtins, T_GETATTR);
- PTuple args = factory.createTuple(new Object[]{func.getEnclosingType(), func.getName()});
- return factory.createTuple(new Object[]{getattr, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{func.getEnclosingType(), func.getName()});
+ return PFactory.createTuple(language, new Object[]{getattr, args});
}
}
@@ -214,7 +215,7 @@ public static Object createInspectSignature(Signature signature, boolean skipSel
parameters.add(callNode.executeWithoutFrame(inspectParameter, StringLiterals.T_KWARGS, ParameterKinds.VAR_KEYWORD.get(parameterKinds, inspectParameter)));
}
- return callNode.executeWithoutFrame(inspectSignature, PythonObjectFactory.getUncached().createTuple(parameters.toArray()));
+ return callNode.executeWithoutFrame(inspectSignature, PFactory.createTuple(PythonLanguage.get(null), parameters.toArray()));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
index 95372770ba..9e6033f13a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -44,6 +44,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -106,8 +107,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
public abstract static class GetNode extends DescrGetBuiltinNode {
@Specialization(guards = {"!isPNone(instance)"})
static PMethod doMethod(PFunction self, Object instance, @SuppressWarnings("unused") Object klass,
- @Cached PythonObjectFactory factory) {
- return factory.createMethod(instance, self);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, instance, self);
}
@Specialization
@@ -176,10 +177,10 @@ static Object setQualname(PFunction self, Object value,
public abstract static class GetDefaultsNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(defaults)")
static Object defaults(PFunction self, @SuppressWarnings("unused") PNone defaults,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] argDefaults = self.getDefaults();
assert argDefaults != null;
- return (argDefaults.length == 0) ? PNone.NONE : factory.createTuple(argDefaults);
+ return (argDefaults.length == 0) ? PNone.NONE : PFactory.createTuple(language, argDefaults);
}
@Specialization
@@ -215,9 +216,9 @@ static Object setDefaults(Object self, Object defaults,
public abstract static class GetKeywordDefaultsNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(arg)")
static Object get(PFunction self, @SuppressWarnings("unused") PNone arg,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PKeyword[] kwdefaults = self.getKwDefaults();
- return (kwdefaults.length > 0) ? factory.createDict(kwdefaults) : PNone.NONE;
+ return (kwdefaults.length > 0) ? PFactory.createDict(language, kwdefaults) : PNone.NONE;
}
@Specialization(guards = "!isNoValue(arg)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
index 7aa0278c7f..591a6b8b28 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -59,9 +60,9 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -85,8 +86,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
public abstract static class GetNode extends DescrGetBuiltinNode {
@Specialization(guards = "!isNoValue(instance)")
static PMethod doMethod(PFunction self, Object instance, Object klass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createMethod(instance, self);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, instance, self);
}
@Specialization(guards = "isNoValue(instance)")
@@ -96,14 +97,14 @@ static Object doFunction(PFunction self, Object instance, Object klass) {
@Specialization(guards = {"!isNoValue(instance)", "!self.needsDeclaringType()"})
static PBuiltinMethod doBuiltinMethod(PBuiltinFunction self, Object instance, Object klass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBuiltinMethod(instance, self);
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, instance, self);
}
@Specialization(guards = {"!isNoValue(instance)", "self.needsDeclaringType()"})
static PBuiltinMethod doBuiltinMethodWithDeclaringClass(PBuiltinFunction self, Object instance, Object klass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBuiltinMethod(instance, self, self.getEnclosingType());
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, instance, self, self.getEnclosingType());
}
@Specialization(guards = "isNoValue(instance)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java
index 9d452b879a..8cde706221 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -31,6 +31,7 @@
import java.lang.invoke.VarHandle;
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.BoundBuiltinCallable;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -45,7 +46,7 @@
import com.oracle.graal.python.nodes.PRootNode;
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -250,11 +251,11 @@ public String toString() {
}
@Override
- public PBuiltinFunction boundToObject(PythonBuiltinClassType klass, PythonObjectFactory factory) {
+ public PBuiltinFunction boundToObject(PythonBuiltinClassType klass, PythonLanguage language) {
if (klass == enclosingType) {
return this;
} else {
- PBuiltinFunction func = factory.createBuiltinFunction(this, klass);
+ PBuiltinFunction func = PFactory.createBuiltinFunction(language, this, klass);
func.setAttribute(T___DOC__, getAttribute(T___DOC__));
return func;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
index 64ebc9484e..973253baff 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -59,9 +60,9 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -85,8 +86,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
public abstract static class GetNode extends DescrGetBuiltinNode {
@Specialization(guards = {"!isNoValue(instance)"})
static PMethod doMethod(PFunction self, Object instance, Object klass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createMethod(PythonBuiltinClassType.MethodWrapper, instance, self);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, PythonBuiltinClassType.MethodWrapper, PythonBuiltinClassType.MethodWrapper.getInstanceShape(language), instance, self);
}
@Specialization(guards = "isNoValue(instance)")
@@ -96,8 +97,8 @@ static Object doFunction(PFunction self, Object instance, Object klass) {
@Specialization(guards = {"!isNoValue(instance)"})
static PBuiltinMethod doBuiltinMethod(PBuiltinFunction self, Object instance, Object klass,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBuiltinMethod(PythonBuiltinClassType.MethodWrapper, instance, self);
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, PythonBuiltinClassType.MethodWrapper, PythonBuiltinClassType.MethodWrapper.getInstanceShape(language), instance, self);
}
@Specialization(guards = "isNoValue(instance)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
index 0a204506da..21e76b2010 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -77,7 +77,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.RootCallTarget;
@@ -288,7 +288,6 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
@Cached ExceptionNodes.GetTracebackNode getTracebackNode,
@Cached ExceptionNodes.SetTracebackNode setTracebackNode,
@Cached ExceptionNodes.SetContextNode setContextNode,
- @Cached PythonObjectFactory.Lazy factory,
@Cached PRaiseNode.Lazy raiseNode) {
boolean hasTb = hasTbProfile.profile(inliningTarget, !(tb instanceof PNone));
if (hasTb && !(tb instanceof PTraceback)) {
@@ -321,11 +320,11 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
self.markAsFinished();
Node location = self.getCurrentCallTarget().getRootNode();
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(self.getArguments());
- PFrame pFrame = MaterializeFrameNode.materializeGeneratorFrame(location, generatorFrame, PFrame.Reference.EMPTY, factory.get(inliningTarget));
+ PFrame pFrame = MaterializeFrameNode.materializeGeneratorFrame(location, generatorFrame, PFrame.Reference.EMPTY);
FrameInfo info = (FrameInfo) generatorFrame.getFrameDescriptor().getInfo();
pFrame.setLine(info.getRootNode().getFirstLineno());
Object existingTracebackObj = getTracebackNode.execute(inliningTarget, instance);
- PTraceback newTraceback = factory.get(inliningTarget).createTraceback(pFrame, pFrame.getLine(),
+ PTraceback newTraceback = PFactory.createTraceback(language, pFrame, pFrame.getLine(),
(existingTracebackObj instanceof PTraceback existingTraceback) ? existingTraceback : null);
setTracebackNode.execute(inliningTarget, instance, newTraceback);
throw PException.fromObject(instance, location, PythonOptions.isPExceptionWithJavaStacktrace(language));
@@ -343,13 +342,12 @@ static Object close(VirtualFrame frame, PGenerator self,
@Cached IsBuiltinObjectProfile isStopIteration,
@Cached ResumeGeneratorNode resumeGeneratorNode,
@Cached InlinedConditionProfile isStartedPorfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (self.isRunning()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
}
if (isStartedPorfile.profile(inliningTarget, self.isStarted() && !self.isFinished())) {
- PBaseException pythonException = factory.createBaseException(GeneratorExit);
+ PBaseException pythonException = PFactory.createBaseException(PythonLanguage.get(inliningTarget), GeneratorExit);
// Pass it to the generator where it will be thrown by the last yield, the location
// will be filled there
boolean withJavaStacktrace = PythonOptions.isPExceptionWithJavaStacktrace(PythonLanguage.get(inliningTarget));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java
index 3ffbaacefe..495c3ed66f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -54,7 +55,7 @@
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -78,9 +79,8 @@ public abstract static class GetCode extends PythonUnaryBuiltinNode {
@Specialization
static Object getCode(PGenerator self,
@Bind("this") Node inliningTarget,
- @Cached InlinedConditionProfile hasCodeProfile,
- @Cached PythonObjectFactory.Lazy factory) {
- return self.getOrCreateCode(inliningTarget, hasCodeProfile, factory);
+ @Cached InlinedConditionProfile hasCodeProfile) {
+ return self.getOrCreateCode(inliningTarget, hasCodeProfile);
}
}
@@ -127,8 +127,8 @@ static boolean suspended(PGenerator self) {
abstract static class AwaitNode extends PythonUnaryBuiltinNode {
@Specialization
static Object await(PGenerator self,
- @Cached PythonObjectFactory factory) {
- return factory.createCoroutineWrapper(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createCoroutineWrapper(language, self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
index f4dd2ac5af..18ebb0b5a0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -38,6 +38,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -157,9 +158,8 @@ public abstract static class GetCodeNode extends PythonUnaryBuiltinNode {
@Specialization
static Object getCode(PGenerator self,
@Bind("this") Node inliningTarget,
- @Cached InlinedConditionProfile hasCodeProfile,
- @Cached PythonObjectFactory.Lazy factory) {
- return self.getOrCreateCode(inliningTarget, hasCodeProfile, factory);
+ @Cached InlinedConditionProfile hasCodeProfile) {
+ return self.getOrCreateCode(inliningTarget, hasCodeProfile);
}
}
@@ -182,14 +182,13 @@ static Object setRunning(@SuppressWarnings("unused") PGenerator self, @SuppressW
@GenerateNodeFactory
public abstract static class GetFrameNode extends PythonUnaryBuiltinNode {
@Specialization
- static Object getFrame(PGenerator self,
- @Cached PythonObjectFactory factory) {
+ static Object getFrame(PGenerator self) {
if (self.isFinished()) {
return PNone.NONE;
} else {
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(self.getArguments());
Node location = ((FrameInfo) generatorFrame.getFrameDescriptor().getInfo()).getRootNode();
- PFrame frame = MaterializeFrameNode.materializeGeneratorFrame(location, generatorFrame, PFrame.Reference.EMPTY, factory);
+ PFrame frame = MaterializeFrameNode.materializeGeneratorFrame(location, generatorFrame, PFrame.Reference.EMPTY);
FrameInfo info = (FrameInfo) generatorFrame.getFrameDescriptor().getInfo();
int bci = self.getBci();
frame.setBci(bci);
@@ -233,8 +232,8 @@ static TruffleString repr(PGenerator self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java
index 2325e7cfc9..89df69e533 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -35,7 +35,7 @@
import com.oracle.graal.python.nodes.bytecode.GeneratorYieldResult;
import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode;
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
@@ -155,11 +155,11 @@ public final String toString() {
return "";
}
- public final PCode getOrCreateCode(Node inliningTarget, InlinedConditionProfile hasCodeProfile, PythonObjectFactory.Lazy factory) {
+ public final PCode getOrCreateCode(Node inliningTarget, InlinedConditionProfile hasCodeProfile) {
if (hasCodeProfile.profile(inliningTarget, code == null)) {
RootCallTarget callTarget;
callTarget = bytecodeRootNode.getCallTarget();
- code = factory.get(inliningTarget).createCode(callTarget);
+ code = PFactory.createCode(PythonLanguage.get(inliningTarget), callTarget);
}
return code;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptor.java
index e148bf4e8c..c928893384 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,7 +47,7 @@
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.nodes.SpecialAttributeNames;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
@@ -102,11 +102,11 @@ public boolean allowsDelete() {
return allowsDelete;
}
- public GetSetDescriptor boundToObject(PythonBuiltinClassType klass, PythonObjectFactory factory) {
+ public GetSetDescriptor boundToObject(PythonBuiltinClassType klass, PythonLanguage language) {
if (klass == type) {
return this;
} else {
- return factory.createGetSetDescriptor(get, set, getName(), klass, allowsDelete);
+ return PFactory.createGetSetDescriptor(language, get, set, getName(), klass, allowsDelete);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/MemberDescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/MemberDescriptorBuiltins.java
index 880a385966..6771172fd3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/MemberDescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/MemberDescriptorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -109,10 +110,10 @@ abstract static class MemberDescriptorReduceNode extends PythonUnaryBuiltinNode
Object doGeneric(GetSetDescriptor descr,
@Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
@Cached GetIdNode getIdNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object getattr = readAttributeFromObjectNode.execute(getContext().getBuiltins(), BuiltinNames.T_GETATTR);
Object id = getIdNode.execute(getattr);
- return factory.createTuple(new Object[]{id, factory.createTuple(new Object[]{descr.getType(), descr.getName()})});
+ return PFactory.createTuple(language, new Object[]{id, PFactory.createTuple(language, new Object[]{descr.getType(), descr.getName()})});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index 8b0ff103c2..896ce7003a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -69,6 +69,7 @@
import java.math.RoundingMode;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -118,7 +119,7 @@
import com.oracle.graal.python.runtime.formatting.IntegerFormatter;
import com.oracle.graal.python.runtime.formatting.InternalFormat;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
@@ -194,70 +195,70 @@ static long roundLongNone(long arg, PNone n) {
@Specialization
static PInt roundPIntNone(PInt arg, PNone n,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
- return factory.get(inliningTarget).createInt(arg.getValue());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, arg.getValue());
}
@Specialization
static Object roundLongInt(long arg, int n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n >= 0) {
return arg;
}
- return makeInt(inliningTarget, op(arg, n), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg, n), intOverflow, longOverflow);
}
@Specialization
static Object roundPIntInt(PInt arg, int n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n >= 0) {
return arg;
}
- return makeInt(inliningTarget, op(arg.getValue(), n), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg.getValue(), n), intOverflow, longOverflow);
}
@Specialization
static Object roundLongLong(long arg, long n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n >= 0) {
return arg;
}
if (n < Integer.MIN_VALUE) {
return 0;
}
- return makeInt(inliningTarget, op(arg, (int) n), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg, (int) n), intOverflow, longOverflow);
}
@Specialization
static Object roundPIntLong(PInt arg, long n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n >= 0) {
return arg;
}
if (n < Integer.MIN_VALUE) {
return 0;
}
- return makeInt(inliningTarget, op(arg.getValue(), (int) n), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg.getValue(), (int) n), intOverflow, longOverflow);
}
@Specialization
static Object roundPIntLong(long arg, PInt n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n.isZeroOrPositive()) {
return arg;
}
try {
- return makeInt(inliningTarget, op(arg, n.intValueExact()), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg, n.intValueExact()), intOverflow, longOverflow);
} catch (OverflowException e) {
// n is < -2^31, max. number of base-10 digits in BigInteger is 2^31 * log10(2)
return 0;
@@ -268,12 +269,12 @@ static Object roundPIntLong(long arg, PInt n,
static Object roundPIntPInt(PInt arg, PInt n,
@Bind("this") Node inliningTarget,
@Shared("intOvf") @Cached InlinedBranchProfile intOverflow,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared("longOvf") @Cached InlinedBranchProfile longOverflow) {
if (n.isZeroOrPositive()) {
return arg;
}
try {
- return makeInt(inliningTarget, op(arg.getValue(), n.intValueExact()), intOverflow, factory);
+ return makeInt(inliningTarget, op(arg.getValue(), n.intValueExact()), intOverflow, longOverflow);
} catch (OverflowException e) {
// n is < -2^31, max. number of base-10 digits in BigInteger is 2^31 * log10(2)
return 0;
@@ -287,7 +288,7 @@ static Object roundPIntPInt(Object arg, Object n,
throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, n);
}
- private static Object makeInt(Node inliningTarget, BigDecimal d, InlinedBranchProfile intOverflow, PythonObjectFactory.Lazy factory) {
+ private static Object makeInt(Node inliningTarget, BigDecimal d, InlinedBranchProfile intOverflow, InlinedBranchProfile longOverflow) {
try {
return intValueExact(d);
} catch (OverflowException e) {
@@ -298,10 +299,10 @@ private static Object makeInt(Node inliningTarget, BigDecimal d, InlinedBranchPr
return longValueExact(d);
} catch (OverflowException e) {
// does not fit long, try BigInteger
+ longOverflow.enter(inliningTarget);
}
try {
- // lazy factory initialization should serve as branch profile
- return factory.get(inliningTarget).createInt(toBigIntegerExact(d));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), toBigIntegerExact(d));
} catch (OverflowException e) {
// has non-zero fractional part, which should not happen
throw CompilerDirectives.shouldNotReachHere("non-integer produced after rounding an integer", e);
@@ -374,12 +375,12 @@ static long addLong(long left, long right) {
@Specialization
static Object addLongWithOverflow(long x, long y,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
/* Inlined version of Math.addExact(x, y) with BigInteger fallback. */
long r = x + y;
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
if (((x ^ r) & (y ^ r)) < 0) {
- return factory.createInt(op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ return PFactory.createInt(language, op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
}
return r;
}
@@ -391,8 +392,8 @@ static Object addPIntLongAndNarrow(PInt left, long right) throws OverflowExcepti
@Specialization(replaces = "addPIntLongAndNarrow")
static Object addPIntLong(PInt left, long right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -402,8 +403,8 @@ static Object addLongPIntAndNarrow(long left, PInt right) throws OverflowExcepti
@Specialization(replaces = "addLongPIntAndNarrow")
static Object addLongPInt(long left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(PInt.longToBigInteger(left), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -413,8 +414,8 @@ static Object addPIntPIntAndNarrow(PInt left, PInt right) throws OverflowExcepti
@Specialization(replaces = "addPIntPIntAndNarrow")
static Object addPIntPInt(PInt left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@TruffleBoundary
@@ -463,13 +464,13 @@ static long doLL(long x, long y) throws ArithmeticException {
@Specialization
static Object doLongWithOverflow(long x, long y,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind("this") Node inliningTarget) {
/* Inlined version of Math.subtractExact(x, y) with BigInteger fallback. */
long r = x - y;
// HD 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of x
if (((x ^ y) & (x ^ r)) < 0) {
- return factory.createInt(op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
}
return r;
}
@@ -481,8 +482,8 @@ static long doPIntLongAndNarrow(PInt left, long right) throws OverflowException
@Specialization(replaces = "doPIntLongAndNarrow")
static PInt doPIntLong(PInt left, long right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -492,8 +493,8 @@ static long doLongPIntAndNarrow(long left, PInt right) throws OverflowException
@Specialization(replaces = "doLongPIntAndNarrow")
static PInt doLongPInt(long left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(PInt.longToBigInteger(left), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -503,8 +504,8 @@ static long doPIntPIntAndNarrow(PInt left, PInt right) throws OverflowException
@Specialization(replaces = "doPIntPIntAndNarrow")
static PInt doPIntPInt(PInt left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@TruffleBoundary
@@ -663,12 +664,11 @@ static Object doLL(long left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
if (left == Long.MIN_VALUE && right == -1) {
overflowValueProfile.enter();
- return factory.createInt(LONG_OVERFLOW_VALUE);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), LONG_OVERFLOW_VALUE);
}
return Math.floorDiv(left, right);
}
@@ -697,14 +697,13 @@ static Object doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
long rightValue = right.longValueExact();
raiseDivisionByZero(inliningTarget, rightValue == 0, divisionByZeroProfile, raiseNode);
if (left == Long.MIN_VALUE && rightValue == -1) {
overflowValueProfile.enter();
- return factory.createInt(LONG_OVERFLOW_VALUE);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), LONG_OVERFLOW_VALUE);
}
return Math.floorDiv(left, rightValue);
} catch (OverflowException e) {
@@ -724,11 +723,11 @@ static long doPiIAndNarrow(PInt left, int right,
@Specialization(replaces = "doPiIAndNarrow")
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -743,11 +742,11 @@ static long doPiLAndNarrow(PInt left, long right,
@Specialization(replaces = "doPiLAndNarrow")
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
@@ -762,11 +761,11 @@ static long doPiPiAndNarrow(PInt left, PInt right,
@Specialization(replaces = "doPiPiAndNarrow")
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
- return factory.createInt(op(left.getValue(), right.getValue()));
+ return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@TruffleBoundary
@@ -798,15 +797,15 @@ abstract static class DivModNode extends BinaryOpBuiltinNode {
@Specialization
static Object doGeneric(VirtualFrame frame, Object left, Object right,
+ @Bind("this") Node inliningTarget,
@Cached FloorDivNode floorDivNode,
- @Cached ModNode modNode,
- @Cached PythonObjectFactory factory) {
+ @Cached ModNode modNode) {
Object div = floorDivNode.execute(frame, left, right);
if (div == PNotImplemented.NOT_IMPLEMENTED) {
return PNotImplemented.NOT_IMPLEMENTED;
}
Object mod = modNode.execute(frame, left, right);
- return factory.createTuple(new Object[]{div, mod});
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{div, mod});
}
}
@@ -848,11 +847,11 @@ static long doLPiAndNarrow(long left, PInt right,
@Specialization(guards = "right.isZeroOrPositive()", replaces = "doLPiAndNarrow")
static PInt doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
- return factory.createInt(op(PInt.longToBigInteger(left), right.getValue()));
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(guards = "!right.isZeroOrPositive()", rewriteOn = OverflowException.class)
@@ -867,11 +866,11 @@ static long doLPiNegativeAndNarrow(long left, PInt right,
@Specialization(guards = "!right.isZeroOrPositive()", replaces = "doLPiNegativeAndNarrow")
static PInt doLPiNegative(long left, PInt right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
- return factory.createInt(opNeg(PInt.longToBigInteger(left), right.getValue()));
+ return PFactory.createInt(language, opNeg(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(guards = "right >= 0", rewriteOn = OverflowException.class)
@@ -886,11 +885,11 @@ static long doPiLAndNarrow(PInt left, long right,
@Specialization(guards = "right >= 0", replaces = "doPiLAndNarrow")
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(guards = "right < 0", rewriteOn = OverflowException.class)
@@ -905,11 +904,11 @@ static long doPiLNegAndNarrow(PInt left, long right,
@Specialization(guards = "right < 0", replaces = "doPiLNegAndNarrow")
static PInt doPiLNeg(PInt left, long right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
- return factory.createInt(opNeg(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, opNeg(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(guards = "right.isZeroOrPositive()", rewriteOn = OverflowException.class)
@@ -924,11 +923,11 @@ static long doPiPiAndNarrow(PInt left, PInt right,
@Specialization(guards = "right.isZeroOrPositive()", replaces = "doPiPiAndNarrow")
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
- return factory.createInt(op(left.getValue(), right.getValue()));
+ return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@Specialization(guards = "!right.isZeroOrPositive()", rewriteOn = OverflowException.class)
@@ -938,8 +937,8 @@ static long doPiPiNegAndNarrow(PInt left, PInt right) throws OverflowException {
@Specialization(guards = "!right.isZeroOrPositive()", replaces = "doPiPiNegAndNarrow")
static PInt doPiPiNeg(PInt left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(opNeg(left.getValue(), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, opNeg(left.getValue(), right.getValue()));
}
@TruffleBoundary
@@ -994,7 +993,7 @@ static long doLL(long x, long y) {
@Specialization
static Object doLongWithOverflow(long x, long y,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind("this") Node inliningTarget) {
/* Inlined version of Math.multiplyExact(x, y) with BigInteger fallback. */
long r = x * y;
long ax = Math.abs(x);
@@ -1005,7 +1004,7 @@ static Object doLongWithOverflow(long x, long y,
// and check for the special case of Long.MIN_VALUE * -1
if (((y != 0) && (r / y != x)) ||
(x == Long.MIN_VALUE && y == -1)) {
- return factory.createInt(mul(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), mul(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
}
}
return r;
@@ -1023,33 +1022,33 @@ static int doPIntLongZero(@SuppressWarnings("unused") long left, @SuppressWarnin
@Specialization(guards = "right == 1")
static PInt doPIntLongOne(PInt left, @SuppressWarnings("unused") long right,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// we must return a new object with the same value
- return factory.createInt(left.getValue());
+ return PFactory.createInt(language, left.getValue());
}
@Specialization(guards = "left == 1")
PInt doPIntLongOne(@SuppressWarnings("unused") long left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(right.getValue());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, right.getValue());
}
@Specialization(guards = {"right != 0", "right != 1"})
static PInt doPIntLong(PInt left, long right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(mul(left.getValue(), PInt.longToBigInteger(right)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, mul(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(guards = {"left != 0", "left != 1"})
PInt doPIntLong(long left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(mul(PInt.longToBigInteger(left), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, mul(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization
static PInt doPIntPInt(PInt left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(mul(left.getValue(), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, mul(left.getValue(), right.getValue()));
}
@TruffleBoundary
@@ -1139,8 +1138,8 @@ static long doLLFast(long left, long right, @SuppressWarnings("unused") PNone no
@Specialization(guards = "right >= 0", replaces = "doLLFast")
@InliningCutoff
PInt doLLPos(long left, long right, @SuppressWarnings("unused") PNone none,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(PInt.longToBigInteger(left), right));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), right));
}
@Specialization(guards = "right < 0")
@@ -1170,11 +1169,10 @@ Object doLPNarrow(long left, PInt right, @SuppressWarnings("unused") PNone none,
@Specialization(replaces = "doLPNarrow")
@InliningCutoff
- Object doLP(long left, PInt right, @SuppressWarnings("unused") PNone none,
- @Shared @Cached PythonObjectFactory factory) {
+ Object doLP(long left, PInt right, @SuppressWarnings("unused") PNone none) {
Object result = op(PInt.longToBigInteger(left), right.getValue());
if (result instanceof BigInteger) {
- return factory.createInt((BigInteger) result);
+ return PFactory.createInt(PythonLanguage.get(this), (BigInteger) result);
} else {
return result;
}
@@ -1189,8 +1187,8 @@ long doPLNarrow(PInt left, long right, @SuppressWarnings("unused") PNone none) t
@Specialization(guards = "right >= 0", replaces = "doPLNarrow")
@InliningCutoff
PInt doPLPos(PInt left, long right, @SuppressWarnings("unused") PNone none,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), right));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), right));
}
@Specialization(guards = "right < 0")
@@ -1208,11 +1206,10 @@ PInt doPLPos(PInt left, long right, @SuppressWarnings("unused") PNone none,
@Specialization
@InliningCutoff
- Object doPP(PInt left, PInt right, @SuppressWarnings("unused") PNone none,
- @Shared @Cached PythonObjectFactory factory) {
+ Object doPP(PInt left, PInt right, @SuppressWarnings("unused") PNone none) {
Object result = op(left.getValue(), right.getValue());
if (result instanceof BigInteger) {
- return factory.createInt((BigInteger) result);
+ return PFactory.createInt(PythonLanguage.get(this), (BigInteger) result);
} else {
return result;
}
@@ -1254,8 +1251,7 @@ static long doLLPosLGeneric(long left, long right, long mod,
// see cpython://Objects/longobject.c#long_pow
@Specialization(replaces = "doPP")
@InliningCutoff
- Object powModulo(Object x, Object y, Object z,
- @Shared @Cached PythonObjectFactory factory) {
+ Object powModulo(Object x, Object y, Object z) {
if (!(MathGuards.isInteger(x) && MathGuards.isInteger(y))) {
return PNotImplemented.NOT_IMPLEMENTED;
}
@@ -1268,7 +1264,7 @@ Object powModulo(Object x, Object y, Object z,
return PNotImplemented.NOT_IMPLEMENTED;
}
if (result instanceof BigInteger) {
- return factory.createInt((BigInteger) result);
+ return PFactory.createInt(PythonLanguage.get(this), (BigInteger) result);
} else {
return result;
}
@@ -1409,16 +1405,14 @@ static Object absInt(int arg) {
@Specialization
static Object absLong(long arg,
- @Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
- return PInt.abs(inliningTarget, arg, factory);
+ @Bind("this") Node inliningTarget) {
+ return PInt.abs(inliningTarget, arg);
}
@Specialization
static PInt absPInt(PInt arg,
- @Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
- return factory.get(inliningTarget).createInt(arg.abs());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, arg.abs());
}
@Specialization
@@ -1463,8 +1457,8 @@ static long floor(long arg) {
@Specialization
static PInt floor(PInt arg,
- @Cached PythonObjectFactory factory) {
- return factory.createInt(arg.getValue());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, arg.getValue());
}
}
@@ -1483,8 +1477,8 @@ static Long pos(Long arg) {
@Specialization
static PInt pos(PInt arg,
- @Cached PythonObjectFactory factory) {
- return factory.createInt(arg.getValue());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, arg.getValue());
}
@Specialization
@@ -1515,15 +1509,15 @@ static long neg(long arg) {
@Specialization
static PInt negOvf(long arg,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
BigInteger value = arg == Long.MIN_VALUE ? negate(PInt.longToBigInteger(arg)) : PInt.longToBigInteger(-arg);
- return factory.createInt(value);
+ return PFactory.createInt(language, value);
}
@Specialization
static PInt doPInt(PInt operand,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(negate(operand.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, negate(operand.getValue()));
}
@Specialization
@@ -1562,8 +1556,8 @@ static long neg(long arg) {
@Specialization
static PInt doPInt(PInt operand,
- @Cached PythonObjectFactory factory) {
- return factory.createInt(not(operand.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, not(operand.getValue()));
}
@TruffleBoundary
@@ -1627,13 +1621,12 @@ static int doII(int left, int right,
@Specialization
static Object doIIOvf(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
try {
return leftShiftExact(inliningTarget, left, right, raiseNode);
} catch (OverflowException e) {
- return doGuardedBiI(inliningTarget, PInt.longToBigInteger(left), right, factory, raiseNode);
+ return doGuardedBiI(inliningTarget, PInt.longToBigInteger(left), right, raiseNode);
}
}
@@ -1648,23 +1641,20 @@ static long doLL(long left, long right,
@Specialization
static Object doILOvf(int left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doLLOvf(left, right, inliningTarget, factory, raiseNode);
+ return doLLOvf(left, right, inliningTarget, raiseNode);
}
@Specialization
static Object doLIOvf(long left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doLLOvf(left, right, inliningTarget, factory, raiseNode);
+ return doLLOvf(left, right, inliningTarget, raiseNode);
}
@Specialization
static Object doLLOvf(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
try {
@@ -1673,7 +1663,7 @@ static Object doLLOvf(long left, long right,
int rightI = (int) right;
if (rightI == right) {
try {
- return factory.createInt(op(PInt.longToBigInteger(left), rightI));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), op(PInt.longToBigInteger(left), rightI));
} catch (OverflowException ex) {
// fallback to the raise of overflow error
}
@@ -1690,15 +1680,15 @@ static int doIPiZero(@SuppressWarnings("unused") int left, @SuppressWarnings("un
@Specialization(replaces = "doIPiZero")
static PInt doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
if (left == 0) {
- return factory.createInt(BigInteger.ZERO);
+ return PFactory.createInt(language, BigInteger.ZERO);
}
try {
int iright = right.intValueExact();
- return factory.createInt(op(PInt.longToBigInteger(left), iright));
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), iright));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
}
@@ -1714,15 +1704,15 @@ static int doLPiZero(@SuppressWarnings("unused") long left, @SuppressWarnings("u
@Specialization(replaces = "doLPiZero")
static PInt doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
if (left == 0) {
- return factory.createInt(BigInteger.ZERO);
+ return PFactory.createInt(language, BigInteger.ZERO);
}
try {
int iright = right.intValueExact();
- return factory.createInt(op(PInt.longToBigInteger(left), iright));
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), iright));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
}
@@ -1731,15 +1721,14 @@ static PInt doLPi(long left, PInt right,
@Specialization
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
- return doGuardedBiI(inliningTarget, left.getValue(), right, factory, raiseNode);
+ return doGuardedBiI(inliningTarget, left.getValue(), right, raiseNode);
}
- static PInt doGuardedBiI(Node inliningTarget, BigInteger left, int right, PythonObjectFactory factory, PRaiseNode.Lazy raiseNode) {
+ static PInt doGuardedBiI(Node inliningTarget, BigInteger left, int right, PRaiseNode.Lazy raiseNode) {
try {
- return factory.createInt(op(left, right));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), op(left, right));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
}
@@ -1748,11 +1737,10 @@ static PInt doGuardedBiI(Node inliningTarget, BigInteger left, int right, Python
@Specialization
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
int rightI = (int) right;
if (rightI == right) {
- return doPiI(left, rightI, inliningTarget, factory, raiseNode);
+ return doPiI(left, rightI, inliningTarget, raiseNode);
} else {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
}
@@ -1766,14 +1754,14 @@ static int doPiPiZero(@SuppressWarnings("unused") PInt left, @SuppressWarnings("
@Specialization(replaces = "doPiPiZero")
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
if (left.isZero()) {
- return factory.createInt(BigInteger.ZERO);
+ return PFactory.createInt(language, BigInteger.ZERO);
}
try {
- return factory.createInt(op(left.getValue(), right.intValueExact()));
+ return PFactory.createInt(language, op(left.getValue(), right.intValueExact()));
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
}
@@ -1852,37 +1840,35 @@ static long doLL(long left, long right,
@Specialization
static Object doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, factory, raiseNode);
+ return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, raiseNode);
}
@Specialization
static Object doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, factory, raiseNode);
+ return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, raiseNode);
}
@Specialization
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
- return factory.createInt(op(left.getValue(), right));
+ return PFactory.createInt(language, op(left.getValue(), right));
}
@Specialization
static Object doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
int rightI = (int) right;
if (rightI == right) {
- return factory.createInt(op(left.getValue(), rightI));
+ return PFactory.createInt(language, op(left.getValue(), rightI));
}
// right is >= 2**31, BigInteger's bitLength is at most 2**31-1
// therefore the result of shifting right is just the sign bit
@@ -1892,9 +1878,8 @@ static Object doPiL(PInt left, long right,
@Specialization
static Object doPInt(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return doHugeShift(inliningTarget, left.getValue(), right, factory, raiseNode);
+ return doHugeShift(inliningTarget, left.getValue(), right, raiseNode);
}
private static void raiseNegativeShiftCount(Node inliningTarget, boolean cond, PRaiseNode.Lazy raiseNode) {
@@ -1909,10 +1894,10 @@ static PNotImplemented doGeneric(Object a, Object b) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- private static Object doHugeShift(Node inliningTarget, BigInteger left, PInt right, PythonObjectFactory factory, PRaiseNode.Lazy raiseNode) {
+ private static Object doHugeShift(Node inliningTarget, BigInteger left, PInt right, PRaiseNode.Lazy raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
try {
- return factory.createInt(op(left, right.intValueExact()));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), op(left, right.intValueExact()));
} catch (OverflowException e) {
// right is >= 2**31, BigInteger's bitLength is at most 2**31-1
// therefore the result of shifting right is just the sign bit
@@ -2008,20 +1993,20 @@ long voidPtrsManaged(VirtualFrame frame, PythonNativeVoidPtr a, PythonNativeVoid
@Specialization
PInt doPInt(long left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(PInt.longToBigInteger(left), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization
PInt doPInt(PInt left, long right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), PInt.longToBigInteger(right)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization
PInt doPInt(PInt left, PInt right,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(op(left.getValue(), right.getValue()));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@SuppressWarnings("unused")
@@ -2600,10 +2585,10 @@ private static boolean isBigEndian(Node raisingNode, TruffleString order) {
@Specialization
static PBytes fromLong(long self, int byteCount, TruffleString byteorder, boolean signed,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached InlinedConditionProfile negativeByteCountProfile,
@Exclusive @Cached InlinedConditionProfile negativeNumberProfile,
@Exclusive @Cached InlinedConditionProfile overflowProfile,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (negativeByteCountProfile.profile(inliningTarget, byteCount < 0)) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
@@ -2613,7 +2598,7 @@ static PBytes fromLong(long self, int byteCount, TruffleString byteorder, boolea
throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
}
}
- return factory.createBytes(fromLong(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
+ return PFactory.createBytes(language, fromLong(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
inliningTarget, overflowProfile, raiseNode));
}
@@ -2680,14 +2665,14 @@ private static byte[] getBytes(BigInteger value) {
@Specialization
static PBytes fromPIntInt(PInt self, int byteCount, TruffleString byteorder, boolean signed,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached InlinedConditionProfile negativeByteCountProfile,
@Exclusive @Cached InlinedConditionProfile overflowProfile,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (negativeByteCountProfile.profile(inliningTarget, byteCount < 0)) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
}
- return factory.createBytes(fromBigInteger(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
+ return PFactory.createBytes(language, fromBigInteger(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
inliningTarget, overflowProfile, raiseNode));
}
@@ -2945,10 +2930,10 @@ static TruffleString formatI(int self, TruffleString formatString,
@Specialization(guards = "!formatString.isEmpty()")
static TruffleString formatL(VirtualFrame frame, long self, TruffleString formatString,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached PyNumberFloatNode floatNode,
- @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return formatPI(frame, factory.createInt(self), formatString, inliningTarget, floatNode, raiseNode);
+ return formatPI(frame, PFactory.createInt(language, self), formatString, inliningTarget, floatNode, raiseNode);
}
@Specialization(guards = "!formatString.isEmpty()")
@@ -3157,8 +3142,8 @@ static int get(@SuppressWarnings("unused") Object self) {
abstract static class AsIntegerRatioNode extends PythonBuiltinNode {
@Specialization
static Object get(VirtualFrame frame, Object self, @Cached IntNode intNode,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{intNode.execute(frame, self), 1});
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, new Object[]{intNode.execute(frame, self), 1});
}
}
@@ -3185,21 +3170,11 @@ static Object doCopy(Object self,
@GenerateNodeFactory
abstract static class GetNewArgsNode extends PythonUnaryBuiltinNode {
@Specialization
- static Object doI(int self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{factory.createInt(self)});
- }
-
- @Specialization
- static Object doL(long self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{factory.createInt(self)});
- }
-
- @Specialization
- static Object getPI(PInt self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{factory.createInt(self.getValue())});
+ static Object doI(Object self,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
+ @Cached PyLongCopy copy) {
+ return PFactory.createTuple(language, new Object[]{copy.execute(inliningTarget, self)});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
index 8f2ce4b2fb..a92f61f607 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,9 +45,10 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.NumericSupport;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.dsl.Cached;
@@ -197,7 +198,6 @@ static Object doOther(Node inliningTarget, byte[] data, boolean littleEndian, bo
@Cached InlinedBranchProfile fastPath4,
@Cached InlinedBranchProfile fastPath8,
@Cached InlinedBranchProfile generic,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
NumericSupport support = littleEndian ? NumericSupport.littleEndian() : NumericSupport.bigEndian();
if (signed) {
@@ -227,7 +227,7 @@ static Object doOther(Node inliningTarget, byte[] data, boolean littleEndian, bo
long longValue = PInt.longValue(integer);
return PInt.isIntRange(longValue) ? (int) longValue : longValue;
} else {
- return factory.createInt(integer);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), integer);
}
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
index 6bf68bcc18..7808530e9a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -30,6 +30,7 @@
import java.math.BigInteger;
import java.util.Objects;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
@@ -37,7 +38,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -616,9 +617,9 @@ public static Object abs(int v) {
return Math.abs(v);
}
- public static Object abs(Node inliningTarget, long v, PythonObjectFactory.Lazy factory) {
+ public static Object abs(Node inliningTarget, long v) {
if (v == Long.MIN_VALUE) {
- return factory.get(inliningTarget).createInt(abs(PInt.longToBigInteger(v)));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), abs(PInt.longToBigInteger(v)));
}
return Math.abs(v);
}
@@ -695,8 +696,8 @@ private boolean fitsIn(BigInteger left, BigInteger right) {
* @return either {@code Long} or {@code PInt} containing an unsigned value with bit pattern
* matching that of {@code value}
*/
- public static Object createPythonIntFromUnsignedLong(Node inliningTarget, PythonObjectFactory factory, InlinedConditionProfile profile, long value) {
- return profile.profile(inliningTarget, value >= 0) ? value : factory.createInt(longToUnsignedBigInt(value));
+ public static Object createPythonIntFromUnsignedLong(Node inliningTarget, PythonLanguage language, InlinedConditionProfile profile, long value) {
+ return profile.profile(inliningTarget, value >= 0) ? value : PFactory.createInt(language, longToUnsignedBigInt(value));
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
index d8cc41b9e0..09427fc2b7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -40,6 +40,7 @@
import java.math.BigInteger;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -78,7 +79,7 @@
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -208,10 +209,10 @@ static Object next(Node inliningTarget, PIntRangeIterator self, boolean throwSto
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PBigRangeIterator self, boolean throwStopIteration,
- @Cached PythonObjectFactory.Lazy factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (self.hasNextBigInt()) {
- return factory.get(inliningTarget).createInt(self.nextBigInt());
+ return PFactory.createInt(language, self.nextBigInt());
}
return stopIteration(inliningTarget, self, throwStopIteration, raiseNode);
}
@@ -340,10 +341,10 @@ static Object doDictKey(Node inliningTarget, @SuppressWarnings("unused") PDictVi
@Specialization
static PTuple doDictItem(Node inliningTarget, @SuppressWarnings("unused") PDictView.PDictItemIterator self, HashingStorage storage, HashingStorageIterator it,
+ @Bind PythonLanguage language,
@Shared("val") @Cached HashingStorageIteratorValue itValueNode,
- @Shared("key") @Cached HashingStorageIteratorKey itKeyNode,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{itKeyNode.execute(inliningTarget, storage, it), itValueNode.execute(inliningTarget, storage, it)});
+ @Shared("key") @Cached HashingStorageIteratorKey itKeyNode) {
+ return PFactory.createTuple(language, new Object[]{itKeyNode.execute(inliningTarget, storage, it), itValueNode.execute(inliningTarget, storage, it)});
}
@Specialization
@@ -407,8 +408,8 @@ static int lengthHint(PIntRangeIterator self) {
@Specialization(guards = "!self.isExhausted()")
static Object lengthHint(PBigRangeIterator self,
- @Cached PythonObjectFactory factory) {
- return factory.createInt(self.getRemainingLength());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, self.getRemainingLength());
}
@Specialization(guards = "!self.isExhausted()")
@@ -482,119 +483,115 @@ static int foreign(Object self,
public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
@Specialization
- Object reduce(VirtualFrame frame, PArrayIterator self,
+ static Object reduce(VirtualFrame frame, PArrayIterator self,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Shared @Cached InlinedConditionProfile exhaustedProfile,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (!exhaustedProfile.profile(inliningTarget, self.isExhausted())) {
- return reduceInternal(frame, inliningTarget, self.array, self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.array, self.getIndex(), context, getAttrNode);
} else {
- return reduceInternal(frame, inliningTarget, factory.createEmptyTuple(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, PFactory.createEmptyTuple(context.getLanguage(inliningTarget)), context, getAttrNode);
}
}
@Specialization
- Object reduce(VirtualFrame frame, PHashingStorageIterator self,
+ static Object reduce(VirtualFrame frame, PHashingStorageIterator self,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached SequenceStorageNodes.CreateStorageFromIteratorNode storageNode,
// unused profile to avoid mixing shared and non-shared inlined nodes
@SuppressWarnings("unused") @Shared @Cached InlinedConditionProfile exhaustedProfile,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
int index = self.index;
boolean isExhausted = self.isExhausted();
int state = self.getIterator().getState();
- PList list = factory.createList(storageNode.execute(frame, self));
+ PList list = PFactory.createList(context.getLanguage(inliningTarget), storageNode.execute(frame, self));
self.getIterator().setState(state);
self.setExhausted(isExhausted);
self.index = index;
- return reduceInternal(frame, inliningTarget, list, PythonContext.get(this), getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, list, context, getAttrNode);
}
@Specialization
- Object reduce(VirtualFrame frame, PIntegerSequenceIterator self,
+ static Object reduce(VirtualFrame frame, PIntegerSequenceIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (self.isExhausted()) {
- return reduceInternal(frame, inliningTarget, factory.createList(), null, context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, PFactory.createList(context.getLanguage(inliningTarget)), null, context, getAttrNode);
}
- return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode);
}
@Specialization
- Object reduce(VirtualFrame frame, PPrimitiveIterator self,
+ static Object reduce(VirtualFrame frame, PPrimitiveIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (self.isExhausted()) {
- return reduceInternal(frame, inliningTarget, factory.createList(), null, context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, PFactory.createList(context.getLanguage(inliningTarget)), null, context, getAttrNode);
}
- return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode);
}
@Specialization
- Object reduce(VirtualFrame frame, PStringIterator self,
+ static Object reduce(VirtualFrame frame, PStringIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (self.isExhausted()) {
- return reduceInternal(frame, inliningTarget, T_EMPTY_STRING, null, context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, T_EMPTY_STRING, null, context, getAttrNode);
}
- return reduceInternal(frame, inliningTarget, self.value, self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.value, self.getIndex(), context, getAttrNode);
}
@Specialization
- Object reduce(VirtualFrame frame, PIntRangeIterator self,
+ static Object reduce(VirtualFrame frame, PIntRangeIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
int start = self.getStart();
int stop = self.getStop();
int step = self.getStep();
int len = self.getLen();
- return reduceInternal(frame, inliningTarget, factory.createIntRange(start, stop, step, len), self.getIndex(), PythonContext.get(this), getAttrNode, factory);
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ return reduceInternal(frame, inliningTarget, PFactory.createIntRange(language, start, stop, step, len), self.getIndex(), context, getAttrNode);
}
@Specialization
- Object reduce(VirtualFrame frame, PBigRangeIterator self,
+ static Object reduce(VirtualFrame frame, PBigRangeIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
PInt start = self.getStart();
PInt stop = self.getStop();
PInt step = self.getStep();
PInt len = self.getLen();
- return reduceInternal(frame, inliningTarget, factory.createBigRange(start, stop, step, len), self.getLongIndex(factory), PythonContext.get(this), getAttrNode, factory);
+ PythonLanguage language = context.getLanguage(inliningTarget);
+ return reduceInternal(frame, inliningTarget, PFactory.createBigRange(language, start, stop, step, len), self.getLongIndex(language), context, getAttrNode);
}
@Specialization(guards = "self.isPSequence()")
- Object reduce(VirtualFrame frame, PSequenceIterator self,
+ static Object reduce(VirtualFrame frame, PSequenceIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (self.isExhausted()) {
- return reduceInternal(frame, inliningTarget, factory.createTuple(new Object[0]), null, context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, PFactory.createTuple(context.getLanguage(inliningTarget), new Object[0]), null, context, getAttrNode);
}
- return reduceInternal(frame, inliningTarget, self.getPSequence(), self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.getPSequence(), self.getIndex(), context, getAttrNode);
}
@Specialization(guards = "!self.isPSequence()")
- Object reduceNonSeq(@SuppressWarnings({"unused"}) VirtualFrame frame, PSequenceIterator self,
+ static Object reduceNonSeq(@SuppressWarnings({"unused"}) VirtualFrame frame, PSequenceIterator self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
- PythonContext context = PythonContext.get(this);
+ @Bind PythonContext context,
+ @Shared @Cached PyObjectGetAttr getAttrNode) {
if (!self.isExhausted()) {
- return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, self.getObject(), self.getIndex(), context, getAttrNode);
} else {
- return reduceInternal(frame, inliningTarget, factory.createTuple(new Object[0]), null, context, getAttrNode, factory);
+ return reduceInternal(frame, inliningTarget, PFactory.createTuple(context.getLanguage(inliningTarget), new Object[0]), null, context, getAttrNode);
}
}
@@ -605,19 +602,20 @@ static int other(Object self,
throw raiseNode.get(inliningTarget).raise(TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "iterator", self);
}
- private static PTuple reduceInternal(VirtualFrame frame, Node inliningTarget, Object arg, PythonContext context, PyObjectGetAttr getAttrNode, PythonObjectFactory factory) {
- return reduceInternal(frame, inliningTarget, arg, null, context, getAttrNode, factory);
+ private static PTuple reduceInternal(VirtualFrame frame, Node inliningTarget, Object arg, PythonContext context, PyObjectGetAttr getAttrNode) {
+ return reduceInternal(frame, inliningTarget, arg, null, context, getAttrNode);
}
- private static PTuple reduceInternal(VirtualFrame frame, Node inliningTarget, Object arg, Object state, PythonContext context, PyObjectGetAttr getAttrNode, PythonObjectFactory factory) {
+ private static PTuple reduceInternal(VirtualFrame frame, Node inliningTarget, Object arg, Object state, PythonContext context, PyObjectGetAttr getAttrNode) {
PythonModule builtins = context.getBuiltins();
+ PythonLanguage language = context.getLanguage(inliningTarget);
Object iter = getAttrNode.execute(frame, inliningTarget, builtins, T_ITER);
- PTuple args = factory.createTuple(new Object[]{arg});
+ PTuple args = PFactory.createTuple(language, new Object[]{arg});
// callable, args, state (optional)
if (state != null) {
- return factory.createTuple(new Object[]{iter, args, state});
+ return PFactory.createTuple(language, new Object[]{iter, args, state});
} else {
- return factory.createTuple(new Object[]{iter, args});
+ return PFactory.createTuple(language, new Object[]{iter, args});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PBigRangeIterator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PBigRangeIterator.java
index b5272521dc..21a3cff0ba 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PBigRangeIterator.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PBigRangeIterator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,8 +42,9 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.ints.PInt;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.Shape;
@@ -98,8 +99,8 @@ public PInt getLen() {
return len;
}
- public PInt getLongIndex(PythonObjectFactory factory) {
- return factory.createInt(longIndex);
+ public PInt getLongIndex(PythonLanguage language) {
+ return PFactory.createInt(language, longIndex);
}
public void setLongIndex(BigInteger idx) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
index 8c2edd1b59..41f11490d7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
@@ -32,6 +32,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -48,7 +49,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -80,13 +81,13 @@ static Object doEmpty(@SuppressWarnings("unused") PZip self,
@Specialization(guards = {"!isEmpty(self.getIterators())", "!self.isStrict()"})
static Object doNext(VirtualFrame frame, PZip self,
@Shared @Cached GetNextNode next,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] iterators = self.getIterators();
Object[] tupleElements = new Object[iterators.length];
for (int i = 0; i < iterators.length; i++) {
tupleElements[i] = next.execute(frame, iterators[i]);
}
- return factory.createTuple(tupleElements);
+ return PFactory.createTuple(language, tupleElements);
}
@Specialization(guards = {"!isEmpty(self.getIterators())", "self.isStrict()"})
@@ -94,7 +95,7 @@ static Object doNext(VirtualFrame frame, PZip self,
@Bind("this") Node inliningTarget,
@Shared @Cached GetNextNode next,
@Cached IsBuiltinObjectProfile classProfile,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object[] iterators = self.getIterators();
Object[] tupleElements = new Object[iterators.length];
@@ -103,7 +104,7 @@ static Object doNext(VirtualFrame frame, PZip self,
for (; i < iterators.length; i++) {
tupleElements[i] = next.execute(frame, iterators[i]);
}
- return factory.createTuple(tupleElements);
+ return PFactory.createTuple(language, tupleElements);
} catch (PException e) {
e.expectStopIteration(inliningTarget, classProfile);
if (i > 0) {
@@ -141,11 +142,11 @@ static Object reduce(PZip self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile strictProfile,
@Cached GetClassNode getClass,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClass.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(self.getIterators());
+ PTuple tuple = PFactory.createTuple(language, self.getIterators());
Object[] elements = strictProfile.profile(inliningTarget, self.isStrict()) ? new Object[]{type, tuple, true} : new Object[]{type, tuple};
- return factory.createTuple(elements);
+ return PFactory.createTuple(language, elements);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
index 96d3fbb4a8..b419a5a504 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -32,6 +32,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -46,7 +47,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -110,16 +111,16 @@ abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(VirtualFrame frame, PSentinelIterator self,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttr,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = PythonContext.get(inliningTarget).getBuiltins();
Object iter = getAttr.execute(frame, inliningTarget, builtins, T_ITER);
Object[] args;
if (self.sentinelReached()) {
- args = new Object[]{factory.createEmptyTuple()};
+ args = new Object[]{PFactory.createEmptyTuple(language)};
} else {
args = new Object[]{self.getCallable(), self.getSentinel()};
}
- return factory.createTuple(new Object[]{iter, factory.createTuple(args)});
+ return PFactory.createTuple(language, new Object[]{iter, PFactory.createTuple(language, args)});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java
index ecd5340a1f..09d6d72a16 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -62,7 +63,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -136,7 +137,7 @@ static Object reduceNoFunc(VirtualFrame frame, PAccumulate self,
@Cached InlinedBranchProfile totalMarkerProfile,
@Cached InlinedBranchProfile elseProfile,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object func = self.getFunc();
if (func == null) {
func = PNone.NONE;
@@ -145,39 +146,39 @@ static Object reduceNoFunc(VirtualFrame frame, PAccumulate self,
hasInitialProfile.enter(inliningTarget);
Object type = getClassNode.execute(inliningTarget, self);
- PChain chain = factory.createChain(PythonBuiltinClassType.PChain);
- chain.setSource(getIter.execute(frame, inliningTarget, factory.createList(new Object[]{self.getIterable()})));
- PTuple initialTuple = factory.createTuple(new Object[]{self.getInitial()});
+ PChain chain = PFactory.createChain(language);
+ chain.setSource(getIter.execute(frame, inliningTarget, PFactory.createList(language, new Object[]{self.getIterable()})));
+ PTuple initialTuple = PFactory.createTuple(language, new Object[]{self.getInitial()});
chain.setActive(getIter.execute(frame, inliningTarget, initialTuple));
- PTuple tuple = factory.createTuple(new Object[]{chain, func});
- return factory.createTuple(new Object[]{type, tuple, PNone.NONE});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{chain, func});
+ return PFactory.createTuple(language, new Object[]{type, tuple, PNone.NONE});
} else if (self.getTotal() == PNone.NONE) {
totalNoneProfile.enter(inliningTarget);
- PChain chain = factory.createChain(PythonBuiltinClassType.PChain);
- PList noneList = factory.createList(new Object[]{PNone.NONE});
+ PChain chain = PFactory.createChain(language);
+ PList noneList = PFactory.createList(language, new Object[]{PNone.NONE});
Object noneIter = getIter.execute(frame, inliningTarget, noneList);
- chain.setSource(getIter.execute(frame, inliningTarget, factory.createList(new Object[]{noneIter, self.getIterable()})));
+ chain.setSource(getIter.execute(frame, inliningTarget, PFactory.createList(language, new Object[]{noneIter, self.getIterable()})));
chain.setActive(PNone.NONE);
- PAccumulate accumulate = factory.createAccumulate(PythonBuiltinClassType.PAccumulate);
+ PAccumulate accumulate = PFactory.createAccumulate(language);
accumulate.setIterable(chain);
accumulate.setFunc(func);
- PTuple tuple = factory.createTuple(new Object[]{accumulate, 1, PNone.NONE});
- return factory.createTuple(new Object[]{PythonBuiltinClassType.PIslice, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{accumulate, 1, PNone.NONE});
+ return PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PIslice, tuple});
} else if (self.getTotal() != null) {
totalMarkerProfile.enter(inliningTarget);
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getIterable(), func});
- return factory.createTuple(new Object[]{type, tuple, self.getTotal()});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getIterable(), func});
+ return PFactory.createTuple(language, new Object[]{type, tuple, self.getTotal()});
} else {
elseProfile.enter(inliningTarget);
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getIterable(), func});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getIterable(), func});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
index 32e0311ef5..5b917c735b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -69,8 +70,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.util.PythonUtils;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -141,8 +141,8 @@ public abstract static class FromIterNode extends PythonBinaryBuiltinNode {
static Object fromIter(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object arg,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory) {
- PChain instance = factory.createChain(PythonBuiltinClassType.PChain);
+ @Bind PythonLanguage language) {
+ PChain instance = PFactory.createChain(language);
instance.setSource(getIter.execute(frame, inliningTarget, arg));
instance.setActive(PNone.NONE);
return instance;
@@ -158,19 +158,19 @@ static Object reducePos(PChain self,
@Cached GetClassNode getClass,
@Cached InlinedConditionProfile hasSourceProfile,
@Cached InlinedConditionProfile hasActiveProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClass.execute(inliningTarget, self);
- PTuple empty = factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
+ PTuple empty = PFactory.createEmptyTuple(language);
if (hasSourceProfile.profile(inliningTarget, self.getSource() != PNone.NONE)) {
if (hasActiveProfile.profile(inliningTarget, self.getActive() != PNone.NONE)) {
- PTuple tuple = factory.createTuple(new Object[]{self.getSource(), self.getActive()});
- return factory.createTuple(new Object[]{type, empty, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getSource(), self.getActive()});
+ return PFactory.createTuple(language, new Object[]{type, empty, tuple});
} else {
- PTuple tuple = factory.createTuple(new Object[]{self.getSource()});
- return factory.createTuple(new Object[]{type, empty, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getSource()});
+ return PFactory.createTuple(language, new Object[]{type, empty, tuple});
}
} else {
- return factory.createTuple(new Object[]{type, empty});
+ return PFactory.createTuple(language, new Object[]{type, empty});
}
}
}
@@ -217,8 +217,8 @@ private static void checkIterator(Node inliningTarget, PyIterCheckNode iterCheck
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
index 7380de3ab0..902aba2cbf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
@@ -111,7 +112,7 @@ static Object nextStopped(PAbstractCombinations self,
@Specialization(guards = {"!self.isStopped()", "isLastResultNull(self)"})
static Object nextNoResult(PAbstractCombinations self,
@Bind("this") Node inliningTarget,
- @Cached @Shared PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached @Exclusive InlinedLoopConditionProfile loopConditionProfile) {
// On the first pass, initialize result tuple using the indices
Object[] result = new Object[self.getR()];
@@ -121,30 +122,28 @@ static Object nextNoResult(PAbstractCombinations self,
result[i] = self.getPool()[idx];
}
self.setLastResult(result);
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
@Specialization(guards = {"!self.isStopped()", "!isLastResultNull(self)"})
static Object next(PCombinations self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached InlinedLoopConditionProfile indexLoopProfile,
@Shared @Cached InlinedLoopConditionProfile resultLoopProfile,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return nextInternal(inliningTarget, self, factory, indexLoopProfile, resultLoopProfile, raiseNode);
+ return nextInternal(inliningTarget, self, indexLoopProfile, resultLoopProfile, raiseNode);
}
@Specialization(guards = {"!self.isStopped()", "!isLastResultNull(self)"})
static Object next(PCombinationsWithReplacement self,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached InlinedLoopConditionProfile indexLoopProfile,
@Shared @Cached InlinedLoopConditionProfile resultLoopProfile,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- return nextInternal(inliningTarget, self, factory, indexLoopProfile, resultLoopProfile, raiseNode);
+ return nextInternal(inliningTarget, self, indexLoopProfile, resultLoopProfile, raiseNode);
}
- private static Object nextInternal(Node inliningTarget, PAbstractCombinations self, PythonObjectFactory factory, InlinedLoopConditionProfile indexLoopProfile,
+ private static Object nextInternal(Node inliningTarget, PAbstractCombinations self, InlinedLoopConditionProfile indexLoopProfile,
InlinedLoopConditionProfile resultLoopProfile, PRaiseNode.Lazy raiseNode) throws PException {
CompilerAsserts.partialEvaluationConstant(self.getClass());
@@ -182,7 +181,7 @@ private static Object nextInternal(Node inliningTarget, PAbstractCombinations se
result[j] = elem;
}
self.setLastResult(result);
- return factory.createTuple(result);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), result);
}
protected boolean isLastResultNull(PAbstractCombinations self) {
@@ -200,18 +199,18 @@ static Object reduce(PAbstractCombinations self,
@Cached InlinedConditionProfile hasNoLastResultProfile,
@Cached InlinedConditionProfile stoppedProfile,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
if (hasNoLastResultProfile.profile(inliningTarget, self.getLastResult() == null)) {
- PTuple args = factory.createTuple(new Object[]{factory.createTuple(self.getPool()), self.getR()});
- return factory.createTuple(new Object[]{type, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{PFactory.createTuple(language, self.getPool()), self.getR()});
+ return PFactory.createTuple(language, new Object[]{type, args});
} else if (stoppedProfile.profile(inliningTarget, self.isStopped())) {
- PTuple args = factory.createTuple(new Object[]{factory.createEmptyTuple(), self.getR()});
- return factory.createTuple(new Object[]{type, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{PFactory.createEmptyTuple(language), self.getR()});
+ return PFactory.createTuple(language, new Object[]{type, args});
}
- PTuple indices = factory.createTuple(PythonUtils.arrayCopyOf(self.getIndices(), self.getR()));
- PTuple args = factory.createTuple(new Object[]{factory.createTuple(self.getPool()), self.getR()});
- return factory.createTuple(new Object[]{type, args, indices});
+ PTuple indices = PFactory.createTuple(language, PythonUtils.arrayCopyOf(self.getIndices(), self.getR()));
+ PTuple args = PFactory.createTuple(language, new Object[]{PFactory.createTuple(language, self.getPool()), self.getR()});
+ return PFactory.createTuple(language, new Object[]{type, args, indices});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CompressBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CompressBuiltins.java
index 67996302fd..cb3238ec69 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CompressBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CompressBuiltins.java
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -110,10 +111,10 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PCompress self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getData(), self.getSelectors()});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getData(), self.getSelectors()});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CountBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CountBuiltins.java
index 9999eca821..2fe6c53551 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CountBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CountBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -63,7 +64,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -140,16 +141,16 @@ static Object reducePos(PCount self,
@Cached CastToJavaLongExactNode castLongNode,
@Cached PyObjectTypeCheck typeCheckNode,
@Cached InlinedConditionProfile hasDefaultStep,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
PTuple tuple;
if (hasDefaultStep.profile(inliningTarget,
!typeCheckNode.execute(inliningTarget, self.getStep(), PythonBuiltinClassType.PInt) || castLongNode.execute(inliningTarget, self.getStep()) != 1)) {
- tuple = factory.createTuple(new Object[]{self.getCnt(), self.getStep()});
+ tuple = PFactory.createTuple(language, new Object[]{self.getCnt(), self.getStep()});
} else {
- tuple = factory.createTuple(new Object[]{self.getCnt()});
+ tuple = PFactory.createTuple(language, new Object[]{self.getCnt()});
}
- return factory.createTuple(new Object[]{type, tuple});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
index 5a4955219f..a06f28a1b8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -61,7 +62,6 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ToArrayNode;
import com.oracle.graal.python.builtins.objects.list.PList;
-import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.GetItemNode;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.LenNode;
@@ -76,12 +76,11 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -170,11 +169,11 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PCycle self,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetClassNode getClass,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClass.execute(inliningTarget, self);
- PTuple iterableTuple = factory.createTuple(new Object[]{self.getIterable()});
- PTuple tuple = factory.createTuple(new Object[]{getSavedList(self, factory), self.isFirstpass()});
- return factory.createTuple(new Object[]{type, iterableTuple, tuple});
+ PTuple iterableTuple = PFactory.createTuple(language, new Object[]{self.getIterable()});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{getSavedList(self, language), self.isFirstpass()});
+ return PFactory.createTuple(language, new Object[]{type, iterableTuple, tuple});
}
@Specialization(guards = "!hasIterable(self)")
@@ -185,22 +184,22 @@ static Object reduceNoIterable(VirtualFrame frame, PCycle self,
@Cached CallUnaryMethodNode callNode,
@Cached PyObjectGetIter getIterNode,
@Cached InlinedBranchProfile indexProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClass.execute(inliningTarget, self);
- PList savedList = getSavedList(self, factory);
+ PList savedList = getSavedList(self, language);
Object it = getIterNode.execute(frame, inliningTarget, savedList);
if (self.getIndex() > 0) {
indexProfile.enter(inliningTarget);
Object setStateCallable = lookupAttrNode.execute(frame, inliningTarget, it, T___SETSTATE__);
callNode.executeObject(frame, setStateCallable, self.getIndex());
}
- PTuple iteratorTuple = factory.createTuple(new Object[]{it});
- PTuple tuple = factory.createTuple(new Object[]{savedList, true});
- return factory.createTuple(new Object[]{type, iteratorTuple, tuple});
+ PTuple iteratorTuple = PFactory.createTuple(language, new Object[]{it});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{savedList, true});
+ return PFactory.createTuple(language, new Object[]{type, iteratorTuple, tuple});
}
- static PList getSavedList(PCycle self, PythonObjectFactory factory) {
- return factory.createList(toArray(self.getSaved()));
+ static PList getSavedList(PCycle self, PythonLanguage language) {
+ return PFactory.createList(language, toArray(self.getSaved()));
}
@TruffleBoundary
@@ -216,8 +215,6 @@ protected boolean hasIterable(PCycle self) {
@Builtin(name = J___SETSTATE__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
- abstract Object execute(VirtualFrame frame, PythonObject self, Object state);
-
@Specialization
static Object setState(VirtualFrame frame, PCycle self, Object state,
@Bind("this") Node inliningTarget,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
index f25a0b534a..7243f932ad 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -125,10 +126,10 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PDropwhile self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getPredicate(), self.getIterable()});
- return factory.createTuple(new Object[]{type, tuple, self.isDoneDropping()});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getPredicate(), self.getIterable()});
+ return PFactory.createTuple(language, new Object[]{type, tuple, self.isDoneDropping()});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/FilterfalseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/FilterfalseBuiltins.java
index f38bbacfcf..b34b55e78f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/FilterfalseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/FilterfalseBuiltins.java
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -58,7 +59,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -130,14 +131,14 @@ Object reduce(PFilterfalse self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile hasNoFuncProfile,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object func = self.getFunc();
if (hasNoFuncProfile.profile(inliningTarget, func == null)) {
func = PNone.NONE;
}
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{func, self.getSequence()});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{func, self.getSequence()});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
index a00f7d7545..d3b061d25d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -64,7 +65,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -105,14 +106,14 @@ static Object next(VirtualFrame frame, PGroupBy self,
@Cached InlinedBranchProfile eqProfile,
@Cached InlinedConditionProfile hasFuncProfile,
@Cached InlinedLoopConditionProfile loopConditionProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
self.setCurrGrouper(null);
while (loopConditionProfile.profile(inliningTarget, doGroupByStep(frame, inliningTarget, self, eqProfile, eqNode))) {
self.groupByStep(frame, inliningTarget, nextNode, callNode, hasFuncProfile);
}
self.setTgtKey(self.getCurrKey());
- PGrouper grouper = factory.createGrouper(self, self.getTgtKey());
- return factory.createTuple(new Object[]{self.getCurrKey(), grouper});
+ PGrouper grouper = PFactory.createGrouper(language, self, self.getTgtKey());
+ return PFactory.createTuple(language, new Object[]{self.getCurrKey(), grouper});
}
private static boolean doGroupByStep(VirtualFrame frame, Node inliningTarget, PGroupBy self, InlinedBranchProfile eqProfile, PyObjectRichCompareBool.EqNode eqNode) {
@@ -139,18 +140,18 @@ static Object reduceMarkerNotSet(PGroupBy self,
@Cached InlinedConditionProfile noKeyFuncProfile,
@Cached InlinedConditionProfile noValuesProfile,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object keyFunc = self.getKeyFunc();
if (noKeyFuncProfile.profile(inliningTarget, keyFunc == null)) {
keyFunc = PNone.NONE;
}
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple1 = factory.createTuple(new Object[]{self.getIt(), keyFunc});
+ PTuple tuple1 = PFactory.createTuple(language, new Object[]{self.getIt(), keyFunc});
if (noValuesProfile.profile(inliningTarget, !valuesSet(self))) {
- return factory.createTuple(new Object[]{type, tuple1});
+ return PFactory.createTuple(language, new Object[]{type, tuple1});
}
- PTuple tuple2 = factory.createTuple(new Object[]{self.getCurrValue(), self.getTgtKey(), self.getCurrKey()});
- return factory.createTuple(new Object[]{type, tuple1, tuple2});
+ PTuple tuple2 = PFactory.createTuple(language, new Object[]{self.getCurrValue(), self.getTgtKey(), self.getCurrKey()});
+ return PFactory.createTuple(language, new Object[]{type, tuple1, tuple2});
}
private static boolean valuesSet(PGroupBy self) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
index 527efebabd..06a07127df 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -62,10 +63,9 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -131,21 +131,21 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PGrouper self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getParent(), self.getTgtKey()});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getParent(), self.getTgtKey()});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
@Specialization(guards = "!currValueIsSelf(self)")
Object reduceCurrNotSelf(VirtualFrame frame, @SuppressWarnings("unused") PGrouper self,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttrNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = getContext().getCore().lookupBuiltinModule(BuiltinNames.T_BUILTINS);
Object iterCallable = getAttrNode.execute(frame, inliningTarget, builtins, T_ITER);
// return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
- return factory.createTuple(new Object[]{iterCallable, factory.createTuple(new Object[]{factory.createEmptyTuple()})});
+ return PFactory.createTuple(language, new Object[]{iterCallable, PFactory.createTuple(language, new Object[]{PFactory.createEmptyTuple(language)})});
}
protected boolean currValueIsSelf(PGrouper self) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
index bcc61d9783..b076d60e46 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -66,11 +67,10 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntLossyNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -158,22 +158,22 @@ static Object reduceNoIterable(VirtualFrame frame, PIslice self,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetClassNode getClassNode,
@Cached PyObjectGetIter getIter,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// return type(self), (iter([]), 0), 0
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{getIter.execute(frame, inliningTarget, factory.createList()), 0});
- return factory.createTuple(new Object[]{type, tuple, 0});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{getIter.execute(frame, inliningTarget, PFactory.createList(language)), 0});
+ return PFactory.createTuple(language, new Object[]{type, tuple, 0});
}
@Specialization(guards = "!isNone(self.getIterable())")
static Object reduce(PIslice self,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
Object stop = (self.getStop() == -1) ? PNone.NONE : self.getStop();
- PTuple tuple = factory.createTuple(new Object[]{self.getIterable(), self.getNext(), stop, self.getStep()});
- return factory.createTuple(new Object[]{type, tuple, self.getCnt()});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getIterable(), self.getNext(), stop, self.getStep()});
+ return PFactory.createTuple(language, new Object[]{type, tuple, self.getCnt()});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
index 2fabb2896f..37ea4b0cbb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,12 +43,13 @@
import static com.oracle.graal.python.builtins.objects.itertools.TeeDataObjectBuiltins.LINKCELLS;
import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_REENTER_TEE_ITERATOR;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
@@ -113,9 +114,9 @@ public void setNextlink(PTeeDataObject nextlink) {
this.nextlink = nextlink;
}
- PTeeDataObject jumplink(PythonObjectFactory factory) {
+ PTeeDataObject jumplink(PythonLanguage language) {
if (getNextlink() == null) {
- PTeeDataObject dataObj = factory.createTeeDataObject(getIt());
+ PTeeDataObject dataObj = PFactory.createTeeDataObject(language, getIt());
nextlink = dataObj;
}
return nextlink;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
index 775ebb45f6..5cb777aceb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -56,7 +57,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -90,7 +91,7 @@ static Object next(VirtualFrame frame, PPairwise self,
@Bind("this") Node inliningTarget,
@Cached BuiltinFunctions.NextNode nextNode,
@Cached IsBuiltinObjectProfile isStopIterationProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object item;
Object old = self.getOld();
if (self.getOld() == null) {
@@ -106,7 +107,7 @@ static Object next(VirtualFrame frame, PPairwise self,
self.setOld(null);
throw e;
}
- return factory.createTuple(new Object[]{old, item});
+ return PFactory.createTuple(language, new Object[]{old, item});
}
@Specialization(guards = "self.getIterable() == null")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
index 3d3851bfb2..b1c9de1981 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -69,7 +70,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -117,7 +118,7 @@ static Object next(PPermutations self,
@Cached InlinedLoopConditionProfile resultLoopProfile,
@Cached InlinedLoopConditionProfile mainLoopProfile,
@Cached InlinedLoopConditionProfile shiftIndicesProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
int r = self.getR();
@@ -139,7 +140,7 @@ static Object next(PPermutations self,
int tmp = indices[i];
indices[i] = indices[indices.length - j];
indices[indices.length - j] = tmp;
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
cycles[i] = indices.length - i;
int n1 = indices.length - 1;
@@ -159,7 +160,7 @@ static Object next(PPermutations self,
} else {
self.setStarted(true);
}
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
}
@@ -170,29 +171,29 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PPermutations self,
@Bind("this") Node inliningTarget,
@Shared @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PList poolList = factory.createList(self.getPool());
- PTuple tuple = factory.createTuple(new Object[]{poolList, self.getR()});
+ PList poolList = PFactory.createList(language, self.getPool());
+ PTuple tuple = PFactory.createTuple(language, new Object[]{poolList, self.getR()});
// we must pickle the indices and use them for setstate
- PTuple indicesTuple = factory.createTuple(self.getIndices());
- PTuple cyclesTuple = factory.createTuple(self.getCycles());
- PTuple tuple2 = factory.createTuple(new Object[]{indicesTuple, cyclesTuple, self.isStarted()});
+ PTuple indicesTuple = PFactory.createTuple(language, self.getIndices());
+ PTuple cyclesTuple = PFactory.createTuple(language, self.getCycles());
+ PTuple tuple2 = PFactory.createTuple(language, new Object[]{indicesTuple, cyclesTuple, self.isStarted()});
Object[] result = new Object[]{type, tuple, tuple2};
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
@Specialization(guards = "self.isRaisedStopIteration()")
static Object reduceStopped(PPermutations self,
@Bind("this") Node inliningTarget,
@Shared @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{factory.createEmptyTuple(), self.getR()});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{PFactory.createEmptyTuple(language), self.getR()});
Object[] result = new Object[]{type, tuple};
- return factory.createTuple(result);
+ return PFactory.createTuple(language, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
index 0496482d7a..8a412aadae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -61,12 +62,11 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -101,14 +101,14 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
static Object next(PProduct self,
@Bind("this") Node inliningTarget,
@Exclusive @Cached InlinedLoopConditionProfile loopProfile,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] lst = new Object[self.getGears().length];
loopProfile.profileCounted(inliningTarget, lst.length);
for (int i = 0; loopProfile.inject(inliningTarget, i < lst.length); i++) {
lst[i] = self.getGears()[i][0];
}
self.setLst(lst);
- return factory.createTuple(lst);
+ return PFactory.createTuple(language, lst);
}
@Specialization(guards = {"!self.isStopped()", "hasLst(self)"})
@@ -119,7 +119,7 @@ static Object next(PProduct self,
@Cached InlinedBranchProfile wasStoppedProfile,
@Exclusive @Cached InlinedLoopConditionProfile loopProfile,
@Cached InlinedBranchProfile doneProfile,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object[][] gears = self.getGears();
int x = gears.length - 1;
@@ -146,7 +146,7 @@ static Object next(PProduct self,
// the existing lst array can be changed in a following next call
Object[] ret = new Object[self.getLst().length];
PythonUtils.arraycopy(self.getLst(), 0, ret, 0, ret.length);
- return factory.createTuple(ret);
+ return PFactory.createTuple(language, ret);
}
@SuppressWarnings("unused")
@@ -198,26 +198,26 @@ static Object reduce(PProduct self,
@Cached InlinedConditionProfile stoppedProfile,
@Cached InlinedConditionProfile noLstProfile,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
if (stoppedProfile.profile(inliningTarget, self.isStopped())) {
- PTuple empty = factory.createEmptyTuple();
- return factory.createTuple(new Object[]{type, factory.createTuple(new Object[]{empty})});
+ PTuple empty = PFactory.createEmptyTuple(language);
+ return PFactory.createTuple(language, new Object[]{type, PFactory.createTuple(language, new Object[]{empty})});
}
- PTuple gearTuples = createGearTuple(self, factory);
+ PTuple gearTuples = createGearTuple(self, language);
if (noLstProfile.profile(inliningTarget, self.getLst() == null)) {
- return factory.createTuple(new Object[]{type, gearTuples});
+ return PFactory.createTuple(language, new Object[]{type, gearTuples});
}
- PTuple indicesTuple = factory.createTuple(PythonUtils.arrayCopyOf(self.getIndices(), self.getIndices().length));
- return factory.createTuple(new Object[]{type, gearTuples, indicesTuple});
+ PTuple indicesTuple = PFactory.createTuple(language, PythonUtils.arrayCopyOf(self.getIndices(), self.getIndices().length));
+ return PFactory.createTuple(language, new Object[]{type, gearTuples, indicesTuple});
}
- private static PTuple createGearTuple(PProduct self, PythonObjectFactory factory) {
+ private static PTuple createGearTuple(PProduct self, PythonLanguage language) {
PList[] lists = new PList[self.getGears().length];
for (int i = 0; i < lists.length; i++) {
- lists[i] = factory.createList(self.getGears()[i]);
+ lists[i] = PFactory.createList(language, self.getGears()[i]);
}
- return factory.createTuple(lists);
+ return PFactory.createTuple(language, lists);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
index 58f51d17dd..1a07d71706 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -64,7 +65,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -139,7 +140,7 @@ static Object reduce(PRepeat self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile negativeCountProfile,
@Cached GetClassNode getClass,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClass.execute(inliningTarget, self);
Object[] tupleElements;
if (negativeCountProfile.profile(inliningTarget, self.getCnt() < 0)) {
@@ -147,8 +148,8 @@ static Object reduce(PRepeat self,
} else {
tupleElements = new Object[]{self.getElement(), self.getCnt()};
}
- PTuple tuple = factory.createTuple(tupleElements);
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, tupleElements);
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/StarmapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/StarmapBuiltins.java
index 96bbb96001..d656ba290c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/StarmapBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/StarmapBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -59,7 +60,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -106,11 +107,11 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reducePos(PStarmap self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
// return type(self), (self.fun, self.iterable)
- PTuple tuple = factory.createTuple(new Object[]{self.getFun(), self.getIterable()});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getFun(), self.getIterable()});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
index cbaa174253..d0784fbad1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -59,7 +60,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -95,11 +96,11 @@ static Object next(VirtualFrame frame, PTakewhile self,
@Cached BuiltinFunctions.NextNode nextNode,
@Cached CallNode callNode,
@Cached PyObjectIsTrueNode isTrue,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object value = nextNode.execute(frame, self.getIterable(), PNone.NO_VALUE);
if (!isTrue.execute(frame, callNode.execute(frame, self.getPredicate(), value))) {
- self.setIterable(factory.createSequenceIterator(factory.createList(PythonUtils.EMPTY_OBJECT_ARRAY)));
+ self.setIterable(PFactory.createSequenceIterator(language, PFactory.createList(language, PythonUtils.EMPTY_OBJECT_ARRAY)));
throw raiseNode.get(inliningTarget).raiseStopIteration();
}
return value;
@@ -113,10 +114,10 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PTakewhile self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
- PTuple tuple = factory.createTuple(new Object[]{self.getPredicate(), self.getIterable()});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getPredicate(), self.getIterable()});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
index 29fad45e82..4fb2a302bb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -56,13 +56,13 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.LenNode;
@@ -75,7 +75,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntLossyNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -105,13 +105,13 @@ static Object newTee(VirtualFrame frame, @SuppressWarnings("unused") Object cls,
@Cached PyObjectGetIter getIter,
@Cached("createCopyNode()") LookupAndCallUnaryNode copyNode,
@Cached InlinedConditionProfile isTeeInstanceProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object it = getIter.execute(frame, inliningTarget, iterable);
if (isTeeInstanceProfile.profile(inliningTarget, it instanceof PTee)) {
return copyNode.executeObject(frame, it);
} else {
- PTeeDataObject dataObj = factory.createTeeDataObject(it);
- return factory.createTee(dataObj, 0);
+ PTeeDataObject dataObj = PFactory.createTeeDataObject(language, it);
+ return PFactory.createTee(language, dataObj, 0);
}
}
@@ -126,8 +126,8 @@ protected LookupAndCallUnaryNode createCopyNode() {
public abstract static class CopyNode extends PythonUnaryBuiltinNode {
@Specialization
static Object copy(PTee self,
- @Cached PythonObjectFactory factory) {
- return factory.createTee(self.getDataobj(), self.getIndex());
+ @Bind PythonLanguage language) {
+ return PFactory.createTee(language, self.getDataobj(), self.getIndex());
}
}
@@ -158,9 +158,9 @@ static Object next(VirtualFrame frame, PTee self,
static Object nextNext(VirtualFrame frame, PTee self,
@Bind("this") Node inliningTarget,
@Shared @Cached BuiltinFunctions.NextNode nextNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
- self.setDataObj(self.getDataobj().jumplink(factory));
+ self.setDataObj(self.getDataobj().jumplink(language));
Object value = self.getDataobj().getItem(frame, inliningTarget, 0, nextNode, raiseNode);
self.setIndex(1);
return value;
@@ -170,25 +170,23 @@ static Object nextNext(VirtualFrame frame, PTee self,
@Builtin(name = J___REDUCE__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
- abstract Object execute(VirtualFrame frame, PythonObject self);
@Specialization
static Object reduce(PTee self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClass,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// return type(self), ((),), (self.dataobj, self.index)
Object type = getClass.execute(inliningTarget, self);
- PTuple tuple1 = factory.createTuple(new Object[]{factory.createEmptyTuple()});
- PTuple tuple2 = factory.createTuple(new Object[]{self.getDataobj(), self.getIndex()});
- return factory.createTuple(new Object[]{type, tuple1, tuple2});
+ PTuple tuple1 = PFactory.createTuple(language, new Object[]{PFactory.createEmptyTuple(language)});
+ PTuple tuple2 = PFactory.createTuple(language, new Object[]{self.getDataobj(), self.getIndex()});
+ return PFactory.createTuple(language, new Object[]{type, tuple1, tuple2});
}
}
@Builtin(name = J___SETSTATE__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
- abstract Object execute(VirtualFrame frame, PythonObject self, Object state);
@Specialization
static Object setState(VirtualFrame frame, PTee self, Object state,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
index 0ee4d51cdf..2fd392cea7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,10 +48,10 @@
import static com.oracle.graal.python.nodes.ErrorMessages.TDATAOBJECT_SHOULD_NOT_HAVE_MORE_LINKS;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REDUCE__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___COPY__;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -64,13 +64,12 @@
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -159,10 +158,6 @@ static Object init(VirtualFrame frame, PTeeDataObject self, Object it, Object va
@Cached PRaiseNode raiseNode) {
throw raiseNode.raise(TypeError, ARG_D_MUST_BE_S_NOT_P, "teedataobject()", 2, "list", values);
}
-
- protected LookupAndCallUnaryNode createCopyNode() {
- return LookupAndCallUnaryNode.create(T___COPY__);
- }
}
@Builtin(name = J___REDUCE__, minNumOfPositionalArgs = 1)
@@ -174,14 +169,14 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PTeeDataObject self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClass,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int numread = self.getNumread();
Object[] values = new Object[numread];
PythonUtils.arraycopy(self.getValues(), 0, values, 0, numread);
Object type = getClass.execute(inliningTarget, self);
Object nextlink = self.getNextlink();
- PTuple tuple = factory.createTuple(new Object[]{self.getIt(), factory.createList(values), nextlink == null ? PNone.NONE : nextlink});
- return factory.createTuple(new Object[]{type, tuple});
+ PTuple tuple = PFactory.createTuple(language, new Object[]{self.getIt(), PFactory.createList(language, values), nextlink == null ? PNone.NONE : nextlink});
+ return PFactory.createTuple(language, new Object[]{type, tuple});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
index 0384b449f1..b2383c162c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -62,7 +63,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -109,14 +110,13 @@ static Object next(VirtualFrame frame, PZipLongest self,
@Cached InlinedConditionProfile noActiveProfile,
@Cached InlinedLoopConditionProfile loopProfile,
@Cached InlinedConditionProfile isNullFillProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object fillValue = isNullFillProfile.profile(inliningTarget, isNullFillValue(self)) ? PNone.NONE : self.getFillValue();
- return next(frame, inliningTarget, self, fillValue, nextNode, isStopIterationProfile, loopProfile, noItProfile, noActiveProfile, factory, raiseNode);
+ return next(frame, inliningTarget, self, fillValue, nextNode, isStopIterationProfile, loopProfile, noItProfile, noActiveProfile, raiseNode);
}
private static Object next(VirtualFrame frame, Node inliningTarget, PZipLongest self, Object fillValue, BuiltinFunctions.NextNode nextNode, IsBuiltinObjectProfile isStopIterationProfile,
- InlinedLoopConditionProfile loopProfile, InlinedConditionProfile noItProfile, InlinedConditionProfile noActiveProfile, PythonObjectFactory factory, PRaiseNode.Lazy raiseNode) {
+ InlinedLoopConditionProfile loopProfile, InlinedConditionProfile noItProfile, InlinedConditionProfile noActiveProfile, PRaiseNode.Lazy raiseNode) {
Object[] result = new Object[self.getItTuple().length];
loopProfile.profileCounted(inliningTarget, result.length);
for (int i = 0; loopProfile.inject(inliningTarget, i < result.length); i++) {
@@ -144,7 +144,7 @@ private static Object next(VirtualFrame frame, Node inliningTarget, PZipLongest
}
result[i] = item;
}
- return factory.createTuple(result);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), result);
}
protected static boolean isNullFillValue(PZipLongest self) {
@@ -166,7 +166,7 @@ static Object reduce(PZipLongest self,
@Cached InlinedConditionProfile noFillValueProfile,
@Cached InlinedLoopConditionProfile loopProfile,
@Cached InlinedConditionProfile noItProfile,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object fillValue = self.getFillValue();
if (noFillValueProfile.profile(inliningTarget, fillValue == null)) {
fillValue = PNone.NONE;
@@ -177,13 +177,13 @@ static Object reduce(PZipLongest self,
for (int i = 0; loopProfile.profile(inliningTarget, i < its.length); i++) {
Object it = self.getItTuple()[i];
if (noItProfile.profile(inliningTarget, it == PNone.NONE)) {
- its[i] = factory.createEmptyTuple();
+ its[i] = PFactory.createEmptyTuple(language);
} else {
its[i] = it;
}
}
- PTuple tuple = factory.createTuple(its);
- return factory.createTuple(new Object[]{type, tuple, fillValue});
+ PTuple tuple = PFactory.createTuple(language, its);
+ return PFactory.createTuple(language, new Object[]{type, tuple, fillValue});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
index 4abd0e414c..764b804251 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
@@ -55,6 +55,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -80,6 +81,7 @@
import com.oracle.graal.python.builtins.objects.range.PIntRange;
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode;
@@ -111,7 +113,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
@@ -313,7 +315,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
}
var sequenceStorage = getStorageNode.execute(inliningTarget, self);
return subscriptNode.execute(frame, inliningTarget, sequenceStorage, idx,
- ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PythonObjectFactory::createList);
+ ErrorMessages.LIST_INDEX_OUT_OF_RANGE, PFactory::createList);
}
@InliningCutoff
@@ -458,10 +460,11 @@ static PList copySequence(Object list,
@Cached GetListStorageNode getStorageNode,
@Cached SequenceStorageNodes.CopyNode copy,
@Cached GetClassForNewListNode getClassForNewListNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
var sequenceStorage = getStorageNode.execute(inliningTarget, list);
Object newClass = getClassForNewListNode.execute(inliningTarget, list);
- return factory.createList(newClass, copy.execute(inliningTarget, sequenceStorage));
+ return PFactory.createList(language, newClass, getInstanceShape.execute(newClass), copy.execute(inliningTarget, sequenceStorage));
}
}
@@ -749,7 +752,8 @@ static PList doPList(Object left, Object right,
@Cached GetListStorageNode getStorageNode,
@Cached GetClassForNewListNode getClassForNewListNode,
@Cached("createConcat()") SequenceStorageNodes.ConcatNode concatNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isListNode.execute(inliningTarget, right)) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "list", right, "list");
@@ -759,7 +763,7 @@ static PList doPList(Object left, Object right,
var rightStorage = getStorageNode.execute(inliningTarget, right);
SequenceStorage newStore = concatNode.execute(leftStorage, rightStorage);
Object newClass = getClassForNewListNode.execute(inliningTarget, left);
- return factory.createList(newClass, newStore);
+ return PFactory.createList(language, newClass, getInstanceShape.execute(newClass), newStore);
}
@NeverDefault
@@ -800,7 +804,7 @@ static Object doPListInt(VirtualFrame frame, Object left, int right,
@Cached PyListCheckNode isListNode,
@Cached GetListStorageNode getStorageNode,
@Cached SequenceStorageNodes.RepeatNode repeatNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (!isListNode.execute(inliningTarget, left)) {
return PNotImplemented.NOT_IMPLEMENTED;
@@ -809,7 +813,7 @@ static Object doPListInt(VirtualFrame frame, Object left, int right,
var sequenceStorage = getStorageNode.execute(inliningTarget, left);
try {
SequenceStorage repeated = repeatNode.execute(frame, sequenceStorage, right);
- return factory.createList(repeated);
+ return PFactory.createList(language, repeated);
} catch (ArithmeticException | OutOfMemoryError e) {
throw raiseNode.get(inliningTarget).raise(MemoryError);
}
@@ -830,10 +834,6 @@ static Object doGeneric(VirtualFrame frame, Object list, Object right,
updateStorageNode.execute(inliningTarget, list, store, updated);
return list;
}
-
- protected IMulNode createIMulNode() {
- return ListBuiltinsFactory.IMulNodeFactory.create();
- }
}
@Builtin(name = J___EQ__, minNumOfPositionalArgs = 2)
@@ -1040,26 +1040,26 @@ public abstract static class IterNode extends PythonUnaryBuiltinNode {
*/
@Specialization(guards = {"isIntStorage(primary)"})
static PIntegerSequenceIterator doPListInt(PList primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createIntegerSequenceIterator((IntSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntegerSequenceIterator(language, (IntSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"isLongStorage(primary)"})
static PLongSequenceIterator doPListLong(PList primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createLongSequenceIterator((LongSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createLongSequenceIterator(language, (LongSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"isDoubleStorage(primary)"})
static PDoubleSequenceIterator doPListDouble(PList primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDoubleSequenceIterator((DoubleSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createDoubleSequenceIterator(language, (DoubleSequenceStorage) primary.getSequenceStorage(), primary);
}
@Fallback
static PSequenceIterator doOther(Object primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createSequenceIterator(primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createSequenceIterator(language, primary);
}
}
@@ -1070,9 +1070,9 @@ abstract static class ReverseNode extends PythonUnaryBuiltinNode {
static Object reverse(Object self,
@Bind("this") Node inliningTarget,
@Cached GetListStorageNode getStorage,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int len = getStorage.execute(inliningTarget, self).length();
- return factory.createSequenceReverseIterator(PythonBuiltinClassType.PReverseIterator, self, len);
+ return PFactory.createSequenceReverseIterator(language, self, len);
}
}
@@ -1081,8 +1081,8 @@ static Object reverse(Object self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/map/MapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/map/MapBuiltins.java
index daea43de4e..dd43ef47c1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/map/MapBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/map/MapBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -57,7 +58,8 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -111,12 +113,12 @@ static PMap iter(PMap self) {
public abstract static class ReduceNode extends PythonBuiltinNode {
@Specialization
static PTuple doit(PMap self, @SuppressWarnings("unused") Object ignored,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] iterators = self.getIterators();
Object[] args = new Object[iterators.length + 1];
args[0] = self.getFunction();
System.arraycopy(iterators, 0, args, 1, iterators.length);
- return factory.createTuple(new Object[]{PythonBuiltinClassType.PMap, factory.createTuple(args)});
+ return PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PMap, PFactory.createTuple(language, args)});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
index 1800a7ca6c..f57e595d9c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -76,7 +77,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -259,8 +260,8 @@ static TruffleString repr(VirtualFrame frame, PMappingproxy self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
index 3e3f9510b7..8425934da2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
@@ -57,6 +57,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -100,7 +101,7 @@
import com.oracle.graal.python.runtime.AsyncHandler;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.BufferFormat;
@@ -179,11 +180,11 @@ static Object getitem(VirtualFrame frame, PMemoryView self, Object index,
@Specialization
static Object getitemSlice(PMemoryView self, PSlice slice,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached InlinedConditionProfile zeroDimProfile,
@Cached SliceNodes.SliceUnpack sliceUnpack,
@Cached SliceNodes.AdjustIndices adjustIndices,
@Cached MemoryViewNodes.InitFlagsNode initFlagsNode,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (zeroDimProfile.profile(inliningTarget, self.getDimensions() == 0)) {
@@ -201,7 +202,7 @@ static Object getitemSlice(PMemoryView self, PSlice slice,
int[] suboffsets = self.getBufferSuboffsets();
int length = self.getLength() - (shape[0] - newShape[0]) * self.getItemSize();
int flags = initFlagsNode.execute(inliningTarget, self.getDimensions(), self.getItemSize(), newShape, newStrides, suboffsets);
- return factory.createMemoryView(PythonContext.get(inliningTarget), self.getLifecycleManager(), self.getBuffer(), self.getOwner(), length, self.isReadOnly(),
+ return PFactory.createMemoryView(language, PythonContext.get(inliningTarget), self.getLifecycleManager(), self.getBuffer(), self.getOwner(), length, self.isReadOnly(),
self.getItemSize(), self.getFormat(), self.getFormatString(), self.getDimensions(), self.getBufferPointer(),
self.getOffset() + sliceInfo.start * strides[0], newShape, newStrides, suboffsets, flags);
}
@@ -424,38 +425,38 @@ public abstract static class ToListNode extends PythonUnaryBuiltinNode {
@Specialization(guards = {"self.getDimensions() == cachedDimensions", "cachedDimensions < 8"}, limit = "3")
Object tolistCached(VirtualFrame frame, PMemoryView self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("self.getDimensions()") int cachedDimensions,
@Shared @Cached MemoryViewNodes.ReadItemAtNode readItemAtNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (cachedDimensions == 0) {
// That's not a list but CPython does it this way
return readItemAtNode.execute(frame, self, self.getBufferPointer(), self.getOffset());
} else {
- return recursive(frame, self, readItemAtNode, 0, cachedDimensions, self.getBufferPointer(), self.getOffset(), factory);
+ return recursive(frame, self, readItemAtNode, 0, cachedDimensions, self.getBufferPointer(), self.getOffset(), language);
}
}
@Specialization(replaces = "tolistCached")
Object tolist(VirtualFrame frame, PMemoryView self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached MemoryViewNodes.ReadItemAtNode readItemAtNode,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (self.getDimensions() == 0) {
return readItemAtNode.execute(frame, self, self.getBufferPointer(), self.getOffset());
} else {
- return recursiveBoundary(frame, self, readItemAtNode, 0, self.getDimensions(), self.getBufferPointer(), self.getOffset(), factory);
+ return recursiveBoundary(frame, self, readItemAtNode, 0, self.getDimensions(), self.getBufferPointer(), self.getOffset(), language);
}
}
- private PList recursiveBoundary(VirtualFrame frame, PMemoryView self, MemoryViewNodes.ReadItemAtNode readItemAtNode, int dim, int ndim, Object ptr, int offset, PythonObjectFactory factory) {
- return recursive(frame, self, readItemAtNode, dim, ndim, ptr, offset, factory);
+ private PList recursiveBoundary(VirtualFrame frame, PMemoryView self, MemoryViewNodes.ReadItemAtNode readItemAtNode, int dim, int ndim, Object ptr, int offset, PythonLanguage language) {
+ return recursive(frame, self, readItemAtNode, dim, ndim, ptr, offset, language);
}
- private PList recursive(VirtualFrame frame, PMemoryView self, MemoryViewNodes.ReadItemAtNode readItemAtNode, int dim, int ndim, Object ptr, int initialOffset, PythonObjectFactory factory) {
+ private PList recursive(VirtualFrame frame, PMemoryView self, MemoryViewNodes.ReadItemAtNode readItemAtNode, int dim, int ndim, Object ptr, int initialOffset, PythonLanguage language) {
int offset = initialOffset;
Object[] objects = new Object[self.getBufferShape()[dim]];
for (int i = 0; i < self.getBufferShape()[dim]; i++) {
@@ -468,11 +469,11 @@ private PList recursive(VirtualFrame frame, PMemoryView self, MemoryViewNodes.Re
if (dim == ndim - 1) {
objects[i] = readItemAtNode.execute(frame, self, xptr, xoffset);
} else {
- objects[i] = recursive(frame, self, readItemAtNode, dim + 1, ndim, xptr, xoffset, factory);
+ objects[i] = recursive(frame, self, readItemAtNode, dim + 1, ndim, xptr, xoffset, language);
}
offset += self.getBufferStrides()[dim];
}
- return factory.createList(objects);
+ return PFactory.createList(language, objects);
}
private CExtNodes.PCallCapiFunction getCallCapiFunction() {
@@ -499,8 +500,8 @@ public abstract static class ToBytesNode extends PythonBinaryClinicBuiltinNode {
@Specialization
PBytes tobytes(PMemoryView self, TruffleString order,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached TruffleString.EqualNode equalNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
byte[] bytes;
@@ -512,7 +513,7 @@ PBytes tobytes(PMemoryView self, TruffleString order,
} else {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ORDER_MUST_BE_C_F_OR_A);
}
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
@Override
@@ -584,11 +585,11 @@ public final Object call(VirtualFrame frame, Object arg) {
@Specialization
static PMemoryView toreadonly(PMemoryView self,
+ @Bind PythonLanguage language,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
- return factory.createMemoryView(PythonContext.get(inliningTarget), self.getLifecycleManager(), self.getBuffer(), self.getOwner(), self.getLength(), true,
+ return PFactory.createMemoryView(language, PythonContext.get(inliningTarget), self.getLifecycleManager(), self.getBuffer(), self.getOwner(), self.getLength(), true,
self.getItemSize(), self.getFormat(), self.getFormatString(), self.getDimensions(), self.getBufferPointer(),
self.getOffset(), self.getBufferShape(), self.getBufferStrides(), self.getBufferSuboffsets(), self.getFlags());
}
@@ -604,10 +605,9 @@ static PMemoryView cast(PMemoryView self, TruffleString formatString, @SuppressW
@Bind("this") Node inliningTarget,
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
- return doCast(inliningTarget, self, formatString, 1, null, PythonContext.get(inliningTarget), lengthNode, atIndexNode, factory, raiseNode);
+ return doCast(inliningTarget, self, formatString, 1, null, PythonContext.get(inliningTarget), lengthNode, atIndexNode, raiseNode);
}
@Specialization(guards = "isPTuple(shapeObj) || isList(shapeObj)")
@@ -618,7 +618,6 @@ static PMemoryView cast(VirtualFrame frame, PMemoryView self, TruffleString form
@Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, shapeObj);
@@ -630,7 +629,7 @@ static PMemoryView cast(VirtualFrame frame, PMemoryView self, TruffleString form
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CAST_ELEMENTS_MUST_BE_POSITIVE_INTEGERS);
}
}
- return doCast(inliningTarget, self, formatString, ndim, shape, PythonContext.get(inliningTarget), lengthNode, atIndexNode, factory, raiseNode);
+ return doCast(inliningTarget, self, formatString, ndim, shape, PythonContext.get(inliningTarget), lengthNode, atIndexNode, raiseNode);
}
@Specialization(guards = {"!isPTuple(shape)", "!isList(shape)", "!isPNone(shape)"})
@@ -641,7 +640,7 @@ static PMemoryView error(PMemoryView self, TruffleString format, Object shape,
}
private static PMemoryView doCast(Node inliningTarget, PMemoryView self, TruffleString formatString, int ndim, int[] shape, PythonContext context, TruffleString.CodePointLengthNode lengthNode,
- TruffleString.CodePointAtIndexNode atIndexNode, PythonObjectFactory factory, PRaiseNode.Lazy raiseNode) {
+ TruffleString.CodePointAtIndexNode atIndexNode, PRaiseNode.Lazy raiseNode) {
if (!self.isCContiguous()) {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CASTS_RESTRICTED_TO_C_CONTIGUOUS);
}
@@ -694,7 +693,7 @@ private static PMemoryView doCast(Node inliningTarget, PMemoryView self, Truffle
}
newStrides = PMemoryView.initStridesFromShape(ndim, itemsize, shape);
}
- return factory.createMemoryView(context, self.getLifecycleManager(), self.getBuffer(), self.getOwner(), self.getLength(), self.isReadOnly(),
+ return PFactory.createMemoryView(PythonLanguage.get(inliningTarget), context, self.getLifecycleManager(), self.getBuffer(), self.getOwner(), self.getLength(), self.isReadOnly(),
itemsize, format, formatString, ndim, self.getBufferPointer(),
self.getOffset(), newShape, newStrides, null, flags);
}
@@ -858,14 +857,14 @@ public abstract static class ShapeNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferShape() == null)) {
- return factory.createEmptyTuple();
+ return PFactory.createEmptyTuple(language);
}
- return factory.createTuple(new IntSequenceStorage(self.getBufferShape()));
+ return PFactory.createTuple(language, new IntSequenceStorage(self.getBufferShape()));
}
}
@@ -876,14 +875,14 @@ public abstract static class StridesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferStrides() == null)) {
- return factory.createEmptyTuple();
+ return PFactory.createEmptyTuple(language);
}
- return factory.createTuple(new IntSequenceStorage(self.getBufferStrides()));
+ return PFactory.createTuple(language, new IntSequenceStorage(self.getBufferStrides()));
}
}
@@ -894,14 +893,14 @@ public abstract static class SuboffsetsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferSuboffsets() == null)) {
- return factory.createEmptyTuple();
+ return PFactory.createEmptyTuple(language);
}
- return factory.createTuple(new IntSequenceStorage(self.getBufferSuboffsets()));
+ return PFactory.createTuple(language, new IntSequenceStorage(self.getBufferSuboffsets()));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
index ab1ae548c8..c7405fdaa4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
@@ -76,7 +76,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
@@ -403,11 +403,11 @@ PTuple doSelfIsObject(VirtualFrame frame, PMethod method, @SuppressWarnings("unu
@Shared("toStringNode") @Cached CastToTruffleStringNode toStringNode,
@Shared("getGetAttr") @Cached PyObjectGetAttr getGetAttr,
@Shared("getName") @Cached PyObjectGetAttr getName,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = getContext().getBuiltins();
Object getattr = getGetAttr.execute(frame, inliningTarget, builtins, T_GETATTR);
- PTuple args = factory.createTuple(new Object[]{method.getSelf(), getName(frame, inliningTarget, method.getFunction(), toStringNode, getName)});
- return factory.createTuple(new Object[]{getattr, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{method.getSelf(), getName(frame, inliningTarget, method.getFunction(), toStringNode, getName)});
+ return PFactory.createTuple(language, new Object[]{getattr, args});
}
@Specialization(guards = "!isSelfModuleOrNull(method)")
@@ -416,11 +416,11 @@ PTuple doSelfIsObject(VirtualFrame frame, PBuiltinMethod method, @SuppressWarnin
@Shared("toStringNode") @Cached CastToTruffleStringNode toStringNode,
@Shared("getGetAttr") @Cached PyObjectGetAttr getGetAttr,
@Shared("getName") @Cached PyObjectGetAttr getName,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = getContext().getBuiltins();
Object getattr = getGetAttr.execute(frame, inliningTarget, builtins, T_GETATTR);
- PTuple args = factory.createTuple(new Object[]{method.getSelf(), getName(frame, inliningTarget, method.getFunction(), toStringNode, getName)});
- return factory.createTuple(new Object[]{getattr, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{method.getSelf(), getName(frame, inliningTarget, method.getFunction(), toStringNode, getName)});
+ return PFactory.createTuple(language, new Object[]{getattr, args});
}
private static TruffleString getName(VirtualFrame frame, Node inliningTarget, Object func, CastToTruffleStringNode toStringNode, PyObjectGetAttr getName) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
index 9534170b94..ec4bf97bfe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -67,7 +68,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -167,26 +168,26 @@ abstract static class MakeMethodNode extends PNodeWithContext {
@Specialization
Object method(Object self, PFunction func,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createMethod(self, func);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, self, func);
}
@Specialization(guards = "!func.needsDeclaringType()")
Object methodBuiltin(Object self, PBuiltinFunction func,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createBuiltinMethod(self, func);
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, self, func);
}
@Specialization(guards = "func.needsDeclaringType()")
Object methodBuiltinWithDeclaringType(Object self, PBuiltinFunction func,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createBuiltinMethod(self, func, func.getEnclosingType());
+ @Bind PythonLanguage language) {
+ return PFactory.createBuiltinMethod(language, self, func, func.getEnclosingType());
}
@Specialization(guards = "!isFunction(func)")
Object generic(Object self, Object func,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createMethod(self, func);
+ @Bind PythonLanguage language) {
+ return PFactory.createMethod(language, self, func);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
index 77e7d15380..f74d62eb88 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -77,7 +78,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -183,12 +184,11 @@ public abstract static class GetNode extends DescrGetBuiltinNode {
@Specialization
static Object doGeneric(PDecoratedMethod self, Object obj, @SuppressWarnings("unused") Object cls,
@Bind("this") Node inliningTarget,
- @Cached InlinedConditionProfile objIsNoneProfile,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile objIsNoneProfile) {
if (objIsNoneProfile.profile(inliningTarget, obj == PNone.NO_VALUE)) {
return self.getCallable();
}
- return factory.createMethod(obj, self.getCallable());
+ return PFactory.createMethod(PythonLanguage.get(inliningTarget), obj, self.getCallable());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
index 23b8f10f15..d3e2e1786a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -40,6 +40,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -69,7 +70,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -190,11 +191,10 @@ public abstract static class GetMethodDefaultsNode extends PythonUnaryBuiltinNod
@Specialization
static Object defaults(PMethod self,
@Bind("this") Node inliningTarget,
- @Cached GetDefaultsNode getDefaultsNode,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached GetDefaultsNode getDefaultsNode) {
Object[] argDefaults = getDefaultsNode.execute(inliningTarget, self);
assert argDefaults != null;
- return (argDefaults.length == 0) ? PNone.NONE : factory.get(inliningTarget).createTuple(argDefaults);
+ return (argDefaults.length == 0) ? PNone.NONE : PFactory.createTuple(PythonLanguage.get(inliningTarget), argDefaults);
}
}
@@ -204,10 +204,9 @@ public abstract static class GetMethodKwdefaultsNode extends PythonUnaryBuiltinN
@Specialization
static Object kwDefaults(PMethod self,
@Bind("this") Node inliningTarget,
- @Cached GetKeywordDefaultsNode getKeywordDefaultsNode,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached GetKeywordDefaultsNode getKeywordDefaultsNode) {
PKeyword[] kwdefaults = getKeywordDefaultsNode.execute(inliningTarget, self);
- return (kwdefaults.length > 0) ? factory.get(inliningTarget).createDict(kwdefaults) : PNone.NONE;
+ return (kwdefaults.length > 0) ? PFactory.createDict(PythonLanguage.get(inliningTarget), kwdefaults) : PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PDecoratedMethod.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PDecoratedMethod.java
index e4462ae95b..c132d51694 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PDecoratedMethod.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PDecoratedMethod.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,12 +40,13 @@
*/
package com.oracle.graal.python.builtins.objects.method;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.BoundBuiltinCallable;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.function.Signature;
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.object.Shape;
@@ -74,14 +75,14 @@ public void setCallable(Object callable) {
}
@SuppressWarnings("unchecked")
- public Object boundToObject(PythonBuiltinClassType binding, PythonObjectFactory factory) {
+ public Object boundToObject(PythonBuiltinClassType binding, PythonLanguage language) {
if (GetPythonObjectClassNode.executeUncached(this) != PythonBuiltinClassType.PStaticmethod) {
if (callable instanceof BoundBuiltinCallable) {
- return factory.createBuiltinClassmethodFromCallableObj(((BoundBuiltinCallable) callable).boundToObject(binding, factory));
+ return PFactory.createBuiltinClassmethodFromCallableObj(language, ((BoundBuiltinCallable) callable).boundToObject(binding, language));
}
} else {
if (callable instanceof PBuiltinMethod) {
- return factory.createStaticmethodFromCallableObj(((PBuiltinMethod) callable).getBuiltinFunction().boundToObject(binding, factory));
+ return PFactory.createStaticmethodFromCallableObj(language, ((PBuiltinMethod) callable).getBuiltinFunction().boundToObject(binding, language));
}
}
return this;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
index 671bf48097..6e54ed2e2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
@@ -121,7 +121,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
@@ -172,17 +172,17 @@ public abstract static class MMapSqItemNode extends SqItemBuiltinNode {
@Specialization
static PBytes doInt(VirtualFrame frame, PMMap self, int index,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached PRaiseNode.Lazy raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
- @Cached PythonObjectFactory factory) {
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib) {
long len = self.getLength();
checkBounds(inliningTarget, raiseNode, MMAP_INDEX_OUT_OF_RANGE, index, len);
try {
- byte b = posixSupportLib.mmapReadByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), index);
+ byte b = posixSupportLib.mmapReadByte(context.getPosixSupport(), self.getPosixSupportHandle(), index);
// CPython indeed returns bytes object from sq_item, although it returns single byte
// value as integer from mp_subscript, see, e.g.: `for i in mmap_object: print(i)`
- return factory.createBytes(new byte[]{b});
+ return PFactory.createBytes(context.getLanguage(inliningTarget), new byte[]{b});
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -196,8 +196,9 @@ public abstract static class GetItemNode extends MpSubscriptBuiltinNode {
@Specialization(guards = "!isPSlice(idxObj)")
static int doSingle(VirtualFrame frame, PMMap self, Object idxObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Exclusive @Cached InlinedConditionProfile negativeIndexProfile,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Cached PyLongAsLongNode asLongNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
@@ -206,7 +207,7 @@ static int doSingle(VirtualFrame frame, PMMap self, Object idxObj,
long idx = negativeIndexProfile.profile(inliningTarget, i < 0) ? i + len : i;
checkBounds(inliningTarget, raiseNode, MMAP_INDEX_OUT_OF_RANGE, idx, len);
try {
- return posixSupportLib.mmapReadByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), idx) & 0xFF;
+ return posixSupportLib.mmapReadByte(context.getPosixSupport(), self.getPosixSupportHandle(), idx) & 0xFF;
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -215,22 +216,22 @@ static int doSingle(VirtualFrame frame, PMMap self, Object idxObj,
@Specialization
static Object doSlice(VirtualFrame frame, PMMap self, PSlice idx,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Exclusive @Cached InlinedConditionProfile emptyProfile,
@Cached CoerceToIntSlice sliceCast,
@Cached ComputeIndices compute,
@Cached LenOfRangeNode sliceLenNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
try {
SliceInfo info = compute.execute(frame, sliceCast.execute(inliningTarget, idx), PInt.intValueExact(self.getLength()));
int len = sliceLenNode.len(inliningTarget, info);
if (emptyProfile.profile(inliningTarget, len == 0)) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(context.getLanguage(inliningTarget));
}
- byte[] result = readBytes(frame, inliningTarget, self, posixSupportLib, PosixSupport.get(inliningTarget), info.start, len, constructAndRaiseNode);
- return factory.createBytes(result);
+ byte[] result = readBytes(frame, inliningTarget, self, posixSupportLib, context.getPosixSupport(), info.start, len, constructAndRaiseNode);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), result);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, e);
}
@@ -244,7 +245,8 @@ public abstract static class SetItemNode extends SqAssItemBuiltinNode {
@Specialization
static void doSingle(VirtualFrame frame, PMMap self, int index, Object val,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached PyBytesCheckNode checkNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@@ -270,7 +272,7 @@ static void doSingle(VirtualFrame frame, PMMap self, int index, Object val,
}
byte b = bufferLib.readByte(val, 0);
try {
- posixSupportLib.mmapWriteByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), idx, b);
+ posixSupportLib.mmapWriteByte(context.getPosixSupport(), self.getPosixSupportHandle(), idx, b);
} catch (PosixException ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, ex);
}
@@ -284,7 +286,8 @@ public abstract static class SetSubscriptNode extends MpAssSubscriptBuiltinNode
@Specialization(guards = "!isPSlice(idxObj)")
static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object valueObj,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Cached PyIndexCheckNode checkNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@@ -317,7 +320,7 @@ static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object value
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, MMAP_ITEM_VALUE_MUST_BE_IN_RANGE);
}
try {
- posixSupportLib.mmapWriteByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), idx, (byte) value);
+ posixSupportLib.mmapWriteByte(context.getPosixSupport(), self.getPosixSupportHandle(), idx, (byte) value);
} catch (PosixException ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, ex);
}
@@ -326,7 +329,8 @@ static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object value
@Specialization
static void doSlice(VirtualFrame frame, PMMap self, PSlice slice, Object valueObj,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached SliceNodes.SliceUnpack sliceUnpack,
@@ -359,11 +363,11 @@ static void doSlice(VirtualFrame frame, PMMap self, PSlice slice, Object valueOb
if (info.sliceLength > 0) {
try {
if (step1Profile.profile(inliningTarget, info.step == 1)) {
- posixSupportLib.mmapWriteBytes(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(),
+ posixSupportLib.mmapWriteBytes(context.getPosixSupport(), self.getPosixSupportHandle(),
info.start, bufferLib.getInternalOrCopiedByteArray(buffer), bufferLen);
} else {
for (int cur = info.start, i = 0; i < info.sliceLength; cur += info.step, i++) {
- posixSupportLib.mmapWriteByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), cur, bufferLib.readByte(buffer, i));
+ posixSupportLib.mmapWriteByte(context.getPosixSupport(), self.getPosixSupportHandle(), cur, bufferLib.readByte(buffer, i));
}
}
} catch (PosixException ex) {
@@ -415,9 +419,10 @@ static Object size(VirtualFrame frame, PMMap self, @SuppressWarnings("unused") O
abstract static class CloseNode extends PythonUnaryBuiltinNode {
@Specialization
- PNone close(PMMap self,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib) {
- self.close(posixSupportLib, getPosixSupport());
+ static PNone close(PMMap self,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib) {
+ self.close(posixSupportLib, context.getPosixSupport());
return PNone.NONE;
}
}
@@ -472,14 +477,15 @@ abstract static class ReadByteNode extends PythonUnaryBuiltinNode {
@Specialization
static int readByte(VirtualFrame frame, PMMap self,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupportLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
if (self.getPos() >= self.getLength()) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, READ_BYTE_OUT_OF_RANGE);
}
try {
- byte res = posixSupportLib.mmapReadByte(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), self.getPos());
+ byte res = posixSupportLib.mmapReadByte(context.getPosixSupport(), self.getPosixSupportHandle(), self.getPos());
self.setPos(self.getPos() + 1);
return res & 0xFF;
} catch (PosixException e) {
@@ -496,14 +502,14 @@ abstract static class ReadNode extends PythonBuiltinNode {
@Specialization
static PBytes read(VirtualFrame frame, PMMap self, Object n,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached InlinedConditionProfile noneProfile,
@Cached InlinedConditionProfile emptyProfile,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached InlinedConditionProfile negativeProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
long nread;
// intentionally accept NO_VALUE and NONE; both mean that we read unlimited # of bytes
@@ -523,12 +529,12 @@ static PBytes read(VirtualFrame frame, PMMap self, Object n,
}
}
if (emptyProfile.profile(inliningTarget, nread == 0)) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(context.getLanguage(inliningTarget));
}
try {
- byte[] buffer = MMapBuiltins.readBytes(frame, inliningTarget, self, posixLib, PosixSupport.get(inliningTarget), self.getPos(), PythonUtils.toIntExact(nread), constructAndRaiseNode);
+ byte[] buffer = MMapBuiltins.readBytes(frame, inliningTarget, self, posixLib, context.getPosixSupport(), self.getPos(), PythonUtils.toIntExact(nread), constructAndRaiseNode);
self.setPos(self.getPos() + buffer.length);
- return factory.createBytes(buffer);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), buffer);
} catch (OverflowException e) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, ErrorMessages.TOO_MANY_REMAINING_BYTES_TO_BE_STORED);
}
@@ -541,12 +547,12 @@ abstract static class ReadlineNode extends PythonUnaryBuiltinNode {
private static final int BUFFER_SIZE = 1024;
@Specialization
- Object readline(VirtualFrame frame, PMMap self,
+ static Object readline(VirtualFrame frame, PMMap self,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SequenceStorageNodes.AppendNode appendNode,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
// Posix abstraction is leaking here a bit: with read mmapped memory, we'd just read
// byte by byte, but that would be very inefficient with emulated mmap, so we use a
// small buffer
@@ -555,7 +561,7 @@ Object readline(VirtualFrame frame, PMMap self,
int nread;
outer: while (self.getPos() < self.getLength()) {
try {
- nread = posixLib.mmapReadBytes(getPosixSupport(), self.getPosixSupportHandle(), self.getPos(), buffer, (int) Math.min(self.getRemaining(), buffer.length));
+ nread = posixLib.mmapReadBytes(context.getPosixSupport(), self.getPosixSupportHandle(), self.getPos(), buffer, (int) Math.min(self.getRemaining(), buffer.length));
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -569,7 +575,7 @@ Object readline(VirtualFrame frame, PMMap self,
}
self.setPos(self.getPos() + nread);
}
- return factory.createBytes(res);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), res);
}
}
@@ -586,9 +592,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static int doIt(VirtualFrame frame, PMMap self, Object dataBuffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("dataBuffer") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
try {
@@ -600,7 +607,7 @@ static int doIt(VirtualFrame frame, PMMap self, Object dataBuffer,
if (self.getPos() > self.getLength() || self.getLength() - self.getPos() < dataLen) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.DATA_OUT_OF_RANGE);
}
- posixLib.mmapWriteBytes(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), self.getPos(), dataBytes, dataLen);
+ posixLib.mmapWriteBytes(context.getPosixSupport(), self.getPosixSupportHandle(), self.getPos(), dataBytes, dataLen);
self.setPos(self.getPos() + dataLen);
return dataLen;
} catch (PosixException e) {
@@ -615,7 +622,6 @@ static int doIt(VirtualFrame frame, PMMap self, Object dataBuffer,
@ArgumentClinic(name = "dist", conversion = ClinicConversion.LongIndex)
@ArgumentClinic(name = "how", conversion = ClinicConversion.Int)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class SeekNode extends PythonTernaryClinicBuiltinNode {
@Override
protected ArgumentClinicProvider getArgumentClinic() {
@@ -665,11 +671,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startIn, Object endIn,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("subBuffer") PythonBufferAccessLibrary bufferLib,
@Cached LongIndexConverterNode startConverter,
@Cached LongIndexConverterNode endConverter,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
try {
@@ -690,7 +697,7 @@ static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startI
byte[] firstBuffer = new byte[bufferSize];
byte[] secondBuffer = new byte[bufferSize];
- readBytes(frame, inliningTarget, self, posixLib, start, secondBuffer, constructAndRaiseNode, raiseNode);
+ readBytes(frame, inliningTarget, self, posixLib, context.getPosixSupport(), start, secondBuffer, constructAndRaiseNode, raiseNode);
for (long selfIdx = start; selfIdx <= end - subLen; selfIdx++, buffersIndex++) {
// Make sure that the buffers have enough room for the search
if (buffersIndex + subLen > bufferSize * 2) {
@@ -699,7 +706,7 @@ static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startI
secondBuffer = tmp;
buffersIndex -= bufferSize; // move to the tail of the first buffer now
long readIndex = selfIdx + subLen - 1;
- readBytes(frame, inliningTarget, self, posixLib, readIndex, secondBuffer, constructAndRaiseNode, raiseNode);
+ readBytes(frame, inliningTarget, self, posixLib, context.getPosixSupport(), readIndex, secondBuffer, constructAndRaiseNode, raiseNode);
// It's OK if we read less than buffer size, the outer loop condition
// 'selfIdx <= end' and the check in readBytes should cover that we don't
// read
@@ -729,12 +736,12 @@ static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startI
}
}
- private static void readBytes(VirtualFrame frame, Node inliningTarget, PMMap self, PosixSupportLibrary posixLib, long index, byte[] buffer, PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- PRaiseNode.Lazy raiseNode) {
+ private static void readBytes(VirtualFrame frame, Node inliningTarget, PMMap self, PosixSupportLibrary posixLib, PosixSupport posixSupport, long index, byte[] buffer,
+ PConstructAndRaiseNode.Lazy constructAndRaiseNode, PRaiseNode.Lazy raiseNode) {
try {
long remaining = self.getLength() - index;
int toReadLen = remaining > buffer.length ? buffer.length : (int) remaining;
- int nread = posixLib.mmapReadBytes(PosixSupport.get(inliningTarget), self.getPosixSupportHandle(), index, buffer, toReadLen);
+ int nread = posixLib.mmapReadBytes(posixSupport, self.getPosixSupportHandle(), index, buffer, toReadLen);
if (toReadLen != nread) {
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, MMAP_CHANGED_LENGTH);
}
@@ -771,10 +778,11 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Specialization
- Object flush(VirtualFrame frame, PMMap self, long offset, Object sizeObj,
+ static Object flush(VirtualFrame frame, PMMap self, long offset, Object sizeObj,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached LongIndexConverterNode sizeConversion,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
long size;
@@ -792,7 +800,7 @@ Object flush(VirtualFrame frame, PMMap self, long offset, Object sizeObj,
}
try {
- posixLib.mmapFlush(getPosixSupport(), self.getPosixSupportHandle(), offset, self.getLength());
+ posixLib.mmapFlush(context.getPosixSupport(), self.getPosixSupportHandle(), offset, self.getLength());
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
index afd41e31b0..a6042bd83a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
@@ -60,6 +60,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -97,7 +98,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -110,6 +111,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -192,11 +194,10 @@ public abstract static class ModuleDictNode extends PythonBinaryBuiltinNode {
static Object doManaged(PythonModule self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetDictIfExistsNode getDict,
- @Cached SetDictNode setDict,
- @Cached PythonObjectFactory factory) {
+ @Cached SetDictNode setDict) {
PDict dict = getDict.execute(self);
if (dict == null) {
- dict = createDict(inliningTarget, self, setDict, factory);
+ dict = createDict(inliningTarget, self, setDict);
}
return dict;
}
@@ -219,8 +220,8 @@ static Object doError(Object self, @SuppressWarnings("unused") Object dict,
throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.DESCRIPTOR_DICT_FOR_MOD_OBJ_DOES_NOT_APPLY_FOR_P, self);
}
- private static PDict createDict(Node inliningTarget, PythonModule self, SetDictNode setDict, PythonObjectFactory factory) {
- PDict dict = factory.createDictFixedStorage(self);
+ private static PDict createDict(Node inliningTarget, PythonModule self, SetDictNode setDict) {
+ PDict dict = PFactory.createDictFixedStorage(PythonLanguage.get(inliningTarget), self);
setDict.execute(inliningTarget, self, dict);
return dict;
}
@@ -314,10 +315,11 @@ static Object get(Object self, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
@Shared("read") @Cached ReadAttributeFromObjectNode read,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached InlinedBranchProfile createAnnotations) {
Object annotations = read.execute(self, T___ANNOTATIONS__);
if (annotations == PNone.NO_VALUE) {
- annotations = factory.get(inliningTarget).createDict();
+ createAnnotations.enter(inliningTarget);
+ annotations = PFactory.createDict(PythonLanguage.get(inliningTarget));
write.execute(self, T___ANNOTATIONS__, annotations);
}
return annotations;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonModule.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonModule.java
index e080f455ea..ba26300675 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonModule.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -41,7 +41,7 @@
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.object.SetDictNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
@@ -109,9 +109,9 @@ private PythonModule(PythonLanguage lang, TruffleString moduleName) {
*/
@TruffleBoundary
public static PythonModule createInternal(TruffleString moduleName) {
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- PythonModule pythonModule = new PythonModule(PythonLanguage.get(null), moduleName);
- PDict dict = factory.createDictFixedStorage(pythonModule);
+ PythonLanguage language = PythonLanguage.get(null);
+ PythonModule pythonModule = new PythonModule(language, moduleName);
+ PDict dict = PFactory.createDictFixedStorage(language, pythonModule);
SetDictNode.executeUncached(pythonModule, dict);
return pythonModule;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
index 8a2222ac7c..ee95c8cd17 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -58,9 +58,9 @@
import java.util.Comparator;
import java.util.List;
-import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
import org.graalvm.collections.Pair;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -82,6 +82,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -94,7 +95,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -169,10 +170,10 @@ static Object reduce(PSimpleNamespace self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached GetOrCreateDictNode getDict,
- @Cached PythonObjectFactory factory) {
- PTuple args = factory.createEmptyTuple();
+ @Bind PythonLanguage language) {
+ PTuple args = PFactory.createEmptyTuple(language);
final PDict dict = getDict.execute(inliningTarget, self);
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args, dict});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args, dict});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
index 373ce219f3..b57d9668a9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
@@ -64,6 +64,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.annotations.Slot;
@@ -142,7 +143,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.nodes.util.SplitArgsNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -815,8 +816,8 @@ static Object dir(VirtualFrame frame, Object obj,
@Cached GetClassNode getClassNode,
@Cached IsSubtypeNode isSubtypeNode,
@Cached com.oracle.graal.python.builtins.objects.type.TypeBuiltins.DirNode dirNode,
- @Cached PythonObjectFactory factory) {
- PSet names = factory.createSet();
+ @Bind PythonLanguage language) {
+ PSet names = PFactory.createSet(language);
Object updateCallable = lookupAttrNode.execute(frame, inliningTarget, names, T_UPDATE);
Object ns = lookupAttrNode.execute(frame, inliningTarget, obj, T___DICT__);
if (isSubtypeNode.execute(frame, getClassNode.execute(inliningTarget, ns), PythonBuiltinClassType.PDict)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
index 8d29113d7c..8e9de09698 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -140,7 +140,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.object.IDUtils;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -329,8 +329,8 @@ static Object id(boolean self,
@Specialization
static Object id(double self,
- @Shared @Cached PythonObjectFactory factory) {
- return IDUtils.getId(self, factory);
+ @Bind PythonLanguage language) {
+ return IDUtils.getId(language, self);
}
@Specialization
@@ -342,8 +342,8 @@ static Object id(PFloat self,
@Specialization
static Object id(long self,
- @Shared @Cached PythonObjectFactory factory) {
- return IDUtils.getId(self, factory);
+ @Bind PythonLanguage language) {
+ return IDUtils.getId(language, self);
}
@Specialization
@@ -556,7 +556,6 @@ static Object getstate(VirtualFrame frame, Node inliningTarget, Object obj, bool
@Cached PyObjectLookupAttrO lookupAttr,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached CheckBasesizeForGetState checkBasesize,
- @Cached PythonObjectFactory.Lazy factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object state;
Object type = getClassNode.execute(inliningTarget, obj);
@@ -592,8 +591,9 @@ static Object getstate(VirtualFrame frame, Node inliningTarget, Object obj, bool
* If we found some slot attributes, pack them in a tuple along the original
* attribute dictionary.
*/
- PDict slotsState = factory.get(inliningTarget).createDict(slotsStorage);
- state = factory.get(inliningTarget).createTuple(new Object[]{state, slotsState});
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
+ PDict slotsState = PFactory.createDict(language, slotsStorage);
+ state = PFactory.createTuple(language, new Object[]{state, slotsState});
}
}
@@ -675,7 +675,7 @@ static Object reduceNewObj(VirtualFrame frame, Node inliningTarget, Object obj,
@Cached PyObjectSizeNode sizeNode,
@Exclusive @Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectGetIter getIter,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object cls = getClassNode.execute(inliningTarget, obj);
if (lookupNew.execute(cls) == PNone.NO_VALUE) {
@@ -703,10 +703,10 @@ static Object reduceNewObj(VirtualFrame frame, Node inliningTarget, Object obj,
} else {
newargsVals = new Object[]{cls};
}
- newargs = factory.createTuple(newargsVals);
+ newargs = PFactory.createTuple(language, newargsVals);
} else if (hasArgsProfile.profile(inliningTarget, hasargs)) {
newobj = lookupAttr.execute(frame, inliningTarget, copyReg, T___NEWOBJ_EX__);
- newargs = factory.createTuple(new Object[]{cls, args, kwargs});
+ newargs = PFactory.createTuple(language, new Object[]{cls, args, kwargs});
} else {
throw raiseNode.get(inliningTarget).raiseBadInternalCall();
}
@@ -719,7 +719,7 @@ static Object reduceNewObj(VirtualFrame frame, Node inliningTarget, Object obj,
Object listitems = objIsList ? getIter.execute(frame, inliningTarget, obj) : PNone.NONE;
Object dictitems = objIsDict ? getIter.execute(frame, inliningTarget, callMethod.execute(frame, inliningTarget, obj, T_ITEMS)) : PNone.NONE;
- return factory.createTuple(new Object[]{newobj, newargs, state, listitems, dictitems});
+ return PFactory.createTuple(language, new Object[]{newobj, newargs, state, listitems, dictitems});
}
@Specialization(guards = "proto < 2")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
index 3e04f31442..95fe5354c5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
@@ -64,6 +64,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -109,7 +110,7 @@
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -292,14 +293,14 @@ static Object reduce(VirtualFrame frame, POrderedDict self,
@Cached PyObjectGetStateNode getStateNode,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectGetIter getIter,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object type = getClassNode.execute(inliningTarget, self);
Object state = getStateNode.execute(frame, inliningTarget, self);
- Object args = factory.createEmptyTuple();
+ Object args = PFactory.createEmptyTuple(language);
// Might be overridden
Object items = callMethod.execute(frame, inliningTarget, self, T_ITEMS);
Object itemsIter = getIter.execute(frame, inliningTarget, items);
- return factory.createTuple(new Object[]{type, args, state, PNone.NONE, itemsIter});
+ return PFactory.createTuple(language, new Object[]{type, args, state, PNone.NONE, itemsIter});
}
}
@@ -360,7 +361,7 @@ static Object popitem(VirtualFrame frame, POrderedDict self, boolean last,
@Bind("this") Node inliningTarget,
@Cached HashingStorageNodes.HashingStorageDelItem delItem,
@Cached ObjectHashMap.RemoveNode removeNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raise) {
ODictNode node = last ? self.last : self.first;
if (node == null) {
@@ -370,7 +371,7 @@ static Object popitem(VirtualFrame frame, POrderedDict self, boolean last,
removeNode.execute(frame, inliningTarget, self.nodes, node.key, node.hash);
// TODO with hash
Object value = delItem.executePop(frame, inliningTarget, self.getDictStorage(), node.key, self);
- return factory.createTuple(new Object[]{node.key, value});
+ return PFactory.createTuple(language, new Object[]{node.key, value});
}
@Override
@@ -453,8 +454,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
abstract static class KeysNode extends PythonUnaryBuiltinNode {
@Specialization
static Object keys(POrderedDict self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictKeys(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictKeys(language, self);
}
}
@@ -463,8 +464,8 @@ static Object keys(POrderedDict self,
abstract static class ValuesNode extends PythonUnaryBuiltinNode {
@Specialization
static Object values(POrderedDict self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictValues(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictValues(language, self);
}
}
@@ -473,8 +474,8 @@ static Object values(POrderedDict self,
abstract static class ItemsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object items(POrderedDict self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictItems(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictItems(language, self);
}
}
@@ -483,8 +484,8 @@ static Object items(POrderedDict self,
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(POrderedDict self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator(self, POrderedDictIterator.IteratorType.KEYS, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, self, POrderedDictIterator.IteratorType.KEYS, false);
}
}
@@ -493,8 +494,8 @@ static Object iter(POrderedDict self,
abstract static class ReversedNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(POrderedDict self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator(self, POrderedDictIterator.IteratorType.KEYS, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, self, POrderedDictIterator.IteratorType.KEYS, true);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictItemsBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictItemsBuiltins.java
index e789b2024d..d54a72325c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictItemsBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictItemsBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -52,8 +53,8 @@
import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictItemsView;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -70,8 +71,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictItemsView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.ITEMS, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.ITEMS, false);
}
}
@@ -80,8 +81,8 @@ static Object iter(PDictItemsView self,
abstract static class ReversedNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictItemsView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.ITEMS, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.ITEMS, true);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
index 0ea2b63941..97e798523a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -64,7 +65,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -96,8 +97,7 @@ abstract static class NextNode extends PythonUnaryBuiltinNode {
static Object next(VirtualFrame frame, POrderedDictIterator self,
@Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode,
- @Cached HashingStorageNodes.HashingStorageGetItemWithHash getItem,
- @Cached PythonObjectFactory factory) {
+ @Cached HashingStorageNodes.HashingStorageGetItemWithHash getItem) {
if (self.current == null) {
throw raiseNode.raise(StopIteration);
}
@@ -116,7 +116,7 @@ static Object next(VirtualFrame frame, POrderedDictIterator self,
if (self.type == POrderedDictIterator.IteratorType.VALUES) {
result = value;
} else {
- result = factory.createTuple(new Object[]{key, value});
+ result = PFactory.createTuple(PythonLanguage.get(inliningTarget), new Object[]{key, value});
}
}
if (!self.reversed) {
@@ -135,16 +135,16 @@ abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(VirtualFrame frame, POrderedDictIterator self,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttr,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached ListNodes.ConstructListNode constructListNode) {
PythonContext context = PythonContext.get(inliningTarget);
Object iterBuiltin = getAttr.execute(frame, inliningTarget, context.getBuiltins(), T_ITER);
- POrderedDictIterator copy = factory.createOrderedDictIterator(self.dict, self.type, self.reversed);
+ POrderedDictIterator copy = PFactory.createOrderedDictIterator(language, self.dict, self.type, self.reversed);
copy.current = self.current;
/* iterate the temporary into a list */
PList list = constructListNode.execute(frame, copy);
- PTuple args = factory.createTuple(new Object[]{list});
- return factory.createTuple(new Object[]{iterBuiltin, args});
+ PTuple args = PFactory.createTuple(language, new Object[]{list});
+ return PFactory.createTuple(language, new Object[]{iterBuiltin, args});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictKeysBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictKeysBuiltins.java
index b394891511..0863121e61 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictKeysBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictKeysBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -52,8 +53,8 @@
import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictKeysView;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -70,8 +71,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictKeysView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.KEYS, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.KEYS, false);
}
}
@@ -80,8 +81,8 @@ static Object iter(PDictKeysView self,
abstract static class ReversedNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictKeysView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.KEYS, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.KEYS, true);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictValuesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictValuesBuiltins.java
index 66b74ea5b8..0d362211a6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictValuesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictValuesBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -52,8 +53,8 @@
import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValuesView;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -70,8 +71,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictValuesView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.VALUES, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.VALUES, false);
}
}
@@ -80,8 +81,8 @@ static Object iter(PDictValuesView self,
abstract static class ReversedNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PDictValuesView self,
- @Cached PythonObjectFactory factory) {
- return factory.createOrderedDictIterator((POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.VALUES, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createOrderedDictIterator(language, (POrderedDict) self.getWrappedDict(), POrderedDictIterator.IteratorType.VALUES, true);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/DirEntryBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/DirEntryBuiltins.java
index a82890023e..cff17ec06d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/DirEntryBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/DirEntryBuiltins.java
@@ -56,6 +56,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -80,7 +81,8 @@
import com.oracle.graal.python.runtime.PosixSupport;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -108,17 +110,17 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateNodeFactory
abstract static class NameNode extends PythonUnaryBuiltinNode {
@Specialization
- Object nameAsBytes(VirtualFrame frame, PDirEntry self,
+ static Object nameAsBytes(VirtualFrame frame, PDirEntry self,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile produceBytesProfile,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
if (produceBytesProfile.profile(inliningTarget, self.produceBytes())) {
- return opaquePathToBytes(posixLib.dirEntryGetName(getPosixSupport(), self.dirEntryData), posixLib, getPosixSupport(), factory);
+ return opaquePathToBytes(posixLib.dirEntryGetName(context.getPosixSupport(), self.dirEntryData), posixLib, context.getPosixSupport(), context.getLanguage(inliningTarget));
} else {
- return posixLib.getPathAsString(getPosixSupport(), posixLib.dirEntryGetName(getPosixSupport(), self.dirEntryData));
+ return posixLib.getPathAsString(context.getPosixSupport(), posixLib.dirEntryGetName(context.getPosixSupport(), self.dirEntryData));
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
@@ -153,25 +155,25 @@ static PosixPath cached(PDirEntry self) {
@Specialization(guards = "self.pathCache == null")
static PosixPath createBytes(VirtualFrame frame, Node inliningTarget, PDirEntry self,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile produceBytesProfile,
@Cached InlinedConditionProfile posixPathProfile,
- @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
- @Cached PythonObjectFactory.Lazy factory,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Object opaquePath;
try {
if (posixPathProfile.profile(inliningTarget, self.scandirPath instanceof PosixPath)) {
- opaquePath = posixLib.dirEntryGetPath(PosixSupport.get(inliningTarget), self.dirEntryData, ((PosixPath) self.scandirPath).value);
+ opaquePath = posixLib.dirEntryGetPath(context.getPosixSupport(), self.dirEntryData, ((PosixPath) self.scandirPath).value);
} else {
- opaquePath = posixLib.dirEntryGetName(PosixSupport.get(inliningTarget), self.dirEntryData);
+ opaquePath = posixLib.dirEntryGetName(context.getPosixSupport(), self.dirEntryData);
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
if (produceBytesProfile.profile(inliningTarget, self.produceBytes())) {
- self.pathCache = new PosixPath(opaquePathToBytes(opaquePath, posixLib, PosixSupport.get(inliningTarget), factory.get(inliningTarget)), opaquePath, true);
+ self.pathCache = new PosixPath(opaquePathToBytes(opaquePath, posixLib, context.getPosixSupport(), context.getLanguage(inliningTarget)), opaquePath, true);
} else {
- self.pathCache = new PosixPath(posixLib.getPathAsString(PosixSupport.get(inliningTarget), opaquePath), opaquePath, false);
+ self.pathCache = new PosixPath(posixLib.getPathAsString(context.getPosixSupport(), opaquePath), opaquePath, false);
}
return self.pathCache;
}
@@ -252,32 +254,32 @@ static PTuple cachedLStat(PDirEntry self, boolean followSymlinks, boolean catchN
@Specialization(guards = {"followSymlinks", "self.statCache == null", "isSymlink"}, limit = "1")
static PTuple uncachedStatWithSymlink(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@SuppressWarnings("unused") @Cached IsSymlinkNode isSymlinkNode,
@SuppressWarnings("unused") @Bind("isSymlinkNode.executeBoolean(frame, self)") boolean isSymlink,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
@Shared("cachedPosixPathNode") @Cached CachedPosixPathNode cachedPosixPathNode,
@Shared("positiveLongProfile") @Cached InlinedConditionProfile positiveLongProfile,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
// There are two caches - one for `follow_symlinks=True` and the other for
// 'follow_symlinks=False`. They are different only when the dir entry is a symlink.
- return uncachedLStatWithSymlink(frame, self, followSymlinks, catchNoent, inliningTarget, posixLib, cachedPosixPathNode, positiveLongProfile, constructAndRaiseNode, factory);
+ return uncachedLStatWithSymlink(frame, self, followSymlinks, catchNoent, inliningTarget, context, posixLib, cachedPosixPathNode, positiveLongProfile, constructAndRaiseNode);
}
@Specialization(guards = {"!followSymlinks", "self.lstatCache == null"})
static PTuple uncachedLStatWithSymlink(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
@Bind("this") Node inliningTarget,
- @Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared("cachedPosixPathNode") @Cached CachedPosixPathNode cachedPosixPathNode,
@Shared("positiveLongProfile") @Cached InlinedConditionProfile positiveLongProfile,
- @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
PTuple res;
int dirFd = self.scandirPath instanceof PosixFd ? ((PosixFd) self.scandirPath).fd : AT_FDCWD.value;
PosixPath posixPath = cachedPosixPathNode.execute(frame, inliningTarget, self);
try {
- long[] rawStat = posixLib.fstatat(PosixSupport.get(inliningTarget), dirFd, posixPath.value, followSymlinks);
- res = PosixModuleBuiltins.createStatResult(inliningTarget, factory, positiveLongProfile, rawStat);
+ long[] rawStat = posixLib.fstatat(context.getPosixSupport(), dirFd, posixPath.value, followSymlinks);
+ res = PosixModuleBuiltins.createStatResult(inliningTarget, context.getLanguage(inliningTarget), positiveLongProfile, rawStat);
} catch (PosixException e) {
if (catchNoent && e.getErrorCode() == OSErrorEnum.ENOENT.getNumber()) {
return null;
@@ -423,8 +425,8 @@ static boolean isDir(VirtualFrame frame, PDirEntry self, boolean followSymlinks,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
index 89ba012a09..e903bc3407 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -63,7 +63,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.dsl.Bind;
@@ -112,7 +112,7 @@ static PDirEntry next(VirtualFrame frame, PScandirIterator self,
@Bind("this") Node inliningTarget,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
if (self.ref.isReleased()) {
throw raiseNode.get(inliningTarget).raiseStopIteration();
@@ -124,7 +124,7 @@ static PDirEntry next(VirtualFrame frame, PScandirIterator self,
self.ref.rewindAndClose(posixLib, posixSupport);
throw raiseNode.get(inliningTarget).raiseStopIteration();
}
- return factory.createDirEntry(dirEntryData, self.path);
+ return PFactory.createDirEntry(language, dirEntryData, self.path);
} catch (PosixException e) {
self.ref.rewindAndClose(posixLib, posixSupport);
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
index 488d1eef29..d52d7949ae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -81,7 +82,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -256,7 +257,7 @@ static Object copy(PProperty pold, Object getArg, Object setArg, Object delArg)
// shortcut: create new property object directly
if (IsBuiltinClassProfile.profileClassSlowPath(type, PythonBuiltinClassType.PProperty)) {
- PProperty copy = PythonObjectFactory.getUncached().createProperty();
+ PProperty copy = PFactory.createProperty(PythonLanguage.get(null));
PropertyInitNode.doGeneric(copy, get, set, del, doc);
return copy;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
index a149c1b169..3d4947b771 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -67,7 +68,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
import com.oracle.graal.python.runtime.GilNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -294,8 +295,8 @@ static PNone doGeneric(PSimpleQueue self, Object item,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
index f17d91e9e0..13a8a35714 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.security.SecureRandom;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
import com.oracle.graal.python.builtins.Builtin;
@@ -69,7 +70,7 @@
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -191,8 +192,8 @@ public abstract static class GetStateNode extends PythonBuiltinNode {
@Specialization
static PTuple getstate(PRandom random,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(encodeState(random));
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, encodeState(random));
}
@TruffleBoundary
@@ -275,7 +276,7 @@ static PInt genBigInteger(PRandom random, int k) {
bb.putInt(4 * i, x);
}
bb.putInt(0, random.nextInt() >>> (32 - (k % 32)));
- return PythonObjectFactory.getUncached().createInt(new BigInteger(1, bb.array()));
+ return PFactory.createInt(PythonLanguage.get(null), new BigInteger(1, bb.array()));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
index 2fa9c621ed..ffaef39146 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -41,6 +41,7 @@
import java.math.BigInteger;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -91,7 +92,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaBigIntegerNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -128,8 +129,8 @@ public abstract static class HashNode extends PythonBuiltinNode {
@Specialization
static long hash(VirtualFrame frame, PIntRange self,
@Bind("this") Node inliningTarget,
- @Shared("hashNode") @Cached PyObjectHashNode hashNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared("hashNode") @Cached PyObjectHashNode hashNode) {
Object[] content = new Object[3];
int intLength = self.getIntLength();
content[0] = intLength;
@@ -143,14 +144,14 @@ static long hash(VirtualFrame frame, PIntRange self,
content[1] = self.getIntStart();
content[2] = self.getIntStep();
}
- return hashNode.execute(frame, inliningTarget, factory.createTuple(content));
+ return hashNode.execute(frame, inliningTarget, PFactory.createTuple(language, content));
}
@Specialization
static long hash(VirtualFrame frame, PBigRange self,
@Bind("this") Node inliningTarget,
- @Shared("hashNode") @Cached PyObjectHashNode hashNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared("hashNode") @Cached PyObjectHashNode hashNode) {
Object[] content = new Object[3];
PInt length = self.getPIntLength();
content[0] = length;
@@ -164,7 +165,7 @@ static long hash(VirtualFrame frame, PBigRange self,
content[1] = self.getStart();
content[2] = self.getStep();
}
- return hashNode.execute(frame, inliningTarget, factory.createTuple(content));
+ return hashNode.execute(frame, inliningTarget, PFactory.createTuple(language, content));
}
}
@@ -246,14 +247,14 @@ boolean doPBigRange(PBigRange self) {
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doPIntRange(PIntRange self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createIntRangeIterator(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntRangeIterator(language, self);
}
@Specialization
static Object doPIntRange(PBigRange self,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createBigRangeIterator(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createBigRangeIterator(language, self);
}
}
@@ -296,10 +297,10 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
@Specialization
static Object reduce(PRange self,
@Bind("this") Node inliningTarget,
- @Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
- PTuple args = factory.createTuple(new Object[]{self.getStart(), self.getStop(), self.getStep()});
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args});
+ @Bind PythonLanguage language,
+ @Cached GetClassNode getClassNode) {
+ PTuple args = PFactory.createTuple(language, new Object[]{self.getStart(), self.getStop(), self.getStep()});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args});
}
}
@@ -421,8 +422,8 @@ static int doInt(PIntRange self, int index,
@InliningCutoff
static Object doBigInt(PBigRange self, int index,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory) {
- return factory.createInt(self.getBigIntItemNormalized(GetItemNode.computeBigRangeItem(inliningTarget, self, index)));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, self.getBigIntItemNormalized(GetItemNode.computeBigRangeItem(inliningTarget, self, index)));
}
}
@@ -464,9 +465,8 @@ static Object doPRange(VirtualFrame frame, PIntRange self, Object idx,
static Object doPRange(PBigRange self, Object idx,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached CastToJavaBigIntegerNode toBigInt,
- @SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createInt(self.getBigIntItemNormalized(computeBigRangeItem(inliningTarget, self, idx, toBigInt)));
+ @SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode) {
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), self.getBigIntItemNormalized(computeBigRangeItem(inliningTarget, self, idx, toBigInt)));
}
@Specialization(guards = "!canBeIndex(this, slice, indexCheckNode)")
@@ -479,13 +479,12 @@ static Object doPRangeSliceSlowPath(VirtualFrame frame, PIntRange self, PSlice s
@Shared @Cached CoerceToObjectSlice toBigIntSlice,
@Shared @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode) {
try {
final int rStart = self.getIntStart();
final int rStep = self.getIntStep();
SliceInfo info = compute.execute(frame, slice, self.getIntLength());
- return createRange(inliningTarget, info, rStart, rStep, lenOfRangeNodeExact, factory);
+ return createRange(inliningTarget, info, rStart, rStep, lenOfRangeNodeExact);
} catch (PException pe) {
pe.expect(inliningTarget, PythonBuiltinClassType.OverflowError, profileError);
// pass
@@ -496,7 +495,7 @@ static Object doPRangeSliceSlowPath(VirtualFrame frame, PIntRange self, PSlice s
BigInteger rangeStart = rangeBI.getBigIntegerStart();
BigInteger rangeStep = rangeBI.getBigIntegerStep();
- SliceObjectInfo info = PObjectSlice.computeIndicesSlowPath(toBigIntSlice.execute(slice), rangeBI.getBigIntegerLength(), null);
+ SliceObjectInfo info = PObjectSlice.computeIndicesSlowPath(toBigIntSlice.execute(slice), rangeBI.getBigIntegerLength(), false);
return createRange(inliningTarget, info, rangeStart, rangeStep, lenOfRangeNode);
}
@@ -514,14 +513,13 @@ static Object doPRangeSliceSlowPath(VirtualFrame frame, PBigRange self, PSlice s
@Shared @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
@SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PythonObjectFactory factory,
// unused node to avoid mixing shared and non-shared inlined nodes
@SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) {
try {
int rStart = asSizeNode.executeExact(frame, inliningTarget, self.getStart());
int rStep = asSizeNode.executeExact(frame, inliningTarget, self.getStep());
SliceInfo info = compute.execute(frame, slice, asSizeNode.executeExact(frame, inliningTarget, self.getLength()));
- return createRange(inliningTarget, info, rStart, rStep, lenOfRangeNodeExact, factory);
+ return createRange(inliningTarget, info, rStart, rStep, lenOfRangeNodeExact);
} catch (PException pe) {
pe.expect(inliningTarget, PythonBuiltinClassType.OverflowError, profileError);
// pass
@@ -532,7 +530,7 @@ static Object doPRangeSliceSlowPath(VirtualFrame frame, PBigRange self, PSlice s
BigInteger rangeStart = rangeBI.getBigIntegerStart();
BigInteger rangeStep = rangeBI.getBigIntegerStep();
- SliceObjectInfo info = PObjectSlice.computeIndicesSlowPath(toBigIntSlice.execute(slice), rangeBI.getBigIntegerLength(), null);
+ SliceObjectInfo info = PObjectSlice.computeIndicesSlowPath(toBigIntSlice.execute(slice), rangeBI.getBigIntegerLength(), false);
return createRange(inliningTarget, info, rangeStart, rangeStep, lenOfRangeNode);
}
@@ -552,22 +550,21 @@ static Object doGeneric(VirtualFrame frame, PRange self, Object idx,
@Shared @Cached PyIndexCheckNode indexCheckNode,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (isNumIndexProfile.profile(inliningTarget, canBeIndex(inliningTarget, idx, indexCheckNode))) {
if (self instanceof PIntRange) {
return doPRange(frame, (PIntRange) self, idx, inliningTarget, indexCheckNode, asSizeNode, normalize);
}
- return doPRange((PBigRange) self, idx, inliningTarget, toBigInt, indexCheckNode, factory);
+ return doPRange((PBigRange) self, idx, inliningTarget, toBigInt, indexCheckNode);
}
if (isSliceIndexProfile.profile(inliningTarget, idx instanceof PSlice)) {
PSlice slice = (PSlice) idx;
if (self instanceof PIntRange) {
return doPRangeSliceSlowPath(frame, (PIntRange) self, slice, inliningTarget, compute, profileError, toBigIntRange, toBigIntSlice, lenOfRangeNodeExact, lenOfRangeNode,
- indexCheckNode, factory);
+ indexCheckNode);
}
return doPRangeSliceSlowPath(frame, (PBigRange) self, slice, inliningTarget, isNumIndexProfile, isSliceIndexProfile, compute, profileError, toBigIntRange, toBigIntSlice,
- lenOfRangeNodeExact, lenOfRangeNode, indexCheckNode, asSizeNode, factory, raiseNode);
+ lenOfRangeNodeExact, lenOfRangeNode, indexCheckNode, asSizeNode, raiseNode);
}
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "range", idx);
}
@@ -599,12 +596,12 @@ private static BigInteger computeBigRangeItem(Node inliningTarget, PBigRange ran
return i;
}
- private static PIntRange createRange(Node inliningTarget, SliceInfo info, int rStart, int rStep, LenOfIntRangeNodeExact lenOfRangeNode, PythonObjectFactory factory) throws OverflowException {
+ private static PIntRange createRange(Node inliningTarget, SliceInfo info, int rStart, int rStep, LenOfIntRangeNodeExact lenOfRangeNode) throws OverflowException {
int newStep = rStep * info.step;
int newStart = rStart + info.start * rStep;
int newStop = rStart + info.stop * rStep;
int len = lenOfRangeNode.executeInt(inliningTarget, newStart, newStop, newStep);
- return factory.createIntRange(newStart, newStop, newStep, len);
+ return PFactory.createIntRange(PythonLanguage.get(inliningTarget), newStart, newStop, newStep, len);
}
@TruffleBoundary
@@ -617,8 +614,8 @@ private static PBigRange createRange(Node inliningTarget, SliceObjectInfo info,
BigInteger start = rStart.add(sliceStart.multiply(rStep));
BigInteger stop = rStart.add(sliceStop.multiply(rStep));
BigInteger len = lenOfRangeNode.execute(inliningTarget, start, stop, step);
- PythonObjectFactory factory = PythonObjectFactory.getUncached();
- return factory.createBigRange(factory.createInt(start), factory.createInt(stop), factory.createInt(step), factory.createInt(len));
+ PythonLanguage language = PythonLanguage.get(null);
+ return PFactory.createBigRange(language, PFactory.createInt(language, start), PFactory.createInt(language, stop), PFactory.createInt(language, step), PFactory.createInt(language, len));
}
@NeverDefault
@@ -874,12 +871,11 @@ static Object doLongRange(VirtualFrame frame, PBigRange self, Object elem,
@Bind("this") Node inliningTarget,
@Shared @Cached ContainsNode containsNode,
@Cached CastToJavaBigIntegerNode castToBigInt,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
if (containsNode.execute(frame, self, elem)) {
BigInteger index = slowIntIndex(inliningTarget, self, elem, castToBigInt);
if (index != null) {
- return factory.createInt(index);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), index);
}
}
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
index 057719c193..f139b88e3e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,12 +45,13 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.slice.PSlice.SliceInfo;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.util.CastToJavaBigIntegerNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -84,14 +85,15 @@ static PBigRange createBigRange(Node inliningTarget, Object start, Object stop,
@Cached CastToJavaBigIntegerNode startToBI,
@Cached CastToJavaBigIntegerNode stopToBI,
@Cached CastToJavaBigIntegerNode stepToBI,
- @Cached PRaiseNode.Lazy raise,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached PRaiseNode.Lazy raise) {
BigInteger stepBI = stepToBI.execute(inliningTarget, step);
checkStepZero(inliningTarget, stepBI, raise);
BigInteger startBI = startToBI.execute(inliningTarget, start);
BigInteger stopBI = stopToBI.execute(inliningTarget, stop);
BigInteger len = lenOfRangeNode.execute(inliningTarget, startBI, stopBI, stepBI);
- return factory.createBigRange(factory.createInt(startBI), factory.createInt(stopBI), factory.createInt(stepBI), factory.createInt(len));
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
+ return PFactory.createBigRange(language, PFactory.createInt(language, startBI), PFactory.createInt(language, stopBI), PFactory.createInt(language, stepBI),
+ PFactory.createInt(language, len));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
index 0cc8893301..f299f37366 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -73,7 +74,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -242,8 +243,8 @@ Object eq(Object self, Object other) {
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
index 801dfb46d2..8dae6a67ea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -36,6 +36,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -179,22 +180,22 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PStringReverseIterator self,
@Bind("this") Node inliningTarget,
@Shared("getClassNode") @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.isExhausted()) {
- return reduceInternal(inliningTarget, self, "", null, getClassNode, factory);
+ return reduceInternal(inliningTarget, self, "", null, getClassNode, language);
}
- return reduceInternal(inliningTarget, self, self.value, self.index, getClassNode, factory);
+ return reduceInternal(inliningTarget, self, self.value, self.index, getClassNode, language);
}
@Specialization(guards = "self.isPSequence()")
static Object reduce(PSequenceReverseIterator self,
@Bind("this") Node inliningTarget,
@Shared("getClassNode") @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.isExhausted()) {
- return reduceInternal(inliningTarget, self, factory.createList(), null, getClassNode, factory);
+ return reduceInternal(inliningTarget, self, PFactory.createList(language), null, getClassNode, language);
}
- return reduceInternal(inliningTarget, self, self.getPSequence(), self.index, getClassNode, factory);
+ return reduceInternal(inliningTarget, self, self.getPSequence(), self.index, getClassNode, language);
}
@Specialization(guards = "!self.isPSequence()")
@@ -202,19 +203,19 @@ static Object reduce(VirtualFrame frame, PSequenceReverseIterator self,
@Bind("this") Node inliningTarget,
@Cached("create(T___REDUCE__)") LookupAndCallUnaryNode callReduce,
@Shared("getClassNode") @Cached GetClassNode getClassNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object content = callReduce.executeObject(frame, self.getObject());
- return reduceInternal(inliningTarget, self, content, self.index, getClassNode, factory);
+ return reduceInternal(inliningTarget, self, content, self.index, getClassNode, language);
}
- private static PTuple reduceInternal(Node inliningTarget, Object self, Object arg, Object state, GetClassNode getClassNode, PythonObjectFactory factory) {
+ private static PTuple reduceInternal(Node inliningTarget, Object self, Object arg, Object state, GetClassNode getClassNode, PythonLanguage language) {
Object revIter = getClassNode.execute(inliningTarget, self);
- PTuple args = factory.createTuple(new Object[]{arg});
+ PTuple args = PFactory.createTuple(language, new Object[]{arg});
// callable, args, state (optional)
if (state != null) {
- return factory.createTuple(new Object[]{revIter, args, state});
+ return PFactory.createTuple(language, new Object[]{revIter, args, state});
} else {
- return factory.createTuple(new Object[]{revIter, args});
+ return PFactory.createTuple(language, new Object[]{revIter, args});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java
index 43408ee3bb..efdb549f23 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java
@@ -61,6 +61,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -101,10 +102,9 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -198,9 +198,9 @@ static Object doBaseSet(PBaseSet self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetIterator getIterator,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getDictStorage();
- return factory.createBaseSetIterator(self, getIterator.execute(inliningTarget, storage), lenNode.execute(inliningTarget, storage));
+ return PFactory.createBaseSetIterator(language, self, getIterator.execute(inliningTarget, storage), lenNode.execute(inliningTarget, storage));
}
}
@@ -229,7 +229,7 @@ static Object reduce(VirtualFrame frame, PBaseSet self,
@Cached HashingStorageIteratorKey getIterKey,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetStateNode getStateNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage storage = self.getDictStorage();
int len = lenNode.execute(inliningTarget, storage);
Object[] keysArray = new Object[len];
@@ -239,9 +239,9 @@ static Object reduce(VirtualFrame frame, PBaseSet self,
assert hasNext;
keysArray[i] = getIterKey.execute(inliningTarget, storage, it);
}
- PTuple contents = factory.createTuple(new Object[]{factory.createList(keysArray)});
+ PTuple contents = PFactory.createTuple(language, new Object[]{PFactory.createList(language, keysArray)});
Object state = getStateNode.execute(frame, inliningTarget, self);
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), contents, state});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), contents, state});
}
}
@@ -282,14 +282,14 @@ abstract static class CreateSetNode extends Node {
@Specialization
static PBaseSet doSet(HashingStorage storage, @SuppressWarnings("unused") PSet template,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createSet(storage);
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language, storage);
}
@Specialization
static PBaseSet doFrozenSet(HashingStorage storage, @SuppressWarnings("unused") PFrozenSet template,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createFrozenSet(storage);
+ @Bind PythonLanguage language) {
+ return PFactory.createFrozenSet(language, storage);
}
}
@@ -556,10 +556,10 @@ static Object doPSet(Node inliningTarget, PSet key,
@Cached HashingStorageCopy copyNode,
@Cached GetClassNode getClassNode,
@Cached(parameters = "Hash", inline = false) LookupCallableSlotInMRONode lookupHash,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached InlinedConditionProfile createSet) {
Object hashDescr = lookupHash.execute(getClassNode.execute(inliningTarget, key));
- if (hashDescr instanceof PNone) {
- return factory.get(inliningTarget).createFrozenSet(copyNode.execute(inliningTarget, key.getDictStorage()));
+ if (createSet.profile(inliningTarget, hashDescr instanceof PNone)) {
+ return PFactory.createFrozenSet(PythonLanguage.get(inliningTarget), copyNode.execute(inliningTarget, key.getDictStorage()));
} else {
return key;
}
@@ -571,8 +571,8 @@ static Object doPSet(Node inliningTarget, PSet key,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java
index ecee481ff7..63062f42f0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java
@@ -29,6 +29,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -38,6 +39,7 @@
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes.GetSetStorageNode;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
+import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageAddAllToOther;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageCopy;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageDiff;
@@ -52,8 +54,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsAnyBuiltinObjectProfile;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -79,16 +80,17 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateNodeFactory
public abstract static class CopyNode extends PythonUnaryBuiltinNode {
- @Specialization
- static PFrozenSet subFrozensetIdentity(PFrozenSet arg,
+ @Specialization(guards = "isBuiltinFrozenSet(self)")
+ static PFrozenSet frozenSetIdentity(PFrozenSet self) {
+ return self;
+ }
+
+ @Specialization(guards = "!isBuiltinFrozenSet(self)")
+ static PFrozenSet doGeneric(PFrozenSet self,
@Bind("this") Node inliningTarget,
- @Cached IsAnyBuiltinObjectProfile isBuiltinClass,
- @Cached PythonObjectFactory.Lazy factory) {
- if (isBuiltinClass.profileIsAnyBuiltinObject(inliningTarget, arg)) {
- return arg;
- } else {
- return factory.get(inliningTarget).createFrozenSet(arg.getDictStorage());
- }
+ @Bind PythonLanguage language,
+ @Cached HashingStorageNodes.HashingStorageCopy copy) {
+ return PFactory.createFrozenSet(language, copy.execute(inliningTarget, self.getDictStorage()));
}
}
@@ -98,8 +100,8 @@ public abstract static class IntersectNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(other)")
static PFrozenSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PFrozenSet self, @SuppressWarnings("unused") PNone other,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFrozenSet(self.getDictStorage());
+ @Bind PythonLanguage language) {
+ return PFactory.createFrozenSet(language, self.getDictStorage());
}
@Specialization(guards = {"args.length == len", "args.length < 32"}, limit = "3")
@@ -109,12 +111,12 @@ static PBaseSet doCached(VirtualFrame frame, PFrozenSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = intersectNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
@Specialization(replaces = "doCached")
@@ -123,12 +125,12 @@ static PBaseSet doGeneric(VirtualFrame frame, PFrozenSet self, Object[] args,
@Shared @Cached GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = intersectNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
static boolean isOther(Object arg) {
@@ -140,9 +142,9 @@ static PFrozenSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PFrozenS
@Bind("this") Node inliningTarget,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = intersectNode.execute(frame, inliningTarget, self.getDictStorage(), getSetStorageNode.execute(frame, inliningTarget, other));
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
}
@@ -155,9 +157,9 @@ static PFrozenSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PFrozenS
@Bind("this") Node inliningTarget,
@Cached HashingCollectionNodes.GetSetStorageNode getHashingStorage,
@Cached HashingStorageXor xorNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = xorNode.execute(frame, inliningTarget, self.getDictStorage(), getHashingStorage.execute(frame, inliningTarget, other));
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
}
@@ -167,8 +169,8 @@ public abstract static class DifferenceNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(other)")
static PFrozenSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PFrozenSet self, @SuppressWarnings("unused") PNone other,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createFrozenSet(self.getDictStorage());
+ @Bind PythonLanguage language) {
+ return PFactory.createFrozenSet(language, self.getDictStorage());
}
@Specialization(guards = {"args.length == len", "args.length < 32"}, limit = "3")
@@ -178,12 +180,12 @@ static PBaseSet doCached(VirtualFrame frame, PFrozenSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = diffNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
@Specialization(replaces = "doCached")
@@ -192,12 +194,12 @@ static PBaseSet doGeneric(VirtualFrame frame, PFrozenSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = diffNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
static boolean isOther(Object arg) {
@@ -209,9 +211,9 @@ static PFrozenSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PFrozenS
@Bind("this") Node inliningTarget,
@Shared @Cached GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = diffNode.execute(frame, inliningTarget, self.getDictStorage(), getSetStorageNode.execute(frame, inliningTarget, other));
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
}
@@ -226,12 +228,12 @@ static PBaseSet doCached(VirtualFrame frame, PBaseSet self, Object[] args,
@Shared @Cached GetSetStorageNode getHashingStorage,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageAddAllToOther addAllToOther,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = addAllToOther.execute(frame, inliningTarget, getHashingStorage.execute(frame, inliningTarget, args[i]), result);
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
@Specialization(replaces = "doCached")
@@ -240,12 +242,12 @@ static PBaseSet doGeneric(VirtualFrame frame, PBaseSet self, Object[] args,
@Shared @Cached GetSetStorageNode getHashingStorage,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageAddAllToOther addAllToOther,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = addAllToOther.execute(frame, inliningTarget, getHashingStorage.execute(frame, inliningTarget, args[i]), result);
}
- return factory.createFrozenSet(result);
+ return PFactory.createFrozenSet(language, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
index a789168129..bbe0f3ea1e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
@@ -36,6 +36,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -75,7 +76,7 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
@@ -149,8 +150,8 @@ public abstract static class CopyNode extends PythonBuiltinNode {
static PSet doSet(PSet self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory) {
- return factory.createSet(copyNode.execute(inliningTarget, self.getDictStorage()));
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language, copyNode.execute(inliningTarget, self.getDictStorage()));
}
}
@@ -209,12 +210,12 @@ static PBaseSet doCached(VirtualFrame frame, PSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageAddAllToOther addAllToOther,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = addAllToOther.execute(frame, inliningTarget, getSetStorageNode.execute(frame, inliningTarget, args[i]), result);
}
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
@Specialization(replaces = "doCached")
@@ -223,12 +224,12 @@ static PBaseSet doGeneric(VirtualFrame frame, PSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageAddAllToOther addAllToOther,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = addAllToOther.execute(frame, inliningTarget, getSetStorageNode.execute(frame, inliningTarget, args[i]), result);
}
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
}
@@ -405,10 +406,9 @@ public abstract static class IntersectNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(other)")
Object doSet(@SuppressWarnings("unused") VirtualFrame frame, PSet self, @SuppressWarnings("unused") PNone other,
@Bind("this") Node inliningTarget,
- @Shared @Cached HashingStorageCopy copyNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached HashingStorageCopy copyNode) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
- return createResult(self, result, factory);
+ return createResult(self, result);
}
@Specialization(guards = {"args.length == len", "args.length < 32"}, limit = "3")
@@ -417,13 +417,12 @@ Object doCached(VirtualFrame frame, PSet self, Object[] args,
@Cached("args.length") int len,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
- @Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached HashingStorageIntersect intersectNode) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = intersectNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return createResult(self, result, factory);
+ return createResult(self, result);
}
@Specialization(replaces = "doCached")
@@ -431,13 +430,12 @@ Object doGeneric(VirtualFrame frame, PSet self, Object[] args,
@Bind("this") Node inliningTarget,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
- @Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached HashingStorageIntersect intersectNode) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = intersectNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return createResult(self, result, factory);
+ return createResult(self, result);
}
static boolean isOther(Object arg) {
@@ -450,14 +448,14 @@ Object doSet(VirtualFrame frame, PSet self, Object other,
@Shared @Cached GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageIntersect intersectNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
result = intersectNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, other));
- return createResult(self, result, factory);
+ return PFactory.createSet(language, result);
}
- protected Object createResult(PSet self, HashingStorage result, PythonObjectFactory factory) {
- return factory.createSet(result);
+ protected Object createResult(PSet self, HashingStorage result) {
+ return PFactory.createSet(PythonLanguage.get(this), result);
}
}
@@ -465,8 +463,7 @@ protected Object createResult(PSet self, HashingStorage result, PythonObjectFact
@GenerateNodeFactory
@ImportStatic({SpecialMethodNames.class})
public abstract static class IntersectUpdateNode extends IntersectNode {
- @Override
- protected Object createResult(PSet self, HashingStorage result, PythonObjectFactory factory) {
+ protected Object createResult(PSet self, HashingStorage result) {
// In order to be compatible w.r.t. __eq__ calls we cannot reuse self storage
self.setDictStorage(result);
return PNone.NONE;
@@ -501,9 +498,9 @@ static PSet doSet(VirtualFrame frame, PSet self, Object other,
@Bind("this") Node inliningTarget,
@Cached GetSetStorageNode getHashingStorage,
@Cached HashingStorageXor xorNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = xorNode.execute(frame, inliningTarget, self.getDictStorage(), getHashingStorage.execute(frame, inliningTarget, other));
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
}
@@ -584,8 +581,8 @@ public abstract static class DifferenceNode extends PythonBuiltinNode {
@Specialization(guards = "isNoValue(other)")
static PSet doSet(@SuppressWarnings("unused") VirtualFrame frame, PSet self, @SuppressWarnings("unused") PNone other,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createSet(self.getDictStorage());
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language, self.getDictStorage());
}
@Specialization(guards = {"args.length == len", "args.length < 32"}, limit = "3")
@@ -595,12 +592,12 @@ static PBaseSet doCached(VirtualFrame frame, PSet self, Object[] args,
@Shared @Cached HashingCollectionNodes.GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < len; i++) {
result = diffNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
@Specialization(replaces = "doCached")
@@ -609,12 +606,12 @@ static PBaseSet doGeneric(VirtualFrame frame, PSet self, Object[] args,
@Shared @Cached GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageCopy copyNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = copyNode.execute(inliningTarget, self.getDictStorage());
for (int i = 0; i < args.length; i++) {
result = diffNode.execute(frame, inliningTarget, result, getSetStorageNode.execute(frame, inliningTarget, args[i]));
}
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
static boolean isOther(Object arg) {
@@ -626,9 +623,9 @@ static PSet doSet(VirtualFrame frame, PSet self, Object other,
@Bind("this") Node inliningTarget,
@Shared @Cached GetSetStorageNode getSetStorageNode,
@Shared @Cached HashingStorageDiff diffNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
HashingStorage result = diffNode.execute(frame, inliningTarget, self.getDictStorage(), getSetStorageNode.execute(frame, inliningTarget, other));
- return factory.createSet(result);
+ return PFactory.createSet(language, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
index aa6dbc34b0..09fa381d61 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,9 +41,8 @@
package com.oracle.graal.python.builtins.objects.set;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageDelItem;
@@ -55,7 +54,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -66,53 +65,29 @@
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-import com.oracle.truffle.api.strings.TruffleString;
-import com.oracle.truffle.api.strings.TruffleStringIterator;
public abstract class SetNodes {
@GenerateUncached
@SuppressWarnings("truffle-inlining") // footprint reduction 116 -> 98
public abstract static class ConstructSetNode extends PNodeWithContext {
- public abstract PSet execute(Frame frame, Object cls, Object value);
+ public abstract PSet execute(Frame frame, Object value);
- public final PSet executeWith(Frame frame, Object value) {
- return this.execute(frame, PythonBuiltinClassType.PSet, value);
- }
-
- @Specialization
- static PSet setString(VirtualFrame frame, Object cls, TruffleString arg,
- @Bind("this") Node inliningTarget,
- @Exclusive @Cached PythonObjectFactory factory,
- @Exclusive @Cached HashingCollectionNodes.SetItemNode setItemNode,
- @Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
- @Cached TruffleStringIterator.NextNode nextNode,
- @Cached TruffleString.FromCodePointNode fromCodePointNode) {
- PSet set = factory.createSet(cls);
- TruffleStringIterator it = createCodePointIteratorNode.execute(arg, TS_ENCODING);
- while (it.hasNext()) {
- int cp = nextNode.execute(it);
- TruffleString s = fromCodePointNode.execute(cp, TS_ENCODING, true);
- setItemNode.execute(frame, inliningTarget, set, s, PNone.NONE);
- }
- return set;
- }
-
- @Specialization(guards = "emptyArguments(none)")
- static PSet set(Object cls, @SuppressWarnings("unused") PNone none,
- @Exclusive @Cached PythonObjectFactory factory) {
- return factory.createSet(cls);
+ @Specialization(guards = "isNoValue(none)")
+ static PSet set(@SuppressWarnings("unused") PNone none,
+ @Bind PythonLanguage language) {
+ return PFactory.createSet(language);
}
@Specialization(guards = "!isNoValue(iterable)")
- static PSet setIterable(VirtualFrame frame, Object cls, Object iterable,
+ static PSet setIterable(VirtualFrame frame, Object iterable,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached HashingCollectionNodes.SetItemNode setItemNode,
@Cached PyObjectGetIter getIter,
@Cached GetNextNode nextNode,
@Cached IsBuiltinObjectProfile errorProfile) {
- PSet set = factory.createSet(cls);
+ PSet set = PFactory.createSet(language);
Object iterator = getIter.execute(frame, inliningTarget, iterable);
while (true) {
try {
@@ -125,7 +100,7 @@ static PSet setIterable(VirtualFrame frame, Object cls, Object iterable,
}
@Fallback
- static PSet setObject(@SuppressWarnings("unused") Object cls, Object value,
+ static PSet setObject(Object value,
@Cached PRaiseNode raiseNode) {
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_NOT_ITERABLE, value);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
index 5379a81015..ba8805dfb4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,7 +48,7 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
@@ -128,7 +128,7 @@ private static int pySign(BigInteger n) {
* _PySlice_GetLongIndices
*/
@TruffleBoundary
- public static SliceObjectInfo computeIndicesSlowPath(PObjectSlice slice, Object lengthIn, PythonObjectFactory factory) {
+ public static SliceObjectInfo computeIndicesSlowPath(PObjectSlice slice, Object lengthIn, boolean usePInt) {
boolean stepIsNegative;
BigInteger lower, upper;
BigInteger start, stop, step, length;
@@ -194,8 +194,9 @@ public static SliceObjectInfo computeIndicesSlowPath(PObjectSlice slice, Object
}
}
- if (factory != null) {
- return new SliceObjectInfo(factory.createInt(start), factory.createInt(stop), factory.createInt(step));
+ if (usePInt) {
+ PythonLanguage language = PythonLanguage.get(null);
+ return new SliceObjectInfo(PFactory.createInt(language, start), PFactory.createInt(language, stop), PFactory.createInt(language, step));
} else {
return new SliceObjectInfo(start, stop, step);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
index 59bdeab756..3a951b574e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -34,6 +34,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -54,7 +55,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -168,9 +169,9 @@ protected static Object get(PObjectSlice self) {
@GenerateNodeFactory
abstract static class IndicesNode extends PythonBinaryBuiltinNode {
- private static PTuple doPSlice(VirtualFrame frame, PSlice self, int length, ComputeIndices compute, PythonObjectFactory factory) {
+ private static PTuple doPSlice(VirtualFrame frame, PSlice self, int length, ComputeIndices compute, PythonLanguage language) {
SliceInfo sliceInfo = compute.execute(frame, self, length);
- return factory.createTuple(new Object[]{sliceInfo.start, sliceInfo.stop, sliceInfo.step});
+ return PFactory.createTuple(language, new Object[]{sliceInfo.start, sliceInfo.stop, sliceInfo.step});
}
protected static boolean isSafeIntSlice(PSlice self, Object length) {
@@ -179,31 +180,31 @@ protected static boolean isSafeIntSlice(PSlice self, Object length) {
@Specialization
static PTuple safeInt(VirtualFrame frame, PIntSlice self, int length,
- @Shared @Cached ComputeIndices compute,
- @Shared @Cached PythonObjectFactory factory) {
- return doPSlice(frame, self, length, compute, factory);
+ @Bind PythonLanguage language,
+ @Shared @Cached ComputeIndices compute) {
+ return doPSlice(frame, self, length, compute, language);
}
@Specialization(guards = "!isPNone(length)", rewriteOn = PException.class)
static PTuple doSliceObject(VirtualFrame frame, PSlice self, Object length,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached SliceExactCastToInt toInt,
- @Shared @Cached ComputeIndices compute,
- @Shared @Cached PythonObjectFactory factory) {
- return doPSlice(frame, self, (int) toInt.execute(frame, inliningTarget, length), compute, factory);
+ @Shared @Cached ComputeIndices compute) {
+ return doPSlice(frame, self, (int) toInt.execute(frame, inliningTarget, length), compute, language);
}
@Specialization(guards = "!isPNone(length)", replaces = {"doSliceObject"})
static PTuple doSliceObjectWithSlowPath(VirtualFrame frame, PSlice self, Object length,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Exclusive @Cached SliceExactCastToInt toInt,
@Shared @Cached ComputeIndices compute,
@Cached IsBuiltinObjectProfile profileError,
@Cached SliceCastToToBigInt castLengthNode,
- @Cached CoerceToObjectSlice castNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Cached CoerceToObjectSlice castNode) {
try {
- return doPSlice(frame, self, (int) toInt.execute(frame, inliningTarget, length), compute, factory);
+ return doPSlice(frame, self, (int) toInt.execute(frame, inliningTarget, length), compute, language);
} catch (PException pe) {
if (!profileError.profileException(inliningTarget, pe, PythonBuiltinClassType.OverflowError)) {
throw pe;
@@ -212,8 +213,8 @@ static PTuple doSliceObjectWithSlowPath(VirtualFrame frame, PSlice self, Object
}
Object lengthIn = castLengthNode.execute(inliningTarget, length);
- PObjectSlice.SliceObjectInfo sliceInfo = PObjectSlice.computeIndicesSlowPath(castNode.execute(self), lengthIn, factory);
- return factory.createTuple(new Object[]{sliceInfo.start, sliceInfo.stop, sliceInfo.step});
+ PObjectSlice.SliceObjectInfo sliceInfo = PObjectSlice.computeIndicesSlowPath(castNode.execute(self), lengthIn, true);
+ return PFactory.createTuple(language, new Object[]{sliceInfo.start, sliceInfo.stop, sliceInfo.step});
}
@Specialization(guards = {"isPNone(length)"})
@@ -240,10 +241,10 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
@Specialization
static Object reduce(PSlice self,
@Bind("this") Node inliningTarget,
- @Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
- PTuple args = factory.createTuple(new Object[]{self.getStart(), self.getStop(), self.getStep()});
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args});
+ @Bind PythonLanguage language,
+ @Cached GetClassNode getClassNode) {
+ PTuple args = PFactory.createTuple(language, new Object[]{self.getStart(), self.getStop(), self.getStep()});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
index 7432624a01..577f2b6b31 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.ints.IntNodes.PyLongSign;
import com.oracle.graal.python.lib.PyIndexCheckNode;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaBigIntegerNode;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -84,34 +85,34 @@ public abstract static class CreateSliceNode extends PNodeWithContext {
@SuppressWarnings("unused")
static PSlice doInt(int start, int stop, PNone step,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createIntSlice(start, stop, 1, false, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, start, stop, 1, false, true);
}
@Specialization
static PSlice doInt(int start, int stop, int step,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createIntSlice(start, stop, step);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, start, stop, step);
}
@Specialization
@SuppressWarnings("unused")
static PSlice doInt(PNone start, int stop, PNone step,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createIntSlice(0, stop, 1, true, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, 0, stop, 1, true, true);
}
@Specialization
@SuppressWarnings("unused")
static PSlice doInt(PNone start, int stop, int step,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createIntSlice(0, stop, step, true, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, 0, stop, step, true, false);
}
@Fallback
static PSlice doGeneric(Object start, Object stop, Object step,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createObjectSlice(start, stop, step);
+ @Bind PythonLanguage language) {
+ return PFactory.createObjectSlice(language, start, stop, step);
}
@NeverDefault
@@ -226,8 +227,8 @@ PObjectSlice doSliceInt(PIntSlice slice,
@Shared @Cached SliceCastToToBigInt start,
@Shared @Cached SliceCastToToBigInt stop,
@Shared @Cached SliceCastToToBigInt step,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createObjectSlice(start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
+ @Bind PythonLanguage language) {
+ return PFactory.createObjectSlice(language, start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
}
protected static boolean isBigInt(PObjectSlice slice) {
@@ -245,8 +246,8 @@ PObjectSlice doSliceObject(PObjectSlice slice,
@Shared @Cached SliceCastToToBigInt start,
@Shared @Cached SliceCastToToBigInt stop,
@Shared @Cached SliceCastToToBigInt step,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createObjectSlice(start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
+ @Bind PythonLanguage language) {
+ return PFactory.createObjectSlice(language, start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
}
}
@@ -271,8 +272,8 @@ static PSlice doSliceObject(Node inliningTarget, PObjectSlice slice,
@Cached SliceLossyCastToInt start,
@Cached SliceLossyCastToInt stop,
@Cached SliceLossyCastToInt step,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createObjectSlice(start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
+ @Bind PythonLanguage language) {
+ return PFactory.createObjectSlice(language, start.execute(inliningTarget, slice.getStart()), stop.execute(inliningTarget, slice.getStop()), step.execute(inliningTarget, slice.getStep()));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
index 9e114866d9..755c2c3b07 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
@@ -60,6 +60,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -97,7 +98,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddrLibrary;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.TimeUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -141,7 +142,8 @@ private static boolean isSelectable(PSocket socket) {
public abstract static class InitNode extends PythonClinicBuiltinNode {
@Specialization
static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, int protoIn, @SuppressWarnings("unused") PNone fileno,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Exclusive @Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
@@ -160,7 +162,6 @@ static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, i
if (proto == -1) {
proto = 0;
}
- PythonContext context = PythonContext.get(inliningTarget);
try {
// TODO SOCK_CLOEXEC?
int fd;
@@ -191,7 +192,8 @@ static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, i
@Specialization(guards = "!isPNone(fileno)")
static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, int protoIn, Object fileno,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "1") UniversalSockAddrLibrary addrLib,
@Bind("this") Node inliningTarget,
@Exclusive @Cached SysModuleBuiltins.AuditNode auditNode,
@@ -200,7 +202,6 @@ static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, i
@Cached PRaiseNode.Lazy raiseNode) {
// sic! CPython really has __new__ there, even though it's in __init__
auditNode.audit(inliningTarget, "socket.__new__", self, familyIn, typeIn, protoIn);
- PythonContext context = PythonContext.get(inliningTarget);
int fd = asIntNode.execute(frame, inliningTarget, fileno);
if (fd < 0) {
@@ -281,23 +282,23 @@ abstract static class AcceptNode extends PythonUnaryBuiltinNode {
@Specialization
static Object accept(VirtualFrame frame, PSocket self,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
checkSelectable(inliningTarget, raiseNode, self);
try {
- PosixSupport posixSupport = PosixSupport.get(inliningTarget);
+ PosixSupport posixSupport = context.getPosixSupport();
PosixSupportLibrary.AcceptResult acceptResult = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, posixSupport, gil, self,
(p, s) -> p.accept(s, self.getFd()),
false, false);
try {
Object pythonAddr = makeSockAddrNode.execute(frame, inliningTarget, acceptResult.sockAddr);
posixLib.setInheritable(posixSupport, acceptResult.socketFd, false);
- return factory.createTuple(new Object[]{acceptResult.socketFd, pythonAddr});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{acceptResult.socketFd, pythonAddr});
} catch (Exception e) {
// If we failed before giving the fd to python-land, close it
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -319,9 +320,10 @@ static Object accept(VirtualFrame frame, PSocket self,
@GenerateNodeFactory
abstract static class BindNode extends PythonBinaryBuiltinNode {
@Specialization
- Object bind(VirtualFrame frame, PSocket self, Object address,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLibrary,
+ static Object bind(VirtualFrame frame, PSocket self, Object address,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLibrary,
@Cached SocketNodes.GetSockAddrArgNode getSockAddrArgNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
@@ -332,7 +334,7 @@ Object bind(VirtualFrame frame, PSocket self, Object address,
try {
gil.release(true);
try {
- posixLibrary.bind(getPosixSupport(), self.getFd(), addr);
+ posixLibrary.bind(context.getPosixSupport(), self.getFd(), addr);
} finally {
gil.acquire();
}
@@ -348,9 +350,10 @@ Object bind(VirtualFrame frame, PSocket self, Object address,
@GenerateNodeFactory
abstract static class CloseNode extends PythonUnaryBuiltinNode {
@Specialization
- Object close(VirtualFrame frame, PSocket socket,
+ static Object close(VirtualFrame frame, PSocket socket,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
int fd = socket.getFd();
@@ -359,7 +362,7 @@ Object close(VirtualFrame frame, PSocket socket,
socket.setFd(INVALID_FD);
gil.release(true);
try {
- posixLib.close(getPosixSupport(), fd);
+ posixLib.close(context.getPosixSupport(), fd);
} finally {
gil.acquire();
}
@@ -379,8 +382,9 @@ Object close(VirtualFrame frame, PSocket socket,
@GenerateNodeFactory
abstract static class ConnectNode extends PythonBinaryBuiltinNode {
@Specialization
- Object connect(VirtualFrame frame, PSocket self, Object address,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object connect(VirtualFrame frame, PSocket self, Object address,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SocketNodes.GetSockAddrArgNode getSockAddrArgNode,
@Cached GilNode gil,
@@ -391,7 +395,7 @@ Object connect(VirtualFrame frame, PSocket self, Object address,
auditNode.audit(inliningTarget, "socket.connect", self, address);
try {
- doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, self, connectAddr);
+ doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, self, connectAddr);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -439,8 +443,9 @@ static void doConnect(Frame frame, Node inliningTarget, PConstructAndRaiseNode.L
@GenerateNodeFactory
abstract static class ConnectExNode extends PythonBinaryBuiltinNode {
@Specialization
- Object connectEx(VirtualFrame frame, PSocket self, Object address,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ static Object connectEx(VirtualFrame frame, PSocket self, Object address,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached SocketNodes.GetSockAddrArgNode getSockAddrArgNode,
@Cached GilNode gil,
@@ -451,7 +456,7 @@ Object connectEx(VirtualFrame frame, PSocket self, Object address,
auditNode.audit(inliningTarget, "socket.connect", self, address); // sic! connect
try {
- ConnectNode.doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, self, connectAddr);
+ ConnectNode.doConnect(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, self, connectAddr);
} catch (PosixException e) {
return e.getErrorCode();
}
@@ -464,9 +469,10 @@ Object connectEx(VirtualFrame frame, PSocket self, Object address,
@GenerateNodeFactory
abstract static class GetPeerNameNode extends PythonUnaryBuiltinNode {
@Specialization
- Object get(VirtualFrame frame, PSocket socket,
+ static Object get(VirtualFrame frame, PSocket socket,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
@@ -474,7 +480,7 @@ Object get(VirtualFrame frame, PSocket socket,
UniversalSockAddr addr;
gil.release(true);
try {
- addr = posixLib.getpeername(getPosixSupport(), socket.getFd());
+ addr = posixLib.getpeername(context.getPosixSupport(), socket.getFd());
} finally {
gil.acquire();
}
@@ -490,9 +496,10 @@ Object get(VirtualFrame frame, PSocket socket,
@GenerateNodeFactory
abstract static class GetSockNameNode extends PythonUnaryBuiltinNode {
@Specialization
- Object get(VirtualFrame frame, PSocket socket,
+ static Object get(VirtualFrame frame, PSocket socket,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
@@ -500,7 +507,7 @@ Object get(VirtualFrame frame, PSocket socket,
UniversalSockAddr addr;
gil.release(true);
try {
- addr = posixLib.getsockname(getPosixSupport(), socket.getFd());
+ addr = posixLib.getsockname(context.getPosixSupport(), socket.getFd());
} finally {
gil.acquire();
}
@@ -516,7 +523,7 @@ Object get(VirtualFrame frame, PSocket socket,
@GenerateNodeFactory
public abstract static class GetBlockingNode extends PythonUnaryBuiltinNode {
@Specialization
- public static boolean get(PSocket socket) {
+ static boolean get(PSocket socket) {
return socket.getTimeoutNs() != 0;
}
}
@@ -541,9 +548,10 @@ static Object get(PSocket socket) {
@GenerateNodeFactory
abstract static class ListenNode extends PythonBinaryClinicBuiltinNode {
@Specialization
- Object listen(VirtualFrame frame, PSocket self, int backlogIn,
+ static Object listen(VirtualFrame frame, PSocket self, int backlogIn,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
int backlog = backlogIn;
@@ -553,7 +561,7 @@ Object listen(VirtualFrame frame, PSocket self, int backlogIn,
try {
gil.release(true);
try {
- posixLib.listen(getPosixSupport(), self.getFd(), backlog);
+ posixLib.listen(context.getPosixSupport(), self.getFd(), backlog);
} finally {
gil.acquire();
}
@@ -576,19 +584,20 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class RecvNode extends PythonTernaryClinicBuiltinNode {
@Specialization
- Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
+ static Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (recvlen < 0) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECV);
}
checkSelectable(inliningTarget, raiseNode, socket);
+ PythonLanguage language = context.getLanguage(inliningTarget);
if (recvlen == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
byte[] bytes;
@@ -599,14 +608,14 @@ Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
}
try {
- int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
+ int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.recv(s, socket.getFd(), bytes, 0, bytes.length, flags),
false, false);
if (outlen == 0) {
- return factory.createEmptyBytes();
+ return PFactory.createEmptyBytes(language);
}
// TODO maybe resize if much smaller?
- return factory.createBytes(bytes, outlen);
+ return PFactory.createBytes(language, bytes, outlen);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -625,13 +634,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class RecvFromNode extends PythonTernaryClinicBuiltinNode {
@Specialization
- Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flags,
+ static Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flags,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (recvlen < 0) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECVFROM);
@@ -646,17 +655,18 @@ Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flags,
}
try {
- RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, getPosixSupport(), gil, socket,
+ RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.recvfrom(s, socket.getFd(), bytes, 0, bytes.length, flags),
false, false);
PBytes resultBytes;
+ PythonLanguage language = context.getLanguage(inliningTarget);
if (result.readBytes == 0) {
- resultBytes = factory.createEmptyBytes();
+ resultBytes = PFactory.createEmptyBytes(language);
} else {
// TODO maybe resize if much smaller?
- resultBytes = factory.createBytes(bytes, result.readBytes);
+ resultBytes = PFactory.createBytes(language, bytes, result.readBytes);
}
- return factory.createTuple(new Object[]{resultBytes, makeSockAddrNode.execute(frame, inliningTarget, result.sockAddr)});
+ return PFactory.createTuple(language, new Object[]{resultBytes, makeSockAddrNode.execute(frame, inliningTarget, result.sockAddr)});
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -677,10 +687,11 @@ abstract static class RecvIntoNode extends PythonQuaternaryClinicBuiltinNode {
@Specialization(limit = "3")
static Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int recvlenIn, int flags,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("bufferObj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
@@ -714,7 +725,7 @@ static Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int
final int len = recvlen;
try {
- int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, PosixSupport.get(inliningTarget), gil, socket,
+ int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.recv(s, socket.getFd(), bytes, 0, len, flags),
false, false);
if (!directWrite) {
@@ -744,14 +755,14 @@ abstract static class RecvFromIntoNode extends PythonQuaternaryClinicBuiltinNode
@Specialization(limit = "3")
static Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj, int recvlenIn, int flags,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("bufferObj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
Object buffer = bufferAcquireLib.acquireWritable(bufferObj, frame, indirectCallData);
try {
@@ -782,13 +793,13 @@ static Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj,
}
try {
- RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, PosixSupport.get(inliningTarget), gil, socket,
+ RecvfromResult result = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.recvfrom(s, socket.getFd(), bytes, 0, bytes.length, flags),
false, false);
if (!directWrite) {
bufferLib.writeFromByteArray(buffer, 0, bytes, 0, result.readBytes);
}
- return factory.createTuple(new Object[]{result.readBytes, makeSockAddrNode.execute(frame, inliningTarget, result.sockAddr)});
+ return PFactory.createTuple(context.getLanguage(inliningTarget), new Object[]{result.readBytes, makeSockAddrNode.execute(frame, inliningTarget, result.sockAddr)});
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -811,10 +822,11 @@ abstract static class SendNode extends PythonTernaryClinicBuiltinNode {
@Specialization(limit = "3")
static int send(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("bufferObj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
@@ -826,7 +838,7 @@ static int send(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
try {
- return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, PosixSupport.get(inliningTarget), gil, socket,
+ return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.send(s, socket.getFd(), bytes, 0, len, flags),
true, false);
} catch (PosixException e) {
@@ -851,10 +863,11 @@ abstract static class SendAllNode extends PythonTernaryClinicBuiltinNode {
@Specialization(limit = "3")
static Object sendAll(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("bufferObj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode.Lazy raiseNode) {
@@ -876,7 +889,7 @@ static Object sendAll(VirtualFrame frame, PSocket socket, Object bufferObj, int
try {
final int offset1 = offset;
final int len1 = len;
- int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, PosixSupport.get(inliningTarget), gil, socket,
+ int outlen = SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.send(s, socket.getFd(), bytes, offset1, len1, flags),
true, false, timeoutHelper);
offset += outlen;
@@ -909,10 +922,11 @@ abstract static class SendToNode extends PythonBuiltinNode {
@Specialization(limit = "3")
static Object sendTo(VirtualFrame frame, PSocket socket, Object bufferObj, Object flagsOrAddress, Object maybeAddress,
@Bind("this") Node inliningTarget,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("bufferObj") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile hasFlagsProfile,
@Cached PyLongAsIntNode asIntNode,
@Cached SocketNodes.GetSockAddrArgNode getSockAddrArgNode,
@@ -941,7 +955,7 @@ static Object sendTo(VirtualFrame frame, PSocket socket, Object bufferObj, Objec
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
try {
- return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, PosixSupport.get(inliningTarget), gil, socket,
+ return SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixLib, context.getPosixSupport(), gil, socket,
(p, s) -> p.sendto(s, socket.getFd(), bytes, 0, len, flags, addr),
true, false);
} catch (PosixException e) {
@@ -958,12 +972,13 @@ static Object sendTo(VirtualFrame frame, PSocket socket, Object bufferObj, Objec
@GenerateNodeFactory
public abstract static class SetBlockingNode extends PythonBinaryClinicBuiltinNode {
@Specialization
- PNone doBoolean(VirtualFrame frame, PSocket socket, boolean blocking,
+ static PNone doBoolean(VirtualFrame frame, PSocket socket, boolean blocking,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.setBlocking(getPosixSupport(), socket.getFd(), blocking);
+ posixLib.setBlocking(context.getPosixSupport(), socket.getFd(), blocking);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -982,15 +997,16 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class SetTimeoutNode extends PythonBinaryBuiltinNode {
@Specialization
- Object setTimeout(VirtualFrame frame, PSocket socket, Object seconds,
+ static Object setTimeout(VirtualFrame frame, PSocket socket, Object seconds,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached SocketNodes.ParseTimeoutNode parseTimeoutNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
long timeout = parseTimeoutNode.execute(frame, inliningTarget, seconds);
socket.setTimeoutNs(timeout);
try {
- posixLib.setBlocking(getPosixSupport(), socket.getFd(), timeout < 0);
+ posixLib.setBlocking(context.getPosixSupport(), socket.getFd(), timeout < 0);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1004,12 +1020,13 @@ Object setTimeout(VirtualFrame frame, PSocket socket, Object seconds,
@GenerateNodeFactory
abstract static class ShutdownNode extends PythonBinaryClinicBuiltinNode {
@Specialization
- Object shutdown(VirtualFrame frame, PSocket socket, int how,
+ static Object shutdown(VirtualFrame frame, PSocket socket, int how,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
- posixLib.shutdown(getPosixSupport(), socket.getFd(), how);
+ posixLib.shutdown(context.getPosixSupport(), socket.getFd(), how);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1081,8 +1098,9 @@ int detach(PSocket socket) {
abstract static class SetSockOptNode extends PythonClinicBuiltinNode {
@Specialization(guards = "isNoValue(none)")
static Object setInt(VirtualFrame frame, PSocket socket, int level, int option, Object value, @SuppressWarnings("unused") PNone none,
+ @Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Bind("this") Node inliningTarget,
@@ -1106,7 +1124,7 @@ static Object setInt(VirtualFrame frame, PSocket socket, int level, int option,
}
try {
- posixLib.setsockopt(PosixSupport.get(inliningTarget), socket.getFd(), level, option, bytes, len);
+ posixLib.setsockopt(context.getPosixSupport(), socket.getFd(), level, option, bytes, len);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1115,7 +1133,8 @@ static Object setInt(VirtualFrame frame, PSocket socket, int level, int option,
@Specialization(guards = "isNone(none)")
static Object setNull(VirtualFrame frame, PSocket socket, int level, int option, @SuppressWarnings("unused") PNone none, Object buflenObj,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Exclusive @Cached PyLongAsIntNode asIntNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@@ -1126,7 +1145,7 @@ static Object setNull(VirtualFrame frame, PSocket socket, int level, int option,
throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.SETSECKOPT_BUFF_OUT_OFRANGE);
}
try {
- posixLib.setsockopt(PosixSupport.get(inliningTarget), socket.getFd(), level, option, null, buflen);
+ posixLib.setsockopt(context.getPosixSupport(), socket.getFd(), level, option, null, buflen);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
@@ -1153,21 +1172,21 @@ protected ArgumentClinicProvider getArgumentClinic() {
@GenerateNodeFactory
abstract static class GetSockOptNode extends PythonQuaternaryClinicBuiltinNode {
@Specialization
- Object getSockOpt(VirtualFrame frame, PSocket socket, int level, int option, int buflen,
+ static Object getSockOpt(VirtualFrame frame, PSocket socket, int level, int option, int buflen,
@Bind("this") Node inliningTarget,
- @CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
+ @Bind PythonContext context,
+ @CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
if (buflen == 0) {
byte[] result = new byte[4];
- posixLib.getsockopt(getPosixSupport(), socket.getFd(), level, option, result, result.length);
+ posixLib.getsockopt(context.getPosixSupport(), socket.getFd(), level, option, result, result.length);
return PythonUtils.ARRAY_ACCESSOR.getInt(result, 0);
} else if (buflen > 0 && buflen < 1024) {
byte[] result = new byte[buflen];
- int len = posixLib.getsockopt(getPosixSupport(), socket.getFd(), level, option, result, result.length);
- return factory.createBytes(result, len);
+ int len = posixLib.getsockopt(context.getPosixSupport(), socket.getFd(), level, option, result, result.length);
+ return PFactory.createBytes(context.getLanguage(inliningTarget), result, len);
} else {
throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.GETSECKOPT_BUFF_OUT_OFRANGE);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
index db3af25fef..e6aad3fbcc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -62,6 +62,7 @@
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
@@ -97,7 +98,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.UnsupportedPosixFeatureException;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.TimeUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -394,7 +395,6 @@ public abstract static class MakeSockAddrNode extends Node {
static Object makeSockAddr(VirtualFrame frame, Node inliningTarget, UniversalSockAddr addr,
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
@CachedLibrary("addr") UniversalSockAddrLibrary addrLib,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached(inline = false) TruffleString.FromByteArrayNode fromByteArrayNode,
@@ -402,23 +402,24 @@ static Object makeSockAddr(VirtualFrame frame, Node inliningTarget, UniversalSoc
@Cached PRaiseNode.Lazy raiseNode) {
try {
PythonContext context = PythonContext.get(inliningTarget);
+ PythonLanguage language = context.getLanguage(inliningTarget);
int family = addrLib.getFamily(addr);
if (family == AF_INET.value) {
Inet4SockAddr inet4SockAddr = addrLib.asInet4SockAddr(addr);
Object posixSupport = context.getPosixSupport();
TruffleString addressString = posixLib.getPathAsString(posixSupport, posixLib.inet_ntop(posixSupport, family, inet4SockAddr.getAddressAsBytes()));
- return factory.createTuple(new Object[]{addressString, inet4SockAddr.getPort()});
+ return PFactory.createTuple(language, new Object[]{addressString, inet4SockAddr.getPort()});
} else if (family == AF_INET6.value) {
Inet6SockAddr inet6SockAddr = addrLib.asInet6SockAddr(addr);
Object posixSupport = context.getPosixSupport();
TruffleString addressString = posixLib.getPathAsString(posixSupport, posixLib.inet_ntop(posixSupport, family, inet6SockAddr.getAddress()));
- return factory.createTuple(new Object[]{addressString, inet6SockAddr.getPort(), inet6SockAddr.getFlowInfo(), inet6SockAddr.getScopeId()});
+ return PFactory.createTuple(language, new Object[]{addressString, inet6SockAddr.getPort(), inet6SockAddr.getFlowInfo(), inet6SockAddr.getScopeId()});
} else if (family == AF_UNIX.value) {
UnixSockAddr unixSockAddr = addrLib.asUnixSockAddr(addr);
byte[] path = unixSockAddr.getPath();
if (PosixConstants.IS_LINUX && path.length > 0 && path[0] == 0) {
// linux-specific "abstract" address
- return factory.createBytes(arrayCopyOf(path, path.length));
+ return PFactory.createBytes(language, arrayCopyOf(path, path.length));
}
return bytesToString(path, fromByteArrayNode, switchEncodingNode);
} else if (family == AF_UNSPEC.value) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java
index 76902ffaf2..f0a7459c18 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -101,6 +101,7 @@
import org.bouncycastle.pkcs.PKCSException;
import org.bouncycastle.util.encoders.DecoderException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageSetItem;
import com.oracle.graal.python.builtins.objects.dict.PDict;
@@ -108,8 +109,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -186,19 +186,19 @@ static boolean isCrl(boolean[] keyUsage) {
* _ssl.c#_decode_certificate
*/
@TruffleBoundary
- public static PDict decodeCertificate(PythonObjectSlowPathFactory factory, X509Certificate cert) throws CertificateParsingException {
- PDict dict = factory.createDict();
+ public static PDict decodeCertificate(X509Certificate cert, PythonLanguage language) throws CertificateParsingException {
+ PDict dict = PFactory.createDict(language);
HashingStorage storage = dict.getDictStorage();
try {
- storage = setItem(storage, T_JAVA_X509_OCSP, parseOCSP(cert, factory));
- storage = setItem(storage, T_JAVA_X509_CA_ISSUERS, parseCAIssuers(cert, factory));
- storage = setItem(storage, T_JAVA_X509_ISSUER, createTupleForX509Name(cert.getIssuerX500Principal().getName("RFC1779"), factory));
+ storage = setItem(storage, T_JAVA_X509_OCSP, parseOCSP(cert, language));
+ storage = setItem(storage, T_JAVA_X509_CA_ISSUERS, parseCAIssuers(cert, language));
+ storage = setItem(storage, T_JAVA_X509_ISSUER, createTupleForX509Name(cert.getIssuerX500Principal().getName("RFC1779"), language));
storage = setItem(storage, T_JAVA_X509_NOT_AFTER, getNotAfter(cert));
storage = setItem(storage, T_JAVA_X509_NOT_BEFORE, getNotBefore(cert));
storage = setItem(storage, T_JAVA_X509_SERIAL_NUMBER, getSerialNumber(cert));
- storage = setItem(storage, T_JAVA_X509_CRL_DISTRIBUTION_POINTS, parseCRLPoints(cert, factory));
- storage = setItem(storage, T_JAVA_X509_SUBJECT, createTupleForX509Name(cert.getSubjectX500Principal().getName("RFC1779"), factory));
- storage = setItem(storage, T_JAVA_X509_SUBJECT_ALT_NAME, parseSubjectAltName(cert, factory));
+ storage = setItem(storage, T_JAVA_X509_CRL_DISTRIBUTION_POINTS, parseCRLPoints(cert, language));
+ storage = setItem(storage, T_JAVA_X509_SUBJECT, createTupleForX509Name(cert.getSubjectX500Principal().getName("RFC1779"), language));
+ storage = setItem(storage, T_JAVA_X509_SUBJECT_ALT_NAME, parseSubjectAltName(cert, language));
storage = setItem(storage, T_JAVA_X509_VERSION, getVersion(cert));
} catch (RuntimeException re) {
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSLErrorCode.ERROR_SSL, re);
@@ -246,23 +246,23 @@ private static TruffleString formatDate(Date d) {
}
@TruffleBoundary
- private static PTuple createTupleForX509Name(String name, PythonObjectFactory factory) {
+ private static PTuple createTupleForX509Name(String name, PythonLanguage language) {
List result = new ArrayList<>();
for (String component : name.split(",")) {
String[] kv = component.split("=");
if (kv.length == 2) {
- PTuple innerTuple = factory.createTuple(new Object[]{ASN1Helper.translateKeyToPython(kv[0].trim()), toTruffleStringUncached(kv[1].trim())});
- result.add(factory.createTuple(new Object[]{innerTuple}));
+ PTuple innerTuple = PFactory.createTuple(language, new Object[]{ASN1Helper.translateKeyToPython(kv[0].trim()), toTruffleStringUncached(kv[1].trim())});
+ result.add(PFactory.createTuple(language, new Object[]{innerTuple}));
}
}
// The String form is in the LDAP format, where the elements are in reverse order from what
// was in the certificate
Collections.reverse(result);
- return factory.createTuple(result.toArray(new Object[0]));
+ return PFactory.createTuple(language, result.toArray(new Object[0]));
}
@TruffleBoundary
- private static PTuple parseSubjectAltName(X509Certificate certificate, PythonObjectFactory factory) throws CertificateParsingException {
+ private static PTuple parseSubjectAltName(X509Certificate certificate, PythonLanguage language) throws CertificateParsingException {
List tuples = new ArrayList<>(16);
Collection> altNames = certificate.getSubjectAlternativeNames();
if (altNames != null) {
@@ -279,38 +279,39 @@ private static PTuple parseSubjectAltName(X509Certificate certificate, PythonObj
switch (type) {
// see openssl v3_alt.c#i2v_GENERAL_NAME()
case 0:
- tuples.add(factory.createTuple(new Object[]{T_OTHERNAME, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_OTHERNAME, stringValue}));
break;
case 1:
- tuples.add(factory.createTuple(new Object[]{T_EMAIL, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_EMAIL, stringValue}));
break;
case 2:
- tuples.add(factory.createTuple(new Object[]{T_DNS, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_DNS, stringValue}));
break;
case 3:
- tuples.add(factory.createTuple(new Object[]{T_X_400_NAME, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_X_400_NAME, stringValue}));
break;
case 4:
- tuples.add(factory.createTuple(new Object[]{T_DIR_NAME, value instanceof String ? createTupleForX509Name((String) value, factory) : factory.createEmptyTuple()}));
+ tuples.add(PFactory.createTuple(language,
+ new Object[]{T_DIR_NAME, value instanceof String ? createTupleForX509Name((String) value, language) : PFactory.createEmptyTuple(language)}));
break;
case 5:
- tuples.add(factory.createTuple(new Object[]{T_EDI_PARTY_NAME, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_EDI_PARTY_NAME, stringValue}));
break;
case 6:
- tuples.add(factory.createTuple(new Object[]{T_URI, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_URI, stringValue}));
break;
case 7:
- tuples.add(factory.createTuple(new Object[]{T_IP_ADDRESS, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_IP_ADDRESS, stringValue}));
break;
case 8:
- tuples.add(factory.createTuple(new Object[]{T_REGISTERED_ID, stringValue}));
+ tuples.add(PFactory.createTuple(language, new Object[]{T_REGISTERED_ID, stringValue}));
break;
default:
continue;
}
}
}
- return factory.createTuple(tuples.toArray(new Object[tuples.size()]));
+ return PFactory.createTuple(language, tuples.toArray(new Object[tuples.size()]));
}
return null;
}
@@ -464,7 +465,7 @@ void iterateSequence(DerSequenceConsumer consumer, T value) thr
}
@TruffleBoundary
- private static PTuple parseCRLPoints(X509Certificate cert, PythonObjectFactory factory) throws CertificateParsingException {
+ private static PTuple parseCRLPoints(X509Certificate cert, PythonLanguage language) throws CertificateParsingException {
List result = new ArrayList<>();
byte[] bytes = cert.getExtensionValue(OID_CRL_DISTRIBUTION_POINTS);
if (bytes == null) {
@@ -502,14 +503,14 @@ private static PTuple parseCRLPoints(X509Certificate cert, PythonObjectFactory f
}
}, result);
if (result.size() > 0) {
- return factory.createTuple(result.toArray(new Object[result.size()]));
+ return PFactory.createTuple(language, result.toArray(new Object[result.size()]));
} else {
return null;
}
}
@TruffleBoundary
- private static PTuple parseCAIssuers(X509Certificate cert, PythonObjectFactory factory) throws CertificateParsingException {
+ private static PTuple parseCAIssuers(X509Certificate cert, PythonLanguage language) throws CertificateParsingException {
List result = new ArrayList<>();
byte[] bytes = cert.getExtensionValue(OID_AUTHORITY_INFO_ACCESS);
if (bytes == null) {
@@ -538,14 +539,14 @@ private static PTuple parseCAIssuers(X509Certificate cert, PythonObjectFactory f
}
}, result);
if (result.size() > 0) {
- return factory.createTuple(result.toArray(new Object[result.size()]));
+ return PFactory.createTuple(language, result.toArray(new Object[result.size()]));
} else {
return null;
}
}
@TruffleBoundary
- private static PTuple parseOCSP(X509Certificate cert, PythonObjectFactory factory) throws CertificateParsingException {
+ private static PTuple parseOCSP(X509Certificate cert, PythonLanguage language) throws CertificateParsingException {
List result = new ArrayList<>();
byte[] bytes = cert.getExtensionValue(OID_AUTHORITY_INFO_ACCESS);
if (bytes == null) {
@@ -574,7 +575,7 @@ private static PTuple parseOCSP(X509Certificate cert, PythonObjectFactory factor
}
}, result);
if (result.size() > 0) {
- return factory.createTuple(result.toArray(new Object[result.size()]));
+ return PFactory.createTuple(language, result.toArray(new Object[result.size()]));
} else {
return null;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
index b4c0a6403a..969e572c33 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -53,6 +54,7 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -60,7 +62,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -83,8 +85,9 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class MemoryBIONode extends PythonUnaryBuiltinNode {
@Specialization
static PMemoryBIO create(Object type,
- @Cached PythonObjectFactory factory) {
- return factory.createMemoryBIO(type);
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ return PFactory.createMemoryBIO(language, type, getInstanceShape.execute(type));
}
}
@@ -112,9 +115,9 @@ static boolean eof(PMemoryBIO self) {
abstract static class ReadNode extends PythonBinaryClinicBuiltinNode {
@Specialization
static PBytes read(PMemoryBIO self, int size,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
int len = size >= 0 ? size : Integer.MAX_VALUE;
- return factory.createBytes(self.read(len));
+ return PFactory.createBytes(language, self.read(len));
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
index 7902bad812..786ec73cf6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
@@ -78,6 +78,7 @@
import org.bouncycastle.util.encoders.DecoderException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -101,6 +102,7 @@
import com.oracle.graal.python.builtins.objects.ssl.CertUtils.NeedsPasswordException;
import com.oracle.graal.python.builtins.objects.ssl.CertUtils.NoCertificateFoundException;
import com.oracle.graal.python.builtins.objects.str.StringNodes;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyCallableCheckNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
@@ -127,7 +129,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.IPAddressUtil;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -165,8 +167,9 @@ abstract static class SSLContextNode extends PythonBinaryClinicBuiltinNode {
@Specialization
static PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
SSLMethod method = SSLMethod.fromPythonId(protocol);
if (method == null) {
@@ -182,7 +185,8 @@ static PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
checkHostname = false;
verifyMode = SSLModuleBuiltins.SSL_CERT_NONE;
}
- PSSLContext context = factory.createSSLContext(type, method, SSLModuleBuiltins.X509_V_FLAG_TRUSTED_FIRST, checkHostname, verifyMode, createSSLContext());
+ PSSLContext context = PFactory.createSSLContext(language, type, getInstanceShape.execute(type), method, SSLModuleBuiltins.X509_V_FLAG_TRUSTED_FIRST, checkHostname, verifyMode,
+ createSSLContext());
long options = SSLOptions.SSL_OP_ALL;
if (method != SSLMethod.SSL3) {
options |= SSLOptions.SSL_OP_NO_SSLv3;
@@ -284,15 +288,15 @@ abstract static class WrapSocketNode extends PythonClinicBuiltinNode {
@Specialization
static Object wrap(PSSLContext context, PSocket sock, boolean serverSide, Object serverHostnameObj, Object owner, @SuppressWarnings("unused") PNone session,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached StringNodes.CastToTruffleStringCheckedNode cast,
- @Cached TruffleString.ToJavaStringNode toJavaStringNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.ToJavaStringNode toJavaStringNode) {
TruffleString serverHostname = null;
if (!(serverHostnameObj instanceof PNone)) {
serverHostname = cast.cast(inliningTarget, serverHostnameObj, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "serverHostname", serverHostnameObj);
}
SSLEngine engine = createSSLEngine(inliningTarget, context, serverSide, serverHostname == null ? null : toJavaStringNode.execute(serverHostname));
- PSSLSocket sslSocket = factory.createSSLSocket(PythonBuiltinClassType.PSSLSocket, context, engine, sock);
+ PSSLSocket sslSocket = PFactory.createSSLSocket(language, context, engine, sock);
if (!(owner instanceof PNone)) {
sslSocket.setOwner(owner);
}
@@ -321,15 +325,15 @@ abstract static class WrapBIONode extends PythonClinicBuiltinNode {
static Object wrap(PSSLContext context, PMemoryBIO incoming, PMemoryBIO outgoing, boolean serverSide, Object serverHostnameObj, Object owner,
@SuppressWarnings("unused") PNone session,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached StringNodes.CastToTruffleStringCheckedNode cast,
- @Cached TruffleString.ToJavaStringNode toJavaStringNode,
- @Cached PythonObjectFactory factory) {
+ @Cached TruffleString.ToJavaStringNode toJavaStringNode) {
TruffleString serverHostname = null;
if (!(serverHostnameObj instanceof PNone)) {
serverHostname = cast.cast(inliningTarget, serverHostnameObj, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "serverHostname", serverHostnameObj);
}
SSLEngine engine = createSSLEngine(inliningTarget, context, serverSide, serverHostname == null ? null : toJavaStringNode.execute(serverHostname));
- PSSLSocket sslSocket = factory.createSSLSocket(PythonBuiltinClassType.PSSLSocket, context, engine, incoming, outgoing);
+ PSSLSocket sslSocket = PFactory.createSSLSocket(language, context, engine, incoming, outgoing);
if (!(owner instanceof PNone)) {
sslSocket.setOwner(owner);
}
@@ -517,13 +521,14 @@ static Object set(VirtualFrame frame, PSSLContext self, Object obj,
abstract static class GetCiphersNode extends PythonUnaryBuiltinNode {
@Specialization
@TruffleBoundary
- static PList getCiphers(PSSLContext self) {
+ static PList getCiphers(PSSLContext self,
+ @Bind PythonLanguage language) {
List ciphers = self.computeEnabledCiphers(self.getContext().createSSLEngine());
Object[] dicts = new Object[ciphers.size()];
for (int i = 0; i < dicts.length; i++) {
- dicts[i] = PythonObjectFactory.getUncached().createDict(ciphers.get(i).asKeywords());
+ dicts[i] = PFactory.createDict(language, ciphers.get(i).asKeywords());
}
- return PythonObjectFactory.getUncached().createList(dicts);
+ return PFactory.createList(language, dicts);
}
}
@@ -641,13 +646,13 @@ Object set(VirtualFrame frame, PSSLContext self,
@NeverDefault
@TruffleBoundary
protected PBytes createCertFileKey() {
- return PythonObjectFactory.getUncached().createBytes("SSL_CERT_FILE".getBytes());
+ return PFactory.createBytes(PythonLanguage.get(null), "SSL_CERT_FILE".getBytes());
}
@NeverDefault
@TruffleBoundary
protected PBytes createCertDirKey() {
- return PythonObjectFactory.getUncached().createBytes("SSL_CERT_DIR".getBytes());
+ return PFactory.createBytes(PythonLanguage.get(null), "SSL_CERT_DIR".getBytes());
}
@NeverDefault
@@ -683,8 +688,8 @@ abstract static class CertStoreStatsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object storeStats(VirtualFrame frame, PSSLContext self,
@Bind("this") Node inliningTarget,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
int x509 = 0, crl = 0, ca = 0;
for (X509Certificate cert : self.getCACerts()) {
@@ -698,7 +703,7 @@ static Object storeStats(VirtualFrame frame, PSSLContext self,
}
}
}
- return factory.createDict(new PKeyword[]{new PKeyword(T_X509, x509), new PKeyword(T_CRL, crl), new PKeyword(T_X509_CA, ca)});
+ return PFactory.createDict(language, new PKeyword[]{new PKeyword(T_X509, x509), new PKeyword(T_CRL, crl), new PKeyword(T_X509_CA, ca)});
} catch (Exception ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
}
@@ -1056,16 +1061,16 @@ abstract static class GetCACerts extends PythonBinaryClinicBuiltinNode {
@Specialization(guards = "!binary_form")
Object getCerts(VirtualFrame frame, PSSLContext self, @SuppressWarnings("unused") boolean binary_form,
@Bind("this") Node inliningTarget,
- @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
try {
List result = PythonUtils.newList();
for (X509Certificate cert : self.getCACerts()) {
if (CertUtils.isCA(cert, CertUtils.getKeyUsage(cert))) {
- PythonUtils.add(result, CertUtils.decodeCertificate(getContext().factory(), cert));
+ PythonUtils.add(result, CertUtils.decodeCertificate(cert, language));
}
}
- return factory.createList(PythonUtils.toArray(result));
+ return PFactory.createList(language, PythonUtils.toArray(result));
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateParsingException ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
}
@@ -1073,15 +1078,15 @@ Object getCerts(VirtualFrame frame, PSSLContext self, @SuppressWarnings("unused"
@Specialization(guards = "binary_form")
static Object getCertsBinary(PSSLContext self, @SuppressWarnings("unused") boolean binary_form,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
try {
List result = PythonUtils.newList();
for (X509Certificate cert : self.getCACerts()) {
if (CertUtils.isCA(cert, CertUtils.getKeyUsage(cert))) {
- PythonUtils.add(result, factory.createBytes(CertUtils.getEncoded(cert)));
+ PythonUtils.add(result, PFactory.createBytes(language, CertUtils.getEncoded(cert)));
}
}
- return factory.createList(PythonUtils.toArray(result));
+ return PFactory.createList(language, PythonUtils.toArray(result));
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateEncodingException ex) {
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSLErrorCode.ERROR_SSL, ex);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLErrorBuiltins.java
index 4347b6ea97..e07cf6ab3e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -65,7 +65,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -85,7 +84,7 @@ public final class SSLErrorBuiltins extends PythonBuiltins {
static final int IDX_VERIFY_MESSAGE = IDX_WRITTEN + 4;
static final int SSL_ERR_NUM_ATTRS = IDX_VERIFY_MESSAGE + 1;
- public static final BaseExceptionAttrNode.StorageFactory SSL_ERROR_ATTR_FACTORY = (args, factory) -> new Object[SSL_ERR_NUM_ATTRS];
+ public static final BaseExceptionAttrNode.StorageFactory SSL_ERROR_ATTR_FACTORY = (args) -> new Object[SSL_ERR_NUM_ATTRS];
public static final TruffleString T_SSL_IN_BRACKETS = tsLiteral("[SSL]");
@Override
@@ -123,10 +122,9 @@ public abstract static class SSLErrorInitNode extends PythonBuiltinNode {
@Specialization
static Object init(VirtualFrame frame, PBaseException self, Object[] args, PKeyword[] kwds,
- @Cached OsErrorBuiltins.OSErrorInitNode initNode,
- @Cached PythonObjectFactory factory) {
+ @Cached OsErrorBuiltins.OSErrorInitNode initNode) {
initNode.execute(frame, self, args, kwds);
- Object[] sslAttrs = SSL_ERROR_ATTR_FACTORY.create(args, factory);
+ Object[] sslAttrs = SSL_ERROR_ATTR_FACTORY.create(args);
PythonUtils.arraycopy(self.getExceptionAttributes(), 0, sslAttrs, 0, self.getExceptionAttributes().length);
self.setExceptionAttributes(sslAttrs);
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
index 1acb11c3bf..8854f325f5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -57,6 +57,7 @@
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -75,8 +76,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -104,18 +104,18 @@ abstract static class ReadNode extends PythonTernaryClinicBuiltinNode {
@Specialization(guards = "isNoValue(buffer)")
static Object read(VirtualFrame frame, PSSLSocket self, int len, @SuppressWarnings("unused") PNone buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Shared @Cached SSLOperationNode sslOperationNode,
- @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (len == 0) {
- return factory.createBytes(new byte[0]);
+ return PFactory.createBytes(language, new byte[0]);
} else if (len < 0) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SIZE_SHOULD_NOT_BE_NEGATIVE);
}
ByteBuffer output = PythonUtils.allocateByteBuffer(len);
sslOperationNode.read(frame, inliningTarget, self, output);
PythonUtils.flipBuffer(output);
- return factory.createBytes(PythonUtils.getBufferArray(output), PythonUtils.getBufferLimit(output));
+ return PFactory.createBytes(language, PythonUtils.getBufferArray(output), PythonUtils.getBufferLimit(output));
}
@Specialization(guards = "!isNoValue(bufferObj)", limit = "3")
@@ -316,7 +316,7 @@ abstract static class GetPeerCertNode extends PythonBinaryClinicBuiltinNode {
@Specialization(guards = "der")
static Object getPeerCertDER(PSSLSocket self, @SuppressWarnings("unused") boolean der,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory.Lazy factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (!self.isHandshakeComplete()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
@@ -324,7 +324,7 @@ static Object getPeerCertDER(PSSLSocket self, @SuppressWarnings("unused") boolea
Certificate certificate = getCertificate(self.getEngine());
if (certificate != null) {
try {
- return factory.get(inliningTarget).createBytes(getEncoded(certificate));
+ return PFactory.createBytes(language, getEncoded(certificate));
} catch (CertificateEncodingException e) {
// Fallthrough
}
@@ -337,7 +337,7 @@ static Object getPeerCertDER(PSSLSocket self, @SuppressWarnings("unused") boolea
@Specialization(guards = "!der")
static PDict getPeerCertDict(PSSLSocket self, @SuppressWarnings("unused") boolean der,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory.Lazy factory,
+ @Bind PythonLanguage language,
@Shared @Cached PRaiseNode.Lazy raiseNode) {
if (!self.isHandshakeComplete()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
@@ -345,12 +345,12 @@ static PDict getPeerCertDict(PSSLSocket self, @SuppressWarnings("unused") boolea
Certificate certificate = getCertificate(self.getEngine());
if (certificate instanceof X509Certificate) {
try {
- return CertUtils.decodeCertificate(PythonContext.get(inliningTarget).factory(), (X509Certificate) certificate);
+ return CertUtils.decodeCertificate((X509Certificate) certificate, language);
} catch (CertificateParsingException e) {
- return factory.get(inliningTarget).createDict();
+ return PFactory.createDict(language);
}
}
- return factory.get(inliningTarget).createDict();
+ return PFactory.createDict(language);
}
@TruffleBoundary
@@ -403,7 +403,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
abstract static class CipherNode extends PythonUnaryBuiltinNode {
@Specialization
static Object getCipher(PSSLSocket self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (!self.isHandshakeComplete()) {
return PNone.NONE;
}
@@ -411,7 +411,7 @@ static Object getCipher(PSSLSocket self,
if (cipher == null) {
return PNone.NONE;
}
- return factory.createTuple(new Object[]{cipher.getOpensslName(), cipher.getProtocol(), cipher.getStrengthBits()});
+ return PFactory.createTuple(language, new Object[]{cipher.getOpensslName(), cipher.getProtocol(), cipher.getStrengthBits()});
}
@TruffleBoundary
@@ -434,13 +434,14 @@ Object get(PSSLSocket socket) {
if (!socket.isHandshakeComplete()) {
return PNone.NONE;
}
+ PythonLanguage language = PythonLanguage.get(null);
List ciphers = socket.getContext().computeEnabledCiphers(socket.getEngine());
Object[] result = new Object[ciphers.size()];
for (int i = 0; i < ciphers.size(); i++) {
SSLCipher cipher = ciphers.get(i);
- result[i] = PythonObjectFactory.getUncached().createTuple(new Object[]{cipher.getOpensslName(), cipher.getProtocol(), cipher.getStrengthBits()});
+ result[i] = PFactory.createTuple(language, new Object[]{cipher.getOpensslName(), cipher.getProtocol(), cipher.getStrengthBits()});
}
- return PythonObjectFactory.getUncached().createList(result);
+ return PFactory.createList(language, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
index a94ccb4f20..effbd08d93 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
@@ -166,7 +166,7 @@
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
import com.oracle.graal.python.runtime.formatting.StringFormatProcessor;
import com.oracle.graal.python.runtime.formatting.TextFormatter;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ComparisonOp;
import com.oracle.graal.python.util.IntPredicate;
import com.oracle.truffle.api.CompilerAsserts;
@@ -356,13 +356,13 @@ public abstract static class GetNewargsNode extends PythonUnaryBuiltinNode {
@Specialization
PTuple doGeneric(Object self,
@Bind("this") Node inliningTarget,
- @Cached CastToTruffleStringCheckedNode cast,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached CastToTruffleStringCheckedNode cast) {
TruffleString selfStr = cast.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___GETNEWARGS__, self);
// CPython requires the resulting string not to be the same object as the original for
// some reason
- PString copy = factory.createString(selfStr);
- return factory.createTuple(new Object[]{copy});
+ PString copy = PFactory.createString(language, selfStr);
+ return PFactory.createTuple(language, new Object[]{copy});
}
}
@@ -956,7 +956,6 @@ static PDict doString(VirtualFrame frame, Object cls, Object from, Object to, Ob
@Cached TruffleStringIterator.NextNode nextNode,
@Cached InlinedConditionProfile hasZProfile,
@Exclusive @Cached HashingStorageSetItem setHashingStorageItem,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
TruffleString toStr = castToNode.cast(inliningTarget, to, ErrorMessages.ARG_S_MUST_BE_S_NOT_P, "2", "str", to);
@@ -988,7 +987,7 @@ static PDict doString(VirtualFrame frame, Object cls, Object from, Object to, Ob
storage = setHashingStorageItem.execute(frame, inliningTarget, storage, key, PNone.NONE);
}
}
- return factory.createDict(storage);
+ return PFactory.createDict(PythonLanguage.get(inliningTarget), storage);
}
@Specialization(guards = {"isNoValue(to)", "isNoValue(z)"})
@@ -1004,7 +1003,6 @@ static PDict doDict(VirtualFrame frame, Object cls, PDict from, Object to, Objec
@Cached HashingStorageIteratorNext iterHasNext,
@Cached HashingStorageIteratorKey iterKey,
@Cached HashingStorageIteratorValue iterValue,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
HashingStorage srcStorage = from.getDictStorage();
HashingStorage destStorage = PDict.createNewStorage(lenNode.execute(inliningTarget, srcStorage));
@@ -1023,7 +1021,7 @@ static PDict doDict(VirtualFrame frame, Object cls, PDict from, Object to, Objec
destStorage = setHashingStorageItem.execute(frame, inliningTarget, destStorage, codePoint, currentValue);
}
}
- return factory.createDict(destStorage);
+ return PFactory.createDict(PythonLanguage.get(inliningTarget), destStorage);
}
@Specialization(guards = {"!isDict(from)", "isNoValue(to)"})
@@ -1152,7 +1150,6 @@ static PTuple doGeneric(Object self, Object sep,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
@Cached TruffleString.SubstringNode substringNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
TruffleString selfStr = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "partition", self);
TruffleString sepStr = castSepNode.cast(inliningTarget, sep, ErrorMessages.MUST_BE_STR_NOT_P, sep);
@@ -1172,7 +1169,7 @@ static PTuple doGeneric(Object self, Object sep,
partitioned[1] = sepStr;
partitioned[2] = substringNode.execute(selfStr, o, selfLen - o, TS_ENCODING, false);
}
- return factory.createTuple(partitioned);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), partitioned);
}
}
@@ -1189,7 +1186,6 @@ static Object doGeneric(Object self, Object sep,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.LastIndexOfStringNode lastIndexOfStringNode,
@Cached TruffleString.SubstringNode substringNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
TruffleString selfStr = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "rpartition", self);
TruffleString sepStr = castSepNode.cast(inliningTarget, sep, ErrorMessages.MUST_BE_STR_NOT_P, sep);
@@ -1209,7 +1205,7 @@ static Object doGeneric(Object self, Object sep,
partitioned[1] = sepStr;
partitioned[2] = substringNode.execute(selfStr, o, selfLen - o, TS_ENCODING, false);
}
- return factory.createTuple(partitioned);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), partitioned);
}
}
@@ -1232,9 +1228,8 @@ static PList doStringNoSep(TruffleString self, PNone sep, int maxsplit,
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Shared("substring") @Cached TruffleString.SubstringNode substringNode,
- @Shared("appendNode") @Cached AppendNode appendNode,
- @Shared @Cached PythonObjectFactory factory) {
- return splitfields(self, maxsplit, appendNode, codePointLengthNode, codePointAtIndexNode, substringNode, factory);
+ @Shared("appendNode") @Cached AppendNode appendNode) {
+ return splitfields(self, maxsplit, appendNode, codePointLengthNode, codePointAtIndexNode, substringNode);
}
@Specialization
@@ -1244,14 +1239,13 @@ static PList doStringSep(TruffleString self, TruffleString sep, int maxsplit,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
@Shared("substring") @Cached TruffleString.SubstringNode substringNode,
@Shared("appendNode") @Cached AppendNode appendNode,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (sep.isEmpty()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
int splits = maxsplit == -1 ? Integer.MAX_VALUE : maxsplit;
- PList list = factory.createList();
+ PList list = PFactory.createList(PythonLanguage.get(inliningTarget));
int lastEnd = 0;
int selfLen = codePointLengthNode.execute(self, TS_ENCODING);
int sepLen = codePointLengthNode.execute(sep, TS_ENCODING);
@@ -1271,12 +1265,12 @@ static PList doStringSep(TruffleString self, TruffleString sep, int maxsplit,
// See {@link PyString}
private static PList splitfields(TruffleString s, int maxsplit, AppendNode appendNode, TruffleString.CodePointLengthNode codePointLengthNode,
TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- TruffleString.SubstringNode substringNode, PythonObjectFactory factory) {
+ TruffleString.SubstringNode substringNode) {
/*
* Result built here is a list of split parts, exactly as required for s.split(None,
* maxsplit). If there are to be n splits, there will be n+1 elements in L.
*/
- PList list = factory.createList();
+ PList list = PFactory.createList(PythonLanguage.get(appendNode));
int length = codePointLengthNode.execute(s, TS_ENCODING);
int start = 0;
int splits = 0;
@@ -1350,7 +1344,6 @@ static PList doStringSepMaxsplit(VirtualFrame frame, TruffleString self, Truffle
@Shared("cpLen") @Cached CodePointLengthNode codePointLengthNode,
@Cached TruffleString.LastIndexOfStringNode lastIndexOfStringNode,
@Shared @Cached TruffleString.SubstringNode substringNode,
- @Shared @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
if (sep.isEmpty()) {
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
@@ -1359,7 +1352,7 @@ static PList doStringSepMaxsplit(VirtualFrame frame, TruffleString self, Truffle
if (maxsplitInput < 0) {
maxsplit = Integer.MAX_VALUE;
}
- PList list = factory.createList();
+ PList list = PFactory.createList(PythonLanguage.get(inliningTarget));
int splits = 0;
int end = codePointLengthNode.execute(self, TS_ENCODING);
int sepLength = codePointLengthNode.execute(sep, TS_ENCODING);
@@ -1382,17 +1375,17 @@ static PList doStringSepMaxsplit(VirtualFrame frame, TruffleString self, Truffle
@Specialization
static PList doStringMaxsplit(VirtualFrame frame, TruffleString s, @SuppressWarnings("unused") PNone sep, int maxsplit,
+ @Bind("this") Node inliningTarget,
@Shared("appendNode") @Cached AppendNode appendNode,
@Shared("reverseNode") @Cached ListReverseNode reverseNode,
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Shared @Cached TruffleString.SubstringNode substringNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached TruffleString.SubstringNode substringNode) {
/*
* Result built here is a list of split parts, exactly as required for s.split(None,
* maxsplit). If there are to be n splits, there will be n+1 elements in L.
*/
- PList list = factory.createList();
+ PList list = PFactory.createList(PythonLanguage.get(inliningTarget));
int length = codePointLengthNode.execute(s, TS_ENCODING);
int maxsplit2 = maxsplit;
@@ -1441,19 +1434,17 @@ public abstract static class SplitLinesNode extends PythonBinaryBuiltinNode {
static PList doString(TruffleString self, @SuppressWarnings("unused") PNone keepends,
@Shared("ts2js") @Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Shared @Cached AppendNode appendNode,
- @Shared @Cached PythonObjectFactory factory) {
- return doStringKeepends(self, false, toJavaStringNode, fromJavaStringNode, appendNode, factory);
+ @Shared @Cached AppendNode appendNode) {
+ return doStringKeepends(self, false, toJavaStringNode, fromJavaStringNode, appendNode);
}
@Specialization
static PList doStringKeepends(TruffleString selfTs, boolean keepends,
@Shared("ts2js") @Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Shared @Cached AppendNode appendNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached AppendNode appendNode) {
// TODO GR-37218: use TRegex or codepoint iterator + hand-written state machine
- PList list = factory.createList();
+ PList list = PFactory.createList(PythonLanguage.get(appendNode));
int lastEnd = 0;
String self = toJavaStringNode.execute(selfTs);
Matcher matcher = getMatcher(self);
@@ -1512,11 +1503,10 @@ static PList doGeneric(Object self, Object keepends,
@Cached CastToJavaIntExactNode castToJavaIntNode,
@Shared("ts2js") @Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Shared @Cached AppendNode appendNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Shared @Cached AppendNode appendNode) {
TruffleString selfStr = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "splitlines", self);
boolean bKeepends = !PGuards.isPNone(keepends) && castToJavaIntNode.execute(inliningTarget, keepends) != 0;
- return doStringKeepends(selfStr, bKeepends, toJavaStringNode, fromJavaStringNode, appendNode, factory);
+ return doStringKeepends(selfStr, bKeepends, toJavaStringNode, fromJavaStringNode, appendNode);
}
}
@@ -1787,13 +1777,14 @@ static Object doIt(VirtualFrame frame, Object selfObj, TruffleString encoding, T
@Cached CastToTruffleStringCheckedNode castSelfNode,
@Cached CodecsModuleBuiltins.EncodeNode encodeNode,
@Cached SequenceStorageNodes.CopyNode copyNode,
- @Cached PythonObjectFactory.Lazy factory,
+ @Cached InlinedBranchProfile convertByteArray,
@Cached PRaiseNode.Lazy raiseNode) {
TruffleString self = castSelfNode.cast(inliningTarget, selfObj, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "index", selfObj);
Object result = encodeNode.execute(frame, self, encoding, errors);
if (!(result instanceof PBytes)) {
if (result instanceof PByteArray) {
- return factory.get(inliningTarget).createBytes(copyNode.execute(inliningTarget, ((PByteArray) result).getSequenceStorage()));
+ convertByteArray.enter(inliningTarget);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), copyNode.execute(inliningTarget, ((PByteArray) result).getSequenceStorage()));
}
throw raiseNode.get(inliningTarget).raise(TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, result);
}
@@ -2474,10 +2465,9 @@ public abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static PStringIterator doGeneric(Object self,
@Bind("this") Node inliningTarget,
- @Cached CastToTruffleStringCheckedNode castSelfNode,
- @Cached PythonObjectFactory factory) {
+ @Cached CastToTruffleStringCheckedNode castSelfNode) {
TruffleString string = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___ITER__, self);
- return factory.createStringIterator(string);
+ return PFactory.createStringIterator(PythonLanguage.get(inliningTarget), string);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
index c1bd198c44..0ec5dbffac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsbCapacity;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
@@ -77,7 +78,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
@@ -483,9 +484,9 @@ public static PString executeUncached(Object string) {
@Specialization
static PString doString(Node inliningTarget, TruffleString string,
- @Shared @Cached HiddenAttr.WriteNode writeNode,
- @Cached(inline = false) PythonObjectFactory factory) {
- final PString interned = factory.createString(string);
+ @Bind PythonLanguage language,
+ @Shared @Cached HiddenAttr.WriteNode writeNode) {
+ final PString interned = PFactory.createString(language, string);
writeNode.execute(inliningTarget, interned, HiddenAttr.INTERNED, true);
return interned;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java
index 7f6d5fd5de..6127930426 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,10 +49,10 @@
import java.util.Locale;
import org.graalvm.nativeimage.ImageInfo;
-
import org.graalvm.shadowed.com.ibm.icu.lang.UCharacter;
import org.graalvm.shadowed.com.ibm.icu.lang.UCharacterCategory;
import org.graalvm.shadowed.com.ibm.icu.lang.UProperty;
+
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
@@ -72,11 +72,6 @@
public final class StringUtils {
- /**
- * The maximum length of the source string when creating a sing-codepoint substring.
- */
- public static final int LAZY_CODEPOINT_THRESHOLD = 20;
-
public enum StripKind {
LEFT,
RIGHT,
@@ -153,24 +148,6 @@ public static boolean isUnicodeWhitespace(int ch) {
}
}
- public static boolean isUnicodeLineBreak(char ch) {
- switch (ch) {
- case 0x000A:
- case 0x000B:
- case 0x000C:
- case 0x000D:
- case 0x001C:
- case 0x001D:
- case 0x001E:
- case 0x0085:
- case 0x2028:
- case 0x2029:
- return true;
- default:
- return false;
- }
- }
-
public static boolean isSpace(int ch) {
if (ch < 128) {
return ASCII_WHITESPACE[ch] == 1;
@@ -241,19 +218,6 @@ public static TruffleString strip(TruffleString str, TruffleString chars, StripK
return substringNode.execute(str, i, j - i, TS_ENCODING, false);
}
- public static Object[] toCharacterArray(TruffleString arg, TruffleString.CodePointLengthNode codePointLengthNode, TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
- TruffleStringIterator.NextNode nextNode, TruffleString.FromCodePointNode fromCodePointNode) {
- Object[] values = new Object[codePointLengthNode.execute(arg, TS_ENCODING)];
- TruffleStringIterator it = createCodePointIteratorNode.execute(arg, TS_ENCODING);
- int i = 0;
- while (it.hasNext()) {
- // TODO: GR-37219: use SubstringNode with lazy=true?
- int codePoint = nextNode.execute(it);
- values[i++] = fromCodePointNode.execute(codePoint, TS_ENCODING, true);
- }
- return values;
- }
-
@TruffleBoundary
public static boolean isPrintable(int codepoint) {
if (ImageInfo.inImageBuildtimeCode()) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
index ef7ef6c4c9..6a423b6eeb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2020 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -13,14 +13,15 @@
import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_PACK_EXPECTED_N_ITEMS_GOT_K;
import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_PACK_INTO_REQ_BUFFER_TO_PACK;
import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_UNPACK_FROM_REQ_AT_LEAST_N_BYTES;
-import static com.oracle.graal.python.nodes.ErrorMessages.UNPACK_REQ_A_BUFFER_OF_N_BYTES;
import static com.oracle.graal.python.nodes.ErrorMessages.S_TAKES_NO_KEYWORD_ARGS;
+import static com.oracle.graal.python.nodes.ErrorMessages.UNPACK_REQ_A_BUFFER_OF_N_BYTES;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.StructError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
@@ -40,7 +41,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -101,8 +102,8 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
@Specialization
Object pack(VirtualFrame frame, PStruct self, Object[] args, PKeyword[] keywords,
- @Cached StructNodes.PackValueNode packValueNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Cached StructNodes.PackValueNode packValueNode) {
if (keywords.length != 0) {
throw raise(TypeError, S_TAKES_NO_KEYWORD_ARGS, "pack()");
}
@@ -111,7 +112,7 @@ Object pack(VirtualFrame frame, PStruct self, Object[] args, PKeyword[] keywords
}
byte[] bytes = new byte[self.getSize()];
packInternal(frame, self, packValueNode, args, bytes, 0);
- return factory.createBytes(bytes);
+ return PFactory.createBytes(language, bytes);
}
}
@@ -203,10 +204,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static Object unpack(VirtualFrame frame, PStruct self, Object buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Cached StructNodes.UnpackValueNode unpackValueNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
int bytesLen = bufferLib.getBufferLength(buffer);
@@ -214,7 +215,7 @@ static Object unpack(VirtualFrame frame, PStruct self, Object buffer,
if (bytesLen != self.getSize()) {
throw raiseNode.get(inliningTarget).raise(StructError, UNPACK_REQ_A_BUFFER_OF_N_BYTES, self.getSize());
}
- return factory.createTuple(unpackInternal(self, unpackValueNode, bytes, 0));
+ return PFactory.createTuple(language, unpackInternal(self, unpackValueNode, bytes, 0));
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -235,9 +236,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static Object iterUnpack(VirtualFrame frame, PStruct self, Object buffer,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
if (self.getSize() == 0) {
@@ -253,7 +254,7 @@ static Object iterUnpack(VirtualFrame frame, PStruct self, Object buffer,
}
// The buffer ownership is transferred to the iterator
// TODO: GR-54860 release it when iterator is collected
- final PStructUnpackIterator structUnpackIterator = factory.createStructUnpackIterator(self, buffer);
+ final PStructUnpackIterator structUnpackIterator = PFactory.createStructUnpackIterator(language, self, buffer);
structUnpackIterator.index = 0;
return structUnpackIterator;
}
@@ -274,10 +275,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(limit = "3")
static Object unpackFrom(VirtualFrame frame, PStruct self, Object buffer, int offset,
@Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Cached StructNodes.UnpackValueNode unpackValueNode,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode) {
try {
int bufferOffset = offset;
@@ -300,7 +301,7 @@ static Object unpackFrom(VirtualFrame frame, PStruct self, Object buffer, int of
throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_UNPACK_FROM_REQ_AT_LEAST_N_BYTES, size + bufferOffset, size, bufferOffset, bytesLen);
}
- return factory.createTuple(unpackInternal(self, unpackValueNode, bytes, bufferOffset));
+ return PFactory.createTuple(language, unpackInternal(self, unpackValueNode, bytes, bufferOffset));
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
index 2c68a5d753..50a43415f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
@@ -6,12 +6,6 @@
package com.oracle.graal.python.builtins.objects.struct;
import static com.oracle.graal.python.builtins.modules.StructModuleBuiltins.ConstructStructNode.NUM_BYTES_LIMIT;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARG_FOR_N_MUST_BE;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARG_NOT_T;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARG_O_O_RANGE;
-import static com.oracle.graal.python.nodes.ErrorMessages.FMT_REQ_RANGE;
-import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_CHR_FMT_BYTES_1;
-import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_FMT_NOT_YET_SUPPORTED;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_BOOL;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_CHAR;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_DOUBLE;
@@ -20,12 +14,19 @@
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_PASCAL_STRING;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_STRING;
import static com.oracle.graal.python.builtins.objects.struct.FormatCode.FMT_VOID_PTR;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARG_FOR_N_MUST_BE;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARG_NOT_T;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARG_O_O_RANGE;
+import static com.oracle.graal.python.nodes.ErrorMessages.FMT_REQ_RANGE;
+import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_CHR_FMT_BYTES_1;
+import static com.oracle.graal.python.nodes.ErrorMessages.STRUCT_FMT_NOT_YET_SUPPORTED;
import static com.oracle.graal.python.nodes.PGuards.isBytes;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.StructError;
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
@@ -44,7 +45,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.util.CastToJavaBigIntegerNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.NumericSupport;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.graal.python.util.PythonUtils;
@@ -406,8 +407,7 @@ static Object unpack8Cached(FormatCode formatCode, @SuppressWarnings("unused") F
@Cached("formatCode.numBytes()") int numBytes,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
@Shared @Cached InlinedConditionProfile profilePIntResult,
- @Shared @Cached InlinedConditionProfile profileSigned,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared @Cached InlinedConditionProfile profileSigned) {
long num;
if (profileSigned.profile(inliningTarget, formatCode.isUnsigned())) {
num = numericSupport.getLongUnsigned(buffer, offset, numBytes);
@@ -416,7 +416,7 @@ static Object unpack8Cached(FormatCode formatCode, @SuppressWarnings("unused") F
num = handleSign(formatCode, num);
}
if (profilePIntResult.profile(inliningTarget, formatCode.isUnsigned() && num < 0)) {
- return factory.get(inliningTarget).createInt(getAsUnsignedBigInt(num));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), getAsUnsignedBigInt(num));
}
return num;
}
@@ -425,10 +425,9 @@ static Object unpack8Cached(FormatCode formatCode, @SuppressWarnings("unused") F
static Object unpack8(FormatCode formatCode, @SuppressWarnings("unused") FormatAlignment formatAlignment, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile profilePIntResult,
- @Shared @Cached InlinedConditionProfile profileSigned,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Shared @Cached InlinedConditionProfile profileSigned) {
return unpack8Cached(formatCode, formatAlignment, buffer, offset, inliningTarget, formatCode.numBytes(),
- getNumericSupport(formatAlignment), profilePIntResult, profileSigned, factory);
+ getNumericSupport(formatAlignment), profilePIntResult, profileSigned);
}
@Specialization(guards = {"isFmtFloat(formatCode)", "numericSupport == getNumericSupport(formatAlignment)"}, limit = "3")
@@ -442,11 +441,10 @@ static Object unpackFloat8(FormatCode formatCode, @SuppressWarnings("unused") Fo
static Object unpackVoidPtr(FormatCode formatCode, FormatAlignment formatAlignment, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile profilePIntResult,
- @Shared @Cached PythonObjectFactory.Lazy factory,
@Shared @Cached PRaiseNode raiseNode) {
long num = getNumericSupport(formatAlignment).getLongUnsigned(buffer, offset, formatCode.numBytes());
if (profilePIntResult.profile(inliningTarget, num < 0)) {
- return factory.get(inliningTarget).createInt(getAsUnsignedBigInt(num));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), getAsUnsignedBigInt(num));
}
return num;
}
@@ -459,8 +457,7 @@ static Object unpackBool(@SuppressWarnings("unused") FormatCode formatCode, @Sup
@Specialization(guards = "isFmtBytes(formatCode)")
static Object unpackBytes(@SuppressWarnings("unused") FormatCode formatCode, @SuppressWarnings("unused") FormatAlignment formatAlignment, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
- @Cached(value = "createIdentityProfile()", inline = false) ValueProfile formatProfile,
- @Shared @Cached PythonObjectFactory.Lazy factory) {
+ @Cached(value = "createIdentityProfile()", inline = false) ValueProfile formatProfile) {
byte[] bytes;
switch (formatProfile.profile(formatCode.formatDef.format)) {
case FMT_CHAR:
@@ -479,7 +476,7 @@ static Object unpackBytes(@SuppressWarnings("unused") FormatCode formatCode, @Su
bytes = new byte[n];
PythonUtils.arraycopy(buffer, offset + 1, bytes, 0, n);
}
- return factory.get(inliningTarget).createBytes(bytes);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), bytes);
}
@Specialization(guards = "!isSupportedFormat(formatCode)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
index 706ba0f621..b0718e01fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
@@ -1,12 +1,12 @@
-/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2020 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
*/
package com.oracle.graal.python.builtins.objects.struct;
-import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_CREATE_P_OBJECTS;
import static com.oracle.graal.python.builtins.objects.struct.StructBuiltins.unpackInternal;
+import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_CREATE_P_OBJECTS;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LENGTH_HINT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___NEW__;
@@ -14,6 +14,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -26,7 +27,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.IndirectCallData;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -91,7 +92,7 @@ static Object next(VirtualFrame frame, PStructUnpackIterator self,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached StructNodes.UnpackValueNode unpackValueNode,
@CachedLibrary("self.getBuffer()") PythonBufferAccessLibrary bufferLib,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
final PStruct struct = self.getStruct();
final Object buffer = self.getBuffer();
@@ -117,7 +118,7 @@ static Object next(VirtualFrame frame, PStructUnpackIterator self,
}
// TODO: GR-54860 handle buffers directly in unpack
- Object result = factory.createTuple(unpackInternal(struct, unpackValueNode, bytes, offset));
+ Object result = PFactory.createTuple(language, unpackInternal(struct, unpackValueNode, bytes, offset));
self.index += struct.getSize();
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
index f35dac0ca0..da6208bc58 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -99,7 +100,7 @@
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -412,8 +413,10 @@ static Object doIt(Node inliningTarget, SuperObject self, Object obj,
@Cached GetTypeNode getType,
@Cached(inline = false) SuperInitNode superInit,
@Cached GetClassNode getClass,
- @Cached(inline = false) PythonObjectFactory factory) {
- SuperObject newSuper = factory.createSuperObject(getClass.execute(inliningTarget, self));
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetInstanceShape getInstanceShape) {
+ Object cls = getClass.execute(inliningTarget, self);
+ SuperObject newSuper = PFactory.createSuperObject(language, cls, getInstanceShape.execute(cls));
superInit.execute(null, newSuper, getType.execute(inliningTarget, self), obj);
return newSuper;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
index 845bf35846..3a200275b3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -121,13 +122,13 @@ abstract static class ReleaseSaveRLockNode extends PythonUnaryBuiltinNode {
static Object releaseSave(PRLock self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile countProfile,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
int count = self.getCount();
if (countProfile.profile(inliningTarget, count == 0)) {
throw raiseNode.get(inliningTarget).raise(PythonErrorType.RuntimeError, ErrorMessages.CANNOT_RELEASE_UNAQUIRED_LOCK);
}
- PTuple retVal = factory.createTuple(new Object[]{count, self.getOwnerId()});
+ PTuple retVal = PFactory.createTuple(language, new Object[]{count, self.getOwnerId()});
self.releaseAll();
return retVal;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalNodes.java
index b42bebeab3..de86e7ad21 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,17 +40,19 @@
*/
package com.oracle.graal.python.builtins.objects.thread;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.call.CallNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
public abstract class ThreadLocalNodes {
@@ -61,12 +63,13 @@ public abstract static class GetThreadLocalDict extends PNodeWithContext {
@Specialization
PDict get(VirtualFrame frame, PThreadLocal self,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory,
+ @Cached InlinedBranchProfile create,
@Cached PyObjectLookupAttr lookup,
@Cached CallNode callNode) {
PDict dict = self.getThreadLocalDict();
if (dict == null) {
- dict = factory.createDict();
+ create.enter(inliningTarget);
+ dict = PFactory.createDict(PythonLanguage.get(inliningTarget));
self.setThreadLocalDict(dict);
Object initMethod = lookup.execute(frame, inliningTarget, self, SpecialMethodNames.T___INIT__);
callNode.execute(frame, initMethod, self.getArgs(), self.getKeywords());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
index f7a393dcbb..36bba4c914 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.pegparser.tokenizer.Token;
import com.oracle.graal.python.pegparser.tokenizer.Token.Kind;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -92,7 +93,7 @@ abstract static class NextNode extends PythonUnaryBuiltinNode {
static PTuple next(PTokenizerIter self,
@Bind("this") Node inliningTarget,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Token token = self.getNextToken();
if (token.type == Kind.ERRORTOKEN || token.type == Kind.ENDMARKER) {
@@ -110,7 +111,7 @@ static PTuple next(PTokenizerIter self,
if (token.type == Kind.NEWLINE) {
endColumn--;
}
- return factory.createTuple(new Object[]{
+ return PFactory.createTuple(language, new Object[]{
fromJavaStringNode.execute(self.getTokenString(token), TS_ENCODING),
token.type,
token.sourceRange.startLine,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/MaterializeLazyTracebackNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/MaterializeLazyTracebackNode.java
index 0f90e1a881..eed52a94df 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/MaterializeLazyTracebackNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/MaterializeLazyTracebackNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,8 +40,9 @@
*/
package com.oracle.graal.python.builtins.objects.traceback;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -134,7 +135,6 @@ static PTraceback getMaterialized(LazyTraceback tb) {
@Fallback
static PTraceback getTraceback(Node inliningTarget, LazyTraceback tb,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached InlinedLoopConditionProfile loopConditionProfile) {
PTraceback newTraceback = null;
LazyTraceback current = tb;
@@ -143,7 +143,7 @@ static PTraceback getTraceback(Node inliningTarget, LazyTraceback tb,
if (current.isMaterialized()) {
newTraceback = current.getTraceback();
} else {
- newTraceback = factory.createTraceback(current);
+ newTraceback = PFactory.createTraceback(PythonLanguage.get(inliningTarget), current);
}
break;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
index 228a0a26ed..f847f3408c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -35,6 +35,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -53,7 +54,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleStackTrace;
import com.oracle.truffle.api.TruffleStackTraceElement;
@@ -85,8 +86,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
public abstract static class DirNode extends PythonBuiltinNode {
@Specialization
static Object dir(@SuppressWarnings("unused") PTraceback self,
- @Cached PythonObjectFactory factory) {
- return factory.createList(PTraceback.getTbFieldNames());
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language, PTraceback.getTbFieldNames());
}
}
@@ -109,8 +110,7 @@ static void doExisting(@SuppressWarnings("unused") PTraceback tb) {
@Specialization(guards = "!tb.isMaterialized()")
static void doMaterialize(Node inliningTarget, PTraceback tb,
@Cached(inline = false) MaterializeFrameNode materializeFrameNode,
- @Cached MaterializeLazyTracebackNode materializeLazyTracebackNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached MaterializeLazyTracebackNode materializeLazyTracebackNode) {
/*
* Truffle stacktrace consists of the frames captured during the unwinding and the
* frames that are now on the Java stack. We don't want the frames from the stack to
@@ -136,7 +136,7 @@ static void doMaterialize(Node inliningTarget, PTraceback tb,
TruffleStackTraceElement element = stackTrace.get(truffleIndex);
if (LazyTraceback.elementWantedForTraceback(element)) {
PFrame pFrame = materializeFrame(element, materializeFrameNode);
- next = factory.createTraceback(pFrame, pFrame.getLine(), next);
+ next = PFactory.createTraceback(PythonLanguage.get(null), pFrame, pFrame.getLine(), next);
next.setBci(pFrame.getBci());
pyIndex++;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
index 45fd01e7a8..8627fd8fbb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -104,10 +104,8 @@
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -262,16 +260,11 @@ public record DescriptorCallTargets(RootCallTarget reprBuiltin, RootCallTarget r
@TruffleBoundary
public static void initType(Python3Core core, BuiltinTypeDescriptor desc) {
- initType(core.factory(), core.getLanguage(), core.lookupType(desc.type), desc);
+ initType(core.getLanguage(), core.lookupType(desc.type), desc);
}
@TruffleBoundary
public static void initType(PythonLanguage language, Object klass, Descriptor desc) {
- initType(PythonContext.get(null).factory(), language, klass, desc);
- }
-
- @TruffleBoundary
- public static void initType(PythonObjectSlowPathFactory factory, PythonLanguage language, Object klass, Descriptor desc) {
assert IsSubtypeNode.getUncached().execute(klass, PythonBuiltinClassType.PTuple);
long flags = TypeNodes.GetTypeFlagsNode.executeUncached(klass);
@@ -285,7 +278,7 @@ public static void initType(PythonObjectSlowPathFactory factory, PythonLanguage
for (int idx = 0; idx < desc.fieldNames.length; ++idx) {
if (desc.fieldNames[idx] != null) {
TruffleString doc = desc.fieldDocStrings == null ? null : desc.fieldDocStrings[idx];
- createMember(factory, language, klass, desc.fieldNames[idx], doc, idx);
+ createMember(language, klass, desc.fieldNames[idx], doc, idx);
} else {
unnamedFields++;
}
@@ -298,8 +291,8 @@ public static void initType(PythonObjectSlowPathFactory factory, PythonLanguage
createBuiltinCallTarget(language, desc, NewNode.class, NewNodeGen::create, false) : //
createBuiltinCallTarget(language, desc, DisabledNewNode.class, ignore -> DisabledNewNodeGen.create(), false)));
- createMethod(factory, klass, ReprNode.class, callTargets.reprBuiltin);
- createMethod(factory, klass, ReduceNode.class, callTargets.reduceBuiltin);
+ createMethod(klass, ReprNode.class, callTargets.reprBuiltin);
+ createMethod(klass, ReduceNode.class, callTargets.reduceBuiltin);
WriteAttributeToObjectNode writeAttrNode = WriteAttributeToObjectNode.getUncached(true);
/*
@@ -315,7 +308,7 @@ public static void initType(PythonObjectSlowPathFactory factory, PythonLanguage
if (ReadAttributeFromObjectNode.getUncachedForceType().execute(klass, T___NEW__) == PNone.NO_VALUE) {
Builtin builtin = NewNode.class.getAnnotation(Builtin.class);
- PythonUtils.createConstructor(factory, klass, builtin, callTargets.newBuiltin);
+ PythonUtils.createConstructor(klass, builtin, callTargets.newBuiltin);
}
if ((flags & TypeFlags.IMMUTABLETYPE) != 0) {
// Restore flags
@@ -329,19 +322,19 @@ private static RootCallTarget createBuiltinCal
return new BuiltinFunctionRootNode(l, builtin, new PrototypeNodeFactory(nodeFactory.apply(descriptor)), declaresExplicitSelf).getCallTarget();
}
- private static void createMember(PythonObjectSlowPathFactory factory, PythonLanguage language, Object klass, TruffleString name, TruffleString doc, int idx) {
+ private static void createMember(PythonLanguage language, Object klass, TruffleString name, TruffleString doc, int idx) {
RootCallTarget callTarget = language.createStructSeqIndexedMemberAccessCachedCallTarget((l) -> new GetStructMemberNode(l, idx), idx);
- PBuiltinFunction getter = factory.createBuiltinFunction(name, klass, 0, 0, callTarget);
- GetSetDescriptor callable = factory.createGetSetDescriptor(getter, null, name, klass, false);
+ PBuiltinFunction getter = PFactory.createBuiltinFunction(language, name, klass, 0, 0, callTarget);
+ GetSetDescriptor callable = PFactory.createGetSetDescriptor(language, getter, null, name, klass, false);
if (doc != null) {
callable.setAttribute(T___DOC__, doc);
}
WriteAttributeToObjectNode.getUncached(true).execute(klass, name, callable);
}
- private static void createMethod(PythonObjectSlowPathFactory factory, Object klass, Class extends PythonBuiltinBaseNode> nodeClass, RootCallTarget callTarget) {
+ private static void createMethod(Object klass, Class extends PythonBuiltinBaseNode> nodeClass, RootCallTarget callTarget) {
Builtin builtin = nodeClass.getAnnotation(Builtin.class);
- PythonUtils.createMethod(factory, klass, builtin, callTarget, PythonBuiltinClassType.PTuple, 0);
+ PythonUtils.createMethod(klass, builtin, callTarget, PythonBuiltinClassType.PTuple, 0);
}
@Builtin(name = J___NEW__, minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true)
@@ -389,14 +382,15 @@ PTuple withoutDict(VirtualFrame frame, Object cls, Object sequence, @SuppressWar
@Exclusive @Cached IsBuiltinObjectProfile notASequenceProfile,
@Exclusive @Cached InlinedBranchProfile wrongLenProfile,
@Exclusive @Cached InlinedBranchProfile needsReallocProfile,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object[] src = sequenceToArray(frame, inliningTarget, sequence, fastConstructListNode, toArrayNode, notASequenceProfile, raiseNode);
Object[] dst = processSequence(inliningTarget, cls, src, wrongLenProfile, needsReallocProfile, raiseNode);
for (int i = src.length; i < dst.length; ++i) {
dst[i] = PNone.NONE;
}
- return factory.createTuple(cls, new ObjectSequenceStorage(dst, inSequence));
+ return PFactory.createTuple(language, cls, getInstanceShape.execute(cls), new ObjectSequenceStorage(dst, inSequence));
}
@Specialization
@@ -409,7 +403,8 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
@Exclusive @Cached InlinedBranchProfile wrongLenProfile,
@Exclusive @Cached InlinedBranchProfile needsReallocProfile,
@Cached HashingStorageGetItem getItem,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
+ @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object[] src = sequenceToArray(frame, inliningTarget, sequence, fastConstructListNode, toArrayNode, notASequenceProfile, raiseNode);
Object[] dst = processSequence(inliningTarget, cls, src, wrongLenProfile, needsReallocProfile, raiseNode);
@@ -418,7 +413,7 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
Object o = getItem.execute(inliningTarget, hs, fieldNames[i]);
dst[i] = o == null ? PNone.NONE : o;
}
- return factory.createTuple(cls, new ObjectSequenceStorage(dst, inSequence));
+ return PFactory.createTuple(language, cls, getInstanceShape.execute(cls), new ObjectSequenceStorage(dst, inSequence));
}
@Specialization(guards = {"!isNoValue(dict)", "!isDict(dict)"})
@@ -483,25 +478,25 @@ PTuple reduce(PTuple self,
@Bind("this") Node inliningTarget,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached GetClassNode getClass,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
assert self.getSequenceStorage() instanceof ObjectSequenceStorage;
Object[] data = CompilerDirectives.castExact(self.getSequenceStorage(), ObjectSequenceStorage.class).getInternalObjectArray();
assert data.length == fieldNames.length;
PTuple seq;
PDict dict;
if (fieldNames.length == inSequence) {
- seq = factory.createTuple(data);
- dict = factory.createDict();
+ seq = PFactory.createTuple(language, data);
+ dict = PFactory.createDict(language);
} else {
HashingStorage storage = EconomicMapStorage.create(fieldNames.length - inSequence);
for (int i = inSequence; i < fieldNames.length; ++i) {
storage = setHashingStorageItem.execute(inliningTarget, storage, fieldNames[i], data[i]);
}
- seq = factory.createTuple(Arrays.copyOf(data, inSequence));
- dict = factory.createDict(storage);
+ seq = PFactory.createTuple(language, Arrays.copyOf(data, inSequence));
+ dict = PFactory.createDict(language, storage);
}
- PTuple seqDictPair = factory.createTuple(new Object[]{seq, dict});
- return factory.createTuple(new Object[]{getClass.execute(inliningTarget, self), seqDictPair});
+ PTuple seqDictPair = PFactory.createTuple(language, new Object[]{seq, dict});
+ return PFactory.createTuple(language, new Object[]{getClass.execute(inliningTarget, self), seqDictPair});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
index 4c696b9e18..e96a6e6c41 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
@@ -50,6 +50,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
@@ -77,7 +78,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqRepeatBuiltinNode;
import com.oracle.graal.python.lib.PyIndexCheckNode;
-import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyObjectHashNode;
import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode;
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
@@ -97,7 +97,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
@@ -296,7 +296,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
raiseNonIntIndex(inliningTarget, raiseNode, idx);
}
return subscriptNode.execute(frame, inliningTarget, getTupleStorage.execute(inliningTarget, self), idx,
- ErrorMessages.TUPLE_OUT_OF_BOUNDS, PythonObjectFactory::createTuple);
+ ErrorMessages.TUPLE_OUT_OF_BOUNDS, PFactory::createTuple);
}
@InliningCutoff
@@ -457,9 +457,9 @@ static PTuple doTuple(Object left, Object right,
@Cached GetTupleStorage getLeft,
@Cached GetTupleStorage getRight,
@Cached("createConcat()") ConcatNode concatNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage concatenated = concatNode.execute(getLeft.execute(inliningTarget, left), getRight.execute(inliningTarget, right));
- return factory.createTuple(concatenated);
+ return PFactory.createTuple(language, concatenated);
}
@NeverDefault
@@ -484,13 +484,11 @@ static Object doTuple(VirtualFrame frame, Object left, int repeats,
@Cached PyTupleCheckExactNode checkTuple,
@Cached GetTupleStorage getLeft,
@Cached InlinedConditionProfile isSingleRepeat,
- @Cached PyNumberAsSizeNode asSizeNode,
- @Cached SequenceStorageNodes.RepeatNode repeatNode,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached SequenceStorageNodes.RepeatNode repeatNode) {
if (isSingleRepeat.profile(inliningTarget, repeats == 1 && checkTuple.execute(inliningTarget, left))) {
return left;
} else {
- return factory.get(inliningTarget).createTuple(repeatNode.execute(frame, getLeft.execute(inliningTarget, left), repeats));
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), repeatNode.execute(frame, getLeft.execute(inliningTarget, left), repeats));
}
}
}
@@ -513,38 +511,38 @@ boolean contains(VirtualFrame frame, Object self, Object other,
public abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization(guards = {"isIntStorage(primary)"})
static PIntegerSequenceIterator doPTupleInt(PTuple primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createIntegerSequenceIterator((IntSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntegerSequenceIterator(language, (IntSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"isObjectStorage(primary)"})
static PObjectSequenceIterator doPTupleObject(PTuple primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createObjectSequenceIterator((ObjectSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createObjectSequenceIterator(language, (ObjectSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"isLongStorage(primary)"})
static PLongSequenceIterator doPTupleLong(PTuple primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createLongSequenceIterator((LongSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createLongSequenceIterator(language, (LongSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"isDoubleStorage(primary)"})
static PDoubleSequenceIterator doPTupleDouble(PTuple primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createDoubleSequenceIterator((DoubleSequenceStorage) primary.getSequenceStorage(), primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createDoubleSequenceIterator(language, (DoubleSequenceStorage) primary.getSequenceStorage(), primary);
}
@Specialization(guards = {"!isIntStorage(primary)", "!isLongStorage(primary)", "!isDoubleStorage(primary)"})
static PSequenceIterator doPTuple(PTuple primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createSequenceIterator(primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createSequenceIterator(language, primary);
}
@Specialization
static PSequenceIterator doNativeTuple(PythonAbstractNativeObject primary,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createSequenceIterator(primary);
+ @Bind PythonLanguage language) {
+ return PFactory.createSequenceIterator(language, primary);
}
}
@@ -607,8 +605,8 @@ public abstract static class GetNewargsNode extends PythonUnaryBuiltinNode {
static PTuple doIt(Object self,
@Bind("this") Node inliningTarget,
@Cached GetTupleStorage getTupleStorage,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{factory.createTuple(getTupleStorage.execute(inliningTarget, self))});
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, new Object[]{PFactory.createTuple(language, getTupleStorage.execute(inliningTarget, self))});
}
}
@@ -617,8 +615,8 @@ static PTuple doIt(Object self,
public abstract static class ClassGetItemNode extends PythonBinaryBuiltinNode {
@Specialization
static Object classGetItem(Object cls, Object key,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAlias(cls, key);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAlias(language, cls, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
index 33d8405fc1..e826238069 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -66,7 +67,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -94,9 +95,9 @@ public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(PTupleGetter self,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory) {
- PTuple args = factory.createTuple(new Object[]{self.getIndex(), self.getDoc()});
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args});
+ @Bind PythonLanguage language) {
+ PTuple args = PFactory.createTuple(language, new Object[]{self.getIndex(), self.getDoc()});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
index ddf02c227a..29bffb65bf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -45,7 +45,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerAsserts;
@@ -131,7 +131,7 @@ protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classS
this.instanceShape = lang.getShapeForClass(this);
}
- this.subClasses = PythonObjectFactory.getUncached().createDict();
+ this.subClasses = PFactory.createDict(lang);
}
public boolean isMROInitialized() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index c984c2a92d..9c0aa4e47d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -1322,7 +1322,6 @@ public void addOperators(PythonClass type) {
assert GetDictIfExistsNode.getUncached().execute(type) == null;
PythonContext context = PythonContext.get(null);
- var factory = context.factory();
PythonLanguage language = context.getLanguage();
for (Entry slotDefEntry : SLOTDEFS.entrySet()) {
TpSlotMeta tpSlotMeta = slotDefEntry.getKey();
@@ -1348,10 +1347,9 @@ public void addOperators(PythonClass type) {
} else if (value instanceof TpSlotNative nativeSlot) {
if (nativeSlot instanceof TpSlotHPyNative hpySlot) {
wrapperDescriptor = HPyExternalFunctionNodes.createWrapperFunction(language, context.getHPyContext(), tpSlotDef.hpyWrapper, hpySlot, tpSlotDef.wrapper, tpSlotDef.name,
- nativeSlot.getCallable(), type,
- factory);
+ nativeSlot.getCallable(), type);
} else {
- wrapperDescriptor = PExternalFunctionWrapper.createWrapperFunction(tpSlotDef.name, (TpSlotCExtNative) nativeSlot, type, tpSlotDef.wrapper, language, factory);
+ wrapperDescriptor = PExternalFunctionWrapper.createWrapperFunction(tpSlotDef.name, (TpSlotCExtNative) nativeSlot, type, tpSlotDef.wrapper, language);
}
}
assert wrapperDescriptor != null;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
index 2c3e4fa940..0d86652c98 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
@@ -175,7 +175,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -307,13 +307,12 @@ abstract static class MroAttrNode extends PythonUnaryBuiltinNode {
static Object doit(Object klass,
@Bind("this") Node inliningTarget,
@Cached TypeNodes.GetMroNode getMroNode,
- @Cached InlinedConditionProfile notInitialized,
- @Cached PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile notInitialized) {
if (notInitialized.profile(inliningTarget, klass instanceof PythonManagedClass && !((PythonManagedClass) klass).isMROInitialized())) {
return PNone.NONE;
}
PythonAbstractClass[] mro = getMroNode.execute(inliningTarget, klass);
- return factory.createTuple(mro);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), mro);
}
}
@@ -324,10 +323,9 @@ public abstract static class MroNode extends PythonUnaryBuiltinNode {
static Object doit(Object klass,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
- @Cached GetMroNode getMroNode,
- @Cached PythonObjectFactory factory) {
+ @Cached GetMroNode getMroNode) {
PythonAbstractClass[] mro = getMroNode.execute(inliningTarget, klass);
- return factory.createList(Arrays.copyOf(mro, mro.length, Object[].class));
+ return PFactory.createList(PythonLanguage.get(inliningTarget), Arrays.copyOf(mro, mro.length, Object[].class));
}
@Fallback
@@ -771,8 +769,8 @@ public abstract static class PrepareNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
Object doIt(Object args, Object kwargs,
- @Cached PythonObjectFactory factory) {
- return factory.createDict(new DynamicObjectStorage(PythonLanguage.get(this)));
+ @Bind PythonLanguage language) {
+ return PFactory.createDict(language, new DynamicObjectStorage(language));
}
}
@@ -784,9 +782,9 @@ abstract static class BasesNode extends PythonBinaryBuiltinNode {
@Specialization
static Object getBases(Object self, @SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
- @Cached TypeNodes.GetBaseClassesNode getBaseClassesNode,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(getBaseClassesNode.execute(inliningTarget, self));
+ @Bind PythonLanguage language,
+ @Cached TypeNodes.GetBaseClassesNode getBaseClassesNode) {
+ return PFactory.createTuple(language, getBaseClassesNode.execute(inliningTarget, self));
}
@Specialization
@@ -886,21 +884,21 @@ static Object base(Object self,
abstract static class DictNode extends PythonUnaryBuiltinNode {
@Specialization
Object doType(PythonBuiltinClassType self,
- @Shared @Cached GetDictIfExistsNode getDict,
- @Shared @Cached PythonObjectFactory factory) {
- return doManaged(getContext().lookupType(self), getDict, factory);
+ @Bind PythonLanguage language,
+ @Shared @Cached GetDictIfExistsNode getDict) {
+ return doManaged(getContext().lookupType(self), language, getDict);
}
@Specialization
static Object doManaged(PythonManagedClass self,
- @Shared @Cached GetDictIfExistsNode getDict,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language,
+ @Shared @Cached GetDictIfExistsNode getDict) {
PDict dict = getDict.execute(self);
if (dict == null) {
- dict = factory.createDictFixedStorage(self, self.getMethodResolutionOrder());
+ dict = PFactory.createDictFixedStorage(language, self, self.getMethodResolutionOrder());
// The mapping is unmodifiable, so we don't have to assign it back
}
- return factory.createMappingproxy(dict);
+ return PFactory.createMappingproxy(language, dict);
}
@Specialization
@@ -1037,13 +1035,12 @@ abstract static class SubclassesNode extends PythonUnaryBuiltinNode {
@Specialization
static PList getSubclasses(Object cls,
@Bind("this") Node inliningTarget,
- @Cached(inline = true) GetSubclassesAsArrayNode getSubclassesNode,
- @Cached PythonObjectFactory factory) {
+ @Cached(inline = true) GetSubclassesAsArrayNode getSubclassesNode) {
// TODO: missing: keep track of subclasses
PythonAbstractClass[] array = getSubclassesNode.execute(inliningTarget, cls);
Object[] classes = new Object[array.length];
PythonUtils.arraycopy(array, 0, classes, 0, array.length);
- return factory.createList(classes);
+ return PFactory.createList(PythonLanguage.get(inliningTarget), classes);
}
}
@@ -1114,16 +1111,16 @@ static void set(PythonClass type, TruffleString value) {
@Specialization
static void set(PythonAbstractNativeObject type, TruffleString value,
+ @Bind PythonLanguage language,
@Cached(inline = false) CStructAccess.WritePointerNode writePointerNode,
@Cached(inline = false) CStructAccess.WriteObjectNewRefNode writeObject,
@Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached(inline = false) TruffleString.CopyToByteArrayNode copyToByteArrayNode,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached(inline = false) TruffleString.CopyToByteArrayNode copyToByteArrayNode) {
value = switchEncodingNode.execute(value, TruffleString.Encoding.UTF_8);
byte[] bytes = copyToByteArrayNode.execute(value, TruffleString.Encoding.UTF_8);
- PBytes bytesObject = factory.createBytes(bytes);
+ PBytes bytesObject = PFactory.createBytes(language, bytes);
writePointerNode.writeToObj(type, PyTypeObject__tp_name, PySequenceArrayWrapper.ensureNativeSequence(bytesObject));
- PString pString = factory.createString(value);
+ PString pString = PFactory.createString(language, value);
pString.setUtf8Bytes(bytesObject);
writeObject.writeToObject(type, PyHeapTypeObject__ht_name, pString);
}
@@ -1450,14 +1447,13 @@ static PSet dir(VirtualFrame frame, Object klass,
@Cached PyObjectLookupAttr lookupAttrNode,
@Cached com.oracle.graal.python.nodes.call.CallNode callNode,
@Cached ToArrayNode toArrayNode,
- @Cached("createGetAttrNode()") GetFixedAttributeNode getBasesNode,
- @Cached PythonObjectFactory factory) {
- return dir(frame, inliningTarget, klass, lookupAttrNode, callNode, getBasesNode, toArrayNode, factory);
+ @Cached("createGetAttrNode()") GetFixedAttributeNode getBasesNode) {
+ return dir(frame, inliningTarget, klass, lookupAttrNode, callNode, getBasesNode, toArrayNode);
}
private static PSet dir(VirtualFrame frame, Node inliningTarget, Object klass, PyObjectLookupAttr lookupAttrNode, com.oracle.graal.python.nodes.call.CallNode callNode,
- GetFixedAttributeNode getBasesNode, ToArrayNode toArrayNode, PythonObjectFactory factory) {
- PSet names = factory.createSet();
+ GetFixedAttributeNode getBasesNode, ToArrayNode toArrayNode) {
+ PSet names = PFactory.createSet(PythonLanguage.get(inliningTarget));
Object updateCallable = lookupAttrNode.execute(frame, inliningTarget, names, T_UPDATE);
Object ns = lookupAttrNode.execute(frame, inliningTarget, klass, T___DICT__);
if (ns != NO_VALUE) {
@@ -1469,7 +1465,7 @@ private static PSet dir(VirtualFrame frame, Node inliningTarget, Object klass, P
for (Object cls : bases) {
// Note that since we are only interested in the keys, the order
// we merge classes is unimportant
- Object baseNames = dir(frame, inliningTarget, cls, lookupAttrNode, callNode, getBasesNode, toArrayNode, factory);
+ Object baseNames = dir(frame, inliningTarget, cls, lookupAttrNode, callNode, getBasesNode, toArrayNode);
callNode.execute(frame, updateCallable, baseNames);
}
}
@@ -1503,13 +1499,14 @@ abstract static class AnnotationsNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNoValue(value)")
static Object get(Object self, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
+ @Cached InlinedBranchProfile createDict,
@Shared("read") @Cached ReadAttributeFromObjectNode read,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Cached PythonObjectFactory.Lazy factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
Object annotations = read.execute(self, T___ANNOTATIONS__);
if (annotations == NO_VALUE) {
- annotations = factory.get(inliningTarget).createDict();
+ createDict.enter(inliningTarget);
+ annotations = PFactory.createDict(PythonLanguage.get(inliningTarget));
try {
write.execute(self, T___ANNOTATIONS__, annotations);
} catch (PException e) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
index db9cbda3a4..122c4f757f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
@@ -207,7 +207,7 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
@@ -1840,6 +1840,10 @@ public abstract static class GetInstanceShape extends PNodeWithContext {
public abstract Shape execute(Object clazz);
+ public static Shape executeUncached(Object clazz) {
+ return TypeNodesFactory.GetInstanceShapeNodeGen.getUncached().execute(clazz);
+ }
+
@Specialization(guards = "clazz == cachedClazz", limit = "1")
@SuppressWarnings("unused")
protected Shape doBuiltinClassTypeCached(PythonBuiltinClassType clazz,
@@ -1899,6 +1903,9 @@ protected static Shape doError(@SuppressWarnings("unused") Object clazz,
throw raise.raise(PythonBuiltinClassType.SystemError, ErrorMessages.CANNOT_GET_SHAPE_OF_NATIVE_CLS);
}
+ public static GetInstanceShape getUncached() {
+ return TypeNodesFactory.GetInstanceShapeNodeGen.getUncached();
+ }
}
@ImportStatic({SpecialMethodNames.class, SpecialAttributeNames.class, SpecialMethodSlot.class})
@@ -1949,13 +1956,12 @@ protected PythonClass makeType(VirtualFrame frame, PDict namespaceOrig, TruffleS
@Cached CallNode callInitSubclassNode,
@Cached("create(T___INIT_SUBCLASS__)") GetAttributeNode getInitSubclassNode,
@Cached GetMroStorageNode getMroStorageNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode raise,
@Cached AllocateTypeWithMetaclassNode typeMetaclass) {
try {
assert SpecialMethodSlot.pushInitializedTypePlaceholder();
- PDict namespace = factory.createDict();
- PythonLanguage language = PythonLanguage.get(this);
+ PDict namespace = PFactory.createDict(language);
namespace.setDictStorage(initNode.execute(frame, namespaceOrig, PKeyword.EMPTY_KEYWORDS));
PythonClass newType = typeMetaclass.execute(frame, name, bases, namespace, metaclass);
@@ -2032,7 +2038,7 @@ protected PythonClass makeType(VirtualFrame frame, PDict namespaceOrig, TruffleS
}
// Call __init_subclass__ on the parent of a newly generated type
- SuperObject superObject = factory.createSuperObject(PythonBuiltinClassType.Super);
+ SuperObject superObject = PFactory.createSuperObject(language);
superObject.init(newType, newType, newType);
callInitSubclassNode.execute(frame, getInitSubclassNode.executeObject(frame, superObject), PythonUtils.EMPTY_OBJECT_ARRAY, kwds);
@@ -2104,7 +2110,7 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached PRaiseNode raise,
@Cached GetObjectArrayNode getObjectArray,
- @Cached PythonObjectFactory factory,
+ @Cached GetInstanceShape getInstanceShape,
@Cached CastToListNode castToListNode,
@Cached PyUnicodeCheckNode stringCheck,
@Cached TruffleString.IsValidNode isValidNode,
@@ -2150,13 +2156,13 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
// 1.) create class, but avoid calling mro method - it might try to access __dict__ so
// we have to copy dict slots first
- PythonClass pythonClass = factory.createPythonClass(metaclass, name, false, base, basesArray);
+ PythonClass pythonClass = PFactory.createPythonClass(language, metaclass, getInstanceShape.execute(metaclass), name, false, base, basesArray);
assert SpecialMethodSlot.replaceInitializedTypeTop(pythonClass);
// 2.) copy the dictionary slots
- copyDictSlots(frame, inliningTarget, ctx, pythonClass, namespace, setHashingStorageItem,
+ copyDictSlots(frame, inliningTarget, language, ctx, pythonClass, namespace, setHashingStorageItem,
getHashingStorageIterator, hashingStorageItNext, hashingStorageItKey, hashingStorageItKeyHash, hashingStorageItValue,
- constructAndRaiseNode, factory, raise, isValidNode, equalNode, codePointLengthNode, getOrCreateDictNode, stringCheck, castToStringNode);
+ constructAndRaiseNode, raise, isValidNode, equalNode, codePointLengthNode, getOrCreateDictNode, stringCheck, castToStringNode);
if (!ctx.qualnameSet) {
pythonClass.setQualName(name);
}
@@ -2227,7 +2233,7 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
throw raise.raise(TypeError, ErrorMessages.DICT_SLOT_DISALLOWED_WE_GOT_ONE);
}
ctx.addDict = true;
- addDictDescrAttribute(basesArray, pythonClass, factory);
+ addDictDescrAttribute(basesArray, pythonClass, language);
} else if (equalNode.execute(slotName, T___WEAKREF__, TS_ENCODING)) {
if (!ctx.mayAddWeak || ctx.addWeak) {
throw raise.raise(TypeError, ErrorMessages.WEAKREF_SLOT_DISALLOWED_WE_GOT_ONE);
@@ -2252,19 +2258,19 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
int indexedSlotCount = getIndexedSlotsCountNode.execute(inliningTarget, base);
if (ctx.copiedSlots != null) {
for (TruffleString slotName : ctx.copiedSlots) {
- IndexedSlotDescriptor slotDesc = factory.createIndexedSlotDescriptor(slotName, indexedSlotCount++, pythonClass);
+ IndexedSlotDescriptor slotDesc = PFactory.createIndexedSlotDescriptor(language, slotName, indexedSlotCount++, pythonClass);
pythonClass.setAttribute(slotName, slotDesc);
}
}
pythonClass.setIndexedSlotCount(indexedSlotCount);
if (ctx.addDict) {
- addDictDescrAttribute(basesArray, pythonClass, factory);
+ addDictDescrAttribute(basesArray, pythonClass, language);
} else if (ctx.mayAddDict) {
pythonClass.setHasSlotsButNoDictFlag();
}
if (ctx.addWeak) {
- addWeakrefDescrAttribute(pythonClass, factory);
+ addWeakrefDescrAttribute(pythonClass, language);
}
if (pythonClass.needsNativeAllocation()) {
@@ -2296,31 +2302,31 @@ private static void typeNewSlotBases(TypeNewContext ctx, Object primaryBase, Pyt
}
@TruffleBoundary
- private static void addDictDescrAttribute(PythonAbstractClass[] basesArray, PythonClass pythonClass, PythonObjectFactory factory) {
+ private static void addDictDescrAttribute(PythonAbstractClass[] basesArray, PythonClass pythonClass, PythonLanguage language) {
// Note: we need to avoid MRO lookup of __dict__ using slots because they are not
// initialized yet
if ((!hasPythonClassBases(basesArray) && LookupAttributeInMRONode.lookupSlowPath(pythonClass, T___DICT__) == PNone.NO_VALUE) || basesHaveSlots(basesArray)) {
Builtin dictBuiltin = ObjectBuiltins.DictNode.class.getAnnotation(Builtin.class);
RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(
l -> new BuiltinFunctionRootNode(l, dictBuiltin, ObjectBuiltinsFactory.DictNodeFactory.getInstance(), true), ObjectBuiltins.DictNode.class);
- setAttribute(T___DICT__, dictBuiltin, callTarget, pythonClass, factory);
+ setAttribute(T___DICT__, dictBuiltin, callTarget, pythonClass, language);
}
}
@TruffleBoundary
- private static void addWeakrefDescrAttribute(PythonClass pythonClass, PythonObjectFactory factory) {
+ private static void addWeakrefDescrAttribute(PythonClass pythonClass, PythonLanguage language) {
if (LookupAttributeInMRONode.lookupSlowPath(pythonClass, T___WEAKREF__) == PNone.NO_VALUE) {
Builtin builtin = GetWeakRefsNode.class.getAnnotation(Builtin.class);
RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(
l -> new BuiltinFunctionRootNode(l, builtin, WeakRefModuleBuiltinsFactory.GetWeakRefsNodeFactory.getInstance(), true), GetWeakRefsNode.class);
- setAttribute(T___WEAKREF__, builtin, callTarget, pythonClass, factory);
+ setAttribute(T___WEAKREF__, builtin, callTarget, pythonClass, language);
}
}
- private static void setAttribute(TruffleString name, Builtin builtin, RootCallTarget callTarget, PythonClass pythonClass, PythonObjectFactory factory) {
+ private static void setAttribute(TruffleString name, Builtin builtin, RootCallTarget callTarget, PythonClass pythonClass, PythonLanguage language) {
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
- PBuiltinFunction function = factory.createBuiltinFunction(name, pythonClass, 1, flags, callTarget);
- GetSetDescriptor desc = factory.createGetSetDescriptor(function, function, name, pythonClass, true);
+ PBuiltinFunction function = PFactory.createBuiltinFunction(language, name, pythonClass, 1, flags, callTarget);
+ GetSetDescriptor desc = PFactory.createGetSetDescriptor(language, function, function, name, pythonClass, true);
pythonClass.setAttribute(name, desc);
}
@@ -2410,10 +2416,11 @@ private static long installMemberDescriptors(PythonManagedClass pythonClass, Tru
return slotOffset;
}
- private static void copyDictSlots(VirtualFrame frame, Node inliningTarget, TypeNewContext ctx, PythonClass pythonClass, PDict namespace, HashingStorageSetItemWithHash setHashingStorageItem,
+ private static void copyDictSlots(VirtualFrame frame, Node inliningTarget, PythonLanguage language, TypeNewContext ctx, PythonClass pythonClass, PDict namespace,
+ HashingStorageSetItemWithHash setHashingStorageItem,
HashingStorageGetIterator getHashingStorageIterator, HashingStorageIteratorNext hashingStorageItNext, HashingStorageIteratorKey hashingStorageItKey,
HashingStorageIteratorKeyHash hashingStorageItKeyHash, HashingStorageIteratorValue hashingStorageItValue,
- PConstructAndRaiseNode.Lazy constructAndRaiseNode, PythonObjectFactory factory, PRaiseNode raise, IsValidNode isValidNode,
+ PConstructAndRaiseNode.Lazy constructAndRaiseNode, PRaiseNode raise, IsValidNode isValidNode,
EqualNode equalNode, CodePointLengthNode codePointLengthNode, GetOrCreateDictNode getOrCreateDictNode, PyUnicodeCheckNode stringCheck,
CastToTruffleStringNode castToStringNode) {
// copy the dictionary slots over, as CPython does through PyDict_Copy
@@ -2433,7 +2440,7 @@ private static void copyDictSlots(VirtualFrame frame, Node inliningTarget, TypeN
if (equalNode.execute(T___NEW__, key, TS_ENCODING)) {
// see CPython: if it's a plain function, make it a static function
if (value instanceof PFunction) {
- pythonClass.setAttribute(key, factory.createStaticmethodFromCallableObj(value));
+ pythonClass.setAttribute(key, PFactory.createStaticmethodFromCallableObj(language, value));
} else {
pythonClass.setAttribute(key, value);
}
@@ -2444,7 +2451,7 @@ private static void copyDictSlots(VirtualFrame frame, Node inliningTarget, TypeN
// __class_getitem__: if they are plain functions, make them
// classmethods
if (value instanceof PFunction) {
- pythonClass.setAttribute(key, factory.createClassmethodFromCallableObj(value));
+ pythonClass.setAttribute(key, PFactory.createClassmethodFromCallableObj(language, value));
} else {
pythonClass.setAttribute(key, value);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlot.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlot.java
index d74d2513c6..4e38bdbc9d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlot.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlot.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -60,6 +60,7 @@
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.TruffleLogger;
@@ -335,7 +336,7 @@ final PBuiltinFunction createBuiltin(Python3Core core, Object type, TruffleStrin
String name = tsName.toJavaStringUncached();
RootCallTarget callTarget = createBuiltinCallTarget(core.getLanguage(), signature, factory, name);
Builtin builtin = ((BuiltinFunctionRootNode) callTarget.getRootNode()).getBuiltin();
- PBuiltinFunction function = core.factory().createWrapperDescriptor(tsName, type, numDefaults(builtin), 0, callTarget, this, wrapper);
+ PBuiltinFunction function = PFactory.createWrapperDescriptor(core.getLanguage(), tsName, type, numDefaults(builtin), 0, callTarget, this, wrapper);
function.setAttribute(T___DOC__, PNone.NONE);
return function;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
index 3f651dc67a..af05abce04 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
@@ -74,6 +74,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -116,7 +117,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -128,6 +129,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.strings.TruffleStringBuilder;
@@ -178,9 +180,10 @@ abstract static class ParametersNode extends PythonUnaryBuiltinNode {
@Specialization
static Object parameters(PGenericAlias self,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached InlinedBranchProfile createProfile) {
if (self.getParameters() == null) {
- self.setParameters(factory.get(inliningTarget).createTuple(GenericTypeNodes.makeParameters(self.getArgs())));
+ createProfile.enter(inliningTarget);
+ self.setParameters(PFactory.createTuple(PythonLanguage.get(inliningTarget), GenericTypeNodes.makeParameters(self.getArgs())));
}
return self.getParameters();
}
@@ -334,8 +337,8 @@ static Object eq(Object self, Object other) {
abstract static class MroEntriesNode extends PythonBinaryBuiltinNode {
@Specialization
static Object mro(PGenericAlias self, @SuppressWarnings("unused") Object bases,
- @Cached PythonObjectFactory factory) {
- return factory.createTuple(new Object[]{self.getOrigin()});
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, new Object[]{self.getOrigin()});
}
}
@@ -370,16 +373,16 @@ static Object reduce(VirtualFrame frame, PGenericAlias self,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetIter getIter,
@Cached PyObjectGetAttr getAttr,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.isStarred()) {
- PGenericAlias copy = factory.createGenericAlias(self.getOrigin(), self.getArgs());
+ PGenericAlias copy = PFactory.createGenericAlias(language, self.getOrigin(), self.getArgs());
PythonModule builtins = PythonContext.get(inliningTarget).getBuiltins();
Object next = getAttr.execute(frame, inliningTarget, builtins, T_NEXT);
- Object args = factory.createTuple(new Object[]{getIter.execute(frame, inliningTarget, copy)});
- return factory.createTuple(new Object[]{next, args});
+ Object args = PFactory.createTuple(language, new Object[]{getIter.execute(frame, inliningTarget, copy)});
+ return PFactory.createTuple(language, new Object[]{next, args});
}
- Object args = factory.createTuple(new Object[]{self.getOrigin(), self.getArgs()});
- return factory.createTuple(new Object[]{getClassNode.execute(inliningTarget, self), args});
+ Object args = PFactory.createTuple(language, new Object[]{self.getOrigin(), self.getArgs()});
+ return PFactory.createTuple(language, new Object[]{getClassNode.execute(inliningTarget, self), args});
}
}
@@ -409,13 +412,13 @@ abstract static class GetItemNode extends MpSubscriptBuiltinNode {
@Specialization
static Object getitem(PGenericAlias self, Object item,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.getParameters() == null) {
- self.setParameters(factory.createTuple(GenericTypeNodes.makeParameters(self.getArgs())));
+ self.setParameters(PFactory.createTuple(language, GenericTypeNodes.makeParameters(self.getArgs())));
}
Object[] newargs = GenericTypeNodes.subsParameters(inliningTarget, self, self.getArgs(), self.getParameters(), item);
- PTuple newargsTuple = factory.createTuple(newargs);
- return factory.createGenericAlias(self.getOrigin(), newargsTuple, self.isStarred());
+ PTuple newargsTuple = PFactory.createTuple(language, newargs);
+ return PFactory.createGenericAlias(language, self.getOrigin(), newargsTuple, self.isStarred());
}
}
@@ -438,8 +441,8 @@ static Object get(PGenericAlias self,
abstract static class IterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object iter(PGenericAlias self,
- @Cached PythonObjectFactory factory) {
- return factory.createGenericAliasIterator(self);
+ @Bind PythonLanguage language) {
+ return PFactory.createGenericAliasIterator(language, self);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
index 9904ac8ec5..511f48bce1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -56,7 +57,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -78,12 +79,12 @@ abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization
static Object next(PGenericAliasIterator self,
@Cached PRaiseNode raiseNode,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.isExhausted()) {
throw raiseNode.raise(PythonBuiltinClassType.StopIteration);
}
PGenericAlias alias = self.getObj();
- PGenericAlias starredAlias = factory.createGenericAlias(alias.getOrigin(), alias.getArgs(), true);
+ PGenericAlias starredAlias = PFactory.createGenericAlias(language, alias.getOrigin(), alias.getArgs(), true);
self.markExhausted();
return starredAlias;
}
@@ -96,16 +97,16 @@ abstract static class ReduceNode extends PythonUnaryBuiltinNode {
static Object reduce(VirtualFrame frame, PGenericAliasIterator self,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttr,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PythonModule builtins = PythonContext.get(inliningTarget).getBuiltins();
Object iter = getAttr.execute(frame, inliningTarget, builtins, T_ITER);
Object[] args;
if (!self.isExhausted()) {
args = new Object[]{self.getObj()};
} else {
- args = new Object[]{factory.createEmptyTuple()};
+ args = new Object[]{PFactory.createEmptyTuple(language)};
}
- return factory.createTuple(new Object[]{iter, factory.createTuple(args)});
+ return PFactory.createTuple(language, new Object[]{iter, PFactory.createTuple(language, args)});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
index 844b9d7b1f..f3429c434f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,6 +52,7 @@
import java.util.Arrays;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
@@ -76,8 +77,7 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.IsNode;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -264,6 +264,7 @@ private static void unpackArgsInner(List newargs, Object item) {
// Equivalent of _Py_subs_parameters
@TruffleBoundary
static Object[] subsParameters(Node node, Object self, PTuple args, PTuple parameters, Object item) {
+ PythonLanguage language = PythonLanguage.get(null);
SequenceStorage paramsStorage = parameters.getSequenceStorage();
int nparams = paramsStorage.length();
if (nparams == 0) {
@@ -274,7 +275,7 @@ static Object[] subsParameters(Node node, Object self, PTuple args, PTuple param
Object param = getItemUncached(paramsStorage, i);
Object prepare = PyObjectLookupAttr.executeUncached(param, T___TYPING_PREPARE_SUBST__);
if (!(prepare instanceof PNone)) {
- Object itemarg = item instanceof PTuple ? item : PythonContext.get(node).factory().createTuple(new Object[]{item});
+ Object itemarg = item instanceof PTuple ? item : PFactory.createTuple(language, new Object[]{item});
item = CallNode.executeUncached(prepare, self, itemarg);
}
}
@@ -298,7 +299,7 @@ static Object[] subsParameters(Node node, Object self, PTuple args, PTuple param
assert iparam >= 0;
arg = CallNode.executeUncached(subst, argitems[iparam]);
} else {
- arg = subsTvars(node, arg, parameters, argitems);
+ arg = subsTvars(arg, parameters, argitems);
}
if (unpack && arg instanceof PTuple tuple /* CPython doesn't check the cast?! */) {
listExtend(newargs, tuple);
@@ -310,7 +311,7 @@ static Object[] subsParameters(Node node, Object self, PTuple args, PTuple param
}
@TruffleBoundary
- private static Object subsTvars(Node node, Object obj, PTuple parameters, Object[] argitems) {
+ private static Object subsTvars(Object obj, PTuple parameters, Object[] argitems) {
Object subparams = PyObjectLookupAttr.executeUncached(obj, T___PARAMETERS__);
if (subparams instanceof PTuple tuple && tuple.getSequenceStorage().length() > 0) {
SequenceStorage subparamsStorage = tuple.getSequenceStorage();
@@ -331,7 +332,7 @@ private static Object subsTvars(Node node, Object obj, PTuple parameters, Object
}
subargs.add(arg);
}
- PTuple subargsTuple = PythonContext.get(node).factory().createTuple(subargs.toArray());
+ PTuple subargsTuple = PFactory.createTuple(PythonLanguage.get(null), subargs.toArray());
obj = PyObjectGetItem.executeUncached(obj, subargsTuple);
}
return obj;
@@ -345,13 +346,13 @@ public abstract static class UnionTypeOrNode extends PNodeWithContext {
static Object union(Object self, Object other,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Cached PyObjectTypeCheck typeCheck,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object[] args = dedupAndFlattenArgs(new Object[]{self, other});
if (args.length == 1) {
return args[0];
}
assert args.length > 1;
- return factory.createUnionType(args);
+ return PFactory.createUnionType(language, args);
}
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
index 86174747fa..2f9632bc54 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
@@ -54,6 +54,7 @@
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.annotations.Slot;
import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
@@ -86,7 +87,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -97,6 +98,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.strings.TruffleStringBuilder;
@@ -123,9 +125,9 @@ Object args(PUnionType self) {
abstract static class ParametersNode extends PythonUnaryBuiltinNode {
@Specialization
static Object parameters(PUnionType self,
- @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
if (self.getParameters() == null) {
- self.setParameters(factory.createTuple(GenericTypeNodes.makeParameters(self.getArgs())));
+ self.setParameters(PFactory.createTuple(language, GenericTypeNodes.makeParameters(self.getArgs())));
}
return self.getParameters();
}
@@ -178,8 +180,8 @@ static long hash(VirtualFrame frame, PUnionType self,
@Bind("this") Node inliningTarget,
@Cached PyObjectHashNode hashNode,
@Cached HashingCollectionNodes.GetClonedHashingStorageNode getHashingStorageNode,
- @Cached PythonObjectFactory factory) {
- PFrozenSet argSet = factory.createFrozenSet(getHashingStorageNode.doNoValue(frame, inliningTarget, self.getArgs()));
+ @Bind PythonLanguage language) {
+ PFrozenSet argSet = PFactory.createFrozenSet(language, getHashingStorageNode.doNoValue(frame, inliningTarget, self.getArgs()));
return hashNode.execute(frame, inliningTarget, argSet);
}
}
@@ -271,9 +273,9 @@ static boolean eq(VirtualFrame frame, PUnionType self, PUnionType other,
@Bind("this") Node inliningTarget,
@Cached HashingCollectionNodes.GetClonedHashingStorageNode getHashingStorageNode,
@Cached PyObjectRichCompareBool.EqNode eqNode,
- @Cached PythonObjectFactory factory) {
- PFrozenSet argSet1 = factory.createFrozenSet(getHashingStorageNode.doNoValue(frame, inliningTarget, self.getArgs()));
- PFrozenSet argSet2 = factory.createFrozenSet(getHashingStorageNode.doNoValue(frame, inliningTarget, other.getArgs()));
+ @Bind PythonLanguage language) {
+ PFrozenSet argSet1 = PFactory.createFrozenSet(language, getHashingStorageNode.doNoValue(frame, inliningTarget, self.getArgs()));
+ PFrozenSet argSet2 = PFactory.createFrozenSet(language, getHashingStorageNode.doNoValue(frame, inliningTarget, other.getArgs()));
return eqNode.compare(frame, inliningTarget, argSet1, argSet2);
}
@@ -292,9 +294,10 @@ abstract static class GetItemNode extends MpSubscriptBuiltinNode {
@Specialization
Object getitem(VirtualFrame frame, PUnionType self, Object item,
@Bind("this") Node inliningTarget,
- @Cached PythonObjectFactory.Lazy factory) {
+ @Cached InlinedBranchProfile createProfile) {
if (self.getParameters() == null) {
- self.setParameters(factory.get(inliningTarget).createTuple(GenericTypeNodes.makeParameters(self.getArgs())));
+ createProfile.enter(inliningTarget);
+ self.setParameters(PFactory.createTuple(PythonLanguage.get(inliningTarget), GenericTypeNodes.makeParameters(self.getArgs())));
}
Object[] newargs = GenericTypeNodes.subsParameters(this, self, self.getArgs(), self.getParameters(), item);
Object result = newargs[0];
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java
index f8cfc842fd..ebf0356f9a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -196,7 +196,6 @@
import com.oracle.graal.python.pegparser.sst.UnaryOpTy;
import com.oracle.graal.python.pegparser.sst.WithItemTy;
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.SuppressFBWarnings;
import com.oracle.truffle.api.memory.ByteArraySupport;
@@ -3138,7 +3137,7 @@ public Void visit(PatternTy.MatchMapping node, PatternContext pc) {
errorCallback.onError(ErrorType.Syntax, unit.currentLocation, "mapping pattern keys may only match literals and attribute lookups");
}
assert constantValue != null;
- Object pythonValue = PythonUtils.pythonObjectFromConstantValue(constantValue, PythonObjectFactory.getUncached());
+ Object pythonValue = PythonUtils.pythonObjectFromConstantValue(constantValue);
for (Object o : seen) {
// need python like equal - e.g. 1 equals True
if (PyObjectRichCompareBool.EqNode.compareUncached(o, pythonValue)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/RaisePythonExceptionErrorCallback.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/RaisePythonExceptionErrorCallback.java
index 1aef184604..7b806c4dab 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/RaisePythonExceptionErrorCallback.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/RaisePythonExceptionErrorCallback.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -61,7 +62,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PIncompleteSourceException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
@@ -163,7 +164,7 @@ public SourceSection getSourceSection() {
cls = PythonBuiltinClassType.TabError;
break;
}
- instance = PythonObjectFactory.getUncached().createBaseException(cls, message, PythonUtils.EMPTY_OBJECT_ARRAY);
+ instance = PFactory.createBaseException(PythonLanguage.get(null), cls, message, PythonUtils.EMPTY_OBJECT_ARRAY);
final Object[] excAttrs = SyntaxErrorBuiltins.SYNTAX_ERROR_ATTR_FACTORY.create();
TruffleString filename = getFilename(source);
excAttrs[SyntaxErrorBuiltins.IDX_FILENAME] = filename;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyContextCopyCurrent.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyContextCopyCurrent.java
index cb3c4de41c..0159df5e47 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyContextCopyCurrent.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyContextCopyCurrent.java
@@ -44,8 +44,7 @@
import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.Specialization;
@@ -60,11 +59,10 @@ public abstract class PyContextCopyCurrent extends PNodeWithContext {
public abstract PContextVarsContext execute(Node inliningTarget);
@Specialization
- static PContextVarsContext doIt(Node inliningTarget,
- @Cached(inline = false) PythonObjectFactory factory) {
+ static PContextVarsContext doIt(Node inliningTarget) {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
PythonContext.PythonThreadState threadState = context.getThreadState(language);
- return factory.copyContextVarsContext(threadState.getContextVarsContext());
+ return PFactory.copyContextVarsContext(language, threadState.getContextVarsContext());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictKeys.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictKeys.java
index f928bdc036..ea0ede1ae7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictKeys.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictKeys.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetIterator;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIterator;
@@ -47,7 +48,8 @@
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorNext;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
import com.oracle.graal.python.builtins.objects.dict.PDict;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -67,7 +69,7 @@ public abstract class PyDictKeys extends Node {
@Specialization
static Object getString(Node inliningTarget, PDict dict,
- @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached HashingStorageLen lenNode,
@Cached HashingStorageGetIterator getIter,
@Cached HashingStorageIteratorNext iterNext,
@@ -80,6 +82,6 @@ static Object getString(Node inliningTarget, PDict dict,
while (iterNext.execute(inliningTarget, storage, it)) {
keys[i++] = iterKey.execute(inliningTarget, storage, it);
}
- return factory.createList(keys);
+ return PFactory.createList(language, keys);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportImport.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportImport.java
index 3db032bdf8..7c056c7d2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportImport.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportImport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,13 +47,15 @@
import static com.oracle.graal.python.nodes.BuiltinNames.T___IMPORT__;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.object.GetDictFromGlobalsNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -86,7 +88,7 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, TruffleString m
@Cached(inline = false) AbstractImportNode.PyImportImportModuleLevelObject importModuleLevelObject,
@Cached PyEvalGetGlobals getGlobals,
@Cached(inline = false) GetDictFromGlobalsNode getDictFromGlobals,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
// Get the builtins from current globals
Object globals = getGlobals.execute(frame, inliningTarget);
Object builtins;
@@ -95,7 +97,7 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, TruffleString m
} else {
// No globals -- use standard builtins, and fake globals
builtins = importModuleLevelObject.execute(frame, PythonContext.get(inliningTarget), T_BUILTINS, null, null, 0);
- globals = factory.createDict(new PKeyword[]{new PKeyword(T___BUILTINS__, builtins)});
+ globals = PFactory.createDict(language, new PKeyword[]{new PKeyword(T___BUILTINS__, builtins)});
}
// Get the __import__ function from the builtins
@@ -110,7 +112,7 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, TruffleString m
// here. Calling for side-effect of import.
callNode.execute(frame, importFunc, new Object[]{moduleName}, new PKeyword[]{
new PKeyword(T_GLOBALS, globals), new PKeyword(T_LOCALS, globals),
- new PKeyword(T_FROMLIST, factory.createList()), new PKeyword(T_LEVEL, 0)
+ new PKeyword(T_FROMLIST, PFactory.createList(language)), new PKeyword(T_LEVEL, 0)
});
return importGetModule.execute(frame, inliningTarget, moduleName);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
index 5861c329e1..0c9af9ddc3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.iterator.PBigRangeIterator;
import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator;
@@ -52,7 +53,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -81,10 +82,10 @@ Object doIntRange(PIntRangeIterator iterator) {
}
@Specialization
- Object doBigIntRange(PBigRangeIterator iterator,
- @Cached PythonObjectFactory factory) {
+ static Object doBigIntRange(PBigRangeIterator iterator,
+ @Bind("this") Node inliningTarget) {
if (iterator.hasNextBigInt()) {
- return factory.createInt(iterator.nextBigInt());
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), iterator.nextBigInt());
}
iterator.setExhausted();
return null;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongCopy.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongCopy.java
index 7c7698e273..b894177240 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongCopy.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongCopy.java
@@ -40,12 +40,13 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.PGuards;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -96,8 +97,8 @@ static long doPIntOverridenNarrowLong(PInt obj) throws OverflowException {
@Specialization(guards = "!isBuiltinPInt(obj)", replaces = "doPIntOverridenNarrowLong")
static PInt doPIntOverriden(PInt obj,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(obj.getValue());
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, obj.getValue());
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
index f633950d5c..7ce2c7818b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,11 +47,13 @@
import java.math.BigInteger;
import java.math.MathContext;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.MathGuards;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -83,8 +85,8 @@ static long doLong(double value) {
@Specialization(guards = {"!fitLong(value)", "isFinite(value)"})
static Object doFinite(double value,
- @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createInt(toBigInteger(value));
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, toBigInteger(value));
}
@Specialization(guards = "!isFinite(value)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
index c854537115..2a543b400a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
@@ -51,7 +51,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -127,7 +127,6 @@ static Object doGeneric(TruffleString numberTs, int base, byte[] originalBytes,
@Cached InlinedBranchProfile invalidBase,
@Cached InlinedBranchProfile notSimpleDecimalLiteralProfile,
@Cached InlinedBranchProfile invalidValueProfile,
- @Cached PythonObjectFactory factory,
@Cached PRaiseNode.Lazy raiseNode,
@Cached StringNodes.StringReprNode stringReprNode,
@Cached BytesNodes.BytesReprNode bytesReprNode) {
@@ -138,14 +137,14 @@ static Object doGeneric(TruffleString numberTs, int base, byte[] originalBytes,
}
notSimpleDecimalLiteralProfile.enter(inliningTarget);
PythonContext context = PythonContext.get(inliningTarget);
- Object value = stringToIntInternal(number, base, context, factory);
+ Object value = stringToIntInternal(number, base, context);
if (value == null) {
invalidValueProfile.enter(inliningTarget);
Object repr;
if (originalBytes == null) {
repr = stringReprNode.execute(numberTs);
} else {
- repr = bytesReprNode.execute(inliningTarget, factory.createBytes(originalBytes, originalBytesLen));
+ repr = bytesReprNode.execute(inliningTarget, PFactory.createBytes(context.getLanguage(inliningTarget), originalBytes, originalBytesLen));
}
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_LITERAL_FOR_INT_WITH_BASE, base, repr);
}
@@ -153,14 +152,14 @@ static Object doGeneric(TruffleString numberTs, int base, byte[] originalBytes,
}
@TruffleBoundary
- private static Object stringToIntInternal(String num, int base, PythonContext context, PythonObjectFactory factory) {
+ private static Object stringToIntInternal(String num, int base, PythonContext context) {
try {
BigInteger bi = asciiToBigInteger(num, base, context);
if (bi == null) {
return null;
}
if (bi.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0 || bi.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) {
- return factory.createInt(bi);
+ return PFactory.createInt(context.getLanguage(), bi);
} else {
return bi.intValue();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
index 2d02aa4da8..9447f3c01a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -64,7 +64,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeByteSequenceStorage;
import com.oracle.graal.python.util.BufferFormat;
import com.oracle.truffle.api.CompilerDirectives;
@@ -89,10 +89,10 @@ public abstract class PyMemoryViewFromObject extends PNodeWithContext {
@Specialization
static PMemoryView fromMemoryView(PMemoryView object,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
object.checkReleased(inliningTarget, raiseNode);
- return factory.createMemoryView(PythonContext.get(inliningTarget), object.getLifecycleManager(), object.getBuffer(), object.getOwner(), object.getLength(),
+ PythonContext context = PythonContext.get(inliningTarget);
+ return PFactory.createMemoryView(context.getLanguage(inliningTarget), context, object.getLifecycleManager(), object.getBuffer(), object.getOwner(), object.getLength(),
object.isReadOnly(), object.getItemSize(), object.getFormat(), object.getFormatString(), object.getDimensions(),
object.getBufferPointer(), object.getOffset(), object.getBufferShape(), object.getBufferStrides(),
object.getBufferSuboffsets(), object.getFlags());
@@ -137,7 +137,6 @@ static PMemoryView fromManaged(VirtualFrame frame, Object object,
@Cached HiddenAttr.ReadNode readGetBufferNode,
@Cached HiddenAttr.ReadNode readReleaseBufferNode,
@Cached CallNode callNode,
- @Shared @Cached PythonObjectFactory factory,
@Cached MemoryViewNodes.InitFlagsNode initFlagsNode,
@Cached TruffleString.CodePointLengthNode lengthNode,
@Cached TruffleString.CodePointAtIndexNode atIndexNode,
@@ -145,8 +144,9 @@ static PMemoryView fromManaged(VirtualFrame frame, Object object,
Object typeObj = getClassNode.execute(inliningTarget, object);
assert typeObj instanceof PythonBuiltinClassType || typeObj instanceof PythonAbstractObject;
PythonAbstractObject type;
+ PythonContext context = PythonContext.get(inliningTarget);
if (isBuiltinClassTypeProfile.profile(inliningTarget, typeObj instanceof PythonBuiltinClassType)) {
- type = PythonContext.get(inliningTarget).lookupType((PythonBuiltinClassType) typeObj);
+ type = context.lookupType((PythonBuiltinClassType) typeObj);
} else {
type = (PythonAbstractObject) typeObj;
}
@@ -179,13 +179,15 @@ static PMemoryView fromManaged(VirtualFrame frame, Object object,
// TODO when Sulong allows exposing pointers as interop buffer, we can get rid of this
Object pythonBuffer = NativeByteSequenceStorage.create(cBuffer.getBuf(), cBuffer.getLen(), cBuffer.getLen(), false);
TruffleString format = cBuffer.getFormat();
- return factory.createMemoryView(PythonContext.get(inliningTarget), bufferLifecycleManager, pythonBuffer, cBuffer.getObj(), cBuffer.getLen(), cBuffer.isReadOnly(), cBuffer.getItemSize(),
+ return PFactory.createMemoryView(context.getLanguage(inliningTarget), context, bufferLifecycleManager, pythonBuffer, cBuffer.getObj(), cBuffer.getLen(), cBuffer.isReadOnly(),
+ cBuffer.getItemSize(),
BufferFormat.forMemoryView(format, lengthNode, atIndexNode),
format, cBuffer.getDims(), cBuffer.getBuf(), 0, shape, strides, suboffsets, flags);
} else if (bufferAcquireLib.hasBuffer(object)) {
// Managed object that implements PythonBufferAcquireLibrary
Object buffer = bufferAcquireLib.acquire(object, BufferFlags.PyBUF_FULL_RO, frame, indirectCallData);
- return factory.createMemoryViewForManagedObject(buffer, bufferLib.getOwner(buffer), bufferLib.getItemSize(buffer), bufferLib.getBufferLength(buffer), bufferLib.isReadonly(buffer),
+ return PFactory.createMemoryViewForManagedObject(context.getLanguage(inliningTarget), buffer, bufferLib.getOwner(buffer), bufferLib.getItemSize(buffer), bufferLib.getBufferLength(buffer),
+ bufferLib.isReadonly(buffer),
bufferLib.getFormatString(buffer), lengthNode, atIndexNode);
} else {
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_A_BYTES_LIKE_OBJECT_REQUIRED_NOT_P, object);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 91ee5c1a5d..221c0d2270 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -42,6 +42,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
@@ -59,9 +60,10 @@
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -142,21 +144,20 @@ protected static SequenceStorageNodes.ConcatNode createConcat() {
return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
}
- @Specialization
- static PList doPList(Node inliningTarget, PList left, PList right,
- @Exclusive @Cached GetClassNode getClassNode,
+ @Specialization(guards = {"isBuiltinList(left)", "isBuiltinList(right)"})
+ static PList doPList(PList left, PList right,
@Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage newStore = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
- return factory.createList(getClassNode.execute(inliningTarget, left), newStore);
+ return PFactory.createList(language, newStore);
}
@Specialization(guards = {"isBuiltinTuple(left)", "isBuiltinTuple(right)"})
- static PTuple doTuple(Node inliningTarget, PTuple left, PTuple right,
+ static PTuple doTuple(PTuple left, PTuple right,
@Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage concatenated = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
- return factory.createTuple(concatenated);
+ return PFactory.createTuple(language, concatenated);
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
index b783cf527c..fbd4580f62 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
@@ -43,6 +43,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CLASS_GETITEM__;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.dict.DictBuiltins;
@@ -62,7 +63,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinClassExactProfile;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -155,7 +156,6 @@ static Object tryType(VirtualFrame frame, Node inliningTarget, Object maybeType,
@Cached TypeNodes.IsTypeNode isTypeNode,
@Cached PyObjectLookupAttr lookupClassGetItem,
@Cached IsBuiltinClassExactProfile isBuiltinClassProfile,
- @Cached(inline = false) PythonObjectFactory factory,
@Cached(inline = false) CallNode callClassGetItem,
@Cached PRaiseNode.Lazy raiseNode) {
if (isTypeNode.execute(inliningTarget, maybeType)) {
@@ -165,7 +165,7 @@ static Object tryType(VirtualFrame frame, Node inliningTarget, Object maybeType,
}
if (isBuiltinClassProfile.profileClass(inliningTarget, maybeType, PythonBuiltinClassType.PythonClass)) {
// Special case type[int], but disallow other types so str[int] fails
- return factory.createGenericAlias(maybeType, key);
+ return PFactory.createGenericAlias(PythonLanguage.get(inliningTarget), maybeType, key);
}
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_NOT_SUBSCRIPTABLE, maybeType);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
index d6c04509b2..2b34a90c7a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.range.PIntRange;
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
@@ -51,10 +52,10 @@
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -84,8 +85,8 @@ public final Object executeCached(Frame frame, Object receiver) {
@Specialization
static Object getIterRange(PIntRange object,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntRangeIterator(object);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntRangeIterator(language, object);
}
@Specialization
@@ -94,7 +95,7 @@ static Object getIter(Frame frame, Node inliningTarget, Object receiver,
@Cached GetClassNode getReceiverClass,
@Cached(parameters = "Iter", inline = false) LookupSpecialMethodSlotNode lookupIter,
@Cached PySequenceCheckNode sequenceCheckNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raise,
@Cached(inline = false) CallUnaryMethodNode callIter,
@Cached PyIterCheckNode checkNode) {
@@ -107,7 +108,7 @@ static Object getIter(Frame frame, Node inliningTarget, Object receiver,
}
if (iterMethod instanceof PNone) {
if (sequenceCheckNode.execute(inliningTarget, receiver)) {
- return factory.createSequenceIterator(receiver);
+ return PFactory.createSequenceIterator(language, receiver);
}
} else {
Object result = callIter.executeObject(frame, iterMethod, receiver);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
index bcc4a7c448..dc0c42ef60 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
@@ -42,6 +42,7 @@
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
@@ -58,9 +59,10 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -84,21 +86,20 @@ protected static SequenceStorageNodes.ConcatNode createConcat() {
return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
}
- @Specialization
- static PList doPList(Node inliningTarget, PList left, PList right,
- @Exclusive @Cached GetClassNode getClassNode,
+ @Specialization(guards = {"isBuiltinList(left)", "isBuiltinList(right)"})
+ static PList doPList(PList left, PList right,
@Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage newStore = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
- return factory.createList(getClassNode.execute(inliningTarget, left), newStore);
+ return PFactory.createList(language, newStore);
}
@Specialization(guards = {"isBuiltinTuple(left)", "isBuiltinTuple(right)"})
static PTuple doTuple(PTuple left, PTuple right,
@Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
SequenceStorage concatenated = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
- return factory.createTuple(concatenated);
+ return PFactory.createTuple(language, concatenated);
}
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySliceNew.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySliceNew.java
index e4380f48dd..516c0b2c29 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySliceNew.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySliceNew.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,12 +40,13 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.slice.PSlice;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -66,42 +67,42 @@ public abstract class PySliceNew extends PNodeWithContext {
@SuppressWarnings("unused")
static PSlice doInt(int start, int stop, PNone step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntSlice(start, stop, 1, false, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, start, stop, 1, false, true);
}
@Specialization
static PSlice doInt(int start, int stop, int step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntSlice(start, stop, step);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, start, stop, step);
}
@Specialization
@SuppressWarnings("unused")
static PSlice doInt(PNone start, int stop, PNone step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntSlice(0, stop, 1, true, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, 0, stop, 1, true, true);
}
@Specialization
@SuppressWarnings("unused")
static PSlice doInt(PNone start, int stop, int step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntSlice(0, stop, step, true, false);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, 0, stop, step, true, false);
}
// This specialization is often used when called from C builtins
@Specialization(guards = {"isIntRange(start)", "isIntRange(stop)"})
@SuppressWarnings("unused")
static PSlice doLong(long start, long stop, PNone step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createIntSlice((int) start, (int) stop, 1, false, true);
+ @Bind PythonLanguage language) {
+ return PFactory.createIntSlice(language, (int) start, (int) stop, 1, false, true);
}
@Fallback
static PSlice doGeneric(Object start, Object stop, Object step,
- @Cached.Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
assert start != PNone.NO_VALUE && stop != PNone.NO_VALUE && step != PNone.NO_VALUE;
- return factory.createObjectSlice(start, stop, step);
+ return PFactory.createObjectSlice(language, start, stop, step);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
index 292ed5e8d9..3d8e435398 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,7 @@
import java.nio.charset.StandardCharsets;
import com.oracle.graal.python.PythonFileDetector;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.code.PCode;
import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes;
@@ -73,7 +74,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -229,9 +230,9 @@ public static TruffleString classNameNoDot(TruffleString name) {
return (i > 0) ? name.substringUncached(i + 1, len - i - 1, TS_ENCODING, true) : name;
}
- public PCode getCode(VirtualFrame frame, PythonObjectFactory factory, TracebackBuiltins.GetTracebackFrameNode getTbFrameNode, PTraceback tb) {
+ public PCode getCode(VirtualFrame frame, PythonLanguage language, TracebackBuiltins.GetTracebackFrameNode getTbFrameNode, PTraceback tb) {
final PFrame pFrame = getTbFrameNode.execute(frame, tb);
- return factory.createCode(pFrame.getTarget());
+ return PFactory.createCode(language, pFrame.getTarget());
}
protected PTraceback getNextTb(Node inliningTarget, TracebackBuiltins.MaterializeTruffleStacktraceNode materializeStNode, PTraceback traceback) {
@@ -333,7 +334,7 @@ private static String trimLeft(CharSequence sequence) {
return (st > 0 ? sequence.subSequence(st, len) : sequence).toString();
}
- private void printInternal(VirtualFrame frame, Node inliningTarget, PythonObjectFactory factory, TracebackBuiltins.GetTracebackFrameNode getTbFrameNode,
+ private void printInternal(VirtualFrame frame, Node inliningTarget, TracebackBuiltins.GetTracebackFrameNode getTbFrameNode,
TracebackBuiltins.MaterializeTruffleStacktraceNode materializeStNode, Object out, PTraceback traceback, long limit,
TruffleString.EqualNode equalNode) {
int depth = 0;
@@ -351,8 +352,9 @@ private void printInternal(VirtualFrame frame, Node inliningTarget, PythonObject
depth--;
tb = getNextTb(inliningTarget, materializeStNode, tb);
}
+ PythonLanguage language = PythonLanguage.get(inliningTarget);
while (tb != null) {
- final PCode code = getCode(frame, factory, getTbFrameNode, tb);
+ final PCode code = getCode(frame, language, getTbFrameNode, tb);
if (lastFile == null ||
!equalNode.execute(code.getFilename(), lastFile, TS_ENCODING) ||
lastLine == -1 || tb.getLineno() != lastLine ||
@@ -383,7 +385,6 @@ public void printTraceBack(VirtualFrame frame, PythonModule sys, Object out, PTr
@Bind("this") Node inliningTarget,
@Cached TracebackBuiltins.GetTracebackFrameNode getTbFrameNode,
@Cached TracebackBuiltins.MaterializeTruffleStacktraceNode materializeStNode,
- @Cached PythonObjectFactory factory,
@Cached TruffleString.EqualNode equalNode) {
long limit = TRACEBACK_LIMIT;
final Object limitv = objectReadAttr(sys, T_TRACEBACKLIMIT);
@@ -394,7 +395,7 @@ public void printTraceBack(VirtualFrame frame, PythonModule sys, Object out, PTr
}
}
fileWriteString(frame, out, "Traceback (most recent call last):\n");
- printInternal(frame, inliningTarget, factory, getTbFrameNode, materializeStNode, out, tb, limit, equalNode);
+ printInternal(frame, inliningTarget, getTbFrameNode, materializeStNode, out, tb, limit, equalNode);
}
@Specialization(guards = "!isPTraceback(tb)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
index 4ec03aba27..7f33752253 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
import static com.oracle.graal.python.runtime.exception.PythonErrorType.RuntimeWarning;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -53,7 +54,7 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -137,7 +138,7 @@ static Object doRegistry(VirtualFrame frame, Node inliningTarget, Object unicode
// If the codec returns a buffer, raise a warning and convert to bytes
if (isByteArrayProfile.profile(inliningTarget, v instanceof PByteArray)) {
warnNode.warnFormat(frame, RuntimeWarning, ENCODER_S_RETURNED_S_INSTEAD_OF_BYTES, encoding, "bytearray");
- return PythonContext.get(inliningTarget).factory().createBytes(copyNode.execute(inliningTarget, ((PByteArray) v).getSequenceStorage()));
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), copyNode.execute(inliningTarget, ((PByteArray) v).getSequenceStorage()));
}
throw raiseNode.get(inliningTarget).raise(TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, v);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
index fc25919b70..70cc0d8e18 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
@@ -43,6 +43,7 @@
import static com.oracle.graal.python.nodes.ErrorMessages.DECODING_STR_NOT_SUPPORTED;
import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
@@ -52,7 +53,8 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -103,12 +105,12 @@ static Object doPString(VirtualFrame frame, PString object, Object encoding, Obj
@Specialization(guards = {"!isPBytes(object)", "!isString(object)"}, limit = "3")
static Object doBuffer(VirtualFrame frame, Node inliningTarget, Object object, Object encoding, Object errors,
+ @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallNode,
@Exclusive @Cached InlinedConditionProfile emptyStringProfile,
@CachedLibrary("object") PythonBufferAcquireLibrary bufferAcquireLib,
@Exclusive @Cached PyUnicodeDecode decode,
- @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib) {
PythonContext context = PythonContext.get(inliningTarget);
Object buffer = bufferAcquireLib.acquireReadonly(object, frame, context, context.getLanguage(inliningTarget), indirectCallNode);
try {
@@ -116,7 +118,7 @@ static Object doBuffer(VirtualFrame frame, Node inliningTarget, Object object, O
if (emptyStringProfile.profile(inliningTarget, len == 0)) {
return T_EMPTY_STRING;
}
- PBytes bytes = factory.createBytes(bufferLib.getInternalOrCopiedByteArray(buffer), len);
+ PBytes bytes = PFactory.createBytes(language, bufferLib.getInternalOrCopiedByteArray(buffer), len);
return decode.execute(frame, inliningTarget, bytes, encoding, errors);
} finally {
bufferLib.release(buffer, frame, indirectCallNode);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
index 4d0883a97f..5cf3878eec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,9 +53,10 @@
import com.oracle.graal.python.nodes.PRaiseNodeGen.LazyNodeGen;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -186,43 +187,43 @@ static PException doPythonBuiltinTypeCached(Node raisingNode, @SuppressWarnings(
@SuppressWarnings("unused") PNone format,
@SuppressWarnings("unused") Object[] arguments,
@Cached("exceptionType") PythonBuiltinClassType cachedType,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- throw raiseExceptionObject(raisingNode, factory.createBaseException(cachedType, data));
+ @Bind PythonLanguage language) {
+ throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, cachedType, data));
}
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0"}, replaces = "doPythonBuiltinTypeCached")
static PException doPythonBuiltinType(Node raisingNode, PythonBuiltinClassType exceptionType, Object[] data, @SuppressWarnings("unused") PNone cause,
@SuppressWarnings("unused") PNone format,
@SuppressWarnings("unused") Object[] arguments,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- throw raiseExceptionObject(raisingNode, factory.createBaseException(exceptionType, data));
+ @Bind PythonLanguage language) {
+ throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, exceptionType, data));
}
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length > 0"})
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object[] data, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
Object[] arguments,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
ensureNoJavaStrings(arguments, fromJavaStringNode);
- throw raiseExceptionObject(raisingNode, factory.createBaseException(type, data, factory.createTuple(arguments)));
+ throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, type, data, PFactory.createTuple(language, arguments)));
}
@Specialization(guards = {"isNoValue(cause)"})
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object[] data, @SuppressWarnings("unused") PNone cause, TruffleString format, Object[] arguments,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
assert format != null;
ensureNoJavaStrings(arguments, fromJavaStringNode);
- throw raiseExceptionObject(raisingNode, factory.createBaseException(type, data, format, arguments));
+ throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, type, data, format, arguments));
}
@Specialization(guards = {"!isNoValue(cause)"})
static PException doBuiltinTypeWithCause(Node raisingNode, PythonBuiltinClassType type, Object[] data, PBaseException cause, TruffleString format, Object[] arguments,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
assert format != null;
ensureNoJavaStrings(arguments, fromJavaStringNode);
- PBaseException baseException = factory.createBaseException(type, data, format, arguments);
+ PBaseException baseException = PFactory.createBaseException(language, type, data, format, arguments);
baseException.setContext(cause);
baseException.setCause(cause);
throw raiseExceptionObject(raisingNode, baseException);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/WriteUnraisableNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/WriteUnraisableNode.java
index 3d87604cbc..e25713eb89 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/WriteUnraisableNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/WriteUnraisableNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.io.IOException;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes;
@@ -55,7 +56,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -89,7 +90,7 @@ static void writeUnraisable(VirtualFrame frame, Object exception, TruffleString
@Cached PyObjectLookupAttr lookup,
@Cached CallNode callNode,
@Cached GetClassNode getClassNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached ExceptionNodes.GetTracebackNode getTracebackNode,
@Cached TruffleString.ConcatNode concatNode,
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode) {
@@ -103,7 +104,8 @@ static void writeUnraisable(VirtualFrame frame, Object exception, TruffleString
if (message != null) {
messageObj = formatMessage(message, concatNode);
}
- Object hookArguments = factory.createStructSeq(SysModuleBuiltins.UNRAISABLEHOOK_ARGS_DESC, exceptionType, exception, traceback, messageObj, object != null ? object : PNone.NONE);
+ Object hookArguments = PFactory.createStructSeq(language, SysModuleBuiltins.UNRAISABLEHOOK_ARGS_DESC, exceptionType, exception, traceback, messageObj,
+ object != null ? object : PNone.NONE);
callNode.execute(frame, unraisablehook, hookArguments);
} catch (PException e) {
ignoreException(context, message, concatNode, copyToByteArrayNode);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarArgsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarArgsNode.java
index 716e488391..10f3ad8cc6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarArgsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarArgsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -25,16 +25,17 @@
*/
package com.oracle.graal.python.nodes.argument;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
public abstract class ReadVarArgsNode extends ReadArgumentNode {
- @Child private PythonObjectFactory factory;
+ private final boolean isBuiltin;
ReadVarArgsNode(boolean isBuiltin) {
- factory = isBuiltin ? null : PythonObjectFactory.create();
+ this.isBuiltin = isBuiltin;
}
public static ReadVarArgsNode create() {
@@ -56,11 +57,11 @@ private Object output(Object[] varArgs) {
if (isBuiltin()) {
return varArgs;
} else {
- return factory.createTuple(varArgs);
+ return PFactory.createTuple(PythonLanguage.get(this), varArgs);
}
}
public boolean isBuiltin() {
- return factory == null;
+ return isBuiltin;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarKeywordsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarKeywordsNode.java
index e09a866e44..8f6a0f059b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarKeywordsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadVarKeywordsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -33,7 +33,7 @@
import com.oracle.graal.python.builtins.objects.function.PArguments;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -47,7 +47,7 @@
public abstract class ReadVarKeywordsNode extends ReadArgumentNode {
@CompilationFinal(dimensions = 1) private final TruffleString[] keywordNames;
- @Child private PythonObjectFactory factory;
+ private final boolean doWrap;
public abstract PKeyword[] executePKeyword(VirtualFrame frame);
@@ -65,7 +65,7 @@ public static ReadVarKeywordsNode createForUserFunction(TruffleString[] names) {
ReadVarKeywordsNode(TruffleString[] keywordNames, boolean doWrap) {
this.keywordNames = keywordNames;
- this.factory = doWrap ? PythonObjectFactory.create() : null;
+ this.doWrap = doWrap;
}
protected int getLimit() {
@@ -86,8 +86,8 @@ protected static int getKwargLen(VirtualFrame frame) {
}
private Object returnValue(PKeyword[] keywords) {
- if (factory != null) {
- return factory.createDict(keywords);
+ if (doWrap) {
+ return PFactory.createDict(PythonLanguage.get(this), keywords);
} else {
return keywords;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/CreateArrowPyCapsuleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/CreateArrowPyCapsuleNode.java
index 0efc521654..6396414b85 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/CreateArrowPyCapsuleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/CreateArrowPyCapsuleNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,7 +47,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.arrow.ArrowArray;
import com.oracle.graal.python.nodes.arrow.ArrowSchema;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -62,8 +62,7 @@ public abstract class CreateArrowPyCapsuleNode extends PNodeWithContext {
@Specialization
static PTuple doArrowCArray(Node inliningTarget, ArrowArray arrowArray, ArrowSchema arrowSchema,
- @Cached PyCapsuleNewNode pyCapsuleNewNode,
- @Cached(inline = false) PythonObjectFactory pythonObjectFactory) {
+ @Cached PyCapsuleNewNode pyCapsuleNewNode) {
var ctx = getContext(inliningTarget);
long arrayDestructor = ctx.arrowSupport.getArrowArrayDestructor();
var arrayCapsuleName = new CArrayWrappers.CByteArrayWrapper(ArrowArray.CAPSULE_NAME);
@@ -73,6 +72,6 @@ static PTuple doArrowCArray(Node inliningTarget, ArrowArray arrowArray, ArrowSch
var schemaCapsuleName = new CArrayWrappers.CByteArrayWrapper(ArrowSchema.CAPSULE_NAME);
PyCapsule arrowSchemaCapsule = pyCapsuleNewNode.execute(inliningTarget, arrowSchema.memoryAddr, schemaCapsuleName, schemaDestructor);
- return pythonObjectFactory.createTuple(new Object[]{arrowSchemaCapsule, arrowArrayCapsule});
+ return PFactory.createTuple(ctx.getLanguage(inliningTarget), new Object[]{arrowSchemaCapsule, arrowArrayCapsule});
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
index eee49e41de..14f01bf355 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
@@ -46,6 +46,7 @@
import static com.oracle.graal.python.nodes.ErrorMessages.DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
@@ -54,10 +55,7 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.list.PList;
-import com.oracle.graal.python.builtins.objects.str.PString;
-import com.oracle.graal.python.builtins.objects.str.StringUtils;
import com.oracle.graal.python.lib.PyObjectGetIter;
-import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.builtins.ListNodesFactory.AppendNodeGen;
@@ -65,9 +63,7 @@
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
-import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
-import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.ArrayBasedSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
@@ -79,12 +75,10 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
-import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.Frame;
@@ -96,8 +90,6 @@
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-import com.oracle.truffle.api.strings.TruffleStringIterator;
/** See the docs on {@link com.oracle.graal.python.builtins.objects.list.ListBuiltins}. */
public abstract class ListNodes {
@@ -203,68 +195,35 @@ static Object doForeign(Object list) {
}
@GenerateUncached
- @ImportStatic({PGuards.class, PythonOptions.class})
@GenerateInline(false) // footprint reduction 40 -> 21
public abstract static class ConstructListNode extends PNodeWithContext {
- public final PList execute(Frame frame, Object value) {
- return execute(frame, PythonBuiltinClassType.PList, value);
- }
-
- protected abstract PList execute(Frame frame, Object cls, Object value);
-
- @Specialization
- static PList listString(Object cls, TruffleString arg,
- @Shared @Cached PythonObjectFactory factory,
- @Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
- @Shared @Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
- @Shared @Cached TruffleStringIterator.NextNode nextNode,
- @Shared @Cached TruffleString.FromCodePointNode fromCodePointNode) {
- return factory.createList(cls, StringUtils.toCharacterArray(arg, codePointLengthNode, createCodePointIteratorNode, nextNode, fromCodePointNode));
- }
-
- @Specialization
- static PList listString(Object cls, PString arg,
- @Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
- @Cached CastToTruffleStringNode castToStringNode,
- @Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
- @Shared @Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
- @Shared @Cached TruffleStringIterator.NextNode nextNode,
- @Shared @Cached TruffleString.FromCodePointNode fromCodePointNode) {
- return listString(cls, castToStringNode.execute(inliningTarget, arg), factory, codePointLengthNode, createCodePointIteratorNode, nextNode, fromCodePointNode);
- }
+ public abstract PList execute(Frame frame, Object value);
@Specialization(guards = "isNoValue(none)")
- static PList none(Object cls, @SuppressWarnings("unused") PNone none,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createList(cls);
+ static PList none(@SuppressWarnings("unused") PNone none,
+ @Bind PythonLanguage language) {
+ return PFactory.createList(language);
}
@Specialization(guards = "isBuiltinList(list)")
// Don't use PSequence, that might copy storages that we don't allow for lists
- static PList fromList(Object cls, PList list,
+ static PList fromList(PList list,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached SequenceStorageNodes.CopyNode copyNode) {
- return factory.createList(cls, copyNode.execute(inliningTarget, list.getSequenceStorage()));
+ return PFactory.createList(language, copyNode.execute(inliningTarget, list.getSequenceStorage()));
}
- @Specialization(guards = {"!isNoValue(iterable)", "!isString(iterable)"})
- static PList listIterable(VirtualFrame frame, Object cls, Object iterable,
+ @Specialization(guards = "!isNoValue(iterable)")
+ static PList listIterable(VirtualFrame frame, Object iterable,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetIter getIter,
@Cached SequenceStorageNodes.CreateStorageFromIteratorNode createStorageFromIteratorNode,
- @Shared @Cached PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
Object iterObj = getIter.execute(frame, inliningTarget, iterable);
SequenceStorage storage = createStorageFromIteratorNode.execute(frame, iterObj);
- return factory.createList(cls, storage);
- }
-
- @Fallback
- static PList listObject(@SuppressWarnings("unused") Object cls, Object value) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw CompilerDirectives.shouldNotReachHere("list does not support iterable object " + value);
+ return PFactory.createList(language, storage);
}
@NeverDefault
@@ -292,7 +251,7 @@ protected static PSequence doPList(PSequence value) {
@Fallback
protected PSequence doGeneric(VirtualFrame frame, Object value,
@Cached(inline = false) ConstructListNode constructListNode) {
- return constructListNode.execute(frame, PythonBuiltinClassType.PList, value);
+ return constructListNode.execute(frame, value);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/TupleNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/TupleNodes.java
index 583ef42436..144d6c65bb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/TupleNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/TupleNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,23 +43,23 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTupleObject__ob_item;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyVarObject__ob_size;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
+import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.CreateStorageFromIteratorNode;
+import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.lib.PyTupleCheckNode;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.NativeObjectSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -75,38 +75,36 @@ public abstract class TupleNodes {
@GenerateUncached
@GenerateInline(false) // footprint reduction 40 -> 21
public abstract static class ConstructTupleNode extends PNodeWithContext {
- public final PTuple execute(VirtualFrame frame, Object value) {
- return execute(frame, PythonBuiltinClassType.PTuple, value);
- }
-
- public abstract PTuple execute(Frame frame, Object cls, Object value);
+ public abstract PTuple execute(Frame frame, Object value);
@Specialization(guards = "isNoValue(none)")
- static PTuple tuple(Object cls, @SuppressWarnings("unused") PNone none,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- return factory.createEmptyTuple(cls);
+ static PTuple tuple(@SuppressWarnings("unused") PNone none,
+ @Bind PythonLanguage language) {
+ return PFactory.createEmptyTuple(language);
}
- @Specialization(guards = {"isBuiltinTupleType(inliningTarget, cls, isSameTypeNode)", "isBuiltinTuple(iterable)"}, limit = "1")
- static PTuple tuple(@SuppressWarnings("unused") Object cls, PTuple iterable,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached TypeNodes.IsSameTypeNode isSameTypeNode) {
+ @Specialization(guards = "isBuiltinTuple(iterable)")
+ static PTuple tuple(PTuple iterable) {
return iterable;
}
+ @Specialization(guards = "isBuiltinList(iterable)")
+ static PTuple list(PList iterable,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
+ @Cached SequenceStorageNodes.CopyNode copyNode) {
+ return PFactory.createTuple(language, copyNode.execute(inliningTarget, iterable.getSequenceStorage()));
+ }
+
@Fallback
@InliningCutoff
- static PTuple tuple(VirtualFrame frame, Object cls, Object iterable,
+ static PTuple generic(VirtualFrame frame, Object iterable,
@Bind("this") Node inliningTarget,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached CreateStorageFromIteratorNode storageNode,
@Cached PyObjectGetIter getIter) {
Object iterObj = getIter.execute(frame, inliningTarget, iterable);
- return factory.createTuple(cls, storageNode.execute(frame, iterObj));
- }
-
- protected static boolean isBuiltinTupleType(Node inliningTarget, Object cls, TypeNodes.IsSameTypeNode isSameTypeNode) {
- return isSameTypeNode.execute(inliningTarget, cls, PythonBuiltinClassType.PTuple);
+ return PFactory.createTuple(language, storageNode.execute(frame, iterObj));
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CopyDictWithoutKeysNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CopyDictWithoutKeysNode.java
index e6694902f8..96d9628273 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CopyDictWithoutKeysNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CopyDictWithoutKeysNode.java
@@ -40,11 +40,12 @@
*/
package com.oracle.graal.python.nodes.bytecode;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.dict.DictNodes;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.lib.PyDictDelItem;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -65,10 +66,10 @@ public abstract class CopyDictWithoutKeysNode extends PNodeWithContext {
static PDict copy(VirtualFrame frame, Object subject, @NeverDefault @SuppressWarnings("unused") Object[] keys,
@Bind("this") Node inliningTarget,
@Cached("keys.length") int keysLength,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached DictNodes.UpdateNode updateNode,
@Shared @Cached PyDictDelItem delItem) {
- PDict rest = factory.createDict();
+ PDict rest = PFactory.createDict(language);
updateNode.execute(frame, rest, subject);
deleteKeys(frame, inliningTarget, keys, keysLength, delItem, rest);
return rest;
@@ -85,10 +86,10 @@ private static void deleteKeys(VirtualFrame frame, Node inliningTarget, Object[]
@Specialization(guards = "keys.length > 32")
static PDict copy(VirtualFrame frame, Object subject, Object[] keys,
@Bind("this") Node inliningTarget,
- @Shared @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared @Cached DictNodes.UpdateNode updateNode,
@Shared @Cached PyDictDelItem delItem) {
- PDict rest = factory.createDict();
+ PDict rest = PFactory.createDict(language);
updateNode.execute(frame, rest, subject);
for (int i = 0; i < keys.length; i++) {
delItem.execute(frame, inliningTarget, rest, keys[i]);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java
index b032f7da80..637625706c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,12 +53,13 @@
import com.oracle.graal.python.compiler.OpCodes;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -83,7 +84,7 @@ public MakeFunctionNode(RootCallTarget callTarget, CodeUnit code, Signature sign
@Specialization
int makeFunction(VirtualFrame frame, Object globals, int initialStackTop, int flags,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached WriteAttributeToPythonObjectNode writeAttrNode) {
int stackTop = initialStackTop;
@@ -95,10 +96,10 @@ int makeFunction(VirtualFrame frame, Object globals, int initialStackTop, int fl
* We cannot initialize the cached code in create, because that may be called
* without langauge context when materializing nodes for instrumentation
*/
- cachedCode = codeObj = factory.createCode(callTarget, signature, code);
+ cachedCode = codeObj = PFactory.createCode(language, callTarget, signature, code);
} else {
// In multi-context mode we have to create the code for every execution
- codeObj = factory.createCode(callTarget, signature, code);
+ codeObj = PFactory.createCode(language, callTarget, signature, code);
}
}
@@ -133,7 +134,8 @@ int makeFunction(VirtualFrame frame, Object globals, int initialStackTop, int fl
codeStableAssumption = Truffle.getRuntime().createAssumption();
defaultsStableAssumption = Truffle.getRuntime().createAssumption();
}
- PFunction function = factory.createFunction(code.name, code.qualname, codeObj, (PythonObject) globals, defaults, kwdefaults, closure, codeStableAssumption, defaultsStableAssumption);
+ PFunction function = PFactory.createFunction(language, code.name, code.qualname, codeObj, (PythonObject) globals, defaults, kwdefaults, closure, codeStableAssumption,
+ defaultsStableAssumption);
if (annotations != null) {
writeAttrNode.execute(function, T___ANNOTATIONS__, annotations);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
index e943d7bf1e..c94084db5b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MATCH_ARGS;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
import com.oracle.graal.python.builtins.objects.str.StringBuiltins;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
@@ -57,7 +58,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -85,7 +86,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
@Cached IsBuiltinObjectProfile isClassProfile,
@Cached StringBuiltins.EqNode eqStrNode,
@Cached PyTupleCheckExactNode tupleCheckExactNode,
- @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PyTupleSizeNode tupleSizeNode,
@Cached TupleBuiltins.GetItemNode getItemNode,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@@ -118,7 +119,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
// it's as if __match_args__ is some "magic" value that is lost as
// soon as they redefine it.
e.expectAttributeError(inliningTarget, isClassProfile);
- matchArgs = factory.createEmptyTuple();
+ matchArgs = PFactory.createEmptyTuple(language);
matchSelf = (getTypeFlagsNode.execute(type) & MATCH_SELF) != 0;
}
int allowed = matchSelf ? 1 : tupleSizeNode.execute(inliningTarget, matchArgs);
@@ -138,7 +139,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
}
// Finally, the keyword subpatterns:
getKwArgs(frame, inliningTarget, subject, type, kwArgs, seen, seenLength, attrs, attrsLength, getAttr, eqStrNode, raise);
- return factory.createList(attrs);
+ return PFactory.createList(language, attrs);
}
@ExplodeLoop
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
index 78329dbc91..b39adc032a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,13 +43,14 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_GET;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
@@ -73,10 +74,9 @@ static Object matchCached(VirtualFrame frame, Object map, @NeverDefault Object[]
@Cached("keys.length") int keysLen,
@Shared @Cached PyObjectRichCompareBool.EqNode compareNode,
@Shared @Cached PyObjectCallMethodObjArgs callMethod,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raise) {
Object[] values = getValues(frame, inliningTarget, map, keys, keysLen, compareNode, callMethod, raise);
- return values != null ? factory.createTuple(values) : PNone.NONE;
+ return values != null ? PFactory.createTuple(PythonLanguage.get(inliningTarget), values) : PNone.NONE;
}
@ExplodeLoop
@@ -113,13 +113,12 @@ static Object match(VirtualFrame frame, Object map, Object[] keys,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectRichCompareBool.EqNode compareNode,
@Shared @Cached PyObjectCallMethodObjArgs callMethod,
- @Shared @Cached PythonObjectFactory factory,
@Shared @Cached PRaiseNode.Lazy raise) {
if (keys.length == 0) {
- return factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
+ return PFactory.createTuple(PythonLanguage.get(inliningTarget), PythonUtils.EMPTY_OBJECT_ARRAY);
}
Object[] values = getValuesLongArray(frame, inliningTarget, map, keys, compareNode, callMethod, raise);
- return values != null ? factory.createTuple(values) : PNone.NONE;
+ return values != null ? PFactory.createTuple(PythonLanguage.get(inliningTarget), values) : PNone.NONE;
}
private static Object[] getValuesLongArray(VirtualFrame frame, Node inliningTarget, Object map, Object[] keys, PyObjectRichCompareBool.EqNode compareNode, PyObjectCallMethodObjArgs callMethod,
@@ -150,8 +149,8 @@ private static void checkSeenLongArray(VirtualFrame frame, Node inliningTarget,
@Specialization(guards = "keys.length == 0")
static Object matchNoKeys(@SuppressWarnings("unused") Object map, @SuppressWarnings("unused") Object[] keys,
- @Shared @Cached PythonObjectFactory factory) {
- return factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
+ @Bind PythonLanguage language) {
+ return PFactory.createTuple(language, PythonUtils.EMPTY_OBJECT_ARRAY);
}
public static MatchKeysNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java
index d3d8e9abe7..3487f3612c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,7 +45,7 @@
import com.oracle.graal.python.builtins.objects.function.PFunction;
import com.oracle.graal.python.builtins.objects.function.Signature;
import com.oracle.graal.python.nodes.PRootNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -63,7 +63,6 @@ public class PBytecodeGeneratorFunctionRootNode extends PRootNode {
@CompilationFinal(dimensions = 1) private final RootCallTarget[] callTargets;
- @Child private PythonObjectFactory factory = PythonObjectFactory.create();
private final ConditionProfile isIterableCoroutine = ConditionProfile.create();
@TruffleBoundary
@@ -80,6 +79,7 @@ public PBytecodeGeneratorFunctionRootNode(PythonLanguage language, FrameDescript
public Object execute(VirtualFrame frame) {
Object[] arguments = frame.getArguments();
+ PythonLanguage language = PythonLanguage.get(this);
// This is passed from InvokeNode node
PFunction generatorFunction = PArguments.getGeneratorFunction(arguments);
assert generatorFunction != null;
@@ -88,14 +88,14 @@ public Object execute(VirtualFrame frame) {
// pass the information to the generator
// .gi_code.co_flags will still be wrong, but at least await will work correctly
if (isIterableCoroutine.profile((generatorFunction.getCode().getFlags() & 0x100) != 0)) {
- return factory.createIterableCoroutine(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
+ return PFactory.createIterableCoroutine(language, generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
} else {
- return factory.createGenerator(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
+ return PFactory.createGenerator(language, generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
}
} else if (rootNode.getCodeUnit().isCoroutine()) {
- return factory.createCoroutine(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
+ return PFactory.createCoroutine(language, generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
} else if (rootNode.getCodeUnit().isAsyncGenerator()) {
- return factory.createAsyncGenerator(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
+ return PFactory.createAsyncGenerator(language, generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
}
throw CompilerDirectives.shouldNotReachHere("Unknown generator/coroutine type");
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index ec48641f73..8ba1f3fb38 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -200,7 +200,7 @@
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonExitException;
import com.oracle.graal.python.runtime.exception.PythonThreadKillException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
@@ -516,7 +516,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
@CompilationFinal(dimensions = 1) private final TruffleString[] freevars;
@CompilationFinal(dimensions = 1) private final TruffleString[] cellvars;
@CompilationFinal(dimensions = 1) private final int[] cell2arg;
- @CompilationFinal(dimensions = 1) protected final Assumption[] cellEffectivelyFinalAssumptions;
+ @CompilationFinal(dimensions = 1) private final Assumption[] cellEffectivelyFinalAssumptions;
@CompilationFinal(dimensions = 1) private final int[] exceptionHandlerRanges;
@@ -562,7 +562,6 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
@Children private final Node[] adoptedNodes;
@Child private CalleeContext calleeContext = CalleeContext.create();
// TODO: make some of those lazy?
- @Child private PythonObjectFactory factory = PythonObjectFactory.create();
@Child private ExceptionStateNodes.GetCaughtExceptionNode getCaughtExceptionNode;
@Child private MaterializeFrameNode traceMaterializeFrameNode = null;
@Child private ChainExceptionsNode chainExceptionsNode;
@@ -570,7 +569,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
@CompilationFinal private Object osrMetadata;
@CompilationFinal private boolean usingCachedNodes;
- @CompilationFinal(dimensions = 1) private int[] conditionProfiles;
+ @CompilationFinal(dimensions = 1) private final int[] conditionProfiles;
@Child private InstrumentationRoot instrumentationRoot = InstrumentationRoot.create();
@@ -868,6 +867,10 @@ private void doInsertChildNode(Node[] nodes, int nodeIndex, Node newNode) {
}
}
+ private PythonLanguage getLanguage() {
+ return getLanguage(PythonLanguage.class);
+ }
+
private static final int CONDITION_PROFILE_MAX_VALUE = 0x3fffffff;
// Inlined from ConditionProfile.Counting#profile
@@ -1052,10 +1055,10 @@ private void copyArgsAndCells(Frame localFrame, Object[] arguments) {
copyArgs(arguments, localFrame);
int varIdx = co.getRegularArgCount();
if (co.takesVarArgs()) {
- localFrame.setObject(varIdx++, factory.createTuple(PArguments.getVariableArguments(arguments)));
+ localFrame.setObject(varIdx++, PFactory.createTuple(getLanguage(), PArguments.getVariableArguments(arguments)));
}
if (co.takesVarKeywordArgs()) {
- localFrame.setObject(varIdx, factory.createDict(PArguments.getKeywordArguments(arguments)));
+ localFrame.setObject(varIdx, PFactory.createDict(getLanguage(), PArguments.getKeywordArguments(arguments)));
}
initCellVars(localFrame);
initFreeVars(localFrame, arguments);
@@ -1172,10 +1175,10 @@ private InstrumentationData getTraceData() {
return instrumentationData;
}
- public PythonContext.PythonThreadState getThreadState(Node node) {
+ public PythonContext.PythonThreadState getThreadState(PBytecodeRootNode node) {
if (this.getTraceData().threadState == null) {
PythonContext context = PythonContext.get(node);
- return this.getTraceData().threadState = context.getThreadState(context.getLanguage(node));
+ return this.getTraceData().threadState = context.getThreadState(node.getLanguage());
}
return this.getTraceData().threadState;
}
@@ -1381,7 +1384,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
}
case OpCodesConstants.LOAD_BIGINT: {
oparg |= Byte.toUnsignedInt(localBC[++bci]);
- virtualFrame.setObject(++stackTop, factory.createInt((BigInteger) localConsts[oparg]));
+ virtualFrame.setObject(++stackTop, PFactory.createInt(language, (BigInteger) localConsts[oparg]));
break;
}
case OpCodesConstants.LOAD_STRING:
@@ -1392,7 +1395,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
}
case OpCodesConstants.LOAD_BYTES: {
oparg |= Byte.toUnsignedInt(localBC[++bci]);
- virtualFrame.setObject(++stackTop, factory.createBytes((byte[]) localConsts[oparg]));
+ virtualFrame.setObject(++stackTop, PFactory.createBytes(language, (byte[]) localConsts[oparg]));
break;
}
case OpCodesConstants.LOAD_CONST_COLLECTION: {
@@ -1405,7 +1408,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
case OpCodesConstants.LOAD_COMPLEX: {
oparg |= Byte.toUnsignedInt(localBC[++bci]);
double[] num = (double[]) localConsts[oparg];
- virtualFrame.setObject(++stackTop, factory.createComplex(num[0], num[1]));
+ virtualFrame.setObject(++stackTop, PFactory.createComplex(language, num[0], num[1]));
break;
}
case OpCodesConstants.MAKE_KEYWORD: {
@@ -1892,7 +1895,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
}
case OpCodesConstants.DELETE_FAST: {
oparg |= Byte.toUnsignedInt(localBC[++bci]);
- bytecodeDeleteFast(localFrame, beginBci, localNodes, oparg, useCachedNodes);
+ bytecodeDeleteFast(localFrame, beginBci, localNodes, oparg);
break;
}
case OpCodesConstants.LOAD_ATTR: {
@@ -2222,7 +2225,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
break;
}
case OpCodesConstants.ASYNCGEN_WRAP: {
- bytecodeAsyncGenWrap(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci);
+ virtualFrame.setObject(stackTop, PFactory.createAsyncGeneratorWrappedValue(language, virtualFrame.getObject(stackTop)));
break;
}
case OpCodesConstants.PUSH_EXC_INFO: {
@@ -2318,7 +2321,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
if (e instanceof AbstractTruffleException) {
exception = (AbstractTruffleException) e;
} else {
- exception = wrapJavaExceptionIfApplicable(e);
+ exception = wrapJavaExceptionIfApplicable(language, e);
if (exception == null) {
throw e;
}
@@ -2382,11 +2385,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
}
}
- @BytecodeInterpreterSwitch
- private void bytecodeAsyncGenWrap(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) {
- virtualFrame.setObject(stackTop, factory.createAsyncGeneratorWrappedValue(virtualFrame.getObject(stackTop)));
- }
-
@BytecodeInterpreterSwitch
private int bytecodeGetAIter(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int bci) {
GetAIterNode node = insertChildNode(localNodes, bci, UNCACHED_GET_AITER, GetAIterNodeGen.class, NODE_GET_AITER, useCachedNodes);
@@ -2877,7 +2875,7 @@ private void traceException(VirtualFrame virtualFrame, MutableLoopData mutableDa
Object peType = GetClassNode.executeUncached(exceptionObject);
Object traceback = ExceptionNodes.GetTracebackNode.executeUncached(exception);
invokeTraceFunction(virtualFrame,
- factory.createTuple(new Object[]{peType, exceptionObject, traceback}), mutableData.getThreadState(this),
+ PFactory.createTuple(getLanguage(), new Object[]{peType, exceptionObject, traceback}), mutableData.getThreadState(this),
mutableData,
PythonContext.TraceEvent.EXCEPTION, bciToLine(bci), true);
}
@@ -3142,7 +3140,7 @@ private void invokeTraceFunction(VirtualFrame virtualFrame, Object arg, PythonCo
pyFrame.setLocalTraceFun(null);
}
} catch (Throwable e) {
- threadState.setTraceFun(null, PythonLanguage.get(this));
+ threadState.setTraceFun(null, getLanguage());
throw e;
} finally {
if (line != -1) {
@@ -3203,7 +3201,7 @@ private void invokeProfileFunction(VirtualFrame virtualFrame, Object arg, Python
Object realResult = result == PNone.NONE ? null : result;
pyFrame.setLocalTraceFun(realResult);
} catch (Throwable e) {
- threadState.setProfileFun(null, PythonLanguage.get(this));
+ threadState.setProfileFun(null, getLanguage());
throw e;
} finally {
threadState.profilingStop();
@@ -4630,17 +4628,17 @@ private void generalizeVariableStores(int index) {
}
@InliningCutoff
- protected PException wrapJavaExceptionIfApplicable(Throwable e) {
+ private PException wrapJavaExceptionIfApplicable(PythonLanguage language, Throwable e) {
if (e instanceof AbstractTruffleException) {
return null;
}
if (e instanceof ControlFlowException) {
return null;
}
- if (PythonLanguage.get(this).getEngineOption(PythonOptions.CatchAllExceptions) && (e instanceof Exception || e instanceof AssertionError)) {
- return ExceptionUtils.wrapJavaException(e, this, factory.createBaseException(SystemError, ErrorMessages.M, new Object[]{e}));
+ if (language.getEngineOption(PythonOptions.CatchAllExceptions) && (e instanceof Exception || e instanceof AssertionError)) {
+ return ExceptionUtils.wrapJavaException(e, this, PFactory.createBaseException(language, SystemError, ErrorMessages.M, new Object[]{e}));
}
- return ExceptionUtils.wrapJavaExceptionIfApplicable(this, e, factory);
+ return ExceptionUtils.wrapJavaExceptionIfApplicable(this, e);
}
@ExplodeLoop
@@ -4784,11 +4782,11 @@ private void bytecodeLoadAttr(VirtualFrame virtualFrame, int stackTop, int bci,
virtualFrame.setObject(stackTop, value);
}
- private void bytecodeDeleteFast(Frame localFrame, int bci, Node[] localNodes, int oparg, boolean useCachedNodes) {
+ private void bytecodeDeleteFast(Frame localFrame, int bci, Node[] localNodes, int oparg) {
if (localFrame.isObject(oparg)) {
Object value = localFrame.getObject(oparg);
if (value == null) {
- raiseVarReferencedBeforeAssignment(localNodes, bci, oparg);
+ throw raiseVarReferencedBeforeAssignment(localNodes, bci, oparg);
}
} else {
generalizeVariableStores(oparg);
@@ -5033,10 +5031,11 @@ private void bytecodeLoadConstCollection(VirtualFrame virtualFrame, int stackTop
int kind = CollectionBits.collectionKind(typeAndKind);
assert kind == CollectionBits.KIND_LIST || kind == CollectionBits.KIND_TUPLE;
boolean list = kind == CollectionBits.KIND_LIST;
- var context = PythonContext.get(this);
- boolean useNativePrimitiveStorage = context.getLanguage(this).getEngineOption(PythonOptions.UseNativePrimitiveStorageStrategy);
+ PythonLanguage language = getLanguage();
+ boolean useNativePrimitiveStorage = language.getEngineOption(PythonOptions.UseNativePrimitiveStorageStrategy);
switch (CollectionBits.elementType(typeAndKind)) {
case CollectionBits.ELEMENT_INT: {
+ var context = PythonContext.get(this);
int[] a = (int[]) array;
if (useNativePrimitiveStorage) {
storage = context.nativeBufferContext.toNativeIntStorage(a);
@@ -5084,9 +5083,9 @@ private void bytecodeLoadConstCollection(VirtualFrame virtualFrame, int stackTop
throw CompilerDirectives.shouldNotReachHere();
}
if (list) {
- result = factory.createList(storage);
+ result = PFactory.createList(language, storage);
} else {
- result = factory.createTuple(storage);
+ result = PFactory.createTuple(language, storage);
}
virtualFrame.setObject(stackTop, result);
}
@@ -5543,17 +5542,17 @@ private int bytecodeCollectionFromStack(VirtualFrame virtualFrame, int type, int
case CollectionBits.KIND_LIST: {
ListFromStackNode storageFromStackNode = insertChildNodeInt(localNodes, nodeIndex, ListFromStackNodeGen.class, LIST_FROM_STACK_NODE, count);
SequenceStorage store = storageFromStackNode.execute(virtualFrame, stackTop - count + 1, stackTop + 1);
- res = factory.createList(store, storageFromStackNode);
+ res = PFactory.createList(getLanguage(), store, storageFromStackNode);
break;
}
case CollectionBits.KIND_TUPLE: {
TupleFromStackNode storageFromStackNode = insertChildNodeInt(localNodes, nodeIndex, TupleFromStackNodeGen.class, TUPLE_FROM_STACK_NODE, count);
SequenceStorage store = storageFromStackNode.execute(virtualFrame, stackTop - count + 1, stackTop + 1);
- res = factory.createTuple(store);
+ res = PFactory.createTuple(getLanguage(), store);
break;
}
case CollectionBits.KIND_SET: {
- PSet set = factory.createSet();
+ PSet set = PFactory.createSet(getLanguage());
HashingCollectionNodes.SetItemNode newNode = insertChildNode(localNodes, nodeIndex, UNCACHED_SET_ITEM, HashingCollectionNodesFactory.SetItemNodeGen.class, NODE_SET_ITEM,
useCachedNodes);
moveFromStack(virtualFrame, stackTop - count + 1, stackTop + 1, set, newNode);
@@ -5561,7 +5560,7 @@ private int bytecodeCollectionFromStack(VirtualFrame virtualFrame, int type, int
break;
}
case CollectionBits.KIND_DICT: {
- PDict dict = factory.createDict();
+ PDict dict = PFactory.createDict(getLanguage());
HashingCollectionNodes.SetItemNode setItem = insertChildNode(localNodes, nodeIndex, UNCACHED_SET_ITEM, HashingCollectionNodesFactory.SetItemNodeGen.class, NODE_SET_ITEM,
useCachedNodes);
assert count % 2 == 0;
@@ -5606,14 +5605,14 @@ private void bytecodeCollectionFromCollection(VirtualFrame virtualFrame, int typ
}
case CollectionBits.KIND_SET: {
SetNodes.ConstructSetNode constructNode = insertChildNode(localNodes, nodeIndex, UNCACHED_CONSTRUCT_SET, SetNodesFactory.ConstructSetNodeGen.class, NODE_CONSTRUCT_SET, useCachedNodes);
- result = constructNode.executeWith(virtualFrame, sourceCollection);
+ result = constructNode.execute(virtualFrame, sourceCollection);
break;
}
case CollectionBits.KIND_DICT: {
// TODO create uncached node
HashingStorage.InitNode initNode = insertChildNode(localNodes, nodeIndex, HashingStorageFactory.InitNodeGen.class, NODE_HASHING_STORAGE_INIT);
HashingStorage storage = initNode.execute(virtualFrame, sourceCollection, PKeyword.EMPTY_KEYWORDS);
- result = factory.createDict(storage);
+ result = PFactory.createDict(getLanguage(), storage);
break;
}
case CollectionBits.KIND_OBJECT: {
@@ -5726,7 +5725,7 @@ private int bytecodeAddToCollection(VirtualFrame virtualFrame, int initialStackT
@BytecodeInterpreterSwitch
private void bytecodeTupleFromList(VirtualFrame virtualFrame, int stackTop) {
PList list = (PList) virtualFrame.getObject(stackTop);
- Object result = factory.createTuple(list.getSequenceStorage());
+ Object result = PFactory.createTuple(getLanguage(), list.getSequenceStorage());
virtualFrame.setObject(stackTop, result);
}
@@ -5734,7 +5733,7 @@ private void bytecodeTupleFromList(VirtualFrame virtualFrame, int stackTop) {
private void bytecodeFrozensetFromList(VirtualFrame virtualFrame, int stackTop, int nodeIndex, Node[] localNodes) {
PList list = (PList) virtualFrame.getObject(stackTop);
HashingStorageFromListSequenceStorageNode node = insertChildNode(localNodes, nodeIndex, HashingStorageFromListSequenceStorageNodeGen.class, NODE_HASHING_STORAGE_FROM_SEQUENCE);
- Object result = factory.createFrozenSet(node.execute(virtualFrame, list.getSequenceStorage()));
+ Object result = PFactory.createFrozenSet(getLanguage(), node.execute(virtualFrame, list.getSequenceStorage()));
virtualFrame.setObject(stackTop, result);
}
@@ -5890,7 +5889,7 @@ protected byte[] extractCode() {
*
* TODO We should revisit this when the AST interpreter is removed.
*/
- return MarshalModuleBuiltins.serializeCodeUnit(co);
+ return MarshalModuleBuiltins.serializeCodeUnit(PythonContext.get(this), co);
}
@Override
@@ -5900,7 +5899,7 @@ protected boolean isCloneUninitializedSupported() {
@Override
protected RootNode cloneUninitialized() {
- return new PBytecodeRootNode(PythonLanguage.get(this), getFrameDescriptor(), getSignature(), co, source, parserErrorCallback);
+ return new PBytecodeRootNode(getLanguage(), getFrameDescriptor(), getSignature(), co, source, parserErrorCallback);
}
public void triggerDeferredDeprecationWarnings() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAnnotationsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAnnotationsNode.java
index ab7481b702..2fe1eb0988 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAnnotationsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAnnotationsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
import static com.oracle.graal.python.builtins.objects.function.PArguments.getSpecialArgument;
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___ANNOTATIONS__;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.dict.PDict;
@@ -57,10 +58,9 @@
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -70,6 +70,7 @@
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@GenerateUncached
@@ -98,13 +99,14 @@ public abstract static class SetupAnnotationsFromDictOrModuleNode extends PNodeW
public abstract void execute(Frame frame, Node inliningTarget, Object locals);
@Specialization
- static void doModule(PythonModule locals,
+ static void doModule(Node inliningTarget, PythonModule locals,
@Cached(inline = false) ReadAttributeFromObjectNode read,
@Cached(inline = false) WriteAttributeToObjectNode write,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached InlinedBranchProfile create) {
Object annotations = read.execute(locals, T___ANNOTATIONS__);
if (annotations == PNone.NO_VALUE) {
- write.execute(locals, T___ANNOTATIONS__, factory.createDict());
+ create.enter(inliningTarget);
+ write.execute(locals, T___ANNOTATIONS__, PFactory.createDict(PythonLanguage.get(inliningTarget)));
}
}
@@ -112,10 +114,11 @@ static void doModule(PythonModule locals,
static void doBuiltinDict(VirtualFrame frame, Node inliningTarget, PDict locals,
@Cached PyDictGetItem getItem,
@Cached PyDictSetItem setItem,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached InlinedBranchProfile create) {
Object annotations = getItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__);
if (annotations == null) {
- setItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__, factory.createDict());
+ create.enter(inliningTarget);
+ setItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__, PFactory.createDict(PythonLanguage.get(inliningTarget)));
}
}
@@ -123,13 +126,12 @@ static void doBuiltinDict(VirtualFrame frame, Node inliningTarget, PDict locals,
static void doOther(VirtualFrame frame, Node inliningTarget, Object locals,
@Cached PyObjectGetItem getItem,
@Cached PyObjectSetItem setItem,
- @Cached IsBuiltinObjectProfile errorProfile,
- @Shared("factory") @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached IsBuiltinObjectProfile errorProfile) {
try {
getItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__);
} catch (PException e) {
e.expect(inliningTarget, PythonBuiltinClassType.KeyError, errorProfile);
- setItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__, factory.createDict());
+ setItem.execute(frame, inliningTarget, locals, T___ANNOTATIONS__, PFactory.createDict(PythonLanguage.get(inliningTarget)));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
index 9813e6c1da..1ea71fe6c4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.list.PList;
@@ -54,14 +55,13 @@
import com.oracle.graal.python.nodes.builtins.ListNodes;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.PSequence;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -82,7 +82,7 @@ static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence s
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
@Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
CompilerAsserts.partialEvaluationConstant(countBefore);
CompilerAsserts.partialEvaluationConstant(countAfter);
@@ -95,7 +95,7 @@ static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence s
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, len);
}
stackTop = moveItemsToStack(frame, inliningTarget, storage, stackTop, 0, countBefore, getItemNode);
- PList starList = factory.createList(getItemSliceNode.execute(storage, countBefore, countBefore + starLen, 1, starLen));
+ PList starList = PFactory.createList(language, getItemSliceNode.execute(storage, countBefore, countBefore + starLen, 1, starLen));
frame.setObject(stackTop--, starList);
moveItemsToStack(frame, inliningTarget, storage, stackTop, len - countAfter, countAfter, getItemNode);
return resultStackTop;
@@ -111,7 +111,7 @@ static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object coll
@Cached ListNodes.ConstructListNode constructListNode,
@Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
@Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
CompilerAsserts.partialEvaluationConstant(countBefore);
CompilerAsserts.partialEvaluationConstant(countAfter);
@@ -135,7 +135,7 @@ static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object coll
frame.setObject(stackTop, starAndAfter);
} else {
int starLen = lenAfter - countAfter;
- PList starList = factory.createList(getItemSliceNode.execute(storage, 0, starLen, 1, starLen));
+ PList starList = PFactory.createList(language, getItemSliceNode.execute(storage, 0, starLen, 1, starLen));
frame.setObject(stackTop--, starList);
moveItemsToStack(frame, inliningTarget, storage, stackTop, starLen, countAfter, getItemNode);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java
index 53f1fe05d0..34eab35e83 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java
@@ -72,7 +72,7 @@
import com.oracle.graal.python.runtime.exception.PythonExitException;
import com.oracle.graal.python.runtime.exception.PythonInterruptedException;
import com.oracle.graal.python.runtime.exception.PythonThreadKillException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -219,7 +219,7 @@ private static boolean isSystemExit(PBaseException pythonException) {
@TruffleBoundary
private void handleJavaException(Throwable e) {
- PException pe = ExceptionUtils.wrapJavaExceptionIfApplicable(this, e, PythonObjectFactory.getUncached());
+ PException pe = ExceptionUtils.wrapJavaExceptionIfApplicable(this, e);
if (pe != null) {
throw handlePythonException(pe);
}
@@ -308,9 +308,10 @@ private Object run(VirtualFrame frame) {
}
PythonContext pythonContext = getContext();
PythonModule mainModule = null;
+ PythonLanguage language = getPythonLanguage();
if (source.isInternal()) {
// internal sources are not run in the main module
- PArguments.setGlobals(arguments, pythonContext.factory().createDict());
+ PArguments.setGlobals(arguments, PFactory.createDict(language));
} else {
mainModule = pythonContext.getMainModule();
PDict mainDict = GetOrCreateDictNode.executeUncached(mainModule);
@@ -318,7 +319,7 @@ private Object run(VirtualFrame frame) {
PArguments.setSpecialArgument(arguments, mainDict);
PArguments.setException(arguments, PException.NO_EXCEPTION);
}
- Object state = IndirectCalleeContext.enterIndirect(getPythonLanguage(), pythonContext, arguments);
+ Object state = IndirectCalleeContext.enterIndirect(language, pythonContext, arguments);
try {
Object result = innerCallTarget.call(arguments);
if (mainModule != null && result == PNone.NONE && !source.isInteractive()) {
@@ -327,7 +328,7 @@ private Object run(VirtualFrame frame) {
return result;
}
} finally {
- IndirectCalleeContext.exit(getPythonLanguage(), pythonContext, state);
+ IndirectCalleeContext.exit(language, pythonContext, state);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
index d172f0b484..2c74fe9c8c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
@@ -64,11 +64,10 @@
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -98,7 +97,7 @@ public abstract static class CastToListNode extends Node {
@Specialization(guards = {"isBuiltinTuple(v)", "cachedLength == getLength(v)", "cachedLength < 32"}, limit = "2")
@ExplodeLoop
static PList starredTupleCachedLength(PTuple v,
- @Exclusive @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached("getLength(v)") int cachedLength,
@Cached SequenceStorageNodes.GetItemNode getItemNode) {
SequenceStorage s = v.getSequenceStorage();
@@ -106,15 +105,15 @@ static PList starredTupleCachedLength(PTuple v,
for (int i = 0; i < cachedLength; i++) {
array[i] = getItemNode.execute(s, i);
}
- return factory.createList(array);
+ return PFactory.createList(language, array);
}
@Specialization(replaces = "starredTupleCachedLength", guards = "isBuiltinTuple(v)")
static PList starredTuple(PTuple v,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached GetObjectArrayNode getObjectArrayNode) {
- return factory.createList(getObjectArrayNode.execute(inliningTarget, v).clone());
+ return PFactory.createList(language, getObjectArrayNode.execute(inliningTarget, v).clone());
}
@Specialization(guards = "isBuiltinList(v)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java
index 34d03bad18..75e1129b3c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.nodes.frame;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.cell.PCell;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageDelItem;
@@ -49,7 +50,7 @@
import com.oracle.graal.python.compiler.CodeUnit;
import com.oracle.graal.python.lib.PyDictGetItem;
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -64,6 +65,7 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
/**
@@ -86,14 +88,15 @@ public static Object executeUncached(PFrame pyFrame) {
}
@Specialization(guards = "!pyFrame.hasCustomLocals()")
- static Object doLoop(PFrame pyFrame,
- @Cached(inline = false) PythonObjectFactory factory,
+ static Object doLoop(Node inliningTarget, PFrame pyFrame,
+ @Cached InlinedBranchProfile create,
@Cached(inline = false) CopyLocalsToDict copyLocalsToDict) {
MaterializedFrame locals = pyFrame.getLocals();
// It doesn't have custom locals, so it has to be a builtin dict or null
PDict localsDict = (PDict) pyFrame.getLocalsDict();
if (localsDict == null) {
- localsDict = factory.createDict();
+ create.enter(inliningTarget);
+ localsDict = PFactory.createDict(PythonLanguage.get(inliningTarget));
pyFrame.setLocalsDict(localsDict);
}
copyLocalsToDict.execute(locals, localsDict);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java
index 113f6234cc..4fb26a1501 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,10 +40,11 @@
*/
package com.oracle.graal.python.nodes.frame;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.frame.PFrame;
import com.oracle.graal.python.builtins.objects.function.PArguments;
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Bind;
@@ -107,37 +108,36 @@ public final PFrame execute(Frame frame, Node location, boolean markAsEscaped, b
"!hasCustomLocals(frameToMaterialize)"}, limit = "1")
static PFrame freshPFrameCachedFD(Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
@Cached(value = "frameToMaterialize.getFrameDescriptor()") FrameDescriptor cachedFD,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("syncValuesNode") @Cached SyncFrameValuesNode syncValuesNode) {
MaterializedFrame locals = createLocalsFrame(cachedFD);
- PFrame escapedFrame = factory.createPFrame(PArguments.getCurrentFrameInfo(frameToMaterialize), location, locals);
+ PFrame escapedFrame = PFactory.createPFrame(language, PArguments.getCurrentFrameInfo(frameToMaterialize), location, locals);
return doEscapeFrame(frameToMaterialize, escapedFrame, markAsEscaped, forceSync, syncValuesNode);
}
@Specialization(guards = {"getPFrame(frameToMaterialize) == null", "!hasGeneratorFrame(frameToMaterialize)", "!hasCustomLocals(frameToMaterialize)"}, replaces = "freshPFrameCachedFD")
static PFrame freshPFrame(Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
- @Shared("factory") @Cached PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Shared("syncValuesNode") @Cached SyncFrameValuesNode syncValuesNode) {
MaterializedFrame locals = createLocalsFrame(frameToMaterialize.getFrameDescriptor());
- PFrame escapedFrame = factory.createPFrame(PArguments.getCurrentFrameInfo(frameToMaterialize), location, locals);
+ PFrame escapedFrame = PFactory.createPFrame(language, PArguments.getCurrentFrameInfo(frameToMaterialize), location, locals);
return doEscapeFrame(frameToMaterialize, escapedFrame, markAsEscaped, forceSync, syncValuesNode);
}
@Specialization(guards = {"getPFrame(frameToMaterialize) == null", "!hasGeneratorFrame(frameToMaterialize)", "hasCustomLocals(frameToMaterialize)"})
static PFrame freshPFrameCusstomLocals(Node location, boolean markAsEscaped, @SuppressWarnings("unused") boolean forceSync,
Frame frameToMaterialize,
- @Shared("factory") @Cached PythonObjectFactory factory) {
- PFrame escapedFrame = factory.createPFrame(PArguments.getCurrentFrameInfo(frameToMaterialize), location, null);
+ @Bind PythonLanguage language) {
+ PFrame escapedFrame = PFactory.createPFrame(language, PArguments.getCurrentFrameInfo(frameToMaterialize), location, null);
escapedFrame.setLocalsDict(PArguments.getSpecialArgument(frameToMaterialize));
return doEscapeFrame(frameToMaterialize, escapedFrame, markAsEscaped, false, null);
}
@Specialization(guards = {"getPFrame(frameToMaterialize) == null", "hasGeneratorFrame(frameToMaterialize)"})
- static PFrame freshPFrameForGenerator(Node location, @SuppressWarnings("unused") boolean markAsEscaped, @SuppressWarnings("unused") boolean forceSync, Frame frameToMaterialize,
- @Shared("factory") @Cached PythonObjectFactory factory) {
+ static PFrame freshPFrameForGenerator(Node location, @SuppressWarnings("unused") boolean markAsEscaped, @SuppressWarnings("unused") boolean forceSync, Frame frameToMaterialize) {
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(frameToMaterialize);
PFrame.Reference frameRef = PArguments.getCurrentFrameInfo(frameToMaterialize);
- PFrame escapedFrame = materializeGeneratorFrame(location, generatorFrame, frameRef, factory);
+ PFrame escapedFrame = materializeGeneratorFrame(location, generatorFrame, frameRef);
frameRef.setPyFrame(escapedFrame);
return doEscapeFrame(frameToMaterialize, escapedFrame, markAsEscaped, false, null);
}
@@ -162,8 +162,8 @@ private static MaterializedFrame createLocalsFrame(FrameDescriptor cachedFD) {
return Truffle.getRuntime().createMaterializedFrame(PythonUtils.EMPTY_OBJECT_ARRAY, cachedFD);
}
- public static PFrame materializeGeneratorFrame(Node location, MaterializedFrame generatorFrame, PFrame.Reference frameRef, PythonObjectFactory factory) {
- PFrame escapedFrame = factory.createPFrame(frameRef, location, generatorFrame);
+ public static PFrame materializeGeneratorFrame(Node location, MaterializedFrame generatorFrame, PFrame.Reference frameRef) {
+ PFrame escapedFrame = PFactory.createPFrame(PythonLanguage.get(location), frameRef, location, generatorFrame);
PArguments.synchronizeArgs(generatorFrame, escapedFrame);
return escapedFrame;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
index 9e398bdd70..5deb4769c2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,7 +45,6 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ControlFlowException;
@@ -58,21 +57,8 @@
*/
public abstract class PythonVarargsBuiltinNode extends PythonBuiltinBaseNode {
- @Child private PythonObjectFactory objectFactory;
@Child private PRaiseNode raiseNode;
- protected final PythonObjectFactory factory() {
- if (objectFactory == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- if (isAdoptable()) {
- objectFactory = insert(PythonObjectFactory.create());
- } else {
- objectFactory = getContext().factory();
- }
- }
- return objectFactory;
- }
-
protected final PRaiseNode getRaiseNode() {
if (raiseNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/DeleteDictNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/DeleteDictNode.java
index 13f5adfde0..3c41dce9fb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/DeleteDictNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/DeleteDictNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.nodes.object;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageCopy;
@@ -48,7 +49,7 @@
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -66,8 +67,7 @@ static void doPythonObject(PythonObject object,
@Bind("this") Node inliningTarget,
@Cached HiddenAttr.ReadNode readHiddenAttrNode,
@Cached HiddenAttr.WriteNode writeHiddenAttrNode,
- @Cached HashingStorageCopy copyNode,
- @Cached PythonObjectFactory factory) {
+ @Cached HashingStorageCopy copyNode) {
/* There is no special handling for class MROs because type.__dict__ cannot be deleted. */
assert !PGuards.isPythonClass(object);
PDict oldDict = (PDict) readHiddenAttrNode.execute(inliningTarget, object, HiddenAttr.DICT, null);
@@ -86,7 +86,7 @@ static void doPythonObject(PythonObject object,
* empty dict dissociated from this object seems like the cleanest option. The disadvantage
* is that the current values won't get garbage collected.
*/
- PDict newDict = factory.createDict();
+ PDict newDict = PFactory.createDict(PythonLanguage.get(inliningTarget));
object.setDict(inliningTarget, writeHiddenAttrNode, newDict);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
index f1f11eb81d..e705a89eb4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_OBJECT_GET_DICT_PTR;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
@@ -56,7 +57,7 @@
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -69,6 +70,7 @@
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateUncached
@SuppressWarnings("truffle-inlining") // footprint reduction 36 -> 17
@@ -121,11 +123,12 @@ static PDict doPythonObject(PythonObject object,
@Specialization
@InliningCutoff
PDict doNativeObject(PythonAbstractNativeObject object,
+ @Bind("this") Node inliningTarget,
@CachedLibrary(limit = "1") InteropLibrary lib,
@Cached PythonToNativeNode toNative,
@Cached CStructAccess.ReadObjectNode readObjectNode,
@Cached CStructAccess.WriteObjectNewRefNode writeObjectNode,
- @Cached PythonObjectFactory factory,
+ @Cached InlinedBranchProfile createDict,
@Cached CExtNodes.PCallCapiFunction callGetDictPtr) {
Object dictPtr = callGetDictPtr.call(FUN_PY_OBJECT_GET_DICT_PTR, toNative.execute(object));
if (lib.isNull(dictPtr)) {
@@ -133,7 +136,8 @@ PDict doNativeObject(PythonAbstractNativeObject object,
} else {
Object dictObject = readObjectNode.readGeneric(dictPtr, 0);
if (dictObject == PNone.NO_VALUE) {
- PDict dict = factory.createDict();
+ createDict.enter(inliningTarget);
+ PDict dict = PFactory.createDict(PythonLanguage.get(inliningTarget));
writeObjectNode.write(dictPtr, dict);
return dict;
} else if (dictObject instanceof PDict dict) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetForeignObjectClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetForeignObjectClassNode.java
index f2ba18eb96..3bdb1cfd1b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetForeignObjectClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetForeignObjectClassNode.java
@@ -54,6 +54,7 @@
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -249,7 +250,7 @@ private PythonManagedClass resolvePolyglotForeignClass(PythonContext context, in
PythonModule polyglotModule = context.lookupBuiltinModule(T_POLYGLOT);
- PythonClass pythonClass = context.factory().createPythonClassAndFixupSlots(context.getLanguage(), PythonBuiltinClassType.PythonClass, name, base, bases);
+ PythonClass pythonClass = PFactory.createPythonClassAndFixupSlots(context.getLanguage(), name, base, bases);
pythonClass.setAttribute(T___MODULE__, T_POLYGLOT);
assert polyglotModule.getAttribute(name) == PNone.NO_VALUE : name;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
index 9290b4d348..b5d569ad8a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,14 +42,16 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -81,11 +83,11 @@ static PDict doPythonObject(Node inliningTarget, PythonObject object,
@Shared("getDict") @Cached(inline = false) GetDictIfExistsNode getDictIfExistsNode,
@Cached SetDictNode setDictNode,
@Cached InlinedBranchProfile createDict,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Bind PythonLanguage language) {
PDict dict = getDictIfExistsNode.execute(object);
if (dict == null) {
createDict.enter(inliningTarget);
- dict = factory.createDictFixedStorage(object);
+ dict = PFactory.createDictFixedStorage(language, object);
setDictNode.execute(inliningTarget, object, dict);
}
return dict;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
index 3158eff127..0b736e22e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
@@ -58,6 +58,7 @@
import com.oracle.graal.python.nodes.SpecialAttributeNames;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.ArrayBuilder;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
@@ -190,7 +191,7 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
PythonClass pythonClass;
try {
// The call might not succeed if, for instance, the MRO can't be constructed
- pythonClass = context.factory().createPythonClassAndFixupSlots(context.getLanguage(), PythonBuiltinClassType.PythonClass, className, bases[0], basesWithForeign);
+ pythonClass = PFactory.createPythonClassAndFixupSlots(context.getLanguage(), className, bases[0], basesWithForeign);
} catch (PException e) {
// Catch the error to additionally print the collected classes and specify the error
// occurred during class creation
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
index c5da70de2d..55e7bd700a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
@@ -79,7 +79,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.ValueType;
@@ -113,7 +113,7 @@ public static PythonModule importModule(TruffleString name) {
if (builtinImport == PNone.NO_VALUE) {
throw PConstructAndRaiseNode.getUncached().raiseImportError(null, IMPORT_NOT_FOUND);
}
- Object fromList = context.factory().createTuple(PythonUtils.EMPTY_TRUFFLESTRING_ARRAY);
+ Object fromList = PFactory.createTuple(context.getLanguage(), PythonUtils.EMPTY_TRUFFLESTRING_ARRAY);
CallNode.executeUncached(builtinImport, name, PNone.NONE, PNone.NONE, fromList, 0);
PythonModule sysModule = context.lookupBuiltinModule(T_SYS);
Object modules = sysModule.getAttribute(T_MODULES);
@@ -170,7 +170,6 @@ static Object importName(VirtualFrame frame, PythonContext context, PythonModule
@Cached PConstructAndRaiseNode.Lazy raiseNode,
@Cached CallNode importCallNode,
@Cached GetDictFromGlobalsNode getDictNode,
- @Cached PythonObjectFactory factory,
@Cached PyImportImportModuleLevelObject importModuleLevel) {
Object importFunc = readAttrNode.execute(builtins, T___IMPORT__, null);
if (importFunc == null) {
@@ -183,7 +182,7 @@ static Object importName(VirtualFrame frame, PythonContext context, PythonModule
} else {
globalsArg = getDictNode.execute(inliningTarget, globals);
}
- return importCallNode.execute(frame, importFunc, name, globalsArg, PNone.NONE, factory.createTuple(fromList), level);
+ return importCallNode.execute(frame, importFunc, name, globalsArg, PNone.NONE, PFactory.createTuple(PythonLanguage.get(inliningTarget), fromList), level);
}
return importModuleLevel.execute(frame, context, name, globals, fromList, level);
}
@@ -259,7 +258,6 @@ static Object genericImport(VirtualFrame frame, PythonContext context, TruffleSt
@Exclusive @Cached EnsureInitializedNode ensureInitialized,
@Cached PyObjectLookupAttr getPathNode,
@Cached PyObjectCallMethodObjArgs callHandleFromlist,
- @Cached PythonObjectFactory factory,
@Exclusive @Cached FindAndLoad findAndLoad,
@Cached InlinedConditionProfile recursiveCase,
@Exclusive @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@@ -324,7 +322,7 @@ static Object genericImport(VirtualFrame frame, PythonContext context, TruffleSt
if (path != PNone.NO_VALUE) {
return callHandleFromlist.execute(frame, inliningTarget, context.getImportlib(), T__HANDLE_FROMLIST,
mod,
- factory.createTuple(fromList),
+ PFactory.createTuple(PythonLanguage.get(inliningTarget), fromList),
context.importFunc());
} else {
return mod;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
index a601e6518a..3d37ed59d9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.complex.PComplex;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
@@ -51,9 +52,9 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -72,14 +73,14 @@ public abstract class CoerceToComplexNode extends PNodeWithContext {
@Specialization
static PComplex doLong(long x,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(x, 0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, x, 0);
}
@Specialization
static PComplex doDouble(double x,
- @Shared @Cached(inline = false) PythonObjectFactory factory) {
- return factory.createComplex(x, 0);
+ @Bind PythonLanguage language) {
+ return PFactory.createComplex(language, x, 0);
}
@Specialization
@@ -91,7 +92,7 @@ static PComplex doComplex(PComplex x) {
static PComplex toComplex(VirtualFrame frame, Node inliningTarget, Object x,
@Cached(value = "create(T___COMPLEX__)", inline = false) LookupAndCallUnaryNode callComplexFunc,
@Cached PyFloatAsDoubleNode asDoubleNode,
- @Shared @Cached(inline = false) PythonObjectFactory factory,
+ @Bind PythonLanguage language,
@Cached PRaiseNode.Lazy raiseNode) {
Object result = callComplexFunc.executeObject(frame, x);
if (result != PNone.NO_VALUE) {
@@ -106,6 +107,6 @@ static PComplex toComplex(VirtualFrame frame, Node inliningTarget, Object x,
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_RETURN, "__complex__", "complex object");
}
}
- return factory.createComplex(asDoubleNode.execute(frame, inliningTarget, x), 0);
+ return PFactory.createComplex(language, asDoubleNode.execute(frame, inliningTarget, x), 0);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNode.java
index 66c6f99559..ba7025a57e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,9 +42,10 @@
import java.math.BigInteger;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -72,14 +73,13 @@ static Object narrowBigInteger0(@SuppressWarnings("unused") BigInteger x) {
@Specialization(guards = "x.signum() != 0")
static Object narrowBigInteger(Node inliningTarget, BigInteger x,
@Cached InlinedConditionProfile fitsIntProfile,
- @Cached InlinedConditionProfile fitsLongProfile,
- @Cached(inline = false) PythonObjectFactory factory) {
+ @Cached InlinedConditionProfile fitsLongProfile) {
if (fitsIntProfile.profile(inliningTarget, PInt.fitsIn(x, PInt.MIN_INT, PInt.MAX_INT))) {
return PInt.intValue(x);
}
if (fitsLongProfile.profile(inliningTarget, PInt.fitsIn(x, PInt.MIN_LONG, PInt.MAX_LONG))) {
return PInt.longValue(x);
}
- return factory.createInt(x);
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), x);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
index 2a27d077bf..2dc3794f47 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
@@ -160,7 +160,9 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.object.SetDictNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
+import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntLossyNode;
+import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.AsyncHandler.AsyncAction;
import com.oracle.graal.python.runtime.PythonContextFactory.GetThreadStateNodeGen;
import com.oracle.graal.python.runtime.arrow.ArrowSupport;
@@ -170,7 +172,7 @@
import com.oracle.graal.python.runtime.exception.PythonThreadKillException;
import com.oracle.graal.python.runtime.locale.PythonLocale;
import com.oracle.graal.python.runtime.object.IDUtils;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.Consumer;
import com.oracle.graal.python.util.PythonSystemThreadTask;
import com.oracle.graal.python.util.PythonUtils;
@@ -525,7 +527,7 @@ public void setNativeWrapper(PThreadState nativeWrapper) {
public PContextVarsContext getContextVarsContext() {
if (contextVarsContext == null) {
- contextVarsContext = PythonObjectFactory.getUncached().createContextVarsContext();
+ contextVarsContext = PFactory.createContextVarsContext(PythonLanguage.get(null));
}
return contextVarsContext;
}
@@ -1672,21 +1674,16 @@ private void patchPackagePaths(TruffleString from, TruffleString to) {
Object[] paths = SequenceStorageNodes.CopyInternalArrayNode.executeUncached(((PList) path).getSequenceStorage());
for (int i = 0; i < paths.length; i++) {
Object pathElement = paths[i];
- TruffleString strPath;
- if (pathElement instanceof PString) {
- strPath = ((PString) pathElement).getValueUncached();
- } else if (isJavaString(pathElement)) {
- strPath = toTruffleStringUncached((String) pathElement);
- } else if (pathElement instanceof TruffleString) {
- strPath = (TruffleString) pathElement;
- } else {
- continue;
- }
- if (strPath.regionEqualsUncached(0, from, 0, from.codePointLengthUncached(TS_ENCODING), TS_ENCODING)) {
- paths[i] = StringReplaceNode.getUncached().execute(strPath, from, to, -1);
+ try {
+ TruffleString strPath = CastToTruffleStringNode.executeUncached(pathElement);
+ if (strPath.regionEqualsUncached(0, from, 0, from.codePointLengthUncached(TS_ENCODING), TS_ENCODING)) {
+ paths[i] = StringReplaceNode.getUncached().execute(strPath, from, to, -1);
+ }
+ } catch (CannotCastException e) {
+ // ignore
}
}
- ((PythonModule) v).setAttribute(SpecialAttributeNames.T___PATH__, factory().createList(paths));
+ ((PythonModule) v).setAttribute(SpecialAttributeNames.T___PATH__, PFactory.createList(PythonLanguage.get(null), paths));
}
// Update module.__file__
@@ -1722,10 +1719,10 @@ private void setupRuntimeInformation(boolean isPatching) {
nativeLZMA = NFILZMASupport.createNative(this, "");
}
- mainModule = factory().createPythonModule(T___MAIN__);
+ mainModule = PFactory.createPythonModule(getLanguage(), T___MAIN__);
mainModule.setAttribute(T___BUILTINS__, getBuiltins());
- mainModule.setAttribute(T___ANNOTATIONS__, factory().createDict());
- SetDictNode.executeUncached(mainModule, factory().createDictFixedStorage(mainModule));
+ mainModule.setAttribute(T___ANNOTATIONS__, PFactory.createDict(getLanguage()));
+ SetDictNode.executeUncached(mainModule, PFactory.createDictFixedStorage(getLanguage(), mainModule));
getSysModules().setItem(T___MAIN__, mainModule);
if (ImageInfo.inImageBuildtimeCode()) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java
index a074375217..9c8802229f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java
@@ -50,6 +50,7 @@
import java.util.List;
import java.util.ListIterator;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes;
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
@@ -65,11 +66,10 @@
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleStackTrace;
@@ -272,16 +272,16 @@ public static PException wrapJavaException(Throwable e, Node node, PBaseExceptio
return PException.fromObject(pythonException, node, e);
}
- @InliningCutoff
- public static PException wrapJavaExceptionIfApplicable(Node location, Throwable e, PythonObjectFactory factory) {
+ public static PException wrapJavaExceptionIfApplicable(Node location, Throwable e) {
if (e instanceof StackOverflowError) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- PythonContext.get(null).ensureGilAfterFailure();
- return ExceptionUtils.wrapJavaException(e, location, factory.createBaseException(RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, new Object[]{}));
+ PythonContext context = PythonContext.get(null);
+ context.ensureGilAfterFailure();
+ return ExceptionUtils.wrapJavaException(e, location, PFactory.createBaseException(context.getLanguage(), RecursionError, ErrorMessages.MAXIMUM_RECURSION_DEPTH_EXCEEDED, new Object[]{}));
}
if (e instanceof OutOfMemoryError) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- return ExceptionUtils.wrapJavaException(e, location, factory.createBaseException(MemoryError));
+ return ExceptionUtils.wrapJavaException(e, location, PFactory.createBaseException(PythonLanguage.get(null), MemoryError));
}
return null;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
index 2e7e18c640..5b16500d7c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.buffer.BufferFlags;
@@ -69,6 +70,7 @@
import com.oracle.graal.python.runtime.formatting.FormattingBuffer.BytesFormattingBuffer;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Formatter;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -115,7 +117,7 @@ int parseNumber(int start, int end) {
@Override
Object parseMappingKey(int start, int end) {
- return core.factory().createBytes(Arrays.copyOfRange(formatBytes, start, end));
+ return PFactory.createBytes(PythonLanguage.get(null), Arrays.copyOfRange(formatBytes, start, end));
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
index a0bdb89c56..359ce10183 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
@@ -15,6 +15,7 @@
import java.math.BigInteger;
import java.math.MathContext;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
@@ -37,6 +38,7 @@
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -180,7 +182,7 @@ protected final Object asNumber(Object arg, char specType) {
if (allowsFloat(specType)) {
// Fast path for simple double values, instead of __int__
BigDecimal decimal = new BigDecimal((Double) arg, MathContext.UNLIMITED);
- return core.factory().createInt(decimal.toBigInteger());
+ return PFactory.createInt(PythonLanguage.get(null), decimal.toBigInteger());
} else {
// non-integer result indicates to the caller that it could not be converted
return arg;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/IDUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/IDUtils.java
index 1d9cd21891..d1cc7c2f89 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/IDUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/IDUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,6 +46,7 @@
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.util.WeakIdentityHashMap;
import com.oracle.truffle.api.CompilerDirectives;
@@ -106,11 +107,11 @@ private static BigInteger asMaskedBigIntId(long id, BigInteger mask) {
return BigInteger.valueOf(id).shiftLeft(2).or(mask);
}
- private static Object asMaskedId(long id, PythonObjectFactory factory, long max, long mask, BigInteger biMask) {
+ private static Object asMaskedId(PythonLanguage language, long id, long max, long mask, BigInteger biMask) {
if (Long.compareUnsigned(id, max) <= 0) {
return (id << 2) | mask;
}
- return factory.createInt(asMaskedBigIntId(id, biMask));
+ return PFactory.createInt(language, asMaskedBigIntId(id, biMask));
}
private static long getId(ReservedID reservedID) {
@@ -125,13 +126,13 @@ public static Object getId(int id) {
return ((long) id << 2) | ID_MASK_LONG;
}
- public static Object getId(long id, PythonObjectFactory factory) {
- return asMaskedId(id, factory, MAX_OBJECT_ID, ID_MASK_LONG, ID_MASK_LONG_BI);
+ public static Object getId(PythonLanguage language, long id) {
+ return asMaskedId(language, id, MAX_OBJECT_ID, ID_MASK_LONG, ID_MASK_LONG_BI);
}
- public static Object getId(double id, PythonObjectFactory factory) {
+ public static Object getId(PythonLanguage language, double id) {
long ieee754 = Double.doubleToLongBits(id);
- return asMaskedId(ieee754, factory, MAX_DOUBLE_ID, ID_MASK_DOUBLE, ID_MASK_DOUBLE_BI);
+ return asMaskedId(language, ieee754, MAX_DOUBLE_ID, ID_MASK_DOUBLE, ID_MASK_DOUBLE_BI);
}
@CompilerDirectives.TruffleBoundary(allowInlining = true)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
new file mode 100644
index 0000000000..2d139cbe55
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
@@ -0,0 +1,1695 @@
+/*
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
+ * Copyright (c) 2013, Regents of the University of California
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.oracle.graal.python.runtime.object;
+
+import java.lang.ref.ReferenceQueue;
+import java.math.BigInteger;
+import java.util.LinkedHashMap;
+import java.util.concurrent.Semaphore;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+
+import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixFileHandle;
+import com.oracle.graal.python.builtins.modules.Profiler;
+import com.oracle.graal.python.builtins.modules.bz2.BZ2Object;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteCodec;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteCodecObject;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteIncrementalDecoderObject;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteIncrementalEncoderObject;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteStreamReaderObject;
+import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteStreamWriterObject;
+import com.oracle.graal.python.builtins.modules.codecs.PEncodingMap;
+import com.oracle.graal.python.builtins.modules.csv.CSVDialect;
+import com.oracle.graal.python.builtins.modules.csv.CSVReader;
+import com.oracle.graal.python.builtins.modules.csv.CSVWriter;
+import com.oracle.graal.python.builtins.modules.csv.QuoteStyle;
+import com.oracle.graal.python.builtins.modules.ctypes.CDataObject;
+import com.oracle.graal.python.builtins.modules.ctypes.CFieldObject;
+import com.oracle.graal.python.builtins.modules.ctypes.CThunkObject;
+import com.oracle.graal.python.builtins.modules.ctypes.PyCArgObject;
+import com.oracle.graal.python.builtins.modules.ctypes.PyCFuncPtrObject;
+import com.oracle.graal.python.builtins.modules.ctypes.StgDictObject;
+import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer;
+import com.oracle.graal.python.builtins.modules.functools.LruCacheObject;
+import com.oracle.graal.python.builtins.modules.functools.PKeyWrapper;
+import com.oracle.graal.python.builtins.modules.functools.PPartial;
+import com.oracle.graal.python.builtins.modules.hashlib.DigestObject;
+import com.oracle.graal.python.builtins.modules.io.PBuffered;
+import com.oracle.graal.python.builtins.modules.io.PBytesIO;
+import com.oracle.graal.python.builtins.modules.io.PBytesIOBuffer;
+import com.oracle.graal.python.builtins.modules.io.PFileIO;
+import com.oracle.graal.python.builtins.modules.io.PNLDecoder;
+import com.oracle.graal.python.builtins.modules.io.PRWPair;
+import com.oracle.graal.python.builtins.modules.io.PStringIO;
+import com.oracle.graal.python.builtins.modules.io.PTextIO;
+import com.oracle.graal.python.builtins.modules.json.PJSONEncoder;
+import com.oracle.graal.python.builtins.modules.json.PJSONEncoder.FastEncode;
+import com.oracle.graal.python.builtins.modules.json.PJSONScanner;
+import com.oracle.graal.python.builtins.modules.lzma.LZMAObject;
+import com.oracle.graal.python.builtins.modules.multiprocessing.PGraalPySemLock;
+import com.oracle.graal.python.builtins.modules.multiprocessing.PSemLock;
+import com.oracle.graal.python.builtins.modules.pickle.PPickleBuffer;
+import com.oracle.graal.python.builtins.modules.pickle.PPickler;
+import com.oracle.graal.python.builtins.modules.pickle.PPicklerMemoProxy;
+import com.oracle.graal.python.builtins.modules.pickle.PUnpickler;
+import com.oracle.graal.python.builtins.modules.pickle.PUnpicklerMemoProxy;
+import com.oracle.graal.python.builtins.modules.zlib.ZLibCompObject;
+import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.array.PArray;
+import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGen;
+import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenASend;
+import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenAThrow;
+import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenWrappedValue;
+import com.oracle.graal.python.builtins.objects.asyncio.PCoroutineWrapper;
+import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
+import com.oracle.graal.python.builtins.objects.bytes.PBytes;
+import com.oracle.graal.python.builtins.objects.capsule.PyCapsule;
+import com.oracle.graal.python.builtins.objects.cell.PCell;
+import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
+import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper;
+import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers;
+import com.oracle.graal.python.builtins.objects.cext.hpy.PythonHPyObject;
+import com.oracle.graal.python.builtins.objects.code.PCode;
+import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
+import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
+import com.oracle.graal.python.builtins.objects.common.EmptyStorage;
+import com.oracle.graal.python.builtins.objects.common.ForeignHashingStorage;
+import com.oracle.graal.python.builtins.objects.common.HashingStorage;
+import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
+import com.oracle.graal.python.builtins.objects.common.KeywordsStorage;
+import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
+import com.oracle.graal.python.builtins.objects.complex.PComplex;
+import com.oracle.graal.python.builtins.objects.contextvars.PContextIterator;
+import com.oracle.graal.python.builtins.objects.contextvars.PContextVar;
+import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext;
+import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsToken;
+import com.oracle.graal.python.builtins.objects.deque.PDeque;
+import com.oracle.graal.python.builtins.objects.deque.PDequeIter;
+import com.oracle.graal.python.builtins.objects.dict.PDefaultDict;
+import com.oracle.graal.python.builtins.objects.dict.PDict;
+import com.oracle.graal.python.builtins.objects.dict.PDictView;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictItemIterator;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictItemsView;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictKeyIterator;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictKeysView;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValueIterator;
+import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValuesView;
+import com.oracle.graal.python.builtins.objects.enumerate.PEnumerate;
+import com.oracle.graal.python.builtins.objects.exception.PBaseException;
+import com.oracle.graal.python.builtins.objects.exception.PBaseExceptionGroup;
+import com.oracle.graal.python.builtins.objects.floats.PFloat;
+import com.oracle.graal.python.builtins.objects.frame.PFrame;
+import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
+import com.oracle.graal.python.builtins.objects.function.PFunction;
+import com.oracle.graal.python.builtins.objects.function.PKeyword;
+import com.oracle.graal.python.builtins.objects.function.Signature;
+import com.oracle.graal.python.builtins.objects.generator.PGenerator;
+import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
+import com.oracle.graal.python.builtins.objects.getsetdescriptor.IndexedSlotDescriptor;
+import com.oracle.graal.python.builtins.objects.ints.PInt;
+import com.oracle.graal.python.builtins.objects.iterator.PArrayIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PBaseSetIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PBigRangeIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PDoubleSequenceIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PIntegerSequenceIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PLongSequenceIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PObjectSequenceIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PSentinelIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PStringIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PStructUnpackIterator;
+import com.oracle.graal.python.builtins.objects.iterator.PZip;
+import com.oracle.graal.python.builtins.objects.itertools.PAccumulate;
+import com.oracle.graal.python.builtins.objects.itertools.PChain;
+import com.oracle.graal.python.builtins.objects.itertools.PCombinations;
+import com.oracle.graal.python.builtins.objects.itertools.PCombinationsWithReplacement;
+import com.oracle.graal.python.builtins.objects.itertools.PCompress;
+import com.oracle.graal.python.builtins.objects.itertools.PCount;
+import com.oracle.graal.python.builtins.objects.itertools.PCycle;
+import com.oracle.graal.python.builtins.objects.itertools.PDropwhile;
+import com.oracle.graal.python.builtins.objects.itertools.PFilterfalse;
+import com.oracle.graal.python.builtins.objects.itertools.PGroupBy;
+import com.oracle.graal.python.builtins.objects.itertools.PGrouper;
+import com.oracle.graal.python.builtins.objects.itertools.PIslice;
+import com.oracle.graal.python.builtins.objects.itertools.PPairwise;
+import com.oracle.graal.python.builtins.objects.itertools.PPermutations;
+import com.oracle.graal.python.builtins.objects.itertools.PProduct;
+import com.oracle.graal.python.builtins.objects.itertools.PRepeat;
+import com.oracle.graal.python.builtins.objects.itertools.PStarmap;
+import com.oracle.graal.python.builtins.objects.itertools.PTakewhile;
+import com.oracle.graal.python.builtins.objects.itertools.PTee;
+import com.oracle.graal.python.builtins.objects.itertools.PTeeDataObject;
+import com.oracle.graal.python.builtins.objects.itertools.PZipLongest;
+import com.oracle.graal.python.builtins.objects.list.PList;
+import com.oracle.graal.python.builtins.objects.map.PMap;
+import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy;
+import com.oracle.graal.python.builtins.objects.memoryview.BufferLifecycleManager;
+import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
+import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
+import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
+import com.oracle.graal.python.builtins.objects.method.PMethod;
+import com.oracle.graal.python.builtins.objects.mmap.PMMap;
+import com.oracle.graal.python.builtins.objects.module.PythonModule;
+import com.oracle.graal.python.builtins.objects.namespace.PSimpleNamespace;
+import com.oracle.graal.python.builtins.objects.object.PythonObject;
+import com.oracle.graal.python.builtins.objects.ordereddict.POrderedDict;
+import com.oracle.graal.python.builtins.objects.ordereddict.POrderedDictIterator;
+import com.oracle.graal.python.builtins.objects.posix.PDirEntry;
+import com.oracle.graal.python.builtins.objects.posix.PScandirIterator;
+import com.oracle.graal.python.builtins.objects.property.PProperty;
+import com.oracle.graal.python.builtins.objects.queue.PSimpleQueue;
+import com.oracle.graal.python.builtins.objects.random.PRandom;
+import com.oracle.graal.python.builtins.objects.range.PBigRange;
+import com.oracle.graal.python.builtins.objects.range.PIntRange;
+import com.oracle.graal.python.builtins.objects.referencetype.PReferenceType;
+import com.oracle.graal.python.builtins.objects.reversed.PSequenceReverseIterator;
+import com.oracle.graal.python.builtins.objects.reversed.PStringReverseIterator;
+import com.oracle.graal.python.builtins.objects.set.PBaseSet;
+import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
+import com.oracle.graal.python.builtins.objects.set.PSet;
+import com.oracle.graal.python.builtins.objects.slice.PIntSlice;
+import com.oracle.graal.python.builtins.objects.slice.PObjectSlice;
+import com.oracle.graal.python.builtins.objects.socket.PSocket;
+import com.oracle.graal.python.builtins.objects.ssl.PMemoryBIO;
+import com.oracle.graal.python.builtins.objects.ssl.PSSLContext;
+import com.oracle.graal.python.builtins.objects.ssl.PSSLSocket;
+import com.oracle.graal.python.builtins.objects.ssl.SSLMethod;
+import com.oracle.graal.python.builtins.objects.str.NativeCharSequence;
+import com.oracle.graal.python.builtins.objects.str.PString;
+import com.oracle.graal.python.builtins.objects.struct.PStruct;
+import com.oracle.graal.python.builtins.objects.superobject.SuperObject;
+import com.oracle.graal.python.builtins.objects.thread.PLock;
+import com.oracle.graal.python.builtins.objects.thread.PRLock;
+import com.oracle.graal.python.builtins.objects.thread.PThread;
+import com.oracle.graal.python.builtins.objects.thread.PThreadLocal;
+import com.oracle.graal.python.builtins.objects.tokenize.PTokenizerIter;
+import com.oracle.graal.python.builtins.objects.traceback.LazyTraceback;
+import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
+import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.builtins.objects.tuple.PTupleGetter;
+import com.oracle.graal.python.builtins.objects.tuple.StructSequence.BuiltinTypeDescriptor;
+import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
+import com.oracle.graal.python.builtins.objects.type.PythonClass;
+import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.types.PGenericAlias;
+import com.oracle.graal.python.builtins.objects.types.PGenericAliasIterator;
+import com.oracle.graal.python.builtins.objects.types.PUnionType;
+import com.oracle.graal.python.compiler.CodeUnit;
+import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
+import com.oracle.graal.python.runtime.NFIZlibSupport;
+import com.oracle.graal.python.runtime.PythonContext;
+import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
+import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
+import com.oracle.graal.python.util.BufferFormat;
+import com.oracle.graal.python.util.OverflowException;
+import com.oracle.graal.python.util.PythonUtils;
+import com.oracle.graal.python.util.Supplier;
+import com.oracle.truffle.api.Assumption;
+import com.oracle.truffle.api.CallTarget;
+import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.RootCallTarget;
+import com.oracle.truffle.api.frame.MaterializedFrame;
+import com.oracle.truffle.api.instrumentation.AllocationReporter;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.object.Shape;
+import com.oracle.truffle.api.strings.TruffleString;
+import com.oracle.truffle.tools.profiler.CPUSampler;
+
+public final class PFactory {
+ private PFactory() {
+ }
+
+ private static T create(PythonLanguage language, Supplier constructor) {
+ AllocationReporter reporter = language.getAllocationReporter();
+ if (reporter.isActive()) {
+ return createWithTrace(constructor, reporter);
+ } else {
+ return constructor.get();
+ }
+ }
+
+ @InliningCutoff
+ private static T createWithTrace(Supplier constructor, AllocationReporter reporter) {
+ reporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
+ T allocatedObject = constructor.get();
+ reporter.onReturnValue(allocatedObject, 0, AllocationReporter.SIZE_UNKNOWN);
+ return allocatedObject;
+ }
+
+ /*
+ * Python objects
+ */
+ public static PythonObject createPythonObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> (new PythonObject(cls, shape)));
+ }
+
+ /**
+ * Creates a PythonObject for the given class. This is potentially slightly slower than if the
+ * shape had been cached, due to the additional shape lookup.
+ */
+ public static PythonObject createPythonHPyObject(PythonLanguage language, Object cls, Shape shape, Object hpyNativeSpace) {
+ return create(language, () -> new PythonHPyObject(cls, shape, hpyNativeSpace));
+ }
+
+ public static PythonNativeVoidPtr createNativeVoidPtr(PythonLanguage language, Object obj) {
+ return create(language, () -> new PythonNativeVoidPtr(obj));
+ }
+
+ public static PythonNativeVoidPtr createNativeVoidPtr(PythonLanguage language, Object obj, long nativePtr) {
+ return create(language, () -> new PythonNativeVoidPtr(obj, nativePtr));
+ }
+
+ public static SuperObject createSuperObject(PythonLanguage language) {
+ return createSuperObject(language, PythonBuiltinClassType.Super, PythonBuiltinClassType.Super.getInstanceShape(language));
+ }
+
+ public static SuperObject createSuperObject(PythonLanguage language, Object self, Shape shape) {
+ return create(language, () -> new SuperObject(self, shape));
+ }
+
+ public static PInt createInt(PythonLanguage language, long value) {
+ return createInt(language, PythonBuiltinClassType.PInt, language.getBuiltinTypeInstanceShape(PythonBuiltinClassType.PInt), asBigInt(value));
+ }
+
+ @TruffleBoundary
+ private static BigInteger asBigInt(long value) {
+ return BigInteger.valueOf(value);
+ }
+
+ public static PInt createInt(PythonLanguage language, BigInteger value) {
+ return createInt(language, PythonBuiltinClassType.PInt, language.getBuiltinTypeInstanceShape(PythonBuiltinClassType.PInt), value);
+ }
+
+ public static PInt createInt(PythonLanguage language, Object cls, Shape shape, long value) {
+ return createInt(language, cls, shape, asBigInt(value));
+ }
+
+ public static PInt createInt(PythonLanguage language, Object cls, Shape shape, BigInteger value) {
+ return create(language, () -> new PInt(cls, shape, value));
+ }
+
+ public static PFloat createFloat(PythonLanguage language, double value) {
+ return createFloat(language, PythonBuiltinClassType.PFloat, language.getBuiltinTypeInstanceShape(PythonBuiltinClassType.PFloat), value);
+ }
+
+ public static PFloat createFloat(PythonLanguage language, Object cls, Shape shape, double value) {
+ return create(language, () -> new PFloat(cls, shape, value));
+ }
+
+ public static PString createString(PythonLanguage language, TruffleString string) {
+ return createString(language, PythonBuiltinClassType.PString, language.getBuiltinTypeInstanceShape(PythonBuiltinClassType.PString), string);
+ }
+
+ public static PString createString(PythonLanguage language, Object cls, Shape shape, TruffleString string) {
+ return create(language, () -> new PString(cls, shape, string));
+ }
+
+ public static PString createString(PythonLanguage language, NativeCharSequence string) {
+ return createString(language, PythonBuiltinClassType.PString, language.getBuiltinTypeInstanceShape(PythonBuiltinClassType.PString), string);
+ }
+
+ public static PString createString(PythonLanguage language, Object cls, Shape shape, NativeCharSequence string) {
+ return create(language, () -> new PString(cls, shape, string));
+ }
+
+ public static PBytes createEmptyBytes(PythonLanguage language) {
+ if (CompilerDirectives.inInterpreter()) {
+ return createBytes(language, PythonUtils.EMPTY_BYTE_ARRAY);
+ } else {
+ return createBytes(language, new byte[0]);
+ }
+ }
+
+ public static PBytes createBytes(PythonLanguage language, byte[] array) {
+ return createBytes(language, array, array.length);
+ }
+
+ public static PBytes createBytes(PythonLanguage language, byte[] array, int length) {
+ return createBytes(language, new ByteSequenceStorage(array, length));
+ }
+
+ public static PBytes createBytes(PythonLanguage language, SequenceStorage storage) {
+ return createBytes(language, PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PBytes.getInstanceShape(language), storage);
+ }
+
+ public static PBytes createBytes(PythonLanguage language, Object cls, Shape shape, byte[] bytes) {
+ return createBytes(language, cls, shape, new ByteSequenceStorage(bytes));
+ }
+
+ public static PBytes createBytes(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage) {
+ return create(language, () -> new PBytes(cls, shape, storage));
+ }
+
+ public static PTuple createEmptyTuple(PythonLanguage language) {
+ return createTuple(language, EmptySequenceStorage.INSTANCE);
+ }
+
+ public static PTuple createEmptyTuple(PythonLanguage language, Object cls, Shape shape) {
+ return createTuple(language, cls, shape, EmptySequenceStorage.INSTANCE);
+ }
+
+ public static PTuple createTuple(PythonLanguage language, Object[] objects) {
+ return createTuple(language, new ObjectSequenceStorage(objects));
+ }
+
+ public static PTuple createTuple(PythonLanguage language, int[] ints) {
+ return createTuple(language, new IntSequenceStorage(ints));
+ }
+
+ public static PTuple createTuple(PythonLanguage language, SequenceStorage store) {
+ return createTuple(language, PythonBuiltinClassType.PTuple, PythonBuiltinClassType.PTuple.getInstanceShape(language), store);
+ }
+
+ public static PTuple createTuple(PythonLanguage language, Object cls, Shape shape, SequenceStorage store) {
+ return create(language, () -> new PTuple(cls, shape, store));
+ }
+
+ public static PTuple createStructSeq(PythonLanguage language, BuiltinTypeDescriptor desc, Object... values) {
+ assert desc.inSequence <= values.length && values.length <= desc.fieldNames.length;
+ return createTuple(language, desc.type, desc.type.getInstanceShape(language), new ObjectSequenceStorage(values, desc.inSequence));
+ }
+
+ public static PTupleGetter createTupleGetter(PythonLanguage language, int index, Object doc) {
+ return createTupleGetter(language, PythonBuiltinClassType.PTupleGetter, PythonBuiltinClassType.PTupleGetter.getInstanceShape(language), index, doc);
+ }
+
+ public static PTupleGetter createTupleGetter(PythonLanguage language, Object cls, Shape shape, int index, Object doc) {
+ return create(language, () -> new PTupleGetter(cls, shape, index, doc));
+ }
+
+ public static PComplex createComplex(PythonLanguage language, Object cls, Shape shape, double real, double imag) {
+ return create(language, () -> new PComplex(cls, shape, real, imag));
+ }
+
+ public static PComplex createComplex(PythonLanguage language, double real, double imag) {
+ return createComplex(language, PythonBuiltinClassType.PComplex, PythonBuiltinClassType.PComplex.getInstanceShape(language), real, imag);
+ }
+
+ public static PIntRange createIntRange(PythonLanguage language, int stop) {
+ return create(language, () -> new PIntRange(language, 0, stop, 1, stop));
+ }
+
+ public static PIntRange createIntRange(PythonLanguage language, int start, int stop, int step, int len) {
+ return create(language, () -> new PIntRange(language, start, stop, step, len));
+ }
+
+ public static PBigRange createBigRange(PythonLanguage language, PInt start, PInt stop, PInt step, PInt len) {
+ return create(language, () -> new PBigRange(language, start, stop, step, len));
+ }
+
+ public static PIntSlice createIntSlice(PythonLanguage language, int start, int stop, int step) {
+ return create(language, () -> new PIntSlice(language, start, stop, step));
+ }
+
+ public static PIntSlice createIntSlice(PythonLanguage language, int start, int stop, int step, boolean isStartNone, boolean isStepNone) {
+ return create(language, () -> new PIntSlice(language, start, stop, step, isStartNone, isStepNone));
+ }
+
+ public static PObjectSlice createObjectSlice(PythonLanguage language, Object start, Object stop, Object step) {
+ return create(language, () -> new PObjectSlice(language, start, stop, step));
+ }
+
+ public static PRandom createRandom(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PRandom(cls, shape));
+ }
+
+ /*
+ * Classes, methods and functions
+ */
+
+ /**
+ * Only to be used during context creation
+ */
+ public static PythonModule createPythonModule(PythonLanguage language, TruffleString name) {
+ return create(language, () -> PythonModule.createInternal(name));
+ }
+
+ public static PythonModule createPythonModule(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PythonModule(cls, shape));
+ }
+
+ public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language, TruffleString name, Object base, PythonAbstractClass[] bases) {
+ return createPythonClassAndFixupSlots(language, PythonBuiltinClassType.PythonClass, PythonBuiltinClassType.PythonClass.getInstanceShape(language), name, base, bases);
+ }
+
+ public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language, Object metaclass, Shape metaclassShape, TruffleString name, Object base, PythonAbstractClass[] bases) {
+ PythonClass result = create(language, () -> new PythonClass(language, metaclass, metaclassShape, name, base, bases));
+ // Fixup tp slots
+ MroSequenceStorage mro = GetMroStorageNode.executeUncached(result);
+ SpecialMethodSlot.initializeSpecialMethodSlots(result, mro, language);
+ TpSlots.inherit(result, mro, true);
+ TpSlots.fixupSlotDispatchers(result);
+ result.initializeMroShape(language);
+ return result;
+ }
+
+ public static PythonClass createPythonClass(PythonLanguage language, Object metaclass, Shape metaclassShape, TruffleString name, boolean invokeMro, Object base, PythonAbstractClass[] bases) {
+ // Note: called from type ctor, which itself will invoke setupSpecialMethodSlots at the
+ // right point
+ return create(language, () -> new PythonClass(language, metaclass, metaclassShape, name, invokeMro, base, bases));
+ }
+
+ public static PMemoryView createMemoryView(PythonLanguage language, PythonContext context, BufferLifecycleManager bufferLifecycleManager, Object buffer, Object owner,
+ int len, boolean readonly, int itemsize, BufferFormat format, TruffleString formatString, int ndim, Object bufPointer,
+ int offset, int[] shape, int[] strides, int[] suboffsets, int flags) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
+ return create(language, () -> new PMemoryView(cls, cls.getInstanceShape(language), context, bufferLifecycleManager, buffer, owner, len, readonly, itemsize, format, formatString,
+ ndim, bufPointer, offset, shape, strides, suboffsets, flags));
+ }
+
+ public static PMemoryView createMemoryViewForManagedObject(PythonLanguage language, Object buffer, Object owner, int itemsize, int length, boolean readonly, TruffleString format,
+ TruffleString.CodePointLengthNode lengthNode, TruffleString.CodePointAtIndexNode atIndexNode) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
+ return create(language, () -> new PMemoryView(cls, cls.getInstanceShape(language), null, null, buffer, owner, length, readonly, itemsize,
+ BufferFormat.forMemoryView(format, lengthNode, atIndexNode), format, 1, null, 0, new int[]{length / itemsize}, new int[]{itemsize}, null,
+ PMemoryView.FLAG_C | PMemoryView.FLAG_FORTRAN));
+ }
+
+ public static PMethod createMethod(PythonLanguage language, Object cls, Shape shape, Object self, Object function) {
+ return create(language, () -> new PMethod(cls, shape, self, function));
+ }
+
+ public static PMethod createMethod(PythonLanguage language, Object self, Object function) {
+ return createMethod(language, PythonBuiltinClassType.PMethod, PythonBuiltinClassType.PMethod.getInstanceShape(language), self, function);
+ }
+
+ public static PMethod createBuiltinMethod(PythonLanguage language, Object self, PFunction function) {
+ return createMethod(language, PythonBuiltinClassType.PBuiltinFunctionOrMethod, PythonBuiltinClassType.PBuiltinFunctionOrMethod.getInstanceShape(language), self, function);
+ }
+
+ public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object cls, Shape shape, Object self, PBuiltinFunction function) {
+ return create(language, () -> new PBuiltinMethod(cls, shape, self, function, null));
+ }
+
+ public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object self, PBuiltinFunction function, Object classObject) {
+ return create(language, () -> new PBuiltinMethod(PythonBuiltinClassType.PBuiltinMethod, PythonBuiltinClassType.PBuiltinMethod.getInstanceShape(language), self, function, classObject));
+ }
+
+ public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object self, PBuiltinFunction function) {
+ return createBuiltinMethod(language, PythonBuiltinClassType.PBuiltinFunctionOrMethod, PythonBuiltinClassType.PBuiltinFunctionOrMethod.getInstanceShape(language), self, function);
+ }
+
+ public static PFunction createFunction(PythonLanguage language, TruffleString name, PCode code, PythonObject globals, PCell[] closure) {
+ return create(language, () -> new PFunction(language, name, name, code, globals, closure));
+ }
+
+ public static PFunction createFunction(PythonLanguage language, TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
+ PCell[] closure) {
+ return create(language, () -> new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure));
+ }
+
+ public static PFunction createFunction(PythonLanguage language, TruffleString name, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
+ return create(language, () -> new PFunction(language, name, name, code, globals, defaultValues, kwDefaultValues, closure));
+ }
+
+ public static PFunction createFunction(PythonLanguage language, TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
+ PCell[] closure,
+ Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
+ return create(language, () -> new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure,
+ codeStableAssumption, defaultsStableAssumption));
+ }
+
+ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget) {
+ return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type,
+ PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget));
+ }
+
+ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget) {
+ return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type, defaults, kw, flags,
+ callTarget));
+ }
+
+ public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language, TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget, TpSlot slot,
+ PExternalFunctionWrapper slotWrapper) {
+ return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type,
+ PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget, slot, slotWrapper));
+ }
+
+ public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language, TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget,
+ TpSlot slot, PExternalFunctionWrapper slotWrapper) {
+ return create(language,
+ () -> new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type, defaults, kw, flags,
+ callTarget, slot, slotWrapper));
+ }
+
+ public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, PBuiltinFunction function, Object klass) {
+ PythonBuiltinClassType type = (PythonBuiltinClassType) function.getInitialPythonClass();
+ return create(language, () -> new PBuiltinFunction(type, type.getInstanceShape(language), function.getName(), klass,
+ function.getDefaults(), function.getKwDefaults(), function.getFlags(), function.getCallTarget(),
+ function.getSlot(), function.getSlotWrapper()));
+ }
+
+ public static GetSetDescriptor createGetSetDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type) {
+ return create(language, () -> new GetSetDescriptor(language, get, set, name, type));
+ }
+
+ public static GetSetDescriptor createGetSetDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type, boolean allowsDelete) {
+ return create(language, () -> new GetSetDescriptor(language, get, set, name, type, allowsDelete));
+ }
+
+ public static GetSetDescriptor createMemberDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type) {
+ return create(language,
+ () -> new GetSetDescriptor(PythonBuiltinClassType.MemberDescriptor, PythonBuiltinClassType.MemberDescriptor.getInstanceShape(language), get, set, name, type, set != null));
+ }
+
+ public static IndexedSlotDescriptor createIndexedSlotDescriptor(PythonLanguage language, TruffleString name, int index, Object type) {
+ return create(language, () -> new IndexedSlotDescriptor(language, name, index, type));
+ }
+
+ public static PDecoratedMethod createClassmethod(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PDecoratedMethod(cls, shape));
+ }
+
+ public static PDecoratedMethod createClassmethodFromCallableObj(PythonLanguage language, Object callable) {
+ return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PClassmethod, PythonBuiltinClassType.PClassmethod.getInstanceShape(language), callable));
+ }
+
+ public static PDecoratedMethod createBuiltinClassmethodFromCallableObj(PythonLanguage language, Object callable) {
+ return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PBuiltinClassMethod, PythonBuiltinClassType.PBuiltinClassMethod.getInstanceShape(language), callable));
+ }
+
+ public static PDecoratedMethod createInstancemethod(PythonLanguage language) {
+ return createInstancemethod(language, PythonBuiltinClassType.PInstancemethod, PythonBuiltinClassType.PInstancemethod.getInstanceShape(language));
+ }
+
+ public static PDecoratedMethod createInstancemethod(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PDecoratedMethod(cls, shape));
+ }
+
+ public static PDecoratedMethod createStaticmethod(PythonLanguage language) {
+ return createStaticmethod(language, PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PStaticmethod.getInstanceShape(language));
+ }
+
+ public static PDecoratedMethod createStaticmethod(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PDecoratedMethod(cls, shape));
+ }
+
+ public static PDecoratedMethod createStaticmethodFromCallableObj(PythonLanguage language, Object callable) {
+ Object func;
+ if (callable instanceof PBuiltinFunction builtinFunction) {
+ /*
+ * CPython's C static methods contain an object of type `builtin_function_or_method`
+ * (our PBuiltinMethod). Their self points to their type, but when called they get NULL
+ * as the first argument instead.
+ */
+ func = createBuiltinMethod(language, builtinFunction.getEnclosingType(), builtinFunction);
+ } else {
+ func = callable;
+ }
+ return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PStaticmethod.getInstanceShape(language), func));
+ }
+
+ /*
+ * Lists, sets and dicts
+ */
+
+ public static PList createList(PythonLanguage language) {
+ return createList(language, EmptySequenceStorage.INSTANCE);
+ }
+
+ public static PList createList(PythonLanguage language, Object[] array) {
+ return createList(language, new ObjectSequenceStorage(array));
+ }
+
+ public static PList createList(PythonLanguage language, SequenceStorage storage) {
+ return createList(language, storage, (PList.ListOrigin) null);
+ }
+
+ public static PList createList(PythonLanguage language, SequenceStorage storage, PList.ListOrigin origin) {
+ return createList(language, PythonBuiltinClassType.PList, PythonBuiltinClassType.PList.getInstanceShape(language), storage, origin);
+ }
+
+ public static PList createList(PythonLanguage language, Object cls, Shape shape) {
+ return createList(language, cls, shape, EmptySequenceStorage.INSTANCE);
+ }
+
+ public static PList createList(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage) {
+ return createList(language, cls, shape, storage, null);
+ }
+
+ public static PList createList(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage, PList.ListOrigin origin) {
+ return create(language, () -> new PList(cls, shape, storage, origin));
+ }
+
+ public static PSet createSet(PythonLanguage language) {
+ return createSet(language, EmptyStorage.INSTANCE);
+ }
+
+ public static PSet createSet(PythonLanguage language, HashingStorage storage) {
+ return createSet(language, PythonBuiltinClassType.PSet, PythonBuiltinClassType.PSet.getInstanceShape(language), storage);
+ }
+
+ public static PSet createSet(PythonLanguage language, Object cls, Shape shape) {
+ return createSet(language, cls, shape, EmptyStorage.INSTANCE);
+ }
+
+ public static PSet createSet(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
+ return create(language, () -> new PSet(cls, shape, storage));
+ }
+
+ public static PFrozenSet createFrozenSet(PythonLanguage language) {
+ return createFrozenSet(language, EmptyStorage.INSTANCE);
+ }
+
+ public static PFrozenSet createFrozenSet(PythonLanguage language, HashingStorage storage) {
+ return createFrozenSet(language, PythonBuiltinClassType.PFrozenSet, PythonBuiltinClassType.PFrozenSet.getInstanceShape(language), storage);
+ }
+
+ public static PFrozenSet createFrozenSet(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
+ return create(language, () -> new PFrozenSet(cls, shape, storage));
+ }
+
+ public static PDict createDict(PythonLanguage language) {
+ return createDict(language, EmptyStorage.INSTANCE);
+ }
+
+ public static PDict createDict(PythonLanguage language, PKeyword[] keywords) {
+ return createDict(language, new KeywordsStorage(keywords));
+ }
+
+ public static PDict createDict(PythonLanguage language, HashingStorage storage) {
+ return createDict(language, PythonBuiltinClassType.PDict, PythonBuiltinClassType.PDict.getInstanceShape(language), storage);
+ }
+
+ public static PDict createDict(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
+ return create(language, () -> new PDict(cls, shape, storage));
+ }
+
+ public static POrderedDict createOrderedDict(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new POrderedDict(cls, shape));
+ }
+
+ public static PDictKeysView createOrderedDictKeys(PythonLanguage language, POrderedDict dict) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictKeys;
+ return create(language, () -> new PDictKeysView(cls, cls.getInstanceShape(language), dict));
+ }
+
+ public static PDictValuesView createOrderedDictValues(PythonLanguage language, POrderedDict dict) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictValues;
+ return create(language, () -> new PDictValuesView(cls, cls.getInstanceShape(language), dict));
+ }
+
+ public static PDictItemsView createOrderedDictItems(PythonLanguage language, POrderedDict dict) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictItems;
+ return create(language, () -> new PDictItemsView(cls, cls.getInstanceShape(language), dict));
+ }
+
+ public static POrderedDictIterator createOrderedDictIterator(PythonLanguage language, POrderedDict dict, POrderedDictIterator.IteratorType type, boolean reversed) {
+ PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictIterator;
+ return create(language, () -> new POrderedDictIterator(cls, cls.getInstanceShape(language), dict, type, reversed));
+ }
+
+ public static PDict createDictFromMap(PythonLanguage language, LinkedHashMap map) {
+ return createDict(language, EconomicMapStorage.create(map));
+ }
+
+ /**
+ * Generic version of {@link #createDictFromMap(PythonLanguage, LinkedHashMap)} that allows any
+ * type of keys. Note that this means that unless the keys are known to be side effect free,
+ * e.g., builtin types, this may end up calling Python code, so indirect call context should be
+ * properly set-up. This helper is meant for Truffle boundary code, in PE code build a storage
+ * by setting elements one by one starting from empty storage.
+ */
+ public static PDict createDictFromMapGeneric(PythonLanguage language, LinkedHashMap map) {
+ return createDict(language, EconomicMapStorage.createGeneric(map));
+ }
+
+ public static PDict createDictFixedStorage(PythonLanguage language, PythonObject pythonObject, MroSequenceStorage mroSequenceStorage) {
+ return createDict(language, new DynamicObjectStorage(pythonObject, mroSequenceStorage));
+ }
+
+ public static PDict createDictFixedStorage(PythonLanguage language, PythonObject pythonObject) {
+ return createDict(language, new DynamicObjectStorage(pythonObject));
+ }
+
+ public static PSimpleNamespace createSimpleNamespace(PythonLanguage language) {
+ return createSimpleNamespace(language, PythonBuiltinClassType.PSimpleNamespace, PythonBuiltinClassType.PSimpleNamespace.getInstanceShape(language));
+ }
+
+ public static PSimpleNamespace createSimpleNamespace(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PSimpleNamespace(cls, shape));
+ }
+
+ public static PKeyWrapper createKeyWrapper(PythonLanguage language, Object cmp) {
+ return create(language, () -> new PKeyWrapper(PythonBuiltinClassType.PKeyWrapper, PythonBuiltinClassType.PKeyWrapper.getInstanceShape(language), cmp));
+ }
+
+ public static PPartial createPartial(PythonLanguage language, Object cls, Shape shape, Object function, Object[] args, PDict kwDict) {
+ return create(language, () -> new PPartial(cls, shape, function, args, kwDict));
+ }
+
+ public static LruCacheObject createLruCacheObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new LruCacheObject(cls, shape));
+ }
+
+ public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape) {
+ return createDefaultDict(language, cls, shape, PNone.NONE);
+ }
+
+ public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape, Object defaultFactory) {
+ return create(language, () -> new PDefaultDict(cls, shape, defaultFactory));
+ }
+
+ public static PDefaultDict createDefaultDict(PythonLanguage language, Object defaultFactory, HashingStorage storage) {
+ return createDefaultDict(language, PythonBuiltinClassType.PDefaultDict, PythonBuiltinClassType.PDefaultDict.getInstanceShape(language), defaultFactory, storage);
+ }
+
+ public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape, Object defaultFactory, HashingStorage storage) {
+ return create(language, () -> new PDefaultDict(cls, shape, storage, defaultFactory));
+ }
+
+ public static PDictView createDictKeysView(PythonLanguage language, PHashingCollection dict) {
+ return create(language, () -> new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict));
+ }
+
+ public static PDictView createDictKeysView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
+ return create(language, () -> new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict, foreignHashingStorage));
+ }
+
+ public static PDictView createDictValuesView(PythonLanguage language, PHashingCollection dict) {
+ return create(language, () -> new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict));
+ }
+
+ public static PDictView createDictValuesView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
+ return create(language, () -> new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict, foreignHashingStorage));
+ }
+
+ public static PDictView createDictItemsView(PythonLanguage language, PHashingCollection dict) {
+ return create(language, () -> new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict));
+ }
+
+ public static PDictView createDictItemsView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
+ return create(language, () -> new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict, foreignHashingStorage));
+ }
+
+ /*
+ * Special objects: generators, proxies, references, cells
+ */
+
+ public static PGenerator createGenerator(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
+ return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator));
+ }
+
+ public static PGenerator createIterableCoroutine(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets,
+ Object[] arguments) {
+ return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator, true));
+ }
+
+ public static PGenerator createCoroutine(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
+ return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PCoroutine));
+ }
+
+ public static PCoroutineWrapper createCoroutineWrapper(PythonLanguage language, PGenerator generator) {
+ return create(language, () -> new PCoroutineWrapper(language, generator));
+ }
+
+ public static PAsyncGen createAsyncGenerator(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
+ return create(language, () -> PAsyncGen.create(language, name, qualname, rootNode, callTargets, arguments));
+ }
+
+ public static PMappingproxy createMappingproxy(PythonLanguage language, Object object) {
+ return createMappingproxy(language, PythonBuiltinClassType.PMappingproxy, PythonBuiltinClassType.PMappingproxy.getInstanceShape(language), object);
+ }
+
+ public static PMappingproxy createMappingproxy(PythonLanguage language, Object cls, Shape shape, Object object) {
+ return create(language, () -> new PMappingproxy(cls, shape, object));
+ }
+
+ public static PReferenceType createReferenceType(PythonLanguage language, Object cls, Shape shape, Object object, Object callback, ReferenceQueue queue) {
+ return create(language, () -> new PReferenceType(cls, shape, object, callback, queue));
+ }
+
+ public static PCell createCell(PythonLanguage language, Assumption effectivelyFinal) {
+ return create(language, () -> new PCell(effectivelyFinal));
+ }
+
+ /*
+ * Frames, traces and exceptions
+ */
+
+ public static PFrame createPFrame(PythonLanguage language, PFrame.Reference frameInfo, Node location, MaterializedFrame locals) {
+ return create(language, () -> new PFrame(language, frameInfo, location, locals));
+ }
+
+ public static PFrame createPFrame(PythonLanguage language, Object threadState, PCode code, PythonObject globals, Object localsDict) {
+ return create(language, () -> new PFrame(language, threadState, code, globals, localsDict));
+ }
+
+ public static PTraceback createTraceback(PythonLanguage language, PFrame frame, int lineno, PTraceback next) {
+ return create(language, () -> new PTraceback(language, frame, lineno, -1, next));
+ }
+
+ public static PTraceback createTracebackWithLasti(PythonLanguage language, PFrame frame, int lineno, int lasti, PTraceback next) {
+ return create(language, () -> new PTraceback(language, frame, lineno, lasti, next));
+ }
+
+ public static PTraceback createTraceback(PythonLanguage language, LazyTraceback tb) {
+ return create(language, () -> new PTraceback(language, tb));
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, PTuple args) {
+ return createBaseException(language, cls, shape, null, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType cls, PTuple args) {
+ return createBaseException(language, cls, cls.getInstanceShape(language), null, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, Object[] data, PTuple args) {
+ return createBaseException(language, type, type.getInstanceShape(language), data, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data, PTuple args) {
+ return create(language, () -> new PBaseException(cls, shape, data, args));
+ }
+
+ /*
+ * Note: we use this method to convert a Java StackOverflowError into a Python RecursionError.
+ * At the time when this is done, some Java stack frames were already unwinded but there is no
+ * guarantee on how many. Therefore, it is important that this method is simple. In particular,
+ * do not add calls if that can be avoided.
+ */
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, TruffleString format, Object[] args) {
+ return createBaseException(language, cls, shape, null, format, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, TruffleString format, Object[] args) {
+ return createBaseException(language, type, type.getInstanceShape(language), null, format, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, Object[] data, TruffleString format, Object[] args) {
+ return createBaseException(language, type, type.getInstanceShape(language), data, format, args);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data, TruffleString format, Object[] args) {
+ assert format != null;
+ return create(language, () -> new PBaseException(cls, shape, data, format, args));
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PBaseException(cls, shape, null));
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type) {
+ return create(language, () -> new PBaseException(type, type.getInstanceShape(language), null));
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, Object[] data) {
+ return createBaseException(language, type, type.getInstanceShape(language), data);
+ }
+
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data) {
+ return create(language, () -> new PBaseException(cls, shape, data));
+ }
+
+ public static PBaseExceptionGroup createBaseExceptionGroup(PythonLanguage language, Object cls, Shape shape, TruffleString message, Object[] exceptions, Object[] args) {
+ return create(language, () -> new PBaseExceptionGroup(cls, shape, message, exceptions, createTuple(language, args)));
+ }
+
+ /*
+ * Arrays
+ */
+
+ public static PArray createArray(PythonLanguage language, Object cls, Shape shape, TruffleString formatString, BufferFormat format) {
+ assert format != null;
+ return create(language, () -> new PArray(cls, shape, formatString, format));
+ }
+
+ public static PArray createArray(PythonLanguage language, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
+ return createArray(language, PythonBuiltinClassType.PArray, PythonBuiltinClassType.PArray.getInstanceShape(language), formatString, format, length);
+ }
+
+ public static PArray createArray(PythonLanguage language, Object cls, Shape shape, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
+ assert format != null;
+ int byteSize = PythonUtils.multiplyExact(length, format.bytesize);
+ return create(language, () -> new PArray(cls, shape, formatString, format, byteSize));
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, byte[] array) {
+ return createByteArray(language, array, array.length);
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, Object cls, Shape shape, byte[] array) {
+ return createByteArray(language, cls, shape, array, array.length);
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, byte[] array, int length) {
+ return createByteArray(language, new ByteSequenceStorage(array, length));
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, Object cls, Shape shape, byte[] array, int length) {
+ return createByteArray(language, cls, shape, new ByteSequenceStorage(array, length));
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, SequenceStorage storage) {
+ return createByteArray(language, PythonBuiltinClassType.PByteArray, PythonBuiltinClassType.PByteArray.getInstanceShape(language), storage);
+ }
+
+ public static PByteArray createByteArray(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage) {
+ return create(language, () -> new PByteArray(cls, shape, storage));
+ }
+
+ /*
+ * Iterators
+ */
+
+ public static PStringIterator createStringIterator(PythonLanguage language, TruffleString str) {
+ return create(language, () -> new PStringIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), str));
+ }
+
+ public static PStringReverseIterator createStringReverseIterator(PythonLanguage language, Object cls, Shape shape, TruffleString str) {
+ return create(language, () -> new PStringReverseIterator(cls, shape, str));
+ }
+
+ public static PIntegerSequenceIterator createIntegerSequenceIterator(PythonLanguage language, IntSequenceStorage storage, Object list) {
+ return create(language, () -> new PIntegerSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ }
+
+ public static PLongSequenceIterator createLongSequenceIterator(PythonLanguage language, LongSequenceStorage storage, Object list) {
+ return create(language, () -> new PLongSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ }
+
+ public static PDoubleSequenceIterator createDoubleSequenceIterator(PythonLanguage language, DoubleSequenceStorage storage, Object list) {
+ return create(language, () -> new PDoubleSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ }
+
+ public static PObjectSequenceIterator createObjectSequenceIterator(PythonLanguage language, ObjectSequenceStorage storage, Object list) {
+ return create(language, () -> new PObjectSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ }
+
+ public static PSequenceIterator createSequenceIterator(PythonLanguage language, Object sequence) {
+ return create(language, () -> new PSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), sequence));
+ }
+
+ public static PSequenceReverseIterator createSequenceReverseIterator(PythonLanguage language, Object sequence, int lengthHint) {
+ return createSequenceReverseIterator(language, PythonBuiltinClassType.PReverseIterator, PythonBuiltinClassType.PReverseIterator.getInstanceShape(language), sequence, lengthHint);
+ }
+
+ public static PSequenceReverseIterator createSequenceReverseIterator(PythonLanguage language, Object cls, Shape shape, Object sequence, int lengthHint) {
+ return create(language, () -> new PSequenceReverseIterator(cls, shape, sequence, lengthHint));
+ }
+
+ public static PIntRangeIterator createIntRangeIterator(PythonLanguage language, PIntRange fastRange) {
+ return createIntRangeIterator(language, fastRange.getIntStart(), fastRange.getIntStop(), fastRange.getIntStep(), fastRange.getIntLength());
+ }
+
+ public static PIntRangeIterator createIntRangeIterator(PythonLanguage language, int start, int stop, int step, int len) {
+ return create(language, () -> new PIntRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
+ }
+
+ public static PBigRangeIterator createBigRangeIterator(PythonLanguage language, PInt start, PInt stop, PInt step, PInt len) {
+ return create(language, () -> new PBigRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
+ }
+
+ public static PBigRangeIterator createBigRangeIterator(PythonLanguage language, PBigRange longRange) {
+ return createBigRangeIterator(language, longRange.getPIntStart(), longRange.getPIntStop(), longRange.getPIntStep(), longRange.getPIntLength());
+ }
+
+ public static PBigRangeIterator createBigRangeIterator(PythonLanguage language, BigInteger start, BigInteger stop, BigInteger step, BigInteger len) {
+ return createBigRangeIterator(language, createInt(language, start), createInt(language, stop), createInt(language, step), createInt(language, len));
+ }
+
+ public static PArrayIterator createArrayIterator(PythonLanguage language, PArray array) {
+ return create(language, () -> new PArrayIterator(PythonBuiltinClassType.PArrayIterator, PythonBuiltinClassType.PArrayIterator.getInstanceShape(language), array));
+ }
+
+ public static PBaseSetIterator createBaseSetIterator(PythonLanguage language, PBaseSet set, HashingStorageNodes.HashingStorageIterator iterator, int initialSize) {
+ return create(language, () -> new PBaseSetIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), set, iterator, initialSize));
+ }
+
+ public static PDictItemIterator createDictItemIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
+ return create(language, () -> new PDictItemIterator(PythonBuiltinClassType.PDictItemIterator, PythonBuiltinClassType.PDictItemIterator.getInstanceShape(language), iterator, hashingStorage,
+ initialSize));
+ }
+
+ public static PDictKeyIterator createDictKeyIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
+ return create(language,
+ () -> new PDictKeyIterator(PythonBuiltinClassType.PDictKeyIterator, PythonBuiltinClassType.PDictKeyIterator.getInstanceShape(language), iterator, hashingStorage, initialSize));
+ }
+
+ public static PDictValueIterator createDictValueIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
+ return create(language, () -> new PDictValueIterator(PythonBuiltinClassType.PDictValueIterator, PythonBuiltinClassType.PDictValueIterator.getInstanceShape(language), iterator, hashingStorage,
+ initialSize));
+ }
+
+ public static Object createSentinelIterator(PythonLanguage language, Object callable, Object sentinel) {
+ return create(language, () -> new PSentinelIterator(PythonBuiltinClassType.PSentinelIterator, PythonBuiltinClassType.PSentinelIterator.getInstanceShape(language), callable, sentinel));
+ }
+
+ public static PEnumerate createEnumerate(PythonLanguage language, Object cls, Shape shape, Object iterator, long start) {
+ return create(language, () -> new PEnumerate(cls, shape, iterator, start));
+ }
+
+ public static PEnumerate createEnumerate(PythonLanguage language, Object cls, Shape shape, Object iterator, PInt start) {
+ return create(language, () -> new PEnumerate(cls, shape, iterator, start));
+ }
+
+ public static PMap createMap(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PMap(cls, shape));
+ }
+
+ public static PZip createZip(PythonLanguage language, Object cls, Shape shape, Object[] iterables, boolean strict) {
+ return create(language, () -> new PZip(cls, shape, iterables, strict));
+ }
+
+ public static PCode createCode(PythonLanguage language, RootCallTarget ct) {
+ return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct));
+ }
+
+ public static PCode createCode(PythonLanguage language, RootCallTarget ct, int flags, int firstlineno, byte[] linetable, TruffleString filename) {
+ return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct, flags, firstlineno, linetable, filename));
+ }
+
+ public static PCode createCode(PythonLanguage language, RootCallTarget callTarget, Signature signature, CodeUnit codeUnit) {
+ return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature, codeUnit));
+ }
+
+ public static PCode createCode(PythonLanguage language, RootCallTarget callTarget, Signature signature, int nlocals,
+ int stacksize, int flags, Object[] constants,
+ TruffleString[] names, TruffleString[] varnames,
+ TruffleString[] freevars, TruffleString[] cellvars,
+ TruffleString filename, TruffleString name, TruffleString qualname,
+ int firstlineno, byte[] linetable) {
+ return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature,
+ nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars,
+ filename, name, qualname, firstlineno, linetable));
+ }
+
+ public static PCode createCode(PythonLanguage language, Supplier createCode, int flags, int firstlineno, byte[] lnotab, TruffleString filename) {
+ return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), createCode, flags, firstlineno, lnotab, filename));
+ }
+
+ /*
+ * Socket
+ */
+
+ public static PSocket createSocket(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PSocket(cls, shape));
+ }
+
+ /*
+ * Threading
+ */
+
+ public static PThreadLocal createThreadLocal(PythonLanguage language, Object cls, Shape shape, Object[] args, PKeyword[] kwArgs) {
+ return create(language, () -> new PThreadLocal(cls, shape, args, kwArgs));
+ }
+
+ public static PLock createLock(PythonLanguage language) {
+ return createLock(language, PythonBuiltinClassType.PLock, PythonBuiltinClassType.PLock.getInstanceShape(language));
+ }
+
+ public static PLock createLock(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PLock(cls, shape));
+ }
+
+ public static PRLock createRLock(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PRLock(cls, shape));
+ }
+
+ public static PThread createPythonThread(PythonLanguage language, Thread thread) {
+ return createPythonThread(language, PythonBuiltinClassType.PThread, PythonBuiltinClassType.PThread.getInstanceShape(language), thread);
+ }
+
+ public static PThread createPythonThread(PythonLanguage language, Object cls, Shape shape, Thread thread) {
+ return create(language, () -> new PThread(cls, shape, thread));
+ }
+
+ public static PSemLock createSemLock(PythonLanguage language, Object cls, Shape shape, long handle, int kind, int maxValue, TruffleString name) {
+ return create(language, () -> new PSemLock(cls, shape, handle, kind, maxValue, name));
+ }
+
+ public static PGraalPySemLock createGraalPySemLock(PythonLanguage language, TruffleString name, int kind, Semaphore sharedSemaphore) {
+ return createGraalPySemLock(language, PythonBuiltinClassType.PGraalPySemLock, PythonBuiltinClassType.PGraalPySemLock.getInstanceShape(language), name, kind, sharedSemaphore);
+ }
+
+ public static PGraalPySemLock createGraalPySemLock(PythonLanguage language, Object cls, Shape shape, TruffleString name, int kind, Semaphore sharedSemaphore) {
+ return create(language, () -> new PGraalPySemLock(cls, shape, name, kind, sharedSemaphore));
+ }
+
+ public static PScandirIterator createScandirIterator(PythonLanguage language, PythonContext context, Object dirStream, PosixFileHandle path, boolean needsRewind) {
+ return create(language,
+ () -> new PScandirIterator(PythonBuiltinClassType.PScandirIterator, PythonBuiltinClassType.PScandirIterator.getInstanceShape(language), context, dirStream, path, needsRewind));
+ }
+
+ public static PDirEntry createDirEntry(PythonLanguage language, Object dirEntryData, PosixFileHandle path) {
+ return create(language, () -> new PDirEntry(PythonBuiltinClassType.PDirEntry, PythonBuiltinClassType.PDirEntry.getInstanceShape(language), dirEntryData, path));
+ }
+
+ public static PEncodingMap createEncodingMap(PythonLanguage language, int count2, int count3, byte[] level1, byte[] level23) {
+ return create(language, () -> new PEncodingMap(PythonBuiltinClassType.PEncodingMap, PythonBuiltinClassType.PEncodingMap.getInstanceShape(language), count2, count3, level1, level23));
+ }
+
+ public static PMMap createMMap(PythonLanguage language, PythonContext context, Object cls, Shape shape, Object mmapHandle, int fd, long length, int access) {
+ return create(language, () -> new PMMap(cls, shape, context, mmapHandle, fd, length, access));
+ }
+
+ public static BZ2Object.BZ2Compressor createBZ2Compressor(PythonLanguage language) {
+ return createBZ2Compressor(language, PythonBuiltinClassType.BZ2Compressor, PythonBuiltinClassType.BZ2Compressor.getInstanceShape(language));
+ }
+
+ public static BZ2Object.BZ2Compressor createBZ2Compressor(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> BZ2Object.createCompressor(cls, shape));
+ }
+
+ public static BZ2Object.BZ2Decompressor createBZ2Decompressor(PythonLanguage language) {
+ return createBZ2Decompressor(language, PythonBuiltinClassType.BZ2Decompressor, PythonBuiltinClassType.BZ2Decompressor.getInstanceShape(language));
+ }
+
+ public static BZ2Object.BZ2Decompressor createBZ2Decompressor(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> BZ2Object.createDecompressor(cls, shape));
+ }
+
+ public static ZLibCompObject createJavaZLibCompObjectCompress(PythonLanguage language, Object stream, int level, int wbits, int strategy, byte[] zdict) {
+ return createJavaZLibCompObject(language, PythonBuiltinClassType.ZlibCompress, PythonBuiltinClassType.ZlibCompress.getInstanceShape(language), stream, level, wbits, strategy, zdict);
+ }
+
+ public static ZLibCompObject createJavaZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object stream, int level, int wbits, int strategy, byte[] zdict) {
+ return create(language, () -> ZLibCompObject.createJava(cls, shape, stream, level, wbits, strategy, zdict));
+ }
+
+ public static ZLibCompObject createJavaZLibCompObjectDecompress(PythonLanguage language, Object stream, int wbits, byte[] zdict) {
+ return createJavaZLibCompObject(language, PythonBuiltinClassType.ZlibDecompress, PythonBuiltinClassType.ZlibDecompress.getInstanceShape(language), stream, wbits, zdict);
+ }
+
+ public static ZLibCompObject createJavaZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object stream, int wbits, byte[] zdict) {
+ return create(language, () -> ZLibCompObject.createJava(cls, shape, stream, wbits, zdict));
+ }
+
+ public static ZLibCompObject createNativeZLibCompObjectCompress(PythonLanguage language, Object zst, NFIZlibSupport zlibSupport) {
+ return createNativeZLibCompObject(language, PythonBuiltinClassType.ZlibCompress, PythonBuiltinClassType.ZlibCompress.getInstanceShape(language), zst, zlibSupport);
+ }
+
+ public static ZLibCompObject createNativeZLibCompObjectDecompress(PythonLanguage language, Object zst, NFIZlibSupport zlibSupport) {
+ return createNativeZLibCompObject(language, PythonBuiltinClassType.ZlibDecompress, PythonBuiltinClassType.ZlibDecompress.getInstanceShape(language), zst, zlibSupport);
+ }
+
+ public static ZLibCompObject createNativeZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object zst, NFIZlibSupport zlibSupport) {
+ return create(language, () -> ZLibCompObject.createNative(cls, shape, zst, zlibSupport));
+ }
+
+ public static LZMAObject.LZMADecompressor createLZMADecompressor(PythonLanguage language, Object cls, Shape shape, boolean isNative) {
+ return create(language, () -> LZMAObject.createDecompressor(cls, shape, isNative));
+ }
+
+ public static LZMAObject.LZMACompressor createLZMACompressor(PythonLanguage language, Object cls, Shape shape, boolean isNative) {
+ return create(language, () -> LZMAObject.createCompressor(cls, shape, isNative));
+ }
+
+ public static CSVReader createCSVReader(PythonLanguage language, Object inputIter, CSVDialect dialect) {
+ return createCSVReader(language, PythonBuiltinClassType.CSVReader, PythonBuiltinClassType.CSVReader.getInstanceShape(language), inputIter, dialect);
+ }
+
+ public static CSVReader createCSVReader(PythonLanguage language, Object cls, Shape shape, Object inputIter, CSVDialect dialect) {
+ return create(language, () -> new CSVReader(cls, shape, inputIter, dialect));
+ }
+
+ public static CSVWriter createCSVWriter(PythonLanguage language, Object write, CSVDialect dialect) {
+ return createCSVWriter(language, PythonBuiltinClassType.CSVWriter, PythonBuiltinClassType.CSVWriter.getInstanceShape(language), write, dialect);
+ }
+
+ public static CSVWriter createCSVWriter(PythonLanguage language, Object cls, Shape shape, Object write, CSVDialect dialect) {
+ return create(language, () -> new CSVWriter(cls, shape, write, dialect));
+ }
+
+ public static CSVDialect createCSVDialect(PythonLanguage language, Object cls, Shape shape, TruffleString delimiter, int delimiterCodePoint, boolean doubleQuote, TruffleString escapeChar,
+ int escapeCharCodePoint,
+ TruffleString lineTerminator, TruffleString quoteChar, int quoteCharCodePoint, QuoteStyle quoting, boolean skipInitialSpace, boolean strict) {
+ return create(language,
+ () -> new CSVDialect(cls, shape, delimiter, delimiterCodePoint, doubleQuote, escapeChar, escapeCharCodePoint, lineTerminator, quoteChar, quoteCharCodePoint,
+ quoting,
+ skipInitialSpace, strict));
+ }
+
+ public static PFileIO createFileIO(PythonLanguage language) {
+ return createFileIO(language, PythonBuiltinClassType.PFileIO, PythonBuiltinClassType.PFileIO.getInstanceShape(language));
+ }
+
+ public static PFileIO createFileIO(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PFileIO(cls, shape));
+ }
+
+ public static PChain createChain(PythonLanguage language) {
+ return createChain(language, PythonBuiltinClassType.PChain, PythonBuiltinClassType.PChain.getInstanceShape(language));
+ }
+
+ public static PChain createChain(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PChain(cls, shape));
+ }
+
+ public static PCount createCount(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PCount(cls, shape));
+ }
+
+ public static PIslice createIslice(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PIslice(cls, shape));
+ }
+
+ public static PPairwise createPairwise(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PPairwise(cls, shape));
+ }
+
+ public static PPermutations createPermutations(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PPermutations(cls, shape));
+ }
+
+ public static PProduct createProduct(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PProduct(cls, shape));
+ }
+
+ public static PRepeat createRepeat(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PRepeat(cls, shape));
+ }
+
+ public static PAccumulate createAccumulate(PythonLanguage language) {
+ return createAccumulate(language, PythonBuiltinClassType.PAccumulate, PythonBuiltinClassType.PAccumulate.getInstanceShape(language));
+ }
+
+ public static PAccumulate createAccumulate(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PAccumulate(cls, shape));
+ }
+
+ public static PDropwhile createDropwhile(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PDropwhile(cls, shape));
+ }
+
+ public static PCombinations createCombinations(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PCombinations(cls, shape));
+ }
+
+ public static PCombinationsWithReplacement createCombinationsWithReplacement(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PCombinationsWithReplacement(cls, shape));
+ }
+
+ public static PCompress createCompress(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PCompress(cls, shape));
+ }
+
+ public static PCycle createCycle(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PCycle(cls, shape));
+ }
+
+ public static PFilterfalse createFilterfalse(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PFilterfalse(cls, shape));
+ }
+
+ public static PGroupBy createGroupBy(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PGroupBy(cls, shape));
+ }
+
+ public static PGrouper createGrouper(PythonLanguage language, PGroupBy parent, Object tgtKey) {
+ return create(language, () -> new PGrouper(parent, tgtKey, PythonBuiltinClassType.PGrouper, PythonBuiltinClassType.PGrouper.getInstanceShape(language)));
+ }
+
+ public static PTee createTee(PythonLanguage language, PTeeDataObject dataObj, int index) {
+ return create(language, () -> new PTee(dataObj, index, PythonBuiltinClassType.PTee, PythonBuiltinClassType.PTee.getInstanceShape(language)));
+ }
+
+ public static PStarmap createStarmap(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PStarmap(cls, shape));
+ }
+
+ public static PTakewhile createTakewhile(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PTakewhile(cls, shape));
+ }
+
+ public static PTeeDataObject createTeeDataObject(PythonLanguage language) {
+ return create(language, () -> new PTeeDataObject(PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
+ }
+
+ public static PTeeDataObject createTeeDataObject(PythonLanguage language, Object it) {
+ return create(language, () -> new PTeeDataObject(it, PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
+ }
+
+ public static PZipLongest createZipLongest(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PZipLongest(cls, shape));
+ }
+
+ public static PTextIO createTextIO(PythonLanguage language) {
+ return createTextIO(language, PythonBuiltinClassType.PTextIOWrapper, PythonBuiltinClassType.PTextIOWrapper.getInstanceShape(language));
+ }
+
+ public static PTextIO createTextIO(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PTextIO(cls, shape));
+ }
+
+ public static PStringIO createStringIO(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PStringIO(cls, shape));
+ }
+
+ public static PBytesIO createBytesIO(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PBytesIO(cls, shape));
+ }
+
+ public static PBytesIOBuffer createBytesIOBuf(PythonLanguage language, PBytesIO source) {
+ return createBytesIOBuf(language, PythonBuiltinClassType.PBytesIOBuf, PythonBuiltinClassType.PBytesIOBuf.getInstanceShape(language), source);
+ }
+
+ public static PBytesIOBuffer createBytesIOBuf(PythonLanguage language, Object cls, Shape shape, PBytesIO source) {
+ return create(language, () -> new PBytesIOBuffer(cls, shape, source));
+ }
+
+ public static PNLDecoder createNLDecoder(PythonLanguage language) {
+ return createNLDecoder(language, PythonBuiltinClassType.PIncrementalNewlineDecoder, PythonBuiltinClassType.PIncrementalNewlineDecoder.getInstanceShape(language));
+ }
+
+ public static PNLDecoder createNLDecoder(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PNLDecoder(cls, shape));
+ }
+
+ public static PBuffered createBufferedReader(PythonLanguage language) {
+ return createBufferedReader(language, PythonBuiltinClassType.PBufferedReader, PythonBuiltinClassType.PBufferedReader.getInstanceShape(language));
+ }
+
+ public static PBuffered createBufferedReader(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PBuffered(cls, shape, true, false));
+ }
+
+ public static PBuffered createBufferedWriter(PythonLanguage language) {
+ return createBufferedWriter(language, PythonBuiltinClassType.PBufferedWriter, PythonBuiltinClassType.PBufferedWriter.getInstanceShape(language));
+ }
+
+ public static PBuffered createBufferedWriter(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PBuffered(cls, shape, false, true));
+ }
+
+ public static PBuffered createBufferedRandom(PythonLanguage language) {
+ return createBufferedRandom(language, PythonBuiltinClassType.PBufferedRandom, PythonBuiltinClassType.PBufferedRandom.getInstanceShape(language));
+ }
+
+ public static PBuffered createBufferedRandom(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PBuffered(cls, shape, true, true));
+ }
+
+ public static PRWPair createRWPair(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PRWPair(cls, shape));
+ }
+
+ public static PyCArgObject createCArgObject(PythonLanguage language) {
+ return create(language, () -> new PyCArgObject(PythonBuiltinClassType.CArgObject, PythonBuiltinClassType.CArgObject.getInstanceShape(language)));
+ }
+
+ public static CThunkObject createCThunkObject(PythonLanguage language, int nArgs) {
+ return createCThunkObject(language, PythonBuiltinClassType.CThunkObject, PythonBuiltinClassType.CThunkObject.getInstanceShape(language), nArgs);
+ }
+
+ public static CThunkObject createCThunkObject(PythonLanguage language, Object cls, Shape shape, int nArgs) {
+ return create(language, () -> new CThunkObject(cls, shape, nArgs));
+ }
+
+ // Don't use directly, use CtypesNodes.CreateCDataObjectNode
+ public static CDataObject createCDataObject(PythonLanguage language, Object cls, Shape shape, Pointer b_ptr, int b_size, boolean b_needsfree) {
+ return create(language, () -> new CDataObject(cls, shape, b_ptr, b_size, b_needsfree));
+ }
+
+ // Don't use directly, use CtypesNodes.CreateCDataObjectNode
+ public static PyCFuncPtrObject createPyCFuncPtrObject(PythonLanguage language, Object cls, Shape shape, Pointer b_ptr, int b_size, boolean b_needsfree) {
+ return create(language, () -> new PyCFuncPtrObject(cls, shape, b_ptr, b_size, b_needsfree));
+ }
+
+ public static CFieldObject createCFieldObject(PythonLanguage language) {
+ return createCFieldObject(language, PythonBuiltinClassType.CField, PythonBuiltinClassType.CField.getInstanceShape(language));
+ }
+
+ public static CFieldObject createCFieldObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new CFieldObject(cls, shape));
+ }
+
+ public static StgDictObject createStgDictObject(PythonLanguage language) {
+ return createStgDictObject(language, PythonBuiltinClassType.StgDict, PythonBuiltinClassType.StgDict.getInstanceShape(language));
+ }
+
+ public static StgDictObject createStgDictObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new StgDictObject(cls, shape));
+ }
+
+ public static PSSLContext createSSLContext(PythonLanguage language, Object cls, Shape shape, SSLMethod method, int verifyFlags, boolean checkHostname, int verifyMode, SSLContext context) {
+ return create(language, () -> new PSSLContext(cls, shape, method, verifyFlags, checkHostname, verifyMode, context));
+ }
+
+ public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext context, SSLEngine engine, PSocket socket) {
+ return createSSLSocket(language, PythonBuiltinClassType.PSSLSocket, PythonBuiltinClassType.PSSLSocket.getInstanceShape(language), context, engine, socket);
+ }
+
+ public static PSSLSocket createSSLSocket(PythonLanguage language, Object cls, Shape shape, PSSLContext context, SSLEngine engine, PSocket socket) {
+ return create(language, () -> new PSSLSocket(cls, shape, context, engine, socket, createMemoryBIO(language), createMemoryBIO(language), createMemoryBIO(language)));
+ }
+
+ public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext context, SSLEngine engine, PMemoryBIO inbound, PMemoryBIO outbound) {
+ return createSSLSocket(language, PythonBuiltinClassType.PSSLSocket, PythonBuiltinClassType.PSSLSocket.getInstanceShape(language), context, engine, inbound, outbound);
+ }
+
+ public static PSSLSocket createSSLSocket(PythonLanguage language, Object cls, Shape shape, PSSLContext context, SSLEngine engine, PMemoryBIO inbound, PMemoryBIO outbound) {
+ return create(language, () -> new PSSLSocket(cls, shape, context, engine, null, inbound, outbound, createMemoryBIO(language)));
+ }
+
+ public static PMemoryBIO createMemoryBIO(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PMemoryBIO(cls, shape));
+ }
+
+ public static PMemoryBIO createMemoryBIO(PythonLanguage language) {
+ return create(language, () -> new PMemoryBIO(PythonBuiltinClassType.PMemoryBIO, PythonBuiltinClassType.PMemoryBIO.getInstanceShape(language)));
+ }
+
+ public static PProperty createProperty(PythonLanguage language) {
+ return create(language, () -> new PProperty(PythonBuiltinClassType.PProperty, PythonBuiltinClassType.PProperty.getInstanceShape(language)));
+ }
+
+ public static PProperty createProperty(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PProperty(cls, shape));
+ }
+
+ // JSON
+ // (not created on fast path, thus TruffleBoundary)
+
+ @TruffleBoundary
+ public static PJSONScanner createJSONScanner(PythonLanguage language, Object cls, Shape shape, boolean strict, Object objectHook, Object objectPairsHook, Object parseFloat, Object parseInt,
+ Object parseConstant) {
+ return create(language, () -> new PJSONScanner(cls, shape, strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant));
+ }
+
+ @TruffleBoundary
+ public static PJSONEncoder createJSONEncoder(PythonLanguage language, Object cls, Shape shape, Object markers, Object defaultFn, Object encoder, Object indent, TruffleString keySeparator,
+ TruffleString itemSeparator,
+ boolean sortKeys, boolean skipKeys, boolean allowNan, FastEncode fastEncode) {
+ return create(language, () -> new PJSONEncoder(cls, shape, markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode));
+ }
+
+ public static PDeque createDeque(PythonLanguage language) {
+ return create(language, () -> new PDeque(PythonBuiltinClassType.PDeque, PythonBuiltinClassType.PDeque.getInstanceShape(language)));
+ }
+
+ public static PDeque createDeque(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PDeque(cls, shape));
+ }
+
+ public static PDequeIter createDequeIter(PythonLanguage language, PDeque deque) {
+ return create(language, () -> new PDequeIter(PythonBuiltinClassType.PDequeIter, PythonBuiltinClassType.PDequeIter.getInstanceShape(language), deque, false));
+ }
+
+ public static PDequeIter createDequeRevIter(PythonLanguage language, PDeque deque) {
+ return create(language, () -> new PDequeIter(PythonBuiltinClassType.PDequeRevIter, PythonBuiltinClassType.PDequeRevIter.getInstanceShape(language), deque, true));
+ }
+
+ public static PSimpleQueue createSimpleQueue(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PSimpleQueue(cls, shape));
+ }
+
+ public static PContextVar createContextVar(PythonLanguage language, TruffleString name, Object def) {
+ return create(language, () -> new PContextVar(PythonBuiltinClassType.ContextVar, PythonBuiltinClassType.ContextVar.getInstanceShape(language), name, def));
+ }
+
+ public static PContextVarsContext createContextVarsContext(PythonLanguage language) {
+ return create(language, () -> new PContextVarsContext(PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
+ }
+
+ public static PContextIterator createContextIterator(PythonLanguage language, PContextVarsContext ctx, PContextIterator.ItemKind kind) {
+ return create(language, () -> new PContextIterator(PythonBuiltinClassType.ContextIterator, PythonBuiltinClassType.ContextIterator.getInstanceShape(language), ctx, kind));
+ }
+
+ public static PContextVarsContext copyContextVarsContext(PythonLanguage language, PContextVarsContext original) {
+ return create(language, () -> new PContextVarsContext(original, PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
+ }
+
+ public static PContextVarsToken createContextVarsToken(PythonLanguage language, PContextVar var, Object oldValue) {
+ return create(language, () -> new PContextVarsToken(var, oldValue, PythonBuiltinClassType.ContextVarsToken, PythonBuiltinClassType.ContextVarsToken.getInstanceShape(language)));
+ }
+
+ public static PGenericAlias createGenericAlias(PythonLanguage language, Object cls, Shape shape, Object origin, Object arguments, boolean starred) {
+ PTuple argumentsTuple;
+ if (arguments instanceof PTuple) {
+ argumentsTuple = (PTuple) arguments;
+ } else {
+ argumentsTuple = createTuple(language, new Object[]{arguments});
+ }
+ return create(language, () -> new PGenericAlias(cls, shape, origin, argumentsTuple, starred));
+ }
+
+ public static PGenericAlias createGenericAlias(PythonLanguage language, Object origin, Object arguments, boolean starred) {
+ return createGenericAlias(language, PythonBuiltinClassType.PGenericAlias, PythonBuiltinClassType.PGenericAlias.getInstanceShape(language), origin, arguments, starred);
+ }
+
+ public static PGenericAlias createGenericAlias(PythonLanguage language, Object origin, Object arguments) {
+ return createGenericAlias(language, origin, arguments, false);
+ }
+
+ public static PGenericAliasIterator createGenericAliasIterator(PythonLanguage language, PGenericAlias object) {
+ return create(language, () -> new PGenericAliasIterator(PythonBuiltinClassType.PGenericAliasIterator, PythonBuiltinClassType.PGenericAliasIterator.getInstanceShape(language), object));
+ }
+
+ public static PUnionType createUnionType(PythonLanguage language, Object[] args) {
+ return create(language, () -> new PUnionType(PythonBuiltinClassType.PUnionType, PythonBuiltinClassType.PUnionType.getInstanceShape(language), createTuple(language, args)));
+ }
+
+ public static DigestObject createDigestObject(PythonLanguage language, PythonBuiltinClassType type, String name, Object digest) {
+ return create(language, () -> DigestObject.create(type, type.getInstanceShape(language), name, digest));
+ }
+
+ public static PyCapsule createCapsuleNativeName(PythonLanguage language, Object pointer, Object name) {
+ return createCapsule(language, new PyCapsule.CapsuleData(pointer, name));
+ }
+
+ public static PyCapsule createCapsuleJavaName(PythonLanguage language, Object pointer, byte[] name) {
+ return createCapsule(language, new PyCapsule.CapsuleData(pointer, new CArrayWrappers.CByteArrayWrapper(name)));
+ }
+
+ public static PyCapsule createCapsule(PythonLanguage language, PyCapsule.CapsuleData data) {
+ return create(language, () -> new PyCapsule(language, data));
+ }
+
+ public static MultibyteIncrementalDecoderObject createMultibyteIncrementalDecoderObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new MultibyteIncrementalDecoderObject(cls, shape));
+ }
+
+ public static MultibyteIncrementalEncoderObject createMultibyteIncrementalEncoderObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new MultibyteIncrementalEncoderObject(cls, shape));
+ }
+
+ public static MultibyteStreamReaderObject createMultibyteStreamReaderObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new MultibyteStreamReaderObject(cls, shape));
+ }
+
+ public static MultibyteStreamWriterObject createMultibyteStreamWriterObject(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new MultibyteStreamWriterObject(cls, shape));
+ }
+
+ public static MultibyteCodecObject createMultibyteCodecObject(PythonLanguage language, MultibyteCodec codec) {
+ return createMultibyteCodecObject(language, PythonBuiltinClassType.MultibyteCodec, PythonBuiltinClassType.MultibyteCodec.getInstanceShape(language), codec);
+ }
+
+ public static MultibyteCodecObject createMultibyteCodecObject(PythonLanguage language, Object cls, Shape shape, MultibyteCodec codec) {
+ return create(language, () -> new MultibyteCodecObject(cls, shape, codec));
+ }
+
+ public static PAsyncGenASend createAsyncGeneratorASend(PythonLanguage language, PAsyncGen receiver, Object message) {
+ return create(language, () -> new PAsyncGenASend(language, receiver, message));
+ }
+
+ public static PAsyncGenAThrow createAsyncGeneratorAThrow(PythonLanguage language, PAsyncGen receiver, Object arg1, Object arg2, Object arg3) {
+ return create(language, () -> new PAsyncGenAThrow(language, receiver, arg1, arg2, arg3));
+ }
+
+ public static PAsyncGenWrappedValue createAsyncGeneratorWrappedValue(PythonLanguage language, Object wrapped) {
+ return create(language, () -> new PAsyncGenWrappedValue(language, wrapped));
+ }
+
+ // pickle
+
+ public static PPickleBuffer createPickleBuffer(PythonLanguage language, Object view) {
+ return createPickleBuffer(language, view, PythonBuiltinClassType.PickleBuffer, PythonBuiltinClassType.PickleBuffer.getInstanceShape(language));
+ }
+
+ public static PPickleBuffer createPickleBuffer(PythonLanguage language, Object view, Object cls, Shape shape) {
+ return create(language, () -> new PPickleBuffer(cls, shape, view));
+ }
+
+ public static PPickler createPickler(PythonLanguage language) {
+ return createPickler(language, PythonBuiltinClassType.Pickler, PythonBuiltinClassType.Pickler.getInstanceShape(language));
+ }
+
+ public static PPickler createPickler(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PPickler(cls, shape));
+ }
+
+ public static PUnpickler createUnpickler(PythonLanguage language) {
+ return createUnpickler(language, PythonBuiltinClassType.Unpickler, PythonBuiltinClassType.Unpickler.getInstanceShape(language));
+ }
+
+ public static PUnpickler createUnpickler(PythonLanguage language, Object cls, Shape shape) {
+ return create(language, () -> new PUnpickler(cls, shape));
+ }
+
+ public static PPicklerMemoProxy createPicklerMemoProxy(PythonLanguage language, PPickler pickler) {
+ return createPicklerMemoProxy(language, pickler, PythonBuiltinClassType.PicklerMemoProxy, PythonBuiltinClassType.PicklerMemoProxy.getInstanceShape(language));
+ }
+
+ public static PPicklerMemoProxy createPicklerMemoProxy(PythonLanguage language, PPickler pickler, Object cls, Shape shape) {
+ return create(language, () -> new PPicklerMemoProxy(cls, shape, pickler));
+ }
+
+ public static PUnpicklerMemoProxy createUnpicklerMemoProxy(PythonLanguage language, PUnpickler unpickler) {
+ return createUnpicklerMemoProxy(language, unpickler, PythonBuiltinClassType.UnpicklerMemoProxy, PythonBuiltinClassType.UnpicklerMemoProxy.getInstanceShape(language));
+ }
+
+ public static PUnpicklerMemoProxy createUnpicklerMemoProxy(PythonLanguage language, PUnpickler unpickler, Object cls, Shape shape) {
+ return create(language, () -> new PUnpicklerMemoProxy(cls, shape, unpickler));
+ }
+
+ public static PStruct createStruct(PythonLanguage language, PStruct.StructInfo structInfo) {
+ return create(language, () -> new PStruct(PythonBuiltinClassType.PStruct, PythonBuiltinClassType.PStruct.getInstanceShape(language), structInfo));
+ }
+
+ public static PStructUnpackIterator createStructUnpackIterator(PythonLanguage language, PStruct struct, Object buffer) {
+ return create(language, () -> new PStructUnpackIterator(PythonBuiltinClassType.PStructUnpackIterator, PythonBuiltinClassType.PStructUnpackIterator.getInstanceShape(language), struct, buffer));
+ }
+
+ public static PTokenizerIter createTokenizerIter(PythonLanguage language, String sourceString) {
+ return createTokenizerIter(language, PythonBuiltinClassType.PTokenizerIter, PythonBuiltinClassType.PTokenizerIter.getInstanceShape(language), sourceString);
+ }
+
+ public static PTokenizerIter createTokenizerIter(PythonLanguage language, Object cls, Shape shape, String sourceString) {
+ return create(language, () -> new PTokenizerIter(cls, shape, sourceString));
+ }
+
+ public static Profiler createProfiler(PythonLanguage language, Object cls, Shape shape, CPUSampler sampler) {
+ return create(language, () -> new Profiler(cls, shape, sampler));
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java
deleted file mode 100644
index ade6180bd8..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java
+++ /dev/null
@@ -1,1739 +0,0 @@
-/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
- * Copyright (c) 2013, Regents of the University of California
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.oracle.graal.python.runtime.object;
-
-import java.lang.ref.ReferenceQueue;
-import java.math.BigInteger;
-import java.util.LinkedHashMap;
-import java.util.concurrent.Semaphore;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.Python3Core;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixFileHandle;
-import com.oracle.graal.python.builtins.modules.bz2.BZ2Object;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteCodec;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteCodecObject;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteIncrementalDecoderObject;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteIncrementalEncoderObject;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteStreamReaderObject;
-import com.oracle.graal.python.builtins.modules.cjkcodecs.MultibyteStreamWriterObject;
-import com.oracle.graal.python.builtins.modules.codecs.PEncodingMap;
-import com.oracle.graal.python.builtins.modules.csv.CSVDialect;
-import com.oracle.graal.python.builtins.modules.csv.CSVReader;
-import com.oracle.graal.python.builtins.modules.csv.CSVWriter;
-import com.oracle.graal.python.builtins.modules.csv.QuoteStyle;
-import com.oracle.graal.python.builtins.modules.ctypes.CDataObject;
-import com.oracle.graal.python.builtins.modules.ctypes.CFieldObject;
-import com.oracle.graal.python.builtins.modules.ctypes.CThunkObject;
-import com.oracle.graal.python.builtins.modules.ctypes.PyCArgObject;
-import com.oracle.graal.python.builtins.modules.ctypes.PyCFuncPtrObject;
-import com.oracle.graal.python.builtins.modules.ctypes.StgDictObject;
-import com.oracle.graal.python.builtins.modules.ctypes.StructParamObject;
-import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer;
-import com.oracle.graal.python.builtins.modules.functools.LruCacheObject;
-import com.oracle.graal.python.builtins.modules.functools.PKeyWrapper;
-import com.oracle.graal.python.builtins.modules.functools.PPartial;
-import com.oracle.graal.python.builtins.modules.hashlib.DigestObject;
-import com.oracle.graal.python.builtins.modules.io.PBuffered;
-import com.oracle.graal.python.builtins.modules.io.PBytesIO;
-import com.oracle.graal.python.builtins.modules.io.PBytesIOBuffer;
-import com.oracle.graal.python.builtins.modules.io.PFileIO;
-import com.oracle.graal.python.builtins.modules.io.PNLDecoder;
-import com.oracle.graal.python.builtins.modules.io.PRWPair;
-import com.oracle.graal.python.builtins.modules.io.PStringIO;
-import com.oracle.graal.python.builtins.modules.io.PTextIO;
-import com.oracle.graal.python.builtins.modules.json.PJSONEncoder;
-import com.oracle.graal.python.builtins.modules.json.PJSONEncoder.FastEncode;
-import com.oracle.graal.python.builtins.modules.json.PJSONScanner;
-import com.oracle.graal.python.builtins.modules.lzma.LZMAObject;
-import com.oracle.graal.python.builtins.modules.multiprocessing.PGraalPySemLock;
-import com.oracle.graal.python.builtins.modules.multiprocessing.PSemLock;
-import com.oracle.graal.python.builtins.modules.pickle.PPickleBuffer;
-import com.oracle.graal.python.builtins.modules.pickle.PPickler;
-import com.oracle.graal.python.builtins.modules.pickle.PPicklerMemoProxy;
-import com.oracle.graal.python.builtins.modules.pickle.PUnpickler;
-import com.oracle.graal.python.builtins.modules.pickle.PUnpicklerMemoProxy;
-import com.oracle.graal.python.builtins.modules.zlib.ZLibCompObject;
-import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.array.PArray;
-import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGen;
-import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenASend;
-import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenAThrow;
-import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenWrappedValue;
-import com.oracle.graal.python.builtins.objects.asyncio.PCoroutineWrapper;
-import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
-import com.oracle.graal.python.builtins.objects.bytes.PBytes;
-import com.oracle.graal.python.builtins.objects.capsule.PyCapsule;
-import com.oracle.graal.python.builtins.objects.cell.PCell;
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
-import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper;
-import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers;
-import com.oracle.graal.python.builtins.objects.cext.hpy.PythonHPyObject;
-import com.oracle.graal.python.builtins.objects.code.PCode;
-import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
-import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
-import com.oracle.graal.python.builtins.objects.common.ForeignHashingStorage;
-import com.oracle.graal.python.builtins.objects.common.HashingStorage;
-import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
-import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
-import com.oracle.graal.python.builtins.objects.complex.PComplex;
-import com.oracle.graal.python.builtins.objects.contextvars.PContextIterator;
-import com.oracle.graal.python.builtins.objects.contextvars.PContextVar;
-import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext;
-import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsToken;
-import com.oracle.graal.python.builtins.objects.deque.PDeque;
-import com.oracle.graal.python.builtins.objects.deque.PDequeIter;
-import com.oracle.graal.python.builtins.objects.dict.PDefaultDict;
-import com.oracle.graal.python.builtins.objects.dict.PDict;
-import com.oracle.graal.python.builtins.objects.dict.PDictView;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictItemIterator;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictItemsView;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictKeyIterator;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictKeysView;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValueIterator;
-import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValuesView;
-import com.oracle.graal.python.builtins.objects.enumerate.PEnumerate;
-import com.oracle.graal.python.builtins.objects.exception.PBaseException;
-import com.oracle.graal.python.builtins.objects.exception.PBaseExceptionGroup;
-import com.oracle.graal.python.builtins.objects.floats.PFloat;
-import com.oracle.graal.python.builtins.objects.frame.PFrame;
-import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
-import com.oracle.graal.python.builtins.objects.function.PFunction;
-import com.oracle.graal.python.builtins.objects.function.PKeyword;
-import com.oracle.graal.python.builtins.objects.function.Signature;
-import com.oracle.graal.python.builtins.objects.generator.PGenerator;
-import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
-import com.oracle.graal.python.builtins.objects.getsetdescriptor.IndexedSlotDescriptor;
-import com.oracle.graal.python.builtins.objects.ints.PInt;
-import com.oracle.graal.python.builtins.objects.iterator.PArrayIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PBaseSetIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PBigRangeIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PDoubleSequenceIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PIntegerSequenceIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PLongSequenceIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PObjectSequenceIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PSentinelIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PStringIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PStructUnpackIterator;
-import com.oracle.graal.python.builtins.objects.iterator.PZip;
-import com.oracle.graal.python.builtins.objects.itertools.PAccumulate;
-import com.oracle.graal.python.builtins.objects.itertools.PChain;
-import com.oracle.graal.python.builtins.objects.itertools.PCombinations;
-import com.oracle.graal.python.builtins.objects.itertools.PCombinationsWithReplacement;
-import com.oracle.graal.python.builtins.objects.itertools.PCompress;
-import com.oracle.graal.python.builtins.objects.itertools.PCount;
-import com.oracle.graal.python.builtins.objects.itertools.PCycle;
-import com.oracle.graal.python.builtins.objects.itertools.PDropwhile;
-import com.oracle.graal.python.builtins.objects.itertools.PFilterfalse;
-import com.oracle.graal.python.builtins.objects.itertools.PGroupBy;
-import com.oracle.graal.python.builtins.objects.itertools.PGrouper;
-import com.oracle.graal.python.builtins.objects.itertools.PIslice;
-import com.oracle.graal.python.builtins.objects.itertools.PPairwise;
-import com.oracle.graal.python.builtins.objects.itertools.PPermutations;
-import com.oracle.graal.python.builtins.objects.itertools.PProduct;
-import com.oracle.graal.python.builtins.objects.itertools.PRepeat;
-import com.oracle.graal.python.builtins.objects.itertools.PStarmap;
-import com.oracle.graal.python.builtins.objects.itertools.PTakewhile;
-import com.oracle.graal.python.builtins.objects.itertools.PTee;
-import com.oracle.graal.python.builtins.objects.itertools.PTeeDataObject;
-import com.oracle.graal.python.builtins.objects.itertools.PZipLongest;
-import com.oracle.graal.python.builtins.objects.list.PList;
-import com.oracle.graal.python.builtins.objects.list.PList.ListOrigin;
-import com.oracle.graal.python.builtins.objects.map.PMap;
-import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy;
-import com.oracle.graal.python.builtins.objects.memoryview.BufferLifecycleManager;
-import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
-import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
-import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod;
-import com.oracle.graal.python.builtins.objects.method.PMethod;
-import com.oracle.graal.python.builtins.objects.mmap.PMMap;
-import com.oracle.graal.python.builtins.objects.module.PythonModule;
-import com.oracle.graal.python.builtins.objects.namespace.PSimpleNamespace;
-import com.oracle.graal.python.builtins.objects.object.PythonObject;
-import com.oracle.graal.python.builtins.objects.ordereddict.POrderedDict;
-import com.oracle.graal.python.builtins.objects.ordereddict.POrderedDictIterator;
-import com.oracle.graal.python.builtins.objects.posix.PDirEntry;
-import com.oracle.graal.python.builtins.objects.posix.PScandirIterator;
-import com.oracle.graal.python.builtins.objects.property.PProperty;
-import com.oracle.graal.python.builtins.objects.queue.PSimpleQueue;
-import com.oracle.graal.python.builtins.objects.random.PRandom;
-import com.oracle.graal.python.builtins.objects.range.PBigRange;
-import com.oracle.graal.python.builtins.objects.range.PIntRange;
-import com.oracle.graal.python.builtins.objects.referencetype.PReferenceType;
-import com.oracle.graal.python.builtins.objects.reversed.PSequenceReverseIterator;
-import com.oracle.graal.python.builtins.objects.reversed.PStringReverseIterator;
-import com.oracle.graal.python.builtins.objects.set.PBaseSet;
-import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
-import com.oracle.graal.python.builtins.objects.set.PSet;
-import com.oracle.graal.python.builtins.objects.slice.PIntSlice;
-import com.oracle.graal.python.builtins.objects.slice.PObjectSlice;
-import com.oracle.graal.python.builtins.objects.socket.PSocket;
-import com.oracle.graal.python.builtins.objects.ssl.PMemoryBIO;
-import com.oracle.graal.python.builtins.objects.ssl.PSSLContext;
-import com.oracle.graal.python.builtins.objects.ssl.PSSLSocket;
-import com.oracle.graal.python.builtins.objects.ssl.SSLMethod;
-import com.oracle.graal.python.builtins.objects.str.NativeCharSequence;
-import com.oracle.graal.python.builtins.objects.str.PString;
-import com.oracle.graal.python.builtins.objects.struct.FormatAlignment;
-import com.oracle.graal.python.builtins.objects.struct.FormatCode;
-import com.oracle.graal.python.builtins.objects.struct.PStruct;
-import com.oracle.graal.python.builtins.objects.superobject.SuperObject;
-import com.oracle.graal.python.builtins.objects.thread.PLock;
-import com.oracle.graal.python.builtins.objects.thread.PRLock;
-import com.oracle.graal.python.builtins.objects.thread.PThread;
-import com.oracle.graal.python.builtins.objects.thread.PThreadLocal;
-import com.oracle.graal.python.builtins.objects.tokenize.PTokenizerIter;
-import com.oracle.graal.python.builtins.objects.traceback.LazyTraceback;
-import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
-import com.oracle.graal.python.builtins.objects.tuple.PTuple;
-import com.oracle.graal.python.builtins.objects.tuple.PTupleGetter;
-import com.oracle.graal.python.builtins.objects.tuple.StructSequence.BuiltinTypeDescriptor;
-import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
-import com.oracle.graal.python.builtins.objects.type.PythonClass;
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.builtins.objects.type.TpSlots;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
-import com.oracle.graal.python.builtins.objects.types.PGenericAlias;
-import com.oracle.graal.python.builtins.objects.types.PGenericAliasIterator;
-import com.oracle.graal.python.builtins.objects.types.PUnionType;
-import com.oracle.graal.python.compiler.CodeUnit;
-import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
-import com.oracle.graal.python.runtime.NFIZlibSupport;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.runtime.object.PythonObjectFactoryNodeGen.LazyNodeGen;
-import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
-import com.oracle.graal.python.runtime.sequence.storage.SequenceStorageFactory;
-import com.oracle.graal.python.util.BufferFormat;
-import com.oracle.graal.python.util.OverflowException;
-import com.oracle.graal.python.util.PythonUtils;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.Assumption;
-import com.oracle.truffle.api.CallTarget;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
-import com.oracle.truffle.api.RootCallTarget;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.GenerateCached;
-import com.oracle.truffle.api.dsl.GenerateInline;
-import com.oracle.truffle.api.dsl.GenerateUncached;
-import com.oracle.truffle.api.dsl.ImportStatic;
-import com.oracle.truffle.api.dsl.NeverDefault;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.MaterializedFrame;
-import com.oracle.truffle.api.instrumentation.AllocationReporter;
-import com.oracle.truffle.api.nodes.Node;
-import com.oracle.truffle.api.object.Shape;
-import com.oracle.truffle.api.strings.TruffleString;
-
-/**
- * Factory for Python objects that also reports to Truffle's {@link AllocationReporter}. The
- * reporting needs current context. There are several implementations of this abstract class. Use
- * this rule of thumb when choosing which one to use:
- *
- * In partially evaluated code: use adopted (@Child/@Cached) {@link PythonObjectFactory} node
- *
- * Behind {@code TruffleBoundary}:
- *
- * When the current context is already available, use {@link Python3Core#factory()}. This avoids
- * repeated context lookups inside the factory.
- * When the current context is not available, but multiple objects will be created: lookup the
- * context and use {@link Python3Core#factory()}. This executes only one context lookup. Note: first
- * check if the caller could pass the context to avoid looking it up behind {@code TruffleBoundary}.
- *
- * When the current context is not available, and only one object is to be created: use
- * {@link PythonObjectFactory#getUncached()}.
- *
- *
- *
- */
-@GenerateUncached
-@ImportStatic(PythonOptions.class)
-@GenerateInline(false) // Footprint reduction 28 -> 9
-public abstract class PythonObjectFactory extends Node {
- // Note: we're keeping this not inlined for now because:
- // - overwhelming number of usages of non-execute entry points to refactor
- // - often used lazily and as a @Child, most notably in all the builtins
-
- @NeverDefault
- public static PythonObjectFactory create() {
- return PythonObjectFactoryNodeGen.create();
- }
-
- public static PythonObjectFactory getUncached() {
- return PythonObjectFactoryNodeGen.getUncached();
- }
-
- protected abstract AllocationReporter executeTrace(Object o, long size);
-
- protected abstract Shape executeGetShape(Object o, boolean flag);
-
- @Specialization
- static Shape getShape(Object o, @SuppressWarnings("unused") boolean flag,
- @Cached TypeNodes.GetInstanceShape getShapeNode) {
- return getShapeNode.execute(o);
- }
-
- @Specialization
- static AllocationReporter doTrace(Object o, long size,
- @Cached(value = "getAllocationReporter()", allowUncached = true) AllocationReporter reporter) {
- if (reporter.isActive()) {
- doTraceImpl(o, size, reporter);
- }
- return null;
- }
-
- @InliningCutoff
- private static void doTraceImpl(Object o, long size, AllocationReporter reporter) {
- reporter.onEnter(null, 0, size);
- reporter.onReturnValue(o, 0, size);
- }
-
- @NeverDefault
- protected AllocationReporter getAllocationReporter() {
- return PythonContext.get(this).getAllocationReporter();
- }
-
- public PythonLanguage getLanguage() {
- return PythonLanguage.get(this);
- }
-
- public final Shape getShape(PythonBuiltinClassType cls) {
- return cls.getInstanceShape(getLanguage());
- }
-
- public final Shape getShape(Object cls) {
- return executeGetShape(cls, true);
- }
-
- public final T trace(T allocatedObject) {
- executeTrace(allocatedObject, AllocationReporter.SIZE_UNKNOWN);
- return allocatedObject;
- }
-
- /*
- * Python objects
- */
-
- /**
- * Creates a PythonObject for the given class. This is potentially slightly slower than if the
- * shape had been cached, due to the additional shape lookup.
- */
- public final PythonObject createPythonObject(Object cls) {
- return createPythonObject(cls, getShape(cls));
- }
-
- /**
- * Creates a PythonObject for the given class. This is potentially slightly slower than if the
- * shape had been cached, due to the additional shape lookup.
- */
- public final PythonObject createPythonHPyObject(Object cls, Object hpyNativeSpace) {
- return trace(new PythonHPyObject(cls, getShape(cls), hpyNativeSpace));
- }
-
- /**
- * Creates a Python object with the given shape. Python object shapes store the class in the
- * shape if possible.
- */
- public final PythonObject createPythonObject(Object klass, Shape instanceShape) {
- return trace(new PythonObject(klass, instanceShape));
- }
-
- public final PythonNativeVoidPtr createNativeVoidPtr(Object obj) {
- return trace(new PythonNativeVoidPtr(obj));
- }
-
- public final PythonNativeVoidPtr createNativeVoidPtr(Object obj, long nativePtr) {
- return trace(new PythonNativeVoidPtr(obj, nativePtr));
- }
-
- public final SuperObject createSuperObject(Object self) {
- return trace(new SuperObject(self, getShape(self)));
- }
-
- /*
- * Primitive types
- */
- public final PInt createInt(int value) {
- Shape shape = getLanguage().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PInt);
- return trace(new PInt(PythonBuiltinClassType.PInt, shape, PInt.longToBigInteger(value)));
- }
-
- public final PInt createInt(long value) {
- Shape shape = getLanguage().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PInt);
- return trace(new PInt(PythonBuiltinClassType.PInt, shape, PInt.longToBigInteger(value)));
- }
-
- public final PInt createInt(BigInteger value) {
- Shape shape = getLanguage().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PInt);
- return trace(new PInt(PythonBuiltinClassType.PInt, shape, value));
- }
-
- public final Object createInt(Object cls, int value) {
- return createInt(cls, PInt.longToBigInteger(value));
- }
-
- public final Object createInt(Object cls, long value) {
- return createInt(cls, PInt.longToBigInteger(value));
- }
-
- public final PInt createInt(Object cls, BigInteger value) {
- return trace(new PInt(cls, getShape(cls), value));
- }
-
- public final PFloat createFloat(double value) {
- Shape shape = getLanguage().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PFloat);
- return trace(new PFloat(PythonBuiltinClassType.PFloat, shape, value));
- }
-
- public final PFloat createFloat(Object cls, double value) {
- return trace(new PFloat(cls, getShape(cls), value));
- }
-
- public final PString createString(TruffleString string) {
- Shape shape = getLanguage().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PString);
- return trace(new PString(PythonBuiltinClassType.PString, shape, string));
- }
-
- public final PString createString(Object cls, TruffleString string) {
- return trace(new PString(cls, getShape(cls), string));
- }
-
- public final PString createString(NativeCharSequence string) {
- return createString(PythonBuiltinClassType.PString, string);
- }
-
- public final PString createString(Object cls, NativeCharSequence string) {
- return trace(new PString(cls, getShape(cls), string));
- }
-
- public final PBytes createEmptyBytes() {
- if (CompilerDirectives.inInterpreter()) {
- return createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
- } else {
- return createBytes(new byte[0]);
- }
- }
-
- public final PBytes createBytes(byte[] array) {
- return createBytes(array, array.length);
- }
-
- public final PBytes createBytes(byte[] array, int offset, int length) {
- if (length != array.length) {
- byte[] buf = new byte[length];
- PythonUtils.arraycopy(array, offset, buf, 0, buf.length);
- return createBytes(buf, length);
- }
- return createBytes(array, length);
- }
-
- public final PBytes createBytes(Object cls, byte[] array) {
- return createBytes(cls, array, array.length);
- }
-
- public final PBytes createBytes(byte[] array, int length) {
- return createBytes(new ByteSequenceStorage(array, length));
- }
-
- public final PBytes createBytes(Object cls, byte[] array, int length) {
- return createBytes(cls, new ByteSequenceStorage(array, length));
- }
-
- public final PBytes createBytes(SequenceStorage storage) {
- return trace(new PBytes(PythonBuiltinClassType.PBytes, getShape(PythonBuiltinClassType.PBytes), storage));
- }
-
- public final PBytes createBytes(Object cls, SequenceStorage storage) {
- return trace(new PBytes(cls, getShape(cls), storage));
- }
-
- public final PTuple createEmptyTuple() {
- return createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
- }
-
- public final PTuple createEmptyTuple(Object cls) {
- return createTuple(cls, EmptySequenceStorage.INSTANCE);
- }
-
- public final PTuple createTuple(Object[] objects) {
- Shape shape = PythonBuiltinClassType.PTuple.getInstanceShape(getLanguage());
- return trace(new PTuple(PythonBuiltinClassType.PTuple, shape, objects));
- }
-
- public final PTuple createTuple(int[] ints) {
- return createTuple(new IntSequenceStorage(ints));
- }
-
- public final PTuple createTuple(SequenceStorage store) {
- Shape shape = PythonBuiltinClassType.PTuple.getInstanceShape(getLanguage());
- return trace(new PTuple(PythonBuiltinClassType.PTuple, shape, store));
- }
-
- public final PTuple createTuple(Object cls, Shape instanceShape, Object[] objects) {
- return trace(new PTuple(cls, instanceShape, objects));
- }
-
- public final PTuple createTuple(Object cls, Object[] objects) {
- return trace(new PTuple(cls, getShape(cls), objects));
- }
-
- public final PTuple createTuple(Object cls, SequenceStorage store) {
- return trace(new PTuple(cls, getShape(cls), store));
- }
-
- public final PTuple createStructSeq(BuiltinTypeDescriptor desc, Object... values) {
- assert desc.inSequence <= values.length && values.length <= desc.fieldNames.length;
- return createTuple(desc.type, new ObjectSequenceStorage(values, desc.inSequence));
- }
-
- public final PTupleGetter createTupleGetter(int index, Object doc) {
- return createTupleGetter(PythonBuiltinClassType.PTupleGetter, index, doc);
- }
-
- public final PTupleGetter createTupleGetter(Object cls, int index, Object doc) {
- return trace(new PTupleGetter(cls, getShape(cls), index, doc));
- }
-
- public final PComplex createComplex(Object cls, double real, double imag) {
- return trace(new PComplex(cls, getShape(cls), real, imag));
- }
-
- public final PComplex createComplex(double real, double imag) {
- return createComplex(PythonBuiltinClassType.PComplex, real, imag);
- }
-
- public final PIntRange createIntRange(int stop) {
- return trace(new PIntRange(getLanguage(), 0, stop, 1, stop));
- }
-
- public final PIntRange createIntRange(int start, int stop, int step, int len) {
- return trace(new PIntRange(getLanguage(), start, stop, step, len));
- }
-
- public final PBigRange createBigRange(BigInteger start, BigInteger stop, BigInteger step, BigInteger len) {
- return createBigRange(createInt(start), createInt(stop), createInt(step), createInt(len));
- }
-
- public final PBigRange createBigRange(PInt start, PInt stop, PInt step, PInt len) {
- return trace(new PBigRange(getLanguage(), start, stop, step, len));
- }
-
- public final PIntSlice createIntSlice(int start, int stop, int step) {
- return trace(new PIntSlice(getLanguage(), start, stop, step));
- }
-
- public final PIntSlice createIntSlice(int start, int stop, int step, boolean isStartNone, boolean isStepNone) {
- return trace(new PIntSlice(getLanguage(), start, stop, step, isStartNone, isStepNone));
- }
-
- public final PObjectSlice createObjectSlice(Object start, Object stop, Object step) {
- return trace(new PObjectSlice(getLanguage(), start, stop, step));
- }
-
- public final PRandom createRandom(Object cls) {
- return trace(new PRandom(cls, getShape(cls)));
- }
-
- /*
- * Classes, methods and functions
- */
-
- /**
- * Only to be used during context creation
- */
- public final PythonModule createPythonModule(TruffleString name) {
- return trace(PythonModule.createInternal(name));
- }
-
- public final PythonModule createPythonModule(Object cls) {
- return trace(new PythonModule(cls, getShape(cls)));
- }
-
- public final PythonClass createPythonClassAndFixupSlots(PythonLanguage language, Object metaclass, TruffleString name, Object base, PythonAbstractClass[] bases) {
- PythonClass result = trace(new PythonClass(language, metaclass, getShape(metaclass), name, base, bases));
- // Fixup tp slots
- MroSequenceStorage mro = GetMroStorageNode.executeUncached(result);
- SpecialMethodSlot.initializeSpecialMethodSlots(result, mro, language);
- TpSlots.inherit(result, mro, true);
- TpSlots.fixupSlotDispatchers(result);
- result.initializeMroShape(language);
- return result;
- }
-
- public final PythonClass createPythonClass(Object metaclass, TruffleString name, boolean invokeMro, Object base, PythonAbstractClass[] bases) {
- // Note: called from type ctor, which itself will invoke setupSpecialMethodSlots at the
- // right point
- return trace(new PythonClass(getLanguage(), metaclass, getShape(metaclass), name, invokeMro, base, bases));
- }
-
- public final PMemoryView createMemoryView(PythonContext context, BufferLifecycleManager bufferLifecycleManager, Object buffer, Object owner,
- int len, boolean readonly, int itemsize, BufferFormat format, TruffleString formatString, int ndim, Object bufPointer,
- int offset, int[] shape, int[] strides, int[] suboffsets, int flags) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
- return trace(new PMemoryView(cls, getShape(cls), context, bufferLifecycleManager, buffer, owner, len, readonly, itemsize, format, formatString,
- ndim, bufPointer, offset, shape, strides, suboffsets, flags));
- }
-
- private final PMemoryView createMemoryView(PythonContext context, BufferLifecycleManager bufferLifecycleManager, Object buffer, Object owner,
- int len, boolean readonly, int itemsize, TruffleString formatString, int ndim, Object bufPointer,
- int offset, int[] shape, int[] strides, int[] suboffsets, int flags, TruffleString.CodePointLengthNode lengthNode, TruffleString.CodePointAtIndexNode atIndexNode) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
- return trace(new PMemoryView(cls, getShape(cls), context, bufferLifecycleManager, buffer, owner, len, readonly, itemsize,
- BufferFormat.forMemoryView(formatString, lengthNode, atIndexNode), formatString, ndim, bufPointer, offset, shape, strides, suboffsets, flags));
- }
-
- public final PMemoryView createMemoryViewForManagedObject(Object buffer, Object owner, int itemsize, int length, boolean readonly, TruffleString format,
- TruffleString.CodePointLengthNode lengthNode, TruffleString.CodePointAtIndexNode atIndexNode) {
- return createMemoryView(null, null, buffer, owner, length, readonly, itemsize, format, 1,
- null, 0, new int[]{length / itemsize}, new int[]{itemsize}, null,
- PMemoryView.FLAG_C | PMemoryView.FLAG_FORTRAN, lengthNode, atIndexNode);
- }
-
- public final PMemoryView createMemoryViewForManagedObject(Object owner, int itemsize, int length, boolean readonly, TruffleString format, TruffleString.CodePointLengthNode lengthNode,
- TruffleString.CodePointAtIndexNode atIndexNode) {
- return createMemoryViewForManagedObject(owner, owner, itemsize, length, readonly, format, lengthNode, atIndexNode);
- }
-
- public final PMethod createMethod(Object cls, Object self, Object function) {
- return trace(new PMethod(cls, getShape(cls), self, function));
- }
-
- public final PMethod createMethod(Object self, Object function) {
- return createMethod(PythonBuiltinClassType.PMethod, self, function);
- }
-
- public final PMethod createBuiltinMethod(Object self, PFunction function) {
- return createMethod(PythonBuiltinClassType.PBuiltinFunctionOrMethod, self, function);
- }
-
- public final PBuiltinMethod createBuiltinMethod(Object cls, Object self, PBuiltinFunction function) {
- return trace(new PBuiltinMethod(cls, getShape(cls), self, function, null));
- }
-
- public final PBuiltinMethod createBuiltinMethod(Object self, PBuiltinFunction function, Object classObject) {
- return trace(new PBuiltinMethod(PythonBuiltinClassType.PBuiltinMethod, getShape(PythonBuiltinClassType.PBuiltinMethod), self, function, classObject));
- }
-
- public final PBuiltinMethod createBuiltinMethod(Object self, PBuiltinFunction function) {
- return createBuiltinMethod(PythonBuiltinClassType.PBuiltinFunctionOrMethod, self, function);
- }
-
- public final PFunction createFunction(TruffleString name, PCode code, PythonObject globals, PCell[] closure) {
- return trace(new PFunction(getLanguage(), name, name, code, globals, closure));
- }
-
- public final PFunction createFunction(TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
- return trace(new PFunction(getLanguage(), name, qualname, code, globals, defaultValues, kwDefaultValues, closure));
- }
-
- public final PFunction createFunction(TruffleString name, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
- return trace(new PFunction(getLanguage(), name, name, code, globals, defaultValues, kwDefaultValues, closure));
- }
-
- public final PFunction createFunction(TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure,
- Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
- return trace(new PFunction(getLanguage(), name, qualname, code, globals, defaultValues, kwDefaultValues, closure,
- codeStableAssumption, defaultsStableAssumption));
- }
-
- public final PBuiltinFunction createBuiltinFunction(TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget) {
- return trace(new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(getLanguage()), name, type,
- PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget));
- }
-
- public final PBuiltinFunction createBuiltinFunction(TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget) {
- return trace(new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(getLanguage()), name, type, defaults, kw, flags,
- callTarget));
- }
-
- public final PBuiltinFunction createWrapperDescriptor(TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget, TpSlot slot, PExternalFunctionWrapper slotWrapper) {
- return trace(new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(getLanguage()), name, type,
- PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget, slot, slotWrapper));
- }
-
- public final PBuiltinFunction createWrapperDescriptor(TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget, TpSlot slot,
- PExternalFunctionWrapper slotWrapper) {
- return trace(new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(getLanguage()), name, type, defaults, kw, flags,
- callTarget, slot, slotWrapper));
- }
-
- public final PBuiltinFunction createBuiltinFunction(PBuiltinFunction function, Object klass) {
- PythonBuiltinClassType type = (PythonBuiltinClassType) function.getInitialPythonClass();
- return trace(new PBuiltinFunction(type, type.getInstanceShape(getLanguage()), function.getName(), klass,
- function.getDefaults(), function.getKwDefaults(), function.getFlags(), function.getCallTarget(),
- function.getSlot(), function.getSlotWrapper()));
- }
-
- public final GetSetDescriptor createGetSetDescriptor(Object get, Object set, TruffleString name, Object type) {
- return trace(new GetSetDescriptor(getLanguage(), get, set, name, type));
- }
-
- public final GetSetDescriptor createGetSetDescriptor(Object get, Object set, TruffleString name, Object type, boolean allowsDelete) {
- return trace(new GetSetDescriptor(getLanguage(), get, set, name, type, allowsDelete));
- }
-
- public final GetSetDescriptor createMemberDescriptor(Object get, Object set, TruffleString name, Object type) {
- return trace(new GetSetDescriptor(PythonBuiltinClassType.MemberDescriptor, PythonBuiltinClassType.MemberDescriptor.getInstanceShape(getLanguage()), get, set, name, type, set != null));
- }
-
- public final IndexedSlotDescriptor createIndexedSlotDescriptor(TruffleString name, int index, Object type) {
- return trace(new IndexedSlotDescriptor(getLanguage(), name, index, type));
- }
-
- public final PDecoratedMethod createClassmethod(Object cls) {
- return trace(new PDecoratedMethod(cls, getShape(cls)));
- }
-
- public final PDecoratedMethod createClassmethodFromCallableObj(Object callable) {
- return trace(new PDecoratedMethod(PythonBuiltinClassType.PClassmethod, PythonBuiltinClassType.PClassmethod.getInstanceShape(getLanguage()), callable));
- }
-
- public final PDecoratedMethod createBuiltinClassmethodFromCallableObj(Object callable) {
- return trace(new PDecoratedMethod(PythonBuiltinClassType.PBuiltinClassMethod, PythonBuiltinClassType.PBuiltinClassMethod.getInstanceShape(getLanguage()), callable));
- }
-
- public final PDecoratedMethod createInstancemethod(Object cls) {
- return trace(new PDecoratedMethod(cls, getShape(cls)));
- }
-
- public final PDecoratedMethod createStaticmethod(Object cls) {
- return trace(new PDecoratedMethod(cls, getShape(cls)));
- }
-
- public final PDecoratedMethod createStaticmethodFromCallableObj(Object callable) {
- Object func = callable;
- if (func instanceof PBuiltinFunction) {
- /*
- * CPython's C static methods contain an object of type `builtin_function_or_method`
- * (our PBuiltinMethod). Their self points to their type, but when called they get NULL
- * as the first argument instead.
- */
- func = createBuiltinMethod(((PBuiltinFunction) func).getEnclosingType(), (PBuiltinFunction) func);
- }
- return trace(new PDecoratedMethod(PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PStaticmethod.getInstanceShape(getLanguage()), func));
- }
-
- /*
- * Lists, sets and dicts
- */
-
- public final PList createList() {
- return createList(PythonUtils.EMPTY_OBJECT_ARRAY);
- }
-
- public final PList createList(SequenceStorage storage) {
- return createList(PythonBuiltinClassType.PList, storage);
- }
-
- public final PList createList(Object cls, Shape instanceShape, SequenceStorage storage) {
- return trace(new PList(cls, instanceShape, storage));
- }
-
- public final PList createList(SequenceStorage storage, ListOrigin origin) {
- return trace(new PList(PythonBuiltinClassType.PList, PythonBuiltinClassType.PList.getInstanceShape(getLanguage()), storage, origin));
- }
-
- public final PList createList(Object cls, SequenceStorage storage) {
- return trace(new PList(cls, getShape(cls), storage));
- }
-
- public final PList createList(Object cls) {
- return createList(cls, PythonUtils.EMPTY_OBJECT_ARRAY);
- }
-
- public final PList createList(Object[] array) {
- return createList(PythonBuiltinClassType.PList, array);
- }
-
- public final PList createList(Object cls, Object[] array) {
- return trace(new PList(cls, getShape(cls), SequenceStorageFactory.createStorage(array)));
- }
-
- public final PSet createSet() {
- Shape shape = PythonBuiltinClassType.PSet.getInstanceShape(getLanguage());
- return trace(new PSet(PythonBuiltinClassType.PSet, shape));
- }
-
- public final PSet createSet(Object cls) {
- return trace(new PSet(cls, getShape(cls)));
- }
-
- public final PSet createSet(Object cls, Shape instanceShape) {
- return trace(new PSet(cls, instanceShape));
- }
-
- public final PSet createSet(HashingStorage storage) {
- Shape shape = PythonBuiltinClassType.PSet.getInstanceShape(getLanguage());
- return trace(new PSet(PythonBuiltinClassType.PSet, shape, storage));
- }
-
- public final PFrozenSet createFrozenSet(Object cls) {
- return trace(new PFrozenSet(cls, getShape(cls)));
- }
-
- public final PFrozenSet createFrozenSet(Object cls, HashingStorage storage) {
- return trace(new PFrozenSet(cls, getShape(cls), storage));
- }
-
- public final PFrozenSet createFrozenSet(HashingStorage storage) {
- Shape shape = PythonBuiltinClassType.PFrozenSet.getInstanceShape(getLanguage());
- return trace(new PFrozenSet(PythonBuiltinClassType.PFrozenSet, shape, storage));
- }
-
- public final PDict createDict() {
- Shape shape = PythonBuiltinClassType.PDict.getInstanceShape(getLanguage());
- return trace(new PDict(PythonBuiltinClassType.PDict, shape));
- }
-
- public final PDict createDict(PKeyword[] keywords) {
- Shape shape = PythonBuiltinClassType.PDict.getInstanceShape(getLanguage());
- return trace(new PDict(PythonBuiltinClassType.PDict, shape, keywords));
- }
-
- public final PDict createDict(Object cls) {
- return trace(new PDict(cls, getShape(cls)));
- }
-
- public final POrderedDict createOrderedDict(Object cls) {
- return trace(new POrderedDict(cls, getShape(cls)));
- }
-
- public final PDictKeysView createOrderedDictKeys(POrderedDict dict) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictKeys;
- return trace(new PDictKeysView(cls, cls.getInstanceShape(getLanguage()), dict));
- }
-
- public final PDictValuesView createOrderedDictValues(POrderedDict dict) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictValues;
- return trace(new PDictValuesView(cls, cls.getInstanceShape(getLanguage()), dict));
- }
-
- public final PDictItemsView createOrderedDictItems(POrderedDict dict) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictItems;
- return trace(new PDictItemsView(cls, cls.getInstanceShape(getLanguage()), dict));
- }
-
- public POrderedDictIterator createOrderedDictIterator(POrderedDict dict, POrderedDictIterator.IteratorType type, boolean reversed) {
- PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictIterator;
- return trace(new POrderedDictIterator(cls, cls.getInstanceShape(getLanguage()), dict, type, reversed));
- }
-
- @SuppressWarnings("unchecked")
- public final PDict createDictFromMap(LinkedHashMap map) {
- return createDict(EconomicMapStorage.create(map));
- }
-
- /**
- * Generic version of {@link #createDictFromMap(LinkedHashMap)} that allows any type of keys.
- * Note that this means that unless the keys are known to be side effect free, e.g., builtin
- * types, this may end up calling Python code, so indirect call context should be properly
- * set-up. This helper is meant for Truffle boundary code, in PE code build a storage by setting
- * elements one by one starting from empty storage.
- */
- @SuppressWarnings("unchecked")
- public final PDict createDictFromMapGeneric(LinkedHashMap map) {
- return createDict(EconomicMapStorage.createGeneric(map));
- }
-
- public final PDict createDictFixedStorage(PythonObject pythonObject, MroSequenceStorage mroSequenceStorage) {
- return createDict(new DynamicObjectStorage(pythonObject, mroSequenceStorage));
- }
-
- public final PDict createDictFixedStorage(PythonObject pythonObject) {
- return createDict(new DynamicObjectStorage(pythonObject));
- }
-
- public final PDict createDict(Object cls, HashingStorage storage) {
- return trace(new PDict(cls, getShape(cls), storage));
- }
-
- public final PDict createDict(HashingStorage storage) {
- return createDict(PythonBuiltinClassType.PDict, storage);
- }
-
- public final PDict createDict(Object cls, Shape instanceShape, HashingStorage storage) {
- return trace(new PDict(cls, instanceShape, storage));
- }
-
- public final PSimpleNamespace createSimpleNamespace() {
- return createSimpleNamespace(PythonBuiltinClassType.PSimpleNamespace);
- }
-
- public final PSimpleNamespace createSimpleNamespace(Object cls) {
- return createSimpleNamespace(cls, getShape(cls));
- }
-
- public final PSimpleNamespace createSimpleNamespace(Object cls, Shape instanceShape) {
- return trace(new PSimpleNamespace(cls, instanceShape));
- }
-
- public final PKeyWrapper createKeyWrapper(Object cmp) {
- return trace(new PKeyWrapper(PythonBuiltinClassType.PKeyWrapper, getShape(PythonBuiltinClassType.PKeyWrapper), cmp));
- }
-
- public final PPartial createPartial(Object cls, Object function, Object[] args, PDict kwDict) {
- return trace(new PPartial(cls, getShape(cls), function, args, kwDict));
- }
-
- public LruCacheObject createLruCacheObject(Object cls) {
- return trace(new LruCacheObject(cls, getShape(cls)));
- }
-
- public final PDefaultDict createDefaultDict(Object cls) {
- return createDefaultDict(cls, PNone.NONE);
- }
-
- public final PDefaultDict createDefaultDict(Object cls, Object defaultFactory) {
- return trace(new PDefaultDict(cls, getShape(cls), defaultFactory));
- }
-
- public final PDefaultDict createDefaultDict(Object defaultFactory, HashingStorage storage) {
- return createDefaultDict(PythonBuiltinClassType.PDefaultDict, defaultFactory, storage);
- }
-
- public final PDefaultDict createDefaultDict(Object cls, Object defaultFactory, HashingStorage storage) {
- return trace(new PDefaultDict(cls, getShape(cls), storage, defaultFactory));
- }
-
- public final PDictView createDictKeysView(PHashingCollection dict) {
- return trace(new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(getLanguage()), dict));
- }
-
- public final PDictView createDictKeysView(Object dict, ForeignHashingStorage foreignHashingStorage) {
- return trace(new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(getLanguage()), dict, foreignHashingStorage));
- }
-
- public final PDictView createDictValuesView(PHashingCollection dict) {
- return trace(new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(getLanguage()), dict));
- }
-
- public final PDictView createDictValuesView(Object dict, ForeignHashingStorage foreignHashingStorage) {
- return trace(new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(getLanguage()), dict, foreignHashingStorage));
- }
-
- public final PDictView createDictItemsView(PHashingCollection dict) {
- return trace(new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(getLanguage()), dict));
- }
-
- public final PDictView createDictItemsView(Object dict, ForeignHashingStorage foreignHashingStorage) {
- return trace(new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(getLanguage()), dict, foreignHashingStorage));
- }
-
- /*
- * Special objects: generators, proxies, references, cells
- */
-
- public final PGenerator createGenerator(TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return trace(PGenerator.create(getLanguage(), name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator));
- }
-
- public final PGenerator createIterableCoroutine(TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return trace(PGenerator.create(getLanguage(), name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator, true));
- }
-
- public final PGenerator createCoroutine(TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return trace(PGenerator.create(getLanguage(), name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PCoroutine));
- }
-
- public final PCoroutineWrapper createCoroutineWrapper(PGenerator generator) {
- return trace(new PCoroutineWrapper(getLanguage(), generator));
- }
-
- public final PAsyncGen createAsyncGenerator(TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return trace(PAsyncGen.create(getLanguage(), name, qualname, rootNode, callTargets, arguments));
- }
-
- public final PMappingproxy createMappingproxy(Object object) {
- PythonBuiltinClassType mpClass = PythonBuiltinClassType.PMappingproxy;
- return trace(new PMappingproxy(mpClass, mpClass.getInstanceShape(getLanguage()), object));
- }
-
- public final PMappingproxy createMappingproxy(Object cls, Object object) {
- return trace(new PMappingproxy(cls, getShape(cls), object));
- }
-
- public final PReferenceType createReferenceType(Object cls, Object object, Object callback, ReferenceQueue queue) {
- return trace(new PReferenceType(cls, getShape(cls), object, callback, queue));
- }
-
- public final PReferenceType createReferenceType(Object object, Object callback, ReferenceQueue queue) {
- return createReferenceType(PythonBuiltinClassType.PReferenceType, object, callback, queue);
- }
-
- public final PCell createCell(Assumption effectivelyFinal) {
- return trace(new PCell(effectivelyFinal));
- }
-
- /*
- * Frames, traces and exceptions
- */
-
- public final PFrame createPFrame(PFrame.Reference frameInfo, Node location, MaterializedFrame locals) {
- return trace(new PFrame(getLanguage(), frameInfo, location, locals));
- }
-
- public final PFrame createPFrame(Object threadState, PCode code, PythonObject globals, Object localsDict) {
- return trace(new PFrame(getLanguage(), threadState, code, globals, localsDict));
- }
-
- public final PTraceback createTraceback(PFrame frame, int lineno, PTraceback next) {
- return trace(new PTraceback(getLanguage(), frame, lineno, -1, next));
- }
-
- public final PTraceback createTracebackWithLasti(PFrame frame, int lineno, int lasti, PTraceback next) {
- return trace(new PTraceback(getLanguage(), frame, lineno, lasti, next));
- }
-
- public final PTraceback createTraceback(LazyTraceback tb) {
- return trace(new PTraceback(getLanguage(), tb));
- }
-
- public final PBaseException createBaseException(Object cls, PTuple args) {
- return createBaseException(cls, null, args);
- }
-
- public final PBaseException createBaseException(Object cls, Object[] data, PTuple args) {
- return trace(new PBaseException(cls, getShape(cls), data, args));
- }
-
- /*
- * Note: we use this method to convert a Java StackOverflowError into a Python RecursionError.
- * At the time when this is done, some Java stack frames were already unwinded but there is no
- * guarantee on how many. Therefore, it is important that this method is simple. In particular,
- * do not add calls if that can be avoided.
- */
- public final PBaseException createBaseException(Object cls, TruffleString format, Object[] args) {
- return createBaseException(cls, null, format, args);
- }
-
- public final PBaseException createBaseException(Object cls, Object[] data, TruffleString format, Object[] args) {
- assert format != null;
- return trace(new PBaseException(cls, getShape(cls), data, format, args));
- }
-
- public final PBaseException createBaseException(Object cls) {
- return trace(new PBaseException(cls, getShape(cls), null));
- }
-
- public final PBaseException createBaseException(Object cls, Object[] data) {
- return trace(new PBaseException(cls, getShape(cls), data));
- }
-
- public final PBaseExceptionGroup createBaseExceptionGroup(Object cls, TruffleString message, Object[] exceptions, Object[] args) {
- return trace(new PBaseExceptionGroup(cls, getShape(cls), message, exceptions, createTuple(args)));
- }
-
- /*
- * Arrays
- */
-
- public final PArray createArray(Object cls, TruffleString formatString, BufferFormat format) {
- assert format != null;
- return trace(new PArray(cls, getShape(cls), formatString, format));
- }
-
- public final PArray createArray(TruffleString formatString, BufferFormat format, int length) throws OverflowException {
- return createArray(PythonBuiltinClassType.PArray, formatString, format, length);
- }
-
- public final PArray createArray(Object cls, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
- assert format != null;
- return trace(new PArray(cls, getShape(cls), formatString, format, length));
- }
-
- public final PByteArray createByteArray(byte[] array) {
- return createByteArray(array, array.length);
- }
-
- public final PByteArray createByteArray(Object cls, byte[] array) {
- return createByteArray(cls, array, array.length);
- }
-
- public final PByteArray createByteArray(byte[] array, int length) {
- return createByteArray(new ByteSequenceStorage(array, length));
- }
-
- public final PByteArray createByteArray(Object cls, byte[] array, int length) {
- return createByteArray(cls, new ByteSequenceStorage(array, length));
- }
-
- public final PByteArray createByteArray(SequenceStorage storage) {
- return createByteArray(PythonBuiltinClassType.PByteArray, storage);
- }
-
- public final PByteArray createByteArray(Object cls, SequenceStorage storage) {
- return trace(new PByteArray(cls, getShape(cls), storage));
- }
-
- /*
- * Iterators
- */
-
- public final PStringIterator createStringIterator(TruffleString str) {
- return trace(new PStringIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), str));
- }
-
- public final PStringReverseIterator createStringReverseIterator(Object cls, TruffleString str) {
- return trace(new PStringReverseIterator(cls, getShape(cls), str));
- }
-
- public final PIntegerSequenceIterator createIntegerSequenceIterator(IntSequenceStorage storage, Object list) {
- return trace(new PIntegerSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), storage, list));
- }
-
- public final PLongSequenceIterator createLongSequenceIterator(LongSequenceStorage storage, Object list) {
- return trace(new PLongSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), storage, list));
- }
-
- public final PDoubleSequenceIterator createDoubleSequenceIterator(DoubleSequenceStorage storage, Object list) {
- return trace(new PDoubleSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), storage, list));
- }
-
- public final PObjectSequenceIterator createObjectSequenceIterator(ObjectSequenceStorage storage, Object list) {
- return trace(new PObjectSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), storage, list));
- }
-
- public final PSequenceIterator createSequenceIterator(Object sequence) {
- return trace(new PSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), sequence));
- }
-
- public final PSequenceReverseIterator createSequenceReverseIterator(Object cls, Object sequence, int lengthHint) {
- return trace(new PSequenceReverseIterator(cls, getShape(cls), sequence, lengthHint));
- }
-
- public final PIntRangeIterator createIntRangeIterator(PIntRange fastRange) {
- return createIntRangeIterator(fastRange.getIntStart(), fastRange.getIntStop(), fastRange.getIntStep(), fastRange.getIntLength());
- }
-
- public final PIntRangeIterator createIntRangeIterator(int start, int stop, int step, int len) {
- return trace(new PIntRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), start, stop, step, len));
- }
-
- public final PBigRangeIterator createBigRangeIterator(PInt start, PInt stop, PInt step, PInt len) {
- return trace(new PBigRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), start, stop, step, len));
- }
-
- public final PBigRangeIterator createBigRangeIterator(PBigRange longRange) {
- return createBigRangeIterator(longRange.getPIntStart(), longRange.getPIntStop(), longRange.getPIntStep(), longRange.getPIntLength());
- }
-
- public final PBigRangeIterator createBigRangeIterator(BigInteger start, BigInteger stop, BigInteger step, BigInteger len) {
- return createBigRangeIterator(createInt(start), createInt(stop), createInt(step), createInt(len));
- }
-
- public final PArrayIterator createArrayIterator(PArray array) {
- return trace(new PArrayIterator(PythonBuiltinClassType.PArrayIterator, PythonBuiltinClassType.PArrayIterator.getInstanceShape(getLanguage()), array));
- }
-
- public final PBaseSetIterator createBaseSetIterator(PBaseSet set, HashingStorageNodes.HashingStorageIterator iterator, int initialSize) {
- return trace(new PBaseSetIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(getLanguage()), set, iterator, initialSize));
- }
-
- public final PDictItemIterator createDictItemIterator(HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return trace(new PDictItemIterator(PythonBuiltinClassType.PDictItemIterator, PythonBuiltinClassType.PDictItemIterator.getInstanceShape(getLanguage()), iterator, hashingStorage, initialSize));
- }
-
- public final PDictKeyIterator createDictKeyIterator(HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return trace(new PDictKeyIterator(PythonBuiltinClassType.PDictKeyIterator, PythonBuiltinClassType.PDictKeyIterator.getInstanceShape(getLanguage()), iterator, hashingStorage, initialSize));
- }
-
- public final PDictValueIterator createDictValueIterator(HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return trace(new PDictValueIterator(PythonBuiltinClassType.PDictValueIterator, PythonBuiltinClassType.PDictValueIterator.getInstanceShape(getLanguage()), iterator, hashingStorage,
- initialSize));
- }
-
- public final Object createSentinelIterator(Object callable, Object sentinel) {
- return trace(new PSentinelIterator(PythonBuiltinClassType.PSentinelIterator, PythonBuiltinClassType.PSentinelIterator.getInstanceShape(getLanguage()), callable, sentinel));
- }
-
- public final PEnumerate createEnumerate(Object cls, Object iterator, long start) {
- return trace(new PEnumerate(cls, getShape(cls), iterator, start));
- }
-
- public final PEnumerate createEnumerate(Object cls, Object iterator, PInt start) {
- return trace(new PEnumerate(cls, getShape(cls), iterator, start));
- }
-
- public final PMap createMap(Object cls) {
- return trace(new PMap(cls, getShape(cls)));
- }
-
- public final PZip createZip(Object cls, Object[] iterables, boolean strict) {
- return trace(new PZip(cls, getShape(cls), iterables, strict));
- }
-
- public final PCode createCode(RootCallTarget ct) {
- return trace(new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(getLanguage()), ct));
- }
-
- public final PCode createCode(RootCallTarget ct, int flags, int firstlineno, byte[] linetable, TruffleString filename) {
- return trace(new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(getLanguage()), ct, flags, firstlineno, linetable, filename));
- }
-
- public final PCode createCode(RootCallTarget callTarget, Signature signature, CodeUnit codeUnit) {
- return trace(new PCode(PythonBuiltinClassType.PCode, getShape(PythonBuiltinClassType.PCode), callTarget, signature, codeUnit));
- }
-
- public final PCode createCode(RootCallTarget callTarget, Signature signature, int nlocals,
- int stacksize, int flags, Object[] constants,
- TruffleString[] names, TruffleString[] varnames,
- TruffleString[] freevars, TruffleString[] cellvars,
- TruffleString filename, TruffleString name, TruffleString qualname,
- int firstlineno, byte[] linetable) {
- return trace(new PCode(PythonBuiltinClassType.PCode, getShape(PythonBuiltinClassType.PCode), callTarget, signature,
- nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars,
- filename, name, qualname, firstlineno, linetable));
- }
-
- public PCode createCode(Supplier createCode, int flags, int firstlineno, byte[] lnotab, TruffleString filename) {
- return trace(new PCode(PythonBuiltinClassType.PCode, getShape(PythonBuiltinClassType.PCode), createCode, flags, firstlineno, lnotab, filename));
- }
-
- /*
- * Socket
- */
-
- public final PSocket createSocket(Object cls) {
- return trace(new PSocket(cls, getShape(cls)));
- }
-
- /*
- * Threading
- */
-
- public PThreadLocal createThreadLocal(Object cls, Object[] args, PKeyword[] kwArgs) {
- return trace(new PThreadLocal(cls, getShape(cls), args, kwArgs));
- }
-
- public final PLock createLock() {
- return createLock(PythonBuiltinClassType.PLock);
- }
-
- public final PLock createLock(Object cls) {
- return trace(new PLock(cls, getShape(cls)));
- }
-
- public final PRLock createRLock() {
- return createRLock(PythonBuiltinClassType.PRLock);
- }
-
- public final PRLock createRLock(Object cls) {
- return trace(new PRLock(cls, getShape(cls)));
- }
-
- public final PThread createPythonThread(Thread thread) {
- return trace(new PThread(PythonBuiltinClassType.PThread, PythonBuiltinClassType.PThread.getInstanceShape(getLanguage()), thread));
- }
-
- public final PThread createPythonThread(Object cls, Thread thread) {
- return trace(new PThread(cls, getShape(cls), thread));
- }
-
- public final PSemLock createSemLock(Object cls, long handle, int kind, int maxValue, TruffleString name) {
- return trace(new PSemLock(cls, getShape(cls), handle, kind, maxValue, name));
- }
-
- public final PGraalPySemLock createGraalPySemLock(Object cls, TruffleString name, int kind, Semaphore sharedSemaphore) {
- return trace(new PGraalPySemLock(cls, getShape(cls), name, kind, sharedSemaphore));
- }
-
- public final PScandirIterator createScandirIterator(PythonContext context, Object dirStream, PosixFileHandle path, boolean needsRewind) {
- return trace(new PScandirIterator(PythonBuiltinClassType.PScandirIterator, PythonBuiltinClassType.PScandirIterator.getInstanceShape(getLanguage()), context, dirStream, path, needsRewind));
- }
-
- public final PDirEntry createDirEntry(Object dirEntryData, PosixFileHandle path) {
- return trace(new PDirEntry(PythonBuiltinClassType.PDirEntry, PythonBuiltinClassType.PDirEntry.getInstanceShape(getLanguage()), dirEntryData, path));
- }
-
- public final PEncodingMap createEncodingMap(int count2, int count3, byte[] level1, byte[] level23) {
- return trace(new PEncodingMap(PythonBuiltinClassType.PEncodingMap, PythonBuiltinClassType.PEncodingMap.getInstanceShape(getLanguage()), count2, count3, level1, level23));
- }
-
- public final PMMap createMMap(PythonContext context, Object clazz, Object mmapHandle, int fd, long length, int access) {
- return trace(new PMMap(clazz, getShape(clazz), context, mmapHandle, fd, length, access));
- }
-
- public final BZ2Object.BZ2Compressor createBZ2Compressor(Object clazz) {
- return trace(BZ2Object.createCompressor(clazz, getShape(clazz)));
- }
-
- public final BZ2Object.BZ2Decompressor createBZ2Decompressor(Object clazz) {
- return trace(BZ2Object.createDecompressor(clazz, getShape(clazz)));
- }
-
- public final ZLibCompObject createJavaZLibCompObject(Object clazz, Object stream, int level, int wbits, int strategy, byte[] zdict) {
- return trace(ZLibCompObject.createJava(clazz, getShape(clazz), stream, level, wbits, strategy, zdict));
- }
-
- public final ZLibCompObject createJavaZLibCompObject(Object clazz, Object stream, int wbits, byte[] zdict) {
- return trace(ZLibCompObject.createJava(clazz, getShape(clazz), stream, wbits, zdict));
- }
-
- public final ZLibCompObject createNativeZLibCompObject(Object clazz, Object zst, NFIZlibSupport zlibSupport) {
- return trace(ZLibCompObject.createNative(clazz, getShape(clazz), zst, zlibSupport));
- }
-
- public final LZMAObject.LZMADecompressor createLZMADecompressor(Object clazz, boolean isNative) {
- return trace(LZMAObject.createDecompressor(clazz, getShape(clazz), isNative));
- }
-
- public final LZMAObject.LZMACompressor createLZMACompressor(Object clazz, boolean isNative) {
- return trace(LZMAObject.createCompressor(clazz, getShape(clazz), isNative));
- }
-
- public final CSVReader createCSVReader(Object clazz, Object inputIter, CSVDialect dialect) {
- return trace(new CSVReader(clazz, getShape(clazz), inputIter, dialect));
- }
-
- public final CSVWriter createCSVWriter(Object clazz, Object write, CSVDialect dialect) {
- return trace(new CSVWriter(clazz, getShape(clazz), write, dialect));
- }
-
- public final CSVDialect createCSVDialect(Object clazz, TruffleString delimiter, int delimiterCodePoint, boolean doubleQuote, TruffleString escapeChar, int escapeCharCodePoint,
- TruffleString lineTerminator, TruffleString quoteChar, int quoteCharCodePoint, QuoteStyle quoting, boolean skipInitialSpace, boolean strict) {
- return trace(new CSVDialect(clazz, getShape(clazz), delimiter, delimiterCodePoint, doubleQuote, escapeChar, escapeCharCodePoint, lineTerminator, quoteChar, quoteCharCodePoint, quoting,
- skipInitialSpace, strict));
- }
-
- public final PFileIO createFileIO(Object clazz) {
- return trace(new PFileIO(clazz, getShape(clazz)));
- }
-
- public final PChain createChain(Object cls) {
- return trace(new PChain(cls, getShape(cls)));
- }
-
- public final PCount createCount(Object cls) {
- return trace(new PCount(cls, getShape(cls)));
- }
-
- public final PIslice createIslice(Object cls) {
- return trace(new PIslice(cls, getShape(cls)));
- }
-
- public final PPairwise createPairwise(Object cls) {
- return trace(new PPairwise(cls, getShape(cls)));
- }
-
- public final PPermutations createPermutations(Object cls) {
- return trace(new PPermutations(cls, getShape(cls)));
- }
-
- public final PProduct createProduct(Object cls) {
- return trace(new PProduct(cls, getShape(cls)));
- }
-
- public final PRepeat createRepeat(Object cls) {
- return trace(new PRepeat(cls, getShape(cls)));
- }
-
- public final PAccumulate createAccumulate(Object cls) {
- return trace(new PAccumulate(cls, getShape(cls)));
- }
-
- public final PDropwhile createDropwhile(Object cls) {
- return trace(new PDropwhile(cls, getShape(cls)));
- }
-
- public final PCombinations createCombinations(Object cls) {
- return trace(new PCombinations(cls, getShape(cls)));
- }
-
- public final PCombinationsWithReplacement createCombinationsWithReplacement(Object cls) {
- return trace(new PCombinationsWithReplacement(cls, getShape(cls)));
- }
-
- public final PCompress createCompress(Object cls) {
- return trace(new PCompress(cls, getShape(cls)));
- }
-
- public final PCycle createCycle(Object cls) {
- return trace(new PCycle(cls, getShape(cls)));
- }
-
- public final PFilterfalse createFilterfalse(Object cls) {
- return trace(new PFilterfalse(cls, getShape(cls)));
- }
-
- public final PGroupBy createGroupBy(Object cls) {
- return trace(new PGroupBy(cls, getShape(cls)));
- }
-
- public final PGrouper createGrouper(Object cls) {
- return trace(new PGrouper(cls, getShape(cls)));
- }
-
- public final PGrouper createGrouper(PGroupBy parent, Object tgtKey) {
- return trace(new PGrouper(parent, tgtKey, PythonBuiltinClassType.PGrouper, PythonBuiltinClassType.PGrouper.getInstanceShape(getLanguage())));
- }
-
- public final PTee createTee() {
- return trace(new PTee(PythonBuiltinClassType.PTee, PythonBuiltinClassType.PTee.getInstanceShape(getLanguage())));
- }
-
- public final PTee createTee(PTeeDataObject dataObj, int index) {
- return trace(new PTee(dataObj, index, PythonBuiltinClassType.PTee, PythonBuiltinClassType.PTee.getInstanceShape(getLanguage())));
- }
-
- public final PStarmap createStarmap(Object cls) {
- return trace(new PStarmap(cls, getShape(cls)));
- }
-
- public final PTakewhile createTakewhile(Object cls) {
- return trace(new PTakewhile(cls, getShape(cls)));
- }
-
- public final PTeeDataObject createTeeDataObject() {
- return trace(new PTeeDataObject(PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(getLanguage())));
- }
-
- public final PTeeDataObject createTeeDataObject(Object it) {
- return trace(new PTeeDataObject(it, PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(getLanguage())));
- }
-
- public final PZipLongest createZipLongest(Object cls) {
- return trace(new PZipLongest(cls, getShape(cls)));
- }
-
- public final PTextIO createTextIO(Object clazz) {
- return trace(new PTextIO(clazz, getShape(clazz)));
- }
-
- public final PStringIO createStringIO(Object clazz) {
- return trace(new PStringIO(clazz, getShape(clazz)));
- }
-
- public final PBytesIO createBytesIO(Object clazz) {
- return trace(new PBytesIO(clazz, getShape(clazz)));
- }
-
- public final PBytesIOBuffer createBytesIOBuf(Object clazz, PBytesIO source) {
- return trace(new PBytesIOBuffer(clazz, getShape(clazz), source));
- }
-
- public final PNLDecoder createNLDecoder(Object clazz) {
- return trace(new PNLDecoder(clazz, getShape(clazz)));
- }
-
- public final PBuffered createBufferedReader(Object clazz) {
- return trace(new PBuffered(clazz, getShape(clazz), true, false));
- }
-
- public final PBuffered createBufferedWriter(Object clazz) {
- return trace(new PBuffered(clazz, getShape(clazz), false, true));
- }
-
- public final PBuffered createBufferedRandom(Object clazz) {
- return trace(new PBuffered(clazz, getShape(clazz), true, true));
- }
-
- public final PRWPair createRWPair(Object clazz) {
- return trace(new PRWPair(clazz, getShape(clazz)));
- }
-
- public final PyCArgObject createCArgObject() {
- return trace(new PyCArgObject(PythonBuiltinClassType.CArgObject, getShape(PythonBuiltinClassType.CArgObject)));
- }
-
- public final CThunkObject createCThunkObject(Object clazz, int nArgs) {
- return trace(new CThunkObject(clazz, getShape(clazz), nArgs));
- }
-
- public final StructParamObject createStructParamObject(Object clazz) {
- return trace(new StructParamObject(clazz, getShape(clazz)));
- }
-
- // Don't use directly, use CtypesNodes.CreateCDataObjectNode
- public final CDataObject createCDataObject(Object clazz, Pointer b_ptr, int b_size, boolean b_needsfree) {
- return trace(new CDataObject(clazz, getShape(clazz), b_ptr, b_size, b_needsfree));
- }
-
- // Don't use directly, use CtypesNodes.CreateCDataObjectNode
- public final PyCFuncPtrObject createPyCFuncPtrObject(Object clazz, Pointer b_ptr, int b_size, boolean b_needsfree) {
- return trace(new PyCFuncPtrObject(clazz, getShape(clazz), b_ptr, b_size, b_needsfree));
- }
-
- public final CFieldObject createCFieldObject(Object clazz) {
- return trace(new CFieldObject(clazz, getShape(clazz)));
- }
-
- public final StgDictObject createStgDictObject(Object clazz) {
- return trace(new StgDictObject(clazz, getShape(clazz)));
- }
-
- public final PSSLContext createSSLContext(Object clazz, SSLMethod method, int verifyFlags, boolean checkHostname, int verifyMode, SSLContext context) {
- return trace(new PSSLContext(clazz, getShape(clazz), method, verifyFlags, checkHostname, verifyMode, context));
- }
-
- public final PSSLSocket createSSLSocket(Object clazz, PSSLContext context, SSLEngine engine, PSocket socket) {
- return trace(new PSSLSocket(clazz, getShape(clazz), context, engine, socket, createMemoryBIO(), createMemoryBIO(), createMemoryBIO()));
- }
-
- public final PSSLSocket createSSLSocket(Object clazz, PSSLContext context, SSLEngine engine, PMemoryBIO inbound, PMemoryBIO outbound) {
- return trace(new PSSLSocket(clazz, getShape(clazz), context, engine, null, inbound, outbound, createMemoryBIO()));
- }
-
- public final PMemoryBIO createMemoryBIO(Object clazz) {
- return trace(new PMemoryBIO(clazz, getShape(clazz)));
- }
-
- public final PMemoryBIO createMemoryBIO() {
- return trace(new PMemoryBIO(PythonBuiltinClassType.PMemoryBIO, getShape(PythonBuiltinClassType.PMemoryBIO)));
- }
-
- public final PProperty createProperty() {
- return trace(new PProperty(PythonBuiltinClassType.PProperty, getShape(PythonBuiltinClassType.PProperty)));
- }
-
- public final PProperty createProperty(Object cls) {
- return trace(new PProperty(cls, getShape(cls)));
- }
-
- // JSON
- // (not created on fast path, thus TruffleBoundary)
-
- @TruffleBoundary
- public final PJSONScanner createJSONScanner(Object clazz, boolean strict, Object objectHook, Object objectPairsHook, Object parseFloat, Object parseInt, Object parseConstant) {
- return trace(new PJSONScanner(clazz, getShape(clazz), strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant));
- }
-
- @TruffleBoundary
- public final PJSONEncoder createJSONEncoder(Object clazz, Object markers, Object defaultFn, Object encoder, Object indent, TruffleString keySeparator, TruffleString itemSeparator,
- boolean sortKeys, boolean skipKeys, boolean allowNan, FastEncode fastEncode) {
- return trace(new PJSONEncoder(clazz, getShape(clazz), markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode));
- }
-
- public final PDeque createDeque() {
- return trace(new PDeque(PythonBuiltinClassType.PDeque, getShape(PythonBuiltinClassType.PDeque)));
- }
-
- public final PDeque createDeque(Object cls) {
- return trace(new PDeque(cls, getShape(cls)));
- }
-
- public final PDequeIter createDequeIter(PDeque deque) {
- return trace(new PDequeIter(PythonBuiltinClassType.PDequeIter, getShape(PythonBuiltinClassType.PDequeIter), deque, false));
- }
-
- public final PDequeIter createDequeRevIter(PDeque deque) {
- return trace(new PDequeIter(PythonBuiltinClassType.PDequeRevIter, getShape(PythonBuiltinClassType.PDequeRevIter), deque, true));
- }
-
- public final PSimpleQueue createSimpleQueue(Object cls) {
- return trace(new PSimpleQueue(cls, getShape(cls)));
- }
-
- public final PContextVar createContextVar(TruffleString name, Object def) {
- return trace(new PContextVar(PythonBuiltinClassType.ContextVar, getShape(PythonBuiltinClassType.ContextVar), name, def));
- }
-
- public final PContextVarsContext createContextVarsContext() {
- return trace(new PContextVarsContext(PythonBuiltinClassType.ContextVarsContext, getShape(PythonBuiltinClassType.ContextVarsContext)));
- }
-
- public final PContextIterator createContextIterator(PContextVarsContext ctx, PContextIterator.ItemKind kind) {
- return trace(new PContextIterator(PythonBuiltinClassType.ContextIterator, getShape(PythonBuiltinClassType.ContextIterator), ctx, kind));
- }
-
- public final PContextVarsContext copyContextVarsContext(PContextVarsContext original) {
- return trace(new PContextVarsContext(original, PythonBuiltinClassType.ContextVarsContext, getShape(PythonBuiltinClassType.ContextVarsContext)));
- }
-
- public final PContextVarsToken createContextVarsToken(PContextVar var, Object oldValue) {
- return trace(new PContextVarsToken(var, oldValue, PythonBuiltinClassType.ContextVarsToken, getShape(PythonBuiltinClassType.ContextVarsToken)));
- }
-
- public final PGenericAlias createGenericAlias(Object cls, Object origin, Object arguments, boolean starred) {
- PTuple argumentsTuple;
- if (arguments instanceof PTuple) {
- argumentsTuple = (PTuple) arguments;
- } else {
- argumentsTuple = createTuple(new Object[]{arguments});
- }
- return trace(new PGenericAlias(cls, getShape(cls), origin, argumentsTuple, starred));
- }
-
- public final PGenericAlias createGenericAlias(Object origin, Object arguments, boolean starred) {
- return createGenericAlias(PythonBuiltinClassType.PGenericAlias, origin, arguments, starred);
- }
-
- public final PGenericAlias createGenericAlias(Object origin, Object arguments) {
- return createGenericAlias(PythonBuiltinClassType.PGenericAlias, origin, arguments, false);
- }
-
- public final PGenericAliasIterator createGenericAliasIterator(PGenericAlias object) {
- PythonBuiltinClassType type = PythonBuiltinClassType.PGenericAliasIterator;
- return trace(new PGenericAliasIterator(type, getShape(type), object));
- }
-
- public final PUnionType createUnionType(Object[] args) {
- return trace(new PUnionType(PythonBuiltinClassType.PUnionType, getShape(PythonBuiltinClassType.PUnionType), createTuple(args)));
- }
-
- public final DigestObject createDigestObject(PythonBuiltinClassType type, String name, Object digest) {
- return trace(DigestObject.create(type, getShape(type), name, digest));
- }
-
- public final PyCapsule createCapsuleNativeName(Object pointer, Object name) {
- return createCapsule(new PyCapsule.CapsuleData(pointer, name));
- }
-
- public final PyCapsule createCapsuleJavaName(Object pointer, byte[] name) {
- return createCapsule(new PyCapsule.CapsuleData(pointer, new CArrayWrappers.CByteArrayWrapper(name)));
- }
-
- public final PyCapsule createCapsule(PyCapsule.CapsuleData data) {
- return trace(new PyCapsule(getLanguage(), data));
- }
-
- public final MultibyteIncrementalDecoderObject createMultibyteIncrementalDecoderObject(Object type) {
- return trace(new MultibyteIncrementalDecoderObject(type, getShape(type)));
- }
-
- public final MultibyteIncrementalEncoderObject createMultibyteIncrementalEncoderObject(Object type) {
- return trace(new MultibyteIncrementalEncoderObject(type, getShape(type)));
- }
-
- public final MultibyteStreamReaderObject createMultibyteStreamReaderObject(Object type) {
- return trace(new MultibyteStreamReaderObject(type, getShape(type)));
- }
-
- public final MultibyteStreamWriterObject createMultibyteStreamWriterObject(Object type) {
- return trace(new MultibyteStreamWriterObject(type, getShape(type)));
- }
-
- public final MultibyteCodecObject createMultibyteCodecObject(Object type, MultibyteCodec codec) {
- return trace(new MultibyteCodecObject(type, getShape(type), codec));
- }
-
- public PAsyncGenASend createAsyncGeneratorASend(PAsyncGen receiver, Object message) {
- return trace(new PAsyncGenASend(getLanguage(), receiver, message));
- }
-
- public PAsyncGenAThrow createAsyncGeneratorAThrow(PAsyncGen receiver, Object arg1, Object arg2, Object arg3) {
- return trace(new PAsyncGenAThrow(getLanguage(), receiver, arg1, arg2, arg3));
- }
-
- public PAsyncGenWrappedValue createAsyncGeneratorWrappedValue(Object wrapped) {
- return trace(new PAsyncGenWrappedValue(getLanguage(), wrapped));
- }
-
- // pickle
-
- public PPickleBuffer createPickleBuffer(Object view) {
- return createPickleBuffer(view, PythonBuiltinClassType.PickleBuffer);
- }
-
- public PPickleBuffer createPickleBuffer(Object view, Object cls) {
- return trace(new PPickleBuffer(cls, getShape(cls), view));
- }
-
- public PPickler createPickler() {
- return createPickler(PythonBuiltinClassType.Pickler);
- }
-
- public PPickler createPickler(Object cls) {
- return trace(new PPickler(cls, getShape(cls)));
- }
-
- public PUnpickler createUnpickler() {
- return createUnpickler(PythonBuiltinClassType.Unpickler);
- }
-
- public PUnpickler createUnpickler(Object cls) {
- return trace(new PUnpickler(cls, getShape(cls)));
- }
-
- public PPicklerMemoProxy createPicklerMemoProxy(PPickler pickler) {
- return createPicklerMemoProxy(pickler, PythonBuiltinClassType.PicklerMemoProxy);
- }
-
- public PPicklerMemoProxy createPicklerMemoProxy(PPickler pickler, Object cls) {
- return trace(new PPicklerMemoProxy(cls, getShape(cls), pickler));
- }
-
- public PUnpicklerMemoProxy createUnpicklerMemoProxy(PUnpickler unpickler) {
- return createUnpicklerMemoProxy(unpickler, PythonBuiltinClassType.UnpicklerMemoProxy);
- }
-
- public PUnpicklerMemoProxy createUnpicklerMemoProxy(PUnpickler unpickler, Object cls) {
- return trace(new PUnpicklerMemoProxy(cls, getShape(cls), unpickler));
- }
-
- public PStruct createStruct(PStruct.StructInfo structInfo) {
- return trace(new PStruct(PythonBuiltinClassType.PStruct, getShape(PythonBuiltinClassType.PStruct), structInfo));
- }
-
- public PStruct createStruct(byte[] format, int size, int len, FormatAlignment formatAlignment, FormatCode[] codes) {
- return trace(new PStruct(PythonBuiltinClassType.PStruct, getShape(PythonBuiltinClassType.PStruct), format, size, len, formatAlignment, codes));
- }
-
- public PStructUnpackIterator createStructUnpackIterator(PStruct struct, Object buffer) {
- return trace(
- new PStructUnpackIterator(PythonBuiltinClassType.PStructUnpackIterator, getShape(PythonBuiltinClassType.PStructUnpackIterator), struct, buffer));
- }
-
- public final PTokenizerIter createTokenizerIter(Object cls, String sourceString) {
- return trace(new PTokenizerIter(cls, getShape(cls), sourceString));
- }
-
- @GenerateInline
- @GenerateUncached
- @GenerateCached(false)
- public abstract static class Lazy extends Node {
- public static Lazy getUncached() {
- return LazyNodeGen.getUncached();
- }
-
- public final PythonObjectFactory get(Node inliningTarget) {
- return execute(inliningTarget);
- }
-
- abstract PythonObjectFactory execute(Node inliningTarget);
-
- @Specialization
- static PythonObjectFactory doIt(@Cached(inline = false) PythonObjectFactory node) {
- return node;
- }
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectSlowPathFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectSlowPathFactory.java
deleted file mode 100644
index 57bde9aff7..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectSlowPathFactory.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.runtime.object;
-
-import java.util.Objects;
-
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.runtime.PythonContext;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.instrumentation.AllocationReporter;
-import com.oracle.truffle.api.object.Shape;
-
-/**
- * A subclass of {@link PythonObjectFactory} which is basically an uncached version of it but
- * directly stores a reference to the {@link AllocationReporter} instead of doing a context lookup
- * and getting it from the context. This class is meant to be used on slow path where the context is
- * explicitly available.
- *
- * Objects of this class should not be created directly, but retrieved from
- * {@link com.oracle.graal.python.builtins.Python3Core}. Note that
- * {@link PythonObjectSlowPathFactory} is context dependent object. It must not be stored in AST or
- * in {@link com.oracle.graal.python.PythonLanguage}, for example.
- */
-public final class PythonObjectSlowPathFactory extends PythonObjectFactory {
-
- private final AllocationReporter reporter;
- private final PythonLanguage language;
- private final SlowPathGetInstanceShapeNode getInstanceShapeNode;
-
- public PythonObjectSlowPathFactory(AllocationReporter reporter, PythonLanguage language) {
- this.reporter = Objects.requireNonNull(reporter);
- this.language = language;
- this.getInstanceShapeNode = new SlowPathGetInstanceShapeNode(language);
- }
-
- @Override
- public PythonLanguage getLanguage() {
- return language;
- }
-
- @TruffleBoundary
- @Override
- protected AllocationReporter executeTrace(Object arg0Value, long arg1Value) {
- assert PythonContext.get(null).getAllocationReporter() == reporter;
- return PythonObjectFactory.doTrace(arg0Value, arg1Value, reporter);
- }
-
- @TruffleBoundary
- @Override
- protected Shape executeGetShape(Object arg0Value, boolean arg1Value) {
- return getInstanceShapeNode.execute(arg0Value);
- }
-
- @Override
- public boolean isAdoptable() {
- return false;
- }
-
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
index 00c43e123d..2700fa86c3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -86,8 +86,7 @@
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.pegparser.scope.ScopeEnvironment;
import com.oracle.graal.python.pegparser.sst.ConstantValue;
-import com.oracle.graal.python.runtime.object.PythonObjectFactory;
-import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
@@ -223,7 +222,7 @@ public static TruffleString[] toTruffleStringArrayUncached(String[] s) {
/**
* Creates an array of {@link Object}'s. The intended use of this method is in slow-path in
- * calls to methods like {@link PythonObjectFactory#createTuple(Object[])}.
+ * calls to methods like {@link PFactory#createTuple}.
*/
public static Object[] convertToObjectArray(TruffleString[] src) {
if (src == null) {
@@ -697,16 +696,15 @@ public static PBuiltinFunction createMethod(PythonLanguage language, Object klas
Class extends PythonBuiltinBaseNode> nodeClass = nodeFactory.getNodeClass();
Builtin builtin = nodeClass.getAnnotation(Builtin.class);
RootCallTarget callTarget = language.createCachedCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, nodeFactory, true), nodeClass);
- return createMethod(PythonObjectFactory.getUncached(), klass, builtin, callTarget, type, numDefaults);
+ return createMethod(klass, builtin, callTarget, type, numDefaults);
}
@TruffleBoundary
- public static PBuiltinFunction createMethod(PythonObjectFactory factory, Object klass, Builtin builtin, RootCallTarget callTarget, Object type,
- int numDefaults) {
+ public static PBuiltinFunction createMethod(Object klass, Builtin builtin, RootCallTarget callTarget, Object type, int numDefaults) {
assert callTarget.getRootNode() instanceof BuiltinFunctionRootNode r && r.getBuiltin() == builtin;
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
TruffleString name = toTruffleStringUncached(builtin.name());
- PBuiltinFunction function = factory.createBuiltinFunction(name, type, numDefaults, flags, callTarget);
+ PBuiltinFunction function = PFactory.createBuiltinFunction(PythonLanguage.get(null), name, type, numDefaults, flags, callTarget);
if (klass != null) {
WriteAttributeToObjectNode.getUncached(true).execute(klass, name, function);
}
@@ -714,22 +712,16 @@ public static PBuiltinFunction createMethod(PythonObjectFactory factory, Object
}
@TruffleBoundary
- public static void createConstructor(PythonObjectSlowPathFactory factory, Object klass, Builtin builtin, RootCallTarget callTarget) {
+ public static void createConstructor(Object klass, Builtin builtin, RootCallTarget callTarget) {
assert J___NEW__.equals(builtin.name());
assert IsSubtypeNode.getUncached().execute(klass, PythonBuiltinClassType.PTuple);
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
- PBuiltinFunction function = factory.createBuiltinFunction(toTruffleStringUncached(builtin.name()), PythonBuiltinClassType.PTuple, 1, flags, callTarget);
- PBuiltinMethod method = factory.createBuiltinMethod(PythonBuiltinClassType.PTuple, function);
+ PythonLanguage language = PythonLanguage.get(null);
+ PBuiltinFunction function = PFactory.createBuiltinFunction(language, toTruffleStringUncached(builtin.name()), PythonBuiltinClassType.PTuple, 1, flags, callTarget);
+ PBuiltinMethod method = PFactory.createBuiltinMethod(language, PythonBuiltinClassType.PTuple, function);
WriteAttributeToObjectNode.getUncached(true).execute(klass, T___NEW__, method);
}
- private static Object[] createCalltargetKeys(Object[] callTargetCacheKeys, Class> nodeClass) {
- Object[] keys = new Object[callTargetCacheKeys.length + 1];
- keys[0] = nodeClass;
- arraycopy(callTargetCacheKeys, 0, keys, 1, callTargetCacheKeys.length);
- return keys;
- }
-
public static Unsafe initUnsafe() {
try {
return Unsafe.getUnsafe();
@@ -842,7 +834,7 @@ public boolean isOverLimit() {
}
}
- public static Object pythonObjectFromConstantValue(ConstantValue v, PythonObjectFactory factory) {
+ public static Object pythonObjectFromConstantValue(ConstantValue v) {
switch (v.kind) {
case BOOLEAN:
return v.getBoolean();
@@ -857,16 +849,16 @@ public static Object pythonObjectFromConstantValue(ConstantValue v, PythonObject
return v.getDouble();
case COMPLEX: {
double[] c = v.getComplex();
- return factory.createComplex(c[0], c[1]);
+ return PFactory.createComplex(PythonLanguage.get(null), c[0], c[1]);
}
case NONE:
return PNone.NONE;
case ELLIPSIS:
return PEllipsis.INSTANCE;
case BIGINTEGER:
- return factory.createInt(v.getBigInteger());
+ return PFactory.createInt(PythonLanguage.get(null), v.getBigInteger());
case BYTES:
- return factory.createBytes(v.getBytes());
+ return PFactory.createBytes(PythonLanguage.get(null), v.getBytes());
case RAW:
return v.getRaw(TruffleString.class);
case TUPLE:
diff --git a/mx.graalpython/copyrights/overrides b/mx.graalpython/copyrights/overrides
index 7111d0cbab..99a7d617eb 100644
--- a/mx.graalpython/copyrights/overrides
+++ b/mx.graalpython/copyrights/overrides
@@ -708,7 +708,7 @@ graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatti
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java,jython.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java,jython.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/TextFormatter.java,jython.copyright
-graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java,zippy.copyright
+graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/PSequence.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/BoolSequenceStorage.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ByteSequenceStorage.java,zippy.copyright
From db8b9a1bd3fb6fe05613078264c36e3d94faa523 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 5 Feb 2025 15:55:23 +0100
Subject: [PATCH 014/512] Comment out failing assert for now
---
.../src/com/oracle/graal/python/PythonLanguage.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
index c48c51e79d..f7ecc2a1ce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
@@ -526,7 +526,8 @@ protected PythonContext createContext(Env env) {
if (allocationReporter == null) {
allocationReporter = env.lookup(AllocationReporter.class);
} else {
- assert allocationReporter == env.lookup(AllocationReporter.class);
+ // GR-61960
+ // assert allocationReporter == env.lookup(AllocationReporter.class);
}
return context;
From 71d7031d142031a8c98c80b25e114be40f477c1c Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 5 Feb 2025 15:57:30 +0100
Subject: [PATCH 015/512] Simplify PythonContext.getLanguage
---
.../com/oracle/graal/python/builtins/Python3Core.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
index 7d6dd23d65..d785ce324b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
@@ -906,11 +906,12 @@ public final PythonLanguage getLanguage() {
* multi-context mode. Can be null.
*/
public final PythonLanguage getLanguage(Node node) {
- if (CompilerDirectives.inCompiledCode() && node != null && CompilerDirectives.isPartialEvaluationConstant(node) && node.getRootNode() != null) {
- // This will make it PE-constant in multi-context mode
- return PythonLanguage.get(node);
+ // The condition is always true in the interpreter
+ if (CompilerDirectives.isPartialEvaluationConstant(language)) {
+ return language;
}
- return language;
+ // This will make it PE-constant in multi-context mode
+ return PythonLanguage.get(node);
}
/**
From 4a7b16ad65b6f2ad4cb0acafd7df39d24943eb42 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 5 Feb 2025 16:29:29 +0100
Subject: [PATCH 016/512] Make PRaiseNode inlined
---
.../asdl/asdl_java.py | 6 +-
.../oracle/graal/python/PythonLanguage.java | 2 +-
.../builtins/modules/AbcModuleBuiltins.java | 4 +-
.../builtins/modules/ArrayModuleBuiltins.java | 44 +--
.../modules/AsyncioModuleBuiltins.java | 6 +-
.../modules/BinasciiModuleBuiltins.java | 33 ++-
.../builtins/modules/BuiltinConstructors.java | 263 +++++++++---------
.../builtins/modules/BuiltinFunctions.java | 148 +++++-----
.../builtins/modules/CmathModuleBuiltins.java | 70 ++---
.../modules/CodecsModuleBuiltins.java | 111 ++++----
.../modules/CodecsTruffleModuleBuiltins.java | 2 +-
.../modules/CollectionsModuleBuiltins.java | 8 +-
.../modules/ContextvarsModuleBuiltins.java | 4 +-
.../builtins/modules/FcntlModuleBuiltins.java | 10 +-
.../modules/GraalHPyDebugModuleBuiltins.java | 2 +-
.../GraalHPyUniversalModuleBuiltins.java | 4 +-
.../modules/GraalPythonModuleBuiltins.java | 14 +-
.../builtins/modules/ImpModuleBuiltins.java | 10 +-
.../modules/ItertoolsModuleBuiltins.java | 134 +++++----
.../modules/JArrayModuleBuiltins.java | 16 +-
.../builtins/modules/JavaModuleBuiltins.java | 32 +--
.../modules/LocaleModuleBuiltins.java | 6 +-
.../modules/LsprofModuleBuiltins.java | 2 +-
.../builtins/modules/MMapModuleBuiltins.java | 18 +-
.../modules/MarshalModuleBuiltins.java | 32 +--
.../builtins/modules/MathModuleBuiltins.java | 218 ++++++++-------
.../modules/OperatorModuleBuiltins.java | 4 +-
.../modules/PolyglotModuleBuiltins.java | 106 +++----
.../builtins/modules/PosixModuleBuiltins.java | 203 +++++++-------
.../PosixSubprocessModuleBuiltins.java | 28 +-
.../builtins/modules/PwdModuleBuiltins.java | 14 +-
.../modules/ReadlineModuleBuiltins.java | 18 +-
.../modules/ResourceModuleBuiltins.java | 4 +-
.../builtins/modules/SREModuleBuiltins.java | 28 +-
.../builtins/modules/SSLModuleBuiltins.java | 28 +-
.../modules/SelectModuleBuiltins.java | 8 +-
.../modules/SignalModuleBuiltins.java | 8 +-
.../modules/SocketModuleBuiltins.java | 66 ++---
.../modules/StructModuleBuiltins.java | 16 +-
.../builtins/modules/SysModuleBuiltins.java | 59 ++--
.../modules/ThreadModuleBuiltins.java | 8 +-
.../builtins/modules/TimeModuleBuiltins.java | 66 ++---
.../modules/TracemallocModuleBuiltins.java | 13 +-
.../modules/UnicodeDataModuleBuiltins.java | 10 +-
.../modules/WarningsModuleBuiltins.java | 61 ++--
.../modules/WeakRefModuleBuiltins.java | 12 +-
.../builtins/modules/ast/AstBuiltins.java | 13 +-
.../modules/ast/AstModuleBuiltins.java | 11 +-
.../python/builtins/modules/ast/Obj2Sst.java | 5 +-
.../builtins/modules/ast/Obj2SstBase.java | 17 +-
.../builtins/modules/ast/Validator.java | 26 +-
.../modules/bz2/BZ2CompressorBuiltins.java | 16 +-
.../modules/bz2/BZ2DecompressorBuiltins.java | 8 +-
.../python/builtins/modules/bz2/Bz2Nodes.java | 34 +--
.../cext/PythonCextAbstractBuiltins.java | 43 ++-
.../modules/cext/PythonCextBuiltins.java | 30 +-
.../cext/PythonCextByteArrayBuiltins.java | 10 +-
.../modules/cext/PythonCextBytesBuiltins.java | 46 +--
.../cext/PythonCextCapsuleBuiltins.java | 77 +++--
.../modules/cext/PythonCextClassBuiltins.java | 4 +-
.../cext/PythonCextComplexBuiltins.java | 4 +-
.../cext/PythonCextContextBuiltins.java | 6 +-
.../modules/cext/PythonCextDictBuiltins.java | 14 +-
.../modules/cext/PythonCextErrBuiltins.java | 9 +-
.../modules/cext/PythonCextFileBuiltins.java | 4 +-
.../modules/cext/PythonCextFloatBuiltins.java | 8 +-
.../modules/cext/PythonCextListBuiltins.java | 8 +-
.../modules/cext/PythonCextLongBuiltins.java | 26 +-
.../cext/PythonCextMemoryViewBuiltins.java | 8 +-
.../cext/PythonCextModuleBuiltins.java | 14 +-
.../cext/PythonCextObjectBuiltins.java | 8 +-
.../cext/PythonCextPickleBufferBuiltins.java | 6 +-
.../cext/PythonCextPythonRunBuiltins.java | 38 ++-
.../modules/cext/PythonCextSetBuiltins.java | 14 +-
.../cext/PythonCextStructSeqBuiltins.java | 4 +-
.../modules/cext/PythonCextTupleBuiltins.java | 12 +-
.../modules/cext/PythonCextTypeBuiltins.java | 5 +-
.../cext/PythonCextUnicodeBuiltins.java | 143 +++++-----
.../modules/cjkcodecs/CodecCtxBuiltins.java | 8 +-
.../cjkcodecs/CodecsCNModuleBuiltins.java | 6 +-
.../cjkcodecs/CodecsHKModuleBuiltins.java | 6 +-
.../CodecsISO2022ModuleBuiltins.java | 6 +-
.../cjkcodecs/CodecsJPModuleBuiltins.java | 6 +-
.../cjkcodecs/CodecsKRModuleBuiltins.java | 6 +-
.../cjkcodecs/CodecsTWModuleBuiltins.java | 6 +-
.../cjkcodecs/MultibyteCodecBuiltins.java | 4 +-
.../modules/cjkcodecs/MultibyteCodecUtil.java | 32 +--
.../cjkcodecs/MultibyteDecodeBuffer.java | 2 +-
.../cjkcodecs/MultibyteEncodeBuffer.java | 2 +-
.../MultibyteIncrementalDecoderBuiltins.java | 16 +-
.../MultibyteIncrementalEncoderBuiltins.java | 20 +-
.../MultibyteStreamReaderBuiltins.java | 8 +-
.../MultibyteStreamWriterBuiltins.java | 8 +-
.../MultibytecodecModuleBuiltins.java | 10 +-
.../builtins/modules/codecs/CharmapNodes.java | 20 +-
.../modules/codecs/CodecsRegistry.java | 11 +-
.../modules/codecs/ErrorHandlers.java | 97 +++----
.../modules/csv/CSVModuleBuiltins.java | 52 ++--
.../modules/csv/CSVReaderBuiltins.java | 18 +-
.../modules/csv/CSVWriterBuiltins.java | 14 +-
.../modules/ctypes/CDataBuiltins.java | 18 +-
.../modules/ctypes/CDataTypeBuiltins.java | 48 ++--
.../ctypes/CDataTypeSequenceBuiltins.java | 8 +-
.../modules/ctypes/CFieldBuiltins.java | 59 ++--
.../builtins/modules/ctypes/CThunkObject.java | 4 +-
.../modules/ctypes/CtypesModuleBuiltins.java | 92 +++---
.../builtins/modules/ctypes/CtypesNodes.java | 2 +-
.../ctypes/LazyPyCArrayTypeBuiltins.java | 20 +-
.../ctypes/LazyPyCSimpleTypeBuiltins.java | 12 +-
.../modules/ctypes/PyCArrayBuiltins.java | 35 ++-
.../modules/ctypes/PyCArrayTypeBuiltins.java | 16 +-
.../modules/ctypes/PyCFuncPtrBuiltins.java | 82 +++---
.../ctypes/PyCFuncPtrTypeBuiltins.java | 12 +-
.../modules/ctypes/PyCPointerBuiltins.java | 41 ++-
.../ctypes/PyCPointerTypeBuiltins.java | 20 +-
.../modules/ctypes/PyCSimpleTypeBuiltins.java | 16 +-
.../modules/ctypes/SimpleCDataBuiltins.java | 12 +-
.../modules/ctypes/StgDictBuiltins.java | 16 +-
.../ctypes/StructUnionTypeBuiltins.java | 32 +--
.../modules/ctypes/StructureBuiltins.java | 16 +-
.../modules/ctypes/UnionTypeBuiltins.java | 2 +-
.../modules/ctypes/memory/PointerNodes.java | 10 +-
.../functools/FunctoolsModuleBuiltins.java | 6 +-
.../modules/functools/KeyWrapperBuiltins.java | 6 +-
.../functools/LruCacheWrapperBuiltins.java | 10 +-
.../modules/functools/PartialBuiltins.java | 22 +-
.../modules/hashlib/Blake2ModuleBuiltins.java | 12 +-
.../modules/hashlib/DigestObjectBuiltins.java | 8 +-
.../hashlib/HashlibModuleBuiltins.java | 46 +--
.../modules/hashlib/Md5ModuleBuiltins.java | 6 +-
.../modules/hashlib/Sha1ModuleBuiltins.java | 6 +-
.../modules/hashlib/Sha256ModuleBuiltins.java | 10 +-
.../modules/hashlib/Sha3ModuleBuiltins.java | 6 +-
.../modules/hashlib/Sha512ModuleBuiltins.java | 10 +-
.../hashlib/ShakeDigestObjectBuiltins.java | 8 +-
.../io/AbstractBufferedIOBuiltins.java | 22 +-
.../modules/io/BufferedIOBaseBuiltins.java | 24 +-
.../modules/io/BufferedIOMixinBuiltins.java | 21 +-
.../builtins/modules/io/BufferedIONodes.java | 28 +-
.../modules/io/BufferedRWPairBuiltins.java | 26 +-
.../io/BufferedReaderMixinBuiltins.java | 21 +-
.../modules/io/BufferedWriterNodes.java | 4 +-
.../builtins/modules/io/BytesIOBuiltins.java | 68 ++---
.../builtins/modules/io/FileIOBuiltins.java | 86 +++---
.../builtins/modules/io/IOBaseBuiltins.java | 35 +--
.../modules/io/IOBaseDictBuiltins.java | 6 +-
.../builtins/modules/io/IOModuleBuiltins.java | 39 ++-
.../python/builtins/modules/io/IONodes.java | 25 +-
.../io/IncrementalNewlineDecoderBuiltins.java | 18 +-
.../python/builtins/modules/io/PBytesIO.java | 4 +-
.../python/builtins/modules/io/PTextIO.java | 6 +-
.../modules/io/RawIOBaseBuiltins.java | 12 +-
.../builtins/modules/io/StringIOBuiltins.java | 86 +++---
.../modules/io/TextIOBaseBuiltins.java | 21 +-
.../modules/io/TextIOWrapperBuiltins.java | 105 +++----
.../modules/io/TextIOWrapperNodes.java | 34 +--
.../modules/json/JSONEncoderBuiltins.java | 10 +-
.../modules/json/JSONModuleBuiltins.java | 10 +-
.../modules/json/JSONScannerBuiltins.java | 4 +-
.../modules/lzma/LZMACompressorBuiltins.java | 20 +-
.../lzma/LZMADecompressorBuiltins.java | 28 +-
.../builtins/modules/lzma/LZMANodes.java | 161 ++++++-----
.../GraalPySemLockBuiltins.java | 4 +-
.../MultiprocessingGraalPyModuleBuiltins.java | 10 +-
.../MultiprocessingModuleBuiltins.java | 4 +-
.../multiprocessing/SemLockBuiltins.java | 12 +-
.../builtins/modules/pickle/MemoTable.java | 4 +-
.../python/builtins/modules/pickle/PData.java | 16 +-
.../modules/pickle/PPickleBuffer.java | 7 +-
.../builtins/modules/pickle/PPickler.java | 14 +-
.../builtins/modules/pickle/PUnpickler.java | 6 +-
.../modules/pickle/PickleBufferBuiltins.java | 6 +-
.../modules/pickle/PickleModuleBuiltins.java | 6 +-
.../builtins/modules/pickle/PickleState.java | 22 +-
.../builtins/modules/pickle/PickleUtils.java | 4 +-
.../modules/pickle/PicklerBuiltins.java | 30 +-
.../builtins/modules/pickle/PicklerNodes.java | 24 +-
.../modules/pickle/UnpicklerBuiltins.java | 24 +-
.../builtins/modules/zlib/ZLibCompObject.java | 6 +-
.../modules/zlib/ZLibModuleBuiltins.java | 28 +-
.../modules/zlib/ZlibCompressBuiltins.java | 16 +-
.../modules/zlib/ZlibDecompressBuiltins.java | 18 +-
.../builtins/modules/zlib/ZlibNodes.java | 51 ++--
.../objects/PythonAbstractObject.java | 132 ++++-----
.../builtins/objects/array/ArrayBuiltins.java | 123 ++++----
.../builtins/objects/array/ArrayNodes.java | 8 +-
.../python/builtins/objects/array/PArray.java | 4 +-
.../objects/asyncio/AsyncGenSendBuiltins.java | 23 +-
.../asyncio/AsyncGenThrowBuiltins.java | 53 ++--
.../objects/asyncio/GetAwaitableNode.java | 20 +-
.../buffer/PythonBufferAcquireLibrary.java | 6 +-
.../objects/bytes/ByteArrayBuiltins.java | 93 +++----
.../builtins/objects/bytes/BytesBuiltins.java | 12 +-
.../objects/bytes/BytesCommonBuiltins.java | 86 +++---
.../builtins/objects/bytes/BytesNodes.java | 54 ++--
.../builtins/objects/bytes/PByteArray.java | 6 +-
.../python/builtins/objects/bytes/PBytes.java | 7 +-
.../builtins/objects/cell/CellBuiltins.java | 34 +--
.../objects/cext/capi/CApiContext.java | 6 +-
.../cext/capi/CApiMemberAccessNodes.java | 39 +--
.../builtins/objects/cext/capi/CExtNodes.java | 47 ++--
.../cext/capi/ExternalFunctionNodes.java | 9 +-
.../cext/capi/PyMemoryViewWrapper.java | 4 +-
.../objects/cext/capi/PyProcsWrapper.java | 4 +-
.../capi/transitions/CApiTransitions.java | 2 +-
.../objects/cext/common/CExtCommonNodes.java | 80 +++---
.../objects/cext/hpy/GraalHPyContext.java | 16 +-
.../cext/hpy/GraalHPyContextFunctions.java | 104 +++----
.../cext/hpy/GraalHPyMemberAccessNodes.java | 28 +-
.../cext/hpy/GraalHPyNativeContext.java | 2 +-
.../objects/cext/hpy/GraalHPyNodes.java | 69 +++--
.../cext/hpy/HPyExternalFunctionNodes.java | 28 +-
.../cext/hpy/jni/GraalHPyJNIContext.java | 16 +-
.../cext/hpy/llvm/GraalHPyLLVMNodes.java | 10 +-
.../objects/cext/structs/CConstants.java | 8 +-
.../builtins/objects/code/CodeNodes.java | 2 +-
.../objects/common/BufferStorageNodes.java | 41 ++-
.../objects/common/ForeignHashingStorage.java | 27 +-
.../objects/common/HashingStorage.java | 8 +-
.../objects/common/HashingStorageNodes.java | 14 +-
.../builtins/objects/common/IndexNodes.java | 35 ++-
.../objects/common/SequenceNodes.java | 11 +-
.../objects/common/SequenceStorageNodes.java | 71 ++---
.../objects/complex/ComplexBuiltins.java | 26 +-
.../objects/contextvars/ContextBuiltins.java | 15 +-
.../contextvars/ContextIteratorBuiltins.java | 4 +-
.../contextvars/ContextVarBuiltins.java | 12 +-
.../contextvars/PContextVarsContext.java | 6 +-
.../contextvars/PContextVarsToken.java | 6 +-
.../builtins/objects/deque/DequeBuiltins.java | 42 +--
.../objects/deque/DequeIterBuiltins.java | 4 +-
.../objects/dict/DefaultDictBuiltins.java | 13 +-
.../builtins/objects/dict/DictBuiltins.java | 28 +-
.../builtins/objects/dict/DictNodes.java | 11 +-
.../objects/dict/DictReprBuiltin.java | 14 +-
.../exception/BaseExceptionBuiltins.java | 47 ++--
.../exception/BaseExceptionGroupBuiltins.java | 6 +-
.../objects/exception/ExceptionNodes.java | 10 +-
.../exception/ImportErrorBuiltins.java | 9 +-
.../objects/exception/OsErrorBuiltins.java | 12 +-
.../exception/PrepareExceptionNode.java | 20 +-
.../exception/SyntaxErrorBuiltins.java | 4 +-
.../exception/UnicodeDecodeErrorBuiltins.java | 18 +-
.../exception/UnicodeEncodeErrorBuiltins.java | 16 +-
.../exception/UnicodeErrorBuiltins.java | 20 +-
.../UnicodeTranslateErrorBuiltins.java | 4 +-
.../objects/floats/FloatBuiltins.java | 70 +++--
.../foreign/ForeignExecutableBuiltins.java | 4 +-
.../foreign/ForeignInstantiableBuiltins.java | 4 +-
.../foreign/ForeignNumberBuiltins.java | 3 +-
.../foreign/ForeignObjectBuiltins.java | 20 +-
.../builtins/objects/frame/FrameBuiltins.java | 16 +-
.../function/AbstractFunctionBuiltins.java | 34 +--
.../function/BuiltinFunctionBuiltins.java | 14 +-
.../objects/function/FunctionBuiltins.java | 14 +-
.../generator/CommonGeneratorBuiltins.java | 50 ++--
.../objects/generator/GeneratorBuiltins.java | 12 +-
.../getsetdescriptor/DescriptorBuiltins.java | 28 +-
.../builtins/objects/ints/IntBuiltins.java | 224 +++++++--------
.../builtins/objects/ints/IntNodes.java | 12 +-
.../python/builtins/objects/ints/PInt.java | 5 +-
.../objects/iterator/IteratorBuiltins.java | 48 ++--
.../objects/iterator/IteratorNodes.java | 8 +-
.../objects/iterator/PZipBuiltins.java | 10 +-
.../iterator/SentinelIteratorBuiltins.java | 6 +-
.../objects/itertools/ChainBuiltins.java | 14 +-
.../itertools/CombinationsBuiltins.java | 19 +-
.../objects/itertools/CycleBuiltins.java | 12 +-
.../objects/itertools/DropwhileBuiltins.java | 4 +-
.../objects/itertools/GroupByBuiltins.java | 4 +-
.../objects/itertools/GrouperBuiltins.java | 6 +-
.../objects/itertools/IsliceBuiltins.java | 13 +-
.../objects/itertools/PTeeDataObject.java | 4 +-
.../objects/itertools/PairwiseBuiltins.java | 4 +-
.../itertools/PermutationsBuiltins.java | 17 +-
.../objects/itertools/ProductBuiltins.java | 8 +-
.../objects/itertools/RepeatBuiltins.java | 9 +-
.../objects/itertools/TakewhileBuiltins.java | 4 +-
.../objects/itertools/TeeBuiltins.java | 14 +-
.../itertools/TeeDataObjectBuiltins.java | 12 +-
.../objects/itertools/ZipLongestBuiltins.java | 10 +-
.../builtins/objects/list/ListBuiltins.java | 34 +--
.../mappingproxy/MappingproxyBuiltins.java | 4 +-
.../memoryview/MemoryViewBuiltins.java | 108 +++----
.../objects/memoryview/MemoryViewNodes.java | 49 ++--
.../objects/memoryview/PMemoryView.java | 28 +-
.../method/AbstractBuiltinMethodBuiltins.java | 12 +-
.../method/AbstractMethodBuiltins.java | 12 +-
.../BuiltinFunctionOrMethodBuiltins.java | 4 +-
.../objects/method/ClassmethodBuiltins.java | 8 +-
.../method/DecoratedMethodBuiltins.java | 4 +-
.../method/InstancemethodBuiltins.java | 4 +-
.../objects/method/MethodBuiltins.java | 8 +-
.../objects/method/StaticmethodBuiltins.java | 6 +-
.../builtins/objects/mmap/MMapBuiltins.java | 86 +++---
.../objects/module/ModuleBuiltins.java | 28 +-
.../objects/module/ModuleGetNameNode.java | 6 +-
.../namespace/SimpleNamespaceBuiltins.java | 10 +-
.../objects/object/ObjectBuiltins.java | 36 ++-
.../builtins/objects/object/ObjectNodes.java | 48 ++--
.../ordereddict/OrderedDictBuiltins.java | 22 +-
.../OrderedDictIteratorBuiltins.java | 6 +-
.../posix/ScandirIteratorBuiltins.java | 6 +-
.../objects/property/PropertyBuiltins.java | 8 +-
.../objects/queue/SimpleQueueBuiltins.java | 24 +-
.../objects/random/RandomBuiltins.java | 14 +-
.../builtins/objects/range/RangeBuiltins.java | 36 +--
.../builtins/objects/range/RangeNodes.java | 6 +-
.../referencetype/ReferenceTypeBuiltins.java | 8 +-
.../objects/reversed/ReversedBuiltins.java | 16 +-
.../builtins/objects/set/SetBuiltins.java | 12 +-
.../python/builtins/objects/set/SetNodes.java | 4 +-
.../builtins/objects/slice/PObjectSlice.java | 4 +-
.../python/builtins/objects/slice/PSlice.java | 6 +-
.../builtins/objects/slice/SliceBuiltins.java | 8 +-
.../builtins/objects/slice/SliceNodes.java | 36 +--
.../objects/socket/SocketBuiltins.java | 56 ++--
.../builtins/objects/socket/SocketNodes.java | 52 ++--
.../objects/ssl/MemoryBIOBuiltins.java | 4 +-
.../objects/ssl/SSLCipherSelector.java | 6 +-
.../objects/ssl/SSLContextBuiltins.java | 90 +++---
.../objects/ssl/SSLOperationNode.java | 10 +-
.../objects/ssl/SSLSocketBuiltins.java | 22 +-
.../builtins/objects/str/StringBuiltins.java | 76 ++---
.../builtins/objects/str/StringNodes.java | 45 +--
.../objects/str/TemplateFormatter.java | 40 +--
.../objects/struct/StructBuiltins.java | 38 +--
.../builtins/objects/struct/StructNodes.java | 65 +++--
.../struct/StructUnpackIteratorBuiltins.java | 12 +-
.../objects/superobject/SuperBuiltins.java | 48 ++--
.../builtins/objects/thread/LockBuiltins.java | 18 +-
.../objects/thread/RLockBuiltins.java | 4 +-
.../objects/thread/ThreadLocalBuiltins.java | 10 +-
.../tokenize/TokenizerIterBuiltins.java | 4 +-
.../objects/traceback/TracebackBuiltins.java | 8 +-
.../objects/tuple/StructSequence.java | 22 +-
.../builtins/objects/tuple/TupleBuiltins.java | 14 +-
.../objects/tuple/TupleGetterBuiltins.java | 12 +-
.../objects/type/PythonBuiltinClass.java | 4 +-
.../objects/type/PythonManagedClass.java | 17 +-
.../builtins/objects/type/TypeBuiltins.java | 161 +++++------
.../builtins/objects/type/TypeNodes.java | 93 +++----
.../objects/type/slots/TpSlotDescrGet.java | 13 +-
.../objects/type/slots/TpSlotDescrSet.java | 10 +-
.../objects/type/slots/TpSlotInquiry.java | 4 +-
.../objects/type/slots/TpSlotLen.java | 25 +-
.../type/slots/TpSlotMpAssSubscript.java | 8 +-
.../objects/type/slots/TpSlotSetAttr.java | 8 +-
.../objects/type/slots/TpSlotSqAssItem.java | 8 +-
.../objects/types/GenericAliasBuiltins.java | 8 +-
.../types/GenericAliasIteratorBuiltins.java | 3 +-
.../objects/types/GenericTypeNodes.java | 7 +-
.../objects/types/UnionTypeBuiltins.java | 10 +-
.../graal/python/compiler/CodeUnit.java | 9 +-
.../graal/python/compiler/Unparser.java | 4 +-
.../oracle/graal/python/lib/GetNextNode.java | 10 +-
.../python/lib/PyArgCheckPositionalNode.java | 12 +-
.../lib/PyConvertOptionalToSizeNode.java | 6 +-
.../graal/python/lib/PyDictDelItem.java | 4 +-
.../graal/python/lib/PyFloatAsDoubleNode.java | 8 +-
.../graal/python/lib/PyFloatFromString.java | 14 +-
.../graal/python/lib/PyImportGetModule.java | 6 +-
.../graal/python/lib/PyIterNextNode.java | 4 +-
.../graal/python/lib/PyLongAsDoubleNode.java | 9 +-
.../graal/python/lib/PyLongAsIntNode.java | 9 +-
.../graal/python/lib/PyLongAsLongNode.java | 6 +-
.../python/lib/PyLongFromDoubleNode.java | 8 +-
.../python/lib/PyLongFromUnicodeObject.java | 21 +-
.../python/lib/PyMemoryViewFromObject.java | 10 +-
.../python/lib/PyNumberAbsoluteNode.java | 4 +-
.../graal/python/lib/PyNumberAddNode.java | 7 +-
.../graal/python/lib/PyNumberAndNode.java | 8 +-
.../graal/python/lib/PyNumberAsSizeNode.java | 10 +-
.../graal/python/lib/PyNumberDivmodNode.java | 8 +-
.../python/lib/PyNumberFloorDivideNode.java | 8 +-
.../graal/python/lib/PyNumberIndexNode.java | 8 +-
.../graal/python/lib/PyNumberInvertNode.java | 4 +-
.../graal/python/lib/PyNumberLongNode.java | 10 +-
.../graal/python/lib/PyNumberLshiftNode.java | 8 +-
.../lib/PyNumberMatrixMultiplyNode.java | 8 +-
.../python/lib/PyNumberMultiplyNode.java | 13 +-
.../python/lib/PyNumberNegativeNode.java | 4 +-
.../graal/python/lib/PyNumberOrNode.java | 8 +-
.../python/lib/PyNumberPositiveNode.java | 4 +-
.../graal/python/lib/PyNumberPowerNode.java | 8 +-
.../python/lib/PyNumberRemainderNode.java | 8 +-
.../graal/python/lib/PyNumberRshiftNode.java | 9 +-
.../python/lib/PyNumberSubtractNode.java | 8 +-
.../python/lib/PyNumberTrueDivideNode.java | 8 +-
.../graal/python/lib/PyNumberXorNode.java | 8 +-
.../graal/python/lib/PyOSFSPathNode.java | 8 +-
.../python/lib/PyObjectAsFileDescriptor.java | 16 +-
.../graal/python/lib/PyObjectDelItem.java | 5 +-
.../oracle/graal/python/lib/PyObjectDir.java | 6 +-
.../graal/python/lib/PyObjectFormat.java | 15 +-
.../graal/python/lib/PyObjectGetAttr.java | 4 +-
.../graal/python/lib/PyObjectGetAttrO.java | 4 +-
.../graal/python/lib/PyObjectGetItem.java | 6 +-
.../graal/python/lib/PyObjectGetIter.java | 6 +-
.../graal/python/lib/PyObjectGetMethod.java | 10 +-
.../graal/python/lib/PyObjectHashNode.java | 10 +-
.../python/lib/PyObjectReprAsObjectNode.java | 8 +-
.../python/lib/PyObjectRichCompareBool.java | 25 +-
.../graal/python/lib/PyObjectSetAttr.java | 11 +-
.../graal/python/lib/PyObjectSetAttrO.java | 6 +-
.../graal/python/lib/PyObjectSetItem.java | 5 +-
.../python/lib/PyObjectSizeGenericNode.java | 6 +-
.../graal/python/lib/PyObjectSizeNode.java | 10 +-
.../python/lib/PyObjectStrAsObjectNode.java | 6 +-
.../graal/python/lib/PySequenceConcat.java | 6 +-
.../python/lib/PySequenceDelItemNode.java | 6 +-
.../python/lib/PySequenceGetItemNode.java | 11 +-
.../python/lib/PySequenceIterSearchNode.java | 12 +-
.../python/lib/PySequenceSetItemNode.java | 6 +-
.../graal/python/lib/PySequenceSizeNode.java | 9 +-
.../python/lib/PyTimeFromObjectNode.java | 20 +-
.../python/lib/PyTraceBackPrintNode.java | 6 +-
.../graal/python/lib/PyTupleSizeNode.java | 7 +-
.../python/lib/PyUnicodeAsEncodedString.java | 8 +-
.../graal/python/lib/PyUnicodeDecode.java | 6 +-
.../python/lib/PyUnicodeFSDecoderNode.java | 4 +-
.../lib/PyUnicodeFromEncodedObject.java | 9 +-
.../python/lib/PyUnicodeReadCharNode.java | 10 +-
.../oracle/graal/python/nodes/PRaiseNode.java | 248 +++++++----------
.../nodes/argument/CreateArgumentsNode.java | 48 ++--
.../keywords/ExpandKeywordStarargsNode.java | 8 +-
.../keywords/MappingToKeywordsNode.java | 4 +-
.../ExecutePositionalStarargsNode.java | 10 +-
.../ArrowSchemaReleaseCallbackNode.java | 12 +-
.../VectorArrowArrayReleaseCallback.java | 12 +-
.../WriteAttributeToObjectNode.java | 30 +-
.../python/nodes/builtins/ListNodes.java | 5 +-
.../nodes/bytecode/AbstractKwargsNode.java | 11 +-
.../python/nodes/bytecode/ForIterINode.java | 4 +-
.../python/nodes/bytecode/ForIterONode.java | 4 +-
.../python/nodes/bytecode/GetAIterNode.java | 8 +-
.../python/nodes/bytecode/GetANextNode.java | 6 +-
.../python/nodes/bytecode/ImportStarNode.java | 6 +-
.../python/nodes/bytecode/KeywordsNode.java | 8 +-
.../nodes/bytecode/KwargsMergeNode.java | 8 +-
.../python/nodes/bytecode/MatchClassNode.java | 16 +-
.../python/nodes/bytecode/MatchKeysNode.java | 16 +-
.../nodes/bytecode/PBytecodeRootNode.java | 32 +--
.../nodes/bytecode/PRaiseCachedNode.java | 73 +++++
.../python/nodes/bytecode/PrintExprNode.java | 4 +-
.../python/nodes/bytecode/RaiseNode.java | 32 +--
.../python/nodes/bytecode/SetupAwithNode.java | 6 +-
.../python/nodes/bytecode/SetupWithNode.java | 6 +-
.../python/nodes/bytecode/UnpackExNode.java | 14 +-
.../nodes/bytecode/UnpackSequenceNode.java | 12 +-
.../graal/python/nodes/call/CallNode.java | 20 +-
.../call/special/AbstractCallMethodNode.java | 2 +-
.../LookupAndCallReversibleBinaryNode.java | 11 +-
.../python/nodes/classes/IsSubtypeNode.java | 8 +-
.../nodes/exception/ExceptMatchNode.java | 21 +-
.../nodes/expression/BinaryArithmetic.java | 6 +-
.../expression/BinaryComparisonNode.java | 12 +-
.../expression/CastToListExpressionNode.java | 2 +-
.../nodes/expression/InplaceArithmetic.java | 8 +-
.../nodes/expression/TernaryArithmetic.java | 10 +-
.../nodes/expression/UnaryArithmetic.java | 6 +-
.../nodes/frame/ReadGlobalOrBuiltinNode.java | 14 +-
.../builtins/PythonVarargsBuiltinNode.java | 27 --
.../nodes/function/builtins/WrapTpNew.java | 17 +-
.../clinic/CodePointConversionNode.java | 6 +-
.../clinic/SliceIndexConversionNode.java | 6 +-
.../clinic/TruffleStringConverterNode.java | 6 +-
.../builtins/clinic/TupleConversionNode.java | 6 +-
.../clinic/WritableBufferConversionNode.java | 4 +-
.../interop/GetInteropBehaviorValueNode.java | 30 +-
.../nodes/object/GetDictIfExistsNode.java | 2 +-
.../nodes/object/GetOrCreateDictNode.java | 2 +-
.../nodes/object/GetRegisteredClassNode.java | 2 +-
.../nodes/statement/AbstractImportNode.java | 28 +-
.../python/nodes/util/BadOPCodeNode.java | 4 +-
.../python/nodes/util/CastToByteNode.java | 39 +--
.../nodes/util/CastToJavaBigIntegerNode.java | 6 +-
.../nodes/util/CastToJavaBooleanNode.java | 4 +-
.../python/nodes/util/CastToJavaByteNode.java | 14 +-
.../nodes/util/CastToJavaIntExactNode.java | 16 +-
.../nodes/util/CastToJavaLongExactNode.java | 12 +-
.../python/nodes/util/CastToJavaLongNode.java | 4 +-
.../nodes/util/CastToJavaShortNode.java | 14 +-
.../util/CastToJavaUnsignedLongNode.java | 17 +-
.../nodes/util/CoerceToComplexNode.java | 4 +-
.../graal/python/runtime/NFIPosixSupport.java | 4 +-
.../graal/python/runtime/PythonContext.java | 4 +-
.../formatting/BytesFormatProcessor.java | 12 +-
.../runtime/formatting/FormatProcessor.java | 20 +-
.../runtime/formatting/IntegerFormatter.java | 6 +-
.../runtime/formatting/InternalFormat.java | 20 +-
.../formatting/StringFormatProcessor.java | 6 +-
.../graal/python/runtime/object/PFactory.java | 18 +-
.../storage/ForeignSequenceStorage.java | 26 +-
.../graal/python/util/NumericSupport.java | 12 +-
.../oracle/graal/python/util/PythonUtils.java | 2 +-
496 files changed, 5414 insertions(+), 5461 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java
diff --git a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
index 465666c897..0b1c8e852f 100755
--- a/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
+++ b/graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py
@@ -44,7 +44,6 @@
from asdl import java_file
from asdl import model
-
SST_PACKAGE = 'com.oracle.graal.python.pegparser.sst'
AST_PACKAGE = 'com.oracle.graal.python.builtins.modules.ast'
@@ -338,6 +337,7 @@ def visit_module(self, module: model.Module):
@staticmethod
def emit_imports(module, emitter):
emitter.println()
+ emitter.println('import com.oracle.truffle.api.nodes.Node;')
emitter.println('import com.oracle.graal.python.builtins.objects.PNone;')
emitter.println('import com.oracle.graal.python.pegparser.sst.ConstantValue;')
top_level_class_names = [t.name.java for t in module.types]
@@ -346,8 +346,8 @@ def emit_imports(module, emitter):
emitter.println('import com.oracle.graal.python.pegparser.tokenizer.SourceRange;')
def emit_constructor(self, emitter: java_file.Emitter):
- with emitter.define(f'{self.CLASS_NAME}({AstStateGenerator.CLASS_NAME} state)'):
- emitter.println('super(state);')
+ with emitter.define(f'{self.CLASS_NAME}(Node node, {AstStateGenerator.CLASS_NAME} state)'):
+ emitter.println('super(node, state);')
@staticmethod
def visit_enum(c: model.Enum, emitter: java_file.Emitter):
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
index f7ecc2a1ce..328fe43789 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
@@ -607,7 +607,7 @@ protected CallTarget parse(ParsingRequest request) {
}
if (MIME_TYPE_BYTECODE.equals(source.getMimeType())) {
byte[] bytes = source.getBytes().toByteArray();
- CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(context, bytes);
+ CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(null, context, bytes);
boolean internal = shouldMarkSourceInternal(context);
// The original file path should be passed as the name
String name = source.getName();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
index 18b4c9bb56..51a5c1bbc3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -105,7 +105,7 @@ static Object init(Object object,
return PNone.NONE;
}
if ((val & COLLECTION_FLAGS) == COLLECTION_FLAGS) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.ABC_FLAGS_CANNOT_BE_SEQUENCE_AND_MAPPING);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ABC_FLAGS_CANNOT_BE_SEQUENCE_AND_MAPPING);
}
long tpFlags = TypeNodes.GetTypeFlagsNode.getUncached().execute(object);
tpFlags |= (val & COLLECTION_FLAGS);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
index fcf8ecaef9..7cb4676972 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java
@@ -130,10 +130,10 @@ static Object array2(VirtualFrame frame, Object cls, Object[] args, PKeyword[] k
@Cached IsBuiltinClassExactProfile isNotSubtypeProfile,
@Cached CastToTruffleStringCheckedNode cast,
@Cached ArrayNodeInternal arrayNodeInternal,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
if (isNotSubtypeProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PArray)) {
if (kwargs.length != 0) {
- throw raise.get(inliningTarget).raise(TypeError, S_TAKES_NO_KEYWORD_ARGS, "array.array()");
+ throw raise.raise(inliningTarget, TypeError, S_TAKES_NO_KEYWORD_ARGS, "array.array()");
}
}
Object initializer = hasInitializerProfile.profile(inliningTarget, args.length == 2) ? args[1] : PNone.NO_VALUE;
@@ -144,9 +144,9 @@ static Object array2(VirtualFrame frame, Object cls, Object[] args, PKeyword[] k
@SuppressWarnings("unused")
Object error(Object cls, Object[] args, PKeyword[] kwargs) {
if (args.length < 2) {
- throw raise(TypeError, S_TAKES_AT_LEAST_D_ARGUMENTS_D_GIVEN, T_ARRAY, 2, args.length);
+ throw PRaiseNode.raiseStatic(this, TypeError, S_TAKES_AT_LEAST_D_ARGUMENTS_D_GIVEN, T_ARRAY, 2, args.length);
} else {
- throw raise(TypeError, S_TAKES_AT_MOST_D_ARGUMENTS_D_GIVEN, T_ARRAY, 3, args.length);
+ throw PRaiseNode.raiseStatic(this, TypeError, S_TAKES_AT_MOST_D_ARGUMENTS_D_GIVEN, T_ARRAY, 3, args.length);
}
}
@@ -190,7 +190,7 @@ static PArray arrayWithRangeInitializer(Node inliningTarget, Object cls, Truffle
array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format, range.getIntLength());
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
int start = range.getIntStart();
@@ -223,10 +223,10 @@ static PArray arrayWithStringInitializer(VirtualFrame frame, Node inliningTarget
@Bind PythonLanguage language,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(inline = false) ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
BufferFormat format = getFormatCheckedNode.execute(inliningTarget, typeCode);
if (format != BufferFormat.UNICODE) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_USE_STR_TO_INITIALIZE_ARRAY, typeCode);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_USE_STR_TO_INITIALIZE_ARRAY, typeCode);
}
PArray array = PFactory.createArray(language, cls, getInstanceShape.execute(cls), typeCode, format);
fromUnicodeNode.execute(frame, array, initializer);
@@ -251,7 +251,7 @@ static PArray arrayArrayInitializer(VirtualFrame frame, Node inliningTarget, Obj
return array;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -275,7 +275,7 @@ static PArray arraySequenceInitializer(VirtualFrame frame, Node inliningTarget,
return array;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -310,7 +310,7 @@ static PArray arrayIteratorInitializer(VirtualFrame frame, Node inliningTarget,
ensureCapacityNode.execute(inliningTarget, array, length);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
putValueNode.execute(frame, inliningTarget, array, length - 1, nextValue);
}
@@ -328,14 +328,14 @@ abstract static class GetFormatCheckedNode extends Node {
static BufferFormat get(Node inliningTarget, TruffleString typeCode,
@Cached(inline = false) TruffleString.CodePointLengthNode lengthNode,
@Cached(inline = false) TruffleString.CodePointAtIndexNode atIndexNode,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached(value = "createIdentityProfile()", inline = false) ValueProfile valueProfile) {
if (lengthNode.execute(typeCode, TS_ENCODING) != 1) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.ARRAY_ARG_1_MUST_BE_UNICODE);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.ARRAY_ARG_1_MUST_BE_UNICODE);
}
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
if (format == null) {
- throw raise.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_TYPECODE);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
}
return valueProfile.profile(format);
}
@@ -363,10 +363,10 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode,
@Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
if (format == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_TYPECODE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
}
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format),
getInstanceShape, raiseNode);
@@ -383,10 +383,10 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode,
@Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
if (format == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_TYPECODE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
}
return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format, getInstanceShape,
raiseNode);
@@ -395,9 +395,9 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Object arrayType, TruffleString typeCode, int mformatCode, PBytes bytes, PyObjectCallMethodObjArgs callDecode,
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, IsSubtypeNode isSubtypeNode,
ArrayBuiltins.ByteSwapNode byteSwapNode, BufferFormat format,
- TypeNodes.GetInstanceShape getInstanceShape, PRaiseNode.Lazy raiseNode) {
+ TypeNodes.GetInstanceShape getInstanceShape, PRaiseNode raiseNode) {
if (!isSubtypeNode.execute(frame, arrayType, PythonBuiltinClassType.PArray)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.N_NOT_SUBTYPE_OF_ARRAY, arrayType);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_NOT_SUBTYPE_OF_ARRAY, arrayType);
}
MachineFormat machineFormat = MachineFormat.fromCode(mformatCode);
if (machineFormat != null) {
@@ -420,15 +420,15 @@ private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Obj
}
return array;
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.THIRD_ARG_MUST_BE_A_VALID_MACHINE_CODE_FMT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.THIRD_ARG_MUST_BE_A_VALID_MACHINE_CODE_FMT);
}
}
@Specialization(guards = "!isPBytes(value)")
@SuppressWarnings("unused")
static Object error(Object arrayType, TruffleString typeCode, int mformatCode, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.FOURTH_ARG_SHOULD_BE_BYTES, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.FOURTH_ARG_SHOULD_BE_BYTES, value);
}
protected static boolean isPBytes(Object obj) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
index b0b39be693..c6a9900c1c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AsyncioModuleBuiltins.java
@@ -99,7 +99,7 @@ static Object getCurrentLoop(
@Cached PRaiseNode raise) {
Object eventLoop = context.getThreadState(context.getLanguage(inliningTarget)).getRunningEventLoop();
if (eventLoop == null) {
- throw raise.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.NO_RUNNING_EVENT_LOOP);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.NO_RUNNING_EVENT_LOOP);
} else {
return eventLoop;
}
@@ -189,7 +189,7 @@ public Object enterTask(VirtualFrame frame, PythonModule self, Object loop, Obje
if (item == null) {
set.execute(frame, inliningTarget, dict, loop, task);
} else {
- throw raise.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANT_ENTER_TASK_ALREADY_RUNNING, task, item);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANT_ENTER_TASK_ALREADY_RUNNING, task, item);
}
return PNone.NONE;
}
@@ -210,7 +210,7 @@ public Object leaveTask(VirtualFrame frame, PythonModule self, Object loop, Obje
item = PNone.NONE;
}
if (item != task) {
- throw raise.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.TASK_NOT_ENTERED, task, item);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.TASK_NOT_ENTERED, task, item);
}
del.execute(frame, inliningTarget, dict, loop);
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
index 0511a7b818..aae17200d2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
@@ -154,9 +154,9 @@ static Object asciiString(TruffleString value,
@Specialization(guards = "!isAscii(value, getCodeRangeNode)")
static Object nonAsciiString(@SuppressWarnings("unused") TruffleString value,
- @Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.STRING_ARG_SHOULD_CONTAIN_ONLY_ASCII);
+ @Bind("this") Node inliningTarget,
+ @Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.STRING_ARG_SHOULD_CONTAIN_ONLY_ASCII);
}
@Specialization
@@ -164,20 +164,19 @@ static Object string(PString value,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode cast,
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
- @Cached InlinedConditionProfile asciiProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached InlinedConditionProfile asciiProfile) {
TruffleString ts = cast.execute(inliningTarget, value);
if (asciiProfile.profile(inliningTarget, isAscii(ts, getCodeRangeNode))) {
return asciiString(ts, getCodeRangeNode);
} else {
- return nonAsciiString(ts, getCodeRangeNode, raiseNode.get(inliningTarget));
+ return nonAsciiString(ts, inliningTarget, getCodeRangeNode);
}
}
@Fallback
static Object error(@SuppressWarnings("unused") Object value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ARG_SHOULD_BE_BYTES_BUFFER_OR_ASCII_NOT_P, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ARG_SHOULD_BE_BYTES_BUFFER_OR_ASCII_NOT_P, value);
}
@ClinicConverterFactory
@@ -227,19 +226,19 @@ private ByteSequenceStorage b64decode(byte[] data, int dataLen, boolean strictMo
} else if (c == '=') {
padding++;
} else if (strictMode) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.ONLY_BASE64_DATA_IS_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, ErrorMessages.ONLY_BASE64_DATA_IS_ALLOWED);
}
}
int expectedPadding = 0;
if (base64chars % 4 == 1) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.INVALID_BASE64_ENCODED_STRING);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, ErrorMessages.INVALID_BASE64_ENCODED_STRING);
} else if (base64chars % 4 == 2) {
expectedPadding = 2;
} else if (base64chars % 4 == 3) {
expectedPadding = 1;
}
if (padding < expectedPadding) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.INCORRECT_PADDING);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, ErrorMessages.INCORRECT_PADDING);
}
// Find the end of the expected padding, if any
int decodeLen = lastBase64Char + 1;
@@ -263,7 +262,7 @@ private ByteSequenceStorage b64decode(byte[] data, int dataLen, boolean strictMo
ByteBuffer result = decoder.decode(ByteBuffer.wrap(data, 0, decodeLen));
return new ByteSequenceStorage(result.array(), result.limit());
} catch (IllegalArgumentException e) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, e);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, e);
}
}
@@ -293,7 +292,7 @@ PBytes a2b(VirtualFrame frame, Object buffer,
@TruffleBoundary
private byte[] a2b(byte[] bytes, int length) {
if (length % 2 != 0) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.ODD_LENGTH_STRING);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, ErrorMessages.ODD_LENGTH_STRING);
}
byte[] output = new byte[length / 2];
for (int i = 0; i < length / 2; i++) {
@@ -310,7 +309,7 @@ private int digitValue(char b) {
} else if (b >= 'A' && b <= 'F') {
return b - 'A' + 10;
} else {
- throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.NON_HEX_DIGIT_FOUND);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, ErrorMessages.NON_HEX_DIGIT_FOUND);
}
}
@@ -331,7 +330,7 @@ private PBytes b2a(byte[] data, int lenght, int newline, PythonLanguage language
try {
encoded = Base64.getEncoder().encode(ByteBuffer.wrap(data, 0, lenght));
} catch (IllegalArgumentException e) {
- throw PRaiseNode.raiseUncached(this, BinasciiError, e);
+ throw PRaiseNode.raiseStatic(this, BinasciiError, e);
}
if (newline != 0) {
byte[] encodedWithNL = Arrays.copyOf(encoded.array(), encoded.limit() + 1);
@@ -373,10 +372,10 @@ static PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (sep != PNone.NO_VALUE || bytesPerSep != 1) {
// TODO implement sep and bytes_per_sep
- throw raiseNode.get(inliningTarget).raise(NotImplementedError);
+ throw raiseNode.raise(inliningTarget, NotImplementedError);
}
try {
return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), language);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
index 985c7f9d0d..5f86503a3b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java
@@ -259,6 +259,7 @@
import com.oracle.truffle.api.nodes.LoopNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
@@ -321,7 +322,7 @@ static Object doCallBytes(VirtualFrame frame, Object cls, Object source, PNone e
@Cached PyBytesCheckNode check,
@Exclusive @Cached BytesNodes.BytesInitNode bytesInitNode,
@Exclusive @Cached CreateBytes createBytes,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object bytesMethod = lookupBytes.execute(frame, getClassNode.execute(inliningTarget, source), source);
if (hasBytes.profile(inliningTarget, bytesMethod != PNone.NO_VALUE)) {
Object bytes = callBytes.executeObject(frame, bytesMethod, source);
@@ -332,7 +333,7 @@ static Object doCallBytes(VirtualFrame frame, Object cls, Object source, PNone e
return createBytes.execute(inliningTarget, cls, toBytesNode.execute(frame, bytes));
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__, bytes);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__, bytes);
}
}
return createBytes.execute(inliningTarget, cls, bytesInitNode.execute(frame, inliningTarget, source, encoding, errors));
@@ -506,7 +507,7 @@ Object complexFromDouble(VirtualFrame frame, Object cls, PFloat real, @SuppressW
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode isBuiltinObjectProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return complexFromObject(frame, cls, real, imag, inliningTarget, createComplexNode, canBeDoubleNode, asDoubleNode, isComplexType, isResultComplexType, isPrimitiveProfile,
isBuiltinObjectProfile,
raiseNode);
@@ -536,7 +537,7 @@ Object complexFromLong(VirtualFrame frame, Object cls, PInt real, @SuppressWarni
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode complexCheck,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return complexFromObject(frame, cls, real, imag, inliningTarget, createComplexNode, canBeDoubleNode, asDoubleNode, isComplexType, isResultComplexType, isPrimitiveProfile, complexCheck,
raiseNode);
}
@@ -551,13 +552,13 @@ Object complexFromObject(VirtualFrame frame, Object cls, Object number, @Suppres
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
@Shared("isPrimitive") @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
@Shared("isBuiltinObj") @Cached PyComplexCheckExactNode complexCheck,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex value = getComplexNumberFromObject(frame, number, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
if (canBeDoubleNode.execute(inliningTarget, number)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, number), 0.0);
} else {
- throw raiseFirstArgError(number, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(number, inliningTarget, raiseNode);
}
}
if (isPrimitiveProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PComplex)) {
@@ -598,13 +599,13 @@ Object complexFromComplexLong(VirtualFrame frame, Object cls, Object one, long t
@Shared("floatAsDouble") @Cached PyFloatAsDoubleNode asDoubleNode,
@Shared("isComplex") @Cached PyComplexCheckExactNode isComplexType,
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex value = getComplexNumberFromObject(frame, one, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
if (canBeDoubleNode.execute(inliningTarget, one)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, one), two);
} else {
- throw raiseFirstArgError(one, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(one, inliningTarget, raiseNode);
}
}
return createComplexNode.execute(inliningTarget, cls, value.getReal(), value.getImag() + two);
@@ -618,13 +619,13 @@ Object complexFromComplexDouble(VirtualFrame frame, Object cls, Object one, doub
@Shared("floatAsDouble") @Cached PyFloatAsDoubleNode asDoubleNode,
@Shared("isComplex") @Cached PyComplexCheckExactNode isComplexType,
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex value = getComplexNumberFromObject(frame, one, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
if (canBeDoubleNode.execute(inliningTarget, one)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, one), two);
} else {
- throw raiseFirstArgError(one, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(one, inliningTarget, raiseNode);
}
}
return createComplexNode.execute(inliningTarget, cls, value.getReal(), value.getImag() + two);
@@ -638,13 +639,13 @@ Object complexFromComplexPInt(VirtualFrame frame, Object cls, Object one, PInt t
@Shared("floatAsDouble") @Cached PyFloatAsDoubleNode asDoubleNode,
@Shared("isComplex") @Cached PyComplexCheckExactNode isComplexType,
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex value = getComplexNumberFromObject(frame, one, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
if (canBeDoubleNode.execute(inliningTarget, one)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, one), two.doubleValueWithOverflow(this));
} else {
- throw raiseFirstArgError(one, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(one, inliningTarget, raiseNode);
}
}
return createComplexNode.execute(inliningTarget, cls, value.getReal(), value.getImag() + two.doubleValueWithOverflow(this));
@@ -658,13 +659,13 @@ Object complexFromComplexComplex(VirtualFrame frame, Object cls, Object one, PCo
@Shared("floatAsDouble") @Cached PyFloatAsDoubleNode asDoubleNode,
@Shared("isComplex") @Cached PyComplexCheckExactNode isComplexType,
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex value = getComplexNumberFromObject(frame, one, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (value == null) {
if (canBeDoubleNode.execute(inliningTarget, one)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, one) - two.getImag(), two.getReal());
} else {
- throw raiseFirstArgError(one, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(one, inliningTarget, raiseNode);
}
}
return createComplexNode.execute(inliningTarget, cls, value.getReal() - two.getImag(), value.getImag() + two.getReal());
@@ -679,7 +680,7 @@ Object complexFromComplexObject(VirtualFrame frame, Object cls, Object one, Obje
@Shared("floatAsDouble") @Cached PyFloatAsDoubleNode asDoubleNode,
@Shared("isComplex") @Cached PyComplexCheckExactNode isComplexType,
@Shared("isComplexResult") @Cached PyComplexCheckExactNode isResultComplexType,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PComplex oneValue = getComplexNumberFromObject(frame, one, inliningTarget, isComplexType, isResultComplexType, raiseNode);
if (canBeDoubleNode.execute(inliningTarget, two)) {
double twoValue = asDoubleNode.execute(frame, inliningTarget, two);
@@ -687,12 +688,12 @@ Object complexFromComplexObject(VirtualFrame frame, Object cls, Object one, Obje
if (canBeDoubleNode.execute(inliningTarget, one)) {
return createComplexNode.execute(inliningTarget, cls, asDoubleNode.execute(frame, inliningTarget, one), twoValue);
} else {
- throw raiseFirstArgError(one, raiseNode.get(inliningTarget));
+ throw raiseFirstArgError(one, inliningTarget, raiseNode);
}
}
return createComplexNode.execute(inliningTarget, cls, oneValue.getReal(), oneValue.getImag() + twoValue);
} else {
- throw raiseSecondArgError(two, raiseNode.get(inliningTarget));
+ throw raiseSecondArgError(two, inliningTarget, raiseNode);
}
}
@@ -700,9 +701,9 @@ Object complexFromComplexObject(VirtualFrame frame, Object cls, Object one, Obje
Object complexFromString(VirtualFrame frame, Object cls, TruffleString real, Object imaginary,
@Bind("this") Node inliningTarget,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (imaginary != PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.COMPLEX_CANT_TAKE_ARG);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.COMPLEX_CANT_TAKE_ARG);
}
return convertStringToComplex(frame, inliningTarget, toJavaStringNode.execute(real), cls, real, raiseNode);
}
@@ -711,9 +712,9 @@ Object complexFromString(VirtualFrame frame, Object cls, TruffleString real, Obj
Object complexFromString(VirtualFrame frame, Object cls, PString real, Object imaginary,
@Bind("this") Node inliningTarget,
@Cached CastToJavaStringNode castToStringNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (imaginary != PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.COMPLEX_CANT_TAKE_ARG);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.COMPLEX_CANT_TAKE_ARG);
}
return convertStringToComplex(frame, inliningTarget, castToStringNode.execute(real), cls, real, raiseNode);
}
@@ -734,16 +735,16 @@ private WarnNode getWarnNode() {
return warnNode;
}
- private static PException raiseFirstArgError(Object x, PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_NUMBER, "complex() first", x);
+ private static PException raiseFirstArgError(Object x, Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_NUMBER, "complex() first", x);
}
- private static PException raiseSecondArgError(Object x, PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_MUST_BE_NUMBER, "complex() second", x);
+ private static PException raiseSecondArgError(Object x, Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_MUST_BE_NUMBER, "complex() second", x);
}
private PComplex getComplexNumberFromObject(VirtualFrame frame, Object object, Node inliningTarget,
- PyComplexCheckExactNode isComplexType, PyComplexCheckExactNode isResultComplexType, PRaiseNode.Lazy raiseNode) {
+ PyComplexCheckExactNode isComplexType, PyComplexCheckExactNode isResultComplexType, PRaiseNode raiseNode) {
if (isComplexType.execute(inliningTarget, object)) {
return (PComplex) object;
} else {
@@ -756,7 +757,7 @@ private PComplex getComplexNumberFromObject(VirtualFrame frame, Object object, N
}
return (PComplex) result;
} else if (result != PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, result);
}
if (object instanceof PComplex) {
// the class extending PComplex but doesn't have __complex__ method
@@ -769,12 +770,12 @@ private PComplex getComplexNumberFromObject(VirtualFrame frame, Object object, N
@Fallback
@SuppressWarnings("unused")
static Object complexGeneric(Object cls, Object realObj, Object imaginaryObj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "complex.__new__(X): X", cls);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "complex.__new__(X): X", cls);
}
// Adapted from CPython's complex_subtype_from_string
- private Object convertStringToComplex(VirtualFrame frame, Node inliningTarget, String src, Object cls, Object origObj, PRaiseNode.Lazy raiseNode) {
+ private Object convertStringToComplex(VirtualFrame frame, Node inliningTarget, String src, Object cls, Object origObj, PRaiseNode raiseNode) {
String str = FloatUtils.removeUnicodeAndUnderscores(src);
if (str == null) {
if (callReprNode == null) {
@@ -783,18 +784,18 @@ private Object convertStringToComplex(VirtualFrame frame, Node inliningTarget, S
}
Object strStr = callReprNode.executeObject(frame, origObj);
if (PGuards.isString(strStr)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.COULD_NOT_CONVERT_STRING_TO_COMPLEX, strStr);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.COULD_NOT_CONVERT_STRING_TO_COMPLEX, strStr);
} else {
// During the formatting of "ValueError: invalid literal ..." exception,
// CPython attempts to raise "TypeError: __repr__ returned non-string",
// which gets later overwitten with the original "ValueError",
// but without any message (since the message formatting failed)
- throw raiseNode.get(inliningTarget).raise(ValueError);
+ throw raiseNode.raise(inliningTarget, ValueError);
}
}
Object c = convertStringToComplexOrNull(str, cls);
if (c == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.COMPLEX_ARG_IS_MALFORMED_STR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.COMPLEX_ARG_IS_MALFORMED_STR);
}
return c;
}
@@ -992,8 +993,8 @@ static boolean isIntegerIndex(Object idx) {
@Specialization(guards = "!isIntegerIndex(start)")
static void enumerate(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object iterable, Object start,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, start);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, start);
}
}
@@ -1072,12 +1073,12 @@ static Object reversed(VirtualFrame frame, Object cls, Object sequence,
@Cached PySequenceCheckNode pySequenceCheck,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object sequenceKlass = getClassNode.execute(inliningTarget, sequence);
Object reversed = lookupReversed.execute(frame, sequenceKlass, sequence);
if (noReversedProfile.profile(inliningTarget, reversed == PNone.NO_VALUE)) {
if (!pySequenceCheck.execute(inliningTarget, sequence)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_ISNT_REVERSIBLE, sequence);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_ISNT_REVERSIBLE, sequence);
} else {
int lengthHint = pySequenceSizeNode.execute(frame, inliningTarget, sequence);
return PFactory.createSequenceReverseIterator(language, cls, getInstanceShape.execute(cls), sequence, lengthHint);
@@ -1344,15 +1345,15 @@ static Object doWithBase(VirtualFrame frame, Node inliningTarget, Object x, Obje
@Cached PyLongFromUnicodeObject longFromUnicode,
@Cached BytesNodes.BytesLikeCheck bytesLikeCheck,
@Cached PyNumberLongNode.LongFromBufferNode fromBufferNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (x == PNone.NO_VALUE) {
missingArgument.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INT_MISSING_STRING_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INT_MISSING_STRING_ARGUMENT);
}
int base = asSizeNode.executeLossy(frame, inliningTarget, baseObj);
if ((base != 0 && base < 2) || base > 36) {
wrongBase.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INT_BASE_MUST_BE_2_AND_36_OR_0);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INT_BASE_MUST_BE_2_AND_36_OR_0);
}
if (unicodeCheckNode.execute(inliningTarget, x)) {
return longFromUnicode.execute(inliningTarget, x, base);
@@ -1360,7 +1361,7 @@ static Object doWithBase(VirtualFrame frame, Node inliningTarget, Object x, Obje
return fromBufferNode.execute(frame, x, base);
}
cannotConvert.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INT_CANT_CONVERT_STRING_WITH_EXPL_BASE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INT_CANT_CONVERT_STRING_WITH_EXPL_BASE);
}
}
}
@@ -1438,7 +1439,7 @@ static PException report(VirtualFrame frame, Object type,
int methodCount = sizeNode.execute(frame, inliningTarget, list);
callSort.execute(frame, inliningTarget, list, T_SORT);
TruffleString joined = cast.execute(inliningTarget, callJoin.execute(frame, inliningTarget, T_COMMA_SPACE, T_JOIN, list));
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_INSTANTIATE_ABSTRACT_CLASS_WITH_ABSTRACT_METHODS, type, methodCount > 1 ? "s" : "", joined);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_INSTANTIATE_ABSTRACT_CLASS_WITH_ABSTRACT_METHODS, type, methodCount > 1 ? "s" : "", joined);
}
}
@@ -1459,12 +1460,12 @@ static void check(Node inliningTarget, Object type, Object[] args, PKeyword[] kw
@Cached(parameters = "Init", inline = false) LookupCallableSlotInMRONode lookupInit,
@Cached(parameters = "New", inline = false) LookupCallableSlotInMRONode lookupNew,
@Cached TypeNodes.CheckCallableIsSpecificBuiltinNode checkSlotIs,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!checkSlotIs.execute(inliningTarget, lookupNew.execute(type), BuiltinConstructorsFactory.ObjectNodeFactory.getInstance())) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEW_TAKES_ONE_ARG);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NEW_TAKES_ONE_ARG);
}
if (checkSlotIs.execute(inliningTarget, lookupInit.execute(type), ObjectBuiltinsFactory.InitNodeFactory.getInstance())) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEW_TAKES_NO_ARGS, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NEW_TAKES_NO_ARGS, type);
}
}
}
@@ -1547,7 +1548,7 @@ static Object call(Object cls,
@SuppressWarnings("unused")
@Fallback
Object fallback(Object o, Object[] varargs, PKeyword[] kwargs) {
- throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "object.__new__(X): X", o);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "object.__new__(X): X", o);
}
@InliningCutoff
@@ -1582,7 +1583,7 @@ static Object doIntStop(Object cls, int stop, @SuppressWarnings("unused") PNone
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doInt(cls, 0, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, raiseNode);
}
@@ -1591,7 +1592,7 @@ static Object doPintStop(Object cls, PInt stop, @SuppressWarnings("unused") PNon
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doPint(cls, PFactory.createInt(language, BigInteger.ZERO), stop, PFactory.createInt(language, BigInteger.ONE), inliningTarget, language, lenOfRangeNode, raiseNode);
}
@@ -1605,7 +1606,7 @@ static Object doGenericStop(VirtualFrame frame, Object cls, Object stop, @Suppre
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doGeneric(frame, cls, 0, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, raiseNode);
}
@@ -1617,7 +1618,7 @@ static Object doIntStartStop(Object cls, int start, int stop, @SuppressWarnings(
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doInt(cls, start, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, raiseNode);
}
@@ -1626,7 +1627,7 @@ static Object doPintStartStop(Object cls, PInt start, PInt stop, @SuppressWarnin
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doPint(cls, start, stop, PFactory.createInt(language, BigInteger.ONE), inliningTarget, language, lenOfRangeNode, raiseNode);
}
@@ -1640,7 +1641,7 @@ static Object doGenericStartStop(VirtualFrame frame, Object cls, Object start, O
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doGeneric(frame, cls, start, stop, 1, inliningTarget, language, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode, raiseNode);
}
@@ -1652,9 +1653,9 @@ static Object doInt(@SuppressWarnings("unused") Object cls, int start, int stop,
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNode,
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (step == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
+ throw raiseNode.raise(inliningTarget, ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
}
try {
int len = lenOfRangeNode.executeInt(inliningTarget, start, stop, step);
@@ -1670,9 +1671,9 @@ static Object doPint(@SuppressWarnings("unused") Object cls, PInt start, PInt st
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (step.isZero()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
+ throw raiseNode.raise(inliningTarget, ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
}
BigInteger len = lenOfRangeNode.execute(inliningTarget, start.getValue(), stop.getValue(), step.getValue());
return PFactory.createBigRange(language, start, stop, step, PFactory.createInt(language, len));
@@ -1688,7 +1689,7 @@ static Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object c
@Shared("cast") @Cached CastToJavaIntExactNode cast,
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object lstart = indexNode.execute(frame, inliningTarget, start);
Object lstop = indexNode.execute(frame, inliningTarget, stop);
Object lstep = indexNode.execute(frame, inliningTarget, step);
@@ -1823,12 +1824,12 @@ static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encodi
@Exclusive @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached("create(T_DECODE)") LookupAndCallTernaryNode callDecodeNode,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = acquireLib.acquireReadonly(obj, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
}
try {
// TODO(fa): we should directly call '_codecs.decode'
@@ -1841,7 +1842,7 @@ static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encodi
} else if (isPStringProfile.profile(inliningTarget, result instanceof PString)) {
return result;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.P_S_RETURNED_NON_STRING, bytesObj, "decode", result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.P_S_RETURNED_NON_STRING, bytesObj, "decode", result);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -1883,12 +1884,12 @@ static Object doNativeSubclassEncodeErr(VirtualFrame frame, Object cls, Object o
@Exclusive @Cached("create(T_DECODE)") LookupAndCallTernaryNode callDecodeNode,
@Shared @Cached(neverDefault = true) CExtNodes.StringSubtypeNew subtypeNew,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = acquireLib.acquireReadonly(obj, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
}
try {
PBytes bytesObj = PFactory.createBytes(PythonLanguage.get(inliningTarget), bufferLib.getCopiedByteArray(buffer));
@@ -1899,7 +1900,7 @@ static Object doNativeSubclassEncodeErr(VirtualFrame frame, Object cls, Object o
} else if (isPStringProfile.profile(inliningTarget, result instanceof PString)) {
return subtypeNew.call(cls, result);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.P_S_RETURNED_NON_STRING, bytesObj, "decode", result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.P_S_RETURNED_NON_STRING, bytesObj, "decode", result);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -1978,8 +1979,8 @@ protected static boolean isSubtypeOfTuple(VirtualFrame frame, IsSubtypeNode isSu
@Fallback
static PTuple tupleObject(Object cls, @SuppressWarnings("unused") Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
}
@@ -2019,17 +2020,17 @@ static PZip zip(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kw,
@Cached PyObjectIsTrueNode isTrueNode,
@Cached InlinedConditionProfile profile,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (profile.profile(inliningTarget, eqNode.execute(kw[0].getName(), T_STRICT, TS_ENCODING))) {
return zip(frame, inliningTarget, cls, args, isTrueNode.execute(frame, kw[0].getValue()), getIter, getInstanceShape);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_IS_AN_INVALID_ARG_FOR_S, kw[0].getName(), T_ZIP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_IS_AN_INVALID_ARG_FOR_S, kw[0].getName(), T_ZIP);
}
@Specialization(guards = "kw.length != 1")
static Object zip(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object[] args, PKeyword[] kw,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.S_TAKES_AT_MOST_ONE_KEYWORD_ARGUMENT_D_GIVEN, T_ZIP, kw.length);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.S_TAKES_AT_MOST_ONE_KEYWORD_ARGUMENT_D_GIVEN, T_ZIP, kw.length);
}
private static PZip zip(VirtualFrame frame, Node inliningTarget, Object cls, Object[] args, boolean strict, PyObjectGetIter getIter, TypeNodes.GetInstanceShape getInstanceShape) {
@@ -2113,8 +2114,8 @@ static PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PD
@Fallback
@SuppressWarnings("unused")
static PFunction function(@SuppressWarnings("unused") Object cls, Object code, Object globals, Object name, Object defaultArgs, Object closure,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.FUNC_CONSTRUCTION_NOT_SUPPORTED, cls, code, globals, name, defaultArgs, closure);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.FUNC_CONSTRUCTION_NOT_SUPPORTED, cls, code, globals, name, defaultArgs, closure);
}
}
@@ -2125,8 +2126,8 @@ public abstract static class BuiltinFunctionNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static PFunction function(Object cls, Object method_def, Object def, Object name, Object module,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "method_descriptor");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "method_descriptor");
}
}
@@ -2136,6 +2137,7 @@ static PFunction function(Object cls, Object method_def, Object def, Object name
public abstract static class TypeNode extends PythonVarargsBuiltinNode {
@Child private IsSubtypeNode isSubtypeNode;
@Child private IsAcceptableBaseNode isAcceptableBaseNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
public abstract Object execute(VirtualFrame frame, Object cls, Object name, Object bases, Object dict, PKeyword[] kwds);
@@ -2144,7 +2146,8 @@ public final Object execute(VirtualFrame frame, Object self, Object[] arguments,
if (arguments.length == 3) {
return execute(frame, self, arguments[0], arguments[1], arguments[2], keywords);
} else {
- throw raise(TypeError, ErrorMessages.TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, "type.__new__", 3, arguments.length);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, "type.__new__", 3, arguments.length);
}
}
@@ -2155,7 +2158,8 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
} else if (arguments.length == 3) {
return execute(frame, self, arguments[0], arguments[1], arguments[2], keywords);
} else {
- throw raise(TypeError, ErrorMessages.TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, "type.__new__", 3, arguments.length);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, "type.__new__", 3, arguments.length);
}
}
@@ -2193,9 +2197,9 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
@Fallback
Object generic(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object name, Object bases, Object namespace, @SuppressWarnings("unused") PKeyword[] kwds) {
if (!(bases instanceof PTuple)) {
- throw raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "type.__new__()", 2, "tuple", bases);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "type.__new__()", 2, "tuple", bases);
} else if (!(namespace instanceof PDict)) {
- throw raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "type.__new__()", 3, "dict", bases);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "type.__new__()", 3, "dict", bases);
} else {
throw CompilerDirectives.shouldNotReachHere("type fallback reached incorrectly");
}
@@ -2206,10 +2210,10 @@ private Object calculateMetaclass(VirtualFrame frame, Node inliningTarget, Objec
Object winner = cls;
for (Object base : getObjectArrayNode.execute(inliningTarget, bases)) {
if (!isTypeNode.execute(inliningTarget, base) && lookupMroEntries.execute(frame, inliningTarget, base, T___MRO_ENTRIES__) != PNone.NO_VALUE) {
- throw raise(TypeError, ErrorMessages.TYPE_DOESNT_SUPPORT_MRO_ENTRY_RESOLUTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_SUPPORT_MRO_ENTRY_RESOLUTION);
}
if (!ensureIsAcceptableBaseNode().execute(base)) {
- throw raise(TypeError, ErrorMessages.TYPE_IS_NOT_ACCEPTABLE_BASE_TYPE, base);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.TYPE_IS_NOT_ACCEPTABLE_BASE_TYPE, base);
}
Object typ = getClassNode.execute(inliningTarget, base);
if (isSubType(frame, winner, typ)) {
@@ -2218,7 +2222,7 @@ private Object calculateMetaclass(VirtualFrame frame, Node inliningTarget, Objec
winner = typ;
continue;
}
- throw raise(TypeError, ErrorMessages.METACLASS_CONFLICT);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.METACLASS_CONFLICT);
}
return winner;
}
@@ -2240,16 +2244,17 @@ public static TypeNode create() {
Object typeGeneric(VirtualFrame frame, Object cls, Object name, Object bases, Object dict, PKeyword[] kwds,
@Bind("this") Node inliningTarget,
@Cached TypeNode nextTypeNode,
+ @Cached PRaiseNode raiseNode,
@Exclusive @Cached IsTypeNode isTypeNode) {
if (!(name instanceof TruffleString || name instanceof PString)) {
- throw raise(TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 1", name);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 1", name);
} else if (!(bases instanceof PTuple)) {
- throw raise(TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 2", bases);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 2", bases);
} else if (!(dict instanceof PDict)) {
- throw raise(TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 3", dict);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "type() argument 3", dict);
} else if (!isTypeNode.execute(inliningTarget, cls)) {
// TODO: this is actually allowed, deal with it
- throw raise(NotImplementedError, ErrorMessages.CREATING_CLASS_NON_CLS_META_CLS);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.CREATING_CLASS_NON_CLS_META_CLS);
}
return nextTypeNode.execute(frame, cls, name, bases, dict, kwds);
}
@@ -2316,8 +2321,8 @@ public abstract static class DictKeysTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_KEYS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_KEYS);
}
}
@@ -2327,8 +2332,8 @@ public abstract static class DictKeysIteratorTypeNode extends PythonBuiltinNode
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_KEYITERATOR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_KEYITERATOR);
}
}
@@ -2338,8 +2343,8 @@ public abstract static class DictValuesTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_VALUES);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_VALUES);
}
}
@@ -2349,8 +2354,8 @@ public abstract static class DictValuesIteratorTypeNode extends PythonBuiltinNod
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_VALUEITERATOR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_VALUEITERATOR);
}
}
@@ -2360,8 +2365,8 @@ public abstract static class DictItemsTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_ITEMS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_ITEMS);
}
}
@@ -2371,8 +2376,8 @@ public abstract static class DictItemsIteratorTypeNode extends PythonBuiltinNode
@SuppressWarnings("unused")
@Specialization
static Object dictKeys(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_ITEMITERATOR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, J_DICT_ITEMITERATOR);
}
}
@@ -2382,8 +2387,8 @@ public abstract static class IteratorTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object iterator(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "iterator");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "iterator");
}
}
@@ -2393,8 +2398,8 @@ public abstract static class ArrayIteratorTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object iterator(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "arrayiterator");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "arrayiterator");
}
}
@@ -2404,8 +2409,8 @@ public abstract static class CallableIteratorTypeNode extends PythonBuiltinNode
@SuppressWarnings("unused")
@Specialization
static Object iterator(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "callable_iterator");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "callable_iterator");
}
}
@@ -2415,8 +2420,8 @@ public abstract static class GeneratorTypeNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object generator(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "generator");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "generator");
}
}
@@ -2440,11 +2445,11 @@ static Object methodGeneric(@SuppressWarnings("unused") Object cls, Object func,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached PyCallableCheckNode callableCheck,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (callableCheck.execute(inliningTarget, func)) {
return PFactory.createMethod(language, self, func);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.FIRST_ARG_MUST_BE_CALLABLE_S, "");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.FIRST_ARG_MUST_BE_CALLABLE_S, "");
}
}
}
@@ -2464,8 +2469,8 @@ Object method(@SuppressWarnings("unused") Object cls, Object self, PBuiltinFunct
public abstract static class FrameTypeNode extends PythonBuiltinNode {
@Specialization
static Object call(
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(RuntimeError, ErrorMessages.CANNOT_CALL_CTOR_OF, "frame type");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, RuntimeError, ErrorMessages.CANNOT_CALL_CTOR_OF, "frame type");
}
}
@@ -2490,15 +2495,15 @@ static Object createTraceback(@SuppressWarnings("unused") Object cls, @SuppressW
@Specialization(guards = {"!isPTraceback(next)", "!isNone(next)"})
@SuppressWarnings("unused")
static Object errorNext(Object cls, Object next, Object frame, Object lasti, Object lineno,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_TRACEBACK_OBJ_OR_NONE, next);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_TRACEBACK_OBJ_OR_NONE, next);
}
@Specialization(guards = "!isPFrame(frame)")
@SuppressWarnings("unused")
static Object errorFrame(Object cls, Object next, Object frame, Object lasti, Object lineno,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.TRACEBACK_TYPE_ARG_MUST_BE_FRAME, frame);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.TRACEBACK_TYPE_ARG_MUST_BE_FRAME, frame);
}
protected static boolean isPFrame(Object obj) {
@@ -2565,8 +2570,8 @@ static PCode call(Object cls, Object argcount, Object kwonlyargcount, Object pos
Object filename, Object name, Object qualname,
Object firstlineno, Object linetable, Object exceptiontable,
Object freevars, Object cellvars,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.INVALID_ARGS, "code");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INVALID_ARGS, "code");
}
@Override
@@ -2672,20 +2677,20 @@ static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Objec
@Cached BuiltinClassProfiles.IsBuiltinClassProfile exceptionProfile,
@Cached BuiltinClassProfiles.IsBuiltinClassProfile baseExceptionProfile,
@Cached TypeNodes.IsSameTypeNode isSameTypeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString message;
try {
message = castToStringNode.execute(inliningTarget, messageObj);
} catch (CannotCastException ex) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "BaseExceptionGroup", 1, "str", messageObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "BaseExceptionGroup", 1, "str", messageObj);
}
if (!sequenceCheckNode.execute(inliningTarget, exceptionsObj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SECOND_ARGUMENT_EXCEPTIONS_MUST_BE_A_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SECOND_ARGUMENT_EXCEPTIONS_MUST_BE_A_SEQUENCE);
}
PTuple exceptionsTuple = toTupleNode.execute(frame, exceptionsObj);
Object[] exceptions = toArrayNode.execute(inliningTarget, exceptionsTuple.getSequenceStorage());
if (exceptions.length == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SECOND_ARGUMENT_EXCEPTIONS_MUST_BE_A_NON_EMPTY_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SECOND_ARGUMENT_EXCEPTIONS_MUST_BE_A_NON_EMPTY_SEQUENCE);
}
PythonContext context = PythonContext.get(inliningTarget);
Object exceptionGroupType = getAttr.execute(inliningTarget, context.getBuiltins(), T_EXCEPTION_GROUP);
@@ -2699,7 +2704,7 @@ static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Objec
if (baseExceptionProfile.profileClass(inliningTarget, exceptionType, PythonBuiltinClassType.PBaseException)) {
nestedBaseExceptions = true;
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ITEM_D_OF_SECOND_ARGUMENT_EXCEPTIONS_IS_NOT_AN_EXCEPTION, i);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ITEM_D_OF_SECOND_ARGUMENT_EXCEPTIONS_IS_NOT_AN_EXCEPTION, i);
}
}
if (isSameTypeNode.execute(inliningTarget, cls, PythonBuiltinClassType.PBaseExceptionGroup)) {
@@ -2712,12 +2717,12 @@ static Object doManaged(VirtualFrame frame, Object cls, Object messageObj, Objec
}
} else if (isSameTypeNode.execute(inliningTarget, cls, exceptionGroupType)) {
if (nestedBaseExceptions) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_NEST_BASE_EXCEPTIONS_IN_AN_EXCEPTION_GROUP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_NEST_BASE_EXCEPTIONS_IN_AN_EXCEPTION_GROUP);
}
} else {
/* user-defined subclass */
if (nestedBaseExceptions && exceptionProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.Exception)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_NEST_BASE_EXCEPTIONS_IN_N, cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_NEST_BASE_EXCEPTIONS_IN_N, cls);
}
}
return PFactory.createBaseExceptionGroup(language, cls, getInstanceShape.execute(cls), message, exceptions, new Object[]{messageObj, exceptionsObj});
@@ -2732,19 +2737,19 @@ static Object doMapping(@SuppressWarnings("unused") Object cls, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyMappingCheckNode mappingCheckNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// descrobject.c mappingproxy_check_mapping()
if (!(obj instanceof PList || obj instanceof PTuple) && mappingCheckNode.execute(inliningTarget, obj)) {
return PFactory.createMappingproxy(language, obj);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "mappingproxy()", "mapping", obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "mappingproxy()", "mapping", obj);
}
@Specialization(guards = "isNoValue(none)")
@SuppressWarnings("unused")
static Object doMissing(Object klass, PNone none,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_POS, "mappingproxy()", "mapping", 1);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_POS, "mappingproxy()", "mapping", 1);
}
}
@@ -2752,7 +2757,7 @@ abstract static class DescriptorNode extends PythonBuiltinNode {
@TruffleBoundary
protected final void denyInstantiationAfterInitialization(TruffleString name) {
if (getContext().isCoreInitialized()) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, name);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, name);
}
}
@@ -2975,12 +2980,12 @@ static PMap doit(VirtualFrame frame, Object cls, Object[] args, PKeyword[] keywo
@Cached PyObjectGetIter getIter,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "map()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "map()");
}
if (args.length < 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MAP_MUST_HAVE_AT_LEAST_TWO_ARGUMENTS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MAP_MUST_HAVE_AT_LEAST_TWO_ARGUMENTS);
}
PMap map = PFactory.createMap(language, cls, getInstanceShape.execute(cls));
map.setFunction(args[0]);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 35ea14c64c..98b69fb966 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -288,6 +288,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -594,8 +595,8 @@ static TruffleString doL(Node inliningTarget, long x, TruffleString prefix, int
@Specialization
@SuppressWarnings("unused")
static TruffleString doD(double x, TruffleString prefix, int radix, LongToString longToString,
- @Cached(inline = false) PRaiseNode raise) {
- throw raise.raiseIntegerInterpretationError(x);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, (Object) x);
}
@Specialization
@@ -626,7 +627,7 @@ static TruffleString doO(VirtualFrame frame, Node inliningTarget, Object x, Truf
return doPI((PInt) index, prefix, radix, longToString, fromJavaStringNode);
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.NotImplementedError, toTruffleStringUncached("bin/oct/hex with native integer subclasses"));
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError, toTruffleStringUncached("bin/oct/hex with native integer subclasses"));
}
}
}
@@ -718,11 +719,11 @@ public abstract static class ChrNode extends PythonUnaryClinicBuiltinNode {
static TruffleString charFromInt(int arg,
@Bind("this") Node inliningTarget,
@Cached TruffleString.FromCodePointNode fromCodePointNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (arg >= 0 && arg <= Character.MAX_CODE_POINT) {
return fromCodePointNode.execute(arg, TS_ENCODING, true);
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ARG_NOT_IN_RANGE, "chr()", "0x110000");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ARG_NOT_IN_RANGE, "chr()", "0x110000");
}
}
@@ -793,10 +794,10 @@ public abstract static class EvalNode extends PythonBuiltinNode {
@Child private GenericInvokeNode invokeNode = GenericInvokeNode.create();
@Child private GetOrCreateDictNode getOrCreateDictNode;
- final void assertNoFreeVars(Node inliningTarget, PCode code, PRaiseNode.Lazy raiseNode) {
+ final void assertNoFreeVars(Node inliningTarget, PCode code, PRaiseNode raiseNode) {
Object[] freeVars = code.getFreeVars();
if (freeVars.length > 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CODE_OBJ_NO_FREE_VARIABLES, getMode());
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CODE_OBJ_NO_FREE_VARIABLES, getMode());
}
}
@@ -812,7 +813,7 @@ static boolean isAnyNone(Object object) {
return object instanceof PNone;
}
- final PCode createAndCheckCode(VirtualFrame frame, Node inliningTarget, Object source, PRaiseNode.Lazy raiseNode) {
+ final PCode createAndCheckCode(VirtualFrame frame, Node inliningTarget, Object source, PRaiseNode raiseNode) {
PCode code = getCompileNode().compile(frame, source, T_STRING_SOURCE, getMode(), -1, -1);
assertNoFreeVars(inliningTarget, code, raiseNode);
return code;
@@ -854,7 +855,7 @@ Object execInheritGlobalsInheritLocals(VirtualFrame frame, Object source, @Suppr
@Exclusive @Cached ReadCallerFrameNode readCallerFrameNode,
@Exclusive @Cached CodeNodes.GetCodeCallTargetNode getCt,
@Cached GetFrameLocalsNode getFrameLocalsNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PCode code = createAndCheckCode(frame, inliningTarget, source, raiseNode);
PFrame callerFrame = readCallerFrameNode.executeWith(frame, 0);
Object[] args = PArguments.create();
@@ -869,14 +870,14 @@ Object execCustomGlobalsGlobalLocals(VirtualFrame frame, Object source, PDict gl
@Bind("this") Node inliningTarget,
@Shared @Cached HashingCollectionNodes.SetItemNode setBuiltins,
@Shared("getCt") @Cached CodeNodes.GetCodeCallTargetNode getCt,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PCode code = createAndCheckCode(frame, inliningTarget, source, raiseNode);
Object[] args = PArguments.create();
setCustomGlobals(frame, inliningTarget, globals, setBuiltins, args);
setCustomLocals(args, globals);
RootCallTarget rootCallTarget = getCt.execute(inliningTarget, code);
if (rootCallTarget == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_CREATE_CALL_TARGET, code);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_CREATE_CALL_TARGET, code);
}
return invokeNode.execute(frame, rootCallTarget, args);
@@ -889,7 +890,7 @@ Object execInheritGlobalsCustomLocals(VirtualFrame frame, Object source, @Suppre
@SuppressWarnings("unused") @Shared @Cached PyMappingCheckNode mappingCheckNode,
@Exclusive @Cached ReadCallerFrameNode readCallerFrameNode,
@Shared("getCt") @Cached CodeNodes.GetCodeCallTargetNode getCt,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PCode code = createAndCheckCode(frame, inliningTarget, source, raiseNode);
PFrame callerFrame = readCallerFrameNode.executeWith(frame, 0);
Object[] args = PArguments.create();
@@ -906,7 +907,7 @@ Object execCustomGlobalsCustomLocals(VirtualFrame frame, Object source, PDict gl
@SuppressWarnings("unused") @Shared @Cached PyMappingCheckNode mappingCheckNode,
@Shared @Cached HashingCollectionNodes.SetItemNode setBuiltins,
@Shared("getCt") @Cached CodeNodes.GetCodeCallTargetNode getCt,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PCode code = createAndCheckCode(frame, inliningTarget, source, raiseNode);
Object[] args = PArguments.create();
setCustomGlobals(frame, inliningTarget, globals, setBuiltins, args);
@@ -918,17 +919,16 @@ Object execCustomGlobalsCustomLocals(VirtualFrame frame, Object source, PDict gl
@Specialization(guards = {"!isAnyNone(globals)", "!isDict(globals)"})
@SuppressWarnings({"unused", "truffle-static-method"})
PNone badGlobals(Object source, Object globals, Object locals,
- @Shared("raise") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.GLOBALS_MUST_BE_DICT, getMode(), globals);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.GLOBALS_MUST_BE_DICT, getMode(), globals);
}
@Specialization(guards = {"isAnyNone(globals) || isDict(globals)", "!isAnyNone(locals)", "!isMapping(inliningTarget, mappingCheckNode, locals)"})
@SuppressWarnings({"unused", "truffle-static-method"})
PNone badLocals(Object source, PDict globals, Object locals,
@Bind("this") Node inliningTarget,
- @Shared @Cached PyMappingCheckNode mappingCheckNode,
- @Shared("raise") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.LOCALS_MUST_BE_MAPPING, getMode(), locals);
+ @Shared @Cached PyMappingCheckNode mappingCheckNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.LOCALS_MUST_BE_MAPPING, getMode(), locals);
}
private CompileNode getCompileNode() {
@@ -1056,7 +1056,7 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
InputType type = getParserInputType(mode, flags);
if (type == InputType.FUNCTION_TYPE) {
if ((flags & PyCF_ONLY_AST) == 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.COMPILE_MODE_FUNC_TYPE_REQUIED_FLAG_ONLY_AST);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.COMPILE_MODE_FUNC_TYPE_REQUIED_FLAG_ONLY_AST);
}
}
if (lstrip && !code.isEmpty()) {
@@ -1122,7 +1122,7 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Shared @Cached ReadCallerFrameNode readCallerFrame,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (wSource instanceof PCode) {
return wSource;
}
@@ -1150,7 +1150,7 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
}
if (AstModuleBuiltins.isAst(context, wSource)) {
- ModTy mod = AstModuleBuiltins.obj2sst(context, wSource, getParserInputType(mode, flags));
+ ModTy mod = AstModuleBuiltins.obj2sst(inliningTarget, context, wSource, getParserInputType(mode, flags));
Source source = PythonUtils.createFakeSource(filename);
RootCallTarget rootCallTarget = context.getLanguage(inliningTarget).compileForBytecodeInterpreter(context, mod, source, false, optimize, null, null, flags);
return wrapRootCallTarget(rootCallTarget);
@@ -1179,14 +1179,14 @@ private void checkSource(TruffleString source) throws PException {
@TruffleBoundary
private void checkOptimize(int optimize, Object kwOptimize) throws PException {
if (optimize < -1 || optimize > 2) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.INVALID_OPTIMIZE_VALUE, kwOptimize);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.INVALID_OPTIMIZE_VALUE, kwOptimize);
}
}
@TruffleBoundary
private void checkFlags(int flags) {
if ((flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK)) != 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY);
+ throw PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY);
}
}
@@ -1202,9 +1202,9 @@ private InputType getParserInputType(TruffleString mode, int flags) {
return InputType.FUNCTION_TYPE;
} else {
if ((flags & PyCF_ONLY_AST) != 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.COMPILE_MODE_MUST_BE_AST_ONLY);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.COMPILE_MODE_MUST_BE_AST_ONLY);
} else {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.COMPILE_MODE_MUST_BE);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.COMPILE_MODE_MUST_BE);
}
}
}
@@ -1212,7 +1212,7 @@ private InputType getParserInputType(TruffleString mode, int flags) {
// modeled after _Py_SourceAsString
TruffleString sourceAsString(VirtualFrame frame, Node inliningTarget, Object source, TruffleString filename, InteropLibrary interopLib, PythonBufferAcquireLibrary acquireLib,
PythonBufferAccessLibrary bufferLib, CodecsModuleBuiltins.HandleDecodingErrorNode handleDecodingErrorNode, PyObjectStrAsTruffleStringNode asStrNode,
- TruffleString.SwitchEncodingNode switchEncodingNode, PRaiseNode.Lazy raiseNode, IndirectCallData indirectCallData) {
+ TruffleString.SwitchEncodingNode switchEncodingNode, PRaiseNode raiseNode, IndirectCallData indirectCallData) {
if (interopLib.isString(source)) {
try {
return switchEncodingNode.execute(interopLib.asTruffleString(source), TS_ENCODING);
@@ -1226,7 +1226,7 @@ TruffleString sourceAsString(VirtualFrame frame, Node inliningTarget, Object sou
try {
buffer = acquireLib.acquireReadonly(source, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S, "compile()", 1, "string, bytes or AST object");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_D_MUST_BE_S, "compile()", 1, "string, bytes or AST object");
}
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(source);
@@ -1547,8 +1547,8 @@ static Object iter(Object callable, Object sentinel,
@Fallback
@SuppressWarnings("unused")
static Object iterNotCallable(Object callable, Object sentinel,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ITER_V_MUST_BE_CALLABLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ITER_V_MUST_BE_CALLABLE);
}
}
@@ -1582,7 +1582,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
@Exclusive @Cached IsBuiltinObjectProfile errorProfile1,
@Exclusive @Cached IsBuiltinObjectProfile errorProfile2,
@Exclusive @Cached InlinedConditionProfile hasDefaultProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
boolean kwArgsAreNone = keywordArgIsNone.profile(inliningTarget, PGuards.isPNone(keywordArgIn));
Object keywordArg = kwArgsAreNone ? null : keywordArgIn;
@@ -1593,7 +1593,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
} catch (PException e) {
e.expectStopIteration(inliningTarget, errorProfile1);
if (hasDefaultProfile.profile(inliningTarget, isNoValue(defaultVal))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.ARG_IS_EMPTY_SEQ, name);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.ARG_IS_EMPTY_SEQ, name);
} else {
return defaultVal;
}
@@ -1642,13 +1642,13 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
@Exclusive @Cached InlinedConditionProfile moreThanTwo,
@Exclusive @Cached InlinedLoopConditionProfile loopProfile,
@Exclusive @Cached InlinedConditionProfile hasDefaultProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
boolean kwArgsAreNone = keywordArgIsNone.profile(inliningTarget, PGuards.isPNone(keywordArgIn));
Object keywordArg = kwArgsAreNone ? null : keywordArgIn;
if (!hasDefaultProfile.profile(inliningTarget, isNoValue(defaultVal))) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_SPECIFY_DEFAULT_FOR_S, name);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_SPECIFY_DEFAULT_FOR_S, name);
}
Object currentValue = arg1;
Object currentKey = applyKeyFunction(frame, inliningTarget, keywordArg, keyCall, currentValue);
@@ -1756,11 +1756,12 @@ public Object next(VirtualFrame frame, Object iterator, Object defaultObject,
@NeverDefault
protected LookupAndCallUnaryNode createNextCall() {
return LookupAndCallUnaryNode.create(T___NEXT__, () -> new LookupAndCallUnaryNode.NoAttributeHandler() {
- @Child PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object iterator) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_ISNT_ITERATOR, iterator);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.OBJ_ISNT_ITERATOR, iterator);
}
});
}
@@ -1778,7 +1779,7 @@ static int ord(Object chrObj,
@Cached CastToTruffleStringNode castToStringNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString chr;
try {
chr = castToStringNode.execute(inliningTarget, chrObj);
@@ -1787,7 +1788,7 @@ static int ord(Object chrObj,
}
int len = codePointLengthNode.execute(chr, TS_ENCODING);
if (len != 1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_CHARACTER_BUT_STRING_FOUND, "ord()", len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_CHARACTER_BUT_STRING_FOUND, "ord()", len);
}
return codePointAtIndexNode.execute(chr, 0, TS_ENCODING);
}
@@ -1797,18 +1798,18 @@ static long ord(PBytesLike chr,
@Bind("this") Node inliningTarget,
@Cached CastToJavaLongExactNode castNode,
@Cached SequenceStorageNodes.GetItemNode getItemNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int len = chr.getSequenceStorage().length();
if (len != 1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_CHARACTER_BUT_STRING_FOUND, "ord()", len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_CHARACTER_BUT_STRING_FOUND, "ord()", len);
}
return castNode.execute(inliningTarget, getItemNode.execute(chr.getSequenceStorage(), 0));
}
@Specialization(guards = {"!isString(obj)", "!isBytes(obj)"})
static Object ord(@SuppressWarnings("unused") Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.S_EXPECTED_STRING_OF_LEN_BUT_P, "ord()", "1", "obj");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_STRING_OF_LEN_BUT_P, "ord()", "1", "obj");
}
}
@@ -1879,19 +1880,19 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
@Exclusive @Cached CallNode callWrite,
@Exclusive @Cached PyObjectCallMethodObjArgs callFlush,
@Exclusive @Cached PyObjectStrAsObjectNode strNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString sep;
try {
sep = sepIn instanceof PNone ? T_SPACE : castSep.execute(inliningTarget, sepIn);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.SEP_MUST_BE_NONE_OR_STRING, sepIn);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.SEP_MUST_BE_NONE_OR_STRING, sepIn);
}
TruffleString end;
try {
end = endIn instanceof PNone ? T_NEWLINE : castEnd.execute(inliningTarget, endIn);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "end", sepIn);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "end", sepIn);
}
Object file;
@@ -1935,7 +1936,7 @@ private Object getStdout() {
Object stdout = readStdout.execute(sys, T_STDOUT);
if (stdout == NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.LOST_SYSSTDOUT);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.LOST_SYSSTDOUT);
}
return stdout;
}
@@ -1965,14 +1966,14 @@ public static Object format(VirtualFrame frame, Object obj, Object formatSpec,
@Bind("this") Node inliningTarget,
@Cached("create(Format)") LookupAndCallBinaryNode callFormat,
@Cached InlinedConditionProfile formatIsNoValueProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object format = formatIsNoValueProfile.profile(inliningTarget, isNoValue(formatSpec)) ? T_EMPTY_STRING : formatSpec;
Object res = callFormat.executeObject(frame, obj, format);
if (res == NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_FORMAT, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_FORMAT, obj);
}
if (!PGuards.isString(res)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_MUST_RETURN_S_NOT_P, T___FORMAT__, "str", res);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_MUST_RETURN_S_NOT_P, T___FORMAT__, "str", res);
}
return res;
}
@@ -2004,10 +2005,10 @@ public abstract static class RoundNode extends PythonBuiltinNode {
static Object round(VirtualFrame frame, Object x, @SuppressWarnings("unused") PNone n,
@Bind("this") Node inliningTarget,
@Cached("create(Round)") LookupAndCallUnaryNode callRound,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object result = callRound.executeObject(frame, x);
if (result == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, T___ROUND__);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, T___ROUND__);
}
return result;
}
@@ -2016,10 +2017,10 @@ static Object round(VirtualFrame frame, Object x, @SuppressWarnings("unused") PN
static Object round(VirtualFrame frame, Object x, Object n,
@Bind("this") Node inliningTarget,
@Cached("create(Round)") LookupAndCallBinaryNode callRound,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object result = callRound.executeObject(frame, x, n);
if (result == NOT_IMPLEMENTED) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, T___ROUND__);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, x, T___ROUND__);
}
return result;
}
@@ -2083,7 +2084,7 @@ public abstract static class BreakPointNode extends PythonBuiltinNode {
Object doIt(VirtualFrame frame, Object[] args, PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
@Cached HashingStorageGetItem getItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (getDebuggerSessionCount() > 0) {
// we already have a Truffle debugger attached, it'll stop here
return PNone.NONE;
@@ -2097,7 +2098,7 @@ Object doIt(VirtualFrame frame, Object[] args, PKeyword[] kwargs,
Object sysModule = getItem.execute(inliningTarget, sysModules.getDictStorage(), T_SYS);
Object breakpointhook = getBreakpointhookNode.execute(sysModule, T_BREAKPOINTHOOK);
if (breakpointhook == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.LOST_SYSBREAKPOINTHOOK);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.LOST_SYSBREAKPOINTHOOK);
}
return callNode.execute(frame, breakpointhook, args, kwargs);
} else {
@@ -2177,7 +2178,7 @@ private int sumIntInternal(VirtualFrame frame, Node inliningTarget, Object arg1,
@SuppressWarnings("unused") @Shared @Cached InlinedConditionProfile hasStart,
@Shared("getIter") @Cached PyObjectGetIter getIter,
// dummy raiseNode, so it can be @Shared, to optimize generated code:
- @SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) throws UnexpectedResultException {
+ @SuppressWarnings("unused") @Shared @Cached PRaiseNode raiseNode) throws UnexpectedResultException {
return sumDoubleInternal(frame, inliningTarget, arg1, start, addNode, getIter, errorProfile);
}
@@ -2211,13 +2212,13 @@ Object sum(VirtualFrame frame, Object arg1, Object start,
@Shared @Cached IsBuiltinObjectProfile errorProfile,
@Shared("getIter") @Cached PyObjectGetIter getIter,
@Shared @Cached InlinedConditionProfile hasStart,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (PGuards.isString(start)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SUM_STRINGS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SUM_STRINGS);
} else if (start instanceof PBytes) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SUM_BYTES);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SUM_BYTES);
} else if (start instanceof PByteArray) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SUM_BYTEARRAY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SUM_BYTEARRAY);
}
Object iterator = getIter.execute(frame, inliningTarget, arg1);
return iterateGeneric(frame, inliningTarget, iterator, hasStart.profile(inliningTarget, start != NO_VALUE) ? start : 0, addNode, errorProfile);
@@ -2284,10 +2285,10 @@ static Object vars(VirtualFrame frame, @SuppressWarnings("unused") PNone none,
static Object vars(VirtualFrame frame, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyObjectLookupAttr lookupAttr,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object dict = lookupAttr.execute(frame, inliningTarget, obj, T___DICT__);
if (dict == NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.VARS_ARGUMENT_MUST_HAVE_DICT);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.VARS_ARGUMENT_MUST_HAVE_DICT);
}
return dict;
}
@@ -2328,7 +2329,7 @@ static PTuple update(PTuple bases, Object[] arguments, int nargs,
@Bind PythonLanguage language,
@Cached PyObjectLookupAttr getMroEntries,
@Cached CallUnaryMethodNode callMroEntries,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
CompilerAsserts.neverPartOfCompilation();
ArrayList newBases = null;
for (int i = 0; i < nargs; i++) {
@@ -2351,7 +2352,7 @@ static PTuple update(PTuple bases, Object[] arguments, int nargs,
}
Object newBase = callMroEntries.executeObject(null, meth, bases);
if (!PGuards.isPTuple(newBase)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.MRO_ENTRIES_MUST_RETURN_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.MRO_ENTRIES_MUST_RETURN_TUPLE);
}
PTuple newBaseTuple = (PTuple) newBase;
if (newBases == null) {
@@ -2386,7 +2387,7 @@ static Object calculate(Object metatype, PTuple bases,
@Cached GetClassNode getClass,
@Cached IsSubtypeNode isSubType,
@Cached IsSubtypeNode isSubTypeReverse,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
CompilerAsserts.neverPartOfCompilation();
/*
* Determine the proper metatype to deal with this, and check for metatype conflicts
@@ -2405,7 +2406,7 @@ static Object calculate(Object metatype, PTuple bases,
} else if (isSubTypeReverse.execute(tmpType, winner)) {
winner = tmpType;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.METACLASS_CONFLICT);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.METACLASS_CONFLICT);
}
}
return winner;
@@ -2451,20 +2452,21 @@ protected Object doItNonFunction(VirtualFrame frame, Object function, Object[] a
@Cached UpdateBasesNode update,
@Cached PyObjectSetItem setOrigBases,
@Cached GetClassNode getClass,
- @Cached IsBuiltinObjectProfile noAttributeProfile) {
+ @Cached IsBuiltinObjectProfile noAttributeProfile,
+ @Cached PRaiseNode raiseNode) {
if (arguments.length < 1) {
- throw raise(PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NOT_ENOUGH_ARGS);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NOT_ENOUGH_ARGS);
}
if (!PGuards.isFunction(function)) {
- throw raise(PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_FUNC_MUST_BE_FUNC);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_FUNC_MUST_BE_FUNC);
}
TruffleString name;
try {
name = castToTruffleStringNode.execute(inliningTarget, arguments[0]);
} catch (CannotCastException e) {
- throw raise(PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NAME_NOT_STRING);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NAME_NOT_STRING);
}
PythonContext ctx = PythonContext.get(inliningTarget);
@@ -2561,9 +2563,9 @@ class InitializeBuildClass {
@InliningCutoff
private PException raiseNoMapping(boolean isClass, Object meta, Object ns) {
if (isClass) {
- throw raise(PythonErrorType.TypeError, ErrorMessages.N_PREPARE_MUST_RETURN_MAPPING, meta, ns);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.TypeError, ErrorMessages.N_PREPARE_MUST_RETURN_MAPPING, meta, ns);
} else {
- throw raise(PythonErrorType.TypeError, ErrorMessages.MTCLS_PREPARE_MUST_RETURN_MAPPING, ns);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.TypeError, ErrorMessages.MTCLS_PREPARE_MUST_RETURN_MAPPING, ns);
}
}
}
@@ -2576,14 +2578,14 @@ public Object doGeneric(VirtualFrame frame, Object asyncIter,
@Bind("this") Node inliningTarget,
@Cached(parameters = "ANext") LookupSpecialMethodSlotNode getANext,
@Cached GetClassNode getAsyncIterType,
- @Cached PRaiseNode.Lazy raiseNoANext,
+ @Cached PRaiseNode raiseNoANext,
@Cached CallUnaryMethodNode callANext,
@Cached TypeNodes.GetNameNode getName) {
// TODO: two argument anext
Object type = getAsyncIterType.execute(inliningTarget, asyncIter);
Object getter = getANext.execute(frame, type, asyncIter);
if (getter == NO_VALUE) {
- throw raiseNoANext.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJECT_NOT_ASYNCGEN, getName.execute(inliningTarget, type));
+ throw raiseNoANext.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJECT_NOT_ASYNCGEN, getName.execute(inliningTarget, type));
}
return callANext.executeObject(frame, getter, asyncIter);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
index 1fe9d7865d..1d20d28c2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
@@ -173,7 +173,7 @@ abstract static class CmathComplexUnaryHelperNode extends Node {
@FunctionalInterface
interface Op {
- ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode);
+ ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode);
}
abstract PComplex execute(VirtualFrame frame, Node inliningTarget, Object value, Op op);
@@ -181,21 +181,21 @@ interface Op {
@Specialization
static PComplex doL(Node inliningTarget, long value, Op op,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(language);
}
@Specialization
static PComplex doD(Node inliningTarget, double value, Op op,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op.compute(inliningTarget, value, 0, raiseNode).toPComplex(language);
}
@Specialization
static PComplex doC(Node inliningTarget, PComplex value, Op op,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op.compute(inliningTarget, value.getReal(), value.getImag(), raiseNode).toPComplex(language);
}
@@ -203,7 +203,7 @@ static PComplex doC(Node inliningTarget, PComplex value, Op op,
static PComplex doGeneral(VirtualFrame frame, Node inliningTarget, Object value, Op op,
@Cached CoerceToComplexNode coerceToComplex,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return doC(inliningTarget, coerceToComplex.execute(frame, inliningTarget, value), op, language, raiseNode);
}
}
@@ -399,7 +399,7 @@ private static PComplex rect(Node raisingNode, double r, double phi) {
if (!Double.isFinite(r) || !Double.isFinite(phi)) {
// need to raise an exception if r is a nonzero number and phi is infinite
if (r != 0.0 && !Double.isNaN(r) && Double.isInfinite(phi)) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
// if r is +/-infinity and phi is finite but nonzero then
@@ -503,7 +503,7 @@ private double computeRealPart(double real, double imag) {
final double scaleUp = 0x1.0p53;
return Math.log(Math.hypot(ax * scaleUp, ay * scaleUp)) - 53 * LN_2;
}
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
double h = Math.hypot(ax, ay);
if (0.71 <= h && h <= 1.73) {
@@ -562,7 +562,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SqrtNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue result = specialValue(SPECIAL_VALUES, real, imag);
if (result != null) {
return result;
@@ -616,7 +616,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AcosNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue result = specialValue(SPECIAL_VALUES, real, imag);
if (result != null) {
return result;
@@ -666,7 +666,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AcoshNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue result = specialValue(SPECIAL_VALUES, real, imag);
if (result != null) {
return result;
@@ -697,7 +697,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AsinNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue s = AsinhNode.compute(inliningTarget, -imag, real, raiseNode);
return new ComplexValue(s.imag, -s.real);
}
@@ -727,7 +727,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AsinhNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue result = specialValue(SPECIAL_VALUES, real, imag);
if (result != null) {
return result;
@@ -763,7 +763,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AtanNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue s = AtanhNode.compute(inliningTarget, -imag, real, raiseNode);
return new ComplexValue(s.imag, -s.real);
}
@@ -796,7 +796,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AtanhNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue result = specialValue(SPECIAL_VALUES, real, imag);
if (result != null) {
return result;
@@ -807,7 +807,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
return computeWithRealPositive(inliningTarget, real, imag, 1.0, raiseNode);
}
- private static ComplexValue computeWithRealPositive(Node inliningTarget, double real, double imag, double resultScale, PRaiseNode.Lazy raiseNode) {
+ private static ComplexValue computeWithRealPositive(Node inliningTarget, double real, double imag, double resultScale, PRaiseNode raiseNode) {
double rreal;
double rimag;
double ay = Math.abs(imag);
@@ -817,7 +817,7 @@ private static ComplexValue computeWithRealPositive(Node inliningTarget, double
rimag = -Math.copySign(Math.PI / 2.0, -imag);
} else if (real == 1.0 && ay < CM_SQRT_DBL_MIN) {
if (ay == 0.0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
rreal = -Math.log(Math.sqrt(ay) / Math.sqrt(Math.hypot(ay, 2.0)));
rimag = Math.copySign(Math.atan2(2.0, -ay) / 2, imag);
@@ -853,7 +853,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, ExpNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
if (!Double.isFinite(real) || !Double.isFinite(imag)) {
ComplexValue r;
if (Double.isInfinite(real) && Double.isFinite(imag) && imag != 0.0) {
@@ -866,7 +866,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
r = specialValue(SPECIAL_VALUES, real, imag);
}
if (Double.isInfinite(imag) && (Double.isFinite(real) || (Double.isInfinite(real) && real > 0))) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
return r;
}
@@ -882,7 +882,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
rimag = l * Math.sin(imag);
}
if (Double.isInfinite(rreal) || Double.isInfinite(rimag)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
}
return new ComplexValue(rreal, rimag);
}
@@ -899,7 +899,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, CosNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
return CoshNode.compute(inliningTarget, -imag, real, raiseNode);
}
}
@@ -928,10 +928,10 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, CoshNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
if (!Double.isFinite(real) || !Double.isFinite(imag)) {
if (Double.isInfinite(imag) && !Double.isNaN(real)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
if (Double.isInfinite(real) && Double.isFinite(imag) && imag != 0.0) {
double r = Math.copySign(INF, Math.sin(imag));
@@ -951,7 +951,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
rimag = Math.sin(imag) * Math.sinh(real);
}
if (Double.isInfinite(rreal) || Double.isInfinite(rimag)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
}
return new ComplexValue(rreal, rimag);
}
@@ -968,7 +968,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SinNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue s = SinhNode.compute(inliningTarget, -imag, real, raiseNode);
return new ComplexValue(s.imag, -s.real);
}
@@ -998,10 +998,10 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SinhNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
if (!Double.isFinite(real) || !Double.isFinite(imag)) {
if (Double.isInfinite(imag) && !Double.isNaN(real)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
if (Double.isInfinite(real) && Double.isFinite(imag) && imag != 0.0) {
double r = Math.copySign(INF, Math.cos(imag));
@@ -1021,7 +1021,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
rimag = Math.sin(imag) * Math.cosh(real);
}
if (Double.isInfinite(rreal) || Double.isInfinite(rimag)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
}
return new ComplexValue(rreal, rimag);
}
@@ -1038,7 +1038,7 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, TanNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
ComplexValue s = TanhNode.compute(inliningTarget, -imag, real, raiseNode);
return new ComplexValue(s.imag, -s.real);
}
@@ -1068,10 +1068,10 @@ static PComplex doIt(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, TanhNode::compute);
}
- static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode.Lazy raiseNode) {
+ static ComplexValue compute(Node inliningTarget, double real, double imag, PRaiseNode raiseNode) {
if (!Double.isFinite(real) || !Double.isFinite(imag)) {
if (Double.isInfinite(imag) && Double.isFinite(real)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
if (Double.isInfinite(real) && Double.isFinite(imag) && imag != 0.0) {
return new ComplexValue(real > 0 ? 1.0 : -1.0, Math.copySign(0.0, 2.0 * Math.sin(imag) * Math.cos(imag)));
@@ -1105,7 +1105,7 @@ abstract static class IsCloseNode extends PythonBuiltinNode {
static boolean doCCDD(PComplex a, PComplex b, double relTolObj, double absTolObj,
@Bind("this") Node inliningTarget,
@Shared @Cached AbsNode absNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return isClose(inliningTarget, a, b, relTolObj, absTolObj, absNode, raiseNode);
}
@@ -1114,7 +1114,7 @@ static boolean doCCDD(PComplex a, PComplex b, double relTolObj, double absTolObj
static boolean doCCNN(PComplex a, PComplex b, PNone relTolObj, PNone absTolObj,
@Bind("this") Node inliningTarget,
@Shared @Cached AbsNode absNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return isClose(inliningTarget, a, b, DEFAULT_REL_TOL, DEFAULT_ABS_TOL, absNode, raiseNode);
}
@@ -1126,7 +1126,7 @@ static boolean doGeneral(VirtualFrame frame, Object aObj, Object bObj, Object re
@Cached PyFloatAsDoubleNode relAsDoubleNode,
@Cached PyFloatAsDoubleNode absAsDoubleNode,
@Shared @Cached AbsNode absNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PComplex a = coerceAToComplex.execute(frame, inliningTarget, aObj);
PComplex b = coerceBToComplex.execute(frame, inliningTarget, bObj);
double relTol = PGuards.isNoValue(relTolObj) ? DEFAULT_REL_TOL : relAsDoubleNode.execute(frame, inliningTarget, relTolObj);
@@ -1134,9 +1134,9 @@ static boolean doGeneral(VirtualFrame frame, Object aObj, Object bObj, Object re
return isClose(inliningTarget, a, b, relTol, absTol, absNode, raiseNode);
}
- private static boolean isClose(Node inliningTarget, PComplex a, PComplex b, double relTol, double absTol, AbsNode absNode, PRaiseNode.Lazy raiseNode) {
+ private static boolean isClose(Node inliningTarget, PComplex a, PComplex b, double relTol, double absTol, AbsNode absNode, PRaiseNode raiseNode) {
if (relTol < 0.0 || absTol < 0.0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TOLERANCE_MUST_NON_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOLERANCE_MUST_NON_NEGATIVE);
}
if (a.getReal() == b.getReal() && a.getImag() == b.getImag()) {
return true;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
index 21d8ae4162..df01b7ccc4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java
@@ -222,9 +222,9 @@ static void handle(Node inliningTarget, TruffleEncoder encoder, TruffleString er
@Cached InlinedConditionProfile surrogatepassProfile,
@Cached InlinedConditionProfile surrogateescapeProfile,
@Cached InlinedConditionProfile xmlcharrefreplaceProfile,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached(inline = false) TruffleString.EqualNode equalNode,
- // TODO: (blocked by GR-46101) make this CallNode.Lazy
+ // TODO: (blocked by GR-46101) make this CallNode.PRaiseNode
@Cached(inline = false) CallNode lazyCallNode) {
boolean fixed;
try {
@@ -240,24 +240,24 @@ static void handle(Node inliningTarget, TruffleEncoder encoder, TruffleString er
} else if (xmlcharrefreplaceProfile.profile(inliningTarget, equalNode.execute(T_XMLCHARREFREPLACE, errorAction, TS_ENCODING))) {
fixed = xmlcharrefreplace(encoder);
} else {
- throw raiseNode.get(inliningTarget).raise(LookupError, ErrorMessages.UNKNOWN_ERROR_HANDLER, errorAction);
+ throw raiseNode.raise(inliningTarget, LookupError, ErrorMessages.UNKNOWN_ERROR_HANDLER, errorAction);
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
if (!fixed) {
int start = encoder.getInputPosition();
int end = start + encoder.getErrorLength();
Object exception = lazyCallNode.executeWithoutFrame(UnicodeEncodeError, encoder.getEncodingName(), inputObject, start, end, encoder.getErrorReason());
if (exception instanceof PBaseException) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject((PBaseException) exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, (PBaseException) exception);
} else {
// Shouldn't happen unless the user manually replaces the method, which is
// really
// unexpected and shouldn't be permitted at all, but currently it is
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeEncodeError, exception);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeEncodeError, exception);
}
}
}
@@ -368,7 +368,7 @@ public Object raise(Node inliningTarget, TruffleDecoder decoder, Object inputObj
@Specialization
static Object doRaise(Node inliningTarget, TruffleDecoder decoder, Object inputObject, boolean justMakeExcept,
@Cached(inline = false) CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int start = decoder.getInputPosition();
int end = start + decoder.getErrorLength();
Object exception = callNode.executeWithoutFrame(UnicodeDecodeError, decoder.getEncodingName(), inputObject, start, end, decoder.getErrorReason());
@@ -376,12 +376,12 @@ static Object doRaise(Node inliningTarget, TruffleDecoder decoder, Object inputO
return exception;
}
if (exception instanceof PBaseException) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
} else {
// Shouldn't happen unless the user manually replaces the method, which is really
// unexpected and shouldn't be permitted at all, but currently it is
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeDecodeError, exception);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeDecodeError, exception);
}
}
}
@@ -441,7 +441,7 @@ void doBackslashreplace(TruffleDecoder decoder, @SuppressWarnings("unused") Truf
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- PRaiseNode.raiseUncached(this, MemoryError);
+ PRaiseNode.raiseStatic(this, MemoryError);
}
}
@@ -457,7 +457,7 @@ static void doSurrogatepass(TruffleDecoder decoder, @SuppressWarnings("unused")
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -472,7 +472,7 @@ static void doSurrogateescape(TruffleDecoder decoder, @SuppressWarnings("unused"
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -487,23 +487,23 @@ static void doCustom(VirtualFrame frame, TruffleDecoder decoder, TruffleString e
@Cached PyLongAsIntNode asIntNode,
@Exclusive @Cached RaiseDecodingErrorNode raiseDecodingErrorNode,
@Cached PyCodecLookupErrorNode lookupErrorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
Object errorHandler = lookupErrorNode.execute(inliningTarget, errorAction);
if (errorHandler == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, UNKNOWN_ERROR_HANDLER, errorAction);
+ throw raiseNode.raise(inliningTarget, LookupError, UNKNOWN_ERROR_HANDLER, errorAction);
}
Object exceptionObject = raiseDecodingErrorNode.makeDecodeException(inliningTarget, decoder, inputObject);
Object restuple = callNode.execute(frame, errorHandler, exceptionObject);
if (!PGuards.isPTuple(restuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
}
SequenceStorage storage = ((PTuple) restuple).getSequenceStorage();
Object[] t = getArray.execute(inliningTarget, storage);
if (storage.length() != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
}
int newpos = asIntNode.execute(null, inliningTarget, t[1]);
/*- Copy back the bytes variables, which might have been modified by the callback */
@@ -517,16 +517,16 @@ static void doCustom(VirtualFrame frame, TruffleDecoder decoder, TruffleString e
newpos = insize + newpos;
}
if (newpos < 0 || newpos > insize) {
- throw raiseNode.get(inliningTarget).raise(IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
+ throw raiseNode.raise(inliningTarget, IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
}
if (!custom(decoder, input, insize, newpos)) {
- throw raiseNode.get(inliningTarget).raise(SystemError);
+ throw raiseNode.raise(inliningTarget, SystemError);
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -608,14 +608,14 @@ byte[] encode(Object self, TruffleString encoding, TruffleString errors,
@Cached CastToJavaStringNode castStr,
@Cached TruffleString.EqualNode equalNode,
@Cached HandleEncodingErrorNode errorHandler,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached NormalizeEncodingNameNode normalizeEncodingNameNode) {
String input = castStr.execute(self);
CodingErrorAction errorAction = convertCodingErrorAction(errors, equalNode);
TruffleString normalizedEncoding = normalizeEncodingNameNode.execute(inliningTarget, encoding);
Charset charset = CharsetMapping.getCharsetNormalized(normalizedEncoding);
if (charset == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, ErrorMessages.UNKNOWN_ENCODING, encoding);
+ throw raiseNode.raise(inliningTarget, LookupError, ErrorMessages.UNKNOWN_ENCODING, encoding);
}
TruffleEncoder encoder;
try {
@@ -625,7 +625,7 @@ byte[] encode(Object self, TruffleString encoding, TruffleString errors,
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, MemoryError);
+ throw PRaiseNode.raiseStatic(this, MemoryError);
}
return encoder.getBytes();
}
@@ -658,9 +658,8 @@ static Object encode(Object self, TruffleString encoding, TruffleString errors,
@Fallback
static Object encode(Object str, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
- @Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_CONVERT_TO_STR_IMPLICITLY, str);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_CONVERT_TO_STR_IMPLICITLY, str);
}
}
@@ -701,7 +700,7 @@ static Object decode(VirtualFrame frame, Object input, TruffleString encoding, T
TruffleString normalizedEncoding = normalizeEncodingNameNode.execute(inliningTarget, encoding);
Charset charset = CharsetMapping.getCharsetForDecodingNormalized(normalizedEncoding, bytes, len);
if (charset == null) {
- throw raiseNode.raise(LookupError, ErrorMessages.UNKNOWN_ENCODING, encoding);
+ throw raiseNode.raise(inliningTarget, LookupError, ErrorMessages.UNKNOWN_ENCODING, encoding);
}
TruffleDecoder decoder;
try {
@@ -711,7 +710,7 @@ static Object decode(VirtualFrame frame, Object input, TruffleString encoding, T
}
} catch (OutOfMemoryError e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
return PFactory.createTuple(language, new Object[]{decoder.getString(), decoder.getInputPosition()});
} finally {
@@ -768,7 +767,7 @@ private ByteArrayBuffer doDecode(byte[] bytes, int bytesLen, TruffleString error
i++;
if (i >= bytesLen) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.TRAILING_S_IN_STR, "\\");
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.TRAILING_S_IN_STR, "\\");
}
chr = (char) bytes[i];
@@ -843,14 +842,14 @@ private ByteArrayBuffer doDecode(byte[] bytes, int bytesLen, TruffleString error
}
// invalid hexadecimal digits
if (T_STRICT.equalsUncached(errors, TS_ENCODING)) {
- throw PRaiseNode.raiseUncached(this, ValueError, INVALID_ESCAPE_AT, "\\x", i - 2);
+ throw PRaiseNode.raiseStatic(this, ValueError, INVALID_ESCAPE_AT, "\\x", i - 2);
}
if (T_REPLACE.equalsUncached(errors, TS_ENCODING)) {
buffer.append('?');
} else if (T_IGNORE.equalsUncached(errors, TS_ENCODING)) {
// do nothing
} else {
- throw PRaiseNode.raiseUncached(this, ValueError, ENCODING_ERROR_WITH_CODE, errors);
+ throw PRaiseNode.raiseStatic(this, ValueError, ENCODING_ERROR_WITH_CODE, errors);
}
// skip \x
@@ -926,8 +925,8 @@ Object encode(PBytes data, @SuppressWarnings("unused") TruffleString errors,
@Fallback
static Object encode(Object data, @SuppressWarnings("unused") Object errors,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BYTESLIKE_OBJ_REQUIRED, data);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BYTESLIKE_OBJ_REQUIRED, data);
}
}
@@ -982,7 +981,7 @@ static PTuple lookup(VirtualFrame frame, Node inliningTarget, TruffleString enco
@Cached InlinedConditionProfile hasTruffleEncodingProfile,
@Cached InlinedConditionProfile isTupleProfile,
@Cached NormalizeEncodingNameNode normalizeEncodingNameNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString normalizedEncoding = normalizeEncodingNameNode.execute(inliningTarget, encoding);
PythonContext context = PythonContext.get(inliningTarget);
ensureRegistryInitialized(context);
@@ -999,7 +998,7 @@ static PTuple lookup(VirtualFrame frame, Node inliningTarget, TruffleString enco
Object obj = callNode.executeObject(func, normalizedEncoding);
if (obj != PNone.NONE) {
if (isTupleProfile.profile(inliningTarget, !isTupleInstanceCheck(frame, inliningTarget, obj, 4, typeCheck, sizeNode))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_SEARCH_MUST_RETURN_4);
+ throw raiseNode.raise(inliningTarget, TypeError, CODEC_SEARCH_MUST_RETURN_4);
}
result = (PTuple) obj;
break;
@@ -1010,7 +1009,7 @@ static PTuple lookup(VirtualFrame frame, Node inliningTarget, TruffleString enco
putSearchPath(context, normalizedEncoding, result);
return result;
}
- throw raiseNode.get(inliningTarget).raise(LookupError, UNKNOWN_ENCODING, encoding);
+ throw raiseNode.raise(inliningTarget, LookupError, UNKNOWN_ENCODING, encoding);
}
@TruffleBoundary
@@ -1045,14 +1044,14 @@ abstract static class RegisterNode extends PythonUnaryBuiltinNode {
static Object lookup(Object searchFunction,
@Bind("this") Node inliningTarget,
@Cached PyCallableCheckNode callableCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (callableCheckNode.execute(inliningTarget, searchFunction)) {
PythonContext context = PythonContext.get(inliningTarget);
ensureRegistryInitialized(context);
add(context, searchFunction);
return PNone.NONE;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ARG_MUST_BE_CALLABLE);
+ throw raiseNode.raise(inliningTarget, TypeError, ARG_MUST_BE_CALLABLE);
}
}
@@ -1157,11 +1156,11 @@ static Object encode(VirtualFrame frame, Object obj, TruffleString encoding, Tru
@Cached PyObjectSizeNode sizeNode,
@Cached PyObjectTypeCheck typeCheck,
@Cached InlinedConditionProfile isTupleProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object encoder = CodecsModuleBuiltins.encoder(frame, encoding, lookupNode, getItemNode);
Object result = callEncoderNode.executeObject(encoder, obj, errors);
if (isTupleProfile.profile(inliningTarget, !isTupleInstanceCheck(frame, inliningTarget, result, 2, typeCheck, sizeNode))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_MUST_RETURN_TUPLE, "encoder");
+ throw raiseNode.raise(inliningTarget, TypeError, S_MUST_RETURN_TUPLE, "encoder");
}
return getResultItemNode.execute(((PTuple) result).getSequenceStorage(), 0);
}
@@ -1190,11 +1189,11 @@ static Object decode(VirtualFrame frame, Object obj, TruffleString encoding, Tru
@Cached PyObjectSizeNode sizeNode,
@Cached PyObjectTypeCheck typeCheck,
@Cached InlinedConditionProfile isTupleProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object decoder = CodecsModuleBuiltins.decoder(frame, encoding, lookupNode, getItemNode);
Object result = callEncoderNode.executeObject(decoder, obj, errors);
if (isTupleProfile.profile(inliningTarget, !isTupleInstanceCheck(frame, inliningTarget, result, 2, typeCheck, sizeNode))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_MUST_RETURN_TUPLE, "decoder");
+ throw raiseNode.raise(inliningTarget, TypeError, S_MUST_RETURN_TUPLE, "decoder");
}
return getResultItemNode.execute(((PTuple) result).getSequenceStorage(), 0);
}
@@ -1319,8 +1318,8 @@ abstract static class UTF16EXDecodeNode extends PythonQuaternaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object encode(VirtualFrame frame, Object obj, Object errors, Object byteorder, Object ffinal,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, toTruffleStringUncached("utf_16_ex_decode"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("utf_16_ex_decode"));
}
}
@@ -1391,7 +1390,7 @@ abstract static class UTF32EXDecodeNode extends PythonQuaternaryBuiltinNode {
@Specialization
@TruffleBoundary
Object encode(Object obj, Object errors, Object byteorder, Object ffinal) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, toTruffleStringUncached("utf_32_ex_decode"));
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, toTruffleStringUncached("utf_32_ex_decode"));
}
}
@@ -1402,7 +1401,7 @@ abstract static class UnicodeInternalEncodeNode extends PythonBinaryBuiltinNode
@Specialization
@TruffleBoundary
Object encode(Object obj, Object errors) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, toTruffleStringUncached("unicode_internal_encode"));
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, toTruffleStringUncached("unicode_internal_encode"));
}
}
@@ -1413,7 +1412,7 @@ abstract static class UnicodeInternalDecodeNode extends PythonBinaryBuiltinNode
@Specialization
@TruffleBoundary
Object encode(Object obj, Object errors) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, toTruffleStringUncached("unicode_internal_decode"));
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, toTruffleStringUncached("unicode_internal_decode"));
}
}
@@ -1557,7 +1556,7 @@ abstract static class ReadbufferEncodeNode extends PythonBinaryBuiltinNode {
@Specialization
@TruffleBoundary
Object encode(Object obj, Object errors) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, toTruffleStringUncached("readbuffer_encode"));
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, toTruffleStringUncached("readbuffer_encode"));
}
}
@@ -1593,7 +1592,7 @@ abstract static class OEMEncodeNode extends PythonBinaryBuiltinNode {
@Specialization
@TruffleBoundary
Object encode(Object obj, Object errors) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, toTruffleStringUncached("oem_encode"));
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, toTruffleStringUncached("oem_encode"));
}
}
@@ -1603,8 +1602,8 @@ abstract static class OEMDecodeNode extends PythonTernaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object decode(Object obj, Object errors, Object ffinal,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, toTruffleStringUncached("oem_decode"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("oem_decode"));
}
}
@@ -1614,8 +1613,8 @@ abstract static class CodePageEncodeNode extends PythonTernaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object encode(Object code_page, Object string, Object errors,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, toTruffleStringUncached("code_page_encode"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("code_page_encode"));
}
}
@@ -1625,8 +1624,8 @@ abstract static class CodePageDecodeNode extends PythonQuaternaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object decode(Object code_page, Object obj, Object errors, Object ffinal,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, toTruffleStringUncached("code_page_decode"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("code_page_decode"));
}
}
@@ -1654,8 +1653,8 @@ abstract static class EncodingMapNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object encodingMap(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "EncodingMap");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "EncodingMap");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
index ffc8d512c0..ed10d4c240 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java
@@ -432,7 +432,7 @@ Object lookup(VirtualFrame frame, TruffleString encoding, TruffleString alternat
PTuple codecInfo = lookupNode.execute(frame, inliningTarget, encoding);
Object isTextObj = getAttributeNode.execute(frame, inliningTarget, codecInfo, T_IS_TEXT_ENCODING);
if (!((isTextObj instanceof Boolean) && (boolean) isTextObj)) {
- throw raiseNode.raise(LookupError, IS_NOT_TEXT_ENCODING, encoding, alternateCommand);
+ throw raiseNode.raise(inliningTarget, LookupError, IS_NOT_TEXT_ENCODING, encoding, alternateCommand);
}
return codecInfo;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
index 934e08654b..98f42ed7e2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CollectionsModuleBuiltins.java
@@ -117,9 +117,9 @@ static PDequeIter doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Obje
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
@Cached DequeIterNextNode getNextNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!dequeProfile.profile(inliningTarget, deque instanceof PDeque)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
}
PDequeIter dequeIter = PFactory.createDequeIter(language, (PDeque) deque);
if (indexNoneProfile.profile(inliningTarget, indexObj != PNone.NO_VALUE)) {
@@ -146,9 +146,9 @@ static PDequeIter doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Obje
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
@Cached DequeIterNextNode getNextNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!dequeProfile.profile(inliningTarget, deque instanceof PDeque)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_OBJ_TYPE_S_GOT_P, BuiltinNames.T_DEQUE, deque);
}
PDequeIter dequeIter = PFactory.createDequeRevIter(language, (PDeque) deque);
if (indexNoneProfile.profile(inliningTarget, indexObj != PNone.NO_VALUE)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
index 33c5ff36ea..a257283410 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java
@@ -127,8 +127,8 @@ static Object construct(@SuppressWarnings("unused") Object cls,
public abstract static class TokenNode extends PythonUnaryBuiltinNode {
@Specialization
Object construct(@SuppressWarnings("unused") Object cls,
- @Cached PRaiseNode raise) {
- throw raise.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.TOKEN_ONLY_BY_CONTEXTVAR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.TOKEN_ONLY_BY_CONTEXTVAR);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
index c20cc0a987..947eca1ea7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FcntlModuleBuiltins.java
@@ -153,7 +153,7 @@ PNone lockf(VirtualFrame frame, int fd, int code, Object lenObj, Object startObj
@Cached SysModuleBuiltins.AuditNode auditNode,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posix,
@Cached PyLongAsLongNode asLongNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
auditNode.audit(inliningTarget, "fcntl.lockf", fd, code, lenObj != PNone.NO_VALUE ? lenObj : PNone.NONE, startObj != PNone.NO_VALUE ? startObj : PNone.NONE, whence);
int lockType;
@@ -164,7 +164,7 @@ PNone lockf(VirtualFrame frame, int fd, int code, Object lenObj, Object startObj
} else if ((code & LOCK_EX.value) != 0) {
lockType = F_WRLCK.getValueIfDefined();
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNRECOGNIZED_LOCKF_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNRECOGNIZED_LOCKF_ARGUMENT);
}
long start = 0;
if (startObj != PNone.NO_VALUE) {
@@ -209,7 +209,7 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Cached GilNode gilNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached SysModuleBuiltins.AuditNode auditNode) {
auditNode.audit(inliningTarget, "fcnt.ioctl", fd, request, arg);
@@ -249,7 +249,7 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
}
} else {
if (len > IOCTL_BUFSZ) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}
}
if (ioctlArg == null) {
@@ -285,7 +285,7 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
stringArg = switchEncodingNode.execute(stringArg, utf8);
int len = stringArg.byteLength(utf8);
if (len > IOCTL_BUFSZ) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}
byte[] ioctlArg = new byte[len + 1];
copyToByteArrayNode.execute(stringArg, 0, ioctlArg, 0, len, utf8);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
index ed28573a80..70ac43ebaf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java
@@ -130,7 +130,7 @@ static final class NotAvailable extends PythonBuiltinNode {
@Override
public Object execute(VirtualFrame frame) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_S_MODE_NOT_AVAILABLE, J_DEBUG);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_S_MODE_NOT_AVAILABLE, J_DEBUG);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
index 339859f6a8..2933df3032 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java
@@ -188,7 +188,7 @@ static Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString ex
@Cached TruffleString.EqualNode eqNode,
@Cached WriteAttributeToObjectNode writeAttrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object module;
PythonContext context = PythonContext.get(inliningTarget);
@@ -199,7 +199,7 @@ static Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString ex
module = GraalHPyContext.loadHPyModule(inliningTarget, context, name, file, spec, hmode);
} catch (CannotCastException e) {
// thrown by getHPyModeFromEnviron if value is not a string
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.HPY_MODE_VALUE_MUST_BE_STRING);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.HPY_MODE_VALUE_MUST_BE_STRING);
} catch (ApiInitException ie) {
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
} catch (ImportException ie) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
index 5bc287952d..9cc60db297 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
@@ -827,13 +827,13 @@ private HashingStorage getStrategy(TruffleString tname, PythonLanguage lang) {
case "economicmap":
return EconomicMapStorage.create();
default:
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ValueError, ErrorMessages.UNKNOWN_STORAGE_STRATEGY);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.UNKNOWN_STORAGE_STRATEGY);
}
}
private void validate(HashingStorage dictStorage) {
if (HashingStorageLen.executeUncached(dictStorage) != 0) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ValueError, ErrorMessages.SHOULD_BE_USED_ONLY_NEW_SETS);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.SHOULD_BE_USED_ONLY_NEW_SETS);
}
}
}
@@ -868,25 +868,25 @@ public abstract static class JavaExtendNode extends PythonUnaryBuiltinNode {
static Object doIt(Object value,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "3") InteropLibrary lib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (ImageInfo.inImageBuildtimeCode()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new UnsupportedOperationException(ErrorMessages.CANT_EXTEND_JAVA_CLASS_NOT_JVM.toJavaStringUncached());
}
if (ImageInfo.inImageRuntimeCode()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.CANT_EXTEND_JAVA_CLASS_NOT_JVM);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.CANT_EXTEND_JAVA_CLASS_NOT_JVM);
}
Env env = PythonContext.get(inliningTarget).getEnv();
if (!isType(value, env, lib)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_EXTEND_JAVA_CLASS_NOT_TYPE, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_EXTEND_JAVA_CLASS_NOT_TYPE, value);
}
try {
return env.createHostAdapter(new Object[]{value});
} catch (Exception ex) {
- throw raiseNode.get(inliningTarget).raise(TypeError, PythonUtils.getMessage(ex), ex);
+ throw raiseNode.raise(inliningTarget, TypeError, PythonUtils.getMessage(ex), ex);
}
}
@@ -1194,7 +1194,7 @@ static Object replicate(TruffleString venvPath, int count,
try {
NativeLibraryLocator.replicate(context.getEnv().getPublicTruffleFile(venvPath.toJavaStringUncached()), context, count);
} catch (IOException | InterruptedException e) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.ValueError, e);
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, e);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
index ff40c6724b..7337778755 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java
@@ -350,7 +350,7 @@ static int doPythonModule(VirtualFrame frame, PythonModule extensionModule,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "1") InteropLibrary lib,
@Cached ExecModuleNode execModuleNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object nativeModuleDef = extensionModule.getNativeModuleDef();
if (nativeModuleDef == null) {
return 0;
@@ -367,7 +367,7 @@ static int doPythonModule(VirtualFrame frame, PythonModule extensionModule,
PythonContext context = PythonContext.get(inliningTarget);
if (!context.hasCApiContext()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.CAPI_NOT_YET_INITIALIZED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.CAPI_NOT_YET_INITIALIZED);
}
/*
@@ -448,7 +448,7 @@ static Object run(VirtualFrame frame, PythonObject moduleSpec,
return builtinModule;
}
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, toTruffleStringUncached("_imp.create_builtin"));
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("_imp.create_builtin"));
}
}
@@ -545,7 +545,7 @@ static Object run(VirtualFrame frame, TruffleString name, Object dataObj,
@Cached TruffleString.EqualNode equalNode,
@Cached InlinedConditionProfile isCodeObjectProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
FrozenInfo info;
if (dataObj != PNone.NONE) {
try {
@@ -573,7 +573,7 @@ static Object run(VirtualFrame frame, TruffleString name, Object dataObj,
}
if (!isCodeObjectProfile.profile(inliningTarget, code instanceof PCode)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOT_A_CODE_OBJECT, name);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOT_A_CODE_OBJECT, name);
}
return code;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
index c7b724608d..9b2b721099 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java
@@ -161,12 +161,12 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
@Cached InlinedConditionProfile negativeProfile,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (negativeProfile.profile(inliningTarget, r < 0)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
+ throw raiseNode.raise(inliningTarget, ValueError, MUST_BE_NON_NEGATIVE, "r");
}
PCombinations self = PFactory.createCombinations(language, cls, getInstanceShape.execute(cls));
@@ -209,12 +209,12 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, int r,
@Cached InlinedConditionProfile negativeProfile,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (negativeProfile.profile(inliningTarget, r < 0)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
+ throw raiseNode.raise(inliningTarget, ValueError, MUST_BE_NON_NEGATIVE, "r");
}
PCombinationsWithReplacement self = PFactory.createCombinationsWithReplacement(language, cls, getInstanceShape.execute(cls));
self.setPool(toArrayNode.execute(frame, iterable));
@@ -246,9 +246,9 @@ static PCompress construct(VirtualFrame frame, Object cls, Object data, Object s
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
PCompress self = PFactory.createCompress(language, cls, getInstanceShape.execute(cls));
self.setData(getIter.execute(frame, inliningTarget, data));
@@ -280,15 +280,15 @@ static PCycle construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "cycle()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "cycle()");
}
if (args.length != 1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "cycle", 1);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "cycle", 1);
}
Object iterable = args[0];
PCycle self = PFactory.createCycle(language, cls, getInstanceShape.execute(cls));
@@ -313,15 +313,15 @@ static PDropwhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "dropwhile()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "dropwhile()");
}
if (args.length != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "dropwhile", 2);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "dropwhile", 2);
}
Object predicate = args[0];
Object iterable = args[1];
@@ -347,15 +347,15 @@ static PFilterfalse construct(VirtualFrame frame, Object cls, Object[] args, PKe
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "filterfalse()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "filterfalse()");
}
if (args.length != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "filterfalse", 2);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "filterfalse", 2);
}
Object func = args[0];
Object sequence = args[1];
@@ -398,9 +398,9 @@ static PGroupBy construct(VirtualFrame frame, Object cls, Object iterable, Objec
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
PGroupBy self = PFactory.createGroupBy(language, cls, getInstanceShape.execute(cls));
self.setKeyFunc(PGuards.isNone(key) ? null : key);
@@ -419,12 +419,12 @@ static PGrouper construct(Object cls, Object parent, Object tgtKey,
@Cached InlinedConditionProfile isPGroupByProfile,
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (!isPGroupByProfile.profile(inliningTarget, parent instanceof PGroupBy)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INCORRECT_USAGE_OF_INTERNAL_GROUPER);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INCORRECT_USAGE_OF_INTERNAL_GROUPER);
}
return PFactory.createGrouper(language, (PGroupBy) parent, tgtKey);
}
@@ -443,15 +443,15 @@ static PTakewhile construct(VirtualFrame frame, Object cls, Object[] args, PKeyw
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "takewhile()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "takewhile()");
}
if (args.length != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "takewhile", 2);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "takewhile", 2);
}
Object predicate = args[0];
Object iterable = args[1];
@@ -474,8 +474,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@SuppressWarnings("unused")
@Specialization(guards = "n < 0")
static Object negativeN(Object iterable, int n,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, S_MUST_BE_S, "n", ">=0");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, S_MUST_BE_S, "n", ">=0");
}
@SuppressWarnings("unused")
@@ -528,7 +528,7 @@ PTeeDataObject construct(Object cls, Object[] arguments, PKeyword[] keywords,
@Bind PythonLanguage language) {
if (!isTypeNode.execute(inliningTarget, cls)) {
errorProfile.enter(inliningTarget);
- throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
return PFactory.createTeeDataObject(language);
}
@@ -560,9 +560,9 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, Object
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!wrongTypeProfile.profile(inliningTarget, isTypeNode.execute(inliningTarget, cls))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
int r;
Object[] pool = toArrayNode.execute(frame, iterable);
@@ -573,11 +573,11 @@ static Object construct(VirtualFrame frame, Object cls, Object iterable, Object
r = castToInt.execute(inliningTarget, rArg);
} catch (CannotCastException e) {
wrongRprofile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_INT_AS_R);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_INT_AS_R);
}
if (r < 0) {
negRprofile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, MUST_BE_NON_NEGATIVE, "r");
+ throw raiseNode.raise(inliningTarget, ValueError, MUST_BE_NON_NEGATIVE, "r");
}
}
PPermutations self = PFactory.createPermutations(language, cls, getInstanceShape.execute(cls));
@@ -689,9 +689,8 @@ static Object constructNoRepeat(Object cls, @SuppressWarnings("unused") Object[]
@Specialization(guards = {"isTypeNode.execute(inliningTarget, cls)", "repeat < 0"}, limit = "1")
static Object constructNeg(Object cls, Object[] iterables, int repeat,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARG_CANNOT_BE_NEGATIVE, "repeat");
+ @Exclusive @Cached IsTypeNode isTypeNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARG_CANNOT_BE_NEGATIVE, "repeat");
}
private static void constructOneRepeat(VirtualFrame frame, PProduct self, Object[] iterables, ToArrayNode toArrayNode) {
@@ -726,9 +725,8 @@ private static Object[][] unpackIterables(VirtualFrame frame, Object[] iterables
@SuppressWarnings("unused")
static Object construct(Object cls, Object iterables, Object repeat,
@Bind("this") Node inliningTarget,
- @Shared("typeNode") @Cached IsTypeNode isTypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ @Shared("typeNode") @Cached IsTypeNode isTypeNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
}
@@ -746,7 +744,7 @@ static Object construct(VirtualFrame frame, Object cls, Object object, Object ti
@Cached TypeNodes.GetInstanceShape getInstanceShape) {
PRepeat self = PFactory.createRepeat(language, cls, getInstanceShape.execute(cls));
self.setElement(object);
- if (timesObj != PNone.NONE) {
+ if (timesObj != PNone.NO_VALUE) {
int times = asSizeNode.executeExact(frame, inliningTarget, timesObj);
self.setCnt(times > 0 ? times : 0);
} else {
@@ -769,12 +767,12 @@ static PChain construct(VirtualFrame frame, Object cls, Object[] args, PKeyword[
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "chain()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "chain()");
}
PChain self = PFactory.createChain(language, cls, getInstanceShape.execute(cls));
self.setSource(getIter.execute(frame, inliningTarget, PFactory.createList(language, args)));
@@ -801,15 +799,15 @@ static Object construct(Object cls, Object start, Object step,
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (!checkNode.execute(inliningTarget, start)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NUMBER_IS_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, NUMBER_IS_REQUIRED);
}
if (!checkNode.execute(inliningTarget, step)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NUMBER_IS_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, NUMBER_IS_REQUIRED);
}
PCount self = PFactory.createCount(language, cls, getInstanceShape.execute(cls));
self.setCnt(start);
@@ -831,15 +829,15 @@ static PStarmap construct(VirtualFrame frame, Object cls, Object[] args, PKeywor
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "starmap()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "starmap()");
}
if (args.length != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "starmap", 2);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_EXPECTED_D_ARGS, "starmap", 2);
}
Object fun = args[0];
Object iterable = args[1];
@@ -876,17 +874,17 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
wrongTypeBranch.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
if (keywords.length > 0 && hasObjectInitNode.executeCached(cls)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "islice()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "islice()");
}
if (args.length < 2 || args.length > 4) {
wrongArgsBranch.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ISLICE_WRONG_ARGS);
+ throw raiseNode.raise(inliningTarget, TypeError, ISLICE_WRONG_ARGS);
}
int start = 0;
int step = 1;
@@ -898,12 +896,12 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
stop = asIntNode.executeExact(frame, inliningTarget, args[1], OverflowError);
} catch (PException e) {
stopNotInt.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
+ throw raiseNode.raise(inliningTarget, ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
}
}
if (stop < -1 || stop > SysModuleBuiltins.MAXSIZE) {
stopWrongValue.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
+ throw raiseNode.raise(inliningTarget, ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
}
} else if (argsLen2.profile(inliningTarget, args.length == 3) || argsLen3.profile(inliningTarget, args.length == 4)) {
if (args[1] != PNone.NONE) {
@@ -912,7 +910,7 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
start = asIntNode.executeExact(frame, inliningTarget, args[1], OverflowError);
} catch (PException e) {
startNotInt.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
+ throw raiseNode.raise(inliningTarget, ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
}
}
if (args[2] != PNone.NONE) {
@@ -921,12 +919,12 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
stop = asIntNode.executeExact(frame, inliningTarget, args[2], OverflowError);
} catch (PException e) {
stopNotInt.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, S_FOR_ISLICE_MUST_BE, "Stop argument");
+ throw raiseNode.raise(inliningTarget, ValueError, S_FOR_ISLICE_MUST_BE, "Stop argument");
}
}
if (start < 0 || stop < -1 || start > SysModuleBuiltins.MAXSIZE || stop > SysModuleBuiltins.MAXSIZE) {
wrongValue.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
+ throw raiseNode.raise(inliningTarget, ValueError, S_FOR_ISLICE_MUST_BE, "Indices");
}
}
if (argsLen3.profile(inliningTarget, args.length == 4)) {
@@ -941,7 +939,7 @@ static Object constructOne(VirtualFrame frame, Object cls, Object[] args, PKeywo
}
if (step < 1) {
stepWrongValue.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, STEP_FOR_ISLICE_MUST_BE);
+ throw raiseNode.raise(inliningTarget, ValueError, STEP_FOR_ISLICE_MUST_BE);
}
}
Object iterable = args[0];
@@ -975,11 +973,11 @@ static Object construct(VirtualFrame frame, Object cls, Object[] args, Object fi
@Cached InlinedBranchProfile errorProfile,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
// Note: @Fallback or other @Specialization generate data-class
errorProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
Object fillValue = fillValueIn;
@@ -1013,10 +1011,10 @@ static PPairwise construct(VirtualFrame frame, Object cls, Object iterable,
@Cached IsTypeNode isTypeNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, cls)) {
// Note: @Fallback or other @Specialization generate data-class
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
}
PPairwise self = PFactory.createPairwise(language, cls, getInstanceShape.execute(cls));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JArrayModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JArrayModuleBuiltins.java
index 263d6183e9..5f236f1b85 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JArrayModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JArrayModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -150,8 +150,8 @@ static Object d(int length, @SuppressWarnings("unused") String typeCode) {
@Fallback
@SuppressWarnings("unused")
static Object error(int length, String typeCode,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.INVALID_TYPE_CODE, typeCode);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.INVALID_TYPE_CODE, typeCode);
}
protected static boolean eq(String a, String b) {
@@ -178,7 +178,7 @@ static Object fromTypeCode(int length, Object typeCodeObj,
@Specialization(guards = "!isString(classObj)")
static Object fromClass(int length, Object classObj,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleLanguage.Env env = PythonContext.get(inliningTarget).getEnv();
if (env.isHostObject(classObj)) {
Object clazz = env.asHostObject(classObj);
@@ -187,7 +187,7 @@ static Object fromClass(int length, Object classObj,
return env.asGuestValue(array);
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SECOND_ARG_MUST_BE_STR_OR_JAVA_CLS, classObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SECOND_ARG_MUST_BE_STR_OR_JAVA_CLS, classObj);
}
@Override
@@ -206,7 +206,7 @@ static Object fromSequence(PSequence sequence, Object type,
@Shared @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemScalarNode,
@Shared @Cached ZerosNode zerosNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, sequence);
int length = storage.length();
Object array = zerosNode.execute(length, type);
@@ -215,7 +215,7 @@ static Object fromSequence(PSequence sequence, Object type,
try {
lib.writeArrayElement(array, i, value);
} catch (UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
} catch (UnsupportedMessageException | InvalidArrayIndexException e) {
throw CompilerDirectives.shouldNotReachHere("failed to set array item");
}
@@ -231,7 +231,7 @@ static Object fromIterable(VirtualFrame frame, Object sequence, Object type,
@Shared @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemScalarNode,
@Shared @Cached ZerosNode zerosNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PList list = constructListNode.execute(frame, sequence);
return fromSequence(list, type, inliningTarget, lib, getSequenceStorageNode, getItemScalarNode, zerosNode, raiseNode);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java
index 4f9f74f27b..f3a83edf88 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -128,10 +128,10 @@ abstract static class TypeNode extends PythonUnaryBuiltinNode {
static Object type(Object name,
@Bind("this") Node inliningTarget,
@Cached CastToJavaStringNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Env env = PythonContext.get(inliningTarget).getEnv();
if (!env.isHostLookupAllowed()) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.NotImplementedError, ErrorMessages.HOST_LOOKUP_NOT_ALLOWED);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.NotImplementedError, ErrorMessages.HOST_LOOKUP_NOT_ALLOWED);
}
String javaString = castToStringNode.execute(name);
Object hostValue;
@@ -141,7 +141,7 @@ static Object type(Object name,
hostValue = null;
}
if (hostValue == null) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.KeyError, ErrorMessages.HOST_SYM_NOT_DEFINED, javaString);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.KeyError, ErrorMessages.HOST_SYM_NOT_DEFINED, javaString);
} else {
return hostValue;
}
@@ -149,8 +149,8 @@ static Object type(Object name,
@Fallback
static Object doError(Object object,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_P, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_P, object);
}
}
@@ -161,10 +161,10 @@ abstract static class AddToClassPathNode extends PythonBuiltinNode {
static PNone add(Object[] args,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castToString,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Env env = PythonContext.get(inliningTarget).getEnv();
if (!env.isHostLookupAllowed()) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.NotImplementedError, ErrorMessages.HOST_ACCESS_NOT_ALLOWED);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.NotImplementedError, ErrorMessages.HOST_ACCESS_NOT_ALLOWED);
}
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
@@ -175,9 +175,9 @@ static PNone add(Object[] args,
// implicitly
env.addToHostClassPath(PythonContext.get(inliningTarget).getPublicTruffleFileRelaxed(entry, T_JAR));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CLASSPATH_ARG_MUST_BE_STRING, i + 1, arg);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CLASSPATH_ARG_MUST_BE_STRING, i + 1, arg);
} catch (SecurityException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INVALD_OR_UNREADABLE_CLASSPATH, entry, e);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INVALD_OR_UNREADABLE_CLASSPATH, entry, e);
}
}
return PNone.NONE;
@@ -232,7 +232,7 @@ static boolean check(Object object, Object klass,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared("isForeign1") @Cached IsForeignObjectNode isForeign1,
@SuppressWarnings("unused") @Shared("isForeign2") @Cached IsForeignObjectNode isForeign2,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Env env = PythonContext.get(inliningTarget).getEnv();
try {
Object hostKlass = env.asHostObject(klass);
@@ -240,7 +240,7 @@ static boolean check(Object object, Object klass,
return ((Class>) hostKlass).isInstance(object);
}
} catch (ClassCastException cce) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.KLASS_ARG_IS_NOT_HOST_OBJ, klass);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.KLASS_ARG_IS_NOT_HOST_OBJ, klass);
}
return false;
}
@@ -250,7 +250,7 @@ static boolean checkForeign(Object object, Object klass,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared("isForeign1") @Cached IsForeignObjectNode isForeign1,
@SuppressWarnings("unused") @Shared("isForeign2") @Cached IsForeignObjectNode isForeign2,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Env env = PythonContext.get(inliningTarget).getEnv();
try {
Object hostObject = env.asHostObject(object);
@@ -259,15 +259,15 @@ static boolean checkForeign(Object object, Object klass,
return ((Class>) hostKlass).isInstance(hostObject);
}
} catch (ClassCastException cce) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.OBJ_OR_KLASS_ARGS_IS_NOT_HOST_OBJ, object, klass);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.OBJ_OR_KLASS_ARGS_IS_NOT_HOST_OBJ, object, klass);
}
return false;
}
@Fallback
static boolean fallback(Object object, Object klass,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.UNSUPPORTED_INSTANCEOF, object, klass);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.UNSUPPORTED_INSTANCEOF, object, klass);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
index 67fce07408..24a7747f03 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java
@@ -192,7 +192,7 @@ private static String setCurrent(PythonContext ctx, int category, String posixLo
if (newLocale != null) {
ctx.setCurrentLocale(current.withCategory(category, newLocale));
} else {
- throw PRaiseNode.raiseUncached(nodeForRaise, PythonErrorType.ValueError, ErrorMessages.UNSUPPORTED_LOCALE_SETTING);
+ throw PRaiseNode.raiseStatic(nodeForRaise, PythonErrorType.ValueError, ErrorMessages.UNSUPPORTED_LOCALE_SETTING);
}
return LocaleUtils.toPosix(newLocale);
}
@@ -204,10 +204,10 @@ static TruffleString doGeneric(VirtualFrame frame, Object category, Object posix
@Cached CastToTruffleStringNode castToStringNode,
@Cached FromJavaStringNode resultAsTruffleStringNode,
@Cached ToJavaStringNode toJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long l = asLongNode.execute(frame, inliningTarget, category);
if (!isValidCategory(l)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.INVALID_LOCALE_CATEGORY);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.INVALID_LOCALE_CATEGORY);
}
TruffleString posixLocaleIDStr = null;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
index a8c503b1da..4637f001af 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LsprofModuleBuiltins.java
@@ -146,7 +146,7 @@ Profiler doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWa
return PFactory.createProfiler(context.getLanguage(), cls, TypeNodes.GetInstanceShape.executeUncached(cls), sampler);
}
}
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.NotImplementedError, ErrorMessages.COVERAGE_TRACKER_NOT_AVAILABLE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.NotImplementedError, ErrorMessages.COVERAGE_TRACKER_NOT_AVAILABLE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
index 962926ddc9..2cc96ed78e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java
@@ -169,12 +169,12 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupport,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (lengthIn < 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MEM_MAPPED_LENGTH_MUST_BE_POSITIVE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MEM_MAPPED_LENGTH_MUST_BE_POSITIVE);
}
if (offset < 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MEM_MAPPED_OFFSET_MUST_BE_POSITIVE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MEM_MAPPED_OFFSET_MUST_BE_POSITIVE);
}
int flags = flagsIn;
int prot = protIn;
@@ -203,7 +203,7 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
}
break;
default:
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEM_MAPPED_OFFSET_INVALID_ACCESS);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEM_MAPPED_OFFSET_INVALID_ACCESS);
}
auditNode.audit(inliningTarget, "mmap.__new__", fd, lengthIn, access, offset);
@@ -220,15 +220,15 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
}
if (fstatResult != null && length == 0) {
if (fstatResult[ST_SIZE] == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_MMAP_AN_EMPTY_FILE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_MMAP_AN_EMPTY_FILE);
}
if (offset >= fstatResult[ST_SIZE]) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MMAP_S_IS_GREATER_THAN_FILE_SIZE, "offset");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MMAP_S_IS_GREATER_THAN_FILE_SIZE, "offset");
}
// Unlike in CPython, this always fits in the long range
length = fstatResult[ST_SIZE] - offset;
} else if (fstatResult != null && (offset > fstatResult[ST_SIZE] || fstatResult[ST_SIZE] - offset < length)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MMAP_S_IS_GREATER_THAN_FILE_SIZE, "length");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MMAP_S_IS_GREATER_THAN_FILE_SIZE, "length");
}
}
@@ -260,8 +260,8 @@ static PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int
@Specialization(guards = "isIllegal(fd)")
@SuppressWarnings("unused")
static PMMap doIllegal(Object clazz, int fd, long lengthIn, int flagsIn, int protIn, int accessIn, long offset,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.OSError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.OSError);
}
protected static boolean isIllegal(int fd) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
index dbe0c43be8..d858f0ee50 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java
@@ -162,7 +162,7 @@ static Object doit(VirtualFrame frame, Object value, Object file, int version,
@Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached("createCallWriteNode()") LookupAndCallBinaryNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonLanguage language = context.getLanguage(inliningTarget);
PythonContext.PythonThreadState threadState = context.getThreadState(language);
Object savedState = IndirectCallContext.enter(frame, threadState, indirectCallData);
@@ -171,7 +171,7 @@ static Object doit(VirtualFrame frame, Object value, Object file, int version,
} catch (IOException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} catch (Marshal.MarshalError me) {
- throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
+ throw raiseNode.raise(inliningTarget, me.type, me.message, me.arguments);
} finally {
IndirectCallContext.exit(frame, threadState, savedState);
}
@@ -192,7 +192,7 @@ static Object doit(VirtualFrame frame, Object value, int version,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonLanguage language = context.getLanguage(inliningTarget);
PythonContext.PythonThreadState threadState = context.getThreadState(language);
Object savedState = IndirectCallContext.enter(frame, threadState, indirectCallData);
@@ -201,7 +201,7 @@ static Object doit(VirtualFrame frame, Object value, int version,
} catch (IOException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} catch (Marshal.MarshalError me) {
- throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
+ throw raiseNode.raise(inliningTarget, me.type, me.message, me.arguments);
} finally {
IndirectCallContext.exit(frame, threadState, savedState);
}
@@ -222,17 +222,17 @@ static Object doit(VirtualFrame frame, Object file,
@Bind PythonContext context,
@Cached("createCallReadNode()") LookupAndCallBinaryNode callNode,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = callNode.executeObject(frame, file, 0);
if (!bufferLib.hasBuffer(buffer)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.READ_RETURNED_NOT_BYTES, buffer);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.READ_RETURNED_NOT_BYTES, buffer);
}
try {
return Marshal.loadFile(context, file);
} catch (NumberFormatException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
} catch (Marshal.MarshalError me) {
- throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
+ throw raiseNode.raise(inliningTarget, me.type, me.message, me.arguments);
}
}
}
@@ -248,13 +248,13 @@ static Object doit(VirtualFrame frame, Object buffer,
@Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return Marshal.load(context, bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
} catch (NumberFormatException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
} catch (Marshal.MarshalError me) {
- throw raiseNode.get(inliningTarget).raise(me.type, me.message, me.arguments);
+ throw raiseNode.raise(inliningTarget, me.type, me.message, me.arguments);
} finally {
bufferLib.release(buffer, frame, indirectCallData);
}
@@ -1348,7 +1348,7 @@ private PCode readCode() {
}
@TruffleBoundary
- public static byte[] serializeCodeUnit(PythonContext context, CodeUnit code) {
+ public static byte[] serializeCodeUnit(Node node, PythonContext context, CodeUnit code) {
try {
Marshal marshal = new Marshal(context, CURRENT_VERSION, null, null);
marshal.writeCodeUnit(code);
@@ -1356,19 +1356,19 @@ public static byte[] serializeCodeUnit(PythonContext context, CodeUnit code) {
} catch (IOException e) {
throw CompilerDirectives.shouldNotReachHere(e);
} catch (Marshal.MarshalError me) {
- throw PRaiseNode.getUncached().raise(me.type, me.message, me.arguments);
+ throw PRaiseNode.raiseStatic(node, me.type, me.message, me.arguments);
}
}
@TruffleBoundary
- public static CodeUnit deserializeCodeUnit(PythonContext context, byte[] bytes) {
+ public static CodeUnit deserializeCodeUnit(Node node, PythonContext context, byte[] bytes) {
try {
Marshal marshal = new Marshal(context, bytes, bytes.length);
return marshal.readCodeUnit();
} catch (Marshal.MarshalError me) {
- throw PRaiseNode.getUncached().raise(me.type, me.message, me.arguments);
+ throw PRaiseNode.raiseStatic(node, me.type, me.message, me.arguments);
} catch (NumberFormatException e) {
- throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
+ throw PRaiseNode.raiseStatic(node, ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
index 4e98b5bb38..19899dc92b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
@@ -125,21 +125,21 @@ public MathModuleBuiltins() {
addBuiltinConstant("nan", Double.NaN);
}
- static void checkMathRangeError(boolean con, Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ static void checkMathRangeError(boolean con, Node inliningTarget, PRaiseNode raiseNode) {
if (con) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
}
}
- static void checkMathDomainError(boolean con, Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ static void checkMathDomainError(boolean con, Node inliningTarget, PRaiseNode raiseNode) {
if (con) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
}
static void checkMathDomainErrorUncached(boolean con, Node raisingNode) {
if (con) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
}
@@ -151,37 +151,37 @@ public abstract static class MathUnaryHelperNode extends Node {
@FunctionalInterface
interface Op {
- double compute(Node inliningTarget, double arg, PRaiseNode.Lazy raiseNode);
+ double compute(Node inliningTarget, double arg, PRaiseNode raiseNode);
}
abstract double execute(VirtualFrame frame, Node inliningTarget, Object value, Op op);
@Specialization
static double doL(Node inliningTarget, long value, Op op,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return computeAndCheckDomain(inliningTarget, value, op, raiseNode);
}
@Specialization
static double doD(Node inliningTarget, double value, Op op,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return computeAndCheckDomain(inliningTarget, value, op, raiseNode);
}
@Specialization
static double doPI(Node inliningTarget, PInt value, Op op,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return computeAndCheckDomain(inliningTarget, value.doubleValueWithOverflow(inliningTarget), op, raiseNode);
}
@Specialization(guards = "!isNumber(value)")
static double doGeneral(VirtualFrame frame, Node inliningTarget, Object value, Op op,
@Cached PyFloatAsDoubleNode asDoubleNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return computeAndCheckDomain(inliningTarget, asDoubleNode.execute(frame, inliningTarget, value), op, raiseNode);
}
- private static double computeAndCheckDomain(Node inliningTarget, double arg, Op op, PRaiseNode.Lazy raiseNode) {
+ private static double computeAndCheckDomain(Node inliningTarget, double arg, Op op, PRaiseNode raiseNode) {
double res = op.compute(inliningTarget, arg, raiseNode);
checkMathDomainError(Double.isNaN(res) && !Double.isNaN(arg), inliningTarget, raiseNode);
return res;
@@ -238,7 +238,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SqrtNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(value < 0, inliningTarget, raiseNode);
return Math.sqrt(value);
}
@@ -255,7 +255,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, ExpNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double result = Math.exp(value);
checkMathRangeError(Double.isFinite(value) && Double.isInfinite(result), inliningTarget, raiseNode);
return result;
@@ -273,7 +273,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, Expm1Node::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double result = Math.expm1(value);
checkMathRangeError(Double.isFinite(value) && Double.isInfinite(result), inliningTarget, raiseNode);
return result;
@@ -352,8 +352,8 @@ private static BigInteger factorialPart(long start, long n) {
@Specialization(guards = {"value < 0"})
static long factorialNegativeInt(@SuppressWarnings("unused") int value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
}
@Specialization(guards = {"0 <= value", "value < SMALL_FACTORIALS.length"})
@@ -369,8 +369,8 @@ static PInt factorialInt(int value,
@Specialization(guards = {"value < 0"})
static long factorialNegativeLong(@SuppressWarnings("unused") long value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
}
@Specialization(guards = {"0 <= value", "value < SMALL_FACTORIALS.length"})
@@ -390,14 +390,14 @@ static Object factorialObject(VirtualFrame frame, Object value,
@Cached PyLongAsLongAndOverflowNode convert,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached FactorialNode recursiveNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return recursiveNode.execute(frame, convert.execute(frame, inliningTarget, value));
} catch (OverflowException e) {
if (asSizeNode.executeLossy(frame, inliningTarget, value) >= 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.FACTORIAL_ARGUMENT_SHOULD_NOT_EXCEED_D, Long.MAX_VALUE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.FACTORIAL_ARGUMENT_SHOULD_NOT_EXCEED_D, Long.MAX_VALUE);
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.FACTORIAL_NOT_DEFINED_FOR_NEGATIVE);
}
}
}
@@ -413,10 +413,10 @@ public abstract static class CombNode extends PythonBinaryBuiltinNode {
@TruffleBoundary
private BigInteger calculateComb(BigInteger n, BigInteger k) {
if (n.signum() < 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "n");
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "n");
}
if (k.signum() < 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "k");
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "k");
}
BigInteger factors = k.min(n.subtract(k));
@@ -483,10 +483,10 @@ public abstract static class PermNode extends PythonBinaryBuiltinNode {
@TruffleBoundary
private BigInteger calculatePerm(BigInteger n, BigInteger k) {
if (n.signum() < 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "n");
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "n");
}
if (k.signum() < 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "k");
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE_INTEGER, "k");
}
if (n.compareTo(k) < 0) {
return BigInteger.ZERO;
@@ -590,15 +590,15 @@ static double fmodDD(double left, double right,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile infProfile,
@Cached InlinedConditionProfile zeroProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
raiseMathDomainError(inliningTarget, Double.isInfinite(left), infProfile, raiseNode);
raiseMathDomainError(inliningTarget, right == 0, zeroProfile, raiseNode);
return left % right;
}
- static void raiseMathDomainError(Node inliningTarget, boolean con, InlinedConditionProfile profile, PRaiseNode.Lazy raiseNode) {
+ static void raiseMathDomainError(Node inliningTarget, boolean con, InlinedConditionProfile profile, PRaiseNode raiseNode) {
if (profile.profile(inliningTarget, con)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
}
@@ -617,10 +617,10 @@ public abstract static class RemainderNode extends PythonBinaryClinicBuiltinNode
@Specialization
static double remainderDD(double x, double y,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (Double.isFinite(x) && Double.isFinite(y)) {
if (y == 0.0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
double absx = Math.abs(x);
double absy = Math.abs(y);
@@ -643,7 +643,7 @@ static double remainderDD(double x, double y,
return y;
}
if (Double.isInfinite(x)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
return x;
}
@@ -754,11 +754,11 @@ public abstract static class IsCloseNode extends PythonClinicBuiltinNode {
@Specialization
static boolean isCloseDouble(double a, double b, double rel_tol, double abs_tol,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
double diff;
if (rel_tol < 0.0 || abs_tol < 0.0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TOLERANCE_MUST_NON_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOLERANCE_MUST_NON_NEGATIVE);
}
if (a == b) {
@@ -797,9 +797,9 @@ private static int makeInt(long x) {
return (int) result;
}
- private static double exceptInfinity(Node inliningTarget, double result, double arg, PRaiseNode.Lazy raiseNode) {
+ private static double exceptInfinity(Node inliningTarget, double result, double arg, PRaiseNode raiseNode) {
if (Double.isInfinite(result) && !Double.isInfinite(arg)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
} else {
return result;
}
@@ -808,7 +808,7 @@ private static double exceptInfinity(Node inliningTarget, double result, double
@Specialization
static double ldexp(double mantissa, long exp,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return exceptInfinity(inliningTarget, Math.scalb(mantissa, makeInt(exp)), mantissa, raiseNode);
}
@@ -819,12 +819,12 @@ static double ldexp(VirtualFrame frame, double mantissa, Object exp,
@Cached IsSubtypeNode isSubtypeNode,
@Cached PyNumberIndexNode indexNode,
@Cached CastToJavaLongLossyNode cast,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, exp), PythonBuiltinClassType.PInt)) {
long longExp = cast.execute(inliningTarget, indexNode.execute(frame, inliningTarget, exp));
return ldexp(mantissa, longExp, inliningTarget, raiseNode);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_INT_MESSAGE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_INT_MESSAGE);
}
}
@@ -870,7 +870,7 @@ static double doIt(VirtualFrame frame, Object iterable,
@Cached("create(Next)") LookupAndCallUnaryNode callNextNode,
@Cached PyFloatAsDoubleNode asDoubleNode,
@Cached IsBuiltinObjectProfile stopProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object iterator = getIter.execute(frame, inliningTarget, iterable);
return fsum(frame, iterator, callNextNode, asDoubleNode, inliningTarget, stopProfile, raiseNode);
}
@@ -886,7 +886,7 @@ static double doIt(VirtualFrame frame, Object iterable,
* CPython ~0.6s CurrentImpl: ~14.3s Using BigDecimal: ~15.1
*/
private static double fsum(VirtualFrame frame, Object iterator, LookupAndCallUnaryNode next,
- PyFloatAsDoubleNode asDoubleNode, Node inliningTarget, IsBuiltinObjectProfile stopProfile, PRaiseNode.Lazy raiseNode) {
+ PyFloatAsDoubleNode asDoubleNode, Node inliningTarget, IsBuiltinObjectProfile stopProfile, PRaiseNode raiseNode) {
double x, y, t, hi, lo = 0, yr, inf_sum = 0, special_sum = 0, sum;
double xsave;
int i, j, n = 0, arayLength = 32;
@@ -923,7 +923,7 @@ private static double fsum(VirtualFrame frame, Object iterator, LookupAndCallUna
* as a result of a nan or inf in the summands
*/
if (Double.isFinite(xsave)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.INTERMEDIATE_OVERFLOW_IN, "fsum");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.INTERMEDIATE_OVERFLOW_IN, "fsum");
}
if (Double.isInfinite(xsave)) {
inf_sum += xsave;
@@ -942,7 +942,7 @@ private static double fsum(VirtualFrame frame, Object iterator, LookupAndCallUna
if (special_sum != 0.0) {
if (Double.isNaN(inf_sum)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_INF_PLUS_INF_IN);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_INF_PLUS_INF_IN);
} else {
sum = special_sum;
return sum;
@@ -1029,7 +1029,7 @@ public static int gcdEmpty(Object self, Object[] args, PKeyword[] keywords) {
@Specialization(guards = "keywords.length != 0")
@SuppressWarnings("unused")
public int gcdKeywords(Object self, Object[] args, PKeyword[] keywords) {
- throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "gcd()");
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "gcd()");
}
}
@@ -1082,32 +1082,32 @@ PInt gcd(PInt x, PInt y,
@Specialization
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") double y,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
}
@Specialization
static int gcd(@SuppressWarnings("unused") long x, @SuppressWarnings("unused") double y,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
}
@Specialization
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") long y,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
}
@Specialization
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") PInt y,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
}
@Specialization(guards = "!isRecursive")
static int gcd(@SuppressWarnings("unused") PInt x, @SuppressWarnings("unused") double y,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
}
@Specialization(guards = {"!isRecursive", "!isNumber(x) || !isNumber(y)"})
@@ -1123,7 +1123,7 @@ static Object gcd(VirtualFrame frame, Object x, Object y,
@Specialization
Object gcdNative(@SuppressWarnings("unused") PythonAbstractNativeObject a, @SuppressWarnings("unused") Object b) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.GCD_FOR_NATIVE_NOT_SUPPORTED);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.GCD_FOR_NATIVE_NOT_SUPPORTED);
}
@NeverDefault
@@ -1186,7 +1186,7 @@ public static int gcdEmpty(Object self, Object[] args, PKeyword[] keywords) {
@Specialization(guards = "keywords.length != 0")
@SuppressWarnings("unused")
public int gcdKeywords(Object self, Object[] args, PKeyword[] keywords) {
- throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "gcd()");
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "gcd()");
}
}
@@ -1250,7 +1250,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AcosNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(Double.isInfinite(value) || -1 > value || value > 1, inliningTarget, raiseNode);
return Math.acos(value);
}
@@ -1284,7 +1284,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AcoshNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(value < 1, inliningTarget, raiseNode);
return MathUtils.acosh(value);
}
@@ -1301,7 +1301,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AsinNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(value < -1 || value > 1, inliningTarget, raiseNode);
return Math.asin(value);
}
@@ -1318,7 +1318,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, CosNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return Math.cos(value);
}
}
@@ -1334,7 +1334,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, CoshNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double result = Math.cosh(value);
checkMathRangeError(Double.isInfinite(result) && Double.isFinite(value), inliningTarget, raiseNode);
return result;
@@ -1352,7 +1352,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SinNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return Math.sin(value);
}
}
@@ -1368,7 +1368,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, SinhNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double result = Math.sinh(value);
checkMathRangeError(Double.isInfinite(result) && Double.isFinite(value), inliningTarget, raiseNode);
return result;
@@ -1386,7 +1386,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, TanNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return Math.tan(value);
}
}
@@ -1402,7 +1402,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, TanhNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return Math.tanh(value);
}
}
@@ -1418,7 +1418,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AtanNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return Math.atan(value);
}
}
@@ -1434,7 +1434,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AtanhNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double abs = Math.abs(value);
checkMathDomainError(abs >= 1.0, inliningTarget, raiseNode);
return MathUtils.atanh(value);
@@ -1454,7 +1454,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, AsinhNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return MathUtils.asinh(value);
}
@@ -1549,18 +1549,18 @@ protected static double logBigInteger(BigInteger val) {
return blex > 0 ? res + blex * LOG2 : res;
}
- private static double countBase(double base, Node inliningTarget, InlinedConditionProfile divByZero, PRaiseNode.Lazy raiseNode) {
+ private static double countBase(double base, Node inliningTarget, InlinedConditionProfile divByZero, PRaiseNode raiseNode) {
double logBase = Math.log(base);
if (divByZero.profile(inliningTarget, logBase == 0)) {
- throw raiseNode.get(inliningTarget).raise(ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "float");
+ throw raiseNode.raise(inliningTarget, ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "float");
}
return logBase;
}
- private static double countBase(BigInteger base, Node inliningTarget, InlinedConditionProfile divByZero, PRaiseNode.Lazy raiseNode) {
+ private static double countBase(BigInteger base, Node inliningTarget, InlinedConditionProfile divByZero, PRaiseNode raiseNode) {
double logBase = logBigInteger(base);
if (divByZero.profile(inliningTarget, logBase == 0)) {
- throw raiseNode.get(inliningTarget).raise(ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "float");
+ throw raiseNode.raise(inliningTarget, ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "float");
}
return logBase;
}
@@ -1569,7 +1569,7 @@ private static double countBase(BigInteger base, Node inliningTarget, InlinedCon
static double log(long value, PNone novalue,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return logDN(value, novalue, inliningTarget, doNotFit, raiseNode);
}
@@ -1577,7 +1577,7 @@ static double log(long value, PNone novalue,
static double logDN(double value, @SuppressWarnings("unused") PNone novalue,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseMathError(inliningTarget, doNotFit, value <= 0, raiseNode);
return Math.log(value);
}
@@ -1587,7 +1587,7 @@ static double logDN(double value, @SuppressWarnings("unused") PNone novalue,
static double logPIN(PInt value, @SuppressWarnings("unused") PNone novalue,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
BigInteger bValue = value.getValue();
raiseMathError(inliningTarget, doNotFit, bValue.compareTo(BigInteger.ZERO) < 0, raiseNode);
return logBigInteger(bValue);
@@ -1598,7 +1598,7 @@ static double logLL(long value, long base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return logDD(value, base, inliningTarget, doNotFit, divByZero, raiseNode);
}
@@ -1607,7 +1607,7 @@ static double logDL(double value, long base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return logDD(value, base, inliningTarget, doNotFit, divByZero, raiseNode);
}
@@ -1616,7 +1616,7 @@ static double logLD(long value, double base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return logDD(value, base, inliningTarget, doNotFit, divByZero, raiseNode);
}
@@ -1625,7 +1625,7 @@ static double logDD(double value, double base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseMathError(inliningTarget, doNotFit, value < 0 || base <= 0, raiseNode);
double logBase = countBase(base, inliningTarget, divByZero, raiseNode);
return Math.log(value) / logBase;
@@ -1637,7 +1637,7 @@ static double logDPI(double value, PInt base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
BigInteger bBase = base.getValue();
raiseMathError(inliningTarget, doNotFit, value < 0 || bBase.compareTo(BigInteger.ZERO) <= 0, raiseNode);
double logBase = countBase(bBase, inliningTarget, divByZero, raiseNode);
@@ -1649,7 +1649,7 @@ static double logPIL(PInt value, long base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return logPID(value, base, inliningTarget, doNotFit, divByZero, raiseNode);
}
@@ -1659,7 +1659,7 @@ static double logPID(PInt value, double base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
BigInteger bValue = value.getValue();
raiseMathError(inliningTarget, doNotFit, bValue.compareTo(BigInteger.ZERO) < 0 || base <= 0, raiseNode);
double logBase = countBase(base, inliningTarget, divByZero, raiseNode);
@@ -1672,7 +1672,7 @@ static double logLPI(long value, PInt base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
BigInteger bBase = base.getValue();
raiseMathError(inliningTarget, doNotFit, value < 0 || bBase.compareTo(BigInteger.ZERO) <= 0, raiseNode);
double logBase = countBase(bBase, inliningTarget, divByZero, raiseNode);
@@ -1685,7 +1685,7 @@ static double logPIPI(PInt value, PInt base,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile doNotFit,
@Shared @Cached InlinedConditionProfile divByZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
BigInteger bValue = value.getValue();
BigInteger bBase = base.getValue();
raiseMathError(inliningTarget, doNotFit, bValue.compareTo(BigInteger.ZERO) < 0 || bBase.compareTo(BigInteger.ZERO) <= 0, raiseNode);
@@ -1728,9 +1728,9 @@ static double logPIPI(PInt value, PInt base,
return executeRecursiveLogNode(frame, value, asDoubleNode.execute(frame, inliningTarget, base));
}
- private static void raiseMathError(Node inliningTarget, InlinedConditionProfile doNotFit, boolean con, PRaiseNode.Lazy raiseNode) {
+ private static void raiseMathError(Node inliningTarget, InlinedConditionProfile doNotFit, boolean con, PRaiseNode raiseNode) {
if (doNotFit.profile(inliningTarget, con)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
}
}
@@ -1750,7 +1750,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, Log1pNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
if (value == 0 || value == Double.POSITIVE_INFINITY || Double.isNaN(value)) {
return value;
}
@@ -1786,7 +1786,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, Log2Node::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(value <= 0, inliningTarget, raiseNode);
double[] frexpR = FrexpNode.frexp(value);
double m = frexpR[0];
@@ -1833,7 +1833,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, Log10Node::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
checkMathDomainError(value <= 0, inliningTarget, raiseNode);
return Math.log10(value);
}
@@ -1862,7 +1862,7 @@ public abstract static class PowNode extends PythonBinaryClinicBuiltinNode {
@Specialization
static double pow(double left, double right,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
double result = 0;
if (!Double.isFinite(left) || !Double.isFinite(right)) {
if (Double.isNaN(left)) {
@@ -1893,12 +1893,12 @@ static double pow(double left, double right,
result = Math.pow(left, right);
if (!Double.isFinite(result)) {
if (Double.isNaN(result)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
} else if (Double.isInfinite(result)) {
if (left == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MATH_DOMAIN_ERROR);
} else {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MATH_RANGE_ERROR);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MATH_RANGE_ERROR);
}
}
}
@@ -1920,10 +1920,10 @@ public abstract static class TruncNode extends PythonUnaryBuiltinNode {
static Object trunc(VirtualFrame frame, Object obj,
@Bind("this") Node inliningTarget,
@Cached("create(T___TRUNC__)") LookupAndCallUnaryNode callTrunc,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = callTrunc.executeObject(frame, obj);
if (result == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, obj, "__trunc__");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, obj, "__trunc__");
}
return result;
}
@@ -1957,7 +1957,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, DegreesNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return value * RAD_TO_DEG;
}
}
@@ -1974,7 +1974,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, RadiansNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
return value * DEG_TO_RAD;
}
}
@@ -1993,10 +1993,11 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
@Specialization(guards = "arguments.length == 2")
public double hypot2(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PyFloatAsDoubleNode xAsDouble,
@Exclusive @Cached PyFloatAsDoubleNode yAsDouble) {
if (keywords.length != 0) {
- throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "hypot()");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "hypot()");
}
double x = xAsDouble.execute(frame, inliningTarget, arguments[0]);
double y = yAsDouble.execute(frame, inliningTarget, arguments[1]);
@@ -2007,9 +2008,10 @@ public double hypot2(VirtualFrame frame, @SuppressWarnings("unused") Object self
@SuppressWarnings("truffle-static-method")
double hypotGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PyFloatAsDoubleNode asDoubleNode) {
if (keywords.length != 0) {
- throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "hypot()");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_TAKES_NO_KEYWORD_ARGS, "hypot()");
}
double max = 0.0;
boolean foundNan = false;
@@ -2114,7 +2116,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, ErfNode::compute);
}
- private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double value, PRaiseNode raiseNode) {
double absx, cf;
if (Double.isNaN(value)) {
@@ -2141,7 +2143,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, ErfcNode::compute);
}
- private static double compute(Node inliningTarget, double x, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double x, PRaiseNode raiseNode) {
double absx, cf;
if (Double.isNaN(x)) {
@@ -2261,7 +2263,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, GammaNode::compute);
}
- private static double compute(Node inliningTarget, double x, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double x, PRaiseNode raiseNode) {
double absx, r, y, z, sqrtpow;
/* special cases */
@@ -2354,7 +2356,7 @@ static double doGeneric(VirtualFrame frame, Object value,
return helperNode.execute(frame, inliningTarget, value, LgammaNode::compute);
}
- private static double compute(Node inliningTarget, double x, PRaiseNode.Lazy raiseNode) {
+ private static double compute(Node inliningTarget, double x, PRaiseNode raiseNode) {
double r;
double absx;
@@ -2407,7 +2409,7 @@ public abstract static class IsqrtNode extends PythonUnaryBuiltinNode {
static Object isqrtLong(long x,
@Bind("this") Node inliningTarget,
@Shared @Cached NarrowBigIntegerNode makeInt,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseIfNegative(inliningTarget, x < 0, raiseNode);
return makeInt.execute(inliningTarget, op(PInt.longToBigInteger(x)));
}
@@ -2416,7 +2418,7 @@ static Object isqrtLong(long x,
static Object isqrtPInt(PInt x,
@Bind("this") Node inliningTarget,
@Shared @Cached NarrowBigIntegerNode makeInt,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseIfNegative(inliningTarget, x.isNegative(), raiseNode);
return makeInt.execute(inliningTarget, op(x.getValue()));
}
@@ -2455,9 +2457,9 @@ private static BigInteger op(BigInteger x) {
return result;
}
- private static void raiseIfNegative(Node inliningTarget, boolean condition, PRaiseNode.Lazy raiseNode) {
+ private static void raiseIfNegative(Node inliningTarget, boolean condition, PRaiseNode raiseNode) {
if (condition) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE, "isqrt() argument");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE, "isqrt() argument");
}
}
}
@@ -2506,13 +2508,13 @@ static double doGeneric(VirtualFrame frame, Object p, Object q,
@Cached InlinedConditionProfile infProfile,
@Cached InlinedConditionProfile nanProfile,
@Cached InlinedConditionProfile trivialProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// adapted from CPython math_dist_impl and vector_norm
Object[] ps = getObjectArray.execute(inliningTarget, tupleCtor.execute(frame, p));
Object[] qs = getObjectArray.execute(inliningTarget, tupleCtor.execute(frame, q));
int len = ps.length;
if (len != qs.length) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BOTH_POINTS_MUST_HAVE_THE_SAME_NUMBER_OF_DIMENSIONS);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BOTH_POINTS_MUST_HAVE_THE_SAME_NUMBER_OF_DIMENSIONS);
}
double[] diffs = new double[len];
double max = 0.0;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
index 5a0322e8dc..d4ac204674 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
@@ -142,14 +142,14 @@ static boolean compare(VirtualFrame frame, Object left, Object right,
@Cached CastToJavaStringNode cast,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
String leftString = cast.execute(left);
String rightString = cast.execute(right);
return tscmp(leftString, rightString);
} catch (CannotCastException e) {
if (!bufferAcquireLib.hasBuffer(left) || !bufferAcquireLib.hasBuffer(right)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_OR_COMBINATION_OF_TYPES, left, right);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_OR_COMBINATION_OF_TYPES, left, right);
}
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
Object leftBuffer = bufferAcquireLib.acquireReadonly(left);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
index 2310c287c7..e5ed3dad0c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
@@ -205,7 +205,7 @@ Object importSymbol(TruffleString name,
@Cached PForeignToPTypeNode convert) {
Env env = getContext().getEnv();
if (!env.isPolyglotBindingsAccessAllowed()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
Object object = env.importSymbol(name.toJavaStringUncached());
if (object == null) {
@@ -222,19 +222,19 @@ abstract static class EvalInteropNode extends PythonTernaryBuiltinNode {
@Specialization
Object eval(Object pathObj, Object stringObj, Object languageObj) {
if (languageObj instanceof PNone) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.POLYGLOT_EVAL_MUST_PASS_LANG_AND_STRING_OR_PATH);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.POLYGLOT_EVAL_MUST_PASS_LANG_AND_STRING_OR_PATH);
}
boolean hasString = !(stringObj instanceof PNone);
boolean hasPath = !(pathObj instanceof PNone);
if (!hasString && !hasPath || hasString && hasPath) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.POLYGLOT_EVAL_MUST_PASS_LANG_AND_STRING_OR_PATH);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.POLYGLOT_EVAL_MUST_PASS_LANG_AND_STRING_OR_PATH);
}
String languageName = toJavaString(languageObj, "language");
String string = hasString ? toJavaString(stringObj, "string") : null;
String path = hasPath ? toJavaString(pathObj, "path") : null;
Env env = getContext().getEnv();
if (!env.isPolyglotEvalAllowed(null)) {
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
Map languages = env.getPublicLanguages();
String mimeType = null;
@@ -244,10 +244,10 @@ Object eval(Object pathObj, Object stringObj, Object languageObj) {
}
LanguageInfo language = languages.get(languageName);
if (language == null) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.POLYGLOT_LANGUAGE_S_NOT_FOUND, languageName);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.POLYGLOT_LANGUAGE_S_NOT_FOUND, languageName);
}
if (!env.isPolyglotEvalAllowed(language)) {
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED_FOR_LANGUAGE_S, languageName);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED_FOR_LANGUAGE_S, languageName);
}
try {
SourceBuilder builder;
@@ -264,9 +264,9 @@ Object eval(Object pathObj, Object stringObj, Object languageObj) {
} catch (AbstractTruffleException e) {
throw e;
} catch (IOException e) {
- throw PRaiseNode.raiseUncached(this, OSError, ErrorMessages.S, e);
+ throw PRaiseNode.raiseStatic(this, OSError, ErrorMessages.S, e);
} catch (RuntimeException e) {
- throw PRaiseNode.raiseUncached(this, RuntimeError, e);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, e);
}
}
@@ -274,7 +274,7 @@ private String toJavaString(Object object, String parameterName) {
try {
return CastToJavaStringNode.getUncached().execute(object);
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.S_BRACKETS_ARG_S_MUST_BE_S_NOT_P, "polyglot.eval", parameterName, "str", object);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.S_BRACKETS_ARG_S_MUST_BE_S_NOT_P, "polyglot.eval", parameterName, "str", object);
}
}
@@ -304,7 +304,7 @@ public abstract static class ExportSymbolNode extends PythonBuiltinNode {
Object exportSymbolKeyValue(TruffleString name, Object value) {
Env env = getContext().getEnv();
if (!env.isPolyglotBindingsAccessAllowed()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
env.exportSymbol(name.toJavaStringUncached(), value);
return value;
@@ -332,7 +332,7 @@ Object exportSymbolAmbiguous(Object arg1, TruffleString arg2) {
Object exportSymbol(PFunction fun, @SuppressWarnings("unused") PNone name) {
Env env = getContext().getEnv();
if (!env.isPolyglotBindingsAccessAllowed()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
env.exportSymbol(fun.getName().toJavaStringUncached(), fun);
return fun;
@@ -343,7 +343,7 @@ Object exportSymbol(PFunction fun, @SuppressWarnings("unused") PNone name) {
Object exportSymbol(PBuiltinFunction fun, @SuppressWarnings("unused") PNone name) {
Env env = getContext().getEnv();
if (!env.isPolyglotBindingsAccessAllowed()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
env.exportSymbol(fun.getName().toJavaStringUncached(), fun);
return fun;
@@ -354,13 +354,13 @@ static Object exportSymbol(VirtualFrame frame, Object fun, @SuppressWarnings("un
@Bind("this") Node inliningTarget,
@Cached("create(T___NAME__)") GetAttributeNode.GetFixedAttributeNode getNameAttributeNode,
@Cached CastToJavaStringNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object attrNameValue = getNameAttributeNode.executeObject(frame, fun);
String methodName;
try {
methodName = castToStringNode.execute(attrNameValue);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.METHOD_NAME_MUST_BE, attrNameValue);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.METHOD_NAME_MUST_BE, attrNameValue);
}
export(inliningTarget, methodName, fun);
return fun;
@@ -368,8 +368,8 @@ static Object exportSymbol(VirtualFrame frame, Object fun, @SuppressWarnings("un
@Fallback
static Object exportSymbol(Object value, Object name,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_ARG_TYPES_S_S_BUT_NOT_P_P, "function", "object, str", value, name);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_ARG_TYPES_S_S_BUT_NOT_P_P, "function", "object, str", value, name);
}
protected static boolean isModuleMethod(Object o) {
@@ -380,7 +380,7 @@ protected static boolean isModuleMethod(Object o) {
private static void export(Node raisingNode, String name, Object obj) {
Env env = PythonContext.get(raisingNode).getEnv();
if (!env.isPolyglotBindingsAccessAllowed()) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
+ throw PRaiseNode.raiseStatic(raisingNode, PythonErrorType.NotImplementedError, ErrorMessages.POLYGLOT_ACCESS_NOT_ALLOWED);
}
env.exportSymbol(name, obj);
}
@@ -407,8 +407,8 @@ static boolean isWhole(double number) {
@Specialization(guards = {"!isSupportedNumber(number)"})
static boolean unsupported(PythonAbstractObject number,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ARG_MUST_BE_NUMBER, "given", number);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ARG_MUST_BE_NUMBER, "given", number);
}
}
@@ -642,7 +642,7 @@ PList get(PythonAbstractObject klass,
}
return PFactory.createList(language);
}
- throw raiseNode.raise(ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a type", klass);
+ throw raiseNode.raise(inliningTarget, ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a type", klass);
}
}
@@ -686,17 +686,17 @@ void handleArg(Object value, InteropBehaviorMethod method, InteropBehavior inter
Signature signature = function.getCode().getSignature();
// validate the function
if (function.getKwDefaults().length != 0) {
- throw raiseNode.raise(ValueError, S_TAKES_NO_KEYWORD_ARGS, method.name);
+ throw raiseNode.raise(this, ValueError, S_TAKES_NO_KEYWORD_ARGS, method.name);
} else if (function.getCode().getCellVars().length != 0) {
- throw raiseNode.raise(ValueError, S_CANNOT_HAVE_S, method.name, "cell vars");
+ throw raiseNode.raise(this, ValueError, S_CANNOT_HAVE_S, method.name, "cell vars");
} else if (function.getCode().getFreeVars().length != 0) {
- throw raiseNode.raise(ValueError, S_CANNOT_HAVE_S, method.name, "free vars");
+ throw raiseNode.raise(this, ValueError, S_CANNOT_HAVE_S, method.name, "free vars");
} else {
// check signature
if (method.takesVarArgs != signature.takesVarArgs()) {
- throw raiseNode.raise(ValueError, method.takesVarArgs ? S_TAKES_VARARGS : S_DOES_NOT_TAKE_VARARGS, method.name);
+ throw raiseNode.raise(this, ValueError, method.takesVarArgs ? S_TAKES_VARARGS : S_DOES_NOT_TAKE_VARARGS, method.name);
} else if (signature.getMaxNumOfPositionalArgs() != method.getNumPositionalArguments()) {
- throw raiseNode.raise(ValueError, S_TAKES_EXACTLY_D_ARGS, method.name, method.getNumPositionalArguments(), signature.getMaxNumOfPositionalArgs());
+ throw raiseNode.raise(this, ValueError, S_TAKES_EXACTLY_D_ARGS, method.name, method.getNumPositionalArguments(), signature.getMaxNumOfPositionalArgs());
}
}
}
@@ -777,7 +777,7 @@ Object register(PythonAbstractObject receiver, Object is_boolean, Object is_date
HiddenAttr.WriteNode.executeUncached(receiver, HiddenAttr.HOST_INTEROP_BEHAVIOR, interopBehavior);
return PNone.NONE;
}
- throw raiseNode.raise(ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a type", receiver);
+ throw raiseNode.raise(inliningTarget, ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a type", receiver);
}
}
@@ -837,10 +837,10 @@ Object register(Object foreignClass, PythonClass pythonClass, boolean allowMetho
@Cached ObjectHashMap.PutNode putNode,
@Cached ObjectHashMap.GetNode getNode,
@Cached PRaiseNode raiseNode) {
- foreignClass = checkAndCleanForeignClass(foreignClass, interopLibrary, raiseNode, getContext().getEnv());
+ foreignClass = checkAndCleanForeignClass(inliningTarget, foreignClass, interopLibrary, raiseNode, getContext().getEnv());
if (!isClassTypeNode.execute(inliningTarget, pythonClass)) {
- throw raiseNode.raise(ValueError, S_ARG_MUST_BE_S_NOT_P, "second", "a python class", pythonClass);
+ throw raiseNode.raise(inliningTarget, ValueError, S_ARG_MUST_BE_S_NOT_P, "second", "a python class", pythonClass);
}
// Contains foreignClasses as keys and PythonClass[] as values
ObjectHashMap interopTypeRegistry = getContext().interopTypeRegistry;
@@ -857,11 +857,11 @@ Object register(Object foreignClass, PythonClass pythonClass, boolean allowMetho
// found one or more classes for the key, insert the new class in at first place
// The logic for the class lookup should be LIFO
if (checkIfAlreadyRegistered(pythonClass, registeredClasses, interopLibrary)) {
- throw raiseNode.raise(KeyError, INTEROP_TYPE_ALREADY_REGISTERED, interopLibrary.getMetaQualifiedName(foreignClass));
+ throw raiseNode.raise(inliningTarget, KeyError, INTEROP_TYPE_ALREADY_REGISTERED, interopLibrary.getMetaQualifiedName(foreignClass));
}
if (!allowMethodOverwrites) {
// method overwrite not allowed, check if there is a conflict
- checkForMethodConflict(pythonClass, registeredClasses, raiseNode);
+ checkForMethodConflict(inliningTarget, pythonClass, registeredClasses, raiseNode);
}
var newClasses = new PythonManagedClass[registeredClasses.length + 1];
newClasses[0] = pythonClass;
@@ -889,21 +889,21 @@ private static boolean checkIfAlreadyRegistered(PythonManagedClass pythonManaged
return false;
}
- private static void checkForMethodConflict(PythonManagedClass toCheck, PythonManagedClass[] registeredClasses, PRaiseNode raiseNode) {
+ private static void checkForMethodConflict(Node inliningTarget, PythonManagedClass toCheck, PythonManagedClass[] registeredClasses, PRaiseNode raiseNode) {
for (TruffleString name : toCheck.getAttributeNames()) {
if (toCheck.getAttribute(name) instanceof PFunction) {
for (PythonManagedClass registeredClass : registeredClasses) {
if (registeredClass.getAttribute(name) instanceof PFunction) {
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, INTEROP_TYPE_NOT_MERGABLE, toCheck, registeredClass, name);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, INTEROP_TYPE_NOT_MERGABLE, toCheck, registeredClass, name);
}
}
}
}
}
- private static Object checkAndCleanForeignClass(Object object, InteropLibrary interopLibrary, PRaiseNode raiseNode, Env env) {
+ private static Object checkAndCleanForeignClass(Node inliningTarget, Object object, InteropLibrary interopLibrary, PRaiseNode raiseNode, Env env) {
if (!interopLibrary.isMetaObject(object)) {
- throw raiseNode.raise(ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a class or interface", object);
+ throw raiseNode.raise(inliningTarget, ValueError, S_ARG_MUST_BE_S_NOT_P, "first", "a class or interface", object);
}
if (!env.isHostObject(object)) {
return object;
@@ -944,10 +944,10 @@ Object read(Object receiver, Object key) {
} else if (key instanceof Number) {
return getInterop().readArrayElement(receiver, ((Number) key).longValue());
} else {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
}
} catch (UnknownIdentifierException | UnsupportedMessageException | InvalidArrayIndexException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, e);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, e);
}
}
}
@@ -966,10 +966,10 @@ Object write(Object receiver, Object key, Object value) {
} else if (key instanceof Number) {
getInterop().writeArrayElement(receiver, ((Number) key).longValue(), value);
} else {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
}
} catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | InvalidArrayIndexException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, e);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, e);
}
return PNone.NONE;
}
@@ -989,10 +989,10 @@ Object remove(Object receiver, Object key) {
} else if (key instanceof Number) {
getInterop().removeArrayElement(receiver, ((Number) key).longValue());
} else {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, ErrorMessages.UNKNOWN_ATTR, key);
}
} catch (UnknownIdentifierException | UnsupportedMessageException | InvalidArrayIndexException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.AttributeError, e);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.AttributeError, e);
}
return PNone.NONE;
}
@@ -1004,11 +1004,11 @@ public abstract static class executeNode extends PythonBuiltinNode {
@Specialization
static Object exec(Object receiver, Object[] arguments,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return getInterop().execute(receiver, arguments);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.AttributeError, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.AttributeError, e);
}
}
}
@@ -1019,11 +1019,11 @@ public abstract static class newNode extends PythonBuiltinNode {
@Specialization
static Object instantiate(Object receiver, Object[] arguments,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return getInterop().instantiate(receiver, arguments);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.AttributeError, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.AttributeError, e);
}
}
}
@@ -1035,11 +1035,11 @@ public abstract static class invokeNode extends PythonBuiltinNode {
static Object invoke(Object receiver, TruffleString key, Object[] arguments,
@Bind("this") Node inliningTarget,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return getInterop().invokeMember(receiver, toJavaStringNode.execute(key), arguments);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownIdentifierException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.AttributeError, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.AttributeError, e);
}
}
}
@@ -1068,11 +1068,11 @@ public abstract static class GetSizeNode extends PythonBuiltinNode {
@Specialization
static Object getSize(Object receiver,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return getInterop().getArraySize(receiver);
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, e);
}
}
}
@@ -1135,11 +1135,11 @@ public abstract static class KeysNode extends PythonBuiltinNode {
@Specialization
static Object remove(Object receiver,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return getInterop().getMembers(receiver);
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, e);
}
}
}
@@ -1184,15 +1184,15 @@ static Object doSequence(PSequence seq,
} else if (storage instanceof ArrayBasedSequenceStorage basicStorage) {
arrayObject = basicStorage.getInternalArrayObject();
} else {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.NotImplementedError, ErrorMessages.GETTING_POLYGLOT_STORAGE_FOR_NATIVE_STORAGE_NOT_IMPLEMENTED);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError, ErrorMessages.GETTING_POLYGLOT_STORAGE_FOR_NATIVE_STORAGE_NOT_IMPLEMENTED);
}
return PythonContext.get(inliningTarget).getEnv().asGuestValue(arrayObject);
}
@Fallback
static Object doError(Object object,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_P, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_P, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
index 1855f6b7cc..c49b42d59b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
@@ -450,7 +450,7 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes, PBytes valueBytes,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// Unlike in other posix builtins, we go through str -> bytes -> byte[] -> String
// conversions for emulated backend because the bytes version after fsencode conversion
// is subject to sys.audit.
@@ -469,17 +469,17 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes, PBytes valueBytes,
return PNone.NONE;
}
- private static Object checkNull(Node inliningTarget, Object value, PRaiseNode.Lazy raiseNode) {
+ private static Object checkNull(Node inliningTarget, Object value, PRaiseNode raiseNode) {
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
return value;
}
- private static void checkEqualSign(Node inliningTarget, byte[] bytes, PRaiseNode.Lazy raiseNode) {
+ private static void checkEqualSign(Node inliningTarget, byte[] bytes, PRaiseNode raiseNode) {
for (byte b : bytes) {
if (b == '=') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ILLEGAL_ENVIRONMENT_VARIABLE_NAME);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ILLEGAL_ENVIRONMENT_VARIABLE_NAME);
}
}
}
@@ -503,7 +503,7 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes,
@Cached SysModuleBuiltins.AuditNode auditNode,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] name = toBytesNode.execute(nameBytes);
Object nameOpaque = checkNull(inliningTarget, posixLib.createPathFromBytes(context.getPosixSupport(), name), raiseNode);
auditNode.audit(inliningTarget, "os.unsetenv", nameBytes);
@@ -515,9 +515,9 @@ static PNone putenv(VirtualFrame frame, PBytes nameBytes,
return PNone.NONE;
}
- private static Object checkNull(Node inliningTarget, Object value, PRaiseNode.Lazy raiseNode) {
+ private static Object checkNull(Node inliningTarget, Object value, PRaiseNode raiseNode) {
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
return value;
}
@@ -543,7 +543,7 @@ static Object execvArgsList(VirtualFrame frame, PosixPath path, PList argv,
@Shared @Cached SysModuleBuiltins.AuditNode auditNode,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, context.getPosixSupport(), toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
throw CompilerDirectives.shouldNotReachHere("execv should not return normally");
}
@@ -558,7 +558,7 @@ static Object execvArgsTuple(VirtualFrame frame, PosixPath path, PTuple argv,
@Shared @Cached AuditNode auditNode,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
execv(frame, path, argv, argv.getSequenceStorage(), inliningTarget, posixLib, context.getPosixSupport(), toArrayNode, toOpaquePathNode, auditNode, gil, constructAndRaiseNode, raiseNode);
throw CompilerDirectives.shouldNotReachHere("execv should not return normally");
}
@@ -566,8 +566,8 @@ static Object execvArgsTuple(VirtualFrame frame, PosixPath path, PTuple argv,
@Specialization(guards = {"!isList(argv)", "!isPTuple(argv)"})
@SuppressWarnings("unused")
static Object execvInvalidArgs(VirtualFrame frame, PosixPath path, Object argv,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S, "execv()", 2, "tuple or list");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ARG_D_MUST_BE_S, "execv()", 2, "tuple or list");
}
private static void execv(VirtualFrame frame, PosixPath path, Object argv, SequenceStorage argvStorage,
@@ -579,10 +579,10 @@ private static void execv(VirtualFrame frame, PosixPath path, Object argv, Seque
SysModuleBuiltins.AuditNode auditNode,
GilNode gil,
PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object[] args = toArrayNode.execute(inliningTarget, argvStorage);
if (args.length < 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ARG_MUST_NOT_BE_EMPTY, "execv()", 2);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ARG_MUST_NOT_BE_EMPTY, "execv()", 2);
}
Object[] opaqueArgs = new Object[args.length];
for (int i = 0; i < args.length; ++i) {
@@ -686,7 +686,7 @@ static PTuple getloadavg(@Bind("this") Node inliningTarget,
load = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
}
if (load < 0) {
- PRaiseNode.raiseUncached(inliningTarget, OSError);
+ PRaiseNode.raiseStatic(inliningTarget, OSError);
}
return PFactory.createTuple(language, new Object[]{load, load, load});
}
@@ -1447,15 +1447,15 @@ static PTuple doStatPath(VirtualFrame frame, PosixPath path, int dirFd, boolean
@Specialization(guards = "!isDefault(dirFd)")
@SuppressWarnings("unused")
static PTuple doStatFdWithDirFd(PosixFd fd, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANT_SPECIFY_DIRFD_WITHOUT_PATH, "stat");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANT_SPECIFY_DIRFD_WITHOUT_PATH, "stat");
}
@Specialization(guards = {"isDefault(dirFd)", "!followSymlinks"})
@SuppressWarnings("unused")
static PTuple doStatFdWithFollowSymlinks(VirtualFrame frame, PosixFd fd, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "stat");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "stat");
}
@Specialization(guards = {"isDefault(dirFd)", "followSymlinks"})
@@ -1920,8 +1920,8 @@ abstract static class ScandirIteratorNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object scandirIterator(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "posix.ScandirIterator");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "posix.ScandirIterator");
}
}
@@ -1931,8 +1931,8 @@ abstract static class DirEntryNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object dirEntry(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "posix.DirEntry");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "posix.DirEntry");
}
}
@@ -2093,7 +2093,7 @@ static long[] times(VirtualFrame frame, PTuple times, @SuppressWarnings("unused"
@Exclusive @Cached LenNode lenNode,
@Shared @Cached("createNotNormalized()") GetItemNode getItemNode,
@Cached ObjectToTimespecNode objectToTimespecNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return convertToTimespec(frame, inliningTarget, times, lenNode, getItemNode, objectToTimespecNode, raiseNode);
}
@@ -2103,42 +2103,43 @@ static long[] ns(VirtualFrame frame, @SuppressWarnings("unused") PNone times, PT
@Exclusive @Cached LenNode lenNode,
@Shared @Cached("createNotNormalized()") GetItemNode getItemNode,
@Cached SplitLongToSAndNsNode splitLongToSAndNsNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return convertToTimespec(frame, inliningTarget, ns, lenNode, getItemNode, splitLongToSAndNsNode, raiseNode);
}
@Specialization(guards = {"!isPNone(times)", "!isNoValue(ns)"})
@SuppressWarnings("unused")
static long[] bothSpecified(VirtualFrame frame, Object times, Object ns,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.YOU_MAY_SPECIFY_EITHER_OR_BUT_NOT_BOTH, "utime", "times", "ns");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.YOU_MAY_SPECIFY_EITHER_OR_BUT_NOT_BOTH, "utime", "times", "ns");
}
@Specialization(guards = {"!isPNone(times)", "!isPTuple(times)", "isNoValue(ns)"})
@SuppressWarnings("unused")
static long[] timesNotATuple(VirtualFrame frame, Object times, PNone ns,
- @Shared @Cached PRaiseNode raiseNode) {
- throw timesTupleError(raiseNode);
+ @Bind("this") Node inliningTarget,
+ @Cached PRaiseNode raiseNode) {
+ throw timesTupleError(inliningTarget, raiseNode);
}
@Specialization(guards = {"!isNoValue(ns)", "!isPTuple(ns)"})
@SuppressWarnings("unused")
static long[] nsNotATuple(VirtualFrame frame, PNone times, Object ns,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// ns can actually also contain objects implementing __divmod__, but CPython produces
// this error message
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE, "utime", "ns", "a tuple of two ints");
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE, "utime", "ns", "a tuple of two ints");
}
- private static PException timesTupleError(PRaiseNode raiseNode) {
+ private static PException timesTupleError(Node inliningTarget, PRaiseNode raiseNode) {
// times can actually also contain floats, but CPython produces this error message
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_EITHER_OR, "utime", "times", "a tuple of two ints", "None");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_EITHER_OR, "utime", "times", "a tuple of two ints", "None");
}
private static long[] convertToTimespec(VirtualFrame frame, Node inliningTarget, PTuple times, LenNode lenNode, GetItemNode getItemNode, ConvertToTimespecBaseNode convertToTimespecBaseNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (lenNode.execute(inliningTarget, times) != 2) {
- throw timesTupleError(raiseNode.get(inliningTarget));
+ throw timesTupleError(inliningTarget, raiseNode);
}
long[] timespec = new long[4];
convertToTimespecBaseNode.execute(frame, inliningTarget, getItemNode.execute(times.getSequenceStorage(), 0), timespec, 0);
@@ -2224,15 +2225,15 @@ static PNone lutimes(VirtualFrame frame, PosixPath path, Object times, Object ns
@Specialization(guards = {"!HAVE_UTIMENSAT.value", "!isDefault(dirFd)", "followSymlinks"})
@SuppressWarnings("unused")
static PNone dirFdNotSupported(VirtualFrame frame, PosixPath path, Object times, Object ns, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, ErrorMessages.UNAVAILABLE_ON_THIS_PLATFORM_NO_FUNC, "dir_fd");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.UNAVAILABLE_ON_THIS_PLATFORM_NO_FUNC, "dir_fd");
}
@Specialization(guards = {"!HAVE_UTIMENSAT.value", "!isDefault(dirFd)", "!followSymlinks"})
@SuppressWarnings("unused")
static PNone dirFdAndFollowSymlinksNotSupported(VirtualFrame frame, PosixPath path, Object times, Object ns, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.UTIME_CANNOT_USE_DIR_FD_AND_FOLLOW_SYMLINKS, "dir_fd");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.UTIME_CANNOT_USE_DIR_FD_AND_FOLLOW_SYMLINKS, "dir_fd");
}
@Specialization(guards = {"HAVE_FUTIMENS.value", "isDefault(dirFd)", "followSymlinks"})
@@ -2276,15 +2277,15 @@ static PNone futimes(VirtualFrame frame, PosixFd fd, Object times, Object ns, in
@Specialization(guards = {"isPNone(times) || isNoValue(ns)", "!isDefault(dirFd)"})
@SuppressWarnings("unused")
static PNone fdWithDirFd(VirtualFrame frame, PosixFd fd, Object times, Object ns, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANT_SPECIFY_DIRFD_WITHOUT_PATH, "utime");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANT_SPECIFY_DIRFD_WITHOUT_PATH, "utime");
}
@Specialization(guards = {"isPNone(times) || isNoValue(ns)", "isDefault(dirFd)", "!followSymlinks"})
@SuppressWarnings("unused")
static PNone fdWithFollowSymlinks(VirtualFrame frame, PosixFd fd, Object times, Object ns, int dirFd, boolean followSymlinks,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "utime");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "utime");
}
protected static boolean isDefault(int dirFd) {
@@ -2408,7 +2409,7 @@ static PNone chmodFollow(VirtualFrame frame, PosixPath path, int mode, int dirFd
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
auditNode.audit(inliningTarget, "os.chmod", path.originalObject, mode, dirFdForAudit(dirFd));
try {
posixLib.fchmodat(context.getPosixSupport(), dirFd, path.value, mode, followSymlinks);
@@ -2416,9 +2417,9 @@ static PNone chmodFollow(VirtualFrame frame, PosixPath path, int mode, int dirFd
// TODO CPython checks for ENOTSUP as well
if (e.getErrorCode() == OSErrorEnum.EOPNOTSUPP.getNumber() && !followSymlinks) {
if (dirFd != AT_FDCWD.value) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "chmod");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "chmod");
} else {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.UNAVAILABLE_ON_THIS_PLATFORM, "chmod", "follow_symlinks");
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.UNAVAILABLE_ON_THIS_PLATFORM, "chmod", "follow_symlinks");
}
}
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e, path.originalObject);
@@ -2434,7 +2435,7 @@ static PNone chmodFollow(VirtualFrame frame, PosixFd fd, int mode, int dirFd, @S
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
// unused node to avoid mixing shared and non-shared inlined nodes
- @SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @SuppressWarnings("unused") @Shared @Cached PRaiseNode raiseNode) {
auditNode.audit(inliningTarget, "os.chmod", fd.originalObject, mode, dirFdForAudit(dirFd));
// Unlike stat and utime which raise CANT_SPECIFY_DIRFD_WITHOUT_PATH or
// CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER when an inappropriate combination of
@@ -2534,7 +2535,7 @@ static Object chown(VirtualFrame frame, PosixPath path, long uid, long gid, int
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
// unused node to avoid mixing shared and non-shared inlined nodes
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
auditNode.audit(inliningTarget, "os.chown", path.originalObject, uid, gid, dirFd != AT_FDCWD.value ? dirFd : -1);
try {
gil.release(true);
@@ -2557,12 +2558,12 @@ static Object chown(VirtualFrame frame, PosixFd fd, long uid, long gid, int dirF
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Shared @Cached GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (dirFd != AT_FDCWD.value) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANT_SPECIFY_BOTH_DIR_FD_AND_FD);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANT_SPECIFY_BOTH_DIR_FD_AND_FD);
}
if (followSymlinks) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "chown");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_USE_FD_AND_FOLLOW_SYMLINKS_TOGETHER, "chown");
}
auditNode.audit(inliningTarget, "os.chown", fd.originalObject, uid, gid, -1);
try {
@@ -2719,28 +2720,28 @@ static int waitstatusToExitcode(VirtualFrame frame, Object statusObj,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Bind("this") Node inliningTarget,
@Cached PyLongAsIntNode longAsInt,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int status = longAsInt.execute(frame, inliningTarget, statusObj);
PosixSupport posixSupport = context.getPosixSupport();
if (posixLib.wifexited(posixSupport, status)) {
int exitcode = posixLib.wexitstatus(posixSupport, status);
if (exitcode < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WEXITSTATUS, exitcode);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WEXITSTATUS, exitcode);
}
return exitcode;
}
if (posixLib.wifsignaled(posixSupport, status)) {
int signum = posixLib.wtermsig(posixSupport, status);
if (signum <= 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WTERMSIG, signum);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WTERMSIG, signum);
}
return -signum;
}
if (posixLib.wifstopped(posixSupport, status)) {
int signum = posixLib.wstopsig(posixSupport, status);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.PROCESS_STOPPED_BY_DELIVERY_OF_SIGNAL, signum);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.PROCESS_STOPPED_BY_DELIVERY_OF_SIGNAL, signum);
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WAIT_STATUS, status);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_WAIT_STATUS, status);
}
}
@@ -2928,8 +2929,8 @@ static PBytes urandom(int size,
@Specialization(guards = "size < 0")
static Object urandomNeg(@SuppressWarnings("unused") int size,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.NEG_ARG_NOT_ALLOWED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.NEG_ARG_NOT_ALLOWED);
}
@TruffleBoundary
@@ -2975,7 +2976,7 @@ static int sysconf(VirtualFrame frame, Object arg,
@Cached PyLongAsIntNode asIntNode,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached HashingStorageNodes.HashingStorageGetItem getItem,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
int id;
if (longCheckNode.execute(inliningTarget, arg)) {
@@ -2985,10 +2986,10 @@ static int sysconf(VirtualFrame frame, Object arg,
if (idObj instanceof Integer idInt) {
id = idInt;
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNRECOGNIZED_CONF_NAME);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNRECOGNIZED_CONF_NAME);
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CONFIGURATION_NAMES_MUST_BE_STRINGS_OR_INTEGERS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CONFIGURATION_NAMES_MUST_BE_STRINGS_OR_INTEGERS);
}
if (id == SC_CLK_TCK) {
return 100; // it's 100 on most default kernel configs. TODO: use real value through
@@ -3169,7 +3170,7 @@ static Object doString(Node inliningTarget, Object strObj,
@Cached CastToTruffleStringNode castToStringNode,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString str = castToStringNode.execute(inliningTarget, strObj);
return checkPath(inliningTarget, posixLib.createPathFromString(context.getPosixSupport(), str), raiseNode);
}
@@ -3179,13 +3180,13 @@ static Object doBytes(Node inliningTarget, PBytes bytes,
@Cached(inline = false) BytesNodes.ToBytesNode toBytesNode,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return checkPath(inliningTarget, posixLib.createPathFromBytes(context.getPosixSupport(), toBytesNode.execute(bytes)), raiseNode);
}
- private static Object checkPath(Node inliningTarget, Object path, PRaiseNode.Lazy raiseNode) {
+ private static Object checkPath(Node inliningTarget, Object path, PRaiseNode raiseNode) {
if (path == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
return path;
}
@@ -3212,10 +3213,10 @@ static Object withCheck(VirtualFrame frame, Node inliningTarget, Object obj, @Su
@Exclusive @Cached PyOSFSPathNode fspathNode,
@Cached PyObjectSizeNode sizeNode,
@Exclusive @Cached StringOrBytesToOpaquePathNode stringOrBytesToOpaquePathNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object stringOrBytes = fspathNode.execute(frame, inliningTarget, obj);
if (sizeNode.execute(frame, inliningTarget, obj) == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EXECV_ARG2_FIRST_ELEMENT_CANNOT_BE_EMPTY);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EXECV_ARG2_FIRST_ELEMENT_CANNOT_BE_EMPTY);
}
return stringOrBytesToOpaquePathNode.execute(inliningTarget, stringOrBytes);
}
@@ -3235,9 +3236,9 @@ abstract static class ObjectToTimespecNode extends ConvertToTimespecBaseNode {
@Specialization
static void doDouble(Node inliningTarget, double value, long[] timespec, int offset,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (Double.isNaN(value)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_VALUE_NAN);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_VALUE_NAN);
}
double denominator = 1000000000.0;
@@ -3254,7 +3255,7 @@ static void doDouble(Node inliningTarget, double value, long[] timespec, int off
}
assert 0.0 <= floatPart && floatPart < denominator;
if (!MathGuards.fitLong(intPart)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.TIMESTAMP_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.TIMESTAMP_OUT_OF_RANGE);
}
timespec[offset] = (long) intPart;
timespec[offset + 1] = (long) floatPart;
@@ -3263,7 +3264,7 @@ static void doDouble(Node inliningTarget, double value, long[] timespec, int off
@Specialization
static void doPFloat(Node inliningTarget, PFloat obj, long[] timespec, int offset,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
doDouble(inliningTarget, obj.getValue(), timespec, offset, raiseNode);
}
@@ -3282,11 +3283,11 @@ static void doLong(long value, long[] timespec, int offset) {
@Specialization(guards = {"!isDouble(value)", "!isPFloat(value)", "!isInteger(value)"})
static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, long[] timespec, int offset,
@Cached PyLongAsLongAndOverflowNode asLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
timespec[offset] = asLongNode.execute(frame, inliningTarget, value);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.TIMESTAMP_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.TIMESTAMP_OUT_OF_RANGE);
}
timespec[offset + 1] = 0;
}
@@ -3319,10 +3320,10 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, lon
@Cached LenNode lenNode,
@Cached(value = "createNotNormalized()", inline = false) GetItemNode getItemNode,
@Cached PyLongAsLongNode asLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object divmod = callDivmod.executeObject(frame, value, BILLION);
if (!PGuards.isPTuple(divmod) || lenNode.execute(inliningTarget, (PSequence) divmod) != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod);
}
SequenceStorage storage = ((PTuple) divmod).getSequenceStorage();
timespec[offset] = asLongNode.execute(frame, inliningTarget, getItemNode.execute(storage, 0));
@@ -3411,7 +3412,7 @@ static int doFdInt(int value) {
@Specialization
static int doFdLong(long value,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return longToFd(inliningTarget, value, raiseNode);
}
@@ -3420,7 +3421,7 @@ static int doFdLong(long value,
static int doFdPInt(PInt value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached CastToJavaLongLossyNode castToLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return doFdLong(castToLongNode.execute(inliningTarget, value), inliningTarget, raiseNode);
}
@@ -3431,21 +3432,21 @@ static int doIndex(VirtualFrame frame, Object value,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberIndexNode indexNode,
@Exclusive @Cached CastToJavaLongLossyNode castToLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, value)) {
Object o = indexNode.execute(frame, inliningTarget, value);
return doFdLong(castToLongNode.execute(inliningTarget, o), inliningTarget, raiseNode);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, value);
}
}
- private static int longToFd(Node inliningTarget, long value, PRaiseNode.Lazy raiseNode) {
+ private static int longToFd(Node inliningTarget, long value, PRaiseNode raiseNode) {
if (value > Integer.MAX_VALUE) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.FD_IS_GREATER_THAN_MAXIMUM);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.FD_IS_GREATER_THAN_MAXIMUM);
}
if (value < Integer.MIN_VALUE) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.FD_IS_LESS_THAN_MINIMUM);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.FD_IS_LESS_THAN_MINIMUM);
}
return (int) value;
}
@@ -3480,7 +3481,7 @@ PosixFileHandle doNone(@SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object path = posixLib.createPathFromString(context.getPosixSupport(), T_DOT);
return new PosixPath(null, checkPath(inliningTarget, path, raiseNode), false);
}
@@ -3498,7 +3499,7 @@ static PosixFileHandle doFdInt(int value) {
@Specialization(guards = "allowFd")
static PosixFileHandle doFdLong(long value,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return new PosixFd(value, DirFdConversionNode.longToFd(inliningTarget, value, raiseNode));
}
@@ -3506,7 +3507,7 @@ static PosixFileHandle doFdLong(long value,
static PosixFileHandle doFdPInt(PInt value,
@Bind("this") Node inliningTarget,
@Exclusive @Cached CastToJavaLongLossyNode castToLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return new PosixFd(value, DirFdConversionNode.longToFd(inliningTarget, castToLongNode.execute(inliningTarget, value), raiseNode));
}
@@ -3517,7 +3518,7 @@ PosixFileHandle doUnicode(Object value,
@Exclusive @Cached CastToTruffleStringNode castToStringNode,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString str = castToStringNode.execute(inliningTarget, value);
Object path = posixLib.createPathFromString(context.getPosixSupport(), str);
return new PosixPath(value, checkPath(inliningTarget, path, raiseNode), false);
@@ -3530,7 +3531,7 @@ PosixFileHandle doBytes(PBytes value,
@Exclusive @Cached BytesNodes.ToBytesNode toByteArrayNode,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object path = posixLib.createPathFromBytes(context.getPosixSupport(), toByteArrayNode.execute(value));
return new PosixPath(value, checkPath(inliningTarget, path, raiseNode), true);
}
@@ -3545,7 +3546,7 @@ PosixFileHandle doBuffer(VirtualFrame frame, Object value,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached WarningsModuleBuiltins.WarnNode warningNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PythonLanguage language = context.getLanguage(inliningTarget);
Object buffer = bufferAcquireLib.acquireReadonly(value, frame, context, language, indirectCallData);
try {
@@ -3566,7 +3567,7 @@ PosixFileHandle doIndex(VirtualFrame frame, Object value,
@SuppressWarnings("unused") @Exclusive @Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberIndexNode indexNode,
@Exclusive @Cached CastToJavaLongLossyNode castToLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object o = indexNode.execute(frame, inliningTarget, value);
return new PosixFd(value, DirFdConversionNode.longToFd(inliningTarget, castToLongNode.execute(inliningTarget, o), raiseNode));
}
@@ -3582,10 +3583,10 @@ PosixFileHandle doGeneric(VirtualFrame frame, Object value,
@Exclusive @Cached CastToTruffleStringNode castToStringNode,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object pathObject = callFSPath.executeObject(frame, value);
if (pathObject == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_S_SHOULD_BE_S_NOT_P, functionNameWithColon, argumentName,
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_S_SHOULD_BE_S_NOT_P, functionNameWithColon, argumentName,
getAllowedTypes(), value);
}
// 'pathObject' replaces 'value' as the PosixPath.originalObject for auditing purposes
@@ -3596,7 +3597,7 @@ PosixFileHandle doGeneric(VirtualFrame frame, Object value,
if (PGuards.isString(pathObject)) {
return doUnicode(pathObject, inliningTarget, castToStringNode, context, posixLib, raiseNode);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, value, pathObject);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, value, pathObject);
}
protected boolean isHandled(Object value) {
@@ -3608,9 +3609,9 @@ private String getAllowedTypes() {
: allowFd ? "string, bytes, os.PathLike or integer" : nullable ? "string, bytes, os.PathLike or None" : "string, bytes or os.PathLike";
}
- private Object checkPath(Node inliningTarget, Object path, PRaiseNode.Lazy raiseNode) {
+ private Object checkPath(Node inliningTarget, Object path, PRaiseNode raiseNode) {
if (path == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.S_EMBEDDED_NULL_CHARACTER_IN_S, functionNameWithColon, argumentName);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.S_EMBEDDED_NULL_CHARACTER_IN_S, functionNameWithColon, argumentName);
}
return path;
}
@@ -3712,14 +3713,14 @@ public abstract static class AbstractIdConversionNode extends ArgumentCastNode {
@Specialization
long doInt(int value,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return checkValue(inliningTarget, value, raiseNode);
}
@Specialization
long doLong(long value,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return checkValue(inliningTarget, value, raiseNode);
}
@@ -3729,12 +3730,12 @@ long doGeneric(VirtualFrame frame, Object value,
@Bind("this") Node inliningTarget,
@Cached PyNumberIndexNode pyNumberIndexNode,
@Cached PyLongAsLongNode asLongNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object index;
try {
index = pyNumberIndexNode.execute(frame, inliningTarget, value);
} catch (PException ex) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_INTEGER_NOT_P, getIdName(), value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_INTEGER_NOT_P, getIdName(), value);
}
/*
* We have no means to distinguish overflow/underflow, so we just let any OverflowError
@@ -3744,13 +3745,13 @@ long doGeneric(VirtualFrame frame, Object value,
return checkValue(inliningTarget, asLongNode.execute(frame, inliningTarget, index), raiseNode);
}
- private long checkValue(Node inliningTarget, long value, PRaiseNode.Lazy raiseNode) {
+ private long checkValue(Node inliningTarget, long value, PRaiseNode raiseNode) {
// Note that -1 is intentionally allowed
if (value < -1) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_IS_LESS_THAN_MINIMUM, getIdName());
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_IS_LESS_THAN_MINIMUM, getIdName());
} else if (value > MAX_UINT32) {
/* uid_t is uint32_t on Linux */
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_IS_GREATER_THAN_MAXIUMUM, getIdName());
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_IS_GREATER_THAN_MAXIUMUM, getIdName());
}
return value;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java
index 36c6a82161..e78b40382a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java
@@ -126,13 +126,13 @@ static Object[] doSequence(VirtualFrame frame, Object processArgs,
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
@Cached ObjectToOpaquePathNode objectToOpaquePathNode,
@Cached("createNotNormalized()") GetItemNode getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PSequence argsSequence;
try {
argsSequence = fastConstructListNode.execute(frame, inliningTarget, processArgs);
} catch (PException e) {
e.expect(inliningTarget, TypeError, isBuiltinClassProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_MUST_BE_S, "argv", "a tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_MUST_BE_S, "argv", "a tuple");
}
SequenceStorage argsStorage = getSequenceStorageNode.execute(inliningTarget, argsSequence);
@@ -142,7 +142,7 @@ static Object[] doSequence(VirtualFrame frame, Object processArgs,
SequenceStorage newStorage = getSequenceStorageNode.execute(inliningTarget, argsSequence);
if (newStorage != argsStorage || newStorage.length() != len) {
// TODO write a test for this
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.ARGS_CHANGED_DURING_ITERATION);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.ARGS_CHANGED_DURING_ITERATION);
}
Object o = getItemNode.execute(argsStorage, i);
argsArray[i] = objectToOpaquePathNode.execute(frame, inliningTarget, o, false);
@@ -171,7 +171,7 @@ static Object doSequence(VirtualFrame frame, Object env,
@Cached ToBytesNode toBytesNode,
@Cached PyObjectGetItem getItem,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// TODO unlike CPython, this accepts a dict (if the keys are integers (0, 1, ..., len-1)
int length = sizeNode.execute(frame, inliningTarget, env);
Object[] result = new Object[length];
@@ -180,7 +180,7 @@ static Object doSequence(VirtualFrame frame, Object env,
byte[] bytes = toBytesNode.execute(frame, o);
Object o1 = posixLib.createPathFromBytes(context.getPosixSupport(), bytes);
if (o1 == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
result[i] = o1;
}
@@ -230,13 +230,13 @@ private static byte[] fsEncode(String s) {
return s.getBytes();
}
- private static Object createPathFromBytes(Node inliningTarget, byte[] bytes, PosixSupportLibrary posixLib, PRaiseNode.Lazy raiseNode) {
+ private static Object createPathFromBytes(Node inliningTarget, byte[] bytes, PosixSupportLibrary posixLib, PRaiseNode raiseNode) {
Object o = posixLib.createPathFromBytes(PosixSupport.get(inliningTarget), bytes);
if (o == null) {
// TODO reconsider the contract of PosixSupportLibrary#createPathFromBytes w.r.t.
// embedded null checks (we need to review that anyway since PosixSupportLibrary
// cannot do Python-specific fsencode)
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
return o;
}
@@ -259,15 +259,15 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
@Cached GilNode gil,
@Cached ToBytesNode toBytesNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(preexecFn instanceof PNone)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.S_NOT_SUPPORTED, "preexec_fn");
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.S_NOT_SUPPORTED, "preexec_fn");
}
if (closeFds && errPipeWrite < 3) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.S_MUST_BE_S, "errpipe_write", ">= 3");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.S_MUST_BE_S, "errpipe_write", ">= 3");
}
if (!(fdsToKeepObj instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "fork_exec()", 4, "tuple", fdsToKeepObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "fork_exec()", 4, "tuple", fdsToKeepObj);
}
Object[] processArgs = args;
int[] fdsToKeep = convertFdSequence(inliningTarget, (PTuple) fdsToKeepObj, tupleGetItem, castToIntNode, raiseNode);
@@ -284,7 +284,7 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
if (Arrays.equals(bytes, sysExecutable)) {
TruffleString[] additionalArgs = PythonOptions.getExecutableList(context);
if (length != 1 && additionalArgs.length != 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNSUPPORTED_USE_OF_SYS_EXECUTABLE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNSUPPORTED_USE_OF_SYS_EXECUTABLE);
}
Object[] extendedArgs = new Object[additionalArgs.length + (processArgs.length == 0 ? 0 : processArgs.length - 1)];
for (int j = 0; j < additionalArgs.length; ++j) {
@@ -319,7 +319,7 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
* Checks that the tuple contains only valid fds (positive integers fitting into an int) in
* ascending order.
*/
- private static int[] convertFdSequence(Node inliningTarget, PTuple fdSequence, GetItemNode getItemNode, CastToJavaIntExactNode castToIntNode, PRaiseNode.Lazy raiseNode) {
+ private static int[] convertFdSequence(Node inliningTarget, PTuple fdSequence, GetItemNode getItemNode, CastToJavaIntExactNode castToIntNode, PRaiseNode raiseNode) {
SequenceStorage storage = fdSequence.getSequenceStorage();
int len = storage.length();
int[] fds = new int[len];
@@ -334,7 +334,7 @@ private static int[] convertFdSequence(Node inliningTarget, PTuple fdSequence, G
} catch (PException | CannotCastException e) {
// 'handled' by raise() below
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BAD_VALUES_IN_FDS_TO_KEEP);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_VALUES_IN_FDS_TO_KEEP);
}
return fds;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
index 30994df2cf..71a25ec7c8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PwdModuleBuiltins.java
@@ -152,13 +152,13 @@ static Object doGetpwuid(VirtualFrame frame, Object uidObj,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached InlinedConditionProfile unsignedConversionProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long uid;
try {
uid = uidConversionNode.executeLong(frame, uidObj);
} catch (PException ex) {
if (classProfile.profileException(inliningTarget, ex, PythonBuiltinClassType.OverflowError)) {
- throw raiseUidNotFound(raiseNode.get(inliningTarget));
+ throw raiseUidNotFound(inliningTarget, raiseNode);
}
throw ex;
}
@@ -174,14 +174,14 @@ static Object doGetpwuid(VirtualFrame frame, Object uidObj,
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
if (pwd == null) {
- throw raiseUidNotFound(raiseNode.get(inliningTarget));
+ throw raiseUidNotFound(inliningTarget, raiseNode);
}
PythonLanguage language = context.getLanguage(inliningTarget);
return PFactory.createStructSeq(language, STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, language, unsignedConversionProfile));
}
- private static PException raiseUidNotFound(PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.KeyError, ErrorMessages.GETPWUID_NOT_FOUND);
+ private static PException raiseUidNotFound(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.KeyError, ErrorMessages.GETPWUID_NOT_FOUND);
}
}
@@ -205,7 +205,7 @@ static Object doGetpwname(VirtualFrame frame, TruffleString name,
@Cached InlinedConditionProfile unsignedConversionProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// Note: CPython also takes only Strings, not bytes, and then encodes the String
// StringOrBytesToOpaquePathNode already checks for embedded '\0'
Object nameEncoded = encodeFSDefault.execute(inliningTarget, name);
@@ -221,7 +221,7 @@ static Object doGetpwname(VirtualFrame frame, TruffleString name,
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
if (pwd == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, ErrorMessages.GETPWNAM_NAME_NOT_FOUND, name);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.KeyError, ErrorMessages.GETPWNAM_NAME_NOT_FOUND, name);
}
return PFactory.createStructSeq(language, STRUCT_PASSWD_DESC, createPwuidObject(inliningTarget, pwd, context.getLanguage(inliningTarget), unsignedConversionProfile));
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ReadlineModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ReadlineModuleBuiltins.java
index 97c29ed086..c04088a8bb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ReadlineModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ReadlineModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -138,7 +138,7 @@ PNone setCompleter(PythonModule self, TruffleString tspec) {
data.bindings.put("tab", spec.split(":")[1].trim());
return PNone.NONE;
} else {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.NotImplementedError, toTruffleStringUncached("any other binding than 'tab'"));
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.NotImplementedError, toTruffleStringUncached("any other binding than 'tab'"));
}
}
}
@@ -148,8 +148,8 @@ PNone setCompleter(PythonModule self, TruffleString tspec) {
abstract static class ReadInitNode extends PythonUnaryBuiltinNode {
@Specialization
static PNone setCompleter(@SuppressWarnings("unused") PythonModule self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.OSError, ErrorMessages.NOT_IMPLEMENTED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.OSError, ErrorMessages.NOT_IMPLEMENTED);
}
}
@@ -174,7 +174,7 @@ TruffleString setCompleter(PythonModule self, int index) {
try {
return data.history.get(index);
} catch (IndexOutOfBoundsException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
}
}
}
@@ -196,7 +196,7 @@ TruffleString setCompleter(PythonModule self, int index, TruffleString string) {
try {
return data.history.set(index, string);
} catch (IndexOutOfBoundsException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
}
}
}
@@ -211,7 +211,7 @@ TruffleString setCompleter(PythonModule self, int index) {
try {
return data.history.remove(index);
} catch (IndexOutOfBoundsException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
}
}
}
@@ -258,7 +258,7 @@ PNone setCompleter(PythonModule self, TruffleString path) {
}
reader.close();
} catch (IOException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.IOError, e);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.IOError, e);
}
return PNone.NONE;
}
@@ -286,7 +286,7 @@ PNone setCompleter(PythonModule self, TruffleString path) {
}
writer.close();
} catch (IOException e) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.IOError, e);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.IOError, e);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
index 44d8d756aa..932fa7b785 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ResourceModuleBuiltins.java
@@ -164,14 +164,14 @@ static PTuple getruusage(VirtualFrame frame, int who,
@Bind PythonContext context,
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PosixSupport posixSupport = context.getPosixSupport();
RusageResult rusage;
try {
rusage = posixLib.getrusage(posixSupport, who);
} catch (PosixException e) {
if (e.getErrorCode() == OSErrorEnum.EINVAL.getNumber()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.RUSAGE_INVALID_WHO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.RUSAGE_INVALID_WHO);
} else {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
index 3f82f666a6..5f929437c2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
@@ -195,7 +195,7 @@ public static final class TRegexCache {
private static final int FLAG_ASCII = 256;
@TruffleBoundary
- public TRegexCache(Object pattern, int flags) {
+ public TRegexCache(Node node, Object pattern, int flags) {
this.originalPattern = pattern;
String patternStr;
boolean binary = true;
@@ -207,7 +207,7 @@ public TRegexCache(Object pattern, int flags) {
try {
buffer = PythonBufferAcquireLibrary.getUncached().acquireReadonly(pattern);
} catch (PException e) {
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.EXPECTED_STR_OR_BYTESLIKE_OBJ);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.EXPECTED_STR_OR_BYTESLIKE_OBJ);
}
PythonBufferAccessLibrary bufferLib = PythonBufferAccessLibrary.getUncached();
try {
@@ -383,7 +383,7 @@ private String getTRegexOptions(String encoding, PythonMethod pythonMethod, bool
}
@TruffleBoundary
- public Object compile(PythonContext context, PythonMethod method, boolean mustAdvance, TruffleString locale) {
+ public Object compile(Node node, PythonContext context, PythonMethod method, boolean mustAdvance, TruffleString locale) {
String encoding = isBinary() ? ENCODING_LATIN_1 : ENCODING_UTF_32;
String options = getTRegexOptions(encoding, method, mustAdvance, locale);
InteropLibrary lib = InteropLibrary.getUncached();
@@ -397,7 +397,7 @@ public Object compile(PythonContext context, PythonMethod method, boolean mustAd
regexp = compiledRegex;
}
} catch (RuntimeException e) {
- throw handleCompilationError(e, lib, context);
+ throw handleCompilationError(node, e, lib, context);
}
if (isLocaleSensitive()) {
setLocaleSensitiveRegexp(method, mustAdvance, locale, regexp);
@@ -407,7 +407,7 @@ public Object compile(PythonContext context, PythonMethod method, boolean mustAd
return regexp;
}
- private RuntimeException handleCompilationError(RuntimeException e, InteropLibrary lib, PythonContext context) {
+ private RuntimeException handleCompilationError(Node node, RuntimeException e, InteropLibrary lib, PythonContext context) {
try {
if (lib.isException(e)) {
if (lib.getExceptionType(e) == ExceptionType.PARSE_ERROR) {
@@ -416,14 +416,14 @@ private RuntimeException handleCompilationError(RuntimeException e, InteropLibra
reason.equalsUncached(T_VALUE_ERROR_LOCALE_FLAG_STR_PATTERN, TS_ENCODING) ||
reason.equalsUncached(T_VALUE_ERROR_ASCII_UNICODE_INCOMPATIBLE, TS_ENCODING) ||
reason.equalsUncached(T_VALUE_ERROR_ASCII_LOCALE_INCOMPATIBLE, TS_ENCODING)) {
- return PRaiseNode.getUncached().raise(ValueError, reason);
+ return PRaiseNode.raiseStatic(node, ValueError, reason);
} else {
SourceSection sourceSection = lib.getSourceLocation(e);
int position = sourceSection.getCharIndex();
PythonModule module = context.lookupBuiltinModule(BuiltinNames.T__SRE);
Object errorConstructor = PyObjectLookupAttr.executeUncached(module, T_ERROR);
PBaseException exception = (PBaseException) CallNode.executeUncached(errorConstructor, reason, originalPattern, position);
- return PRaiseNode.getUncached().raiseExceptionObject(exception);
+ return PRaiseNode.raiseExceptionObject(node, exception);
}
}
}
@@ -472,7 +472,7 @@ Object call(VirtualFrame frame, PythonObject patternObject, Object pattern, Obje
@Cached PyLongAsIntNode flagsToIntNode,
@Cached HiddenAttr.WriteNode writeCacheNode) {
int flagsStr = flagsToIntNode.execute(frame, inliningTarget, flags);
- TRegexCache tRegexCache = new TRegexCache(pattern, flagsStr);
+ TRegexCache tRegexCache = new TRegexCache(inliningTarget, pattern, flagsStr);
writeCacheNode.execute(inliningTarget, patternObject, HiddenAttr.TREGEX_CACHE, tRegexCache);
return PNone.NONE;
}
@@ -514,7 +514,7 @@ Object localeNonSensitive(PythonObject pattern, PythonMethod method, boolean mus
if (tRegex != null) {
return tRegex;
} else {
- return tRegexCache.compile(getContext(), method, mustAdvance, null);
+ return tRegexCache.compile(this, getContext(), method, mustAdvance, null);
}
}
@@ -533,7 +533,7 @@ Object localeSensitive(VirtualFrame frame, PythonObject pattern, PythonMethod me
if (tRegex != null) {
return tRegex;
} else {
- return tRegexCache.compile(getContext(), method, mustAdvance, locale);
+ return tRegexCache.compile(this, getContext(), method, mustAdvance, locale);
}
}
@@ -566,17 +566,17 @@ static void check(VirtualFrame frame, Object input, boolean expectBytes,
@Cached BuiltinFunctions.IsInstanceNode isBytesNode,
@Cached InlinedConditionProfile unsupportedInputTypeProfile,
@Cached InlinedConditionProfile unexpectedInputTypeProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean isString = (boolean) isStringNode.execute(frame, input, PythonBuiltinClassType.PString);
boolean isBytes = !isString && (boolean) isBytesNode.execute(frame, input, supportedBinaryInputTypes);
if (unsupportedInputTypeProfile.profile(inliningTarget, !isString && !isBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, T_UNSUPPORTED_INPUT_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, T_UNSUPPORTED_INPUT_TYPE);
}
if (unexpectedInputTypeProfile.profile(inliningTarget, expectBytes != isBytes)) {
if (expectBytes) {
- throw raiseNode.get(inliningTarget).raise(TypeError, T_UNEXPECTED_STR);
+ throw raiseNode.raise(inliningTarget, TypeError, T_UNEXPECTED_STR);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, T_UNEXPECTED_BYTES);
+ throw raiseNode.raise(inliningTarget, TypeError, T_UNEXPECTED_BYTES);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
index 2260a423dd..3b500ccdac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java
@@ -310,14 +310,14 @@ static Object txt2obj(TruffleString txt, boolean name,
@Bind("this") Node inliningTarget,
@Cached TruffleString.EqualNode equalNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// TODO implement properly
if (equalNode.execute(T_OID_TLS_SERVER, txt, TS_ENCODING)) {
return PFactory.createTuple(language, new Object[]{129, T_SERVER_AUTH, T_TLS_WEB_SERVER_AUTHENTICATION, txt});
} else if (equalNode.execute(T_OID_TLS_CLIENT, txt, TS_ENCODING)) {
return PFactory.createTuple(language, new Object[]{130, T_CLIENT_AUTH, T_TLS_WEB_CLIENT_AUTHENTICATION, txt});
}
- throw raiseNode.get(inliningTarget).raise(NotImplementedError);
+ throw raiseNode.raise(inliningTarget, NotImplementedError);
}
@Override
@@ -332,8 +332,8 @@ abstract static class Nid2ObjNode extends PythonUnaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object nid2obj(Object nid,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -342,8 +342,8 @@ static Object nid2obj(Object nid,
abstract static class RandStatusNode extends PythonBuiltinNode {
@Specialization
static Object randStatus(
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -353,8 +353,8 @@ abstract static class RandAddNode extends PythonBinaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object randAdd(Object string, Object entropy,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -364,8 +364,8 @@ abstract static class RandBytesNode extends PythonUnaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object randBytes(Object n,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -375,8 +375,8 @@ abstract static class RandPseudoBytesNode extends PythonUnaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object randPseudoBytes(Object n,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -408,8 +408,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static Object fail(TruffleString argument,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PermissionError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PermissionError);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
index 6f41808631..28281d1d0d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java
@@ -134,7 +134,7 @@ static PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object x
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ObjAndFDList readFDs = seq2set(frame, inliningTarget, rlist, sizeNode, asFileDescriptor, callGetItemNode, constructListNode, raiseNode);
ObjAndFDList writeFDs = seq2set(frame, inliningTarget, wlist, sizeNode, asFileDescriptor, callGetItemNode, constructListNode, raiseNode);
ObjAndFDList xFDs = seq2set(frame, inliningTarget, xlist, sizeNode, asFileDescriptor, callGetItemNode, constructListNode, raiseNode);
@@ -144,7 +144,7 @@ static PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object x
isNotNoneTimeout.enter(inliningTarget);
timeoutval = TimeUtils.pyTimeAsTimeval(pyTimeFromObjectNode.execute(frame, inliningTarget, timeout, RoundType.TIMEOUT, SEC_TO_NS));
if (timeoutval.getSeconds() < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE, "timeout");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.MUST_BE_NON_NEGATIVE, "timeout");
}
}
@@ -186,7 +186,7 @@ private static PList toList(boolean[] result, ObjAndFDList fds, PythonLanguage l
private static ObjAndFDList seq2set(VirtualFrame frame, Node inliningTarget, Object sequence, PyObjectSizeNode sizeNode, PyObjectAsFileDescriptor asFileDescriptor,
PyObjectGetItem callGetItemNode,
- FastConstructListNode constructListNode, PRaiseNode.Lazy raiseNode) {
+ FastConstructListNode constructListNode, PRaiseNode raiseNode) {
// We cannot assume any size of those two arrays, because the sequence may change as a
// side effect of the invocation of fileno. We also need to call PyObjectSizeNode
// repeatedly in the loop condition
@@ -198,7 +198,7 @@ private static ObjAndFDList seq2set(VirtualFrame frame, Node inliningTarget, Obj
objects.add(pythonObject);
int fd = asFileDescriptor.execute(frame, inliningTarget, pythonObject);
if (fd >= FD_SETSIZE.value) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.FILE_DESCRIPTOR_OUT_OF_RANGE_IN_SELECT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.FILE_DESCRIPTOR_OUT_OF_RANGE_IN_SELECT);
}
fds.add(fd);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
index 654b436933..2520389596 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java
@@ -334,8 +334,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
abstract static class DefaultIntHandlerNode extends PythonBuiltinNode {
@Specialization
static Object defaultIntHandler(@SuppressWarnings("unused") Object[] args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.KeyboardInterrupt);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.KeyboardInterrupt);
}
}
@@ -376,7 +376,7 @@ static Object signal(Node raisingNode, int signum, Object handler, ModuleData da
data.signalSema.release();
});
} catch (IllegalArgumentException e) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonErrorType.ValueError, e);
+ throw PRaiseNode.raiseStatic(raisingNode, PythonErrorType.ValueError, e);
}
Object result = handlerToPython(oldHandler, signum, data);
data.signalHandlers.put(signum, handler);
@@ -393,7 +393,7 @@ private static Object signal(Node raisingNode, int signum, int id, ModuleData da
oldHandler = Signals.setSignalHandler(signum, id);
}
} catch (IllegalArgumentException e) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonErrorType.TypeError, ErrorMessages.SIGNAL_MUST_BE_SIGIGN_SIGDFL_OR_CALLABLE_OBJ);
+ throw PRaiseNode.raiseStatic(raisingNode, PythonErrorType.TypeError, ErrorMessages.SIGNAL_MUST_BE_SIGIGN_SIGDFL_OR_CALLABLE_OBJ);
}
Object result = handlerToPython(oldHandler, signum, data);
data.signalHandlers.remove(signum);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
index 20a289e4ce..a60a03f073 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java
@@ -154,7 +154,7 @@ static int findProtocolByName(Node raisingNode, String protocolName) {
return constant.getValueIfDefined();
}
}
- throw PRaiseNode.raiseUncached(raisingNode, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
+ throw PRaiseNode.raiseStatic(raisingNode, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
}
@Override
@@ -428,7 +428,7 @@ static Object getServByName(TruffleString serviceName, Object protocolNameObj,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString protocolName;
if (noneProtocol.profile(inliningTarget, PGuards.isNoValue(protocolNameObj))) {
protocolName = null;
@@ -464,7 +464,7 @@ static Object getServByName(TruffleString serviceName, Object protocolNameObj,
addrInfoCursorLib.release(cursor);
}
} catch (GetAddrInfoException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
}
}
@@ -490,7 +490,7 @@ Object getServByPort(int port, Object protocolNameObj,
@Cached TruffleString.EqualNode equalNode,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString protocolName;
if (nonProtocol.profile(inliningTarget, PGuards.isNoValue(protocolNameObj))) {
protocolName = null;
@@ -504,7 +504,7 @@ Object getServByPort(int port, Object protocolNameObj,
* the legacy API in the future
*/
if (port < 0 || port > 0xffff) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_PORT_RANGE, "getservbyport");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_PORT_RANGE, "getservbyport");
}
auditNode.audit(inliningTarget, "socket.getservbyport", port, protocolName != null ? protocolName : "");
@@ -524,14 +524,14 @@ Object getServByPort(int port, Object protocolNameObj,
gil.acquire();
}
} catch (GetAddrInfoException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
}
}
@TruffleBoundary
private void checkName(TruffleString name) {
if (name.toJavaStringUncached().matches("^\\d+$")) {
- throw PRaiseNode.raiseUncached(this, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
+ throw PRaiseNode.raiseStatic(this, OSError, ErrorMessages.SERVICE_PROTO_NOT_FOUND);
}
}
@@ -559,11 +559,11 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached TruffleString.FromLongNode fromLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage addr = sockaddr.getSequenceStorage();
int addrLen = addr.length();
if (addrLen < 2 || addrLen > 4) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ILLEGAL_SOCKET_ADDR_ARG, "getnameinfo()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ILLEGAL_SOCKET_ADDR_ARG, "getnameinfo()");
}
TruffleString address;
int port, flowinfo = 0, scopeid = 0;
@@ -571,13 +571,13 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
try {
address = castAddress.execute(inliningTarget, arg0);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, arg0);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, arg0);
}
port = asIntNode.execute(frame, inliningTarget, getItem.execute(inliningTarget, addr, 1));
if (addrLen > 2) {
flowinfo = asIntNode.execute(frame, inliningTarget, getItem.execute(inliningTarget, addr, 2));
if (flowinfo < 0 || flowinfo > 0xfffff) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_FLOWINFO_RANGE, "getnameinfo");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_FLOWINFO_RANGE, "getnameinfo");
}
}
if (addrLen > 3) {
@@ -600,7 +600,7 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
family = addrInfoCursorLib.getFamily(cursor);
resolvedAddr = addrInfoCursorLib.getSockAddr(cursor);
if (addrInfoCursorLib.next(cursor)) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.SOCKADDR_RESOLVED_TO_MULTIPLE_ADDRESSES);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.SOCKADDR_RESOLVED_TO_MULTIPLE_ADDRESSES);
}
} finally {
addrInfoCursorLib.release(cursor);
@@ -612,13 +612,13 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
UniversalSockAddr queryAddr;
if (family == AF_INET.value) {
if (addrLen != 2) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.IPV4_MUST_BE_2_TUPLE);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.IPV4_MUST_BE_2_TUPLE);
}
queryAddr = posixLib.createUniversalSockAddrInet4(posixSupport, new Inet4SockAddr(port, sockAddrLibrary.asInet4SockAddr(resolvedAddr).getAddress()));
} else if (family == AF_INET6.value) {
queryAddr = posixLib.createUniversalSockAddrInet6(posixSupport, new Inet6SockAddr(port, sockAddrLibrary.asInet6SockAddr(resolvedAddr).getAddress(), flowinfo, scopeid));
} else {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.UNKNOWN_FAMILY);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.UNKNOWN_FAMILY);
}
Object[] getnameinfo = posixLib.getnameinfo(posixSupport, queryAddr, flags);
@@ -633,8 +633,8 @@ static Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
@Fallback
@SuppressWarnings("unused")
static Object error(Object sockaddr, Object flags,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.GETNAMEINFO_ARG1_MUST_BE_TUPLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.GETNAMEINFO_ARG1_MUST_BE_TUPLE);
}
@Override
@@ -667,7 +667,7 @@ static Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObje
@Cached SequenceStorageNodes.AppendNode appendNode,
@Cached TruffleString.FromLongNode fromLongNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object host = null;
PosixSupport posixSupport = context.getPosixSupport();
if (hostObject != PNone.NONE) {
@@ -685,7 +685,7 @@ static Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObje
} else if (portObject == PNone.NONE) {
port = null;
} else {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.INT_OR_STRING_EXPECTED);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.INT_OR_STRING_EXPECTED);
}
auditNode.audit(inliningTarget, "socket.getaddrinfo", hostObject, portObjectProfiled, family, type, proto, flags);
@@ -804,7 +804,7 @@ static PBytes doConvert(TruffleString addr,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PosixSupport posixSupport = context.getPosixSupport();
int converted = posixLib.inet_aton(posixSupport, posixLib.createPathFromString(posixSupport, addr));
@@ -812,7 +812,7 @@ static PBytes doConvert(TruffleString addr,
ByteArraySupport.bigEndian().putInt(bytes, 0, converted);
return PFactory.createBytes(context.getLanguage(inliningTarget), bytes);
} catch (PosixSupportLibrary.InvalidAddressException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.ILLEGAL_IP_ADDR_STRING_TO_INET_ATON);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.ILLEGAL_IP_ADDR_STRING_TO_INET_ATON);
}
}
@@ -833,13 +833,13 @@ static TruffleString doGeneric(VirtualFrame frame, Object addr,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(addr, frame, indirectCallData);
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
if (len != 4) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.PACKED_IP_WRONG_LENGTH, "inet_ntoa");
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.PACKED_IP_WRONG_LENGTH, "inet_ntoa");
}
PosixSupport posixSupport = context.getPosixSupport();
Object result = posixLib.inet_ntoa(posixSupport, ByteArraySupport.bigEndian().getInt(bytes, 0));
@@ -861,7 +861,7 @@ static PBytes doConvert(VirtualFrame frame, int family, TruffleString addr,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PosixSupport posixSupport = context.getPosixSupport();
byte[] bytes = posixLib.inet_pton(posixSupport, family, posixLib.createPathFromString(posixSupport, addr));
@@ -869,7 +869,7 @@ static PBytes doConvert(VirtualFrame frame, int family, TruffleString addr,
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} catch (PosixSupportLibrary.InvalidAddressException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.ILLEGAL_IP_ADDR_STRING_TO_INET_PTON);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.ILLEGAL_IP_ADDR_STRING_TO_INET_PTON);
}
}
@@ -892,21 +892,21 @@ static TruffleString doGeneric(VirtualFrame frame, int family, Object obj,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(obj, frame, indirectCallData);
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
if (family == AF_INET.value) {
if (len != 4) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ILLEGAL_LENGTH_OF_PACKED_IP_ADDRS);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ILLEGAL_LENGTH_OF_PACKED_IP_ADDRS);
}
} else if (family == AF_INET6.value) {
if (len != 16) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ILLEGAL_LENGTH_OF_PACKED_IP_ADDRS);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ILLEGAL_LENGTH_OF_PACKED_IP_ADDRS);
}
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNKNOWN_ADDR_FAMILY, family);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNKNOWN_ADDR_FAMILY, family);
}
try {
PosixSupport posixSupport = context.getPosixSupport();
@@ -935,10 +935,10 @@ static int convert(VirtualFrame frame, Object xObj,
@Bind("this") Node inliningTarget,
@Cached PyLongAsIntNode asIntNode,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int x = asIntNode.execute(frame, inliningTarget, xObj);
if (x < 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.NTOHS_CANT_CONVERT_NEG_PYTHON_INT);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.NTOHS_CANT_CONVERT_NEG_PYTHON_INT);
}
if (x > 0xFFFF) {
warnNode.warnEx(frame, DeprecationWarning, ErrorMessages.NTOH_PYTHON_STRING_TOO_LARGE_TO_CONVERT, 1);
@@ -959,13 +959,13 @@ abstract static class NToHLNode extends PythonUnaryBuiltinNode {
static long convert(VirtualFrame frame, Object xObj,
@Bind("this") Node inliningTarget,
@Cached PyLongAsLongNode asLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long x = asLongNode.execute(frame, inliningTarget, xObj);
if (x < 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
}
if (x > 0xFFFFFFFFL) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.INT_LATGER_THAN_32_BITS);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.INT_LATGER_THAN_32_BITS);
}
int i = (int) x;
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
index d70b4ad778..6db62a371c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/StructModuleBuiltins.java
@@ -262,8 +262,8 @@ static PStruct struct(@SuppressWarnings("unused") Object cls, PBytes format,
@Specialization(guards = {"!isPBytes(format)", "!isPString(format)", "!isAsciiTruffleString(format, getCodeRangeNode)"})
static PStruct fallback(@SuppressWarnings("unused") Object cls, Object format,
@SuppressWarnings("unused") @Shared @Cached TruffleString.GetCodeRangeNode getCodeRangeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(StructError, ARG_MUST_BE_STR_OR_BYTES, "Struct()", format);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, StructError, ARG_MUST_BE_STR_OR_BYTES, "Struct()", format);
}
protected static boolean isAsciiTruffleString(Object o, TruffleString.GetCodeRangeNode getCodeRangeNode) {
@@ -278,7 +278,7 @@ private static PStruct.StructInfo createStructInternal(Node raisingNode, byte[]
int num;
if (containsNullCharacter(format)) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonBuiltinClassType.StructError, EMBEDDED_NULL_CHARACTER);
+ throw PRaiseNode.raiseStatic(raisingNode, PythonBuiltinClassType.StructError, EMBEDDED_NULL_CHARACTER);
}
char alignment = DEFAULT_ALIGNMENT;
@@ -301,12 +301,12 @@ private static PStruct.StructInfo createStructInternal(Node raisingNode, byte[]
num = c - '0';
while (++i < format.length && '0' <= (c = (char) format[i]) && c <= '9') {
if (num >= Integer.MAX_VALUE / 10 && (num > Integer.MAX_VALUE / 10 || (c - '0') > Integer.MAX_VALUE % 10)) {
- throw PRaiseNode.raiseUncached(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
+ throw PRaiseNode.raiseStatic(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
}
num = num * 10 + (c - '0');
}
if (i == format.length) {
- throw PRaiseNode.raiseUncached(raisingNode, StructError, REPEAT_COUNT_WITHOUT_FMT);
+ throw PRaiseNode.raiseStatic(raisingNode, StructError, REPEAT_COUNT_WITHOUT_FMT);
}
} else {
num = 1;
@@ -333,11 +333,11 @@ private static PStruct.StructInfo createStructInternal(Node raisingNode, byte[]
int itemSize = formatDef.size;
size = align(size, c, formatDef);
if (size == -1) {
- throw PRaiseNode.raiseUncached(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
+ throw PRaiseNode.raiseStatic(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
}
if (num > (Integer.MAX_VALUE - size) / itemSize) {
- throw PRaiseNode.raiseUncached(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
+ throw PRaiseNode.raiseStatic(raisingNode, StructError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
}
size += num * itemSize;
}
@@ -383,7 +383,7 @@ private static FormatDef getEntry(Node raisingNode, char format, FormatDef[] tab
if (formatDef != null) {
return formatDef;
}
- throw PRaiseNode.raiseUncached(raisingNode, StructError, BAD_CHR_IN_STRUCT_FMT, format);
+ throw PRaiseNode.raiseStatic(raisingNode, StructError, BAD_CHR_IN_STRUCT_FMT, format);
}
private static boolean isAlignment(char alignment) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
index ef559ae7f6..e05902b286 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java
@@ -253,6 +253,7 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -899,10 +900,10 @@ static PFrame counted(VirtualFrame frame, int num,
@Bind("this") Node inliningTarget,
@Cached ReadCallerFrameNode readCallerNode,
@Cached InlinedConditionProfile callStackDepthProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PFrame requested = escapeFrame(frame, num, readCallerNode);
if (callStackDepthProfile.profile(inliningTarget, requested == null)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CALL_STACK_NOT_DEEP_ENOUGH);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CALL_STACK_NOT_DEEP_ENOUGH);
}
return requested;
}
@@ -967,18 +968,18 @@ public abstract static class InternNode extends PythonUnaryBuiltinNode {
static Object doPString(Object s,
@Bind("this") Node inliningTarget,
@Cached StringNodes.InternStringNode internNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final PString interned = internNode.execute(inliningTarget, s);
if (interned == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_INTERN_P, s);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_INTERN_P, s);
}
return interned;
}
@Fallback
static Object doOthers(Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "intern()", "str", obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "intern()", "str", obj);
}
}
@@ -1030,7 +1031,7 @@ static Object doGeneric(VirtualFrame frame, Object object, @SuppressWarnings("un
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
@Cached("createWithError()") LookupAndCallUnaryNode callSizeofNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return checkResult(frame, inliningTarget, asSizeNode, callSizeofNode.executeObject(frame, object), raiseNode);
}
@@ -1039,7 +1040,7 @@ static Object doGeneric(VirtualFrame frame, Object object, Object dflt,
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
@Cached("createWithoutError()") LookupAndCallUnaryNode callSizeofNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object result = callSizeofNode.executeObject(frame, object);
if (result == PNone.NO_VALUE) {
return dflt;
@@ -1047,10 +1048,10 @@ static Object doGeneric(VirtualFrame frame, Object object, Object dflt,
return checkResult(frame, inliningTarget, asSizeNode, result, raiseNode);
}
- private static Object checkResult(VirtualFrame frame, Node inliningTarget, PyNumberAsSizeNode asSizeNode, Object result, PRaiseNode.Lazy raiseNode) {
+ private static Object checkResult(VirtualFrame frame, Node inliningTarget, PyNumberAsSizeNode asSizeNode, Object result, PRaiseNode raiseNode) {
int value = asSizeNode.executeExact(frame, inliningTarget, result);
if (value < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SHOULD_RETURN, "__sizeof__()", ">= 0");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SHOULD_RETURN, "__sizeof__()", ">= 0");
}
return value;
}
@@ -1058,11 +1059,12 @@ private static Object checkResult(VirtualFrame frame, Node inliningTarget, PyNum
@NeverDefault
protected LookupAndCallUnaryNode createWithError() {
return LookupAndCallUnaryNode.create(T___SIZEOF__, () -> new NoAttributeHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object receiver) {
- throw raiseNode.raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, receiver, T___SIZEOF__);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_METHOD, receiver, T___SIZEOF__);
}
});
}
@@ -1342,10 +1344,10 @@ private void writeUnraisableExc(MaterializedFrame frame, PythonModule sys, Objec
Object doit(VirtualFrame frame, PythonModule sys, Object args,
@Bind("this") Node inliningTarget,
@Cached PyTupleGetItem getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final Object cls = getObjectClass(args);
if (cls != PythonBuiltinClassType.PUnraisableHookArgs) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ARG_TYPE_MUST_BE, "sys.unraisablehook", "UnraisableHookArgs");
+ throw raiseNode.raise(inliningTarget, TypeError, ARG_TYPE_MUST_BE, "sys.unraisablehook", "UnraisableHookArgs");
}
final Object excType = getItemNode.execute(inliningTarget, args, 0);
final Object excValue = getItemNode.execute(inliningTarget, args, 1);
@@ -1687,10 +1689,10 @@ static Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyUnicodeAsEncodedString pyUnicodeAsEncodedString,
@Cached PyUnicodeFromEncodedObject pyUnicodeFromEncodedObject,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final PythonModule builtins = PythonContext.get(inliningTarget).getBuiltins();
if (builtins == null) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, LOST_S, "builtins module");
+ throw raiseNode.raise(inliningTarget, RuntimeError, LOST_S, "builtins module");
}
// Print value except if None
// After printing, also assign to '_'
@@ -1702,7 +1704,7 @@ static Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
setAttr.execute(frame, inliningTarget, builtins, T___, PNone.NONE);
Object stdOut = objectLookupAttr(frame, inliningTarget, sys, T_STDOUT, lookupAttr);
if (PGuards.isPNone(stdOut)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, LOST_S, "sys.stdout");
+ throw raiseNode.raise(inliningTarget, RuntimeError, LOST_S, "sys.stdout");
}
Object reprVal = null;
@@ -1855,9 +1857,9 @@ static Object setRecLim(VirtualFrame frame, @SuppressWarnings("unused") PythonMo
@Bind("this") Node inliningTarget,
@Cached PyLongAsIntNode longAsIntNode,
@Cached PyFloatCheckExactNode floatCheckExactNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (floatCheckExactNode.execute(inliningTarget, limit)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_EXPECTED_GOT_P, "integer", limit);
+ throw raiseNode.raise(inliningTarget, TypeError, S_EXPECTED_GOT_P, "integer", limit);
}
int newLimit;
@@ -1868,7 +1870,7 @@ static Object setRecLim(VirtualFrame frame, @SuppressWarnings("unused") PythonMo
}
if (newLimit < 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, REC_LIMIT_GREATER_THAN_1);
+ throw raiseNode.raise(inliningTarget, ValueError, REC_LIMIT_GREATER_THAN_1);
}
// TODO: check to see if Issue #25274 applies
@@ -1908,9 +1910,9 @@ static Object setCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") P
@Cached WarningsModuleBuiltins.WarnNode warnNode,
@Cached PyLongAsIntNode longAsIntNode,
@Cached PyFloatCheckExactNode floatCheckExactNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (floatCheckExactNode.execute(inliningTarget, arg)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_EXPECTED_GOT_P, "integer", arg);
+ throw raiseNode.raise(inliningTarget, TypeError, S_EXPECTED_GOT_P, "integer", arg);
}
try {
@@ -1956,10 +1958,10 @@ abstract static class SetSwitchIntervalNode extends PythonBuiltinNode {
static Object setCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys, Object arg,
@Bind("this") Node inliningTarget,
@Cached PyFloatAsDoubleNode floatAsDoubleNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
double interval = floatAsDoubleNode.execute(frame, inliningTarget, arg);
if (interval <= 0.0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SWITCH_INTERVAL_MUST_BE_POSITIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, SWITCH_INTERVAL_MUST_BE_POSITIVE);
}
PythonContext.get(inliningTarget).getSysModuleState().setSwitchInterval(FACTOR * interval);
return PNone.NONE;
@@ -1980,8 +1982,8 @@ abstract static class ExitNode extends PythonBinaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object exitNoCode(PythonModule sys, PNone status,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseSystemExit(PNone.NONE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseSystemExitStatic(inliningTarget, PNone.NONE);
}
@Specialization(guards = "!isPNone(status)")
@@ -1989,15 +1991,14 @@ static Object exit(VirtualFrame frame, @SuppressWarnings("unused") PythonModule
@Bind("this") Node inliningTarget,
@Cached PyTupleCheckNode tupleCheckNode,
@Cached TupleBuiltins.LenNode tupleLenNode,
- @Cached PyTupleGetItem getItemNode,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Cached PyTupleGetItem getItemNode) {
Object code = status;
if (tupleCheckNode.execute(inliningTarget, status)) {
if (tupleLenNode.executeInt(frame, status) == 1) {
code = getItemNode.execute(inliningTarget, status, 0);
}
}
- throw raiseNode.raiseSystemExit(code);
+ throw PRaiseNode.raiseSystemExitStatic(inliningTarget, code);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
index 59a4cad38c..e7aef1644f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
@@ -199,9 +199,9 @@ long getStackSize(@SuppressWarnings("unused") PNone stackSize) {
@Specialization
static long getStackSize(long stackSize,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (stackSize < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SIZE_MUST_BE_D_OR_S, 0, "a positive value");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SIZE_MUST_BE_D_OR_S, 0, "a positive value");
}
return PythonContext.get(inliningTarget).getAndSetPythonsThreadStackSize(stackSize);
}
@@ -303,8 +303,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
abstract static class ExitThreadNode extends PythonBuiltinNode {
@Specialization
static Object exit(
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseSystemExit(PNone.NONE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseSystemExitStatic(inliningTarget, PNone.NONE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
index 043be4b730..10f9383697 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
@@ -271,21 +271,21 @@ static long doNone(VirtualFrame frame, Node inliningTarget, PNone none) {
@Specialization
static long doLong(Node inliningTarget, long t,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
check(inliningTarget, t, raiseNode);
return t;
}
@Specialization
static long doDouble(Node inliningTarget, double t,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
check(inliningTarget, t, raiseNode);
return (long) t;
}
@Specialization(guards = "!isPNone(obj)")
static long doObject(VirtualFrame frame, Node inliningTarget, Object obj,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached CastToJavaDoubleNode castToDouble,
@Cached PyLongAsLongNode asLongNode) {
long t;
@@ -302,9 +302,9 @@ private static boolean isValidTime(double t) {
return t >= MIN_TIME && t <= MAX_TIME;
}
- private static void check(Node inliningTarget, double time, PRaiseNode.Lazy raiseNode) {
+ private static void check(Node inliningTarget, double time, PRaiseNode raiseNode) {
if (!isValidTime(time)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, TIMESTAMP_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, TIMESTAMP_OUT_OF_RANGE);
}
}
}
@@ -339,7 +339,7 @@ Object tzset() {
}
TimeZone.setDefault(TimeZone.getTimeZone(tzEnv));
} else {
- PRaiseNode.raiseUncached(this, PythonBuiltinClassType.AttributeError, SET_TIMEZONE_ERROR);
+ PRaiseNode.raiseStatic(this, PythonBuiltinClassType.AttributeError, SET_TIMEZONE_ERROR);
}
return PNone.NONE;
}
@@ -523,8 +523,8 @@ Object sleep(PythonModule self, long seconds,
@SuppressWarnings("unused")
@Specialization(guards = "!isPositive(seconds)")
static Object err(PythonModule self, long seconds,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MUST_BE_NON_NEGATIVE, "sleep length");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_BE_NON_NEGATIVE, "sleep length");
}
@Specialization(guards = "isPositive(seconds)")
@@ -547,8 +547,8 @@ Object sleep(PythonModule self, double seconds,
@SuppressWarnings("unused")
@Specialization(guards = "!isPositive(seconds)")
static Object err(PythonModule self, double seconds,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MUST_BE_NON_NEGATIVE, "sleep length");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_BE_NON_NEGATIVE, "sleep length");
}
@Specialization(guards = "!isInteger(secondsObj)")
@@ -630,10 +630,10 @@ private static String timeFormat(int[] date) {
protected static int[] checkStructtime(VirtualFrame frame, Node inliningTarget, PTuple time,
SequenceStorageNodes.GetInternalObjectArrayNode getInternalObjectArrayNode,
PyNumberAsSizeNode asSizeNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object[] otime = getInternalObjectArrayNode.execute(inliningTarget, time.getSequenceStorage());
if (time.getSequenceStorage().length() != 9) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ILLEGAL_TIME_TUPLE_ARG, "asctime()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ILLEGAL_TIME_TUPLE_ARG, "asctime()");
}
int[] date = new int[9];
for (int i = 0; i < 9; i++) {
@@ -642,37 +642,37 @@ protected static int[] checkStructtime(VirtualFrame frame, Node inliningTarget,
// This is specific to java
if (date[TM_YEAR] < Year.MIN_VALUE || date[TM_YEAR] > Year.MAX_VALUE) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.YEAR_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.YEAR_OUT_OF_RANGE);
}
if (date[TM_MON] == 0) {
date[TM_MON] = 1;
} else if (date[TM_MON] < 0 || date[TM_MON] > 12) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MONTH_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MONTH_OUT_OF_RANGE);
}
if (date[TM_MDAY] == 0) {
date[TM_MDAY] = 1;
} else if (date[TM_MDAY] < 0 || date[TM_MDAY] > 31) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.DAY_OF_MONTH_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.DAY_OF_MONTH_OUT_OF_RANGE);
}
if (date[TM_HOUR] < 0 || date[TM_HOUR] > 23) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.HOUR_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.HOUR_OUT_OF_RANGE);
}
if (date[TM_MIN] < 0 || date[TM_MIN] > 59) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MINUTE_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MINUTE_OUT_OF_RANGE);
}
if (date[TM_SEC] < 0 || date[TM_SEC] > 61) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SECONDS_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SECONDS_OUT_OF_RANGE);
}
if (date[TM_WDAY] == -1) {
date[TM_WDAY] = 6;
} else if (date[TM_WDAY] < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.DAY_OF_WEEK_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.DAY_OF_WEEK_OUT_OF_RANGE);
} else if (date[TM_WDAY] > 6) {
date[TM_WDAY] = date[TM_WDAY] % 7;
}
@@ -680,7 +680,7 @@ protected static int[] checkStructtime(VirtualFrame frame, Node inliningTarget,
if (date[TM_YDAY] == 0) {
date[TM_YDAY] = 1;
} else if (date[TM_YDAY] < 0 || date[TM_YDAY] > 366) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.DAY_OF_YEAR_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.DAY_OF_YEAR_OUT_OF_RANGE);
}
if (date[TM_ISDST] < -1) {
@@ -945,9 +945,9 @@ static TruffleString formatTime(PythonModule module, TruffleString format, @Supp
@Shared("byteIndexOfCp") @Cached TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode,
@Shared("ts2js") @Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (byteIndexOfCodePointNode.execute(format, 0, 0, format.byteLength(TS_ENCODING), TS_ENCODING) >= 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMBEDDED_NULL_CHARACTER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EMBEDDED_NULL_CHARACTER);
}
ModuleState moduleState = module.getModuleState(ModuleState.class);
return format(toJavaStringNode.execute(format), getIntLocalTimeStruct(moduleState.currentZoneId, (long) timeSeconds()), fromJavaStringNode);
@@ -961,9 +961,9 @@ static TruffleString formatTime(VirtualFrame frame, @SuppressWarnings("unused")
@Shared("byteIndexOfCp") @Cached TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode,
@Shared("ts2js") @Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (byteIndexOfCodePointNode.execute(format, 0, 0, format.byteLength(TS_ENCODING), TS_ENCODING) >= 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMBEDDED_NULL_CHARACTER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EMBEDDED_NULL_CHARACTER);
}
int[] date = checkStructtime(frame, inliningTarget, time, getArray, asSizeNode, raiseNode);
return format(toJavaStringNode.execute(format), date, fromJavaStringNode);
@@ -972,8 +972,8 @@ static TruffleString formatTime(VirtualFrame frame, @SuppressWarnings("unused")
@Specialization
@SuppressWarnings("unused")
static TruffleString formatTime(PythonModule module, TruffleString format, Object time,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.TUPLE_OR_STRUCT_TIME_ARG_REQUIRED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.TUPLE_OR_STRUCT_TIME_ARG_REQUIRED);
}
}
@@ -992,10 +992,10 @@ static double mktime(VirtualFrame frame, PythonModule module, PTuple tuple,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached GetObjectArrayNode getObjectArrayNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] items = getObjectArrayNode.execute(inliningTarget, tuple);
if (items.length != ELEMENT_COUNT) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.FUNC_TAKES_EXACTLY_D_ARGS, ELEMENT_COUNT, items.length);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.FUNC_TAKES_EXACTLY_D_ARGS, ELEMENT_COUNT, items.length);
}
int[] integers = new int[ELEMENT_COUNT];
for (int i = 0; i < ELEMENT_COUNT; i++) {
@@ -1058,15 +1058,15 @@ static TruffleString localtime(VirtualFrame frame, @SuppressWarnings("unused") P
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getArray,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
return format(StrfTimeNode.checkStructtime(frame, inliningTarget, time, getArray, asSizeNode, raiseNode), fromJavaStringNode);
}
@Fallback
@SuppressWarnings("unused")
static Object localtime(Object module, Object time,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.TUPLE_OR_STRUCT_TIME_ARG_REQUIRED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.TUPLE_OR_STRUCT_TIME_ARG_REQUIRED);
}
protected static TruffleString format(int[] tm, TruffleString.FromJavaStringNode fromJavaStringNode) {
@@ -1115,7 +1115,7 @@ static Object getClockInfo(TruffleString name,
@Cached WriteAttributeToPythonObjectNode writeAttrNode,
@Cached TruffleString.EqualNode equalNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final boolean adjustable;
final boolean monotonic;
@@ -1127,7 +1127,7 @@ static Object getClockInfo(TruffleString name,
adjustable = true;
monotonic = false;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, UNKNOWN_CLOCK);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, UNKNOWN_CLOCK);
}
final PSimpleNamespace ns = PFactory.createSimpleNamespace(language);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TracemallocModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TracemallocModuleBuiltins.java
index 7ba1ed0fbc..ae552073fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TracemallocModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TracemallocModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,10 +52,11 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.nodes.Node;
@CoreFunctions(defineModule = J__TRACEMALLOC)
public final class TracemallocModuleBuiltins extends PythonBuiltins {
@@ -75,8 +76,8 @@ public void initialize(Python3Core core) {
abstract static class GetObjectTracebackNode extends PythonBuiltinNode {
@Specialization
static Object getObjectTraceback(Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError);
}
}
@@ -85,8 +86,8 @@ static Object getObjectTraceback(Object obj,
abstract static class GetTracesNode extends PythonBuiltinNode {
@Specialization
static Object getTraces(
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/UnicodeDataModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/UnicodeDataModuleBuiltins.java
index 354414ca22..50bb3f8d0b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/UnicodeDataModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/UnicodeDataModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -141,7 +141,7 @@ static TruffleString normalize(@SuppressWarnings("unused") TruffleString form, T
@Specialization(guards = "getNormalizer(form) == null")
TruffleString invalidForm(@SuppressWarnings("unused") TruffleString form, @SuppressWarnings("unused") TruffleString unistr) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.INVALID_NORMALIZATION_FORM);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.INVALID_NORMALIZATION_FORM);
}
@TruffleBoundary
@@ -173,7 +173,7 @@ boolean isNormalized(@SuppressWarnings("unused") TruffleString form, TruffleStri
@Specialization(guards = "getNormalizer(form) == null")
TruffleString invalidForm(@SuppressWarnings("unused") TruffleString form, @SuppressWarnings("unused") TruffleString unistr) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.INVALID_NORMALIZATION_FORM);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.INVALID_NORMALIZATION_FORM);
}
@Override
@@ -192,11 +192,11 @@ public abstract static class NameNode extends PythonBinaryClinicBuiltinNode {
static Object name(int cp, Object defaultValue,
@Bind("this") Node inliningTarget,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
String result = getUnicodeName(cp);
if (result == null) {
if (defaultValue == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NO_SUCH_NAME);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NO_SUCH_NAME);
}
return defaultValue;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
index 469e070bb9..efc34f1b3a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java
@@ -204,7 +204,6 @@ private static PList initFilters(PythonLanguage language) {
static final class WarningsModuleNode extends Node {
@Child CastToTruffleStringNode castStr;
- @Child PRaiseNode raiseNode;
@Child PyObjectRichCompareBool.EqNode eqNode;
@Child GetClassNode getClassNode;
@Child PyNumberAsSizeNode asSizeNode;
@@ -376,15 +375,6 @@ private TruffleString.SubstringNode getSubstringNode() {
return substringNode;
}
- private PRaiseNode getRaise() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- reportPolymorphicSpecialize();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
-
private IsSubClassNode getIsSubClass() {
if (isSubClassNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -465,7 +455,7 @@ private boolean checkMatched(VirtualFrame frame, Object obj, Object arg) {
return getEqualNode().execute(objStr, getCastStr().executeCached(arg), TS_ENCODING);
} catch (CannotCastException e) {
// Python calls PyUnicode_Compare directly, which raises this error
- throw getRaise().raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANT_COMPARE, obj, arg);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.CANT_COMPARE, obj, arg);
}
} catch (CannotCastException e) {
Object result = getCallMethodNode().executeCached(frame, obj, T_MATCH, arg);
@@ -529,7 +519,7 @@ private static PDict getOnceRegistry(Node node, PythonContext context, PythonMod
registry = getStateOnceRegistry(module);
}
if (!(registry instanceof PDict)) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.TypeError, ErrorMessages.WARN_ONCE_REG_MUST_BE_DICT, registry);
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.TypeError, ErrorMessages.WARN_ONCE_REG_MUST_BE_DICT, registry);
}
return (PDict) registry;
}
@@ -545,7 +535,7 @@ private TruffleString getDefaultAction(VirtualFrame frame, PythonModule module)
try {
return getCastStr().executeCached(defaultAction);
} catch (CannotCastException e) {
- throw getRaise().raise(PythonBuiltinClassType.TypeError, ErrorMessages.WARN_DEF_ACTION_MUST_BE_STRING, defaultAction);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.WARN_DEF_ACTION_MUST_BE_STRING, defaultAction);
}
}
@@ -560,18 +550,18 @@ private TruffleString getFilter(VirtualFrame frame, PythonModule _warnings, Obje
filters = getStateFilters(_warnings);
}
if (!(filters instanceof PList)) {
- throw getRaise().raise(PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_MUST_BE_LIST);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_MUST_BE_LIST);
}
SequenceStorage filtersStorage = ((PList) filters).getSequenceStorage();
SequenceStorageNodes.GetItemScalarNode sequenceGetItem = getSequenceGetItemNode();
for (int i = 0; i < filtersStorage.length(); i++) {
Object tmpItem = sequenceGetItem.executeCached(filtersStorage, i);
if (!(tmpItem instanceof PTuple)) {
- throw getRaise().raise(PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_IETM_ISNT_5TUPLE, i);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_IETM_ISNT_5TUPLE, i);
}
SequenceStorage tmpStorage = ((PTuple) tmpItem).getSequenceStorage();
if (tmpStorage.length() != 5) {
- throw getRaise().raise(PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_IETM_ISNT_5TUPLE, i);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.WARN_FILTERS_IETM_ISNT_5TUPLE, i);
}
Object actionObj = sequenceGetItem.executeCached(tmpStorage, 0);
@@ -581,7 +571,7 @@ private TruffleString getFilter(VirtualFrame frame, PythonModule _warnings, Obje
} catch (CannotCastException e) {
// CPython does this check after the other __getitem__ calls, but we know it's a
// tuple so...
- throw getRaise().raise(PythonBuiltinClassType.TypeError, ErrorMessages.ACTION_MUST_BE_STRING, actionObj);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.ACTION_MUST_BE_STRING, actionObj);
}
Object msg = sequenceGetItem.executeCached(tmpStorage, 1);
Object cat = sequenceGetItem.executeCached(tmpStorage, 2);
@@ -713,10 +703,8 @@ private static void showWarning(Object filename, int lineno, Object text, Object
}
@TruffleBoundary
- private static void callShowWarning(PythonContext context, Object category, Object text, Object message,
+ private void callShowWarning(PythonContext context, Object category, Object text, Object message,
TruffleString filename, int lineno, TruffleString sourceline, Object sourceIn) {
- PRaiseNode raise = PRaiseNode.getUncached();
-
Object showFn = getWarningsAttr(context, T__SHOWWARNMSG, sourceIn != null);
if (showFn == null) {
showWarning(filename, lineno, text, category, sourceline);
@@ -724,12 +712,12 @@ private static void callShowWarning(PythonContext context, Object category, Obje
}
if (!PyCallableCheckNode.executeUncached(showFn)) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.WARN_MUST_BE_SET_CALLABLE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.WARN_MUST_BE_SET_CALLABLE);
}
Object warnmsgCls = getWarningsAttr(context, T_WARNING_MESSAGE, false);
if (warnmsgCls == null) {
- throw raise.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.UNABLE_GET_WARN_MSG);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNABLE_GET_WARN_MSG);
}
Object source = sourceIn == null ? PNone.NONE : sourceIn;
@@ -765,7 +753,7 @@ private void warnExplicit(VirtualFrame frame, PythonModule warnings,
} else if (registryObj instanceof PDict) {
registry = (PDict) registryObj;
} else {
- throw getRaise().raise(PythonBuiltinClassType.TypeError, ErrorMessages.REGISTRY_MUST_BE_DICT);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.REGISTRY_MUST_BE_DICT);
}
if (module == null) {
@@ -806,22 +794,21 @@ private void warnExplicit(VirtualFrame frame, PythonModule warnings,
PythonLanguage language = context.getLanguage(this);
Object state = IndirectCallContext.enter(frame, language, context, indirectCallData);
try {
- warnExplicitPart2(context, this, warnings, filename, lineno, registry, globals, source, category, message, text, key, item[0], action);
+ warnExplicitPart2(context, warnings, filename, lineno, registry, globals, source, category, message, text, key, item[0], action);
} finally {
IndirectCallContext.exit(frame, language, context, state);
}
}
@TruffleBoundary
- private static void warnExplicitPart2(PythonContext context, Node node, PythonModule warnings, TruffleString filename, int lineno, PDict registry, PDict globals, Object source,
+ private void warnExplicitPart2(PythonContext context, PythonModule warnings, TruffleString filename, int lineno, PDict registry, PDict globals, Object source,
Object category, Object message, Object text, Object key, Object item, TruffleString action) {
if (action.equalsUncached(T_ERROR, TS_ENCODING)) {
if (!PyExceptionInstanceCheckNode.executeUncached(message)) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION,
- PyObjectReprAsTruffleStringNode.executeUncached(message));
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, PyObjectReprAsTruffleStringNode.executeUncached(message));
} else {
- throw PRaiseNode.raiseExceptionObject(node, message);
+ throw PRaiseNode.raiseExceptionObject(this, message);
}
}
@@ -833,7 +820,7 @@ private static void warnExplicitPart2(PythonContext context, Node node, PythonMo
boolean alreadyWarned = false;
if (action.equalsUncached(T_ONCE, TS_ENCODING)) {
if (registry == null) {
- PDict currentRegistry = getOnceRegistry(node, context, warnings);
+ PDict currentRegistry = getOnceRegistry(this, context, warnings);
alreadyWarned = updateRegistry(context.getLanguage(), warnings, currentRegistry, text, category, false);
} else {
alreadyWarned = updateRegistry(context.getLanguage(), warnings, registry, text, category, false);
@@ -843,7 +830,7 @@ private static void warnExplicitPart2(PythonContext context, Node node, PythonMo
alreadyWarned = updateRegistry(context.getLanguage(), warnings, registry, text, category, false);
}
} else if (!action.equalsUncached(T_DEFAULT, TS_ENCODING)) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNRECOGNIZED_ACTION_IN_WARNINGS, action,
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNRECOGNIZED_ACTION_IN_WARNINGS, action,
PyObjectReprAsTruffleStringNode.executeUncached(item));
}
@@ -856,7 +843,7 @@ private static void warnExplicitPart2(PythonContext context, Node node, PythonMo
// to delay it
TruffleString sourceline = null;
if (globals != null) {
- sourceline = getSourceLine(node, globals, lineno);
+ sourceline = getSourceLine(this, globals, lineno);
}
callShowWarning(context, category, text, message, filename, lineno, sourceline, source);
@@ -912,7 +899,7 @@ private Object getCategory(VirtualFrame frame, Object message, Object category)
} else if (category == null || category == PNone.NONE) {
return PythonBuiltinClassType.UserWarning;
} else if (!getIsTypeNode().executeCached(category) || !getIsSubClass().executeBoolean(frame, category, PythonBuiltinClassType.Warning)) {
- throw getRaise().raise(PythonBuiltinClassType.TypeError, ErrorMessages.CATEGORY_MUST_BE_WARN_SUBCLS, category);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.CATEGORY_MUST_BE_WARN_SUBCLS, category);
} else {
return category;
}
@@ -958,13 +945,13 @@ private static TruffleString getSourceLine(Node node, PDict globals, int lineno)
try {
src = CastToJavaStringNode.getUncached().execute(source);
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_S_NOT_P, "str", source);
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_S_NOT_P, "str", source);
}
String[] lines = src.split("\n");
if (lines.length >= lineno) {
return toTruffleStringUncached(lines[lineno - 1]);
} else {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS);
}
}
}
@@ -1010,12 +997,12 @@ static Object doWarn(VirtualFrame frame, PythonModule mod, Object message, Objec
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached CastToTruffleStringNode castStr,
@Cached WarningsModuleNode moduleFunctionsNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString filename;
try {
filename = castStr.execute(inliningTarget, flname);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "warn_explicit()", 3, "str", flname);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, "warn_explicit()", 3, "str", flname);
}
PDict globalsDict;
if (globals instanceof PNone) {
@@ -1023,7 +1010,7 @@ static Object doWarn(VirtualFrame frame, PythonModule mod, Object message, Objec
} else if (globals instanceof PDict) {
globalsDict = (PDict) globals;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.MOD_GLOBALS_MUST_BE_DICT, globals);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MOD_GLOBALS_MUST_BE_DICT, globals);
}
// CPython calls get_source_line here. But since that's potentially slow, maybe we can
// get away with doing that lazily
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
index 298854a1e0..85a05e4c0d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java
@@ -263,7 +263,7 @@ static PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
@Bind PythonLanguage language,
@Exclusive @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached HiddenAttr.ReadNode readQueueNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object obj = object;
if (object instanceof PythonBuiltinClassType tobj) {
obj = PythonContext.get(inliningTarget).getCore().lookupType(tobj);
@@ -275,7 +275,7 @@ static PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
allowed = type.getWeaklistoffset() != 0;
}
if (!allowed) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_CREATE_WEAK_REFERENCE_TO, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_WEAK_REFERENCE_TO, obj);
}
assert obj instanceof PythonAbstractObject;
Object wr = readWeaklistNode.execute(inliningTarget, (PythonAbstractObject) obj, WEAKLIST, null);
@@ -307,7 +307,7 @@ PReferenceType refType(Object cls, PythonAbstractNativeObject pythonObject, Obje
@Bind PythonLanguage language,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
@Exclusive @Cached HiddenAttr.ReadNode readQueueNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object actualCallback = callback instanceof PNone ? null : callback;
Object clazz = getClassNode.execute(inliningTarget, pythonObject);
@@ -341,14 +341,14 @@ PReferenceType refType(Object cls, PythonAbstractNativeObject pythonObject, Obje
CApiTransitions.addNativeWeakRef(getContext(), pythonObject);
return PFactory.createReferenceType(language, cls, getInstanceShape.execute(cls), pythonObject, actualCallback, getWeakReferenceQueue(inliningTarget, readQueueNode));
} else {
- return refType(cls, pythonObject, actualCallback, raiseNode.get(inliningTarget));
+ return refType(cls, pythonObject, actualCallback, raiseNode);
}
}
@Fallback
static PReferenceType refType(@SuppressWarnings("unused") Object cls, Object object, @SuppressWarnings("unused") Object callback,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CREATE_WEAK_REFERENCE_TO, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_WEAK_REFERENCE_TO, object);
}
@SuppressWarnings("unchecked")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
index b67a26f384..a5cd3e7ba7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstBuiltins.java
@@ -108,26 +108,27 @@ protected Object doIt(VirtualFrame frame, Object self, Object[] args, PKeyword[]
@Cached PyObjectLookupAttr lookupAttrNode,
@Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@Cached PyObjectSetAttrO setAttrNode,
- @Cached TruffleString.EqualNode equalNode) {
+ @Cached TruffleString.EqualNode equalNode,
+ @Cached PRaiseNode raiseNode) {
Object fieldsObj = lookupAttrNode.execute(frame, inliningTarget, self, T__FIELDS);
Object[] fields;
if (fieldsObj == PNone.NO_VALUE) {
fields = EMPTY_OBJECT_ARRAY;
} else {
if (!(fieldsObj instanceof PSequence)) {
- throw raise(TypeError, IS_NOT_A_SEQUENCE, fieldsObj);
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A_SEQUENCE, fieldsObj);
}
fields = getObjectArrayNode.execute(inliningTarget, fieldsObj);
}
if (fields.length < args.length) {
- throw raise(TypeError, S_CONSTRUCTOR_TAKES_AT_MOST_D_POSITIONAL_ARGUMENT_S, self, fields.length, fields.length == 1 ? "" : "s");
+ throw raiseNode.raise(inliningTarget, TypeError, S_CONSTRUCTOR_TAKES_AT_MOST_D_POSITIONAL_ARGUMENT_S, self, fields.length, fields.length == 1 ? "" : "s");
}
for (int i = 0; i < args.length; ++i) {
setAttrNode.execute(frame, inliningTarget, self, fields[i], args[i]);
}
for (PKeyword kwArg : kwArgs) {
if (contains(fields, args.length, kwArg.getName(), equalNode)) {
- throw raise(TypeError, P_GOT_MULTIPLE_VALUES_FOR_ARGUMENT_S, self, kwArg.getName());
+ throw raiseNode.raise(inliningTarget, TypeError, P_GOT_MULTIPLE_VALUES_FOR_ARGUMENT_S, self, kwArg.getName());
}
setAttrNode.execute(frame, inliningTarget, self, kwArg.getName(), kwArg.getValue());
}
@@ -167,8 +168,8 @@ static Object dict(PythonObject self, PDict dict,
@Specialization(guards = {"!isNoValue(d)", "!isDict(d)"})
@SuppressWarnings("unused")
static Object setDict(PythonObject self, Object d,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, d);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, d);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
index 841d0e853d..ed66e9f5e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java
@@ -63,6 +63,7 @@
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.builtins.objects.type.PythonClass;
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
import com.oracle.graal.python.pegparser.InputType;
@@ -75,6 +76,7 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@CoreFunctions(defineModule = AstModuleBuiltins.J__AST, isEager = true)
@@ -136,7 +138,7 @@ public static Object sst2Obj(PythonContext context, ModTy mod) {
}
@TruffleBoundary
- public static ModTy obj2sst(PythonContext context, Object obj, InputType type) {
+ public static ModTy obj2sst(Node node, PythonContext context, Object obj, InputType type) {
AstState state = getAstState(context);
PythonClass expectedClass;
switch (type) {
@@ -153,11 +155,12 @@ public static ModTy obj2sst(PythonContext context, Object obj, InputType type) {
throw shouldNotReachHere();
}
if (!Obj2SstBase.isInstanceOf(obj, expectedClass)) {
- throw Obj2SstBase.raiseTypeError(EXPECTED_S_NODE_GOT_P, expectedClass.getName(), obj);
+ Object[] arguments = new Object[]{expectedClass.getName(), obj};
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.TypeError, EXPECTED_S_NODE_GOT_P, arguments);
}
- ModTy mod = new Obj2Sst(state).obj2ModTy(obj);
- Validator.validateMod(mod);
+ ModTy mod = new Obj2Sst(node, state).obj2ModTy(obj);
+ Validator.validateMod(node, mod);
return mod;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
index 243cd7c5e8..1166363cdf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2Sst.java
@@ -45,6 +45,7 @@
// Generated from Python.asdl by main_asdl_gen.py
package com.oracle.graal.python.builtins.modules.ast;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.pegparser.sst.ConstantValue;
import com.oracle.graal.python.pegparser.sst.ModTy;
@@ -69,8 +70,8 @@
final class Obj2Sst extends Obj2SstBase {
- Obj2Sst(AstState state) {
- super(state);
+ Obj2Sst(Node node, AstState state) {
+ super(node, state);
}
ModTy obj2ModTy(Object obj) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2SstBase.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2SstBase.java
index 9f41864f94..9d8ca154cb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2SstBase.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Obj2SstBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -91,13 +91,16 @@
import com.oracle.graal.python.pegparser.sst.ConstantValue;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
abstract class Obj2SstBase {
final AstState state;
+ private final Node node;
- protected Obj2SstBase(AstState state) {
+ protected Obj2SstBase(Node node, AstState state) {
+ this.node = node;
this.state = state;
}
@@ -305,7 +308,7 @@ ConstantValue obj2ConstantValue(Object obj) {
throw raiseTypeError(ErrorMessages.GOT_AN_INVALID_TYPE_IN_CONSTANT, obj);
}
- static PException unexpectedNodeType(TruffleString expected, Object obj) {
+ protected PException unexpectedNodeType(TruffleString expected, Object obj) {
throw raiseTypeError(EXPECTED_SOME_SORT_OF_S_BUT_GOT_S, expected, repr(obj));
}
@@ -317,15 +320,15 @@ private static TruffleString repr(Object o) {
return PyObjectReprAsTruffleStringNode.executeUncached(o);
}
- private static PException raise(PythonBuiltinClassType type, TruffleString format, Object... arguments) {
- throw PRaiseNode.getUncached().raise(type, format, arguments);
+ private PException raise(PythonBuiltinClassType type, TruffleString format, Object... arguments) {
+ throw PRaiseNode.raiseStatic(node, type, format, arguments);
}
- static PException raiseTypeError(TruffleString format, Object... arguments) {
+ protected PException raiseTypeError(TruffleString format, Object... arguments) {
throw raise(PythonBuiltinClassType.TypeError, format, arguments);
}
- private static PException raiseValueError(TruffleString format, Object... arguments) {
+ protected PException raiseValueError(TruffleString format, Object... arguments) {
throw raise(PythonBuiltinClassType.ValueError, format, arguments);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Validator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Validator.java
index 0c6265010d..c6259fbf05 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Validator.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/Validator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -93,13 +93,17 @@
import com.oracle.graal.python.pegparser.sst.UnaryOpTy;
import com.oracle.graal.python.pegparser.sst.WithItemTy;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
final class Validator implements SSTreeVisitor {
private static final String[] FORBIDDEN_NAMES = {"None", "True", "False"};
- private Validator() {
+ private final Node node;
+
+ private Validator(Node node) {
+ this.node = node;
}
/*-
@@ -107,9 +111,9 @@ private Validator() {
*/
// Equivalent of _PyAST_Validate - entry point of the validation
- static void validateMod(ModTy mod) {
+ static void validateMod(Node node, ModTy mod) {
// TODO recursion checks
- mod.accept(new Validator());
+ mod.accept(new Validator(node));
}
@Override
@@ -754,7 +758,7 @@ private void validatePatternMatchValue(ExprTy expr) {
throw raiseValueError(ErrorMessages.PATTERNS_MAY_ONLY_MATCH_LITERALS_AND_ATTRIBUTE_LOOKUPS);
}
- private static void validateCapture(String name) {
+ private void validateCapture(String name) {
if (name.equals("_")) {
throw raiseValueError(ErrorMessages.CANT_CAPTURE_NAME_UNDERSCORE_IN_PATTERNS);
}
@@ -1023,7 +1027,7 @@ private void validateAssignList(ExprTy[] targets, ExprContextTy ctx) {
}
// Equivalent of _validate_nonempty_seq
- private static void validateNonEmptySeq(Object[] seq, TruffleString what, TruffleString owner) {
+ private void validateNonEmptySeq(Object[] seq, TruffleString what, TruffleString owner) {
if (seqLen(seq) == 0) {
throw raiseValueError(ErrorMessages.EMPTY_S_ON_S, what, owner);
}
@@ -1049,7 +1053,7 @@ private static int seqLen(Object[] seq) {
}
// Equivalent of validate_name
- private static void validateName(String id) {
+ private void validateName(String id) {
for (String f : FORBIDDEN_NAMES) {
if (f.equals(id)) {
throw raiseValueError(ErrorMessages.IDENTIFIER_FIELD_CANT_REPRESENT_S_CONSTANT, f);
@@ -1062,11 +1066,11 @@ private void validateConstant(@SuppressWarnings("unused") ConstantValue value) {
// Already done in Obj2SstBase#obj2ConstantValue()
}
- private static PException raiseValueError(TruffleString format, Object... args) {
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.ValueError, format, args);
+ private PException raiseValueError(TruffleString format, Object... args) {
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, format, args);
}
- private static PException raiseTypeError(TruffleString format, Object... args) {
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.TypeError, format, args);
+ private PException raiseTypeError(TruffleString format, Object... args) {
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.TypeError, format, args);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
index 28865aeb0d..203cb0c65e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java
@@ -105,14 +105,14 @@ PNone init(BZ2Object.BZ2Compressor self, int compresslevel,
@Cached NativeLibrary.InvokeNativeFunction createStream,
@Cached NativeLibrary.InvokeNativeFunction compressInit,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
NFIBz2Support bz2Support = PythonContext.get(this).getNFIBz2Support();
Object bzst = bz2Support.createStream(createStream);
int err = bz2Support.compressInit(bzst, compresslevel, compressInit);
if (err != BZ_OK) {
- errorHandling(err, raiseNode.get(inliningTarget));
+ errorHandling(inliningTarget, err, raiseNode);
}
self.init(bzst, bz2Support);
return PNone.NONE;
@@ -124,8 +124,8 @@ PNone init(BZ2Object.BZ2Compressor self, int compresslevel,
@SuppressWarnings("unused")
@Fallback
static Object err(Object self, Object compresslevel,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, COMPRESSLEVEL_MUST_BE_BETWEEN_1_AND_9);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, COMPRESSLEVEL_MUST_BE_BETWEEN_1_AND_9);
}
}
@@ -158,8 +158,8 @@ static PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Compressor self, O
@SuppressWarnings("unused")
@Specialization(guards = "self.isFlushed()")
static PNone error(BZ2Object.BZ2Compressor self, Object data,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, COMPRESSOR_HAS_BEEN_FLUSHED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, COMPRESSOR_HAS_BEEN_FLUSHED);
}
}
@@ -179,8 +179,8 @@ static PBytes doit(BZ2Object.BZ2Compressor self,
@SuppressWarnings("unused")
@Specialization(guards = "self.isFlushed()")
static PNone error(BZ2Object.BZ2Compressor self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, REPEATED_CALL_TO_FLUSH);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, REPEATED_CALL_TO_FLUSH);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
index e33951bfd7..8fba6e2f51 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java
@@ -93,12 +93,12 @@ static PNone init(BZ2Object.BZ2Decompressor self,
@Bind("this") Node inliningTarget,
@Cached NativeLibrary.InvokeNativeFunction createStream,
@Cached NativeLibrary.InvokeNativeFunction compressInit,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
NFIBz2Support bz2Support = PythonContext.get(inliningTarget).getNFIBz2Support();
Object bzst = bz2Support.createStream(createStream);
int err = bz2Support.decompressInit(bzst, compressInit);
if (err != BZ_OK) {
- errorHandling(err, raiseNode.get(inliningTarget));
+ errorHandling(inliningTarget, err, raiseNode);
}
self.init(bzst, bz2Support);
return PNone.NONE;
@@ -144,8 +144,8 @@ static PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Decompressor self,
@SuppressWarnings("unused")
@Specialization(guards = {"self.isEOF()"})
static Object err(BZ2Object.BZ2Decompressor self, PBytesLike data, int maxLength,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(EOFError, END_OF_STREAM_ALREADY_REACHED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, EOFError, END_OF_STREAM_ALREADY_REACHED);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/Bz2Nodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/Bz2Nodes.java
index dcc065e578..8b102a71c6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/Bz2Nodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/Bz2Nodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -112,12 +112,12 @@ static byte[] nativeCompress(BZ2Object.BZ2Compressor self, PythonContext context
@Bind("this") Node inliningTarget,
@Cached NativeLibrary.InvokeNativeFunction compress,
@Cached GetOutputNativeBufferNode getBuffer,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
NFIBz2Support bz2Support = context.getNFIBz2Support();
Object inGuest = context.getEnv().asGuestValue(bytes);
int err = bz2Support.compress(self.getBzs(), inGuest, len, action, INITIAL_BUFFER_SIZE, compress);
if (err != BZ_OK) {
- errorHandling(err, raiseNode.get(inliningTarget));
+ errorHandling(inliningTarget, err, raiseNode);
}
return getBuffer.execute(inliningTarget, self.getBzs(), context);
}
@@ -236,7 +236,7 @@ static byte[] nativeInternalDecompress(BZ2Object.BZ2Decompressor self, int maxLe
@Cached GetOutputNativeBufferNode getBuffer,
@Cached InlinedConditionProfile errProfile,
@Cached InlinedBranchProfile ofProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
NFIBz2Support bz2Support = context.getNFIBz2Support();
Object inGuest = self.getNextInGuest(context);
@@ -249,12 +249,12 @@ static byte[] nativeInternalDecompress(BZ2Object.BZ2Decompressor self, int maxLe
self.setBzsAvailInReal(bzsAvailInReal);
} catch (OverflowException of) {
ofProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
+ throw raiseNode.raise(inliningTarget, SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
}
if (err == BZ_STREAM_END) {
self.setEOF();
} else if (errProfile.profile(inliningTarget, err != BZ_OK)) {
- errorHandling(err, raiseNode.get(inliningTarget));
+ errorHandling(inliningTarget, err, raiseNode);
}
return getBuffer.execute(inliningTarget, self.getBzs(), context);
}
@@ -271,14 +271,14 @@ static byte[] getBuffer(Node inliningTarget, Object bzst, PythonContext context,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getBufferSize,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getBuffer,
@Cached InlinedBranchProfile ofProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
NFIBz2Support bz2Support = context.getNFIBz2Support();
int size;
try {
size = PInt.intValueExact(bz2Support.getOutputBufferSize(bzst, getBufferSize));
} catch (OverflowException of) {
ofProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
+ throw raiseNode.raise(inliningTarget, SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
}
if (size == 0) {
return PythonUtils.EMPTY_BYTE_ARRAY;
@@ -291,25 +291,25 @@ static byte[] getBuffer(Node inliningTarget, Object bzst, PythonContext context,
}
}
- protected static void errorHandling(int bzerror, PRaiseNode raise) {
+ protected static void errorHandling(Node inliningTarget, int bzerror, PRaiseNode raise) {
switch (bzerror) {
case BZ_PARAM_ERROR:
- throw raise.raise(ValueError, INVALID_PARAMETERS_PASSED_TO_LIBBZIP2);
+ throw raise.raise(inliningTarget, ValueError, INVALID_PARAMETERS_PASSED_TO_LIBBZIP2);
case BZ_MEM_ERROR:
- throw raise.raise(MemoryError);
+ throw raise.raise(inliningTarget, MemoryError);
case BZ_DATA_ERROR:
case BZ_DATA_ERROR_MAGIC:
- throw raise.raise(OSError, INVALID_DATA_STREAM);
+ throw raise.raise(inliningTarget, OSError, INVALID_DATA_STREAM);
case BZ_IO_ERROR:
- throw raise.raise(OSError, UNKNOWN_IO_ERROR);
+ throw raise.raise(inliningTarget, OSError, UNKNOWN_IO_ERROR);
case BZ_UNEXPECTED_EOF:
- throw raise.raise(EOFError, COMPRESSED_FILE_ENDED_BEFORE_EOS);
+ throw raise.raise(inliningTarget, EOFError, COMPRESSED_FILE_ENDED_BEFORE_EOS);
case BZ_SEQUENCE_ERROR:
- throw raise.raise(RuntimeError, INVALID_SEQUENCE_OF_COMMANDS);
+ throw raise.raise(inliningTarget, RuntimeError, INVALID_SEQUENCE_OF_COMMANDS);
case BZ_CONFIG_ERROR:
- throw raise.raise(ValueError, LIBBZIP2_WAS_NOT_COMPILED_CORRECTLY);
+ throw raise.raise(inliningTarget, ValueError, LIBBZIP2_WAS_NOT_COMPILED_CORRECTLY);
default:
- throw raise.raise(OSError, UNRECOGNIZED_ERROR_FROM_LIBBZIP2_D, bzerror);
+ throw raise.raise(inliningTarget, OSError, UNRECOGNIZED_ERROR_FROM_LIBBZIP2_D, bzerror);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 05d971d18c..2dfa351af1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -40,7 +40,6 @@
*/
package com.oracle.graal.python.builtins.modules.cext;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiCallPath.Direct;
@@ -140,6 +139,7 @@
import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.TruffleLogger;
import com.oracle.truffle.api.dsl.Bind;
@@ -187,7 +187,7 @@ abstract static class PyNumber_Index extends CApiUnaryBuiltinNode {
static Object index(Object obj,
@Bind("this") Node inliningTarget,
@Cached PyNumberIndexNode indexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, obj, raiseNode);
return indexNode.execute(null, inliningTarget, obj);
}
@@ -261,8 +261,8 @@ static Object toBase(Object n, @SuppressWarnings("unused") int base,
@Specialization(guards = "!checkBase(base)")
static Object toBase(@SuppressWarnings("unused") Object n, @SuppressWarnings("unused") int base,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BASE_MUST_BE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BASE_MUST_BE);
}
protected boolean checkBase(int base) {
@@ -493,7 +493,7 @@ static Object setItem(Object obj, long key, Object value,
@Bind("this") Node inliningTarget,
@Cached PySequenceSetItemNode setItemNode) {
if ((int) key != key) {
- throw PRaiseNode.raiseUncached(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, key);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, key);
}
setItemNode.execute(null, inliningTarget, obj, (int) key, value);
return 0;
@@ -517,10 +517,9 @@ static Object getSlice(Object obj, long iLow, long iHigh,
@Specialization(guards = "!checkNode.execute(inliningTarget, obj)", limit = "1")
static Object getSlice(Object obj, @SuppressWarnings("unused") Object key, @SuppressWarnings("unused") Object value,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_IS_UNSLICEABLE, obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_IS_UNSLICEABLE, obj);
}
}
@@ -554,10 +553,9 @@ static Object repeat(Object obj, long n,
@Specialization(guards = "!checkNode.execute(inliningTarget, obj)", limit = "1")
static Object repeat(Object obj, @SuppressWarnings("unused") Object n,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANT_BE_REPEATED, obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANT_BE_REPEATED, obj);
}
}
@@ -590,10 +588,9 @@ static Object concat(Object s1, Object s2,
@Specialization(guards = "!checkNode.execute(inliningTarget, s1)", limit = "1")
static Object concat(Object s1, @SuppressWarnings("unused") Object s2,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, s1);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, s1);
}
}
@@ -604,7 +601,7 @@ static Object run(Object o, long i,
@Bind("this") Node inliningTarget,
@Cached PySequenceDelItemNode delItemNode) {
if ((int) i != i) {
- throw PRaiseNode.raiseUncached(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, i);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, i);
}
delItemNode.execute(null, inliningTarget, o, (int) i);
return 0;
@@ -618,7 +615,7 @@ static Object doManaged(Object delegate, long position,
@Bind("this") Node inliningTarget,
@Cached PySequenceGetItemNode getItemNode) {
if ((int) position != position) {
- throw PRaiseNode.raiseUncached(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, position);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, position);
}
return getItemNode.execute(null, delegate, (int) position);
}
@@ -643,14 +640,14 @@ static int setSlice(Object sequence, Object iLow, Object iHigh, Object s,
@Cached GetObjectSlotsNode getSlotsNode,
@Cached CallSlotMpAssSubscriptNode callSetItem,
@Cached PySliceNew sliceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getSlotsNode.execute(inliningTarget, sequence);
if (slots.mp_ass_subscript() != null) {
PSlice slice = sliceNode.execute(inliningTarget, iLow, iHigh, PNone.NONE);
callSetItem.execute(null, inliningTarget, slots.mp_ass_subscript(), sequence, slice, s);
return 0;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.P_OBJECT_DOESNT_SUPPORT_SLICE_ASSIGNMENT, sequence);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.P_OBJECT_DOESNT_SUPPORT_SLICE_ASSIGNMENT, sequence);
}
}
}
@@ -663,14 +660,14 @@ static int setSlice(Object sequence, Object iLow, Object iHigh,
@Cached GetObjectSlotsNode getSlotsNode,
@Cached CallSlotMpAssSubscriptNode callSetItem,
@Cached PySliceNew sliceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getSlotsNode.execute(inliningTarget, sequence);
if (slots.mp_ass_subscript() != null) {
PSlice slice = sliceNode.execute(inliningTarget, iLow, iHigh, PNone.NONE);
callSetItem.execute(null, inliningTarget, slots.mp_ass_subscript(), sequence, slice, PNone.NO_VALUE);
return 0;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.P_OBJECT_DOESNT_SUPPORT_SLICE_DELETION, sequence);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.P_OBJECT_DOESNT_SUPPORT_SLICE_DELETION, sequence);
}
}
}
@@ -803,7 +800,7 @@ static Object values(Object obj,
@Cached PyObjectGetAttr getAttrNode,
@Cached CallNode callNode,
@Shared @Cached ConstructListNode listNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, obj, raiseNode);
Object attr = getAttrNode.execute(inliningTarget, obj, T_VALUES);
return listNode.execute(null, callNode.executeWithoutFrame(attr));
@@ -822,12 +819,12 @@ static int doMapping(Object obj,
@Cached com.oracle.graal.python.lib.PyObjectSizeNode sizeNode,
@Cached IsSameTypeNode isSameType,
@Cached GetClassNode getClassNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object cls = getClassNode.execute(inliningTarget, obj);
if (isSameType.execute(inliningTarget, cls, PythonBuiltinClassType.PSet) ||
isSameType.execute(inliningTarget, cls, PythonBuiltinClassType.PFrozenSet) ||
isSameType.execute(inliningTarget, cls, PythonBuiltinClassType.PDeque)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, OBJ_ISNT_MAPPING, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, OBJ_ISNT_MAPPING, obj);
} else {
return sizeNode.execute(null, inliningTarget, obj);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
index b44f6287df..a651521214 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java
@@ -323,7 +323,7 @@ public static PException checkThrowableBeforeNative(Throwable t, String where1,
out.println("ERROR: Native API called without Truffle context. This can happen when called from C-level atexit, C++ global destructor or an unregistered native thread");
}
out.flush();
- throw PRaiseNode.raiseUncached(null, SystemError, ErrorMessages.INTERNAL_EXCEPTION_OCCURED);
+ throw PRaiseNode.raiseStatic(null, SystemError, ErrorMessages.INTERNAL_EXCEPTION_OCCURED);
}
public abstract static class CApiBuiltinNode extends PNodeWithContext {
@@ -374,7 +374,7 @@ protected final CApiContext getCApiContext() {
protected final PException badInternalCall(String argName) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.S_S_BAD_ARG_TO_INTERNAL_FUNC, getName(), argName);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.S_S_BAD_ARG_TO_INTERNAL_FUNC, getName(), argName);
}
@NonIdempotent
@@ -394,25 +394,25 @@ private String getName() {
@TruffleBoundary
protected PException raiseFallback(Object obj, PythonBuiltinClassType type) {
if (obj == PNone.NO_VALUE) {
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_S, getName());
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_S, getName());
}
if (IsSubtypeNode.getUncached().execute(GetClassNode.executeUncached(obj), type)) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, type.getName());
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, type.getName());
} else {
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.EXPECTED_S_NOT_P, type.getName(), obj);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.EXPECTED_S_NOT_P, type.getName(), obj);
}
}
@TruffleBoundary
protected PException raiseFallback(Object obj, PythonBuiltinClassType type1, PythonBuiltinClassType type2) {
if (obj == PNone.NO_VALUE) {
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_S, getName());
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_S, getName());
}
Object objType = GetClassNode.executeUncached(obj);
if (IsSubtypeNode.getUncached().execute(objType, type1) || IsSubtypeNode.getUncached().execute(objType, type2)) {
- throw PRaiseNode.raiseUncached(this, NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, type1.getName());
+ throw PRaiseNode.raiseStatic(this, NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, type1.getName());
} else {
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.EXPECTED_S_NOT_P, type1.getName(), obj);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.EXPECTED_S_NOT_P, type1.getName(), obj);
}
}
@@ -425,18 +425,18 @@ protected final int castToInt(long elementSize) {
return (int) elementSize;
}
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, INDEX_OUT_OF_RANGE);
+ throw PRaiseNode.raiseStatic(this, SystemError, INDEX_OUT_OF_RANGE);
}
- protected static void checkNonNullArg(Node inliningTarget, Object obj, PRaiseNode.Lazy raiseNode) {
+ protected static void checkNonNullArg(Node inliningTarget, Object obj, PRaiseNode raiseNode) {
if (obj == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.NULL_ARG_INTERNAL);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.NULL_ARG_INTERNAL);
}
}
- protected static void checkNonNullArg(Node inliningTarget, Object obj1, Object obj2, PRaiseNode.Lazy raiseNode) {
+ protected static void checkNonNullArg(Node inliningTarget, Object obj1, Object obj2, PRaiseNode raiseNode) {
if (obj1 == PNone.NO_VALUE || obj2 == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.NULL_ARG_INTERNAL);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.NULL_ARG_INTERNAL);
}
}
}
@@ -992,7 +992,7 @@ abstract static class PyTruffle_Type extends CApiUnaryBuiltinNode {
static Object doI(TruffleString typeName,
@Bind("this") Node inliningTarget,
@Cached TruffleString.EqualNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Python3Core core = PythonContext.get(inliningTarget);
for (PythonBuiltinClassType type : PythonBuiltinClassType.VALUES) {
if (eqNode.execute(type.getName(), typeName, TS_ENCODING)) {
@@ -1005,7 +1005,7 @@ static Object doI(TruffleString typeName,
return attribute;
}
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.KeyError, ErrorMessages.APOSTROPHE_S, typeName);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.KeyError, ErrorMessages.APOSTROPHE_S, typeName);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java
index 8cfbb409bb..fbe4cc493a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -78,17 +78,17 @@ static Object doNative(PythonAbstractNativeObject obj,
@Cached GetPythonObjectClassNode getClassNode,
@Cached IsSubtypeNode isSubtypeNode,
@Cached CStructAccess.GetElementPtrNode getArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, obj), PythonBuiltinClassType.PByteArray)) {
return getArray.getElementPtr(obj.getPtr(), CFields.PyByteArrayObject__ob_start);
}
- return doError(obj, raiseNode.get(inliningTarget));
+ return doError(obj, raiseNode);
}
@Fallback
static Object doError(Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_P_FOUND, "bytearray", obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_P_FOUND, "bytearray", obj);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
index f3d47b9596..b89d3af482 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
@@ -142,7 +142,7 @@ static long doOther(PythonAbstractNativeObject obj,
@TruffleBoundary
static long fallback(Object obj,
@Bind("this") Node inliningTarget) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, obj);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, obj);
}
}
@@ -184,7 +184,7 @@ static Object fromObject(Object obj,
@Cached IsSubtypeNode isSubtypeNode,
@Cached BytesNode bytesNode,
@Cached PyObjectLookupAttr lookupAttrNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (PGuards.isPBytes(obj)) {
return obj;
} else {
@@ -194,7 +194,7 @@ static Object fromObject(Object obj,
} else if (isAcceptedSubtype(inliningTarget, obj, klass, isSubtypeNode, lookupAttrNode)) {
return bytesNode.execute(null, PythonBuiltinClassType.PBytes, obj, PNone.NO_VALUE, PNone.NO_VALUE);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_CONVERT_P_OBJ_TO_S, obj, "bytes");
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_CONVERT_P_OBJ_TO_S, obj, "bytes");
}
}
}
@@ -235,13 +235,13 @@ static Object doNativePointer(Object nativePointer, long size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Exclusive @Cached GetByteArrayNode getByteArrayNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, nativePointer, size));
} catch (InteropException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
}
}
}
@@ -268,13 +268,13 @@ static Object doNativePointer(Object nativePointer, long size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Exclusive @Cached GetByteArrayNode getByteArrayNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return PFactory.createByteArray(language, getByteArrayNode.execute(inliningTarget, nativePointer, size));
} catch (InteropException e) {
- return raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ return raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
- return raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
+ return raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
}
}
}
@@ -303,8 +303,8 @@ static int resize(PBytesLike self, long newSizeL,
@Fallback
static int fallback(Object self, @SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, ErrorMessages.EXPECTED_S_NOT_P, "a bytes object", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.EXPECTED_S_NOT_P, "a bytes object", self);
}
}
@@ -327,11 +327,11 @@ static PBytes doLong(long size,
static PBytes doLongOvf(long size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return doInt(PInt.intValueExact(size), language);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
}
}
@@ -345,11 +345,11 @@ static PBytes doPInt(PInt size,
static PBytes doPIntOvf(PInt size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return doInt(size.intValueExact(), language);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
}
}
}
@@ -373,11 +373,11 @@ static PByteArray doLong(long size,
static PByteArray doLongOvf(long size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return doInt(PInt.intValueExact(size), language);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
}
}
@@ -391,11 +391,11 @@ static PByteArray doPInt(PInt size,
static PByteArray doPIntOvf(PInt size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return doInt(size.intValueExact(), language);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(IndexError, size);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
}
}
}
@@ -436,17 +436,17 @@ static Object doNative(PythonAbstractNativeObject obj,
@Cached GetPythonObjectClassNode getClassNode,
@Cached IsSubtypeNode isSubtypeNode,
@Cached CStructAccess.GetElementPtrNode getArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, obj), PythonBuiltinClassType.PBytes)) {
return getArray.getElementPtr(obj.getPtr(), CFields.PyBytesObject__ob_sval);
}
- return doError(obj, raiseNode.get(inliningTarget));
+ return doError(obj, raiseNode);
}
@Fallback
static Object doError(Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_P_FOUND, "bytes", obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_P_FOUND, "bytes", obj);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
index 410ef50f24..acf80b9b04 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java
@@ -102,9 +102,9 @@ public abstract static class PyCapsuleNewNode extends Node {
static PyCapsule doGeneric(Node inliningTarget, Object pointer, Object namePtr, Object destructor,
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (interopLibrary.isNull(pointer)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT);
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT);
}
PyCapsule capsule = PFactory.createCapsuleNativeName(language, pointer, interopLibrary.isNull(namePtr) ? null : namePtr);
if (!interopLibrary.isNull(destructor)) {
@@ -155,20 +155,19 @@ public abstract static class PyCapsuleGetPointerNode extends Node {
@Specialization
static Object doCapsule(Node inliningTarget, PyCapsule o, Object name,
@Cached PyCapsuleNameMatchesNode nameMatchesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
}
if (!nameMatchesNode.execute(inliningTarget, name, o.getNamePtr())) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INCORRECT_NAME, "PyCapsule_GetPointer");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INCORRECT_NAME, "PyCapsule_GetPointer");
}
return o.getPointer();
}
@Fallback
- static Object doError(Node inliningTarget, @SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
+ static Object doError(Node inliningTarget, @SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
}
}
@@ -178,17 +177,17 @@ abstract static class PyCapsule_GetName extends CApiUnaryBuiltinNode {
@Specialization
Object get(PyCapsule o,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetName");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetName");
}
return o.getNamePtr() == null ? getNULL() : o.getNamePtr();
}
@Fallback
static Object doit(@SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetName");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetName");
}
}
@@ -197,9 +196,9 @@ abstract static class PyCapsule_GetDestructor extends CApiUnaryBuiltinNode {
@Specialization
Object doCapsule(PyCapsule o,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetDestructor");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetDestructor");
}
if (o.getDestructor() == null) {
return getNULL();
@@ -209,8 +208,8 @@ Object doCapsule(PyCapsule o,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
}
}
@@ -219,9 +218,9 @@ abstract static class PyCapsule_GetContext extends CApiUnaryBuiltinNode {
@Specialization
Object doCapsule(PyCapsule o,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetContext");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetContext");
}
if (o.getContext() == null) {
return getNULL();
@@ -231,8 +230,8 @@ Object doCapsule(PyCapsule o,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_GetPointer");
}
}
@@ -242,13 +241,13 @@ abstract static class PyCapsule_SetPointer extends CApiBinaryBuiltinNode {
static int doCapsule(PyCapsule o, Object pointer,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "2") InteropLibrary interopLibrary,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (interopLibrary.isNull(pointer)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_NULL_POINTER, "PyCapsule_SetPointer");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_NULL_POINTER, "PyCapsule_SetPointer");
}
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetPointer");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetPointer");
}
o.setPointer(pointer);
@@ -257,8 +256,8 @@ static int doCapsule(PyCapsule o, Object pointer,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetPointer");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetPointer");
}
}
@@ -268,9 +267,9 @@ abstract static class PyCapsule_SetName extends CApiBinaryBuiltinNode {
static int set(PyCapsule o, Object namePtr,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "1") InteropLibrary lib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetName");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetName");
}
o.setNamePtr(lib.isNull(namePtr) ? null : namePtr);
return 0;
@@ -278,8 +277,8 @@ static int set(PyCapsule o, Object namePtr,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetName");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetName");
}
}
@@ -289,9 +288,9 @@ abstract static class PyCapsule_SetDestructor extends CApiBinaryBuiltinNode {
static int doCapsule(PyCapsule o, Object destructor,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "1") InteropLibrary lib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetDestructor");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetDestructor");
}
o.registerDestructor(lib.isNull(destructor) ? null : destructor);
return 0;
@@ -299,8 +298,8 @@ static int doCapsule(PyCapsule o, Object destructor,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetDestructor");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetDestructor");
}
}
@@ -309,9 +308,9 @@ abstract static class PyCapsule_SetContext extends CApiBinaryBuiltinNode {
@Specialization
static int doCapsule(PyCapsule o, Object context,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (o.getPointer() == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetContext");
+ throw raiseNode.raise(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetContext");
}
o.setContext(context);
return 0;
@@ -319,8 +318,8 @@ static int doCapsule(PyCapsule o, Object context,
@Fallback
static Object doError(@SuppressWarnings("unused") Object o, @SuppressWarnings("unused") Object name,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetContext");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetContext");
}
}
@@ -335,7 +334,7 @@ static Object doGeneric(Object namePtr, @SuppressWarnings("unused") int noBlock,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
@Cached TruffleString.SubstringNode substringNode,
@Cached ReadAttributeFromObjectNode getAttrNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString name = (TruffleString) charPtrToPythonNode.execute(namePtr);
TruffleString trace = name;
Object object = null;
@@ -361,7 +360,7 @@ static Object doGeneric(Object namePtr, @SuppressWarnings("unused") int noBlock,
if (capsule != null && PyCapsule_IsValid.doCapsule(capsule, namePtr, inliningTarget, nameMatchesNode) == 1) {
return capsule.getPointer();
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, PY_CAPSULE_IMPORT_S_IS_NOT_VALID, name);
+ throw raiseNode.raise(inliningTarget, AttributeError, PY_CAPSULE_IMPORT_S_IS_NOT_VALID, name);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
index a7a603d441..d542cf7d3b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java
@@ -64,7 +64,7 @@ abstract static class PyInstanceMethod_New extends CApiUnaryBuiltinNode {
static Object staticmethod(Object func,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, func, raiseNode);
PDecoratedMethod res = PFactory.createInstancemethod(language);
res.setCallable(func);
@@ -78,7 +78,7 @@ abstract static class PyMethod_New extends CApiBinaryBuiltinNode {
static Object methodNew(Object func, Object self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, func, self, raiseNode);
// Note: CPython also constructs the object directly, without running the constructor or
// checking the inputs
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
index cf805f5aca..de47d11bf8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java
@@ -123,7 +123,7 @@ static Object asDouble(Object obj,
@Cached CallNode callNode,
@Cached GetClassNode getClassNode,
@Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString name;
if (isComplexSubtypeProfile.profile(inliningTarget, isComplexSubtype(inliningTarget, obj, getClassNode, isSubtypeNode))) {
name = T_REAL;
@@ -133,7 +133,7 @@ static Object asDouble(Object obj,
try {
return callNode.executeWithoutFrame(getAttr.execute(null, inliningTarget, obj, name));
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError);
+ throw raiseNode.raise(inliningTarget, TypeError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
index b131a49166..18842442b5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java
@@ -135,9 +135,9 @@ abstract static class PyContextVar_Set extends CApiBinaryBuiltinNode {
static Object doGeneric(Object var, Object val,
@Bind("this") Node inliningTarget,
@Bind PythonContext pythonContext,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(var instanceof PContextVar pvar)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
}
PythonLanguage language = pythonContext.getLanguage(inliningTarget);
PythonContext.PythonThreadState threadState = pythonContext.getThreadState(language);
@@ -181,7 +181,7 @@ abstract static class PyContext_Enter extends CApiUnaryBuiltinNode {
static Object doGeneric(PContextVarsContext context,
@Bind("this") Node inliningTarget,
@Bind PythonContext pythonContext,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext.PythonThreadState threadState = pythonContext.getThreadState(pythonContext.getLanguage(inliningTarget));
context.enter(inliningTarget, threadState, raiseNode);
return 0;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
index 9edf930793..ca5ebd1eb0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java
@@ -330,9 +330,9 @@ static Object getItem(PDict dict, Object key,
@Specialization(guards = "!isDict(obj)")
static Object getItem(Object obj, @SuppressWarnings("unused") Object key,
- @Cached StrNode strNode,
- @Cached PRaiseNode raiseNode) {
- return raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(null, obj), obj);
+ @Bind("this") Node inliningTarget,
+ @Cached StrNode strNode) {
+ return PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(null, obj), obj);
}
protected boolean isDict(Object obj) {
@@ -394,10 +394,10 @@ static int setItem(PDict dict, Object key, Object value, Object givenHash,
@Cached CastToJavaLongExactNode castToLong,
@Cached SetItemNode setItemNode,
@Cached InlinedBranchProfile wrongHashProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (hashNode.execute(null, inliningTarget, key) != castToLong.execute(inliningTarget, givenHash)) {
wrongHashProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AssertionError, HASH_MISMATCH);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AssertionError, HASH_MISMATCH);
}
setItemNode.execute(null, inliningTarget, dict, key, value);
return 0;
@@ -524,10 +524,10 @@ static int merge(PDict a, Object b, @SuppressWarnings("unused") int override,
@Cached PyObjectLookupAttr lookupKeys,
@Cached PyObjectLookupAttr lookupAttr,
@Shared @Cached CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// lookup "keys" to raise the right error:
if (lookupKeys.execute(null, inliningTarget, b, T_KEYS) == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, OBJ_P_HAS_NO_ATTR_S, b, T_KEYS);
+ throw raiseNode.raise(inliningTarget, AttributeError, OBJ_P_HAS_NO_ATTR_S, b, T_KEYS);
}
Object updateCallable = lookupAttr.execute(null, inliningTarget, a, T_UPDATE);
callNode.executeWithoutFrame(updateCallable, new Object[]{b});
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
index 407591b9e2..d1998526b6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextErrBuiltins.java
@@ -308,11 +308,10 @@ Object run(Object typ, PBaseException val, Object tb) {
abstract static class _PyTruffleErr_CreateAndSetException extends CApiBinaryBuiltinNode {
@Specialization(guards = "!isExceptionClass(inliningTarget, type, isTypeNode, isSubClassNode)")
static Object create(Object type, @SuppressWarnings("unused") Object value,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached IsTypeNode isTypeNode,
@SuppressWarnings("unused") @Shared @Cached IsSubClassNode isSubClassNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, EXCEPTION_NOT_BASEEXCEPTION, new Object[]{type});
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, EXCEPTION_NOT_BASEEXCEPTION, new Object[]{type});
}
@Specialization(guards = "isExceptionClass(inliningTarget, type, isTypeNode, isSubClassNode)")
@@ -346,7 +345,7 @@ static Object newEx(TruffleString name, Object base, Object dict,
@Cached InlinedBranchProfile notDotProfile,
@Cached InlinedBranchProfile notModuleProfile,
@Cached InlinedConditionProfile baseProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (base == PNone.NO_VALUE) {
base = PythonErrorType.Exception;
}
@@ -357,7 +356,7 @@ static Object newEx(TruffleString name, Object base, Object dict,
int dotIdx = indexOfCodepointNode.execute(name, '.', 0, length, TS_ENCODING);
if (dotIdx < 0) {
notDotProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(SystemError, MUST_BE_MODULE_CLASS, "PyErr_NewException", "name");
+ throw raiseNode.raise(inliningTarget, SystemError, MUST_BE_MODULE_CLASS, "PyErr_NewException", "name");
}
if (getItem.execute(null, inliningTarget, ((PDict) dict).getDictStorage(), base) == null) {
notModuleProfile.enter(inliningTarget);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFileBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFileBuiltins.java
index 4bf832f020..05633e8c4d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFileBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFileBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,7 +71,7 @@ static int writeStr(Object obj, Object f, int flags,
@Cached ReprNode reprNode,
@Cached PyObjectGetAttr getAttr,
@Cached CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, obj, raiseNode);
checkNonNullArg(inliningTarget, f, raiseNode);
Object value;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFloatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFloatBuiltins.java
index bdbaa62a28..9e083a04c5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFloatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextFloatBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -73,10 +73,10 @@ static double fromDouble(double d) {
@Specialization(guards = "!isDouble(obj)")
static Object fromDouble(Object obj,
- @Cached StrNode strNode,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget,
+ @Cached StrNode strNode) {
// cpython PyFloat_FromDouble takes only 'double'
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(null, obj), obj);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(null, obj), obj);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
index 4e3c3b4657..57603cb639 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextListBuiltins.java
@@ -98,8 +98,8 @@ public final class PythonCextListBuiltins {
abstract static class PyList_New extends CApiUnaryBuiltinNode {
@Specialization(guards = "size < 0")
static Object newListError(long size,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, size);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, size);
}
@SuppressWarnings("unused")
@@ -132,11 +132,11 @@ static Object doPList(PList list, long key,
@Cached ListGeneralizationNode generalizationNode,
@Cached SetItemScalarNode setItemNode,
@Cached GetItemScalarNode getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage sequenceStorage = list.getSequenceStorage();
// we must do a bounds-check but we must not normalize the index
if (key < 0 || key >= sequenceStorage.length()) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.LIST_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.LIST_INDEX_OUT_OF_RANGE);
}
Object result = getItemNode.execute(inliningTarget, sequenceStorage, (int) key);
Object promotedValue = promoteNode.execute(inliningTarget, result);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
index 168e515605..9552018377 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java
@@ -229,7 +229,7 @@ static Object doGeneric(Object object, int mode, long targetTypeSize,
@Cached GetClassNode getClassNode,
@Cached ConvertPIntToPrimitiveNode convertPIntToPrimitiveNode,
@Cached CastToNativeLongNode castToNativeLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
/*
* The 'mode' parameter is usually a constant since this function is primarily used
@@ -237,7 +237,7 @@ static Object doGeneric(Object object, int mode, long targetTypeSize,
* profile the value and even if it is not constant, it is profiled implicitly.
*/
if (requiredPInt(mode) && !isSubtypeNode.execute(getClassNode.execute(inliningTarget, object), PythonBuiltinClassType.PInt)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
// the 'ConvertPIntToPrimitiveNode' uses 'AsNativePrimitive' which does coercion
Object coerced = convertPIntToPrimitiveNode.execute(inliningTarget, object, signed(mode), PInt.intValueExact(targetTypeSize), exact(mode));
@@ -353,13 +353,13 @@ static long doPointer(long n) {
long doPointer(PInt n,
@Bind("this") Node inliningTarget,
@Cached InlinedBranchProfile overflowProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
return n.longValueExact();
} catch (OverflowException e) {
overflowProfile.enter(inliningTarget);
try {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
} catch (PException pe) {
ensureTransformExcNode().executeCached(pe);
return 0;
@@ -375,7 +375,7 @@ static Object doPointer(PythonNativeVoidPtr n) {
@Fallback
long doGeneric(Object n,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (asPrimitiveNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
asPrimitiveNode = insert(ConvertPIntToPrimitiveNodeGen.create());
@@ -384,7 +384,7 @@ long doGeneric(Object n,
try {
return asPrimitiveNode.executeLongCached(n, 0, Long.BYTES);
} catch (UnexpectedResultException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
}
} catch (PException e) {
ensureTransformExcNode().executeCached(e);
@@ -403,10 +403,10 @@ private TransformExceptionToNativeNode ensureTransformExcNode() {
@CApiBuiltin(ret = Int, args = {PyLongObject, UNSIGNED_CHAR_PTR, SIZE_T, Int, Int}, call = Direct)
abstract static class _PyLong_AsByteArray extends CApi5BuiltinNode {
- private static void checkSign(Node inliningTarget, boolean negative, int isSigned, PRaiseNode.Lazy raiseNode) {
+ private static void checkSign(Node inliningTarget, boolean negative, int isSigned, PRaiseNode raiseNode) {
if (negative) {
if (isSigned == 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
}
}
}
@@ -416,7 +416,7 @@ static Object get(int value, Object bytes, long n, int littleEndian, int isSigne
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile profile,
@Shared @Cached CStructAccess.WriteByteNode write,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkSign(inliningTarget, value < 0, isSigned, raiseNode);
byte[] array = IntBuiltins.ToBytesNode.fromLong(value, PythonUtils.toIntError(n), littleEndian == 0, isSigned != 0, inliningTarget, profile, raiseNode);
write.writeByteArray(bytes, array);
@@ -428,7 +428,7 @@ static Object get(long value, Object bytes, long n, int littleEndian, int isSign
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile profile,
@Shared @Cached CStructAccess.WriteByteNode write,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkSign(inliningTarget, value < 0, isSigned, raiseNode);
byte[] array = IntBuiltins.ToBytesNode.fromLong(value, PythonUtils.toIntError(n), littleEndian == 0, isSigned != 0, inliningTarget, profile, raiseNode);
write.writeByteArray(bytes, array);
@@ -440,7 +440,7 @@ static Object get(PInt value, Object bytes, long n, int littleEndian, int isSign
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile profile,
@Shared @Cached CStructAccess.WriteByteNode write,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkSign(inliningTarget, value.isNegative(), isSigned, raiseNode);
byte[] array = IntBuiltins.ToBytesNode.fromBigInteger(value, PythonUtils.toIntError(n), littleEndian == 0, isSigned != 0, inliningTarget, profile, raiseNode);
write.writeByteArray(bytes, array);
@@ -465,9 +465,9 @@ static Object convert(Object charPtr, long size, int littleEndian, int signed,
@Bind("this") Node inliningTarget,
@Cached CStructAccess.ReadByteNode readByteNode,
@Cached IntNodes.PyLongFromByteArray fromByteArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (size != (int) size) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
}
byte[] bytes = readByteNode.readByteArray(charPtr, (int) size);
return fromByteArray.execute(inliningTarget, bytes, littleEndian != 0, signed != 0);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMemoryViewBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMemoryViewBuiltins.java
index a2c42d09ae..4a3b96e430 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMemoryViewBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMemoryViewBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -85,7 +85,7 @@ static Object get(Object obj, int buffertype, byte orderByte,
@Cached ContiguousNode contiguousNode,
@Cached TruffleString.EqualNode eqNode,
@Cached TruffleString.FromCodePointNode fromCodePointNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
assert buffertype == PY_BUF_READ || buffertype == PY_BUF_WRITE;
char order = (char) orderByte;
assert order == 'C' || order == 'F' || order == 'A';
@@ -94,14 +94,14 @@ static Object get(Object obj, int buffertype, byte orderByte,
boolean release = true;
try {
if (buffertype == PY_BUF_WRITE && mv.isReadOnly()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, UNDERLYING_BUFFER_IS_NOT_WRITABLE);
+ throw raiseNode.raise(inliningTarget, BufferError, UNDERLYING_BUFFER_IS_NOT_WRITABLE);
}
if ((boolean) contiguousNode.execute(null, mv)) {
release = false;
return mv;
}
if (buffertype == PY_BUF_WRITE) {
- throw raiseNode.get(inliningTarget).raise(BufferError, WRITABLE_CONTIGUES_FOR_NON_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, WRITABLE_CONTIGUES_FOR_NON_CONTIGUOUS);
}
PMemoryView mvBytes = memoryViewFromObject.execute(null, toBytesNode.execute(null, mv, fromCodePointNode.execute(order, TS_ENCODING, true)));
if (eqNode.execute(T_UINT_8_TYPE_CODE, mv.getFormatString(), TS_ENCODING)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java
index 7f59cc181f..ec82881d57 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -177,7 +177,7 @@ static Object getName(PythonModule module,
Object nameAttr = read.execute(module, T___NAME__);
if (!pyUnicodeCheckNode.execute(inliningTarget, nameAttr)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.NAMELESS_MODULE);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.NAMELESS_MODULE);
}
Object promotedName = promoteBorrowedValue.execute(inliningTarget, nameAttr);
if (promotedName == null) {
@@ -209,11 +209,10 @@ static Object addObject(Object m, TruffleString k, Object o,
@SuppressWarnings("unused")
@Specialization(guards = "!isModuleSubtype(inliningTarget, m, getClassNode, isSubtypeNode)")
static Object pop(Object m, Object key, Object defaultValue,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, S_NEEDS_S_AS_FIRST_ARG, "PyModule_AddObjectRef", "module");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, S_NEEDS_S_AS_FIRST_ARG, "PyModule_AddObjectRef", "module");
}
}
@@ -232,11 +231,10 @@ static Object addObject(Object m, TruffleString k, long o,
@Specialization(guards = "!isModuleSubtype(inliningTarget, m, getClassNode, isSubtypeNode)")
static Object pop(@SuppressWarnings("unused") Object m, @SuppressWarnings("unused") Object key, @SuppressWarnings("unused") Object defaultValue,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, S_NEEDS_S_AS_FIRST_ARG, "PyModule_AddIntConstant", "module");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, S_NEEDS_S_AS_FIRST_ARG, "PyModule_AddIntConstant", "module");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
index bb596034d9..d2ff8dc9e6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
@@ -433,7 +433,7 @@ static Object asFileDescriptor(Object obj,
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
@Cached TruffleString.EqualNode eqNode,
@Cached PyObjectAsFileDescriptor asFileDescriptorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!longCheckNode.execute(inliningTarget, obj)) {
Object posixSupport = PythonContext.get(inliningTarget).getPosixSupport();
if (eqNode.execute(T_JAVA, posixLib.getBackend(posixSupport), TS_ENCODING)) {
@@ -441,7 +441,7 @@ static Object asFileDescriptor(Object obj,
* For non Python 'int' objects, we refuse to hand out the fileno field when
* using the emulated Posix backend, because it is likely a fake.
*/
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.S_NOT_SUPPORTED_ON_JAVA_POSIX_BACKEND, "PyObject_AsFileDescriptor");
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.S_NOT_SUPPORTED_ON_JAVA_POSIX_BACKEND, "PyObject_AsFileDescriptor");
}
}
return asFileDescriptorNode.execute(null, inliningTarget, obj);
@@ -488,8 +488,8 @@ static int hasAttr(Object obj, Object attr,
abstract static class PyObject_HashNotImplemented extends CApiUnaryBuiltinNode {
@Specialization
static Object unhashable(Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, UNHASHABLE_TYPE_P, obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, UNHASHABLE_TYPE_P, obj);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPickleBufferBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPickleBufferBuiltins.java
index 34e56c14f5..e3e6b1731e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPickleBufferBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPickleBufferBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -65,13 +65,13 @@ abstract static class PyTruffle_PickleBuffer_viewobj extends CApiUnaryBuiltinNod
static Object getviewobj(PPickleBuffer object,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object owner = null;
if (object.getView() != null) {
owner = bufferLib.getOwner(object.getView());
}
if (owner == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
}
return owner;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPythonRunBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPythonRunBuiltins.java
index df7d577fd7..69a83f53f5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPythonRunBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextPythonRunBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -69,7 +69,6 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -89,7 +88,7 @@ static Object run(Object source, int type, Object globals, Object locals, @Suppr
@SuppressWarnings("unused") @Exclusive @Cached PyMappingCheckNode isMapping,
@Cached PyObjectLookupAttr lookupNode,
@Cached CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonModule builtins = PythonContext.get(inliningTarget).getBuiltins();
Object compileCallable = lookupNode.execute(null, inliningTarget, builtins, T_COMPILE);
TruffleString stype;
@@ -100,7 +99,7 @@ static Object run(Object source, int type, Object globals, Object locals, @Suppr
} else if (type == Py_eval_input) {
stype = StringLiterals.T_EVAL;
} else {
- throw raiseNode.get(inliningTarget).raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
Object code = callNode.executeWithoutFrame(compileCallable, source, stype, stype);
Object execCallable = lookupNode.execute(null, inliningTarget, builtins, type == Py_eval_input ? T_EVAL : T_EXEC);
@@ -110,17 +109,16 @@ static Object run(Object source, int type, Object globals, Object locals, @Suppr
@Specialization(guards = "!isString(source) || !isDict(globals)")
static Object run(@SuppressWarnings("unused") Object source, @SuppressWarnings("unused") int type, @SuppressWarnings("unused") Object globals,
@SuppressWarnings("unused") Object locals, @SuppressWarnings("unused") Object flags,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
@Specialization(guards = {"isString(source)", "isDict(globals)", "!isMapping.execute(inliningTarget, locals)"}, limit = "1")
static Object run(@SuppressWarnings("unused") Object source, @SuppressWarnings("unused") int type, @SuppressWarnings("unused") Object globals, Object locals,
@SuppressWarnings("unused") Object flags,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Exclusive @Cached PyMappingCheckNode isMapping,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, locals);
+ @Bind("this") Node inliningTarget,
+ @SuppressWarnings("unused") @Exclusive @Cached PyMappingCheckNode isMapping) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, locals);
}
protected static boolean checkArgs(Object source, Object globals, Object locals, Node inliningTarget, PyMappingCheckNode isMapping) {
@@ -133,7 +131,7 @@ abstract static class Py_CompileString extends CApiTernaryBuiltinNode {
@Specialization(guards = {"isString(source)", "isString(filename)"})
static Object compile(Object source, Object filename, int type,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectLookupAttr lookupNode,
@Cached CallNode callNode) {
return Py_CompileStringExFlags.compile(source, filename, type, null, -1, inliningTarget, raiseNode, lookupNode, callNode);
@@ -142,8 +140,8 @@ static Object compile(Object source, Object filename, int type,
@SuppressWarnings("unused")
@Specialization(guards = "!isString(source) || !isString(filename)")
static Object fail(Object source, Object filename, Object type,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
}
@@ -153,7 +151,7 @@ abstract static class Py_CompileStringExFlags extends CApi5BuiltinNode {
static Object compile(Object source, Object filename, int type,
@SuppressWarnings("unused") Object flags, int optimizationLevel,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectLookupAttr lookupNode,
@Cached CallNode callNode) {
PythonModule builtins = PythonContext.get(lookupNode).getCore().getBuiltins();
@@ -166,7 +164,7 @@ static Object compile(Object source, Object filename, int type,
} else if (type == Py_eval_input) {
stype = StringLiterals.T_EVAL;
} else {
- throw raiseNode.get(inliningTarget).raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
int defaultFlags = 0;
boolean dontInherit = false;
@@ -176,8 +174,8 @@ static Object compile(Object source, Object filename, int type,
@SuppressWarnings("unused")
@Specialization(guards = "!isString(source) || !isString(filename)")
static Object fail(Object source, Object filename, Object type, Object flags, Object optimizationLevel,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
}
@@ -188,7 +186,7 @@ static Object compile(Object source, Object filename, int type,
@SuppressWarnings("unused") Object flags,
int optimizationLevel,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectLookupAttr lookupNode,
@Cached CallNode callNode) {
return Py_CompileStringExFlags.compile(source, filename, type, null, optimizationLevel, inliningTarget, raiseNode, lookupNode, callNode);
@@ -197,8 +195,8 @@ static Object compile(Object source, Object filename, int type,
@SuppressWarnings("unused")
@Specialization(guards = "!isString(source)")
static Object fail(Object source, Object filename, Object type, Object flags, Object optimizationLevel,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
index c887fbe379..e52002b3f0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
@@ -169,21 +169,19 @@ static Object nextEntry(@SuppressWarnings("unused") Object set, @SuppressWarning
@Specialization(guards = {"!isPSet(anyset)", "!isPFrozenSet(anyset)", "isSetSubtype(inliningTarget, anyset, getClassNode, isSubtypeNode)"})
static Object nextNative(@SuppressWarnings("unused") Object anyset, @SuppressWarnings("unused") Object pos,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "set");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "set");
}
@Specialization(guards = {"!isPSet(anyset)", "!isPFrozenSet(anyset)", "!isSetSubtype(inliningTarget, anyset, getClassNode, isSubtypeNode)"})
static Object nextEntry(Object anyset, @SuppressWarnings("unused") Object pos,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
@Cached StrNode strNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(anyset), anyset);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(anyset), anyset);
}
protected boolean isSetSubtype(Node inliningTarget, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -285,8 +283,8 @@ static int add(PBaseSet self, Object o,
@Specialization(guards = "!isAnySet(self)")
static int add(Object self, @SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, EXPECTED_S_NOT_P, "a set object", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, EXPECTED_S_NOT_P, "a set object", self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
index 19fd093562..81c957989e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java
@@ -161,11 +161,11 @@ static Object doGeneric(Object cls,
@Cached CastToJavaIntExactNode castToIntNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
Object realSizeObj = readRealSizeNode.execute(cls, StructSequence.T_N_FIELDS);
if (realSizeObj == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC, EMPTY_OBJECT_ARRAY);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC, EMPTY_OBJECT_ARRAY);
} else {
int realSize = castToIntNode.execute(inliningTarget, realSizeObj);
Object[] values = new Object[realSize];
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
index 94356e0df5..8ef9b5e324 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java
@@ -88,11 +88,11 @@ abstract static class PyTuple_New extends CApiUnaryBuiltinNode {
static PTuple doGeneric(long longSize,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached CStructAccess.AllocateNode alloc) {
int size = (int) longSize;
if (longSize != size) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.MemoryError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.MemoryError);
}
/*
* Already allocate the tuple with native memory, since it has to be populated from the
@@ -116,7 +116,7 @@ static Object doPTuple(PTuple tuple, long key,
@Cached ListGeneralizationNode generalizationNode,
@Shared @Cached SetItemScalarNode setItemNode,
@Shared @Cached GetItemScalarNode getItemNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage sequenceStorage = tuple.getSequenceStorage();
int index = checkIndex(inliningTarget, key, sequenceStorage, raiseNode);
Object result = getItemNode.execute(inliningTarget, sequenceStorage, index);
@@ -138,7 +138,7 @@ static Object doNative(PythonAbstractNativeObject tuple, long key,
@Shared("promote") @Cached PromoteBorrowedValue promoteNode,
@Shared @Cached SetItemScalarNode setItemNode,
@Shared @Cached GetItemScalarNode getItemNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage sequenceStorage = asNativeStorage.execute(tuple);
int index = checkIndex(inliningTarget, key, sequenceStorage, raiseNode);
Object result = getItemNode.execute(inliningTarget, sequenceStorage, index);
@@ -158,10 +158,10 @@ Object fallback(Object tuple, @SuppressWarnings("unused") Object pos) {
throw raiseFallback(tuple, PythonBuiltinClassType.PTuple);
}
- private static int checkIndex(Node inliningTarget, long key, SequenceStorage sequenceStorage, PRaiseNode.Lazy raiseNode) {
+ private static int checkIndex(Node inliningTarget, long key, SequenceStorage sequenceStorage, PRaiseNode raiseNode) {
// we must do a bounds-check but we must not normalize the index
if (key < 0 || key >= sequenceStorage.length()) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.TUPLE_OUT_OF_BOUNDS);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.TUPLE_OUT_OF_BOUNDS);
}
return (int) key;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
index d7cc998246..9ec25257b8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java
@@ -188,8 +188,9 @@ abstract static class PyTruffle_Compute_Mro extends CApiBinaryBuiltinNode {
@Specialization
@TruffleBoundary
- static Object doIt(PythonNativeClass self, TruffleString className) {
- PythonAbstractClass[] doSlowPath = TypeNodes.ComputeMroNode.doSlowPath(self);
+ static Object doIt(PythonNativeClass self, TruffleString className,
+ @Bind("this") Node inliningTarget) {
+ PythonAbstractClass[] doSlowPath = TypeNodes.ComputeMroNode.doSlowPath(inliningTarget, self);
return PFactory.createTuple(PythonLanguage.get(null), new MroSequenceStorage(className, doSlowPath));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
index 4dbf93ba44..340340700e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
@@ -227,11 +227,10 @@ static Object fromObject(Object obj,
@Specialization(guards = {"!isStringSubtype(inliningTarget, obj, getClassNode, isSubtypeNode)"})
static Object fromObject(Object obj,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_CONVERT_TO_STR_IMPLICITLY, obj);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_CONVERT_TO_STR_IMPLICITLY, obj);
}
protected boolean isPStringType(Node inliningTarget, Object obj, GetClassNode getClassNode) {
@@ -255,20 +254,18 @@ static Object concat(Object left, Object right,
@Specialization(guards = {"!isString(left)", "!isStringSubtype(inliningTarget, left, getClassNode, isSubtypeNode)"})
static Object leftNotString(Object left, @SuppressWarnings("unused") Object right,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, left);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, left);
}
@Specialization(guards = {"!isString(right)", "!isStringSubtype(inliningTarget, right, getClassNode, isSubtypeNode)"})
static Object rightNotString(@SuppressWarnings("unused") Object left, Object right,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, right);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, right);
}
}
@@ -301,7 +298,7 @@ static Object doGeneric(Object obj, Object encodingObj, Object errorsObj,
errors = (TruffleString) errorsObjProfiled;
}
if (nullProfile.profile(inliningTarget, obj == PNone.NO_VALUE)) {
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
return decodeNode.execute(null, inliningTarget, obj, encoding, errors);
}
@@ -364,7 +361,7 @@ static Object find(Object format, Object args,
@Cached ModNode modNode,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, format, args, raiseNode);
return modNode.execute(null, format, args);
}
@@ -374,9 +371,9 @@ static Object find(Object format, @SuppressWarnings("unused") Object args,
@Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkNonNullArg(inliningTarget, format, args, raiseNode);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, format);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, format);
}
}
@@ -407,11 +404,10 @@ static Object find(Object string, Object c, long start, long end, @SuppressWarni
@Specialization(guards = {"!isTruffleString(string)", "!isStringSubtype(inliningTarget, string, getClassNode, isSubtypeNode)"})
static Object find(Object string, @SuppressWarnings("unused") Object c, @SuppressWarnings("unused") Object start, @SuppressWarnings("unused") Object end,
@SuppressWarnings("unused") Object direction,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, string);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, string);
}
}
@@ -429,7 +425,7 @@ static Object doString(Object s, long start, long end,
@SuppressWarnings("unused") @Exclusive @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode) {
if (profile.profile(inliningTarget, start < 0 || end < 0)) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw PRaiseNode.raiseStatic(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
Object getItemCallable = lookupAttrNode.execute(null, inliningTarget, s, T___GETITEM__);
return callNode.executeWithoutFrame(getItemCallable, sliceNode.execute(inliningTarget, start, end, PNone.NONE));
@@ -437,11 +433,10 @@ static Object doString(Object s, long start, long end,
@Specialization(guards = {"!isTruffleString(s)", "isStringSubtype(s, inliningTarget, getClassNode, isSubtypeNode)"}, limit = "1")
static Object doError(Object s, @SuppressWarnings("unused") Object start, @SuppressWarnings("unused") Object end,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, s);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, s);
}
protected static boolean isStringSubtype(Object obj, Node n, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -463,11 +458,10 @@ static Object find(Object separator, Object seq,
@Specialization(guards = {"!isTruffleString(separator)", "isStringSubtype(inliningTarget, separator, getClassNode, isSubtypeNode)"})
static Object find(Object separator, @SuppressWarnings("unused") Object seq,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, separator);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, separator);
}
}
@@ -487,11 +481,10 @@ static Object compare(Object left, Object right,
@Specialization(guards = {"!isAnyString(inliningTarget, left, getClassNode, isSubtypeNode) || !isAnyString(inliningTarget, right, getClassNode, isSubtypeNode)"})
static Object compare(Object left, Object right,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_COMPARE, left, right);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_COMPARE, left, right);
}
}
@@ -526,11 +519,10 @@ static Object compare(Object left, Object right,
@Specialization(guards = {"!isAnyString(inliningTarget, left, getClassNode, isSubtypeNode) || !isAnyString(inliningTarget, right, getClassNode, isSubtypeNode)"})
static Object compare(Object left, Object right,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_COMPARE, left, right);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_COMPARE, left, right);
}
}
@@ -569,11 +561,10 @@ static int tailmatch(Object string, Object substring, long start, long end, @Sup
@SuppressWarnings("unused")
@Specialization(guards = {"!isAnyString(inliningTarget, string, getClassNode, isSubtypeNode) || !isAnyString(inliningTarget, substring, getClassNode, isSubtypeNode)"})
static Object find(Object string, Object substring, Object start, Object end, Object direction,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached GetClassNode getClassNode,
@Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_STR_NOT_P, string);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, string);
}
}
@@ -591,11 +582,10 @@ static Object encode(Object obj, Object encoding, Object errors,
@Specialization(guards = {"!isString(obj)", "!isStringSubtype(inliningTarget, obj, getClassNode, isSubtypeNode)"})
static Object encode(@SuppressWarnings("unused") Object obj, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -657,11 +647,10 @@ static Object escape(Object s,
@Specialization(guards = {"!isString(obj)", "!isStringSubtype(inliningTarget, obj, getClassNode, isSubtypeNode)"})
static Object escape(@SuppressWarnings("unused") Object obj,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached GetClassNode getClassNode,
@SuppressWarnings("unused") @Shared @Cached IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -673,19 +662,19 @@ static int doGeneric(Object type, long lindex,
@Cached CastToTruffleStringNode castToStringNode,
@Cached TruffleString.CodePointLengthNode lengthNode,
@Cached TruffleString.CodePointAtIndexNode codepointAtIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
TruffleString s = castToStringNode.execute(inliningTarget, type);
int index = PInt.intValueExact(lindex);
// avoid StringIndexOutOfBoundsException
if (index < 0 || index >= lengthNode.execute(s, TS_ENCODING)) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
return codepointAtIndexNode.execute(s, index, TS_ENCODING);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
}
}
@@ -702,12 +691,12 @@ static Object doGeneric(Object ptr, long elements, long elementSize, int isAscii
@CApiBuiltin(ret = PyObjectTransfer, args = {Pointer, Py_ssize_t, Int}, call = Ignored)
abstract static class PyTruffleUnicode_FromUCS extends CApiTernaryBuiltinNode {
- private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNode.Lazy raiseNode) throws PException {
+ private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNode raiseNode) throws PException {
return switch (kind) {
case 1 -> ISO_8859_1;
case 2 -> UTF_16;
case 4 -> TS_ENCODING;
- default -> throw raiseNode.get(inliningTarget).raiseBadInternalCall();
+ default -> throw raiseNode.raiseBadInternalCall(inliningTarget);
};
}
@@ -717,7 +706,7 @@ static Object doNative(Object ptr, long byteLength, int kind,
@SuppressWarnings("unused") @Shared("ptrLib") @CachedLibrary(limit = "1") InteropLibrary ptrLib,
@Cached FromNativePointerNode fromNativePointerNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
int iByteLength = PInt.intValueExact(byteLength);
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
@@ -729,7 +718,7 @@ static Object doNative(Object ptr, long byteLength, int kind,
TruffleString ts = fromNativePointerNode.execute(ptr, 0, iByteLength, srcEncoding, true);
return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -740,7 +729,7 @@ static Object doManaged(Object ptr, long byteLength, int kind,
@Cached GetByteArrayNode getByteArrayNode,
@Cached FromByteArrayNode fromByteArrayNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
byte[] ucsBytes = getByteArrayNode.execute(inliningTarget, ptr, byteLength);
@@ -751,9 +740,9 @@ static Object doManaged(Object ptr, long byteLength, int kind,
* This means that we cannot read the array-like foreign object or the foreign
* elements cannot be interpreted as bytes. In any case, that's a fatal error.
*/
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.M, e);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
}
@@ -761,12 +750,12 @@ static Object doManaged(Object ptr, long byteLength, int kind,
@CApiBuiltin(ret = PyObjectTransfer, args = {Pointer, Py_ssize_t, Int}, call = Ignored)
abstract static class PyTruffleUnicode_FromUTF extends CApiTernaryBuiltinNode {
- private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNode.Lazy raiseNode) throws PException {
+ private static Encoding encodingFromKind(Node inliningTarget, int kind, PRaiseNode raiseNode) throws PException {
return switch (kind) {
case 1 -> UTF_8;
case 2 -> UTF_16LE;
case 4 -> UTF_32LE;
- default -> throw raiseNode.get(inliningTarget).raiseBadInternalCall();
+ default -> throw raiseNode.raiseBadInternalCall(inliningTarget);
};
}
@@ -776,14 +765,14 @@ static Object doNative(Object ptr, long byteLength, int kind,
@SuppressWarnings("unused") @Shared("ptrLib") @CachedLibrary(limit = "1") InteropLibrary ptrLib,
@Cached FromNativePointerNode fromNativePointerNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
int iByteLength = PInt.intValueExact(byteLength);
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
TruffleString ts = fromNativePointerNode.execute(ptr, 0, iByteLength, srcEncoding, true);
return PFactory.createString(PythonLanguage.get(inliningTarget), switchEncodingNode.execute(ts, TS_ENCODING));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -794,7 +783,7 @@ static Object doManaged(Object ptr, long byteLength, int kind,
@Cached GetByteArrayNode getByteArrayNode,
@Cached FromByteArrayNode fromByteArrayNode,
@Shared("switchEncodingNode") @Cached SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
Encoding srcEncoding = encodingFromKind(inliningTarget, kind, raiseNode);
byte[] ucsBytes = getByteArrayNode.execute(inliningTarget, ptr, byteLength);
@@ -805,9 +794,9 @@ static Object doManaged(Object ptr, long byteLength, int kind,
* This means that we cannot read the array-like foreign object or the foreign
* elements cannot be interpreted as bytes. In any case, that's a fatal error.
*/
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.M, e);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
}
@@ -852,14 +841,14 @@ static Object doUtf8Decode(Object cByteArray, long size, TruffleString errors, i
@Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
return decode.call(null, bytes, T_UTF8, errors, reportConsumed == 0);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
} catch (InteropException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
}
}
}
@@ -873,7 +862,7 @@ static Object decode(Object cByteArray, long size, TruffleString errors, int byt
@Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
TruffleString encoding;
@@ -886,9 +875,9 @@ static Object decode(Object cByteArray, long size, TruffleString errors, int byt
}
return decode.call(null, bytes, encoding, errors, reportConsumed == 0);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
} catch (InteropException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
}
}
}
@@ -902,7 +891,7 @@ static Object decode(Object cByteArray, long size, TruffleString errors, int byt
@Bind PythonLanguage language,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CodecsModuleBuiltins.CodecsDecodeNode decode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PBytes bytes = PFactory.createBytes(language, getByteArrayNode.execute(inliningTarget, cByteArray, size));
TruffleString encoding;
@@ -915,9 +904,9 @@ static Object decode(Object cByteArray, long size, TruffleString errors, int byt
}
return decode.call(null, bytes, encoding, errors, reportConsumed == 0);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.INPUT_TOO_LONG);
} catch (InteropException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
}
}
}
@@ -989,8 +978,8 @@ Object doUnicode(Object s, TruffleString errors,
@Fallback
static Object doUnicode(@SuppressWarnings("unused") Object s, @SuppressWarnings("unused") Object errors,
- @Cached PRaiseNode raiseNode) {
- return raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -1045,8 +1034,8 @@ static Object doUnicode(PString s, Object sizePtr,
@Fallback
@SuppressWarnings("unused")
static Object doError(Object s, Object sizePtr,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -1096,8 +1085,8 @@ static Object doUnicode(PString s, Object sizePtr,
@Fallback
@SuppressWarnings("unused")
static Object doError(Object s, Object sizePtr,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -1133,17 +1122,17 @@ static Object doUnicode(Object s, long elementSize,
@Bind("this") Node inliningTarget,
@Cached UnicodeAsWideCharNode asWideCharNode,
@Cached CastToTruffleStringNode castStr,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PBytes wchars = asWideCharNode.executeLittleEndian(inliningTarget, castStr.execute(inliningTarget, s), elementSize);
if (wchars != null) {
return wchars;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.UNSUPPORTED_SIZE_WAS, "wchar", elementSize);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.UNSUPPORTED_SIZE_WAS, "wchar", elementSize);
}
} catch (IllegalArgumentException e) {
// TODO
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.LookupError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.LookupError, ErrorMessages.M, e);
}
}
}
@@ -1180,14 +1169,14 @@ static Object doit(Object encoding, Object object, long length, long start, long
@Bind("this") Node inliningTarget,
@Cached GetByteArrayNode getByteArrayNode,
@Cached CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PBytes bytes;
try {
bytes = PFactory.createBytes(PythonLanguage.get(inliningTarget), getByteArrayNode.execute(inliningTarget, object, length));
} catch (InteropException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.M, e);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
}
return callNode.executeWithoutFrame(UnicodeDecodeError, encoding, bytes, start, end, reason);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecCtxBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecCtxBuiltins.java
index d92537ce8c..cae8468c93 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecCtxBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecCtxBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -97,13 +97,13 @@ static Object codecctxErrorsSet(MultibyteStatefulCodecContext self, Object value
@Cached TruffleString.EqualNode isEqual,
@Cached CastToTruffleStringNode castToStringNode,
@Cached PyUnicodeCheckNode unicodeCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (value == PNone.NONE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, CANNOT_DELETE);
+ throw raiseNode.raise(inliningTarget, AttributeError, CANNOT_DELETE);
}
if (!unicodeCheckNode.execute(inliningTarget, value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ERRORS_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ERRORS_MUST_BE_A_STRING);
}
TruffleString str = castToStringNode.execute(inliningTarget, value);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
index 2a7e28741d..8a0a6123e9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsCNModuleBuiltins.java
@@ -126,15 +126,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
index 79329e4033..c1a8c13e16 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsHKModuleBuiltins.java
@@ -118,15 +118,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
index fdf58b9d1e..a6ce7e5163 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsISO2022ModuleBuiltins.java
@@ -128,15 +128,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
index 7555de5d80..59352af1c5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsJPModuleBuiltins.java
@@ -150,15 +150,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
index 25f99a0321..33e5a58157 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsKRModuleBuiltins.java
@@ -123,15 +123,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
index 8a71f69d73..283810add0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/CodecsTWModuleBuiltins.java
@@ -118,15 +118,15 @@ static Object getcodec(Object encoding,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached CastToTruffleStringNode asUTF8Node,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_NAME_MUST_BE_A_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_NAME_MUST_BE_A_STRING);
}
MultibyteCodec codec = findCodec(CODEC_LIST, asUTF8Node.execute(inliningTarget, encoding), isEqual);
if (codec == null) {
- throw raiseNode.get(inliningTarget).raise(LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, LookupError, NO_SUCH_CODEC_IS_SUPPORTED);
}
PyCapsule codecobj = PFactory.createCapsuleJavaName(language, codec, PyMultibyteCodec_CAPSULE_NAME);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
index 126804b23c..6a31839447 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecBuiltins.java
@@ -142,12 +142,12 @@ static Object notTS(VirtualFrame frame, MultibyteCodecObject self, Object input,
@Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared @Cached TruffleString.EqualNode isEqual,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object ucvt = input;
if (!unicodeCheck.execute(inliningTarget, input)) {
ucvt = strNode.execute(frame, inliningTarget, input);
if (!unicodeCheck.execute(inliningTarget, ucvt)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, COULDN_T_CONVERT_THE_OBJECT_TO_UNICODE);
+ throw raiseNode.raise(inliningTarget, TypeError, COULDN_T_CONVERT_THE_OBJECT_TO_UNICODE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
index 207f24926a..a62459db0f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java
@@ -183,7 +183,7 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
@Cached(inline = true) CallErrorCallbackNode callErrorCallbackNode,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached EncodeNode encodeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString reason = ILLEGAL_MULTIBYTE_SEQUENCE;
int esize = e;
@@ -197,9 +197,9 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
esize = buf.getInpos();
break;
case MBERR_INTERNAL:
- throw raiseNode.get(inliningTarget).raise(RuntimeError, INTERNAL_CODEC_ERROR);
+ throw raiseNode.raise(inliningTarget, RuntimeError, INTERNAL_CODEC_ERROR);
default:
- throw raiseNode.get(inliningTarget).raise(RuntimeError, UNKNOWN_RUNTIME_ERROR);
+ throw raiseNode.raise(inliningTarget, RuntimeError, UNKNOWN_RUNTIME_ERROR);
}
}
@@ -246,7 +246,7 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
}
if (errors == ERROR_STRICT) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(buf.excobj);
+ throw raiseNode.raiseExceptionObject(inliningTarget, buf.excobj);
// PyCodec_StrictErrors(buf.excobj);
}
@@ -271,7 +271,7 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
}
if (isError) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODING_ERROR_HANDLER_MUST_RETURN);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODING_ERROR_HANDLER_MUST_RETURN);
}
PBytes retstr;
@@ -301,10 +301,10 @@ static int encerror(VirtualFrame frame, MultibyteCodec codec,
newpos += buf.getInlen();
}
} catch (PException exception) {
- throw raiseNode.get(inliningTarget).raise(IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
+ throw raiseNode.raise(inliningTarget, IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
}
if (newpos < 0 || newpos > buf.getInlen()) {
- throw raiseNode.get(inliningTarget).raise(IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
+ throw raiseNode.raise(inliningTarget, IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
}
buf.setInpos(newpos);
@@ -334,7 +334,7 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
@Cached PyLongAsIntNode asSizeNode,
@Cached CastToJavaStringNode toString,
@Cached(inline = true) CallErrorCallbackNode callErrorCallbackNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString reason = ILLEGAL_MULTIBYTE_SEQUENCE;
int esize = e;
@@ -349,9 +349,9 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
esize = buf.remaining();
break;
case MBERR_INTERNAL:
- throw raiseNode.get(inliningTarget).raise(RuntimeError, INTERNAL_CODEC_ERROR);
+ throw raiseNode.raise(inliningTarget, RuntimeError, INTERNAL_CODEC_ERROR);
default:
- throw raiseNode.get(inliningTarget).raise(RuntimeError, UNKNOWN_RUNTIME_ERROR);
+ throw raiseNode.raise(inliningTarget, RuntimeError, UNKNOWN_RUNTIME_ERROR);
}
}
@@ -381,7 +381,7 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
}
if (errors == ERROR_STRICT) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(buf.excobj);
+ throw raiseNode.raiseExceptionObject(inliningTarget, buf.excobj);
// PyCodec_StrictErrors(buf.excobj);
}
@@ -404,7 +404,7 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
}
if (isError) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODING_ERROR_HANDLER_MUST_RETURN);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODING_ERROR_HANDLER_MUST_RETURN);
}
buf.writeStr(toString.execute(retuni));
@@ -416,10 +416,10 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
newpos += buf.getInpos();
}
} catch (PException ee) {
- throw raiseNode.get(inliningTarget).raise(IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
+ throw raiseNode.raise(inliningTarget, IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
}
if (newpos > buf.getInSize()) {
- throw raiseNode.get(inliningTarget).raise(IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
+ throw raiseNode.raise(inliningTarget, IndexError, POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newpos);
}
buf.setInpos(newpos);
@@ -443,14 +443,14 @@ abstract static class EncodeNode extends Node {
@Specialization
static PBytes encode(VirtualFrame frame, Node inliningTarget, MultibyteCodec codec, MultibyteCodecState state, MultibyteEncodeBuffer buf, Object errors, int flags,
@Cached(inline = false) EncodeErrorNode encodeErrorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// if (buf.inlen == 0 && (flags & MBENC_RESET) == 0) {
// return PFactory.createBytes(language, EMPTY_BYTE_ARRAY);
// }
if (buf.getInlen() > (MAXSIZE - 16) / 2) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
while (!buf.isFull()) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
index 94672160ec..265d0c66d8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteDecodeBuffer.java
@@ -129,7 +129,7 @@ protected TruffleString toTString() {
protected void grow(Node raisingNode) {
int newCapacity = 2 * writer.capacity() + 1;
if (newCapacity < 0) {
- throw PRaiseNode.raiseUncached(raisingNode, MemoryError);
+ throw PRaiseNode.raiseStatic(raisingNode, MemoryError);
}
CharBuffer newBuffer = CharBuffer.allocate(newCapacity);
writer.flip();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
index 34f298cf23..8bcaaaadce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteEncodeBuffer.java
@@ -128,7 +128,7 @@ protected void expandOutputBuffer(int esize, Node raisingNode) {
int orgsize = outputBuffer.capacity();
int incsize = esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize;
if (orgsize > MAXSIZE - incsize) {
- throw PRaiseNode.raiseUncached(raisingNode, MemoryError);
+ throw PRaiseNode.raiseStatic(raisingNode, MemoryError);
}
ByteBuffer newBuffer = ByteBuffer.allocate(incsize);
outputBuffer.flip();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
index 8e471c805d..f1458916fe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalDecoderBuiltins.java
@@ -113,7 +113,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
@Cached TruffleString.EqualNode isEqual,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) { // "|s:IncrementalDecoder"
+ @Cached PRaiseNode raiseNode) { // "|s:IncrementalDecoder"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
errors = castToStringNode.execute(inliningTarget, err);
@@ -123,7 +123,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_IS_UNEXPECTED_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, CODEC_IS_UNEXPECTED_TYPE);
}
self.codec = ((MultibyteCodecObject) codec).codec;
@@ -164,7 +164,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object decode(VirtualFrame frame, MultibyteIncrementalDecoderObject self, byte[] input, int end,
@Bind("this") Node inliningTarget,
@Cached MultibyteCodecUtil.DecodeErrorNode decodeErrorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] data = input;
int size = input.length;
@@ -174,7 +174,7 @@ static Object decode(VirtualFrame frame, MultibyteIncrementalDecoderObject self,
byte[] wdata = data;
if (self.pendingsize != 0) {
if (size > MAXSIZE - self.pendingsize) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
wsize = size + self.pendingsize;
wdata = new byte[wsize];
@@ -208,11 +208,11 @@ static Object decode(VirtualFrame frame, MultibyteIncrementalDecoderObject self,
static int decoderAppendPending(Node inliningTarge, MultibyteStatefulDecoderContext ctx,
MultibyteDecodeBuffer buf,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
int npendings = buf.remaining();
if (npendings + ctx.pendingsize > MAXDECPENDING ||
npendings > MAXSIZE - ctx.pendingsize) {
- throw raiseNode.get(inliningTarge).raise(UnicodeError, PENDING_BUFFER_OVERFLOW);
+ throw raiseNode.raise(inliningTarge, UnicodeError, PENDING_BUFFER_OVERFLOW);
}
buf.getRemaining(ctx.pending, ctx.pendingsize, npendings);
ctx.pendingsize += npendings;
@@ -270,7 +270,7 @@ static Object setstate(VirtualFrame frame, MultibyteIncrementalDecoderObject sel
@Cached HiddenAttr.ReadNode readHiddenAttrNode,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] array = getArray.execute(inliningTarget, state.getSequenceStorage());
Object buffer = array[0];
Object statelong = array[1];
@@ -278,7 +278,7 @@ static Object setstate(VirtualFrame frame, MultibyteIncrementalDecoderObject sel
byte[] bufferstr = toBytesNode.execute(frame, buffer);
int buffersize = bufferstr.length;
if (buffersize > MAXDECPENDING) {
- throw raiseNode.get(inliningTarget).raise(UnicodeError, PENDING_BUFFER_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, UnicodeError, PENDING_BUFFER_TOO_LARGE);
}
self.pendingsize = buffersize;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
index 5302fc7ae5..a4ed3ffacb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java
@@ -126,7 +126,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
@Cached TruffleString.EqualNode isEqual,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) { // "|s:IncrementalEncoder"
+ @Cached PRaiseNode raiseNode) { // "|s:IncrementalEncoder"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
@@ -137,7 +137,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object err,
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_IS_UNEXPECTED_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, CODEC_IS_UNEXPECTED_TYPE);
}
self.codec = ((MultibyteCodecObject) codec).codec;
@@ -172,7 +172,7 @@ static Object ts(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Truffl
@Shared @Cached TruffleString.ConcatNode concatNode,
@Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared @Cached TruffleString.SubstringNode substringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString inbuf = ucvt;
TruffleString origpending = null;
if (ctx.pending != null) {
@@ -192,7 +192,7 @@ static Object ts(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Truffl
if (buf.getInpos() < datalen) {
if (datalen - buf.getInpos() > MAXENCPENDING) {
/* normal codecs can't reach here */
- throw raiseNode.get(inliningTarget).raise(UnicodeError, PENDING_BUFFER_OVERFLOW);
+ throw raiseNode.raise(inliningTarget, UnicodeError, PENDING_BUFFER_OVERFLOW);
}
ctx.pending = substringNode.execute(inbuf, buf.getInpos(), datalen, TS_ENCODING, false);
}
@@ -216,12 +216,12 @@ static Object notTS(VirtualFrame frame, MultibyteStatefulEncoderContext ctx, Obj
@Shared @Cached TruffleString.ConcatNode concatNode,
@Shared @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared @Cached TruffleString.SubstringNode substringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object ucvt = unistr;
if (!unicodeCheckNode.execute(inliningTarget, unistr)) {
ucvt = strNode.execute(frame, inliningTarget, unistr);
if (!unicodeCheckNode.execute(inliningTarget, unistr)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, COULDN_T_CONVERT_THE_OBJECT_TO_STR);
+ throw raiseNode.raise(inliningTarget, TypeError, COULDN_T_CONVERT_THE_OBJECT_TO_STR);
}
}
TruffleString str = toTruffleStringNode.execute(inliningTarget, ucvt);
@@ -259,7 +259,7 @@ static Object getstate(MultibyteIncrementalEncoderObject self,
@Cached HiddenAttr.WriteNode writeHiddenAttrNode,
@Cached CodecsModuleBuiltins.CodecsEncodeToJavaBytesNode asUTF8AndSize,
@Cached IntNodes.PyLongFromByteArray fromByteArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* state made up of 1 byte for buffer size, up to MAXENCPENDING*4 bytes for UTF-8
* encoded buffer (each character can use up to 4 bytes), and required bytes for
@@ -274,7 +274,7 @@ static Object getstate(MultibyteIncrementalEncoderObject self,
byte[] pendingbuffer = asUTF8AndSize.execute(self.pending, T_UTF8, T_STRICT);
int pendingsize = pendingbuffer.length;
if (pendingsize > MAXENCPENDING * 4) {
- throw raiseNode.get(inliningTarget).raise(UnicodeError, PENDING_BUFFER_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, UnicodeError, PENDING_BUFFER_TOO_LARGE);
}
statebytes[0] = (byte) pendingsize;
PythonUtils.arraycopy(pendingbuffer, 0, statebytes, 1, pendingsize);
@@ -301,13 +301,13 @@ static Object setstate(MultibyteIncrementalEncoderObject self, PInt statelong,
@Bind("this") Node inliningTarget,
@Cached HiddenAttr.ReadNode readHiddenAttrNode,
@Cached IntNodes.PyLongAsByteArray asByteArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int sizeOfStateBytes = 1 + MAXENCPENDING * 4 + MULTIBYTECODECSTATE;
byte[] statebytes = asByteArray.execute(inliningTarget, statelong, sizeOfStateBytes, false);
if (statebytes[0] > MAXENCPENDING * 4) {
- throw raiseNode.get(inliningTarget).raise(UnicodeError, PENDING_BUFFER_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, UnicodeError, PENDING_BUFFER_TOO_LARGE);
}
self.pending = decodeUTF8(statebytes, 1, statebytes[0]);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
index 02e9cf81ac..e99bb6d1ea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamReaderBuiltins.java
@@ -109,7 +109,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object stream,
@Cached TruffleString.EqualNode isEqual,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) { // "O|s:StreamReader"
+ @Cached PRaiseNode raiseNode) { // "O|s:StreamReader"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
@@ -119,7 +119,7 @@ static Object mbstreamreaderNew(VirtualFrame frame, Object type, Object stream,
MultibyteStreamReaderObject self = PFactory.createMultibyteStreamReaderObject(language, type, getInstanceShape.execute(type));
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_IS_UNEXPECTED_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, CODEC_IS_UNEXPECTED_TYPE);
}
self.codec = ((MultibyteCodecObject) codec).codec;
@@ -156,7 +156,7 @@ static TruffleString iread(VirtualFrame frame, MultibyteStreamReaderObject self,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached TypeNodes.GetNameNode getNameNode,
@Cached MultibyteCodecUtil.DecodeErrorNode decodeErrorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (sizehint == 0) {
return T_EMPTY_STRING;
@@ -173,7 +173,7 @@ static TruffleString iread(VirtualFrame frame, MultibyteStreamReaderObject self,
if (!(cres instanceof PBytes)) {
Object crestType = getClassNode.execute(inliningTarget, cres);
if (!bytesCheckNode.execute(inliningTarget, crestType)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, STREAM_FUNCTION_RETURNED_A_NON_BYTES_OBJECT_S, getNameNode.execute(inliningTarget, cres));
+ throw raiseNode.raise(inliningTarget, TypeError, STREAM_FUNCTION_RETURNED_A_NON_BYTES_OBJECT_S, getNameNode.execute(inliningTarget, cres));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
index f00753fc89..f18ce75768 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteStreamWriterBuiltins.java
@@ -108,7 +108,7 @@ static Object mbstreamwriterNew(VirtualFrame frame, Object type, Object stream,
@Cached TruffleString.EqualNode isEqual,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) { // "O|s:StreamWriter"
+ @Cached PRaiseNode raiseNode) { // "O|s:StreamWriter"
TruffleString errors = null;
if (err != PNone.NO_VALUE) {
errors = castToStringNode.execute(inliningTarget, err);
@@ -118,7 +118,7 @@ static Object mbstreamwriterNew(VirtualFrame frame, Object type, Object stream,
Object codec = getAttr.execute(frame, inliningTarget, type, StringLiterals.T_CODEC);
if (!(codec instanceof MultibyteCodecObject)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CODEC_IS_UNEXPECTED_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, CODEC_IS_UNEXPECTED_TYPE);
}
self.codec = ((MultibyteCodecObject) codec).codec;
@@ -185,8 +185,8 @@ static Object writelines(VirtualFrame frame, MultibyteStreamWriterObject self, P
// assuming !pySequenceCheck.execute(lines)
@Fallback
static Object writelines(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object lines,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARG_MUST_BE_A_SEQUENCE_OBJECT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARG_MUST_BE_A_SEQUENCE_OBJECT);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
index 2ad485b8a1..0089eb2fcb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibytecodecModuleBuiltins.java
@@ -127,14 +127,14 @@ abstract static class CreateCodecNode extends PythonUnaryBuiltinNode {
@Specialization
static Object createCodec(PyCapsule arg,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
return createCodec(inliningTarget, arg, raiseNode);
}
static Object createCodec(Node inliningTarget, PyCapsule arg,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (!PyCapsule.capsuleJavaNameIs(arg, PyMultibyteCodec_CAPSULE_NAME)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ARGUMENT_TYPE_INVALID);
+ throw raiseNode.raise(inliningTarget, ValueError, ARGUMENT_TYPE_INVALID);
}
MultibyteCodec codec;
codec = (MultibyteCodec) arg.getPointer();
@@ -144,8 +144,8 @@ static Object createCodec(Node inliningTarget, PyCapsule arg,
@Fallback
static Object createCodec(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ARGUMENT_TYPE_INVALID);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ARGUMENT_TYPE_INVALID);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
index 548ef01be4..813b5abc0e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java
@@ -120,10 +120,10 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, TruffleString map,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@Cached(inline = false) TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached(inline = false) HashingStorageSetItem setItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int len = Math.min(codePointLengthNode.execute(map, TS_ENCODING), 256);
if (len == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
byte[] level1 = new byte[32];
byte[] level2 = new byte[512];
@@ -196,9 +196,9 @@ public abstract static class PyUnicodeEncodeCharmapNode extends Node {
@Specialization
static byte[] doLatin1(TruffleString src, TruffleString errors, PNone mapping,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// TODO latin1
- throw raiseNode.raise(NotImplementedError, toTruffleStringUncached("latin1"));
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("latin1"));
}
@Fallback
@@ -328,7 +328,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, int cp, Object mappi
@Cached PyLongCheckNode pyLongCheckNode,
@Cached PyLongAsLongNode pyLongAsLongNode,
@Cached PyBytesCheckNode pyBytesCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object item;
try {
item = pyObjectGetItemNode.execute(frame, inliningTarget, mapping, cp);
@@ -342,14 +342,14 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, int cp, Object mappi
if (pyLongCheckNode.execute(inliningTarget, item)) {
long value = pyLongAsLongNode.execute(frame, inliningTarget, item);
if (value < 0 || value > 255) {
- raiseNode.get(inliningTarget).raise(TypeError, CHARACTER_MAPPING_MUST_BE_IN_RANGE_256);
+ raiseNode.raise(inliningTarget, TypeError, CHARACTER_MAPPING_MUST_BE_IN_RANGE_256);
}
return value;
}
if (pyBytesCheckNode.execute(inliningTarget, item)) {
return item;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, CHARACTER_MAPPING_MUST_RETURN_INT_BYTES_OR_NONE_NOT_P, item);
+ throw raiseNode.raise(inliningTarget, TypeError, CHARACTER_MAPPING_MUST_RETURN_INT_BYTES_OR_NONE_NOT_P, item);
}
}
@@ -463,7 +463,7 @@ static TruffleString decodeGenericMapping(VirtualFrame frame, Object data, Truff
@Cached InlinedConditionProfile longValuesProfile,
@Cached InlinedConditionProfile strValuesProfile,
@Cached InlinedConditionProfile errProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// equivalent of charmap_decode_mapping
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
@@ -501,7 +501,7 @@ static TruffleString decodeGenericMapping(VirtualFrame frame, Object data, Truff
break;
}
if (value < 0 || value > Character.MAX_CODE_POINT) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_BE_IN_RANGE, PInt.toHexString(Character.MAX_CODE_POINT + 1));
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_BE_IN_RANGE, PInt.toHexString(Character.MAX_CODE_POINT + 1));
} else {
appendCodePointNode.execute(tsb, (int) value, 1, true);
}
@@ -518,7 +518,7 @@ static TruffleString decodeGenericMapping(VirtualFrame frame, Object data, Truff
appendStringNode.execute(tsb, castToTruffleStringNode.execute(inliningTarget, item));
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_RETURN_INT_NONE_OR_STR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_RETURN_INT_NONE_OR_STR);
}
}
} finally {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CodecsRegistry.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CodecsRegistry.java
index 205bbde344..66ff758337 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CodecsRegistry.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CodecsRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -93,7 +93,7 @@ public abstract static class PyCodecLookupErrorNode extends Node {
@Specialization
static Object lookup(Node inliningTarget, TruffleString name,
@Cached InlinedConditionProfile resultProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
ensureRegistryInitialized(context);
if (name == null) {
@@ -101,7 +101,7 @@ static Object lookup(Node inliningTarget, TruffleString name,
}
Object result = getErrorHandler(context, name);
if (resultProfile.profile(inliningTarget, result == null)) {
- throw raiseNode.get(inliningTarget).raise(LookupError, UNKNOWN_ERROR_HANDLER, name);
+ throw raiseNode.raise(inliningTarget, LookupError, UNKNOWN_ERROR_HANDLER, name);
}
return result;
}
@@ -124,9 +124,8 @@ static void register(Node inliningTarget, TruffleString name, Object handler,
@Specialization(guards = "!callableCheckNode.execute(inliningTarget, handler)")
static void registerNoCallable(@SuppressWarnings("unused") Node inliningTarget, @SuppressWarnings("unused") TruffleString name, @SuppressWarnings("unused") Object handler,
- @SuppressWarnings("unused") @Cached @Shared("callableCheck") PyCallableCheckNode callableCheckNode,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, HANDLER_MUST_BE_CALLABLE);
+ @SuppressWarnings("unused") @Cached @Shared("callableCheck") PyCallableCheckNode callableCheckNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, HANDLER_MUST_BE_CALLABLE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
index 3c893aaced..112036bd11 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java
@@ -258,8 +258,8 @@ static boolean isNeither(Node inliningTarget, Object o, PyObjectTypeCheck pyObje
return !isDecode(inliningTarget, o, pyObjectTypeCheck) && !isEncode(inliningTarget, o, pyObjectTypeCheck) && !isTranslate(inliningTarget, o, pyObjectTypeCheck);
}
- static PException wrongExceptionType(Object o, PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DONT_KNOW_HOW_TO_HANDLE_P_IN_ERROR_CALLBACK, o);
+ static PException wrongExceptionType(Node inliningTarget, Object o) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DONT_KNOW_HOW_TO_HANDLE_P_IN_ERROR_CALLBACK, o);
}
}
@@ -268,14 +268,14 @@ static PException wrongExceptionType(Object o, PRaiseNode raiseNode) {
abstract static class StrictErrorHandlerNode extends ErrorHandlerBaseNode {
@Specialization
static Object doException(PBaseException exception,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseExceptionObject(exception);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
}
@Fallback
static Object doFallback(@SuppressWarnings("unused") Object o,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CODEC_MUST_PASS_EXCEPTION_INSTANCE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CODEC_MUST_PASS_EXCEPTION_INSTANCE);
}
}
@@ -303,9 +303,8 @@ static Object doEncodeOrTranslateException(PBaseException exception,
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -344,9 +343,8 @@ static Object doEncodeOrTranslateException(PBaseException exception,
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -384,9 +382,8 @@ static Object doEncode(PBaseException exception,
@Specialization(guards = "!isEncode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -469,9 +466,8 @@ static Object doEncodeOrTranslateException(PBaseException exception,
@Specialization(guards = "isNeither(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -522,9 +518,8 @@ static Object doEncode(PBaseException exception,
@Specialization(guards = "!isEncode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -543,14 +538,14 @@ static Object doEncode(PBaseException exception,
@Cached PyUnicodeEncodeErrorGetEncodingNode getEncodingNode,
@Exclusive @Cached GetStandardEncodingNode getStandardEncodingNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
TruffleString src = getObjectNode.execute(inliningTarget, exception);
TruffleString encodingName = getEncodingNode.execute(inliningTarget, exception);
StandardEncoding encoding = getStandardEncodingNode.execute(inliningTarget, encodingName);
if (encoding == StandardEncoding.UNKNOWN) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
if (start >= end) {
return PFactory.createTuple(language, new Object[]{PFactory.createBytes(language, new byte[0]), end});
@@ -560,7 +555,7 @@ static Object doEncode(PBaseException exception,
for (int i = start; i < end; ++i) {
int cp = codePointAtIndexNode.execute(src, i, TS_ENCODING, ErrorHandling.BEST_EFFORT);
if (!isSurrogate(cp)) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
encodeCodepoint(encoding, result, pos, cp);
pos += encoding.byteLength;
@@ -582,14 +577,14 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached TruffleString.FromCodePointNode fromCodePointNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
getEndNode.execute(inliningTarget, exception); // called for side effects only
Object object = getObjectNode.execute(inliningTarget, exception);
TruffleString encodingName = getEncodingNode.execute(inliningTarget, exception);
StandardEncoding encoding = getStandardEncodingNode.execute(inliningTarget, encodingName);
if (encoding == StandardEncoding.UNKNOWN) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
Object srcBuf = acquireLib.acquireReadonly(object, frame, indirectCallData);
try {
@@ -599,7 +594,7 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
cp = decodeCodepoint(encoding, accessLib.getInternalOrCopiedByteArray(srcBuf), start);
}
if (!isSurrogate(cp)) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
return PFactory.createTuple(language, new Object[]{fromCodePointNode.execute(cp, TS_ENCODING, true), start + encoding.byteLength});
} finally {
@@ -610,9 +605,8 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@Specialization(guards = "!isEncodeOrDecode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
private static void encodeCodepoint(StandardEncoding encoding, byte[] result, int pos, int cp) {
@@ -678,7 +672,7 @@ static Object doEncode(PBaseException exception,
@Cached PyUnicodeEncodeOrTranslateErrorGetStartNode getStartNode,
@Cached PyUnicodeEncodeOrTranslateErrorGetEndNode getEndNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
TruffleString src = getObjectNode.execute(inliningTarget, exception);
@@ -690,7 +684,7 @@ static Object doEncode(PBaseException exception,
for (int i = start; i < end; ++i) {
int cp = codePointAtIndexNode.execute(src, i, TS_ENCODING, ErrorHandling.BEST_EFFORT);
if (cp < 0xdc80 || cp > 0xdcff) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
result[pos++] = (byte) (cp - 0xdc00);
}
@@ -710,7 +704,7 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int start = getStartNode.execute(inliningTarget, exception);
int end = getEndNode.execute(inliningTarget, exception);
Object object = getObjectNode.execute(inliningTarget, exception);
@@ -728,7 +722,7 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
consumed++;
}
if (consumed == 0) {
- throw raiseNode.get(inliningTarget).raiseExceptionObject(exception);
+ throw raiseNode.raiseExceptionObject(inliningTarget, exception);
}
return PFactory.createTuple(language, new Object[]{toStringNode.execute(tsb), start + consumed});
} finally {
@@ -739,9 +733,8 @@ static Object doDecode(VirtualFrame frame, PBaseException exception,
@Specialization(guards = "!isEncodeOrDecode(inliningTarget, o, pyObjectTypeCheck)", limit = "1")
static Object doFallback(Object o,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck,
- @Cached PRaiseNode raiseNode) {
- throw wrongExceptionType(o, raiseNode);
+ @SuppressWarnings("unused") @Cached @Exclusive PyObjectTypeCheck pyObjectTypeCheck) {
+ throw wrongExceptionType(inliningTarget, o);
}
}
@@ -861,9 +854,9 @@ static DecodingErrorHandlerResult doTuple(Node inliningTarget, PTuple result,
@Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@Cached CastToTruffleStringCheckedNode castToTruffleStringCheckedNode,
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (lenNode.execute(inliningTarget, result) != 2) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
}
Object[] array = getObjectArrayNode.execute(inliningTarget, result);
TruffleString str = castToTruffleStringCheckedNode.cast(inliningTarget, array[0], ErrorMessages.DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
@@ -872,9 +865,8 @@ static DecodingErrorHandlerResult doTuple(Node inliningTarget, PTuple result,
}
@Fallback
- static DecodingErrorHandlerResult doOther(@SuppressWarnings("unused") Object result,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
+ static DecodingErrorHandlerResult doOther(Node inliningTarget, @SuppressWarnings("unused") Object result) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.DECODING_ERROR_HANDLER_MUST_RETURN_STR_INT_TUPLE);
}
}
@@ -895,7 +887,7 @@ static DecodingErrorHandlerResult doIt(VirtualFrame frame, Node inliningTarget,
@Cached ParseDecodingErrorHandlerResultNode parseResultNode,
@Cached PyUnicodeDecodeErrorGetObjectNode getObjectNode,
@Cached PyObjectSizeNode sizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
cache.errorHandlerObject = cache.errorHandlerObject == null ? lookupErrorNode.execute(inliningTarget, errors) : cache.errorHandlerObject;
cache.exceptionObject = makeDecodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
Object resultObj = callNode.execute(frame, cache.errorHandlerObject, cache.exceptionObject);
@@ -932,9 +924,9 @@ static EncodingErrorHandlerResult doTuple(Node inliningTarget, PTuple result,
@Cached CastToJavaIntExactNode castToJavaIntExactNode,
@Cached PyUnicodeCheckNode pyUnicodeCheckNode,
@Cached PyBytesCheckNode pyBytesCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (lenNode.execute(inliningTarget, result) != 2) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
}
Object[] array = getObjectArrayNode.execute(inliningTarget, result);
boolean isUnicode;
@@ -943,16 +935,15 @@ static EncodingErrorHandlerResult doTuple(Node inliningTarget, PTuple result,
} else if (pyBytesCheckNode.execute(inliningTarget, array[0])) {
isUnicode = false;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
}
int pos = castToJavaIntExactNode.execute(inliningTarget, array[1]);
return new EncodingErrorHandlerResult(array[0], pos, isUnicode);
}
@Fallback
- static EncodingErrorHandlerResult doOther(@SuppressWarnings("unused") Object result,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
+ static EncodingErrorHandlerResult doOther(Node inliningTarget, @SuppressWarnings("unused") Object result) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ENCODING_ERROR_HANDLER_MUST_RETURN_STR_BYTES_INT_TUPLE);
}
}
@@ -972,7 +963,7 @@ static EncodingErrorHandlerResult doIt(VirtualFrame frame, Node inliningTarget,
@Cached(inline = false) CallNode callNode,
@Cached ParseEncodingErrorHandlerResultNode parseResultNode,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
cache.errorHandlerObject = cache.errorHandlerObject == null ? lookupErrorNode.execute(inliningTarget, errors) : cache.errorHandlerObject;
int len = codePointLengthNode.execute(srcObj, TS_ENCODING);
cache.exceptionObject = makeEncodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
@@ -993,18 +984,18 @@ abstract static class RaiseEncodeException extends Node {
@Specialization
static void doIt(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache, TruffleString encoding, TruffleString srcObj, int startPos, int endPos, TruffleString reason,
@Cached MakeEncodeExceptionNode makeEncodeExceptionNode,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ @Cached PRaiseNode raiseNode) {
cache.exceptionObject = makeEncodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
raiseNode.raiseExceptionObject(cache.exceptionObject);
}
}
- private static int adjustAndCheckPos(int newPos, int len, Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ private static int adjustAndCheckPos(int newPos, int len, Node inliningTarget, PRaiseNode raiseNode) {
if (newPos < 0) {
newPos += len;
}
if (newPos < 0 || newPos > len) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newPos);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.POSITION_D_FROM_ERROR_HANDLER_OUT_OF_BOUNDS, newPos);
}
return newPos;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
index 3361d93597..371d09f82a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java
@@ -165,12 +165,12 @@ static PNone register(VirtualFrame frame, PythonModule module, Object nameObj, O
@Cached ReadAttributeFromObjectNode readNode,
@Cached CallNode callNode,
@Cached PyDictSetItem setItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString name;
try {
name = nameNode.execute(inliningTarget, nameObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_STRING, "dialect name");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_STRING, "dialect name");
}
Object result = callNode.execute(frame, PythonBuiltinClassType.CSVDialect, new Object[]{dialectObj}, keywords);
@@ -195,7 +195,7 @@ static PNone unregister(VirtualFrame frame, PythonModule module, Object nameObj,
@Cached ReadAttributeFromObjectNode readNode,
@Cached PyDictDelItem delItem,
@Cached HashingStorageGetItem getItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// TODO GR-38165: unchecked cast to PDict
PDict dialects = (PDict) readNode.execute(module, T__DIALECTS);
@@ -203,7 +203,7 @@ static PNone unregister(VirtualFrame frame, PythonModule module, Object nameObj,
if (getItem.hasKey(frame, inliningTarget, (dialects).getDictStorage(), nameObj)) {
delItem.execute(frame, inliningTarget, dialects, nameObj);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.UNKNOWN_DIALECT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.UNKNOWN_DIALECT);
}
return PNone.NONE;
@@ -227,7 +227,7 @@ static CSVDialect get(VirtualFrame frame, PythonModule module, Object nameObj,
@Bind("this") Node inliningTarget,
@Cached PyDictGetItem getItemNode,
@Cached ReadAttributeFromObjectNode readNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// TODO GR-38165: unchecked cast to PDict
PDict dialects = (PDict) readNode.execute(module, T__DIALECTS);
@@ -235,7 +235,7 @@ static CSVDialect get(VirtualFrame frame, PythonModule module, Object nameObj,
CSVDialect dialect = (CSVDialect) getItemNode.execute(frame, inliningTarget, dialects, nameObj);
if (dialect == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.UNKNOWN_DIALECT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.UNKNOWN_DIALECT);
}
return dialect;
@@ -281,10 +281,10 @@ static Object createReader(VirtualFrame frame, Object outputFile, Object dialect
@Cached PyObjectLookupAttr lookupAttr,
@Cached PyCallableCheckNode checkCallable,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object write = lookupAttr.execute(frame, inliningTarget, outputFile, T_WRITE);
if (write == PNone.NO_VALUE || !checkCallable.execute(inliningTarget, write)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_MUST_HAVE_WRITE_METHOD, "argument 1");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_MUST_HAVE_WRITE_METHOD, "argument 1");
}
CSVDialect dialect = (CSVDialect) callNode.execute(frame, PythonBuiltinClassType.CSVDialect, new Object[]{dialectObj}, kwargs);
return PFactory.createCSVWriter(language, write, dialect);
@@ -303,13 +303,13 @@ static long getOrSetFieldSizeLimit(VirtualFrame frame, PythonModule self, Object
@Bind("this") Node inliningTarget,
@Cached PyLongCheckExactNode checkLongNode,
@Cached PyLongAsLongNode castToLong,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
CSVModuleBuiltins csvModuleBuiltins = (CSVModuleBuiltins) self.getBuiltins();
long oldLimit = csvModuleBuiltins.fieldLimit;
if (newLimit != PNone.NO_VALUE) {
if (!checkLongNode.execute(inliningTarget, newLimit)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_INTEGER, "limit");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_INTEGER, "limit");
}
csvModuleBuiltins.fieldLimit = castToLong.execute(frame, inliningTarget, newLimit);
}
@@ -346,7 +346,7 @@ static Object doNoDialectObj(VirtualFrame frame, PythonBuiltinClassType cls, @Su
@Exclusive @Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached PyLongCheckExactNode pyLongCheckExactNode,
@Exclusive @Cached PyLongAsIntNode pyLongAsIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return createCSVDialect(frame, inliningTarget, cls, delimiterObj, doublequoteObj, escapecharObj, lineterminatorObj,
quotecharObj, quotingObj, skipinitialspaceObj, strictObj, isTrueNode, pyLongCheckExactNode, pyLongAsIntNode, raiseNode);
}
@@ -359,7 +359,7 @@ static Object doStringWithKeywords(VirtualFrame frame, PythonBuiltinClassType cl
@Exclusive @Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached PyLongCheckExactNode pyLongCheckExactNode,
@Exclusive @Cached PyLongAsIntNode pyLongAsIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PythonModule module = PythonContext.get(inliningTarget).lookupBuiltinModule(T__CSV);
CSVDialect dialectObj = getDialect.execute(frame, module, dialectName);
@@ -402,7 +402,7 @@ static Object doDialectClassWithKeywords(VirtualFrame frame, PythonBuiltinClassT
@Exclusive @Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached PyLongCheckExactNode pyLongCheckExactNode,
@Exclusive @Cached PyLongAsIntNode pyLongAsIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
// We use multiple AttributeNodes to be able to cache all attributes as current
// CACHE_SIZE is 3.
@@ -428,7 +428,7 @@ static Object doPStringWithKeywords(VirtualFrame frame, PythonBuiltinClassType c
@Exclusive @Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached PyLongCheckExactNode pyLongCheckExactNode,
@Exclusive @Cached PyLongAsIntNode pyLongAsIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString dialectNameStr = castToStringNode.execute(inliningTarget, dialectName);
PythonModule module = PythonContext.get(inliningTarget).lookupBuiltinModule(T__CSV);
@@ -473,7 +473,7 @@ static Object doGeneric(VirtualFrame frame, PythonBuiltinClassType cls, Object d
@Exclusive @Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached PyLongCheckExactNode pyLongCheckExactNode,
@Exclusive @Cached PyLongAsIntNode pyLongAsIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
delimiterObj = getAttributeValue(frame, inliningTarget, dialectObj, delimiterObj, T_ATTR_DELIMITER, getFirstAttributesNode);
doublequoteObj = getAttributeValue(frame, inliningTarget, dialectObj, doublequoteObj, T_ATTR_DOUBLEQUOTE, getFirstAttributesNode);
@@ -494,7 +494,7 @@ protected static boolean isCSVDialect(Object dialect) {
private static Object createCSVDialect(VirtualFrame frame, Node inliningTarget, PythonBuiltinClassType cls, Object delimiterObj, Object doublequoteObj, Object escapecharObj,
Object lineterminatorObj, Object quotecharObj, Object quotingObj, Object skipinitialspaceObj, Object strictObj,
- PyObjectIsTrueNode isTrueNode, PyLongCheckExactNode pyLongCheckExactNode, PyLongAsIntNode pyLongAsIntNode, PRaiseNode.Lazy raiseNode) {
+ PyObjectIsTrueNode isTrueNode, PyLongCheckExactNode pyLongCheckExactNode, PyLongAsIntNode pyLongAsIntNode, PRaiseNode raiseNode) {
TruffleString delimiter = getChar(inliningTarget, T_ATTR_DELIMITER, delimiterObj, T_COMMA, false);
boolean doubleQuote = getBoolean(frame, doublequoteObj, true, isTrueNode);
TruffleString escapeChar = getChar(inliningTarget, T_ATTR_ESCAPECHAR, escapecharObj, T_NOT_SET, true);
@@ -513,15 +513,15 @@ private static Object createCSVDialect(VirtualFrame frame, Node inliningTarget,
private static Object createCSVDialect(Node raisingNode, PythonBuiltinClassType cls, TruffleString delimiter, boolean doubleQuote, TruffleString escapeChar, TruffleString lineTerminator,
TruffleString quoteChar, QuoteStyle quoting, boolean skipInitialSpace, boolean strict) {
if (TruffleString.EqualNode.getUncached().execute(delimiter, T_NOT_SET, TS_ENCODING)) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.DELIMITER_MUST_BE_ONE_CHAR_STRING);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.DELIMITER_MUST_BE_ONE_CHAR_STRING);
}
if (quoting != QUOTE_NONE && TruffleString.EqualNode.getUncached().execute(quoteChar, T_NOT_SET, TS_ENCODING)) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.QUOTECHAR_MUST_BE_SET_IF_QUOTING_ENABLED);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.QUOTECHAR_MUST_BE_SET_IF_QUOTING_ENABLED);
}
if (lineTerminator == null) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.LINETERMINATOR_MUST_BE_SET);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.LINETERMINATOR_MUST_BE_SET);
}
// delimiter cannot be NOT_SET
@@ -557,8 +557,8 @@ private static TruffleString getChar(Node raisingNode, TruffleString name, Objec
try {
charValue = CastToTruffleStringNode.executeUncached(valueObj);
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, optional ? ErrorMessages.S_MUST_BE_STRING_OR_NONE_NOT_S : ErrorMessages.S_MUST_BE_STRING_NOT_S, name,
- GetClassNode.executeUncached(valueObj));
+ TruffleString format = optional ? ErrorMessages.S_MUST_BE_STRING_OR_NONE_NOT_S : ErrorMessages.S_MUST_BE_STRING_NOT_S;
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, format, name, GetClassNode.executeUncached(valueObj));
}
if (optional && TruffleString.EqualNode.getUncached().execute(charValue, T_NOT_SET, TS_ENCODING)) {
@@ -566,7 +566,7 @@ private static TruffleString getChar(Node raisingNode, TruffleString name, Objec
}
if (TruffleString.CodePointLengthNode.getUncached().execute(charValue, TS_ENCODING) != 1) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.MUST_BE_ONE_CHARACTER_STRING, name);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.MUST_BE_ONE_CHARACTER_STRING, name);
}
return charValue;
@@ -595,14 +595,14 @@ private static TruffleString getString(Node raisingNode, TruffleString attribute
try {
value = CastToTruffleStringNode.executeUncached(valueObj);
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.MUST_BE_STRING_QUOTED, attribute);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.MUST_BE_STRING_QUOTED, attribute);
}
return value;
}
private static QuoteStyle getQuotingValue(VirtualFrame frame, Node inliningTarget, TruffleString name, Object valueObj, QuoteStyle defaultValue,
- PyLongCheckExactNode pyLongCheckExactNode, PyLongAsIntNode pyLongAsIntNode, PRaiseNode.Lazy raiseNode) {
+ PyLongCheckExactNode pyLongCheckExactNode, PyLongAsIntNode pyLongAsIntNode, PRaiseNode raiseNode) {
if (valueObj == PNone.NO_VALUE) {
return defaultValue;
@@ -613,13 +613,13 @@ private static QuoteStyle getQuotingValue(VirtualFrame frame, Node inliningTarge
}
if (!pyLongCheckExactNode.execute(inliningTarget, valueObj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_INTEGER_QUOTED_ATTR, name);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_INTEGER_QUOTED_ATTR, name);
}
int value = pyLongAsIntNode.execute(frame, inliningTarget, valueObj);
if (!QuoteStyle.containsOrdinalValue(value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_QUOTING_VALUE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_QUOTING_VALUE);
}
return QuoteStyle.getQuoteStyle(value);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
index 8ee12c5684..8a5394ec37 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVReaderBuiltins.java
@@ -132,7 +132,7 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
@Cached GetClassNode getClassNode,
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PList fields = PFactory.createList(language);
CSVModuleBuiltins csvModuleBuiltins = (CSVModuleBuiltins) PythonContext.get(inliningTarget).lookupBuiltinModule(T__CSV).getBuiltins();
self.parseReset();
@@ -145,7 +145,7 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
self.fieldLimit = csvModuleBuiltins.fieldLimit;
if (!self.field.isEmpty() || self.state == IN_QUOTED_FIELD) {
if (self.dialect.strict) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.UNEXPECTED_END_OF_DATA);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.UNEXPECTED_END_OF_DATA);
} else {
try {
parseSaveField(inliningTarget, self, fields, toStringNode, pyNumberFloatNode, appendNode);
@@ -155,7 +155,7 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
break;
}
}
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
self.fieldLimit = csvModuleBuiltins.fieldLimit;
@@ -163,7 +163,7 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
try {
line = castToStringNode.execute(inliningTarget, lineObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.WRONG_ITERATOR_RETURN_TYPE, getClassNode.execute(inliningTarget, lineObj));
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.WRONG_ITERATOR_RETURN_TYPE, getClassNode.execute(inliningTarget, lineObj));
}
self.lineNum++;
@@ -180,7 +180,7 @@ static Object nextPos(VirtualFrame frame, CSVReader self,
@SuppressWarnings("fallthrough")
private static void parseProcessCodePoint(Node inliningTarget, CSVReader self, PList fields, int codePoint, AppendCodePointNode appendCodePointNode, ToStringNode toStringNode,
- PyNumberFloatNode pyNumberFloatNode, AppendNode appendNode, PRaiseNode.Lazy raiseNode) {
+ PyNumberFloatNode pyNumberFloatNode, AppendNode appendNode, PRaiseNode raiseNode) {
CSVDialect dialect = self.dialect;
switch (self.state) {
@@ -315,7 +315,7 @@ private static void parseProcessCodePoint(Node inliningTarget, CSVReader self, P
self.state = IN_FIELD;
} else {
/* illegal */
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.S_EXPECTED_AFTER_S, dialect.delimiter, dialect.quoteChar);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.S_EXPECTED_AFTER_S, dialect.delimiter, dialect.quoteChar);
}
break;
@@ -325,7 +325,7 @@ private static void parseProcessCodePoint(Node inliningTarget, CSVReader self, P
} else if (codePoint == EOL) {
self.state = START_RECORD;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.NEWLINE_IN_UNQOUTED_FIELD);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.NEWLINE_IN_UNQOUTED_FIELD);
}
break;
}
@@ -342,11 +342,11 @@ private static void parseSaveField(Node inliningTarget, CSVReader self, PList fi
}
}
- private static void parseAddCodePoint(Node inliningTarget, CSVReader self, int codePoint, TruffleStringBuilder.AppendCodePointNode appendCodePointNode, PRaiseNode.Lazy raise) {
+ private static void parseAddCodePoint(Node inliningTarget, CSVReader self, int codePoint, TruffleStringBuilder.AppendCodePointNode appendCodePointNode, PRaiseNode raise) {
assert TS_ENCODING == TruffleString.Encoding.UTF_32;
int cpLen = self.field.byteLength() / 4; // assumes UTF-32
if (cpLen + 1 > self.fieldLimit) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.LARGER_THAN_FIELD_SIZE_LIMIT, self.fieldLimit);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.LARGER_THAN_FIELD_SIZE_LIMIT, self.fieldLimit);
}
appendCodePointNode.execute(self.field, codePoint, 1, true);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVWriterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVWriterBuiltins.java
index 1a11fd9916..498c5edcea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVWriterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVWriterBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -103,14 +103,14 @@ static Object doIt(VirtualFrame frame, CSVWriter self, Object seq,
@Cached PyNumberCheckNode pyNumberCheckNode,
@Cached GetNextNode getNextNode,
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object iter;
try {
iter = getIter.execute(frame, inliningTarget, seq);
} catch (PException e) {
e.expect(inliningTarget, PythonBuiltinClassType.TypeError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.EXPECTED_ITERABLE_NOT_S, getClass.execute(inliningTarget, seq));
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.EXPECTED_ITERABLE_NOT_S, getClass.execute(inliningTarget, seq));
}
// Join all fields of passed in sequence in internal buffer.
@@ -135,7 +135,7 @@ static Object doIt(VirtualFrame frame, CSVWriter self, Object seq,
}
if (!first && sb.isEmpty()) {
if (dialect.quoting == QUOTE_NONE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.EMPTY_FIELD_RECORD_MUST_BE_QUOTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.EMPTY_FIELD_RECORD_MUST_BE_QUOTED);
}
joinAppend(inliningTarget, sb, dialect, null, true, createCodePointIteratorNode, nextNode, byteIndexOfCodePointNode, appendCodePointNode, appendStringNode, raiseNode);
}
@@ -146,7 +146,7 @@ static Object doIt(VirtualFrame frame, CSVWriter self, Object seq,
private static void joinField(Node inliningTarget, TruffleStringBuilder sb, CSVDialect dialect, Object field, TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
TruffleStringIterator.NextNode nextNode, TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode, TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
TruffleStringBuilder.AppendStringNode appendStringNode, PyObjectStrAsTruffleStringNode objectStrAsTruffleStringNode, PyNumberCheckNode pyNumberCheckNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
boolean quoted;
switch (dialect.quoting) {
@@ -171,7 +171,7 @@ private static void joinField(Node inliningTarget, TruffleStringBuilder sb, CSVD
private static void joinAppend(Node inliningTarget, TruffleStringBuilder sb, CSVDialect dialect, TruffleString field, boolean quoted,
TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode, TruffleStringIterator.NextNode nextNode, TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode,
- TruffleStringBuilder.AppendCodePointNode appendCodePointNode, TruffleStringBuilder.AppendStringNode appendStringNode, PRaiseNode.Lazy raiseNode) {
+ TruffleStringBuilder.AppendCodePointNode appendCodePointNode, TruffleStringBuilder.AppendStringNode appendStringNode, PRaiseNode raiseNode) {
/*
* If we don't already know that the field must be quoted due to dialect settings, check
* if the field contains characters due to which it must be quoted.
@@ -214,7 +214,7 @@ private static void joinAppend(Node inliningTarget, TruffleStringBuilder sb, CSV
}
if (wantEscape) {
if (dialect.escapeCharCodePoint == NOT_SET_CODEPOINT) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.CSVError, ErrorMessages.ESCAPE_WITHOUT_ESCAPECHAR);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.CSVError, ErrorMessages.ESCAPE_WITHOUT_ESCAPECHAR);
}
appendStringNode.execute(sb, dialect.escapeChar);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
index 6381bad907..2751615735 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataBuiltins.java
@@ -158,8 +158,8 @@ static Object PyCData_from_outparam(CDataObject self) {
protected abstract static class HashNode extends PythonBuiltinNode {
@Specialization
static long hash(@SuppressWarnings("unused") CDataObject self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, UNHASHABLE_TYPE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, UNHASHABLE_TYPE);
}
}
@@ -176,10 +176,10 @@ static Object reduce(VirtualFrame frame, CDataObject self,
@Cached ReadAttributeFromPythonObjectNode readAttrNode,
@Cached PointerNodes.ReadBytesNode readBytesNode,
@Cached GetClassNode getClassNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject stgDict = pyObjectStgDictNode.execute(inliningTarget, self);
if ((stgDict.flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER)) != 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CTYPES_OBJECTS_CONTAINING_POINTERS_CANNOT_BE_PICKLED);
+ throw raiseNode.raise(inliningTarget, ValueError, CTYPES_OBJECTS_CONTAINING_POINTERS_CANNOT_BE_PICKLED);
}
Object dict = getAttributeNode.executeObject(frame, self);
Object[] t1 = new Object[]{dict, null};
@@ -190,7 +190,7 @@ static Object reduce(VirtualFrame frame, CDataObject self,
Object unpickle = readAttrNode.execute(ctypes, T_UNPICKLE, null);
if (unpickle == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, toTruffleStringUncached("unpickle isn't supported yet."));
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("unpickle isn't supported yet."));
}
Object[] t3 = new Object[]{unpickle, PFactory.createTuple(language, t2)};
return PFactory.createTuple(language, t3); // "O(O(NN))"
@@ -211,11 +211,11 @@ static Object PyCData_setstate(VirtualFrame frame, CDataObject self, PTuple args
@Cached GetNameNode getNameNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = args.getSequenceStorage();
Object[] array = getArray.execute(inliningTarget, storage);
if (storage.length() < 3 || !PGuards.isDict(array[0]) || !PGuards.isInteger(array[2])) {
- throw raiseNode.get(inliningTarget).raise(TypeError);
+ throw raiseNode.raise(inliningTarget, TypeError);
}
PDict dict = (PDict) array[0];
Object data = array[1];
@@ -228,7 +228,7 @@ static Object PyCData_setstate(VirtualFrame frame, CDataObject self, PTuple args
memmove(inliningTarget, self.b_ptr, data, len);
Object mydict = getAttributeNode.executeObject(frame, self);
if (!PGuards.isDict(mydict)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_DICT_MUST_BE_A_DICTIONARY_NOT_S,
+ throw raiseNode.raise(inliningTarget, TypeError, S_DICT_MUST_BE_A_DICTIONARY_NOT_S,
getNameNode.execute(inliningTarget, getClassNode.execute(inliningTarget, self)),
getNameNode.execute(inliningTarget, getClassNode.execute(inliningTarget, mydict)));
}
@@ -240,7 +240,7 @@ static Object PyCData_setstate(VirtualFrame frame, CDataObject self, PTuple args
@SuppressWarnings("unused")
private static void memmove(Node raisingNode, Object dest, Object src, int len) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(raisingNode, NotImplementedError, toTruffleStringUncached("memmove is partially supported.")); // TODO
+ throw PRaiseNode.raiseStatic(raisingNode, NotImplementedError, toTruffleStringUncached("memmove is partially supported.")); // TODO
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
index 878c21408f..61dfe2cc68 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeBuiltins.java
@@ -157,7 +157,7 @@ static Object CDataType_from_param(VirtualFrame frame, Object type, Object value
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectLookupAttr lookupAttr,
@Cached IsInstanceNode isInstanceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isInstanceNode.executeWith(frame, value, type)) {
return value;
}
@@ -175,7 +175,7 @@ static Object CDataType_from_param(VirtualFrame frame, Object type, Object value
return value;
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_P_INSTANCE_INSTEAD_OF_POINTER_TO_P, type, ob != null ? ob : PNone.NONE);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_P_INSTANCE_INSTEAD_OF_POINTER_TO_P, type, ob != null ? ob : PNone.NONE);
}
Object as_parameter = lookupAttr.execute(frame, inliningTarget, value, T__AS_PARAMETER_);
@@ -184,7 +184,7 @@ static Object CDataType_from_param(VirtualFrame frame, Object type, Object value
return CDataType_from_param(frame, type, as_parameter, inliningTarget,
pyTypeStgDictNode, lookupAttr, isInstanceNode, raiseNode);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_P_INSTANCE_INSTEAD_OF_P, type, value);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_P_INSTANCE_INSTEAD_OF_P, type, value);
}
}
@@ -232,25 +232,25 @@ static Object CDataType_from_buffer(VirtualFrame frame, Object type, Object obj,
@Cached PyCDataAtAddress atAddress,
@Cached KeepRefNode keepRefNode,
@Cached AuditNode auditNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
PMemoryView mv = memoryViewNode.execute(frame, obj);
if (mv.isReadOnly()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, UNDERLYING_BUFFER_IS_NOT_WRITABLE);
+ throw raiseNode.raise(inliningTarget, TypeError, UNDERLYING_BUFFER_IS_NOT_WRITABLE);
}
if (!mv.isCContiguous()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, UNDERLYING_BUFFER_IS_NOT_C_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, TypeError, UNDERLYING_BUFFER_IS_NOT_C_CONTIGUOUS);
}
if (offset < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, OFFSET_CANNOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, OFFSET_CANNOT_BE_NEGATIVE);
}
if (dict.size > mv.getLength() - offset) {
- throw raiseNode.get(inliningTarget).raise(ValueError, BUFFER_SIZE_TOO_SMALL_D_INSTEAD_OF_AT_LEAST_D_BYTES, mv.getLength(), dict.size + offset);
+ throw raiseNode.raise(inliningTarget, ValueError, BUFFER_SIZE_TOO_SMALL_D_INSTEAD_OF_AT_LEAST_D_BYTES, mv.getLength(), dict.size + offset);
}
auditNode.audit(inliningTarget, "ctypes.cdata/buffer", mv, mv.getLength(), offset);
@@ -283,18 +283,18 @@ static Object CDataType_from_buffer_copy(Object type, Object buffer, int offset,
@Cached AuditNode auditNode,
@Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
if (offset < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, OFFSET_CANNOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, OFFSET_CANNOT_BE_NEGATIVE);
}
int bufferLen = bufferLib.getBufferLength(buffer);
if (dict.size > bufferLen - offset) {
- throw raiseNode.get(inliningTarget).raise(ValueError, BUFFER_SIZE_TOO_SMALL_D_INSTEAD_OF_AT_LEAST_D_BYTES, bufferLen, dict.size + offset);
+ throw raiseNode.raise(inliningTarget, ValueError, BUFFER_SIZE_TOO_SMALL_D_INSTEAD_OF_AT_LEAST_D_BYTES, bufferLen, dict.size + offset);
}
// This prints the raw pointer in C, so just print 0
@@ -332,17 +332,17 @@ static Object CDataType_in_dll(VirtualFrame frame, Object type, Object dll, Truf
@Cached AuditNode auditNode,
@Cached PointerNodes.PointerFromLongNode pointerFromLongNode,
@Cached CtypesDlSymNode dlSymNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
auditNode.audit(inliningTarget, "ctypes.dlsym", dll, name);
Object obj = getAttributeNode.executeObject(frame, dll);
if (!longCheckNode.execute(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THE_HANDLE_ATTRIBUTE_OF_THE_SECOND_ARGUMENT_MUST_BE_AN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, THE_HANDLE_ATTRIBUTE_OF_THE_SECOND_ARGUMENT_MUST_BE_AN_INTEGER);
}
Pointer handlePtr;
try {
handlePtr = pointerFromLongNode.execute(inliningTarget, obj);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.COULD_NOT_CONVERT_THE_HANDLE_ATTRIBUTE_TO_A_POINTER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.COULD_NOT_CONVERT_THE_HANDLE_ATTRIBUTE_TO_A_POINTER);
}
Object address = dlSymNode.execute(frame, handlePtr, name, ValueError);
if (address instanceof PythonNativeVoidPtr ptr) {
@@ -366,7 +366,7 @@ static CDataObject PyCData_AtAddress(Object type, Pointer pointer,
@Cached PyTypeCheck pyTypeCheck,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CtypesNodes.CreateCDataObjectNode createCDataObjectNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// auditNode.audit("ctypes.cdata", buf);
// assert(PyType_Check(type));
StgDictObject stgdict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
@@ -431,9 +431,9 @@ static void PyCData_set(VirtualFrame frame, CDataObject dst, Object type, FieldS
@Cached KeepRefNode keepRefNode,
@Cached PointerNodes.MemcpyNode memcpyNode,
@Cached PointerNodes.WritePointerNode writePointerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, dst)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NOT_A_CTYPE_INSTANCE);
+ throw raiseNode.raise(inliningTarget, TypeError, NOT_A_CTYPE_INSTANCE);
}
Object result = PyCDataSetInternal(frame, inliningTarget, type, setfunc, value, size, ptr,
@@ -465,7 +465,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
PyObjectStgDictNode pyObjectStgDictNode,
PointerNodes.MemcpyNode memcpyNode,
PointerNodes.WritePointerNode writePointerNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (setfunc != FieldSet.nil) {
return setFuncNode.execute(frame, setfunc, ptr, value, size);
}
@@ -495,7 +495,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
writePointerNode.execute(inliningTarget, ptr, Pointer.NULL);
return PNone.NONE;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_P_INSTANCE_GOT_P, type, value);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_P_INSTANCE_GOT_P, type, value);
}
}
CDataObject src = (CDataObject) value;
@@ -512,7 +512,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
assert p2 != null : "Cannot be NULL for pointer types";
if (p1.proto != p2.proto) {
- throw raiseNode.get(inliningTarget).raise(TypeError, INCOMPATIBLE_TYPES_P_INSTANCE_INSTEAD_OF_P_INSTANCE, value, type);
+ throw raiseNode.raise(inliningTarget, TypeError, INCOMPATIBLE_TYPES_P_INSTANCE_INSTEAD_OF_P_INSTANCE, value, type);
}
writePointerNode.execute(inliningTarget, ptr, src.b_ptr);
@@ -528,7 +528,7 @@ static Object PyCDataSetInternal(VirtualFrame frame, Node inliningTarget, Object
*/
return PFactory.createTuple(language, new Object[]{keep, value});
}
- throw raiseNode.get(inliningTarget).raise(TypeError, INCOMPATIBLE_TYPES_P_INSTANCE_INSTEAD_OF_P_INSTANCE, value, type);
+ throw raiseNode.raise(inliningTarget, TypeError, INCOMPATIBLE_TYPES_P_INSTANCE_INSTEAD_OF_P_INSTANCE, value, type);
}
}
@@ -591,7 +591,7 @@ static void KeepRef(VirtualFrame frame, Node inliningTarget, CDataObject target,
@Cached(inline = false) TruffleStringBuilder.ToStringNode toStringNode,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached HashingStorageSetItem setItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
CDataObject ob = PyCData_GetContainer(target, language);
if (!PGuards.isDict(ob.b_objects)) {
ob.b_objects = keep;
@@ -606,7 +606,7 @@ static void KeepRef(VirtualFrame frame, Node inliningTarget, CDataObject target,
private static final int MAX_KEY_SIZE = 256;
static TruffleString unique_key(Node inliningTarget, CDataObject cdata, int index,
- PRaiseNode.Lazy raiseNode, TruffleStringBuilder.AppendStringNode appendStringNode,
+ PRaiseNode raiseNode, TruffleStringBuilder.AppendStringNode appendStringNode,
TruffleStringBuilder.ToStringNode toStringNode, TruffleString.FromJavaStringNode fromJavaStringNode) {
assert TS_ENCODING == Encoding.UTF_32;
final int bytesPerCodepoint = 4; // assumes utf-32
@@ -618,7 +618,7 @@ static TruffleString unique_key(Node inliningTarget, CDataObject cdata, int inde
int bytesLeft = MAX_KEY_SIZE - sb.byteLength() / bytesPerCodepoint - 1;
/* Hex format needs 2 characters per byte */
if (bytesLeft < Integer.BYTES * 2) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CTYPES_OBJECT_STRUCTURE_TOO_DEEP);
+ throw raiseNode.raise(inliningTarget, ValueError, CTYPES_OBJECT_STRUCTURE_TOO_DEEP);
}
appendStringNode.execute(sb, T_COLON);
appendStringNode.execute(sb, fromJavaStringNode.execute(toHex(target.b_index), TS_ENCODING));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
index 1602d3d3ed..c522f5fee0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataTypeSequenceBuiltins.java
@@ -118,7 +118,7 @@ static Object PyCArrayType_from_ctype(VirtualFrame frame, Object itemtype, int l
@Cached GetNameNode getNameNode,
@Cached SimpleTruffleStringFormatNode simpleFormatNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object key = PFactory.createTuple(language, new Object[]{itemtype, length});
CtypesThreadState ctypes = CtypesThreadState.get(context, context.getLanguage(inliningTarget));
Object result = getItem.execute(frame, inliningTarget, ctypes.cache, key);
@@ -127,7 +127,7 @@ static Object PyCArrayType_from_ctype(VirtualFrame frame, Object itemtype, int l
}
if (!isTypeNode.execute(inliningTarget, itemtype)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_A_TYPE_OBJECT);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_A_TYPE_OBJECT);
}
TruffleString name = simpleFormatNode.format("%s_Array_%d", getNameNode.execute(inliningTarget, itemtype), length);
PDict dict = PFactory.createDict(language, new PKeyword[]{new PKeyword(T__LENGTH_, length), new PKeyword(T__TYPE_, itemtype)});
@@ -140,8 +140,8 @@ static Object PyCArrayType_from_ctype(VirtualFrame frame, Object itemtype, int l
@Specialization(guards = "length < 0")
static Object error(@SuppressWarnings("unused") Object self, int length,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ARRAY_LENGTH_MUST_BE_0_NOT_D, length);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ARRAY_LENGTH_MUST_BE_0_NOT_D, length);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
index 593e499b8d..cc37e4ce67 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java
@@ -154,9 +154,9 @@ static void doit(VirtualFrame frame, CFieldObject self, Object inst, Object valu
@Bind("this") Node inliningTarget,
@Cached PyTypeCheck pyTypeCheck,
@Cached PyCDataSetNode cDataSetNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, inst)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NOT_A_CTYPE_INSTANCE);
+ throw raiseNode.raise(inliningTarget, TypeError, NOT_A_CTYPE_INSTANCE);
}
CDataObject dst = (CDataObject) inst;
cDataSetNode.execute(frame, dst, self.proto, self.setfunc, value, self.index, self.size, dst.b_ptr.withOffset(self.offset));
@@ -165,8 +165,8 @@ static void doit(VirtualFrame frame, CFieldObject self, Object inst, Object valu
@Specialization(guards = "isNoValue(value)")
@InliningCutoff
static void doit(CFieldObject self, Object inst, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, CANT_DELETE_ATTRIBUTE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, CANT_DELETE_ATTRIBUTE);
}
}
@@ -181,12 +181,12 @@ static Object doit(CFieldObject self, Object inst, @SuppressWarnings("unused") O
@Cached InlinedConditionProfile instIsNoValueProfile,
@Cached PyCDataGetNode pyCDataGetNode,
@Cached PyTypeCheck pyTypeCheck,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (instIsNoValueProfile.profile(inliningTarget, inst == PNone.NO_VALUE)) {
return self;
}
if (!pyTypeCheck.isCDataObject(inliningTarget, inst)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NOT_A_CTYPE_INSTANCE);
+ throw raiseNode.raise(inliningTarget, TypeError, NOT_A_CTYPE_INSTANCE);
}
CDataObject src = (CDataObject) inst;
return pyCDataGetNode.execute(inliningTarget, self.proto, self.getfunc, src, self.index, self.size, src.b_ptr.withOffset(self.offset));
@@ -245,11 +245,11 @@ static CFieldObject PyCField_FromDesc(Node inliningTarget, Object desc, int inde
@Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
CFieldObject self = PFactory.createCFieldObject(language);
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, desc);
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, HAS_NO_STGINFO);
+ throw raiseNode.raise(inliningTarget, TypeError, HAS_NO_STGINFO);
}
int fieldtype;
if (bitsize != 0 /* this is a bitfield request */
@@ -289,7 +289,7 @@ static CFieldObject PyCField_FromDesc(Node inliningTarget, Object desc, int inde
if (adict != null && adict.proto != null) {
StgDictObject idict = pyTypeStgDictNode.execute(inliningTarget, adict.proto);
if (idict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, HAS_NO_STGINFO);
+ throw raiseNode.raise(inliningTarget, TypeError, HAS_NO_STGINFO);
}
if (idict.getfunc == FieldDesc.c.getfunc) {
FieldDesc fd = FieldDesc.s;
@@ -571,7 +571,7 @@ static Object c_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Bind("this") Node inliningTarget,
@Cached GetInternalByteArrayNode getBytes,
@Exclusive @Cached PointerNodes.WriteByteNode writeByteNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (PGuards.isBytes(value)) {
PBytesLike bytes = (PBytesLike) value;
if (bytes.getSequenceStorage().length() == 1) {
@@ -588,7 +588,7 @@ static Object c_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ONE_CHARACTER_BYTES_BYTEARRAY_INTEGER_EXPECTED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ONE_CHARACTER_BYTES_BYTEARRAY_INTEGER_EXPECTED);
}
/* u - a single wchar_t character */
@@ -599,14 +599,14 @@ static Object u_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Shared @Cached TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
@Exclusive @Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) { // CTYPES_UNICODE
+ @Exclusive @Cached PRaiseNode raiseNode) { // CTYPES_UNICODE
if (!PGuards.isString(value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
}
TruffleString str = switchEncodingNode.execute(toString.execute(inliningTarget, value), WCHAR_T_ENCODING);
InternalByteArray bytes = getInternalByteArrayNode.execute(str, WCHAR_T_ENCODING);
if (bytes.getLength() != WCHAR_T_SIZE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ONE_CHARACTER_UNICODE_EXPECTED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ONE_CHARACTER_UNICODE_EXPECTED);
}
writeBytesNode.execute(inliningTarget, ptr, bytes.getArray(), bytes.getOffset(), bytes.getLength());
return PNone.NONE;
@@ -619,15 +619,15 @@ static Object U_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Shared @Cached TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
@Exclusive @Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) { // CTYPES_UNICODE
+ @Exclusive @Cached PRaiseNode raiseNode) { // CTYPES_UNICODE
if (!PGuards.isString(value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
}
TruffleString str = switchEncodingNode.execute(toString.execute(inliningTarget, value), WCHAR_T_ENCODING);
InternalByteArray bytes = getInternalByteArrayNode.execute(str, WCHAR_T_ENCODING);
if (bytes.getLength() > size) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.STR_TOO_LONG, bytes.getLength(), size);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.STR_TOO_LONG, bytes.getLength(), size);
}
writeBytesNode.execute(inliningTarget, ptr, bytes.getArray(), bytes.getOffset(), bytes.getLength());
return value;
@@ -638,9 +638,9 @@ static Object s_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Bind("this") Node inliningTarget,
@Cached ToBytesWithoutFrameNode getBytes,
@Exclusive @Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (!PGuards.isPBytes(value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, value);
}
byte[] data = getBytes.execute(inliningTarget, value);
@@ -651,7 +651,7 @@ static Object s_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
*/
++size;
} else if (size > length) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BYTES_TOO_LONG, size, length);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BYTES_TOO_LONG, size, length);
}
writeBytesNode.execute(inliningTarget, ptr, data);
@@ -665,7 +665,7 @@ static Object z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Exclusive @Cached PointerNodes.PointerFromLongNode pointerFromLongNode,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (value == PNone.NONE) {
writePointerNode.execute(inliningTarget, ptr, Pointer.NULL);
return PNone.NONE;
@@ -687,7 +687,7 @@ static Object z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
new PointerReference(value, valuePtr, PythonContext.get(inliningTarget).getSharedFinalizer());
return value;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BYTES_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BYTES_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P, value);
}
@Specialization(guards = "setfunc == Z_set")
@@ -700,7 +700,7 @@ static Object Z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) { // CTYPES_UNICODE
+ @Exclusive @Cached PRaiseNode raiseNode) { // CTYPES_UNICODE
if (value == PNone.NONE) {
writePointerNode.execute(inliningTarget, ptr, Pointer.NULL);
return PNone.NONE;
@@ -709,7 +709,7 @@ static Object Z_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
return PNone.NONE;
}
if (!PGuards.isString(value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNICODE_STR_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNICODE_STR_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P, value);
}
TruffleString str = switchEncodingNode.execute(toString.execute(inliningTarget, value), WCHAR_T_ENCODING);
@@ -729,14 +729,14 @@ static Object P_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@Exclusive @Cached PyLongCheckNode longCheckNode,
@Exclusive @Cached PointerNodes.PointerFromLongNode pointerFromLongNode,
@Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Pointer valuePtr;
if (value == PNone.NONE) {
valuePtr = Pointer.NULL;
} else if (longCheckNode.execute(inliningTarget, value)) {
valuePtr = pointerFromLongNode.execute(inliningTarget, value);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_BE_CONVERTED_TO_POINTER);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_BE_CONVERTED_TO_POINTER);
}
writePointerNode.execute(inliningTarget, ptr, valuePtr);
@@ -745,9 +745,10 @@ static Object P_set(@SuppressWarnings("unused") FieldSet setfunc, Pointer ptr, O
@SuppressWarnings("unused")
@Fallback
- static Object error(VirtualFrame frame, FieldSet setfunc, Pointer ptr, Object value, int size) {
+ static Object error(VirtualFrame frame, FieldSet setfunc, Pointer ptr, Object value, int size,
+ @Bind("this") Node inliningTarget) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.getUncached().raise(NotImplementedError, toTruffleStringUncached("Field setter %s is not supported yet."), setfunc.name());
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("Field setter %s is not supported yet."), setfunc.name());
}
private static final byte[] CTYPES_CFIELD_CAPSULE_NAME_PYMEM = PyCapsule.capsuleName("_ctypes/cfield.c pymem");
@@ -935,7 +936,7 @@ static Object O_get(@SuppressWarnings("unused") FieldGet getfunc, Pointer ptr, @
@Cached PRaiseNode raiseNode) {
Pointer valuePtr = readPointerNode.execute(inliningTarget, ptr);
if (valuePtr.isNull()) {
- throw raiseNode.raise(ValueError, ErrorMessages.PY_OBJ_IS_NULL);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.PY_OBJ_IS_NULL);
}
return readPythonObject.execute(inliningTarget, valuePtr);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CThunkObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CThunkObject.java
index 5c8fe53714..307dd8fc86 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CThunkObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CThunkObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -167,7 +167,7 @@ Object execute(Object[] pArgs,
memcpyNode.execute(inliningTarget, obj.b_ptr, value, dict.size);
arglist[i] = obj;
} else {
- throw raiseNode.raise(TypeError, CANNOT_BUILD_PARAMETER);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_BUILD_PARAMETER);
// PrintError("Parsing argument %zd\n", i);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
index 5c3bd3442d..c026873eb9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java
@@ -509,7 +509,7 @@ static Object POINTER(VirtualFrame frame, Object cls,
@Cached GetNameNode getNameNode,
@Cached CastToTruffleStringNode toTruffleStringNode,
@Cached SimpleTruffleStringFormatNode formatNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonLanguage language = context.getLanguage(inliningTarget);
CtypesThreadState ctypes = CtypesThreadState.get(context, language);
Object result = getItem.execute(frame, inliningTarget, ctypes.ptrtype_cache, cls);
@@ -530,7 +530,7 @@ static Object POINTER(VirtualFrame frame, Object cls,
result = callNode.execute(frame, PyCPointerType, args, PKeyword.EMPTY_KEYWORDS);
key = cls;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_A_CTYPES_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_A_CTYPES_TYPE);
}
HashingStorage newStorage = setItem.execute(frame, inliningTarget, ctypes.ptrtype_cache, key, result);
assert newStorage == ctypes.ptrtype_cache;
@@ -588,13 +588,13 @@ static Object buffer_info(Object arg,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, arg);
if (dict == null) {
dict = pyObjectStgDictNode.execute(inliningTarget, arg);
}
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, NOT_A_CTYPES_TYPE_OR_OBJECT);
+ throw raiseNode.raise(inliningTarget, TypeError, NOT_A_CTYPES_TYPE_OR_OBJECT);
}
Object[] shape = new Object[dict.ndim];
for (int i = 0; i < dict.ndim; ++i) {
@@ -619,16 +619,16 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object resize(CDataObject obj, int size,
@Bind("this") Node inliningTarget,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyObjectStgDictNode.execute(inliningTarget, obj);
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXCEPTED_CTYPES_INSTANCE);
+ throw raiseNode.raise(inliningTarget, TypeError, EXCEPTED_CTYPES_INSTANCE);
}
if (size < dict.size) {
- throw raiseNode.get(inliningTarget).raise(ValueError, MINIMUM_SIZE_IS_D, dict.size);
+ throw raiseNode.raise(inliningTarget, ValueError, MINIMUM_SIZE_IS_D, dict.size);
}
if (obj.b_needsfree) {
- throw raiseNode.get(inliningTarget).raise(ValueError, MEMORY_CANNOT_BE_RESIZED_BECAUSE_THIS_OBJECT_DOESN_T_OWN_IT);
+ throw raiseNode.raise(inliningTarget, ValueError, MEMORY_CANNOT_BE_RESIZED_BECAUSE_THIS_OBJECT_DOESN_T_OWN_IT);
}
obj.b_size = size;
return PNone.NONE;
@@ -746,7 +746,7 @@ static Object py_dl_open(PythonModule self, TruffleString name, int m,
} catch (Exception e) {
exception = e;
}
- throw PRaiseNode.raiseUncached(inliningTarget, OSError, getErrMsg(exception));
+ throw PRaiseNode.raiseStatic(inliningTarget, OSError, getErrMsg(exception));
}
}
@@ -758,13 +758,13 @@ protected abstract static class DlCloseNode extends PythonUnaryBuiltinNode {
static Object py_dl_close(Object pointerObj,
@Bind("this") Node inliningTarget,
@Cached CtypesNodes.HandleFromLongNode handleFromLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
DLHandler handle = handleFromLongNode.getDLHandler(inliningTarget, pointerObj);
if (handle != null) {
handle.isClosed = true;
return PNone.NONE;
}
- throw raiseNode.get(inliningTarget).raise(OSError, T_DL_ERROR);
+ throw raiseNode.raise(inliningTarget, OSError, T_DL_ERROR);
}
}
@@ -781,11 +781,11 @@ static Object ctypes_dlsym(VirtualFrame frame, Pointer handlePtr, Object n, Pyth
@Cached PyObjectHashNode hashNode,
@Cached CastToJavaStringNode asString,
@CachedLibrary(limit = "1") InteropLibrary ilib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
DLHandler handle = handleFromPointerNode.getDLHandler(inliningTarget, handlePtr);
String name = asString.execute(n);
if (handle == null || handle.isClosed) {
- throw raiseNode.get(inliningTarget).raise(error, T_DL_ERROR);
+ throw raiseNode.raise(inliningTarget, error, T_DL_ERROR);
}
try {
Object sym = ilib.readMember(handle.library, name);
@@ -801,7 +801,7 @@ static Object ctypes_dlsym(VirtualFrame frame, Pointer handlePtr, Object n, Pyth
return PFactory.createNativeVoidPtr(context.getLanguage(inliningTarget), func);
}
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
- throw raiseNode.get(inliningTarget).raise(error, e);
+ throw raiseNode.raise(inliningTarget, error, e);
}
}
}
@@ -864,9 +864,9 @@ static Object doBytes(PythonModule self, PBytes path,
@Cached ToBytesNode toBytesNode,
@CachedLibrary(limit = "1") InteropLibrary ilib,
@CachedLibrary(limit = "1") InteropLibrary resultLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!hasDynamicLoaderCache()) {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, S_SYMBOL_IS_MISSING, DYLD_SHARED_CACHE_CONTAINS_PATH);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, S_SYMBOL_IS_MISSING, DYLD_SHARED_CACHE_CONTAINS_PATH);
}
CtypesModuleBuiltins builtins = (CtypesModuleBuiltins) self.getBuiltins();
@@ -920,7 +920,7 @@ static Object align_func(Object obj,
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, obj);
if (dict != null) {
return dict.align;
@@ -931,7 +931,7 @@ static Object align_func(Object obj,
return dict.align;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, NO_ALIGNMENT_INFO);
+ throw raiseNode.raise(inliningTarget, TypeError, NO_ALIGNMENT_INFO);
}
}
@@ -944,7 +944,7 @@ static Object doit(Object obj,
@Bind("this") Node inliningTarget,
@Cached PyTypeCheck pyTypeCheck,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, obj);
if (dict != null) {
return dict.size;
@@ -953,7 +953,7 @@ static Object doit(Object obj,
if (pyTypeCheck.isCDataObject(inliningTarget, obj)) {
return ((CDataObject) obj).b_size;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, THIS_TYPE_HAS_NO_SIZE);
+ throw raiseNode.raise(inliningTarget, TypeError, THIS_TYPE_HAS_NO_SIZE);
}
}
@@ -973,7 +973,7 @@ Object doit(CDataObject obj, int offset,
@Exclusive @Cached GetClassNode getClassNode,
@Cached PyTypeCheck pyTypeCheck,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
return error(null, obj, offset, inliningTarget, getClassNode, raiseNode);
}
@@ -991,10 +991,10 @@ Object doit(CDataObject obj, int offset,
static Object error(VirtualFrame frame, Object obj, Object off,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetClassNode getClassNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object clazz = getClassNode.execute(inliningTarget, obj);
TruffleString name = GetNameNode.executeUncached(clazz);
- throw raiseNode.get(inliningTarget).raise(TypeError, BYREF_ARGUMENT_MUST_BE_A_CTYPES_INSTANCE_NOT_S, name);
+ throw raiseNode.raise(inliningTarget, TypeError, BYREF_ARGUMENT_MUST_BE_A_CTYPES_INSTANCE_NOT_S, name);
}
}
@@ -1038,9 +1038,9 @@ static Object doit(CDataObject obj,
@Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
@Cached AuditNode auditNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
- return error(obj, raiseNode.get(inliningTarget));
+ return error(obj, raiseNode);
}
auditNode.audit(inliningTarget, "ctypes.addressof", obj);
return PFactory.createNativeVoidPtr(language, obj.b_ptr);
@@ -1048,8 +1048,8 @@ static Object doit(CDataObject obj,
@Fallback
static Object error(@SuppressWarnings("unused") Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, INVALID_TYPE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, INVALID_TYPE);
}
}
@@ -1081,8 +1081,8 @@ static Object call_function(VirtualFrame frame, Object pointerObj, PTuple argume
protected abstract static class FormatErrorNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doit(@SuppressWarnings("unused") Object errorCode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -1152,10 +1152,10 @@ Object _ctypes_callproc(VirtualFrame frame, NativeFunction pProc, Object[] argar
@Cached CallNode callNode,
@Cached GetResultNode getResultNode,
@CachedLibrary(limit = "1") InteropLibrary ilib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int argcount = argarray.length;
if (argcount > CTYPES_MAX_ARGCOUNT) {
- throw raiseNode.get(inliningTarget).raise(ArgError, TOO_MANY_ARGUMENTS_D_MAXIMUM_IS_D, argcount, CTYPES_MAX_ARGCOUNT);
+ throw raiseNode.raise(inliningTarget, ArgError, TOO_MANY_ARGUMENTS_D_MAXIMUM_IS_D, argcount, CTYPES_MAX_ARGCOUNT);
}
CTypesCallArgument[] args = new CTypesCallArgument[argcount];
@@ -1184,7 +1184,7 @@ Object _ctypes_callproc(VirtualFrame frame, NativeFunction pProc, Object[] argar
try {
v = callNode.execute(frame, converters[i], arg);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(ArgError, ARGUMENT_D, i + 1);
+ throw raiseNode.raise(inliningTarget, ArgError, ARGUMENT_D, i + 1);
}
}
convParamNode.execute(frame, v, i + 1, args[i]);
@@ -1227,11 +1227,11 @@ static Object callManagedFunction(Node inliningTarget, NativeFunction pProc, Obj
throw e;
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException | AbstractTruffleException e) {
CompilerDirectives.transferToInterpreter();
- throw PRaiseNode.raiseUncached(inliningTarget, RuntimeError, FFI_CALL_FAILED);
+ throw PRaiseNode.raiseStatic(inliningTarget, RuntimeError, FFI_CALL_FAILED);
} catch (UnsupportedSpecializationException ee) {
// TODO: llvm/GR-???
CompilerDirectives.transferToInterpreter();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, toTruffleStringUncached("require backend support."));
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("require backend support."));
}
}
@@ -1246,7 +1246,7 @@ protected Object getFunction(NativeFunction pProc, String signature) throws Exce
* NFI compatible native function calls (temporary replacement)
*/
Object callNativeFunction(Node inliningTarget, NativeFunction pProc, Object[] avalues, FFIType[] atypes, FFIType restype,
- InteropLibrary ilib, PRaiseNode.Lazy raiseNode) {
+ InteropLibrary ilib, PRaiseNode raiseNode) {
Object function;
if (pProc.function != null && equals(atypes, pProc.atypes) && restype == pProc.rtype) {
function = pProc.function;
@@ -1255,7 +1255,7 @@ Object callNativeFunction(Node inliningTarget, NativeFunction pProc, Object[] av
try {
function = getFunction(pProc, signature.toJavaStringUncached());
} catch (Exception e) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, FFI_PREP_CIF_FAILED);
+ throw raiseNode.raise(inliningTarget, RuntimeError, FFI_PREP_CIF_FAILED);
}
pProc.atypes = atypes;
pProc.rtype = restype;
@@ -1266,7 +1266,7 @@ Object callNativeFunction(Node inliningTarget, NativeFunction pProc, Object[] av
return ilib.execute(function, avalues);
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
- throw PRaiseNode.raiseUncached(inliningTarget, RuntimeError, FFI_CALL_FAILED);
+ throw PRaiseNode.raiseStatic(inliningTarget, RuntimeError, FFI_CALL_FAILED);
}
}
@@ -1412,7 +1412,7 @@ static Object callGetFunc(VirtualFrame frame, Object restype, FFIType rtype, Obj
// value for large structs, because NFI still needs to allocate and pass the
// buffer for the result to the callee.
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.RETURNING_STRUCT_BY_VALUE_NOT_SUPPORTED);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.RETURNING_STRUCT_BY_VALUE_NOT_SUPPORTED);
}
case FFI_TYPE_POINTER -> {
// NOTE: we are returning pointer to the result buffer and the result buffer
@@ -1487,7 +1487,7 @@ void convParam(VirtualFrame frame, Object obj, int index, CTypesCallArgument pa,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached CArgObjectBuiltins.ParamFuncNode paramFuncNode,
@Cached ConvParamNode recursive,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (obj instanceof CDataObject cdata) {
pa.stgDict = pyObjectStgDictNode.execute(inliningTarget, cdata);
PyCArgObject carg = paramFuncNode.execute(inliningTarget, cdata, pa.stgDict);
@@ -1520,7 +1520,7 @@ void convParam(VirtualFrame frame, Object obj, int index, CTypesCallArgument pa,
pa.valuePointer = Pointer.create(pa.ffi_type, pa.ffi_type.size, asInt.executeExact(frame, inliningTarget, obj), 0);
} catch (PException e) {
e.expectOverflowError(inliningTarget, profile);
- throw raiseNode.get(inliningTarget).raise(OverflowError, INT_TOO_LONG_TO_CONVERT);
+ throw raiseNode.raise(inliningTarget, OverflowError, INT_TOO_LONG_TO_CONVERT);
}
return;
}
@@ -1560,7 +1560,7 @@ void convParam(VirtualFrame frame, Object obj, int index, CTypesCallArgument pa,
recursive.execute(frame, arg, index, pa, false);
return;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, DON_T_KNOW_HOW_TO_CONVERT_PARAMETER_D, index);
+ throw raiseNode.raise(inliningTarget, TypeError, DON_T_KNOW_HOW_TO_CONVERT_PARAMETER_D, index);
}
}
@@ -1640,9 +1640,8 @@ static Object doIntrinsicPointer(Node inliningTarget, CTypesCallArgument arg, @S
@Specialization(guards = {"mode == NFI", "isFFIType(arg, FFI_TYPE_STRUCT)"})
@SuppressWarnings("unused")
- static Object doNFIStruct(Node inliningTarget, CTypesCallArgument arg, @SuppressWarnings("unused") BackendMode mode,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError, ErrorMessages.PASSING_STRUCTS_BY_VALUE_NOT_SUPPORTED);
+ static Object doNFIStruct(Node inliningTarget, CTypesCallArgument arg, @SuppressWarnings("unused") BackendMode mode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.NotImplementedError, ErrorMessages.PASSING_STRUCTS_BY_VALUE_NOT_SUPPORTED);
}
@Specialization(guards = {"mode == LLVM", "isFFIType(arg, FFI_TYPE_STRUCT)"})
@@ -1730,6 +1729,7 @@ boolean isExecutable() {
@ExportMessage
Object execute(Object[] arguments,
+ @Bind("$node") Node inliningTarget,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@CachedLibrary("this.llvmSym") InteropLibrary ilib) {
try {
@@ -1740,7 +1740,7 @@ Object execute(Object[] arguments,
}
return ilib.execute(llvmSym, arguments);
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
- throw PRaiseNode.getUncached().raise(RuntimeError, e);
+ throw PRaiseNode.raiseStatic(inliningTarget, RuntimeError, e);
}
}
}
@@ -1758,7 +1758,7 @@ static void raiseError(Object arg,
@Cached GetClassNode getClassNode,
@Cached GetNameNode getNameNode) {
Object clazz = isTypeNode.execute(inliningTarget, arg) ? arg : getClassNode.execute(inliningTarget, arg);
- throw raiseNode.raise(TypeError, CAST_ARGUMENT_2_MUST_BE_A_POINTER_TYPE_NOT_S, getNameNode.execute(inliningTarget, clazz));
+ throw raiseNode.raise(inliningTarget, TypeError, CAST_ARGUMENT_2_MUST_BE_A_POINTER_TYPE_NOT_S, getNameNode.execute(inliningTarget, clazz));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
index b01f95d28b..90ce8009fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesNodes.java
@@ -316,7 +316,7 @@ public abstract static class PyCDataFromBaseObjNode extends Node {
@Specialization
static CDataObject PyCData_FromBaseObj(Node inliningTarget, Object type, CDataObject base, int index, Pointer adr,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached StgDictBuiltins.PyTypeStgDictNode pyTypeStgDictNode,
@Cached CreateCDataObjectNode createCDataObjectNode,
@Cached PyCDataMallocBufferNode mallocBufferNode,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
index d9910ce92a..956b8676c9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java
@@ -157,13 +157,13 @@ static Object doSet(VirtualFrame frame, CDataObject self, Object value,
@CachedLibrary("value") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = acquireLib.acquire(value, BufferFlags.PyBUF_SIMPLE, frame, indirectCallData);
try {
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
if (len > self.b_size) {
- throw raiseNode.get(inliningTarget).raise(ValueError, BYTE_STRING_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, ValueError, BYTE_STRING_TOO_LONG);
}
writeBytesNode.execute(inliningTarget, self.b_ptr, bytes, 0, len);
return PNone.NONE;
@@ -191,11 +191,11 @@ static Object doSet(CDataObject self, PBytes value,
@Bind("this") Node inliningTarget,
@Cached GetInternalByteArrayNode getBytes,
@Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = value.getSequenceStorage();
int len = storage.length();
if (len > self.b_size) {
- throw raiseNode.get(inliningTarget).raise(ValueError, BYTE_STRING_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, ValueError, BYTE_STRING_TOO_LONG);
}
byte[] bytes = getBytes.execute(inliningTarget, storage);
writeBytesNode.execute(inliningTarget, self.b_ptr, bytes, 0, len);
@@ -204,8 +204,8 @@ static Object doSet(CDataObject self, PBytes value,
@Fallback
static Object error(@SuppressWarnings("unused") Object self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BYTES_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BYTES_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
}
}
@@ -232,11 +232,11 @@ static Object doSet(CDataObject self, Object value,
@Shared @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
@Cached PointerNodes.WriteBytesNode writeBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString str = switchEncodingNode.execute(toTruffleStringNode.execute(inliningTarget, value), WCHAR_T_ENCODING);
int len = str.byteLength(WCHAR_T_ENCODING);
if (len > self.b_size) {
- throw raiseNode.get(inliningTarget).raise(ValueError, STRING_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, ValueError, STRING_TOO_LONG);
}
InternalByteArray bytes = getInternalByteArrayNode.execute(str, WCHAR_T_ENCODING);
writeBytesNode.execute(inliningTarget, self.b_ptr, bytes.getArray(), bytes.getOffset(), bytes.getLength());
@@ -245,8 +245,8 @@ static Object doSet(CDataObject self, Object value,
@Fallback
static Object error(@SuppressWarnings("unused") Object self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, UNICODE_STRING_EXPECTED_INSTEAD_OF_P_INSTANCE, value);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
index 6ad818bd6a..2315806713 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java
@@ -157,7 +157,7 @@ static Object c_wchar_p_from_param(VirtualFrame frame, Object type, Object value
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached CWCharPFromParamNode cwCharPFromParamNode,
@Cached PyObjectLookupAttr lookupAttr,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (PGuards.isString(value)) {
PyCArgObject parg = PFactory.createCArgObject(PythonLanguage.get(inliningTarget));
parg.pffi_type = ffi_type_pointer;
@@ -192,7 +192,7 @@ static Object c_wchar_p_from_param(VirtualFrame frame, Object type, Object value
if (as_parameter != PNone.NO_VALUE) {
return cwCharPFromParamNode.execute(frame, type, as_parameter);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, WRONG_TYPE);
}
}
@@ -267,7 +267,7 @@ static Object c_void_p_from_param(VirtualFrame frame, Object type, Object value,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached PyObjectLookupAttr lookupAttr,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/* c_void_p instance (or subclass) */
boolean res = isInstanceNode.executeWith(frame, value, type);
if (res) {
@@ -316,7 +316,7 @@ static Object c_void_p_from_param(VirtualFrame frame, Object type, Object value,
if (as_parameter != PNone.NO_VALUE) {
return cVoidPFromParamNode.execute(frame, type, as_parameter);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, WRONG_TYPE);
}
}
@@ -354,7 +354,7 @@ static Object c_char_p_from_param(VirtualFrame frame, Object type, Object value,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached CCharPFromParamNode cCharPFromParamNode,
@Cached PyObjectLookupAttr lookupAttr,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean res = isInstanceNode.executeWith(frame, value, type);
if (res) {
return value;
@@ -381,7 +381,7 @@ static Object c_char_p_from_param(VirtualFrame frame, Object type, Object value,
if (as_parameter != PNone.NO_VALUE) {
return cCharPFromParamNode.execute(frame, type, as_parameter);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, WRONG_TYPE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
index 43c604be2f..eab04c7cb8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java
@@ -91,7 +91,6 @@
import com.oracle.graal.python.lib.PyObjectSetItem;
import com.oracle.graal.python.lib.PyObjectSizeNode;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -135,7 +134,7 @@ static Object newCData(Object type, @SuppressWarnings("unused") Object[] args, @
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CtypesNodes.GenericPyCDataNewNode newNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
return newNode.execute(inliningTarget, type, dict);
}
@@ -166,11 +165,11 @@ static void Array_ass_item(VirtualFrame frame, CDataObject self, int index, Obje
@Bind("this") Node inliningTarget,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached PyCDataSetNode pyCDataSetNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject stgdict = pyObjectStgDictNode.execute(inliningTarget, self);
assert stgdict != null : "Cannot be NULL for array object instances";
if (index < 0 || index >= stgdict.length) {
- throw raiseNode.get(inliningTarget).raise(IndexError, INVALID_INDEX);
+ throw raiseNode.raise(inliningTarget, IndexError, INVALID_INDEX);
}
int size = stgdict.size / stgdict.length;
// self.b_ptr.createStorage(stgdict.ffi_type_pointer, stgdict.size, value);
@@ -182,8 +181,8 @@ static void Array_ass_item(VirtualFrame frame, CDataObject self, int index, Obje
@SuppressWarnings("unused")
@Specialization(guards = "isNoValue(value)")
static void error(CDataObject self, int index, PNone value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARRAY_DOES_NOT_SUPPORT_ITEM_DELETION);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARRAY_DOES_NOT_SUPPORT_ITEM_DELETION);
}
}
@@ -197,7 +196,7 @@ static void Array_ass_subscript(VirtualFrame frame, CDataObject self, Object ind
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSint,
@Shared @Cached PyCArraySetItemNode setItemNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, indexObj)) {
int index = asSint.executeExact(frame, inliningTarget, indexObj, IndexError);
if (index < 0) {
@@ -205,7 +204,7 @@ static void Array_ass_subscript(VirtualFrame frame, CDataObject self, Object ind
}
setItemNode.executeIntKey(frame, self, index, value);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, INDICES_MUST_BE_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, INDICES_MUST_BE_INTEGER);
}
}
@@ -217,14 +216,14 @@ static void Array_ass_subscript(VirtualFrame frame, CDataObject self, PSlice sli
@Cached SliceUnpack sliceUnpack,
@Cached AdjustIndices adjustIndices,
@Shared @Cached PyCArraySetItemNode setItemNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PSlice.SliceInfo sliceInfo = adjustIndices.execute(inliningTarget, self.b_length, sliceUnpack.execute(inliningTarget, slice));
int start = sliceInfo.start, step = sliceInfo.step;
int slicelen = sliceInfo.sliceLength;
int otherlen = pySequenceLength.execute(frame, inliningTarget, value);
if (otherlen != slicelen) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CAN_ONLY_ASSIGN_SEQUENCE_OF_SAME_SIZE);
+ throw raiseNode.raise(inliningTarget, ValueError, CAN_ONLY_ASSIGN_SEQUENCE_OF_SAME_SIZE);
}
for (int cur = start, i = 0; i < otherlen; cur += step, i++) {
Object item = pySequenceGetItem.execute(frame, inliningTarget, value, i);
@@ -235,8 +234,8 @@ static void Array_ass_subscript(VirtualFrame frame, CDataObject self, PSlice sli
@SuppressWarnings("unused")
@Specialization(guards = "isNoValue(value)")
static void error(CDataObject self, Object index, PNone value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARRAY_DOES_NOT_SUPPORT_ITEM_DELETION);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARRAY_DOES_NOT_SUPPORT_ITEM_DELETION);
}
}
@@ -246,7 +245,7 @@ abstract static class PyCArrayGetItemNode extends SqItemBuiltinNode {
@Specialization
static Object doIt(CDataObject self, int index,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyCDataGetNode pyCDataGetNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode) {
checkIndex(inliningTarget, self, index, raiseNode);
@@ -261,15 +260,15 @@ static Object getItem(Node inliningTarget, CDataObject self, int index, PyCDataG
return pyCDataGetNode.execute(inliningTarget, stgdict.proto, stgdict.getfunc, self, index, size, self.b_ptr.withOffset(offset));
}
- private static void checkIndex(Node inliningTarget, CDataObject self, int index, Lazy raiseNode) {
+ private static void checkIndex(Node inliningTarget, CDataObject self, int index, PRaiseNode raiseNode) {
if (index < 0 || index >= self.b_length) {
raiseInvalidIndex(inliningTarget, raiseNode);
}
}
@InliningCutoff
- private static void raiseInvalidIndex(Node inliningTarget, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(IndexError, INVALID_INDEX);
+ private static void raiseInvalidIndex(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, IndexError, INVALID_INDEX);
}
}
@@ -362,9 +361,9 @@ static Object doGeneric(VirtualFrame frame, CDataObject self, Object item,
@Cached InlinedConditionProfile negativeIndexProfile,
@Exclusive @Cached PyCDataGetNode pyCDataGetNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!indexCheckNode.execute(inliningTarget, item)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, INDICES_MUST_BE_INTEGERS);
+ throw raiseNode.raise(inliningTarget, TypeError, INDICES_MUST_BE_INTEGERS);
}
Object idx = indexNode.execute(frame, inliningTarget, item);
int index = asSizeNode.executeExact(frame, inliningTarget, idx);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
index c50d24a0b9..e0ca0bb57f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayTypeBuiltins.java
@@ -121,14 +121,14 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
@Cached HashingStorageAddAllToOther addAllToOtherNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* create the new instance (which is a class, since we are a metatype!)
*/
Object result = typeNew.execute(frame, type, args[0], args[1], args[2], kwds);
Object length_attr = lookupAttrLength.execute(frame, inliningTarget, result, T__LENGTH_);
if (length_attr == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, CLASS_MUST_DEFINE_A_LENGTH_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, AttributeError, CLASS_MUST_DEFINE_A_LENGTH_ATTRIBUTE);
}
int length;
@@ -136,26 +136,26 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
length = asSizeNode.executeExact(frame, inliningTarget, length_attr);
} catch (PException e) {
if (e.expectTypeOrOverflowError(inliningTarget, profile)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, THE_LENGTH_ATTRIBUTE_IS_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, THE_LENGTH_ATTRIBUTE_IS_TOO_LARGE);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, THE_LENGTH_ATTRIBUTE_MUST_BE_AN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, THE_LENGTH_ATTRIBUTE_MUST_BE_AN_INTEGER);
}
}
if (length < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, THE_LENGTH_ATTRIBUTE_MUST_NOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, THE_LENGTH_ATTRIBUTE_MUST_NOT_BE_NEGATIVE);
}
Object type_attr = lookupAttrType.execute(frame, inliningTarget, result, T__TYPE_);
if (type_attr == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, CLASS_MUST_DEFINE_A_TYPE_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, AttributeError, CLASS_MUST_DEFINE_A_TYPE_ATTRIBUTE);
}
StgDictObject stgdict = PFactory.createStgDictObject(language);
StgDictObject itemdict = pyTypeStgDictNode.execute(inliningTarget, type_attr);
if (itemdict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, TYPE_MUST_HAVE_STORAGE_INFO);
+ throw raiseNode.raise(inliningTarget, TypeError, TYPE_MUST_HAVE_STORAGE_INFO);
}
assert itemdict.format != null;
@@ -171,7 +171,7 @@ static Object PyCArrayType_new(VirtualFrame frame, Object type, Object[] args, P
int itemsize = itemdict.size;
if (itemsize != 0 && length > Integer.MAX_VALUE / itemsize) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ARRAY_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ARRAY_TOO_LARGE);
}
int itemalign = itemdict.align;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
index 8ffc0a903e..252f1d06f7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java
@@ -199,7 +199,7 @@ static Object simple(Object type, @SuppressWarnings("unused") Object[] args, @Su
@Bind("this") Node inliningTarget,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
return pyCDataNewNode.execute(inliningTarget, type, dict);
}
@@ -218,7 +218,7 @@ static Object usingNativePointer(Object type, Object[] args, @SuppressWarnings("
@Exclusive @Cached PointerNodes.WritePointerNode writePointerNode,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
CDataObject cdata = pyCDataNewNode.execute(inliningTarget, type, dict);
Pointer value = pointerFromLongNode.execute(inliningTarget, args[0]);
@@ -235,15 +235,15 @@ static Object callback(VirtualFrame frame, Object type, Object[] args, @Suppress
@Cached PyCallableCheckNode callableCheck,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object callable = args[0];
if (!callableCheck.execute(inliningTarget, callable)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ARGUMENT_MUST_BE_CALLABLE_OR_INTEGER_FUNCTION_ADDRESS);
+ throw raiseNode.raise(inliningTarget, TypeError, ARGUMENT_MUST_BE_CALLABLE_OR_INTEGER_FUNCTION_ADDRESS);
}
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
if (dict == null || dict.argtypes == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_CONSTRUCT_INSTANCE_OF_THIS_CLASS_NO_ARGTYPES);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_CONSTRUCT_INSTANCE_OF_THIS_CLASS_NO_ARGTYPES);
}
CThunkObject thunk = _ctypes_alloc_callback(inliningTarget, callable, dict.argtypes, dict.restype, dict.flags);
PyCFuncPtrObject self = (PyCFuncPtrObject) pyCDataNewNode.execute(inliningTarget, type, dict);
@@ -256,10 +256,9 @@ static Object callback(VirtualFrame frame, Object type, Object[] args, @Suppress
@Specialization(guards = {"args.length > 1", "!isPTuple(args)", "isLong(this, args, longCheckNode)"}, limit = "1")
static Object error(@SuppressWarnings("unused") Object type, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] kwds,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Exclusive @Cached PyLongCheckNode longCheckNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARGUMENT_MUST_BE_CALLABLE_OR_INTEGER_FUNCTION_ADDRESS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARGUMENT_MUST_BE_CALLABLE_OR_INTEGER_FUNCTION_ADDRESS);
}
static CThunkObject CThunkObjectNew(int nArgs) {
@@ -311,7 +310,7 @@ static CThunkObject _ctypes_alloc_callback(Node raisingNode, Object callable, Ob
} else {
StgDictObject dict = PyTypeStgDictNode.executeUncached(restype);
if (dict == null || dict.setfunc == FieldSet.nil) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, INVALID_RESULT_TYPE_FOR_CALLBACK_FUNCTION);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, INVALID_RESULT_TYPE_FOR_CALLBACK_FUNCTION);
}
thunk.setfunc = dict.setfunc;
thunk.ffi_restype = dict.ffi_type_pointer;
@@ -356,9 +355,9 @@ Object PyCFuncPtr_get_errcheck(PyCFuncPtrObject self, @SuppressWarnings("unused"
static Object PyCFuncPtr_set_errcheck(PyCFuncPtrObject self, Object value,
@Bind("this") Node inliningTarget,
@Cached PyCallableCheckNode callableCheck,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (value != PNone.NONE && !callableCheck.execute(inliningTarget, value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THE_ERRCHECK_ATTRIBUTE_MUST_BE_CALLABLE);
+ throw raiseNode.raise(inliningTarget, TypeError, THE_ERRCHECK_ATTRIBUTE_MUST_BE_CALLABLE);
}
self.errcheck = value;
return PNone.NONE;
@@ -392,14 +391,14 @@ static Object PyCFuncPtr_set_restype(VirtualFrame frame, PyCFuncPtrObject self,
@Cached PyObjectLookupAttr lookupAttr,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyCallableCheckNode callableCheck,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (value == PNone.NONE) {
self.checker = null;
self.restype = null;
return PNone.NONE;
}
if (pyTypeStgDictNode.execute(inliningTarget, value) == null && !callableCheck.execute(inliningTarget, value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, RESTYPE_MUST_BE_A_TYPE_A_CALLABLE_OR_NONE);
+ throw raiseNode.raise(inliningTarget, TypeError, RESTYPE_MUST_BE_A_TYPE_A_CALLABLE_OR_NONE);
}
if (!PGuards.isPFunction(value)) {
Object checker = lookupAttr.execute(frame, inliningTarget, value, T__CHECK_RETVAL_);
@@ -446,7 +445,7 @@ static Object PyCFuncPtr_set_argtypes(VirtualFrame frame, PyCFuncPtrObject self,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectLookupAttr lookupAttr,
@Shared @Cached GetInternalObjectArrayNode getArray,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage storage = value.getSequenceStorage();
Object[] ob = getArray.execute(inliningTarget, value.getSequenceStorage());
self.converters = converters_from_argtypes(frame, inliningTarget, ob, storage.length(), raiseNode, lookupAttr);
@@ -459,7 +458,7 @@ static Object PyCFuncPtr_set_argtypes(VirtualFrame frame, PyCFuncPtrObject self,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectLookupAttr lookupAttr,
@Shared @Cached GetInternalObjectArrayNode getArray,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage storage = value.getSequenceStorage();
Object[] ob = getArray.execute(inliningTarget, value.getSequenceStorage());
self.converters = converters_from_argtypes(frame, inliningTarget, ob, storage.length(), raiseNode, lookupAttr);
@@ -469,8 +468,8 @@ static Object PyCFuncPtr_set_argtypes(VirtualFrame frame, PyCFuncPtrObject self,
@Fallback
static Object error(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARGTYPES_MUST_BE_A_SEQUENCE_OF_TYPES);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARGTYPES_MUST_BE_A_SEQUENCE_OF_TYPES);
}
}
@@ -510,7 +509,8 @@ Object PyCFuncPtr_call(VirtualFrame frame, PyCFuncPtrObject self, Object[] inarg
@Cached CallProcNode callProcNode,
@Cached TruffleString.EqualNode equalNode,
@Cached PointerNodes.ReadPointerNode readPointerNode,
- @Cached CtypesNodes.HandleFromPointerNode handleFromPointerNode) {
+ @Cached CtypesNodes.HandleFromPointerNode handleFromPointerNode,
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyObjectStgDictNode.execute(inliningTarget, self);
assert dict != null : "Cannot be NULL for PyCFuncPtrObject instances";
Object restype = self.restype != null ? self.restype : dict.restype;
@@ -528,10 +528,10 @@ Object PyCFuncPtr_call(VirtualFrame frame, PyCFuncPtrObject self, Object[] inarg
* TODO this happens in a numpy tests that use structs with function pointers:
* numpy/core/tests/test_ufunc.py::TestLowlevelAPIAccess::test_loop_access
*/
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CTYPES_FUNCTION_CALL_COULD_NOT_OBTAIN_FUNCTION_POINTER);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CTYPES_FUNCTION_CALL_COULD_NOT_OBTAIN_FUNCTION_POINTER);
}
Object[] callargs = _build_callargs(frame, inliningTarget, self, argtypes, inargs, kwds, props,
- pyTypeCheck, getArray, castToJavaIntExactNode, castToTruffleStringNode, pyTypeStgDictNode, callNode, getNameNode, equalNode);
+ pyTypeCheck, getArray, castToJavaIntExactNode, castToTruffleStringNode, pyTypeStgDictNode, callNode, getNameNode, equalNode, raiseNode);
int inoutmask = props[pinoutmask_idx];
int outmask = props[poutmask_idx];
int numretvals = props[pnumretvals_idx];
@@ -546,11 +546,11 @@ Object PyCFuncPtr_call(VirtualFrame frame, PyCFuncPtrObject self, Object[] inarg
* argtypes tuple.
*/
if (required > actual) {
- throw raise(TypeError, THIS_FUNCTION_TAKES_AT_LEAST_D_ARGUMENT_S_D_GIVEN,
+ throw raiseNode.raise(inliningTarget, TypeError, THIS_FUNCTION_TAKES_AT_LEAST_D_ARGUMENT_S_D_GIVEN,
required, required == 1 ? "" : "s", actual);
}
} else if (required != actual) {
- throw raise(TypeError, THIS_FUNCTION_TAKES_D_ARGUMENT_S_D_GIVEN,
+ throw raiseNode.raise(inliningTarget, TypeError, THIS_FUNCTION_TAKES_D_ARGUMENT_S_D_GIVEN,
required, required == 1 ? "" : "s", actual);
}
}
@@ -576,7 +576,7 @@ Object PyCFuncPtr_call(VirtualFrame frame, PyCFuncPtrObject self, Object[] inarg
return _build_result(frame, inliningTarget, result, callargs, outmask, inoutmask, numretvals, callMethodObjArgs);
}
- protected Object _get_arg(int[] pindex, TruffleString name, Object defval, Object[] inargs, PKeyword[] kwds, TruffleString.EqualNode equalNode) {
+ protected Object _get_arg(Node inliningTarget, int[] pindex, TruffleString name, Object defval, Object[] inargs, PKeyword[] kwds, TruffleString.EqualNode equalNode, PRaiseNode raiseNode) {
if (pindex[0] < inargs.length) {
return inargs[pindex[0]++];
}
@@ -592,9 +592,9 @@ protected Object _get_arg(int[] pindex, TruffleString name, Object defval, Objec
}
/* we can't currently emit a better error message */
if (name != null) {
- throw raise(TypeError, REQUIRED_ARGUMENT_S_MISSING, name);
+ throw raiseNode.raise(inliningTarget, TypeError, REQUIRED_ARGUMENT_S_MISSING, name);
} else {
- throw raise(TypeError, NOT_ENOUGH_ARGUMENTS);
+ throw raiseNode.raise(inliningTarget, TypeError, NOT_ENOUGH_ARGUMENTS);
}
}
@@ -627,7 +627,7 @@ Object[] _build_callargs(VirtualFrame frame, Node inliningTarget, PyCFuncPtrObje
PyTypeStgDictNode pyTypeStgDictNode,
CallNode callNode,
GetNameNode getNameNode,
- TruffleString.EqualNode equalNode) {
+ TruffleString.EqualNode equalNode, PRaiseNode raiseNode) {
/*
* It's a little bit difficult to determine how many arguments the function call
* requires/accepts. For simplicity, we count the consumed args and compare this to the
@@ -676,7 +676,7 @@ Object[] _build_callargs(VirtualFrame frame, Node inliningTarget, PyCFuncPtrObje
case 0:
case PARAMFLAG_FIN:
/* 'in' parameter. Copy it from inargs. */
- ob = _get_arg(inargs_index, name, defval, inargs, kwds, equalNode);
+ ob = _get_arg(inliningTarget, inargs_index, name, defval, inargs, kwds, equalNode, raiseNode);
callargs[i] = ob;
break;
case PARAMFLAG_FOUT:
@@ -702,10 +702,10 @@ Object[] _build_callargs(VirtualFrame frame, Node inliningTarget, PyCFuncPtrObje
/*
* Cannot happen: _validate_paramflags() would not accept such an object
*/
- throw raise(RuntimeError, NULL_STGDICT_UNEXPECTED);
+ throw raiseNode.raise(inliningTarget, RuntimeError, NULL_STGDICT_UNEXPECTED);
}
if (PGuards.isString(dict.proto)) { // TODO Py_TPFLAGS_UNICODE_SUBCLASS
- throw raise(TypeError, S_OUT_PARAMETER_MUST_BE_PASSED_AS_DEFAULT_VALUE, getNameNode.execute(inliningTarget, ob));
+ throw raiseNode.raise(inliningTarget, TypeError, S_OUT_PARAMETER_MUST_BE_PASSED_AS_DEFAULT_VALUE, getNameNode.execute(inliningTarget, ob));
}
if (pyTypeCheck.isPyCArrayTypeObject(inliningTarget, ob)) {
ob = callNode.execute(frame, ob);
@@ -722,7 +722,7 @@ Object[] _build_callargs(VirtualFrame frame, Node inliningTarget, PyCFuncPtrObje
props[pnumretvals_idx]++;
break;
default:
- throw raise(ValueError, PARAMFLAG_D_NOT_YET_IMPLEMENTED, flag);
+ throw raiseNode.raise(inliningTarget, ValueError, PARAMFLAG_D_NOT_YET_IMPLEMENTED, flag);
}
}
@@ -738,7 +738,7 @@ Object[] _build_callargs(VirtualFrame frame, Node inliningTarget, PyCFuncPtrObje
* When we have default values or named parameters, this error message is
* misleading. See unittests/test_paramflags.py
*/
- throw raise(TypeError, CALL_TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, inargs_index, actual_args);
+ throw raiseNode.raise(inliningTarget, TypeError, CALL_TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN, inargs_index, actual_args);
}
/*
@@ -822,7 +822,7 @@ static Object PyCFuncPtr_FromDll(VirtualFrame frame, Object type, Object[] args,
@Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
@Cached AuditNode auditNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// PyArg_ParseTuple(args, "O|O", &tuple, ¶mflags);
PTuple tuple = (PTuple) args[0];
Object[] paramflags = null;
@@ -838,13 +838,13 @@ static Object PyCFuncPtr_FromDll(VirtualFrame frame, Object type, Object[] args,
Object obj = getAttributeNode.execute(frame, inliningTarget, dll, T__HANDLE);
if (!longCheckNode.execute(inliningTarget, obj)) { // PyLong_Check
- throw raiseNode.get(inliningTarget).raise(TypeError, THE_HANDLE_ATTRIBUTE_OF_THE_SECOND_ARGUMENT_MUST_BE_AN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, THE_HANDLE_ATTRIBUTE_OF_THE_SECOND_ARGUMENT_MUST_BE_AN_INTEGER);
}
Pointer handlePtr;
try {
handlePtr = pointerFromLongNode.execute(inliningTarget, obj);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.COULD_NOT_CONVERT_THE_HANDLE_ATTRIBUTE_TO_A_POINTER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.COULD_NOT_CONVERT_THE_HANDLE_ATTRIBUTE_TO_A_POINTER);
}
Object address = dlSymNode.execute(frame, handlePtr, name, AttributeError);
_validate_paramflags(inliningTarget, type, paramflags, pyTypeCheck, getArray, pyTypeStgDictNode, codePointAtIndexNode, raiseNode);
@@ -867,7 +867,7 @@ static void _validate_paramflags(Node inliningTarget, Object type, Object[] para
GetInternalObjectArrayNode getArray,
PyTypeStgDictNode pyTypeStgDictNode,
TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
Object[] argtypes = dict.argtypes;
@@ -876,12 +876,12 @@ static void _validate_paramflags(Node inliningTarget, Object type, Object[] para
}
if (!PGuards.isPTuple(paramflags)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, PARAMFLAGS_MUST_BE_A_TUPLE_OR_NONE);
+ throw raiseNode.raise(inliningTarget, TypeError, PARAMFLAGS_MUST_BE_A_TUPLE_OR_NONE);
}
int len = paramflags.length;
if (len != dict.argtypes.length) {
- throw raiseNode.get(inliningTarget).raise(ValueError, PARAMFLAGS_MUST_HAVE_THE_SAME_LENGTH_AS_ARGTYPES);
+ throw raiseNode.raise(inliningTarget, ValueError, PARAMFLAGS_MUST_HAVE_THE_SAME_LENGTH_AS_ARGTYPES);
}
for (int i = 0; i < len; ++i) {
@@ -891,7 +891,7 @@ static void _validate_paramflags(Node inliningTarget, Object type, Object[] para
int flag = (int) array[0];
if (array.length > 1) {
if (!PGuards.isString(array[1])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, PARAMFLAGS_MUST_BE_A_SEQUENCE_OF_INT_STRING_VALUE_TUPLES);
+ throw raiseNode.raise(inliningTarget, TypeError, PARAMFLAGS_MUST_BE_A_SEQUENCE_OF_INT_STRING_VALUE_TUPLES);
}
}
Object typ = argtypes[i];
@@ -905,7 +905,7 @@ static void _validate_paramflags(Node inliningTarget, Object type, Object[] para
_check_outarg_type(inliningTarget, typ, i + 1, pyTypeCheck, pyTypeStgDictNode, codePointAtIndexNode, raiseNode);
break;
default:
- throw raiseNode.get(inliningTarget).raise(TypeError, PARAMFLAG_VALUE_D_NOT_SUPPORTED, flag);
+ throw raiseNode.raise(inliningTarget, TypeError, PARAMFLAG_VALUE_D_NOT_SUPPORTED, flag);
}
}
}
@@ -915,7 +915,7 @@ static void _check_outarg_type(Node inliningTarget, Object arg, int index,
PyTypeCheck pyTypeCheck,
PyTypeStgDictNode pyTypeStgDictNode,
TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (pyTypeCheck.isPyCPointerTypeObject(inliningTarget, arg)) {
return;
}
@@ -935,7 +935,7 @@ && strchr(PzZ, codePointAtIndexNode.execute((TruffleString) dict.proto, 0, TS_EN
return;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, OUT_PARAMETER_D_MUST_BE_A_POINTER_TYPE_NOT_S, index, GetNameNode.executeUncached(arg));
+ throw raiseNode.raise(inliningTarget, TypeError, OUT_PARAMETER_D_MUST_BE_A_POINTER_TYPE_NOT_S, index, GetNameNode.executeUncached(arg));
}
protected static boolean strchr(char[] chars, int code) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
index 6a289c5bfc..c3d6f9ef14 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrTypeBuiltins.java
@@ -129,7 +129,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
@Cached HashingStorageGetItem getItem,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject stgdict = PFactory.createStgDictObject(language);
stgdict.paramfunc = CArgObjectBuiltins.PyCFuncPtrTypeParamFunc;
@@ -160,7 +160,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
Object ob = getItem.execute(inliningTarget, stgdict.getDictStorage(), T_FLAGS_);
if (!PGuards.isInteger(ob)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CLASS_MUST_DEFINE_FLAGS_WHICH_MUST_BE_AN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, CLASS_MUST_DEFINE_FLAGS_WHICH_MUST_BE_AN_INTEGER);
}
stgdict.flags = asNumber.execute(inliningTarget, ob) | TYPEFLAG_ISPOINTER;
@@ -168,7 +168,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
ob = getItem.execute(inliningTarget, stgdict.getDictStorage(), T_ARGTYPES_);
if (ob != null) {
if (!PGuards.isPTuple(ob)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ARGTYPES_MUST_BE_A_SEQUENCE_OF_TYPES);
+ throw raiseNode.raise(inliningTarget, TypeError, ARGTYPES_MUST_BE_A_SEQUENCE_OF_TYPES);
}
SequenceStorage storage = ((PTuple) ob).getSequenceStorage();
Object[] obtuple = getArray.execute(inliningTarget, storage);
@@ -181,7 +181,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
if (!PGuards.isPNone(ob)) {
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, ob);
if (dict == null && !callableCheck.execute(inliningTarget, ob)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, RESTYPE_MUST_BE_A_TYPE_A_CALLABLE_OR_NONE1);
+ throw raiseNode.raise(inliningTarget, TypeError, RESTYPE_MUST_BE_A_TYPE_A_CALLABLE_OR_NONE1);
}
stgdict.restype = ob;
Object checker = lookupAttr.execute(frame, inliningTarget, ob, T__CHECK_RETVAL_);
@@ -192,7 +192,7 @@ static Object PyCFuncPtrType_new(VirtualFrame frame, Object type, Object[] args,
}
static Object[] converters_from_argtypes(VirtualFrame frame, Node inliningTarget, Object[] args, int nArgs,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
PyObjectLookupAttr lookupAttr) {
Object[] converters = new Object[nArgs];
@@ -202,7 +202,7 @@ static Object[] converters_from_argtypes(VirtualFrame frame, Node inliningTarget
cnv = lookupAttr.execute(frame, inliningTarget, tp, T_FROM_PARAM);
if (cnv == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ITEM_D_IN_ARGTYPES_HAS_NO_FROM_PARAM_METHOD, i + 1);
+ throw raiseNode.raise(inliningTarget, TypeError, ITEM_D_IN_ARGTYPES_HAS_NO_FROM_PARAM_METHOD, i + 1);
}
converters[i] = cnv;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
index d03ce6ebfd..0f34e1b54a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java
@@ -91,7 +91,6 @@
import com.oracle.graal.python.lib.PyIndexCheckNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -135,13 +134,13 @@ abstract static class PointerSetContentsNode extends Node {
static void set(VirtualFrame frame, Node inliningTarget, CDataObject self, Object value,
@Bind PythonLanguage language,
@Cached PyTypeCheck pyTypeCheck,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached(inline = false) IsInstanceNode isInstanceNode,
@Cached KeepRefNode keepRefNode,
@Cached PointerNodes.WritePointerNode writePointerNode) {
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, POINTER_DOES_NOT_SUPPORT_ITEM_DELETION);
+ throw raiseNode.raise(inliningTarget, TypeError, POINTER_DOES_NOT_SUPPORT_ITEM_DELETION);
}
StgDictObject stgdict = pyObjectStgDictNode.execute(inliningTarget, self);
assert stgdict != null : "Cannot be NULL for pointer instances";
@@ -149,7 +148,7 @@ static void set(VirtualFrame frame, Node inliningTarget, CDataObject self, Objec
if (!pyTypeCheck.isCDataObject(inliningTarget, value)) {
boolean res = isInstanceNode.executeWith(frame, value, stgdict.proto);
if (!res) {
- raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_N_INSTEAD_OF_P, stgdict.proto, value);
+ raiseNode.raise(inliningTarget, TypeError, EXPECTED_N_INSTEAD_OF_P, stgdict.proto, value);
}
}
@@ -176,10 +175,10 @@ static Object Pointer_new(Object type, @SuppressWarnings("unused") Object[] args
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
if (dict.proto == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_CREATE_INSTANCE_HAS_NO_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_CREATE_INSTANCE_HAS_NO_TYPE);
}
return pyCDataNewNode.execute(inliningTarget, type, dict);
}
@@ -210,9 +209,9 @@ static Object get_contents(CDataObject self, @SuppressWarnings("unused") PNone v
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached CtypesNodes.PyCDataFromBaseObjNode fromBaseObjNode,
@Cached PointerNodes.ReadPointerNode readPointerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.b_ptr.isNull()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NULL_POINTER_ACCESS);
+ throw raiseNode.raise(inliningTarget, ValueError, NULL_POINTER_ACCESS);
}
StgDictObject stgdict = pyObjectStgDictNode.execute(inliningTarget, self);
@@ -253,13 +252,13 @@ static void Pointer_ass_item(VirtualFrame frame, CDataObject self, int index, Ob
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PointerNodes.ReadPointerNode readPointerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (value == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, POINTER_DOES_NOT_SUPPORT_ITEM_DELETION);
+ throw raiseNode.raise(inliningTarget, TypeError, POINTER_DOES_NOT_SUPPORT_ITEM_DELETION);
}
if (self.b_ptr.isNull()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NULL_POINTER_ACCESS);
+ throw raiseNode.raise(inliningTarget, ValueError, NULL_POINTER_ACCESS);
}
StgDictObject stgdict = pyObjectStgDictNode.execute(inliningTarget, self);
@@ -289,7 +288,7 @@ static Object Pointer_item(CDataObject self, int index,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
@Exclusive @Cached PointerNodes.ReadPointerNode readPointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.b_ptr.isNull()) {
raiseNullPtr(inliningTarget, raiseNode);
}
@@ -309,8 +308,8 @@ static Object Pointer_item(CDataObject self, int index,
}
@InliningCutoff
- private static void raiseNullPtr(Node inliningTarget, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NULL_POINTER_ACCESS);
+ private static void raiseNullPtr(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, ValueError, NULL_POINTER_ACCESS);
}
}
@@ -325,7 +324,7 @@ static Object doInt(CDataObject self, int index,
@Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
@Exclusive @Cached PointerNodes.ReadPointerNode readPointerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return PointerGetItemNode.Pointer_item(self, index, inliningTarget, pyCDataGetNode,
pyTypeStgDictNode, pyObjectStgDictNode, readPointerNode, raiseNode);
}
@@ -342,7 +341,7 @@ static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
/*
* Since pointers have no length, and we want to apply different semantics to negative
* indices than normal slicing, we have to dissect the slice object ourselves.
@@ -353,19 +352,19 @@ static Object doSubscript(VirtualFrame frame, CDataObject self, PSlice slice,
} else {
step = asSizeNode.executeExact(frame, inliningTarget, slice.getStep(), ValueError);
if (step == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SLICE_STEP_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, SLICE_STEP_CANNOT_BE_ZERO);
}
}
if (slice.getStart() == PNone.NONE) {
if (step < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SLICE_START_IS_REQUIRED_FOR_STEP_0);
+ throw raiseNode.raise(inliningTarget, ValueError, SLICE_START_IS_REQUIRED_FOR_STEP_0);
}
start = 0;
} else {
start = asSizeNode.executeExact(frame, inliningTarget, slice.getStart(), ValueError);
}
if (slice.getStop() == PNone.NONE) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SLICE_STOP_IS_REQUIRED);
+ throw raiseNode.raise(inliningTarget, ValueError, SLICE_STOP_IS_REQUIRED);
}
stop = asSizeNode.executeExact(frame, inliningTarget, slice.getStop(), ValueError);
int len;
@@ -432,12 +431,12 @@ static Object doGeneric(VirtualFrame frame, CDataObject self, Object item,
@Exclusive @Cached PointerNodes.ReadPointerNode readPointerNode,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
@Cached PyIndexCheckNode indexCheckNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, item)) {
int i = asSizeNode.executeExact(frame, inliningTarget, item, IndexError);
return PointerGetItemNode.Pointer_item(self, i, inliningTarget, pyCDataGetNode, pyTypeStgDictNode, pyObjectStgDictNode, readPointerNode, raiseNode);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, POINTER_INDICES_MUST_BE_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, POINTER_INDICES_MUST_BE_INTEGER);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
index 885b2586f8..252b5288ea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerTypeBuiltins.java
@@ -130,7 +130,7 @@ static Object PyCPointerType_new(VirtualFrame frame, Object type, Object[] args,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
@Cached StringUtils.SimpleTruffleStringFormatNode formatNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* stgdict items size, align, length contain info about pointers itself, stgdict.proto
* has info about the pointed to type!
@@ -186,9 +186,9 @@ protected abstract static class FromParamNode extends PythonBinaryBuiltinNode {
/* _byref consumes a refcount to its argument */
static PyCArgObject byref(Node inliningTarget, Object obj,
PyTypeCheck pyTypeCheck,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (!pyTypeCheck.isCDataObject(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, EXPECTED_CDATA_INSTANCE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, EXPECTED_CDATA_INSTANCE);
}
CDataObject cdata = (CDataObject) obj;
@@ -217,7 +217,7 @@ static Object PyCPointerType_from_param(VirtualFrame frame, Object type, Object
@Cached PyObjectStgDictNode pyObjectStgDictNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CDataTypeFromParamNode fromParamNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject typedict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
/*
* If we expect POINTER(), but receive a instance, accept it by calling
@@ -251,7 +251,7 @@ static Object PyCPointerType_set_type(Object self, TruffleString type,
@Cached HashingStorageSetItem setItem,
@Cached IsTypeNode isTypeNode,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, self, raiseNode);
PyCPointerType_SetProto(inliningTarget, dict, type, isTypeNode, pyTypeStgDictNode, raiseNode);
dict.setDictStorage(setItem.execute(inliningTarget, dict.getDictStorage(), T__TYPE_, type));
@@ -261,8 +261,8 @@ static Object PyCPointerType_set_type(Object self, TruffleString type,
@SuppressWarnings("unused")
@Specialization(guards = "!isString(type)")
static Object error(Object self, Object type,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, TYPE_MUST_BE_A_TYPE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, TYPE_MUST_BE_A_TYPE);
}
}
@@ -281,12 +281,12 @@ static Object error(Object self, Object type,
static void PyCPointerType_SetProto(Node inliningTarget, StgDictObject stgdict, Object proto,
IsTypeNode isTypeNode,
PyTypeStgDictNode pyTypeStgDictNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (proto == null || !isTypeNode.execute(inliningTarget, proto)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, TYPE_MUST_BE_A_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, TYPE_MUST_BE_A_TYPE);
}
if (pyTypeStgDictNode.execute(inliningTarget, proto) == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, TYPE_MUST_HAVE_STORAGE_INFO);
+ throw raiseNode.raise(inliningTarget, TypeError, TYPE_MUST_HAVE_STORAGE_INFO);
}
stgdict.proto = proto;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
index fefdf623ac..7e479d1484 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java
@@ -152,7 +152,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
@Cached TruffleString.EqualNode eqNode,
@Cached TruffleString.FromCharArrayUTF16Node fromCharArrayNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* create the new instance (which is a class, since we are a metatype!)
@@ -161,7 +161,7 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
Object proto = lookupAttrType.execute(frame, inliningTarget, result, T__TYPE_);
if (proto == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, CLASS_MUST_DEFINE_A_TYPE_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, AttributeError, CLASS_MUST_DEFINE_A_TYPE_ATTRIBUTE);
}
TruffleString proto_str;
int proto_len;
@@ -169,19 +169,19 @@ static Object PyCSimpleType_new(VirtualFrame frame, Object type, Object[] args,
proto_str = toTruffleStringNode.execute(inliningTarget, proto);
proto_len = codePointLengthNode.execute(proto_str, TS_ENCODING);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, CLASS_MUST_DEFINE_A_TYPE_STRING_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, TypeError, CLASS_MUST_DEFINE_A_TYPE_STRING_ATTRIBUTE);
}
if (proto_len != 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, A_TYPE_ATTRIBUTE_WHICH_MUST_BE_A_STRING_OF_LENGTH_1);
+ throw raiseNode.raise(inliningTarget, ValueError, A_TYPE_ATTRIBUTE_WHICH_MUST_BE_A_STRING_OF_LENGTH_1);
}
if (indexOfStringNode.execute(T_SIMPLE_TYPE_CHARS, proto_str, 0, SIMPLE_TYPE_CHARS_LENGTH, TS_ENCODING) < 0) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, WHICH_MUST_BE_A_SINGLE_CHARACTER_STRING_CONTAINING_ONE_OF_S, T_SIMPLE_TYPE_CHARS);
+ throw raiseNode.raise(inliningTarget, AttributeError, WHICH_MUST_BE_A_SINGLE_CHARACTER_STRING_CONTAINING_ONE_OF_S, T_SIMPLE_TYPE_CHARS);
}
char code = (char) codePointAtIndexNode.execute(proto_str, 0, TS_ENCODING);
FieldDesc fmt = FFIType._ctypes_get_fielddesc(code);
if (fmt == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, TYPE_S_NOT_SUPPORTED, proto_str);
+ throw raiseNode.raise(inliningTarget, ValueError, TYPE_S_NOT_SUPPORTED, proto_str);
}
StgDictObject stgdict = PFactory.createStgDictObject(language);
@@ -309,7 +309,7 @@ static Object PyCSimpleType_from_param(VirtualFrame frame, Object type, Object v
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached PyObjectLookupAttr lookupAsParam,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* If the value is already an instance of the requested type, we can use it as is
*/
@@ -345,7 +345,7 @@ static Object PyCSimpleType_from_param(VirtualFrame frame, Object type, Object v
// Py_LeaveRecursiveCall();
return r;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, WRONG_TYPE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/SimpleCDataBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/SimpleCDataBuiltins.java
index 1b6d2405f8..6a212a881f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/SimpleCDataBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/SimpleCDataBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -110,13 +110,13 @@ public void postInitialize(Python3Core core) {
}
static void Simple_set_value(VirtualFrame frame, Node inliningTarget, CDataObject self, Object value,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
PyObjectStgDictNode pyObjectStgDictNode,
SetFuncNode setFuncNode,
KeepRefNode keepRefNode) {
StgDictObject dict = pyObjectStgDictNode.execute(inliningTarget, self);
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANT_DELETE_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, TypeError, CANT_DELETE_ATTRIBUTE);
}
assert dict != null : "Cannot be NULL for CDataObject instances";
assert dict.setfunc != FieldSet.nil;
@@ -133,7 +133,7 @@ static Object newCData(Object type, @SuppressWarnings("unused") Object[] args, @
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
return pyCDataNewNode.execute(inliningTarget, type, dict);
}
@@ -149,7 +149,7 @@ static Object Simple_init(VirtualFrame frame, CDataObject self, Object[] args, @
@Cached SetFuncNode setFuncNode,
@Cached KeepRefNode keepRefNode,
@Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (args.length > 0) {
Simple_set_value(frame, inliningTarget, self, args[0], raiseNode, pyObjectStgDictNode, setFuncNode, keepRefNode);
}
@@ -178,7 +178,7 @@ static Object set_value(VirtualFrame frame, CDataObject self, Object value,
@Cached SetFuncNode setFuncNode,
@Cached KeepRefNode keepRefNode,
@Exclusive @Cached PyObjectStgDictNode pyObjectStgDictNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Simple_set_value(frame, inliningTarget, self, value, raiseNode, pyObjectStgDictNode, setFuncNode, keepRefNode);
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
index 5be831605e..42a22fdc9e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java
@@ -197,10 +197,10 @@ static void MakeFields(VirtualFrame frame, Object type, CFieldObject descr, int
@Cached("create(T__FIELDS_)") GetAttributeNode getAttrString,
@Cached MakeFieldsNode recursiveNode,
@Cached("createFor(this)") IndirectCallData indirectCallData,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object fields = getAttrString.executeObject(frame, descr.proto);
if (!sequenceCheckNode.execute(inliningTarget, fields)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, FIELDS_MUST_BE_A_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, TypeError, FIELDS_MUST_BE_A_SEQUENCE);
}
PythonContext context = PythonContext.get(inliningTarget);
@@ -215,7 +215,7 @@ static void MakeFields(VirtualFrame frame, Object type, CFieldObject descr, int
Object fname = array[0];
CFieldObject fdescr = (CFieldObject) getAttributeNode.execute(frame, inliningTarget, descr.proto, fname);
if (getClassNode.execute(inliningTarget, fdescr) != context.lookupType(CField)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, UNEXPECTED_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, UNEXPECTED_TYPE);
}
if (fdescr.anonymous != 0) {
Object state = IndirectCallContext.enter(frame, language, context, indirectCallData);
@@ -252,10 +252,10 @@ static StgDictObject executeUncached(Object type) {
return PyTypeStgDictNodeGen.getUncached().execute(null, type);
}
- protected StgDictObject checkAbstractClass(Node inliningTarget, Object type, PRaiseNode.Lazy raiseNode) {
+ protected StgDictObject checkAbstractClass(Node inliningTarget, Object type, PRaiseNode raiseNode) {
StgDictObject dict = execute(inliningTarget, type);
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ABSTRACT_CLASS);
+ throw raiseNode.raise(inliningTarget, TypeError, ABSTRACT_CLASS);
}
return dict;
}
@@ -320,20 +320,20 @@ static void MakeAnonFields(VirtualFrame frame, Object type,
@Cached GetClassNode getClassNode,
@Cached PyObjectGetAttrO getAttr,
@Cached PyObjectLookupAttr lookupAnon,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object anon = lookupAnon.execute(frame, inliningTarget, type, T__ANONYMOUS_);
if (PGuards.isPNone(anon)) {
return;
}
if (!sequenceCheckNode.execute(inliningTarget, anon)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ANONYMOUS_MUST_BE_A_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, TypeError, ANONYMOUS_MUST_BE_A_SEQUENCE);
}
for (int i = 0; i < sizeNode.execute(frame, inliningTarget, anon); ++i) {
Object fname = getItemNode.execute(frame, inliningTarget, anon, i); /* borrowed */
CFieldObject descr = (CFieldObject) getAttr.execute(frame, inliningTarget, type, fname);
if (getClassNode.execute(inliningTarget, descr) != CField) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, S_IS_SPECIFIED_IN_ANONYMOUS_BUT_NOT_IN_FIELDS, fname);
+ throw raiseNode.raise(inliningTarget, AttributeError, S_IS_SPECIFIED_IN_ANONYMOUS_BUT_NOT_IN_FIELDS, fname);
}
descr.anonymous = 1;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
index 76692aed21..cdace3dd84 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructUnionTypeBuiltins.java
@@ -236,7 +236,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to be a way to use
* the old, broken semantics: _fields_ are not extended but replaced in subclasses.
@@ -260,7 +260,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
pack = asSizeNode.executeLossy(frame, inliningTarget, tmp);
} catch (PException e) {
e.expectTypeOrOverflowError(inliningTarget, isBuiltinClassProfile);
- throw raiseNode.get(inliningTarget).raise(ValueError, PACK_MUST_BE_A_NON_NEGATIVE_INTEGER);
+ throw raiseNode.raise(inliningTarget, ValueError, PACK_MUST_BE_A_NON_NEGATIVE_INTEGER);
}
}
@@ -270,14 +270,14 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
len = sizeNode.execute(frame, inliningTarget, fields);
} catch (PException e) {
e.expectTypeError(inliningTarget, isBuiltinClassProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, FIELDS_MUST_BE_A_SEQUENCE_OF_PAIRS);
+ throw raiseNode.raise(inliningTarget, TypeError, FIELDS_MUST_BE_A_SEQUENCE_OF_PAIRS);
}
StgDictObject stgdict = pyTypeStgDictNode.execute(inliningTarget, type);
/* If this structure/union is already marked final we cannot assign _fields_ anymore. */
if ((stgdict.flags & DICTFLAG_FINAL) != 0) { /* is final ? */
- throw raiseNode.get(inliningTarget).raise(AttributeError, FIELDS_IS_FINAL);
+ throw raiseNode.raise(inliningTarget, AttributeError, FIELDS_IS_FINAL);
}
stgdict.format = null;
@@ -346,13 +346,13 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
Object pair = getItemNode.execute(frame, inliningTarget, fields, i);
// !PyArg_ParseTuple(pair, "UO|i", & name, &desc, &bitsize)
if (!PGuards.isPTuple(pair)) {
- fieldsError(raiseNode.get(inliningTarget));
+ fieldsError(inliningTarget, raiseNode);
}
SequenceStorage storage = ((PTuple) pair).getSequenceStorage();
Object[] tuple = getArray.execute(inliningTarget, storage);
int tupleLen = storage.length();
if (tupleLen < 2 || !PGuards.isString(tuple[0]) || (tupleLen > 2 && !PGuards.isInteger(tuple[2]))) {
- fieldsError(raiseNode.get(inliningTarget));
+ fieldsError(inliningTarget, raiseNode);
}
Object name = tuple[0];
Object desc = tuple[1];
@@ -363,7 +363,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
}
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, desc);
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
+ throw raiseNode.raise(inliningTarget, TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
}
stgdict.ffi_type_pointer.elements[ffi_ofs + i] = dict.ffi_type_pointer;
if ((dict.flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER)) != 0) {
@@ -389,10 +389,10 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
}
/* else fall through */
default:
- throw raiseNode.get(inliningTarget).raise(TypeError, BIT_FIELDS_NOT_ALLOWED_FOR_TYPE_S, getNameNode.execute(inliningTarget, desc));
+ throw raiseNode.raise(inliningTarget, TypeError, BIT_FIELDS_NOT_ALLOWED_FOR_TYPE_S, getNameNode.execute(inliningTarget, desc));
}
if (bitsize <= 0 || bitsize > dict.size * 8) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NUMBER_OF_BITS_INVALID_FOR_BIT_FIELD);
+ throw raiseNode.raise(inliningTarget, ValueError, NUMBER_OF_BITS_INVALID_FOR_BIT_FIELD);
}
} else {
bitsize = 0;
@@ -556,19 +556,19 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
*/
// !PyArg_ParseTuple(pair, "UO|i", & name, &desc, &bitsize)
if (!PGuards.isPTuple(pair)) {
- fieldsError(raiseNode.get(inliningTarget));
+ fieldsError(inliningTarget, raiseNode);
}
SequenceStorage storage = ((PTuple) pair).getSequenceStorage();
Object[] tuple = getArray.execute(inliningTarget, storage);
int tupleLen = storage.length();
if (tupleLen < 2 || !PGuards.isString(tuple[0]) || (tupleLen > 2 && !PGuards.isInteger(tuple[2]))) {
- fieldsError(raiseNode.get(inliningTarget));
+ fieldsError(inliningTarget, raiseNode);
}
Object desc = tuple[1];
StgDictObject dict = pyTypeStgDictNode.execute(inliningTarget, desc);
/* Possibly this check could be avoided, but see above comment. */
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
+ throw raiseNode.raise(inliningTarget, TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
}
assert (element_index < (ffi_ofs + len)); /* will be used below */
if (!pyTypeCheck.isPyCArrayTypeObject(inliningTarget, desc)) {
@@ -578,7 +578,7 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
int length = dict.length;
StgDictObject edict = pyTypeStgDictNode.execute(inliningTarget, dict.proto);
if (edict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
+ throw raiseNode.raise(inliningTarget, TypeError, SECOND_ITEM_IN_FIELDS_TUPLE_INDEX_D_MUST_BE_A_C_TYPE, i);
}
FFIType ffiType = new FFIType(
length * edict.ffi_type_pointer.size,
@@ -607,15 +607,15 @@ static void PyCStructUnionType_update_stgdict(VirtualFrame frame, Object type, O
* We did check that this flag was NOT set above, it must not have been set until now.
*/
if ((stgdict.flags & DICTFLAG_FINAL) != 0) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, STRUCTURE_OR_UNION_CANNOT_CONTAIN_ITSELF);
+ throw raiseNode.raise(inliningTarget, AttributeError, STRUCTURE_OR_UNION_CANNOT_CONTAIN_ITSELF);
}
stgdict.flags |= DICTFLAG_FINAL;
makeAnonFieldsNode.execute(frame, type);
}
- static void fieldsError(PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, FIELDS_MUST_BE_A_SEQUENCE_OF_NAME_C_TYPE_PAIRS);
+ static void fieldsError(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, TypeError, FIELDS_MUST_BE_A_SEQUENCE_OF_NAME_C_TYPE_PAIRS);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructureBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructureBuiltins.java
index b778fed0c6..100b4c048a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructureBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructureBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -113,7 +113,7 @@ static Object GenericPyCDataNew(Object type, @SuppressWarnings("unused") Object[
@Bind("this") Node inliningTarget,
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached CtypesNodes.GenericPyCDataNewNode pyCDataNewNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
StgDictObject dict = pyTypeStgDictNode.checkAbstractClass(inliningTarget, type, raiseNode);
return pyCDataNewNode.execute(inliningTarget, type, dict);
}
@@ -136,12 +136,12 @@ static Object Struct_init(VirtualFrame frame, CDataObject self, Object[] args, P
@Cached PyTypeStgDictNode pyTypeStgDictNode,
@Cached GetBaseClassNode getBaseClassNode,
@Cached TruffleString.EqualNode equalNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (args.length > 0) {
int res = _init_pos_args(frame, inliningTarget, self, getClassNode.execute(inliningTarget, self), args, kwds, 0,
indirectCallData, setAttr, getItemNode, toString, getItem, pyTypeStgDictNode, getBaseClassNode, equalNode, raiseNode, RECURSION_LIMIT);
if (res < args.length) {
- throw raiseNode.get(inliningTarget).raise(TypeError, TOO_MANY_INITIALIZERS);
+ throw raiseNode.raise(inliningTarget, TypeError, TOO_MANY_INITIALIZERS);
}
}
@@ -173,7 +173,7 @@ static int _init_pos_args(VirtualFrame frame, Node inliningTarget, Object self,
PyTypeStgDictNode pyTypeStgDictNode,
GetBaseClassNode getBaseClassNode,
EqualNode equalNode,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
int recursionLimit) {
Object fields;
int index = idx;
@@ -206,9 +206,7 @@ static int _init_pos_args(VirtualFrame frame, Node inliningTarget, Object self,
Object val = args[i + index];
if (kwds.length > 0) {
if (KeywordsStorage.findStringKey(kwds, name, equalNode) != -1) {
- // using execute() instead of raise() because we need to pass raisingNode
- // explicitly (raiseNode might be uncached)
- throw raiseNode.get(inliningTarget).execute(inliningTarget, TypeError, null, PNone.NO_VALUE, DUPLICATE_VALUES_FOR_FIELD_S, new Object[]{name});
+ throw raiseNode.raise(inliningTarget, TypeError, DUPLICATE_VALUES_FOR_FIELD_S, name);
}
}
@@ -225,7 +223,7 @@ static int _init_pos_args_boundary(Object self, Object type, Object[] args, PKey
return _init_pos_args(null, null, self, type, args, kwds, idx, indirectCallData, setAttr,
getItemNode, CastToTruffleStringNode.getUncached(),
HashingStorageGetItemNodeGen.getUncached(), PyTypeStgDictNodeGen.getUncached(),
- GetBaseClassNode.getUncached(), TruffleString.EqualNode.getUncached(), PRaiseNode.Lazy.getUncached(), 0);
+ GetBaseClassNode.getUncached(), TruffleString.EqualNode.getUncached(), PRaiseNode.getUncached(), 0);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
index 2f7f6f3093..a48fc8965c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/UnionTypeBuiltins.java
@@ -112,7 +112,7 @@ static void doStringKey(VirtualFrame frame, Object object, TruffleString key, Ob
static void doGenericKey(VirtualFrame frame, Object object, Object keyObject, Object value,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castKeyNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Exclusive @Cached ObjectNodes.GenericSetAttrNode genericSetAttrNode,
@Shared @Cached WriteAttributeToObjectNode write,
@Shared @Cached TruffleString.EqualNode equalNode,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerNodes.java
index f018dbe61e..bd13e21cf8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -671,7 +671,7 @@ static long doMemoryView(Node inliningTarget, MemoryBlock memory, MemoryViewStor
throw CompilerDirectives.shouldNotReachHere(e);
}
} else {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_CANNOT_BE_CONVERTED_TO_NATIVE_MEMORY);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_CANNOT_BE_CONVERTED_TO_NATIVE_MEMORY);
}
memory.storage = new LongPointerStorage(nativePointer);
return nativePointer + offset;
@@ -689,7 +689,7 @@ static long doPythonObject(Node inliningTarget, @SuppressWarnings("unused") Memo
if (!lib.isPointer(nativeObject)) {
lib.toNative(nativeObject);
if (!lib.isPointer(nativeObject)) {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_CONVERT_OBJECT_POINTER_TO_NATIVE);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_CONVERT_OBJECT_POINTER_TO_NATIVE);
}
}
try {
@@ -716,7 +716,7 @@ public final Object execute(Node inliningTarget, Pointer ptr) {
@Specialization
static Object doObjectPointer(Node inliningTarget, @SuppressWarnings("unused") MemoryBlock memory, ObjectPointerStorage storage, int offset) {
if (offset != 0) {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_APPLY_OFFSET_TO_AN_OBJECT_POINTER);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_APPLY_OFFSET_TO_AN_OBJECT_POINTER);
}
return storage.pointer;
}
@@ -734,7 +734,7 @@ public final long execute(Node inliningTarget, Pointer ptr) {
@Specialization
@SuppressWarnings("unused")
static long doObjectPointer(Node inliningTarget, MemoryBlock memory, ObjectPointerStorage storage, int offset) {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_CONVERT_OBJECT_POINTER_TO_NATIVE);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_CONVERT_OBJECT_POINTER_TO_NATIVE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
index 3c0ca89832..7c84fcadaf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/FunctoolsModuleBuiltins.java
@@ -124,14 +124,14 @@ Object doReduce(VirtualFrame frame, Object function, Object sequence, Object ini
@Cached InlinedConditionProfile initialNoValueProfile,
@Cached IsBuiltinObjectProfile stopIterProfile,
@Cached IsBuiltinObjectProfile typeError,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object initial = initialNoValueProfile.profile(inliningTarget, PGuards.isNoValue(initialIn)) ? null : initialIn;
Object seqIterator, result = initial;
try {
seqIterator = getIter.execute(frame, inliningTarget, sequence);
} catch (PException pe) {
pe.expectTypeError(inliningTarget, typeError);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_ARG_N_MUST_SUPPORT_ITERATION, "reduce()", 2);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_ARG_N_MUST_SUPPORT_ITERATION, "reduce()", 2);
}
Object[] args = new Object[2];
@@ -160,7 +160,7 @@ Object doReduce(VirtualFrame frame, Object function, Object sequence, Object ini
reportLoopCount(this, count >= 0 ? count : Integer.MAX_VALUE);
if (result == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, REDUCE_EMPTY_SEQ);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, REDUCE_EMPTY_SEQ);
}
return result;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
index 22456534d6..8a9614ee78 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
@@ -66,12 +66,14 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
@CoreFunctions(extendClasses = PythonBuiltinClassType.PKeyWrapper)
public final class KeyWrapperBuiltins extends PythonBuiltins {
@@ -120,8 +122,8 @@ boolean doCompare(VirtualFrame frame, PKeyWrapper self, PKeyWrapper other,
@Fallback
@SuppressWarnings("unused")
static boolean fallback(Object self, Object other,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, OTHER_ARG_MUST_BE_KEY);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, OTHER_ARG_MUST_BE_KEY);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
index 9d540461cd..0891a08e92 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/LruCacheWrapperBuiltins.java
@@ -150,10 +150,10 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
@Cached PyIndexCheckNode indexCheck,
@Cached PyNumberAsSizeNode numberAsSize,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!callableCheck.execute(inliningTarget, func)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THE_FIRST_ARGUMENT_MUST_BE_CALLABLE);
+ throw raiseNode.raise(inliningTarget, TypeError, THE_FIRST_ARGUMENT_MUST_BE_CALLABLE);
}
/* select the caching function, and make/inc maxsize_O */
@@ -174,7 +174,7 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
wrapper = WrapperType.BOUNDED;
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, MAXSIZE_SHOULD_BE_INTEGER_OR_NONE);
+ throw raiseNode.raise(inliningTarget, TypeError, MAXSIZE_SHOULD_BE_INTEGER_OR_NONE);
}
PythonContext context = PythonContext.get(inliningTarget);
@@ -258,8 +258,8 @@ static Object setDict(LruCacheObject self, PDict mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static Object setDict(@SuppressWarnings("unused") LruCacheObject self, Object mapping,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
index b7bfb230c8..612145e5f5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/PartialBuiltins.java
@@ -238,10 +238,10 @@ static Object createGeneric(Object cls, Object[] args, PKeyword[] keywords,
@Cached PyCallableCheckNode callableCheckNode,
@Bind PythonLanguage language,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object function = args[0];
if (!callableCheckNode.execute(inliningTarget, function)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_ARG_MUST_BE_CALLABLE, "the first");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_ARG_MUST_BE_CALLABLE, "the first");
}
final Object[] funcArgs = PythonUtils.arrayCopyOfRange(args, 1, args.length);
@@ -257,8 +257,8 @@ static Object createGeneric(Object cls, Object[] args, PKeyword[] keywords,
@Specialization(guards = "!atLeastOneArg(args)")
@SuppressWarnings("unused")
static Object noCallable(Object cls, Object[] args, PKeyword[] keywords,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, TYPE_S_TAKES_AT_LEAST_ONE_ARGUMENT, "partial");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, TYPE_S_TAKES_AT_LEAST_ONE_ARGUMENT, "partial");
}
}
@@ -302,8 +302,8 @@ static Object setDict(PPartial self, PDict mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static Object setDict(@SuppressWarnings("unused") PPartial self, Object mapping,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
}
@@ -358,9 +358,9 @@ static Object setState(VirtualFrame frame, PPartial self, PTuple state,
@Cached TupleNodes.ConstructTupleNode constructTupleNode,
@Cached HashingStorageCopy copyStorageNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (state.getSequenceStorage().length() != 4) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
}
final Object function = getItemNode.execute(inliningTarget, state, 0);
@@ -371,7 +371,7 @@ static Object setState(VirtualFrame frame, PPartial self, PTuple state,
if (!callableCheckNode.execute(inliningTarget, function) ||
!PGuards.isPTuple(fnArgs) ||
(fnKwargs != PNone.NONE && !PGuards.isDict(fnKwargs))) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
}
self.setFn(function);
@@ -407,8 +407,8 @@ static Object setState(VirtualFrame frame, PPartial self, PTuple state,
@Fallback
@SuppressWarnings("unused")
static Object fallback(Object self, Object state,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, INVALID_PARTIAL_STATE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Blake2ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Blake2ModuleBuiltins.java
index 7cef0d745d..fb55766a3c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Blake2ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Blake2ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -129,9 +129,9 @@ static Object newDigest(VirtualFrame frame, Object type, Object data, int digest
PNone key, PNone salt, PNone person, int fanout, int depth, int leafSize, int nodeOffset, int nodeDepth, int innerSize, boolean lastNode, boolean usedforsecurity,
@Bind("this") Node inliningTarget,
@Cached HashlibModuleBuiltins.CreateDigestNode createNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (fanout != 1 || depth != 1 || leafSize != 0 || nodeOffset != 0 || nodeDepth != 0 || innerSize != 0 || lastNode) {
- throw fail(frame, type, data, digestSize, key, salt, person, fanout, depth, leafSize, nodeOffset, nodeDepth, innerSize, lastNode, usedforsecurity, raiseNode.get(inliningTarget));
+ throw fail(frame, type, data, digestSize, key, salt, person, fanout, depth, leafSize, nodeOffset, nodeDepth, innerSize, lastNode, usedforsecurity, raiseNode);
}
PythonBuiltinClassType resultType = null;
if (type instanceof PythonBuiltinClass builtinType) {
@@ -139,7 +139,7 @@ static Object newDigest(VirtualFrame frame, Object type, Object data, int digest
} else if (type instanceof PythonBuiltinClassType enumType) {
resultType = enumType;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.WRONG_TYPE);
}
String javaName;
String pythonName;
@@ -164,8 +164,8 @@ static Object newDigest(VirtualFrame frame, Object type, Object data, int digest
static PException fail(VirtualFrame frame, Object type, Object data, Object digestSize,
Object key, Object salt, Object person, Object fanout, Object depth, Object leafSize, Object nodeOffset, Object nodeDepth, Object innerSize, Object lastNode,
Object usedforsecurity,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DIGEST_SIZE_BLAKE_ARGUMENT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DIGEST_SIZE_BLAKE_ARGUMENT);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
index a8678ca506..7cb16c038e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/DigestObjectBuiltins.java
@@ -90,11 +90,11 @@ abstract static class CopyNode extends PythonUnaryBuiltinNode {
@Specialization
static DigestObject copy(DigestObject self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return self.copy();
} catch (CloneNotSupportedException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError);
}
}
}
@@ -135,9 +135,9 @@ static PNone update(VirtualFrame frame, DigestObject self, Object buffer,
@Bind("this") Node inliningTarget,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.wasReset()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.UPDATING_FINALIZED_DIGEST_IS_NOT_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.UPDATING_FINALIZED_DIGEST_IS_NOT_SUPPORTED);
}
try {
self.update(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
index 9dff6e5708..eaabeb4ff1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java
@@ -201,13 +201,13 @@ static Object cmpStrings(Object a, Object b,
@Cached TruffleString.GetCodeRangeNode getCodeRangeNode,
@Cached CastToTruffleStringNode castA,
@Cached CastToTruffleStringNode castB,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString tsA = castA.execute(inliningTarget, a);
TruffleString tsB = castB.execute(inliningTarget, b);
CodeRange crA = getCodeRangeNode.execute(tsA, TS_ENCODING);
CodeRange crB = getCodeRangeNode.execute(tsB, TS_ENCODING);
if (!(crA.isSubsetOf(CodeRange.ASCII) && crB.isSubsetOf(CodeRange.ASCII))) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.COMPARING_STRINGS_WITH_NON_ASCII);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.COMPARING_STRINGS_WITH_NON_ASCII);
}
byte[] bytesA = getByteArrayNode.execute(tsA, TS_ENCODING);
byte[] bytesB = getByteArrayNode.execute(castB.execute(inliningTarget, b), TS_ENCODING);
@@ -220,7 +220,7 @@ static boolean cmpBuffers(VirtualFrame frame, Object a, Object b,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary accessLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (acquireLib.hasBuffer(a) && acquireLib.hasBuffer(b)) {
Object bufferA = acquireLib.acquireReadonly(a, frame, indirectCallData);
try {
@@ -236,7 +236,7 @@ static boolean cmpBuffers(VirtualFrame frame, Object a, Object b,
accessLib.release(bufferA, frame, indirectCallData);
}
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_OR_COMBINATION_OF_TYPES, a, b);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_OR_COMBINATION_OF_TYPES, a, b);
}
}
@@ -254,10 +254,10 @@ static Object hmacDigest(VirtualFrame frame, PythonModule self, Object key, Obje
@Bind("this") Node inliningTarget,
@Cached HmacNewNode newNode,
@Cached DigestObjectBuiltins.DigestNode digestNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (msg instanceof PNone) {
// hmac_digest is a bit more strict
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, msg);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, msg);
}
Object hmacObject = newNode.execute(frame, self, key, msg, digest);
return digestNode.execute(frame, hmacObject);
@@ -272,8 +272,8 @@ abstract static class HmacNewNode extends PythonQuaternaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object hmacNewError(PythonModule self, Object key, Object msg, PNone digest,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_POS, "hmac_new", "digestmod", 3);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_POS, "hmac_new", "digestmod", 3);
}
@Specialization(guards = "!isString(digestmod)")
@@ -285,7 +285,7 @@ static Object hmacNewFromFunction(VirtualFrame frame, PythonModule self, Object
@Shared("concatStr") @Cached TruffleString.ConcatNode concatStr,
@Shared("acquireLib") @CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@Shared("bufferLib") @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
// cast guaranteed in our initialize
EconomicMapStorage constructors = self.getModuleState(EconomicMapStorage.class);
Object name = getItemNode.execute(frame, inliningTarget, constructors, digestmod);
@@ -293,7 +293,7 @@ static Object hmacNewFromFunction(VirtualFrame frame, PythonModule self, Object
assert name instanceof TruffleString; // guaranteed in our initialize
return hmacNew(self, key, msg, name, inliningTarget, castStr, castJStr, concatStr, acquireLib, bufferLib, raiseNode);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.UnsupportedDigestmodError);
}
}
@@ -305,11 +305,11 @@ static Object hmacNew(@SuppressWarnings("unused") PythonModule self, Object keyO
@Shared("concatStr") @Cached TruffleString.ConcatNode concatStr,
@Shared("acquireLib") @CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@Shared("bufferLib") @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString digestmod = castStr.execute(inliningTarget, digestmodObj);
Object key;
if (!acquireLib.hasBuffer(keyObj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, keyObj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, keyObj);
} else {
key = acquireLib.acquireReadonly(keyObj);
}
@@ -320,7 +320,7 @@ static Object hmacNew(@SuppressWarnings("unused") PythonModule self, Object keyO
} else if (acquireLib.hasBuffer(msgObj)) {
msg = acquireLib.acquireReadonly(msgObj);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, msgObj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, msgObj);
}
try {
byte[] msgBytes = msg == null ? null : bufferLib.getInternalOrCopiedByteArray(msg);
@@ -329,7 +329,7 @@ static Object hmacNew(@SuppressWarnings("unused") PythonModule self, Object keyO
return PFactory.createDigestObject(PythonLanguage.get(inliningTarget), PythonBuiltinClassType.HashlibHmac,
castJStr.execute(concatStr.execute(HMAC_PREFIX, digestmod, TS_ENCODING, true)), mac);
} catch (InvalidKeyException | NoSuchAlgorithmException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError, e);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.UnsupportedDigestmodError, e);
} finally {
if (msg != null) {
bufferLib.release(msg);
@@ -365,14 +365,14 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, PythonBuiltinClassTy
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary(limit = "2") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
Object buffer;
if (value instanceof PNone) {
buffer = null;
} else if (acquireLib.hasBuffer(value)) {
buffer = acquireLib.acquireReadonly(value, frame, indirectCallData);
} else {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
}
try {
byte[] bytes = buffer == null ? null : bufferLib.getInternalOrCopiedByteArray(buffer);
@@ -381,7 +381,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, PythonBuiltinClassTy
try {
digest = createDigest(javaName, bytes, bytesLen);
} catch (NoSuchAlgorithmException e) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.UnsupportedDigestmodError, e);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.UnsupportedDigestmodError, e);
}
return PFactory.createDigestObject(PythonLanguage.get(inliningTarget), type, pythonName, digest);
} finally {
@@ -458,8 +458,8 @@ abstract static class HashNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object hash(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HASH");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HASH");
}
}
@@ -469,8 +469,8 @@ abstract static class HashXofNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object hash(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HASHXOF");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HASHXOF");
}
}
@@ -480,8 +480,8 @@ abstract static class HmacNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object hash(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HMAC");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_hashlib.HMAC");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Md5ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Md5ModuleBuiltins.java
index 4dd0f06807..f944f595f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Md5ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Md5ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -82,8 +82,8 @@ abstract static class Md5Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object md5(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_md5.md5");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_md5.md5");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha1ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha1ModuleBuiltins.java
index 98e8ef5064..34ec8c3856 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha1ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha1ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -82,8 +82,8 @@ abstract static class Sha1Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object sha1(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha1.sha1");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha1.sha1");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha256ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha256ModuleBuiltins.java
index 738dfd11c0..f62bbde73e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha256ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha256ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -93,8 +93,8 @@ abstract static class Sha224Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object sha224(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha256.sha224");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha256.sha224");
}
}
@@ -104,8 +104,8 @@ abstract static class Sha256Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object sha256(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha256.sha256");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha256.sha256");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha3ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha3ModuleBuiltins.java
index 66e35129f7..56cae0bf8f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha3ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha3ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -87,14 +87,14 @@ abstract static class ShaNode extends PythonBuiltinNode {
static Object newDigest(VirtualFrame frame, Object type, Object buffer, @SuppressWarnings("unused") Object usedForSecurity,
@Bind("this") Node inliningTarget,
@Cached HashlibModuleBuiltins.CreateDigestNode createNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonBuiltinClassType resultType;
if (type instanceof PythonBuiltinClass builtinType) {
resultType = builtinType.getType();
} else if (type instanceof PythonBuiltinClassType enumType) {
resultType = enumType;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.WRONG_TYPE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.WRONG_TYPE);
}
return createNode.execute(frame, inliningTarget, resultType, pythonNameFromType(resultType), javaNameFromType(resultType), buffer);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha512ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha512ModuleBuiltins.java
index bb60193f76..43721c3b30 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha512ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/Sha512ModuleBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -93,8 +93,8 @@ abstract static class Sha384Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object sha384(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha512.sha384");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha512.sha384");
}
}
@@ -104,8 +104,8 @@ abstract static class Sha512Node extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object sha512(Object args, Object kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha512.sha512");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, "_sha512.sha512");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
index 268a976356..7e18f650da 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/ShakeDigestObjectBuiltins.java
@@ -96,9 +96,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
static PBytes digest(DigestObject self, int length,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getDigestLength() != length) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFAULT_DIGEST_LENGTHS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFAULT_DIGEST_LENGTHS);
}
return PFactory.createBytes(language, self.digest());
}
@@ -117,9 +117,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
static TruffleString hexdigest(DigestObject self, int length,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.ByteToHexNode toHexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getDigestLength() != length) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFAULT_DIGEST_LENGTHS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFAULT_DIGEST_LENGTHS);
}
byte[] digest = self.digest();
return toHexNode.execute(inliningTarget, digest, digest.length, (byte) 0, 0);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
index 10d38fa1fc..71f1cc86c9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/AbstractBufferedIOBuiltins.java
@@ -100,8 +100,8 @@ static void bufferedInit(VirtualFrame frame, Node inliningTarget, PBuffered self
@SuppressWarnings("unused")
@Specialization(guards = "bufferSize <= 0")
static void bufferSizeError(PBuffered self, int bufferSize,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, BUF_SIZE_POS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, BUF_SIZE_POS);
}
private static void init(PBuffered self, int bufferSize, PythonLanguage language) {
@@ -165,11 +165,11 @@ protected ArgumentClinicProvider getArgumentClinic() {
@SuppressWarnings("unused")
@Specialization(guards = "!self.isOK()")
static Object initError(PBuffered self, Object o,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (self.isDetached()) {
- throw raiseNode.raise(ValueError, IO_STREAM_DETACHED);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_STREAM_DETACHED);
} else {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
}
@@ -179,11 +179,11 @@ abstract static class PythonBinaryWithInitErrorBuiltinNode extends PythonBinaryB
@SuppressWarnings("unused")
@Specialization(guards = "!self.isOK()")
static Object initError(PBuffered self, Object buffer,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (self.isDetached()) {
- throw raiseNode.raise(ValueError, IO_STREAM_DETACHED);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_STREAM_DETACHED);
} else {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
}
@@ -192,11 +192,11 @@ abstract static class PythonUnaryWithInitErrorBuiltinNode extends PythonUnaryBui
@SuppressWarnings("unused")
@Specialization(guards = "!self.isOK()")
static Object initError(PBuffered self,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (self.isDetached()) {
- throw raiseNode.raise(ValueError, IO_STREAM_DETACHED);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_STREAM_DETACHED);
} else {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java
index d2c08166f0..150cdc080d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -100,8 +100,8 @@ abstract static class DetachNode extends PythonBuiltinNode {
*/
@Specialization
static Object detach(@SuppressWarnings("unused") Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_DETACH);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_DETACH);
}
}
@@ -115,8 +115,8 @@ abstract static class ReadNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object read(Object self, Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_READ);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_READ);
}
}
@@ -130,8 +130,8 @@ abstract static class Read1Node extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object read1(Object self, Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_READ1);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_READ1);
}
}
@@ -153,18 +153,18 @@ Object readinto(VirtualFrame frame, Object self, Object buffer,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached InlinedConditionProfile isBytes,
@Cached InlinedConditionProfile oversize,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int len = bufferLib.getBufferLength(buffer);
Object data = callMethod.execute(frame, inliningTarget, self, getMethodName(), len);
if (isBytes.profile(inliningTarget, !(data instanceof PBytes))) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_SHOULD_RETURN_BYTES, "read()");
+ throw raiseNode.raise(inliningTarget, ValueError, S_SHOULD_RETURN_BYTES, "read()");
}
// Directly using data as buffer because CPython also accesses the underlying memory
// of the bytes object
int dataLen = bufferLib.getBufferLength(data);
if (oversize.profile(inliningTarget, dataLen > len)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_RETURNED_TOO_MUCH_DATA, "read()", len, dataLen);
+ throw raiseNode.raise(inliningTarget, ValueError, S_RETURNED_TOO_MUCH_DATA, "read()", len, dataLen);
}
bufferLib.readIntoBuffer(data, 0, buffer, 0, dataLen, bufferLib);
return dataLen;
@@ -219,8 +219,8 @@ abstract static class WriteNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static Object write(Object self, Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_WRITE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_WRITE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
index 16089c404f..2d56ea743f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -110,7 +110,6 @@
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -283,17 +282,17 @@ static long doit(VirtualFrame frame, PBuffered self, Object off, int whence,
@Specialization(guards = {"self.isOK()", "!isSupportedWhence(whence)"})
static Object whenceError(@SuppressWarnings("unused") PBuffered self, @SuppressWarnings("unused") int off, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, UNSUPPORTED_WHENCE, whence);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, UNSUPPORTED_WHENCE, whence);
}
@Specialization(guards = "!self.isOK()")
static Object initError(PBuffered self, @SuppressWarnings("unused") int off, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (self.isDetached()) {
- throw raiseNode.raise(ValueError, IO_STREAM_DETACHED);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_STREAM_DETACHED);
} else {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
}
@@ -345,8 +344,8 @@ static Object doit(VirtualFrame frame, PBuffered self, Object pos,
@Specialization(guards = {"self.isOK()", "!self.isWritable()"})
static Object notWritable(@SuppressWarnings("unused") PBuffered self, @SuppressWarnings("unused") Object pos,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_TRUNCATE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_TRUNCATE);
}
}
@@ -413,7 +412,7 @@ static TruffleString repr(VirtualFrame frame, PBuffered self,
@Cached IsBuiltinObjectProfile isValueError,
@Cached PyObjectReprAsTruffleStringNode repr,
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString typeName = getNameNode.execute(inliningTarget, getClassNode.execute(inliningTarget, self));
Object nameobj = PNone.NO_VALUE;
try {
@@ -426,7 +425,7 @@ static TruffleString repr(VirtualFrame frame, PBuffered self,
return simpleTruffleStringFormatNode.format("<%s>", typeName);
} else {
if (!PythonContext.get(inliningTarget).reprEnter(self)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, REENTRANT_CALL_INSIDE_S_REPR, typeName);
+ throw raiseNode.raise(inliningTarget, RuntimeError, REENTRANT_CALL_INSIDE_S_REPR, typeName);
} else {
try {
TruffleString name = repr.execute(frame, inliningTarget, nameobj);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
index 1604b1a4dd..7dbf414744 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
@@ -109,10 +109,10 @@ public CheckIsClosedNode(TruffleString method) {
@Specialization
boolean isClosedBuffered(VirtualFrame frame, PBuffered self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached IsClosedNode isClosedNode) {
if (isClosedNode.execute(frame, inliningTarget, self)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, messageFmt, method);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, messageFmt, method);
}
return false;
}
@@ -155,11 +155,11 @@ static boolean isSeekable(VirtualFrame frame, PBuffered self,
@Bind("this") Node inliningTarget,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectIsTrueNode isTrue,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
assert self.isOK();
Object res = callMethod.execute(frame, inliningTarget, self.getRaw(), T_SEEKABLE);
if (!isTrue.execute(frame, res)) {
- throw raiseNode.get(inliningTarget).raise(IOUnsupportedOperation, FILE_OR_STREAM_IS_NOT_SEEKABLE);
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, FILE_OR_STREAM_IS_NOT_SEEKABLE);
}
return true;
}
@@ -181,7 +181,7 @@ static long doInt(long number, @SuppressWarnings("unused") PythonBuiltinClassTyp
@Specialization
static long toLong(VirtualFrame frame, Node inliningTarget, Object number, PythonBuiltinClassType err,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyNumberIndexNode indexNode,
@Cached CastToJavaLongExactNode cast,
@Cached IsBuiltinObjectProfile errorProfile) {
@@ -190,7 +190,7 @@ static long toLong(VirtualFrame frame, Node inliningTarget, Object number, Pytho
return cast.execute(inliningTarget, index);
} catch (PException e) {
e.expect(inliningTarget, OverflowError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(err, CANNOT_FIT_P_IN_OFFSET_SIZE, number);
+ throw raiseNode.raise(inliningTarget, err, CANNOT_FIT_P_IN_OFFSET_SIZE, number);
} catch (CannotCastException e) {
throw CompilerDirectives.shouldNotReachHere();
}
@@ -218,12 +218,12 @@ public final long executeCached(VirtualFrame frame, PBuffered self) {
*/
@Specialization
static long bufferedRawTell(VirtualFrame frame, Node inliningTarget, PBuffered self,
- @Cached PRaiseNode.Lazy lazyRaiseNode,
+ @Cached PRaiseNode lazyRaiseNode,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached AsOffNumberNode asOffNumberNode) {
long n = tell(frame, inliningTarget, self.getRaw(), callMethod, asOffNumberNode);
if (n < 0) {
- throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_STREAM_INVALID_POS, n);
+ throw lazyRaiseNode.raise(inliningTarget, OSError, IO_STREAM_INVALID_POS, n);
}
self.setAbsPos(n);
return n;
@@ -278,13 +278,13 @@ abstract static class RawSeekNode extends PNodeWithContext {
@Specialization
static long bufferedRawSeek(VirtualFrame frame, PBuffered self, long target, int whence,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached AsOffNumberNode asOffNumberNode) {
Object res = callMethod.execute(frame, inliningTarget, self.getRaw(), T_SEEK, target, whence);
long n = asOffNumberNode.execute(frame, inliningTarget, res, ValueError);
if (n < 0) {
- raise.get(inliningTarget).raise(OSError, IO_STREAM_INVALID_POS, n);
+ raise.raise(inliningTarget, OSError, IO_STREAM_INVALID_POS, n);
}
self.setAbsPos(n);
return n;
@@ -456,7 +456,7 @@ static void normal(Node inliningTarget, PBuffered self,
@Specialization(guards = {"!self.isOwn()", "getContext().isFinalizing()"})
static void finalizing(Node inliningTarget, PBuffered self,
- @Shared @Cached PRaiseNode.Lazy lazyRaise) {
+ @Shared @Cached PRaiseNode lazyRaise) {
/*
* When finalizing, we don't want a deadlock to happen with daemon threads abruptly shut
* down while they owned the lock. Therefore, only wait for a grace period (1 s.). Note
@@ -464,14 +464,14 @@ static void finalizing(Node inliningTarget, PBuffered self,
* written threaded I/O code.
*/
if (!self.getLock().acquireTimeout(inliningTarget, (long) 1e3)) {
- throw lazyRaise.get(inliningTarget).raise(SystemError, SHUTDOWN_POSSIBLY_DUE_TO_DAEMON_THREADS);
+ throw lazyRaise.raise(inliningTarget, SystemError, SHUTDOWN_POSSIBLY_DUE_TO_DAEMON_THREADS);
}
}
@Specialization(guards = "self.isOwn()")
static void error(Node inliningTarget, PBuffered self,
- @Shared @Cached PRaiseNode.Lazy lazyRaise) {
- throw lazyRaise.get(inliningTarget).raise(RuntimeError, REENTRANT_CALL_INSIDE_P, self);
+ @Shared @Cached PRaiseNode lazyRaise) {
+ throw lazyRaise.raise(inliningTarget, RuntimeError, REENTRANT_CALL_INSIDE_P, self);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
index 4a6189b539..145befb24e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedRWPairBuiltins.java
@@ -147,8 +147,8 @@ protected static boolean isInit(PRWPair self) {
@SuppressWarnings("unused")
@Specialization(guards = "!isInit(self)")
static Object error(VirtualFrame frame, PRWPair self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -161,8 +161,8 @@ protected static boolean isInit(PRWPair self) {
@SuppressWarnings("unused")
@Specialization(guards = "!isInit(self)")
static Object error(VirtualFrame frame, PRWPair self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -175,8 +175,8 @@ protected static boolean isInit(PRWPair self) {
@SuppressWarnings("unused")
@Specialization(guards = "!isInit(self)")
static Object error(VirtualFrame frame, PRWPair self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -189,8 +189,8 @@ protected static boolean isInit(PRWPair self) {
@SuppressWarnings("unused")
@Specialization(guards = "!isInit(self)")
static Object error(VirtualFrame frame, PRWPair self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -305,7 +305,7 @@ static Object close(VirtualFrame frame, PRWPair self,
@Cached InlinedConditionProfile gotException,
@Cached InlinedBranchProfile hasException,
@Cached PyErrChainExceptions chainExceptions,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PException writeEx = null;
if (self.getWriter() != null) {
try {
@@ -315,7 +315,7 @@ static Object close(VirtualFrame frame, PRWPair self,
writeEx = e;
}
} else {
- writeEx = raiseNode.get(inliningTarget).raise(ValueError, IO_UNINIT);
+ writeEx = raiseNode.raise(inliningTarget, ValueError, IO_UNINIT);
}
PException readEx;
@@ -330,7 +330,7 @@ static Object close(VirtualFrame frame, PRWPair self,
readEx = e;
}
} else {
- readEx = raiseNode.get(inliningTarget).raise(ValueError, IO_UNINIT);
+ readEx = raiseNode.raise(inliningTarget, ValueError, IO_UNINIT);
}
hasException.enter(inliningTarget);
@@ -379,8 +379,8 @@ static Object doit(VirtualFrame frame, PRWPair self,
@SuppressWarnings("unused")
@Fallback
static Object error(VirtualFrame frame, Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(RuntimeError, THE_S_OBJECT_IS_BEING_GARBAGE_COLLECTED, "BufferedRWPair");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, RuntimeError, THE_S_OBJECT_IS_BEING_GARBAGE_COLLECTED, "BufferedRWPair");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
index 6e9a6459af..c619347623 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java
@@ -75,6 +75,7 @@
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.io.BufferedIONodes.CheckIsClosedNode;
import com.oracle.graal.python.builtins.modules.io.BufferedIONodes.EnterBufferedNode;
import com.oracle.graal.python.builtins.modules.io.BufferedIONodes.FlushAndRewindUnlockedNode;
@@ -141,7 +142,7 @@ static byte[] bufferedreaderRawRead(VirtualFrame frame, Node inliningTarget, PBu
@Cached PyObjectCallMethodObjArgs callMethodReadInto,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached InlinedConditionProfile osError,
- @Cached PRaiseNode.Lazy lazyRaiseNode) {
+ @Cached PRaiseNode lazyRaiseNode) {
PByteArray memobj = PFactory.createByteArray(language, new byte[len]);
// TODO _PyIO_trap_eintr [GR-23297]
Object res = callMethodReadInto.execute(frame, inliningTarget, self.getRaw(), T_READINTO, memobj);
@@ -153,10 +154,10 @@ static byte[] bufferedreaderRawRead(VirtualFrame frame, Node inliningTarget, PBu
try {
n = asSizeNode.executeExact(frame, inliningTarget, res, ValueError);
} catch (PException e) {
- throw lazyRaiseNode.get(inliningTarget).raiseWithCause(OSError, e, ErrorMessages.RAW_READINTO_FAILED);
+ throw lazyRaiseNode.raiseWithCause(inliningTarget, OSError, e, ErrorMessages.RAW_READINTO_FAILED);
}
if (osError.profile(inliningTarget, n < 0 || n > len)) {
- throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_S_INVALID_LENGTH, "readinto()", n, len);
+ throw lazyRaiseNode.raise(inliningTarget, OSError, IO_S_INVALID_LENGTH, "readinto()", n, len);
}
if (n > 0 && self.getAbsPos() != -1) {
self.incAbsPos(n);
@@ -394,7 +395,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
@Cached GetClassNode getClassNode,
@Cached PyObjectCallMethodObjArgs callMethod,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkIsClosedNode.execute(frame, self);
try {
lock.enter(inliningTarget, self);
@@ -418,7 +419,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
if (hasReadallProfile.profile(inliningTarget, readall != PNone.NO_VALUE)) {
Object tmp = dispatchGetattribute.executeObject(frame, readall, self.getRaw());
if (tmp != PNone.NONE && !(tmp instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IO_S_SHOULD_RETURN_BYTES, "readall()");
+ throw raiseNode.raise(inliningTarget, TypeError, IO_S_SHOULD_RETURN_BYTES, "readall()");
}
if (currentSize0Profile.profile(inliningTarget, currentSize != 0)) {
if (tmp != PNone.NONE) {
@@ -446,7 +447,7 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
/* Read until EOF or until read() would block. */
Object r = callMethod.execute(frame, inliningTarget, self.getRaw(), T_READ);
if (r != PNone.NONE && !(r instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IO_S_SHOULD_RETURN_BYTES, "read()");
+ throw raiseNode.raise(inliningTarget, TypeError, IO_S_SHOULD_RETURN_BYTES, "read()");
}
if (r != PNone.NONE) {
dataLen = bufferLib.getBufferLength(r);
@@ -472,8 +473,8 @@ Object bufferedreaderReadAll(VirtualFrame frame, PBuffered self, @SuppressWarnin
@SuppressWarnings("unused")
@Specialization(guards = {"self.isOK()", "!isValidSize(size)"})
static Object initError(VirtualFrame frame, PBuffered self, int size,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MUST_BE_NON_NEG_OR_NEG_1);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_BE_NON_NEG_OR_NEG_1);
}
}
@@ -824,11 +825,11 @@ static PBytes doit(VirtualFrame frame, PBuffered self,
@Bind("this") Node inliningTarget,
@Cached("create(T_READLINE)") CheckIsClosedNode checkIsClosedNode,
@Cached BufferedReadlineNode readlineNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkIsClosedNode.execute(frame, self);
byte[] line = readlineNode.execute(frame, inliningTarget, self, -1);
if (line.length == 0) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return PFactory.createBytes(PythonLanguage.get(inliningTarget), line);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
index af283f1837..30404126c1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedWriterNodes.java
@@ -227,7 +227,7 @@ static int bufferedwriterRawWrite(VirtualFrame frame, Node inliningTarget, PBuff
@Bind PythonLanguage language,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy lazyRaiseNode) {
+ @Cached PRaiseNode lazyRaiseNode) {
PBytes memobj = PFactory.createBytes(language, buf, len);
Object res = callMethod.execute(frame, inliningTarget, self.getRaw(), T_WRITE, memobj);
if (res == PNone.NONE) {
@@ -238,7 +238,7 @@ static int bufferedwriterRawWrite(VirtualFrame frame, Node inliningTarget, PBuff
}
int n = asSizeNode.executeExact(frame, inliningTarget, res, ValueError);
if (n < 0 || n > len) {
- throw lazyRaiseNode.get(inliningTarget).raise(OSError, IO_S_INVALID_LENGTH, "write()", n, len);
+ throw lazyRaiseNode.raise(inliningTarget, OSError, IO_S_INVALID_LENGTH, "write()", n, len);
}
if (n > 0 && self.getAbsPos() != -1) {
self.incAbsPos(n);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
index f5d34eac5f..fab9fb561e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java
@@ -142,8 +142,8 @@ abstract static class ClosedCheckPythonUnaryBuiltinNode extends PythonUnaryBuilt
@Specialization(guards = "!self.hasBuf()")
@SuppressWarnings("unused")
static Object closedError(PBytesIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -151,8 +151,8 @@ abstract static class ClosedCheckPythonBinaryBuiltinNode extends PythonBinaryBui
@Specialization(guards = "!self.hasBuf()")
@SuppressWarnings("unused")
static Object closedError(PBytesIO self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -166,8 +166,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "!self.hasBuf()")
@SuppressWarnings("unused")
static Object closedError(PBytesIO self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -181,7 +181,7 @@ public abstract static class InitNode extends PythonBinaryBuiltinNode {
@SuppressWarnings("unused")
static PNone init(PBytesIO self, PNone initvalue,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
self.setPos(0);
return PNone.NONE;
@@ -191,7 +191,7 @@ static PNone init(PBytesIO self, PNone initvalue,
static PNone init(VirtualFrame frame, PBytesIO self, Object initvalue,
@Bind("this") Node inliningTarget,
@Cached WriteNode writeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
/* In case, __init__ is called multiple times. */
self.setStringSize(0);
self.setPos(0);
@@ -399,10 +399,10 @@ static Object truncate(PBytesIO self, int size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
if (size < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NEGATIVE_SIZE_VALUE_D, size);
+ throw raiseNode.raise(inliningTarget, ValueError, NEGATIVE_SIZE_VALUE_D, size);
}
if (size < self.getStringSize()) {
self.unshareAndResize(bufferLib, language, size, true);
@@ -416,7 +416,7 @@ static Object truncate(PBytesIO self, @SuppressWarnings("unused") PNone size,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return truncate(self, self.getPos(), inliningTarget, language, bufferLib, raiseNode);
}
@@ -426,7 +426,7 @@ static Object truncate(VirtualFrame frame, PBytesIO self, Object size,
@Bind PythonLanguage language,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared("lib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return truncate(self, asSizeNode.executeExact(frame, inliningTarget, size), inliningTarget, language, bufferLib, raiseNode);
}
}
@@ -442,7 +442,7 @@ static Object doWrite(VirtualFrame frame, PBytesIO self, Object b,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("b") PythonBufferAcquireLibrary acquireLib,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
Object buffer = acquireLib.acquireReadonly(b, frame, indirectCallData);
try {
@@ -475,7 +475,7 @@ static Object writeLines(VirtualFrame frame, PBytesIO self, Object lines,
@Cached WriteNode writeNode,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached PyObjectGetIter getIter,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
Object iter = getIter.execute(frame, inliningTarget, lines);
while (true) {
@@ -560,35 +560,35 @@ static Object seek(PBytesIO self, int pos, int whence) {
@Specialization(guards = {"self.hasBuf()", "!isSupportedWhence(whence)"})
static Object whenceError(@SuppressWarnings("unused") PBytesIO self, @SuppressWarnings("unused") int pos, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, INVALID_WHENCE_D_SHOULD_BE_0_1_OR_2, whence);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INVALID_WHENCE_D_SHOULD_BE_0_1_OR_2, whence);
}
@SuppressWarnings("unused")
@Specialization(guards = {"self.hasBuf()", "isLargePos(pos, self.getPos())", "whence == 1"})
static Object largePos1(PBytesIO self, int pos, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(OverflowError, NEW_POSITION_TOO_LARGE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, OverflowError, NEW_POSITION_TOO_LARGE);
}
@SuppressWarnings("unused")
@Specialization(guards = {"self.hasBuf()", "isLargePos(pos, self.getStringSize())", "whence == 2"})
static Object largePos2(PBytesIO self, int pos, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(OverflowError, NEW_POSITION_TOO_LARGE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, OverflowError, NEW_POSITION_TOO_LARGE);
}
@Specialization(guards = {"self.hasBuf()", "pos < 0", "whence == 0"})
static Object negPos(@SuppressWarnings("unused") PBytesIO self, int pos, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, NEGATIVE_SEEK_VALUE_D, pos);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, NEGATIVE_SEEK_VALUE_D, pos);
}
@SuppressWarnings("unused")
@Specialization(guards = "!self.hasBuf()")
static Object closedError(PBytesIO self, int pos, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -650,12 +650,12 @@ static Object doit(VirtualFrame frame, PBytesIO self, PTuple state,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached GetOrCreateDictNode getDict,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
SequenceStorage storage = state.getSequenceStorage();
Object[] array = getArray.execute(inliningTarget, storage);
if (storage.length() < 3) {
- return notTuple(self, state, raiseNode.get(inliningTarget));
+ return notTuple(self, state, raiseNode);
}
/*
* Reset the object to its default state. This is only needed to handle the case of
@@ -674,18 +674,18 @@ static Object doit(VirtualFrame frame, PBytesIO self, PTuple state,
* against erroneous (or malicious) inputs.
*/
if (!indexCheckNode.execute(inliningTarget, array[1])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SECOND_ITEM_OF_STATE_MUST_BE_AN_INTEGER_NOT_P, array[1]);
+ throw raiseNode.raise(inliningTarget, TypeError, SECOND_ITEM_OF_STATE_MUST_BE_AN_INTEGER_NOT_P, array[1]);
}
int pos = asSizeNode.executeExact(frame, inliningTarget, array[1]);
if (pos < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, POSITION_VALUE_CANNOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, POSITION_VALUE_CANNOT_BE_NEGATIVE);
}
self.setPos(pos);
/* Set the dictionary of the instance variables. */
if (!PGuards.isNone(array[2])) {
if (!PGuards.isDict(array[2])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THIRD_ITEM_OF_STATE_SHOULD_BE_A_DICT_GOT_A_P, array[2]);
+ throw raiseNode.raise(inliningTarget, TypeError, THIRD_ITEM_OF_STATE_SHOULD_BE_A_DICT_GOT_A_P, array[2]);
}
/*
* Alternatively, we could replace the internal dictionary completely. However, it
@@ -699,8 +699,8 @@ static Object doit(VirtualFrame frame, PBytesIO self, PTuple state,
@Specialization(guards = "!isPTuple(state)")
static Object notTuple(PBytesIO self, Object state,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, P_SETSTATE_ARGUMENT_SHOULD_BE_D_TUPLE_GOT_P, self, 3, state);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, P_SETSTATE_ARGUMENT_SHOULD_BE_D_TUPLE_GOT_P, self, 3, state);
}
}
@@ -761,7 +761,7 @@ abstract static class CloseNode extends PythonUnaryBuiltinNode {
@Specialization
static Object close(PBytesIO self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkExports(inliningTarget, raiseNode);
self.setBuf(null);
return PNone.NONE;
@@ -777,10 +777,10 @@ static Object doit(PBytesIO self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int n = scanEOL(self, -1, bufferLib);
if (n == 0) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return readBytes(self, n, bufferLib, language);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
index 85aa552c4b..2fee23d480 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java
@@ -238,11 +238,11 @@ private static int open(VirtualFrame frame, TruffleString name, int flags, int m
PosixSupportLibrary posixLib,
GilNode gil,
InlinedBranchProfile errorProfile,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
Object path = posixLib.createPathFromString(ctxt.getPosixSupport(), name);
if (path == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, EMBEDDED_NULL_BYTE);
+ throw raiseNode.raise(inliningTarget, ValueError, EMBEDDED_NULL_BYTE);
}
while (true) {
try {
@@ -328,7 +328,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
@Cached InlinedConditionProfile errorProfile,
@Cached(inline = false) GilNode gil,
@Cached(inline = false) TruffleString.FromLongNode fromLongNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
if (self.getFD() >= 0) {
if (self.isCloseFD()) {
@@ -358,7 +358,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
} else {
self.setCloseFD(true);
if (errorProfile.profile(inliningTarget, !closefd)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, CANNOT_USE_CLOSEFD);
+ throw raiseNode.raise(inliningTarget, ValueError, CANNOT_USE_CLOSEFD);
}
if (opener instanceof PNone) {
@@ -366,7 +366,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
} else {
Object fdobj = callOpener.execute(frame, opener, nameobj, flags);
if (!indexCheckNode.execute(inliningTarget, fdobj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_INT_FROM_OPENER);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_INT_FROM_OPENER);
}
self.setFD(asSizeNode.executeExact(frame, inliningTarget, fdobj), context);
@@ -375,7 +375,7 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
* The opener returned a negative but didn't set an exception. See issue
* #27066
*/
- throw raiseNode.get(inliningTarget).raise(ValueError, OPENER_RETURNED_D, self.getFD());
+ throw raiseNode.raise(inliningTarget, ValueError, OPENER_RETURNED_D, self.getFD());
}
}
try {
@@ -461,15 +461,15 @@ static void doInit(VirtualFrame frame, Node inliningTarget, PFileIO self, Object
@Specialization(guards = "isInvalidMode(mode)")
static void invalidMode(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") Object nameobj, IONodes.IOMode mode, @SuppressWarnings("unused") boolean closefd,
@SuppressWarnings("unused") Object opener,
- @Shared @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, INVALID_MODE_S, mode.mode);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INVALID_MODE_S, mode.mode);
}
@SuppressWarnings("unused")
@Specialization(guards = "isBadMode(mode)")
static void badMode(PFileIO self, Object nameobj, IONodes.IOMode mode, boolean closefd, Object opener,
- @Shared @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, BAD_MODE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, BAD_MODE);
}
}
@@ -540,14 +540,14 @@ static Object read(VirtualFrame frame, PFileIO self, int size,
@Specialization(guards = {"!self.isClosed()", "!self.isReadable()"})
static Object notReadable(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") int size,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "reading");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "reading");
}
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") int size,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -565,7 +565,7 @@ static Object readall(VirtualFrame frame, PFileIO self,
@Cached InlinedBranchProfile multipleReadsProfile,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int bufsize = SMALLCHUNK;
boolean mayBeQuick = false;
try {
@@ -612,7 +612,7 @@ static Object readall(VirtualFrame frame, PFileIO self,
// see CPython's function 'fileio.c: new_buffersize'
bufsize = bytesRead + Math.max(SMALLCHUNK, bytesRead + 256);
if (bufsize <= 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, UNBOUNDED_READ_RETURNED_MORE_BYTES);
+ throw raiseNode.raise(inliningTarget, OverflowError, UNBOUNDED_READ_RETURNED_MORE_BYTES);
}
}
@@ -646,8 +646,8 @@ static Object readall(VirtualFrame frame, PFileIO self,
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -690,15 +690,15 @@ static Object readinto(VirtualFrame frame, PFileIO self, Object buffer,
@SuppressWarnings("unused")
@Specialization(guards = {"!self.isClosed()", "!self.isReadable()"})
static Object notReadable(PFileIO self, Object buffer,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "reading");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "reading");
}
@SuppressWarnings("unused")
@Specialization(guards = "self.isClosed()")
static Object closedError(PFileIO self, Object buffer,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
@Override
@@ -721,13 +721,13 @@ static Object write(VirtualFrame frame, PFileIO self, Object buffer,
@Cached InlinedBranchProfile errorProfile,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (self.isClosed()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, IO_CLOSED);
+ throw raiseNode.raise(inliningTarget, ValueError, IO_CLOSED);
}
if (!self.isWritable()) {
- throw raiseNode.get(inliningTarget).raise(IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "writing");
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "writing");
}
try {
return PosixModuleBuiltins.WriteNode.write(self.getFD(), bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer),
@@ -779,8 +779,8 @@ Object seek(VirtualFrame frame, PFileIO self, long pos, int whence,
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") Object pos, @SuppressWarnings("unused") int whence,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
protected static long internalSeek(PFileIO self, long pos, int whence,
@@ -851,15 +851,15 @@ static Object none(VirtualFrame frame, PFileIO self, @SuppressWarnings("unused")
@SuppressWarnings("unused")
@Specialization(guards = {"!self.isClosed()", "!self.isWritable()"})
static Object notWritable(PFileIO self, Object posobj,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "writing");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, FILE_NOT_OPEN_FOR_S, "writing");
}
@SuppressWarnings("unused")
@Specialization(guards = "self.isClosed()")
static Object closedError(PFileIO self, Object posobj,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -959,8 +959,8 @@ static Object known(PFileIO self) {
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -974,8 +974,8 @@ static Object readable(PFileIO self) {
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -989,8 +989,8 @@ static Object writable(PFileIO self) {
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -1004,8 +1004,8 @@ static Object fileno(PFileIO self) {
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -1026,8 +1026,8 @@ boolean isatty(@SuppressWarnings("unused") PFileIO self,
@Specialization(guards = "self.isClosed()")
static boolean closedError(@SuppressWarnings("unused") PFileIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -1141,7 +1141,7 @@ static TruffleString doit(VirtualFrame frame, PFileIO self,
@Cached("create(Repr)") LookupAndCallUnaryNode repr,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString mode = ModeNode.modeString(self);
TruffleString closefd = self.isCloseFD() ? T_TRUE : T_FALSE;
Object nameobj = lookupName.execute(frame, inliningTarget, self, T_NAME);
@@ -1149,7 +1149,7 @@ static TruffleString doit(VirtualFrame frame, PFileIO self,
return simpleTruffleStringFormatNode.format("<_io.FileIO fd=%d mode='%s' closefd=%s>", self.getFD(), mode, closefd);
}
if (!PythonContext.get(inliningTarget).reprEnter(self)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, REENTRANT_CALL_INSIDE_P_REPR, self);
+ throw raiseNode.raise(inliningTarget, RuntimeError, REENTRANT_CALL_INSIDE_P_REPR, self);
}
try {
TruffleString name = castToTruffleStringNode.execute(inliningTarget, repr.executeObject(frame, nameobj));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
index 6535c80d7d..c9059dccef 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java
@@ -201,9 +201,9 @@ abstract static class CheckClosedHelperNode extends Node {
static PNone doIt(VirtualFrame frame, Node inliningTarget, PythonObject self,
@Cached PyObjectGetAttr getAttr,
@Cached PyObjectIsTrueNode isTrueNode,
- @Cached PRaiseNode.Lazy lazyRaiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isTrueNode.execute(frame, getAttr.execute(frame, inliningTarget, self, T_CLOSED))) {
- throw lazyRaiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IO_CLOSED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IO_CLOSED);
}
return PNone.NONE;
}
@@ -242,14 +242,14 @@ final boolean checkReadable(VirtualFrame frame, Node inliningTarget, Object self
static boolean doIt(VirtualFrame frame, Node inliningTarget, Object self, TruffleString method, TruffleString errorMessage,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached(inline = false) IsNode isNode,
- @Cached PRaiseNode.Lazy lazyRaiseNode) {
+ @Cached PRaiseNode raiseNode) {
CompilerAsserts.partialEvaluationConstant(method);
CompilerAsserts.partialEvaluationConstant(errorMessage);
Object v = callMethod.execute(frame, inliningTarget, self, method);
if (isNode.isTrue(v)) {
return true;
}
- throw unsupported(lazyRaiseNode.get(inliningTarget), errorMessage);
+ throw unsupported(inliningTarget, raiseNode, errorMessage);
}
}
@@ -324,9 +324,9 @@ abstract static class FlushNode extends PythonUnaryBuiltinNode {
static PNone flush(VirtualFrame frame, PythonObject self,
@Bind("this") Node inliningTarget,
@Cached PyObjectLookupAttr lookup,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isClosed(inliningTarget, self, frame, lookup)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IO_CLOSED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IO_CLOSED);
}
return PNone.NONE;
}
@@ -337,8 +337,9 @@ static PNone flush(VirtualFrame frame, PythonObject self,
abstract static class SeekNode extends PythonBuiltinNode {
@Specialization
static Object seek(@SuppressWarnings("unused") PythonObject self, @SuppressWarnings("unused") Object args,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
- throw unsupported(raiseNode, T_SEEK);
+ throw unsupported(inliningTarget, raiseNode, T_SEEK);
}
}
@@ -347,8 +348,9 @@ static Object seek(@SuppressWarnings("unused") PythonObject self, @SuppressWarni
abstract static class TruncateNode extends PythonBuiltinNode {
@Specialization
static Object truncate(@SuppressWarnings("unused") PythonObject self,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
- throw unsupported(raiseNode, T_TRUNCATE);
+ throw unsupported(inliningTarget, raiseNode, T_TRUNCATE);
}
}
@@ -391,8 +393,9 @@ static Object exit(VirtualFrame frame, PythonObject self,
abstract static class FilenoNode extends PythonUnaryBuiltinNode {
@Specialization
static Object fileno(@SuppressWarnings("unused") PythonObject self,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
- throw unsupported(raiseNode, T_FILENO);
+ throw unsupported(inliningTarget, raiseNode, T_FILENO);
}
}
@@ -428,10 +431,10 @@ static Object next(VirtualFrame frame, PythonObject self,
@Bind("this") Node inliningTarget,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectSizeNode sizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object line = callMethod.execute(frame, inliningTarget, self, T_READLINE);
if (sizeNode.execute(frame, inliningTarget, line) <= 0) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return line;
}
@@ -488,7 +491,7 @@ static PBytes readline(VirtualFrame frame, Object self, int limit,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached InlinedConditionProfile hasPeek,
@Cached InlinedConditionProfile isBytes,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/* For backwards compatibility, a (slowish) readline(). */
Object peek = lookupPeek.execute(frame, inliningTarget, self, T_PEEK);
ByteArrayOutputStream buffer = createOutputStream();
@@ -498,7 +501,7 @@ static PBytes readline(VirtualFrame frame, Object self, int limit,
Object readahead = callPeek.execute(frame, peek, 1);
// TODO _PyIO_trap_eintr [GR-23297]
if (isBytes.profile(inliningTarget, !(readahead instanceof PBytes))) {
- throw raiseNode.get(inliningTarget).raise(OSError, S_SHOULD_RETURN_BYTES_NOT_P, "peek()", readahead);
+ throw raiseNode.raise(inliningTarget, OSError, S_SHOULD_RETURN_BYTES_NOT_P, "peek()", readahead);
}
byte[] buf = bufferLib.getInternalOrCopiedByteArray(readahead);
int bufLen = bufferLib.getBufferLength(readahead);
@@ -515,7 +518,7 @@ static PBytes readline(VirtualFrame frame, Object self, int limit,
Object b = callRead.execute(frame, inliningTarget, self, T_READ, nreadahead);
if (isBytes.profile(inliningTarget, !(b instanceof PBytes))) {
- throw raiseNode.get(inliningTarget).raise(OSError, S_SHOULD_RETURN_BYTES_NOT_P, "read()", b);
+ throw raiseNode.raise(inliningTarget, OSError, S_SHOULD_RETURN_BYTES_NOT_P, "read()", b);
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(b);
int bytesLen = bufferLib.getBufferLength(b);
@@ -586,7 +589,7 @@ private static boolean isClosed(Node inliningTarget, PythonObject self, VirtualF
/**
* Equivalent of {@code iobase_unsupported}.
*/
- private static PException unsupported(PRaiseNode raiseNode, TruffleString message) {
- throw raiseNode.raise(IOUnsupportedOperation, message);
+ private static PException unsupported(Node inliningTarget, PRaiseNode raiseNode, TruffleString message) {
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, message);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseDictBuiltins.java
index c219e42c9c..e4d5253fec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseDictBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -94,8 +94,8 @@ static Object doit(PythonObject self, @SuppressWarnings("unused") PNone none,
@Specialization
static Object setDict(PythonObject self, @SuppressWarnings("unused") Object d,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.AssertionError, ErrorMessages.ATTR_DICT_IS_NOT_WRITABLE, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AssertionError, ErrorMessages.ATTR_DICT_IS_NOT_WRITABLE, self);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
index 9a7709f4fd..b8fc0ecf8e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOModuleBuiltins.java
@@ -110,7 +110,6 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -139,7 +138,7 @@ public void initialize(Python3Core core) {
addBuiltinConstant("DEFAULT_BUFFER_SIZE", DEFAULT_BUFFER_SIZE);
PythonBuiltinClass unsupportedOpExcType = core.lookupType(IOUnsupportedOperation);
PythonBuiltinClass osError = core.lookupType(OSError);
- unsupportedOpExcType.setBases(osError, new PythonAbstractClass[]{osError, core.lookupType(ValueError)});
+ unsupportedOpExcType.setBases(null, osError, new PythonAbstractClass[]{osError, core.lookupType(ValueError)});
addBuiltinConstant(IOUnsupportedOperation.getName(), unsupportedOpExcType);
addBuiltinConstant(BlockingIOError.getName(), core.lookupType(BlockingIOError));
@@ -330,7 +329,7 @@ protected static Object openText(VirtualFrame frame, Object file, IONodes.IOMode
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, initFileIO);
Object result = fileIO;
try {
@@ -359,12 +358,12 @@ protected static Object openText(VirtualFrame frame, Object file, IONodes.IOMode
buffering = fileIO.getBlksize();
}
if (buffering < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_BUFFERING_SIZE);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_BUFFERING_SIZE);
}
/* if not buffering, returns the raw file object */
if (buffering == 0) {
- invalidunbuf(file, mode, bufferingValue, encoding, errors, newline, closefd, opener, raiseNode.get(inliningTarget));
+ invalidunbuf(file, mode, bufferingValue, encoding, errors, newline, closefd, opener, raiseNode);
}
/* wraps into a buffered file */
@@ -411,7 +410,7 @@ protected static Object openBinaryB1(VirtualFrame frame, Object file, IONodes.IO
@Exclusive @Cached IONodes.CreateBufferedIONode createBufferedIO,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
warnNode.warnEx(frame, RuntimeWarning, LINE_BUFFERING_ISNT_SUPPORTED, 1);
return openBinary(frame, file, mode, bufferingValue, encoding, errors, newline, closefd, opener, inliningTarget, initFileIO, createBufferedIO, posixLib, callClose, raiseNode);
}
@@ -427,7 +426,7 @@ protected static Object openBinary(VirtualFrame frame, Object file, IONodes.IOMo
@Exclusive @Cached IONodes.CreateBufferedIONode createBufferedIO,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Exclusive @Cached PyObjectCallMethodObjArgs callClose,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PFileIO fileIO = createFileIO(frame, inliningTarget, file, mode, closefd, opener, initFileIO);
try {
/* buffering */
@@ -451,7 +450,7 @@ protected static Object openBinary(VirtualFrame frame, Object file, IONodes.IOMo
buffering = fileIO.getBlksize();
}
if (buffering < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_BUFFERING_SIZE);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_BUFFERING_SIZE);
}
/* if not buffering, returns the raw file object */
@@ -472,35 +471,35 @@ protected static Object openBinary(VirtualFrame frame, Object file, IONodes.IOMo
@SuppressWarnings("unused")
@Specialization(guards = "isUnknown(mode)")
protected static Object unknownMode(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, UNKNOWN_MODE_S, mode.mode);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, UNKNOWN_MODE_S, mode.mode);
}
@SuppressWarnings("unused")
@Specialization(guards = "isTB(mode)")
protected static Object invalidTB(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CAN_T_HAVE_TEXT_AND_BINARY_MODE_AT_ONCE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CAN_T_HAVE_TEXT_AND_BINARY_MODE_AT_ONCE);
}
@SuppressWarnings("unused")
@Specialization(guards = "!isValidUniveral(mode)")
protected static Object invalidUniversal(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MODE_U_CANNOT_BE_COMBINED_WITH_X_W_A_OR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MODE_U_CANNOT_BE_COMBINED_WITH_X_W_A_OR);
}
@SuppressWarnings("unused")
@Specialization(guards = "isXRWA(mode)")
protected static Object invalidxrwa(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MUST_HAVE_EXACTLY_ONE_OF_CREATE_READ_WRITE_APPEND_MODE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_HAVE_EXACTLY_ONE_OF_CREATE_READ_WRITE_APPEND_MODE);
}
@SuppressWarnings("unused")
@Specialization(guards = {"isBinary(mode)", "isAnyNotNone(encoding, errors, newline)"})
protected static Object invalidBinary(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
String s;
if (encoding != PNone.NONE) {
s = "encoding";
@@ -509,14 +508,14 @@ protected static Object invalidBinary(Object file, IONodes.IOMode mode, int buff
} else {
s = "newline";
}
- throw raiseNode.raise(ValueError, BINARY_MODE_DOESN_T_TAKE_AN_S_ARGUMENT, s);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, BINARY_MODE_DOESN_T_TAKE_AN_S_ARGUMENT, s);
}
@SuppressWarnings("unused")
@Specialization(guards = {"!isBinary(mode)", "bufferingValue == 0"})
protected static Object invalidunbuf(Object file, IONodes.IOMode mode, int bufferingValue, Object encoding, Object errors, Object newline, boolean closefd, Object opener,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CAN_T_HAVE_UNBUFFERED_TEXT_IO);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CAN_T_HAVE_UNBUFFERED_TEXT_IO);
}
public static boolean isAnyNotNone(Object encoding, Object errors, Object newline) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
index 57b90112fd..792011dc9c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java
@@ -69,7 +69,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -377,21 +376,21 @@ IOMode generic(VirtualFrame frame, Object modeObj,
@Cached InlinedBranchProfile errProfile2,
@Cached InlinedBranchProfile errProfile3,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString mode;
try {
mode = toString.execute(inliningTarget, modeObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
IOMode m = new IOMode(mode, createCodePointIteratorNode, nextNode);
if (m.hasNil) {
errProfile1.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, EMBEDDED_NULL_CHARACTER);
+ throw raiseNode.raise(inliningTarget, ValueError, EMBEDDED_NULL_CHARACTER);
}
if (m.isInvalid) {
errProfile2.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_MODE_S, mode);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_MODE_S, mode);
}
if (warnUniversal && m.universal) {
errProfile3.enter(inliningTarget);
@@ -431,11 +430,11 @@ static Object generic(VirtualFrame frame, Object nameobj,
@Cached BytesNodes.DecodeUTF8FSPathNode fspath,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, nameobj)) {
int fd = asSizeNode.executeExact(frame, inliningTarget, nameobj);
if (fd < 0) {
- err(fd, raiseNode.get(inliningTarget));
+ err(fd, raiseNode);
}
return fd;
} else {
@@ -445,14 +444,14 @@ static Object generic(VirtualFrame frame, Object nameobj,
@Specialization(guards = "fd < 0")
static int err(int fd,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, OPENER_RETURNED_D, fd);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, OPENER_RETURNED_D, fd);
}
@Specialization(guards = "fd < 0")
static int err(long fd,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, OPENER_RETURNED_D, fd);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, OPENER_RETURNED_D, fd);
}
@ClinicConverterFactory
@@ -524,11 +523,11 @@ static TruffleString string(TruffleString s) {
@Specialization(guards = "!isString(s)")
static TruffleString str(Node inliningTarget, Object s,
@Cached CastToTruffleStringNode str,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return str.execute(inliningTarget, s);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_OBJ_TYPE_S_GOT_P, "str", s);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_OBJ_TYPE_S_GOT_P, "str", s);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
index 0010e47da7..72cc54ac5d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java
@@ -298,14 +298,14 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object state = callMethod.execute(frame, inliningTarget, self.getDecoder(), T_GETSTATE);
if (!(state instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_STATE_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_STATE_ARGUMENT);
}
Object[] objects = getObjectArrayNode.execute(inliningTarget, state);
if (objects.length != 2 || !indexCheckNode.execute(inliningTarget, objects[1])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_STATE_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_STATE_ARGUMENT);
}
int flag = asSizeNode.executeExact(frame, inliningTarget, objects[1]);
flag <<= 1;
@@ -326,10 +326,10 @@ static Object noDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
@Exclusive @Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
@Exclusive @Cached PyIndexCheckNode indexCheckNode,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object[] objects = getObjectArrayNode.execute(inliningTarget, state);
if (objects.length != 2 || !indexCheckNode.execute(inliningTarget, objects[1])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_STATE_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_STATE_ARGUMENT);
}
int flag = asSizeNode.executeExact(frame, inliningTarget, objects[1]);
self.setPendingCR((flag & 1) != 0);
@@ -344,10 +344,10 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
@Exclusive @Cached PyIndexCheckNode indexCheckNode,
@Exclusive @Cached PyNumberAsSizeNode asSizeNode,
@Cached PyObjectCallMethodObjArgs callMethod,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object[] objects = getObjectArrayNode.execute(inliningTarget, state);
if (objects.length != 2 || !indexCheckNode.execute(inliningTarget, objects[1])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_STATE_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_STATE_ARGUMENT);
}
int flag = asSizeNode.executeExact(frame, inliningTarget, objects[1]);
self.setPendingCR((flag & 1) != 0);
@@ -358,8 +358,8 @@ static Object withDecoder(VirtualFrame frame, PNLDecoder self, PTuple state,
@Fallback
static Object err(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object state,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, STATE_ARGUMENT_MUST_BE_A_TUPLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, STATE_ARGUMENT_MUST_BE_A_TUPLE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
index 9b5a9a650f..225f228bdc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PBytesIO.java
@@ -101,9 +101,9 @@ public int getExports() {
return exports.getExports().get();
}
- public void checkExports(Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ public void checkExports(Node inliningTarget, PRaiseNode raiseNode) {
if (getExports() != 0) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.EXISTING_EXPORTS_OF_DATA_OBJECT_CANNOT_BE_RE_SIZED);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.EXISTING_EXPORTS_OF_DATA_OBJECT_CANNOT_BE_RE_SIZED);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PTextIO.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PTextIO.java
index e0bda2dbdc..200ff15b56 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PTextIO.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PTextIO.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -424,12 +424,12 @@ public static Object build(CookieType cookie) {
return IntNodes.PyLongFromByteArray.executeUncached(buffer, true, false);
}
- public static CookieType parse(long v, Node inliningTarget, InlinedConditionProfile overflow, PRaiseNode.Lazy raise) {
+ public static CookieType parse(long v, Node inliningTarget, InlinedConditionProfile overflow, PRaiseNode raise) {
byte[] buffer = IntBuiltins.ToBytesNode.fromLong(v, COOKIE_BUF_LEN, false, false, inliningTarget, overflow, raise);
return parse(buffer);
}
- public static CookieType parse(PInt v, Node inliningTarget, InlinedConditionProfile overflow, PRaiseNode.Lazy raise) {
+ public static CookieType parse(PInt v, Node inliningTarget, InlinedConditionProfile overflow, PRaiseNode raise) {
byte[] buffer = IntBuiltins.ToBytesNode.fromBigInteger(v, COOKIE_BUF_LEN, false, false, inliningTarget, overflow, raise);
return parse(buffer);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
index ee5e07aa9f..36b8db7086 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java
@@ -158,7 +158,7 @@ static Object readall(VirtualFrame frame, Object self,
@Cached InlinedConditionProfile chunksSize0Profile,
@Cached InlinedCountingConditionProfile bytesLen0Profile,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ByteArrayOutputStream chunks = createOutputStream();
while (true) {
Object data = callMethodRead.execute(frame, inliningTarget, self, T_READ, DEFAULT_BUFFER_SIZE);
@@ -170,7 +170,7 @@ static Object readall(VirtualFrame frame, Object self,
break;
}
if (!(data instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_SHOULD_RETURN_BYTES, "read()");
+ throw raiseNode.raise(inliningTarget, TypeError, S_SHOULD_RETURN_BYTES, "read()");
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(data);
int bytesLen = bufferLib.getBufferLength(data);
@@ -193,8 +193,8 @@ abstract static class ReadIntoNode extends PythonBuiltinNode {
*/
@Specialization
static Object readinto(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -207,8 +207,8 @@ abstract static class WriteNode extends PythonBuiltinNode {
*/
@Specialization
static Object write(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
index 1f0ef51ac2..5cefff275f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
@@ -146,14 +146,14 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class ClosedCheckPythonUnaryBuiltinNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PStringIO self,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PStringIO self,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -166,19 +166,19 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") Object arg,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") Object arg,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
static void writeString(VirtualFrame frame, Node inliningTarget, PStringIO self, TruffleString obj,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
IncrementalNewlineDecoderBuiltins.DecodeNode decodeNode,
StringReplaceNode replaceNode,
TruffleString.CodePointLengthNode codePointLengthNode,
@@ -205,7 +205,7 @@ static void writeString(VirtualFrame frame, Node inliningTarget, PStringIO self,
* things like comparing an unsigned and a signed integer.
*/
if (self.getPos() > Integer.MAX_VALUE - decodedLen) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, NEW_POSITION_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, NEW_POSITION_TOO_LARGE);
}
if (self.isAccumulating()) {
@@ -272,7 +272,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization
static PNone init(VirtualFrame frame, PStringIO self, TruffleString initialValue, Object newlineArg,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy lazyRaiseNode,
+ @Cached PRaiseNode lazyRaiseNode,
@Cached IncrementalNewlineDecoderBuiltins.DecodeNode decodeNode,
@Cached IncrementalNewlineDecoderBuiltins.InitNode initNode,
@Cached StringReplaceNode replaceNode,
@@ -284,7 +284,7 @@ static PNone init(VirtualFrame frame, PStringIO self, TruffleString initialValue
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached IONodes.ToTruffleStringNode toTruffleStringNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString newline;
if (newlineArg == PNone.NO_VALUE) {
@@ -479,7 +479,7 @@ static Object obj(VirtualFrame frame, PStringIO self, Object arg,
@Shared @Cached TruffleString.SubstringNode substringNode,
@Shared @Cached TruffleStringBuilder.ToStringNode toStringNode,
@Shared @Cached TruffleStringBuilder.AppendStringNode appendStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int size = asSizeNode.executeExact(frame, inliningTarget, indexNode.execute(frame, inliningTarget, arg), OverflowError);
if (size >= 0) {
if (size < self.getStringSize()) {
@@ -487,13 +487,13 @@ static Object obj(VirtualFrame frame, PStringIO self, Object arg,
}
return size;
}
- return negSize(self, size, raiseNode.get(inliningTarget));
+ return negSize(self, size, raiseNode);
}
@Specialization(guards = {"self.isOK()", "!self.isClosed()", "size < 0"})
static Object negSize(@SuppressWarnings("unused") PStringIO self, int size,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, NEGATIVE_SIZE_VALUE_D, size);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, NEGATIVE_SIZE_VALUE_D, size);
}
}
@@ -517,7 +517,7 @@ static Object doWrite(VirtualFrame frame, PStringIO self, TruffleString s,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int size = codePointLengthNode.execute(s, TS_ENCODING);
if (size > 0) {
writeString(frame, inliningTarget, self, s, raiseNode, decodeNode, replaceNode, codePointLengthNode,
@@ -576,32 +576,32 @@ static Object seek(PStringIO self, int pos, int whence) {
@SuppressWarnings("unused")
@Specialization(guards = {"self.isOK()", "!self.isClosed()", "!isSupportedWhence(whence)"})
static Object whenceError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") int pos, int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, INVALID_WHENCE_D_SHOULD_BE_0_1_OR_2, whence);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INVALID_WHENCE_D_SHOULD_BE_0_1_OR_2, whence);
}
@Specialization(guards = {"self.isOK()", "!self.isClosed()", "isSupportedWhence(whence)", "pos != 0", "whence != 0"})
static Object largePos1(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") int pos, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(OSError, CAN_T_DO_NONZERO_CUR_RELATIVE_SEEKS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, OSError, CAN_T_DO_NONZERO_CUR_RELATIVE_SEEKS);
}
@Specialization(guards = {"self.isOK()", "!self.isClosed()", "pos < 0", "whence == 0"})
static Object negPos(@SuppressWarnings("unused") PStringIO self, int pos, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, NEGATIVE_SEEK_VALUE_D, pos);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, NEGATIVE_SEEK_VALUE_D, pos);
}
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") int pos, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") int pos, @SuppressWarnings("unused") int whence,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -656,11 +656,11 @@ static Object doit(VirtualFrame frame, PStringIO self, PTuple state,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached HashingStorageAddAllToOther addAllToOtherNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = state.getSequenceStorage();
Object[] array = getArray.execute(inliningTarget, storage);
if (storage.length() < 4) {
- return notTuple(self, state, raiseNode.get(inliningTarget));
+ return notTuple(self, state, raiseNode);
}
initNode.execute(frame, self, array[0], array[1]);
/*
@@ -685,18 +685,18 @@ static Object doit(VirtualFrame frame, PStringIO self, PTuple state,
* erroneous (or malicious) inputs.
*/
if (!indexCheckNode.execute(inliningTarget, array[2])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THIRD_ITEM_OF_STATE_MUST_BE_AN_INTEGER_GOT_P, array[2]);
+ throw raiseNode.raise(inliningTarget, TypeError, THIRD_ITEM_OF_STATE_MUST_BE_AN_INTEGER_GOT_P, array[2]);
}
int pos = asSizeNode.executeExact(frame, inliningTarget, array[2]);
if (pos < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, POSITION_VALUE_CANNOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, POSITION_VALUE_CANNOT_BE_NEGATIVE);
}
self.setPos(pos);
/* Set the dictionary of the instance variables. */
if (!PGuards.isNone(array[3])) {
if (!PGuards.isDict(array[3])) {
- throw raiseNode.get(inliningTarget).raise(TypeError, THIRD_ITEM_OF_STATE_SHOULD_BE_A_DICT_GOT_A_P, array[3]);
+ throw raiseNode.raise(inliningTarget, TypeError, THIRD_ITEM_OF_STATE_SHOULD_BE_A_DICT_GOT_A_P, array[3]);
}
/*
* Alternatively, we could replace the internal dictionary completely. However, it
@@ -711,14 +711,14 @@ static Object doit(VirtualFrame frame, PStringIO self, PTuple state,
@Specialization(guards = {"!self.isClosed()", "!isPTuple(state)"})
static Object notTuple(PStringIO self, Object state,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, P_SETSTATE_ARGUMENT_SHOULD_BE_D_TUPLE_GOT_P, self, 4, state);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, P_SETSTATE_ARGUMENT_SHOULD_BE_D_TUPLE_GOT_P, self, 4, state);
}
@Specialization(guards = "self.isClosed()")
static Object closedError(@SuppressWarnings("unused") PStringIO self, @SuppressWarnings("unused") Object arg,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_CLOSED);
}
}
@@ -788,8 +788,8 @@ static boolean closed(PStringIO self) {
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PStringIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -820,11 +820,11 @@ static Object builtin(PStringIO self,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
@Cached FindLineEndingNode findLineEndingNode,
@Cached TruffleString.SubstringNode substringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.realize();
TruffleString line = stringioReadline(inliningTarget, self, -1, findLineEndingNode, substringNode, toStringNode);
if (line.isEmpty()) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return line;
}
@@ -838,15 +838,15 @@ static Object slowpath(VirtualFrame frame, PStringIO self,
@SuppressWarnings("unused") @Exclusive @Cached IsBuiltinObjectExactProfile profile,
@Cached PyObjectCallMethodObjArgs callMethodReadline,
@Cached CastToTruffleStringNode toString,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.realize();
Object res = callMethodReadline.execute(frame, inliningTarget, self, T_READLINE);
if (!PGuards.isString(res)) {
- throw raiseNode.get(inliningTarget).raise(OSError, S_SHOULD_HAVE_RETURNED_A_STR_OBJECT_NOT_P, T_READLINE, res);
+ throw raiseNode.raise(inliningTarget, OSError, S_SHOULD_HAVE_RETURNED_A_STR_OBJECT_NOT_P, T_READLINE, res);
}
TruffleString line = toString.execute(inliningTarget, res);
if (line.isEmpty()) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return line;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOBaseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOBaseBuiltins.java
index 8636fbeb8d..0c2e88189a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOBaseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOBaseBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -64,10 +64,11 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.nodes.Node;
@CoreFunctions(extendClasses = PythonBuiltinClassType.PTextIOBase)
public final class TextIOBaseBuiltins extends PythonBuiltins {
@@ -82,8 +83,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class DetachNode extends PythonBuiltinNode {
@Specialization
static Object detach(@SuppressWarnings("unused") Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_DETACH);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_DETACH);
}
}
@@ -92,8 +93,8 @@ static Object detach(@SuppressWarnings("unused") Object self,
abstract static class ReadNode extends PythonBuiltinNode {
@Specialization
static Object read(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_READ);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_READ);
}
}
@@ -102,8 +103,8 @@ static Object read(@SuppressWarnings("unused") Object self, @SuppressWarnings("u
abstract static class ReadlineNode extends PythonBuiltinNode {
@Specialization
static Object read(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_READLINE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_READLINE);
}
}
@@ -112,8 +113,8 @@ static Object read(@SuppressWarnings("unused") Object self, @SuppressWarnings("u
abstract static class WriteNode extends PythonBuiltinNode {
@Specialization
static Object write(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object args,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, T_WRITE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, T_WRITE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
index 2374247068..a8606b2935 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java
@@ -133,6 +133,7 @@
import com.oracle.graal.python.annotations.ArgumentClinic;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.modules.io.TextIOWrapperNodes.WriteFlushNode;
import com.oracle.graal.python.builtins.objects.PNone;
@@ -197,8 +198,8 @@ abstract static class InitCheckPythonUnaryBuiltinNode extends PythonUnaryBuiltin
@Specialization(guards = "!self.isOK()")
@SuppressWarnings("unused")
static Object initError(PTextIO self,
- @Exclusive @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Exclusive @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -210,8 +211,8 @@ protected static boolean checkAttached(PTextIO self) {
@Specialization(guards = {"self.isOK()", "self.isDetached()"})
@SuppressWarnings("unused")
static Object attachError(PTextIO self,
- @Exclusive @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, DETACHED_BUFFER);
+ @Exclusive @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, DETACHED_BUFFER);
}
}
@@ -234,8 +235,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "!self.isOK()")
@SuppressWarnings("unused")
static Object initError(PTextIO self, Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
}
@@ -247,8 +248,8 @@ protected static boolean checkAttached(PTextIO self) {
@Specialization(guards = {"self.isOK()", "self.isDetached()"})
@SuppressWarnings("unused")
static Object attachError(PTextIO self, Object o,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, DETACHED_BUFFER);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, DETACHED_BUFFER);
}
}
@@ -315,7 +316,7 @@ static Object reconfigure(VirtualFrame frame, PTextIO self, Object encodingObj,
Object errorsObj, Object newlineObj,
Object lineBufferingObj, Object writeThroughObj,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy lazyRaiseNode,
+ @Cached PRaiseNode lazyRaiseNode,
@Cached IONodes.ToTruffleStringNode toStringNode,
@Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectIsTrueNode isTrueNode,
@@ -355,8 +356,8 @@ static Object reconfigure(VirtualFrame frame, PTextIO self, Object encodingObj,
@SuppressWarnings("unused")
@Specialization(guards = "!isValid(self, encodingObj, errorsObj, newlineObj)")
static Object error(VirtualFrame frame, PTextIO self, Object encodingObj, Object errorsObj, Object newlineObj, Object lineBufferingObj, Object writeThroughObj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, NOT_POSSIBLE_TO_SET_THE_ENCODING_OR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, NOT_POSSIBLE_TO_SET_THE_ENCODING_OR);
}
}
@@ -372,8 +373,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = {"checkAttached(self)", "isOpen(frame, self)", "!self.hasEncoder()"})
static Object write(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") TruffleString data,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, NOT_WRITABLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, NOT_WRITABLE);
}
@Specialization(guards = {"checkAttached(self)", "isOpen(frame, self)", "self.hasEncoder()"})
@@ -387,7 +388,7 @@ static Object write(VirtualFrame frame, PTextIO self, TruffleString data,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfCodePointNode indexOfCodePointNode,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean haslf = false;
boolean needflush = false;
TruffleString text = data;
@@ -421,7 +422,7 @@ static Object write(VirtualFrame frame, PTextIO self, TruffleString data,
Object b = callMethodEncode.execute(frame, inliningTarget, self.getEncoder(), T_ENCODE, text);
if (b != text && !(b instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ENCODER_SHOULD_RETURN_A_BYTES_OBJECT_NOT_P, b);
+ throw raiseNode.raise(inliningTarget, TypeError, ENCODER_SHOULD_RETURN_A_BYTES_OBJECT_NOT_P, b);
}
byte[] encodedText = bufferLib.getInternalOrCopiedByteArray(b);
@@ -520,8 +521,8 @@ static TruffleString read(VirtualFrame frame, PTextIO self, int n,
@Specialization(guards = {"checkAttached(self)", "isOpen(frame, self)", "!self.hasDecoder()"})
static Object noDecoder(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") int n,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, NOT_READABLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, NOT_READABLE);
}
}
@@ -679,10 +680,10 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkClosedNode.execute(frame, self);
if (!self.isSeekable()) {
- throw raiseNode.get(inliningTarget).raise(IOUnsupportedOperation, UNDERLYING_STREAM_IS_NOT_SEEKABLE);
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, UNDERLYING_STREAM_IS_NOT_SEEKABLE);
}
Object cookieObj = c;
@@ -691,7 +692,7 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
case SEEK_CUR:
/* seek relative to current position */
if (!eqNode.compare(frame, inliningTarget, cookieObj, 0)) {
- throw raiseNode.get(inliningTarget).raise(IOUnsupportedOperation, CAN_T_DO_NONZERO_CUR_RELATIVE_SEEKS);
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, CAN_T_DO_NONZERO_CUR_RELATIVE_SEEKS);
}
/*
@@ -704,7 +705,7 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
case SEEK_END:
/* seek relative to end of file */
if (!eqNode.compare(frame, inliningTarget, cookieObj, 0)) {
- throw raiseNode.get(inliningTarget).raise(IOUnsupportedOperation, CAN_T_DO_NONZERO_END_RELATIVE_SEEKS);
+ throw raiseNode.raise(inliningTarget, IOUnsupportedOperation, CAN_T_DO_NONZERO_END_RELATIVE_SEEKS);
}
callMethodFlush.execute(frame, inliningTarget, self, T_FLUSH);
@@ -726,20 +727,20 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
break;
default:
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_WHENCE_D_SHOULD_BE_D_D_OR_D, whence, SEEK_SET, SEEK_CUR, SEEK_END);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_WHENCE_D_SHOULD_BE_D_D_OR_D, whence, SEEK_SET, SEEK_CUR, SEEK_END);
}
Object cookieLong = longNode.execute(frame, inliningTarget, cookieObj);
PTextIO.CookieType cookie;
if (cookieLong instanceof PInt) {
if (((PInt) cookieLong).isNegative()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NEGATIVE_SEEK_POSITION_D, cookieLong);
+ throw raiseNode.raise(inliningTarget, ValueError, NEGATIVE_SEEK_POSITION_D, cookieLong);
}
cookie = PTextIO.CookieType.parse((PInt) cookieLong, inliningTarget, overflow, raiseNode);
} else {
long l = toLong.execute(inliningTarget, cookieLong);
if (l < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, NEGATIVE_SEEK_POSITION_D, cookieLong);
+ throw raiseNode.raise(inliningTarget, ValueError, NEGATIVE_SEEK_POSITION_D, cookieLong);
}
cookie = PTextIO.CookieType.parse(l, inliningTarget, overflow, raiseNode);
}
@@ -765,7 +766,7 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
Object inputChunk = callMethodRead.execute(frame, inliningTarget, self.getBuffer(), T_READ, cookie.bytesToFeed);
if (!(inputChunk instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, UNDERLYING_READ_SHOULD_HAVE_RETURNED_A_BYTES_OBJECT_NOT_S, inputChunk);
+ throw raiseNode.raise(inliningTarget, TypeError, UNDERLYING_READ_SHOULD_HAVE_RETURNED_A_BYTES_OBJECT_NOT_S, inputChunk);
}
self.setSnapshotDecFlags(cookie.decFlags);
@@ -777,7 +778,7 @@ static Object seek(VirtualFrame frame, PTextIO self, Object c, int whence,
/* Skip chars_to_skip of the decoded characters. */
if (decodedLen < cookie.charsToSkip) {
- throw raiseNode.get(inliningTarget).raise(OSError, CAN_T_RESTORE_LOGICAL_FILE_POSITION);
+ throw raiseNode.raise(inliningTarget, OSError, CAN_T_RESTORE_LOGICAL_FILE_POSITION);
}
self.incDecodedCharsUsed(cookie.charsToSkip);
} else {
@@ -798,14 +799,14 @@ protected static boolean checkAttached(PTextIO self) {
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") Object o1, @SuppressWarnings("unused") Object o2,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
@Specialization(guards = {"self.isOK()", "self.isDetached()"})
static Object attachError(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") Object o1, @SuppressWarnings("unused") Object o2,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, DETACHED_BUFFER);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, DETACHED_BUFFER);
}
}
@@ -815,11 +816,11 @@ abstract static class TellNode extends ClosedCheckPythonUnaryBuiltinNode {
@Specialization(guards = "!self.isSeekable() || !self.isTelling()")
static Object error(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") PTextIO self,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (!self.isSeekable()) {
- throw raiseNode.raise(IOUnsupportedOperation, UNDERLYING_STREAM_IS_NOT_SEEKABLE);
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, UNDERLYING_STREAM_IS_NOT_SEEKABLE);
} else {
- throw raiseNode.raise(OSError, TELLING_POSITION_DISABLED_BY_NEXT_CALL);
+ throw PRaiseNode.raiseStatic(inliningTarget, OSError, TELLING_POSITION_DISABLED_BY_NEXT_CALL);
}
}
@@ -907,7 +908,7 @@ static Object tell(VirtualFrame frame, PTextIO self,
@Exclusive @Cached PyLongAsLongNode asLongNode,
@Cached PyObjectSizeNode sizeNode,
@CachedLibrary(limit = "2") InteropLibrary isString,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PTextIO.CookieType cookie = getCookie(frame, inliningTarget, self, writeFlushNode, callMethodFlush, callMethodTell, asLongNode);
byte[] snapshotNextInput = self.getSnapshotNextInput();
int nextInputLength = self.getSnapshotNextInput().length;
@@ -991,7 +992,7 @@ static Object tell(VirtualFrame frame, PTextIO self,
if (!isString.isString(decoded)) {
fail(frame, inliningTarget, self, savedState, callMethodSetState);
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODER_SHOULD_RETURN_A_STRING_RESULT_NOT_P, decoded);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODER_SHOULD_RETURN_A_STRING_RESULT_NOT_P, decoded);
}
charsDecoded += sizeNode.execute(frame, inliningTarget, decoded);
@@ -999,7 +1000,7 @@ static Object tell(VirtualFrame frame, PTextIO self,
if (charsDecoded < decodedCharsUsed) {
fail(frame, inliningTarget, self, savedState, callMethodSetState);
- throw raiseNode.get(inliningTarget).raise(OSError, CAN_T_RECONSTRUCT_LOGICAL_FILE_POSITION);
+ throw raiseNode.raise(inliningTarget, OSError, CAN_T_RECONSTRUCT_LOGICAL_FILE_POSITION);
}
}
callMethodSetState.execute(frame, inliningTarget, self.getDecoder(), T_SETSTATE, savedState);
@@ -1018,21 +1019,21 @@ static Object[] decoderGetstate(VirtualFrame frame, Node inliningTarget, PTextIO
SequenceNodes.GetObjectArrayNode getArray,
PyObjectCallMethodObjArgs callMethodGetState,
PyObjectCallMethodObjArgs callMethodSetState,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object state = callMethodGetState.execute(frame, inliningTarget, self.getDecoder(), T_GETSTATE);
if (!(state instanceof PTuple)) {
fail(frame, inliningTarget, self, saved_state, callMethodSetState);
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE);
}
Object[] array = getArray.execute(inliningTarget, state);
if (array.length < 2) {
fail(frame, inliningTarget, self, saved_state, callMethodSetState);
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE);
}
if (!(array[0] instanceof PBytes)) {
fail(frame, inliningTarget, self, saved_state, callMethodSetState);
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE_THE_FIRST, array[0]);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE_THE_FIRST, array[0]);
}
return array;
}
@@ -1172,10 +1173,10 @@ static Object none(PTextIO self, @SuppressWarnings("unused") PNone none) {
static Object chunkSize(VirtualFrame frame, PTextIO self, Object arg,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int size = asSizeNode.executeExact(frame, inliningTarget, arg, ValueError);
if (size <= 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, A_STRICTLY_POSITIVE_INTEGER_IS_REQUIRED);
+ throw raiseNode.raise(inliningTarget, ValueError, A_STRICTLY_POSITIVE_INTEGER_IS_REQUIRED);
}
self.setChunkSize(size);
return 0;
@@ -1183,20 +1184,20 @@ static Object chunkSize(VirtualFrame frame, PTextIO self, Object arg,
@Specialization(guards = {"self.isOK()", "!self.isDetached()"})
static Object noDelete(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") DescriptorDeleteMarker marker,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, CANNOT_DELETE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, CANNOT_DELETE);
}
@Specialization(guards = "!self.isOK()")
static Object initError(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") Object arg,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, IO_UNINIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, IO_UNINIT);
}
@Specialization(guards = {"self.isOK()", "self.isDetached()"})
static Object attachError(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") Object arg,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, DETACHED_BUFFER);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, DETACHED_BUFFER);
}
}
@@ -1207,13 +1208,13 @@ abstract static class IternextNode extends ClosedCheckPythonUnaryBuiltinNode {
static TruffleString doit(VirtualFrame frame, PTextIO self,
@Bind("this") Node inliningTarget,
@Cached TextIOWrapperNodes.ReadlineNode readlineNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.setTelling(false);
TruffleString line = readlineNode.execute(frame, self, -1);
if (line.isEmpty()) {
self.clearSnapshot();
self.setTelling(self.isSeekable());
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return line;
}
@@ -1231,9 +1232,9 @@ static Object doit(VirtualFrame frame, PTextIO self,
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
@Cached IONodes.ToTruffleStringNode toString,
@Cached IsBuiltinObjectProfile isValueError,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!PythonContext.get(inliningTarget).reprEnter(self)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, REENTRANT_CALL_INSIDE_P_REPR, self);
+ throw raiseNode.raise(inliningTarget, RuntimeError, REENTRANT_CALL_INSIDE_P_REPR, self);
}
try {
Object nameobj = PNone.NO_VALUE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
index a614ee75ac..252b9fb6ad 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java
@@ -121,7 +121,7 @@ public abstract class TextIOWrapperNodes {
public static final TruffleString T_CODECS_OPEN = tsLiteral("codecs.open()");
- protected static void validateNewline(TruffleString str, Node inliningTarget, PRaiseNode.Lazy raise, TruffleString.CodePointLengthNode codePointLengthNode,
+ protected static void validateNewline(TruffleString str, Node inliningTarget, PRaiseNode raise, TruffleString.CodePointLengthNode codePointLengthNode,
TruffleString.CodePointAtIndexNode codePointAtIndexNode) {
int len = codePointLengthNode.execute(str, TS_ENCODING);
int c = len == 0 ? '\0' : codePointAtIndexNode.execute(str, 0, TS_ENCODING);
@@ -129,7 +129,7 @@ protected static void validateNewline(TruffleString str, Node inliningTarget, PR
!(c == '\n' && len == 1) &&
!(c == '\r' && len == 1) &&
!(c == '\r' && len == 2 && codePointAtIndexNode.execute(str, 1, TS_ENCODING) == '\n')) {
- throw raise.get(inliningTarget).raise(ValueError, ILLEGAL_NEWLINE_VALUE_S, str);
+ throw raise.raise(inliningTarget, ValueError, ILLEGAL_NEWLINE_VALUE_S, str);
}
}
@@ -169,8 +169,8 @@ static void ideal(@SuppressWarnings("unused") PTextIO self) {
@Specialization(guards = {"self.isFileIO()", "self.getFileIO().isClosed()"})
static void error(@SuppressWarnings("unused") PTextIO self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.IO_CLOSED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.IO_CLOSED);
}
@Specialization(guards = "!self.isFileIO()")
@@ -178,10 +178,10 @@ static void checkGeneric(VirtualFrame frame, PTextIO self,
@Bind("this") Node inliningTarget,
@Cached PyObjectGetAttr getAttr,
@Cached PyObjectIsTrueNode isTrueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object res = getAttr.execute(frame, inliningTarget, self.getBuffer(), T_CLOSED);
if (isTrueNode.execute(frame, res)) {
- error(self, raiseNode.get(inliningTarget));
+ error(self, raiseNode);
}
}
}
@@ -504,7 +504,7 @@ static boolean readChunk(VirtualFrame frame, Node inliningTarget, PTextIO self,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* The return value is True unless EOF was reached. The decoded string is placed in
* self._decoded_chars (replacing its previous value). The entire input chunk is sent to
@@ -524,15 +524,15 @@ static boolean readChunk(VirtualFrame frame, Node inliningTarget, PTextIO self,
* with decoder state (b'', decFlags).
*/
if (!(state instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE);
}
Object[] array = getArray.execute(inliningTarget, state);
if (array.length < 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE);
}
if (!(array[0] instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ILLEGAL_DECODER_STATE_THE_FIRST, array[0]);
+ throw raiseNode.raise(inliningTarget, TypeError, ILLEGAL_DECODER_STATE_THE_FIRST, array[0]);
}
decBuffer = (PBytes) array[0];
@@ -557,7 +557,7 @@ static boolean readChunk(VirtualFrame frame, Node inliningTarget, PTextIO self,
try {
inputChunkBuf = bufferAcquireLib.acquireReadonly(inputChunk, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, S_SHOULD_HAVE_RETURNED_A_BYTES_LIKE_OBJECT_NOT_P, (self.isHasRead1() ? T_READ1 : T_READ), inputChunk);
+ throw raiseNode.raise(inliningTarget, TypeError, S_SHOULD_HAVE_RETURNED_A_BYTES_LIKE_OBJECT_NOT_P, (self.isHasRead1() ? T_READ1 : T_READ), inputChunk);
}
try {
int nbytes = bufferLib.getBufferLength(inputChunkBuf);
@@ -598,8 +598,8 @@ static boolean readChunk(VirtualFrame frame, Node inliningTarget, PTextIO self,
@Specialization(guards = "!self.hasDecoder()")
static boolean error(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") int size_hint,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(IOUnsupportedOperation, NOT_READABLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, IOUnsupportedOperation, NOT_READABLE);
}
}
@@ -816,7 +816,7 @@ static void init(VirtualFrame frame, Node inliningTarget, PTextIO self, Object b
@Cached(inline = false) TruffleString.IndexOfCodePointNode indexOfCodePointNode,
@Cached(inline = false) TruffleString.EqualNode equalNode,
@Cached(inline = false) WarningsModuleBuiltins.WarnNode warnNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.setOK(false);
self.setDetached(false);
// encoding and newline are processed through arguments clinic and safe to cast.
@@ -830,13 +830,13 @@ static void init(VirtualFrame frame, Node inliningTarget, PTextIO self, Object b
encoding = null;
} else {
if (indexOfCodePointNode.execute(encoding, 0, 0, codePointLengthNode.execute(encoding, TS_ENCODING), TS_ENCODING) != -1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, EMBEDDED_NULL_CHARACTER);
+ throw raiseNode.raise(inliningTarget, ValueError, EMBEDDED_NULL_CHARACTER);
}
}
if (newline != null) {
if (indexOfCodePointNode.execute(newline, 0, 0, codePointLengthNode.execute(newline, TS_ENCODING), TS_ENCODING) != -1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, EMBEDDED_NULL_CHARACTER);
+ throw raiseNode.raise(inliningTarget, ValueError, EMBEDDED_NULL_CHARACTER);
}
validateNewline(newline, inliningTarget, raiseNode, codePointLengthNode, codePointAtIndexNode);
}
@@ -856,7 +856,7 @@ static void init(VirtualFrame frame, Node inliningTarget, PTextIO self, Object b
} else if (encoding != null) {
self.setEncoding(encoding);
} else {
- throw raiseNode.get(inliningTarget).raise(OSError, COULD_NOT_DETERMINE_DEFAULT_ENCODING);
+ throw raiseNode.raise(inliningTarget, OSError, COULD_NOT_DETERMINE_DEFAULT_ENCODING);
}
/* Check we have been asked for a real text encoding */
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
index 59cc6e6a1d..333cd0283a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONEncoderBuiltins.java
@@ -134,7 +134,7 @@ private void appendConst(TruffleStringBuilderUTF32 builder, Object obj) {
private void appendFloat(PJSONEncoder encoder, TruffleStringBuilderUTF32 builder, double obj) {
if (!Double.isFinite(obj)) {
if (!encoder.allowNan) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.OUT_OF_RANGE_FLOAT_NOT_JSON_COMPLIANT);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.OUT_OF_RANGE_FLOAT_NOT_JSON_COMPLIANT);
}
if (obj > 0) {
builder.appendStringUncached(T_POSITIVE_INFINITY);
@@ -165,7 +165,7 @@ private void appendString(PJSONEncoder encoder, TruffleStringBuilderUTF32 builde
case None:
Object result = CallUnaryMethodNode.getUncached().executeObject(encoder.encoder, obj);
if (!isString(result)) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.ENCODER_MUST_RETURN_STR, result);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.ENCODER_MUST_RETURN_STR, result);
}
builder.appendStringUncached(CastToTruffleStringNode.executeUncached(result));
break;
@@ -230,7 +230,7 @@ private static void endRecursion(PJSONEncoder encoder, Object obj) {
private void startRecursion(PJSONEncoder encoder, Object obj) {
if (encoder.markers != PNone.NONE) {
if (!encoder.tryAddCircular(obj)) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.CIRCULAR_REFERENCE_DETECTED);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.CIRCULAR_REFERENCE_DETECTED);
}
}
}
@@ -277,7 +277,7 @@ private void appendDictSlowPath(PJSONEncoder encoder, TruffleStringBuilderUTF32
break;
}
if (!(item instanceof PTuple itemTuple) || itemTuple.getSequenceStorage().length() != 2) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.ITEMS_MUST_RETURN_2_TUPLES);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.ITEMS_MUST_RETURN_2_TUPLES);
}
SequenceStorage sequenceStorage = itemTuple.getSequenceStorage();
Object key = SequenceStorageNodes.GetItemScalarNode.executeUncached(sequenceStorage, 0);
@@ -297,7 +297,7 @@ private boolean appendDictEntry(PJSONEncoder encoder, TruffleStringBuilderUTF32
if (encoder.skipKeys) {
return true;
}
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.KEYS_MUST_BE_STR_INT___NOT_P, key);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.KEYS_MUST_BE_STR_INT___NOT_P, key);
}
builder.appendCodePointUncached('"');
appendSimpleObj(encoder, builder, key);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
index 2de099ac51..f5e5884b28 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java
@@ -126,7 +126,7 @@ static TruffleString call(TruffleString string,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleString.SubstringNode substringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int len = string.byteLength(TS_ENCODING);
// 12.5% overallocated, TruffleStringBuilder.ToStringNode will copy anyway
@@ -134,7 +134,7 @@ static TruffleString call(TruffleString string,
JSONUtils.appendString(string, createCodePointIteratorNode.execute(string, TS_ENCODING), builder, false, nextNode, appendCodePointNode, appendStringNode, substringNode);
return toStringNode.execute(builder);
} catch (OutOfMemoryError | NegativeArraySizeException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, ErrorMessages.STR_TOO_LONG_TO_ESCAPE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.STR_TOO_LONG_TO_ESCAPE);
}
}
@@ -162,7 +162,7 @@ static TruffleString call(TruffleString string,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleString.SubstringNode substringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int len = string.byteLength(TS_ENCODING);
// 12.5% overallocated, TruffleStringBuilder.ToStringNode will copy anyway
@@ -171,7 +171,7 @@ static TruffleString call(TruffleString string,
nextNode, appendCodePointNode, appendStringNode, substringNode);
return toStringNode.execute(builder);
} catch (OutOfMemoryError | NegativeArraySizeException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, ErrorMessages.STR_TOO_LONG_TO_ESCAPE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.STR_TOO_LONG_TO_ESCAPE);
}
}
}
@@ -226,7 +226,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
PJSONEncoder doNew(Object cls, Object markers, Object defaultFn, Object encoder, Object indent, TruffleString keySeparator, TruffleString itemSeparator, boolean sortKeys,
boolean skipKeys, boolean allowNan) {
if (markers != PNone.NONE && !(markers instanceof PDict)) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.MAKE_ENCODER_ARG_1_MUST_BE_DICT, markers);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.MAKE_ENCODER_ARG_1_MUST_BE_DICT, markers);
}
FastEncode fastEncode = FastEncode.None;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
index 48838a024b..8861be6638 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java
@@ -349,7 +349,7 @@ private Object scanOnceUnicode(PJSONScanner scanner, String string, int idx, Int
* Returns a new PyObject representation of the term.
*/
if (idx < 0) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ValueError, ErrorMessages.IDX_CANNOT_BE_NEG);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ValueError, ErrorMessages.IDX_CANNOT_BE_NEG);
}
int length = string.length();
if (idx >= length) {
@@ -431,7 +431,7 @@ static TruffleString scanStringUnicode(String string, int start, boolean strict,
StringBuilder builder = null;
if (start < 0 || start > string.length()) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonBuiltinClassType.ValueError, ErrorMessages.END_IS_OUT_OF_BOUNDS);
+ throw PRaiseNode.raiseStatic(raisingNode, PythonBuiltinClassType.ValueError, ErrorMessages.END_IS_OUT_OF_BOUNDS);
}
int idx = start;
while (idx < string.length()) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
index d5644b074a..875ca50e13 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
@@ -136,22 +136,22 @@ static PNone init(VirtualFrame frame, LZMACompressor self, int format, int check
@Specialization(guards = "badIntegrity(format, check)")
@SuppressWarnings("unused")
static PNone integrityError(LZMACompressor self, long format, long check, Object preset, Object filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, INTEGRITY_CHECKS_ONLY_SUPPORTED_BY);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INTEGRITY_CHECKS_ONLY_SUPPORTED_BY);
}
@Specialization(guards = {"!badIntegrity(format, check)", "badPresetFilters(preset, filters)"})
@SuppressWarnings("unused")
static PNone presetError(LZMACompressor self, long format, long check, Object preset, Object filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, CANNOT_SPECIFY_PREST_AND_FILTER_CHAIN);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CANNOT_SPECIFY_PREST_AND_FILTER_CHAIN);
}
@Specialization(guards = {"!badIntegrity(format, check)", "!badPresetFilters(preset, filters)", "badRawFilter(format, filters)"})
@SuppressWarnings("unused")
static PNone rawError(LZMACompressor self, long format, long check, Object preset, PNone filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, MUST_SPECIFY_FILTERS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_SPECIFY_FILTERS);
}
protected static boolean badIntegrity(long format, long check) {
@@ -189,8 +189,8 @@ static PBytes doBytes(VirtualFrame frame, LZMACompressor self, Object data,
@SuppressWarnings("unused")
@Specialization(guards = "self.isFlushed()")
static PNone error(LZMACompressor self, Object data,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, COMPRESSOR_HAS_BEEN_FLUSHED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, COMPRESSOR_HAS_BEEN_FLUSHED);
}
@ValueType
@@ -236,8 +236,8 @@ static PBytes doit(LZMACompressor self,
@SuppressWarnings("unused")
@Specialization(guards = "self.isFlushed()")
static PNone error(LZMACompressor self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, REPEATED_CALL_TO_FLUSH);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, REPEATED_CALL_TO_FLUSH);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
index 17983e6658..be0e92dd3f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
@@ -117,12 +117,12 @@ static PNone notRaw(VirtualFrame frame, LZMADecompressor self, int format, Objec
@Bind("this") Node inliningTarget,
@Cached CastToJavaIntExactNode cast,
@Shared("d") @Cached LZMANodes.LZMADecompressInit decompressInit,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int memlimit;
try {
memlimit = cast.execute(inliningTarget, memlimitObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
return doNotRaw(frame, self, format, memlimit, decompressInit);
@@ -155,29 +155,29 @@ static PNone raw(VirtualFrame frame, LZMADecompressor self, int format, PNone me
@SuppressWarnings("unused")
@Specialization(guards = {"isRaw(format)", "!isPNone(memlimit)"})
static PNone rawError(LZMADecompressor self, int format, Object memlimit, Object filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANNOT_SPECIFY_MEM_LIMIT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANNOT_SPECIFY_MEM_LIMIT);
}
@SuppressWarnings("unused")
@Specialization(guards = "isRaw(format)")
static PNone rawFilterError(LZMADecompressor self, int format, Object memlimit, PNone filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.MUST_SPECIFY_FILTERS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.MUST_SPECIFY_FILTERS);
}
@SuppressWarnings("unused")
@Specialization(guards = {"!isRaw(format)", "!isPNone(filters)"})
static PNone rawFilterError(LZMADecompressor self, int format, Object memlimit, Object filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANNOT_SPECIFY_FILTERS);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANNOT_SPECIFY_FILTERS);
}
@SuppressWarnings("unused")
@Specialization(guards = "!validFormat(format)")
static PNone invalidFormat(LZMADecompressor self, int format, Object memlimit, Object filters,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.INVALID_CONTAINER_FORMAT, format);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.INVALID_CONTAINER_FORMAT, format);
}
protected static boolean validFormat(int format) {
@@ -229,8 +229,8 @@ static PBytes doObject(VirtualFrame frame, LZMADecompressor self, Object data, i
@SuppressWarnings("unused")
@Specialization(guards = {"self.isEOF()"})
static Object err(LZMADecompressor self, Object data, int maxLength,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(EOFError, ALREADY_AT_END_OF_STREAM);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, EOFError, ALREADY_AT_END_OF_STREAM);
}
}
@@ -270,8 +270,8 @@ int doCheck(LZMADecompressor.Native self) {
@Specialization
static int doCheck(@SuppressWarnings("unused") LZMADecompressor.Java self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, T_LZMA_JAVA_ERROR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, T_LZMA_JAVA_ERROR);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java
index 723990fb85..3519e4e58e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -204,12 +204,12 @@ long l(long l) {
@Specialization
long ll(long l,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (l < 0) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.CANT_CONVERT_NEG_INT_TO_UNSIGNED);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANT_CONVERT_NEG_INT_TO_UNSIGNED);
}
if (l > MAX_UINT32 && with32BitLimit) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.VALUE_TOO_LARGE_FOR_UINT32);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.VALUE_TOO_LARGE_FOR_UINT32);
}
return l;
}
@@ -219,11 +219,11 @@ long ll(long l,
long o(Object o,
@Bind("this") Node inliningTarget,
@Cached CastToJavaLongExactNode cast,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
return ll(cast.execute(inliningTarget, o), inliningTarget, raiseNode);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, INTEGER_REQUIRED);
}
}
@@ -247,10 +247,10 @@ public abstract static class GetOptionsDict extends Node {
static HashingStorage fast(VirtualFrame frame, PDict dict,
@Bind("this") Node inliningTarget,
@Shared("getItem") @Cached HashingStorageGetItem getItem,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
HashingStorage storage = dict.getDictStorage();
if (!getItem.hasKey(frame, inliningTarget, storage, T_ID)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, FILTER_SPECIFIER_MUST_HAVE);
+ throw raiseNode.raise(inliningTarget, ValueError, FILTER_SPECIFIER_MUST_HAVE);
}
return storage;
}
@@ -260,10 +260,10 @@ static HashingStorage slow(VirtualFrame frame, Object object,
@Bind("this") Node inliningTarget,
@Shared("getItem") @Cached HashingStorageGetItem getItem,
@Cached GetDictIfExistsNode getDict,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PDict dict = getDict.execute(object);
if (dict == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, FILTER_SPEC_MUST_BE_DICT);
+ throw raiseNode.raise(inliningTarget, TypeError, FILTER_SPEC_MUST_BE_DICT);
}
return fast(frame, dict, inliningTarget, getItem, raiseNode);
}
@@ -292,23 +292,23 @@ static OptionsState doit(Frame frame, Node inliningTarget, HashingStorage storag
@Cached CastToJavaLongLossyNode toLong,
@Cached InlinedConditionProfile errProfile,
@Cached HashingStorageGetItem getItem,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached(inline = false) TruffleString.EqualNode equalNode) {
Object key = itKey.execute(inliningTarget, storage, it);
TruffleString skey = strNode.execute(frame, inliningTarget, key);
int idx = getOptionIndex(skey, s, equalNode);
if (errProfile.profile(inliningTarget, idx == -1)) {
- throw raise.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_FILTER_SPECIFIED_FOR_FILTER, s.filterType);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.INVALID_FILTER_SPECIFIED_FOR_FILTER, s.filterType);
}
long l = toLong.execute(inliningTarget, getItem.execute(inliningTarget, s.dictStorage, skey));
if (errProfile.profile(inliningTarget, l < 0)) {
- throw raise.get(inliningTarget).raise(OverflowError, ErrorMessages.CANT_CONVERT_NEG_INT_TO_UNSIGNED);
+ throw raise.raise(inliningTarget, OverflowError, ErrorMessages.CANT_CONVERT_NEG_INT_TO_UNSIGNED);
}
if (errProfile.profile(inliningTarget, l > MAX_UINT32 && idx > 0) /*
* filters are special
* case
*/) {
- throw raise.get(inliningTarget).raise(OverflowError, ErrorMessages.VALUE_TOO_LARGE_FOR_UINT32);
+ throw raise.raise(inliningTarget, OverflowError, ErrorMessages.VALUE_TOO_LARGE_FOR_UINT32);
}
s.options[idx] = l;
return s;
@@ -421,7 +421,7 @@ static long[] converter(VirtualFrame frame, Object spec,
@Cached GetOptionsDict getOptionsDict,
@Cached HashingStorageGetItem getItem,
@Cached HashingStorageForEach forEachNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
HashingStorage dict = getOptionsDict.execute(frame, spec);
Object idObj = getItem.execute(inliningTarget, dict, T_ID);
long id = toLong.execute(inliningTarget, idObj);
@@ -451,7 +451,7 @@ static long[] converter(VirtualFrame frame, Object spec,
state = new OptionsState("BCJ", BCJOption.values(), options, dict);
break;
default:
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_FILTER, id);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_FILTER, id);
}
options[0] = id;
forEachNode.execute(frame, inliningTarget, dict, getOptions, state);
@@ -472,11 +472,11 @@ long[][] parseFilter(VirtualFrame frame, Object filterSpecs,
@Cached LZMAFilterConverter converter,
@Cached SequenceNodes.CheckIsSequenceNode checkIsSequenceNode,
@Cached PyObjectSizeNode sizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkIsSequenceNode.execute(inliningTarget, filterSpecs);
int numFilters = sizeNode.execute(frame, inliningTarget, filterSpecs);
if (numFilters > LZMA_FILTERS_MAX) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TOO_MAMNY_FILTERS_LZMA_SUPPORTS_MAX_S, LZMA_FILTERS_MAX);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOO_MAMNY_FILTERS_LZMA_SUPPORTS_MAX_S, LZMA_FILTERS_MAX);
}
long[][] filters = new long[numFilters][0];
for (int i = 0; i < numFilters; i++) {
@@ -498,7 +498,7 @@ static void parseFilterChainSpec(VirtualFrame frame, Object lzmast, PythonContex
@Cached NativeLibrary.InvokeNativeFunction setFilterSpecDelta,
@Cached NativeLibrary.InvokeNativeFunction setFilterSpecBCJ,
@Cached LZMAParseFilterChain parseFilterChain,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long[][] filters = parseFilterChain.execute(frame, filterSpecs);
for (int i = 0; i < filters.length; i++) {
setFilterOptions(inliningTarget, lzmast, filters[i], i, context, setFilterSpecLZMA, setFilterSpecDelta, setFilterSpecBCJ, raiseNode);
@@ -509,7 +509,7 @@ private static void setFilterOptions(Node inliningTarget, Object lzmast, long[]
NativeLibrary.InvokeNativeFunction setFilterSpecLZMA,
NativeLibrary.InvokeNativeFunction setFilterSpecDelta,
NativeLibrary.InvokeNativeFunction setFilterSpecBCJ,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = context.getNFILZMASupport();
Object opts = context.getEnv().asGuestValue(filter);
int err;
@@ -521,7 +521,7 @@ private static void setFilterOptions(Node inliningTarget, Object lzmast, long[]
err = lzmaSupport.setFilterSpecLZMA(lzmast, fidx, opts, setFilterSpecLZMA);
if (err != LZMA_OK) {
if (err == LZMA_PRESET_ERROR) {
- throw raiseNode.get(inliningTarget).raise(LZMAError, INVALID_COMPRESSION_PRESET, filter[LZMAOption.preset.ordinal()]);
+ throw raiseNode.raise(inliningTarget, LZMAError, INVALID_COMPRESSION_PRESET, filter[LZMAOption.preset.ordinal()]);
}
errorHandling(inliningTarget, err, raiseNode);
}
@@ -546,7 +546,7 @@ private static void setFilterOptions(Node inliningTarget, Object lzmast, long[]
}
return;
}
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_FILTER, id);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_FILTER, id);
}
}
@@ -559,14 +559,14 @@ protected abstract static class JavaFilterChain extends Node {
@Specialization
static FilterOptions[] parseFilterChainSpec(VirtualFrame frame, Node inliningTarget, Object filterSpecs,
@Cached(inline = false) LZMAParseFilterChain parseFilterChain,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long[][] filters = parseFilterChain.execute(frame, filterSpecs);
FilterOptions[] optionsChain = new FilterOptions[filters.length];
for (int i = 0; i < filters.length; i++) {
try {
optionsChain[i] = getFilterOptions(filters[i], inliningTarget);
} catch (UnsupportedOptionsException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.M, e);
}
}
@@ -592,7 +592,7 @@ private static FilterOptions getFilterOptions(long[] longFilter, Node raisingNod
try {
lzma2Options = new LZMA2Options(filter[1]);
} catch (UnsupportedOptionsException e) {
- throw PRaiseNode.raiseUncached(raisingNode, LZMAError, INVALID_COMPRESSION_PRESET, filter[LZMAOption.preset.ordinal()]);
+ throw PRaiseNode.raiseStatic(raisingNode, LZMAError, INVALID_COMPRESSION_PRESET, filter[LZMAOption.preset.ordinal()]);
}
for (int j = 2; j < filter.length; j++) {
setLZMAOption(lzma2Options, j, filter[j]);
@@ -643,7 +643,7 @@ private static FilterOptions getFilterOptions(long[] longFilter, Node raisingNod
}
return sparcOptions;
}
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, INVALID_FILTER, longFilter[0]);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, INVALID_FILTER, longFilter[0]);
}
@TruffleBoundary
@@ -692,7 +692,7 @@ static void xz(LZMACompressor.Native self, @SuppressWarnings("unused") int forma
@Shared("cs") @Cached NativeLibrary.InvokeNativeFunction createStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaEasyEncoder,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = PythonContext.get(inliningTarget).getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
self.init(lzmast, lzmaSupport);
@@ -709,7 +709,7 @@ static void xz(VirtualFrame frame, LZMACompressor.Native self, @SuppressWarnings
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaStreamEncoder,
@Exclusive @Cached NativeFilterChain filterChain,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PythonContext ctxt = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = ctxt.getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
@@ -728,7 +728,7 @@ static void alone(LZMACompressor.Native self, int format, long preset, PNone fil
@Shared("cs") @Cached NativeLibrary.InvokeNativeFunction createStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaAloneEncoderPreset,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = PythonContext.get(inliningTarget).getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
self.init(lzmast, lzmaSupport);
@@ -746,7 +746,7 @@ static void alone(VirtualFrame frame, LZMACompressor.Native self, int format, lo
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaAloneEncoder,
@Exclusive @Cached NativeFilterChain filterChain,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PythonContext ctxt = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = ctxt.getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
@@ -766,7 +766,7 @@ static void raw(VirtualFrame frame, LZMACompressor.Native self, int format, long
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaRawEncoder,
@Exclusive @Cached NativeFilterChain filterChain,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PythonContext ctxt = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = ctxt.getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
@@ -781,11 +781,11 @@ static void raw(VirtualFrame frame, LZMACompressor.Native self, int format, long
@Specialization(guards = "format == FORMAT_XZ")
static void xz(LZMACompressor.Java self, @SuppressWarnings("unused") int format, long preset, @SuppressWarnings("unused") PNone filters,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
self.lzmaEasyEncoder(parseLZMAOptions(preset));
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.M, e);
}
}
@@ -793,11 +793,11 @@ static void xz(LZMACompressor.Java self, @SuppressWarnings("unused") int format,
static void xz(VirtualFrame frame, LZMACompressor.Java self, @SuppressWarnings("unused") int format, @SuppressWarnings("unused") long preset, Object filters,
@Bind("this") Node inliningTarget,
@Shared @Cached JavaFilterChain filterChain,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
self.lzmaStreamEncoder(filterChain.execute(frame, inliningTarget, filters));
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.M, e);
}
}
@@ -805,11 +805,11 @@ static void xz(VirtualFrame frame, LZMACompressor.Java self, @SuppressWarnings("
@Specialization(guards = "format == FORMAT_ALONE")
static void alone(LZMACompressor.Java self, int format, long preset, PNone filters,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
self.lzmaAloneEncoder(parseLZMAOptions(preset));
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.M, e);
}
}
@@ -818,15 +818,15 @@ static void alone(LZMACompressor.Java self, int format, long preset, PNone filte
static void alone(VirtualFrame frame, LZMACompressor.Java self, int format, long preset, Object filters,
@Bind("this") Node inliningTarget,
@Shared @Cached JavaFilterChain filterChain,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
FilterOptions[] optionsChain = filterChain.execute(frame, inliningTarget, filters);
if (optionsChain.length != 1 && !(optionsChain[0] instanceof LZMA2Options)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_FILTER_CHAIN_FOR_FORMAT);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_FILTER_CHAIN_FOR_FORMAT);
}
try {
self.lzmaAloneEncoder((LZMA2Options) optionsChain[0]);
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.M, e);
}
}
@@ -835,24 +835,23 @@ static void alone(VirtualFrame frame, LZMACompressor.Java self, int format, long
static void raw(VirtualFrame frame, LZMACompressor.Java self, int format, long preset, Object filters,
@Bind("this") Node inliningTarget,
@Shared @Cached JavaFilterChain filterChain,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
FilterOptions[] optionsChain = filterChain.execute(frame, inliningTarget, filters);
if (optionsChain.length != 1 && !(optionsChain[0] instanceof LZMA2Options)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_FILTER_CHAIN_FOR_FORMAT);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_FILTER_CHAIN_FOR_FORMAT);
}
try {
self.lzmaRawEncoder(optionsChain);
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.M, e);
}
}
@Fallback
@SuppressWarnings("unused")
static void error(VirtualFrame frame, LZMACompressor self, int format, long preset, Object filters,
- @Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_CONTAINER_FORMAT, format);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INVALID_CONTAINER_FORMAT, format);
}
}
@@ -876,7 +875,7 @@ static byte[] nativeCompress(Node inliningTarget, LZMACompressor.Native self, Py
@Cached(inline = false) NativeLibrary.InvokeNativeFunction compress,
@Cached GetOutputNativeBufferNode getBuffer,
@Cached InlinedConditionProfile errProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = context.getNFILZMASupport();
Object inGuest = context.getEnv().asGuestValue(bytes);
int err = lzmaSupport.compress(self.getLzs(), inGuest, len, action, INITIAL_BUFFER_SIZE, compress);
@@ -889,26 +888,26 @@ static byte[] nativeCompress(Node inliningTarget, LZMACompressor.Native self, Py
@SuppressWarnings("unused")
@Specialization(guards = "action == LZMA_RUN")
static byte[] javaCompress(Node inliningTarget, LZMACompressor.Java self, PythonContext context, byte[] bytes, int len, int action,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
self.write(bytes, 0, len);
byte[] result = self.getByteArray();
self.resetBuffer();
return result;
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.M, e);
}
}
@SuppressWarnings("unused")
@Specialization(guards = "action == LZMA_FINISH")
static byte[] javaFlush(Node inliningTarget, LZMACompressor.Java self, PythonContext context, byte[] bytes, int len, int action,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
self.finish();
return self.getByteArray();
} catch (IOException e) {
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.M, e);
}
}
}
@@ -930,7 +929,7 @@ static void auto(LZMADecompressor.Native self, @SuppressWarnings("unused") int f
@Shared("cs") @Cached NativeLibrary.InvokeNativeFunction createStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaAutoDecoder,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = PythonContext.get(inliningTarget).getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
self.init(lzmast, lzmaSupport);
@@ -947,7 +946,7 @@ static void xz(LZMADecompressor.Native self, @SuppressWarnings("unused") int for
@Shared("cs") @Cached NativeLibrary.InvokeNativeFunction createStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaStreamDecoder,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = PythonContext.get(inliningTarget).getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
self.init(lzmast, lzmaSupport);
@@ -964,7 +963,7 @@ static void alone(LZMADecompressor.Native self, @SuppressWarnings("unused") int
@Shared("cs") @Cached NativeLibrary.InvokeNativeFunction createStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction lzmaAloneDecoder,
@Shared @Cached InlinedConditionProfile errProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = PythonContext.get(inliningTarget).getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
self.init(lzmast, lzmaSupport);
@@ -985,8 +984,8 @@ public abstract static class LZMARawDecompressInit extends Node {
@SuppressWarnings("unused")
@Specialization
static void rawJava(VirtualFrame frame, LZMADecompressor.Java self, Object filters,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, T_LZMA_JAVA_ERROR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, T_LZMA_JAVA_ERROR);
}
@Specialization
@@ -995,7 +994,7 @@ static void rawNative(VirtualFrame frame, Node inliningTarget, LZMADecompressor.
@Cached(inline = false) NativeLibrary.InvokeNativeFunction lzmaRawDecoder,
@Cached(inline = false) NativeFilterChain filterChain,
@Cached InlinedConditionProfile errProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = context.getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
@@ -1116,7 +1115,7 @@ static byte[] nativeInternalDecompress(Node inliningTarget, LZMADecompressor.Nat
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getNextInIndex,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getLzsCheck,
@Cached GetOutputNativeBufferNode getBuffer,
- @Exclusive @Cached PRaiseNode.Lazy lazyRaiseNode,
+ @Exclusive @Cached PRaiseNode lazyRaiseNode,
@Cached InlinedConditionProfile errProfile) {
PythonContext context = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = context.getNFILZMASupport();
@@ -1132,7 +1131,7 @@ static byte[] nativeInternalDecompress(Node inliningTarget, LZMADecompressor.Nat
self.setLzsAvailIn(lzsAvailIn);
self.setLzsAvailOut(lzsAvailOut);
} catch (OverflowException of) {
- throw lazyRaiseNode.get(inliningTarget).raise(SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
+ throw lazyRaiseNode.raise(inliningTarget, SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
}
if (err == LZMA_STREAM_END) {
self.setEOF();
@@ -1145,7 +1144,7 @@ static byte[] nativeInternalDecompress(Node inliningTarget, LZMADecompressor.Nat
@TruffleBoundary
@Specialization
static byte[] javaInternalDecompress(Node inliningTarget, LZMADecompressor.Java self, int maxLength,
- @Exclusive @Cached PRaiseNode.Lazy lazyRaiseNode) {
+ @Exclusive @Cached PRaiseNode lazyRaiseNode) {
if (maxLength == 0) {
return PythonUtils.EMPTY_BYTE_ARRAY;
}
@@ -1191,7 +1190,7 @@ static byte[] javaInternalDecompress(Node inliningTarget, LZMADecompressor.Java
} catch (EOFException eof) {
self.setEOF();
} catch (IOException e) {
- PRaiseNode.raiseUncached(inliningTarget, OSError, e);
+ PRaiseNode.raiseStatic(inliningTarget, OSError, e);
}
byte[] ret = toByteArray(baos);
self.decompressedData(ret.length);
@@ -1231,13 +1230,13 @@ public abstract static class GetOutputNativeBufferNode extends Node {
static byte[] getBuffer(Node inliningTarget, Object lzmast, PythonContext context,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getBufferSize,
@Cached(inline = false) NativeLibrary.InvokeNativeFunction getBuffer,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
NFILZMASupport lzmaSupport = context.getNFILZMASupport();
int size;
try {
size = PInt.intValueExact(lzmaSupport.getOutputBufferSize(lzmast, getBufferSize));
} catch (OverflowException of) {
- throw raiseNode.get(inliningTarget).raise(SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
+ throw raiseNode.raise(inliningTarget, SystemError, VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
}
if (size == 0) {
return PythonUtils.EMPTY_BYTE_ARRAY;
@@ -1298,7 +1297,7 @@ static byte[] encodeNative(VirtualFrame frame, Object filter,
@Cached NativeLibrary.InvokeNativeFunction encodeFilter,
@Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Cached InlinedConditionProfile errProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext ctxt = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = ctxt.getNFILZMASupport();
Object lzmast = lzmaSupport.createStream(createStream);
@@ -1307,7 +1306,7 @@ static byte[] encodeNative(VirtualFrame frame, Object filter,
if (errProfile.profile(inliningTarget, lzret != LZMA_OK)) {
lzmaSupport.deallocateStream(lzmast, deallocateStream);
if (lzret == LZMA_PRESET_ERROR) {
- throw raiseNode.get(inliningTarget).raise(LZMAError, INVALID_COMPRESSION_PRESET, opts[LZMAOption.preset.ordinal()]);
+ throw raiseNode.raise(inliningTarget, LZMAError, INVALID_COMPRESSION_PRESET, opts[LZMAOption.preset.ordinal()]);
}
errorHandling(inliningTarget, lzret, raiseNode);
}
@@ -1319,8 +1318,8 @@ static byte[] encodeNative(VirtualFrame frame, Object filter,
@SuppressWarnings("unused")
@Specialization(guards = "!useNativeContext()")
static byte[] encodeJava(Object filter,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, T_LZMA_JAVA_ERROR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, T_LZMA_JAVA_ERROR);
}
}
@@ -1340,7 +1339,7 @@ static void decodeNative(VirtualFrame frame, long id, byte[] encoded, PDict dict
@Cached NativeLibrary.InvokeNativeFunction decodeFilter,
@Cached HashingStorageSetItem setItem,
@Cached InlinedConditionProfile errProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext ctxt = PythonContext.get(inliningTarget);
NFILZMASupport lzmaSupport = ctxt.getNFILZMASupport();
long[] opts = new long[MAX_OPTS_INDEX];
@@ -1350,7 +1349,7 @@ static void decodeNative(VirtualFrame frame, long id, byte[] encoded, PDict dict
int lzret = lzmaSupport.decodeFilter(id, encodedProps, len, filter, decodeFilter);
if (errProfile.profile(inliningTarget, lzret != LZMA_OK)) {
if (lzret == LZMA_ID_ERROR) {
- throw raiseNode.get(inliningTarget).raise(LZMAError, INVALID_FILTER, opts[LZMAOption.id.ordinal()]);
+ throw raiseNode.raise(inliningTarget, LZMAError, INVALID_FILTER, opts[LZMAOption.id.ordinal()]);
}
errorHandling(inliningTarget, lzret, raiseNode);
}
@@ -1360,8 +1359,8 @@ static void decodeNative(VirtualFrame frame, long id, byte[] encoded, PDict dict
@SuppressWarnings("unused")
@Specialization(guards = "!useNativeContext()")
static void decodeJava(long id, byte[] encoded, PDict dict,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, T_LZMA_JAVA_ERROR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, T_LZMA_JAVA_ERROR);
}
static void buildFilterSpec(VirtualFrame frame, Node inliningTarget, long[] opts, PDict dict, HashingStorageSetItem setItem) {
@@ -1435,7 +1434,7 @@ public int getAvailIn() {
}
}
- protected static int errorHandling(Node inliningTarget, int lzret, PRaiseNode.Lazy raiseNode) {
+ protected static int errorHandling(Node inliningTarget, int lzret, PRaiseNode raiseNode) {
switch (lzret) {
case LZMA_OK:
case LZMA_GET_CHECK:
@@ -1443,23 +1442,23 @@ protected static int errorHandling(Node inliningTarget, int lzret, PRaiseNode.La
case LZMA_STREAM_END:
return 0;
case LZMA_UNSUPPORTED_CHECK:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.UNSUPPORTED_INTEGRITY_CHECK);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.UNSUPPORTED_INTEGRITY_CHECK);
case LZMA_MEM_ERROR:
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
case LZMA_MEMLIMIT_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.MEM_USAGE_LIMIT_EXCEEDED);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.MEM_USAGE_LIMIT_EXCEEDED);
case LZMA_FORMAT_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.INPUT_FMT_NOT_SUPPORTED_BY_DECODER);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.INPUT_FMT_NOT_SUPPORTED_BY_DECODER);
case LZMA_OPTIONS_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.INVALID_UNSUPPORTED_OPTIONS);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.INVALID_UNSUPPORTED_OPTIONS);
case LZMA_DATA_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.CORRUPT_INPUT_DATA);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.CORRUPT_INPUT_DATA);
case LZMA_BUF_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.INSUFFICIENT_BUFFER_SPACE);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.INSUFFICIENT_BUFFER_SPACE);
case LZMA_PROG_ERROR:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.INTERNAL_ERROR);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.INTERNAL_ERROR);
default:
- throw raiseNode.get(inliningTarget).raise(LZMAError, ErrorMessages.UNRECOGNIZED_ERROR_FROM_LIBLZMA, lzret);
+ throw raiseNode.raise(inliningTarget, LZMAError, ErrorMessages.UNRECOGNIZED_ERROR_FROM_LIBLZMA, lzret);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
index 41e7a60abf..cc66ccc62c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/GraalPySemLockBuiltins.java
@@ -264,10 +264,10 @@ abstract static class ReleaseLockNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doRelease(PGraalPySemLock self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getKind() == PGraalPySemLock.RECURSIVE_MUTEX) {
if (!self.isMine()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AssertionError, ErrorMessages.ATTEMP_TO_RELEASE_RECURSIVE_LOCK);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AssertionError, ErrorMessages.ATTEMP_TO_RELEASE_RECURSIVE_LOCK);
}
if (self.getCount() > 1) {
self.decreaseCount();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
index 86d2466c87..44ab5a02d0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingGraalPyModuleBuiltins.java
@@ -136,9 +136,9 @@ static PGraalPySemLock construct(Object cls, int kind, int value, @SuppressWarni
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (kind != PGraalPySemLock.RECURSIVE_MUTEX && kind != PGraalPySemLock.SEMAPHORE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.UNRECOGNIZED_KIND);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.UNRECOGNIZED_KIND);
}
Semaphore semaphore = newSemaphore(value);
if (!unlink) {
@@ -149,7 +149,7 @@ static PGraalPySemLock construct(Object cls, int kind, int value, @SuppressWarni
// semaphores, so a conflict raises.
SharedMultiprocessingData multiprocessing = PythonContext.get(inliningTarget).getSharedMultiprocessingData();
if (multiprocessing.getNamedSemaphore(name) != null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.FileExistsError, ErrorMessages.SEMAPHORE_NAME_TAKEN, name);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.FileExistsError, ErrorMessages.SEMAPHORE_NAME_TAKEN, name);
} else {
multiprocessing.putNamedSemaphore(name, semaphore);
}
@@ -305,7 +305,7 @@ Object doWrite(int fd, PBytes data,
byte[] bytes = bufferLib.getCopiedByteArray(data);
sharedData.addPipeData(fd, bytes,
() -> {
- throw PRaiseNode.raiseUncached(this, OSError, ErrorMessages.BAD_FILE_DESCRIPTOR);
+ throw PRaiseNode.raiseStatic(this, OSError, ErrorMessages.BAD_FILE_DESCRIPTOR);
},
() -> {
throw PConstructAndRaiseNode.getUncached().raiseOSError(null, OSErrorEnum.EPIPE);
@@ -335,7 +335,7 @@ Object doReadInt(int fd, @SuppressWarnings("unused") Object length,
gil.release(true);
try {
Object data = sharedData.takePipeData(this, fd, () -> {
- throw PRaiseNode.raiseUncached(this, OSError, ErrorMessages.BAD_FILE_DESCRIPTOR);
+ throw PRaiseNode.raiseStatic(this, OSError, ErrorMessages.BAD_FILE_DESCRIPTOR);
});
if (data == PNone.NONE) {
return PFactory.createEmptyBytes(language);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
index 503ec392a6..57ef5fa43e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/MultiprocessingModuleBuiltins.java
@@ -97,9 +97,9 @@ static PSemLock construct(VirtualFrame frame, Object cls, int kind, int value, i
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (kind != PGraalPySemLock.RECURSIVE_MUTEX && kind != PGraalPySemLock.SEMAPHORE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.UNRECOGNIZED_KIND);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.UNRECOGNIZED_KIND);
}
Object posixName = posixLib.createPathFromString(posixSupport, name);
long handle;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
index 6b25b671de..fd6fe707cd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/multiprocessing/SemLockBuiltins.java
@@ -207,11 +207,11 @@ static PNone release(VirtualFrame frame, PSemLock self,
@Bind("this") Node inliningTarget,
@Bind("getPosixSupport()") PosixSupport posixSupport,
@CachedLibrary("posixSupport") PosixSupportLibrary posixLib,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
if (self.getKind() == PSemLock.RECURSIVE_MUTEX) {
if (!self.isMine()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AssertionError, ErrorMessages.ATTEMP_TO_RELEASE_RECURSIVE_LOCK);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AssertionError, ErrorMessages.ATTEMP_TO_RELEASE_RECURSIVE_LOCK);
}
if (self.getCount() > 1) {
self.decreaseCount();
@@ -223,7 +223,7 @@ static PNone release(VirtualFrame frame, PSemLock self,
try {
sval = posixLib.semGetValue(posixSupport, self.getHandle());
if (sval >= self.getMaxValue()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SEMAPHORE_RELEASED_TOO_MANY_TIMES);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SEMAPHORE_RELEASED_TOO_MANY_TIMES);
}
} catch (UnsupportedPosixFeatureException e) {
/* We will only check properly the maxvalue == 1 case */
@@ -231,7 +231,7 @@ static PNone release(VirtualFrame frame, PSemLock self,
if (posixLib.semTryWait(posixSupport, self.getHandle())) {
/* it was not locked so undo wait and raise */
posixLib.semPost(posixSupport, self.getHandle());
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SEMAPHORE_RELEASED_TOO_MANY_TIMES);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SEMAPHORE_RELEASED_TOO_MANY_TIMES);
}
}
}
@@ -296,7 +296,7 @@ int get(VirtualFrame frame, PSemLock self,
@Bind("getPosixSupport()") PosixSupport posixSupport,
@CachedLibrary("posixSupport") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int sval = posixLib.semGetValue(posixSupport, self.getHandle());
/*
@@ -311,7 +311,7 @@ int get(VirtualFrame frame, PSemLock self,
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} catch (UnsupportedPosixFeatureException e) {
// Not available on Darwin
- throw raiseNode.get(inliningTarget).raise(NotImplementedError);
+ throw raiseNode.raise(inliningTarget, NotImplementedError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/MemoTable.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/MemoTable.java
index 595da28de2..4393f54f42 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/MemoTable.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/MemoTable.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -173,7 +173,7 @@ private void resize() {
if (newLength <= keys.length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
// overflow
- throw PRaiseNode.raiseUncached(null, PicklingError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
+ throw PRaiseNode.raiseStatic(null, PicklingError, ErrorMessages.STRUCT_SIZE_TOO_LONG);
}
MemoIterator iterator = iterator(); // captures the current contents
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
index 61a1f25b8f..c53e006ed1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PData.java
@@ -98,8 +98,8 @@ public void grow() throws OverflowException {
}
public abstract static class PDataBaseNode extends PNodeWithContext {
- static PException raiseUnderflow(PData self, PRaiseNode raiseNode) {
- return raiseNode.raise(PythonBuiltinClassType.UnpicklingError,
+ static PException raiseUnderflow(PData self, Node inliningTarget, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.UnpicklingError,
self.mark ? ErrorMessages.PDATA_UNEXPECTED_MARK_FOUND : ErrorMessages.PDATA_UNPICKLING_STACK_UNDERFLOW);
}
}
@@ -112,9 +112,9 @@ public abstract static class PDataPopNode extends PDataBaseNode {
@Specialization
static Object pop(PData self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.size <= self.fence) {
- throw raiseUnderflow(self, raiseNode.get(inliningTarget));
+ throw raiseUnderflow(self, inliningTarget, raiseNode);
}
return self.data[--self.size];
}
@@ -132,12 +132,12 @@ public abstract static class PDataPushNode extends PDataBaseNode {
@Specialization
static void push(PData self, Object obj,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.size == self.data.length) {
try {
self.grow();
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseOverflow();
+ throw raiseNode.raiseOverflow(inliningTarget);
}
}
self.data[self.size++] = obj;
@@ -157,11 +157,11 @@ public abstract static class PDataPopTupleNode extends PDataBaseNode {
static PTuple popTuple(PData self, int start,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int len, i, j;
if (start < self.fence) {
- throw raiseUnderflow(self, raiseNode.get(inliningTarget));
+ throw raiseUnderflow(self, inliningTarget, raiseNode);
}
len = self.size - start;
Object[] items = new Object[len];
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickleBuffer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickleBuffer.java
index d9bf079ce6..456c130bd1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickleBuffer.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickleBuffer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,10 +47,12 @@
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
@ExportLibrary(PythonBufferAcquireLibrary.class)
@@ -80,6 +82,7 @@ boolean hasBuffer() {
@ExportMessage
Object acquire(int flags,
+ @Bind("$node") Node inliningTarget,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary acquireLib,
@Cached PRaiseNode raise) {
@@ -88,7 +91,7 @@ Object acquire(int flags,
owner = bufferLib.getOwner(view);
}
if (owner == null) {
- throw raise.raise(ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
}
return acquireLib.acquire(owner, flags);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
index 673b820c03..c47ce7a2d1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PPickler.java
@@ -273,32 +273,32 @@ private void fastMemoRemove(Object object) {
}
// helper methods
- public void setProtocol(Node inliningTarget, PRaiseNode.Lazy raiseNode, int protocol, boolean fixImports) {
+ public void setProtocol(Node inliningTarget, PRaiseNode raiseNode, int protocol, boolean fixImports) {
proto = protocol;
if (proto < 0) {
proto = PickleUtils.PICKLE_PROTOCOL_HIGHEST;
} else if (proto > PickleUtils.PICKLE_PROTOCOL_HIGHEST) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.PICKLE_PROTO_MUST_BE_LE, PickleUtils.PICKLE_PROTOCOL_HIGHEST);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.PICKLE_PROTO_MUST_BE_LE, PickleUtils.PICKLE_PROTOCOL_HIGHEST);
}
this.bin = (proto > 0) ? 1 : 0;
this.fixImports = fixImports && proto < 3;
}
- public void setOutputStream(VirtualFrame frame, Node inliningTarget, PRaiseNode.Lazy raiseNode, PyObjectLookupAttr lookup, Object file) {
+ public void setOutputStream(VirtualFrame frame, Node inliningTarget, PRaiseNode raiseNode, PyObjectLookupAttr lookup, Object file) {
write = lookup.execute(frame, inliningTarget, file, PickleUtils.T_METHOD_WRITE);
if (write == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.FILE_MUST_HAVE_WRITE_ATTR);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.FILE_MUST_HAVE_WRITE_ATTR);
}
}
- public void setBufferCallback(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object callback) {
+ public void setBufferCallback(Node inliningTarget, PRaiseNode raiseNode, Object callback) {
bufferCallback = callback;
if (PGuards.isNone(callback) || PGuards.isNoValue(callback)) {
bufferCallback = null;
}
if (bufferCallback != null && proto < 5) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.BUFFCB_NEEDS_PROTO_GE_5);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.BUFFCB_NEEDS_PROTO_GE_5);
}
}
@@ -951,7 +951,7 @@ private void saveReduce(VirtualFrame frame, PythonContext ctx, PPickler pickler,
boolean useNewobj = false, useNewobjEx = false;
if (!(arguments instanceof PTuple)) {
- throw getRaiseNode().raiseBadInternalCall();
+ throw raise(PythonBuiltinClassType.SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
int size = length(frame, arguments);
if (size < 2 || size > 6) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
index f655fa1a01..f4729ecb59 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java
@@ -294,7 +294,7 @@ public void initInternals(VirtualFrame frame, Node inliningTarget, PyObjectLooku
this.persFuncSelf = pair.getRight();
}
- public void setInputStream(VirtualFrame frame, Node inliningTarget, PRaiseNode.Lazy raiseNode, PyObjectLookupAttr lookup, Object file) {
+ public void setInputStream(VirtualFrame frame, Node inliningTarget, PRaiseNode raiseNode, PyObjectLookupAttr lookup, Object file) {
this.peek = lookup.execute(frame, inliningTarget, file, T_METHOD_PEEK);
if (this.peek == PNone.NO_VALUE) {
this.peek = null;
@@ -306,7 +306,7 @@ public void setInputStream(VirtualFrame frame, Node inliningTarget, PRaiseNode.L
this.read = lookup.execute(frame, inliningTarget, file, T_METHOD_READ);
this.readline = lookup.execute(frame, inliningTarget, file, T_METHOD_READLINE);
if (this.readline == PNone.NO_VALUE || this.read == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.FILE_MUST_HAVE_A_AND_B_ATTRS, T_METHOD_READ, T_METHOD_READLINE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.FILE_MUST_HAVE_A_AND_B_ATTRS, T_METHOD_READ, T_METHOD_READLINE);
}
}
@@ -926,7 +926,7 @@ private void loadFloat(VirtualFrame frame, PUnpickler self) {
// TODO: (cbasca) we skip an entire branch from _pickle.c:load_float
// TODO: (cbasca) should we return a PFloat ? (same for load_int/long variants)
- value = PickleUtils.asciiBytesToDouble(s, getRaiseNode(), PythonBuiltinClassType.OverflowError);
+ value = PickleUtils.asciiBytesToDouble(this, s, PythonBuiltinClassType.OverflowError);
pDataPush(self, value);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
index 6c64e33abb..f663f3150c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleBufferBuiltins.java
@@ -86,16 +86,16 @@ Object raw(VirtualFrame frame, PPickleBuffer self,
@Cached PyMemoryViewFromObject memoryViewFromObject,
@Cached MemoryViewNodes.ReleaseNode releaseNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final Object view = self.getView();
if (view == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
}
PMemoryView mv = memoryViewFromObject.execute(frame, self);
// Make it into raw (1-dimensional bytes) memoryview
try {
if (!mv.isAnyContiguous()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.CANNOT_EXTRACT_RAW_BUFFER_FROM_NON_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.CANNOT_EXTRACT_RAW_BUFFER_FROM_NON_CONTIGUOUS);
}
int[] shape = new int[]{mv.getLength()};
int[] strides = new int[]{1};
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
index 4f7a0a56c9..61d8bd3c95 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleModuleBuiltins.java
@@ -173,7 +173,7 @@ static Object dump(VirtualFrame frame, @SuppressWarnings("unused") PythonModule
@Cached PPickler.DumpNode dumpNode,
@Cached PPickler.FlushToFileNode flushToFileNode,
@Cached PyObjectLookupAttr lookup,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PPickler pickler = PFactory.createPickler(language);
pickler.setProtocol(inliningTarget, raiseNode, protocol, fixImports);
pickler.setOutputStream(frame, inliningTarget, raiseNode, lookup, file);
@@ -201,7 +201,7 @@ static Object dump(VirtualFrame frame, @SuppressWarnings("unused") PythonModule
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached PPickler.DumpNode dumpNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PPickler pickler = PFactory.createPickler(language);
pickler.setProtocol(inliningTarget, raiseNode, protocol, fixImports);
pickler.setBufferCallback(inliningTarget, raiseNode, bufferCallback);
@@ -230,7 +230,7 @@ static Object load(VirtualFrame frame, @SuppressWarnings("unused") PythonModule
@Cached PUnpickler.LoadNode loadNode,
@Cached PyObjectLookupAttr lookup,
@Cached PyObjectGetIter getIter,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PUnpickler unpickler = PFactory.createUnpickler(language);
unpickler.setInputStream(frame, inliningTarget, raiseNode, lookup, file);
unpickler.setInputEncoding(encoding, errors);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleState.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleState.java
index 5f8e057b40..9d72cf64e9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleState.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleState.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -99,7 +99,7 @@ public abstract static class PickleStateInitNode extends Node {
@Specialization
void init(PickleState state,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectGetAttr getAttr,
@Cached PyCallableCheckNode callableCheck) {
PythonContext context = PythonContext.get(this);
@@ -111,28 +111,28 @@ void init(PickleState state,
if (dispatchTable instanceof PDict dispatchTableDict) {
state.dispatchTable = dispatchTableDict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg.dispatch_table", "dict", dispatchTable);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg.dispatch_table", "dict", dispatchTable);
}
var extensionRegistry = getAttr.execute(null, inliningTarget, copyreg, PickleUtils.T_ATTR_EXT_REGISTRY);
if (extensionRegistry instanceof PDict extensionRegistryDict) {
state.extensionRegistry = extensionRegistryDict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._extension_registry", "dict", extensionRegistry);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._extension_registry", "dict", extensionRegistry);
}
var invertedRegistry = getAttr.execute(null, inliningTarget, copyreg, PickleUtils.T_ATTR_INV_REGISTRY);
if (invertedRegistry instanceof PDict invertedRegistryDict) {
state.invertedRegistry = invertedRegistryDict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._inverted_registry", "dict", invertedRegistry);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._inverted_registry", "dict", invertedRegistry);
}
var extensionCache = getAttr.execute(null, inliningTarget, copyreg, PickleUtils.T_ATTR_EXT_CACHE);
if (extensionCache instanceof PDict extensionCacheDict) {
state.extensionCache = extensionCacheDict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._extension_cache", "dict", extensionCache);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "copyreg._extension_cache", "dict", extensionCache);
}
final Object codecs = importModule(PickleUtils.T_MOD_CODECS);
@@ -140,7 +140,7 @@ void init(PickleState state,
if (callableCheck.execute(inliningTarget, codecsEncode)) {
state.codecsEncode = codecsEncode;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "codecs.encode", "callable", codecsEncode);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, "codecs.encode", "callable", codecsEncode);
}
final Object functools = importModule(PickleUtils.T_MOD_FUNCTOOLS);
@@ -152,14 +152,14 @@ void init(PickleState state,
if (nameMapping2To3 instanceof PDict nameMapping2To3Dict) {
state.nameMapping2To3 = nameMapping2To3Dict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_NAME_MAPPING, "dict", nameMapping2To3);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_NAME_MAPPING, "dict", nameMapping2To3);
}
var importMapping2To3 = getAttr.execute(null, inliningTarget, compatPickle, PickleUtils.T_ATTR_IMPORT_MAPPING);
if (importMapping2To3 instanceof PDict importMapping2To3Dict) {
state.importMapping2To3 = importMapping2To3Dict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_IMPORT_MAPPING, "dict", importMapping2To3);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_IMPORT_MAPPING, "dict", importMapping2To3);
}
// ... and the 3.x -> 2.x mapping tables
@@ -167,13 +167,13 @@ void init(PickleState state,
if (nameMapping3To2 instanceof PDict nameMapping3To2Dict) {
state.nameMapping3To2 = nameMapping3To2Dict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_REVERSE_NAME_MAPPING, "dict", nameMapping3To2);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_REVERSE_NAME_MAPPING, "dict", nameMapping3To2);
}
var importMapping3To2 = getAttr.execute(null, inliningTarget, compatPickle, PickleUtils.T_ATTR_REVERSE_IMPORT_MAPPING);
if (importMapping3To2 instanceof PDict importMapping3To2Dict) {
state.importMapping3To2 = importMapping3To2Dict;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_REVERSE_IMPORT_MAPPING, "dict",
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.S_SHOULD_BE_A_S_NOT_A_P, PickleUtils.T_CP_REVERSE_IMPORT_MAPPING, "dict",
importMapping3To2);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
index 3efa079792..ba48abdb2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PickleUtils.java
@@ -287,11 +287,11 @@ public static double asciiBytesToDouble(byte[] bytes) {
}
@TruffleBoundary
- public static double asciiBytesToDouble(byte[] bytes, PRaiseNode raiseNode, PythonBuiltinClassType errorType) {
+ public static double asciiBytesToDouble(Node node, byte[] bytes, PythonBuiltinClassType errorType) {
try {
return asciiBytesToDouble(bytes);
} catch (NumberFormatException nfe) {
- throw raiseNode.raise(errorType);
+ throw PRaiseNode.raiseStatic(node, errorType);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
index 0fd7fffb30..fe48592c84 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerBuiltins.java
@@ -118,7 +118,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object init(VirtualFrame frame, PPickler self, Object file, int protocol, boolean fixImports, Object bufferCallback,
@Bind("this") Node inliningTarget,
@Cached PyObjectLookupAttr lookup,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.setProtocol(inliningTarget, raiseNode, protocol, fixImports);
self.setOutputStream(frame, inliningTarget, raiseNode, lookup, file);
self.setBufferCallback(inliningTarget, raiseNode, bufferCallback);
@@ -137,9 +137,9 @@ static Object dump(VirtualFrame frame, PPickler self, Object obj,
@Bind("this") Node inliningTarget,
@Cached PPickler.FlushToFileNode flushToFileNode,
@Cached PPickler.DumpNode dumpNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getWrite() == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.PicklingError, ErrorMessages.INIT_CALLED_WITH, "Pickler", self);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.PicklingError, ErrorMessages.INIT_CALLED_WITH, "Pickler", self);
}
self.clearBuffer();
dumpNode.execute(frame, self, obj);
@@ -175,10 +175,10 @@ public abstract static class PicklerDispatchTableNode extends PythonBuiltinNode
@Specialization(guards = "isNoValue(none)")
static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
final Object dispatchTable = self.getDispatchTable();
if (dispatchTable == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_ATTR_DISPATCH_TABLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, T_ATTR_DISPATCH_TABLE);
}
return dispatchTable;
}
@@ -186,10 +186,10 @@ static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
@Specialization(guards = "isDeleteMarker(marker)")
static Object delete(PPickler self, @SuppressWarnings("unused") Object marker,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
final Object dispatchTable = self.getDispatchTable();
if (dispatchTable == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_ATTR_DISPATCH_TABLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, T_ATTR_DISPATCH_TABLE);
}
self.setDispatchTable(null);
return PNone.NONE;
@@ -259,7 +259,7 @@ static Object set(VirtualFrame frame, PPickler self, Object obj,
@Cached HashingStorageGetIterator getIter,
@Cached HashingStorageIteratorNext iterNext,
@Cached HashingStorageIteratorValue iterValue,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
MemoTable newMemo;
if (obj instanceof PPicklerMemoProxy) {
final PPickler pickler = ((PPicklerMemoProxy) obj).getPickler();
@@ -271,7 +271,7 @@ static Object set(VirtualFrame frame, PPickler self, Object obj,
while (iterNext.execute(inliningTarget, dictStorage, it)) {
Object value = iterValue.execute(inliningTarget, dictStorage, it);
if (!(value instanceof PTuple) || sizeNode.execute(frame, inliningTarget, value) != 2) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.VALUES_MUST_BE_2TUPLES, "memo");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.VALUES_MUST_BE_2TUPLES, "memo");
}
SequenceStorage tupleStorage = getSequenceStorageNode.execute(inliningTarget, value);
int memoId = asSizeNode.executeExact(frame, inliningTarget, getItemNode.execute(frame, tupleStorage, 0));
@@ -279,7 +279,7 @@ static Object set(VirtualFrame frame, PPickler self, Object obj,
newMemo.set(memoObj, memoId);
}
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_OR_B_NOT_C, "memo", "PicklerMemoProxy", "dict", obj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_OR_B_NOT_C, "memo", "PicklerMemoProxy", "dict", obj);
}
self.setMemo(newMemo);
return PNone.NONE;
@@ -293,10 +293,10 @@ public abstract static class PicklerPersistentIdNode extends PythonBuiltinNode {
static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
final Object persFunc = self.getPersFunc();
if (persFunc == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_ID);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_ID);
}
return PickleUtils.reconstructMethod(language, persFunc, self.getPersFuncSelf());
}
@@ -305,12 +305,12 @@ static Object get(PPickler self, @SuppressWarnings("unused") PNone none,
static Object set(PPickler self, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyCallableCheckNode callableCheck,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (PGuards.isDeleteMarker(obj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATRIBUTE_DELETION_NOT_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATRIBUTE_DELETION_NOT_SUPPORTED);
}
if (!callableCheck.execute(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_CALLABLE, T_METHOD_PERSISTENT_ID, "one argument");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_CALLABLE, T_METHOD_PERSISTENT_ID, "one argument");
}
self.setPersFuncSelf(null);
self.setPersFunc(obj);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
index 74c5c9e9ec..7e68d843d9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java
@@ -111,6 +111,7 @@
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
public final class PicklerNodes {
@@ -164,30 +165,21 @@ abstract static class BasePickleNode extends Node {
@Child private HashingStorageIteratorNext hashingStorageItNext;
@Child private HashingStorageIteratorKey hashingStorageItKey;
@Child private HashingStorageIteratorValue hashingStorageItValue;
- @Child private PRaiseNode raiseNode;
-
- protected final PRaiseNode getRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- if (isAdoptable()) {
- raiseNode = insert(PRaiseNode.create());
- } else {
- raiseNode = PRaiseNode.getUncached();
- }
- }
- return raiseNode;
- }
+ private final BranchProfile errorProfile = BranchProfile.create();
protected PException raise(PythonBuiltinClassType type, TruffleString string) {
- return getRaiseNode().raise(type, string);
+ errorProfile.enter();
+ return PRaiseNode.raiseStatic(this, type, string);
}
protected PException raise(PythonBuiltinClassType exceptionType) {
- return getRaiseNode().raise(exceptionType);
+ errorProfile.enter();
+ return PRaiseNode.raiseStatic(this, exceptionType);
}
protected final PException raise(PythonBuiltinClassType type, TruffleString format, Object... arguments) {
- return getRaiseNode().raise(type, format, arguments);
+ errorProfile.enter();
+ return PRaiseNode.raiseStatic(this, type, format, arguments);
}
protected TruffleString.FromByteArrayNode ensureTsFromByteArray() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
index 051c0a9d16..27240d4785 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/UnpicklerBuiltins.java
@@ -113,7 +113,7 @@ static Object load(VirtualFrame frame, PUnpickler self, Object file, boolean fix
@Bind("this") Node inliningTarget,
@Cached PyObjectLookupAttr lookup,
@Cached PyObjectGetIter getIter,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.setInputStream(frame, inliningTarget, raiseNode, lookup, file);
self.setInputEncoding(encoding, errors);
self.setBuffers(frame, inliningTarget, getIter, buffers);
@@ -132,9 +132,9 @@ public abstract static class UnpicklerLoadNode extends PythonUnaryBuiltinNode {
static Object load(VirtualFrame frame, PUnpickler self,
@Bind("this") Node inliningTarget,
@Cached PUnpickler.LoadNode loadNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getRead() == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.UnpicklingError, ErrorMessages.INIT_CALLED_WITH, "Unpickler", self);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.UnpicklingError, ErrorMessages.INIT_CALLED_WITH, "Unpickler", self);
}
return loadNode.execute(frame, self);
}
@@ -164,10 +164,10 @@ public abstract static class UnpicklerPersistentLoadNode extends PythonBuiltinNo
static Object get(PUnpickler self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
final Object persFunc = self.getPersFunc();
if (persFunc == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_LOAD);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, T_METHOD_PERSISTENT_LOAD);
}
return PickleUtils.reconstructMethod(language, persFunc, self.getPersFuncSelf());
}
@@ -176,12 +176,12 @@ static Object get(PUnpickler self, @SuppressWarnings("unused") PNone none,
static Object set(PUnpickler self, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyCallableCheckNode callableCheck,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (PGuards.isDeleteMarker(obj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATRIBUTE_DELETION_NOT_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATRIBUTE_DELETION_NOT_SUPPORTED);
}
if (!callableCheck.execute(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_CALLABLE, T_METHOD_PERSISTENT_LOAD, "one argument");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_CALLABLE, T_METHOD_PERSISTENT_LOAD, "one argument");
}
self.setPersFuncSelf(null);
self.setPersFunc(obj);
@@ -207,7 +207,7 @@ static Object set(VirtualFrame frame, PUnpickler self, Object obj,
@Cached HashingStorageIteratorNext storageIterNext,
@Cached HashingStorageIteratorKey storageIterKey,
@Cached HashingStorageIteratorValue storageIterValue,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (obj instanceof PUnpicklerMemoProxy) {
final PUnpickler unpickler = ((PUnpicklerMemoProxy) obj).getUnpickler();
self.setMemo(unpickler.getMemoCopy());
@@ -219,16 +219,16 @@ static Object set(VirtualFrame frame, PUnpickler self, Object obj,
Object key = storageIterKey.execute(inliningTarget, dictStorage, it);
Object value = storageIterValue.execute(inliningTarget, dictStorage, it);
if (!PGuards.canBeInteger(key)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.MEMO_KEY_MUST_BE_INT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MEMO_KEY_MUST_BE_INT);
}
final int idx = asSizeNode.executeExact(frame, inliningTarget, key);
if (idx < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.MEMO_KEY_MUST_BE_POS_INT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.MEMO_KEY_MUST_BE_POS_INT);
}
self.memoPut(idx, value);
}
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_OR_B_NOT_C, "memo", "UnpicklerMemoProxy", "dict", obj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_MUST_BE_A_OR_B_NOT_C, "memo", "UnpicklerMemoProxy", "dict", obj);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
index c68a766994..2cd7ea0328 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibCompObject.java
@@ -242,12 +242,12 @@ private static int gzipHeader(byte[] bytes, Node node) {
int idx = 0;
// Check header magic
if (readShort(bytes, idx, crc) != GZIP_MAGIC) {
- throw PRaiseNode.raiseUncached(node, ZLibError, ErrorMessages.NOT_IN_GZIP_FORMAT);
+ throw PRaiseNode.raiseStatic(node, ZLibError, ErrorMessages.NOT_IN_GZIP_FORMAT);
}
idx += 2;
// Check compression method
if (getValue(bytes[idx++], crc) != 8) {
- throw PRaiseNode.raiseUncached(node, ZLibError, ErrorMessages.UNSUPPORTED_COMPRESSION_METHOD);
+ throw PRaiseNode.raiseStatic(node, ZLibError, ErrorMessages.UNSUPPORTED_COMPRESSION_METHOD);
}
// Read flags
int flg = getValue(bytes[idx++], crc);
@@ -278,7 +278,7 @@ private static int gzipHeader(byte[] bytes, Node node) {
if ((flg & FHCRC) == FHCRC) {
int v = (int) crc.getValue() & 0xffff;
if (readShort(bytes, idx, crc) != v) {
- throw PRaiseNode.raiseUncached(node, ZLibError, ErrorMessages.CORRUPT_GZIP_HEADER);
+ throw PRaiseNode.raiseStatic(node, ZLibError, ErrorMessages.CORRUPT_GZIP_HEADER);
}
idx += 2;
n += 2;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
index eaadef3527..6eae81e755 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
@@ -310,8 +310,8 @@ static byte[] doMemView(VirtualFrame frame, PMemoryView bytesLike,
@Fallback
static byte[] error(@SuppressWarnings("unused") VirtualFrame frame, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, value);
}
@ClinicConverterFactory
@@ -387,8 +387,8 @@ static long doJavaObject(VirtualFrame frame, Object data, int value,
@Fallback
static long error(Object data, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, EXPECTED_BYTESLIKE_GOT_P, data);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, EXPECTED_BYTESLIKE_GOT_P, data);
}
long nativeCrc32(byte[] bytes, int len, int value,
@@ -576,10 +576,10 @@ static PBytes decompress(VirtualFrame frame, Object buffer, int wbits, int bufsi
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached DecompressInnerNode innerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (bufsize < 0) {
- throw raiseNode.get(inliningTarget).raise(ZLibError, ErrorMessages.MUST_BE_NON_NEGATIVE, "bufsize");
+ throw raiseNode.raise(inliningTarget, ZLibError, ErrorMessages.MUST_BE_NON_NEGATIVE, "bufsize");
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
@@ -622,14 +622,14 @@ static byte[] doJava(Node inliningTarget, byte[] bytes, int length, int wbits, i
while (!decompresser.finished()) {
int howmany = decompresser.inflate(resultArray);
if (howmany == 0 && decompresser.needsInput()) {
- throw PRaiseNode.raiseUncached(inliningTarget, ZLibError, ErrorMessages.ERROR_5_WHILE_DECOMPRESSING);
+ throw PRaiseNode.raiseStatic(inliningTarget, ZLibError, ErrorMessages.ERROR_5_WHILE_DECOMPRESSING);
}
baos.write(resultArray, 0, howmany);
}
decompresser.end();
return baos.toByteArray();
} catch (DataFormatException e) {
- throw PRaiseNode.raiseUncached(inliningTarget, ZLibError, ErrorMessages.WHILE_PREPARING_TO_S_DATA, "decompress");
+ throw PRaiseNode.raiseStatic(inliningTarget, ZLibError, ErrorMessages.WHILE_PREPARING_TO_S_DATA, "decompress");
}
}
}
@@ -707,15 +707,15 @@ static Object doJava(int level, @SuppressWarnings("unused") int method, int wbit
@SuppressWarnings("unused")
@Specialization(guards = {"method == DEFLATED", "!useNative()", "!isValidWBitRange(wbits)"})
static Object invalid(int level, int method, int wbits, int memLevel, int strategy, byte[] zdict,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_INITIALIZATION_OPTION);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_INITIALIZATION_OPTION);
}
@SuppressWarnings("unused")
@Specialization(guards = {"method != DEFLATED"})
static Object methodErr(int level, int method, int wbits, int memLevel, int strategy, byte[] zdict,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFLATED_ALLOWED_AS_METHOD, DEFLATED, method);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ONLY_DEFLATED_ALLOWED_AS_METHOD, DEFLATED, method);
}
}
@@ -782,8 +782,8 @@ static Object doJava(int wbits, byte[] zdict) {
@SuppressWarnings("unused")
@Specialization(guards = {"!useNative()", "!isValidWBitRange(wbits)"})
static Object invalid(int wbits, byte[] zdict,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_INITIALIZATION_OPTION);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_INITIALIZATION_OPTION);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
index 7c35370221..d3093d5d81 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java
@@ -109,10 +109,10 @@ static PBytes compress(VirtualFrame frame, ZLibCompObject self, Object buffer,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached CompressInnerNode innerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (!self.isInitialized()) {
- throw raiseNode.get(inliningTarget).raise(ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while compressing data", "inconsistent stream state");
+ throw raiseNode.raise(inliningTarget, ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while compressing data", "inconsistent stream state");
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
@@ -183,15 +183,15 @@ static Object doJava(ZLibCompObject.JavaZlibCompObject self) {
@SuppressWarnings("unused")
@Specialization(guards = {"self.isInitialized()", "!self.canCopy()"})
static PNone error(ZLibCompObject.JavaZlibCompObject self,
- @Cached.Shared @Cached(inline = false) PRaiseNode raise) {
- throw raise.raise(NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
}
@SuppressWarnings("unused")
@Specialization(guards = "!self.isInitialized()")
static PNone error(ZLibCompObject self,
- @Cached.Shared @Cached(inline = false) PRaiseNode raise) {
- throw raise.raise(ValueError, ErrorMessages.INCONSISTENT_STREAM_STATE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.INCONSISTENT_STREAM_STATE);
}
}
@@ -283,8 +283,8 @@ static PBytes doit(ZLibCompObject.JavaZlibCompObject self, int mode,
@SuppressWarnings("unused")
@Specialization(guards = "!self.isInitialized()")
static PNone error(ZLibCompObject self, int mode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while compressing data", "inconsistent stream state");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while compressing data", "inconsistent stream state");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
index eec33b9332..b43e5fd4a0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibDecompressBuiltins.java
@@ -115,13 +115,13 @@ static PBytes decompress(VirtualFrame frame, ZLibCompObject self, Object buffer,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached DecompressInnerNode innerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (!self.isInitialized()) {
- throw raiseNode.get(inliningTarget).raise(ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while decompressing data", "inconsistent stream state");
+ throw raiseNode.raise(inliningTarget, ZLibError, ERROR_D_S_S, Z_STREAM_ERROR, "while decompressing data", "inconsistent stream state");
}
if (maxLength < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_MUST_BE_GREATER_THAN_ZERO, "max_length");
+ throw raiseNode.raise(inliningTarget, ValueError, S_MUST_BE_GREATER_THAN_ZERO, "max_length");
}
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
int len = bufferLib.getBufferLength(buffer);
@@ -188,15 +188,15 @@ static Object doJava(Node inliningTarget, ZLibCompObject.JavaZlibCompObject self
@SuppressWarnings("unused")
@Specialization(guards = {"self.isInitialized()", "!self.canCopy()"})
static PNone error(ZLibCompObject.JavaZlibCompObject self,
- @Cached.Shared @Cached(inline = false) PRaiseNode raise) {
- throw raise.raise(NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, toTruffleStringUncached("JDK based zlib doesn't support copying"));
}
@SuppressWarnings("unused")
@Specialization(guards = "!self.isInitialized()")
static PNone error(ZLibCompObject self,
- @Cached.Shared @Cached(inline = false) PRaiseNode raise) {
- throw raise.raise(ValueError, INCONSISTENT_STREAM_STATE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INCONSISTENT_STREAM_STATE);
}
}
@@ -295,8 +295,8 @@ static PBytes empty(ZLibCompObject.NativeZlibCompObject self, int length,
@SuppressWarnings("unused")
@Specialization(guards = "length <= 0")
static PBytes error(ZLibCompObject self, int length,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, S_MUST_BE_GREATER_THAN_ZERO, "length");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, S_MUST_BE_GREATER_THAN_ZERO, "length");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
index 2b4a974768..65fce92816 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java
@@ -88,6 +88,7 @@
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -243,6 +244,7 @@ public abstract static class ZlibNativeErrorMsg extends Node {
@SuppressWarnings("unused")
@Specialization(guards = "err == Z_VERSION_ERROR")
static void doVersionError(Object zst, int err, TruffleString msg, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("r") @Cached PRaiseNode raise) {
/*
@@ -250,11 +252,12 @@ static void doVersionError(Object zst, int err, TruffleString msg, NFIZlibSuppor
* first, before looking at comp->zst.msg.
*/
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ZLibError, ERROR_D_S_S, err, msg, LIBRARY_VERSION_MISMATCH);
+ throw raise.raise(inliningTarget, ZLibError, ERROR_D_S_S, err, msg, LIBRARY_VERSION_MISMATCH);
}
@Specialization(guards = "err != Z_VERSION_ERROR")
static void doError(Object zst, int err, TruffleString msg, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Exclusive @Cached NativeLibrary.InvokeNativeFunction hasStreamErrorMsg,
@@ -277,9 +280,9 @@ static void doError(Object zst, int err, TruffleString msg, NFIZlibSupport zlibS
}
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
if (zmsg == null) {
- throw raise.raise(ZLibError, ERROR_D_S, err, msg);
+ throw raise.raise(inliningTarget, ZLibError, ERROR_D_S, err, msg);
} else {
- throw raise.raise(ZLibError, ERROR_D_S_S, err, msg, zmsg);
+ throw raise.raise(inliningTarget, ZLibError, ERROR_D_S_S, err, msg, zmsg);
}
}
}
@@ -293,68 +296,72 @@ public abstract static class ZlibFunctionNativeErrorHandling extends Node {
@Specialization(guards = "function == DEFLATE_INIT_ERROR")
static void deflateInitError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, OUT_OF_MEMORY_WHILE_S_DATA, "compressing");
+ throw raise.raise(inliningTarget, MemoryError, OUT_OF_MEMORY_WHILE_S_DATA, "compressing");
}
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ZLibError, ErrorMessages.BAD_COMPRESSION_LEVEL);
+ throw raise.raise(inliningTarget, ZLibError, ErrorMessages.BAD_COMPRESSION_LEVEL);
}
zlibError.execute(zst, err, formatNode.format(WHILE_S_DATA, "compressing"), zlibSupport, deallocate);
}
@Specialization(guards = "function == DEFLATE_OBJ_ERROR")
static void deflateObjInitError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "compression");
+ throw raise.raise(inliningTarget, MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "compression");
}
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ValueError, INVALID_INITIALIZATION_OPTION);
+ throw raise.raise(inliningTarget, ValueError, INVALID_INITIALIZATION_OPTION);
}
zlibError.execute(zst, err, formatNode.format(WHILE_CREATING_S_OBJECT, "compression"), zlibSupport, deallocate);
}
@Specialization(guards = "function == DEFLATE_COPY_ERROR")
static void deflateCopyError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "compression");
+ throw raise.raise(inliningTarget, MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "compression");
}
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ValueError, INCONSISTENT_STREAM_STATE);
+ throw raise.raise(inliningTarget, ValueError, INCONSISTENT_STREAM_STATE);
}
zlibError.execute(zst, err, formatNode.format(WHILE_COPYING_S_OBJECT, "compression"), zlibSupport, deallocate);
}
@Specialization(guards = "function == INFLATE_COPY_ERROR")
static void inflateCopyError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "decompression");
+ throw raise.raise(inliningTarget, MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "decompression");
}
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ValueError, INCONSISTENT_STREAM_STATE);
+ throw raise.raise(inliningTarget, ValueError, INCONSISTENT_STREAM_STATE);
}
zlibError.execute(zst, err, formatNode.format(WHILE_COPYING_S_OBJECT, "compression"), zlibSupport, deallocate);
}
@@ -362,25 +369,27 @@ static void inflateCopyError(Object zst, @SuppressWarnings("unused") int functio
@SuppressWarnings("unused")
@Specialization(guards = "function == DEFLATE_DICT_ERROR")
static void deflateDictError(Object zst, int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("r") @Cached PRaiseNode raise) {
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ValueError, INVALID_DICTIONARY);
+ throw raise.raise(inliningTarget, ValueError, INVALID_DICTIONARY);
}
- throw raise.raise(ValueError, ErrorMessages.DEFLATED_SET_DICT);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.DEFLATED_SET_DICT);
}
@Specialization(guards = "function == INFLATE_INIT_ERROR")
static void inflateInitError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, OUT_OF_MEMORY_WHILE_S_DATA, "decompressing");
+ throw raise.raise(inliningTarget, MemoryError, OUT_OF_MEMORY_WHILE_S_DATA, "decompressing");
}
zlibError.execute(zst, err, formatNode.format(WHILE_PREPARING_TO_S_DATA, "decompress"), zlibSupport, deallocate);
@@ -388,17 +397,18 @@ static void inflateInitError(Object zst, @SuppressWarnings("unused") int functio
@Specialization(guards = "function == INFLATE_OBJ_ERROR")
static void inflateObjInitError(Object zst, @SuppressWarnings("unused") int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("r") @Cached PRaiseNode raise,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("err") @Cached ZlibNativeErrorMsg zlibError,
@Shared("format") @Cached SimpleTruffleStringFormatNode formatNode) {
if (err == Z_MEM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "decompression");
+ throw raise.raise(inliningTarget, MemoryError, CANT_ALLOCATE_MEMORY_FOR_S_OBJECT, "decompression");
}
if (err == Z_STREAM_ERROR) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(ValueError, INVALID_INITIALIZATION_OPTION);
+ throw raise.raise(inliningTarget, ValueError, INVALID_INITIALIZATION_OPTION);
}
zlibError.execute(zst, err, formatNode.format(WHILE_CREATING_S_OBJECT, "decompression"), zlibSupport, deallocate);
}
@@ -452,16 +462,17 @@ static void inflateFlushError(Object zst, @SuppressWarnings("unused") int functi
@SuppressWarnings("unused")
@Specialization(guards = "function == MEMORY_ERROR")
static void memError(Object zst, int function, int err, NFIZlibSupport zlibSupport, boolean deallocate,
+ @Bind("this") Node inliningTarget,
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@Shared("r") @Cached PRaiseNode raise) {
deallocateStream(zst, zlibSupport, deallocateStream, deallocate);
- throw raise.raise(MemoryError);
+ throw raise.raise(inliningTarget, MemoryError);
}
@SuppressWarnings("unused")
@Fallback
void fallback(Object zst, int function, int err, NFIZlibSupport zlibSupport, boolean deallocate) {
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.UNHANDLED_ERROR);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.UNHANDLED_ERROR);
}
}
@@ -584,11 +595,11 @@ private static byte[] createByteArray(ZLibCompObject.JavaZlibCompObject self, In
// we inflate again with a dictionary
bytesWritten = inflater.inflate(result, 0, len);
} else {
- throw PRaiseNode.raiseUncached(nodeForRaise, ZLibError, WHILE_SETTING_ZDICT);
+ throw PRaiseNode.raiseStatic(nodeForRaise, ZLibError, WHILE_SETTING_ZDICT);
}
}
} catch (DataFormatException e) {
- throw PRaiseNode.raiseUncached(nodeForRaise, ZLibError, e);
+ throw PRaiseNode.raiseStatic(nodeForRaise, ZLibError, e);
}
baos.write(result, 0, bytesWritten);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
index 6152dda06f..1cf346883a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java
@@ -291,7 +291,7 @@ public boolean hasArrayElements(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetObjectSlotsNode getSlotsNode,
@Exclusive @Cached PySequenceCheckNode sequenceCheck,
@Exclusive @Cached GilNode gil) {
@@ -406,7 +406,7 @@ public long getArraySize(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaLongExactNode toLongNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
try {
@@ -441,7 +441,7 @@ public boolean isArrayElementReadable(long idx,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PySequenceSizeNode sequenceSizeNode,
@Shared("getBehavior") @Cached GetInteropBehaviorNode getBehavior,
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
@@ -471,7 +471,7 @@ public boolean isArrayElementModifiable(long idx,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PySequenceSizeNode sequenceSizeNode,
@Shared("getBehavior") @Cached GetInteropBehaviorNode getBehavior,
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
@@ -503,7 +503,7 @@ public boolean isArrayElementInsertable(long idx,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PySequenceSizeNode sequenceSizeNode,
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -533,7 +533,7 @@ public boolean isArrayElementRemovable(long idx,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PySequenceSizeNode sequenceSizeNode,
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -659,7 +659,7 @@ public boolean isExecutable(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached PyCallableCheckNode callableCheck,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
@@ -852,7 +852,7 @@ public boolean isDate(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -878,7 +878,7 @@ public LocalDate asDate(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode castToIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
// GR-44020: make shared:
@@ -893,7 +893,7 @@ public LocalDate asDate(
Object value = getValue.execute(inliningTarget, behavior, method, this);
if (value instanceof PTuple tuple) {
if (pyTupleSizeNode.execute(inliningTarget, tuple) != 3) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_MUST_BE_A_S_TUPLE, "return value", "3");
+ throw raiseNode.raise(inliningTarget, ValueError, S_MUST_BE_A_S_TUPLE, "return value", "3");
}
SequenceStorage storage = tuple.getSequenceStorage();
int year = castToIntNode.executeWithThrowSystemError(inliningTarget, getItemNode.execute(inliningTarget, storage, 0), raiseNode);
@@ -902,10 +902,10 @@ public LocalDate asDate(
try {
return createLocalDate(year, month, day);
} catch (Exception e) {
- throw raiseNode.get(inliningTarget).raise(SystemError, e);
+ throw raiseNode.raise(inliningTarget, SystemError, e);
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
}
} else {
@@ -925,7 +925,7 @@ public boolean isTime(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -951,7 +951,7 @@ public LocalTime asTime(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode castToIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
// GR-44020: make shared:
@@ -966,7 +966,7 @@ public LocalTime asTime(
Object value = getValue.execute(inliningTarget, behavior, method, this);
if (value instanceof PTuple tuple) {
if (pyTupleSizeNode.execute(inliningTarget, tuple) != 4) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_MUST_BE_A_S_TUPLE, "return value", "4");
+ throw raiseNode.raise(inliningTarget, ValueError, S_MUST_BE_A_S_TUPLE, "return value", "4");
}
SequenceStorage storage = tuple.getSequenceStorage();
int hour = castToIntNode.executeWithThrowSystemError(inliningTarget, getItemNode.execute(inliningTarget, storage, 0), raiseNode);
@@ -976,10 +976,10 @@ public LocalTime asTime(
try {
return createLocalTime(hour, min, sec, micro);
} catch (Exception e) {
- throw raiseNode.get(inliningTarget).raise(SystemError, e);
+ throw raiseNode.raise(inliningTarget, SystemError, e);
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
}
} else {
throw UnsupportedMessageException.create();
@@ -999,7 +999,7 @@ public boolean isTimeZone(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1025,7 +1025,7 @@ public ZoneId asTimeZone(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode castToIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
@@ -1045,10 +1045,10 @@ public ZoneId asTimeZone(
return createZoneId(utcDeltaInSeconds);
}
} catch (Exception e) {
- throw raiseNode.get(inliningTarget).raise(SystemError, e);
+ throw raiseNode.raise(inliningTarget, SystemError, e);
}
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "str or int", value);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "str or int", value);
}
} else {
throw UnsupportedMessageException.create();
@@ -1087,7 +1087,7 @@ public boolean isDuration(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1113,7 +1113,7 @@ public Duration asDuration(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaLongExactNode castToLongNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
// GR-44020: make shared:
@@ -1128,7 +1128,7 @@ public Duration asDuration(
Object value = getValue.execute(inliningTarget, behavior, method, this);
if (value instanceof PTuple tuple) {
if (pyTupleSizeNode.execute(inliningTarget, tuple) != 2) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_MUST_BE_A_S_TUPLE, "return value", "2");
+ throw raiseNode.raise(inliningTarget, ValueError, S_MUST_BE_A_S_TUPLE, "return value", "2");
}
SequenceStorage storage = tuple.getSequenceStorage();
long sec = castToLongNode.executeWithThrowSystemError(inliningTarget, getItemNode.execute(inliningTarget, storage, 0), raiseNode);
@@ -1136,10 +1136,10 @@ public Duration asDuration(
try {
return createDuration(sec, nano);
} catch (Exception e) {
- throw raiseNode.get(inliningTarget).raise(SystemError, e);
+ throw raiseNode.raise(inliningTarget, SystemError, e);
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "return value", "tuple", value);
}
} else {
throw UnsupportedMessageException.create();
@@ -1672,7 +1672,7 @@ public boolean hasIterator(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("getClass") @Cached(inline = false) GetClassNode getClassNode,
@Cached(parameters = "Iter") LookupCallableSlotInMRONode lookupIter,
// GR-44020: make shared:
@@ -1727,7 +1727,7 @@ public boolean isIterator(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("getClass") @Cached(inline = false) GetClassNode getClassNode,
@Cached(parameters = "Next") LookupCallableSlotInMRONode lookupNext,
// GR-44020: make shared:
@@ -1755,7 +1755,7 @@ public boolean hasIteratorNextElement(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetNextNode getNextNode,
@Exclusive @Cached IsBuiltinObjectProfile exceptionProfile,
@Exclusive @Cached GilNode gil,
@@ -1830,7 +1830,7 @@ public boolean isBoolean(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1855,7 +1855,7 @@ public boolean isNumber(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1880,7 +1880,7 @@ public boolean isString(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1905,7 +1905,7 @@ public boolean fitsInByte(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1930,7 +1930,7 @@ public boolean fitsInShort(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1955,7 +1955,7 @@ public boolean fitsInInt(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -1980,7 +1980,7 @@ public boolean fitsInLong(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2005,7 +2005,7 @@ public boolean fitsInFloat(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2030,7 +2030,7 @@ public boolean fitsInDouble(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2055,7 +2055,7 @@ public boolean fitsInBigInteger(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2080,7 +2080,7 @@ public boolean asBoolean(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2105,7 +2105,7 @@ public byte asByte(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaByteNode toByteNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2130,7 +2130,7 @@ public short asShort(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaShortNode toShortNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2155,7 +2155,7 @@ public int asInt(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2180,7 +2180,7 @@ public long asLong(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaLongExactNode toLongNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2205,7 +2205,7 @@ public float asFloat(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaDoubleNode toDoubleNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2230,7 +2230,7 @@ public double asDouble(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaDoubleNode toDoubleNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2277,7 +2277,7 @@ public String asString(@Bind("$node") Node inliningTarget,
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
@Cached CastToJavaStringNode toStringNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2302,7 +2302,7 @@ public boolean hasHashEntries(@Bind("$node") Node inliningTarget,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2328,7 +2328,7 @@ public long getHashSize(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaLongExactNode toLongNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
@@ -2442,7 +2442,7 @@ public boolean isHashEntryReadable(Object key,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2468,7 +2468,7 @@ public boolean isHashEntryRemovable(Object key,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
// GR-44020: make shared:
@Exclusive @Cached GilNode gil) {
boolean mustRelease = gil.acquire();
@@ -2514,7 +2514,7 @@ public boolean isHashEntryModifiable(Object key,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("getBehavior") @Cached GetInteropBehaviorNode getBehavior,
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
// GR-44020: make shared:
@@ -2540,7 +2540,7 @@ public boolean isHashEntryInsertable(Object key,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaBooleanNode toBooleanNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("getBehavior") @Cached GetInteropBehaviorNode getBehavior,
@Shared("getValue") @Cached GetInteropBehaviorValueNode getValue,
// GR-44020: make shared:
@@ -2611,7 +2611,7 @@ public byte readBufferByte(long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2627,7 +2627,7 @@ public void writeBufferByte(long byteOffset, byte value, @Bind("$node") Node inl
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2644,7 +2644,7 @@ public short readBufferShort(ByteOrder order, long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2660,7 +2660,7 @@ public void writeBufferShort(ByteOrder order, long byteOffset, short value, @Bin
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2677,7 +2677,7 @@ public int readBufferInt(ByteOrder order, long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2693,7 +2693,7 @@ public void writeBufferInt(ByteOrder order, long byteOffset, int value, @Bind("$
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2710,7 +2710,7 @@ public long readBufferLong(ByteOrder order, long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2726,7 +2726,7 @@ public void writeBufferLong(ByteOrder order, long byteOffset, long value, @Bind(
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2743,7 +2743,7 @@ public float readBufferFloat(ByteOrder order, long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2760,7 +2760,7 @@ public void writeBufferFloat(ByteOrder order, long byteOffset, float value,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2777,7 +2777,7 @@ public double readBufferDouble(ByteOrder order, long byteOffset,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2794,7 +2794,7 @@ public void writeBufferDouble(ByteOrder order, long byteOffset, double value,
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
int offset = toIntNode.executeWithThrow(inliningTarget, byteOffset, raiseNode, PythonBuiltinClassType.OverflowError);
@@ -2811,7 +2811,7 @@ public void readBuffer(long byteOffset, byte[] destination, int destinationOffse
// GR-44020: make shared:
@Exclusive @Cached CastToJavaIntExactNode toIntNode,
// GR-44020: make shared:
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Shared("bufferLib") @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (bufferLib.isBuffer(this)) {
if (length < 0 || (destination.length - destinationOffset > length)) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
index 0710f48b4d..24deb2c7e2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
@@ -108,7 +108,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.builtins.ListNodes;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
@@ -189,21 +188,21 @@ Object concat(PArray left, PArray right,
return newArray;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, MemoryError);
+ throw PRaiseNode.raiseStatic(this, MemoryError);
}
}
@Specialization(guards = "left.getFormat() != right.getFormat()")
@SuppressWarnings("unused")
static Object error(PArray left, PArray right,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
@Fallback
static Object error(@SuppressWarnings("unused") Object left, Object right,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CAN_ONLY_APPEND_ARRAY_TO_ARRAY, right);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_APPEND_ARRAY_TO_ARRAY, right);
}
}
@@ -219,8 +218,8 @@ static Object concat(VirtualFrame frame, PArray left, PArray right,
@Fallback
static Object error(@SuppressWarnings("unused") Object left, Object right,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CAN_ONLY_EXTEND_ARRAY_WITH_ARRAY, right);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_EXTEND_ARRAY_WITH_ARRAY, right);
}
}
@@ -250,7 +249,7 @@ static PArray concat(PArray self, int valueIn,
return newArray;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -270,7 +269,7 @@ static Object concat(PArray self, int value,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Cached ArrayNodes.SetLengthNode setLengthNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int newLength = Math.max(PythonUtils.multiplyExact(self.getLength(), value), 0);
if (newLength != self.getLength()) {
@@ -285,7 +284,7 @@ static Object concat(PArray self, int value,
return self;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -359,8 +358,8 @@ static Object eq(PArray left, Object right, ComparisonOp op) {
@Specialization(guards = "!isArray(left)")
@SuppressWarnings("unused")
static Object error(Object left, Object right, ComparisonOp op,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_ARRAY + "." + J_ARRAY, left);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_ARRAY + "." + J_ARRAY, left);
}
}
@@ -438,8 +437,8 @@ static Object cmp(PArray left, Object right, ComparisonOp op, BinaryComparisonNo
@Specialization(guards = "!isArray(left)")
@SuppressWarnings("unused")
static Object error(Object left, Object right, ComparisonOp op, BinaryComparisonNode compareNode,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_ARRAY + "." + J_ARRAY, left);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_ARRAY + "." + J_ARRAY, left);
}
}
@@ -562,12 +561,12 @@ abstract static class SqItemNode extends SqItemBuiltinNode {
@Specialization
static Object doIt(PArray self, int index,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached ArrayNodes.GetValueNode getValueNode) {
return getItem(inliningTarget, self, index, raiseNode, getValueNode);
}
- private static Object getItem(Node inliningTarget, PArray self, int index, PRaiseNode.Lazy raiseNode, GetValueNode getValueNode) {
+ private static Object getItem(Node inliningTarget, PArray self, int index, PRaiseNode raiseNode, GetValueNode getValueNode) {
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_OUT_OF_BOUNDS, index, self.getLength());
return getValueNode.execute(inliningTarget, self, index);
}
@@ -580,7 +579,7 @@ abstract static class MpSubscriptNode extends MpSubscriptBuiltinNode {
static Object doIndex(VirtualFrame frame, PArray self, Object idx,
@Bind("this") Node inliningTarget,
@Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyNumberAsSizeNode numberAsSizeNode,
@Exclusive @Cached InlinedConditionProfile negativeIndexProfile,
@Cached ArrayNodes.GetValueNode getValueNode) {
@@ -625,8 +624,8 @@ static Object doSlice(PArray self, PSlice slice,
}
@InliningCutoff
- private static PException raiseNonIntIndex(Node inliningTarget, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARRAY_INDICES_MUST_BE_INTS);
+ private static PException raiseNonIntIndex(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARRAY_INDICES_MUST_BE_INTS);
}
}
@@ -638,7 +637,7 @@ abstract static class SetItemNode extends SqAssItemBuiltinNode {
static void setitem(VirtualFrame frame, PArray self, int index, Object value,
@Bind("this") Node inliningTarget,
@Cached ArrayNodes.PutValueNode putValueNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
putValueNode.execute(frame, inliningTarget, self, index, value);
}
@@ -647,7 +646,7 @@ static void setitem(VirtualFrame frame, PArray self, int index, Object value,
static void delitem(PArray self, int index, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
@Cached DeleteArraySliceNode deleteSliceNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
self.checkCanResize(inliningTarget, raiseNode);
deleteSliceNode.execute(inliningTarget, self, index, 1);
@@ -674,7 +673,7 @@ static void delitem(VirtualFrame frame, PArray self, Object idx, @SuppressWarnin
@Shared @Cached PyNumberIndexNode indexNode,
@Shared @Cached("forArrayAssign()") NormalizeIndexNode normalizeIndexNode,
@Shared @Cached DeleteArraySliceNode deleteSliceNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
int index = normalizeIndexNode.execute(indexNode.execute(frame, inliningTarget, idx), self.getLength());
deleteSliceNode.execute(inliningTarget, self, index, 1);
@@ -701,7 +700,7 @@ static void setitem(PArray self, PSlice slice, Object other,
@Shared @Cached DeleteArraySliceNode deleteSliceNode,
@Cached ArrayNodes.ShiftNode shiftNode,
@Cached ArrayNodes.SetLengthNode setLengthNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int length = self.getLength();
PSlice.SliceInfo sliceInfo = adjustIndices.execute(inliningTarget, length, sliceUnpack.execute(inliningTarget, slice));
int start = sliceInfo.start;
@@ -715,7 +714,7 @@ static void setitem(PArray self, PSlice slice, Object other,
if (other instanceof PArray otherArray) {
hasOtherProfile.enter(inliningTarget);
if (self.getFormat() != otherArray.getFormat()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
sourceBuffer = otherArray.getBuffer();
needed = otherArray.getLength();
@@ -731,7 +730,7 @@ static void setitem(PArray self, PSlice slice, Object other,
needed = 0;
} else {
otherTypeErrorProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_ASSIGN_ARRAY, other);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_ASSIGN_ARRAY, other);
}
if (step == 1) {
simpleStepProfile.enter(inliningTarget);
@@ -772,7 +771,7 @@ static void setitem(PArray self, PSlice slice, Object other,
}
} else {
wrongLengthProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ATTEMPT_ASSIGN_ARRAY_OF_SIZE, needed, sliceLength);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ATTEMPT_ASSIGN_ARRAY_OF_SIZE, needed, sliceLength);
}
}
}
@@ -883,7 +882,7 @@ static Object bufferinfo(PArray self,
nativePointer = lib.asPointer(nativePointer);
} catch (UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
return PFactory.createTuple(language, new Object[]{nativePointer, self.getLength()});
@@ -899,7 +898,7 @@ static Object append(VirtualFrame frame, PArray self, Object value,
@Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Cached ArrayNodes.SetLengthNode setLengthNode,
@Cached ArrayNodes.PutValueNode putValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int index = self.getLength();
int newLength = PythonUtils.addExact(index, 1);
@@ -910,7 +909,7 @@ static Object append(VirtualFrame frame, PArray self, Object value,
return PNone.NONE;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
}
@@ -924,7 +923,7 @@ static Object extend(PArray self, PArray value,
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Exclusive @Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Exclusive @Cached ArrayNodes.SetLengthNode setLengthNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
int newLength = PythonUtils.addExact(self.getLength(), value.getLength());
if (newLength != self.getLength()) {
@@ -937,7 +936,7 @@ static Object extend(PArray self, PArray value,
return PNone.NONE;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@@ -949,7 +948,7 @@ static Object extend(VirtualFrame frame, PArray self, PSequence value,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
@Exclusive @Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Exclusive @Cached ArrayNodes.SetLengthNode setLengthNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, value);
int storageLength = storage.length();
try {
@@ -960,7 +959,7 @@ static Object extend(VirtualFrame frame, PArray self, PSequence value,
}
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
int length = self.getLength();
for (int i = 0; i < storageLength; i++) {
@@ -982,7 +981,7 @@ static Object extend(VirtualFrame frame, PArray self, Object value,
@Cached IsBuiltinObjectProfile errorProfile,
@Exclusive @Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Exclusive @Cached ArrayNodes.SetLengthNode setLengthNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object iter = getIter.execute(frame, inliningTarget, value);
int length = self.getLength();
while (true) {
@@ -1001,7 +1000,7 @@ static Object extend(VirtualFrame frame, PArray self, Object value,
ensureCapacityNode.execute(inliningTarget, self, length);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
putValueNode.execute(frame, inliningTarget, self, length - 1, nextValue);
setLengthNode.execute(inliningTarget, self, length);
@@ -1013,10 +1012,10 @@ static Object extend(VirtualFrame frame, PArray self, Object value,
@Specialization(guards = "self.getFormat() != value.getFormat()")
@SuppressWarnings("unused")
static Object error(PArray self, PArray value,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// CPython allows extending an array with an arbitrary iterable. Except a differently
// formatted array. Weird
- throw raiseNode.raise(TypeError, ErrorMessages.CAN_ONLY_EXTEND_WITH_ARRAY_OF_SAME_KIND);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_EXTEND_WITH_ARRAY_OF_SAME_KIND);
}
}
@@ -1031,7 +1030,7 @@ static Object insert(VirtualFrame frame, PArray self, int inputIndex, Object val
@Cached ArrayNodes.CheckValueNode checkValueNode,
@Cached ArrayNodes.PutValueNode putValueNode,
@Cached ArrayNodes.ShiftNode shiftNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int index = normalizeIndexNode.execute(inputIndex, self.getLength());
if (index > self.getLength()) {
index = self.getLength();
@@ -1062,7 +1061,7 @@ static Object remove(VirtualFrame frame, PArray self, Object value,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached ArrayNodes.GetValueNode getValueNode,
@Cached DeleteArraySliceNode deleteSliceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
for (int i = 0; i < self.getLength(); i++) {
Object item = getValueNode.execute(inliningTarget, self, i);
if (eqNode.compare(frame, inliningTarget, item, value)) {
@@ -1071,7 +1070,7 @@ static Object remove(VirtualFrame frame, PArray self, Object value,
return PNone.NONE;
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ARRAY_REMOVE_X_NOT_IN_ARRAY);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ARRAY_REMOVE_X_NOT_IN_ARRAY);
}
}
@@ -1085,9 +1084,9 @@ static Object pop(PArray self, int inputIndex,
@Cached("forPop()") NormalizeIndexNode normalizeIndexNode,
@Cached ArrayNodes.GetValueNode getValueNode,
@Cached DeleteArraySliceNode deleteSliceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getLength() == 0) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.POP_FROM_EMPTY_ARRAY);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.POP_FROM_EMPTY_ARRAY);
}
int index = normalizeIndexNode.execute(inputIndex, self.getLength());
Object value = getValueNode.execute(inliningTarget, self, index);
@@ -1118,14 +1117,14 @@ static Object frombytes(VirtualFrame frame, PArray self, Object buffer,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Cached ArrayNodes.SetLengthNode setLengthNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int itemShift = self.getItemSizeShift();
int oldSize = self.getLength();
try {
int bufferLength = bufferLib.getBufferLength(buffer);
if (!PythonUtils.isDivisible(bufferLength, itemShift)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BYTES_ARRAY_NOT_MULTIPLE_OF_ARRAY_SIZE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BYTES_ARRAY_NOT_MULTIPLE_OF_ARRAY_SIZE);
}
int newLength = PythonUtils.addExact(oldSize, bufferLength >> itemShift);
self.checkCanResize(inliningTarget, raiseNode);
@@ -1134,7 +1133,7 @@ static Object frombytes(VirtualFrame frame, PArray self, Object buffer,
bufferLib.readIntoBuffer(buffer, 0, self.getBuffer(), oldSize << itemShift, bufferLength, bufferLib);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
return PNone.NONE;
} finally {
@@ -1159,9 +1158,9 @@ static Object fromfile(VirtualFrame frame, PArray self, Object file, int n,
@Cached PyObjectSizeNode sizeNode,
@Cached InlinedConditionProfile nNegativeProfile,
@Cached FromBytesNode fromBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (nNegativeProfile.profile(inliningTarget, n < 0)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEGATIVE_COUNT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEGATIVE_COUNT);
}
int nbytes = n << self.getItemSizeShift();
Object readResult = callMethod.execute(frame, inliningTarget, file, T_READ, nbytes);
@@ -1171,10 +1170,10 @@ static Object fromfile(VirtualFrame frame, PArray self, Object file, int n,
// It would make more sense to check this before the frombytes call, but CPython
// does it this way
if (readLength != nbytes) {
- throw raiseNode.get(inliningTarget).raise(EOFError, ErrorMessages.READ_DIDNT_RETURN_ENOUGH_BYTES);
+ throw raiseNode.raise(inliningTarget, EOFError, ErrorMessages.READ_DIDNT_RETURN_ENOUGH_BYTES);
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.READ_DIDNT_RETURN_BYTES);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.READ_DIDNT_RETURN_BYTES);
}
return PNone.NONE;
}
@@ -1196,7 +1195,7 @@ static Object fromlist(VirtualFrame frame, PArray self, PList list,
@Cached ArrayNodes.EnsureCapacityNode ensureCapacityNode,
@Cached ArrayNodes.SetLengthNode setLengthNode,
@Cached ArrayNodes.PutValueNode putValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, list);
int length = storage.length();
@@ -1210,15 +1209,15 @@ static Object fromlist(VirtualFrame frame, PArray self, PList list,
return PNone.NONE;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@Fallback
@SuppressWarnings("unused")
static Object error(Object self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ARG_MUST_BE_LIST);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ARG_MUST_BE_LIST);
}
}
@@ -1236,7 +1235,7 @@ static Object fromunicode(VirtualFrame frame, PArray self, TruffleString str,
@Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
@Cached TruffleStringIterator.NextNode nextNode,
@Cached TruffleString.FromCodePointNode fromCodePointNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int length = codePointLengthNode.execute(str, TS_ENCODING);
int newLength = PythonUtils.addExact(self.getLength(), length);
@@ -1252,15 +1251,15 @@ static Object fromunicode(VirtualFrame frame, PArray self, TruffleString str,
return PNone.NONE;
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
@Fallback
@SuppressWarnings("unused")
static Object error(Object self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.FROMUNICODE_ARG_MUST_BE_STR_NOT_P, arg);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.FROMUNICODE_ARG_MUST_BE_STR_NOT_P, arg);
}
@Override
@@ -1302,9 +1301,9 @@ static TruffleString tounicode(PArray self,
@Cached ArrayNodes.GetValueNode getValueNode,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (formatProfile.profile(inliningTarget, self.getFormat() != BufferFormat.UNICODE)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MAY_ONLY_BE_CALLED_ON_UNICODE_TYPE_ARRAYS);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MAY_ONLY_BE_CALLED_ON_UNICODE_TYPE_ARRAYS);
}
TruffleStringBuilder sb = TruffleStringBuilder.create(TS_ENCODING);
int length = self.getLength();
@@ -1400,7 +1399,7 @@ static int index(VirtualFrame frame, PArray self, Object value, int start, int s
@Bind("this") Node inliningTarget,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached ArrayNodes.GetValueNode getValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int length = self.getLength();
if (start < 0) {
start += length;
@@ -1416,7 +1415,7 @@ static int index(VirtualFrame frame, PArray self, Object value, int start, int s
return i;
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ARRAY_INDEX_X_NOT_IN_ARRAY);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ARRAY_INDEX_X_NOT_IN_ARRAY);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayNodes.java
index 5cbe44a9d6..f4570c743e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -112,7 +112,7 @@ static void ensure(Node inliningTarget, PArray array, int newCapacity,
ensureCapacityNode.execute(inliningTarget, array.getSequenceStorage(), internalCapacity);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.MemoryError);
+ PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.MemoryError);
}
}
}
@@ -130,7 +130,7 @@ static void set(Node inliningTarget, PArray array, int newLength,
setLenNode.execute(inliningTarget, array.getSequenceStorage(), internalLength);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.MemoryError);
+ PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.MemoryError);
}
}
}
@@ -170,7 +170,7 @@ static void shift(Node inliningTarget, PArray array, int from, int by,
setLengthNode.execute(inliningTarget, array, newLength);
} catch (OverflowException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.MemoryError);
+ PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.MemoryError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
index 87c31b135b..7e9ca190ec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java
@@ -140,9 +140,9 @@ public AtomicLong getExports() {
return exports;
}
- public void checkCanResize(Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ public void checkCanResize(Node inliningTarget, PRaiseNode raiseNode) {
if (exports.get() != 0) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.EXPORTS_CANNOT_RESIZE);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.EXPORTS_CANNOT_RESIZE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenSendBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenSendBuiltins.java
index db641813be..52ee2d072d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenSendBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenSendBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -107,16 +107,15 @@ public Object send(VirtualFrame frame, PAsyncGenASend self, Object sent,
@Cached CommonGeneratorBuiltins.SendNode send,
@Cached IsBuiltinObjectProfile isStopIteration,
@Cached IsBuiltinObjectProfile isGenExit,
- @Cached IsBuiltinObjectExactProfile isAsyncGenWrappedValue,
- @Cached PRaiseNode raiseStopIteration) {
+ @Cached IsBuiltinObjectExactProfile isAsyncGenWrappedValue) {
Object result;
if (self.getState() == AwaitableState.CLOSED) {
- throw raiseReuse.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ASEND);
+ throw raiseReuse.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ASEND);
}
if (self.getState() == AwaitableState.INIT) {
if (self.receiver.isRunningAsync()) {
- throw raiseAlreadyRunning.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.AGEN_ALREADY_RUNNING);
+ throw raiseAlreadyRunning.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.AGEN_ALREADY_RUNNING);
}
if (sent == null || sent == PNone.NONE) {
sent = self.message;
@@ -131,7 +130,7 @@ public Object send(VirtualFrame frame, PAsyncGenASend self, Object sent,
throw handleAGError(self.receiver, e, inliningTarget, isStopIteration, isGenExit);
}
try {
- return unwrapAGYield(self.receiver, result, inliningTarget, isAsyncGenWrappedValue, raiseStopIteration);
+ return unwrapAGYield(self.receiver, result, inliningTarget, isAsyncGenWrappedValue);
} catch (PException e) {
self.setState(AwaitableState.CLOSED);
throw e;
@@ -159,12 +158,11 @@ static PException handleAGError(PAsyncGen self, PException exception,
static Object unwrapAGYield(PAsyncGen self, Object result,
Node inliningTarget,
- IsBuiltinObjectExactProfile isAGWrappedValue,
- PRaiseNode raise) {
+ IsBuiltinObjectExactProfile isAGWrappedValue) {
if (isAGWrappedValue.profileObject(inliningTarget, result, PythonBuiltinClassType.PAsyncGenAWrappedValue)) {
self.setRunningAsync(false);
Object wrapped = ((PAsyncGenWrappedValue) result).getWrapped();
- throw raise.raise(PythonBuiltinClassType.StopIteration, new Object[]{wrapped});
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration, new Object[]{wrapped});
}
return result;
}
@@ -181,12 +179,11 @@ public Object doThrow(VirtualFrame frame, PAsyncGenASend self, Object arg1, Obje
@Cached CommonGeneratorBuiltins.ThrowNode throwNode,
@Cached IsBuiltinObjectProfile isStopIteration,
@Cached IsBuiltinObjectProfile isGeneratorExit,
- @Cached IsBuiltinObjectExactProfile isAGWrappedValue,
- @Cached PRaiseNode raiseStopIteration) {
+ @Cached IsBuiltinObjectExactProfile isAGWrappedValue) {
Object result;
if (self.getState() == AwaitableState.CLOSED) {
- throw raiseReuse.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ASEND);
+ throw raiseReuse.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ASEND);
}
try {
result = throwNode.execute(frame, self.receiver, arg1, arg2, arg3);
@@ -195,7 +192,7 @@ public Object doThrow(VirtualFrame frame, PAsyncGenASend self, Object arg1, Obje
throw handleAGError(self.receiver, e, inliningTarget, isStopIteration, isGeneratorExit);
}
try {
- return unwrapAGYield(self.receiver, result, inliningTarget, isAGWrappedValue, raiseStopIteration);
+ return unwrapAGYield(self.receiver, result, inliningTarget, isAGWrappedValue);
} catch (PException e) {
self.setState(AwaitableState.CLOSED);
throw e;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenThrowBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenThrowBuiltins.java
index 5d22de9a24..a26f24fb45 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenThrowBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/AsyncGenThrowBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -122,14 +122,13 @@ public Object send(VirtualFrame frame, PAsyncGenAThrow self, Object sent,
@Cached IsBuiltinObjectExactProfile isAGWrappedValue,
@Cached IsBuiltinObjectProfile isStopAsyncIter,
@Cached IsBuiltinObjectProfile isGeneratorExit,
- @Cached PRaiseNode raiseIgnoreExit,
@Cached PRaiseNode raiseStopIteration,
@Cached CommonGeneratorBuiltins.SendNode sendNode) {
PAsyncGen gen = self.receiver;
Object retval;
if (self.getState() == AwaitableState.CLOSED) {
- throw raiseReuse.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ATHROW);
+ throw raiseReuse.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ATHROW);
}
// CPython checks for gi_frame_state here, but we don't have gi_frame_state.
@@ -137,24 +136,24 @@ public Object send(VirtualFrame frame, PAsyncGenAThrow self, Object sent,
// https://github.com/python/cpython/blob/main/Objects/genobject.c#L2082-L2086
if (self.receiver.isFinished()) {
self.setState(AwaitableState.CLOSED);
- throw raiseStopIteration.raise(PythonBuiltinClassType.StopIteration);
+ throw raiseStopIteration.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
if (self.getState() == AwaitableState.INIT) {
if (gen.isRunningAsync()) {
self.setState(AwaitableState.CLOSED);
- throw raiseAlreadyRunning.raise(PythonBuiltinClassType.RuntimeError); // todo
- // error
- // msg
+ throw raiseAlreadyRunning.raise(inliningTarget, PythonBuiltinClassType.RuntimeError); // todo
+ // error
+ // msg
}
if (gen.isClosed()) {
self.setState(AwaitableState.CLOSED);
- throw raiseStopAsyncIteraion.raise(PythonBuiltinClassType.StopAsyncIteration);
+ throw raiseStopAsyncIteraion.raise(inliningTarget, PythonBuiltinClassType.StopAsyncIteration);
}
if (sent != PNone.NONE) {
- throw raiseNonNodeToNewCoro.raise(PythonBuiltinClassType.RuntimeError, SEND_NON_NONE_TO_UNSTARTED_GENERATOR);
+ throw raiseNonNodeToNewCoro.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, SEND_NON_NONE_TO_UNSTARTED_GENERATOR);
}
self.setState(AwaitableState.ITER);
@@ -167,10 +166,10 @@ public Object send(VirtualFrame frame, PAsyncGenAThrow self, Object sent,
try {
retval = throwNode.execute(frame, gen, PythonBuiltinClassType.GeneratorExit, PNone.NO_VALUE, PNone.NO_VALUE);
} catch (PException e) {
- throw checkError(self, gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit, raiseStopIteration);
+ throw checkError(self, gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit);
}
if (isAGWrappedValue.profileObject(inliningTarget, retval, PythonBuiltinClassType.PAsyncGenAWrappedValue)) {
- throw yieldClose(self, gen, raiseIgnoreExit);
+ throw yieldClose(inliningTarget, self, gen);
}
} else {
// athrow mode
@@ -178,9 +177,9 @@ public Object send(VirtualFrame frame, PAsyncGenAThrow self, Object sent,
retval = throwNode.execute(frame, gen, self.arg1, self.arg2, self.arg3);
} catch (PException e) {
PException exception = AsyncGenSendBuiltins.handleAGError(gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit);
- throw checkError(self, gen, exception, inliningTarget, isStopAsyncIter, isGeneratorExit, raiseStopIteration);
+ throw checkError(self, gen, exception, inliningTarget, isStopAsyncIter, isGeneratorExit);
}
- return AsyncGenSendBuiltins.unwrapAGYield(gen, retval, inliningTarget, isAGWrappedValue, raiseStopIteration);
+ return AsyncGenSendBuiltins.unwrapAGYield(gen, retval, inliningTarget, isAGWrappedValue);
}
}
@@ -192,38 +191,36 @@ public Object send(VirtualFrame frame, PAsyncGenAThrow self, Object sent,
throw AsyncGenSendBuiltins.handleAGError(gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit);
} else {
// aclose
- throw checkError(self, gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit, raiseStopIteration);
+ throw checkError(self, gen, e, inliningTarget, isStopAsyncIter, isGeneratorExit);
}
}
if (self.arg1 != null) {
- return AsyncGenSendBuiltins.unwrapAGYield(gen, retval, inliningTarget, isAGWrappedValue, raiseStopIteration);
+ return AsyncGenSendBuiltins.unwrapAGYield(gen, retval, inliningTarget, isAGWrappedValue);
} else {
// aclose
if (isAGWrappedValue.profileObject(inliningTarget, retval, PythonBuiltinClassType.PAsyncGenAWrappedValue)) {
- throw yieldClose(self, gen, raiseIgnoreExit);
+ throw yieldClose(inliningTarget, self, gen);
} else {
return retval;
}
}
}
- static PException yieldClose(PAsyncGenAThrow athrow, PAsyncGen gen,
- PRaiseNode raiseIgnoreExit) {
+ static PException yieldClose(Node inliningTarget, PAsyncGenAThrow athrow, PAsyncGen gen) {
gen.setRunningAsync(false);
athrow.setState(AwaitableState.CLOSED);
- return raiseIgnoreExit.raise(PythonBuiltinClassType.RuntimeError, GENERATOR_IGNORED_EXIT);
+ return PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.RuntimeError, GENERATOR_IGNORED_EXIT);
}
static PException checkError(PAsyncGenAThrow athrow, PAsyncGen gen, PException exception,
Node inliningTarget,
IsBuiltinObjectProfile isStopAsyncIter,
- IsBuiltinObjectProfile isGenExit,
- PRaiseNode raiseStopIteration) {
+ IsBuiltinObjectProfile isGenExit) {
gen.setRunningAsync(false);
athrow.setState(AwaitableState.CLOSED);
if (athrow.arg1 == null && (isStopAsyncIter.profileException(inliningTarget, exception, PythonBuiltinClassType.StopAsyncIteration) ||
isGenExit.profileException(inliningTarget, exception, PythonBuiltinClassType.GeneratorExit))) {
- return raiseStopIteration.raise(PythonBuiltinClassType.StopIteration);
+ return PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return exception;
}
@@ -246,13 +243,11 @@ public Object doThrow(VirtualFrame frame, PAsyncGenAThrow self, Object arg1, Obj
@Cached CommonGeneratorBuiltins.ThrowNode throwNode,
@Cached IsBuiltinObjectProfile isStopAsyncIteration,
@Cached IsBuiltinObjectProfile isGeneratorExit,
- @Cached IsBuiltinObjectExactProfile isAGWrappedValue,
- @Cached PRaiseNode raiseStopIteration,
- @Cached PRaiseNode raiseIgnoredExit) {
+ @Cached IsBuiltinObjectExactProfile isAGWrappedValue) {
Object retval;
if (self.getState() == AwaitableState.CLOSED) {
- throw raiseReuse.raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ATHROW);
+ throw raiseReuse.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_ATHROW);
}
try {
@@ -264,16 +259,16 @@ public Object doThrow(VirtualFrame frame, PAsyncGenAThrow self, Object arg1, Obj
// aclose()
if (isStopAsyncIteration.profileException(inliningTarget, e, PythonBuiltinClassType.StopAsyncIteration) ||
isGeneratorExit.profileException(inliningTarget, e, PythonBuiltinClassType.GeneratorExit)) {
- throw raiseStopIteration.raise(PythonBuiltinClassType.StopIteration);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
throw e;
}
}
if (self.arg1 != null) {
- return AsyncGenSendBuiltins.unwrapAGYield(self.receiver, retval, inliningTarget, isAGWrappedValue, raiseStopIteration);
+ return AsyncGenSendBuiltins.unwrapAGYield(self.receiver, retval, inliningTarget, isAGWrappedValue);
} else {
if (isAGWrappedValue.profileObject(inliningTarget, retval, PythonBuiltinClassType.PAsyncGenAWrappedValue)) {
- throw Send.yieldClose(self, self.receiver, raiseIgnoredExit);
+ throw Send.yieldClose(inliningTarget, self, self.receiver);
}
return retval;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/GetAwaitableNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/GetAwaitableNode.java
index f48c021293..9b98d618b4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/GetAwaitableNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/GetAwaitableNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -69,24 +69,24 @@ public abstract class GetAwaitableNode extends Node {
@Specialization
public static Object doGenerator(PGenerator generator,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raise,
- @Exclusive @Cached PRaiseNode.Lazy raiseReusedCoro) {
+ @Exclusive @Cached PRaiseNode raise,
+ @Exclusive @Cached PRaiseNode raiseReusedCoro) {
if (generator.isCoroutine()) {
if (generator.getYieldFrom() != null) {
- throw raiseReusedCoro.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CORO_ALREADY_AWAITED);
+ throw raiseReusedCoro.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CORO_ALREADY_AWAITED);
} else {
return generator;
}
} else {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_BE_USED_AWAIT, "generator");
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_BE_USED_AWAIT, "generator");
}
}
@Specialization
public static Object doGeneric(Frame frame, Object awaitable,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNoAwait,
- @Exclusive @Cached PRaiseNode.Lazy raiseNotIter,
+ @Exclusive @Cached PRaiseNode raiseNoAwait,
+ @Exclusive @Cached PRaiseNode raiseNotIter,
@Cached(parameters = "Await") LookupSpecialMethodSlotNode findAwait,
@Cached TypeNodes.GetNameNode getName,
@Cached GetClassNode getAwaitableType,
@@ -96,7 +96,7 @@ public static Object doGeneric(Frame frame, Object awaitable,
Object type = getAwaitableType.execute(inliningTarget, awaitable);
Object getter = findAwait.execute(frame, type, awaitable);
if (getter == PNone.NO_VALUE) {
- throw raiseNoAwait.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_BE_USED_AWAIT, getName.execute(inliningTarget, type));
+ throw raiseNoAwait.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANNOT_BE_USED_AWAIT, getName.execute(inliningTarget, type));
}
Object iterator = callAwait.executeObject(getter, awaitable);
if (iterCheck.execute(inliningTarget, iterator)) {
@@ -104,9 +104,9 @@ public static Object doGeneric(Frame frame, Object awaitable,
}
Object itType = getIteratorType.execute(inliningTarget, iterator);
if (itType == PythonBuiltinClassType.PCoroutine) {
- throw raiseNotIter.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.AWAIT_RETURN_COROUTINE);
+ throw raiseNotIter.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.AWAIT_RETURN_COROUTINE);
} else {
- throw raiseNotIter.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.AWAIT_RETURN_NON_ITER, getName.execute(inliningTarget, itType));
+ throw raiseNotIter.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.AWAIT_RETURN_NON_ITER, getName.execute(inliningTarget, itType));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java
index 3c1edf8028..2aa92be08f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -202,7 +202,7 @@ public final Object acquireWritableWithTypeError(Object receiver, String callerN
try {
return acquireWritable(receiver);
} catch (PException e) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_READ_WRITE_BYTES_LIKE_NOT_P, callerName, receiver);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_READ_WRITE_BYTES_LIKE_NOT_P, callerName, receiver);
} finally {
IndirectCallContext.exit(frame, indirectCallData, savedState);
}
@@ -225,7 +225,7 @@ public final Object acquireWritableWithTypeError(Object receiver, String callerN
*/
@Abstract
public Object acquire(Object receiver, int flags) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, receiver);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, receiver);
}
/**
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
index a50c5fc9f6..c48cd23418 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
@@ -185,14 +185,14 @@ static PNone doInit(VirtualFrame frame, PByteArray self, Object source, Object e
@Specialization(guards = "isNone(self)")
static PNone doInit(@SuppressWarnings("unused") PByteArray self, Object source, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S, source, "bytearray");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S, source, "bytearray");
}
@Specialization(guards = "!isBytes(self)")
static PNone doInit(Object self, @SuppressWarnings("unused") Object source, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___INIT__, "bytearray", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___INIT__, "bytearray", self);
}
}
@@ -217,7 +217,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile validProfile,
@Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached BytesNodes.GetBytesStorage getBytesStorage,
@Cached SequenceStorageMpSubscriptNode subscriptNode) {
if (!validProfile.profile(inliningTarget, SequenceStorageMpSubscriptNode.isValidIndex(inliningTarget, idx, indexCheckNode))) {
@@ -228,8 +228,8 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
}
@InliningCutoff
- private static PException raiseNonIntIndex(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object index) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "bytearray", index);
+ private static PException raiseNonIntIndex(Node inliningTarget, PRaiseNode raiseNode, Object index) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "bytearray", index);
}
}
@@ -267,13 +267,13 @@ static void set(VirtualFrame frame, PByteArray self, Object indexObj, Object val
@Cached PyNumberAsSizeNode asSizeNode,
@Cached("forBytearray()") NormalizeIndexNode normalizeIndexNode,
@Cached SequenceStorageNodes.SetItemScalarNode setItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, indexObj)) {
int index = asSizeNode.executeExact(frame, inliningTarget, indexObj);
index = normalizeIndexNode.execute(index, self.getSequenceStorage().length());
setItemNode.execute(inliningTarget, self.getSequenceStorage(), index, value);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "bytearray", indexObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "bytearray", indexObj);
}
}
@@ -286,7 +286,7 @@ static void doSliceSequence(VirtualFrame frame, PByteArray self, PSlice slice, P
@Cached @Shared SliceNodes.CoerceToIntSlice sliceCast,
@Cached @Shared SliceNodes.SliceUnpack unpack,
@Cached @Shared SliceNodes.AdjustIndices adjustIndices,
- @Cached @Shared PRaiseNode.Lazy raiseNode) {
+ @Cached @Shared PRaiseNode raiseNode) {
SequenceStorage storage = self.getSequenceStorage();
int otherLen = getSequenceStorageNode.execute(inliningTarget, value).length();
SliceInfo unadjusted = unpack.execute(inliningTarget, sliceCast.execute(inliningTarget, slice));
@@ -310,7 +310,7 @@ static void doSliceBuffer(VirtualFrame frame, PByteArray self, PSlice slice, Obj
@Cached @Shared SliceNodes.CoerceToIntSlice sliceCast,
@Cached @Shared SliceNodes.SliceUnpack unpack,
@Cached @Shared SliceNodes.AdjustIndices adjustIndices,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(value, frame, indirectCallData);
try {
// TODO avoid copying if possible. Note that it is possible that value is self
@@ -331,7 +331,7 @@ static void doSliceGeneric(VirtualFrame frame, PByteArray self, PSlice slice, Ob
@Cached @Shared SliceNodes.SliceUnpack unpack,
@Cached @Shared SliceNodes.AdjustIndices adjustIndices,
@Cached ListNodes.ConstructListNode constructListNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PList values = constructListNode.execute(frame, value);
doSliceSequence(frame, self, slice, values, inliningTarget, differentLenProfile, getSequenceStorageNode, setItemSliceNode, sliceCast, unpack, adjustIndices, raiseNode);
}
@@ -340,7 +340,7 @@ static void doSliceGeneric(VirtualFrame frame, PByteArray self, PSlice slice, Ob
static void doDelete(VirtualFrame frame, PByteArray self, Object key, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
@Cached SequenceStorageNodes.DeleteNode deleteNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
deleteNode.execute(frame, self.getSequenceStorage(), key);
}
@@ -358,7 +358,7 @@ public abstract static class InsertNode extends PythonTernaryClinicBuiltinNode {
static PNone insert(VirtualFrame frame, PByteArray self, int index, int value,
@Bind("this") Node inliningTarget,
@Shared @Cached CastToByteNode toByteNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
byte v = toByteNode.execute(frame, value);
ByteSequenceStorage target = (ByteSequenceStorage) self.getSequenceStorage();
@@ -372,7 +372,7 @@ static PNone insert(VirtualFrame frame, PByteArray self, int index, int value,
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Cached SequenceStorageNodes.InsertItemNode insertItemNode,
@Shared @Cached CastToByteNode toByteNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
byte v = toByteNode.execute(frame, value);
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, self);
@@ -433,7 +433,7 @@ public abstract static class IAddNode extends PythonBinaryBuiltinNode {
static PByteArray add(PByteArray self, PBytesLike other,
@Bind("this") Node inliningTarget,
@Cached @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage res = concatNode.execute(self.getSequenceStorage(), other.getSequenceStorage());
updateSequenceStorage(self, res);
@@ -448,12 +448,12 @@ static PByteArray add(VirtualFrame frame, PByteArray self, Object other,
@CachedLibrary("other") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
}
try {
self.checkCanResize(inliningTarget, raiseNode);
@@ -481,7 +481,7 @@ public abstract static class IMulNode extends PythonBinaryBuiltinNode {
static Object mul(VirtualFrame frame, PByteArray self, int times,
@Bind("this") Node inliningTarget,
@Cached @Shared SequenceStorageNodes.RepeatNode repeatNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage res = repeatNode.execute(frame, self.getSequenceStorage(), times);
self.setSequenceStorage(res);
@@ -493,7 +493,7 @@ static Object mul(VirtualFrame frame, PByteArray self, Object times,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached @Shared SequenceStorageNodes.RepeatNode repeatNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage res = repeatNode.execute(frame, self.getSequenceStorage(), asSizeNode.executeExact(frame, inliningTarget, times));
self.setSequenceStorage(res);
@@ -503,8 +503,8 @@ static Object mul(VirtualFrame frame, PByteArray self, Object times,
@SuppressWarnings("unused")
@Fallback
static Object mul(Object self, Object other,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, other);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, other);
}
}
@@ -518,7 +518,7 @@ static PNone remove(VirtualFrame frame, PByteArray self, Object value,
@Cached("createCast()") CastToByteNode cast,
@Cached SequenceStorageNodes.GetInternalByteArrayNode getBytes,
@Cached SequenceStorageNodes.DeleteNode deleteNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage storage = self.getSequenceStorage();
int len = storage.length();
@@ -527,22 +527,22 @@ static PNone remove(VirtualFrame frame, PByteArray self, Object value,
deleteNode.execute(frame, storage, pos);
return PNone.NONE;
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NOT_IN_BYTEARRAY);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_IN_BYTEARRAY);
}
@NeverDefault
static CastToByteNode createCast() {
- return CastToByteNode.create((val, raiseNode) -> {
- throw raiseNode.raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
- }, (val, raiseNode) -> {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
+ return CastToByteNode.create((node, val) -> {
+ throw PRaiseNode.raiseStatic(node, ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ }, (node, val) -> {
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
});
}
@Fallback
static Object doError(@SuppressWarnings("unused") Object self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
}
}
@@ -555,7 +555,7 @@ static Object popLast(VirtualFrame frame, PByteArray self, @SuppressWarnings("un
@Bind("this") Node inliningTarget,
@Shared("getItem") @Cached SequenceStorageNodes.GetItemNode getItemNode,
@Shared @Cached("createDelete()") SequenceStorageNodes.DeleteNode deleteNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage store = self.getSequenceStorage();
Object ret = getItemNode.execute(store, -1);
@@ -568,7 +568,7 @@ static Object doIndex(VirtualFrame frame, PByteArray self, Object idx,
@Bind("this") Node inliningTarget,
@Shared("getItem") @Cached SequenceStorageNodes.GetItemNode getItemNode,
@Shared @Cached("createDelete()") SequenceStorageNodes.DeleteNode deleteNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage store = self.getSequenceStorage();
Object ret = getItemNode.execute(frame, store, idx);
@@ -578,8 +578,8 @@ static Object doIndex(VirtualFrame frame, PByteArray self, Object idx,
@Fallback
static Object doError(@SuppressWarnings("unused") Object self, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
}
@NeverDefault
@@ -602,7 +602,7 @@ static PNone append(VirtualFrame frame, PByteArray byteArray, Object arg,
@Bind("this") Node inliningTarget,
@Cached("createCast()") CastToByteNode toByteNode,
@Cached SequenceStorageNodes.AppendNode appendNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byteArray.checkCanResize(inliningTarget, raiseNode);
appendNode.execute(inliningTarget, byteArray.getSequenceStorage(), toByteNode.execute(frame, arg), BytesNodes.BytesLikeNoGeneralizationNode.SUPPLIER);
return PNone.NONE;
@@ -610,10 +610,10 @@ static PNone append(VirtualFrame frame, PByteArray byteArray, Object arg,
@NeverDefault
static CastToByteNode createCast() {
- return CastToByteNode.create((val, raiseNode) -> {
- throw raiseNode.raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
- }, (val, raiseNode) -> {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
+ return CastToByteNode.create((node, val) -> {
+ throw PRaiseNode.raiseStatic(node, ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ }, (node, val) -> {
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
});
}
}
@@ -628,7 +628,7 @@ static PNone doBytes(VirtualFrame frame, PByteArray self, PBytesLike source,
@Bind("this") Node inliningTarget,
@Cached IteratorNodes.GetLength lenNode,
@Cached("createExtend()") @Shared SequenceStorageNodes.ExtendNode extendNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
int len = lenNode.execute(frame, inliningTarget, source);
extend(frame, self, source, len, extendNode);
@@ -646,7 +646,7 @@ static PNone doGeneric(VirtualFrame frame, PByteArray self, Object source,
@Cached BytesNodes.IterableToByteNode iterableToByteNode,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached("createExtend()") @Shared SequenceStorageNodes.ExtendNode extendNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
byte[] b;
if (bufferProfile.profile(inliningTarget, bufferAcquireLib.hasBuffer(source))) {
@@ -662,7 +662,7 @@ static PNone doGeneric(VirtualFrame frame, PByteArray self, Object source,
b = iterableToByteNode.execute(frame, source);
} catch (PException e) {
e.expect(inliningTarget, TypeError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_EXTEND_BYTEARRAY_WITH_P, source);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_EXTEND_BYTEARRAY_WITH_P, source);
}
}
PByteArray bytes = PFactory.createByteArray(language, b);
@@ -722,7 +722,7 @@ static PNone clear(VirtualFrame frame, PByteArray byteArray,
@Bind("this") Node inliningTarget,
@Cached SequenceStorageNodes.DeleteNode deleteNode,
@Cached PySliceNew sliceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byteArray.checkCanResize(inliningTarget, raiseNode);
deleteNode.execute(frame, byteArray.getSequenceStorage(), sliceNode.execute(inliningTarget, PNone.NONE, PNone.NONE, 1));
return PNone.NONE;
@@ -774,7 +774,7 @@ static PByteArray translate(VirtualFrame frame, PByteArray self, Object table, O
@Cached InlinedBranchProfile hasTable,
@Cached InlinedBranchProfile hasDelete,
@Cached BytesNodes.ToBytesNode toBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] bTable = null;
if (table != PNone.NONE) {
hasTable.enter(inliningTarget);
@@ -899,9 +899,8 @@ static Object cmp(VirtualFrame frame, Node inliningTarget, Object self, Object o
@InliningCutoff
@SuppressWarnings("unused")
static Object error(VirtualFrame frame, Node inliningTarget, Object self, Object other, ComparisonOp op,
- @Shared @Cached PyByteArrayCheckNode check,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_BYTEARRAY, self);
+ @Shared @Cached PyByteArrayCheckNode check) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_BYTEARRAY, self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
index f2f0b369ec..1d2117c3d0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java
@@ -137,7 +137,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile validProfile,
@Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached BytesNodes.GetBytesStorage getBytesStorage,
@Cached SequenceStorageMpSubscriptNode subscriptNode) {
if (!validProfile.profile(inliningTarget, SequenceStorageMpSubscriptNode.isValidIndex(inliningTarget, idx, indexCheckNode))) {
@@ -148,8 +148,8 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
}
@InliningCutoff
- private static PException raiseNonIntIndex(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object index) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "byte", index);
+ private static PException raiseNonIntIndex(Node inliningTarget, PRaiseNode raiseNode, Object index) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "byte", index);
}
}
@@ -178,7 +178,7 @@ static Object translate(VirtualFrame frame, Object self, Object table, Object de
@Cached InlinedBranchProfile hasDelete,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached PyBytesCheckExactNode checkExactNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] bTable = null;
if (table != PNone.NONE) {
hasTable.enter(inliningTarget);
@@ -264,7 +264,7 @@ static Object cmp(Node inliningTarget, Object self, Object other, ComparisonOp o
@SuppressWarnings("unused") @Cached PyBytesCheckNode check,
@Cached BytesNodes.GetBytesStorage getBytesStorage,
@Exclusive @Cached SequenceStorageNodes.GetInternalByteArrayNode getArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (check.execute(inliningTarget, self)) {
if (check.execute(inliningTarget, other)) {
SequenceStorage selfStorage = getBytesStorage.execute(inliningTarget, self);
@@ -274,7 +274,7 @@ static Object cmp(Node inliningTarget, Object self, Object other, ComparisonOp o
return PNotImplemented.NOT_IMPLEMENTED;
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_BYTES, self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.builtinName, J_BYTES, self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
index ddd6c980a9..9e4733c4d3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
@@ -198,12 +198,12 @@ public static CodingErrorAction toCodingErrorAction(TruffleString errors, Truffl
return null;
}
- public static CodingErrorAction toCodingErrorAction(Node inliningTarget, TruffleString errors, PRaiseNode.Lazy raiseNode, TruffleString.EqualNode eqNode) {
+ public static CodingErrorAction toCodingErrorAction(Node inliningTarget, TruffleString errors, PRaiseNode raiseNode, TruffleString.EqualNode eqNode) {
CodingErrorAction action = toCodingErrorAction(errors, eqNode);
if (action != null) {
return action;
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.LookupError, ErrorMessages.UNKNOWN_ERROR_HANDLER, errors);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.LookupError, ErrorMessages.UNKNOWN_ERROR_HANDLER, errors);
}
@TruffleBoundary
@@ -244,10 +244,10 @@ static Object decode(VirtualFrame frame, Object self, TruffleString encoding, Tr
@Bind("this") Node inliningTarget,
@Cached CodecsModuleBuiltins.DecodeNode decodeNode,
@Cached IsInstanceNode isInstanceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = decodeNode.executeWithStrings(frame, self, encoding, errors);
if (!isInstanceNode.executeWith(frame, result, PythonBuiltinClassType.PString)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, result);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, result);
}
return result;
}
@@ -305,12 +305,12 @@ static PBytesLike add(VirtualFrame frame, Object self, Object other,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached("createWithOverflowError()") @Shared SequenceStorageNodes.ConcatNode concatNode,
@Cached @Exclusive BytesNodes.CreateBytesNode create,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
}
try {
// TODO avoid copying
@@ -449,8 +449,8 @@ boolean doIt(VirtualFrame frame, Object self, Object substrs, int start, int end
@Fallback
static boolean doGeneric(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object substr,
@SuppressWarnings("unused") Object start, @SuppressWarnings("unused") Object end,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, METHOD_REQUIRES_A_BYTES_OBJECT_GOT_P, substr);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, METHOD_REQUIRES_A_BYTES_OBJECT_GOT_P, substr);
}
protected abstract boolean doIt(byte[] bytes, int len, byte[] prefix, int start, int end);
@@ -578,10 +578,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
static int index(VirtualFrame frame, Object self, Object arg, int start, int end,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.FindNode findNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int result = findNode.execute(frame, inliningTarget, self, arg, start, end);
if (result == -1) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SUBSECTION_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SUBSECTION_NOT_FOUND);
}
return result;
}
@@ -603,10 +603,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
static int indexWithStartEnd(VirtualFrame frame, Object self, Object arg, int start, int end,
@Bind("this") Node inliningTarget,
@Cached BytesNodes.FindNode findNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int result = findNode.executeReverse(frame, inliningTarget, self, arg, start, end);
if (result == -1) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SUBSECTION_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SUBSECTION_NOT_FOUND);
}
return result;
}
@@ -627,7 +627,7 @@ PTuple partition(VirtualFrame frame, Object self, Object sep,
@Cached InlinedConditionProfile notFound,
@Cached BytesNodes.ToBytesNode toBytesNode,
@Cached BytesNodes.CreateBytesNode createBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
byte[] bytes = toBytesNode.execute(frame, self);
@@ -635,7 +635,7 @@ PTuple partition(VirtualFrame frame, Object self, Object sep,
try {
int lenSep = bufferLib.getBufferLength(sepBuffer);
if (lenSep == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
byte[] sepBytes = bufferLib.getCopiedByteArray(sepBuffer);
int idx = BytesNodes.FindNode.find(bytes, len, sepBytes, 0, bytes.length, isRight());
@@ -805,14 +805,14 @@ static byte pstring(Object strObj,
@Cached CastToTruffleStringNode toStr,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString str = toStr.execute(inliningTarget, strObj);
if (codePointLengthNode.execute(str, TS_ENCODING) != 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SEP_MUST_BE_LENGTH_1);
+ throw raiseNode.raise(inliningTarget, ValueError, SEP_MUST_BE_LENGTH_1);
}
int cp = codePointAtIndexNode.execute(str, 0, TS_ENCODING);
if (cp > 127) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SEP_MUST_BE_ASCII);
+ throw raiseNode.raise(inliningTarget, ValueError, SEP_MUST_BE_ASCII);
}
return (byte) cp;
}
@@ -823,17 +823,17 @@ static byte doBuffer(VirtualFrame frame, Object object,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("object") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
Object buffer = bufferAcquireLib.acquireReadonly(object, frame, context, language, indirectCallData);
try {
if (bufferLib.getBufferLength(buffer) != 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SEP_MUST_BE_LENGTH_1);
+ throw raiseNode.raise(inliningTarget, ValueError, SEP_MUST_BE_LENGTH_1);
}
byte b = bufferLib.readByte(buffer, 0);
if (b < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SEP_MUST_BE_ASCII);
+ throw raiseNode.raise(inliningTarget, ValueError, SEP_MUST_BE_ASCII);
}
return b;
} finally {
@@ -844,8 +844,8 @@ static byte doBuffer(VirtualFrame frame, Object object,
@SuppressWarnings("unused")
@Fallback
static byte error(VirtualFrame frame, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.SEP_MUST_BE_STR_OR_BYTES);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.SEP_MUST_BE_STR_OR_BYTES);
}
@ClinicConverterFactory
@@ -897,8 +897,8 @@ static TruffleString hex(Object self, byte sep, int bytesPerSepGroup,
@SuppressWarnings("unused")
@Fallback
static TruffleString err(Object self, Object sep, Object bytesPerSepGroup,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, DESCRIPTOR_NEED_OBJ, "hex", "bytes");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, DESCRIPTOR_NEED_OBJ, "hex", "bytes");
}
}
@@ -1206,7 +1206,7 @@ PBytesLike bytes(VirtualFrame frame, Object self, Object widthObj, Object fillOb
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
@Cached InlinedBranchProfile hasFill,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int width = asSizeNode.executeExact(frame, inliningTarget, widthObj);
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
@@ -1216,7 +1216,7 @@ PBytesLike bytes(VirtualFrame frame, Object self, Object widthObj, Object fillOb
if (fillObj instanceof PBytesLike && bufferLib.getBufferLength(fillObj) == 1) {
fillByte = bufferLib.readByte(fillObj, 0);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BYTE_STRING_OF_LEN_ONE_ONLY, methodName(), fillObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BYTE_STRING_OF_LEN_ONE_ONLY, methodName(), fillObj);
}
}
if (checkSkip(len, width)) {
@@ -1360,8 +1360,8 @@ static PBytesLike replace(Object self, Object substrBuffer, Object replacementBu
@Fallback
static boolean error(@SuppressWarnings("unused") Object self, Object substr, @SuppressWarnings("unused") Object replacement, @SuppressWarnings("unused") Object count,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, BYTESLIKE_OBJ_REQUIRED, substr);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, BYTESLIKE_OBJ_REQUIRED, substr);
}
@TruffleBoundary(allowInlining = true)
@@ -1482,22 +1482,22 @@ static int doInt(int i) {
@Specialization
static int toInt(long x,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
return PInt.intValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
}
}
@Specialization
static int toInt(PInt x,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
return x.intValueExact();
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
}
}
@@ -1634,8 +1634,8 @@ PList split(Object self, byte[] sep, int maxsplit,
@SuppressWarnings("unused")
@Specialization(guards = {"isEmptySep(sep)"})
static PList error(Object bytes, byte[] sep, int maxsplit,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
private static PList getBytesResult(List bytes, ListNodes.AppendNode appendNode, Object self, Node inliningTarget, BytesNodes.CreateBytesNode createBytesNode,
@@ -1940,8 +1940,8 @@ PBytesLike strip(VirtualFrame frame, Object self, Object object,
@Fallback
@SuppressWarnings("unused")
static Object strip(Object self, Object object,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, ErrorMessages.INVALID_ARGS, "lstrip/rstrip");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.INVALID_ARGS, "lstrip/rstrip");
}
protected abstract int mod();
@@ -2071,11 +2071,11 @@ static PBytes maketrans(VirtualFrame frame, @SuppressWarnings("unused") Object c
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached BytesNodes.ToBytesNode toByteNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] fromB = toByteNode.execute(frame, from);
byte[] toB = toByteNode.execute(frame, to);
if (fromB.length != toB.length) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.ARGS_MUST_HAVE_SAME_LENGTH, "maketrans");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.ARGS_MUST_HAVE_SAME_LENGTH, "maketrans");
}
byte[] table = new byte[256];
@@ -2191,7 +2191,7 @@ static PBytesLike expandtabs(Object self, int tabsize,
@Cached GetBytesStorage getBytesStorage,
@Cached GetInternalByteArrayNode getInternalByteArrayNode,
@Cached BytesNodes.CreateBytesNode create,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = getBytesStorage.execute(inliningTarget, self);
int len = storage.length();
if (len == 0) {
@@ -2206,18 +2206,18 @@ static PBytesLike expandtabs(Object self, int tabsize,
if (tabsize > 0) {
int incr = tabsize - (j % tabsize);
if (j > max - incr) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.RESULT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.RESULT_TOO_LONG);
}
j += incr;
}
} else {
if (j > max - 1) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.RESULT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.RESULT_TOO_LONG);
}
j++;
if (p == N || p == R) {
if (i > max - j) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.RESULT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.RESULT_TOO_LONG);
}
i += j;
j = 0;
@@ -2225,7 +2225,7 @@ static PBytesLike expandtabs(Object self, int tabsize,
}
}
if (i > max - j) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.RESULT_TOO_LONG);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.RESULT_TOO_LONG);
}
byte[] q = new byte[i + j];
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
index dfceba80ec..21b49d787f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
@@ -252,12 +252,12 @@ byte[] doBuffer(VirtualFrame frame, Object object,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("object") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = bufferAcquireLib.acquireReadonly(object, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(errorType, errorMessageFormat, object);
+ throw raiseNode.raise(inliningTarget, errorType, errorMessageFormat, object);
}
try {
return bufferLib.getCopiedByteArray(buffer);
@@ -287,12 +287,12 @@ public abstract static class ToBytesWithoutFrameNode extends Node {
static byte[] doBuffer(Node inliningTarget, Object object,
@CachedLibrary("object") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer;
try {
buffer = bufferAcquireLib.acquireReadonly(object);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, EXPECTED_BYTESLIKE_GOT_P, object);
+ throw raiseNode.raise(inliningTarget, TypeError, EXPECTED_BYTESLIKE_GOT_P, object);
}
try {
return bufferLib.getCopiedByteArray(buffer);
@@ -528,8 +528,8 @@ static Object str(PString str,
@Fallback
Object doOthers(@SuppressWarnings("unused") VirtualFrame frame, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, className, argNum, PythonBuiltinClassType.PString, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ARG_D_MUST_BE_S_NOT_P, className, argNum, PythonBuiltinClassType.PString, value);
}
@ClinicConverterFactory
@@ -560,7 +560,7 @@ static byte[] doGeneric(VirtualFrame frame, Object object,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached BytesNodes.IterableToByteNode iterableToByteNode,
@Cached IsBuiltinObjectProfile errorProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (bufferAcquireLib.hasBuffer(object)) {
// TODO PyBUF_FULL_RO
Object buffer = bufferAcquireLib.acquire(object, BufferFlags.PyBUF_ND, frame, indirectCallData);
@@ -577,7 +577,7 @@ static byte[] doGeneric(VirtualFrame frame, Object object,
e.expect(inliningTarget, TypeError, errorProfile);
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S, object, "bytes");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S, object, "bytes");
}
}
@@ -605,18 +605,18 @@ static byte[] fromObject(VirtualFrame frame, Node inliningTarget, Object source,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached(inline = false) BytesFromObject bytesFromObject,
// Exclusive as a workaround for GR-44836
- @Cached @Exclusive PRaiseNode.Lazy raiseNode) {
+ @Cached @Exclusive PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, source)) {
try {
int size = asSizeNode.executeExact(frame, inliningTarget, source);
if (size < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEGATIVE_COUNT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEGATIVE_COUNT);
}
try {
return new byte[size];
} catch (OutOfMemoryError error) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
} catch (PException e) {
e.expect(inliningTarget, TypeError, errorProfile);
@@ -643,18 +643,18 @@ static byte[] fromString(Node inliningTarget, Object source, Object encoding, Ob
@Specialization(guards = "isString(source)")
@SuppressWarnings("unused")
static byte[] fromString(Node inliningTarget, Object source, PNone encoding, Object errors,
- @Cached @Shared PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.STRING_ARG_WO_ENCODING);
+ @Cached @Shared PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.STRING_ARG_WO_ENCODING);
}
@Fallback
@SuppressWarnings("unused")
public static byte[] error(Node inliningTarget, Object source, Object encoding, Object errors,
- @Cached @Shared PRaiseNode.Lazy raiseNode) {
+ @Cached @Shared PRaiseNode raiseNode) {
if (PGuards.isNone(encoding)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ENCODING_ARG_WO_STRING);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ENCODING_ARG_WO_STRING);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ERRORS_WITHOUT_STR_ARG);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ERRORS_WITHOUT_STR_ARG);
}
}
@@ -686,7 +686,7 @@ static TruffleString negative(Node inliningTarget, byte[] argbuf, int arglen, by
@Shared @Cached InlinedConditionProfile earlyExit,
@Shared @Cached(inline = false) TruffleString.FromByteArrayNode fromByteArrayNode,
@Shared @Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (earlyExit.profile(inliningTarget, arglen == 0)) {
return T_EMPTY_STRING;
}
@@ -694,7 +694,7 @@ static TruffleString negative(Node inliningTarget, byte[] argbuf, int arglen, by
/* How many sep characters we'll be inserting. */
int resultlen = (arglen - 1) / absBytesPerSepGroup;
if (arglen >= SysModuleBuiltins.MAXSIZE / 2 - resultlen) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
resultlen += arglen * 2;
@@ -728,7 +728,7 @@ static TruffleString positive(Node inliningTarget, byte[] argbuf, int arglen, by
@Shared @Cached InlinedConditionProfile earlyExit,
@Shared @Cached(inline = false) TruffleString.FromByteArrayNode fromByteArrayNode,
@Shared @Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (earlyExit.profile(inliningTarget, arglen == 0)) {
return T_EMPTY_STRING;
}
@@ -736,7 +736,7 @@ static TruffleString positive(Node inliningTarget, byte[] argbuf, int arglen, by
int resultlen = (arglen - 1) / absBytesPerSepGroup;
if (arglen >= SysModuleBuiltins.MAXSIZE / 2 - resultlen) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
resultlen += arglen * 2;
@@ -884,7 +884,7 @@ static byte[] ascii(TruffleString str,
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
TruffleString ascii = switchEncodingNode.execute(str, Encoding.US_ASCII);
InternalByteArray iba = getInternalByteArrayNode.execute(ascii, Encoding.US_ASCII);
byte[] bytes = new byte[iba.getLength() / 2];
@@ -897,13 +897,13 @@ static byte[] ascii(TruffleString str,
}
int top = BytesUtils.digitValue(c);
if (top >= 16 || top < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
}
c = i + 1 < iba.getEnd() ? strchar[++i] : 0;
int bottom = BytesUtils.digitValue(c);
if (bottom >= 16 || bottom < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
}
bytes[n++] = (byte) ((top << 4) | bottom);
@@ -920,12 +920,12 @@ static byte[] nonAscii(TruffleString str,
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
@Cached TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,
@Cached TruffleStringIterator.NextNode nextNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
TruffleStringIterator it = createCodePointIteratorNode.execute(str, TS_ENCODING);
int i = 0;
while (it.hasNext()) {
if (nextNode.execute(it) > 127) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, NON_HEX_NUMBER_IN_FROMHEX, i);
}
++i;
}
@@ -1006,9 +1006,9 @@ static boolean compareByteArrays(ComparisonOp op, byte[] selfArray, int selfLeng
@GenerateCached(false)
public abstract static class BaseTranslateNode extends PythonBuiltinNode {
- static void checkLengthOfTable(Node inliningTarget, byte[] table, InlinedConditionProfile isLenTable256Profile, PRaiseNode.Lazy raiseNode) {
+ static void checkLengthOfTable(Node inliningTarget, byte[] table, InlinedConditionProfile isLenTable256Profile, PRaiseNode raiseNode) {
if (isLenTable256Profile.profile(inliningTarget, table.length != 256)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.TRANS_TABLE_MUST_BE_256);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.TRANS_TABLE_MUST_BE_256);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java
index 039317f973..dc1a8f7e83 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -94,9 +94,9 @@ public void setExports(long exports) {
this.exports = exports;
}
- public void checkCanResize(Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ public void checkCanResize(Node inliningTarget, PRaiseNode raiseNode) {
if (exports != 0) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.EXPORTS_CANNOT_RESIZE);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.EXPORTS_CANNOT_RESIZE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java
index be372e2f33..64317fe78a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -35,12 +35,14 @@
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.truffle.api.CompilerAsserts;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
@SuppressWarnings("truffle-abstract-export")
@@ -99,9 +101,10 @@ public static void removeArrayElement(PBytes self, long key) throws UnsupportedM
@ExportMessage
Object acquire(int flags,
+ @Bind("$node") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
if ((flags & BufferFlags.PyBUF_WRITABLE) != 0) {
- throw raiseNode.raise(BufferError, ErrorMessages.OBJ_IS_NOT_WRITABLE);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.OBJ_IS_NOT_WRITABLE);
}
return this;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cell/CellBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cell/CellBuiltins.java
index 56edf4e0a3..420c927db9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cell/CellBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cell/CellBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -117,11 +117,11 @@ static boolean eq(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object eq(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___EQ__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___EQ__, "cell", self);
}
}
@@ -147,11 +147,11 @@ static boolean ne(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object eq(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___NE__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___NE__, "cell", self);
}
}
@@ -177,11 +177,11 @@ static boolean lt(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object notImplemented(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___LT__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___LT__, "cell", self);
}
}
@@ -207,11 +207,11 @@ static boolean le(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object notImplemented(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___LE__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___LE__, "cell", self);
}
}
@@ -237,11 +237,11 @@ static boolean gt(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object notImplemented(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GT__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GT__, "cell", self);
}
}
@@ -267,11 +267,11 @@ static boolean ge(VirtualFrame frame, PCell self, PCell other,
@Fallback
static Object notImplemented(Object self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GE__, "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GE__, "cell", self);
}
}
@@ -297,11 +297,11 @@ static TruffleString repr(PCell self,
@Fallback
static Object eq(Object self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self instanceof PCell) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, "__repr__", "cell", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, "__repr__", "cell", self);
}
}
@@ -312,10 +312,10 @@ public abstract static class CellContentsNode extends PythonBuiltinNode {
static Object get(PCell self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Cached GetRefNode getRef,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object ref = getRef.execute(inliningTarget, self);
if (ref == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IS_EMPTY, "Cell");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IS_EMPTY, "Cell");
}
return ref;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java
index f788fa4500..93fc71e8ca 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -1115,7 +1115,7 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
interopLib = InteropLibrary.getUncached(library);
try {
if (interopLib.getLanguage(library).toString().startsWith("class com.oracle.truffle.nfi")) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.SystemError, ErrorMessages.NO_BITCODE_FOUND, spec.path);
+ throw PRaiseNode.raiseStatic(null, PythonBuiltinClassType.SystemError, ErrorMessages.NO_BITCODE_FOUND, spec.path);
}
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
@@ -1297,7 +1297,7 @@ public Object initCApiModule(Node location, Object sharedLibrary, TruffleString
*/
Object clazz = GetClassNode.executeUncached(result);
if (clazz == PNone.NO_VALUE) {
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.SystemError, ErrorMessages.INIT_FUNC_RETURNED_UNINT_OBJ, initFuncName);
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.SystemError, ErrorMessages.INIT_FUNC_RETURNED_UNINT_OBJ, initFuncName);
}
return CreateModuleNodeGen.getUncached().execute(cApiContext, spec, result, sharedLibrary);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
index f060fadafc..ead440a621 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java
@@ -82,7 +82,6 @@
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -213,8 +212,6 @@ public abstract static class ReadMemberNode extends PythonUnaryBuiltinNode {
@Child private PythonToNativeNode toSulongNode;
@Child private CExtAsPythonObjectNode asPythonObjectNode;
- @Child private PForeignToPTypeNode fromForeign;
- @Child private PRaiseNode raiseNode;
@Child private CStructAccess.ReadBaseNode read;
@@ -229,13 +226,12 @@ protected ReadMemberNode(int type, int offset, CExtAsPythonObjectNode asPythonOb
this.read = getReadNode(type);
this.offset = offset;
this.asPythonObjectNode = asPythonObjectNode;
- if (asPythonObjectNode == null) {
- fromForeign = PForeignToPTypeNode.create();
- }
}
@Specialization
- Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self) {
+ Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self,
+ @Bind("this") Node inliningTarget,
+ @Cached PRaiseNode raiseNode) {
if (read == null) {
return PNone.NONE;
} else {
@@ -243,7 +239,7 @@ Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self) {
assert !(nativeResult instanceof Byte || nativeResult instanceof Short || nativeResult instanceof Float || nativeResult instanceof Character || nativeResult instanceof PException ||
nativeResult instanceof String) : nativeResult + " " + nativeResult.getClass();
if (type == T_OBJECT_EX && nativeResult == PNone.NO_VALUE) {
- throw ensureRaiseNode().raise(PythonBuiltinClassType.AttributeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError);
}
if (type == T_OBJECT && nativeResult == PNone.NO_VALUE) {
nativeResult = PNone.NONE;
@@ -264,14 +260,6 @@ private PythonToNativeNode ensureToSulongNode() {
return toSulongNode;
}
- private PRaiseNode ensureRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
-
@TruffleBoundary
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Object owner, TruffleString propertyName, int type, int offset) {
CExtAsPythonObjectNode asPythonObjectNode = getReadConverterNode(type);
@@ -295,8 +283,8 @@ protected ReadOnlyMemberNode(TruffleString propertyName) {
@Specialization
@SuppressWarnings("unused")
Object doGeneric(Object self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, propertyName, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, propertyName, self);
}
@TruffleBoundary
@@ -315,12 +303,12 @@ protected abstract static class BadMemberDescrNode extends PythonBinaryBuiltinNo
@Specialization
static Object doGeneric(Object self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (value == DescriptorDeleteMarker.INSTANCE) {
// This node is actually only used for T_NONE, so this error message is right.
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
}
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_P, self);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_P, self);
}
@TruffleBoundary
@@ -495,12 +483,13 @@ abstract static class WriteObjectExNode extends WriteTypeNode {
@Specialization
static void write(Object pointer, Object newValue,
+ @Bind("this") Node inliningTarget,
@Cached CStructAccess.ReadObjectNode read,
@Cached CStructAccess.WriteObjectNewRefNode write,
@Cached PRaiseNode raise) {
Object current = read.readGeneric(pointer, 0);
if (newValue == DescriptorDeleteMarker.INSTANCE && current == PNone.NO_VALUE) {
- throw raise.raise(PythonBuiltinClassType.AttributeError);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.AttributeError);
}
write.write(pointer, newValue);
}
@@ -586,7 +575,7 @@ protected WriteMemberNode(int type, int offset) {
@Specialization
Object doGeneric(Object self, Object value,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object selfPtr = toSulongNode.execute(self);
selfPtr = getElement.readGeneric(selfPtr, offset);
@@ -598,12 +587,12 @@ Object doGeneric(Object self, Object value,
*/
if (type != T_OBJECT && type != T_OBJECT_EX) {
if (value == DescriptorDeleteMarker.INSTANCE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
}
}
if (type == T_BOOL && !ensureIsSameTypeNode().executeCached(PythonBuiltinClassType.Boolean, ensureGetClassNode().executeCached(value))) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_TYPE_VALUE_MUST_BE_BOOL);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_TYPE_VALUE_MUST_BE_BOOL);
}
write.execute(selfPtr, value);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
index d875b2524b..1121c22ab5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java
@@ -729,7 +729,7 @@ static PComplex runGeneric(Node inliningTarget, Object value,
@Cached PyFloatAsDoubleNode asDoubleNode,
@Cached(inline = false) LookupAndCallUnaryDynamicNode callComplex,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = callComplex.executeObject(value, T___COMPLEX__);
// TODO(fa) according to CPython's 'PyComplex_AsCComplex', they still allow subclasses
// of PComplex
@@ -737,7 +737,7 @@ static PComplex runGeneric(Node inliningTarget, Object value,
if (result instanceof PComplex) {
return (PComplex) result;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, value);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, value);
}
} else {
return PFactory.createComplex(language, asDoubleNode.execute(null, inliningTarget, value), 0.0);
@@ -1148,7 +1148,7 @@ static Object doObject(Frame frame, Object errorValue, PythonBuiltinClassType er
private static void raiseNative(Frame frame, Node inliningTarget, PythonBuiltinClassType errType, TruffleString format, Object[] arguments, PRaiseNode raiseNode,
TransformExceptionToNativeNode transformExceptionToNativeNode) {
try {
- throw raiseNode.raise(errType, format, arguments);
+ throw raiseNode.raise(inliningTarget, errType, format, arguments);
} catch (PException p) {
transformExceptionToNativeNode.execute(frame, inliningTarget, p);
}
@@ -1431,7 +1431,6 @@ Object doGeneric(TruffleString f, Object vaList) {
CastToJavaStringNode castToJavaStringNode = CastToJavaStringNodeGen.getUncached();
FromCharPointerNode fromCharPointerNode = FromCharPointerNodeGen.getUncached();
InteropLibrary interopLibrary = InteropLibrary.getUncached();
- PRaiseNode raiseNode = PRaiseNode.getUncached();
StringBuilder result = new StringBuilder();
int vaArgIdx = 0;
@@ -1453,7 +1452,7 @@ Object doGeneric(TruffleString f, Object vaList) {
int prec = getPrec(matcher.group("prec"));
assert spec.length() == 1;
char la = spec.charAt(0);
- PythonContext context = PythonContext.get(raiseNode);
+ PythonContext context = PythonContext.get(null);
switch (la) {
case '%':
// %%
@@ -1461,9 +1460,9 @@ Object doGeneric(TruffleString f, Object vaList) {
valid = true;
break;
case 'c':
- int ordinal = getAndCastToInt(interopLibrary, raiseNode, vaList);
+ int ordinal = getAndCastToInt(interopLibrary, vaList);
if (ordinal < 0 || ordinal > 0x110000) {
- throw raiseNode.raise(PythonBuiltinClassType.OverflowError, ErrorMessages.CHARACTER_ARG_NOT_IN_RANGE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.OverflowError, ErrorMessages.CHARACTER_ARG_NOT_IN_RANGE);
}
result.append((char) ordinal);
vaArgIdx++;
@@ -1478,12 +1477,12 @@ Object doGeneric(TruffleString f, Object vaList) {
case "l":
case "z":
vaArgIdx++;
- result.append(castToLong(interopLibrary, raiseNode, GetNextVaArgNode.executeUncached(vaList)));
+ result.append(castToLong(interopLibrary, GetNextVaArgNode.executeUncached(vaList)));
valid = true;
break;
}
} else {
- result.append(getAndCastToInt(interopLibrary, raiseNode, vaList));
+ result.append(getAndCastToInt(interopLibrary, vaList));
vaArgIdx++;
valid = true;
}
@@ -1496,19 +1495,19 @@ Object doGeneric(TruffleString f, Object vaList) {
case "l":
case "z":
vaArgIdx++;
- result.append(castToLong(interopLibrary, raiseNode, GetNextVaArgNode.executeUncached(vaList)));
+ result.append(castToLong(interopLibrary, GetNextVaArgNode.executeUncached(vaList)));
valid = true;
break;
}
} else {
- result.append(Integer.toUnsignedString(getAndCastToInt(interopLibrary, raiseNode, vaList)));
+ result.append(Integer.toUnsignedString(getAndCastToInt(interopLibrary, vaList)));
vaArgIdx++;
valid = true;
}
break;
case 'x':
// %x
- result.append(Integer.toHexString(getAndCastToInt(interopLibrary, raiseNode, vaList)));
+ result.append(Integer.toHexString(getAndCastToInt(interopLibrary, vaList)));
vaArgIdx++;
valid = true;
break;
@@ -1600,7 +1599,7 @@ Object doGeneric(TruffleString f, Object vaList) {
// matched)
result.append(format, cur, format.length());
} catch (InteropException e) {
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.ERROR_WHEN_ACCESSING_VAR_ARG_AT_POS, vaArgIdx);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.ERROR_WHEN_ACCESSING_VAR_ARG_AT_POS, vaArgIdx);
}
return toTruffleStringUncached(result.toString());
}
@@ -1616,7 +1615,7 @@ private static int getPrec(String prec) {
* Read an element from the {@code va_list} with the specified type and cast it to a Java
* {@code int}. Throws a {@code SystemError} if this is not possible.
*/
- private static int getAndCastToInt(InteropLibrary lib, PRaiseNode raiseNode, Object vaList) throws InteropException {
+ private int getAndCastToInt(InteropLibrary lib, Object vaList) throws InteropException {
Object value = GetNextVaArgNode.executeUncached(vaList);
if (lib.fitsInInt(value)) {
try {
@@ -1635,14 +1634,14 @@ private static int getAndCastToInt(InteropLibrary lib, PRaiseNode raiseNode, Obj
throw shouldNotReachHere();
}
}
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.P_OBJ_CANT_BE_INTEPRETED_AS_INTEGER, value);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.P_OBJ_CANT_BE_INTEPRETED_AS_INTEGER, value);
}
/**
* Cast a value to a Java {@code long}. Throws a {@code SystemError} if this is not
* possible.
*/
- private static long castToLong(InteropLibrary lib, PRaiseNode raiseNode, Object value) {
+ private long castToLong(InteropLibrary lib, Object value) {
if (lib.fitsInLong(value)) {
try {
return lib.asLong(value);
@@ -1660,7 +1659,7 @@ private static long castToLong(InteropLibrary lib, PRaiseNode raiseNode, Object
throw shouldNotReachHere();
}
}
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.P_OBJ_CANT_BE_INTEPRETED_AS_INTEGER, value);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.P_OBJ_CANT_BE_INTEPRETED_AS_INTEGER, value);
}
private static Object getPyObject(Object vaList) throws InteropException {
@@ -1727,7 +1726,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
@Cached CStructAccess.ReadI32Node readI32Node,
@Cached GetThreadStateNode getThreadStateNode,
@Cached TransformExceptionFromNativeNode transformExceptionFromNativeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// call to type the pointer
Object moduleDef = moduleDefWrapper instanceof PythonAbstractNativeObject ? ((PythonAbstractNativeObject) moduleDefWrapper).getPtr() : moduleDefWrapper;
@@ -1749,7 +1748,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
mSize = readI64.read(moduleDef, PyModuleDef__m_size);
if (mSize < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.M_SIZE_CANNOT_BE_NEGATIVE, mName);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.M_SIZE_CANNOT_BE_NEGATIVE, mName);
}
// parse slot definitions
@@ -1764,7 +1763,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
break loop;
case SLOT_PY_MOD_CREATE:
if (createFunction != null) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.MODULE_HAS_MULTIPLE_CREATE_SLOTS, mName);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.MODULE_HAS_MULTIPLE_CREATE_SLOTS, mName);
}
createFunction = readPointerNode.readStructArrayElement(slotDefinitions, i, PyModuleDef_Slot__value);
break;
@@ -1772,7 +1771,7 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
hasExecutionSlots = true;
break;
default:
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.MODULE_USES_UNKNOW_SLOT_ID, mName, slotId);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.MODULE_USES_UNKNOW_SLOT_ID, mName, slotId);
}
}
}
@@ -1805,10 +1804,10 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, Object m
*/
if (!(module instanceof PythonModule)) {
if (mSize > 0) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.NOT_A_MODULE_OBJECT_BUT_REQUESTS_MODULE_STATE, mName);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.NOT_A_MODULE_OBJECT_BUT_REQUESTS_MODULE_STATE, mName);
}
if (hasExecutionSlots) {
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.MODULE_SPECIFIES_EXEC_SLOTS_BUT_DIDNT_CREATE_INSTANCE, mName);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.MODULE_SPECIFIES_EXEC_SLOTS_BUT_DIDNT_CREATE_INSTANCE, mName);
}
// otherwise CPython is just fine
} else {
@@ -1920,7 +1919,7 @@ static int doGeneric(CApiContext capiContext, PythonModule module, Object module
ErrorMessages.EXECUTION_RAISED_EXCEPTION);
break;
default:
- throw raiseNode.raise(SystemError, ErrorMessages.MODULE_INITIALIZED_WITH_UNKNOWN_SLOT, mName, slotId);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.MODULE_INITIALIZED_WITH_UNKNOWN_SLOT, mName, slotId);
}
}
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
index 6e118171d4..419eabe0a2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
@@ -61,6 +61,7 @@
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
@@ -860,10 +861,10 @@ static Object invoke(VirtualFrame frame, Node inliningTarget, PythonThreadState
return lib.execute(callable, cArguments);
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, name, e);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, name, e);
} catch (ArityException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, name, e.getExpectedMinArity(), e.getActualArity());
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, name, e.getExpectedMinArity(), e.getActualArity());
} catch (Throwable exception) {
/*
* Always re-acquire the GIL here. This is necessary because it could happen that C
@@ -2418,7 +2419,7 @@ static Object doGeneric(PythonThreadState state, @SuppressWarnings("unused") Tru
AbstractTruffleException currentException = state.getCurrentException();
// if no exception occurred, the iterator is exhausted -> raise StopIteration
if (currentException == null) {
- throw raiseNode.raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
} else {
throw clearCurrentExceptionNode.getCurrentExceptionForReraise(inliningTarget, state);
}
@@ -2558,7 +2559,7 @@ static boolean doGeneric(PythonThreadState threadState, TruffleString name, Obje
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.FUNC_DIDNT_RETURN_INT, name);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.FUNC_DIDNT_RETURN_INT, name);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java
index 08f3b241f7..37afca237d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -92,7 +92,7 @@ private static Object intArrayToNativePySSizeArray(int[] intArray) {
@TruffleBoundary
private static Object allocate(PMemoryView object) {
if (object.isReleased()) {
- throw PRaiseNode.raiseUncached(null, ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
+ throw PRaiseNode.raiseStatic(null, ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
}
GetElementPtrNode getElementNode = GetElementPtrNode.getUncached();
CStructAccess.WritePointerNode writePointerNode = CStructAccess.WritePointerNode.getUncached();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
index 66a8204fd9..5d97a74122 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
@@ -1026,7 +1026,7 @@ static int doL(Node inliningTarget, long l,
return (int) l;
}
errorBranch.enter(inliningTarget);
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, l);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, l);
}
@Fallback
@@ -1165,7 +1165,7 @@ long execute(Object[] arguments,
Object result = executeNode.executeObject(null, getDelegate(), toJavaNode.execute(arguments[0]));
return PyObjectHashNode.avoidNegative1(cast.execute(inliningTarget, result));
} catch (CannotCastException e) {
- throw raiseNode.raise(TypeError, ErrorMessages.HASH_SHOULD_RETURN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HASH_SHOULD_RETURN_INTEGER);
} catch (Throwable t) {
throw checkThrowableBeforeNative(t, "HashfuncWrapper", getDelegate());
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
index b2c0b9a338..3d811fd88d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java
@@ -1065,7 +1065,7 @@ static long doGeneric(Node inliningTarget, PythonAbstractObjectNativeWrapper wra
* Python-level MemoryError.
*/
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.MemoryError);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.MemoryError);
} finally {
gil.release(acquired);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
index 06659c2b69..e8ffc7c7a4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java
@@ -202,18 +202,18 @@ static byte[] doGeneric(Charset charset, Object unicodeObject, TruffleString err
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castToTruffleStringNode,
@Cached TruffleString.EqualNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString str;
try {
str = castToTruffleStringNode.execute(inliningTarget, unicodeObject);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_MUST_BE_S_NOT_P, "argument", "a string", unicodeObject);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_MUST_BE_S_NOT_P, "argument", "a string", unicodeObject);
}
try {
CodingErrorAction action = BytesCommonBuiltins.toCodingErrorAction(inliningTarget, errors, raiseNode, eqNode);
return BytesCommonBuiltins.doEncode(charset, str, action);
} catch (CharacterCodingException e) {
- throw raiseNode.get(inliningTarget).raise(UnicodeEncodeError, ErrorMessages.M, e);
+ throw raiseNode.raise(inliningTarget, UnicodeEncodeError, ErrorMessages.M, e);
}
}
}
@@ -605,7 +605,7 @@ private static void checkFunctionResultSlowpath(Node inliningTarget, PythonThrea
@TruffleBoundary
private static PException raiseNullButNoError(Node node, TruffleString name, TruffleString nullButNoErrorMessage) {
- throw PRaiseNode.raiseUncached(node, SystemError, nullButNoErrorMessage, name);
+ throw PRaiseNode.raiseStatic(node, SystemError, nullButNoErrorMessage, name);
}
@TruffleBoundary
@@ -697,9 +697,10 @@ static int doIntToUInt32Pos(int value, int signed, int targetTypeSize, boolean e
@Specialization(guards = {"targetTypeSize == 4", "signed == 0"}, replaces = "doIntToUInt32Pos")
@SuppressWarnings("unused")
static int doIntToUInt32(int value, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNativeNode") @Cached PRaiseNode raiseNativeNode) {
if (exact && value < 0) {
- throw raiseNegativeValue(raiseNativeNode);
+ throw raiseNegativeValue(inliningTarget, raiseNativeNode);
}
return value;
}
@@ -719,9 +720,10 @@ static long doIntToUInt64Pos(int value, int signed, int targetTypeSize, boolean
@Specialization(guards = {"targetTypeSize == 8", "signed == 0"}, replaces = "doIntToUInt64Pos")
@SuppressWarnings("unused")
static long doIntToUInt64(int value, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNativeNode") @Cached PRaiseNode raiseNativeNode) {
if (exact && value < 0) {
- throw raiseNegativeValue(raiseNativeNode);
+ throw raiseNegativeValue(inliningTarget, raiseNativeNode);
}
return value;
}
@@ -741,9 +743,10 @@ static long doLongToUInt64Pos(long value, int signed, int targetTypeSize, boolea
@Specialization(guards = {"targetTypeSize == 8", "signed == 0"}, replaces = "doLongToUInt64Pos")
@SuppressWarnings("unused")
static long doLongToUInt64(long value, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNativeNode") @Cached PRaiseNode raiseNativeNode) {
if (exact && value < 0) {
- throw raiseNegativeValue(raiseNativeNode);
+ throw raiseNegativeValue(inliningTarget, raiseNativeNode);
}
return value;
}
@@ -751,33 +754,36 @@ static long doLongToUInt64(long value, int signed, int targetTypeSize, boolean e
@Specialization(guards = {"exact", "targetTypeSize == 4", "signed != 0"})
@SuppressWarnings("unused")
static int doLongToInt32Exact(long obj, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return PInt.intValueExact(obj);
} catch (OverflowException e) {
- throw raiseNode.raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
}
}
@Specialization(guards = {"exact", "targetTypeSize == 4", "signed == 0", "obj >= 0"})
@SuppressWarnings("unused")
static int doLongToUInt32PosExact(long obj, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
if (Integer.toUnsignedLong((int) obj) == obj) {
return (int) obj;
} else {
- throw raiseNode.raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
}
}
@Specialization(guards = {"exact", "targetTypeSize == 4", "signed == 0"}, replaces = "doLongToUInt32PosExact")
@SuppressWarnings("unused")
static int doLongToUInt32Exact(long obj, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
if (obj < 0) {
- throw raiseNegativeValue(raiseNode);
+ throw raiseNegativeValue(inliningTarget, raiseNode);
}
- return doLongToUInt32PosExact(obj, signed, targetTypeSize, exact, raiseNode);
+ return doLongToUInt32PosExact(obj, signed, targetTypeSize, exact, inliningTarget, raiseNode);
}
@Specialization(guards = {"!exact", "targetTypeSize == 4"})
@@ -796,40 +802,42 @@ static Object doVoidPtrToI64(PythonNativeVoidPtr obj, int signed, int targetType
@SuppressWarnings("unused")
@TruffleBoundary
static int doPIntTo32Bit(PInt obj, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
if (signed != 0) {
return obj.intValueExact();
} else if (obj.bitLength() <= 32) {
if (obj.isNegative()) {
- throw raiseNegativeValue(raiseNode);
+ throw raiseNegativeValue(inliningTarget, raiseNode);
}
return obj.intValue();
}
} catch (OverflowException e) {
// fall through
}
- throw raiseNode.raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
}
@Specialization(guards = {"exact", "targetTypeSize == 8"})
@SuppressWarnings("unused")
@TruffleBoundary
static long doPIntTo64Bit(PInt obj, int signed, int targetTypeSize, boolean exact,
+ @Bind("this") Node inliningTarget,
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
if (signed != 0) {
return obj.longValueExact();
} else if (obj.bitLength() <= 64) {
if (obj.isNegative()) {
- throw raiseNegativeValue(raiseNode);
+ throw raiseNegativeValue(inliningTarget, raiseNode);
}
return obj.longValue();
}
} catch (OverflowException e) {
// fall through
}
- throw raiseNode.raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
}
@Specialization(guards = {"!exact", "targetTypeSize == 4"})
@@ -864,84 +872,84 @@ static Object doGeneric(Object obj, int signed, int targetTypeSize, boolean exac
* 'signed', 'targetTypeSize', and 'exact' are usually constants.
*/
if (targetTypeSize == 4) {
- return toInt32(result, signed, exact, raiseNode);
+ return toInt32(inliningTarget, result, signed, exact, raiseNode);
} else if (targetTypeSize == 8) {
- return toInt64(result, signed, exact, raiseNode);
+ return toInt64(inliningTarget, result, signed, exact, raiseNode);
}
- throw raiseNode.raise(SystemError, ErrorMessages.UNSUPPORTED_TARGET_SIZE, targetTypeSize);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.UNSUPPORTED_TARGET_SIZE, targetTypeSize);
}
@Specialization(guards = {"targetTypeSize != 4", "targetTypeSize != 8"})
@SuppressWarnings("unused")
static int doUnsupportedTargetSize(Object obj, int signed, int targetTypeSize, boolean exact,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, ErrorMessages.UNSUPPORTED_TARGET_SIZE, targetTypeSize);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.UNSUPPORTED_TARGET_SIZE, targetTypeSize);
}
- private static PException raiseNegativeValue(PRaiseNode raiseNativeNode) {
- throw raiseNativeNode.raise(OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
+ private static PException raiseNegativeValue(Node inliningTarget, PRaiseNode raiseNativeNode) {
+ throw raiseNativeNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
}
/**
* Slow-path conversion of an object to a signed or unsigned 32-bit value.
*/
- private static int toInt32(Object object, int signed, boolean exact,
+ private static int toInt32(Node inliningTarget, Object object, int signed, boolean exact,
PRaiseNode raiseNode) {
if (object instanceof Integer) {
int ival = (int) object;
if (signed != 0) {
return ival;
}
- return doIntToUInt32(ival, signed, 4, exact, raiseNode);
+ return doIntToUInt32(ival, signed, 4, exact, inliningTarget, raiseNode);
} else if (object instanceof Long) {
long lval = (long) object;
if (exact) {
if (signed != 0) {
- return doLongToInt32Exact(lval, 1, 4, true, raiseNode);
+ return doLongToInt32Exact(lval, 1, 4, true, inliningTarget, raiseNode);
}
- return doLongToUInt32Exact(lval, signed, 4, true, raiseNode);
+ return doLongToUInt32Exact(lval, signed, 4, true, inliningTarget, raiseNode);
}
return doLongToInt32Lossy(lval, 0, 4, false);
} else if (object instanceof PInt) {
PInt pval = (PInt) object;
if (exact) {
- return doPIntTo32Bit(pval, signed, 4, true, raiseNode);
+ return doPIntTo32Bit(pval, signed, 4, true, inliningTarget, raiseNode);
}
return doPIntToInt32Lossy(pval, signed, 4, false);
} else if (object instanceof PythonNativeVoidPtr) {
// that's just not possible
- throw raiseNode.raise(PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, 4);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, 4);
}
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, object);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, object);
}
/**
* Slow-path conversion of an object to a signed or unsigned 64-bit value.
*/
- private static Object toInt64(Object object, int signed, boolean exact,
+ private static Object toInt64(Node inliningTarget, Object object, int signed, boolean exact,
PRaiseNode raiseNode) {
if (object instanceof Integer) {
Integer ival = (Integer) object;
if (signed != 0) {
return ival.longValue();
}
- return doIntToUInt64(ival, signed, 8, exact, raiseNode);
+ return doIntToUInt64(ival, signed, 8, exact, inliningTarget, raiseNode);
} else if (object instanceof Long) {
long lval = (long) object;
if (signed != 0) {
return doLongToInt64(lval, 1, 8, exact);
}
- return doLongToUInt64(lval, signed, 8, exact, raiseNode);
+ return doLongToUInt64(lval, signed, 8, exact, inliningTarget, raiseNode);
} else if (object instanceof PInt) {
PInt pval = (PInt) object;
if (exact) {
- return doPIntTo64Bit(pval, signed, 8, true, raiseNode);
+ return doPIntTo64Bit(pval, signed, 8, true, inliningTarget, raiseNode);
}
return doPIntToInt64Lossy(pval, signed, 8, false);
} else if (object instanceof PythonNativeVoidPtr) {
return doVoidPtrToI64((PythonNativeVoidPtr) object, signed, 8, exact);
}
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, object);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, object);
}
}
@@ -1146,10 +1154,10 @@ public abstract static class AsNativeCharNode extends CExtToNativeNode {
static byte doGeneric(Object value,
@Bind("this") Node inliningTarget,
@Cached EncodeNativeStringNode encodeNativeStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
byte[] encoded = encodeNativeStringNode.execute(StandardCharsets.UTF_8, value, T_STRICT);
if (encoded.length != 1) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
return encoded[0];
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
index 0fdb508249..c658e0a093 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java
@@ -210,8 +210,8 @@ public static Object loadHPyModule(Node location, PythonContext context, Truffle
try {
abiVersion = backend.getHPyABIVersion(llvmLibrary, hpyMajorVersionFuncName, hpyMinorVersionFuncName);
} catch (Exception e) {
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ERROR_LOADING_EXT_MODULE,
- path, hpyMajorVersionFuncName, hpyMinorVersionFuncName, e.getMessage());
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ERROR_LOADING_EXT_MODULE, path, hpyMajorVersionFuncName, hpyMinorVersionFuncName,
+ e.getMessage());
}
/*
@@ -219,8 +219,8 @@ public static Object loadHPyModule(Node location, PythonContext context, Truffle
* which HPyContext to create.
*/
if (abiVersion.major != HPY_ABI_VERSION || abiVersion.minor > HPY_ABI_VERSION_MINOR) {
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_VERSION_ERROR,
- name, abiVersion.major, abiVersion.minor, HPY_ABI_VERSION, HPY_ABI_VERSION_MINOR);
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_VERSION_ERROR, name, abiVersion.major, abiVersion.minor, HPY_ABI_VERSION,
+ HPY_ABI_VERSION_MINOR);
}
// Sanity check of the tag in the shared object filename
@@ -233,7 +233,7 @@ public static Object loadHPyModule(Node location, PythonContext context, Truffle
// HPy only supports multi-phase extension module initialization.
assert !(hpyModuleDefPtr instanceof PythonModule);
if (InteropLibrary.getUncached().isNull(hpyModuleDefPtr)) {
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.ERROR_LOADING_HPY_EXT_S_S, path, name);
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.ERROR_LOADING_HPY_EXT_S_S, path, name);
}
Object module = GraalHPyModuleCreateNodeGen.getUncached().execute(context.getHPyContext(), name, spec, hpyModuleDefPtr);
@@ -255,14 +255,12 @@ private static void validateABITag(Node location, String shortname, String sonam
String abiTagVersion = matcher.group(1);
int abiTag = Integer.parseInt(abiTagVersion);
if (abiTag != abiVersion.major) {
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_TAG_MISMATCH,
- shortname, soname, abiTag, abiVersion.major, abiVersion.minor);
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_TAG_MISMATCH, shortname, soname, abiTag, abiVersion.major, abiVersion.minor);
}
// major version fits -> validation successful
return;
}
- throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_NO_ABI_TAG,
- shortname, soname, abiVersion.major, abiVersion.minor);
+ throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_NO_ABI_TAG, shortname, soname, abiVersion.major, abiVersion.minor);
}
public Object createArgumentsArray(Object[] args) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
index 1927550d25..872b8ea638 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
@@ -1293,7 +1293,7 @@ static Object doGeneric(@SuppressWarnings("unusued") Object hpyContext, Object o
@Cached PRaiseNode raiseNode,
@Cached AsNativePrimitiveNode asNativePrimitiveNode) {
if (!isSubtypeNode.execute(getClassNode.execute(inliningTarget, object), PythonBuiltinClassType.PInt)) {
- throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
return asNativePrimitiveNode.execute(object, 0, SIZEOF_INT32, true);
}
@@ -1332,7 +1332,7 @@ static Object doGeneric(@SuppressWarnings("unusued") Object hpyContext, Object o
@Cached PRaiseNode raiseNode,
@Cached AsNativePrimitiveNode asNativePrimitiveNode) {
if (!isSubtypeNode.execute(getClassNode.execute(inliningTarget, object), PythonBuiltinClassType.PInt)) {
- throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
return asNativePrimitiveNode.execute(object, 0, SIZEOF_INT64, true);
}
@@ -1359,7 +1359,7 @@ static Object doGeneric(@SuppressWarnings("unusued") Object hpyContext, Object o
@Cached PRaiseNode raiseNode,
@Cached AsNativePrimitiveNode asNativePrimitiveNode) {
if (!isSubtypeNode.execute(getClassNode.execute(inliningTarget, object), PythonBuiltinClassType.PInt)) {
- throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
return asNativePrimitiveNode.execute(object, 1, SIZEOF_INTPTR, true);
}
@@ -1402,7 +1402,7 @@ static Object doGeneric(GraalHPyContext hpyContext, long len,
Arrays.fill(data, PNone.NONE);
return PFactory.createList(hpyContext.getContext().getLanguage(inliningTarget), data);
} catch (OverflowException e) {
- throw raiseNode.raise(PythonBuiltinClassType.MemoryError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.MemoryError);
}
}
}
@@ -1413,10 +1413,11 @@ public abstract static class GraalHPyListAppend extends HPyTernaryContextFunctio
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object left, Object value,
+ @Bind("this") Node inliningTarget,
@Cached ListNodes.AppendNode appendNode,
@Cached PRaiseNode raiseNode) {
if (!PGuards.isList(left)) {
- throw raiseNode.raise(SystemError, ErrorMessages.BAD_INTERNAL_CALL);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_INTERNAL_CALL);
}
appendNode.execute((PList) left, value);
return 0;
@@ -1522,8 +1523,8 @@ public abstract static class GraalHPyErrNoMemory extends HPyUnaryContextFunction
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.MemoryError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.MemoryError);
}
}
@@ -1541,7 +1542,7 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object er
@Cached PyExceptionInstanceCheckNode exceptionCheckNode,
@Cached PRaiseNode raiseNode) {
if (!(PGuards.isPythonClass(errTypeObj) && isSubtypeNode.execute(errTypeObj, PythonBuiltinClassType.PBaseException))) {
- return raiseNode.raise(SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
+ return raiseNode.raise(inliningTarget, SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
}
Object exception;
// If the exception value is already an exception object, just take it.
@@ -1566,13 +1567,14 @@ public abstract static class GraalHPyErrSetString extends HPyTernaryContextFunct
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object errTypeObj, Object charPtr,
+ @Bind("this") Node inliningTarget,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached IsSubtypeNode isSubtypeNode,
@Cached CallNode callExceptionConstructorNode,
@Cached PyExceptionInstanceCheckNode exceptionCheckNode,
@Cached PRaiseNode raiseNode) {
if (!(PGuards.isPythonClass(errTypeObj) && isSubtypeNode.execute(errTypeObj, PythonBuiltinClassType.PBaseException))) {
- return raiseNode.raise(SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
+ return raiseNode.raise(inliningTarget, SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
}
Object exception = callExceptionConstructorNode.executeWithoutFrame(errTypeObj, fromCharPointerNode.execute(charPtr));
@@ -1602,7 +1604,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object errTypeObj, Object er
Object i = callHelperFunctionNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_GET_ERRNO);
Object message = fromCharPointerNode.execute(hpyContext, callHelperFunctionNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_GET_STRERROR, i), true);
if (!isSubtypeNode.execute(errTypeObj, PythonBuiltinClassType.PBaseException)) {
- return raiseNode.raise(SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
+ return raiseNode.raise(inliningTarget, SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
}
Object exception = null;
if (!isNullNode.execute(hpyContext, errMessagePtr)) {
@@ -1639,7 +1641,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object errTypeObj, Object fi
Object i = callHelperNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_GET_ERRNO);
Object message = fromCharPointerNode.execute(callHelperNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_GET_STRERROR, i));
if (!isSubtypeNode.execute(errTypeObj, PythonBuiltinClassType.PBaseException)) {
- return raiseNode.raise(SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
+ return raiseNode.raise(inliningTarget, SystemError, ErrorMessages.EXCEPTION_NOT_BASEEXCEPTION, errTypeObj);
}
Object exception = null;
if (filenameObject1 != NULL_HANDLE_DELEGATE) {
@@ -1836,7 +1838,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object unicodeObject, Object
try {
tsUtf8 = switchEncodingNode.execute(castToTruffleStringNode.execute(inliningTarget, unicodeObject), Encoding.UTF_8);
} catch (CannotCastException e) {
- throw raiseNode.raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
InternalByteArray internalByteArray = getInternalByteArrayNode.execute(tsUtf8, Encoding.UTF_8);
if (!isNullNode.execute(hpyContext, sizePtr)) {
@@ -1924,6 +1926,7 @@ public abstract static class GraalHPyUnicodeDecodeASCII extends HPyQuaternaryCon
@Specialization
static Object doGeneric(GraalHPyContext hpyContext, Object charPtr, long size, Object errorsPtr,
+ @Bind("this") Node inliningTarget,
@Cached(parameters = "hpyContext") GraalHPyCAccess.IsNullNode isNullNode,
@Cached(parameters = "hpyContext") HPyFromCharPointerNode fromCharPointerNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.ReadI8ArrayNode readI8ArrayNode,
@@ -1943,7 +1946,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object charPtr, long size, O
return fromJavaStringNode.execute(decoded, TS_ENCODING);
}
// TODO: refactor helper nodes for CodecsModuleBuiltins to use them here
- throw raiseNode.raise(PythonBuiltinClassType.UnicodeDecodeError, ErrorMessages.MALFORMED_INPUT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.UnicodeDecodeError, ErrorMessages.MALFORMED_INPUT);
}
@TruffleBoundary
@@ -2004,11 +2007,12 @@ public abstract static class GraalHPyBytesAsString extends HPyBinaryContextFunct
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object object,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
if (object instanceof PBytes bytes) {
return PySequenceArrayWrapper.ensureNativeSequence(bytes);
}
- throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, object);
}
}
@@ -2025,7 +2029,7 @@ static long doGeneric(@SuppressWarnings("unused") Object hpyContext, Object obje
if (object instanceof PBytes) {
return lenNode.execute(inliningTarget, (PSequence) object);
}
- throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_BYTES_P_FOUND, object);
}
}
@@ -2044,7 +2048,7 @@ static PBytes doGeneric(GraalHPyContext hpyContext, Object charPtr,
try {
size = castToJavaIntNode.execute(inliningTarget, callHelperNode.call(hpyContext, GraalHPyNativeSymbol.GRAAL_HPY_STRLEN, charPtr));
} catch (PException e) {
- throw raiseNode.raise(OverflowError, ErrorMessages.BYTE_STR_IS_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.BYTE_STR_IS_TOO_LARGE);
}
byte[] bytes = readI8ArrayNode.execute(hpyContext, charPtr, 0, size);
return PFactory.createBytes(hpyContext.getContext().getLanguage(inliningTarget), bytes);
@@ -2062,10 +2066,10 @@ static PBytes doGeneric(GraalHPyContext hpyContext, Object charPtr, long lsize,
@Cached(parameters = "hpyContext") GraalHPyCAccess.ReadI8ArrayNode readI8ArrayNode,
@Cached PRaiseNode raiseNode) {
if (isNullNode.execute(hpyContext, charPtr)) {
- throw raiseNode.raise(ValueError, ErrorMessages.NULL_CHAR_PASSED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NULL_CHAR_PASSED);
}
if (lsize < 0) {
- throw raiseNode.raise(SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED);
}
PythonLanguage language = hpyContext.getContext().getLanguage(inliningTarget);
if (lsize == 0) {
@@ -2301,7 +2305,7 @@ public abstract static class GraalHPyNew extends HPyTernaryContextFunction {
static Object doGeneric(GraalHPyContext hpyContext, Object type, Object dataOutVar,
@Bind("this") Node inliningTarget,
@Cached IsTypeNode isTypeNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached(parameters = "hpyContext") GraalHPyCAccess.AllocateNode allocateNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.WritePointerNode writePointerNode,
@@ -2311,7 +2315,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object type, Object dataOutV
// check if argument is actually a type
if (!isTypeNode.execute(inliningTarget, profiledTypeObject)) {
- return raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.HPY_NEW_ARG_1_MUST_BE_A_TYPE);
+ return raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_NEW_ARG_1_MUST_BE_A_TYPE);
}
Object dataPtr = null;
@@ -2618,7 +2622,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object arrayPtr, long neleme
n = castToJavaIntExactNode.execute(inliningTarget, nelements);
} catch (CannotCastException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(castToJavaIntExactNode, PythonBuiltinClassType.MemoryError);
+ throw PRaiseNode.raiseStatic(castToJavaIntExactNode, PythonBuiltinClassType.MemoryError);
}
Object[] elements = readHPyArrayNode.execute(hpyContext, arrayPtr, 0, n);
@@ -2854,13 +2858,13 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ca
@Cached CallNode callNode,
@Cached PRaiseNode raiseNode) {
// check and expand args
- Object[] args = castArgs(argsObject, expandArgsNode, raiseNode);
+ Object[] args = castArgs(inliningTarget, argsObject, expandArgsNode, raiseNode);
// check and expand kwargs
PKeyword[] keywords = castKwargs(inliningTarget, kwargsObject, lenNode, expandKwargsNode, raiseNode);
return callNode.executeWithoutFrame(callable, args, keywords);
}
- private static Object[] castArgs(Object args,
+ private static Object[] castArgs(Node inliningTarget, Object args,
ExecutePositionalStarargsNode expandArgsNode,
PRaiseNode raiseNode) {
// this indicates that a NULL handle was passed (which is valid)
@@ -2870,7 +2874,7 @@ private static Object[] castArgs(Object args,
if (PGuards.isPTuple(args)) {
return expandArgsNode.executeWith(null, args);
}
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CALLTUPLEDICT_REQUIRES_ARGS_TUPLE_OR_NULL);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CALLTUPLEDICT_REQUIRES_ARGS_TUPLE_OR_NULL);
}
private static PKeyword[] castKwargs(Node inliningTarget, Object kwargs,
@@ -2884,7 +2888,7 @@ private static PKeyword[] castKwargs(Node inliningTarget, Object kwargs,
if (PGuards.isDict(kwargs)) {
return expandKwargsNode.execute(inliningTarget, kwargs);
}
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CALLTUPLEDICT_REQUIRES_KW_DICT_OR_NULL);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CALLTUPLEDICT_REQUIRES_KW_DICT_OR_NULL);
}
private static boolean isEmptyDict(Node inliningTarget, Object delegate, HashingStorageLen lenNode) {
@@ -2905,7 +2909,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object callable, Object args
@Cached PRaiseNode raiseNode) {
if (!PInt.isIntRange(lnargs)) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
}
int nargs = (int) lnargs;
PTuple kwnames;
@@ -2955,7 +2959,7 @@ static Object doGeneric(GraalHPyContext hpyContext, TruffleString name, Object a
@Cached PRaiseNode raiseNode) {
if (!PInt.isIntRange(lnargs)) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
}
int nargs = (int) lnargs;
int nkw = kwnames != PNone.NO_VALUE ? tupleSizeNode.execute(inliningTarget, kwnames) : 0;
@@ -3069,7 +3073,7 @@ static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Obj
int len = codepointLengthNode.execute(name, TS_ENCODING);
int dotIdx = indexOfCodepointNode.execute(name, '.', 0, len, TS_ENCODING);
if (dotIdx < 0) {
- throw raiseNode.raise(SystemError, ErrorMessages.NAME_MUST_BE_MOD_CLS);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.NAME_MUST_BE_MOD_CLS);
}
if (base == PNone.NO_VALUE) {
@@ -3087,7 +3091,7 @@ static Object createNewExceptionWithDoc(Node inliningTarget, Object namePtr, Obj
* CPython expects a PyDictObject and if not, it raises a
* ErrorMessages.BAD_INTERNAL_CALL.
*/
- throw raiseNode.raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
dict = (PDict) dictObj;
dictStorage = dict.getDictStorage();
@@ -3333,11 +3337,11 @@ public abstract static class GraalHPyDictKeys extends HPyBinaryContextFunction {
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object dictObj,
@Bind("this") Node inliningTarget,
@Cached PyDictKeys keysNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (dictObj instanceof PDict dict) {
return keysNode.execute(inliningTarget, dict);
}
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
}
@@ -3348,11 +3352,11 @@ public abstract static class GraalHPyDictCopy extends HPyBinaryContextFunction {
static Object doGeneric(GraalHPyContext hpyContext, Object dictObj,
@Bind("this") Node inliningTarget,
@Cached HashingStorageCopy copyNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (dictObj instanceof PDict dict) {
return PFactory.createDict(hpyContext.getContext().getLanguage(inliningTarget), copyNode.execute(inliningTarget, dict.getDictStorage()));
}
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
}
@@ -3375,14 +3379,14 @@ static PyCapsule doGeneric(GraalHPyContext hpyContext, Object pointer, Object na
@Cached(parameters = "hpyContext") GraalHPyCAccess.IsNullNode isNullNode,
@Cached PRaiseNode raiseNode) {
if (isNullNode.execute(hpyContext, pointer)) {
- throw raiseNode.raise(ValueError, ErrorMessages.HPYCAPSULE_NEW_NULL_PTR_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.HPYCAPSULE_NEW_NULL_PTR_ERROR);
}
Object hpyDestructor = null;
if (!isNullNode.execute(hpyContext, dtorPtr)) {
Object cpyTrampoline = readPointerNode.read(hpyContext, dtorPtr, GraalHPyCField.HPyCapsule_Destructor__cpy_trampoline);
hpyDestructor = readPointerNode.read(hpyContext, dtorPtr, GraalHPyCField.HPyCapsule_Destructor__impl);
if (isNullNode.execute(hpyContext, cpyTrampoline) || isNullNode.execute(hpyContext, hpyDestructor)) {
- throw raiseNode.raise(ValueError, ErrorMessages.INVALID_HPYCAPSULE_DESTRUCTOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_HPYCAPSULE_DESTRUCTOR);
}
}
PyCapsule capsule = PFactory.createCapsuleNativeName(hpyContext.getContext().getLanguage(inliningTarget), pointer, namePtr);
@@ -3403,13 +3407,13 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ca
@Bind("this") Node inliningTarget,
@Cached PyCapsuleNameMatchesNode nameMatchesNode,
@Cached PRaiseNode raiseNode) {
- isLegalCapsule(capsule, key, raiseNode);
+ isLegalCapsule(inliningTarget, capsule, key, raiseNode);
PyCapsule pyCapsule = (PyCapsule) capsule;
Object result;
switch (key) {
case CapsuleKey.Pointer -> {
if (!nameMatchesNode.execute(inliningTarget, pyCapsule.getNamePtr(), namePtr)) {
- throw raiseNode.raise(ValueError, INCORRECT_NAME);
+ throw raiseNode.raise(inliningTarget, ValueError, INCORRECT_NAME);
}
result = pyCapsule.getPointer();
}
@@ -3425,9 +3429,9 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ca
return result;
}
- public static void isLegalCapsule(Object object, int key, PRaiseNode raiseNode) {
+ public static void isLegalCapsule(Node inliningTarget, Object object, int key, PRaiseNode raiseNode) {
if (!(object instanceof PyCapsule) || ((PyCapsule) object).getPointer() == null) {
- throw raiseNode.raise(ValueError, getErrorMessage(key));
+ throw raiseNode.raise(inliningTarget, ValueError, getErrorMessage(key));
}
}
@@ -3448,15 +3452,16 @@ public static TruffleString getErrorMessage(int key) {
public abstract static class GraalHPyCapsuleSet extends HPyQuaternaryContextFunction {
@Specialization
static int doGeneric(GraalHPyContext hpyContext, Object capsule, int key, Object valuePtr,
+ @Bind("this") Node inliningTarget,
@Cached(parameters = "hpyContext") GraalHPyCAccess.IsNullNode isNullNode,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached PRaiseNode raiseNode) {
- GraalHPyCapsuleGet.isLegalCapsule(capsule, key, raiseNode);
+ GraalHPyCapsuleGet.isLegalCapsule(inliningTarget, capsule, key, raiseNode);
PyCapsule pyCapsule = (PyCapsule) capsule;
switch (key) {
case CapsuleKey.Pointer -> {
if (isNullNode.execute(hpyContext, valuePtr)) {
- throw raiseNode.raise(ValueError, ErrorMessages.CAPSULE_SETPOINTER_CALLED_WITH_NULL_POINTER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CAPSULE_SETPOINTER_CALLED_WITH_NULL_POINTER);
}
pyCapsule.setPointer(valuePtr);
}
@@ -3504,7 +3509,7 @@ static int doGeneric(GraalHPyContext hpyContext, Object var, Object def, Object
@Cached PRaiseNode raiseNode,
@Cached(parameters = "hpyContext") GraalHPyCAccess.WriteHPyNode writeHPyNode) {
if (!(var instanceof PContextVar contextVar)) {
- throw raiseNode.raise(TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
}
PythonContext context = hpyContext.getContext();
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
@@ -3536,7 +3541,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object var, Object val,
@Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode) {
if (!(var instanceof PContextVar contextVar)) {
- throw raiseNode.raise(TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
}
PythonContext context = hpyContext.getContext();
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
@@ -3557,7 +3562,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object obj, Object encodingP
@Cached(parameters = "hpyContext") HPyFromCharPointerNode fromNativeCharPointerNode,
@Cached PyUnicodeFromEncodedObject libNode) {
if (nullProfile.profile(inliningTarget, obj == PNone.NO_VALUE)) {
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
TruffleString encoding;
if (!isNullNode.execute(hpyContext, encodingPtr)) {
@@ -3592,7 +3597,7 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ob
int start = castStart.execute(inliningTarget, lstart);
int end = castEnd.execute(inliningTarget, lend);
if (profile.profile(inliningTarget, start < 0 || end < 0)) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
SliceInfo sliceInfo = PSlice.computeIndices(start, end, 1, codePointLengthNode.execute(value, TS_ENCODING));
return getSlice.execute(value, sliceInfo);
@@ -3630,7 +3635,7 @@ static int doGeneric(@SuppressWarnings("unused") Object hpyContext, Object typeO
Object profiledTypeObject = classProfile.profile(inliningTarget, typeObject);
int result = GraalHPyDef.getBuiltinShapeFromHiddenAttribute(profiledTypeObject);
if (result == -2) {
- throw raiseNode.raise(TypeError, ErrorMessages.S_MUST_BE_S, "arg", "type");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_MUST_BE_S, "arg", "type");
}
return result;
}
@@ -3641,6 +3646,7 @@ static int doGeneric(@SuppressWarnings("unused") Object hpyContext, Object typeO
public abstract static class GraalHPyCompile extends HPyQuaternaryContextFunction {
@Specialization
static Object doGeneric(GraalHPyContext hpyContext, Object srcPtr, Object filenamePtr, int kind,
+ @Bind("this") Node inliningTarget,
@Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
@Cached FromCharPointerNode fromCharPointerNode,
@Cached CallNode callNode,
@@ -3650,7 +3656,7 @@ static Object doGeneric(GraalHPyContext hpyContext, Object srcPtr, Object filena
Object builtinFunction = readAttributeFromObjectNode.execute(hpyContext.getContext().getBuiltins(), BuiltinNames.T_COMPILE);
GraalHPySourceKind sourceKind = GraalHPySourceKind.fromValue(kind);
if (sourceKind == null) {
- throw raiseNode.raise(SystemError, ErrorMessages.HPY_INVALID_SOURCE_KIND);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.HPY_INVALID_SOURCE_KIND);
}
return callNode.executeWithoutFrame(builtinFunction, src, filename, sourceKind.getMode());
}
@@ -3679,7 +3685,7 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, PCode cod
if (globals instanceof PythonObject) {
PArguments.setGlobals(pArguments, (PythonObject) globals);
} else {
- throw raiseNode.raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
}
RootCallTarget rootCallTarget = getCallTargetNode.execute(inliningTarget, code);
@@ -3700,7 +3706,7 @@ static int doGeneric(GraalHPyContext hpyContext, PythonObject object, Object cal
Object clazz = getClassNode.execute(inliningTarget, object);
if (!(clazz instanceof PythonClass pythonClass) || !pythonClass.isHPyType()) {
errorProfile.enter(inliningTarget);
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.HPY_TYPE_DOES_NOT_IMPLEMENT_CALL_PROTOCOL, clazz);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.HPY_TYPE_DOES_NOT_IMPLEMENT_CALL_PROTOCOL, clazz);
}
Object callFunction = readCallFunctionNode.execute(inliningTarget, hpyContext, callFunctionDefPtr);
GraalHPyData.setHPyCallFunction(object, callFunction);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
index de9a964821..b343ff1d62 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyMemberAccessNodes.java
@@ -220,13 +220,13 @@ protected HPyReadMemberNode(int offset, int type, CExtAsPythonObjectNode asPytho
@Specialization
Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
GraalHPyContext hPyContext = getContext().getHPyContext();
Object nativeSpacePtr = ensureReadNativeSpaceNode().executeCached(self);
if (nativeSpacePtr == PNone.NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.ATTEMPTING_READ_FROM_OFFSET_D, offset, self);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.ATTEMPTING_READ_FROM_OFFSET_D, offset, self);
}
Object nativeResult;
switch (type) {
@@ -237,7 +237,7 @@ Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self,
if (type == HPY_MEMBER_OBJECT) {
return PNone.NONE;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError);
}
}
return fieldValue;
@@ -342,8 +342,8 @@ protected HPyReadOnlyMemberNode(TruffleString propertyName) {
@Specialization
@SuppressWarnings("unused")
Object doGeneric(Object self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, propertyName, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, propertyName, self);
}
@TruffleBoundary
@@ -361,12 +361,12 @@ protected abstract static class HPyBadMemberDescrNode extends PythonBinaryBuilti
@Specialization
static Object doGeneric(Object self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
if (value == DescriptorDeleteMarker.INSTANCE) {
// This node is actually only used for T_NONE, so this error message is right.
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
}
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_P, self);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_P, self);
}
@TruffleBoundary
@@ -407,14 +407,14 @@ protected HPyWriteMemberNode(int type, int offset) {
@Specialization
Object doGeneric(VirtualFrame frame, Object self, Object value,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = getContext();
GraalHPyContext hPyContext = context.getHPyContext();
Object nativeSpacePtr = ensureReadNativeSpaceNode().executeCached(self);
if (nativeSpacePtr == PNone.NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.SystemError, ErrorMessages.ATTEMPTING_WRITE_OFFSET_D, offset, self);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.ATTEMPTING_WRITE_OFFSET_D, offset, self);
}
/*
@@ -427,13 +427,13 @@ Object doGeneric(VirtualFrame frame, Object self, Object value,
if (self instanceof PythonObject pythonObject) {
Object oldValue = ensureReadHPyFieldNode(hPyContext).read(hPyContext, pythonObject, nativeSpacePtr, offset);
if (oldValue == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError);
}
} else {
throw CompilerDirectives.shouldNotReachHere("Cannot have HPyField on non-Python object");
}
} else if (type != HPY_MEMBER_OBJECT) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE);
}
// NO_VALUE will be converted to the NULL handle
newValue = PNone.NO_VALUE;
@@ -524,7 +524,7 @@ Object doGeneric(VirtualFrame frame, Object self, Object value,
case HPY_MEMBER_BOOL:
// note: exact type check is sufficient; bool cannot be subclassed
if (!ensureIsBuiltinObjectProfile().profileObject(this, newValue, PythonBuiltinClassType.Boolean)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_VALUE_MUST_BE_BOOL);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_VALUE_MUST_BE_BOOL);
}
val = ensureIsNode().isTrue(newValue) ? 1 : 0;
ensureWriteGenericNode(hPyContext).execute(hPyContext, nativeSpacePtr, offset, Bool, val);
@@ -544,7 +544,7 @@ Object doGeneric(VirtualFrame frame, Object self, Object value,
ensureWriteGenericNode(hPyContext).execute(hPyContext, nativeSpacePtr, offset, HPyContextSignatureType.HPy_ssize_t, val);
break;
default:
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_S, "");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.BAD_MEMBER_DESCR_TYPE_FOR_S, "");
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
index 9de14d1240..2a36d5cf01 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNativeContext.java
@@ -239,7 +239,7 @@ public static PException checkThrowableBeforeNative(Throwable t, String where1,
out.println("should not throw exceptions apart from PException");
t.printStackTrace(out);
out.flush();
- throw PRaiseNode.raiseUncached(null, SystemError, ErrorMessages.INTERNAL_EXCEPTION_OCCURED);
+ throw PRaiseNode.raiseStatic(null, SystemError, ErrorMessages.INTERNAL_EXCEPTION_OCCURED);
}
public abstract AllocateNode createAllocateNode();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
index fbf5f3b277..5228f2d329 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java
@@ -297,10 +297,9 @@ public static int raiseIntUncached(GraalHPyContext nativeContext, int errorValue
@Specialization
static int doInt(Frame frame, GraalHPyContext nativeContext, int errorValue, PythonBuiltinClassType errType, TruffleString format, Object[] arguments,
@Bind("this") Node inliningTarget,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode,
@Shared("transformExceptionToNativeNode") @Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode) {
try {
- throw raiseNode.execute(raiseNode, errType, PNone.NO_VALUE, format, arguments);
+ throw PRaiseNode.raiseStatic(inliningTarget, errType, format, arguments);
} catch (PException p) {
transformExceptionToNativeNode.execute(frame, inliningTarget, nativeContext, p);
}
@@ -310,10 +309,9 @@ static int doInt(Frame frame, GraalHPyContext nativeContext, int errorValue, Pyt
@Specialization
static Object doObject(Frame frame, GraalHPyContext nativeContext, Object errorValue, PythonBuiltinClassType errType, TruffleString format, Object[] arguments,
@Bind("this") Node inliningTarget,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode,
@Shared("transformExceptionToNativeNode") @Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode) {
try {
- throw raiseNode.execute(raiseNode, errType, PNone.NO_VALUE, format, arguments);
+ throw PRaiseNode.raiseStatic(inliningTarget, errType, format, arguments);
} catch (PException p) {
transformExceptionToNativeNode.execute(frame, inliningTarget, nativeContext, p);
}
@@ -425,9 +423,10 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
size = readGenericNode.readLong(context, moduleDefPtr, GraalHPyCField.HPyModuleDef__size);
if (size < 0) {
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, tsLiteral("HPy does not permit HPyModuleDef.size < 0"));
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, tsLiteral("HPy does not permit HPyModuleDef.size < 0"));
} else if (size > 0) {
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, tsLiteral("Module state is not supported yet in HPy, set HPyModuleDef.size = 0 if module state is not needed"));
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError,
+ tsLiteral("Module state is not supported yet in HPy, set HPyModuleDef.size = 0 if module state is not needed"));
}
// process HPy module slots
@@ -453,13 +452,13 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
switch (slotData.slot) {
case HPY_MOD_CREATE -> {
if (createFunction != null) {
- throw raiseNode.raise(PythonErrorType.SystemError, ErrorMessages.MODULE_HAS_MULTIPLE_CREATE_SLOTS, mName);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.MODULE_HAS_MULTIPLE_CREATE_SLOTS, mName);
}
createFunction = slotData.impl;
}
case HPY_MOD_EXEC -> {
if (createFunction != null) {
- throw raiseNode.raise(PythonErrorType.SystemError, ErrorMessages.HPY_DEFINES_CREATE_AND_OTHER_SLOTS, mName);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.HPY_DEFINES_CREATE_AND_OTHER_SLOTS, mName);
}
/*
* In contrast to CPython, we already parse and store the
@@ -468,7 +467,7 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
*/
executeSlots.add(slotData.impl);
}
- default -> throw raiseNode.raise(PythonErrorType.SystemError, ErrorMessages.MODULE_USES_UNKNOW_SLOT_ID, mName, slotData.slot);
+ default -> throw raiseNode.raise(inliningTarget, PythonErrorType.SystemError, ErrorMessages.MODULE_USES_UNKNOW_SLOT_ID, mName, slotData.slot);
}
break;
case GraalHPyDef.HPY_DEF_KIND_MEMBER:
@@ -503,11 +502,11 @@ static Object doGeneric(GraalHPyContext context, TruffleString mName, Object spe
* 'size > 0')
*/
if (hasLegacyMethods || mDoc != null || nModuleGlobals != 0) {
- throw raiseNode.raise(SystemError, ErrorMessages.HPY_DEFINES_CREATE_AND_NON_DEFAULT);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.HPY_DEFINES_CREATE_AND_NON_DEFAULT);
}
module = callCreate(inliningTarget, createFunction, context, spec, checkFunctionResultNode, asHandleNode, createLib);
if (module instanceof PythonModule) {
- throw raiseNode.raise(SystemError, ErrorMessages.HPY_MOD_CREATE_RETURNED_BUILTIN_MOD);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.HPY_MOD_CREATE_RETURNED_BUILTIN_MOD);
}
} else {
PythonModule pmodule = PFactory.createPythonModule(language, mName);
@@ -583,9 +582,9 @@ static Object callCreate(Node inliningTarget, Object callable, GraalHPyContext h
try {
return checkFunctionResultNode.execute(pythonThreadState, CREATE, lib.execute(callable, hPyContext.getBackend(), hSpec));
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, CREATE, e);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, CREATE, e);
} catch (ArityException e) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, CREATE, e.getExpectedMinArity(), e.getActualArity());
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, CREATE, e.getExpectedMinArity(), e.getActualArity());
} finally {
// close all handles (if necessary)
if (hSpec.isAllocated()) {
@@ -635,9 +634,9 @@ static void callExec(Node node, GraalHPyContext hPyContext, Object callable, Pyt
try {
checkFunctionResultNode.execute(pythonThreadState, T_EXEC, lib.execute(callable, hPyContext.getBackend(), hModule));
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, T_EXEC, e);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, T_EXEC, e);
} catch (ArityException e) {
- throw PRaiseNode.raiseUncached(node, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, T_EXEC, e.getExpectedMinArity(), e.getActualArity());
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, T_EXEC, e.getExpectedMinArity(), e.getActualArity());
} finally {
// close all handles (if necessary)
if (hModule.isAllocated()) {
@@ -688,7 +687,7 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object enclosingType, Obje
Object methodFunctionPointer;
signature = HPyFuncSignature.fromValue(readGenericNode.readInt(context, methodDef, GraalHPyCField.HPyDef__meth__signature));
if (signature == null) {
- throw raiseNode.raise(PythonBuiltinClassType.ValueError, ErrorMessages.UNSUPPORTED_HYPMETH_SIG);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.UNSUPPORTED_HYPMETH_SIG);
}
methodFunctionPointer = readPointerNode.read(context, methodDef, GraalHPyCField.HPyDef__meth__impl);
@@ -1126,7 +1125,7 @@ static HPySlotData doIt(Node inliningTarget, GraalHPyContext context, Object slo
HPySlot slot = HPySlot.fromValue(slotNr);
if (slot == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.INVALID_SLOT_VALUE, slotNr);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.INVALID_SLOT_VALUE, slotNr);
}
// read and check the function pointer
@@ -1203,10 +1202,10 @@ static Object doIt(GraalHPyContext context, PythonClass enclosingType, TpSlots.B
*/
if (HPY_TP_CALL.equals(slot)) {
if (enclosingType.getItemSize() > 0) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CANNOT_USE_CALL_WITH_VAR_OBJECTS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CANNOT_USE_CALL_WITH_VAR_OBJECTS);
}
if (enclosingType.getBuiltinShape() == GraalHPyDef.HPyType_BUILTIN_SHAPE_LEGACY && enclosingType.getBasicSize() == 0) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CANNOT_USE_CALL_WITH_LEGACY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CANNOT_USE_CALL_WITH_LEGACY);
}
enclosingType.setHPyDefaultCallFunc(slotData.impl());
}
@@ -1243,7 +1242,7 @@ static boolean doIt(GraalHPyContext context, Object enclosingType, TpSlots.Build
@Cached ReadPropertyNode readPropertyNode,
@Cached WritePropertyNode writePropertyNode,
@CachedLibrary(limit = "1") InteropLibrary lib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// computes '&(slotDefArrPtr[i].slot)'
long slotIdOffset = ReadGenericNode.getElementPtr(context, i, context.getCTypeSize(HPyContextSignatureType.PyType_Slot), GraalHPyCField.PyType_Slot__slot);
@@ -1255,7 +1254,7 @@ static boolean doIt(GraalHPyContext context, Object enclosingType, TpSlots.Build
HPyLegacySlot slot = HPyLegacySlot.fromValue(slotId);
if (slot == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.INVALID_SLOT_VALUE, slotId);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.INVALID_SLOT_VALUE, slotId);
}
// computes '&(slotDefArrPtr[i].pfunc)'
@@ -2333,14 +2332,14 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
// extract bases from type spec params
PTuple bases = extractBases(typeSpecParams, language);
// extract metaclass from type spec params
- Object metatype = getMetatype(typeSpecParams, raiseNode);
+ Object metatype = getMetatype(inliningTarget, typeSpecParams);
if (metatype != null) {
if (!isTypeNode.execute(inliningTarget, metatype)) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_METACLASS_IS_NOT_A_TYPE, metatype);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_METACLASS_IS_NOT_A_TYPE, metatype);
}
if (!hasSameConstructorNode.execute(inliningTarget, metatype, PythonBuiltinClassType.PythonClass)) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_METACLASS_WITH_CUSTOM_CONS_NOT_SUPPORTED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_METACLASS_WITH_CUSTOM_CONS_NOT_SUPPORTED);
}
}
@@ -2383,7 +2382,7 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
long flags = readI32Node.readUnsigned(context, typeSpec, GraalHPyCField.HPyType_Spec__flags);
int builtinShape = readI32Node.read(context, typeSpec, GraalHPyCField.HPyType_Spec__builtin_shape);
if (!GraalHPyDef.isValidBuiltinShape(builtinShape)) {
- throw raiseNode.raise(ValueError, ErrorMessages.HPY_INVALID_BUILTIN_SHAPE, builtinShape);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.HPY_INVALID_BUILTIN_SHAPE, builtinShape);
}
long basicSize = readI32Node.read(context, typeSpec, GraalHPyCField.HPyType_Spec__basicsize);
@@ -2448,18 +2447,18 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
* '__vectorcalloffset__'.
*/
if (newType.getHPyVectorcallOffset() != Long.MIN_VALUE && newType.getHPyDefaultCallFunc() != null) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CANNOT_HAVE_CALL_AND_VECTORCALLOFFSET);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CANNOT_HAVE_CALL_AND_VECTORCALLOFFSET);
}
if (needsTpTraverse) {
- throw raiseNode.raise(ValueError, ErrorMessages.TRAVERSE_FUNCTION_NEEDED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TRAVERSE_FUNCTION_NEEDED);
}
// process legacy slots; this is of type 'cpy_PyTypeSlot legacy_slots[]'
Object legacySlotsArrPtr = readPointerNode.read(context, typeSpec, GraalHPyCField.HPyType_Spec__legacy_slots);
if (!isNullNode.execute(context, legacySlotsArrPtr)) {
if (builtinShape != GraalHPyDef.HPyType_BUILTIN_SHAPE_LEGACY) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_CANNOT_SPECIFY_LEG_SLOTS_WO_SETTING_LEG);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HPY_CANNOT_SPECIFY_LEG_SLOTS_WO_SETTING_LEG);
}
for (int i = 0;; i++) {
if (!createLegacySlotNode.execute(context, newType, tpSlotsBuilder, legacySlotsArrPtr, i)) {
@@ -2507,10 +2506,10 @@ static Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpe
baseFlags = 0;
}
int baseBuiltinShape = GraalHPyDef.getBuiltinShapeFromHiddenAttribute(baseClass);
- checkInheritanceConstraints(flags, baseFlags, builtinShape, baseBuiltinShape > GraalHPyDef.HPyType_BUILTIN_SHAPE_LEGACY, raiseNode);
+ checkInheritanceConstraints(inliningTarget, flags, baseFlags, builtinShape, baseBuiltinShape > GraalHPyDef.HPyType_BUILTIN_SHAPE_LEGACY, raiseNode);
return newType;
} catch (CannotCastException e) {
- throw raiseNode.raise(SystemError, ErrorMessages.COULD_NOT_CREATE_TYPE_FROM_SPEC_BECAUSE, e);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.COULD_NOT_CREATE_TYPE_FROM_SPEC_BECAUSE, e);
}
}
@@ -2596,17 +2595,17 @@ private static PTuple extractBases(HPyTypeSpecParam[] typeSpecParams, PythonLang
* Reference implementation can be found in {@code ctx_type.c:get_metatype}
*/
@TruffleBoundary
- private static Object getMetatype(HPyTypeSpecParam[] typeSpecParams, PRaiseNode raiseNode) {
+ private static Object getMetatype(Node inliningTarget, HPyTypeSpecParam[] typeSpecParams) {
Object result = null;
if (typeSpecParams != null) {
for (HPyTypeSpecParam typeSpecParam : typeSpecParams) {
if (typeSpecParam.kind() == GraalHPyDef.HPyType_SPEC_PARAM_METACLASS) {
if (result != null) {
- throw raiseNode.raise(ValueError, ErrorMessages.HPY_METACLASS_SPECIFIED_MULTIPLE_TIMES);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.HPY_METACLASS_SPECIFIED_MULTIPLE_TIMES);
}
result = typeSpecParam.object();
if (!IsTypeNode.executeUncached(result)) {
- throw raiseNode.raise(TypeError, ErrorMessages.HPY_METACLASS_IS_NOT_A_TYPE, result);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.HPY_METACLASS_IS_NOT_A_TYPE, result);
}
}
}
@@ -2614,7 +2613,7 @@ private static Object getMetatype(HPyTypeSpecParam[] typeSpecParams, PRaiseNode
return result;
}
- private static void checkInheritanceConstraints(long flags, long baseFlags, int builtinShape, boolean baseIsPure, PRaiseNode raiseNode) {
+ private static void checkInheritanceConstraints(Node inliningTarget, long flags, long baseFlags, int builtinShape, boolean baseIsPure, PRaiseNode raiseNode) {
// Pure types may inherit from:
//
// * pure types, or
@@ -2627,7 +2626,7 @@ private static void checkInheritanceConstraints(long flags, long baseFlags, int
// See https://github.com/hpyproject/hpy/issues/169 for details.
assert GraalHPyDef.isValidBuiltinShape(builtinShape);
if (builtinShape == GraalHPyDef.HPyType_BUILTIN_SHAPE_LEGACY && baseIsPure) {
- throw raiseNode.raise(TypeError, ErrorMessages.LEG_TYPE_SHOULDNT_INHERIT_MEM_LAYOUT_FROM_PURE_TYPE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.LEG_TYPE_SHOULDNT_INHERIT_MEM_LAYOUT_FROM_PURE_TYPE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
index a51505dd58..a270b04aed 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java
@@ -121,6 +121,7 @@
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
public abstract class HPyExternalFunctionNodes {
@@ -365,6 +366,7 @@ public abstract static class HPyExternalFunctionInvokeNode extends Node {
@Specialization(limit = "1")
Object doIt(VirtualFrame frame, TruffleString name, Object callable, GraalHPyContext hPyContext, Object[] arguments,
+ @Bind("this") Node inliningTarget,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("callable") InteropLibrary lib,
@Cached PRaiseNode raiseNode) {
@@ -385,9 +387,9 @@ Object doIt(VirtualFrame frame, TruffleString name, Object callable, GraalHPyCon
try {
return checkFunctionResultNode.execute(pythonThreadState, name, lib.execute(callable, convertedArguments));
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, name, e);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_FAILED, name, e);
} catch (ArityException e) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, name, e.getExpectedMinArity(), e.getActualArity());
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CALLING_NATIVE_FUNC_EXPECTED_ARGS, name, e.getExpectedMinArity(), e.getActualArity());
} finally {
// special case after calling a C function: transfer caught exception back to frame
// to simulate the global state semantics
@@ -926,7 +928,7 @@ static final class HPyMethObjObjArgProcRoot extends HPyMethodDescriptorRootNode
@Child private ReadIndexedArgumentNode readArg1Node;
@Child private ReadVarArgsNode readVarargsNode;
- @Child private PRaiseNode raiseNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
public HPyMethObjObjArgProcRoot(PythonLanguage language, TruffleString name) {
super(language, name, HPyCheckPrimitiveResultNodeGen.create(), HPyAllAsHandleNodeGen.create());
@@ -940,20 +942,12 @@ protected Object[] prepareCArguments(VirtualFrame frame, @SuppressWarnings("unus
} else if (varargs.length == 1) {
return new Object[]{getSelf(frame), getArg1(frame), varargs[0]};
} else {
- throw getRaiseNode().raise(PythonBuiltinClassType.TypeError,
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError,
ErrorMessages.TAKES_FROM_D_TO_D_POS_ARG_S_BUT_D_S_GIVEN_S,
getName(), 2, 3, "s", 1 + varargs.length, "were", "");
}
}
- private PRaiseNode getRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
-
private Object[] getVarargs(VirtualFrame frame) {
if (readVarargsNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1135,7 +1129,7 @@ static long doLong(PythonThreadState pythonThreadState, TruffleString name, long
static Object doObject(PythonThreadState pythonThreadState, TruffleString name, Object value,
@Bind("this") Node inliningTarget,
@CachedLibrary("value") InteropLibrary lib,
- @Shared @Cached PRaiseNode.Lazy raiseNode,
+ @Shared @Cached PRaiseNode raiseNode,
@Shared @Cached TransformExceptionFromNativeNode transformExceptionFromNativeNode) {
if (lib.fitsInLong(value)) {
try {
@@ -1146,7 +1140,7 @@ static Object doObject(PythonThreadState pythonThreadState, TruffleString name,
throw CompilerDirectives.shouldNotReachHere();
}
}
- throw raiseNode.get(inliningTarget).raise(SystemError, ErrorMessages.FUNC_S_DIDNT_RETURN_INT, name);
+ throw raiseNode.raise(inliningTarget, SystemError, ErrorMessages.FUNC_S_DIDNT_RETURN_INT, name);
}
}
@@ -1372,7 +1366,7 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
Object nativeSpacePtr = getNativeSpacePointerNode.executeCached(objects[0]);
if (nativeSpacePtr == PNone.NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.ATTEMPTING_GETTER_NO_NATIVE_SPACE);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.ATTEMPTING_GETTER_NO_NATIVE_SPACE);
}
objects[0] = new PythonAbstractNativeObject(nativeSpacePtr);
return objects;
@@ -1454,7 +1448,7 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
Object nativeSpacePtr = getNativeSpacePointerNode.executeCached(objects[0]);
if (nativeSpacePtr == PNone.NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.ATTEMPTING_SETTER_NO_NATIVE_SPACE);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.ATTEMPTING_SETTER_NO_NATIVE_SPACE);
}
objects[0] = new PythonAbstractNativeObject(nativeSpacePtr);
return objects;
@@ -1777,7 +1771,7 @@ public Object execute(VirtualFrame frame) {
callable = null;
}
if (callable == null) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.HPY_OBJECT_DOES_NOT_SUPPORT_CALL, self);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.HPY_OBJECT_DOES_NOT_SUPPORT_CALL, self);
}
getCalleeContext().enter(frame);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
index 1a703b622c..7289ec2e46 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/jni/GraalHPyJNIContext.java
@@ -1470,7 +1470,7 @@ public long ctxContextVarGet(long varBits, long defBits, long errBits) {
Object var = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(varBits));
if (!(var instanceof PContextVar)) {
try {
- throw PRaiseNode.raiseUncached(null, TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
} catch (PException e) {
HPyTransformExceptionToNativeNode.executeUncached(context, e);
}
@@ -1550,7 +1550,7 @@ public long ctxCapsuleGet(long capsuleBits, int key, long namePtr) {
if (!(capsule instanceof PyCapsule pyCapsule) || pyCapsule.getPointer() == null) {
return HPyRaiseNodeGen.getUncached().raiseIntWithoutFrame(context, 0, ValueError, GraalHPyCapsuleGet.getErrorMessage(key));
}
- GraalHPyCapsuleGet.isLegalCapsule(capsule, key, PRaiseNode.getUncached());
+ GraalHPyCapsuleGet.isLegalCapsule(null, capsule, key, PRaiseNode.getUncached());
Object result;
switch (key) {
case CapsuleKey.Pointer -> {
@@ -1839,13 +1839,13 @@ public long ctxGetItemi(long hCollection, long lidx) {
try {
// If handle 'hCollection' is a boxed int or double, the object is not subscriptable.
if (!GraalHPyBoxing.isBoxedHandle(hCollection)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_NOT_SUBSCRIPTABLE, 0);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.OBJ_NOT_SUBSCRIPTABLE, 0);
}
Object receiver = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(hCollection));
Object clazz = GetClassNode.executeUncached(receiver);
if (clazz == PythonBuiltinClassType.PList || clazz == PythonBuiltinClassType.PTuple) {
if (!PInt.isIntRange(lidx)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, lidx);
+ throw PRaiseNode.raiseStatic(null, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, lidx);
}
int idx = (int) lidx;
PSequence sequence = (PSequence) receiver;
@@ -1893,7 +1893,7 @@ public int ctxSetItem(long hSequence, long hKey, long hValue) {
try {
// If handle 'hSequence' is a boxed int or double, the object is not a sequence.
if (!GraalHPyBoxing.isBoxedHandle(hSequence)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
}
Object receiver = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(hSequence));
Object clazz = GetClassNode.executeUncached(receiver);
@@ -1937,7 +1937,7 @@ public int ctxSetItemi(long hSequence, long lidx, long hValue) {
try {
// If handle 'hSequence' is a boxed int or double, the object is not a sequence.
if (!GraalHPyBoxing.isBoxedHandle(hSequence)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
}
Object receiver = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(hSequence));
Object clazz = GetClassNode.executeUncached(receiver);
@@ -1958,7 +1958,7 @@ public int ctxSetItemi(long hSequence, long lidx, long hValue) {
private boolean ctxListSetItem(Object receiver, long lidx, long hValue) {
// fast path for list
if (!PInt.isIntRange(lidx)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, lidx);
+ throw PRaiseNode.raiseStatic(null, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, lidx);
}
int idx = (int) lidx;
PList sequence = (PList) receiver;
@@ -2603,7 +2603,7 @@ public long ctxCall(long callable, long args, long lnargs, long kwnames) {
assert args != 0 || lnargs == 0;
try {
if (!PInt.isIntRange(lnargs)) {
- throw PRaiseNode.raiseUncached(null, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, 0);
}
int nargs = (int) lnargs;
Object callableObj = context.getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(callable));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/llvm/GraalHPyLLVMNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/llvm/GraalHPyLLVMNodes.java
index f48b29dcc6..e05918ba65 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/llvm/GraalHPyLLVMNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/llvm/GraalHPyLLVMNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -322,7 +322,7 @@ static Object[] doPointer(GraalHPyContext ctx, Object pointer, long offset, long
throw CompilerDirectives.shouldNotReachHere(e);
} catch (InvalidArrayIndexException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(arrayLib, SystemError, ErrorMessages.CANNOT_ACCESS_IDX, e.getInvalidIndex(), n);
+ throw PRaiseNode.raiseStatic(arrayLib, SystemError, ErrorMessages.CANNOT_ACCESS_IDX, e.getInvalidIndex(), n);
}
}
@@ -900,14 +900,14 @@ static Object doIt(Node inliningTarget, GraalHPyContext context, GraalHPyNativeS
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
@Cached HPyLLVMImportSymbolNode importCExtSymbolNode,
@Cached EnsureTruffleStringNode ensureTruffleStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
Object llvmFunction = importCExtSymbolNode.execute(inliningTarget, context, name);
return ensureTruffleStringNode.execute(inliningTarget, interopLibrary.execute(llvmFunction, args));
} catch (UnsupportedTypeException | ArityException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, e);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, e);
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.HPY_CAPI_SYM_NOT_CALLABLE, name);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.HPY_CAPI_SYM_NOT_CALLABLE, name);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CConstants.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CConstants.java
index 47f21f9fb1..f4ee44d620 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CConstants.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CConstants.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -90,7 +90,7 @@ public int intValue() {
CompilerDirectives.transferToInterpreterAndInvalidate();
resolve();
if (intValue == -1) {
- throw PRaiseNode.raiseUncached(null, SystemError, INTERNAL_INT_OVERFLOW);
+ throw PRaiseNode.raiseStatic(null, SystemError, INTERNAL_INT_OVERFLOW);
}
return intValue;
}
@@ -104,10 +104,10 @@ private static void resolve() {
for (CConstants constant : VALUES) {
constant.longValue = constants[constant.ordinal()];
if (constant.longValue == -1) {
- throw PRaiseNode.raiseUncached(null, SystemError, toTruffleStringUncached("internal limitation - cannot extract constants with value '-1'"));
+ throw PRaiseNode.raiseStatic(null, SystemError, toTruffleStringUncached("internal limitation - cannot extract constants with value '-1'"));
}
if ((constant.longValue & 0xFFFF0000L) == 0xDEAD0000L) {
- throw PRaiseNode.raiseUncached(null, SystemError, toTruffleStringUncached("marker value reached, regenerate C code (mx python-capi)"));
+ throw PRaiseNode.raiseStatic(null, SystemError, toTruffleStringUncached("marker value reached, regenerate C code (mx python-capi)"));
}
if (constant.longValue == (int) constant.longValue) {
constant.intValue = (int) constant.longValue;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
index 1869dc930c..157a5e2429 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
@@ -154,7 +154,7 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
@SuppressWarnings("static-method")
private RootCallTarget deserializeForBytecodeInterpreter(PythonContext context, byte[] data, TruffleString[] cellvars, TruffleString[] freevars) {
- CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(context, data);
+ CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(null, context, data);
if (cellvars != null && !Arrays.equals(code.cellvars, cellvars) || freevars != null && !Arrays.equals(code.freevars, freevars)) {
code = new CodeUnit(code.name, code.qualname, code.argCount, code.kwOnlyArgCount, code.positionalOnlyArgCount, code.stacksize, code.code,
code.srcOffsetTable, code.flags, code.names, code.varnames,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
index 3e1e1ee89c..4c5652bd89 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/BufferStorageNodes.java
@@ -166,11 +166,11 @@ static PBytes unpackChar(@SuppressWarnings("unused") BufferFormat format, Object
@Specialization(guards = "format == UNICODE")
static TruffleString unpackUnicode(Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached(inline = false) TruffleString.FromCodePointNode fromCodePointNode) {
int codePoint = bufferLib.readInt(buffer, offset);
if (!Character.isValidCodePoint(codePoint)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNMAPPABLE_CHARACTER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNMAPPABLE_CHARACTER);
}
return fromCodePointNode.execute(codePoint, TS_ENCODING, true);
}
@@ -186,9 +186,9 @@ public abstract static class PackValueNode extends Node {
@Specialization(guards = "format == UINT_8")
static void packUnsignedByteInt(Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, int value, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (value < 0 || value > 0xFF) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeByte(buffer, offset, (byte) value);
}
@@ -197,10 +197,10 @@ static void packUnsignedByteInt(Node inliningTarget, @SuppressWarnings("unused")
static void packUnsignedByteGeneric(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object object, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int value = asSizeNode.executeExact(frame, inliningTarget, object);
if (value < 0 || value > 0xFF) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeByte(buffer, offset, (byte) value);
}
@@ -209,10 +209,10 @@ static void packUnsignedByteGeneric(VirtualFrame frame, Node inliningTarget, @Su
static void packSignedByteGeneric(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object object, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int value = asSizeNode.executeExact(frame, inliningTarget, object);
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeByte(buffer, offset, (byte) value);
}
@@ -221,10 +221,10 @@ static void packSignedByteGeneric(VirtualFrame frame, Node inliningTarget, @Supp
static void packSignedShortGeneric(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object object, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int value = asSizeNode.executeExact(frame, inliningTarget, object);
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeShort(buffer, offset, (short) value);
}
@@ -233,10 +233,10 @@ static void packSignedShortGeneric(VirtualFrame frame, Node inliningTarget, @Sup
static void packUnsignedShortGeneric(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, Object object, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int value = asSizeNode.executeExact(frame, inliningTarget, object);
if (value < 0 || value > (Short.MAX_VALUE << 1) + 1) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeShort(buffer, offset, (short) value);
}
@@ -260,10 +260,10 @@ static void packUnsignedIntGeneric(VirtualFrame frame, Node inliningTarget, @Sup
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PyNumberIndexNode indexNode,
@Shared @Cached CastToJavaLongExactNode castToLong,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
long value = castToLong.execute(inliningTarget, indexNode.execute(frame, inliningTarget, object));
if (value < 0 || value > ((long) (Integer.MAX_VALUE) << 1L) + 1L) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
bufferLib.writeInt(buffer, offset, (int) value);
}
@@ -313,9 +313,9 @@ static void packBoolean(VirtualFrame frame, @SuppressWarnings("unused") BufferFo
@Specialization(guards = "format == CHAR")
static void packChar(Node inliningTarget, @SuppressWarnings("unused") BufferFormat format, PBytes object, Object buffer, int offset,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (bufferLib.getBufferLength(object) != 1) {
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
byte value = bufferLib.readByte(object, 0);
bufferLib.writeByte(buffer, offset, value);
@@ -323,9 +323,8 @@ static void packChar(Node inliningTarget, @SuppressWarnings("unused") BufferForm
@Specialization(guards = {"format == CHAR", "!isPBytes(object)"})
@SuppressWarnings("unused")
- static void packChar(Node inliningTarget, BufferFormat format, Object object, Object buffer, int offset,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError);
+ static void packChar(Node inliningTarget, BufferFormat format, Object object, Object buffer, int offset) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError);
}
@Specialization(guards = "format == UNICODE")
@@ -334,13 +333,13 @@ static void packDouble(Node inliningTarget, @SuppressWarnings("unused") BufferFo
@Cached StringNodes.CastToTruffleStringCheckedNode cast,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@Cached(inline = false) TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString str = cast.cast(inliningTarget, object, ErrorMessages.ARRAY_ITEM_MUST_BE_UNICODE);
if (codePointLengthNode.execute(str, TS_ENCODING) == 1) {
int codePoint = codePointAtIndexNode.execute(str, 0, TS_ENCODING);
bufferLib.writeInt(buffer, offset, codePoint);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError);
+ throw raiseNode.raise(inliningTarget, TypeError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/ForeignHashingStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/ForeignHashingStorage.java
index 721a463be6..9aee630703 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/ForeignHashingStorage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/ForeignHashingStorage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -48,7 +48,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.runtime.GilNode;
@@ -121,7 +120,7 @@ static Object get(Node inliningTarget, ForeignHashingStorage storage, Object key
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
@Cached(inline = false) PForeignToPTypeNode toPythonNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var dict = storage.foreignDict;
Object value;
gil.release(true);
@@ -130,7 +129,7 @@ static Object get(Node inliningTarget, ForeignHashingStorage storage, Object key
} catch (UnknownKeyException e) {
return null;
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_READABLE, key, dict);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_READABLE, key, dict);
} finally {
gil.acquire();
}
@@ -150,21 +149,21 @@ public abstract static class PutNode extends PNodeWithContext {
static void put(Node inliningTarget, ForeignHashingStorage storage, Object key, Object value,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var dict = storage.foreignDict;
gil.release(true);
try {
interop.writeHashEntry(dict, key, value);
} catch (UnknownKeyException e) {
- throw raiseNode.get(inliningTarget).raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
} catch (UnsupportedMessageException e) {
if (interop.isHashEntryExisting(dict, key)) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_WRITABLE, key, dict);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_WRITABLE, key, dict);
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_INSERTABLE, key, dict);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_INSERTABLE, key, dict);
}
} catch (UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
} finally {
gil.acquire();
}
@@ -182,7 +181,7 @@ public abstract static class RemoveNode extends PNodeWithContext {
static boolean remove(Node inliningTarget, ForeignHashingStorage storage, Object key,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var dict = storage.foreignDict;
gil.release(true);
@@ -191,7 +190,7 @@ static boolean remove(Node inliningTarget, ForeignHashingStorage storage, Object
} catch (UnknownKeyException e) {
return false;
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_REMOVABLE, key, dict);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_REMOVABLE, key, dict);
} finally {
gil.acquire();
}
@@ -233,7 +232,7 @@ static void clear(Node inliningTarget, ForeignHashingStorage storage,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary iteratorInterop,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// We cannot just remove while iterating otherwise we get e.g.
// ConcurrentModificationException with java.util.HashMap
// So we remove keys by batch of 32 keys.
@@ -262,13 +261,13 @@ static void clear(Node inliningTarget, ForeignHashingStorage storage,
}
}
- private static void remove(Node inliningTarget, Object dict, Object key, InteropLibrary interop, Lazy raiseNode) {
+ private static void remove(Node inliningTarget, Object dict, Object key, InteropLibrary interop, PRaiseNode raiseNode) {
try {
interop.removeHashEntry(dict, key);
} catch (UnknownKeyException e) {
// already removed concurrently
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_REMOVABLE, key, dict);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_REMOVABLE, key, dict);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorage.java
index 0da6b4a46f..2930148360 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -232,7 +232,7 @@ static ArrayBuilder partialMergeFromSeq2(VirtualFrame frame, Object it
@Shared @Cached PyObjectGetItem getItemNode,
@Cached FastConstructListNode createListNode,
@Cached LenNode seqLenNode,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached InlinedConditionProfile lengthTwoProfile,
@Cached IsBuiltinObjectProfile isTypeErrorProfile) throws PException {
Object it = getIter.execute(frame, inliningTarget, iterable);
@@ -248,7 +248,7 @@ static ArrayBuilder partialMergeFromSeq2(VirtualFrame frame, Object it
len = seqLenNode.execute(inliningTarget, element);
if (lengthTwoProfile.profile(inliningTarget, len != 2)) {
- throw raise.get(inliningTarget).raise(ValueError, ErrorMessages.DICT_UPDATE_SEQ_ELEM_HAS_LENGTH_2_REQUIRED, elements.size(), len);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.DICT_UPDATE_SEQ_ELEM_HAS_LENGTH_2_REQUIRED, elements.size(), len);
}
Object key = getItemNode.execute(frame, inliningTarget, element, 0);
Object value = getItemNode.execute(frame, inliningTarget, element, 1);
@@ -257,7 +257,7 @@ static ArrayBuilder partialMergeFromSeq2(VirtualFrame frame, Object it
} catch (PException e) {
if (!lengthTwoProfile.profile(inliningTarget, len != 2) &&
isTypeErrorProfile.profileException(inliningTarget, e, TypeError)) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_CONVERT_DICT_UPDATE_SEQ, elements.size());
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_CONVERT_DICT_UPDATE_SEQ, elements.size());
}
throw e;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java
index 06a19bd600..d9050b2d12 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java
@@ -40,6 +40,9 @@
*/
package com.oracle.graal.python.builtins.objects.common;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
+import static com.oracle.graal.python.nodes.ErrorMessages.FOREIGN_OBJ_ISNT_REVERSE_ITERABLE;
+
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage.EconomicMapSetStringKey;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.CachedHashingStorageGetItemNodeGen;
@@ -98,9 +101,6 @@
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
-import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
-import static com.oracle.graal.python.nodes.ErrorMessages.FOREIGN_OBJ_ISNT_REVERSE_ITERABLE;
-
public class HashingStorageNodes {
public abstract static class HashingStorageGuards {
@@ -908,9 +908,9 @@ static HashingStorageIterator keywords(@SuppressWarnings("unused") KeywordsStora
@Specialization
static HashingStorageIterator foreign(@SuppressWarnings("unused") ForeignHashingStorage self,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// InteropLibrary does not provide a reverse HashEntriesIterator
- throw raiseNode.raise(TypeError, FOREIGN_OBJ_ISNT_REVERSE_ITERABLE);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, FOREIGN_OBJ_ISNT_REVERSE_ITERABLE);
}
}
@@ -1039,9 +1039,9 @@ static boolean foreign(ForeignHashingStorage self, HashingStorageIterator it,
@Specialization(guards = "it.isReverse")
static boolean foreignReverse(@SuppressWarnings("unused") ForeignHashingStorage self, HashingStorageIterator it,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// InteropLibrary does not provide a reverse HashEntriesIterator
- throw raiseNode.raise(TypeError, FOREIGN_OBJ_ISNT_REVERSE_ITERABLE);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, FOREIGN_OBJ_ISNT_REVERSE_ITERABLE);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/IndexNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/IndexNodes.java
index a651a07fa3..88544ace1f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/IndexNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/IndexNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,7 +46,6 @@
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -193,7 +192,7 @@ abstract static class NormalizeIndexWithBoundsCheckNode extends NormalizeIndexCu
static int doInt(int index, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int normalizedIndex = index;
if (negativeIndexProfile.profile(inliningTarget, normalizedIndex < 0)) {
normalizedIndex += length;
@@ -205,7 +204,7 @@ static int doInt(int index, int length, TruffleString errorMessage,
@Specialization
static int doBool(boolean bIndex, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int index = PInt.intValue(bIndex);
checkBounds(inliningTarget, raiseNode, errorMessage, index, length);
return index;
@@ -215,7 +214,7 @@ static int doBool(boolean bIndex, int length, TruffleString errorMessage,
static int doLong(long lIndex, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
int index = PInt.intValueExact(lIndex);
return doInt(index, length, errorMessage, inliningTarget, negativeIndexProfile, raiseNode);
}
@@ -224,11 +223,11 @@ static int doLong(long lIndex, int length, TruffleString errorMessage,
int doLongOvf(long index, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
return doLong(index, length, errorMessage, inliningTarget, negativeIndexProfile, raiseNode);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(PythonBuiltinClassType.IndexError, index);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, index);
}
}
@@ -236,7 +235,7 @@ int doLongOvf(long index, int length, TruffleString errorMessage,
static int doPInt(PInt index, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
int idx = index.intValueExact();
return doInt(idx, length, errorMessage, inliningTarget, negativeIndexProfile, raiseNode);
}
@@ -245,11 +244,11 @@ static int doPInt(PInt index, int length, TruffleString errorMessage,
int doPIntOvf(PInt index, int length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
return doPInt(index, length, errorMessage, inliningTarget, negativeIndexProfile, raiseNode);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raiseNumberTooLarge(PythonBuiltinClassType.IndexError, index);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, index);
}
}
@@ -257,7 +256,7 @@ int doPIntOvf(PInt index, int length, TruffleString errorMessage,
static long doLongLong(long lIndex, long length, TruffleString errorMessage,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile negativeIndexProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
long normalizedIndex = lIndex;
if (negativeIndexProfile.profile(inliningTarget, normalizedIndex < 0)) {
normalizedIndex += length;
@@ -306,7 +305,7 @@ static int doLongOvf(long index, int length, TruffleString errorMessage,
try {
return doLong(index, length, errorMessage, inliningTarget, negativeIndexProfile);
} catch (OverflowException e) {
- throw raiseNode.raiseNumberTooLarge(PythonBuiltinClassType.IndexError, index);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, index);
}
}
@@ -326,7 +325,7 @@ static int doPIntOvf(PInt index, int length, TruffleString errorMessage,
try {
return doPInt(index, length, errorMessage, inliningTarget, negativeIndexProfile);
} catch (OverflowException e) {
- throw raiseNode.raiseNumberTooLarge(PythonBuiltinClassType.IndexError, index);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, index);
}
}
@@ -342,26 +341,26 @@ static long doLongLong(long index, long length, @SuppressWarnings("unused") Truf
}
}
- public static void checkBounds(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString errorMessage, int idx, int length) {
+ public static void checkBounds(Node inliningTarget, PRaiseNode raiseNode, TruffleString errorMessage, int idx, int length) {
if (idx < 0 || idx >= length) {
raiseIndexError(inliningTarget, errorMessage, raiseNode);
}
}
- public static void checkBounds(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString errorMessage, long idx, long length) {
+ public static void checkBounds(Node inliningTarget, PRaiseNode raiseNode, TruffleString errorMessage, long idx, long length) {
if (idx < 0 || idx >= length) {
raiseIndexError(inliningTarget, errorMessage, raiseNode);
}
}
- public static void checkBounds(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString errorMessage, int idx, long length) {
+ public static void checkBounds(Node inliningTarget, PRaiseNode raiseNode, TruffleString errorMessage, int idx, long length) {
if (idx < 0 || idx >= length) {
raiseIndexError(inliningTarget, errorMessage, raiseNode);
}
}
@InliningCutoff
- private static void raiseIndexError(Node inliningTarget, TruffleString errorMessage, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, errorMessage);
+ private static void raiseIndexError(Node inliningTarget, TruffleString errorMessage, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, errorMessage);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceNodes.java
index 7e2783727f..686169d706 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -163,9 +163,8 @@ static SequenceStorage doForeign(Node inliningTarget, Object seq,
}
@Fallback
- static SequenceStorage doFallback(Node inliningTarget, Object seq,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A_SEQUENCE, seq);
+ static SequenceStorage doFallback(Node inliningTarget, Object seq) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, IS_NOT_A_SEQUENCE, seq);
}
@NeverDefault
@@ -247,9 +246,9 @@ public abstract static class CheckIsSequenceNode extends Node {
@Specialization
static void check(Node inliningTarget, Object obj,
@Cached PySequenceCheckNode sequenceCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!sequenceCheckNode.execute(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A_SEQUENCE, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A_SEQUENCE, obj);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index 3406fd3255..2e9807b5f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -181,12 +181,12 @@ public abstract static class SequenceStorageSqItemNode extends Node {
@Specialization
static Object doIt(Node inliningTarget, SequenceStorage self, int index, TruffleString errorMessage,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
return getItem(inliningTarget, self, index, errorMessage, raiseNode, getItemNode);
}
- private static Object getItem(Node inliningTarget, SequenceStorage storage, int index, TruffleString errorMessage, PRaiseNode.Lazy raiseNode, GetItemScalarNode getItemNode) {
+ private static Object getItem(Node inliningTarget, SequenceStorage storage, int index, TruffleString errorMessage, PRaiseNode raiseNode, GetItemScalarNode getItemNode) {
checkBounds(inliningTarget, raiseNode, errorMessage, index, storage.length());
return getItemNode.execute(inliningTarget, storage, index);
}
@@ -219,7 +219,7 @@ static Object doNonSlice(VirtualFrame frame, Node inliningTarget, SequenceStorag
TruffleString indexBoundsErrorMessage, @SuppressWarnings("unused") StorageWrapperFactory wrapperFactory,
@Cached PyNumberAsSizeNode numberAsSizeNode,
@Cached InlinedConditionProfile negativeIndexProfile,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
int index = numberAsSizeNode.executeExact(frame, inliningTarget, idx, PythonBuiltinClassType.IndexError);
if (negativeIndexProfile.profile(inliningTarget, index < 0)) {
@@ -1749,7 +1749,7 @@ static void multiStep(SequenceStorage self, SliceInfo sinfo, SequenceStorage val
} else {
/*- Assign slice */
if (wrongLength.profile(inliningTarget, needed != slicelen)) {
- raiseNode.raise(ValueError, ErrorMessages.ATTEMPT_TO_ASSIGN_SEQ_OF_SIZE_TO_SLICE_OF_SIZE, needed, slicelen);
+ raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ATTEMPT_TO_ASSIGN_SEQ_OF_SIZE_TO_SLICE_OF_SIZE, needed, slicelen);
}
for (int cur = start, i = 0; i < slicelen; cur += step, i++) {
setLeftItemNode.execute(inliningTarget, self, cur, getRightItemNode.execute(inliningTarget, data, i));
@@ -1814,7 +1814,7 @@ static void singleStep(SequenceStorage self, int lo, int hi, SequenceStorage dat
ensureCapacityNode.execute(inliningTarget, self, len + growth);
if (memoryError.profile(inliningTarget, len > Integer.MAX_VALUE - growth)) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
len += growth;
@@ -2197,7 +2197,7 @@ static SequenceStorage doLeftEmpty(@SuppressWarnings("unused") EmptySequenceStor
try {
return copyNode.execute(inliningTarget, right);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -2209,7 +2209,7 @@ static SequenceStorage doRightEmpty(@SuppressWarnings("unused") EmptySequenceSto
try {
return copyNode.execute(inliningTarget, left);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -2354,14 +2354,14 @@ SequenceStorage doRight(SequenceStorage left, SequenceStorage right,
destlen = PythonUtils.addExact(len1, len2);
if (errorForOverflow == OverflowError && shouldOverflow.profile(inliningTarget, destlen >= SysModuleBuiltins.MAXSIZE)) {
// cpython raises an overflow error when this happens
- throw raiseNode.raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
SequenceStorage generalized = generalizeStore(createEmpty(createEmptyNode, inliningTarget, left, right, destlen), right);
return doConcat(generalized, left, right);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
@@ -2547,95 +2547,102 @@ static SequenceStorage doZeroRepeat(SequenceStorage s, @SuppressWarnings("unused
/* special but common case: something like '[False] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
BoolSequenceStorage doBoolSingleElement(BoolSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
boolean[] repeated = new boolean[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getBoolItemNormalized(0));
return new BoolSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
/* special but common case: something like '["\x00"] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
ByteSequenceStorage doByteSingleElement(ByteSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
byte[] repeated = new byte[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getByteItemNormalized(0));
return new ByteSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
/* special but common case: something like '[0] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
IntSequenceStorage doIntSingleElement(IntSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
int[] repeated = new int[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getIntItemNormalized(0));
return new IntSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
/* special but common case: something like '[0L] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
LongSequenceStorage doLongSingleElement(LongSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
long[] repeated = new long[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getLongItemNormalized(0));
return new LongSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
/* special but common case: something like '[0.0] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
DoubleSequenceStorage doDoubleSingleElement(DoubleSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
double[] repeated = new double[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getDoubleItemNormalized(0));
return new DoubleSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
/* special but common case: something like '[None] * n' */
@Specialization(guards = {"s.length() == 1", "times > 0"})
ObjectSequenceStorage doObjectSingleElement(ObjectSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode) {
try {
Object[] repeated = new Object[PythonUtils.multiplyExact(s.length(), times)];
Arrays.fill(repeated, s.getObjectItemNormalized(0));
return new ObjectSequenceStorage(repeated);
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
@Specialization(limit = "MAX_BASIC_STORAGES", guards = {"times > 0", "!isNative(s)", "s.getClass() == cachedClass"})
SequenceStorage doArrayBasedManaged(ArrayBasedSequenceStorage s, int times,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raiseNode,
@Cached("s.getClass()") Class extends ArrayBasedSequenceStorage> cachedClass) {
try {
@@ -2649,9 +2656,9 @@ SequenceStorage doArrayBasedManaged(ArrayBasedSequenceStorage s, int times,
repeated.setNewLength(newLength);
return repeated;
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
@@ -2683,9 +2690,9 @@ SequenceStorage doGeneric(SequenceStorage s, int times,
repeated.setNewLength(newLen);
return repeated;
} catch (OutOfMemoryError e) {
- throw raiseNode.raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
} catch (OverflowException e) {
- throw raiseNode.raise(errorForOverflow);
+ throw raiseNode.raise(inliningTarget, errorForOverflow);
}
}
@@ -2697,7 +2704,7 @@ SequenceStorage doNonInt(VirtualFrame frame, SequenceStorage s, Object times,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached PRaiseNode raiseNode) {
if (!indexCheckNode.execute(inliningTarget, times)) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, times);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, times);
}
int i = asSizeNode.executeExact(frame, inliningTarget, times);
if (recursive == null) {
@@ -2843,7 +2850,7 @@ protected SequenceStorage doGeneric(SequenceStorage s, Object indicationVal,
return s;
}
- throw raiseNode.raise(TypeError, getErrorMessage());
+ throw raiseNode.raise(inliningTarget, TypeError, getErrorMessage());
}
protected TruffleString getErrorMessage() {
@@ -3226,7 +3233,7 @@ static void doNativeByte(NativeByteSequenceStorage s, int cap,
@Shared @CachedLibrary(limit = "2") InteropLibrary lib,
@Shared @Cached CStructAccess.AllocateNode alloc,
@Shared @Cached CStructAccess.FreeNode free,
- @Shared @Cached PRaiseNode.Lazy raiseNode,
+ @Shared @Cached PRaiseNode raiseNode,
@Cached CStructAccess.ReadByteNode read,
@Cached CStructAccess.WriteByteNode write) {
int oldCapacity = s.getCapacity();
@@ -3235,7 +3242,7 @@ static void doNativeByte(NativeByteSequenceStorage s, int cap,
Object oldMem = s.getPtr();
Object newMem = alloc.alloc(newCapacity);
if (lib.isNull(newMem)) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
// TODO: turn this into a memcpy
for (long i = 0; i < oldCapacity; i++) {
@@ -3253,7 +3260,7 @@ static void doNativeObject(NativeObjectSequenceStorage s, int cap,
@Shared @CachedLibrary(limit = "2") InteropLibrary lib,
@Shared @Cached CStructAccess.AllocateNode alloc,
@Shared @Cached CStructAccess.FreeNode free,
- @Shared @Cached PRaiseNode.Lazy raiseNode,
+ @Shared @Cached PRaiseNode raiseNode,
@Cached CStructAccess.ReadPointerNode read,
@Cached CStructAccess.WritePointerNode write) {
int oldCapacity = s.getCapacity();
@@ -3263,7 +3270,7 @@ static void doNativeObject(NativeObjectSequenceStorage s, int cap,
long bytes = newCapacity * 8;
Object newMem = alloc.alloc(bytes);
if (lib.isNull(newMem)) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
// TODO: turn this into a memcpy
for (long i = 0; i < oldCapacity; i++) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
index c24a8823e8..a14a8f779e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
@@ -234,7 +234,7 @@ public abstract static class AbsNode extends PythonUnaryBuiltinNode {
static double abs(Object self,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
double x = c.getReal();
double y = c.getImag();
@@ -268,7 +268,7 @@ static double abs(Object self,
// remove scaling
double r = scalb(scaledH, middleExp);
if (Double.isInfinite(r)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.ABSOLUTE_VALUE_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.ABSOLUTE_VALUE_TOO_LARGE);
}
return r;
}
@@ -425,7 +425,7 @@ static Object doComplex(Object leftObj, Object rightObj,
@Cached InlinedConditionProfile topConditionProfile,
@Cached InlinedConditionProfile zeroDivisionProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
if (notImplementedProfile.profile(inliningTarget, left == null || right == null)) {
@@ -438,7 +438,7 @@ static Object doComplex(Object leftObj, Object rightObj,
if (topConditionProfile.profile(inliningTarget, absRightReal >= absRightImag)) {
/* divide tops and bottom by right.real */
if (zeroDivisionProfile.profile(inliningTarget, absRightReal == 0.0)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "complex");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.S_DIVISION_BY_ZERO, "complex");
} else {
double ratio = right.getImag() / right.getReal();
double denom = right.getReal() + right.getImag() * ratio;
@@ -537,7 +537,7 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
@Cached InlinedBranchProfile smallNegativeProfile,
@Cached InlinedBranchProfile complexProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ComplexValue left = toComplexLeft.execute(inliningTarget, leftObj);
ComplexValue right = toComplexRight.execute(inliningTarget, rightObj);
if (notImplementedProfile.profile(inliningTarget, left == null || right == null)) {
@@ -550,7 +550,7 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
} else if (left.getReal() == 0.0 && left.getImag() == 0.0) {
leftZeroProfile.enter(inliningTarget);
if (right.getImag() != 0.0 || right.getReal() < 0.0) {
- throw PRaiseNode.raiseUncached(inliningTarget, ZeroDivisionError, ErrorMessages.COMPLEX_ZERO_TO_NEGATIVE_POWER);
+ throw PRaiseNode.raiseStatic(inliningTarget, ZeroDivisionError, ErrorMessages.COMPLEX_ZERO_TO_NEGATIVE_POWER);
}
result = PFactory.createComplex(language, 0.0, 0.0);
} else if (right.getImag() == 0.0 && right.getReal() == (int) right.getReal() && right.getReal() < 100 && right.getReal() > -100) {
@@ -566,7 +566,7 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
result = complexToComplexBoundary(left.getReal(), left.getImag(), right.getReal(), right.getImag(), language);
}
if (Double.isInfinite(result.getReal()) || Double.isInfinite(result.getImag())) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.COMPLEX_EXPONENTIATION);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.COMPLEX_EXPONENTIATION);
}
return result;
}
@@ -575,8 +575,8 @@ static Object doGeneric(Object leftObj, Object rightObj, @SuppressWarnings("unus
@InliningCutoff
@SuppressWarnings("unused")
static Object error(Object left, Object right, Object mod,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.COMPLEX_MODULO);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.COMPLEX_MODULO);
}
private static PComplex complexToSmallPositiveIntPower(ComplexValue x, long n, PythonLanguage language) {
@@ -759,7 +759,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static TruffleString format(Object self, TruffleString formatString,
@Bind("this") Node inliningTarget,
@Cached ToComplexValueNode toComplexValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ComplexValue c = toComplexValueNode.execute(inliningTarget, self);
InternalFormat.Spec spec = InternalFormat.fromText(formatString, Spec.NONE, '>', inliningTarget);
validateSpec(inliningTarget, spec, raiseNode);
@@ -773,14 +773,14 @@ private static TruffleString doFormat(Node raisingNode, double real, double imag
return formatter.pad().getResult();
}
- private static void validateSpec(Node inliningTarget, Spec spec, PRaiseNode.Lazy raiseNode) {
+ private static void validateSpec(Node inliningTarget, Spec spec, PRaiseNode raiseNode) {
if (spec.getFill(' ') == '0') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ZERO_PADDING_NOT_ALLOWED_FOR_COMPLEX_FMT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ZERO_PADDING_NOT_ALLOWED_FOR_COMPLEX_FMT);
}
char align = spec.getAlign('>');
if (align == '=') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.S_ALIGNMENT_FLAG_NOT_ALLOWED_FOR_COMPLEX_FMT, align);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.S_ALIGNMENT_FLAG_NOT_ALLOWED_FOR_COMPLEX_FMT, align);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
index c63dbeaa3a..9fa115934f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextBuiltins.java
@@ -101,7 +101,7 @@ public abstract static class GetContextVar extends MpSubscriptBuiltinNode {
@Specialization
Object get(PContextVarsContext self, Object key,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
return getContextVar(inliningTarget, self, key, null, raise);
}
}
@@ -154,7 +154,7 @@ static Object get(VirtualFrame frame, PContextVarsContext self, Object fun, Obje
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
@Cached CallNode call,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
self.enter(inliningTarget, threadState, raise);
try {
@@ -185,7 +185,7 @@ public abstract static class GetMethod extends PythonBuiltinNode {
Object doGetDefault(PContextVarsContext self, Object key, Object def,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile noValueProfile,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
Object defVal = noValueProfile.profile(inliningTarget, isNoValue(def)) ? PNone.NONE : def;
return getContextVar(inliningTarget, self, key, defVal, raise);
}
@@ -197,20 +197,21 @@ Object doGetDefault(PContextVarsContext self, Object key, Object def,
public abstract static class Contains extends PythonBuiltinNode {
@Specialization
boolean doIn(PContextVarsContext self, Object key,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raise) {
if (key instanceof PContextVar var) {
return self.contextVarValues.lookup(var, var.getHash()) != null;
}
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CONTEXTVAR_KEY_EXPECTED, key);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CONTEXTVAR_KEY_EXPECTED, key);
}
}
- private static Object getContextVar(Node inliningTarget, PContextVarsContext self, Object key, Object def, PRaiseNode.Lazy raise) {
+ private static Object getContextVar(Node inliningTarget, PContextVarsContext self, Object key, Object def, PRaiseNode raise) {
if (key instanceof PContextVar ctxVar) {
Object value = self.contextVarValues.lookup(key, ctxVar.getHash());
if (value == null) {
if (def == null) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, new Object[]{key});
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.KeyError, new Object[]{key});
} else {
return def;
}
@@ -218,7 +219,7 @@ private static Object getContextVar(Node inliningTarget, PContextVarsContext sel
return value;
}
} else {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CONTEXTVAR_KEY_EXPECTED, key);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CONTEXTVAR_KEY_EXPECTED, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
index cb57c10bfd..6b2da34c1c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextIteratorBuiltins.java
@@ -83,10 +83,10 @@ public abstract static class Next extends PythonUnaryBuiltinNode {
static Object next(PContextIterator self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object next = self.next(language);
if (next == null) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
} else {
return next;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
index 9ed2bcdb6f..f5e6d5c1e1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/ContextVarBuiltins.java
@@ -84,7 +84,7 @@ public abstract static class GetNode extends PythonBinaryBuiltinNode {
static Object get(PContextVar self, Object def,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile defIsNoValueProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object defValue = defIsNoValueProfile.profile(inliningTarget, isNoValue(def)) ? PContextVar.NO_DEFAULT : def;
PythonContext context = PythonContext.get(inliningTarget);
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
@@ -92,7 +92,7 @@ static Object get(PContextVar self, Object def,
if (value != null) {
return value;
}
- throw raiseNode.get(inliningTarget).raise(LookupError);
+ throw raiseNode.raise(inliningTarget, LookupError);
}
}
@@ -118,7 +118,7 @@ public abstract static class ResetNode extends PythonBinaryBuiltinNode {
static Object reset(PContextVar self, PContextVarsToken token,
@Bind("this") Node inliningTarget,
@Bind PythonContext pythonContext,
- @Shared @Cached PRaiseNode.Lazy raise) {
+ @Shared @Cached PRaiseNode raise) {
if (self == token.getVar()) {
token.use(inliningTarget, raise);
PythonContext.PythonThreadState threadState = pythonContext.getThreadState(pythonContext.getLanguage(inliningTarget));
@@ -129,7 +129,7 @@ static Object reset(PContextVar self, PContextVarsToken token,
self.setValue(threadState, token.getOldValue());
}
} else {
- throw raise.get(inliningTarget).raise(ValueError, ErrorMessages.TOKEN_FOR_DIFFERENT_CONTEXTVAR, token);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.TOKEN_FOR_DIFFERENT_CONTEXTVAR, token);
}
return PNone.NONE;
}
@@ -137,8 +137,8 @@ static Object reset(PContextVar self, PContextVarsToken token,
@Specialization(guards = "!isToken(token)")
Object doError(@SuppressWarnings("unused") PContextVar self, Object token,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raise) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.INSTANCE_OF_TOKEN_EXPECTED, token);
+ @Shared @Cached PRaiseNode raise) {
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.INSTANCE_OF_TOKEN_EXPECTED, token);
}
static boolean isToken(Object obj) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsContext.java
index d26463bb45..9896cf8266 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -52,9 +52,9 @@ public class PContextVarsContext extends PythonBuiltinObject {
Hamt contextVarValues;
private PContextVarsContext previousContext = null;
- public void enter(Node inliningTarget, PythonContext.PythonThreadState threadState, PRaiseNode.Lazy raise) {
+ public void enter(Node inliningTarget, PythonContext.PythonThreadState threadState, PRaiseNode raise) {
if (previousContext != null) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_ENTER_CONTEXT_ALREADY_ENTERED, this);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_ENTER_CONTEXT_ALREADY_ENTERED, this);
}
previousContext = threadState.getContextVarsContext();
assert previousContext != null : "ThreadState had null Context. This should not happen";
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsToken.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsToken.java
index 1c0e80d1a8..ea4b0c6c90 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsToken.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsToken.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -60,9 +60,9 @@ public PContextVarsToken(PContextVar var, Object oldValue, Object cls, Shape ins
this.oldValue = oldValue;
}
- public void use(Node inliningTarget, PRaiseNode.Lazy raise) {
+ public void use(Node inliningTarget, PRaiseNode raise) {
if (used) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.TOKEN_ALREADY_USED, this);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.TOKEN_ALREADY_USED, this);
}
used = true;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
index b9ad4d96ac..2715e62fde 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
@@ -204,12 +204,12 @@ static PNone doGeneric(VirtualFrame frame, PDeque self, Object iterable, Object
@Exclusive @Cached GetNextNode getNextNode,
@Exclusive @Cached IsBuiltinObjectProfile isTypeErrorProfile,
@Exclusive @Cached IsBuiltinObjectProfile isStopIterationProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!PGuards.isPNone(maxlenObj)) {
try {
int maxlen = castToIntNode.execute(inliningTarget, maxlenObj);
if (maxlen < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MAXLEN_MUST_BE_NONNEG);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MAXLEN_MUST_BE_NONNEG);
}
self.setMaxLength(maxlen);
} catch (PException e) {
@@ -218,9 +218,9 @@ static PNone doGeneric(VirtualFrame frame, PDeque self, Object iterable, Object
* OverflowError
*/
e.expect(inliningTarget, TypeError, isTypeErrorProfile);
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
}
@@ -318,7 +318,7 @@ int doGeneric(PDeque self, Object value) {
n++;
}
if (startState != self.getState()) {
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
}
}
return n;
@@ -405,7 +405,7 @@ public abstract static class DequeIndexNode extends PythonQuaternaryBuiltinNode
static int doWithoutSlice(VirtualFrame frame, PDeque self, Object value, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone stop,
@Bind("this") Node inliningTarget,
@Shared("eqNode") @Cached PyObjectRichCompareBool.EqNode eqNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doWithIntSlice(frame, self, value, 0, self.getSize(), inliningTarget, eqNode, raiseNode);
}
@@ -413,7 +413,7 @@ static int doWithoutSlice(VirtualFrame frame, PDeque self, Object value, @Suppre
static int doWithIntSlice(VirtualFrame frame, PDeque self, Object value, int start, int stop,
@Bind("this") Node inliningTarget,
@Shared("eqNode") @Cached PyObjectRichCompareBool.EqNode eqNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int size = self.getSize();
int normStart = normalize(start, size);
int normStop = normalize(stop, size);
@@ -436,11 +436,11 @@ static int doWithIntSlice(VirtualFrame frame, PDeque self, Object value, int sta
return idx;
}
if (startState != self.getState()) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
}
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.S_IS_NOT_DEQUE, value);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.S_IS_NOT_DEQUE, value);
}
@Specialization
@@ -450,7 +450,7 @@ static int doGeneric(VirtualFrame frame, PDeque self, Object value, Object start
@Cached CastToJavaIntExactNode castToIntNode,
@Cached PyNumberAsSizeNode startIndexNode,
@Cached PyNumberAsSizeNode stopIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int istart;
int istop;
if (start != PNone.NO_VALUE) {
@@ -496,7 +496,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
PNone doGeneric(PDeque self, int index, Object value) {
int n = self.getSize();
if (self.getMaxLength() == n) {
- throw PRaiseNode.raiseUncached(this, IndexError, ErrorMessages.DEQUE_AT_MAX_SIZE);
+ throw PRaiseNode.raiseStatic(this, IndexError, ErrorMessages.DEQUE_AT_MAX_SIZE);
}
// shortcuts for simple cases
@@ -526,10 +526,10 @@ public abstract static class DequePopNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doGeneric(PDeque self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object value = self.pop();
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.POP_FROM_EMPTY_DEQUE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.POP_FROM_EMPTY_DEQUE);
}
return value;
}
@@ -543,10 +543,10 @@ public abstract static class DequePopLeftNode extends PythonUnaryBuiltinNode {
@Specialization
static Object doGeneric(PDeque self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object value = self.popLeft();
if (value == null) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.POP_FROM_EMPTY_DEQUE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.POP_FROM_EMPTY_DEQUE);
}
return value;
}
@@ -566,7 +566,7 @@ Object doGeneric(PDeque self, Object value) {
try {
boolean result = PyObjectRichCompareBool.EqNode.compareUncached(self.peekLeft(), value);
if (n != self.getSize()) {
- throw PRaiseNode.raiseUncached(this, IndexError, DEQUE_MUTATED_DURING_REMOVE);
+ throw PRaiseNode.raiseStatic(this, IndexError, DEQUE_MUTATED_DURING_REMOVE);
}
if (result) {
Object removed = self.popLeft();
@@ -586,7 +586,7 @@ Object doGeneric(PDeque self, Object value) {
throw e;
}
}
- throw PRaiseNode.raiseUncached(this, ValueError, DEQUE_REMOVE_X_NOT_IN_DEQUE);
+ throw PRaiseNode.raiseStatic(this, ValueError, DEQUE_REMOVE_X_NOT_IN_DEQUE);
}
}
@@ -734,9 +734,9 @@ static PDeque doDeque(PDeque self, PDeque other) {
@Specialization(replaces = "doDeque")
static PDeque doGeneric(PDeque self, Object other,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(other instanceof PDeque)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_CONCATENATE_DEQUE_NOT_P_TO_DEQUE, other);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_CONCATENATE_DEQUE_NOT_P_TO_DEQUE, other);
}
return doDeque(self, (PDeque) other);
}
@@ -770,7 +770,7 @@ static PDeque doGeneric(Node node, PDeque self, int n) {
}
if (size > Integer.MAX_VALUE / n) {
- throw PRaiseNode.raiseUncached(node, MemoryError);
+ throw PRaiseNode.raiseStatic(node, MemoryError);
}
// Reduce the number of repetitions when maxlen would be exceeded
@@ -814,7 +814,7 @@ boolean doGeneric(PDeque self, Object value) {
return true;
}
if (startState != self.getState()) {
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
}
}
return false;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
index 4f247352db..f0db1b3b0b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeIterBuiltins.java
@@ -104,7 +104,7 @@ Object doGeneric(PDequeIter self) {
if (self.startState == self.deque.getState()) {
if (!self.hasNext()) {
assert self.lengthHint() == 0;
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.StopIteration);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.StopIteration);
}
return self.next();
}
@@ -114,7 +114,7 @@ Object doGeneric(PDequeIter self) {
// fall through
}
self.reset();
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.DEQUE_MUTATED_DURING_ITERATION);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
index 808dfc44b6..6aa6a1a045 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DefaultDictBuiltins.java
@@ -151,9 +151,8 @@ static PDefaultDict copy(@SuppressWarnings("unused") VirtualFrame frame, PDefaul
public abstract static class MissingNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "isNone(self.getDefaultFactory())")
static Object doNoFactory(@SuppressWarnings("unused") PDefaultDict self, Object key,
- @Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, new Object[]{key});
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.KeyError, new Object[]{key});
}
@Specialization(guards = "!isNone(self.getDefaultFactory())")
@@ -175,13 +174,13 @@ static Object doInit(VirtualFrame frame, PDefaultDict self, Object[] args, PKeyw
@Bind("this") Node inliningTarget,
@Cached DictBuiltins.InitNode dictInitNode,
@Cached PyCallableCheckNode callableCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] newArgs = args;
Object newDefault = PNone.NONE;
if (newArgs.length > 0) {
newDefault = newArgs[0];
if (newDefault != PNone.NONE && !callableCheckNode.execute(inliningTarget, newDefault)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, FIRST_ARG_MUST_BE_CALLABLE_S, " or None");
+ throw raiseNode.raise(inliningTarget, TypeError, FIRST_ARG_MUST_BE_CALLABLE_S, " or None");
}
newArgs = PythonUtils.arrayCopyOfRange(args, 1, args.length);
}
@@ -216,7 +215,7 @@ static Object or(VirtualFrame frame, PDict self, PDict other,
@Cached GetClassNode getClassNode,
@Cached CallNode callNode,
@Cached DictNodes.UpdateNode updateNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PDefaultDict dd = (PDefaultDict) (self instanceof PDefaultDict ? self : other);
Object type = getClassNode.execute(inliningTarget, dd);
Object result = callNode.execute(frame, type, dd.getDefaultFactory(), self);
@@ -225,7 +224,7 @@ static Object or(VirtualFrame frame, PDict self, PDict other,
return result;
} else {
/* Cpython doesn't check for this and ends up with SystemError */
- throw raiseNode.get(inliningTarget).raise(TypeError);
+ throw raiseNode.raise(inliningTarget, TypeError);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
index d831723eb7..325a06fd49 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
@@ -179,7 +179,7 @@ static Object doEmpty(Object self, Object[] args, PKeyword[] kwargs) {
@Specialization(guards = "args.length > 1")
Object doGeneric(@SuppressWarnings("unused") Object self, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs) {
- throw raise(TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, "dict", 1, args.length);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, "dict", 1, args.length);
}
}
@@ -212,14 +212,14 @@ static Object popDefault(VirtualFrame frame, Object dict, Object key, Object def
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached InlinedConditionProfile hasKeyProfile,
@Cached HashingStorageDelItem delItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var storage = getStorageNode.execute(inliningTarget, dict);
Object retVal = delItem.executePop(frame, inliningTarget, storage, key, dict);
if (hasKeyProfile.profile(inliningTarget, retVal != null)) {
return retVal;
} else {
if (PGuards.isNoValue(defaultValue)) {
- throw raiseNode.get(inliningTarget).raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
} else {
return defaultValue;
}
@@ -238,11 +238,11 @@ static Object popItem(Object dict,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStoragePop popNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var storage = getStorageNode.execute(inliningTarget, dict);
Object[] result = popNode.execute(inliningTarget, storage, dict);
if (result == null) {
- throw raiseNode.get(inliningTarget).raise(KeyError, ErrorMessages.IS_EMPTY, "popitem(): dictionary");
+ throw raiseNode.raise(inliningTarget, KeyError, ErrorMessages.IS_EMPTY, "popitem(): dictionary");
}
return PFactory.createTuple(language, result);
}
@@ -314,13 +314,13 @@ Object getItem(VirtualFrame frame, Object self, Object key,
var storage = getStorageNode.execute(inliningTarget, self);
final Object result = getItem.execute(frame, inliningTarget, storage, key);
if (notFoundProfile.profile(inliningTarget, result == null)) {
- return handleMissing(frame, self, key, raiseNode);
+ return handleMissing(frame, inliningTarget, self, key, raiseNode);
}
return result;
}
@InliningCutoff
- private Object handleMissing(VirtualFrame frame, Object self, Object key, PRaiseNode raiseNode) {
+ private Object handleMissing(VirtualFrame frame, Node inliningTarget, Object self, Object key, PRaiseNode raiseNode) {
if (self instanceof PDict dict && !PGuards.isBuiltinDict(dict)) {
if (missing == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -328,7 +328,7 @@ private Object handleMissing(VirtualFrame frame, Object self, Object key, PRaise
}
return missing.execute(frame, dict, key);
}
- throw raiseNode.raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
}
@@ -342,10 +342,10 @@ protected abstract static class DispatchMissingNode extends Node {
static Object missing(VirtualFrame frame, Object self, Object key,
@Bind("this") Node inliningTarget,
@Cached("create(Missing)") LookupAndCallBinaryNode callMissing,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = callMissing.executeObject(frame, self, key);
if (result == PNotImplemented.NOT_IMPLEMENTED) {
- throw raiseNode.get(inliningTarget).raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
return result;
}
@@ -366,10 +366,10 @@ static void run(VirtualFrame frame, Object self, Object key, @SuppressWarnings("
@Bind("this") Node inliningTarget,
@Cached DictNodes.GetDictStorageNode getStorageNode,
@Cached HashingStorageDelItem delItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
var storage = getStorageNode.execute(inliningTarget, self);
if (!delItem.execute(frame, inliningTarget, storage, key, self)) {
- throw raiseNode.get(inliningTarget).raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
}
}
@@ -550,8 +550,8 @@ static Object update(VirtualFrame frame, Object self, Object[] args, PKeyword[]
@Specialization(guards = "args.length > 1")
@SuppressWarnings("unused")
static Object error(Object self, Object[] args, PKeyword[] kwargs,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, "update", 1, args.length);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, "update", 1, args.length);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictNodes.java
index 2ef65b2cac..39eb1e090f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -103,9 +103,8 @@ static HashingStorage doForeign(Node inliningTarget, Object dict,
}
@Fallback
- static HashingStorage doFallback(Node inliningTarget, Object object,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "dict", object);
+ static HashingStorage doFallback(Node inliningTarget, Object object) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "dict", object);
}
}
@@ -183,14 +182,14 @@ public static void updateDictGeneric(VirtualFrame frame, Node inliningTarget, Ob
@Cached HashingStorageGetIterator getOtherIter,
@Cached HashingStorageIteratorNext iterNext,
@Cached HashingStorageLen otherLenNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int initialSize = otherLenNode.execute(inliningTarget, otherStorage);
HashingStorageIterator itOther = getOtherIter.execute(inliningTarget, otherStorage);
var newStorage = selfStorage;
while (iterNext.execute(inliningTarget, otherStorage, itOther)) {
newStorage = transferItem.execute(frame, inliningTarget, otherStorage, itOther, newStorage);
if (initialSize != otherLenNode.execute(inliningTarget, otherStorage)) {
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.MUTATED_DURING_UPDATE, "dict");
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.MUTATED_DURING_UPDATE, "dict");
}
}
updateStorageNode.execute(inliningTarget, self, selfStorage, newStorage);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictReprBuiltin.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictReprBuiltin.java
index 4da9323000..2dda3e591f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictReprBuiltin.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictReprBuiltin.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -139,12 +139,12 @@ protected final int getLimit() {
protected static TruffleString getReprString(Node inliningTarget, Object obj, ReprState s,
LookupAndCallUnaryDynamicNode reprNode,
CastToTruffleStringNode castStr,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object reprObj = s == null || obj != s.self ? reprNode.executeObject(obj, T___REPR__) : T_ELLIPSIS_IN_BRACES;
try {
return castStr.execute(inliningTarget, reprObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprObj);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprObj);
}
}
@@ -165,7 +165,7 @@ public static ReprState append(@SuppressWarnings("unused") Node node, HashingSto
@Bind("this") Node inliningTarget,
@Cached LookupAndCallUnaryDynamicNode reprNode,
@Cached CastToTruffleStringNode castStr,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached InlinedConditionProfile lengthCheck,
@Cached HashingStorageIteratorKey itKey,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode) {
@@ -186,7 +186,7 @@ public static ReprState dict(Frame frame, @SuppressWarnings("unused") Node node,
@Bind("this") Node inliningTarget,
@Cached LookupAndCallUnaryDynamicNode reprNode,
@Cached CastToTruffleStringNode castStr,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached InlinedConditionProfile lengthCheck,
@Cached HashingStorageIteratorValue itValue,
@Cached TruffleStringBuilder.AppendStringNode appendStringNode) {
@@ -208,7 +208,7 @@ public static ReprState dict(Frame frame, @SuppressWarnings("unused") Node node,
@Cached LookupAndCallUnaryDynamicNode keyReprNode,
@Cached LookupAndCallUnaryDynamicNode valueReprNode,
@Cached CastToTruffleStringNode castStr,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached InlinedConditionProfile lengthCheck,
@Cached HashingStorageIteratorKey itKey,
@Cached HashingStorageIteratorValue itValue,
@@ -236,7 +236,7 @@ public static ReprState dict(Frame frame, @SuppressWarnings("unused") Node node,
@Cached LookupAndCallUnaryDynamicNode keyReprNode,
@Cached LookupAndCallUnaryDynamicNode valueReprNode,
@Cached CastToTruffleStringNode castStr,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached InlinedConditionProfile lengthCheck,
@Cached HashingStorageIteratorKey itKey,
@Cached HashingStorageIteratorValue itValue,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
index dd9ab9aa4d..cd0b6eea75 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java
@@ -159,10 +159,12 @@ Object doWithArguments(PBaseException self, Object[] args, @SuppressWarnings("un
}
@Specialization(replaces = {"doNoArguments", "doWithArguments"})
- Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords,
- @Bind PythonLanguage language) {
+ static Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords,
+ @Bind("this") Node inliningTarget,
+ @Bind PythonLanguage language,
+ @Cached PRaiseNode raiseNode) {
if (keywords.length != 0) {
- throw raise(TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
+ throw raiseNode.raise(inliningTarget, TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
}
if (args.length == 0) {
self.setArgs(null);
@@ -173,12 +175,13 @@ Object doGeneric(PBaseException self, Object[] args, PKeyword[] keywords,
}
@Specialization
- Object doNative(PythonAbstractNativeObject self, Object[] args, PKeyword[] keywords,
+ static Object doNative(PythonAbstractNativeObject self, Object[] args, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
@Cached ExceptionNodes.SetArgsNode setArgsNode,
- @Bind PythonLanguage language) {
+ @Bind PythonLanguage language,
+ @Cached PRaiseNode raiseNode) {
if (keywords.length != 0) {
- throw raise(TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
+ throw raiseNode.raise(inliningTarget, TypeError, P_TAKES_NO_KEYWORD_ARGS, self);
}
if (args.length == 0) {
setArgsNode.execute(inliningTarget, self, PFactory.createEmptyTuple(language));
@@ -242,10 +245,9 @@ public static Object setCause(Object self, @SuppressWarnings("unused") PNone val
@Specialization(guards = {"!isNoValue(value)", "!check.execute(inliningTarget, value)"})
public static Object cause(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object value,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached PyExceptionInstanceCheckNode check,
- @Cached PRaiseNode raise) {
- throw raise.raise(TypeError, ErrorMessages.EXCEPTION_CAUSE_MUST_BE_NONE_OR_DERIVE_FROM_BASE_EX);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXCEPTION_CAUSE_MUST_BE_NONE_OR_DERIVE_FROM_BASE_EX);
}
}
@@ -278,10 +280,9 @@ public static Object setContext(Object self, @SuppressWarnings("unused") PNone v
@Specialization(guards = {"!isNoValue(value)", "!check.execute(inliningTarget, value)"})
public static Object context(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object value,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached PyExceptionInstanceCheckNode check,
- @Cached PRaiseNode raise) {
- throw raise.raise(TypeError, ErrorMessages.EXCEPTION_CONTEXT_MUST_BE_NONE_OR_DERIVE_FROM_BASE_EX);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXCEPTION_CONTEXT_MUST_BE_NONE_OR_DERIVE_FROM_BASE_EX);
}
}
@@ -300,12 +301,12 @@ static Object setSuppressContext(Object self, Object valueObj,
@Bind("this") Node inliningTarget,
@Cached ExceptionNodes.SetSuppressContextNode setSuppressContextNode,
@Cached CastToJavaBooleanNode castToJavaBooleanNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean value;
try {
value = castToJavaBooleanNode.execute(inliningTarget, valueObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ATTR_VALUE_MUST_BE_BOOL);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ATTR_VALUE_MUST_BE_BOOL);
}
setSuppressContextNode.execute(inliningTarget, self, value);
return PNone.NONE;
@@ -341,8 +342,8 @@ static Object setTraceback(Object self, PTraceback tb,
@Fallback
static Object setTraceback(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object tb,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.MUST_BE_S_OR_S, "__traceback__", "a traceback", "None");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.MUST_BE_S_OR_S, "__traceback__", "a traceback", "None");
}
}
@@ -387,8 +388,8 @@ static Object dict(Object self, @SuppressWarnings("unused") PNone mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static PNone dict(@SuppressWarnings("unused") Object self, Object mapping,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
}
@@ -522,9 +523,9 @@ static Object setDict(VirtualFrame frame, Object self, PDict state,
@Specialization(guards = "!isDict(state)")
static Object generic(@SuppressWarnings("unused") Object self, Object state,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (state != PNone.NONE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, STATE_IS_NOT_A_DICT);
+ throw raiseNode.raise(inliningTarget, TypeError, STATE_IS_NOT_A_DICT);
}
return PNone.NONE;
}
@@ -541,9 +542,9 @@ Object addNote(VirtualFrame frame, Object self, Object note,
@Cached PyObjectSetAttr setAttr,
@Cached ListNodes.AppendNode appendNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!unicodeCheckNode.execute(inliningTarget, note)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOTE_MUST_BE_A_STR_NOT_P, note);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOTE_MUST_BE_A_STR_NOT_P, note);
}
Object notes = lookupAttr.execute(frame, inliningTarget, self, T___NOTES__);
if (notes == PNone.NO_VALUE) {
@@ -553,7 +554,7 @@ Object addNote(VirtualFrame frame, Object self, Object note,
if (notes instanceof PList notesList) {
appendNode.execute(notesList, note);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_ADD_NOTE_NOTES_IS_NOT_A_LIST);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_ADD_NOTE_NOTES_IS_NOT_A_LIST);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
index 3192501836..ecd281fc2f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java
@@ -189,7 +189,7 @@ private static PBaseExceptionGroup subset(Node inliningTarget, PBaseExceptionGro
}
Object egObj = PyObjectCallMethodObjArgs.executeUncached(orig, T_DERIVE, PFactory.createTuple(PythonLanguage.get(null), exceptions));
if (!(egObj instanceof PBaseExceptionGroup eg)) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.DERIVE_MUST_RETURN_AN_INSTANCE_OF_BASE_EXCEPTION_GROUP);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DERIVE_MUST_RETURN_AN_INSTANCE_OF_BASE_EXCEPTION_GROUP);
}
Object tb = ExceptionNodes.GetTracebackNode.executeUncached(orig);
if (tb instanceof PTraceback) {
@@ -230,12 +230,12 @@ private static MatcherType getMatcherType(Node inliningTarget, Object value) {
for (int i = 0; i < storage.length(); i++) {
Object elem = SequenceStorageNodes.GetItemScalarNode.executeUncached(storage, i);
if (!isExceptionTypeUncached(elem)) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.EXPECTED_A_FUNCTION_EXCEPTION_TYPE_OR_TUPLE_OF_EXCEPTION_TYPES);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_A_FUNCTION_EXCEPTION_TYPE_OR_TUPLE_OF_EXCEPTION_TYPES);
}
}
return MatcherType.BY_TYPE;
}
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.EXPECTED_A_FUNCTION_EXCEPTION_TYPE_OR_TUPLE_OF_EXCEPTION_TYPES);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_A_FUNCTION_EXCEPTION_TYPE_OR_TUPLE_OF_EXCEPTION_TYPES);
}
private static boolean isExceptionTypeUncached(Object value) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
index 4a8bbdadcb..7765db96c0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ExceptionNodes.java
@@ -157,7 +157,7 @@ static void doNative(Node inliningTarget, PythonAbstractNativeObject exception,
@Specialization
@SuppressWarnings("unused")
static void doInterop(Node inliningTarget, AbstractTruffleException exception, Object value) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
}
}
@@ -221,7 +221,7 @@ static void doNative(Node inliningTarget, PythonAbstractNativeObject exception,
@Specialization
@SuppressWarnings("unused")
static void doInterop(Node inliningTarget, AbstractTruffleException exception, Object value) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
}
}
@@ -280,7 +280,7 @@ static void doNative(@SuppressWarnings("unused") Node inliningTarget, PythonAbst
@Specialization
@SuppressWarnings("unused")
static void doInterop(Node inliningTarget, AbstractTruffleException exception, boolean value) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
}
}
@@ -352,7 +352,7 @@ static void doNative(Node inliningTarget, PythonAbstractNativeObject exception,
@Specialization
@SuppressWarnings("unused")
static void doInterop(Node inliningTarget, AbstractTruffleException exception, Object value) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
}
}
@@ -479,7 +479,7 @@ static void doNative(@SuppressWarnings("unused") Node inliningTarget, PythonAbst
@Specialization
@SuppressWarnings("unused")
static void doInterop(Node inliningTarget, AbstractTruffleException exception, PTuple argsTuple) {
- throw PRaiseNode.raiseUncached(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_SET_PROPERTY_ON_INTEROP_EXCEPTION);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
index 5622884d95..bb42438e2a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/ImportErrorBuiltins.java
@@ -64,6 +64,7 @@
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
import com.oracle.graal.python.lib.PyUnicodeCheckExactNode;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -133,9 +134,11 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
}
@Specialization
- Object init(PBaseException self, Object[] args, PKeyword[] kwargs,
+ static Object init(PBaseException self, Object[] args, PKeyword[] kwargs,
+ @Bind("this") Node inliningTarget,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode,
- @Cached TruffleString.EqualNode equalNode) {
+ @Cached TruffleString.EqualNode equalNode,
+ @Cached PRaiseNode raiseNode) {
baseExceptionInitNode.execute(self, args);
Object[] attrs = IMPORT_ERROR_ATTR_FACTORY.create(args);
for (PKeyword kw : kwargs) {
@@ -145,7 +148,7 @@ Object init(PBaseException self, Object[] args, PKeyword[] kwargs,
} else if (equalNode.execute(kwName, PATH, TS_ENCODING)) {
attrs[IDX_PATH] = kw.getValue();
} else {
- throw raise(PythonBuiltinClassType.TypeError, S_IS_AN_INVALID_ARG_FOR_S, kw.getName(), "ImportError");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_IS_AN_INVALID_ARG_FOR_S, kw.getName(), "ImportError");
}
}
self.setExceptionAttributes(attrs);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
index 0ce7bf5ca3..fcef70114f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/OsErrorBuiltins.java
@@ -277,13 +277,13 @@ static Object newCData(VirtualFrame frame, Object subType, Object[] args, PKeywo
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = subType;
Object[] parsedArgs = new Object[IDX_WRITTEN + 1];
final Python3Core core = PythonContext.get(inliningTarget);
if (!osErrorUseInit(frame, inliningTarget, core, type, getAttr)) {
if (kwds.length != 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, P_TAKES_NO_KEYWORD_ARGS, type);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, P_TAKES_NO_KEYWORD_ARGS, type);
}
parsedArgs = osErrorParseArgs(args, inliningTarget, checkPositionalNode);
@@ -322,7 +322,7 @@ static Object initNoArgs(VirtualFrame frame, PBaseException self, Object[] args,
@Cached PyNumberAsSizeNode pyNumberAsSizeNode,
@Cached PyArgCheckPositionalNode checkPositionalNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final Object type = getClassNode.execute(inliningTarget, self);
if (!osErrorUseInit(frame, inliningTarget, PythonContext.get(inliningTarget), type, getAttr)) {
// Everything already done in OSError_new
@@ -330,7 +330,7 @@ static Object initNoArgs(VirtualFrame frame, PBaseException self, Object[] args,
}
if (kwds.length != 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, P_TAKES_NO_KEYWORD_ARGS, type);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, P_TAKES_NO_KEYWORD_ARGS, type);
}
Object[] parsedArgs = osErrorParseArgs(args, inliningTarget, checkPositionalNode);
@@ -411,8 +411,8 @@ boolean isInvalid(PBaseException self) {
@Specialization(guards = "isInvalid(self)")
@SuppressWarnings("unused")
static Object generic(PBaseException self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.CHARACTERS_WRITTEN);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.CHARACTERS_WRITTEN);
}
@Specialization(guards = "!isInvalid(self)")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
index 6eb9abba49..bc6cf47604 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java
@@ -91,10 +91,9 @@ static Object doException(PythonAbstractNativeObject exc, @SuppressWarnings("unu
@Specialization(guards = {"check.execute(inliningTarget, exc)", "!isPNone(value)"})
static Object doException(@SuppressWarnings("unused") PBaseException exc, @SuppressWarnings("unused") Object value,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@SuppressWarnings("unused") @Shared @Cached PyExceptionInstanceCheckNode check,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.INSTANCE_EX_MAY_NOT_HAVE_SEP_VALUE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INSTANCE_EX_MAY_NOT_HAVE_SEP_VALUE);
}
@Specialization(guards = {"isTypeNode.execute(inliningTarget, type)", "!isPNone(value)", "!isPTuple(value)"}, limit = "1")
@@ -107,7 +106,7 @@ static Object doExceptionOrCreate(VirtualFrame frame, Object type, Object value,
@Shared @Cached IsSubtypeNode isSubtypeNode,
@Shared @Cached PRaiseNode raiseNode,
@Shared("callCtor") @Cached CallNode callConstructor) {
- checkExceptionClass(type, isSubtypeNode, raiseNode);
+ checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
if (isInstanceProfile.profile(inliningTarget, isInstanceNode.executeWith(frame, value, type))) {
return value;
} else {
@@ -128,7 +127,7 @@ static Object doCreate(VirtualFrame frame, Object type, @SuppressWarnings("unuse
@Shared @Cached IsSubtypeNode isSubtypeNode,
@Shared @Cached PRaiseNode raiseNode,
@Shared("callCtor") @Cached CallNode callConstructor) {
- checkExceptionClass(type, isSubtypeNode, raiseNode);
+ checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
Object instance = callConstructor.execute(frame, type);
if (check.execute(inliningTarget, instance)) {
return instance;
@@ -146,7 +145,7 @@ static Object doCreateTuple(VirtualFrame frame, Object type, PTuple value,
@Shared @Cached IsSubtypeNode isSubtypeNode,
@Shared @Cached PRaiseNode raiseNode,
@Shared("callCtor") @Cached CallNode callConstructor) {
- checkExceptionClass(type, isSubtypeNode, raiseNode);
+ checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
Object[] args = getObjectArrayNode.execute(inliningTarget, value);
Object instance = callConstructor.execute(frame, type, args);
if (check.execute(inliningTarget, instance)) {
@@ -159,9 +158,8 @@ static Object doCreateTuple(VirtualFrame frame, Object type, PTuple value,
@Specialization(guards = "fallbackGuard(type, inliningTarget, isTypeNode)", limit = "1")
static Object doError(Object type, @SuppressWarnings("unused") Object value,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.EXCEPTIONS_MUST_BE_CLASSES_OR_INSTANCES_DERIVING_FROM_BASE_EX, type);
+ @SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXCEPTIONS_MUST_BE_CLASSES_OR_INSTANCES_DERIVING_FROM_BASE_EX, type);
}
static boolean fallbackGuard(Object type, Node inliningTarget, IsTypeNode isTypeNode) {
@@ -176,9 +174,9 @@ private static PBaseException handleInstanceNotAnException(Object type, Object i
return PFactory.createBaseException(PythonLanguage.get(null), TypeError, ErrorMessages.CALLING_N_SHOULD_HAVE_RETURNED_AN_INSTANCE_OF_BASE_EXCEPTION_NOT_P, new Object[]{type, instance});
}
- private static void checkExceptionClass(Object type, IsSubtypeNode isSubtypeNode, PRaiseNode raiseNode) {
+ private static void checkExceptionClass(Node inliningTarget, Object type, IsSubtypeNode isSubtypeNode, PRaiseNode raiseNode) {
if (!isSubtypeNode.execute(type, PythonBuiltinClassType.PBaseException)) {
- throw raiseNode.raise(TypeError, ErrorMessages.EXCEPTIONS_MUST_BE_CLASSES_OR_INSTANCES_DERIVING_FROM_BASE_EX, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXCEPTIONS_MUST_BE_CLASSES_OR_INSTANCES_DERIVING_FROM_BASE_EX, type);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
index 76c04f6394..509dc4c3ab 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SyntaxErrorBuiltins.java
@@ -189,7 +189,7 @@ static Object init(VirtualFrame frame, PBaseException self, Object[] args,
@Cached TupleNodes.ConstructTupleNode constructTupleNode,
@Cached SequenceStorageNodes.GetItemNode getItemNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseExceptionInitNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
baseExceptionInitNode.execute(self, args);
Object[] attrs = SYNTAX_ERROR_ATTR_FACTORY.create();
if (args.length >= 1) {
@@ -200,7 +200,7 @@ static Object init(VirtualFrame frame, PBaseException self, Object[] args,
final SequenceStorage storage = info.getSequenceStorage();
if (storage.length() != 4) {
// not a very good error message, but it's what Python 2.4 gives
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, TUPLE_OUT_OF_BOUNDS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, TUPLE_OUT_OF_BOUNDS);
}
attrs[IDX_FILENAME] = getItemNode.execute(storage, 0);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeDecodeErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeDecodeErrorBuiltins.java
index a3d7b4c833..181595c89e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeDecodeErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeDecodeErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -110,7 +110,7 @@ static Object initNoArgs(VirtualFrame frame, PBaseException self, Object[] args,
@Cached CastToTruffleStringNode toStringNode,
@Cached CastToJavaIntExactNode toJavaIntExactNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
baseInitNode.execute(self, args);
// PyArg_ParseTuple(args, "UOnnU"), TODO: add proper error messages
self.setExceptionAttributes(new Object[]{
@@ -177,14 +177,14 @@ static PBaseException createNew(VirtualFrame frame, Node inliningTarget, @Suppre
int endPos,
TruffleString reason,
@Cached(inline = false) CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = callNode.execute(frame, UnicodeDecodeError, encoding, inputObject, startPos, endPos, reason);
if (obj instanceof PBaseException exception) {
return exception;
}
// Shouldn't happen unless the user manually replaces the method, which is really
// unexpected and shouldn't be permitted at all, but currently it is
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeDecodeError, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeDecodeError, obj);
}
@Specialization(guards = "exceptionObject != null")
@@ -214,13 +214,13 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, PBaseException excep
@Cached(inline = false) BaseExceptionAttrNode attrNode,
@Cached GetClassNode getClassNode,
@Cached(inline = false) IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = attrNode.get(exceptionObject, IDX_OBJECT, UNICODE_ERROR_ATTR_FACTORY);
if (obj == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "object");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "object");
}
if (!isSubtypeNode.execute(frame, getClassNode.execute(inliningTarget, obj), PythonBuiltinClassType.PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ATTRIBUTE_MUST_BE_BYTES, "object");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ATTRIBUTE_MUST_BE_BYTES, "object");
}
return obj;
}
@@ -297,10 +297,10 @@ public abstract static class PyUnicodeDecodeErrorGetEncodingNode extends Node {
static TruffleString doIt(Node inliningTarget, PBaseException exceptionObject,
@Cached(inline = false) BaseExceptionAttrNode attrNode,
@Cached CastToTruffleStringCheckedNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = attrNode.get(exceptionObject, IDX_ENCODING, UNICODE_ERROR_ATTR_FACTORY);
if (obj == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "encoding");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "encoding");
}
return castToStringNode.cast(inliningTarget, obj, ErrorMessages.S_ATTRIBUTE_MUST_BE_UNICODE, "encoding");
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeEncodeErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeEncodeErrorBuiltins.java
index 36f7588105..6ee7334eb3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeEncodeErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeEncodeErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -102,7 +102,7 @@ static Object initNoArgs(PBaseException self, Object[] args,
@Cached CastToTruffleStringNode toStringNode,
@Cached CastToJavaIntExactNode toJavaIntExactNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
baseInitNode.execute(self, args);
// PyArg_ParseTuple(args, "UUnnU"), TODO: add proper error messages
self.setExceptionAttributes(new Object[]{
@@ -178,14 +178,14 @@ static PBaseException createNew(VirtualFrame frame, Node inliningTarget, @Suppre
int startPos, int endPos,
TruffleString reason,
@Cached(inline = false) CallNode callNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = callNode.execute(frame, UnicodeEncodeError, encoding, inputObject, startPos, endPos, reason);
if (obj instanceof PBaseException exception) {
return exception;
}
// Shouldn't happen unless the user manually replaces the method, which is really
// unexpected and shouldn't be permitted at all, but currently it is
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeEncodeError, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, UnicodeEncodeError, obj);
}
@Specialization(guards = "exceptionObject != null")
@@ -214,10 +214,10 @@ public abstract static class PyUnicodeEncodeOrTranslateErrorGetObjectNode extend
static TruffleString doIt(Node inliningTarget, PBaseException exceptionObject,
@Cached(inline = false) BaseExceptionAttrNode attrNode,
@Cached CastToTruffleStringCheckedNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = attrNode.get(exceptionObject, IDX_OBJECT, UNICODE_ERROR_ATTR_FACTORY);
if (obj == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "object");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "object");
}
return castToStringNode.cast(inliningTarget, obj, ErrorMessages.S_ATTRIBUTE_MUST_BE_UNICODE, "object");
}
@@ -294,10 +294,10 @@ public abstract static class PyUnicodeEncodeErrorGetEncodingNode extends Node {
static TruffleString doIt(Node inliningTarget, PBaseException exceptionObject,
@Cached(inline = false) BaseExceptionAttrNode attrNode,
@Cached CastToTruffleStringCheckedNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object obj = attrNode.get(exceptionObject, IDX_ENCODING, UNICODE_ERROR_ATTR_FACTORY);
if (obj == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "encoding");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_ATTRIBUTE_NOT_SET, "encoding");
}
return castToStringNode.cast(inliningTarget, obj, ErrorMessages.S_ATTRIBUTE_MUST_BE_UNICODE, "encoding");
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
index 9420fe0832..38d08d7198 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java
@@ -92,17 +92,17 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
return UnicodeErrorBuiltinsFactory.getFactories();
}
- public static TruffleString getArgAsString(Node inliningTarget, Object[] args, int index, PRaiseNode.Lazy raiseNode, CastToTruffleStringNode castNode) {
+ public static TruffleString getArgAsString(Node inliningTarget, Object[] args, int index, PRaiseNode raiseNode, CastToTruffleStringNode castNode) {
if (args.length < index + 1 || !PGuards.isString(args[index])) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError);
} else {
return castNode.execute(inliningTarget, args[index]);
}
}
- public static int getArgAsInt(Node inliningTarget, Object[] args, int index, PRaiseNode.Lazy raiseNode, CastToJavaIntExactNode castNode) {
+ public static int getArgAsInt(Node inliningTarget, Object[] args, int index, PRaiseNode raiseNode, CastToJavaIntExactNode castNode) {
if (args.length < index + 1 || !(PGuards.isInteger(args[index]) || PGuards.isPInt(args[index]))) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError);
} else {
return castNode.execute(inliningTarget, args[index]);
}
@@ -143,9 +143,9 @@ static PBytes doOther(VirtualFrame frame, Object value,
}
}
- public static Object getArgAsBytes(VirtualFrame frame, Node inliningTarget, Object[] args, int index, PRaiseNode.Lazy raiseNode, GetArgAsBytesNode getArgAsBytesNode) {
+ public static Object getArgAsBytes(VirtualFrame frame, Node inliningTarget, Object[] args, int index, PRaiseNode raiseNode, GetArgAsBytesNode getArgAsBytesNode) {
if (args.length < index + 1) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError);
} else {
return getArgAsBytesNode.execute(frame, inliningTarget, args[index]);
}
@@ -209,8 +209,8 @@ static Object setPInt(PBaseException self, PInt value,
@Specialization(guards = {"!isNoValue(value)", "!canBeInteger(value)"})
@SuppressWarnings("unused")
static Object generic(PBaseException self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, INTEGER_REQUIRED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, INTEGER_REQUIRED);
}
}
@@ -246,8 +246,8 @@ static Object setPInt(PBaseException self, PInt value,
@Specialization(guards = {"!isNoValue(value)", "!canBeInteger(value)"})
@SuppressWarnings("unused")
static Object generic(PBaseException self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, INTEGER_REQUIRED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, INTEGER_REQUIRED);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeTranslateErrorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeTranslateErrorBuiltins.java
index 3ffffd7c75..9e0eb7cafe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeTranslateErrorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeTranslateErrorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -96,7 +96,7 @@ static Object initNoArgs(PBaseException self, Object[] args,
@Cached CastToTruffleStringNode toStringNode,
@Cached CastToJavaIntExactNode toJavaIntExactNode,
@Cached BaseExceptionBuiltins.BaseExceptionInitNode baseInitNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
baseInitNode.execute(self, args);
// PyArg_ParseTuple(args, "UnnU"), TODO: add proper error messages
self.setExceptionAttributes(new Object[]{
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
index 8d15d6345f..fd44d02fcc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
@@ -115,6 +115,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.strings.TruffleString.FromJavaStringNode;
@@ -136,13 +137,13 @@ private static double castToDoubleChecked(Node inliningTarget, Object obj, CastT
try {
return cast.execute(inliningTarget, obj);
} catch (CannotCastException e) {
- throw raiseWrongSelf(obj);
+ throw raiseWrongSelf(inliningTarget, obj);
}
}
@InliningCutoff
- private static PException raiseWrongSelf(Object obj) {
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "float", obj);
+ private static PException raiseWrongSelf(Node inliningTarget, Object obj) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "float", obj);
}
@GenerateCached(false)
@@ -165,7 +166,7 @@ Object doOther(Object object,
@GenerateCached(false)
abstract static class AbstractNumericBinaryBuiltin extends BinaryOpBuiltinNode {
- @Child private PRaiseNode raiseNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
protected abstract Object op(double a, double b);
@@ -197,15 +198,8 @@ Object doOther(Object a, Object b,
void raiseDivisionByZero(boolean cond) {
if (cond) {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- if (isAdoptable()) {
- raiseNode = insert(PRaiseNode.create());
- } else {
- raiseNode = PRaiseNode.getUncached();
- }
- }
- throw raiseNode.raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
}
}
@@ -360,7 +354,7 @@ public final Object execute(double left, double right) {
@Specialization
static double doDI(double left, int right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doOperation(inliningTarget, left, right, raiseNode);
}
@@ -368,7 +362,7 @@ static double doDI(double left, int right, @SuppressWarnings("unused") PNone non
* The special cases we need to deal with always return 1, so 0 means no special case, not a
* result.
*/
- private static double doSpecialCases(Node inliningTarget, double left, double right, PRaiseNode.Lazy raiseNode) {
+ private static double doSpecialCases(Node inliningTarget, double left, double right, PRaiseNode raiseNode) {
// see cpython://Objects/floatobject.c#float_pow for special cases
if (Double.isNaN(right) && left == 1) {
// 1**nan = 1, unlike on Java
@@ -380,12 +374,12 @@ private static double doSpecialCases(Node inliningTarget, double left, double ri
}
if (left == 0 && right < 0 && Double.isFinite(right)) {
// 0**w is an error if w is finite and negative, unlike Java
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
return 0;
}
- private static double doOperation(Node inliningTarget, double left, double right, PRaiseNode.Lazy raiseNode) {
+ private static double doOperation(Node inliningTarget, double left, double right, PRaiseNode raiseNode) {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
return 1.0;
}
@@ -397,7 +391,7 @@ private static double doOperation(Node inliningTarget, double left, double right
static double doDD(VirtualFrame frame, double left, double right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberPowerNode powerNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws UnexpectedResultException {
+ @Shared @Cached PRaiseNode raiseNode) throws UnexpectedResultException {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
return 1.0;
}
@@ -415,7 +409,7 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone none,
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberPowerNode powerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (doSpecialCases(inliningTarget, left, right, raiseNode) == 1) {
return 1.0;
}
@@ -433,9 +427,9 @@ static Object doGeneric(VirtualFrame frame, Object left, Object right, Object mo
@Bind("this") Node inliningTarget,
@Cached CastToJavaDoubleNode castToJavaDoubleNode,
@Shared @Cached PyNumberPowerNode powerNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (!(mod instanceof PNone)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.POW_3RD_ARG_NOT_ALLOWED_UNLESS_INTEGERS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.POW_3RD_ARG_NOT_ALLOWED_UNLESS_INTEGERS);
}
double leftDouble, rightDouble;
@@ -495,7 +489,7 @@ private double fromHex(String arg) {
String str = arg.trim().toLowerCase();
if (str.isEmpty()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
} else if (str.equals("inf") || str.equals("infinity") || str.equals("+inf") || str.equals("+infinity")) {
return Double.POSITIVE_INFINITY;
} else if (str.equals("-inf") || str.equals("-infinity")) {
@@ -512,7 +506,7 @@ private double fromHex(String arg) {
}
if (str.isEmpty()) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
}
if (!str.startsWith("0x")) {
@@ -530,12 +524,12 @@ private double fromHex(String arg) {
try {
double result = Double.parseDouble(str);
if (Double.isInfinite(result)) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.OverflowError, ErrorMessages.HEX_VALUE_TOO_LARGE_AS_FLOAT);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.OverflowError, ErrorMessages.HEX_VALUE_TOO_LARGE_AS_FLOAT);
}
return result;
} catch (NumberFormatException ex) {
- throw PRaiseNode.raiseUncached(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.ValueError, ErrorMessages.INVALID_STRING);
}
}
@@ -556,8 +550,8 @@ Object fromhexO(Object cl, TruffleString arg,
@Fallback
@SuppressWarnings("unused")
static double fromhex(Object object, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
}
@@ -675,14 +669,14 @@ private static double op(double x, int n) {
@Specialization
static double round(double x, int n,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (Double.isNaN(x) || Double.isInfinite(x) || x == 0.0) {
// nans, infinities and zeros round to themselves
return x;
}
double d = op(x, n);
if (Double.isInfinite(d)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.ROUNDED_VALUE_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.ROUNDED_VALUE_TOO_LARGE);
}
return d;
}
@@ -692,7 +686,7 @@ static Object round(VirtualFrame frame, Object x, Object n,
@Bind("this") Node inliningTarget,
@Exclusive @Cached CastToJavaDoubleNode cast,
@Cached PyNumberAsSizeNode asSizeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
return round(castToDoubleChecked(inliningTarget, x, cast), asSizeNode.executeLossy(frame, inliningTarget, n), inliningTarget, raiseNode);
}
@@ -704,13 +698,13 @@ static Object round(Object xObj, @SuppressWarnings("unused") PNone none,
@Cached InlinedConditionProfile nanProfile,
@Cached InlinedConditionProfile infProfile,
@Cached InlinedConditionProfile isLongProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
double x = castToDoubleChecked(inliningTarget, xObj, cast);
if (nanProfile.profile(inliningTarget, Double.isNaN(x))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float NaN");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float NaN");
}
if (infProfile.profile(inliningTarget, Double.isInfinite(x))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float infinity");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float infinity");
}
double result = round(x, 0, inliningTarget, raiseNode);
if (isLongProfile.profile(inliningTarget, result > Long.MAX_VALUE || result < Long.MIN_VALUE)) {
@@ -966,13 +960,13 @@ static PTuple get(Object selfObj,
@Cached CastToJavaDoubleNode cast,
@Cached InlinedConditionProfile nanProfile,
@Cached InlinedConditionProfile infProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
double self = castToDoubleChecked(inliningTarget, selfObj, cast);
if (nanProfile.profile(inliningTarget, Double.isNaN(self))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT_RATIO, "NaN");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT_RATIO, "NaN");
}
if (infProfile.profile(inliningTarget, Double.isInfinite(self))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT_RATIO, "Infinity");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT_RATIO, "Infinity");
}
// At the first time find mantissa and exponent. This is functionality of
@@ -1073,8 +1067,8 @@ static TruffleString getFormat(@SuppressWarnings("unused") Object cls, @Suppress
@Fallback
static TruffleString getFormat(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object typeStr,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.ValueError, ErrorMessages.ARG_D_MUST_BE_S_OR_S, "__getformat__()", 1, "double", "float");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.ValueError, ErrorMessages.ARG_D_MUST_BE_S_OR_S, "__getformat__()", 1, "double", "float");
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignExecutableBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignExecutableBuiltins.java
index b9c054c701..5b7b7ecc96 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignExecutableBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignExecutableBuiltins.java
@@ -76,7 +76,7 @@ static Object doInteropCall(VirtualFrame frame, Object callee, Object[] argument
@CachedLibrary(limit = "4") InteropLibrary lib,
@Cached PForeignToPTypeNode toPTypeNode,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
try {
@@ -89,7 +89,7 @@ static Object doInteropCall(VirtualFrame frame, Object callee, Object[] argument
IndirectCallContext.exit(frame, language, context, state);
}
} catch (ArityException | UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignInstantiableBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignInstantiableBuiltins.java
index 2e259e80ca..bad5fb6f03 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignInstantiableBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignInstantiableBuiltins.java
@@ -78,7 +78,7 @@ static Object doInteropCall(VirtualFrame frame, Object callee, Object[] argument
@CachedLibrary(limit = "4") InteropLibrary lib,
@Cached PForeignToPTypeNode toPTypeNode,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
try {
@@ -91,7 +91,7 @@ static Object doInteropCall(VirtualFrame frame, Object callee, Object[] argument
IndirectCallContext.exit(frame, language, context, state);
}
} catch (ArityException | UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index 127f6073b4..f4dce3ab2a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -79,6 +79,7 @@
import com.oracle.graal.python.lib.PyNumberTrueDivideNode;
import com.oracle.graal.python.lib.PyNumberXorNode;
import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode;
+import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -700,7 +701,7 @@ protected static Object doIt(Object object,
throw new IllegalStateException("foreign value claims to be a big integer but isn't");
}
}
- throw raiseNode.raiseIntegerInterpretationError(object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, object);
} finally {
gil.acquire();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
index 6f2172be6a..078ffd4076 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
@@ -169,14 +169,14 @@ static Object doIt(Node inliningTarget, Object object, Object memberObj,
@Cached(inline = false) CastToJavaStringNode castToString,
@Cached(inline = false) GilNode gil,
@Cached(inline = false) PForeignToPTypeNode toPythonNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
String member;
try {
member = castToString.execute(memberObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, memberObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, memberObj);
}
if (read.isMemberReadable(object, member)) {
@@ -198,7 +198,7 @@ static Object doIt(Node inliningTarget, Object object, Object memberObj,
} finally {
gil.acquire();
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, memberObj);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, memberObj);
}
}
@@ -212,13 +212,13 @@ static void doSet(Object object, Object key, Object value,
@Shared @CachedLibrary(limit = "3") InteropLibrary lib,
@Shared @Cached CastToJavaStringNode castToString,
@Shared @Cached GilNode gil,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
gil.release(true);
String member;
try {
member = castToString.execute(key);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, key);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, key);
}
try {
try {
@@ -241,11 +241,11 @@ static void doSet(Object object, Object key, Object value,
}
}
} catch (UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.INVALID_TYPE_FOR_S, key);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INVALID_TYPE_FOR_S, key);
} finally {
gil.acquire();
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, key);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, key);
}
@Specialization(guards = "isNoValue(value)")
@@ -254,14 +254,14 @@ static void doDelete(Object object, Object key, @SuppressWarnings("unused") PNon
@Shared @CachedLibrary(limit = "3") InteropLibrary lib,
@Shared @Cached CastToJavaStringNode castToString,
@Shared @Cached GilNode gil,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
lib.removeMember(object, castToString.execute(key));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, key);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, key);
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, key);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.AttributeError, ErrorMessages.FOREIGN_OBJ_HAS_NO_ATTR_S, key);
} finally {
gil.acquire();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
index 17fad7107d..978c84e856 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java
@@ -156,8 +156,8 @@ public abstract static class LinenoNode extends PythonBinaryBuiltinNode {
@Specialization
Object delete(VirtualFrame frame, PFrame self, DescriptorDeleteMarker ignored,
@Bind("this") Node inliningTarget,
- @Cached @Cached.Exclusive PRaiseNode.Lazy raise) {
- raise.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, ErrorMessages.CANNOT_DELETE);
+ @Cached @Cached.Exclusive PRaiseNode raise) {
+ raise.raise(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.CANNOT_DELETE);
return PNone.NONE;
}
@@ -187,7 +187,7 @@ PNone set(VirtualFrame frame, PFrame self, Object newLineno,
@Bind("this") Node inliningTarget,
@Cached @Cached.Exclusive InlinedConditionProfile isCurrentFrameProfile,
@Cached @Cached.Exclusive MaterializeFrameNode materializeNode,
- @Cached @Cached.Exclusive PRaiseNode.Lazy raise,
+ @Cached @Cached.Exclusive PRaiseNode raise,
@Cached PyLongCheckExactNode isLong,
@Cached PyLongAsLongAndOverflowNode toLong) {
syncLocationIfNeeded(frame, self, this, inliningTarget, isCurrentFrameProfile, materializeNode);
@@ -198,17 +198,17 @@ PNone set(VirtualFrame frame, PFrame self, Object newLineno,
if (lineno <= Integer.MAX_VALUE && lineno >= Integer.MIN_VALUE) {
self.setJumpDestLine((int) lineno);
} else {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_OUT_OF_RANGE);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_OUT_OF_RANGE);
}
} catch (OverflowException e) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_OUT_OF_RANGE);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_OUT_OF_RANGE);
}
} else {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_MUST_BE_AN_INTEGER);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.LINENO_MUST_BE_AN_INTEGER);
}
} else {
PythonContext context = getContext();
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.CANT_JUMP_FROM_S_EVENT,
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.CANT_JUMP_FROM_S_EVENT,
context.getThreadState(context.getLanguage(inliningTarget)).getTracingWhat().pythonName);
}
return PNone.NONE;
@@ -261,7 +261,7 @@ static Object doSet(PFrame self, Object v, @Bind("this") Node inliningTarget,
try {
self.setTraceLine(cast.execute(inliningTarget, v));
} catch (CannotCastException e) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_VALUE_MUST_BE_BOOL);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_VALUE_MUST_BE_BOOL);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
index a3263bbdb2..21bf7bdab2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java
@@ -132,8 +132,8 @@ Object getClosure(PFunction self,
@SuppressWarnings("unused")
@Fallback
static Object getClosure(Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__closure__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__closure__");
}
}
@@ -157,8 +157,8 @@ Object getGlobals(PFunction self,
@SuppressWarnings("unused")
@Fallback
static Object getGlobals(Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__globals__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__globals__");
}
}
@@ -210,8 +210,8 @@ static Object setModule(PFunction self, Object value,
@SuppressWarnings("unused")
@Specialization
static Object getModule(PBuiltinFunction self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__module__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__module__");
}
}
@@ -243,8 +243,8 @@ static Object getModule(PFunction self, Object value,
@SuppressWarnings("unused")
@Specialization
static Object getModule(PBuiltinFunction self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__annotations__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__annotations__");
}
}
@@ -268,15 +268,15 @@ static Object dict(PFunction self, @SuppressWarnings("unused") PNone mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static PNone dict(@SuppressWarnings("unused") PFunction self, Object mapping,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
@Specialization
@SuppressWarnings("unused")
static Object builtinCode(PBuiltinFunction self, Object mapping,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__dict__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__dict__");
}
}
@@ -288,10 +288,10 @@ public abstract static class TextSignatureNode extends PythonBinaryBuiltinNode {
static Object getFunction(PFunction self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Cached ReadAttributeFromObjectNode readNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object signature = readNode.execute(self, T___TEXT_SIGNATURE__);
if (signature == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "function", "__text_signature__");
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "function", "__text_signature__");
}
return signature;
}
@@ -309,7 +309,7 @@ static TruffleString getBuiltin(PBuiltinFunction self, @SuppressWarnings("unused
@Bind("this") Node inliningTarget) {
Signature signature = self.getSignature();
if (signature.isHidden()) {
- throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, self, T___TEXT_SIGNATURE__);
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, self, T___TEXT_SIGNATURE__);
}
return signatureToText(signature, false);
}
@@ -378,8 +378,8 @@ private static boolean appendCommaIfNeeded(TruffleStringBuilder sb, boolean firs
@Specialization(guards = "!isNoValue(value)")
static Object setBuiltin(@SuppressWarnings("unused") PBuiltinFunction self,
@SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__text_signature__", "builtin_function_or_method");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__text_signature__", "builtin_function_or_method");
}
public static TextSignatureNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
index eee179f311..3b7cf6e569 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
@@ -91,8 +91,8 @@ static TruffleString getName(PBuiltinFunction self, @SuppressWarnings("unused")
@Specialization(guards = "!isNoValue(value)")
static TruffleString setName(@SuppressWarnings("unused") PBuiltinFunction self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__name__", "builtin function");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__name__", "builtin function");
}
}
@@ -106,8 +106,8 @@ static TruffleString getQualname(PBuiltinFunction self, @SuppressWarnings("unuse
@Specialization(guards = "!isNoValue(value)")
static TruffleString setQualname(@SuppressWarnings("unused") PBuiltinFunction self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__qualname__", "builtin function");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_WRITABLE, "__qualname__", "builtin function");
}
}
@@ -117,8 +117,8 @@ static TruffleString setQualname(@SuppressWarnings("unused") PBuiltinFunction se
public abstract static class ObjclassNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.getEnclosingType() == null")
static Object objclassMissing(@SuppressWarnings("unused") PBuiltinFunction self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__objclass__");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "builtin_function_or_method", "__objclass__");
}
@Specialization(guards = "self.getEnclosingType() != null")
@@ -151,7 +151,7 @@ public abstract static class SignatureNode extends PythonUnaryBuiltinNode {
static Object doIt(PBuiltinFunction fun,
@Bind("this") Node inliningTarget) {
if (fun.getSignature().isHidden()) {
- throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__);
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__);
}
return createInspectSignature(fun.getSignature(), false);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
index 9e6033f13a..fde1aecc90 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
@@ -206,8 +206,8 @@ static Object setDefaults(PFunction self, @SuppressWarnings("unused") PNone defa
@Fallback
@SuppressWarnings("unused")
static Object setDefaults(Object self, Object defaults,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_SET_TO_S_NOT_P, T___DEFAULTS__, "tuple");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.MUST_BE_SET_TO_S_NOT_P, T___DEFAULTS__, "tuple");
}
}
@@ -238,7 +238,7 @@ Object set(PFunction self, PDict arg) {
if (key instanceof PString) {
key = ((PString) key).getValueUncached();
} else if (!(key instanceof TruffleString)) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, ErrorMessages.KEYWORD_NAMES_MUST_BE_STR_GOT_P, key);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.KEYWORD_NAMES_MUST_BE_STR_GOT_P, key);
}
keywords.add(new PKeyword((TruffleString) key, HashingStorageIteratorValue.executeUncached(storage, it)));
}
@@ -275,8 +275,8 @@ static Object doMethod(PMethod method,
@Fallback
static Object doGeneric(Object object,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.GETTING_THER_SOURCE_NOT_SUPPORTED_FOR_P, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.GETTING_THER_SOURCE_NOT_SUPPORTED_FOR_P, object);
}
}
@@ -294,11 +294,11 @@ static Object getCodeU(PFunction self, @SuppressWarnings("unused") PNone none,
@Specialization
static Object setCode(PFunction self, PCode code,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int closureLength = self.getClosure() == null ? 0 : self.getClosure().length;
int freeVarsLength = code.getFreeVars().length;
if (closureLength != freeVarsLength) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.REQUIRES_CODE_OBJ, self.getName(), closureLength, freeVarsLength);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.REQUIRES_CODE_OBJ, self.getName(), closureLength, freeVarsLength);
}
self.setCode(code);
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
index 21e76b2010..def38180b9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java
@@ -135,18 +135,18 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
return CommonGeneratorBuiltinsFactory.getFactories();
}
- private static void checkResumable(Node inliningTarget, PGenerator self, PRaiseNode.Lazy raiseNode) {
+ private static void checkResumable(Node inliningTarget, PGenerator self, PRaiseNode raiseNode) {
if (self.isFinished()) {
if (self.isAsyncGen()) {
- throw raiseNode.get(inliningTarget).raise(StopAsyncIteration);
+ throw raiseNode.raise(inliningTarget, StopAsyncIteration);
}
if (self.isCoroutine()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_CORO);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_CORO);
}
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
if (self.isRunning()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
}
}
@@ -161,7 +161,7 @@ static Object cached(VirtualFrame frame, Node inliningTarget, PGenerator self, O
@Cached(value = "createDirectCall(self.getCurrentCallTarget())", inline = false) CallTargetInvokeNode call,
@Exclusive @Cached InlinedBranchProfile returnProfile,
@Exclusive @Cached IsBuiltinObjectProfile errorProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.setRunning(true);
Object[] arguments = prepareArguments(self);
if (sendValue != null) {
@@ -174,7 +174,7 @@ static Object cached(VirtualFrame frame, Node inliningTarget, PGenerator self, O
throw handleException(self, inliningTarget, errorProfile, raiseNode, e);
} catch (GeneratorReturnException e) {
returnProfile.enter(inliningTarget);
- throw handleReturn(self, e, raiseNode.get(inliningTarget));
+ throw handleReturn(inliningTarget, self, e);
} finally {
self.setRunning(false);
}
@@ -188,7 +188,7 @@ static Object generic(VirtualFrame frame, Node inliningTarget, PGenerator self,
@Cached(inline = false) GenericInvokeNode call,
@Exclusive @Cached InlinedBranchProfile returnProfile,
@Exclusive @Cached IsBuiltinObjectProfile errorProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.setRunning(true);
Object[] arguments = prepareArguments(self);
if (sendValue != null) {
@@ -205,25 +205,25 @@ static Object generic(VirtualFrame frame, Node inliningTarget, PGenerator self,
throw handleException(self, inliningTarget, errorProfile, raiseNode, e);
} catch (GeneratorReturnException e) {
returnProfile.enter(inliningTarget);
- throw handleReturn(self, e, raiseNode.get(inliningTarget));
+ throw handleReturn(inliningTarget, self, e);
} finally {
self.setRunning(false);
}
return handleResult(inliningTarget, self, result);
}
- private static PException handleException(PGenerator self, Node inliningTarget, IsBuiltinObjectProfile profile, PRaiseNode.Lazy raiseNode, PException e) {
+ private static PException handleException(PGenerator self, Node inliningTarget, IsBuiltinObjectProfile profile, PRaiseNode raiseNode, PException e) {
self.markAsFinished();
if (self.isAsyncGen()) {
// Async generators need to wrap StopAsyncIteration in a runtime error
if (profile.profileException(inliningTarget, e, StopAsyncIteration)) {
- throw raiseNode.get(inliningTarget).raiseWithCause(RuntimeError, e.getEscapedException(), ErrorMessages.ASYNCGEN_RAISED_ASYNCSTOPITER);
+ throw raiseNode.raiseWithCause(inliningTarget, RuntimeError, e, ErrorMessages.ASYNCGEN_RAISED_ASYNCSTOPITER);
}
}
// PEP 479 - StopIteration raised from generator body needs to be wrapped in
// RuntimeError
e.expectStopIteration(inliningTarget, profile);
- throw raiseNode.get(inliningTarget).raiseWithCause(RuntimeError, e.getEscapedException(), ErrorMessages.GENERATOR_RAISED_STOPITER);
+ throw raiseNode.raiseWithCause(inliningTarget, RuntimeError, e, ErrorMessages.GENERATOR_RAISED_STOPITER);
}
private static Object handleResult(Node node, PGenerator self, GeneratorYieldResult result) {
@@ -231,15 +231,15 @@ private static Object handleResult(Node node, PGenerator self, GeneratorYieldRes
return result.yieldValue;
}
- private static PException handleReturn(PGenerator self, GeneratorReturnException e, PRaiseNode raiseNode) {
+ private static PException handleReturn(Node inliningTarget, PGenerator self, GeneratorReturnException e) {
self.markAsFinished();
if (self.isAsyncGen()) {
- throw raiseNode.raise(StopAsyncIteration);
+ throw PRaiseNode.raiseStatic(inliningTarget, StopAsyncIteration);
}
if (e.value != PNone.NONE) {
- throw raiseNode.raise(StopIteration, new Object[]{e.value});
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration, new Object[]{e.value});
} else {
- throw raiseNode.raise(StopIteration);
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
}
@@ -260,12 +260,12 @@ public abstract static class SendNode extends PythonBinaryBuiltinNode {
static Object send(VirtualFrame frame, PGenerator self, Object value,
@Bind("this") Node inliningTarget,
@Cached ResumeGeneratorNode resumeGeneratorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// even though this isn't a builtin for async generators, SendNode is used on async
// generators by PAsyncGenSend
checkResumable(inliningTarget, self, raiseNode);
if (!self.isStarted() && value != PNone.NONE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SEND_NON_NONE_TO_UNSTARTED_GENERATOR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SEND_NON_NONE_TO_UNSTARTED_GENERATOR);
}
return resumeGeneratorNode.execute(frame, inliningTarget, self, value);
}
@@ -288,15 +288,15 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
@Cached ExceptionNodes.GetTracebackNode getTracebackNode,
@Cached ExceptionNodes.SetTracebackNode setTracebackNode,
@Cached ExceptionNodes.SetContextNode setContextNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean hasTb = hasTbProfile.profile(inliningTarget, !(tb instanceof PNone));
if (hasTb && !(tb instanceof PTraceback)) {
invalidTbProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.THROW_THIRD_ARG_MUST_BE_TRACEBACK);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.THROW_THIRD_ARG_MUST_BE_TRACEBACK);
}
if (self.isRunning()) {
runningProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
}
Object instance = prepareExceptionNode.execute(frame, typ, val);
if (hasTb) {
@@ -306,7 +306,7 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
setContextNode.execute(inliningTarget, instance, PNone.NONE); // Will be filled when
// caught
if (self.isCoroutine() && self.isFinished()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_CORO);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_CORO);
}
if (startedProfile.profile(inliningTarget, self.isStarted() && !self.isFinished())) {
// Pass it to the generator where it will be thrown by the last yield, the location
@@ -342,9 +342,9 @@ static Object close(VirtualFrame frame, PGenerator self,
@Cached IsBuiltinObjectProfile isStopIteration,
@Cached ResumeGeneratorNode resumeGeneratorNode,
@Cached InlinedConditionProfile isStartedPorfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.isRunning()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
}
if (isStartedPorfile.profile(inliningTarget, self.isStarted() && !self.isFinished())) {
PBaseException pythonException = PFactory.createBaseException(PythonLanguage.get(inliningTarget), GeneratorExit);
@@ -362,7 +362,7 @@ static Object close(VirtualFrame frame, PGenerator self,
} finally {
self.markAsFinished();
}
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.GENERATOR_IGNORED_EXIT);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.GENERATOR_IGNORED_EXIT);
} else {
self.markAsFinished();
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
index 18ebb0b5a0..7f49e23bd3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java
@@ -71,12 +71,12 @@
@CoreFunctions(extendClasses = PythonBuiltinClassType.PGenerator)
public final class GeneratorBuiltins extends PythonBuiltins {
- private static void checkResumable(Node inliningTarget, PGenerator self, PRaiseNode.Lazy raiseNode) {
+ private static void checkResumable(Node inliningTarget, PGenerator self, PRaiseNode raiseNode) {
if (self.isFinished()) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
if (self.isRunning()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.GENERATOR_ALREADY_EXECUTING);
}
}
@@ -146,7 +146,7 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
static Object next(VirtualFrame frame, PGenerator self,
@Bind("this") Node inliningTarget,
@Cached CommonGeneratorBuiltins.ResumeGeneratorNode resumeGeneratorNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkResumable(inliningTarget, self, raiseNode);
return resumeGeneratorNode.execute(frame, inliningTarget, self, null);
}
@@ -173,8 +173,8 @@ static Object getRunning(PGenerator self, @SuppressWarnings("unused") PNone none
@Specialization(guards = "!isNoValue(obj)")
static Object setRunning(@SuppressWarnings("unused") PGenerator self, @SuppressWarnings("unused") Object obj,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, "gi_running", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, "gi_running", self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/DescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/DescriptorBuiltins.java
index 09f580f2da..360e880e8f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/DescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/DescriptorBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -142,10 +142,10 @@ abstract static class DescriptorCheckNode extends Node {
static void check(Node inliningTarget, Object descrType, Object name, Object obj,
@Cached GetClassNode getClassNode,
@Cached(inline = false) IsSubtypeNode isSubtypeNode,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, obj);
if (!isSubtypeNode.execute(type, descrType)) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESC_S_FOR_N_DOESNT_APPLY_TO_N, name, descrType, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESC_S_FOR_N_DOESNT_APPLY_TO_N, name, descrType, type);
}
}
}
@@ -158,27 +158,27 @@ public abstract static class DescrGetNode extends Node {
@Specialization
Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetNameNode getNameNode,
@Cached CallUnaryMethodNode callNode) {
if (descr.getGet() != null) {
return callNode.executeObject(frame, descr.getGet(), obj);
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_READABLE, descr.getName(), getNameNode.execute(inliningTarget, descr.getType()));
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_IS_NOT_READABLE, descr.getName(), getNameNode.execute(inliningTarget, descr.getType()));
}
}
@Specialization
Object doIndexedSlotDescriptor(IndexedSlotDescriptor descr, PythonAbstractObject obj,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetOrCreateIndexedSlots getSlotsNode) {
Object[] slots = getSlotsNode.execute(inliningTarget, obj);
Object val = slots[descr.getIndex()];
if (val != null) {
return val;
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, descr.getType(), descr.getName());
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, descr.getType(), descr.getName());
}
}
@@ -190,12 +190,12 @@ public abstract static class DescrSetNode extends Node {
Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj, Object value,
@Bind("this") Node inliningTarget,
@Cached GetNameNode getNameNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached CallBinaryMethodNode callNode) {
if (descr.getSet() != null) {
return callNode.executeObject(frame, descr.getSet(), obj, value);
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_WRITABLE, descr.getName(), getNameNode.execute(inliningTarget, descr.getType()));
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_OF_S_OBJ_IS_NOT_WRITABLE, descr.getName(), getNameNode.execute(inliningTarget, descr.getType()));
}
}
@@ -215,7 +215,7 @@ public abstract static class DescrDeleteNode extends Node {
@Specialization
Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetNameNode getNameNode,
@Cached CallBinaryMethodNode callNode,
@Cached InlinedBranchProfile branchProfile) {
@@ -224,9 +224,9 @@ Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj
} else {
branchProfile.enter(inliningTarget);
if (descr.getSet() != null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_DELETE_ATTRIBUTE, getNameNode.execute(inliningTarget, descr.getType()), descr.getName());
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_DELETE_ATTRIBUTE, getNameNode.execute(inliningTarget, descr.getType()), descr.getName());
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, descr.getName(), obj);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTRIBUTE_S_OF_P_OBJECTS_IS_NOT_WRITABLE, descr.getName(), obj);
}
}
}
@@ -234,7 +234,7 @@ Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj
@Specialization
Object doIndexedSlotDescriptor(IndexedSlotDescriptor descr, PythonAbstractObject obj,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached GetOrCreateIndexedSlots getSlotsNode,
@Cached InlinedConditionProfile profile) {
// PyMember_SetOne - Check if the attribute is set.
@@ -243,7 +243,7 @@ Object doIndexedSlotDescriptor(IndexedSlotDescriptor descr, PythonAbstractObject
slots[descr.getIndex()] = null;
return PNone.NONE;
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, ErrorMessages.S, descr.getName());
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.S, descr.getName());
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index 896ce7003a..fc97c6d276 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -157,16 +157,16 @@
public final class IntBuiltins extends PythonBuiltins {
public static final TpSlots SLOTS = IntBuiltinsSlotsGen.SLOTS;
- private static void raiseDivisionByZero(Node inliningTarget, boolean cond, InlinedBranchProfile divisionByZeroProfile, PRaiseNode.Lazy raiseNode) {
+ private static void raiseDivisionByZero(Node inliningTarget, boolean cond, InlinedBranchProfile divisionByZeroProfile, PRaiseNode raiseNode) {
if (cond) {
- raiseDivisionByZero(inliningTarget, divisionByZeroProfile, raiseNode.get(inliningTarget));
+ raiseDivisionByZero(inliningTarget, divisionByZeroProfile, raiseNode);
}
}
@InliningCutoff
private static void raiseDivisionByZero(Node inliningTarget, InlinedBranchProfile divisionByZeroProfile, PRaiseNode raiseNode) {
divisionByZeroProfile.enter(inliningTarget);
- throw raiseNode.raise(PythonErrorType.ZeroDivisionError, ErrorMessages.S_DIVISION_OR_MODULO_BY_ZERO, "integer");
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.S_DIVISION_OR_MODULO_BY_ZERO, "integer");
}
@Override
@@ -284,8 +284,8 @@ static Object roundPIntPInt(PInt arg, PInt n,
@Specialization(guards = {"!isInteger(n)"})
@SuppressWarnings("unused")
static Object roundPIntPInt(Object arg, Object n,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, n);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, n);
}
private static Object makeInt(Node inliningTarget, BigDecimal d, InlinedBranchProfile intOverflow, InlinedBranchProfile longOverflow) {
@@ -534,32 +534,32 @@ public abstract static class TrueDivNode extends BinaryOpBuiltinNode {
@Specialization
static double divII(int x, int y,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return divDD(x, y, inliningTarget, raiseNode);
}
@Specialization(guards = {"fitsIntoDouble(x)", "fitsIntoDouble(y)"})
static double divLL(long x, long y,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return divDD(x, y, inliningTarget, raiseNode);
}
@Specialization(guards = {"!fitsIntoDouble(x) || !fitsIntoDouble(y)"})
static double divLLLarge(long x, long y,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (y == 0) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
return op(inliningTarget, PInt.longToBigInteger(x), PInt.longToBigInteger(y));
}
static double divDD(double x, double y,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (y == 0) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
return x / y;
}
@@ -567,9 +567,9 @@ static double divDD(double x, double y,
@Specialization
static double doPI(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (right.isZero()) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
return op(inliningTarget, PInt.longToBigInteger(left), right.getValue());
}
@@ -577,9 +577,9 @@ static double doPI(long left, PInt right,
@Specialization
static double doPL(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (right == 0) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
return op(inliningTarget, left.getValue(), PInt.longToBigInteger(right));
}
@@ -587,9 +587,9 @@ static double doPL(PInt left, long right,
@Specialization
static double doPP(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (right.isZero()) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
return op(inliningTarget, left.getValue(), right.getValue());
}
@@ -611,7 +611,7 @@ private static double op(Node raisingNode, BigInteger a, BigInteger b) {
BigDecimal result = aDecimal.divide(bDecimal, bPrec - aPrec + precisionOfDouble, RoundingMode.HALF_EVEN);
double d = result.doubleValue();
if (Double.isInfinite(d)) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.INTEGER_DIVISION_RESULT_TOO_LARGE);
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.INTEGER_DIVISION_RESULT_TOO_LARGE);
}
return d;
}
@@ -650,7 +650,7 @@ static Object doII(int left, int right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
if (left == Integer.MIN_VALUE && right == -1) {
overflowValueProfile.enter();
@@ -664,7 +664,7 @@ static Object doLL(long left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
if (left == Long.MIN_VALUE && right == -1) {
overflowValueProfile.enter();
@@ -678,7 +678,7 @@ static Object doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
int rightValue = right.intValueExact();
raiseDivisionByZero(inliningTarget, rightValue == 0, divisionByZeroProfile, raiseNode);
@@ -697,7 +697,7 @@ static Object doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
long rightValue = right.longValueExact();
raiseDivisionByZero(inliningTarget, rightValue == 0, divisionByZeroProfile, raiseNode);
@@ -715,7 +715,7 @@ static Object doLPi(long left, PInt right,
static long doPiIAndNarrow(PInt left, int right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -725,7 +725,7 @@ static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -734,7 +734,7 @@ static PInt doPiI(PInt left, int right,
static long doPiLAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -744,7 +744,7 @@ static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -753,7 +753,7 @@ static PInt doPiL(PInt left, long right,
static long doPiPiAndNarrow(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(left.getValue(), right.getValue()));
}
@@ -763,7 +763,7 @@ static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@@ -821,7 +821,7 @@ public abstract static class ModNode extends BinaryOpBuiltinNode {
static int doII(int left, int right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return Math.floorMod(left, right);
}
@@ -830,7 +830,7 @@ static int doII(int left, int right,
static long doLL(long left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return Math.floorMod(left, right);
}
@@ -839,7 +839,7 @@ static long doLL(long left, long right,
static long doLPiAndNarrow(long left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(PInt.longToBigInteger(left), right.getValue()));
}
@@ -849,7 +849,7 @@ static PInt doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@@ -858,7 +858,7 @@ static PInt doLPi(long left, PInt right,
static long doLPiNegativeAndNarrow(long left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PInt.longValueExact(opNeg(PInt.longToBigInteger(left), right.getValue()));
}
@@ -868,7 +868,7 @@ static PInt doLPiNegative(long left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, opNeg(PInt.longToBigInteger(left), right.getValue()));
}
@@ -877,7 +877,7 @@ static PInt doLPiNegative(long left, PInt right,
static long doPiLAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -887,7 +887,7 @@ static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -896,7 +896,7 @@ static PInt doPiL(PInt left, long right,
static long doPiLNegAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PInt.longValueExact(opNeg(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -906,7 +906,7 @@ static PInt doPiLNeg(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, opNeg(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -915,7 +915,7 @@ static PInt doPiLNeg(PInt left, long right,
static long doPiPiAndNarrow(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PInt.longValueExact(op(left.getValue(), right.getValue()));
}
@@ -925,7 +925,7 @@ static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached InlinedBranchProfile divisionByZeroProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@@ -1147,9 +1147,9 @@ PInt doLLPos(long left, long right, @SuppressWarnings("unused") PNone none,
double doLLNeg(long left, long right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Shared("leftIsZero") @Cached InlinedConditionProfile leftIsZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (leftIsZero.profile(inliningTarget, left == 0)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
return Math.pow(left, right);
}
@@ -1159,7 +1159,7 @@ PInt doLLPos(long left, long right, @SuppressWarnings("unused") PNone none,
Object doLPNarrow(long left, PInt right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Shared("leftIsZero") @Cached InlinedConditionProfile leftIsZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
long lright = right.longValueExact();
if (lright >= 0) {
return doLLFast(left, lright, none);
@@ -1196,10 +1196,10 @@ PInt doPLPos(PInt left, long right, @SuppressWarnings("unused") PNone none,
double doPLNeg(PInt left, long right, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Shared("leftIsZero") @Cached InlinedConditionProfile leftIsZero,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
double leftDouble = PInt.doubleValueWithOverflow(this, left.getValue());
if (leftIsZero.profile(inliningTarget, leftDouble == 0.0)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
return Math.pow(leftDouble, right);
}
@@ -1232,9 +1232,9 @@ static long doLLPosLPos(long left, long right, long mod) {
static long doLLPosLGeneric(long left, long right, long mod,
@Bind("this") Node inliningTarget,
@Exclusive @Cached InlinedConditionProfile modNegativeProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (mod == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.POW_THIRD_ARG_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.POW_THIRD_ARG_CANNOT_BE_ZERO);
}
try {
if (modNegativeProfile.profile(inliningTarget, mod < 0)) {
@@ -1283,7 +1283,7 @@ private Object objectOp(Object left, Object right, Object mod) {
BigInteger bigRight = integerToBigInteger(right);
BigInteger bigMod = integerToBigInteger(mod);
if (bigMod.signum() == 0) {
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.POW_THIRD_ARG_CANNOT_BE_ZERO);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.POW_THIRD_ARG_CANNOT_BE_ZERO);
} else {
BigInteger bigModPos;
if (bigMod.signum() < 0) {
@@ -1301,7 +1301,7 @@ private Object objectOp(Object left, Object right, Object mod) {
} catch (ArithmeticException e) {
// a positive mod was used, so this exception must mean the exponent was
// negative and the base is not relatively prime to the exponent
- throw PRaiseNode.raiseUncached(this, ValueError, ErrorMessages.POW_BASE_NOT_INVERTIBLE);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.POW_BASE_NOT_INVERTIBLE);
}
}
}
@@ -1356,7 +1356,7 @@ private Object op(BigInteger left, BigInteger right) {
double leftDouble = PInt.doubleValueWithOverflow(this, left);
double rightDouble = PInt.doubleValueWithOverflow(this, right);
if (leftDouble == 0.0) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.ZeroDivisionError, ErrorMessages.POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER);
}
return Math.pow(leftDouble, rightDouble);
}
@@ -1384,7 +1384,7 @@ private BigInteger op(BigInteger a, long b) {
}
if (b != (int) b) {
// exponent does not fit in an int, this is likely going to cause out-of-memory
- throw PRaiseNode.raiseUncached(this, PythonErrorType.ArithmeticError, ErrorMessages.EXPONENT_TOO_LARGE);
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.ArithmeticError, ErrorMessages.EXPONENT_TOO_LARGE);
}
return a.pow((int) b);
}
@@ -1574,7 +1574,7 @@ public abstract static class LShiftNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
- private static long leftShiftExact(Node inliningTarget, long left, long right, PRaiseNode.Lazy raiseNode) throws OverflowException {
+ private static long leftShiftExact(Node inliningTarget, long left, long right, PRaiseNode raiseNode) throws OverflowException {
if (right >= Long.SIZE || right < 0) {
shiftError(inliningTarget, right, raiseNode);
}
@@ -1588,7 +1588,7 @@ private static long leftShiftExact(Node inliningTarget, long left, long right, P
return result;
}
- private static int leftShiftExact(Node inliningTarget, int left, int right, PRaiseNode.Lazy raiseNode) throws OverflowException {
+ private static int leftShiftExact(Node inliningTarget, int left, int right, PRaiseNode raiseNode) throws OverflowException {
if (right >= Integer.SIZE || right < 0) {
shiftError(inliningTarget, right, raiseNode);
}
@@ -1602,18 +1602,18 @@ private static int leftShiftExact(Node inliningTarget, int left, int right, PRai
return result;
}
- private static void shiftError(Node inliningTarget, long shiftCount, PRaiseNode.Lazy raiseNode) throws OverflowException {
+ private static void shiftError(Node inliningTarget, long shiftCount, PRaiseNode raiseNode) throws OverflowException {
if (shiftCount >= Integer.SIZE) {
throw OverflowException.INSTANCE;
} else if (shiftCount < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
}
}
@Specialization(rewriteOn = OverflowException.class)
static int doII(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return leftShiftExact(inliningTarget, left, right, raiseNode);
}
@@ -1621,7 +1621,7 @@ static int doII(int left, int right,
@Specialization
static Object doIIOvf(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
try {
return leftShiftExact(inliningTarget, left, right, raiseNode);
@@ -1633,7 +1633,7 @@ static Object doIIOvf(int left, int right,
@Specialization(rewriteOn = OverflowException.class)
static long doLL(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) throws OverflowException {
+ @Shared @Cached PRaiseNode raiseNode) throws OverflowException {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return leftShiftExact(inliningTarget, left, right, raiseNode);
}
@@ -1641,21 +1641,21 @@ static long doLL(long left, long right,
@Specialization
static Object doILOvf(int left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doLLOvf(left, right, inliningTarget, raiseNode);
}
@Specialization
static Object doLIOvf(long left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doLLOvf(left, right, inliningTarget, raiseNode);
}
@Specialization
static Object doLLOvf(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
try {
return leftShiftExact(inliningTarget, left, right, raiseNode);
@@ -1668,7 +1668,7 @@ static Object doLLOvf(long left, long right,
// fallback to the raise of overflow error
}
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@@ -1681,7 +1681,7 @@ static int doIPiZero(@SuppressWarnings("unused") int left, @SuppressWarnings("un
static PInt doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
if (left == 0) {
return PFactory.createInt(language, BigInteger.ZERO);
@@ -1690,7 +1690,7 @@ static PInt doIPi(int left, PInt right,
int iright = right.intValueExact();
return PFactory.createInt(language, op(PInt.longToBigInteger(left), iright));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@@ -1704,7 +1704,7 @@ static int doLPiZero(@SuppressWarnings("unused") long left, @SuppressWarnings("u
@Specialization(replaces = "doLPiZero")
static PInt doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
PythonLanguage language = PythonLanguage.get(inliningTarget);
if (left == 0) {
@@ -1714,35 +1714,35 @@ static PInt doLPi(long left, PInt right,
int iright = right.intValueExact();
return PFactory.createInt(language, op(PInt.longToBigInteger(left), iright));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@Specialization
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return doGuardedBiI(inliningTarget, left.getValue(), right, raiseNode);
}
- static PInt doGuardedBiI(Node inliningTarget, BigInteger left, int right, PRaiseNode.Lazy raiseNode) {
+ static PInt doGuardedBiI(Node inliningTarget, BigInteger left, int right, PRaiseNode raiseNode) {
try {
return PFactory.createInt(PythonLanguage.get(inliningTarget), op(left, right));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@Specialization
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int rightI = (int) right;
if (rightI == right) {
return doPiI(left, rightI, inliningTarget, raiseNode);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@@ -1754,7 +1754,7 @@ static int doPiPiZero(@SuppressWarnings("unused") PInt left, @SuppressWarnings("
@Specialization(replaces = "doPiPiZero")
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
PythonLanguage language = PythonLanguage.get(inliningTarget);
if (left.isZero()) {
@@ -1763,7 +1763,7 @@ static PInt doPiPi(PInt left, PInt right,
try {
return PFactory.createInt(language, op(left.getValue(), right.intValueExact()));
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError);
}
}
@@ -1782,9 +1782,9 @@ static BigInteger op(BigInteger left, int right) throws OverflowException {
}
}
- private static void raiseNegativeShiftCount(Node inliningTarget, boolean cond, PRaiseNode.Lazy raiseNode) {
+ private static void raiseNegativeShiftCount(Node inliningTarget, boolean cond, PRaiseNode raiseNode) {
if (cond) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
}
}
@@ -1805,7 +1805,7 @@ public abstract static class RShiftNode extends BinaryOpBuiltinNode {
@Specialization(guards = "right < 32")
static int doIISmall(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return left >> right;
}
@@ -1813,7 +1813,7 @@ static int doIISmall(int left, int right,
@Specialization(replaces = "doIISmall")
static int doII(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
// Note: according to JLS, if 'left' is an int, then only the 5 LSBs of 'right' are
// considered. However, Python would consider more bits, so do the max possible shift.
@@ -1823,7 +1823,7 @@ static int doII(int left, int right,
@Specialization(guards = "right < 64")
static long doLLSmall(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return left >> right;
}
@@ -1831,7 +1831,7 @@ static long doLLSmall(long left, long right,
@Specialization(replaces = "doLLSmall")
static long doLL(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
// for explanation, see 'doII'
return left >> (right >= 64 ? 63 : right);
@@ -1840,14 +1840,14 @@ static long doLL(long left, long right,
@Specialization
static Object doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, raiseNode);
}
@Specialization
static Object doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doHugeShift(inliningTarget, PInt.longToBigInteger(left), right, raiseNode);
}
@@ -1855,7 +1855,7 @@ static Object doLPi(long left, PInt right,
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
return PFactory.createInt(language, op(left.getValue(), right));
}
@@ -1864,7 +1864,7 @@ static PInt doPiI(PInt left, int right,
static Object doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, right < 0, raiseNode);
int rightI = (int) right;
if (rightI == right) {
@@ -1878,13 +1878,13 @@ static Object doPiL(PInt left, long right,
@Specialization
static Object doPInt(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doHugeShift(inliningTarget, left.getValue(), right, raiseNode);
}
- private static void raiseNegativeShiftCount(Node inliningTarget, boolean cond, PRaiseNode.Lazy raiseNode) {
+ private static void raiseNegativeShiftCount(Node inliningTarget, boolean cond, PRaiseNode raiseNode) {
if (cond) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.NEGATIVE_SHIFT_COUNT);
}
}
@@ -1894,7 +1894,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- private static Object doHugeShift(Node inliningTarget, BigInteger left, PInt right, PRaiseNode.Lazy raiseNode) {
+ private static Object doHugeShift(Node inliningTarget, BigInteger left, PInt right, PRaiseNode raiseNode) {
raiseNegativeShiftCount(inliningTarget, !right.isZeroOrPositive(), raiseNode);
try {
return PFactory.createInt(PythonLanguage.get(inliningTarget), op(left, right.intValueExact()));
@@ -2579,7 +2579,7 @@ private static boolean isBigEndian(Node raisingNode, TruffleString order) {
if (order.equalsUncached(T_LITTLE, TS_ENCODING)) {
return false;
}
- throw PRaiseNode.raiseUncached(raisingNode, PythonErrorType.ValueError, ErrorMessages.BYTEORDER_MUST_BE_LITTLE_OR_BIG);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.BYTEORDER_MUST_BE_LITTLE_OR_BIG);
}
@Specialization
@@ -2589,13 +2589,13 @@ static PBytes fromLong(long self, int byteCount, TruffleString byteorder, boolea
@Exclusive @Cached InlinedConditionProfile negativeByteCountProfile,
@Exclusive @Cached InlinedConditionProfile negativeNumberProfile,
@Exclusive @Cached InlinedConditionProfile overflowProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (negativeByteCountProfile.profile(inliningTarget, byteCount < 0)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
}
if (self < 0) {
if (negativeNumberProfile.profile(inliningTarget, !signed)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
}
}
return PFactory.createBytes(language, fromLong(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
@@ -2605,7 +2605,7 @@ static PBytes fromLong(long self, int byteCount, TruffleString byteorder, boolea
public static byte[] fromLong(long self, int byteCount, boolean isBigEndian, boolean signed,
Node inliningTarget,
InlinedConditionProfile overflowProfile,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
byte signByte = 0;
if (self < 0) {
assert signed : ErrorMessages.MESSAGE_CONVERT_NEGATIVE;
@@ -2634,7 +2634,7 @@ public static byte[] fromLong(long self, int byteCount, boolean isBigEndian, boo
}
if (overflowProfile.profile(inliningTarget, !signed && number != 0 || (signed && bytes.length == 1 && bytes[0] != self) || (byteCount == 0 && self != 0 && self != -1))) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.MESSAGE_INT_TO_BIG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.MESSAGE_INT_TO_BIG);
}
if (signed) {
@@ -2650,7 +2650,7 @@ public static byte[] fromLong(long self, int byteCount, boolean isBigEndian, boo
private static byte getSignByte(BigInteger value, boolean signed, Node raisingNode) {
if (value.compareTo(BigInteger.ZERO) < 0) {
if (!signed) {
- throw PRaiseNode.raiseUncached(raisingNode, PythonErrorType.OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.MESSAGE_CONVERT_NEGATIVE);
}
return -1;
}
@@ -2668,9 +2668,9 @@ static PBytes fromPIntInt(PInt self, int byteCount, TruffleString byteorder, boo
@Bind PythonLanguage language,
@Exclusive @Cached InlinedConditionProfile negativeByteCountProfile,
@Exclusive @Cached InlinedConditionProfile overflowProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (negativeByteCountProfile.profile(inliningTarget, byteCount < 0)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.MESSAGE_LENGTH_ARGUMENT);
}
return PFactory.createBytes(language, fromBigInteger(self, byteCount, isBigEndian(inliningTarget, byteorder), signed,
inliningTarget, overflowProfile, raiseNode));
@@ -2679,7 +2679,7 @@ static PBytes fromPIntInt(PInt self, int byteCount, TruffleString byteorder, boo
public static byte[] fromBigInteger(PInt self, int byteCount, boolean isBigEndian, boolean signed,
Node inliningTarget,
InlinedConditionProfile overflowProfile,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
BigInteger value = self.getValue();
byte signByte = getSignByte(value, signed, inliningTarget);
byte[] bytes = getBytes(value);
@@ -2697,7 +2697,7 @@ public static byte[] fromBigInteger(PInt self, int byteCount, boolean isBigEndia
}
if (overflowProfile.profile(inliningTarget, len > byteCount)) {
// the corrected len is still bigger then we need.
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.OverflowError, ErrorMessages.MESSAGE_INT_TO_BIG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.OverflowError, ErrorMessages.MESSAGE_INT_TO_BIG);
}
// the array starts with sign bytes and has to be truncated to the requested
// size
@@ -2761,21 +2761,21 @@ static Object fromObject(VirtualFrame frame, Object cl, Object object, TruffleSt
@Cached BytesNodes.BytesFromObject bytesFromObject,
@Cached IntNodes.PyLongFromByteArray fromByteArray,
@Cached CallNode callCtor,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
boolean littleEndian;
if (equalNode.execute(byteorder, T_BIG, TS_ENCODING)) {
littleEndian = false;
} else if (equalNode.execute(byteorder, T_LITTLE, TS_ENCODING)) {
littleEndian = true;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.BYTEORDER_MUST_BE_LITTLE_OR_BIG);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.BYTEORDER_MUST_BE_LITTLE_OR_BIG);
}
byte[] bytes;
Object bytesObj = callBytes.executeObject(frame, object);
if (bytesObj != PNone.NO_VALUE) {
hasBytesProfile.enter(inliningTarget);
if (!(bytesObj instanceof PBytes)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__);
}
bytes = bufferLib.getCopiedByteArray(bytesObj);
} else {
@@ -2843,7 +2843,7 @@ static TruffleString doPInt(PInt self,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached InlinedIntValueProfile maxDigitsProfile,
@Cached InlinedIntValueProfile maxDigitsBitLengthProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
int intMaxStrDigits = maxDigitsProfile.profile(inliningTarget, context.getIntMaxStrDigits());
/*
@@ -2861,7 +2861,7 @@ static TruffleString doPInt(PInt self,
if (intMaxStrDigits > 0) {
int bitLength = positiveBitLength(self);
if (bitLength >= maxDigitsBitLengthProfile.profile(inliningTarget, context.getMinIntBitLengthOverLimit())) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION, intMaxStrDigits);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION, intMaxStrDigits);
}
}
String value = self.toString();
@@ -2872,7 +2872,7 @@ static TruffleString doPInt(PInt self,
if (intMaxStrDigits > 0) {
int digits = self.isNegative() ? value.length() - 1 : value.length();
if (digits > intMaxStrDigits) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION);
}
}
return fromJavaStringNode.execute(value, TS_ENCODING);
@@ -2911,14 +2911,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "!formatString.isEmpty()")
static TruffleString formatB(boolean self, TruffleString formatString,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return formatI(self ? 1 : 0, formatString, inliningTarget, raiseNode);
}
@Specialization(guards = "!formatString.isEmpty()")
static TruffleString formatI(int self, TruffleString formatString,
@Bind("this") Node inliningTarget,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Spec spec = getSpec(formatString, inliningTarget);
if (isDoubleSpec(spec)) {
return formatDouble(spec, self, inliningTarget);
@@ -2932,7 +2932,7 @@ static TruffleString formatL(VirtualFrame frame, long self, TruffleString format
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached PyNumberFloatNode floatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return formatPI(frame, PFactory.createInt(language, self), formatString, inliningTarget, floatNode, raiseNode);
}
@@ -2940,7 +2940,7 @@ static TruffleString formatL(VirtualFrame frame, long self, TruffleString format
static TruffleString formatPI(VirtualFrame frame, PInt self, TruffleString formatString,
@Bind("this") Node inliningTarget,
@Shared @Cached PyNumberFloatNode floatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Spec spec = getSpec(formatString, inliningTarget);
if (isDoubleSpec(spec)) {
// lazy init of floatNode serves as branch profile
@@ -2987,15 +2987,15 @@ private static TruffleString formatPInt(PInt self, Spec spec, Node raisingNode)
return formatter.pad().getResult();
}
- private static void validateIntegerSpec(Node inliningTarget, PRaiseNode.Lazy raiseNode, Spec spec) {
+ private static void validateIntegerSpec(Node inliningTarget, PRaiseNode raiseNode, Spec spec) {
if (Spec.specified(spec.precision)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.PRECISION_NOT_ALLOWED_FOR_INT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.PRECISION_NOT_ALLOWED_FOR_INT);
}
if (spec.type == 'c') {
if (Spec.specified(spec.sign)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SIGN_NOT_ALLOWED_WITH_C_FOR_INT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SIGN_NOT_ALLOWED_WITH_C_FOR_INT);
} else if (spec.alternate) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ALTERNATE_NOT_ALLOWED_WITH_C_FOR_INT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ALTERNATE_NOT_ALLOWED_WITH_C_FOR_INT);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
index a92f61f607..4cd53ffff2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java
@@ -150,26 +150,26 @@ static byte[] doPrimitive(long value, int size, boolean bigEndian,
@Specialization
static byte[] doArbitraryBytesLong(Node inliningTarget, long value, int size, boolean bigEndian,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
final byte[] bytes = new byte[size];
NumericSupport support = bigEndian ? NumericSupport.bigEndian() : NumericSupport.littleEndian();
try {
support.putBigInteger(bytes, 0, PInt.longToBigInteger(value), size);
} catch (OverflowException oe) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, TOO_LARGE_TO_CONVERT, "int");
+ throw raiseNode.raise(inliningTarget, OverflowError, TOO_LARGE_TO_CONVERT, "int");
}
return bytes;
}
@Specialization
static byte[] doPInt(Node inliningTarget, PInt value, int size, boolean bigEndian,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
final byte[] bytes = new byte[size];
NumericSupport support = bigEndian ? NumericSupport.bigEndian() : NumericSupport.littleEndian();
try {
support.putBigInteger(bytes, 0, value.getValue(), size);
} catch (OverflowException oe) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, TOO_LARGE_TO_CONVERT, "int");
+ throw raiseNode.raise(inliningTarget, OverflowError, TOO_LARGE_TO_CONVERT, "int");
}
return bytes;
}
@@ -198,7 +198,7 @@ static Object doOther(Node inliningTarget, byte[] data, boolean littleEndian, bo
@Cached InlinedBranchProfile fastPath4,
@Cached InlinedBranchProfile fastPath8,
@Cached InlinedBranchProfile generic,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
NumericSupport support = littleEndian ? NumericSupport.littleEndian() : NumericSupport.bigEndian();
if (signed) {
switch (data.length) {
@@ -230,7 +230,7 @@ static Object doOther(Node inliningTarget, byte[] data, boolean littleEndian, bo
return PFactory.createInt(PythonLanguage.get(inliningTarget), integer);
}
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
index 7808530e9a..1b8e62a498 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java
@@ -403,7 +403,7 @@ public double doubleValueWithOverflow(Node raisingNode) {
public static double doubleValueWithOverflow(Node raisingNode, BigInteger value) {
double d = value.doubleValue();
if (Double.isInfinite(d)) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.INT_TOO_LARGE_TO_CONVERT_TO_FLOAT);
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.INT_TOO_LARGE_TO_CONVERT_TO_FLOAT);
}
return d;
}
@@ -605,7 +605,7 @@ public static int long2int(Node inliningTarget, long size, InlinedBranchProfile
int intSize = (int) size;
if (intSize != size) {
errorProfile.enter(inliningTarget);
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size);
}
return intSize;
}
@@ -689,7 +689,6 @@ private boolean fitsIn(BigInteger left, BigInteger right) {
* Creates a Python {@code int} object from a Java {@code long} value by interpreting it as an
* unsigned number.
*
- * @param factory Python object factory
* @param profile condition profile for the case when the unsigned value fits into Java
* {@code long}
* @param value the value
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
index 09427fc2b7..bb0cd3889d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java
@@ -140,18 +140,18 @@ public abstract static class NextHelperNode extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object iterator, boolean throwStopIteration);
- private static Object stopIteration(Node inliningTarget, PBuiltinIterator self, boolean throwStopIteration, PRaiseNode.Lazy raiseNode) {
+ private static Object stopIteration(Node inliningTarget, PBuiltinIterator self, boolean throwStopIteration, PRaiseNode raiseNode) {
self.setExhausted();
if (throwStopIteration) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
} else {
return STOP_MARKER;
}
}
- private static Object stopIterationForeign(Node inliningTarget, boolean throwStopIteration, PRaiseNode.Lazy raiseNode) {
+ private static Object stopIterationForeign(Node inliningTarget, boolean throwStopIteration, PRaiseNode raiseNode) {
if (throwStopIteration) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
} else {
return STOP_MARKER;
}
@@ -159,9 +159,9 @@ private static Object stopIterationForeign(Node inliningTarget, boolean throwSto
@Specialization(guards = "self.isExhausted()")
static Object exhausted(Node inliningTarget, @SuppressWarnings("unused") PBuiltinIterator self, boolean throwStopIteration,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (throwStopIteration) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
} else {
return STOP_MARKER;
}
@@ -171,7 +171,7 @@ static Object exhausted(Node inliningTarget, @SuppressWarnings("unused") PBuilti
static Object next(Node inliningTarget, PArrayIterator self, boolean throwStopIteration,
@Cached InlinedExactClassProfile itemTypeProfile,
@Cached ArrayNodes.GetValueNode getValueNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
PArray array = self.array;
if (self.getIndex() < array.getLength()) {
return itemTypeProfile.profile(inliningTarget, getValueNode.execute(inliningTarget, array, self.index++));
@@ -181,7 +181,7 @@ static Object next(Node inliningTarget, PArrayIterator self, boolean throwStopIt
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PIntegerSequenceIterator self, boolean throwStopIteration,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getIndex() < self.sequence.length()) {
return self.sequence.getIntItemNormalized(self.index++);
}
@@ -190,7 +190,7 @@ static Object next(Node inliningTarget, PIntegerSequenceIterator self, boolean t
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PObjectSequenceIterator self, boolean throwStopIteration,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getIndex() < self.sequence.length()) {
return self.sequence.getObjectItemNormalized(self.index++);
}
@@ -200,7 +200,7 @@ static Object next(Node inliningTarget, PObjectSequenceIterator self, boolean th
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PIntRangeIterator self, boolean throwStopIteration,
@Exclusive @Cached InlinedConditionProfile profile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (profile.profile(inliningTarget, self.hasNextInt())) {
return self.nextInt();
}
@@ -210,7 +210,7 @@ static Object next(Node inliningTarget, PIntRangeIterator self, boolean throwSto
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PBigRangeIterator self, boolean throwStopIteration,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.hasNextBigInt()) {
return PFactory.createInt(language, self.nextBigInt());
}
@@ -219,7 +219,7 @@ static Object next(Node inliningTarget, PBigRangeIterator self, boolean throwSto
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PDoubleSequenceIterator self, boolean throwStopIteration,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getIndex() < self.sequence.length()) {
return self.sequence.getDoubleItemNormalized(self.index++);
}
@@ -228,7 +228,7 @@ static Object next(Node inliningTarget, PDoubleSequenceIterator self, boolean th
@Specialization(guards = "!self.isExhausted()")
static Object next(Node inliningTarget, PLongSequenceIterator self, boolean throwStopIteration,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getIndex() < self.sequence.length()) {
return self.sequence.getLongItemNormalized(self.index++);
}
@@ -239,7 +239,7 @@ static Object next(Node inliningTarget, PLongSequenceIterator self, boolean thro
static Object next(Node inliningTarget, PStringIterator self, boolean throwStopIteration,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@Cached(inline = false) TruffleString.SubstringNode substringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.getIndex() < codePointLengthNode.execute(self.value, TS_ENCODING)) {
return substringNode.execute(self.value, self.index++, 1, TS_ENCODING, false);
}
@@ -253,13 +253,13 @@ static Object nextHashingStorageIter(Node inliningTarget, PHashingStorageIterato
@Cached HashingStorageIteratorNext nextNode,
@Cached PHashingStorageIteratorNextValue itValueNode,
@Exclusive @Cached InlinedConditionProfile profile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
HashingStorage storage = self.getHashingStorage();
final HashingStorageIterator it = self.getIterator();
if (profile.profile(inliningTarget, nextNode.execute(inliningTarget, storage, it))) {
if (sizeChanged.profile(inliningTarget, self.checkSizeChanged(inliningTarget, lenNode))) {
String name = PBaseSetIterator.isInstance(self) ? "Set" : "dictionary";
- throw raiseNode.get(inliningTarget).raise(RuntimeError, ErrorMessages.CHANGED_SIZE_DURING_ITERATION, name);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.CHANGED_SIZE_DURING_ITERATION, name);
}
self.index++;
return itValueNode.execute(inliningTarget, self, storage, it);
@@ -271,7 +271,7 @@ static Object nextHashingStorageIter(Node inliningTarget, PHashingStorageIterato
static Object next(Node inliningTarget, PSequenceIterator self, boolean throwStopIteration,
@Cached SequenceNodes.GetSequenceStorageNode getStorage,
@Cached(value = "createNotNormalized()", inline = false) SequenceStorageNodes.GetItemNode getItemNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
SequenceStorage s = getStorage.execute(inliningTarget, self.getPSequence());
if (self.getIndex() < s.length()) {
return getItemNode.execute(s, self.index++);
@@ -283,7 +283,7 @@ static Object next(Node inliningTarget, PSequenceIterator self, boolean throwSto
static Object next(VirtualFrame frame, Node inliningTarget, PSequenceIterator self, boolean throwStopIteration,
@Cached(inline = false) PySequenceGetItemNode getItem,
@Cached IsBuiltinObjectProfile profile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
/*
* This must use PySequence_GetItem and not any other get item nodes. The reason is
@@ -305,7 +305,7 @@ static Object foreign(Node inliningTarget, Object self, boolean throwStopIterati
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
@Cached(inline = false) PForeignToPTypeNode toPythonNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
final Object element;
gil.release(true);
@@ -597,9 +597,8 @@ static Object reduceNonSeq(@SuppressWarnings({"unused"}) VirtualFrame frame, PSe
@Fallback
static int other(Object self,
- @Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "iterator", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "iterator", self);
}
private static PTuple reduceInternal(VirtualFrame frame, Node inliningTarget, Object arg, PythonContext context, PyObjectGetAttr getAttrNode) {
@@ -650,9 +649,8 @@ static Object setstate(VirtualFrame frame, PBuiltinIterator self, Object index,
@Fallback
static Object other(Object self, Object index,
- @Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "iterator", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "iterator", self);
}
protected static boolean isPBigRangeIterator(Object obj) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorNodes.java
index 00f0bb40e7..12b75fb4d9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -177,7 +177,7 @@ static int length(VirtualFrame frame, Node inliningTarget, Object iterable,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached InlinedConditionProfile hasLenProfile,
@Cached InlinedConditionProfile hasLengthHintProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object clazz = getClassNode.execute(inliningTarget, iterable);
TpSlots slots = getSlotsNode.execute(inliningTarget, clazz);
if (hasLenProfile.profile(inliningTarget, slots.combined_sq_mp_length() != null)) {
@@ -204,11 +204,11 @@ static int length(VirtualFrame frame, Node inliningTarget, Object iterable,
if (indexCheckNode.execute(inliningTarget, len)) {
int intLen = asSizeNode.executeExact(frame, inliningTarget, len);
if (intLen < 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.LENGTH_HINT_SHOULD_RETURN_MT_ZERO);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.LENGTH_HINT_SHOULD_RETURN_MT_ZERO);
}
return intLen;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_INTEGER_NOT_P, T___LENGTH_HINT__, len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_INTEGER_NOT_P, T___LENGTH_HINT__, len);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
index 41f11490d7..f48f59267f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java
@@ -74,8 +74,8 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "isEmpty(self.getIterators())")
static Object doEmpty(@SuppressWarnings("unused") PZip self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
@Specialization(guards = {"!isEmpty(self.getIterators())", "!self.isStrict()"})
@@ -96,7 +96,7 @@ static Object doNext(VirtualFrame frame, PZip self,
@Shared @Cached GetNextNode next,
@Cached IsBuiltinObjectProfile classProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] iterators = self.getIterators();
Object[] tupleElements = new Object[iterators.length];
int i = 0;
@@ -108,12 +108,12 @@ static Object doNext(VirtualFrame frame, PZip self,
} catch (PException e) {
e.expectStopIteration(inliningTarget, classProfile);
if (i > 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.ZIP_ARG_D_IS_SHORTER_THEN_ARG_SD, i + 1, i == 1 ? " " : "s 1-", i);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ZIP_ARG_D_IS_SHORTER_THEN_ARG_SD, i + 1, i == 1 ? " " : "s 1-", i);
}
for (i = 1; i < iterators.length; i++) {
try {
next.execute(frame, iterators[i]);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.ZIP_ARG_D_IS_LONGER_THEN_ARG_SD, i + 1, i == 1 ? " " : "s 1-", i);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.ZIP_ARG_D_IS_LONGER_THEN_ARG_SD, i + 1, i == 1 ? " " : "s 1-", i);
} catch (PException e2) {
e2.expectStopIteration(inliningTarget, classProfile);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
index b419a5a504..a93f9c27ef 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/SentinelIteratorBuiltins.java
@@ -73,9 +73,9 @@ static Object doIterator(VirtualFrame frame, PSentinelIterator iterator,
@Cached CallNode callNode,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached PyObjectRichCompareBool.EqNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (iterator.sentinelReached()) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
Object nextValue;
try {
@@ -88,7 +88,7 @@ static Object doIterator(VirtualFrame frame, PSentinelIterator iterator,
boolean iteratorDone = eqNode.compare(frame, inliningTarget, nextValue, iterator.getSentinel());
if (iteratorDone) {
iterator.markSentinelReached();
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return nextValue;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
index 5b917c735b..09c0ffd1e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ChainBuiltins.java
@@ -110,7 +110,7 @@ static Object next(VirtualFrame frame, PChain self,
@Cached IsBuiltinObjectProfile isStopIterationProfile,
@Cached InlinedBranchProfile nextExceptioProfile,
@Cached InlinedLoopConditionProfile loopProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
while (loopProfile.profile(inliningTarget, self.getSource() != PNone.NONE)) {
if (self.getActive() == PNone.NONE) {
try {
@@ -130,7 +130,7 @@ static Object next(VirtualFrame frame, PChain self,
self.setActive(PNone.NONE);
}
}
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
}
@@ -185,13 +185,13 @@ static Object setState(VirtualFrame frame, PChain self, Object state,
@Cached GetItemNode getItemNode,
@Cached InlinedBranchProfile len2Profile,
@Cached PyIterCheckNode iterCheckNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(state instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "a length 1 or 2 tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "a length 1 or 2 tuple");
}
int len = (int) lenNode.execute(frame, state);
if (len < 1 || len > 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "a length 1 or 2 tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "a length 1 or 2 tuple");
}
Object source = getItemNode.execute(frame, state, 0);
checkIterator(inliningTarget, iterCheckNode, source, raiseNode);
@@ -205,9 +205,9 @@ static Object setState(VirtualFrame frame, PChain self, Object state,
return PNone.NONE;
}
- private static void checkIterator(Node inliningTarget, PyIterCheckNode iterCheckNode, Object obj, PRaiseNode.Lazy raiseNode) throws PException {
+ private static void checkIterator(Node inliningTarget, PyIterCheckNode iterCheckNode, Object obj, PRaiseNode raiseNode) throws PException {
if (!iterCheckNode.execute(inliningTarget, obj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ARGUMENTS_MUST_BE_ITERATORS);
+ throw raiseNode.raise(inliningTarget, TypeError, ARGUMENTS_MUST_BE_ITERATORS);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
index 902aba2cbf..932733c7fc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CombinationsBuiltins.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.itertools;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
@@ -105,8 +106,8 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization(guards = "self.isStopped()")
static Object nextStopped(PAbstractCombinations self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
@Specialization(guards = {"!self.isStopped()", "isLastResultNull(self)"})
@@ -130,7 +131,7 @@ static Object next(PCombinations self,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedLoopConditionProfile indexLoopProfile,
@Shared @Cached InlinedLoopConditionProfile resultLoopProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return nextInternal(inliningTarget, self, indexLoopProfile, resultLoopProfile, raiseNode);
}
@@ -139,12 +140,12 @@ static Object next(PCombinationsWithReplacement self,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedLoopConditionProfile indexLoopProfile,
@Shared @Cached InlinedLoopConditionProfile resultLoopProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return nextInternal(inliningTarget, self, indexLoopProfile, resultLoopProfile, raiseNode);
}
private static Object nextInternal(Node inliningTarget, PAbstractCombinations self, InlinedLoopConditionProfile indexLoopProfile,
- InlinedLoopConditionProfile resultLoopProfile, PRaiseNode.Lazy raiseNode) throws PException {
+ InlinedLoopConditionProfile resultLoopProfile, PRaiseNode raiseNode) throws PException {
CompilerAsserts.partialEvaluationConstant(self.getClass());
@@ -161,7 +162,7 @@ private static Object nextInternal(Node inliningTarget, PAbstractCombinations se
// If i is negative, then the indices are all at their maximum value and we're done
if (i < 0) {
self.setStopped(true);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, StopIteration);
}
// Increment the current index which we know is not at its maximum.
@@ -223,7 +224,7 @@ static Object setState(PAbstractCombinations self, Object stateObj,
@Bind("this") Node inliningTarget,
@Cached CastToJavaIntExactNode cast,
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int n = self.getPool().length;
if (stateObj instanceof PTuple state && state.getSequenceStorage().length() == self.getR()) {
SequenceStorage storage = state.getSequenceStorage();
@@ -240,7 +241,7 @@ static Object setState(PAbstractCombinations self, Object stateObj,
self.getIndices()[i] = index;
}
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
Object[] result = new Object[self.getR()];
for (int i = 0; i < self.getR(); i++) {
@@ -249,7 +250,7 @@ static Object setState(PAbstractCombinations self, Object stateObj,
self.setLastResult(result);
return PNone.NONE;
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_ARGS, T___SETSTATE__);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_ARGS, T___SETSTATE__);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
index a06f28a1b8..6562eb0817 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CycleBuiltins.java
@@ -115,7 +115,7 @@ static Object next(VirtualFrame frame, PCycle self,
@Cached IsBuiltinObjectProfile isStopIterationProfile,
@Cached InlinedBranchProfile iterableProfile,
@Cached InlinedBranchProfile firstPassProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getIterable() != null) {
iterableProfile.enter(inliningTarget);
try {
@@ -131,7 +131,7 @@ static Object next(VirtualFrame frame, PCycle self,
}
}
if (isEmpty(self.getSaved())) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
Object item = get(self.getSaved(), self.getIndex());
self.setIndex(self.getIndex() + 1);
@@ -223,13 +223,13 @@ static Object setState(VirtualFrame frame, PCycle self, Object state,
@Cached IsBuiltinObjectProfile isTypeErrorProfile,
@Cached ToArrayNode toArrayNode,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!((state instanceof PTuple) && ((int) lenNode.execute(frame, state) == 2))) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "2-tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "2-tuple");
}
Object obj = getItemNode.execute(frame, state, 0);
if (!(obj instanceof PList)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, STATE_ARGUMENT_D_MUST_BE_A_S, 1, "Plist");
+ throw raiseNode.raise(inliningTarget, TypeError, STATE_ARGUMENT_D_MUST_BE_A_S, 1, "Plist");
}
PList saved = (PList) obj;
@@ -238,7 +238,7 @@ static Object setState(VirtualFrame frame, PCycle self, Object state,
firstPass = asSizeNode.executeLossy(frame, inliningTarget, getItemNode.execute(frame, state, 1)) != 0;
} catch (PException e) {
e.expectTypeError(inliningTarget, isTypeErrorProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, STATE_ARGUMENT_D_MUST_BE_A_S, 2, "int");
+ throw raiseNode.raise(inliningTarget, TypeError, STATE_ARGUMENT_D_MUST_BE_A_S, 2, "int");
}
Object[] savedArray = toArrayNode.execute(inliningTarget, saved.getSequenceStorage());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
index 7243f932ad..3609a583f3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/DropwhileBuiltins.java
@@ -140,11 +140,11 @@ public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
static Object setState(PDropwhile self, Object state,
@Bind("this") Node inliningTarget,
@Cached CastToJavaBooleanNode castToBoolean,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
self.setDoneDropping(castToBoolean.execute(inliningTarget, state));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_ARGS, T___SETSTATE__);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_ARGS, T___SETSTATE__);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
index d3b061d25d..1b5ac87fba 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GroupByBuiltins.java
@@ -168,9 +168,9 @@ static Object setState(VirtualFrame frame, PGroupBy self, Object state,
@Bind("this") Node inliningTarget,
@Cached TupleBuiltins.LenNode lenNode,
@Cached TupleBuiltins.GetItemNode getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(state instanceof PTuple) || (int) lenNode.execute(frame, state) != 3) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "3-tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "3-tuple");
}
Object currValue = getItemNode.execute(frame, state, 0);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
index 06a07127df..80a5206723 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/GrouperBuiltins.java
@@ -104,11 +104,11 @@ static Object next(VirtualFrame frame, PGrouper self,
@Cached InlinedBranchProfile currValueMarkerProfile,
@Cached InlinedBranchProfile currValueTgtProfile,
@Cached InlinedConditionProfile hasFuncProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PGroupBy gbo = self.getParent();
if (gbo.getCurrGrouper() != self) {
currGrouperProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
if (gbo.getCurrValue() == null) {
currValueMarkerProfile.enter(inliningTarget);
@@ -116,7 +116,7 @@ static Object next(VirtualFrame frame, PGrouper self,
}
if (!eqNode.compare(frame, inliningTarget, self.getTgtKey(), gbo.getCurrKey())) {
currValueTgtProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
Object r = gbo.getCurrValue();
gbo.setCurrValue(null);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
index b076d60e46..8a1d726f33 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/IsliceBuiltins.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.itertools;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
import static com.oracle.graal.python.nodes.ErrorMessages.INVALID_ARGS;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
@@ -101,8 +102,8 @@ static Object iter(PIslice self) {
public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "isNone(self.getIterable())")
static Object next(@SuppressWarnings("unused") PIslice self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
@Specialization(guards = "!isNone(self.getIterable())")
@@ -113,7 +114,7 @@ static Object next(VirtualFrame frame, PIslice self,
@Cached InlinedBranchProfile nextExceptionProfile,
@Cached InlinedBranchProfile nextExceptionProfile2,
@Cached InlinedBranchProfile setNextProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object it = self.getIterable();
int stop = self.getStop();
Object item;
@@ -130,7 +131,7 @@ static Object next(VirtualFrame frame, PIslice self,
}
if (stop != -1 && self.getCnt() >= stop) {
self.setIterable(PNone.NONE);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, StopIteration);
}
try {
item = nextNode.execute(frame, it, PNone.NO_VALUE);
@@ -184,11 +185,11 @@ public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
static Object setState(PIslice self, Object state,
@Bind("this") Node inliningTarget,
@Cached CastToJavaIntLossyNode castInt,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
self.setCnt(castInt.execute(inliningTarget, state));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_ARGS, T___SETSTATE__);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_ARGS, T___SETSTATE__);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
index 37ea4b0cbb..cb20fc0baa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PTeeDataObject.java
@@ -122,14 +122,14 @@ PTeeDataObject jumplink(PythonLanguage language) {
return nextlink;
}
- Object getItem(VirtualFrame frame, Node inliningTarget, int i, BuiltinFunctions.NextNode nextNode, PRaiseNode.Lazy raiseNode) {
+ Object getItem(VirtualFrame frame, Node inliningTarget, int i, BuiltinFunctions.NextNode nextNode, PRaiseNode raiseNode) {
assert i < TeeDataObjectBuiltins.LINKCELLS;
if (i < numread) {
return values[i];
} else {
assert i == numread;
if (running) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, CANNOT_REENTER_TEE_ITERATOR);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, CANNOT_REENTER_TEE_ITERATOR);
}
running = true;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
index 5cb777aceb..1f0b789210 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PairwiseBuiltins.java
@@ -112,8 +112,8 @@ static Object next(VirtualFrame frame, PPairwise self,
@Specialization(guards = "self.getIterable() == null")
static Object next(@SuppressWarnings("unused") PPairwise self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
index b1c9de1981..3500aa3628 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/PermutationsBuiltins.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.itertools;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
import static com.oracle.graal.python.nodes.ErrorMessages.INVALID_ARGS;
@@ -105,9 +106,9 @@ static Object iter(PPermutations self) {
public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.isStopped()")
static Object next(PPermutations self,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
self.setRaisedStopIteration(true);
- throw raiseNode.raiseStopIteration();
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
@Specialization(guards = "!self.isStopped()")
@@ -119,7 +120,7 @@ static Object next(PPermutations self,
@Cached InlinedLoopConditionProfile mainLoopProfile,
@Cached InlinedLoopConditionProfile shiftIndicesProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int r = self.getR();
int[] indices = self.getIndices();
@@ -156,7 +157,7 @@ static Object next(PPermutations self,
self.setStopped(true);
if (isStartedProfile.profile(inliningTarget, self.isStarted())) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, StopIteration);
} else {
self.setStarted(true);
}
@@ -210,16 +211,16 @@ static Object setState(VirtualFrame frame, PPermutations self, Object state,
@Cached InlinedLoopConditionProfile cyclesProfile,
@Cached CastToJavaBooleanNode castBoolean,
@Cached CastToJavaIntExactNode castInt,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (sizeNode.execute(frame, inliningTarget, state) != 3) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_ARGS, T___SETSTATE__);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_ARGS, T___SETSTATE__);
}
Object indices = getItemNode.execute(frame, state, 0);
Object cycles = getItemNode.execute(frame, state, 1);
int poolLen = self.getPool().length;
if (sizeNode.execute(frame, inliningTarget, indices) != poolLen || sizeNode.execute(frame, inliningTarget, cycles) != self.getR()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_ARGS, T___SETSTATE__);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_ARGS, T___SETSTATE__);
}
self.setStarted(castBoolean.execute(inliningTarget, getItemNode.execute(frame, state, 2)));
@@ -247,7 +248,7 @@ static Object setState(VirtualFrame frame, PPermutations self, Object state,
return PNone.NONE;
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
index 8a412aadae..73e109e2ae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ProductBuiltins.java
@@ -120,7 +120,7 @@ static Object next(PProduct self,
@Exclusive @Cached InlinedLoopConditionProfile loopProfile,
@Cached InlinedBranchProfile doneProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[][] gears = self.getGears();
int x = gears.length - 1;
if (gearsProfile.profile(inliningTarget, x >= 0)) {
@@ -140,7 +140,7 @@ static Object next(PProduct self,
if (self.isStopped()) {
wasStoppedProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
// the existing lst array can be changed in a following next call
@@ -152,8 +152,8 @@ static Object next(PProduct self,
@SuppressWarnings("unused")
@Specialization(guards = "self.isStopped()")
static Object nextStopped(PProduct self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
private static void rotatePreviousGear(Node inliningTarget, PProduct self, InlinedLoopConditionProfile loopProfile, InlinedBranchProfile doneProfile) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
index 1a07d71706..a5e805f45f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/RepeatBuiltins.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.itertools;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.nodes.ErrorMessages.LEN_OF_UNSIZED_OBJECT;
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___NAME__;
@@ -106,8 +107,8 @@ static Object nextPos(PRepeat self) {
@SuppressWarnings("unused")
@Specialization(guards = "self.getCnt() == 0")
static Object nextZero(PRepeat self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
@Specialization(guards = "self.getCnt() < 0")
@@ -127,8 +128,8 @@ static Object hintPos(PRepeat self) {
@SuppressWarnings("unused")
@Specialization(guards = "self.getCnt() < 0")
static Object hintNeg(PRepeat self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, LEN_OF_UNSIZED_OBJECT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, LEN_OF_UNSIZED_OBJECT);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
index d0784fbad1..fc50ba486f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TakewhileBuiltins.java
@@ -97,11 +97,11 @@ static Object next(VirtualFrame frame, PTakewhile self,
@Cached CallNode callNode,
@Cached PyObjectIsTrueNode isTrue,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object value = nextNode.execute(frame, self.getIterable(), PNone.NO_VALUE);
if (!isTrue.execute(frame, callNode.execute(frame, self.getPredicate(), value))) {
self.setIterable(PFactory.createSequenceIterator(language, PFactory.createList(language, PythonUtils.EMPTY_OBJECT_ARRAY)));
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return value;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
index 4fb2a302bb..775263a32a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeBuiltins.java
@@ -148,7 +148,7 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
static Object next(VirtualFrame frame, PTee self,
@Bind("this") Node inliningTarget,
@Shared @Cached BuiltinFunctions.NextNode nextNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object value = self.getDataobj().getItem(frame, inliningTarget, self.getIndex(), nextNode, raiseNode);
self.setIndex(self.getIndex() + 1);
return value;
@@ -159,7 +159,7 @@ static Object nextNext(VirtualFrame frame, PTee self,
@Bind("this") Node inliningTarget,
@Shared @Cached BuiltinFunctions.NextNode nextNode,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.setDataObj(self.getDataobj().jumplink(language));
Object value = self.getDataobj().getItem(frame, inliningTarget, 0, nextNode, raiseNode);
self.setIndex(1);
@@ -194,14 +194,14 @@ static Object setState(VirtualFrame frame, PTee self, Object state,
@Cached LenNode lenNode,
@Cached TupleBuiltins.GetItemNode getItemNode,
@Cached CastToJavaIntLossyNode castToIntNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!(state instanceof PTuple) || (int) lenNode.execute(frame, state) != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "2-tuple");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "2-tuple");
}
Object dataObject = getItemNode.execute(frame, state, 0);
if (!(dataObject instanceof PTeeDataObject)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, IS_NOT_A, "state", "_tee_dataobject");
+ throw raiseNode.raise(inliningTarget, TypeError, IS_NOT_A, "state", "_tee_dataobject");
}
self.setDataObj((PTeeDataObject) dataObject);
Object secondElement = getItemNode.execute(frame, state, 1);
@@ -209,10 +209,10 @@ static Object setState(VirtualFrame frame, PTee self, Object state,
try {
index = castToIntNode.execute(inliningTarget, secondElement);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, INTEGER_REQUIRED_GOT, secondElement);
+ throw raiseNode.raise(inliningTarget, TypeError, INTEGER_REQUIRED_GOT, secondElement);
}
if (index < 0 || index > LINKCELLS) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, INDEX_OUT_OF_RANGE);
}
self.setIndex(index);
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
index 2fd392cea7..279dd0dfbf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java
@@ -129,17 +129,17 @@ static Object init(VirtualFrame frame, PTeeDataObject self, Object it, PList val
@Cached LenNode lenNode,
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getInternalObjectArrayNode,
@Cached InlinedBranchProfile numreadLCProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int numread = (int) lenNode.execute(frame, values);
if (numread == LINKCELLS) {
numreadLCProfile.enter(inliningTarget);
if (!(nxt instanceof PTeeDataObject)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, S_MUST_BE_S, "_tee_dataobject next link", "_tee_dataobject");
+ throw raiseNode.raise(inliningTarget, ValueError, S_MUST_BE_S, "_tee_dataobject next link", "_tee_dataobject");
}
} else if (numread > LINKCELLS) {
- throw raiseNode.get(inliningTarget).raise(ValueError, TDATAOBJECT_SHOULD_NOT_HAVE_MORE_LINKS, LINKCELLS);
+ throw raiseNode.raise(inliningTarget, ValueError, TDATAOBJECT_SHOULD_NOT_HAVE_MORE_LINKS, LINKCELLS);
} else if (!(nxt instanceof PNone)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, TDATAOBJECT_SHOULDNT_HAVE_NEXT);
+ throw raiseNode.raise(inliningTarget, ValueError, TDATAOBJECT_SHOULDNT_HAVE_NEXT);
}
self.setIt(it);
Object[] valuesArray = getInternalObjectArrayNode.execute(inliningTarget, values.getSequenceStorage());
@@ -155,8 +155,8 @@ static Object init(VirtualFrame frame, PTeeDataObject self, Object it, PList val
@SuppressWarnings("unused")
@Specialization(guards = {"!isList(values)", "!isNone(values)"})
static Object init(VirtualFrame frame, PTeeDataObject self, Object it, Object values, Object nxt,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ARG_D_MUST_BE_S_NOT_P, "teedataobject()", 2, "list", values);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARG_D_MUST_BE_S_NOT_P, "teedataobject()", 2, "list", values);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
index b2383c162c..ba82bf8630 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/ZipLongestBuiltins.java
@@ -97,8 +97,8 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization(guards = "zeroSize(self)")
static Object nextNoFillValue(VirtualFrame frame, PZipLongest self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, StopIteration);
}
@Specialization(guards = "!zeroSize(self)")
@@ -110,13 +110,13 @@ static Object next(VirtualFrame frame, PZipLongest self,
@Cached InlinedConditionProfile noActiveProfile,
@Cached InlinedLoopConditionProfile loopProfile,
@Cached InlinedConditionProfile isNullFillProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object fillValue = isNullFillProfile.profile(inliningTarget, isNullFillValue(self)) ? PNone.NONE : self.getFillValue();
return next(frame, inliningTarget, self, fillValue, nextNode, isStopIterationProfile, loopProfile, noItProfile, noActiveProfile, raiseNode);
}
private static Object next(VirtualFrame frame, Node inliningTarget, PZipLongest self, Object fillValue, BuiltinFunctions.NextNode nextNode, IsBuiltinObjectProfile isStopIterationProfile,
- InlinedLoopConditionProfile loopProfile, InlinedConditionProfile noItProfile, InlinedConditionProfile noActiveProfile, PRaiseNode.Lazy raiseNode) {
+ InlinedLoopConditionProfile loopProfile, InlinedConditionProfile noItProfile, InlinedConditionProfile noActiveProfile, PRaiseNode raiseNode) {
Object[] result = new Object[self.getItTuple().length];
loopProfile.profileCounted(inliningTarget, result.length);
for (int i = 0; loopProfile.inject(inliningTarget, i < result.length); i++) {
@@ -131,7 +131,7 @@ private static Object next(VirtualFrame frame, Node inliningTarget, PZipLongest
if (isStopIterationProfile.profileException(inliningTarget, e, StopIteration)) {
self.setNumActive(self.getNumActive() - 1);
if (noActiveProfile.profile(inliningTarget, self.getNumActive() == 0)) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, StopIteration);
} else {
item = fillValue;
self.getItTuple()[i] = PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
index 764b804251..f3916c4527 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
@@ -308,7 +308,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
@Cached GetListStorageNode getStorageNode,
@Cached InlinedConditionProfile validProfile,
@Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached SequenceStorageMpSubscriptNode subscriptNode) {
if (!validProfile.profile(inliningTarget, SequenceStorageMpSubscriptNode.isValidIndex(inliningTarget, idx, indexCheckNode))) {
raiseNonIntIndex(inliningTarget, raiseNode, idx);
@@ -319,8 +319,8 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
}
@InliningCutoff
- private static void raiseNonIntIndex(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object index) {
- raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "list", index);
+ private static void raiseNonIntIndex(Node inliningTarget, PRaiseNode raiseNode, Object index) {
+ raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "list", index);
}
}
@@ -394,8 +394,8 @@ static void doGenericDel(VirtualFrame frame, Object list, Object key, @SuppressW
@Specialization(guards = "!isIndexOrSlice(this, indexCheckNode, key)")
static void doError(Object self, Object key, Object value,
@Shared("indexCheckNode") @SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "list", key);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "list", key);
}
@NeverDefault
@@ -519,7 +519,7 @@ static PNone remove(VirtualFrame frame, Object list, Object value,
@Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode,
@Cached SequenceStorageNodes.DeleteNode deleteNode,
@Cached PyObjectRichCompareBool.EqNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage listStore = getStorageNode.execute(inliningTarget, list);
int len = listStore.length();
for (int i = 0; i < len; i++) {
@@ -529,7 +529,7 @@ static PNone remove(VirtualFrame frame, Object list, Object value,
return PNone.NONE;
}
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.NOT_IN_LIST_MESSAGE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.NOT_IN_LIST_MESSAGE);
}
}
@@ -564,8 +564,8 @@ static Object doIndex(VirtualFrame frame, Object list, Object idx,
@Fallback
static Object doError(@SuppressWarnings("unused") Object list, Object arg,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
}
@NeverDefault
@@ -593,7 +593,7 @@ static Object index(VirtualFrame frame, Object self, Object value, int start, in
@Cached InlinedBranchProfile startAdjust,
@Cached InlinedBranchProfile stopAdjust,
@Cached SequenceStorageNodes.ItemIndexNode indexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage s = getListStorageNode.execute(inliningTarget, self);
start = adjustIndex(inliningTarget, s, start, startAdjust);
stop = adjustIndex(inliningTarget, s, stop, stopAdjust);
@@ -601,7 +601,7 @@ static Object index(VirtualFrame frame, Object self, Object value, int start, in
if (idx != -1) {
return idx;
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.X_NOT_IN_LIST);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.X_NOT_IN_LIST);
}
private static int adjustIndex(Node inliningTarget, SequenceStorage s, int index, InlinedBranchProfile profile) {
@@ -692,14 +692,14 @@ public final Object execute(VirtualFrame frame, Object list) {
static Object doPList(VirtualFrame frame, PList list, Object keyfunc, boolean reverse,
@Bind("this") Node inliningTarget,
@Shared @Cached SortSequenceStorageNode sortSequenceStorageNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = list.getSequenceStorage();
// Make the list temporarily empty to prevent concurrent modification
list.setSequenceStorage(EmptySequenceStorage.INSTANCE);
try {
sortSequenceStorageNode.execute(frame, storage, keyfunc, reverse);
if (list.getSequenceStorage() != EmptySequenceStorage.INSTANCE) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.LIST_MODIFIED_DURING_SORT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.LIST_MODIFIED_DURING_SORT);
}
} finally {
list.setSequenceStorage(storage);
@@ -754,9 +754,9 @@ static PList doPList(Object left, Object right,
@Cached("createConcat()") SequenceStorageNodes.ConcatNode concatNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isListNode.execute(inliningTarget, right)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "list", right, "list");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "list", right, "list");
}
var leftStorage = getStorageNode.execute(inliningTarget, left);
@@ -805,7 +805,7 @@ static Object doPListInt(VirtualFrame frame, Object left, int right,
@Cached GetListStorageNode getStorageNode,
@Cached SequenceStorageNodes.RepeatNode repeatNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isListNode.execute(inliningTarget, left)) {
return PNotImplemented.NOT_IMPLEMENTED;
}
@@ -815,7 +815,7 @@ static Object doPListInt(VirtualFrame frame, Object left, int right,
SequenceStorage repeated = repeatNode.execute(frame, sequenceStorage, right);
return PFactory.createList(language, repeated);
} catch (ArithmeticException | OutOfMemoryError e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
index f57e595d9c..41fe34298e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
@@ -287,8 +287,8 @@ Object or(VirtualFrame frame, Object self, Object other) {
abstract static class IOrNode extends PythonBinaryBuiltinNode {
@Specialization
static Object or(Object self, @SuppressWarnings("unused") Object other,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IOR_IS_NOT_SUPPORTED_BY_P_USE_INSTEAD, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.IOR_IS_NOT_SUPPORTED_BY_P_USE_INSTEAD, self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
index 8425934da2..1cc0102b31 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java
@@ -153,7 +153,7 @@ public abstract static class MemoryViewSqItemNode extends SqItemBuiltinNode {
@Specialization
static Object doInt(VirtualFrame frame, PMemoryView self, int index,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached MemoryViewNodes.PointerLookupNode pointerFromIndexNode,
@Cached MemoryViewNodes.ReadItemAtNode readItemAtNode) {
self.checkReleased(inliningTarget, raiseNode);
@@ -171,7 +171,7 @@ static Object getitem(VirtualFrame frame, PMemoryView self, Object index,
@Bind("this") Node inliningTarget,
@Cached MemoryViewNodes.PointerLookupNode pointerFromIndexNode,
@Cached MemoryViewNodes.ReadItemAtNode readItemAtNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
MemoryViewNodes.MemoryPointer ptr = pointerFromIndexNode.execute(frame, self, index);
return readItemAtNode.execute(frame, self, ptr.ptr, ptr.offset);
@@ -185,10 +185,10 @@ static Object getitemSlice(PMemoryView self, PSlice slice,
@Cached SliceNodes.SliceUnpack sliceUnpack,
@Cached SliceNodes.AdjustIndices adjustIndices,
@Cached MemoryViewNodes.InitFlagsNode initFlagsNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (zeroDimProfile.profile(inliningTarget, self.getDimensions() == 0)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
}
int[] shape = self.getBufferShape();
PSlice.SliceInfo sliceInfo = adjustIndices.execute(inliningTarget, shape[0], sliceUnpack.execute(inliningTarget, slice));
@@ -211,12 +211,12 @@ static Object getitemSlice(PMemoryView self, PSlice slice,
static Object getitemEllipsis(PMemoryView self, @SuppressWarnings("unused") PEllipsis ellipsis,
@Bind("this") Node inliningTarget,
@Exclusive @Cached InlinedConditionProfile zeroDimProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (zeroDimProfile.profile(inliningTarget, self.getDimensions() == 0)) {
return self;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_INVALID_SLICE_KEY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_INVALID_SLICE_KEY);
}
}
@@ -228,7 +228,7 @@ static void setitem(VirtualFrame frame, PMemoryView self, Object index, Object o
@Bind("this") Node inliningTarget,
@Shared @Cached MemoryViewNodes.PointerLookupNode pointerLookupNode,
@Shared @Cached MemoryViewNodes.WriteItemAtNode writeItemAtNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
checkReadonly(inliningTarget, self, raiseNode);
@@ -245,18 +245,18 @@ static void setitem(VirtualFrame frame, PMemoryView self, PSlice slice, Object o
@Shared @Cached MemoryViewNodes.PointerLookupNode pointerLookupNode,
@Cached MemoryViewNodes.ToJavaBytesNode toJavaBytesNode,
@Cached MemoryViewNodes.WriteBytesAtNode writeBytesAtNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
checkReadonly(inliningTarget, self, raiseNode);
if (self.getDimensions() != 1) {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.MEMORYVIEW_SLICE_ASSIGNMENT_RESTRICTED_TO_DIM_1);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_SLICE_ASSIGNMENT_RESTRICTED_TO_DIM_1);
}
PMemoryView srcView = createMemoryView.execute(frame, object);
try {
PMemoryView destView = (PMemoryView) getItemNode.execute(frame, self, slice);
try {
if (srcView.getDimensions() != destView.getDimensions() || srcView.getBufferShape()[0] != destView.getBufferShape()[0] || srcView.getFormat() != destView.getFormat()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEMORYVIEW_DIFFERENT_STRUCTURES);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEMORYVIEW_DIFFERENT_STRUCTURES);
}
// The intermediate array is necessary for overlapping views (where src and dest
// are the same buffer)
@@ -279,26 +279,26 @@ static void setitem(VirtualFrame frame, PMemoryView self, @SuppressWarnings("unu
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile zeroDimProfile,
@Shared @Cached MemoryViewNodes.WriteItemAtNode writeItemAtNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
checkReadonly(inliningTarget, self, raiseNode);
if (zeroDimProfile.profile(inliningTarget, self.getDimensions() == 0)) {
writeItemAtNode.execute(frame, self, self.getBufferPointer(), 0, object);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
}
}
@Specialization(guards = "isNoValue(value)")
static void error(@SuppressWarnings("unused") PMemoryView self, @SuppressWarnings("unused") Object key, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_DELETE_MEMORY);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_DELETE_MEMORY);
}
- private static void checkReadonly(Node inliningTarget, PMemoryView self, PRaiseNode.Lazy raiseNode) {
+ private static void checkReadonly(Node inliningTarget, PMemoryView self, PRaiseNode raiseNode) {
if (self.isReadOnly()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_MODIFY_READONLY_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_MODIFY_READONLY_MEMORY);
}
}
@@ -428,7 +428,7 @@ Object tolistCached(VirtualFrame frame, PMemoryView self,
@Bind PythonLanguage language,
@Cached("self.getDimensions()") int cachedDimensions,
@Shared @Cached MemoryViewNodes.ReadItemAtNode readItemAtNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (cachedDimensions == 0) {
// That's not a list but CPython does it this way
@@ -443,7 +443,7 @@ Object tolist(VirtualFrame frame, PMemoryView self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached MemoryViewNodes.ReadItemAtNode readItemAtNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (self.getDimensions() == 0) {
return readItemAtNode.execute(frame, self, self.getBufferPointer(), self.getOffset());
@@ -502,7 +502,7 @@ PBytes tobytes(PMemoryView self, TruffleString order,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached TruffleString.EqualNode equalNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
byte[] bytes;
// The nodes act as branch profiles
@@ -511,7 +511,7 @@ PBytes tobytes(PMemoryView self, TruffleString order,
} else if (equalNode.execute(order, T_F, TS_ENCODING)) {
bytes = getToJavaBytesFortranOrderNode().execute(self);
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ORDER_MUST_BE_C_F_OR_A);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ORDER_MUST_BE_C_F_OR_A);
}
return PFactory.createBytes(language, bytes);
}
@@ -550,7 +550,7 @@ TruffleString none(PMemoryView self, @SuppressWarnings("unused") PNone sep, @Sup
@Shared("p") @Cached InlinedConditionProfile earlyExit,
@Shared("b") @Cached MemoryViewNodes.ToJavaBytesNode toJavaBytesNode,
@Shared("h") @Cached BytesNodes.ByteToHexNode toHexNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return hex(self, (byte) 0, 0, inliningTarget, earlyExit, toJavaBytesNode, toHexNode, raiseNode);
}
@@ -560,7 +560,7 @@ TruffleString hex(PMemoryView self, byte sep, int bytesPerSepGroup,
@Shared("p") @Cached InlinedConditionProfile earlyExit,
@Shared("b") @Cached MemoryViewNodes.ToJavaBytesNode toJavaBytesNode,
@Shared("h") @Cached BytesNodes.ByteToHexNode toHexNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (earlyExit.profile(inliningTarget, self.getLength() == 0)) {
return T_EMPTY_STRING;
@@ -587,7 +587,7 @@ public final Object call(VirtualFrame frame, Object arg) {
static PMemoryView toreadonly(PMemoryView self,
@Bind PythonLanguage language,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return PFactory.createMemoryView(language, PythonContext.get(inliningTarget), self.getLifecycleManager(), self.getBuffer(), self.getOwner(), self.getLength(), true,
self.getItemSize(), self.getFormat(), self.getFormatString(), self.getDimensions(), self.getBufferPointer(),
@@ -605,7 +605,7 @@ static PMemoryView cast(PMemoryView self, TruffleString formatString, @SuppressW
@Bind("this") Node inliningTarget,
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return doCast(inliningTarget, self, formatString, 1, null, PythonContext.get(inliningTarget), lengthNode, atIndexNode, raiseNode);
}
@@ -618,7 +618,7 @@ static PMemoryView cast(VirtualFrame frame, PMemoryView self, TruffleString form
@Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, shapeObj);
int ndim = storage.length();
@@ -626,7 +626,7 @@ static PMemoryView cast(VirtualFrame frame, PMemoryView self, TruffleString form
for (int i = 0; i < ndim; i++) {
shape[i] = asSizeNode.executeExact(frame, inliningTarget, getItemScalarNode.execute(inliningTarget, storage, i));
if (shape[i] <= 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CAST_ELEMENTS_MUST_BE_POSITIVE_INTEGERS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CAST_ELEMENTS_MUST_BE_POSITIVE_INTEGERS);
}
}
return doCast(inliningTarget, self, formatString, ndim, shape, PythonContext.get(inliningTarget), lengthNode, atIndexNode, raiseNode);
@@ -635,30 +635,30 @@ static PMemoryView cast(VirtualFrame frame, PMemoryView self, TruffleString form
@Specialization(guards = {"!isPTuple(shape)", "!isList(shape)", "!isPNone(shape)"})
@SuppressWarnings("unused")
static PMemoryView error(PMemoryView self, TruffleString format, Object shape,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ARG_S_MUST_BE_A_LIST_OR_TUPLE, "shape");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ARG_S_MUST_BE_A_LIST_OR_TUPLE, "shape");
}
private static PMemoryView doCast(Node inliningTarget, PMemoryView self, TruffleString formatString, int ndim, int[] shape, PythonContext context, TruffleString.CodePointLengthNode lengthNode,
- TruffleString.CodePointAtIndexNode atIndexNode, PRaiseNode.Lazy raiseNode) {
+ TruffleString.CodePointAtIndexNode atIndexNode, PRaiseNode raiseNode) {
if (!self.isCContiguous()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CASTS_RESTRICTED_TO_C_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CASTS_RESTRICTED_TO_C_CONTIGUOUS);
}
BufferFormat format = BufferFormat.forMemoryView(formatString, lengthNode, atIndexNode);
int itemsize = format.bytesize;
if (itemsize < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEMORYVIEW_DESTINATION_FORMAT_ERROR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEMORYVIEW_DESTINATION_FORMAT_ERROR);
}
if (!MemoryViewNodes.isByteFormat(format) && !MemoryViewNodes.isByteFormat(self.getFormat())) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CANNOT_CAST_NON_BYTE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CANNOT_CAST_NON_BYTE);
}
if (self.getLength() % itemsize != 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_LENGTH_NOT_MULTIPLE_OF_ITEMSIZE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_LENGTH_NOT_MULTIPLE_OF_ITEMSIZE);
}
if (shape != null || self.getDimensions() != 1) {
for (int i = 0; i < self.getDimensions(); i++) {
if (self.getBufferShape()[i] == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CANNOT_CAST_VIEW_WITH_ZEROS_IN_SHAPE_OR_STRIDES);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CANNOT_CAST_VIEW_WITH_ZEROS_IN_SHAPE_OR_STRIDES);
}
}
}
@@ -670,24 +670,24 @@ private static PMemoryView doCast(Node inliningTarget, PMemoryView self, Truffle
newStrides = null;
flags |= PMemoryView.FLAG_SCALAR;
if (self.getLength() != itemsize) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CAST_WRONG_LENGTH);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CAST_WRONG_LENGTH);
}
} else {
if (shape == null) {
newShape = new int[]{self.getLength() / itemsize};
} else {
if (ndim != 1 && self.getDimensions() != 1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CAST_MUST_BE_1D_TO_ND_OR_ND_TO_1D);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CAST_MUST_BE_1D_TO_ND_OR_ND_TO_1D);
}
if (ndim > PMemoryView.MAX_DIM) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEMORYVIEW_NUMBER_OF_DIMENSIONS_MUST_NOT_EXCEED_D, ndim);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEMORYVIEW_NUMBER_OF_DIMENSIONS_MUST_NOT_EXCEED_D, ndim);
}
int newLength = itemsize;
for (int i = 0; i < ndim; i++) {
newLength *= shape[i];
}
if (newLength != self.getLength()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_CAST_WRONG_LENGTH);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_CAST_WRONG_LENGTH);
}
newShape = shape;
}
@@ -713,7 +713,7 @@ public abstract static class LenNode extends LenBuiltinNode {
static int len(PMemoryView self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile zeroDimProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return zeroDimProfile.profile(inliningTarget, self.getDimensions() == 0) ? 1 : self.getBufferShape()[0];
}
@@ -742,13 +742,13 @@ static int hash(PMemoryView self,
@Cached InlinedConditionProfile cachedProfile,
@Cached InlinedConditionProfile writableProfile,
@Cached MemoryViewNodes.ToJavaBytesNode toJavaBytesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (cachedProfile.profile(inliningTarget, self.getCachedHash() != -1)) {
return self.getCachedHash();
}
self.checkReleased(inliningTarget, raiseNode);
if (writableProfile.profile(inliningTarget, !self.isReadOnly())) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_HASH_WRITEABLE_MEMORYVIEW);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_HASH_WRITEABLE_MEMORYVIEW);
} else {
// TODO avoid copying
int hash = hashArray(toJavaBytesNode.execute(self));
@@ -769,7 +769,7 @@ public abstract static class EnterNode extends PythonUnaryBuiltinNode {
@Specialization
static Object enter(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self;
}
@@ -805,7 +805,7 @@ public abstract static class ItemSizeNode extends PythonUnaryBuiltinNode {
@Specialization
static int get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.getItemSize();
}
@@ -818,7 +818,7 @@ public abstract static class NBytesNode extends PythonUnaryBuiltinNode {
@Specialization
static int get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.getLength();
}
@@ -831,7 +831,7 @@ public abstract static class ObjNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.getOwner() != null ? self.getOwner() : PNone.NONE;
}
@@ -844,7 +844,7 @@ public abstract static class FormatNode extends PythonUnaryBuiltinNode {
@Specialization
static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.getFormatString() != null ? self.getFormatString() : T_UINT_8_TYPE_CODE;
}
@@ -859,7 +859,7 @@ static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferShape() == null)) {
return PFactory.createEmptyTuple(language);
@@ -877,7 +877,7 @@ static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferStrides() == null)) {
return PFactory.createEmptyTuple(language);
@@ -895,7 +895,7 @@ static Object get(PMemoryView self,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Cached InlinedConditionProfile nullProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
if (nullProfile.profile(inliningTarget, self.getBufferSuboffsets() == null)) {
return PFactory.createEmptyTuple(language);
@@ -911,7 +911,7 @@ public abstract static class ReadonlyNode extends PythonUnaryBuiltinNode {
@Specialization
static boolean get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.isReadOnly();
}
@@ -924,7 +924,7 @@ public abstract static class NDimNode extends PythonUnaryBuiltinNode {
@Specialization
static int get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.getDimensions();
}
@@ -937,7 +937,7 @@ public abstract static class CContiguousNode extends PythonUnaryBuiltinNode {
@Specialization
static boolean get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.isCContiguous();
}
@@ -950,7 +950,7 @@ public abstract static class FContiguousNode extends PythonUnaryBuiltinNode {
@Specialization
static boolean get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.isFortranContiguous();
}
@@ -963,7 +963,7 @@ public abstract static class ContiguousNode extends PythonUnaryBuiltinNode {
@Specialization
static boolean get(PMemoryView self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
return self.isAnyContiguous();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java
index 227216af94..00d5a649ba 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -103,7 +103,7 @@ static void checkBufferBounds(Node node, PMemoryView self, PythonBufferAccessLib
* reference counting.
*/
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(node, IndexError, ErrorMessages.INVALID_BUFFER_ACCESS);
+ throw PRaiseNode.raiseStatic(node, IndexError, ErrorMessages.INVALID_BUFFER_ACCESS);
}
}
@@ -158,7 +158,7 @@ static Object unpack(Node inliningTarget, BufferFormat format, @SuppressWarnings
@Fallback
@SuppressWarnings("unused")
static Object notImplemented(Node inliningTarget, BufferFormat format, TruffleString formatStr, Object buffer, int offset) {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_FORMAT_S_NOT_SUPPORTED, formatStr);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_FORMAT_S_NOT_SUPPORTED, formatStr);
}
}
@@ -172,19 +172,19 @@ public abstract static class PackValueNode extends Node {
static void pack(VirtualFrame frame, Node inliningTarget, BufferFormat format, TruffleString formatStr, Object value, Object buffer, int offset,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached BufferStorageNodes.PackValueNode packValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
packValueNode.execute(frame, inliningTarget, format, value, buffer, offset);
} catch (PException e) {
e.expect(inliningTarget, OverflowError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEMORYVIEW_INVALID_VALUE_FOR_FORMAT_S, formatStr);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEMORYVIEW_INVALID_VALUE_FOR_FORMAT_S, formatStr);
}
}
@Fallback
@SuppressWarnings("unused")
static void notImplemented(Node inliningTarget, BufferFormat format, TruffleString formatStr, Object object, Object buffer, int offset) {
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_FORMAT_S_NOT_SUPPORTED, formatStr);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.MEMORYVIEW_FORMAT_S_NOT_SUPPORTED, formatStr);
}
}
@@ -340,7 +340,7 @@ abstract static class PointerLookupNode extends Node {
public abstract MemoryPointer execute(VirtualFrame frame, PMemoryView self, int index);
- private void lookupDimension(Node inliningTarget, PMemoryView self, MemoryPointer ptr, int dim, int initialIndex, InlinedConditionProfile hasSuboffsetsProfile, PRaiseNode.Lazy raiseNode) {
+ private void lookupDimension(Node inliningTarget, PMemoryView self, MemoryPointer ptr, int dim, int initialIndex, InlinedConditionProfile hasSuboffsetsProfile, PRaiseNode raiseNode) {
int index = initialIndex;
int[] shape = self.getBufferShape();
int nitems = shape[dim];
@@ -348,7 +348,7 @@ private void lookupDimension(Node inliningTarget, PMemoryView self, MemoryPointe
index += nitems;
}
if (index < 0 || index >= nitems) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS_ON_DIMENSION_D, dim + 1);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.INDEX_OUT_OF_BOUNDS_ON_DIMENSION_D, dim + 1);
}
ptr.offset += self.getBufferStrides()[dim] * index;
@@ -367,17 +367,17 @@ MemoryPointer resolveInt(PMemoryView self, int index,
@Bind("this") Node inliningTarget,
@Shared @Cached InlinedConditionProfile hasOneDimensionProfile,
@Shared @Cached InlinedConditionProfile hasSuboffsetsProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (hasOneDimensionProfile.profile(inliningTarget, self.getDimensions() == 1)) {
MemoryPointer ptr = new MemoryPointer(self.getBufferPointer(), self.getOffset());
lookupDimension(inliningTarget, self, ptr, 0, index, hasSuboffsetsProfile, raiseNode);
return ptr;
}
if (self.getDimensions() == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
} else {
// CPython doesn't implement this either, as of 3.8
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.MULTI_DIMENSIONAL_SUB_VIEWS_NOT_IMPLEMENTED);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.MULTI_DIMENSIONAL_SUB_VIEWS_NOT_IMPLEMENTED);
}
}
@@ -391,7 +391,7 @@ MemoryPointer resolveTupleCached(VirtualFrame frame, PMemoryView self, PTuple in
@Cached("self.getDimensions()") int cachedDimensions,
@Shared @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage indicesStorage = getSequenceStorageNode.execute(inliningTarget, indices);
checkTupleLength(inliningTarget, indicesStorage, cachedDimensions, raiseNode);
MemoryPointer ptr = new MemoryPointer(self.getBufferPointer(), self.getOffset());
@@ -410,7 +410,7 @@ MemoryPointer resolveTupleGeneric(VirtualFrame frame, PMemoryView self, PTuple i
@Shared @Cached PyIndexCheckNode indexCheckNode,
@Shared @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
SequenceStorage indicesStorage = getSequenceStorageNode.execute(inliningTarget, indices);
int ndim = self.getDimensions();
checkTupleLength(inliningTarget, indicesStorage, ndim, raiseNode);
@@ -429,30 +429,30 @@ MemoryPointer resolveIntObj(VirtualFrame frame, PMemoryView self, Object indexOb
@Shared @Cached InlinedConditionProfile hasOneDimensionProfile,
@Shared @Cached InlinedConditionProfile hasSuboffsetsProfile,
@Shared @Cached PyIndexCheckNode indexCheckNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
final int index = convertIndex(frame, inliningTarget, indexCheckNode, indexObj, raiseNode);
return resolveInt(self, index, inliningTarget, hasOneDimensionProfile, hasSuboffsetsProfile, raiseNode);
}
- private static void checkTupleLength(Node inliningTarget, SequenceStorage indicesStorage, int ndim, PRaiseNode.Lazy raiseNode) {
+ private static void checkTupleLength(Node inliningTarget, SequenceStorage indicesStorage, int ndim, PRaiseNode raiseNode) {
int length = indicesStorage.length();
if (length == ndim) {
return;
}
// Error cases
if (ndim == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INVALID_INDEXING_OF_0_DIM_MEMORY);
} else if (length > ndim) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_INDEX_D_DIMENSION_VIEW_WITH_D, ndim, length);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_INDEX_D_DIMENSION_VIEW_WITH_D, ndim, length);
} else {
// CPython doesn't implement this either, as of 3.8
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.SUB_VIEWS_NOT_IMPLEMENTED);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.SUB_VIEWS_NOT_IMPLEMENTED);
}
}
- private int convertIndex(VirtualFrame frame, Node inliningTarget, PyIndexCheckNode indexCheckNode, Object indexObj, PRaiseNode.Lazy raiseNode) {
+ private int convertIndex(VirtualFrame frame, Node inliningTarget, PyIndexCheckNode indexCheckNode, Object indexObj, PRaiseNode raiseNode) {
if (!indexCheckNode.execute(inliningTarget, indexObj)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_INVALID_SLICE_KEY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_INVALID_SLICE_KEY);
}
return getAsSizeNode().executeExact(frame, inliningTarget, indexObj, IndexError);
}
@@ -486,7 +486,7 @@ byte[] tobytesCached(PMemoryView self,
@Cached("self.getDimensions()") int cachedDimensions,
@Shared @Cached ReadBytesAtNode readBytesAtNode,
@Shared @Cached CExtNodes.PCallCapiFunction callCapiFunction,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
byte[] bytes = new byte[self.getLength()];
if (cachedDimensions == 0) {
@@ -502,7 +502,7 @@ byte[] tobytesGeneric(PMemoryView self,
@Bind("this") Node inliningTarget,
@Shared @Cached ReadBytesAtNode readBytesAtNode,
@Shared @Cached CExtNodes.PCallCapiFunction callCapiFunction,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
self.checkReleased(inliningTarget, raiseNode);
byte[] bytes = new byte[self.getLength()];
if (self.getDimensions() == 0) {
@@ -596,8 +596,9 @@ public final void execute(PMemoryView self) {
@Specialization(guards = "self.getReference() == null")
static void releaseSimple(PMemoryView self,
+ @Bind("this") Node inliningTarget,
@Shared("raise") @Cached PRaiseNode raiseNode) {
- self.checkExports(raiseNode);
+ self.checkExports(inliningTarget, raiseNode);
self.setReleased();
}
@@ -607,7 +608,7 @@ static void releaseNative(VirtualFrame frame, PMemoryView self,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached ReleaseBufferNode releaseNode,
@Shared("raise") @Cached PRaiseNode raiseNode) {
- self.checkExports(raiseNode);
+ self.checkExports(inliningTarget, raiseNode);
if (self.checkShouldReleaseBuffer()) {
releaseNode.execute(frame, inliningTarget, indirectCallData, self.getLifecycleManager());
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java
index fb958911da..f0eed188e5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -250,9 +250,9 @@ public void setShouldReleaseImmediately(boolean shouldReleaseImmediately) {
this.shouldReleaseImmediately = shouldReleaseImmediately;
}
- public void checkReleased(Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ public void checkReleased(Node inliningTarget, PRaiseNode raiseNode) {
if (isReleased()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
}
}
@@ -263,10 +263,10 @@ boolean checkShouldReleaseBuffer() {
return false;
}
- void checkExports(PRaiseNode node) {
+ void checkExports(Node inliningTarget, PRaiseNode node) {
long exportsValue = getExports().get();
if (exportsValue > 0) {
- throw node.raise(BufferError, ErrorMessages.MEMORYVIEW_HAS_D_EXPORTED_BUFFERS, exportsValue);
+ throw node.raise(inliningTarget, BufferError, ErrorMessages.MEMORYVIEW_HAS_D_EXPORTED_BUFFERS, exportsValue);
}
}
@@ -290,29 +290,29 @@ int getBufferLength() {
@ExportMessage
Object acquire(int requestedFlags,
@Bind("$node") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkReleased(inliningTarget, raiseNode);
if (BufferFlags.requestsWritable(requestedFlags) && readonly) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_WRITABLE);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_WRITABLE);
}
if (BufferFlags.requestsCContiguous(requestedFlags) && !isCContiguous()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_C_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_C_CONTIGUOUS);
}
if (BufferFlags.requestsFContiguous(requestedFlags) && !isFortranContiguous()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_FORTRAN_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_FORTRAN_CONTIGUOUS);
}
if (BufferFlags.requestsAnyContiguous(requestedFlags) && !isAnyContiguous()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_CONTIGUOUS);
}
if (!BufferFlags.requestsIndirect(requestedFlags) && (flags & FLAG_PIL) != 0) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_REQUIRES_SUBOFFSETS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_REQUIRES_SUBOFFSETS);
}
if (!BufferFlags.requestsStrides(requestedFlags) && !isCContiguous()) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_C_CONTIGUOUS);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_UNDERLYING_BUF_ISNT_C_CONTIGUOUS);
}
// TODO should reflect the cast to unsigned bytes if necessary
if (!BufferFlags.requestsShape(requestedFlags) && BufferFlags.requestsFormat(requestedFlags)) {
- throw raiseNode.get(inliningTarget).raise(BufferError, ErrorMessages.MV_CANNOT_CAST_UNSIGNED_BYTES_IF_FMT_FLAG);
+ throw raiseNode.raise(inliningTarget, BufferError, ErrorMessages.MV_CANNOT_CAST_UNSIGNED_BYTES_IF_FMT_FLAG);
}
exports.incrementAndGet();
return this;
@@ -329,7 +329,7 @@ void release(
* should be no such helper memoryviews, the C buffer should have a separate implementation.
*/
if (shouldReleaseImmediately) {
- checkExports(raiseNode);
+ checkExports(inliningTarget, raiseNode);
if (checkShouldReleaseBuffer()) {
releaseNode.execute(inliningTarget, getLifecycleManager());
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractBuiltinMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractBuiltinMethodBuiltins.java
index 19861c30e8..815e3ca134 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractBuiltinMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractBuiltinMethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
@@ -116,7 +116,7 @@ static TruffleString getQualName(VirtualFrame frame, PMethod method,
@Shared @Cached InlinedConditionProfile isGlobalProfile,
@Shared @Cached GetClassNode getClassNode,
@Shared @Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return makeQualname(frame, inliningTarget, method, method.getSelf(), getQualNameAttrNode, getNameAttrNode, castToStringNode, getClassNode, isTypeNode, isGlobalProfile,
simpleTruffleStringFormatNode, raiseNode);
}
@@ -131,19 +131,19 @@ static TruffleString getQualName(VirtualFrame frame, PBuiltinMethod method,
@Shared @Cached InlinedConditionProfile isGlobalProfile,
@Shared @Cached GetClassNode getClassNode,
@Shared @Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return makeQualname(frame, inliningTarget, method, method.getSelf(), getQualNameAttrNode, getNameAttrNode, castToStringNode, getClassNode, isTypeNode, isGlobalProfile,
simpleTruffleStringFormatNode, raiseNode);
}
private static TruffleString makeQualname(VirtualFrame frame, Node inliningTarget, Object method, Object self, GetAttributeNode getQualNameAttrNode, GetAttributeNode getNameAttrNode,
CastToTruffleStringNode castToStringNode, GetClassNode getClassNode, TypeNodes.IsTypeNode isTypeNode, InlinedConditionProfile isGlobalProfile,
- SimpleTruffleStringFormatNode simpleTruffleStringFormatNode, PRaiseNode.Lazy raiseNode) {
+ SimpleTruffleStringFormatNode simpleTruffleStringFormatNode, PRaiseNode raiseNode) {
TruffleString methodName;
try {
methodName = castToStringNode.execute(inliningTarget, getNameAttrNode.executeObject(frame, method));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___NAME__);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___NAME__);
}
if (isGlobalProfile.profile(inliningTarget, self == PNone.NO_VALUE || self instanceof PythonModule)) {
return methodName;
@@ -154,7 +154,7 @@ private static TruffleString makeQualname(VirtualFrame frame, Node inliningTarge
try {
typeQualName = castToStringNode.execute(inliningTarget, getQualNameAttrNode.executeObject(frame, type));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___QUALNAME__);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___QUALNAME__);
}
return simpleTruffleStringFormatNode.format("%s.%s", typeQualName, methodName);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
index c7405fdaa4..1591ecff5b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java
@@ -245,8 +245,8 @@ static Object getModule(VirtualFrame frame, PMethod self, @SuppressWarnings("unu
@Specialization(guards = "!isNoValue(value)")
static Object getModule(@SuppressWarnings("unused") PMethod self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "method", T___MODULE__);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_S_HAS_NO_ATTR_S, "method", T___MODULE__);
}
}
@@ -333,7 +333,7 @@ static TruffleString doSelfIsObject(VirtualFrame frame, PMethod method,
@Shared("getQualname") @Cached PyObjectGetAttr getQualname,
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName,
@Shared("formatter") @Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return getQualName(frame, inliningTarget, method.getSelf(), method.getFunction(), getClassNode, isTypeNode, toStringNode, getQualname, lookupName, simpleTruffleStringFormatNode,
raiseNode);
}
@@ -347,21 +347,21 @@ static TruffleString doSelfIsObject(VirtualFrame frame, PBuiltinMethod method,
@Shared("getQualname") @Cached PyObjectGetAttr getQualname,
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName,
@Shared("formatter") @Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return getQualName(frame, inliningTarget, method.getSelf(), method.getFunction(), getClassNode, isTypeNode, toStringNode, getQualname, lookupName, simpleTruffleStringFormatNode,
raiseNode);
}
private static TruffleString getQualName(VirtualFrame frame, Node inliningTarget, Object self, Object func, GetClassNode getClassNode, TypeNodes.IsTypeNode isTypeNode,
CastToTruffleStringNode toStringNode, PyObjectGetAttr getQualname, PyObjectLookupAttr lookupName, SimpleTruffleStringFormatNode simpleTruffleStringFormatNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object type = isTypeNode.execute(inliningTarget, self) ? self : getClassNode.execute(inliningTarget, self);
try {
TruffleString typeQualName = toStringNode.execute(inliningTarget, getQualname.execute(frame, inliningTarget, type, T___QUALNAME__));
return simpleTruffleStringFormatNode.format("%s.%s", typeQualName, getName(frame, inliningTarget, func, toStringNode, lookupName));
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___QUALNAME__);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_UNICODE_OBJECT, T___QUALNAME__);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java
index b0c80b9bc1..5aef32c3ca 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -152,7 +152,7 @@ public Object doIt(Object fun,
@Bind("this") Node inliningTarget) {
Signature signature = GetSignatureNode.executeUncached(fun);
if (signature.isHidden()) {
- throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__);
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__);
}
return BuiltinFunctionBuiltins.SignatureNode.createInspectSignature(signature, true);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
index ec4bf97bfe..631db6babe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java
@@ -127,7 +127,7 @@ static Object get(PDecoratedMethod self, Object obj, @SuppressWarnings("unused")
@Bind("this") Node inliningTarget,
@Shared @Cached GetClassNode getClass,
@Shared @Cached MakeMethodNode makeMethod,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doGet(inliningTarget, self, getClass.execute(inliningTarget, obj), makeMethod, raiseNode);
}
@@ -145,14 +145,14 @@ static Object getTypeCached(@SuppressWarnings("unused") PDecoratedMethod self, @
static Object getType(PDecoratedMethod self, @SuppressWarnings("unused") Object obj, Object type,
@Bind("this") Node inliningTarget,
@Shared @Cached MakeMethodNode makeMethod,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return doGet(inliningTarget, self, type, makeMethod, raiseNode);
}
- private static Object doGet(Node inliningTarget, PDecoratedMethod self, Object type, MakeMethodNode makeMethod, PRaiseNode.Lazy raiseNode) {
+ private static Object doGet(Node inliningTarget, PDecoratedMethod self, Object type, MakeMethodNode makeMethod, PRaiseNode raiseNode) {
Object callable = self.getCallable();
if (callable == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.UNINITIALIZED_S_OBJECT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNINITIALIZED_S_OBJECT);
}
return makeMethod.execute(inliningTarget, type, callable);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java
index b45360f89f..9411e45cf3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java
@@ -155,8 +155,8 @@ static Object setDict(PDecoratedMethod self, PDict mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static Object setDict(@SuppressWarnings("unused") PDecoratedMethod self, Object mapping,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
index f74d62eb88..bd573df628 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/InstancemethodBuiltins.java
@@ -116,8 +116,8 @@ static PNone init(PDecoratedMethod self, Object callable,
@Specialization(guards = "!checkCallableNode.execute(this, callable)")
static PNone noCallble(@SuppressWarnings("unused") PDecoratedMethod self, Object callable,
@Shared("checkCallable") @SuppressWarnings("unused") @Cached PyCallableCheckNode checkCallableNode,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, FIRST_ARG_MUST_BE_CALLABLE_S, callable);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, FIRST_ARG_MUST_BE_CALLABLE_S, callable);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
index d3e2e1786a..e7fac1ff3f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java
@@ -133,14 +133,14 @@ static Object doIt(VirtualFrame frame, PMethod self, Object keyObj,
@Cached ObjectBuiltins.GetAttributeNode objectGetattrNode,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached CastToTruffleStringNode castKeyToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// TODO: (GR-53090) this is different to what CPython does and CPython also does not
// define tp_descrget for method
TruffleString key;
try {
key = castKeyToStringNode.execute(inliningTarget, keyObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
}
try {
@@ -154,8 +154,8 @@ static Object doIt(VirtualFrame frame, PMethod self, Object keyObj,
@Specialization(guards = "!isPMethod(self)")
@InliningCutoff
static Object getattribute(Object self, @SuppressWarnings("unused") Object key,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GETATTRIBUTE__, "method", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GETATTRIBUTE__, "method", self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java
index 5ef47ed787..c219c00123 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -103,10 +103,10 @@ static Object getCached(@SuppressWarnings("unused") PDecoratedMethod self, @Supp
@Specialization(replaces = "getCached")
static Object get(PDecoratedMethod self, @SuppressWarnings("unused") Object obj, @SuppressWarnings("unused") Object type,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object callable = self.getCallable();
if (callable == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.UNINITIALIZED_S_OBJECT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.UNINITIALIZED_S_OBJECT);
}
return callable;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
index 6e54ed2e2c..370ecb228a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
@@ -173,7 +173,7 @@ public abstract static class MMapSqItemNode extends SqItemBuiltinNode {
static PBytes doInt(VirtualFrame frame, PMMap self, int index,
@Bind("this") Node inliningTarget,
@Bind PythonContext context,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib) {
long len = self.getLength();
@@ -201,7 +201,7 @@ static int doSingle(VirtualFrame frame, PMMap self, Object idxObj,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Cached PyLongAsLongNode asLongNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
long i = asLongNode.execute(frame, inliningTarget, idxObj);
long len = self.getLength();
long idx = negativeIndexProfile.profile(inliningTarget, i < 0) ? i + len : i;
@@ -223,7 +223,7 @@ static Object doSlice(VirtualFrame frame, PMMap self, PSlice idx,
@Cached ComputeIndices compute,
@Cached LenOfRangeNode sliceLenNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
try {
SliceInfo info = compute.execute(frame, sliceCast.execute(inliningTarget, idx), PInt.intValueExact(self.getLength()));
int len = sliceLenNode.len(inliningTarget, info);
@@ -233,7 +233,7 @@ static Object doSlice(VirtualFrame frame, PMMap self, PSlice idx,
byte[] result = readBytes(frame, inliningTarget, self, posixSupportLib, context.getPosixSupport(), info.start, len, constructAndRaiseNode);
return PFactory.createBytes(context.getLanguage(inliningTarget), result);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, e);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError, e);
}
}
}
@@ -250,25 +250,25 @@ static void doSingle(VirtualFrame frame, PMMap self, int index, Object val,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Cached PyBytesCheckNode checkNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// NB: sq_ass_item and mp_ass_subscript implementations behave differently even with
// integer indices
if (self.isClosed()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
}
long len = self.getLength();
long idx = index < 0 ? index + len : index;
if (idx < 0 || idx >= len) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, MMAP_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, MMAP_INDEX_OUT_OF_RANGE);
}
if (val == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_ITEM_DELETION);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_ITEM_DELETION);
}
if (!(checkNode.execute(inliningTarget, val) && bufferLib.getBufferLength(val) == 1)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, MMAP_ASSIGNMENT_MUST_BE_LENGTH_1_BYTES);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, MMAP_ASSIGNMENT_MUST_BE_LENGTH_1_BYTES);
}
if (self.isReadonly()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
}
byte b = bufferLib.readByte(val, 0);
try {
@@ -291,33 +291,33 @@ static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object value
@Cached PyIndexCheckNode checkNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
// NB: sq_ass_item and mp_ass_subscript implementations behave differently even with
// integer indices
if (self.isClosed()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
}
if (self.isReadonly()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
}
if (!checkNode.execute(inliningTarget, idxObj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_INDICES_MUST_BE_INTEGER);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_INDICES_MUST_BE_INTEGER);
}
long idx = asSizeNode.executeExact(frame, inliningTarget, idxObj, PythonBuiltinClassType.IndexError);
long len = self.getLength();
idx = idx < 0 ? idx + len : idx;
if (idx < 0 || idx >= len) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, MMAP_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, MMAP_INDEX_OUT_OF_RANGE);
}
if (valueObj == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_ITEM_DELETION);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_ITEM_DELETION);
}
if (!checkNode.execute(inliningTarget, valueObj)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_ITEM_VALUE_MUST_BE_AN_INT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_ITEM_VALUE_MUST_BE_AN_INT);
}
int value = asSizeNode.executeExact(frame, inliningTarget, valueObj, PythonBuiltinClassType.TypeError);
if (value < 0 || value > 255) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, MMAP_ITEM_VALUE_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, MMAP_ITEM_VALUE_MUST_BE_IN_RANGE);
}
try {
posixSupportLib.mmapWriteByte(context.getPosixSupport(), self.getPosixSupportHandle(), idx, (byte) value);
@@ -337,28 +337,28 @@ static void doSlice(VirtualFrame frame, PMMap self, PSlice slice, Object valueOb
@Cached SliceNodes.AdjustIndices adjustIndices,
@Cached InlinedConditionProfile step1Profile,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (self.isClosed()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
}
if (self.isReadonly()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_CANNOT_MODIFY_READONLY_MEMORY);
}
int len;
try {
len = PInt.intValueExact(self.getLength());
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError);
}
SliceInfo info = adjustIndices.execute(inliningTarget, len, sliceUnpack.execute(inliningTarget, slice));
if (valueObj == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_SLICE_DELETION);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, MMAP_OBJECT_DOESNT_SUPPORT_SLICE_DELETION);
}
Object buffer = acquireLib.acquireReadonly(valueObj);
try {
int bufferLen = bufferLib.getBufferLength(buffer);
if (info.sliceLength != bufferLen) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, MMAP_SLICE_ASSIGNMENT_IS_WRONG_SIZE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, MMAP_SLICE_ASSIGNMENT_IS_WRONG_SIZE);
}
if (info.sliceLength > 0) {
try {
@@ -388,7 +388,7 @@ public abstract static class LenNode extends LenBuiltinNode {
@Specialization
static int len(PMMap self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
return PyNumberAsSizeNode.doLongExact(inliningTarget, self.getLength(), PythonBuiltinClassType.OverflowError, raiseNode);
}
}
@@ -454,9 +454,9 @@ abstract static class ResizeNode extends PythonBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static long resize(PMMap self, Object n,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// TODO: implement resize in NFI
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.RESIZING_NOT_AVAILABLE);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.RESIZING_NOT_AVAILABLE);
}
}
@@ -480,9 +480,9 @@ static int readByte(VirtualFrame frame, PMMap self,
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.getPos() >= self.getLength()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, READ_BYTE_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, READ_BYTE_OUT_OF_RANGE);
}
try {
byte res = posixSupportLib.mmapReadByte(context.getPosixSupport(), self.getPosixSupportHandle(), self.getPos());
@@ -510,7 +510,7 @@ static PBytes read(VirtualFrame frame, PMMap self, Object n,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached InlinedConditionProfile negativeProfile,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long nread;
// intentionally accept NO_VALUE and NONE; both mean that we read unlimited # of bytes
if (noneProfile.profile(inliningTarget, isPNone(n))) {
@@ -518,7 +518,7 @@ static PBytes read(VirtualFrame frame, PMMap self, Object n,
} else {
// _Py_convert_optional_to_ssize_t:
if (!indexCheckNode.execute(inliningTarget, n)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, n);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, n);
}
nread = asSizeNode.executeExact(frame, inliningTarget, n);
@@ -536,7 +536,7 @@ static PBytes read(VirtualFrame frame, PMMap self, Object n,
self.setPos(self.getPos() + buffer.length);
return PFactory.createBytes(context.getLanguage(inliningTarget), buffer);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, ErrorMessages.TOO_MANY_REMAINING_BYTES_TO_BE_STORED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.TOO_MANY_REMAINING_BYTES_TO_BE_STORED);
}
}
}
@@ -597,15 +597,15 @@ static int doIt(VirtualFrame frame, PMMap self, Object dataBuffer,
@CachedLibrary("dataBuffer") PythonBufferAccessLibrary bufferLib,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (!self.isWriteable()) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MMAP_CANNOT_MODIFY_READONLY_MEMORY);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MMAP_CANNOT_MODIFY_READONLY_MEMORY);
}
byte[] dataBytes = bufferLib.getInternalOrCopiedByteArray(dataBuffer);
int dataLen = bufferLib.getBufferLength(dataBuffer);
if (self.getPos() > self.getLength() || self.getLength() - self.getPos() < dataLen) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.DATA_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.DATA_OUT_OF_RANGE);
}
posixLib.mmapWriteBytes(context.getPosixSupport(), self.getPosixSupportHandle(), self.getPos(), dataBytes, dataLen);
self.setPos(self.getPos() + dataLen);
@@ -632,7 +632,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object seek(PMMap self, long dist, int how,
@Bind("this") Node inliningTarget,
@Cached InlinedBranchProfile errorProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long where;
switch (how) {
case 0: // relative to start
@@ -646,10 +646,10 @@ static Object seek(PMMap self, long dist, int how,
break;
default:
errorProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.UNKNOWN_S_TYPE, "seek");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.UNKNOWN_S_TYPE, "seek");
}
if (where > self.getLength() || where < 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SEEK_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SEEK_OUT_OF_RANGE);
}
self.setPos(where);
return PNone.NONE;
@@ -678,7 +678,7 @@ static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startI
@Cached LongIndexConverterNode endConverter,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
long start = normalizeIndex(frame, startConverter, startIn, self.getLength(), self.getPos());
long end = normalizeIndex(frame, endConverter, endIn, self.getLength(), self.getLength());
@@ -737,13 +737,13 @@ static long find(VirtualFrame frame, PMMap self, Object subBuffer, Object startI
}
private static void readBytes(VirtualFrame frame, Node inliningTarget, PMMap self, PosixSupportLibrary posixLib, PosixSupport posixSupport, long index, byte[] buffer,
- PConstructAndRaiseNode.Lazy constructAndRaiseNode, PRaiseNode.Lazy raiseNode) {
+ PConstructAndRaiseNode.Lazy constructAndRaiseNode, PRaiseNode raiseNode) {
try {
long remaining = self.getLength() - index;
int toReadLen = remaining > buffer.length ? buffer.length : (int) remaining;
int nread = posixLib.mmapReadBytes(posixSupport, self.getPosixSupportHandle(), index, buffer, toReadLen);
if (toReadLen != nread) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, MMAP_CHANGED_LENGTH);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, MMAP_CHANGED_LENGTH);
}
} catch (PosixException ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, ex);
@@ -784,7 +784,7 @@ static Object flush(VirtualFrame frame, PMMap self, long offset, Object sizeObj,
@Cached LongIndexConverterNode sizeConversion,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long size;
if (sizeObj == PNone.NO_VALUE) {
size = self.getLength();
@@ -793,7 +793,7 @@ static Object flush(VirtualFrame frame, PMMap self, long offset, Object sizeObj,
}
if (size < 0 || offset < 0 || self.getLength() - offset < size) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.FLUSH_VALUES_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.FLUSH_VALUES_OUT_OF_RANGE);
}
if (self.getAccess() == ACCESS_READ || self.getAccess() == ACCESS_COPY) {
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
index a6042bd83a..afb659abcf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java
@@ -171,7 +171,7 @@ static Object dir(VirtualFrame frame, PythonModule self,
@Cached ListNodes.ConstructListNode constructListNode,
@Cached CallNode callNode,
@Cached PyObjectLookupAttr lookup,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object dictObj = lookup.execute(frame, inliningTarget, self, T___DICT__);
if (dictObj instanceof PDict dict) {
Object dirFunc = pyDictGetItem.execute(frame, inliningTarget, dict, T___DIR__);
@@ -181,7 +181,7 @@ static Object dir(VirtualFrame frame, PythonModule self,
return constructListNode.execute(frame, dict);
}
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_DICTIONARY, ".__dict__");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_DICTIONARY, ".__dict__");
}
}
}
@@ -206,18 +206,18 @@ static Object doManaged(PythonModule self, @SuppressWarnings("unused") PNone non
static Object doNativeObject(PythonAbstractNativeObject self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Exclusive @Cached GetDictIfExistsNode getDict,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PDict dict = getDict.execute(self);
if (dict == null) {
- doError(self, none, raiseNode.get(inliningTarget));
+ doError(self, none, raiseNode);
}
return dict;
}
@Fallback
static Object doError(Object self, @SuppressWarnings("unused") Object dict,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.DESCRIPTOR_DICT_FOR_MOD_OBJ_DOES_NOT_APPLY_FOR_P, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.DESCRIPTOR_DICT_FOR_MOD_OBJ_DOES_NOT_APPLY_FOR_P, self);
}
private static PDict createDict(Node inliningTarget, PythonModule self, SetDictNode setDict) {
@@ -272,7 +272,7 @@ static Object getattribute(VirtualFrame frame, PythonModule self, TruffleString
@Cached CallNode callNode,
@Cached PyObjectIsTrueNode castToBooleanNode,
@Cached CastToTruffleStringNode castNameToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
e.expect(inliningTarget, PythonBuiltinClassType.AttributeError, isAttrError);
Object getAttr = readGetattr.execute(self, T___GETATTR__);
if (customGetAttr.profile(inliningTarget, getAttr != PNone.NO_VALUE)) {
@@ -290,20 +290,20 @@ static Object getattribute(VirtualFrame frame, PythonModule self, TruffleString
if (moduleSpec != PNone.NO_VALUE) {
Object isInitializing = readGetattr.execute(moduleSpec, T__INITIALIZING);
if (isInitializing != PNone.NO_VALUE && castToBooleanNode.execute(frame, isInitializing)) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.MODULE_PARTIALLY_INITIALIZED_S_HAS_NO_ATTR_S, moduleName, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.MODULE_PARTIALLY_INITIALIZED_S_HAS_NO_ATTR_S, moduleName, key);
}
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.MODULE_S_HAS_NO_ATTR_S, moduleName, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.MODULE_S_HAS_NO_ATTR_S, moduleName, key);
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.MODULE_HAS_NO_ATTR_S, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.MODULE_HAS_NO_ATTR_S, key);
}
}
}
@Specialization(guards = "!isPythonModule(self)")
static Object getattribute(Object self, @SuppressWarnings("unused") Object key,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GETATTRIBUTE__, "module", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GETATTRIBUTE__, "module", self);
}
}
@@ -330,10 +330,10 @@ static Object delete(Object self, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
@Shared("read") @Cached ReadAttributeFromObjectNode read,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object annotations = read.execute(self, T___ANNOTATIONS__);
if (annotations == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, new Object[]{T___ANNOTATIONS__});
+ throw raiseNode.raise(inliningTarget, AttributeError, new Object[]{T___ANNOTATIONS__});
}
write.execute(self, T___ANNOTATIONS__, PNone.NO_VALUE);
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleGetNameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleGetNameNode.java
index 547ad995af..88118ab53b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleGetNameNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleGetNameNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -69,13 +69,13 @@ public abstract class ModuleGetNameNode extends Node {
static TruffleString doPythonModule(Node inliningTarget, PythonModule module,
@Cached(inline = false) ReadAttributeFromObjectNode readNameNode,
@Cached CastToTruffleStringNode castToTruffleStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
Object name = readNameNode.execute(module, SpecialAttributeNames.T___NAME__);
return castToTruffleStringNode.execute(inliningTarget, name);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.NAMELESS_MODULE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.NAMELESS_MODULE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
index ee95c8cd17..293519e099 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java
@@ -121,10 +121,12 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@GenerateNodeFactory
protected abstract static class SimpleNamespaceInitNode extends PythonVarargsBuiltinNode {
@Specialization
- Object init(PSimpleNamespace self, Object[] args, PKeyword[] kwargs,
- @Cached WriteAttributeToPythonObjectNode writeAttrNode) {
+ static Object init(PSimpleNamespace self, Object[] args, PKeyword[] kwargs,
+ @Bind("this") Node inliningTarget,
+ @Cached WriteAttributeToPythonObjectNode writeAttrNode,
+ @Cached PRaiseNode raiseNode) {
if (args.length > 0) {
- throw raise(PythonBuiltinClassType.TypeError, NO_POSITIONAL_ARGUMENTS_EXPECTED);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, NO_POSITIONAL_ARGUMENTS_EXPECTED);
}
for (PKeyword keyword : kwargs) {
writeAttrNode.execute(self, keyword.getName(), keyword.getValue());
@@ -233,7 +235,7 @@ protected static TruffleString getReprString(Node inliningTarget, Object obj,
try {
return castStr.execute(inliningTarget, reprObj);
} catch (CannotCastException e) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprObj);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprObj);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
index b57d9668a9..b76f4a73bc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
@@ -112,7 +112,6 @@
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
@@ -197,16 +196,16 @@ static PNone setClass(VirtualFrame frame, Object self, Object value,
@Cached CheckCompatibleForAssigmentNode checkCompatibleForAssigmentNode,
@Exclusive @Cached GetClassNode getClassNode,
@Cached SetClassNode setClassNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, value)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CLASS_MUST_BE_SET_TO_CLASS, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CLASS_MUST_BE_SET_TO_CLASS, value);
}
Object type = getClassNode.execute(inliningTarget, self);
boolean bothModuleSubtypes = isModuleProfile.profileClass(inliningTarget, type, PythonBuiltinClassType.PythonModule) &&
isModuleProfile.profileClass(inliningTarget, value, PythonBuiltinClassType.PythonModule);
boolean bothMutable = (getTypeFlagsNode.execute(type) & TypeFlags.IMMUTABLETYPE) == 0 && (getTypeFlagsNode.execute(value) & TypeFlags.IMMUTABLETYPE) == 0;
if (!bothModuleSubtypes && !bothMutable) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
}
checkCompatibleForAssigmentNode.execute(frame, type, value);
@@ -263,15 +262,15 @@ static PNone init(Object self, Object[] arguments, PKeyword[] keywords,
@Cached(parameters = "Init") LookupCallableSlotInMRONode lookupInit,
@Cached(parameters = "New") LookupCallableSlotInMRONode lookupNew,
@Cached TypeNodes.CheckCallableIsSpecificBuiltinNode checkSlotIs,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (arguments.length != 0 || keywords.length != 0) {
Object type = getClassNode.execute(inliningTarget, self);
if (!checkSlotIs.execute(inliningTarget, lookupInit.execute(type), ObjectBuiltinsFactory.InitNodeFactory.getInstance())) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INIT_TAKES_ONE_ARG_OBJECT);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INIT_TAKES_ONE_ARG_OBJECT);
}
if (checkSlotIs.execute(inliningTarget, lookupNew.execute(type), BuiltinConstructorsFactory.ObjectNodeFactory.getInstance())) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INIT_TAKES_ONE_ARG, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.INIT_TAKES_ONE_ARG, type);
}
}
return PNone.NONE;
@@ -395,7 +394,7 @@ Object doItTruffleString(VirtualFrame frame, Object object, @SuppressWarnings("u
@Exclusive @Cached GetClassNode getClassNode,
@Exclusive @Cached GetObjectSlotsNode getSlotsNode,
@Cached("create(cachedKey)") LookupAttributeInMRONode lookup,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
Object descr = lookup.execute(type);
return fullLookup(frame, inliningTarget, object, cachedKey, type, descr, getSlotsNode, raiseNode);
@@ -409,12 +408,12 @@ Object doIt(VirtualFrame frame, Object object, Object keyObj,
@Exclusive @Cached GetClassNode getClassNode,
@Exclusive @Cached GetObjectSlotsNode getSlotsNode,
@Cached CastToTruffleStringNode castKeyToStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString key;
try {
key = castKeyToStringNode.execute(inliningTarget, keyObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
}
Object type = getClassNode.execute(inliningTarget, object);
@@ -422,7 +421,7 @@ Object doIt(VirtualFrame frame, Object object, Object keyObj,
return fullLookup(frame, inliningTarget, object, key, type, descr, getSlotsNode, raiseNode);
}
- private Object fullLookup(VirtualFrame frame, Node inliningTarget, Object object, TruffleString key, Object type, Object descr, GetObjectSlotsNode getSlotsNode, Lazy raiseNode) {
+ private Object fullLookup(VirtualFrame frame, Node inliningTarget, Object object, TruffleString key, Object type, Object descr, GetObjectSlotsNode getSlotsNode, PRaiseNode raiseNode) {
boolean hasDescr = descr != PNone.NO_VALUE;
if (hasDescr && (profileFlags & HAS_DESCR) == 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -456,7 +455,7 @@ private Object fullLookup(VirtualFrame frame, Node inliningTarget, Object object
return dispatch(frame, object, type, descr, descrGetSlot);
}
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
private Object readAttribute(Object object, TruffleString key) {
@@ -608,8 +607,8 @@ private static Object getDescrFromBuiltinBase(Node inliningTarget, Object type,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)", "!isDeleteMarker(mapping)"})
static Object dict(@SuppressWarnings("unused") Object self, Object mapping,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
@Specialization(guards = "isFallback(self, mapping, inliningTarget, getClassNode, otherBuiltinClassProfile, isBuiltinClassProfile)", limit = "1")
@@ -618,9 +617,8 @@ static Object raise(Object self, Object mapping,
@Bind("this") Node inliningTarget,
@Exclusive @Cached IsOtherBuiltinClassProfile otherBuiltinClassProfile,
@Exclusive @Cached IsBuiltinClassExactProfile isBuiltinClassProfile,
- @Exclusive @Cached GetClassNode getClassNode,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, self, "__dict__");
+ @Exclusive @Cached GetClassNode getClassNode) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, self, "__dict__");
}
static boolean isFallback(Object self, Object mapping, Node inliningTarget,
@@ -652,8 +650,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "!formatString.isEmpty()")
static Object format(Object self, @SuppressWarnings("unused") TruffleString formatString,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_FORMAT_STRING_PASSED_TO_P_FORMAT, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_FORMAT_STRING_PASSED_TO_P_FORMAT, self);
}
@Specialization(guards = "formatString.isEmpty()")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
index 8e9de09698..e2f81ebc48 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java
@@ -461,14 +461,14 @@ static Pair doNewArgsEx(VirtualFrame frame, Object getNewArgsExA
@Cached SequenceStorageNodes.GetItemNode getItemNode,
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
@Cached PyObjectSizeNode sizeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object newargs = callNode.execute(frame, getNewArgsExAttr);
if (!tupleCheckNode.execute(inliningTarget, newargs)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, T___GETNEWARGS_EX__, "tuple", newargs);
+ throw raiseNode.raise(inliningTarget, TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, T___GETNEWARGS_EX__, "tuple", newargs);
}
int length = sizeNode.execute(frame, inliningTarget, newargs);
if (length != 2) {
- throw raiseNode.get(inliningTarget).raise(ValueError, SHOULD_RETURN_A_NOT_B, T___GETNEWARGS_EX__, "tuple of length 2", length);
+ throw raiseNode.raise(inliningTarget, ValueError, SHOULD_RETURN_A_NOT_B, T___GETNEWARGS_EX__, "tuple of length 2", length);
}
SequenceStorage sequenceStorage = getSequenceStorageNode.execute(inliningTarget, newargs);
@@ -476,10 +476,10 @@ static Pair doNewArgsEx(VirtualFrame frame, Object getNewArgsExA
Object kwargs = getItemNode.execute(sequenceStorage, 1);
if (!tupleCheckNode.execute(inliningTarget, args)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "first item of the tuple returned by __getnewargs_ex__", "tuple", args);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "first item of the tuple returned by __getnewargs_ex__", "tuple", args);
}
if (!isDictSubClassNode.execute(inliningTarget, kwargs)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "second item of the tuple returned by __getnewargs_ex__", "dict", kwargs);
+ throw raiseNode.raise(inliningTarget, TypeError, MUST_BE_TYPE_A_NOT_TYPE_B, "second item of the tuple returned by __getnewargs_ex__", "dict", kwargs);
}
return Pair.create(args, kwargs);
@@ -490,10 +490,10 @@ static Pair doNewArgs(VirtualFrame frame, @SuppressWarnings("unu
@Bind("this") Node inliningTarget,
@Exclusive @Cached CallNode callNode,
@Exclusive @Cached PyTupleCheckNode tupleCheckNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object args = callNode.execute(frame, getNewArgsAttr);
if (!tupleCheckNode.execute(inliningTarget, args)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, T___GETNEWARGS__, "tuple", args);
+ throw raiseNode.raise(inliningTarget, TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, T___GETNEWARGS__, "tuple", args);
}
return Pair.create(args, PNone.NONE);
}
@@ -519,7 +519,7 @@ static Object[] getstate(VirtualFrame frame, Node inliningTarget, Object type,
@Cached SequenceStorageNodes.ToArrayNode toArrayNode,
@Cached PyImportImport importNode,
@Cached PyObjectCallMethodObjArgs callMethod,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object slotnames = read.execute(type, T___SLOTNAMES__);
boolean hadCachedSlotnames = false;
if (slotnames != PNone.NO_VALUE) {
@@ -533,9 +533,9 @@ static Object[] getstate(VirtualFrame frame, Node inliningTarget, Object type,
} else if (slotnames == PNone.NONE) {
return EMPTY_OBJECT_ARRAY;
} else if (hadCachedSlotnames) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.COPYREG_SLOTNAMES_DIDN_T_RETURN_A_LIST_OR_NONE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.COPYREG_SLOTNAMES_DIDN_T_RETURN_A_LIST_OR_NONE);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.N_SLOTNAMES_SHOULD_BE_A_LIST_OR_NONE_NOT_P, type, slotnames);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_SLOTNAMES_SHOULD_BE_A_LIST_OR_NONE_NOT_P, type, slotnames);
}
}
}
@@ -556,11 +556,11 @@ static Object getstate(VirtualFrame frame, Node inliningTarget, Object obj, bool
@Cached PyObjectLookupAttrO lookupAttr,
@Cached HashingStorageSetItem setHashingStorageItem,
@Cached CheckBasesizeForGetState checkBasesize,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object state;
Object type = getClassNode.execute(inliningTarget, obj);
if (required && getItemsizeNode.execute(inliningTarget, type) != 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
}
Object dict = lookupAttr.execute(frame, inliningTarget, obj, T___DICT__);
@@ -573,7 +573,7 @@ static Object getstate(VirtualFrame frame, Node inliningTarget, Object obj, bool
Object[] slotnames = getSlotNamesNode.execute(frame, inliningTarget, type);
if (required && !checkBasesize.execute(inliningTarget, obj, type, slotnames.length)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
}
if (slotnames.length > 0) {
@@ -676,10 +676,10 @@ static Object reduceNewObj(VirtualFrame frame, Node inliningTarget, Object obj,
@Exclusive @Cached PyObjectCallMethodObjArgs callMethod,
@Cached PyObjectGetIter getIter,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object cls = getClassNode.execute(inliningTarget, obj);
if (lookupNew.execute(cls) == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
}
Pair rv = getNewArgsNode.execute(frame, obj);
@@ -708,7 +708,7 @@ static Object reduceNewObj(VirtualFrame frame, Node inliningTarget, Object obj,
newobj = lookupAttr.execute(frame, inliningTarget, copyReg, T___NEWOBJ_EX__);
newargs = PFactory.createTuple(language, new Object[]{cls, args, kwargs});
} else {
- throw raiseNode.get(inliningTarget).raiseBadInternalCall();
+ throw raiseNode.raiseBadInternalCall(inliningTarget);
}
boolean objIsList = isSubClassNode.executeWith(frame, cls, PythonBuiltinClassType.PList);
@@ -847,7 +847,7 @@ static void doStringKey(Node inliningTarget, VirtualFrame frame, Object object,
@Shared @Cached(inline = false) LookupAttributeInMRONode.Dynamic getExisting,
@Shared @Cached(inline = false) ReadAttributeFromObjectNode attrRead,
@Shared @Cached InlinedBranchProfile deleteNonExistingBranchProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
setAttr(inliningTarget, frame, object, key, value, writeNode, getClassNode, hasDescriptor,
getDescrSlotsNode, callSetNode, getExisting, attrRead, deleteNonExistingBranchProfile,
raiseNode);
@@ -864,18 +864,18 @@ static void doGeneric(Node inliningTarget, VirtualFrame frame, Object object, Ob
@Shared @Cached(inline = false) LookupAttributeInMRONode.Dynamic getExisting,
@Shared @Cached(inline = false) ReadAttributeFromObjectNode attrRead,
@Shared @Cached InlinedBranchProfile deleteNonExistingBranchProfile,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
TruffleString key = castAttributeKey(inliningTarget, keyObject, castKeyToStringNode, raiseNode);
setAttr(inliningTarget, frame, object, key, value, writeNode, getClassNode, hasDescriptor,
getDescrSlotsNode, callSetNode, getExisting, attrRead, deleteNonExistingBranchProfile,
raiseNode);
}
- public static TruffleString castAttributeKey(Node inliningTarget, Object keyObject, CastToTruffleStringNode castKeyToStringNode, PRaiseNode.Lazy raiseNode) {
+ public static TruffleString castAttributeKey(Node inliningTarget, Object keyObject, CastToTruffleStringNode castKeyToStringNode, PRaiseNode raiseNode) {
try {
return castKeyToStringNode.execute(inliningTarget, keyObject);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ATTR_NAME_MUST_BE_STRING, keyObject);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ATTR_NAME_MUST_BE_STRING, keyObject);
}
}
@@ -884,7 +884,7 @@ private static void setAttr(Node inliningTarget, VirtualFrame frame, Object obje
InlinedConditionProfile hasDescriptor, GetObjectSlotsNode getDescrSlotsNode,
CallSlotDescrSet callSetNode, LookupAttributeInMRONode.Dynamic getExisting,
ReadAttributeFromObjectNode attrRead, InlinedBranchProfile deleteNonExistingBranchProfile,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
Object descr = getExisting.execute(type, key);
if (hasDescriptor.profile(inliningTarget, !PGuards.isNoValue(descr))) {
@@ -912,9 +912,9 @@ private static void setAttr(Node inliningTarget, VirtualFrame frame, Object obje
}
if (descr != PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.ATTR_S_READONLY, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.ATTR_S_READONLY, key);
} else {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.HAS_NO_ATTR, object, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, object, key);
}
}
@@ -998,7 +998,7 @@ static void doIt(Object object, Object key, Object type,
message = ErrorMessages.HAS_NO_ATTR;
firstArg = object;
}
- raiseNode.raise(PythonBuiltinClassType.AttributeError, message, firstArg, key);
+ raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, message, firstArg, key);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
index 95fe5354c5..19018ae0c8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
@@ -146,12 +146,12 @@ abstract static class InitNode extends PythonBuiltinNode {
static PNone update(VirtualFrame frame, PDict self, Object[] args, PKeyword[] kwargs,
@Bind("this") Node inliningTarget,
@Cached UpdateFromArgsNode update,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object mapping = PNone.NO_VALUE;
if (args.length == 1) {
mapping = args[0];
} else if (args.length > 1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, 1, args.length);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, 1, args.length);
}
update.execute(frame, inliningTarget, self, mapping, kwargs);
return PNone.NONE;
@@ -192,7 +192,7 @@ static void delitem(VirtualFrame frame, POrderedDict self, Object key, @Suppress
long hash = hashNode.execute(frame, inliningTarget, key);
ODictNode node = (ODictNode) removeNode.execute(frame, inliningTarget, self.nodes, key, hash);
if (node == null) {
- throw raiseNode.raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
self.remove(node);
// TODO with hash
@@ -338,7 +338,7 @@ static Object pop(VirtualFrame frame, POrderedDict self, Object key, Object defa
@Cached PySequenceContainsNode containsNode,
@Cached PyObjectGetItem getItem,
@Cached PyObjectDelItem delItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// XXX the CPython implementation is weird when self is a subclass
if (containsNode.execute(frame, inliningTarget, self, key)) {
Object value = getItem.execute(frame, inliningTarget, self, key);
@@ -347,7 +347,7 @@ static Object pop(VirtualFrame frame, POrderedDict self, Object key, Object defa
} else if (defaultValue != PNone.NO_VALUE) {
return defaultValue;
} else {
- throw raiseNode.get(inliningTarget).raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
}
}
@@ -362,10 +362,10 @@ static Object popitem(VirtualFrame frame, POrderedDict self, boolean last,
@Cached HashingStorageNodes.HashingStorageDelItem delItem,
@Cached ObjectHashMap.RemoveNode removeNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
ODictNode node = last ? self.last : self.first;
if (node == null) {
- throw raise.get(inliningTarget).raise(KeyError, ErrorMessages.IS_EMPTY, "dictionary");
+ throw raise.raise(inliningTarget, KeyError, ErrorMessages.IS_EMPTY, "dictionary");
}
self.remove(node);
removeNode.execute(frame, inliningTarget, self.nodes, node.key, node.hash);
@@ -420,13 +420,13 @@ static PNone move(VirtualFrame frame, POrderedDict self, Object key, boolean las
@Cached PRaiseNode raiseNode) {
if (self.first == null) {
// Empty
- throw raiseNode.raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
if ((last ? self.last : self.first).key != key) {
long hash = hashNode.execute(frame, inliningTarget, key);
ODictNode node = (ODictNode) getNode.execute(frame, inliningTarget, self.nodes, key, hash);
if (node == null) {
- throw raiseNode.raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
if (last) {
if (self.last != node) {
@@ -630,8 +630,8 @@ static Object dict(Object self, @SuppressWarnings("unused") PNone mapping,
@Specialization(guards = {"!isNoValue(mapping)", "!isDict(mapping)"})
static PNone dict(@SuppressWarnings("unused") Object self, Object mapping,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, mapping);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
index 97e798523a..cf5dc45c52 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictIteratorBuiltins.java
@@ -99,10 +99,10 @@ static Object next(VirtualFrame frame, POrderedDictIterator self,
@Cached PRaiseNode raiseNode,
@Cached HashingStorageNodes.HashingStorageGetItemWithHash getItem) {
if (self.current == null) {
- throw raiseNode.raise(StopIteration);
+ throw raiseNode.raise(inliningTarget, StopIteration);
}
if (self.size != self.dict.nodes.size()) {
- throw raiseNode.raise(RuntimeError, ErrorMessages.CHANGED_SIZE_DURING_ITERATION, "OrderedDict");
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.CHANGED_SIZE_DURING_ITERATION, "OrderedDict");
}
Object result;
Object key = self.current.key;
@@ -111,7 +111,7 @@ static Object next(VirtualFrame frame, POrderedDictIterator self,
} else {
Object value = getItem.execute(frame, inliningTarget, self.dict.getDictStorage(), key, self.current.hash);
if (value == null) {
- throw raiseNode.raise(KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
}
if (self.type == POrderedDictIterator.IteratorType.VALUES) {
result = value;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
index e903bc3407..75dcd10d55 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/ScandirIteratorBuiltins.java
@@ -113,16 +113,16 @@ static PDirEntry next(VirtualFrame frame, PScandirIterator self,
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (self.ref.isReleased()) {
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
PosixSupport posixSupport = PosixSupport.get(inliningTarget);
try {
Object dirEntryData = posixLib.readdir(posixSupport, self.ref.getReference());
if (dirEntryData == null) {
self.ref.rewindAndClose(posixLib, posixSupport);
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
return PFactory.createDirEntry(language, dirEntryData, self.path);
} catch (PosixException e) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
index d52d7949ae..9aebab77c0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/property/PropertyBuiltins.java
@@ -157,7 +157,7 @@ abstract static class PropertyFuncNode extends PythonBinaryBuiltinNode {
@Specialization(guards = "!isNoValue(value)")
@SuppressWarnings("unused")
static Object doSet(PProperty self, Object value,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
/*
* That's a bit unfortunate: if we define 'isGetter = true' and 'isSetter = false' then
* this will use a GetSetDescriptor which has a slightly different error message for
@@ -165,7 +165,7 @@ static Object doSet(PProperty self, Object value,
* with expected message. This should be fixed by distinguishing between getset and
* member descriptors.
*/
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.READONLY_ATTRIBUTE);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.READONLY_ATTRIBUTE);
}
}
@@ -314,9 +314,9 @@ PException error(VirtualFrame frame, PProperty self, Object obj, String what,
TruffleString qualName = getQualNameNode.execute(inliningTarget, getClassNode.execute(inliningTarget, obj));
if (self.getPropertyName() != null) {
TruffleString propertyName = reprNode.execute(frame, inliningTarget, self.getPropertyName());
- throw raiseNode.raise(AttributeError, ErrorMessages.PROPERTY_S_OF_S_OBJECT_HAS_NO_S, propertyName, qualName, what);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.PROPERTY_S_OF_S_OBJECT_HAS_NO_S, propertyName, qualName, what);
} else {
- throw raiseNode.raise(AttributeError, ErrorMessages.PROPERTY_OF_S_OBJECT_HAS_NO_S, qualName, what);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.PROPERTY_OF_S_OBJECT_HAS_NO_S, qualName, what);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
index 3d4947b771..8b8b133f55 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/queue/SimpleQueueBuiltins.java
@@ -128,12 +128,12 @@ public abstract static class SimpleQueueGetNoWaitNode extends PythonUnaryBuiltin
@Specialization
static Object doNoTimeout(PSimpleQueue self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = self.poll();
if (result != null) {
return result;
}
- throw raiseNode.get(inliningTarget).raise(Empty);
+ throw raiseNode.raise(inliningTarget, Empty);
}
}
@@ -165,7 +165,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static Object doNoTimeout(PSimpleQueue self, boolean block, @SuppressWarnings("unused") Object timeout,
@Bind("this") Node inliningTarget,
@Shared @Cached GilNode gil,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
// CPython first tries a non-blocking get without releasing the GIL
Object result = self.poll();
if (result != null) {
@@ -183,7 +183,7 @@ static Object doNoTimeout(PSimpleQueue self, boolean block, @SuppressWarnings("u
gil.acquire();
}
}
- throw raiseNode.get(inliningTarget).raise(Empty);
+ throw raiseNode.raise(inliningTarget, Empty);
}
@Specialization(guards = "withTimeout(block, timeout)")
@@ -192,7 +192,7 @@ static Object doTimeout(VirtualFrame frame, PSimpleQueue self, boolean block, Ob
@Cached PyLongAsLongAndOverflowNode asLongNode,
@Cached CastToJavaDoubleNode castToDouble,
@Shared @Cached GilNode gil,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
assert block;
// convert timeout object (given in seconds) to a Java long in microseconds
@@ -203,12 +203,12 @@ static Object doTimeout(VirtualFrame frame, PSimpleQueue self, boolean block, Ob
try {
ltimeout = PythonUtils.multiplyExact(asLongNode.execute(frame, inliningTarget, timeout), 1000000);
} catch (OverflowException oe) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.TIMEOUT_VALUE_TOO_LARGE);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.TIMEOUT_VALUE_TOO_LARGE);
}
}
if (ltimeout < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TIMEOUT_MUST_BE_NON_NEG_NUM);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TIMEOUT_MUST_BE_NON_NEG_NUM);
}
// CPython first tries a non-blocking get without releasing the GIL
@@ -229,7 +229,7 @@ static Object doTimeout(VirtualFrame frame, PSimpleQueue self, boolean block, Ob
} finally {
gil.acquire();
}
- throw raiseNode.get(inliningTarget).raise(Empty);
+ throw raiseNode.raise(inliningTarget, Empty);
}
static boolean withTimeout(boolean block, Object timeout) {
@@ -253,13 +253,13 @@ public abstract static class SimpleQueuePutNode extends PythonQuaternaryBuiltinN
@Specialization
static PNone doGeneric(PSimpleQueue self, Object item, @SuppressWarnings("unused") Object block, @SuppressWarnings("unused") Object timeout,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!self.put(item)) {
/*
* CPython uses a Python list as backing storage. This will throw an OverflowError
* if no more elements can be added to the list.
*/
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
return PNone.NONE;
}
@@ -278,13 +278,13 @@ public abstract static class SimpleQueuePutNoWaitNode extends PythonBinaryBuilti
@Specialization
static PNone doGeneric(PSimpleQueue self, Object item,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!self.put(item)) {
/*
* CPython uses a Python list as backing storage. This will throw an OverflowError
* if no more elements can be added to the list.
*/
- throw raiseNode.get(inliningTarget).raise(OverflowError);
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
index 13a8a35714..beed98da00 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
@@ -160,10 +160,10 @@ static PNone setstate(PRandom random, PTuple tuple,
@Bind("this") Node inliningTarget,
@Cached GetObjectArrayNode getObjectArrayNode,
@Cached CastToJavaUnsignedLongNode castNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] arr = getObjectArrayNode.execute(inliningTarget, tuple);
if (arr.length != PRandom.N + 1) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.STATE_VECTOR_INVALID);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.STATE_VECTOR_INVALID);
}
int[] state = new int[PRandom.N];
for (int i = 0; i < PRandom.N; ++i) {
@@ -172,7 +172,7 @@ static PNone setstate(PRandom random, PTuple tuple,
}
long index = castNode.execute(inliningTarget, arr[PRandom.N]);
if (index < 0 || index > PRandom.N) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.STATE_VECTOR_INVALID);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.STATE_VECTOR_INVALID);
}
random.restore(state, (int) index);
return PNone.NONE;
@@ -181,8 +181,8 @@ static PNone setstate(PRandom random, PTuple tuple,
@Fallback
@SuppressWarnings("unused")
static Object setstate(Object random, Object state,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.STATE_VECTOR_MUST_BE_A_TUPLE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.STATE_VECTOR_MUST_BE_A_TUPLE);
}
}
@@ -236,8 +236,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Specialization(guards = "k < 0")
@SuppressWarnings("unused")
static int negative(PRandom random, int k,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.NUMBER_OF_BITS_MUST_BE_NON_NEGATIVE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.NUMBER_OF_BITS_MUST_BE_NON_NEGATIVE);
}
@Specialization(guards = "k == 0")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
index ffaef39146..79c58f9caa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
@@ -208,12 +208,12 @@ static int doPBigRange(VirtualFrame frame, PBigRange self,
@Bind("this") Node inliningTarget,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object length = self.getLength();
if (indexCheckNode.execute(inliningTarget, length)) {
return asSizeNode.executeExact(frame, inliningTarget, length);
}
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, length);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, length);
}
@NeverDefault
@@ -410,7 +410,7 @@ public abstract static class RangeSqItemNode extends SqItemBuiltinNode {
static int doInt(PIntRange self, int index,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile negativeIndexProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (negativeIndexProfile.profile(inliningTarget, index < 0)) {
index += self.getIntLength();
}
@@ -514,7 +514,7 @@ static Object doPRangeSliceSlowPath(VirtualFrame frame, PBigRange self, PSlice s
@SuppressWarnings("unused") @Shared @Cached PyIndexCheckNode indexCheckNode,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
// unused node to avoid mixing shared and non-shared inlined nodes
- @SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @SuppressWarnings("unused") @Shared @Cached PRaiseNode raiseNode) {
try {
int rStart = asSizeNode.executeExact(frame, inliningTarget, self.getStart());
int rStep = asSizeNode.executeExact(frame, inliningTarget, self.getStep());
@@ -550,7 +550,7 @@ static Object doGeneric(VirtualFrame frame, PRange self, Object idx,
@Shared @Cached PyIndexCheckNode indexCheckNode,
@Shared @Cached PyNumberAsSizeNode asSizeNode,
@Shared @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (isNumIndexProfile.profile(inliningTarget, canBeIndex(inliningTarget, idx, indexCheckNode))) {
if (self instanceof PIntRange) {
return doPRange(frame, (PIntRange) self, idx, inliningTarget, indexCheckNode, asSizeNode, normalize);
@@ -566,7 +566,7 @@ static Object doGeneric(VirtualFrame frame, PRange self, Object idx,
return doPRangeSliceSlowPath(frame, (PBigRange) self, slice, inliningTarget, isNumIndexProfile, isSliceIndexProfile, compute, profileError, toBigIntRange, toBigIntSlice,
lenOfRangeNodeExact, lenOfRangeNode, indexCheckNode, asSizeNode, raiseNode);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "range", idx);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "range", idx);
}
@TruffleBoundary
@@ -591,7 +591,7 @@ private static BigInteger computeBigRangeItem(Node inliningTarget, PBigRange ran
}
if (i.compareTo(BigInteger.ZERO) < 0 || i.compareTo(length) >= 0) {
- throw PRaiseNode.raiseUncached(inliningTarget, IndexError, ErrorMessages.RANGE_OBJ_IDX_OUT_OF_RANGE);
+ throw PRaiseNode.raiseStatic(inliningTarget, IndexError, ErrorMessages.RANGE_OBJ_IDX_OUT_OF_RANGE);
}
return i;
}
@@ -840,14 +840,14 @@ private static BigInteger slowIntIndex(Node inliningTarget, PBigRange self, Obje
static int doFastRange(VirtualFrame frame, PIntRange self, int elem,
@Bind("this") Node inliningTarget,
@Shared @Cached ContainsNode containsNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (containsNode.execute(frame, self, elem)) {
int index = fastIntIndex(self, elem);
if (index != -1) {
return index;
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
}
@Specialization(guards = "canBeInteger(elem)")
@@ -855,7 +855,7 @@ static Object doFastRangeGeneric(VirtualFrame frame, PIntRange self, Object elem
@Bind("this") Node inliningTarget,
@Shared @Cached ContainsNode containsNode,
@Cached PyNumberAsSizeNode asSizeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (containsNode.execute(frame, self, elem)) {
int value = asSizeNode.executeExact(frame, inliningTarget, elem);
int index = fastIntIndex(self, value);
@@ -863,7 +863,7 @@ static Object doFastRangeGeneric(VirtualFrame frame, PIntRange self, Object elem
return index;
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.IS_NOT_IN_RANGE, elem);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IS_NOT_IN_RANGE, elem);
}
@Specialization(guards = "canBeInteger(elem)")
@@ -871,14 +871,14 @@ static Object doLongRange(VirtualFrame frame, PBigRange self, Object elem,
@Bind("this") Node inliningTarget,
@Shared @Cached ContainsNode containsNode,
@Cached CastToJavaBigIntegerNode castToBigInt,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (containsNode.execute(frame, self, elem)) {
BigInteger index = slowIntIndex(inliningTarget, self, elem, castToBigInt);
if (index != null) {
return PFactory.createInt(PythonLanguage.get(inliningTarget), index);
}
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
}
/**
@@ -892,7 +892,7 @@ static Object containsIterator(VirtualFrame frame, PIntRange self, Object elem,
@Cached PyObjectGetIter getIter,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached IsBuiltinObjectProfile errorProfile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
int idx = 0;
Object iter = getIter.execute(frame, inliningTarget, self);
while (true) {
@@ -906,11 +906,11 @@ static Object containsIterator(VirtualFrame frame, PIntRange self, Object elem,
break;
}
if (idx == SysModuleBuiltins.MAXSIZE) {
- throw raiseNode.get(inliningTarget).raiseOverflow();
+ throw raiseNode.raiseOverflow(inliningTarget);
}
idx++;
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
}
}
@@ -991,7 +991,7 @@ static int doGeneric(VirtualFrame frame, PRange self, Object elem,
@Cached GetNextNode nextNode,
@Cached PyObjectRichCompareBool.EqNode eqNode,
@Cached IsBuiltinObjectProfile errorProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int count = 0;
Object iter = getIter.execute(frame, inliningTarget, self);
while (true) {
@@ -999,7 +999,7 @@ static int doGeneric(VirtualFrame frame, PRange self, Object elem,
Object item = nextNode.execute(frame, iter);
if (eqNode.compare(frame, inliningTarget, elem, item)) {
if (count == SysModuleBuiltins.MAXSIZE) {
- throw raiseNode.get(inliningTarget).raiseOverflow();
+ throw raiseNode.raiseOverflow(inliningTarget);
}
count = count + 1;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
index f139b88e3e..ef29cc7899 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeNodes.java
@@ -73,9 +73,9 @@ public abstract static class CreateBigRangeNode extends Node {
public abstract PBigRange execute(Node inliningTarget, Object start, Object stop, Object step);
@TruffleBoundary
- private static void checkStepZero(Node inliningTarget, BigInteger stepBI, PRaiseNode.Lazy raise) {
+ private static void checkStepZero(Node inliningTarget, BigInteger stepBI, PRaiseNode raise) {
if (stepBI.compareTo(BigInteger.ZERO) == 0) {
- throw raise.get(inliningTarget).raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
+ throw raise.raise(inliningTarget, ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
}
}
@@ -85,7 +85,7 @@ static PBigRange createBigRange(Node inliningTarget, Object start, Object stop,
@Cached CastToJavaBigIntegerNode startToBI,
@Cached CastToJavaBigIntegerNode stopToBI,
@Cached CastToJavaBigIntegerNode stepToBI,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
BigInteger stepBI = stepToBI.execute(inliningTarget, step);
checkStepZero(inliningTarget, stepBI, raise);
BigInteger startBI = startToBI.execute(inliningTarget, start);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
index f299f37366..a713daa3eb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
@@ -141,21 +141,21 @@ static long computeHash(VirtualFrame frame, PReferenceType self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile referentProfile,
@Cached PyObjectHashNode hashNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object referent = self.getObject();
if (referentProfile.profile(inliningTarget, referent != null)) {
long hash = hashNode.execute(frame, inliningTarget, referent);
self.setHash(hash);
return hash;
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.WEAK_OBJ_GONE_AWAY);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.WEAK_OBJ_GONE_AWAY);
}
}
@Fallback
static int hashWrong(@SuppressWarnings("unused") Object self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, "__hash__", "weakref", self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, "__hash__", "weakref", self);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
index 8dae6a67ea..c7fc519f6e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/reversed/ReversedBuiltins.java
@@ -87,8 +87,8 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.isExhausted()")
static Object exhausted(@SuppressWarnings("unused") PBuiltinIterator self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseStopIteration();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
@Specialization(guards = "!self.isExhausted()")
@@ -96,7 +96,7 @@ static Object next(VirtualFrame frame, PSequenceReverseIterator self,
@Bind("this") Node inliningTarget,
@Cached PySequenceGetItemNode getItemNode,
@Cached IsBuiltinObjectProfile profile,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.index >= 0) {
try {
return getItemNode.execute(frame, self.getObject(), self.index--);
@@ -105,19 +105,19 @@ static Object next(VirtualFrame frame, PSequenceReverseIterator self,
}
}
self.setExhausted();
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
@Specialization(guards = "!self.isExhausted()")
static Object next(PStringReverseIterator self,
@Bind("this") Node inliningTarget,
@Cached TruffleString.SubstringNode substringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (self.index >= 0) {
return substringNode.execute(self.value, self.index--, 1, TS_ENCODING, false);
}
self.setExhausted();
- throw raiseNode.get(inliningTarget).raiseStopIteration();
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
}
@@ -149,10 +149,10 @@ static int lengthHint(PStringReverseIterator self) {
static int lengthHint(PSequenceReverseIterator self,
@Bind("this") Node inliningTarget,
@Cached SequenceNodes.LenNode lenNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int len = lenNode.execute(inliningTarget, self.getPSequence());
if (len == -1) {
- throw raiseNode.get(inliningTarget).raise(TypeError, OBJ_HAS_NO_LEN, self);
+ throw raiseNode.raise(inliningTarget, TypeError, OBJ_HAS_NO_LEN, self);
}
if (len < self.index) {
return 0;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
index bbe0f3ea1e..4cb3141a30 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
@@ -137,8 +137,8 @@ static PNone doGeneric(VirtualFrame frame, PSet self, Object iterable,
@Fallback
static PNone fail(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object self, Object iterable,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.SET_DOES_NOT_SUPPORT_ITERABLE_OBJ, iterable);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.SET_DOES_NOT_SUPPORT_ITERABLE_OBJ, iterable);
}
}
@@ -684,9 +684,9 @@ abstract static class RemoveNode extends PythonBinaryBuiltinNode {
static Object remove(VirtualFrame frame, PSet self, Object key,
@Bind("this") Node inliningTarget,
@Cached com.oracle.graal.python.builtins.objects.set.SetNodes.DiscardNode discardNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!discardNode.execute(frame, self, key)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, PythonErrorType.KeyError, new Object[]{key});
}
return PNone.NONE;
}
@@ -710,12 +710,12 @@ public abstract static class PopNode extends PythonUnaryBuiltinNode {
static Object remove(PSet self,
@Bind("this") Node inliningTarget,
@Cached HashingStoragePop popNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] result = popNode.execute(inliningTarget, self.getDictStorage(), self);
if (result != null) {
return result[0];
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.KeyError, ErrorMessages.POP_FROM_EMPTY_SET);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.KeyError, ErrorMessages.POP_FROM_EMPTY_SET);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
index 09fa381d61..c5348cb4f3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java
@@ -101,8 +101,8 @@ static PSet setIterable(VirtualFrame frame, Object iterable,
@Fallback
static PSet setObject(Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_NOT_ITERABLE, value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_NOT_ITERABLE, value);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
index ba8805dfb4..c66da77e16 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PObjectSlice.java
@@ -134,7 +134,7 @@ public static SliceObjectInfo computeIndicesSlowPath(PObjectSlice slice, Object
BigInteger start, stop, step, length;
length = (BigInteger) lengthIn;
if (pySign(length) < 0) {
- throw PRaiseNode.raiseUncached(null, ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
+ throw PRaiseNode.raiseStatic(null, ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
}
if (slice.getStep() == PNone.NONE) {
step = ONE;
@@ -143,7 +143,7 @@ public static SliceObjectInfo computeIndicesSlowPath(PObjectSlice slice, Object
step = (BigInteger) slice.getStep();
stepIsNegative = pySign(step) < 0;
if (pySign(step) == 0) {
- throw PRaiseNode.raiseUncached(null, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw PRaiseNode.raiseStatic(null, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PSlice.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PSlice.java
index 2989727c5e..d49fed28e8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PSlice.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PSlice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -110,7 +110,7 @@ public record SliceInfoLong(long start, long stop, long step) {
protected static void checkNegative(int length) {
if (length < 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(null, ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
+ throw PRaiseNode.raiseStatic(null, ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
}
}
@@ -142,7 +142,7 @@ public static SliceInfo computeIndices(Object startIn, Object stopIn, Object ste
stepIsNegative = pySign(step) < 0;
if (pySign(step) == 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(null, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw PRaiseNode.raiseStatic(null, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
index 3a951b574e..6e3df887c1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceBuiltins.java
@@ -219,8 +219,8 @@ static PTuple doSliceObjectWithSlowPath(VirtualFrame frame, PSlice self, Object
@Specialization(guards = {"isPNone(length)"})
static PTuple lengthNone(@SuppressWarnings("unused") PSlice self, @SuppressWarnings("unused") Object length,
- @Cached PRaiseNode raise) {
- throw raise.raise(ValueError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError);
}
}
@@ -230,8 +230,8 @@ public abstract static class HashNode extends PythonBuiltinNode {
@SuppressWarnings("unused")
@Specialization
public static long hash(PSlice self,
- @Cached PRaiseNode raise) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNHASHABLE_TYPE_P, PythonBuiltinClassType.PSlice);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNHASHABLE_TYPE_P, PythonBuiltinClassType.PSlice);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
index 577f2b6b31..e867c633bd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/SliceNodes.java
@@ -137,13 +137,13 @@ public abstract static class AdjustIndices extends PNodeWithContext {
@Specialization
static PSlice.SliceInfo calc(Node inliningTarget, int length, PSlice.SliceInfo slice,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int start = slice.start;
int stop = slice.stop;
int step = slice.step;
if (step == 0) {
- raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
assert step > Integer.MIN_VALUE : "step must not be minimum integer value";
@@ -207,8 +207,8 @@ PSlice.SliceInfo doSliceObject(VirtualFrame frame, PObjectSlice slice, int lengt
@Specialization(guards = "length < 0")
PSlice.SliceInfo doSliceInt(@SuppressWarnings("unused") PSlice slice, @SuppressWarnings("unused") int length,
- @Cached PRaiseNode raise) {
- throw raise.raise(ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.LENGTH_SHOULD_NOT_BE_NEG);
}
}
@@ -297,7 +297,7 @@ static PSlice.SliceInfo doSliceInt(PIntSlice slice) {
@InliningCutoff
static PSlice.SliceInfo doSliceObject(Node inliningTarget, PObjectSlice slice,
@Cached SliceLossyCastToInt toInt,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/* this is harder to get right than you might think */
int start, stop, step;
if (slice.getStep() == PNone.NONE) {
@@ -305,7 +305,7 @@ static PSlice.SliceInfo doSliceObject(Node inliningTarget, PObjectSlice slice,
} else {
step = (int) toInt.execute(inliningTarget, slice.getStep());
if (step == 0) {
- raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
}
@@ -339,10 +339,10 @@ public abstract static class SliceUnpackLong extends PNodeWithContext {
@Specialization
static PSlice.SliceInfoLong doSliceInt(Node inliningTarget, PIntSlice slice,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
long step = slice.getIntStep();
if (step == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
long start;
@@ -357,7 +357,7 @@ static PSlice.SliceInfoLong doSliceInt(Node inliningTarget, PIntSlice slice,
@Specialization
static PSlice.SliceInfoLong doSliceObject(Node inliningTarget, PObjectSlice slice,
@Cached SliceLossyCastToLong toInt,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
/* this is harder to get right than you might think */
long start, stop, step;
if (slice.getStep() == PNone.NONE) {
@@ -365,7 +365,7 @@ static PSlice.SliceInfoLong doSliceObject(Node inliningTarget, PObjectSlice slic
} else {
step = toInt.execute(inliningTarget, slice.getStep());
if (step == 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SLICE_STEP_CANNOT_BE_ZERO);
}
/*
* Same as in CPython 'PySlice_Unpack': Here step might be -Long.MAX_VALUE-1; in
@@ -410,13 +410,13 @@ protected static Object doNone(@SuppressWarnings("unused") PNone i) {
@Specialization(guards = "!isPNone(i)")
protected static Object doGeneric(Node inliningTarget, Object i,
@Cached InlinedBranchProfile exceptionProfile,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached CastToJavaBigIntegerNode cast) {
try {
return cast.execute(inliningTarget, i);
} catch (PException e) {
exceptionProfile.enter(inliningTarget);
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
}
}
}
@@ -436,13 +436,13 @@ protected static Object doNone(@SuppressWarnings("unused") PNone i) {
@Specialization(guards = "!isPNone(i)")
protected static Object doGeneric(Node inliningTarget, Object i,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode) {
if (indexCheckNode.execute(inliningTarget, i)) {
return asSizeNode.executeExact(null, inliningTarget, i);
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
}
}
@@ -462,14 +462,14 @@ protected static Object doNone(@SuppressWarnings("unused") PNone i) {
@Specialization(guards = "!isPNone(i)")
protected static Object doGeneric(Node inliningTarget, Object i,
@Cached InlinedBranchProfile exceptionProfile,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode) {
if (indexCheckNode.execute(inliningTarget, i)) {
return asSizeNode.executeLossy(null, inliningTarget, i);
}
exceptionProfile.enter(inliningTarget);
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
}
}
@@ -483,7 +483,7 @@ public abstract static class SliceLossyCastToLong extends Node {
@Specialization(guards = "!isPNone(i)")
static long doGeneric(Node inliningTarget, Object i,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached PyIndexCheckNode indexCheckNode,
@Cached(inline = false) PyLongSign signNode,
@Cached PyLongAsLongAndOverflowNode asSizeNode) {
@@ -497,7 +497,7 @@ static long doGeneric(Node inliningTarget, Object i,
return Long.MAX_VALUE;
}
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SLICE_INDICES_MUST_BE_INT_NONE_HAVE_INDEX);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
index 755c2c3b07..7456dd77cf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java
@@ -124,9 +124,9 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
return SocketBuiltinsFactory.getFactories();
}
- private static void checkSelectable(Node inliningTarget, PRaiseNode.Lazy raiseNode, PSocket socket) {
+ private static void checkSelectable(Node inliningTarget, PRaiseNode raiseNode, PSocket socket) {
if (!isSelectable(socket)) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.UNABLE_TO_SELECT_ON_SOCKET);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.UNABLE_TO_SELECT_ON_SOCKET);
}
}
@@ -199,13 +199,13 @@ static Object init(VirtualFrame frame, PSocket self, int familyIn, int typeIn, i
@Exclusive @Cached SysModuleBuiltins.AuditNode auditNode,
@Cached PyLongAsIntNode asIntNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// sic! CPython really has __new__ there, even though it's in __init__
auditNode.audit(inliningTarget, "socket.__new__", self, familyIn, typeIn, protoIn);
int fd = asIntNode.execute(frame, inliningTarget, fileno);
if (fd < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_FILE_DESC);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_FILE_DESC);
}
int family = familyIn;
try {
@@ -287,7 +287,7 @@ static Object accept(VirtualFrame frame, PSocket self,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
checkSelectable(inliningTarget, raiseNode, self);
try {
@@ -590,9 +590,9 @@ static Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (recvlen < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECV);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECV);
}
checkSelectable(inliningTarget, raiseNode, socket);
PythonLanguage language = context.getLanguage(inliningTarget);
@@ -604,7 +604,7 @@ static Object recv(VirtualFrame frame, PSocket socket, int recvlen, int flags,
try {
bytes = new byte[recvlen];
} catch (OutOfMemoryError error) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
try {
@@ -641,9 +641,9 @@ static Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flag
@Cached GilNode gil,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (recvlen < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECVFROM);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECVFROM);
}
checkSelectable(inliningTarget, raiseNode, socket);
@@ -651,7 +651,7 @@ static Object recvFrom(VirtualFrame frame, PSocket socket, int recvlen, int flag
try {
bytes = new byte[recvlen];
} catch (OutOfMemoryError error) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
try {
@@ -694,11 +694,11 @@ static Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireWritable(bufferObj, frame, indirectCallData);
try {
if (recvlenIn < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECV_INTO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECV_INTO);
}
int buflen = bufferLib.getBufferLength(buffer);
int recvlen = recvlenIn;
@@ -706,7 +706,7 @@ static Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int
recvlen = buflen;
}
if (buflen < recvlen) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.BUFF_TOO_SMALL);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BUFF_TOO_SMALL);
}
checkSelectable(inliningTarget, raiseNode, socket);
@@ -719,7 +719,7 @@ static Object recvInto(VirtualFrame frame, PSocket socket, Object bufferObj, int
try {
bytes = new byte[recvlen];
} catch (OutOfMemoryError error) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -763,11 +763,11 @@ static Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj,
@Cached GilNode gil,
@Cached SocketNodes.MakeSockAddrNode makeSockAddrNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireWritable(bufferObj, frame, indirectCallData);
try {
if (recvlenIn < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECVFROM_INTO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NEG_BUFF_SIZE_IN_RECVFROM_INTO);
}
int buflen = bufferLib.getBufferLength(buffer);
int recvlen = recvlenIn;
@@ -775,7 +775,7 @@ static Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj,
recvlen = buflen;
}
if (buflen < recvlen) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NBYTES_GREATER_THAT_BUFF);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NBYTES_GREATER_THAT_BUFF);
}
checkSelectable(inliningTarget, raiseNode, socket);
@@ -788,7 +788,7 @@ static Object recvFromInto(VirtualFrame frame, PSocket socket, Object bufferObj,
try {
bytes = new byte[recvlen];
} catch (OutOfMemoryError error) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
@@ -829,7 +829,7 @@ static int send(VirtualFrame frame, PSocket socket, Object bufferObj, int flags,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(bufferObj, frame, indirectCallData);
try {
checkSelectable(inliningTarget, raiseNode, socket);
@@ -870,7 +870,7 @@ static Object sendAll(VirtualFrame frame, PSocket socket, Object bufferObj, int
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireReadonly(bufferObj, frame, indirectCallData);
try {
checkSelectable(inliningTarget, raiseNode, socket);
@@ -933,7 +933,7 @@ static Object sendTo(VirtualFrame frame, PSocket socket, Object bufferObj, Objec
@Cached SysModuleBuiltins.AuditNode auditNode,
@Cached GilNode gil,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int flags;
Object address;
if (hasFlagsProfile.profile(inliningTarget, maybeAddress == PNone.NO_VALUE)) {
@@ -1138,11 +1138,11 @@ static Object setNull(VirtualFrame frame, PSocket socket, int level, int option,
@Bind("this") Node inliningTarget,
@Exclusive @Cached PyLongAsIntNode asIntNode,
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int buflen = asIntNode.execute(frame, inliningTarget, buflenObj);
if (buflen < 0) {
// GraalPython-specific because we don't have unsigned integers
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.SETSECKOPT_BUFF_OUT_OFRANGE);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.SETSECKOPT_BUFF_OUT_OFRANGE);
}
try {
posixLib.setsockopt(context.getPosixSupport(), socket.getFd(), level, option, null, buflen);
@@ -1155,8 +1155,8 @@ static Object setNull(VirtualFrame frame, PSocket socket, int level, int option,
@Fallback
@SuppressWarnings("unused")
static Object error(Object self, Object level, Object option, Object flag1, Object flag2,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.SETSECKOPT_REQUIRERS_3RD_ARG_NULL);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.SETSECKOPT_REQUIRERS_3RD_ARG_NULL);
}
@Override
@@ -1177,7 +1177,7 @@ static Object getSockOpt(VirtualFrame frame, PSocket socket, int level, int opti
@Bind PythonContext context,
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (buflen == 0) {
byte[] result = new byte[4];
@@ -1188,7 +1188,7 @@ static Object getSockOpt(VirtualFrame frame, PSocket socket, int level, int opti
int len = posixLib.getsockopt(context.getPosixSupport(), socket.getFd(), level, option, result, result.length);
return PFactory.createBytes(context.getLanguage(inliningTarget), result, len);
} else {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.GETSECKOPT_BUFF_OUT_OFRANGE);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.GETSECKOPT_BUFF_OUT_OFRANGE);
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
index e6aad3fbcc..3bd1e0eac4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java
@@ -133,14 +133,14 @@ static UniversalSockAddr doInet(VirtualFrame frame, @SuppressWarnings("unused")
@Cached @Shared("idnaConverter") IdnaFromStringOrBytesConverterNode idnaConverter,
@Cached @Shared("errorProfile") IsBuiltinObjectProfile errorProfile,
@Cached @Shared("setIpAddr") SetIpAddrNode setIpAddrNode,
- @Cached @Shared PRaiseNode.Lazy raiseNode) {
+ @Cached @Shared PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
if (!(address instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_AF_INET_VALUES_MUST_BE_TUPLE_NOT_P, caller, address);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_AF_INET_VALUES_MUST_BE_TUPLE_NOT_P, caller, address);
}
Object[] hostAndPort = getObjectArrayNode.execute(inliningTarget, address);
if (hostAndPort.length != 2) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.AF_INET_VALUES_MUST_BE_PAIR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.AF_INET_VALUES_MUST_BE_PAIR);
}
byte[] host = idnaConverter.execute(frame, hostAndPort[0]);
int port = parsePort(frame, caller, asIntNode, inliningTarget, errorProfile, hostAndPort[1], raiseNode);
@@ -159,14 +159,14 @@ static UniversalSockAddr doInet6(VirtualFrame frame, @SuppressWarnings("unused")
@Cached @Shared("idnaConverter") IdnaFromStringOrBytesConverterNode idnaConverter,
@Cached @Shared("errorProfile") IsBuiltinObjectProfile errorProfile,
@Cached @Shared("setIpAddr") SetIpAddrNode setIpAddrNode,
- @Cached @Shared PRaiseNode.Lazy raiseNode) {
+ @Cached @Shared PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
if (!(address instanceof PTuple)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_AF_INET_VALUES_MUST_BE_TUPLE_NOT_S, caller, address);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_AF_INET_VALUES_MUST_BE_TUPLE_NOT_S, caller, address);
}
Object[] hostAndPort = getObjectArrayNode.execute(inliningTarget, address);
if (hostAndPort.length < 2 || hostAndPort.length > 4) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.AF_INET6_ADDR_MUST_BE_TUPLE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.AF_INET6_ADDR_MUST_BE_TUPLE);
}
byte[] host = idnaConverter.execute(frame, hostAndPort[0]);
int port = parsePort(frame, caller, asIntNode, inliningTarget, errorProfile, hostAndPort[1], raiseNode);
@@ -174,7 +174,7 @@ static UniversalSockAddr doInet6(VirtualFrame frame, @SuppressWarnings("unused")
if (hostAndPort.length > 2) {
flowinfo = asIntNode.execute(frame, inliningTarget, hostAndPort[2]);
if (flowinfo < 0 || flowinfo > 0xfffff) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_FLOWINFO_RANGE, caller);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_FLOWINFO_RANGE, caller);
}
}
int scopeid = 0;
@@ -197,7 +197,7 @@ static UniversalSockAddr doUnix(VirtualFrame frame, @SuppressWarnings("unused")
@CachedLibrary(limit = "1") PythonBufferAcquireLibrary bufferAcquireLib,
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@CachedLibrary(limit = "1") @Shared("posixLib") PosixSupportLibrary posixLib,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
byte[] path;
if (unicodeCheckNode.execute(inliningTarget, address)) {
// PyUnicode_EncodeFSDefault
@@ -220,17 +220,17 @@ static UniversalSockAddr doUnix(VirtualFrame frame, @SuppressWarnings("unused")
try {
return posixLib.createUniversalSockAddrUnix(posixSupport, new UnixSockAddr(path));
} catch (UnsupportedPosixFeatureException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.AF_UNIX_NOT_SUPPORTED, caller);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.AF_UNIX_NOT_SUPPORTED, caller);
} catch (InvalidUnixSocketPathException e) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.AF_UNIX_PATH_TOO_LONG, caller);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.AF_UNIX_PATH_TOO_LONG, caller);
}
}
@Specialization(guards = {"!isInet(socket)", "!isInet6(socket)", "!isUnix(socket)"})
@SuppressWarnings("unused")
static UniversalSockAddr getSockAddr(VirtualFrame frame, PSocket socket, Object address, String caller,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(OSError, ErrorMessages.BAD_FAMILY, caller);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, OSError, ErrorMessages.BAD_FAMILY, caller);
}
static boolean isInet(PSocket socket) {
@@ -246,7 +246,7 @@ static boolean isUnix(PSocket socket) {
}
private static int parsePort(VirtualFrame frame, String caller, PyLongAsIntNode asIntNode, Node inliningTarget, IsBuiltinObjectProfile errorProfile, Object portObj,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
int port;
try {
port = asIntNode.execute(frame, inliningTarget, portObj);
@@ -255,7 +255,7 @@ private static int parsePort(VirtualFrame frame, String caller, PyLongAsIntNode
port = -1;
}
if (port < 0 || port > 0xffff) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.S_PORT_RANGE, caller);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.S_PORT_RANGE, caller);
}
return port;
}
@@ -280,7 +280,7 @@ static UniversalSockAddr setipaddr(VirtualFrame frame, byte[] name, int family,
@Cached InetPtoNCachedPNode inetPtoNCachedPNode,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
PythonContext context = PythonContext.get(inliningTarget);
Object posixSupport = context.getPosixSupport();
try {
@@ -292,7 +292,7 @@ static UniversalSockAddr setipaddr(VirtualFrame frame, byte[] name, int family,
family, SOCK_DGRAM.value, 0, AI_PASSIVE.value);
try {
if (addrInfoLib.next(cursor)) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.WILD_CARD_RESOLVED_TO_MULTIPLE_ADDRESS);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.WILD_CARD_RESOLVED_TO_MULTIPLE_ADDRESS);
}
return addrInfoLib.getSockAddr(cursor);
} finally {
@@ -305,7 +305,7 @@ static UniversalSockAddr setipaddr(VirtualFrame frame, byte[] name, int family,
/* special-case broadcast - inet_addr() below can return INADDR_NONE for this */
if (Arrays.equals(name, BROADCAST_IP) || Arrays.equals(name, BROADCAST)) {
if (family != AF_INET.value && family != AF_UNSPEC.value) {
- throw raiseNode.get(inliningTarget).raise(OSError, ErrorMessages.ADDRESS_FAMILY_MISMATCHED);
+ throw raiseNode.raise(inliningTarget, OSError, ErrorMessages.ADDRESS_FAMILY_MISMATCHED);
}
return posixLib.createUniversalSockAddrInet4(posixSupport, new Inet4SockAddr(0, INADDR_BROADCAST.value));
}
@@ -399,7 +399,7 @@ static Object makeSockAddr(VirtualFrame frame, Node inliningTarget, UniversalSoc
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
@Cached(inline = false) TruffleString.FromByteArrayNode fromByteArrayNode,
@Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PythonContext context = PythonContext.get(inliningTarget);
PythonLanguage language = context.getLanguage(inliningTarget);
@@ -426,7 +426,7 @@ static Object makeSockAddr(VirtualFrame frame, Node inliningTarget, UniversalSoc
// Can be returned from recvfrom when used on a connected socket
return PNone.NONE;
} else {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
+ throw raiseNode.raise(inliningTarget, NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING));
@@ -458,7 +458,7 @@ static Object makeAddr(VirtualFrame frame, Node inliningTarget, UniversalSockAdd
@CachedLibrary("addr") UniversalSockAddrLibrary addrLib,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
PythonContext context = PythonContext.get(inliningTarget);
int family = addrLib.getFamily(addr);
@@ -471,7 +471,7 @@ static Object makeAddr(VirtualFrame frame, Node inliningTarget, UniversalSockAdd
Object posixSupport = context.getPosixSupport();
return posixLib.getPathAsString(posixSupport, posixLib.inet_ntop(posixSupport, family, inet6SockAddr.getAddress()));
} else {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
+ throw raiseNode.raise(inliningTarget, NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING));
@@ -501,7 +501,7 @@ byte[] convert(VirtualFrame frame, Object value,
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode,
@Cached CodecsModuleBuiltins.EncodeNode encodeNode,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
Object bytes;
if (unicodeCheckNode.execute(inliningTarget, value)) {
TruffleString string = castToString.execute(inliningTarget, value);
@@ -518,9 +518,9 @@ byte[] convert(VirtualFrame frame, Object value,
bytes = value;
} else {
if (builtinName != null) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_BYTELIKE_OR_BYTEARRAY, builtinName, argumentIndex, value);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_BYTELIKE_OR_BYTEARRAY, builtinName, argumentIndex, value);
} else {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.STR_BYTES_OR_BYTEARRAY_EXPECTED, value);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.STR_BYTES_OR_BYTEARRAY_EXPECTED, value);
}
}
return bufferLib.getCopiedByteArray(bytes);
@@ -554,10 +554,10 @@ static long parse(@SuppressWarnings("unused") PNone none) {
@Specialization(guards = "!isNone(seconds)")
static long parse(VirtualFrame frame, Node inliningTarget, Object seconds,
@Cached PyTimeFromObjectNode timeFromObjectNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
long timeout = timeFromObjectNode.execute(frame, inliningTarget, seconds, RoundType.TIMEOUT, TimeUtils.SEC_TO_NS);
if (timeout < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TIMEOUT_VALUE_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TIMEOUT_VALUE_OUT_OF_RANGE);
}
return timeout;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
index 969e572c33..bb02505f09 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/MemoryBIOBuiltins.java
@@ -136,7 +136,7 @@ static int write(VirtualFrame frame, PMemoryBIO self, Object buffer,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (self.didWriteEOF()) {
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSL_CANNOT_WRITE_AFTER_EOF);
@@ -147,7 +147,7 @@ static int write(VirtualFrame frame, PMemoryBIO self, Object buffer,
self.write(bytes, len);
return len;
} catch (OverflowException | OutOfMemoryError e) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
} finally {
bufferLib.release(buffer, frame, indirectCallData);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLCipherSelector.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLCipherSelector.java
index b69faff792..7ef0a4df79 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLCipherSelector.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLCipherSelector.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -111,7 +111,7 @@ private static void selectSingle(Node node, String cipherString, List
if (cipherString.startsWith("@STRENGTH")) {
selected.sort(Comparator.comparingInt(SSLCipher::getStrengthBits).reversed());
} else if (cipherString.startsWith("@SECLEVEL=")) {
- throw PRaiseNode.raiseUncached(node, NotImplementedError, toTruffleStringUncached("@SECLEVEL not implemented"));
+ throw PRaiseNode.raiseStatic(node, NotImplementedError, toTruffleStringUncached("@SECLEVEL not implemented"));
} else {
throw PConstructAndRaiseNode.raiseUncachedSSLError(ErrorMessages.NO_CIPHER_CAN_BE_SELECTED);
}
@@ -133,7 +133,7 @@ private static List getCiphersForCipherString(Node node, String ciphe
List ciphers = SSLCipherStringMapping.get(component);
if (ciphers == null) {
if (component.equals("PROFILE=SYSTEM")) {
- throw PRaiseNode.raiseUncached(node, NotImplementedError, toTruffleStringUncached("PROFILE=SYSTEM not implemented"));
+ throw PRaiseNode.raiseStatic(node, NotImplementedError, toTruffleStringUncached("PROFILE=SYSTEM not implemented"));
}
return Collections.emptyList();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
index 786ec73cf6..86d8a854e1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
@@ -170,10 +170,10 @@ static PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SSLMethod method = SSLMethod.fromPythonId(protocol);
if (method == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, "NULL");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, "NULL");
}
try {
boolean checkHostname;
@@ -194,7 +194,7 @@ static PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
context.setOptions(options);
return context;
} catch (NoSuchAlgorithmException e) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, e);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, e);
} catch (KeyManagementException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, e);
}
@@ -231,9 +231,9 @@ static SSLEngine createSSLEngine(Node raisingNode, PSSLContext context, boolean
parameters.setServerNames(Collections.singletonList(new SNIHostName(serverHostname)));
} catch (IllegalArgumentException e) {
if (serverHostname.contains("\0")) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.ARG_MUST_BE_ENCODED_NON_NULL);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.ARG_MUST_BE_ENCODED_NON_NULL);
}
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.INVALID_HOSTNAME);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.INVALID_HOSTNAME);
}
if (context.getCheckHostname()) {
parameters.setEndpointIdentificationAlgorithm("HTTPS");
@@ -307,8 +307,8 @@ static Object wrap(PSSLContext context, PSocket sock, boolean serverSide, Object
@Fallback
@SuppressWarnings("unused")
static Object wrap(Object context, Object sock, Object serverSide, Object serverHostname, Object owner, Object session,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.INVALID_WRAP_SOCKET_CALL);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INVALID_WRAP_SOCKET_CALL);
}
@Override
@@ -344,8 +344,8 @@ static Object wrap(PSSLContext context, PMemoryBIO incoming, PMemoryBIO outgoing
@Fallback
@SuppressWarnings("unused")
static Object wrap(Object context, Object incoming, Object outgoing, Object serverSide, Object serverHostname, Object owner, Object session,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.INVALID_WRAP_BIO_CALL);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INVALID_WRAP_BIO_CALL);
}
@Override
@@ -433,10 +433,10 @@ static int get(PSSLContext self, @SuppressWarnings("unused") PNone value) {
static Object set(VirtualFrame frame, PSSLContext self, Object value,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int mode = asSizeNode.executeLossy(frame, inliningTarget, value);
if (mode == SSLModuleBuiltins.SSL_CERT_NONE && self.getCheckHostname()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CANNOT_SET_VERIFY_MODE_TO_CERT_NONE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_SET_VERIFY_MODE_TO_CERT_NONE);
}
switch (mode) {
case SSLModuleBuiltins.SSL_CERT_NONE:
@@ -445,14 +445,14 @@ static Object set(VirtualFrame frame, PSSLContext self, Object value,
self.setVerifyMode(mode);
return PNone.NONE;
default:
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.INVALID_VALUE_FOR_VERIFY_MODE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.INVALID_VALUE_FOR_VERIFY_MODE);
}
}
}
- private static void setMinMaxVersion(Node inliningTarget, PRaiseNode.Lazy raiseNode, PSSLContext context, boolean maximum, int value) {
+ private static void setMinMaxVersion(Node inliningTarget, PRaiseNode raiseNode, PSSLContext context, boolean maximum, int value) {
if (context.getMethod().isSingleVersion()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.CONTEXT_DOESNT_SUPPORT_MIN_MAX);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CONTEXT_DOESNT_SUPPORT_MIN_MAX);
}
SSLProtocol selected = null;
switch (value) {
@@ -470,7 +470,7 @@ private static void setMinMaxVersion(Node inliningTarget, PRaiseNode.Lazy raiseN
}
}
if (selected == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNSUPPORTED_PROTOCOL_VERSION, value);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNSUPPORTED_PROTOCOL_VERSION, value);
}
}
if (maximum) {
@@ -492,7 +492,7 @@ static int get(PSSLContext self, @SuppressWarnings("unused") Object none) {
static Object set(VirtualFrame frame, PSSLContext self, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
setMinMaxVersion(inliningTarget, raiseNode, self, false, asSizeNode.executeExact(frame, inliningTarget, obj));
return PNone.NONE;
}
@@ -510,7 +510,7 @@ static int get(PSSLContext self, @SuppressWarnings("unused") Object none) {
static Object set(VirtualFrame frame, PSSLContext self, Object obj,
@Bind("this") Node inliningTarget,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
setMinMaxVersion(inliningTarget, raiseNode, self, true, asSizeNode.executeExact(frame, inliningTarget, obj));
return PNone.NONE;
}
@@ -556,17 +556,17 @@ abstract static class NumTicketsNode extends PythonBinaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization(guards = "isNoValue(value)")
static int get(PSSLContext self, PNone value,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// not used yet so rather raise error
- throw raiseNode.raise(NotImplementedError);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
@SuppressWarnings("unused")
@Specialization(guards = "!isNoValue(value)")
static Object set(VirtualFrame frame, PSSLContext self, Object value,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// not used yet so rather raise error
- throw raiseNode.raise(NotImplementedError);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
// int num;
// try {
// num = (int) castToLong.execute(lib.asIndexWithFrame(value, frame));
@@ -589,8 +589,8 @@ static Object set(VirtualFrame frame, PSSLContext self, Object value,
abstract static class SNICallbackNode extends PythonBinaryBuiltinNode {
@Specialization
static Object notImplemented(@SuppressWarnings("unused") PSSLContext self, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -723,15 +723,15 @@ Object load(VirtualFrame frame, PSSLContext self, Object cafile, Object capath,
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached TruffleString.EqualNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (cafile instanceof PNone && capath instanceof PNone && cadata instanceof PNone) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CA_FILE_PATH_DATA_CANNOT_BE_ALL_OMMITED);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CA_FILE_PATH_DATA_CANNOT_BE_ALL_OMMITED);
}
if (!(cafile instanceof PNone) && !PGuards.isString(cafile) && !PGuards.isBytes(cafile)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "cafile");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "cafile");
}
if (!(capath instanceof PNone) && !PGuards.isString(capath) && !PGuards.isBytes(capath)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "capath");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "capath");
}
final TruffleFile file;
if (!(cafile instanceof PNone)) {
@@ -758,7 +758,7 @@ Object load(VirtualFrame frame, PSSLContext self, Object cafile, Object capath,
if (cadata instanceof PBytesLike) {
certificates = fromBytesLike(toBytes.execute(inliningTarget, ((PBytesLike) cadata).getSequenceStorage()));
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_ASCII_OR_BYTELIKE, "cadata");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_ASCII_OR_BYTELIKE, "cadata");
}
}
self.setCAEntries(certificates);
@@ -790,10 +790,10 @@ private TruffleFile toTruffleFile(VirtualFrame frame, Node inliningTarget, PyUni
}
}
- private static List fromString(Node inliningTarget, String dataString, PRaiseNode.Lazy raiseNode)
+ private static List fromString(Node inliningTarget, String dataString, PRaiseNode raiseNode)
throws IOException, CertificateException, CRLException {
if (dataString.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_CERTIFICATE_DATA);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_CERTIFICATE_DATA);
}
return getCertificates(dataString);
}
@@ -845,12 +845,12 @@ Object load(VirtualFrame frame, PSSLContext self, Object certfile, Object keyfil
@Cached GetPasswordNode getPasswordNode,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached TruffleString.EqualNode eqNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!PGuards.isString(certfile) && !PGuards.isBytes(certfile)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "certfile");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "certfile");
}
if (!(keyfile instanceof PNone) && !PGuards.isString(keyfile) && !PGuards.isBytes(keyfile)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "keyfile");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, "keyfile");
}
Object kf = keyfile instanceof PNone ? certfile : keyfile;
TruffleFile certTruffleFile = toTruffleFile(frame, inliningTarget, asPath.execute(frame, certfile), toJavaStringNode, eqNode, constructAndRaiseNode);
@@ -867,7 +867,7 @@ Object load(VirtualFrame frame, PSSLContext self, Object certfile, Object keyfil
throw CompilerDirectives.shouldNotReachHere();
}
}
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, ErrorMessages.PASSWORD_NOT_IMPLEMENTED);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, ErrorMessages.PASSWORD_NOT_IMPLEMENTED);
}
} catch (IOException ex) {
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
@@ -888,7 +888,7 @@ private BufferedReader getReader(TruffleFile file, String arg) throws IOExceptio
LOGGER.fine(() -> String.format("load_cert_chain %s:%s", arg, file.getPath()));
return file.newBufferedReader();
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, arg);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.S_SHOULD_BE_A_VALID_FILESYSTEMPATH, arg);
}
}
@@ -937,20 +937,22 @@ abstract static class GetPasswordNode extends PNodeWithContext {
@Specialization(guards = "isString(password)")
static char[] doString(Object password,
+ @Bind("this") Node inliningTarget,
@Cached CastToJavaStringNode cast,
@Shared @Cached PRaiseNode raiseNode) {
String str = cast.execute(password);
- checkPasswordLength(raiseNode, str.length());
+ checkPasswordLength(raiseNode, str.length(), inliningTarget);
return stringToChars(str);
}
@Specialization(limit = "2")
static char[] doBytes(PBytesLike bytes,
+ @Bind("this") Node inliningTarget,
@CachedLibrary("bytes") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PRaiseNode raiseNode) {
byte[] data = bufferLib.getInternalOrCopiedByteArray(bytes);
int length = bufferLib.getBufferLength(bytes);
- checkPasswordLength(raiseNode, length);
+ checkPasswordLength(raiseNode, length, inliningTarget);
char[] res = new char[length];
for (int i = 0; i < res.length; i++) {
res[i] = (char) data[i];
@@ -970,9 +972,9 @@ static char[] doCallable(VirtualFrame frame, Object callable,
if (PGuards.isString(result) || result instanceof PBytesLike) {
return recursive.execute(frame, result);
}
- throw raiseNode.raise(TypeError, ErrorMessages.PSSWD_CALLBACK_MUST_RETURN_STR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.PSSWD_CALLBACK_MUST_RETURN_STR);
}
- throw raiseNode.raise(TypeError, ErrorMessages.PSSWD_SHOULD_BE_STR_OR_CALLABLE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.PSSWD_SHOULD_BE_STR_OR_CALLABLE);
}
@TruffleBoundary
@@ -980,9 +982,9 @@ private static char[] stringToChars(String str) {
return str.toCharArray();
}
- private static void checkPasswordLength(PRaiseNode raiseNode, int length) {
+ private static void checkPasswordLength(PRaiseNode raiseNode, int length, Node inliningTarget) {
if (length > MAX_LEN) {
- throw raiseNode.raise(ValueError, ErrorMessages.PSSWD_CANNOT_BE_LONGER_THAN_D_BYTES, MAX_LEN);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.PSSWD_CANNOT_BE_LONGER_THAN_D_BYTES, MAX_LEN);
}
}
}
@@ -993,11 +995,11 @@ abstract static class LoadDhParamsNode extends PythonBinaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
static PNone load(VirtualFrame frame, PSSLContext self, Object pathObject,
- @Cached PyUnicodeFSDecoderNode asPath,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget,
+ @Cached PyUnicodeFSDecoderNode asPath) {
TruffleString path = asPath.execute(frame, pathObject);
// not used yet so rather raise error
- throw raiseNode.raise(NotImplementedError);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
// File file = new File(path);
// if (!file.exists()) {
// throw raiseOSError(frame, OSErrorEnum.ENOENT);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java
index fc04f6d46f..8dc68a63fb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -177,7 +177,7 @@ static void doSocket(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
@Cached(inline = false) GilNode gil,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
@Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
assert socket.getSocket() != null;
prepare(socket);
TimeoutHelper timeoutHelper = null;
@@ -270,7 +270,7 @@ static void doSocket(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
} catch (SSLException e) {
throw handleSSLException(e);
} catch (OverflowException | OutOfMemoryError node) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
PythonContext.triggerAsyncActions(inliningTarget);
}
@@ -279,7 +279,7 @@ static void doSocket(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
@Specialization(guards = "socket.getSocket() == null")
static void doMemory(VirtualFrame frame, Node inliningTarget, PSSLSocket socket, ByteBuffer appInput, ByteBuffer targetBuffer, SSLOperation operation,
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
prepare(socket);
SSLOperationStatus status;
try {
@@ -312,7 +312,7 @@ static void doMemory(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
} catch (SSLException e) {
throw handleSSLException(e);
} catch (OverflowException | OutOfMemoryError node) {
- throw raiseNode.get(inliningTarget).raise(MemoryError);
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
index 8854f325f5..1e25fb80b3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java
@@ -106,11 +106,11 @@ static Object read(VirtualFrame frame, PSSLSocket self, int len, @SuppressWarnin
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
@Shared @Cached SSLOperationNode sslOperationNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (len == 0) {
return PFactory.createBytes(language, new byte[0]);
} else if (len < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SIZE_SHOULD_NOT_BE_NEGATIVE);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SIZE_SHOULD_NOT_BE_NEGATIVE);
}
ByteBuffer output = PythonUtils.allocateByteBuffer(len);
sslOperationNode.read(frame, inliningTarget, self, output);
@@ -126,7 +126,7 @@ static Object readInto(VirtualFrame frame, PSSLSocket self, int len, Object buff
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
@Shared @Cached SSLOperationNode sslOperationNode,
// unused node to avoid mixing shared and non-shared inlined nodes
- @SuppressWarnings("unused") @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @SuppressWarnings("unused") @Shared @Cached PRaiseNode raiseNode) {
Object buffer = bufferAcquireLib.acquireWritableWithTypeError(bufferObj, "read", frame, indirectCallData);
try {
int bufferLen = bufferLib.getBufferLength(buffer);
@@ -294,9 +294,9 @@ static Object get(@SuppressWarnings("unused") PSSLSocket self, @SuppressWarnings
@Specialization(guards = "!isNoValue(obj)")
static Object set(@SuppressWarnings("unused") PSSLSocket self, @SuppressWarnings("unused") Object obj,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// JDK API doesn't support setting session ID
- throw raiseNode.raise(NotImplementedError);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError);
}
}
@@ -317,9 +317,9 @@ abstract static class GetPeerCertNode extends PythonBinaryClinicBuiltinNode {
static Object getPeerCertDER(PSSLSocket self, @SuppressWarnings("unused") boolean der,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (!self.isHandshakeComplete()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
}
Certificate certificate = getCertificate(self.getEngine());
if (certificate != null) {
@@ -338,9 +338,9 @@ static Object getPeerCertDER(PSSLSocket self, @SuppressWarnings("unused") boolea
static PDict getPeerCertDict(PSSLSocket self, @SuppressWarnings("unused") boolean der,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (!self.isHandshakeComplete()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.HANDSHAKE_NOT_DONE_YET);
}
Certificate certificate = getCertificate(self.getEngine());
if (certificate instanceof X509Certificate) {
@@ -387,9 +387,9 @@ abstract static class GetChannelBinding extends PythonBinaryClinicBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object getChannelBinding(PSSLSocket self, TruffleString sbType,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
// JDK doesn't have an API to access what we need. BouncyCastle could provide this
- throw raiseNode.raise(ValueError, ErrorMessages.S_CHANNEL_BINDING_NOT_IMPLEMENTED, sbType);
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.S_CHANNEL_BINDING_NOT_IMPLEMENTED, sbType);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
index effbd08d93..a525f5a831 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
@@ -245,7 +245,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
static TruffleString format(Object self, TruffleString formatString,
@Bind("this") Node inliningTarget,
@Cached CastToJavaStringCheckedNode castToJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// We cannot cast self via argument clinic, because we need to keep it as-is for the
// empty format string case, which should call __str__, which may be overridden
String str = castToJavaStringNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___STR__, self);
@@ -259,23 +259,23 @@ private static TruffleString formatString(Node raisingNode, Spec spec, String st
return formatter.pad().getResult();
}
- private static Spec getAndValidateSpec(Node inliningTarget, TruffleString formatString, PRaiseNode.Lazy raiseNode) {
+ private static Spec getAndValidateSpec(Node inliningTarget, TruffleString formatString, PRaiseNode raiseNode) {
Spec spec = InternalFormat.fromText(formatString, 's', '<', inliningTarget);
if (Spec.specified(spec.type) && spec.type != 's') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNKNOWN_FORMAT_CODE, spec.type, "str");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNKNOWN_FORMAT_CODE, spec.type, "str");
}
if (Spec.specified(spec.sign)) {
if (spec.sign == ' ') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SPACE_NOT_ALLOWED_IN_STRING_FORMAT_SPECIFIER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SPACE_NOT_ALLOWED_IN_STRING_FORMAT_SPECIFIER);
} else {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SIGN_NOT_ALLOWED_FOR_STRING_FMT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SIGN_NOT_ALLOWED_FOR_STRING_FMT);
}
}
if (spec.alternate) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.ALTERNATE_NOT_ALLOWED_WITH_STRING_FMT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.ALTERNATE_NOT_ALLOWED_WITH_STRING_FMT);
}
if (Spec.specified(spec.align) && spec.align == '=') {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EQUALS_ALIGNMENT_FLAG_NOT_ALLOWED_FOR_STRING_FMT);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EQUALS_ALIGNMENT_FLAG_NOT_ALLOWED_FOR_STRING_FMT);
}
return spec;
}
@@ -296,7 +296,7 @@ static TruffleString format(VirtualFrame frame, Object self, Object[] args, PKey
try {
string = castToStringNode.execute(inliningTarget, self);
} catch (CannotCastException e) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T_FORMAT, "str", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T_FORMAT, "str", self);
}
TemplateFormatter template = new TemplateFormatter(string);
PythonContext context = PythonContext.get(inliningTarget);
@@ -561,18 +561,18 @@ static TruffleString doSS(Object self, Object other,
@Cached CastToTruffleStringNode castToStringLeftNode,
@Cached CastToTruffleStringNode castToStringRightNode,
@Shared @Cached TruffleString.ConcatNode concatNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString left;
TruffleString right;
try {
left = castToStringLeftNode.execute(inliningTarget, self);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___ADD__, "str", self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___ADD__, "str", self);
}
try {
right = castToStringRightNode.execute(inliningTarget, other);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "str", other, "str");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "str", other, "str");
}
return doIt(left, right, concatNode);
}
@@ -956,7 +956,7 @@ static PDict doString(VirtualFrame frame, Object cls, Object from, Object to, Ob
@Cached TruffleStringIterator.NextNode nextNode,
@Cached InlinedConditionProfile hasZProfile,
@Exclusive @Cached HashingStorageSetItem setHashingStorageItem,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TruffleString toStr = castToNode.cast(inliningTarget, to, ErrorMessages.ARG_S_MUST_BE_S_NOT_P, "2", "str", to);
TruffleString fromStr = castFromNode.cast(inliningTarget, from, ErrorMessages.FIRST_MAKETRANS_ARGS_MUST_BE_A_STR);
@@ -968,7 +968,7 @@ static PDict doString(VirtualFrame frame, Object cls, Object from, Object to, Ob
int toLen = codePointLengthNode.execute(toStr, TS_ENCODING);
int fromLen = codePointLengthNode.execute(fromStr, TS_ENCODING);
if (toLen != fromLen) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.FIRST_TWO_MAKETRANS_ARGS_MUST_HAVE_EQ_LENGTH);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.FIRST_TWO_MAKETRANS_ARGS_MUST_HAVE_EQ_LENGTH);
}
HashingStorage storage = PDict.createNewStorage(fromLen);
TruffleStringIterator fromIt = createCodePointIteratorNode.execute(fromStr, TS_ENCODING);
@@ -1003,7 +1003,7 @@ static PDict doDict(VirtualFrame frame, Object cls, PDict from, Object to, Objec
@Cached HashingStorageIteratorNext iterHasNext,
@Cached HashingStorageIteratorKey iterKey,
@Cached HashingStorageIteratorValue iterValue,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
HashingStorage srcStorage = from.getDictStorage();
HashingStorage destStorage = PDict.createNewStorage(lenNode.execute(inliningTarget, srcStorage));
HashingStorageIterator it = getIter.execute(inliningTarget, srcStorage);
@@ -1015,7 +1015,7 @@ static PDict doDict(VirtualFrame frame, Object cls, PDict from, Object to, Objec
} else {
TruffleString strKey = cast.cast(inliningTarget, currentKey, ErrorMessages.KEYS_IN_TRANSLATE_TABLE_MUST_BE_STRINGS_OR_INTEGERS);
if (codePointLengthNode.execute(strKey, TS_ENCODING) != 1) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.STRING_KEYS_MUST_BE_LENGTH_1);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.STRING_KEYS_MUST_BE_LENGTH_1);
}
int codePoint = codePointAtIndexNode.execute(strKey, 0, TS_ENCODING);
destStorage = setHashingStorageItem.execute(frame, inliningTarget, destStorage, codePoint, currentValue);
@@ -1027,8 +1027,8 @@ static PDict doDict(VirtualFrame frame, Object cls, PDict from, Object to, Objec
@Specialization(guards = {"!isDict(from)", "isNoValue(to)"})
@SuppressWarnings("unused")
static PDict doFail(Object cls, Object from, Object to, Object z,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.IF_YOU_GIVE_ONLY_ONE_ARG_TO_DICT);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.IF_YOU_GIVE_ONLY_ONE_ARG_TO_DICT);
}
}
@@ -1150,11 +1150,11 @@ static PTuple doGeneric(Object self, Object sep,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
@Cached TruffleString.SubstringNode substringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString selfStr = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "partition", self);
TruffleString sepStr = castSepNode.cast(inliningTarget, sep, ErrorMessages.MUST_BE_STR_NOT_P, sep);
if (sepStr.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
int selfLen = codePointLengthNode.execute(selfStr, TS_ENCODING);
int indexOf = indexOfStringNode.execute(selfStr, sepStr, 0, selfLen, TS_ENCODING);
@@ -1186,11 +1186,11 @@ static Object doGeneric(Object self, Object sep,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.LastIndexOfStringNode lastIndexOfStringNode,
@Cached TruffleString.SubstringNode substringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString selfStr = castSelfNode.cast(inliningTarget, self, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "rpartition", self);
TruffleString sepStr = castSepNode.cast(inliningTarget, sep, ErrorMessages.MUST_BE_STR_NOT_P, sep);
if (sepStr.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
int selfLen = codePointLengthNode.execute(selfStr, TS_ENCODING);
int lastIndexOf = lastIndexOfStringNode.execute(selfStr, sepStr, selfLen, 0, TS_ENCODING);
@@ -1239,9 +1239,9 @@ static PList doStringSep(TruffleString self, TruffleString sep, int maxsplit,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
@Shared("substring") @Cached TruffleString.SubstringNode substringNode,
@Shared("appendNode") @Cached AppendNode appendNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (sep.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
int splits = maxsplit == -1 ? Integer.MAX_VALUE : maxsplit;
@@ -1344,9 +1344,9 @@ static PList doStringSepMaxsplit(VirtualFrame frame, TruffleString self, Truffle
@Shared("cpLen") @Cached CodePointLengthNode codePointLengthNode,
@Cached TruffleString.LastIndexOfStringNode lastIndexOfStringNode,
@Shared @Cached TruffleString.SubstringNode substringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (sep.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.EMPTY_SEPARATOR);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EMPTY_SEPARATOR);
}
int maxsplit = maxsplitInput;
if (maxsplitInput < 0) {
@@ -1712,13 +1712,13 @@ static int index(Object selfObj, Object subObj, int start, int end,
@Cached CastToTruffleStringCheckedNode castNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfStringNode indexOfStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString self = castNode.cast(inliningTarget, selfObj, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "index", selfObj);
TruffleString sub = castNode.cast(inliningTarget, subObj, ErrorMessages.MUST_BE_STR_NOT_P, subObj);
int idx = indexOf(self, sub, start, end, codePointLengthNode, indexOfStringNode);
if (idx < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SUBSTRING_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SUBSTRING_NOT_FOUND);
}
return idx;
}
@@ -1740,12 +1740,12 @@ static int rindex(Object selfObj, Object subObj, int start, int end,
@Cached CastToTruffleStringCheckedNode castNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.LastIndexOfStringNode lastIndexOfStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString self = castNode.cast(inliningTarget, selfObj, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "rindex", selfObj);
TruffleString sub = castNode.cast(inliningTarget, subObj, ErrorMessages.MUST_BE_STR_NOT_P, subObj);
int idx = lastIndexOf(self, sub, start, end, codePointLengthNode, lastIndexOfStringNode);
if (idx < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.SUBSTRING_NOT_FOUND);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.SUBSTRING_NOT_FOUND);
}
return idx;
}
@@ -1778,7 +1778,7 @@ static Object doIt(VirtualFrame frame, Object selfObj, TruffleString encoding, T
@Cached CodecsModuleBuiltins.EncodeNode encodeNode,
@Cached SequenceStorageNodes.CopyNode copyNode,
@Cached InlinedBranchProfile convertByteArray,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString self = castSelfNode.cast(inliningTarget, selfObj, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, "index", selfObj);
Object result = encodeNode.execute(frame, self, encoding, errors);
if (!(result instanceof PBytes)) {
@@ -1786,7 +1786,7 @@ static Object doIt(VirtualFrame frame, Object selfObj, TruffleString encoding, T
convertByteArray.enter(inliningTarget);
return PFactory.createBytes(PythonLanguage.get(inliningTarget), copyNode.execute(inliningTarget, ((PByteArray) result).getSequenceStorage()));
}
- throw raiseNode.get(inliningTarget).raise(TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, result);
+ throw raiseNode.raise(inliningTarget, TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, result);
}
return result;
}
@@ -2271,7 +2271,7 @@ TruffleString doIt(VirtualFrame frame, Object selfObj, Object width, Object fill
@Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode,
@Cached InlinedConditionProfile errorProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString self = castSelfNode.cast(inliningTarget, selfObj, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___ITER__, selfObj);
int fillChar;
if (PGuards.isNoValue(fill)) {
@@ -2279,7 +2279,7 @@ TruffleString doIt(VirtualFrame frame, Object selfObj, Object width, Object fill
} else {
TruffleString fillStr = castFillNode.cast(inliningTarget, fill, FILL_CHAR_MUST_BE_UNICODE_CHAR_NOT_P, fill);
if (errorProfile.profile(inliningTarget, codePointLengthNode.execute(fillStr, TS_ENCODING) != 1)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.FILL_CHAR_MUST_BE_LENGTH_1);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.FILL_CHAR_MUST_BE_LENGTH_1);
}
fillChar = codePointAtIndexNode.execute(fillStr, 0, TS_ENCODING);
}
@@ -2436,7 +2436,7 @@ static TruffleString doString(VirtualFrame frame, Object self, Object idx,
@Cached PyNumberAsSizeNode asSizeNode,
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.SubstringNode substringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString str = castToString.cast(inliningTarget, self, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T___GETITEM__, "str", self);
int len = codePointLengthNode.execute(str, TS_ENCODING);
int index;
@@ -2444,7 +2444,7 @@ static TruffleString doString(VirtualFrame frame, Object self, Object idx,
index = asSizeNode.executeExact(frame, inliningTarget, idx);
} catch (PException e) {
if (!indexCheckNode.execute(inliningTarget, idx)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.STRING_INDICES_MUST_BE_INTEGERS_NOT_P, idx);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.STRING_INDICES_MUST_BE_INTEGERS_NOT_P, idx);
}
throw e;
}
@@ -2452,7 +2452,7 @@ static TruffleString doString(VirtualFrame frame, Object self, Object idx,
index += len;
}
if (index < 0 || index >= len) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
return substringNode.execute(str, index, 1, TS_ENCODING, false);
}
@@ -2624,11 +2624,11 @@ static long doGeneric(Object self,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode cast,
@Shared("hashCode") @Cached TruffleString.HashCodeNode hashCodeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return doString(cast.execute(inliningTarget, self), hashCodeNode);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___HASH__, self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.REQUIRES_STR_OBJECT_BUT_RECEIVED_P, T___HASH__, self);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
index 0ec5dbffac..a9e71272bf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java
@@ -194,7 +194,7 @@ static int doNativeObject(PythonNativeObject x,
return intValue((Number) result);
}
// the object's type is not a subclass of 'str'
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
}
@Specialization
@@ -232,11 +232,11 @@ static String doConvert(TruffleString self, @SuppressWarnings("unused") TruffleS
@Specialization(guards = "!isTruffleString(self)")
static String doConvert(Node inliningTarget, Object self, TruffleString errMsgFormat, Object[] errMsgArgs,
@Cached(inline = false) CastToJavaStringNode castToJavaStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return castToJavaStringNode.execute(self);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, errMsgFormat, errMsgArgs);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, errMsgFormat, errMsgArgs);
}
}
}
@@ -259,11 +259,11 @@ static TruffleString doTruffleString(TruffleString self, @SuppressWarnings("unus
@Specialization(guards = "!isTruffleString(self)")
static TruffleString doConvert(Node inliningTarget, Object self, TruffleString errMsgFormat, Object[] errMsgArgs,
@Cached CastToTruffleStringNode castToTruffleStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return castToTruffleStringNode.execute(inliningTarget, self);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, errMsgFormat, errMsgArgs);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, errMsgFormat, errMsgArgs);
}
}
}
@@ -306,7 +306,7 @@ static TruffleString doPSequence(TruffleString self, PSequence sequence,
@Cached InlinedConditionProfile isSingleItemProfile,
@Cached SequenceStorageNodes.GetItemNode getItemNode,
@Exclusive @Cached CastToTruffleStringNode castToStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raise,
+ @Exclusive @Cached PRaiseNode raise,
@Shared @Cached TruffleStringBuilder.AppendStringNode appendStringNode,
@Shared @Cached TruffleStringBuilder.ToStringNode toStringNode) {
@@ -337,16 +337,16 @@ static TruffleString doPSequence(TruffleString self, PSequence sequence,
}
return toStringNode.execute(sb);
} catch (OutOfMemoryError e) {
- throw raise.get(inliningTarget).raise(MemoryError);
+ throw raise.raise(inliningTarget, MemoryError);
} catch (CannotCastException e) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, INVALID_SEQ_ITEM, i, item);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, INVALID_SEQ_ITEM, i, item);
}
}
@Specialization
static TruffleString doGeneric(VirtualFrame frame, TruffleString string, Object iterable,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raise,
+ @Exclusive @Cached PRaiseNode raise,
@Cached PyObjectGetIter getIter,
@Cached GetNextNode nextNode,
@Cached IsBuiltinObjectProfile errorProfile0,
@@ -360,7 +360,7 @@ static TruffleString doGeneric(VirtualFrame frame, TruffleString string, Object
iterator = getIter.execute(frame, inliningTarget, iterable);
} catch (PException e) {
e.expect(inliningTarget, PythonBuiltinClassType.TypeError, errorProfile0);
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_JOIN_ITERABLE);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_JOIN_ITERABLE);
}
try {
TruffleStringBuilder sb = TruffleStringBuilder.create(TS_ENCODING);
@@ -383,15 +383,15 @@ static TruffleString doGeneric(VirtualFrame frame, TruffleString string, Object
appendStringNode.execute(sb, checkItem(inliningTarget, value, i++, castToStringNode, raise));
}
} catch (OutOfMemoryError e) {
- throw raise.get(inliningTarget).raise(MemoryError);
+ throw raise.raise(inliningTarget, MemoryError);
}
}
- private static TruffleString checkItem(Node inliningTarget, Object item, int pos, CastToTruffleStringNode castNode, PRaiseNode.Lazy raise) {
+ private static TruffleString checkItem(Node inliningTarget, Object item, int pos, CastToTruffleStringNode castNode, PRaiseNode raise) {
try {
return castNode.execute(inliningTarget, item);
} catch (CannotCastException e) {
- throw raise.get(inliningTarget).raise(TypeError, INVALID_SEQ_ITEM, pos, item);
+ throw raise.raise(inliningTarget, TypeError, INVALID_SEQ_ITEM, pos, item);
}
}
@@ -414,34 +414,37 @@ static void doNone(TruffleStringBuilder sb, PNone none) {
@Specialization
static void doInt(TruffleStringBuilder sb, int translated,
+ @Bind("this") Node inliningTarget,
@Shared("raise") @Cached PRaiseNode raise,
@Shared @Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode) {
if (Character.isValidCodePoint(translated)) {
appendCodePointNode.execute(sb, translated, 1, true);
} else {
- throw raise.raise(ValueError, ErrorMessages.INVALID_UNICODE_CODE_POINT);
+ throw raise.raise(inliningTarget, ValueError, ErrorMessages.INVALID_UNICODE_CODE_POINT);
}
}
@Specialization
static void doLong(TruffleStringBuilder sb, long translated,
+ @Bind("this") Node inliningTarget,
@Shared("raise") @Cached PRaiseNode raise,
@Shared @Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode) {
try {
- doInt(sb, PInt.intValueExact(translated), raise, appendCodePointNode);
+ doInt(sb, PInt.intValueExact(translated), inliningTarget, raise, appendCodePointNode);
} catch (OverflowException e) {
- throw raiseError(raise);
+ throw raiseError(inliningTarget, raise);
}
}
@Specialization
static void doPInt(TruffleStringBuilder sb, PInt translated,
+ @Bind("this") Node inliningTarget,
@Shared("raise") @Cached PRaiseNode raise,
@Shared @Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode) {
try {
- doInt(sb, translated.intValueExact(), raise, appendCodePointNode);
+ doInt(sb, translated.intValueExact(), inliningTarget, raise, appendCodePointNode);
} catch (OverflowException e) {
- throw raiseError(raise);
+ throw raiseError(inliningTarget, raise);
}
}
@@ -462,12 +465,12 @@ static void doObject(TruffleStringBuilder sb, Object translated,
TruffleString translatedStr = castToStringNode.execute(inliningTarget, translated);
doString(sb, translatedStr, appendStringNode);
} catch (CannotCastException e) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_RETURN_INT_NONE_OR_STR);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CHARACTER_MAPPING_MUST_RETURN_INT_NONE_OR_STR);
}
}
- private static PException raiseError(PRaiseNode raise) {
- return raise.raise(ValueError, ErrorMessages.CHARACTER_MAPPING_MUST_BE_IN_RANGE, PInt.toHexString(Character.MAX_CODE_POINT + 1));
+ private static PException raiseError(Node inliningTarget, PRaiseNode raise) {
+ return raise.raise(inliningTarget, ValueError, ErrorMessages.CHARACTER_MAPPING_MUST_BE_IN_RANGE, PInt.toHexString(Character.MAX_CODE_POINT + 1));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java
index f65ae7907b..644561c894 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -113,7 +113,7 @@ public TruffleString build(Node node, Object[] argsArg, Object kwArgs, FormatNod
private TruffleString buildString(Node node, int start, int end, int level, FormatNode formatNode) {
if (level == 0) {
- throw PRaiseNode.raiseUncached(node, ValueError, RECURSION_DEPTH_EXCEEDED);
+ throw PRaiseNode.raiseStatic(node, ValueError, RECURSION_DEPTH_EXCEEDED);
}
return doBuildString(node, start, end, level - 1, this.template, formatNode);
}
@@ -131,14 +131,14 @@ private TruffleString doBuildString(Node node, int start, int end, int level, St
boolean markupFollows = true;
if (c == '}') {
if (atEnd || s.charAt(i) != '}') {
- throw PRaiseNode.raiseUncached(node, ValueError, SINGLE_RBRACE_ENCOUNTERED_IN_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(node, ValueError, SINGLE_RBRACE_ENCOUNTERED_IN_FORMAT_STRING);
}
i += 1;
markupFollows = false;
}
if (c == '{') {
if (atEnd) {
- throw PRaiseNode.raiseUncached(node, ValueError, SINGLE_RBRACE_ENCOUNTERED_IN_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(node, ValueError, SINGLE_RBRACE_ENCOUNTERED_IN_FORMAT_STRING);
}
if (s.charAt(i) == '{') {
i += 1;
@@ -181,7 +181,7 @@ private TruffleString doBuildString(Node node, int start, int end, int level, St
i += 1;
}
if (nested > 0) {
- throw PRaiseNode.raiseUncached(node, ValueError, EXPECTED_RBRACE_BEFORE_END_OF_STRING);
+ throw PRaiseNode.raiseStatic(node, ValueError, EXPECTED_RBRACE_BEFORE_END_OF_STRING);
}
Object rendered = renderField(node, fieldStart, i, recursive, level, formatNode);
out.append(rendered);
@@ -217,13 +217,13 @@ private Field parseField(Node node, int start, int end) {
if (c == '!') {
i += 1;
if (i == end) {
- throw PRaiseNode.raiseUncached(node, ValueError, EXPECTED_CONVERSION);
+ throw PRaiseNode.raiseStatic(node, ValueError, EXPECTED_CONVERSION);
}
conversion = s.charAt(i);
i += 1;
if (i < end) {
if (s.charAt(i) != ':') {
- throw PRaiseNode.raiseUncached(node, ValueError, EXPECTED_S_AFTER_FORMAT_CONVERSION, ':');
+ throw PRaiseNode.raiseStatic(node, ValueError, EXPECTED_S_AFTER_FORMAT_CONVERSION, ':');
}
i += 1;
}
@@ -237,7 +237,7 @@ private Field parseField(Node node, int start, int end) {
i += 1;
}
} else if (c == '{') {
- throw PRaiseNode.raiseUncached(node, ValueError, UNEXPECTED_S_IN_FIELD_NAME, "'{'");
+ throw PRaiseNode.raiseStatic(node, ValueError, UNEXPECTED_S_IN_FIELD_NAME, "'{'");
}
i += 1;
}
@@ -274,10 +274,10 @@ private Object getArgument(Node node, String name) {
if (useNumeric) {
if (this.autoNumberingState == ANS_MANUAL) {
if (isEmpty) {
- throw PRaiseNode.raiseUncached(node, ValueError, SWITCHING_FROM_MANUAL_TO_AUTOMATIC_NUMBERING);
+ throw PRaiseNode.raiseStatic(node, ValueError, SWITCHING_FROM_MANUAL_TO_AUTOMATIC_NUMBERING);
}
} else if (!isEmpty) {
- throw PRaiseNode.raiseUncached(node, ValueError, SWITCHING_FROM_AUTOMATIC_TO_MANUAL_NUMBERING);
+ throw PRaiseNode.raiseStatic(node, ValueError, SWITCHING_FROM_AUTOMATIC_TO_MANUAL_NUMBERING);
}
}
if (isEmpty) {
@@ -289,13 +289,13 @@ private Object getArgument(Node node, String name) {
String kwarg = intString;
arg = getKeyword(node, kwarg);
} else if (index > SysModuleBuiltins.MAXSIZE) {
- throw PRaiseNode.raiseUncached(node, ValueError, TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(node, ValueError, TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
} else {
if (this.args == null) {
- throw PRaiseNode.raiseUncached(node, ValueError, FORMAT_STR_CONTAINS_POS_FIELDS);
+ throw PRaiseNode.raiseStatic(node, ValueError, FORMAT_STR_CONTAINS_POS_FIELDS);
}
if (index >= this.args.length) {
- throw PRaiseNode.raiseUncached(node, IndexError, REPLACEMENT_INDEX_S_OUT_OF_RANGE, index);
+ throw PRaiseNode.raiseStatic(node, IndexError, REPLACEMENT_INDEX_S_OUT_OF_RANGE, index);
}
arg = this.args[index];
}
@@ -320,7 +320,7 @@ private Object resolveLookups(Node node, Object obj, String name, int startArg,
i += 1;
}
if (start == i) {
- throw PRaiseNode.raiseUncached(node, ValueError, EMPTY_ATTR_IN_FORMAT_STR);
+ throw PRaiseNode.raiseStatic(node, ValueError, EMPTY_ATTR_IN_FORMAT_STR);
}
TruffleString attr = toTruffleStringUncached(name.substring(start, i));
if (result != null) {
@@ -341,11 +341,11 @@ private Object resolveLookups(Node node, Object obj, String name, int startArg,
i += 1;
}
if (!gotBracket) {
- throw PRaiseNode.raiseUncached(node, ValueError, MISSING_S, "']'");
+ throw PRaiseNode.raiseStatic(node, ValueError, MISSING_S, "']'");
}
String s = name.substring(start, i);
if (s.isEmpty()) {
- throw PRaiseNode.raiseUncached(node, ValueError, EMPTY_ATTR_IN_FORMAT_STR);
+ throw PRaiseNode.raiseStatic(node, ValueError, EMPTY_ATTR_IN_FORMAT_STR);
}
int index = toInt(node, s);
Object item = index != -1 ? index : toTruffleStringUncached(s);
@@ -356,7 +356,7 @@ private Object resolveLookups(Node node, Object obj, String name, int startArg,
this.parserList.add(new Object[]{false, item});
}
} else {
- throw PRaiseNode.raiseUncached(node, ValueError, ONLY_S_AND_S_AMY_FOLLOW_S, "'['", "'.'", "']'");
+ throw PRaiseNode.raiseStatic(node, ValueError, ONLY_S_AND_S_AMY_FOLLOW_S, "'['", "'.'", "']'");
}
}
return result;
@@ -372,7 +372,7 @@ private static int toInt(Node node, String s) {
} catch (NumberFormatException e) {
return -1;
} catch (ArithmeticException e) {
- throw PRaiseNode.raiseUncached(node, ValueError, TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(node, ValueError, TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
}
}
@@ -462,7 +462,7 @@ private static Object convert(Node node, Object obj, char conversion) {
case 'a':
return PyObjectAsciiNode.executeUncached(obj);
default:
- throw PRaiseNode.raiseUncached(node, ValueError, INVALID_CONVERSION);
+ throw PRaiseNode.raiseStatic(node, ValueError, INVALID_CONVERSION);
}
}
@@ -491,7 +491,7 @@ private Object getKeyword(Node node, String key) {
return result;
}
}
- throw PRaiseNode.raiseUncached(node, KeyError, tKey);
+ throw PRaiseNode.raiseStatic(node, KeyError, tKey);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
index 6a423b6eeb..48cb26dc28 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructBuiltins.java
@@ -101,14 +101,16 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
}
@Specialization
- Object pack(VirtualFrame frame, PStruct self, Object[] args, PKeyword[] keywords,
+ static Object pack(VirtualFrame frame, PStruct self, Object[] args, PKeyword[] keywords,
+ @Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Cached StructNodes.PackValueNode packValueNode) {
+ @Cached StructNodes.PackValueNode packValueNode,
+ @Cached PRaiseNode raiseNode) {
if (keywords.length != 0) {
- throw raise(TypeError, S_TAKES_NO_KEYWORD_ARGS, "pack()");
+ throw raiseNode.raise(inliningTarget, TypeError, S_TAKES_NO_KEYWORD_ARGS, "pack()");
}
if (args.length != self.getLen()) {
- throw raise(StructError, STRUCT_PACK_EXPECTED_N_ITEMS_GOT_K, self.getLen(), args.length);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_PACK_EXPECTED_N_ITEMS_GOT_K, self.getLen(), args.length);
}
byte[] bytes = new byte[self.getSize()];
packInternal(frame, self, packValueNode, args, bytes, 0);
@@ -134,11 +136,11 @@ static Object packInto(VirtualFrame frame, PStruct self, Object buffer, int offs
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Cached StructNodes.PackValueNode packValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
final long size = self.getUnsignedSize();
if (args.length != self.getLen()) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_PACK_EXPECTED_N_ITEMS_GOT_K, size, args.length);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_PACK_EXPECTED_N_ITEMS_GOT_K, size, args.length);
}
int bufferOffset = offset;
int bufferLen = bufferLib.getBufferLength(buffer);
@@ -154,12 +156,12 @@ static Object packInto(VirtualFrame frame, PStruct self, Object buffer, int offs
if (bufferOffset < 0) {
// Check that negative offset is low enough to fit data
if (bufferOffset + size > 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_NO_SPACE_TO_PACK_N_BYTES, size, bufferOffset);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_NO_SPACE_TO_PACK_N_BYTES, size, bufferOffset);
}
// Check that negative offset is not crossing buffer boundary
if (bufferOffset + bufferLen < 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_OFFSET_OUT_OF_RANGE, bufferOffset, bufferLen);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_OFFSET_OUT_OF_RANGE, bufferOffset, bufferLen);
}
bufferOffset += bufferLen;
@@ -170,7 +172,7 @@ static Object packInto(VirtualFrame frame, PStruct self, Object buffer, int offs
assert bufferOffset >= 0;
assert size >= 0;
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_PACK_INTO_REQ_BUFFER_TO_PACK, size + bufferOffset, size, bufferOffset, bufferLen);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_PACK_INTO_REQ_BUFFER_TO_PACK, size + bufferOffset, size, bufferOffset, bufferLen);
}
// TODO: GR-54860 use buffer API in the packing process
@@ -208,12 +210,12 @@ static Object unpack(VirtualFrame frame, PStruct self, Object buffer,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Cached StructNodes.UnpackValueNode unpackValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int bytesLen = bufferLib.getBufferLength(buffer);
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
if (bytesLen != self.getSize()) {
- throw raiseNode.get(inliningTarget).raise(StructError, UNPACK_REQ_A_BUFFER_OF_N_BYTES, self.getSize());
+ throw raiseNode.raise(inliningTarget, StructError, UNPACK_REQ_A_BUFFER_OF_N_BYTES, self.getSize());
}
return PFactory.createTuple(language, unpackInternal(self, unpackValueNode, bytes, 0));
} finally {
@@ -239,14 +241,14 @@ static Object iterUnpack(VirtualFrame frame, PStruct self, Object buffer,
@Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
if (self.getSize() == 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_ITER_CANNOT_UNPACK_FROM_STRUCT_OF_SIZE_0);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_ITER_CANNOT_UNPACK_FROM_STRUCT_OF_SIZE_0);
}
int bufferLen = bufferLib.getBufferLength(buffer);
if (bufferLen % self.getSize() != 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_ITER_UNPACK_REQ_A_BUFFER_OF_A_MUL_OF_BYTES, self.getSize());
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_ITER_UNPACK_REQ_A_BUFFER_OF_A_MUL_OF_BYTES, self.getSize());
}
} catch (Exception e) {
bufferLib.release(buffer, frame, indirectCallData);
@@ -279,7 +281,7 @@ static Object unpackFrom(VirtualFrame frame, PStruct self, Object buffer, int of
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
@Cached StructNodes.UnpackValueNode unpackValueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
int bufferOffset = offset;
int bytesLen = bufferLib.getBufferLength(buffer);
@@ -288,17 +290,17 @@ static Object unpackFrom(VirtualFrame frame, PStruct self, Object buffer, int of
final long size = self.getUnsignedSize();
if (bufferOffset < 0) {
if (bufferOffset + size > 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_NOT_ENOUGH_DATA_TO_UNPACK_N_BYTES, size, bufferOffset);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_NOT_ENOUGH_DATA_TO_UNPACK_N_BYTES, size, bufferOffset);
}
if (bufferOffset + bytesLen < 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_OFFSET_OUT_OF_RANGE, bufferOffset, bytesLen);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_OFFSET_OUT_OF_RANGE, bufferOffset, bytesLen);
}
bufferOffset += bytesLen;
}
if ((bytesLen - bufferOffset) < size) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_UNPACK_FROM_REQ_AT_LEAST_N_BYTES, size + bufferOffset, size, bufferOffset, bytesLen);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_UNPACK_FROM_REQ_AT_LEAST_N_BYTES, size + bufferOffset, size, bufferOffset, bytesLen);
}
return PFactory.createTuple(language, unpackInternal(self, unpackValueNode, bytes, bufferOffset));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
index 50a43415f6..ad5ddd92f6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructNodes.java
@@ -82,13 +82,13 @@ static long get(VirtualFrame frame, Object value, boolean unsigned,
@Cached PyLongCheckNode pyLongCheckNode,
@Cached PyNumberIndexNode indexNode,
@Cached PyLongAsLongNode pyLongAsLongNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object longValue;
if (!pyLongCheckNode.execute(inliningTarget, value)) {
if (indexCheckNode.execute(inliningTarget, value)) {
longValue = indexNode.execute(frame, inliningTarget, value);
} else {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_NOT_T, "an integer");
+ throw raiseNode.raise(inliningTarget, StructError, ARG_NOT_T, "an integer");
}
} else {
longValue = value;
@@ -99,10 +99,10 @@ static long get(VirtualFrame frame, Object value, boolean unsigned,
x = pyLongAsLongNode.execute(frame, inliningTarget, longValue);
} catch (PException pe) {
pe.expect(inliningTarget, PythonBuiltinClassType.OverflowError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_O_O_RANGE);
+ throw raiseNode.raise(inliningTarget, StructError, ARG_O_O_RANGE);
}
if (unsigned && x < 0) {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_O_O_RANGE);
+ throw raiseNode.raise(inliningTarget, StructError, ARG_O_O_RANGE);
}
return x;
}
@@ -159,30 +159,30 @@ public static boolean isSupportedFormat(FormatCode formatCode) {
}
// checks
- private static PException raiseNumberError(FormatCode formatCode, PRaiseNode raiseNode) {
+ private static PException raiseNumberError(Node inliningTarget, FormatCode formatCode, PRaiseNode raiseNode) {
if (formatCode.formatDef.name == null) {
- return raiseNode.raise(StructError, ARG_O_O_RANGE);
+ return raiseNode.raise(inliningTarget, StructError, ARG_O_O_RANGE);
}
- return raiseNode.raise(StructError, FMT_REQ_RANGE, formatCode.formatDef.name, formatCode.formatDef.min, formatCode.formatDef.max);
+ return raiseNode.raise(inliningTarget, StructError, FMT_REQ_RANGE, formatCode.formatDef.name, formatCode.formatDef.min, formatCode.formatDef.max);
}
private static PException raiseNumberErrorUncached(Node raisingNode, FormatCode formatCode) {
if (formatCode.formatDef.name == null) {
- return PRaiseNode.raiseUncached(raisingNode, StructError, ARG_O_O_RANGE);
+ return PRaiseNode.raiseStatic(raisingNode, StructError, ARG_O_O_RANGE);
}
- return PRaiseNode.raiseUncached(raisingNode, StructError, FMT_REQ_RANGE, formatCode.formatDef.name, formatCode.formatDef.min, formatCode.formatDef.max);
+ return PRaiseNode.raiseStatic(raisingNode, StructError, FMT_REQ_RANGE, formatCode.formatDef.name, formatCode.formatDef.min, formatCode.formatDef.max);
}
- public static long checkLong(Node inliningTarget, FormatCode formatCode, long value, PRaiseNode.Lazy raiseNode) {
+ public static long checkLong(Node inliningTarget, FormatCode formatCode, long value, PRaiseNode raiseNode) {
if (value < formatCode.formatDef.min || value > formatCode.formatDef.max) {
- throw raiseNumberError(formatCode, raiseNode.get(inliningTarget));
+ throw raiseNumberError(inliningTarget, formatCode, raiseNode);
}
return value;
}
- public static long checkLongUnsigned(Node inliningTarget, FormatCode formatCode, long value, PRaiseNode.Lazy raiseNode) {
+ public static long checkLongUnsigned(Node inliningTarget, FormatCode formatCode, long value, PRaiseNode raiseNode) {
if (value < formatCode.formatDef.min || Long.compareUnsigned(value, formatCode.formatDef.max) > 0) {
- throw raiseNumberError(formatCode, raiseNode.get(inliningTarget));
+ throw raiseNumberError(inliningTarget, formatCode, raiseNode);
}
return value;
}
@@ -222,7 +222,7 @@ public abstract static class PackValueNode extends StructBaseNode {
public abstract void execute(VirtualFrame frame, FormatCode formatCode, FormatAlignment formatAlignment, Object value, byte[] buffer, int offset);
private static void packLongInternal(Node inliningTarget, FormatCode formatCode, long value, byte[] buffer, int offset, NumericSupport numericSupport, int numBytes,
- InlinedConditionProfile profileSigned, PRaiseNode.Lazy raiseNode) {
+ InlinedConditionProfile profileSigned, PRaiseNode raiseNode) {
final long num;
if (profileSigned.profile(inliningTarget, formatCode.isUnsigned())) {
num = checkLongUnsigned(inliningTarget, formatCode, value, raiseNode);
@@ -237,7 +237,7 @@ static void packLong(FormatCode formatCode, @SuppressWarnings("unused") FormatAl
@Bind("this") Node inliningTarget,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
@Shared @Cached InlinedConditionProfile profileSigned,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
packLongInternal(inliningTarget, formatCode, value, buffer, offset, numericSupport, formatCode.numBytes(), profileSigned, raiseNode);
}
@@ -246,7 +246,7 @@ static void packInt(FormatCode formatCode, @SuppressWarnings("unused") FormatAli
@Bind("this") Node inliningTarget,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
@Shared @Cached InlinedConditionProfile profileSigned,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
packLongInternal(inliningTarget, formatCode, value, buffer, offset, numericSupport, formatCode.numBytes(), profileSigned, raiseNode);
}
@@ -255,12 +255,12 @@ static void packPInt(FormatCode formatCode, @SuppressWarnings("unused") FormatAl
@Bind("this") Node inliningTarget,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
@Shared @Cached CastToJavaBigIntegerNode toJavaBigIntegerNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
BigInteger num = checkBigInt(inliningTarget, formatCode, toJavaBigIntegerNode.execute(inliningTarget, value));
numericSupport.putBigInteger(buffer, offset, num, formatCode.numBytes());
} catch (OverflowException oe) {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_O_O_RANGE);
+ throw raiseNode.raise(inliningTarget, StructError, ARG_O_O_RANGE);
}
}
@@ -268,7 +268,7 @@ static void packPInt(FormatCode formatCode, @SuppressWarnings("unused") FormatAl
static void packFloat(FormatCode formatCode, @SuppressWarnings("unused") FormatAlignment formatAlignment, double value, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
numericSupport.putDouble(inliningTarget, buffer, offset, value, formatCode.numBytes(), raiseNode);
}
@@ -276,7 +276,7 @@ static void packFloat(FormatCode formatCode, @SuppressWarnings("unused") FormatA
static void packPFloat(FormatCode formatCode, FormatAlignment formatAlignment, PFloat value, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
@Cached("getNumericSupport(formatAlignment)") NumericSupport numericSupport,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
packFloat(formatCode, formatAlignment, value.getValue(), buffer, offset, inliningTarget, numericSupport, raiseNode);
}
@@ -291,13 +291,13 @@ static void packBytes(FormatCode formatCode, @SuppressWarnings("unused") FormatA
@Bind("this") Node inliningTarget,
@Shared @Cached("createEqualityProfile()") PrimitiveValueProfile formatProfile,
@CachedLibrary("value") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
int n = bufferLib.getBufferLength(value);
switch (formatProfile.profile(formatCode.formatDef.format)) {
case FMT_CHAR:
if (n != 1) {
- throw raiseNode.get(inliningTarget).raise(StructError, STRUCT_CHR_FMT_BYTES_1);
+ throw raiseNode.raise(inliningTarget, StructError, STRUCT_CHR_FMT_BYTES_1);
}
assert n <= buffer.length - offset;
bufferLib.readIntoByteArray(value, 0, buffer, offset, n);
@@ -340,7 +340,7 @@ static void packObjectCached(VirtualFrame frame, FormatCode formatCode, FormatAl
@Shared @Cached InlinedConditionProfile profileSigned,
@Shared @Cached IsBuiltinObjectProfile errorProfile,
@Shared @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
if (isNumberUpToSize8Unsigned(formatCode)) {
packLong(formatCode, formatAlignment, getLongNode.execute(frame, value, formatCode.isUnsigned()), buffer, offset, inliningTarget, numericSupport, profileSigned, raiseNode);
} else if (isNumberSize8Unsigned(formatCode)) {
@@ -351,15 +351,15 @@ static void packObjectCached(VirtualFrame frame, FormatCode formatCode, FormatAl
BigInteger num = checkBigInt(inliningTarget, formatCode, toJavaBigIntegerNode.execute(inliningTarget, value));
getNumericSupport(formatAlignment).putBigInteger(buffer, offset, num, formatCode.numBytes());
} catch (OverflowException oe) {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_O_O_RANGE);
+ throw raiseNode.raise(inliningTarget, StructError, ARG_O_O_RANGE);
} catch (PException pe) {
pe.expect(inliningTarget, PythonBuiltinClassType.TypeError, errorProfile);
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_NOT_T, "an integer");
+ throw raiseNode.raise(inliningTarget, StructError, ARG_NOT_T, "an integer");
}
}
} else if (isFmtFloat(formatCode)) {
if (!canBeDoubleNode.execute(inliningTarget, value)) {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_NOT_T, "a float");
+ throw raiseNode.raise(inliningTarget, StructError, ARG_NOT_T, "a float");
}
packFloat(formatCode, formatAlignment, asDoubleNode.execute(frame, inliningTarget, value), buffer, offset, inliningTarget, numericSupport, raiseNode);
} else if (isFmtVoidPtr(formatCode)) {
@@ -369,11 +369,11 @@ static void packObjectCached(VirtualFrame frame, FormatCode formatCode, FormatAl
packBoolean(formatCode, formatAlignment, isTrueNode.execute(frame, value), buffer, offset);
} else if (isFmtBytes(formatCode)) {
if (!isBytes(value)) {
- throw raiseNode.get(inliningTarget).raise(StructError, ARG_FOR_N_MUST_BE, formatCode.formatDef.format, "bytes");
+ throw raiseNode.raise(inliningTarget, StructError, ARG_FOR_N_MUST_BE, formatCode.formatDef.format, "bytes");
}
packBytes(formatCode, formatAlignment, (PBytesLike) value, buffer, offset, inliningTarget, formatProfile, bufferLib, raiseNode);
} else {
- throw raiseNode.get(inliningTarget).raise(NotImplementedError, STRUCT_FMT_NOT_YET_SUPPORTED, formatCode);
+ throw raiseNode.raise(inliningTarget, NotImplementedError, STRUCT_FMT_NOT_YET_SUPPORTED, formatCode);
}
}
@@ -389,7 +389,7 @@ static void packObject(VirtualFrame frame, FormatCode formatCode, FormatAlignmen
@Shared @Cached InlinedConditionProfile profileSigned,
@Shared @Cached IsBuiltinObjectProfile errorProfile,
@Shared @CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
packObjectCached(frame, formatCode, formatAlignment, value, buffer, offset, inliningTarget, getLongNode, toJavaBigIntegerNode,
canBeDoubleNode, asDoubleNode, isTrueNode,
getNumericSupport(formatAlignment), formatProfile, profileSigned, errorProfile, bufferLib, raiseNode);
@@ -440,8 +440,7 @@ static Object unpackFloat8(FormatCode formatCode, @SuppressWarnings("unused") Fo
@SuppressWarnings("unused")
static Object unpackVoidPtr(FormatCode formatCode, FormatAlignment formatAlignment, byte[] buffer, int offset,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedConditionProfile profilePIntResult,
- @Shared @Cached PRaiseNode raiseNode) {
+ @Shared @Cached InlinedConditionProfile profilePIntResult) {
long num = getNumericSupport(formatAlignment).getLongUnsigned(buffer, offset, formatCode.numBytes());
if (profilePIntResult.profile(inliningTarget, num < 0)) {
return PFactory.createInt(PythonLanguage.get(inliningTarget), getAsUnsignedBigInt(num));
@@ -482,8 +481,8 @@ static Object unpackBytes(@SuppressWarnings("unused") FormatCode formatCode, @Su
@Specialization(guards = "!isSupportedFormat(formatCode)")
@SuppressWarnings("unused")
static byte[] unpackUnsupported(FormatCode formatCode, FormatAlignment formatAlignment, byte[] buffer, int offset,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(NotImplementedError, STRUCT_FMT_NOT_YET_SUPPORTED, formatCode);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, STRUCT_FMT_NOT_YET_SUPPORTED, formatCode);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
index b0718e01fa..d0ab50aa91 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/struct/StructUnpackIteratorBuiltins.java
@@ -49,8 +49,8 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
protected abstract static class NewNode extends PythonBuiltinNode {
@Specialization
static Object createNew(Object type, @SuppressWarnings("unused") Object[] args, @SuppressWarnings("unused") PKeyword[] kwds,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, CANNOT_CREATE_P_OBJECTS, type);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, CANNOT_CREATE_P_OBJECTS, type);
}
}
@@ -82,8 +82,8 @@ static int lenHint(PStructUnpackIterator self,
public abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.isExhausted()")
static Object nextExhausted(@SuppressWarnings("unused") PStructUnpackIterator self,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.StopIteration);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.StopIteration);
}
@Specialization(guards = "!self.isExhausted()", limit = "3")
@@ -93,7 +93,7 @@ static Object next(VirtualFrame frame, PStructUnpackIterator self,
@Cached StructNodes.UnpackValueNode unpackValueNode,
@CachedLibrary("self.getBuffer()") PythonBufferAccessLibrary bufferLib,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final PStruct struct = self.getStruct();
final Object buffer = self.getBuffer();
final int bufferLen = bufferLib.getBufferLength(buffer);
@@ -101,7 +101,7 @@ static Object next(VirtualFrame frame, PStructUnpackIterator self,
if (struct == null || self.index >= bufferLen) {
self.setExhausted();
bufferLib.release(buffer, frame, indirectCallData);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.StopIteration);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
assert self.index + struct.getSize() <= bufferLen;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
index da6208bc58..f54b1c517f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java
@@ -85,6 +85,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.SpecialAttributeNames;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
@@ -117,6 +118,7 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -201,11 +203,13 @@ public abstract static class SuperInitNode extends PythonVarargsBuiltinNode {
@Child private GetClassNode getClassNode;
@Child private PyObjectLookupAttr getAttrNode;
@Child private TypeNodes.IsTypeNode isTypeNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
if (keywords.length != 0) {
- throw raise(RuntimeError, ErrorMessages.UNEXPECTED_KEYWORD_ARGS, "super()");
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.UNEXPECTED_KEYWORD_ARGS, "super()");
}
if (arguments.length == 1) {
return execute(frame, arguments[0], PNone.NO_VALUE, PNone.NO_VALUE);
@@ -214,14 +218,16 @@ public Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused") Obje
} else if (arguments.length == 3) {
return execute(frame, arguments[0], arguments[1], arguments[2]);
} else {
- throw raise(RuntimeError, ErrorMessages.INVALID_NUMBER_OF_ARGUMENTS, "super()");
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.INVALID_NUMBER_OF_ARGUMENTS, "super()");
}
}
@Override
public final Object execute(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords) {
if (keywords.length != 0) {
- throw raise(RuntimeError, ErrorMessages.UNEXPECTED_KEYWORD_ARGS, "super()");
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.UNEXPECTED_KEYWORD_ARGS, "super()");
}
if (arguments.length == 0) {
return execute(frame, self, PNone.NO_VALUE, PNone.NO_VALUE);
@@ -230,16 +236,19 @@ public final Object execute(VirtualFrame frame, Object self, Object[] arguments,
} else if (arguments.length == 2) {
return execute(frame, self, arguments[0], arguments[1]);
} else {
- throw raise(RuntimeError, ErrorMessages.TOO_MANY_ARG, "super()");
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.TOO_MANY_ARG, "super()");
}
}
protected abstract Object execute(VirtualFrame frame, Object self, Object cls, Object obj);
@Specialization(guards = "!isNoValue(cls)")
- PNone init(VirtualFrame frame, SuperObject self, Object cls, Object obj) {
+ PNone init(VirtualFrame frame, SuperObject self, Object cls, Object obj,
+ @Bind("this") Node inliningTarget,
+ @Cached PRaiseNode raiseNode) {
if (!(obj instanceof PNone)) {
- Object type = supercheck(frame, cls, obj);
+ Object type = supercheck(frame, inliningTarget, cls, obj, raiseNode);
self.init(cls, type, obj);
} else {
self.init(cls, null, null);
@@ -258,13 +267,14 @@ protected boolean isInBuiltinFunctionRoot() {
@Specialization(guards = {"!isInBuiltinFunctionRoot()", "isNoValue(clsArg)", "isNoValue(objArg)"})
PNone initInPlace(VirtualFrame frame, SuperObject self, @SuppressWarnings("unused") PNone clsArg, @SuppressWarnings("unused") PNone objArg,
@Bind("this") Node inliningTarget,
+ @Shared @Cached PRaiseNode raiseNode,
@Shared @Cached CellBuiltins.GetRefNode getRefNode) {
PBytecodeRootNode rootNode = (PBytecodeRootNode) getRootNode();
Frame localFrame = frame;
if (rootNode.getCodeUnit().isGeneratorOrCoroutine()) {
localFrame = PArguments.getGeneratorFrame(frame);
}
- return initFromLocalFrame(frame, inliningTarget, self, rootNode, localFrame, getRefNode);
+ return initFromLocalFrame(frame, inliningTarget, self, rootNode, localFrame, getRefNode, raiseNode);
}
/**
@@ -273,41 +283,43 @@ PNone initInPlace(VirtualFrame frame, SuperObject self, @SuppressWarnings("unuse
@Specialization(guards = {"isInBuiltinFunctionRoot()", "isNoValue(clsArg)", "isNoValue(objArg)"})
PNone init(VirtualFrame frame, SuperObject self, @SuppressWarnings("unused") PNone clsArg, @SuppressWarnings("unused") PNone objArg,
@Bind("this") Node inliningTarget,
+ @Shared @Cached PRaiseNode raiseNode,
@Cached ReadCallerFrameNode readCaller,
@Shared @Cached CellBuiltins.GetRefNode getRefNode) {
PFrame target = readCaller.executeWith(frame, FrameSelector.SKIP_PYTHON_BUILTIN, 0);
if (target == null) {
- throw raise(RuntimeError, ErrorMessages.NO_CURRENT_FRAME, "super()");
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.NO_CURRENT_FRAME, "super()");
}
MaterializedFrame locals = target.getLocals();
if (locals == null) {
- throw raise(RuntimeError, ErrorMessages.SUPER_NO_CLASS);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS);
}
FrameInfo frameInfo = (FrameInfo) locals.getFrameDescriptor().getInfo();
- return initFromLocalFrame(frame, inliningTarget, self, frameInfo.getRootNode(), locals, getRefNode);
+ return initFromLocalFrame(frame, inliningTarget, self, frameInfo.getRootNode(), locals, getRefNode, raiseNode);
}
- private PNone initFromLocalFrame(VirtualFrame frame, Node inliningTarget, SuperObject self, PBytecodeRootNode rootNode, Frame localFrame, CellBuiltins.GetRefNode getRefNode) {
+ private PNone initFromLocalFrame(VirtualFrame frame, Node inliningTarget, SuperObject self, PBytecodeRootNode rootNode, Frame localFrame, CellBuiltins.GetRefNode getRefNode,
+ PRaiseNode raiseNode) {
PCell classCell = rootNode.readClassCell(localFrame);
if (classCell == null) {
- throw raise(RuntimeError, ErrorMessages.SUPER_NO_CLASS);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS);
}
Object cls = getRefNode.execute(inliningTarget, classCell);
if (cls == null) {
// the cell is empty
- throw raise(RuntimeError, ErrorMessages.SUPER_EMPTY_CLASS);
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_EMPTY_CLASS);
}
Object obj = rootNode.readSelf(localFrame);
if (obj == null) {
- throw raise(RuntimeError, ErrorMessages.NO_ARGS, "super()");
+ throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.NO_ARGS, "super()");
}
- return init(frame, self, cls, obj);
+ return init(frame, self, cls, obj, inliningTarget, raiseNode);
}
@SuppressWarnings("unused")
@Fallback
PNone initFallback(Object self, Object cls, Object obj) {
- throw raise(RuntimeError, ErrorMessages.INVALID_ARGS, "super()");
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.INVALID_ARGS, "super()");
}
private IsSubtypeNode getIsSubtype() {
@@ -342,7 +354,7 @@ private PyObjectLookupAttr getGetAttr() {
return getAttrNode;
}
- private Object supercheck(VirtualFrame frame, Object cls, Object object) {
+ private Object supercheck(VirtualFrame frame, Node inliningTarget, Object cls, Object object, PRaiseNode raiseNode) {
/*
* Check that a super() call makes sense. Return a type object.
*
@@ -379,7 +391,7 @@ private Object supercheck(VirtualFrame frame, Object cls, Object object) {
// error is ignored
}
- throw raise(PythonErrorType.TypeError, ErrorMessages.SUPER_OBJ_MUST_BE_INST_SUB_OR_TYPE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.SUPER_OBJ_MUST_BE_INST_SUB_OR_TYPE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/LockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/LockBuiltins.java
index 41c435b6b4..339f1d6a72 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/LockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/LockBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -152,22 +152,22 @@ boolean acTimeOut(AbstractPythonLock self, @SuppressWarnings("unused") boolean b
@SuppressWarnings("unused")
@Specialization(guards = {"invalidArgs(blocking, timeout)", "timeout != UNSET_TIMEOUT", "!blocking"})
static boolean err1(AbstractPythonLock self, boolean blocking, double timeout,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANT_SPECIFY_TIMEOUT_FOR_NONBLOCKING);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.CANT_SPECIFY_TIMEOUT_FOR_NONBLOCKING);
}
@SuppressWarnings("unused")
@Specialization(guards = {"invalidArgs(blocking, timeout)", "timeout != UNSET_TIMEOUT", "isNeg(timeout)"})
static boolean err2(AbstractPythonLock self, boolean blocking, double timeout,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(ValueError, ErrorMessages.TIMEOUT_VALUE_MUST_BE_POSITIVE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, ValueError, ErrorMessages.TIMEOUT_VALUE_MUST_BE_POSITIVE);
}
@SuppressWarnings("unused")
@Specialization(guards = {"invalidArgs(blocking, timeout)", "timeout != UNSET_TIMEOUT", "timeout > TIMEOUT_MAX"})
static boolean err3(AbstractPythonLock self, boolean blocking, double timeout,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(OverflowError, ErrorMessages.TIMEOUT_VALUE_TOO_LARGE);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, OverflowError, ErrorMessages.TIMEOUT_VALUE_TOO_LARGE);
}
protected static boolean invalidArgs(boolean blocking, double timeout) {
@@ -211,9 +211,9 @@ static Object doRelease(PLock self) {
@Specialization
static Object doRelease(PRLock self,
@Bind("this") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!self.isOwned()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.LOCK_NOT_HELD);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.LOCK_NOT_HELD);
}
self.release();
return PNone.NONE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
index 3a200275b3..fdbbdca3a7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/RLockBuiltins.java
@@ -123,10 +123,10 @@ static Object releaseSave(PRLock self,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile countProfile,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int count = self.getCount();
if (countProfile.profile(inliningTarget, count == 0)) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.RuntimeError, ErrorMessages.CANNOT_RELEASE_UNAQUIRED_LOCK);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.RuntimeError, ErrorMessages.CANNOT_RELEASE_UNAQUIRED_LOCK);
}
PTuple retVal = PFactory.createTuple(language, new Object[]{count, self.getOwnerId()});
self.releaseAll();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalBuiltins.java
index 947e2607c1..f1f6562e1c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalBuiltins.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -133,14 +133,14 @@ Object doIt(VirtualFrame frame, PThreadLocal object, Object keyObj,
@Cached InlinedConditionProfile hasDescrProfile,
@Cached InlinedConditionProfile hasDescrGetProfile,
@Cached InlinedConditionProfile hasValueProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// Note: getting thread local dict has potential side-effects, don't move
PDict localDict = getThreadLocalDict.execute(frame, object);
TruffleString key;
try {
key = castKeyToStringNode.execute(inliningTarget, keyObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
}
Object type = getClassNode.execute(inliningTarget, object);
@@ -167,7 +167,7 @@ Object doIt(VirtualFrame frame, PThreadLocal object, Object keyObj,
return dispatch(frame, object, type, descr, descrGetSlot);
}
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
private Object dispatch(VirtualFrame frame, Object object, Object type, Object descr, TpSlot get) {
@@ -199,7 +199,7 @@ static void doGeneric(VirtualFrame frame, PThreadLocal object, Object keyObject,
@Bind("this") Node inliningTarget,
@Exclusive @Cached ThreadLocalNodes.GetThreadLocalDict getThreadLocalDict,
@Cached CastToTruffleStringNode castKeyToStringNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached GenericSetAttrWithDictNode setAttrWithDictNode) {
// Note: getting thread local dict has potential side-effects, don't move
PDict localDict = getThreadLocalDict.execute(frame, object);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
index 36bba4c914..a1ea04b3fa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tokenize/TokenizerIterBuiltins.java
@@ -94,10 +94,10 @@ static PTuple next(PTokenizerIter self,
@Bind("this") Node inliningTarget,
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Token token = self.getNextToken();
if (token.type == Kind.ERRORTOKEN || token.type == Kind.ENDMARKER) {
- throw raiseNode.get(inliningTarget).raiseStopIteration(T_EOF);
+ throw raiseNode.raiseStopIteration(inliningTarget, T_EOF);
}
int startColumn;
int endColumn;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
index f847f3408c..634fe02311 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java
@@ -272,12 +272,12 @@ static Object set(PTraceback self, PTraceback next,
@Bind("this") Node inliningTarget,
@Cached InlinedLoopConditionProfile loopProfile,
@Exclusive @Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
// Check for loops
PTraceback tb = next;
while (loopProfile.profile(inliningTarget, tb != null)) {
if (tb == self) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.TRACEBACK_LOOP_DETECTED);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TRACEBACK_LOOP_DETECTED);
}
tb = tb.getNext();
}
@@ -301,8 +301,8 @@ static Object clear(PTraceback self, @SuppressWarnings("unused") PNone next,
@Specialization(guards = {"!isPNone(next)", "!isPTraceback(next)"})
static Object setError(@SuppressWarnings("unused") PTraceback self, Object next,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_TRACEBACK_OBJ, next);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.EXPECTED_TRACEBACK_OBJ, next);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
index 8627fd8fbb..473aff97db 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java
@@ -353,7 +353,7 @@ public final Object varArgExecute(VirtualFrame frame, Object self, Object[] argu
@Specialization
@SuppressWarnings("unused")
Object error(Object cls, Object[] arguments, PKeyword[] keywords) {
- throw raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, StructSequence.getTpName(cls));
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, StructSequence.getTpName(cls));
}
}
@@ -384,7 +384,7 @@ PTuple withoutDict(VirtualFrame frame, Object cls, Object sequence, @SuppressWar
@Exclusive @Cached InlinedBranchProfile needsReallocProfile,
@Bind PythonLanguage language,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object[] src = sequenceToArray(frame, inliningTarget, sequence, fastConstructListNode, toArrayNode, notASequenceProfile, raiseNode);
Object[] dst = processSequence(inliningTarget, cls, src, wrongLenProfile, needsReallocProfile, raiseNode);
for (int i = src.length; i < dst.length; ++i) {
@@ -405,7 +405,7 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
@Cached HashingStorageGetItem getItem,
@Bind PythonLanguage language,
@Shared @Cached TypeNodes.GetInstanceShape getInstanceShape,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object[] src = sequenceToArray(frame, inliningTarget, sequence, fastConstructListNode, toArrayNode, notASequenceProfile, raiseNode);
Object[] dst = processSequence(inliningTarget, cls, src, wrongLenProfile, needsReallocProfile, raiseNode);
HashingStorage hs = dict.getDictStorage();
@@ -419,23 +419,23 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
@Specialization(guards = {"!isNoValue(dict)", "!isDict(dict)"})
@SuppressWarnings("unused")
static PTuple doDictError(VirtualFrame frame, Object cls, Object sequence, Object dict,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.TAKES_A_DICT_AS_SECOND_ARG_IF_ANY, StructSequence.getTpName(cls));
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.TAKES_A_DICT_AS_SECOND_ARG_IF_ANY, StructSequence.getTpName(cls));
}
private static Object[] sequenceToArray(VirtualFrame frame, Node inliningTarget, Object sequence, FastConstructListNode fastConstructListNode,
- ToArrayNode toArrayNode, IsBuiltinObjectProfile notASequenceProfile, PRaiseNode.Lazy raiseNode) {
+ ToArrayNode toArrayNode, IsBuiltinObjectProfile notASequenceProfile, PRaiseNode raiseNode) {
PSequence seq;
try {
seq = fastConstructListNode.execute(frame, inliningTarget, sequence);
} catch (PException e) {
e.expect(inliningTarget, TypeError, notASequenceProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CONSTRUCTOR_REQUIRES_A_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CONSTRUCTOR_REQUIRES_A_SEQUENCE);
}
return toArrayNode.execute(inliningTarget, seq.getSequenceStorage());
}
- private Object[] processSequence(Node inliningTarget, Object cls, Object[] src, InlinedBranchProfile wrongLenProfile, InlinedBranchProfile needsReallocProfile, PRaiseNode.Lazy raiseNode) {
+ private Object[] processSequence(Node inliningTarget, Object cls, Object[] src, InlinedBranchProfile wrongLenProfile, InlinedBranchProfile needsReallocProfile, PRaiseNode raiseNode) {
int len = src.length;
int minLen = inSequence;
int maxLen = fieldNames.length;
@@ -443,12 +443,12 @@ private Object[] processSequence(Node inliningTarget, Object cls, Object[] src,
if (len < minLen || len > maxLen) {
wrongLenProfile.enter(inliningTarget);
if (minLen == maxLen) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TAKES_A_D_SEQUENCE, StructSequence.getTpName(cls), minLen, len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TAKES_A_D_SEQUENCE, StructSequence.getTpName(cls), minLen, len);
}
if (len < minLen) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TAKES_AN_AT_LEAST_D_SEQUENCE, StructSequence.getTpName(cls), minLen, len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TAKES_AN_AT_LEAST_D_SEQUENCE, StructSequence.getTpName(cls), minLen, len);
} else { // len > maxLen
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TAKES_AN_AT_MOST_D_SEQUENCE, StructSequence.getTpName(cls), maxLen, len);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TAKES_AN_AT_MOST_D_SEQUENCE, StructSequence.getTpName(cls), maxLen, len);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
index e96a6e6c41..e8835f56b6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
@@ -153,7 +153,7 @@ int index(VirtualFrame frame, Object self, Object value, int startIn, int endIn,
@Cached InlinedBranchProfile startLe0Profile,
@Cached InlinedBranchProfile endLe0Profile,
@Cached SequenceStorageNodes.ItemIndexNode itemIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage storage = getTupleStorage.execute(inliningTarget, self);
int start = startIn;
if (start < 0) {
@@ -175,7 +175,7 @@ int index(VirtualFrame frame, Object self, Object value, int startIn, int endIn,
if (idx != -1) {
return idx;
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.X_NOT_IN_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.ValueError, ErrorMessages.X_NOT_IN_TUPLE);
}
}
@@ -289,7 +289,7 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile validProfile,
@Cached PyIndexCheckNode indexCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached GetTupleStorage getTupleStorage,
@Cached SequenceStorageMpSubscriptNode subscriptNode) {
if (!validProfile.profile(inliningTarget, SequenceStorageMpSubscriptNode.isValidIndex(inliningTarget, idx, indexCheckNode))) {
@@ -300,8 +300,8 @@ static Object doIt(VirtualFrame frame, Object self, Object idx,
}
@InliningCutoff
- private static void raiseNonIntIndex(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object index) {
- raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "tuple", index);
+ private static void raiseNonIntIndex(Node inliningTarget, PRaiseNode raiseNode, Object index) {
+ raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "tuple", index);
}
}
@@ -469,8 +469,8 @@ protected static SequenceStorageNodes.ConcatNode createConcat() {
@Fallback
static Object doGeneric(@SuppressWarnings("unused") Object left, Object right,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "tuple", right, "tuple");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_CONCAT_S_NOT_P_TO_S, "tuple", right, "tuple");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
index e826238069..ced2e38cf8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleGetterBuiltins.java
@@ -109,10 +109,10 @@ static Object getTuple(VirtualFrame frame, PTupleGetter self, PTuple instance, @
@Bind("this") Node inliningTarget,
@Cached PyObjectSizeNode sizeNode,
@Cached TupleBuiltins.GetItemNode getItemNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final int index = self.getIndex();
if (index >= sizeNode.execute(frame, inliningTarget, instance)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.IndexError, TUPLE_OUT_OF_BOUNDS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.IndexError, TUPLE_OUT_OF_BOUNDS);
}
return getItemNode.execute(frame, instance, index);
}
@@ -125,9 +125,9 @@ static Object getNone(@SuppressWarnings("unused") VirtualFrame frame, PTupleGett
@Fallback
@InliningCutoff
static Object getOthers(@SuppressWarnings("unused") VirtualFrame frame, Object self, Object instance, @SuppressWarnings("unused") Object owner,
- @Cached PRaiseNode raiseNode) {
+ @Bind("this") Node inliningTarget) {
final int index = ((PTupleGetter) self).getIndex();
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, DESC_FOR_INDEX_S_FOR_S_DOESNT_APPLY_TO_P,
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, DESC_FOR_INDEX_S_FOR_S_DOESNT_APPLY_TO_P,
index, "tuple subclasses", instance);
}
}
@@ -140,9 +140,9 @@ abstract static class DescrSet extends DescrSetBuiltinNode {
@SuppressWarnings("unused")
void set(PTupleGetter self, Object instance, Object value) {
if (PGuards.isNoValue(value)) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.AttributeError, CANT_DELETE_ATTRIBUTE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.AttributeError, CANT_DELETE_ATTRIBUTE);
} else {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.AttributeError, CANT_SET_ATTRIBUTE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.AttributeError, CANT_SET_ATTRIBUTE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonBuiltinClass.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonBuiltinClass.java
index 259834f2be..71e53b9f46 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonBuiltinClass.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonBuiltinClass.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -78,7 +78,7 @@ public void setAttribute(TruffleString name, Object value) {
if (!PythonContext.get(null).isCoreInitialized()) {
setAttributeUnsafe(name, value);
} else {
- throw PRaiseNode.raiseUncached(null, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(name), this);
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(name), this);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
index 29bffb65bf..b98201849a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java
@@ -52,6 +52,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.strings.TruffleString.CodePointAtIndexNode;
@@ -113,7 +114,8 @@ protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classS
unsafeSetSuperClass(baseClasses);
}
- this.setMRO(ComputeMroNode.doSlowPath(this, invokeMro));
+ // TODO should pass node for exception location
+ this.setMRO(ComputeMroNode.doSlowPath(null, this, invokeMro));
if (invokeMro) {
mroInitialized = true;
}
@@ -142,8 +144,8 @@ public boolean isMROInitialized() {
* Invoke metaclass mro() method and set the result as new method resolution order.
*/
@TruffleBoundary
- public void invokeMro() {
- PythonAbstractClass[] mro = ComputeMroNode.invokeMro(this);
+ public void invokeMro(Node node) {
+ PythonAbstractClass[] mro = ComputeMroNode.invokeMro(node, this);
if (mro != null) {
this.setMRO(mro);
}
@@ -294,7 +296,8 @@ private void unsafeSetSuperClass(PythonAbstractClass... newBaseClasses) {
for (PythonAbstractClass base : getBaseClasses()) {
if (base instanceof PythonManagedClass && !((PythonManagedClass) base).mroInitialized) {
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.CANNOT_EXTEND_INCOMPLETE_P, base);
+ // TODO should pass node for exception location
+ throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.CANNOT_EXTEND_INCOMPLETE_P, base);
}
}
for (PythonAbstractClass base : getBaseClasses()) {
@@ -309,7 +312,7 @@ private void unsafeSetSuperClass(PythonAbstractClass... newBaseClasses) {
}
@TruffleBoundary
- public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseClasses) {
+ public final void setBases(Node node, Object newBaseClass, PythonAbstractClass[] newBaseClasses) {
Object oldBase = getBase();
PythonAbstractClass[] oldBaseClasses = getBaseClasses();
PythonAbstractClass[] oldMRO = this.methodResolutionOrder.getInternalClassArray();
@@ -328,12 +331,12 @@ public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseCla
this.base = newBaseClass;
this.baseClasses = newBaseClasses;
this.methodResolutionOrder.lookupChanged();
- this.setMRO(ComputeMroNode.doSlowPath(this));
+ this.setMRO(ComputeMroNode.doSlowPath(node, this));
for (PythonAbstractClass scls : subclassesArray) {
if (scls instanceof PythonManagedClass pmc) {
pmc.methodResolutionOrder.lookupChanged();
- pmc.setMRO(ComputeMroNode.doSlowPath(scls));
+ pmc.setMRO(ComputeMroNode.doSlowPath(node, scls));
}
}
} catch (PException pe) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
index 0d86652c98..9268bd9af5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
@@ -197,6 +197,7 @@
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -289,14 +290,14 @@ static Object setDoc(PythonClass self, Object value) {
@Specialization(guards = {"!isNoValue(value)", "!isDeleteMarker(value)", "isKindOfBuiltinClass(self)"})
static Object doc(Object self, @SuppressWarnings("unused") Object value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___DOC__, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___DOC__, self);
}
@Specialization
static Object doc(Object self, @SuppressWarnings("unused") DescriptorDeleteMarker marker,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.CANT_DELETE_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___DOC__, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.CANT_DELETE_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___DOC__, self);
}
}
@@ -331,8 +332,8 @@ static Object doit(Object klass,
@Fallback
@SuppressWarnings("unused")
static Object doit(Object object,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T_MRO, "type", object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, T_MRO, "type", object);
}
}
@@ -340,6 +341,7 @@ static Object doit(Object object,
@GenerateNodeFactory
public abstract static class InitNode extends PythonVarargsBuiltinNode {
@Child private SplitArgsNode splitArgsNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
@@ -353,7 +355,8 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
@Specialization
Object init(@SuppressWarnings("unused") Object self, Object[] arguments, @SuppressWarnings("unused") PKeyword[] kwds) {
if (arguments.length != 1 && arguments.length != 3) {
- throw raise(TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type.__init__()", 1, 3);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type.__init__()", 1, 3);
}
return PNone.NONE;
}
@@ -388,12 +391,13 @@ Object selfInArgs(VirtualFrame frame, @SuppressWarnings("unused") Object self, O
@Cached CallNodeHelper callNodeHelper,
@Cached SplitArgsNode splitArgsNode,
@Exclusive @Cached IsSameTypeNode isSameTypeNode,
- @Exclusive @Cached GetClassNode getClassNode) {
+ @Exclusive @Cached GetClassNode getClassNode,
+ @Shared @Cached PRaiseNode raiseNode) {
if (isSameTypeNode.execute(inliningTarget, PythonBuiltinClassType.PythonClass, arguments[0])) {
if (arguments.length == 2 && keywords.length == 0) {
return getClassNode.execute(inliningTarget, arguments[1]);
} else if (arguments.length != 4) {
- throw raise(TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type()", 1, 3);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type()", 1, 3);
}
}
return callNodeHelper.execute(frame, arguments[0], splitArgsNode.execute(inliningTarget, arguments), keywords);
@@ -403,12 +407,13 @@ Object selfInArgs(VirtualFrame frame, @SuppressWarnings("unused") Object self, O
Object selfSeparate(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
@Exclusive @Cached IsSameTypeNode isSameTypeNode,
- @Exclusive @Cached GetClassNode getClassNode) {
+ @Exclusive @Cached GetClassNode getClassNode,
+ @Shared @Cached PRaiseNode raiseNode) {
if (isSameTypeNode.execute(inliningTarget, PythonBuiltinClassType.PythonClass, self)) {
if (arguments.length == 1 && keywords.length == 0) {
return getClassNode.execute(inliningTarget, arguments[0]);
} else if (arguments.length != 3) {
- throw raise(TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type()", 1, 3);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TAKES_D_OR_D_ARGS, "type()", 1, 3);
}
}
return getCallNodeHelper().execute(frame, self, arguments, keywords);
@@ -467,7 +472,7 @@ protected Object doIt0BuiltinSingle(VirtualFrame frame, @SuppressWarnings("unuse
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PythonBuiltinClassType type = cachedSelf.getType();
return op(frame, inliningTarget, type, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -480,7 +485,7 @@ protected Object doIt0User(VirtualFrame frame, @SuppressWarnings("unused") Pytho
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op(frame, inliningTarget, cachedSelf, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -492,7 +497,7 @@ protected Object doIt0BuiltinMulti(VirtualFrame frame, @SuppressWarnings("unused
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op(frame, inliningTarget, cachedType, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -504,7 +509,7 @@ protected Object doIt0BuiltinType(VirtualFrame frame, @SuppressWarnings("unused"
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op(frame, inliningTarget, cachedType, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -515,7 +520,7 @@ protected Object doItIndirect0Builtin(VirtualFrame frame, PythonBuiltinClass sel
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
PythonBuiltinClassType type = self.getType();
return op(frame, inliningTarget, type, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -527,7 +532,7 @@ protected Object doItIndirect0BuiltinType(VirtualFrame frame, PythonBuiltinClass
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op(frame, inliningTarget, self, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -538,7 +543,7 @@ protected Object doItIndirect0User(VirtualFrame frame, PythonClass self, Object[
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return op(frame, inliningTarget, self, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -552,7 +557,7 @@ protected Object doIt1(VirtualFrame frame, @SuppressWarnings("unused") PythonAbs
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkFlags(self, inliningTarget, getTypeFlagsNode, raiseNode);
return op(frame, inliningTarget, PythonNativeClass.cast(cachedSelf), arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@@ -565,19 +570,19 @@ protected Object doItIndirect1(VirtualFrame frame, PythonAbstractNativeObject se
@Shared @Cached InlinedConditionProfile hasInit,
@Shared @Cached InlinedConditionProfile gotInitResult,
@Shared @Cached BindNew bindNew,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkFlags(self, inliningTarget, getTypeFlagsNode, raiseNode);
return op(frame, inliningTarget, PythonNativeClass.cast(self), arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
- private void checkFlags(PythonAbstractNativeObject self, Node inliningTarget, GetTypeFlagsNode getTypeFlagsNode, PRaiseNode.Lazy raiseNode) {
+ private void checkFlags(PythonAbstractNativeObject self, Node inliningTarget, GetTypeFlagsNode getTypeFlagsNode, PRaiseNode raiseNode) {
if ((getTypeFlagsNode.execute(self) & TypeFlags.DISALLOW_INSTANTIATION) != 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, getTypeName(self));
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, getTypeName(self));
}
}
private Object op(VirtualFrame frame, Node inliningTarget, Object self, Object[] arguments, PKeyword[] keywords, GetClassNode getInstanceClassNode,
- InlinedConditionProfile hasInit, InlinedConditionProfile gotInitResult, BindNew bindNew, PRaiseNode.Lazy raiseNode) {
+ InlinedConditionProfile hasInit, InlinedConditionProfile gotInitResult, BindNew bindNew, PRaiseNode raiseNode) {
Object newMethod = lookupNew.execute(self);
assert newMethod != NO_VALUE;
Object[] newArgs = PythonUtils.prependArgument(self, arguments);
@@ -587,7 +592,7 @@ private Object op(VirtualFrame frame, Node inliningTarget, Object self, Object[]
}
private void callInit(Node inliningTarget, Object newInstance, Object self, VirtualFrame frame, Object[] arguments, PKeyword[] keywords, GetClassNode getInstanceClassNode,
- InlinedConditionProfile hasInit, InlinedConditionProfile gotInitResult, PRaiseNode.Lazy raiseNode) {
+ InlinedConditionProfile hasInit, InlinedConditionProfile gotInitResult, PRaiseNode raiseNode) {
Object newInstanceKlass = getInstanceClassNode.execute(inliningTarget, newInstance);
if (isSubType(newInstanceKlass, self)) {
Object initMethod = getInitNode().execute(frame, newInstanceKlass, newInstance);
@@ -595,7 +600,7 @@ private void callInit(Node inliningTarget, Object newInstance, Object self, Virt
Object[] initArgs = PythonUtils.prependArgument(newInstance, arguments);
Object initResult = getDispatchNode().execute(frame, initMethod, initArgs, keywords);
if (gotInitResult.profile(inliningTarget, initResult != PNone.NONE && initResult != NO_VALUE)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_RETURN_NONE, "__init__()");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_RETURN_NONE, "__init__()");
}
}
}
@@ -655,12 +660,12 @@ protected Object doIt(VirtualFrame frame, Object object, Object keyObj,
@Cached InlinedBranchProfile hasValueProfile,
@Cached InlinedBranchProfile hasNonDescriptorValueProfile,
@Cached InlinedBranchProfile errorProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TruffleString key;
try {
key = castToString.execute(inliningTarget, keyObj);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
}
Object metatype = getClassNode.execute(inliningTarget, object);
@@ -697,7 +702,7 @@ protected Object doIt(VirtualFrame frame, Object object, Object keyObj,
}
}
errorProfile.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, object, key);
}
private Object readAttribute(Object object, TruffleString key) {
@@ -751,7 +756,7 @@ static void set(VirtualFrame frame, Object object, Object key, Object value,
@TruffleBoundary
void setBuiltin(Object object, Object key, Object value) {
if (PythonContext.get(this).isInitialized()) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(key), object);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(key), object);
} else {
set(null, object, key, value, null, ObjectNodes.GenericSetAttrNode.getUncached(), WriteAttributeToObjectNode.getUncached(true));
}
@@ -798,18 +803,18 @@ static Object setBases(VirtualFrame frame, PythonClass cls, PTuple value,
@Cached IsSubtypeNode isSubtypeNode,
@Cached IsSameTypeNode isSameTypeNode,
@Cached GetMroNode getMroNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object[] a = getArray.execute(inliningTarget, value);
if (a.length == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CAN_ONLY_ASSIGN_NON_EMPTY_TUPLE_TO_P, cls);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_ASSIGN_NON_EMPTY_TUPLE_TO_P, cls);
}
PythonAbstractClass[] baseClasses = new PythonAbstractClass[a.length];
for (int i = 0; i < a.length; i++) {
if (PGuards.isPythonClass(a[i])) {
if (isSubtypeNode.execute(frame, a[i], cls) ||
hasMRO(inliningTarget, getMroNode, a[i]) && typeIsSubtypeBaseChain(inliningTarget, a[i], cls, getBase, isSameTypeNode)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BASES_ITEM_CAUSES_INHERITANCE_CYCLE);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BASES_ITEM_CAUSES_INHERITANCE_CYCLE);
}
if (a[i] instanceof PythonBuiltinClassType) {
baseClasses[i] = PythonContext.get(inliningTarget).lookupType((PythonBuiltinClassType) a[i]);
@@ -817,7 +822,7 @@ static Object setBases(VirtualFrame frame, PythonClass cls, PTuple value,
baseClasses[i] = (PythonAbstractClass) a[i];
}
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_TUPLE_OF_CLASSES_NOT_P, getName.execute(inliningTarget, cls), "__bases__", a[i]);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_TUPLE_OF_CLASSES_NOT_P, getName.execute(inliningTarget, cls), "__bases__", a[i]);
}
}
@@ -829,7 +834,7 @@ static Object setBases(VirtualFrame frame, PythonClass cls, PTuple value,
Object oldBase = getBase.execute(inliningTarget, cls);
checkCompatibleForAssigment.execute(frame, oldBase, newBestBase);
- cls.setBases(newBestBase, baseClasses);
+ cls.setBases(inliningTarget, newBestBase, baseClasses);
SpecialMethodSlot.reinitializeSpecialMethodSlots(cls, PythonLanguage.get(inliningTarget));
TpSlots.updateAllSlots(cls);
@@ -855,14 +860,14 @@ private static boolean typeIsSubtypeBaseChain(Node inliningTarget, Object a, Obj
@Specialization(guards = "!isPTuple(value)")
static Object setObject(@SuppressWarnings("unused") PythonClass cls, @SuppressWarnings("unused") Object value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CAN_ONLY_ASSIGN_S_TO_S_S_NOT_P, "tuple", GetNameNode.executeUncached(cls), "__bases__", value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CAN_ONLY_ASSIGN_S_TO_S_S_NOT_P, "tuple", GetNameNode.executeUncached(cls), "__bases__", value);
}
@Specialization
static Object setBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarnings("unused") Object value,
- @Shared @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___BASES__, cls);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___BASES__, cls);
}
}
@@ -953,9 +958,9 @@ boolean isInstance(VirtualFrame frame, Object cls, Object instance,
@Cached InlinedConditionProfile typeErrorProfile,
@Cached AbstractObjectIsSubclassNode abstractIsSubclassNode,
@Cached AbstractObjectGetBasesNode getBasesNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (typeErrorProfile.profile(inliningTarget, getBasesNode.execute(frame, cls) == null)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ISINSTANCE_ARG_2_MUST_BE_TYPE_OR_TUPLE_OF_TYPE, instance);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ISINSTANCE_ARG_2_MUST_BE_TYPE_OR_TUPLE_OF_TYPE, instance);
}
PythonObject instanceClass = getInstanceClassAttr(frame, instance);
@@ -985,7 +990,7 @@ static boolean doObjectObject(VirtualFrame frame, Object cls, Object derived,
@Cached PyTupleCheckNode tupleCheck,
@Cached TypeNodes.IsTypeNode isClsTypeNode,
@Cached TypeNodes.IsTypeNode isDerivedTypeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isSameTypeNode.execute(inliningTarget, cls, derived)) {
return true;
}
@@ -995,10 +1000,10 @@ static boolean doObjectObject(VirtualFrame frame, Object cls, Object derived,
return isSubtypeNode.execute(frame, derived, cls);
}
if (!checkClass(frame, inliningTarget, derived, getBasesAttrNode, tupleCheck, isAttrErrorProfile)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_D_MUST_BE_S, "issubclass()", 1, "class");
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_D_MUST_BE_S, "issubclass()", 1, "class");
}
if (!checkClass(frame, inliningTarget, cls, getBasesAttrNode, tupleCheck, isAttrErrorProfile)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ISSUBCLASS_MUST_BE_CLASS_OR_TUPLE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ISSUBCLASS_MUST_BE_CLASS_OR_TUPLE);
}
return false;
}
@@ -1056,15 +1061,15 @@ abstract static class CheckSetSpecialTypeAttrNode extends Node {
@Specialization
static void check(Node inliningTarget, Object type, Object value, TruffleString name,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached(inline = false) GetTypeFlagsNode getTypeFlagsNode,
@Cached SysModuleBuiltins.AuditNode auditNode) {
if (PGuards.isKindOfBuiltinClass(type) || (getTypeFlagsNode.execute(type) & TypeFlags.IMMUTABLETYPE) != 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, name, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, name, type);
}
if (value == DescriptorDeleteMarker.INSTANCE) {
// Sic, it's not immutable, but CPython has this message
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_DELETE_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, name, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_DELETE_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, name, type);
}
auditNode.audit(inliningTarget, "object.__setattr__", type, name, value);
}
@@ -1136,16 +1141,16 @@ static Object setName(VirtualFrame frame, Object cls, Object value,
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfCodePointNode indexOfCodePointNode,
@Cached SetNameInnerNode innerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
check.execute(inliningTarget, cls, value, T___NAME__);
TruffleString string;
try {
string = castToTruffleStringNode.execute(inliningTarget, value);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_ASSIGN_S_TO_P_S_NOT_P, "string", cls, T___NAME__, value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_ASSIGN_S_TO_P_S_NOT_P, "string", cls, T___NAME__, value);
}
if (indexOfCodePointNode.execute(string, 0, 0, codePointLengthNode.execute(string, TS_ENCODING), TS_ENCODING) >= 0) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.TYPE_NAME_NO_NULL_CHARS);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.TYPE_NAME_NO_NULL_CHARS);
}
if (!isValidNode.execute(string, TS_ENCODING)) {
throw constructAndRaiseNode.get(inliningTarget).raiseUnicodeEncodeError(frame, "utf-8", string, 0, string.codePointLengthUncached(TS_ENCODING), "can't encode classname");
@@ -1173,10 +1178,10 @@ static TruffleString getModuleBuiltin(PythonBuiltinClass cls, @SuppressWarnings(
static Object getModule(PythonClass cls, @SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
@Cached ReadAttributeFromObjectNode readAttrNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object module = readAttrNode.execute(cls, T___MODULE__);
if (module == NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError);
+ throw raiseNode.raise(inliningTarget, AttributeError);
}
return module;
}
@@ -1197,12 +1202,12 @@ static Object getModule(PythonNativeClass cls, @SuppressWarnings("unused") PNone
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.IndexOfCodePointNode indexOfCodePointNode,
@Cached TruffleString.SubstringNode substringNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
// see function 'typeobject.c: type_module'
if ((getFlags.execute(cls) & TypeFlags.HEAPTYPE) != 0) {
Object module = readAttr.execute(cls, T___MODULE__);
if (module == NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError);
+ throw raiseNode.raise(inliningTarget, AttributeError);
}
return module;
} else {
@@ -1222,10 +1227,10 @@ static Object setNative(PythonNativeClass cls, Object value,
@Bind("this") Node inliningTarget,
@Shared @Cached GetTypeFlagsNode getFlags,
@Cached("createForceType()") WriteAttributeToObjectNode writeAttr,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
long flags = getFlags.execute(cls);
if ((flags & TypeFlags.HEAPTYPE) == 0) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SET_N_S, cls, T___MODULE__);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_N_S, cls, T___MODULE__);
}
writeAttr.execute(cls, T___MODULE__, value);
return PNone.NONE;
@@ -1233,14 +1238,14 @@ static Object setNative(PythonNativeClass cls, Object value,
@Specialization(guards = "!isNoValue(value)")
static Object setModuleType(@SuppressWarnings("unused") PythonBuiltinClassType cls, @SuppressWarnings("unused") Object value,
- @Shared("raise") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE, "built-in/extension 'type'");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE, "built-in/extension 'type'");
}
@Specialization(guards = "!isNoValue(value)")
static Object setModuleBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarnings("unused") Object value,
- @Shared("raise") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE, "built-in/extension 'type'");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE, "built-in/extension 'type'");
}
}
@@ -1302,13 +1307,13 @@ static Object setName(Object cls, Object value,
@Cached CheckSetSpecialTypeAttrNode check,
@Cached CastToTruffleStringNode castToStringNode,
@Cached SetQualNameInnerNode innerNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
check.execute(inliningTarget, cls, value, T___QUALNAME__);
TruffleString stringValue;
try {
stringValue = castToStringNode.execute(inliningTarget, value);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_ASSIGN_STR_TO_QUALNAME, cls, value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_ASSIGN_STR_TO_QUALNAME, cls, value);
}
innerNode.execute(inliningTarget, cls, stringValue);
return PNone.NONE;
@@ -1368,11 +1373,11 @@ static Object doGeneric(Object self,
@Bind("this") Node inliningTarget,
@Cached IsTypeNode isTypeNode,
@Cached GetTypeFlagsNode getTypeFlagsNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (PGuards.isClass(inliningTarget, self, isTypeNode)) {
return getTypeFlagsNode.execute(self);
}
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.DESC_FLAG_FOR_TYPE_DOESNT_APPLY_TO_OBJ, self);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.DESC_FLAG_FOR_TYPE_DOESNT_APPLY_TO_OBJ, self);
}
}
@@ -1384,7 +1389,7 @@ static Object get(Object self, @SuppressWarnings("unused") PNone none,
@Bind("this") Node inliningTarget,
@Exclusive @Cached IsSameTypeNode isSameTypeNode,
@Exclusive @Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
// Avoid returning this descriptor
if (!isSameTypeNode.execute(inliningTarget, self, PythonBuiltinClassType.PythonClass)) {
Object result = readAttributeFromObjectNode.execute(self, T___ABSTRACTMETHODS__);
@@ -1392,7 +1397,7 @@ static Object get(Object self, @SuppressWarnings("unused") PNone none,
return result;
}
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, self, T___ABSTRACTMETHODS__);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_N_HAS_NO_ATTR_S, self, T___ABSTRACTMETHODS__);
}
@Specialization(guards = {"!isNoValue(value)", "!isDeleteMarker(value)"})
@@ -1401,13 +1406,13 @@ static Object set(VirtualFrame frame, PythonClass self, Object value,
@Cached PyObjectIsTrueNode isTrueNode,
@Exclusive @Cached IsSameTypeNode isSameTypeNode,
@Exclusive @Cached WriteAttributeToObjectNode writeAttributeToObjectNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (!isSameTypeNode.execute(inliningTarget, self, PythonBuiltinClassType.PythonClass)) {
writeAttributeToObjectNode.execute(self, T___ABSTRACTMETHODS__, value);
self.setAbstractClass(isTrueNode.execute(frame, value));
return PNone.NONE;
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
}
@Specialization(guards = "!isNoValue(value)")
@@ -1416,7 +1421,7 @@ static Object delete(PythonClass self, @SuppressWarnings("unused") DescriptorDel
@Exclusive @Cached IsSameTypeNode isSameTypeNode,
@Exclusive @Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
@Exclusive @Cached WriteAttributeToObjectNode writeAttributeToObjectNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
if (!isSameTypeNode.execute(inliningTarget, self, PythonBuiltinClassType.PythonClass)) {
if (readAttributeFromObjectNode.execute(self, T___ABSTRACTMETHODS__) != NO_VALUE) {
writeAttributeToObjectNode.execute(self, T___ABSTRACTMETHODS__, NO_VALUE);
@@ -1424,14 +1429,14 @@ static Object delete(PythonClass self, @SuppressWarnings("unused") DescriptorDel
return PNone.NONE;
}
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
}
@Fallback
@SuppressWarnings("unused")
static Object set(Object self, Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, AttributeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, J___ABSTRACTMETHODS__, self);
}
}
@@ -1502,7 +1507,7 @@ static Object get(Object self, @SuppressWarnings("unused") Object value,
@Cached InlinedBranchProfile createDict,
@Shared("read") @Cached ReadAttributeFromObjectNode read,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object annotations = read.execute(self, T___ANNOTATIONS__);
if (annotations == NO_VALUE) {
createDict.enter(inliningTarget);
@@ -1510,7 +1515,7 @@ static Object get(Object self, @SuppressWarnings("unused") Object value,
try {
write.execute(self, T___ANNOTATIONS__, annotations);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, self, T___ANNOTATIONS__);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, self, T___ANNOTATIONS__);
}
}
return annotations;
@@ -1521,15 +1526,15 @@ static Object delete(Object self, @SuppressWarnings("unused") Object value,
@Bind("this") Node inliningTarget,
@Shared("read") @Cached ReadAttributeFromObjectNode read,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
Object annotations = read.execute(self, T___ANNOTATIONS__);
try {
write.execute(self, T___ANNOTATIONS__, NO_VALUE);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___ANNOTATIONS__, self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___ANNOTATIONS__, self);
}
if (annotations == NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(AttributeError, new Object[]{T___ANNOTATIONS__});
+ throw raiseNode.raise(inliningTarget, AttributeError, new Object[]{T___ANNOTATIONS__});
}
return PNone.NONE;
}
@@ -1538,11 +1543,11 @@ static Object delete(Object self, @SuppressWarnings("unused") Object value,
static Object set(Object self, Object value,
@Bind("this") Node inliningTarget,
@Shared("write") @Cached WriteAttributeToObjectNode write,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
write.execute(self, T___ANNOTATIONS__, value);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___ANNOTATIONS__, self);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_S_OF_IMMUTABLE_TYPE_N, T___ANNOTATIONS__, self);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
index 122c4f757f..d10697b51f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
@@ -590,7 +590,7 @@ private static MroSequenceStorage doPythonClass(PythonManagedClass obj, Node inl
@InliningCutoff
private static void initializeMRO(PythonManagedClass obj, Node inliningTarget, InlinedConditionProfile isPythonClass, PythonLanguage language) {
- PythonAbstractClass[] mro = ComputeMroNode.doSlowPath(obj, false);
+ PythonAbstractClass[] mro = ComputeMroNode.doSlowPath(inliningTarget, obj, false);
if (isPythonClass.profile(inliningTarget, obj instanceof PythonClass)) {
((PythonClass) obj).setMRO(mro, language);
} else {
@@ -632,7 +632,7 @@ static MroSequenceStorage doNativeClass(Node inliningTarget, PythonNativeClass o
}
}
raiseSystemErrorBranch.enter(inliningTarget);
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.INVALID_MRO_OBJ);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.INVALID_MRO_OBJ);
}
private static Object initializeType(Node inliningTarget, PythonNativeClass obj, CStructAccess.ReadObjectNode getTpMroNode) {
@@ -642,7 +642,7 @@ private static Object initializeType(Node inliningTarget, PythonNativeClass obj,
// call 'PyType_Ready' on the type
int res = (int) PCallCapiFunction.callUncached(NativeCAPISymbol.FUN_PY_TYPE_READY, PythonToNativeNodeGen.getUncached().execute(obj));
if (res < 0) {
- PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.LAZY_INITIALIZATION_FAILED, GetNameNode.executeUncached(obj));
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.LAZY_INITIALIZATION_FAILED, GetNameNode.executeUncached(obj));
}
Object tupleObj = getTpMroNode.readFromObj(obj, PyTypeObject__tp_mro);
@@ -669,7 +669,7 @@ static MroSequenceStorage doSlowPath(Node inliningTarget, Object obj) {
return (MroSequenceStorage) sequenceStorage;
}
}
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.INVALID_MRO_OBJ);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.INVALID_MRO_OBJ);
}
throw new IllegalStateException("unknown type " + obj.getClass().getName());
}
@@ -924,7 +924,7 @@ PythonAbstractClass[] doPythonClass(PythonBuiltinClassType obj) {
@Specialization
static PythonAbstractClass[] doNative(Node inliningTarget, PythonNativeClass obj,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached(inline = false) CStructAccess.ReadObjectNode getTpBasesNode,
@Cached InlinedExactClassProfile resultTypeProfile,
@Cached GetInternalObjectArrayNode toArrayNode) {
@@ -935,10 +935,10 @@ static PythonAbstractClass[] doNative(Node inliningTarget, PythonNativeClass obj
try {
return cast(values, storage);
} catch (ClassCastException e) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.UNSUPPORTED_OBJ_IN, "tp_bases");
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.UNSUPPORTED_OBJ_IN, "tp_bases");
}
}
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.SystemError, ErrorMessages.TYPE_DOES_NOT_PROVIDE_BASES);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.TYPE_DOES_NOT_PROVIDE_BASES);
}
// TODO: get rid of this
@@ -983,7 +983,7 @@ static Object doNative(Node inliningTarget, PythonNativeClass obj,
return result;
}
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.INVALID_BASE_TYPE_OBJ_FOR_CLASS, GetNameNode.doSlowPath(obj), result);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.INVALID_BASE_TYPE_OBJ_FOR_CLASS, GetNameNode.doSlowPath(obj), result);
}
public static GetBaseClassNode getUncached() {
@@ -1013,7 +1013,7 @@ static PythonAbstractClass getOne(PythonAbstractClass[] bases) {
static PythonAbstractClass getBestBase(Node inliningTarget, PythonAbstractClass[] bases,
@Cached(inline = false) IsSubtypeNode isSubTypeNode,
@Cached GetSolidBaseNode getSolidBaseNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
return bestBase(inliningTarget, bases, getSolidBaseNode, isSubTypeNode, raiseNode);
}
@@ -1028,7 +1028,7 @@ static PythonAbstractClass fallback(PythonAbstractClass[] bases) {
/**
* Aims to get as close as possible to typeobject.best_base().
*/
- private static PythonAbstractClass bestBase(Node inliningTarget, PythonAbstractClass[] bases, GetSolidBaseNode getSolidBaseNode, IsSubtypeNode isSubTypeNode, PRaiseNode.Lazy raiseNode)
+ private static PythonAbstractClass bestBase(Node inliningTarget, PythonAbstractClass[] bases, GetSolidBaseNode getSolidBaseNode, IsSubtypeNode isSubTypeNode, PRaiseNode raiseNode)
throws PException {
PythonAbstractClass base = null;
Object winner = null;
@@ -1044,7 +1044,7 @@ private static PythonAbstractClass bestBase(Node inliningTarget, PythonAbstractC
winner = candidate;
base = basei;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MULTIPLE_BASES_LAYOUT_CONFLICT);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MULTIPLE_BASES_LAYOUT_CONFLICT);
}
}
return base;
@@ -1084,7 +1084,6 @@ public abstract static class CheckCompatibleForAssigmentNode extends PNodeWithCo
@Child private LookupAttributeInMRONode lookupSlotsNode;
@Child private LookupAttributeInMRONode lookupNewNode;
@Child private PyObjectSizeNode sizeNode;
- @Child private PRaiseNode raiseNode;
@Child private GetNameNode getTypeNameNode;
@Child private ReadAttributeFromObjectNode readAttr;
@Child private InstancesOfTypeHaveDictNode instancesHaveDictNode;
@@ -1099,7 +1098,7 @@ boolean isCompatible(VirtualFrame frame, Object oldBase, Object newBase,
@Cached GetBaseClassNode getBaseClassNode) {
if (!compatibleForAssignment(frame, inliningTarget, oldBase, newBase, isSameTypeNode, getBaseClassNode)) {
errorSlotsBranch.enter(inliningTarget);
- throw getRaiseNode().raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_S_LAYOUT_DIFFERS_FROM_S, getTypeName(newBase), getTypeName(oldBase));
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CLASS_ASSIGNMENT_S_LAYOUT_DIFFERS_FROM_S, getTypeName(newBase), getTypeName(oldBase));
}
return true;
}
@@ -1246,14 +1245,6 @@ private LookupAttributeInMRONode getLookupNewNode() {
}
return lookupNewNode;
}
-
- private PRaiseNode getRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
}
/**
@@ -1596,17 +1587,17 @@ static final class NotSameTypeException extends ControlFlowException {
public abstract static class ComputeMroNode extends Node {
@TruffleBoundary
- public static PythonAbstractClass[] doSlowPath(PythonAbstractClass cls) {
- return doSlowPath(cls, true);
+ public static PythonAbstractClass[] doSlowPath(Node node, PythonAbstractClass cls) {
+ return doSlowPath(node, cls, true);
}
@TruffleBoundary
- public static PythonAbstractClass[] doSlowPath(PythonAbstractClass cls, boolean invokeMro) {
- return computeMethodResolutionOrder(cls, invokeMro);
+ public static PythonAbstractClass[] doSlowPath(Node node, PythonAbstractClass cls, boolean invokeMro) {
+ return computeMethodResolutionOrder(node, cls, invokeMro);
}
@TruffleBoundary
- static PythonAbstractClass[] invokeMro(PythonAbstractClass cls) {
+ static PythonAbstractClass[] invokeMro(Node node, PythonAbstractClass cls) {
Object type = GetClassNode.executeUncached(cls);
if (IsTypeNode.executeUncached(type) && type instanceof PythonClass) {
Object mroMeth = LookupAttributeInMRONode.Dynamic.getUncached().execute(type, T_MRO);
@@ -1614,20 +1605,20 @@ static PythonAbstractClass[] invokeMro(PythonAbstractClass cls) {
Object mroObj = CallUnaryMethodNode.getUncached().executeObject(mroMeth, cls);
if (mroObj instanceof PSequence mroSequence) {
SequenceStorage mroStorage = mroSequence.getSequenceStorage();
- return mroCheck(cls, GetInternalObjectArrayNode.executeUncached(mroStorage), mroStorage);
+ return mroCheck(node, cls, GetInternalObjectArrayNode.executeUncached(mroStorage), mroStorage);
}
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.OBJ_NOT_ITERABLE, cls);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.OBJ_NOT_ITERABLE, cls);
}
}
return null;
}
- private static PythonAbstractClass[] computeMethodResolutionOrder(PythonAbstractClass cls, boolean invokeMro) {
+ private static PythonAbstractClass[] computeMethodResolutionOrder(Node node, PythonAbstractClass cls, boolean invokeMro) {
CompilerAsserts.neverPartOfCompilation();
PythonAbstractClass[] currentMRO;
if (invokeMro) {
- PythonAbstractClass[] mro = invokeMro(cls);
+ PythonAbstractClass[] mro = invokeMro(node, cls);
if (mro != null) {
return mro;
}
@@ -1656,12 +1647,12 @@ private static PythonAbstractClass[] computeMethodResolutionOrder(PythonAbstract
toMerge[baseClasses.length] = new MROMergeState(baseClasses);
ArrayList mro = new ArrayList<>();
mro.add(cls);
- currentMRO = mergeMROs(toMerge, mro);
+ currentMRO = mergeMROs(node, toMerge, mro);
}
return currentMRO;
}
- private static PythonAbstractClass[] mroCheck(Object cls, Object[] mro, SequenceStorage storage) {
+ private static PythonAbstractClass[] mroCheck(Node node, Object cls, Object[] mro, SequenceStorage storage) {
List resultMro = new ArrayList<>(storage.length());
Object solid = GetSolidBaseNode.executeUncached(cls);
for (int i = 0; i < storage.length(); i++) {
@@ -1670,17 +1661,17 @@ private static PythonAbstractClass[] mroCheck(Object cls, Object[] mro, Sequence
continue;
}
if (!IsTypeNode.executeUncached(object)) {
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.S_RETURNED_NON_CLASS, "mro()", object);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.S_RETURNED_NON_CLASS, "mro()", object);
}
if (!IsSubtypeNode.getUncached().execute(solid, GetSolidBaseNode.executeUncached(object))) {
- throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.S_RETURNED_BASE_WITH_UNSUITABLE_LAYOUT, "mro()", object);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.S_RETURNED_BASE_WITH_UNSUITABLE_LAYOUT, "mro()", object);
}
resultMro.add((PythonAbstractClass) object);
}
return resultMro.toArray(new PythonAbstractClass[resultMro.size()]);
}
- private static PythonAbstractClass[] mergeMROs(MROMergeState[] toMerge, List mro) {
+ private static PythonAbstractClass[] mergeMROs(Node node, MROMergeState[] toMerge, List mro) {
int idx;
scan: for (idx = 0; idx < toMerge.length; idx++) {
if (toMerge[idx].isMerged()) {
@@ -1719,7 +1710,7 @@ private static PythonAbstractClass[] mergeMROs(MROMergeState[] toMerge, List= 0) {
- throw raise.raise(PythonBuiltinClassType.ValueError, ErrorMessages.TYPE_NAME_NO_NULL_CHARS);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.TYPE_NAME_NO_NULL_CHARS);
}
// 1.) create class, but avoid calling mro method - it might try to access __dict__ so
@@ -2168,7 +2159,7 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
}
// 3.) invoke metaclass mro() method
- pythonClass.invokeMro();
+ pythonClass.invokeMro(inliningTarget);
// CPython masks the __hash__ method with None when __eq__ is overriden, but __hash__ is
// not
@@ -2213,7 +2204,7 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
int slotlen = slotsStorage.length();
if (slotlen > 0 && hasItemSize) {
- throw raise.raise(TypeError, ErrorMessages.NONEMPTY_SLOTS_NOT_ALLOWED_FOR_SUBTYPE_OF_S, base);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.NONEMPTY_SLOTS_NOT_ALLOWED_FOR_SUBTYPE_OF_S, base);
}
for (int i = 0; i < slotlen; i++) {
@@ -2223,20 +2214,20 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
if (stringCheck.execute(inliningTarget, element)) {
slotName = castToStringNode.execute(inliningTarget, element);
if (!(boolean) isIdentifier.execute(frame, slotName)) {
- throw raise.raise(TypeError, ErrorMessages.SLOTS_MUST_BE_IDENTIFIERS);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SLOTS_MUST_BE_IDENTIFIERS);
}
} else {
- throw raise.raise(TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "__slots__ items", element);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_STRINGS_NOT_P, "__slots__ items", element);
}
if (equalNode.execute(slotName, T___DICT__, TS_ENCODING)) {
if (!ctx.mayAddDict || ctx.addDict) {
- throw raise.raise(TypeError, ErrorMessages.DICT_SLOT_DISALLOWED_WE_GOT_ONE);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.DICT_SLOT_DISALLOWED_WE_GOT_ONE);
}
ctx.addDict = true;
addDictDescrAttribute(basesArray, pythonClass, language);
} else if (equalNode.execute(slotName, T___WEAKREF__, TS_ENCODING)) {
if (!ctx.mayAddWeak || ctx.addWeak) {
- throw raise.raise(TypeError, ErrorMessages.WEAKREF_SLOT_DISALLOWED_WE_GOT_ONE);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.WEAKREF_SLOT_DISALLOWED_WE_GOT_ONE);
}
ctx.addWeak = true;
}
@@ -2478,7 +2469,7 @@ private static void copyDictSlots(VirtualFrame frame, Node inliningTarget, Pytho
pythonClass.setQualName(castToStringNode.execute(inliningTarget, value));
ctx.qualnameSet = true;
} catch (CannotCastException e) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_S_NOT_P, "type __qualname__", "str", value);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MUST_BE_S_NOT_P, "type __qualname__", "str", value);
}
continue;
}
@@ -2517,7 +2508,7 @@ private static TruffleString[] copySlots(Node inliningTarget, TypeNewContext ctx
try {
slotName = PythonUtils.mangleName(className, slotName);
} catch (OutOfMemoryError e) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.PRIVATE_IDENTIFIER_TOO_LARGE_TO_BE_MANGLED);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.PRIVATE_IDENTIFIER_TOO_LARGE_TO_BE_MANGLED);
}
if (slotName == null) {
return null;
@@ -2529,7 +2520,7 @@ private static TruffleString[] copySlots(Node inliningTarget, TypeNewContext ctx
if (!T___CLASSCELL__.equalsUncached(slotName, TS_ENCODING) && !T___QUALNAME__.equalsUncached(slotName, TS_ENCODING) &&
HashingStorageGetItem.hasKeyUncached(namespace.getDictStorage(), slotName)) {
// __qualname__ and __classcell__ will be deleted later
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.S_S_CONFLICTS_WITH_CLASS_VARIABLE, slotName, "__slots__");
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.S_S_CONFLICTS_WITH_CLASS_VARIABLE, slotName, "__slots__");
}
j++;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java
index 52dc42ff18..8ff5790f59 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -73,7 +73,6 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.RootCallTarget;
@@ -87,6 +86,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -152,7 +152,7 @@ public void initialize(PythonLanguage language) {
static final class DescrGetWrapperNode extends PythonTernaryBuiltinNode {
private final ConditionProfile objIsNoneProfile = ConditionProfile.create();
private final ConditionProfile typeIsNoneProfile = ConditionProfile.create();
- @Child private PRaiseNode raiseNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
@Child private DescrGetBuiltinNode wrapped;
DescrGetWrapperNode(DescrGetBuiltinNode wrapped) {
@@ -168,11 +168,8 @@ public Object execute(VirtualFrame frame, Object self, Object objIn, Object type
Object obj = normalizeNone(objIsNoneProfile, objIn);
Object type = normalizeNone(typeIsNoneProfile, typeIn);
if (obj == PNone.NO_VALUE && type == PNone.NO_VALUE) {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GET_NONE_NONE_IS_INVALID);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.GET_NONE_NONE_IS_INVALID);
}
return wrapped.execute(frame, self, obj, type);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java
index b336adedd6..3a80efeb55 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -210,8 +210,8 @@ static void callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative slo
}
}
- private static PException raiseAttributeError(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString attrName) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, attrName);
+ private static PException raiseAttributeError(Node inliningTarget, PRaiseNode raiseNode, TruffleString attrName) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, attrName);
}
@GenerateInline(inlineByDefault = true)
@@ -241,7 +241,7 @@ static void callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused") Tp
@Specialization(guards = "!isNoValue(value)")
static void callPythonSet(VirtualFrame frame, Node inliningTarget, TpSlotDescrSetPython slot, Object self, Object obj, Object value,
@Cached TernaryPythonSlotDispatcherNode dispatcherNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object callable = slot.getSetCallable();
if (callable == null) {
throw raiseAttributeError(inliningTarget, raiseNode, T___SET__);
@@ -253,7 +253,7 @@ static void callPythonSet(VirtualFrame frame, Node inliningTarget, TpSlotDescrSe
@InliningCutoff
static void callPythonDel(VirtualFrame frame, Node inliningTarget, TpSlotDescrSetPython slot, Object self, Object obj, @SuppressWarnings("unused") Object value,
@Cached BinaryPythonSlotDispatcherNode dispatcherNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object callable = slot.getDelCallable();
if (callable == null) {
throw raiseAttributeError(inliningTarget, raiseNode, T___DEL__);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java
index 982f7127e7..9f0d8244b3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java
@@ -152,7 +152,7 @@ static boolean doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
@Bind("this") Node inliningTarget,
@Cached UnaryPythonSlotDispatcherNode dispatcherNode,
@Cached PyBoolCheckNode pyBoolCheckNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyObjectIsTrueNode pyObjectIsTrueNode) {
// See CPython: slot_nb_bool
// TODO: it is not clear to me why CPython lookups __len__ in the slot wrapper although
@@ -160,7 +160,7 @@ static boolean doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
// __len__. We ignore the __len__ lookup for now.
Object result = dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.getType(), self);
if (!pyBoolCheckNode.execute(inliningTarget, result)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BOOL_SHOULD_RETURN_BOOL, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BOOL_SHOULD_RETURN_BOOL, result);
}
return pyObjectIsTrueNode.execute(frame, result);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java
index faca264b47..12e49e7e98 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -66,7 +66,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.util.CastToJavaIntLossyNode;
import com.oracle.graal.python.runtime.ExecutionContext.CallContext;
@@ -175,7 +174,7 @@ static int callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative
@Exclusive @Cached GetThreadStateNode getThreadStateNode,
@Cached(inline = false) PythonToNativeNode toNativeNode,
@Exclusive @Cached ExternalFunctionInvokeNode externalInvokeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached(inline = false) CheckPrimitiveFunctionResultNode checkResultNode) {
PythonContext ctx = PythonContext.get(inliningTarget);
PythonThreadState state = getThreadStateNode.execute(inliningTarget, ctx);
@@ -192,7 +191,7 @@ static int callNative(VirtualFrame frame, Node inliningTarget, TpSlotHPyNative s
@Exclusive @Cached GetThreadStateNode getThreadStateNode,
@Cached(inline = false) HPyAsHandleNode toNativeNode,
@Exclusive @Cached ExternalFunctionInvokeNode externalInvokeNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached(inline = false) CheckPrimitiveFunctionResultNode checkResultNode) {
PythonContext ctx = PythonContext.get(inliningTarget);
PythonThreadState state = getThreadStateNode.execute(inliningTarget, ctx);
@@ -205,8 +204,8 @@ static int callNative(VirtualFrame frame, Node inliningTarget, TpSlotHPyNative s
}
@InliningCutoff
- private static void raiseOverflow(Node inliningTarget, Lazy raiseNode, long l) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, l);
+ private static void raiseOverflow(Node inliningTarget, PRaiseNode raiseNode, long l) {
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, l);
}
@Specialization(replaces = "callCachedBuiltin")
@@ -231,7 +230,7 @@ static int callGenericComplexBuiltin(VirtualFrame frame, Node inliningTarget, Tp
static int callHPy(VirtualFrame frame, Node inliningTarget, TpSlotNative slot, Object self,
@Cached GetThreadStateNode getThreadStateNode,
@Cached UnaryHPySlotDispatcherNode hpyDispatcher,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached(inline = false) CheckPrimitiveFunctionResultNode checkResultNode) {
PythonContext ctx = PythonContext.get(inliningTarget);
PythonThreadState state = getThreadStateNode.execute(inliningTarget, ctx);
@@ -257,7 +256,7 @@ static int doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
@Bind("this") Node inliningTarget,
@Cached UnaryPythonSlotDispatcherNode dispatcherNode,
@Cached InlinedBranchProfile genericCheck,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyNumberIndexNode indexNode,
@Cached CastToJavaIntLossyNode castLossy,
@Cached PyNumberAsSizeNode asSizeNode) {
@@ -274,7 +273,7 @@ static int doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
return convertAndCheckLen(frame, inliningTarget, result, indexNode, castLossy, asSizeNode, raiseNode);
}
- static int checkLen(Node inliningTarget, PRaiseNode.Lazy raiseNode, int len) {
+ static int checkLen(Node inliningTarget, PRaiseNode raiseNode, int len) {
if (len < 0) {
raiseLenGt0(inliningTarget, raiseNode);
}
@@ -282,12 +281,12 @@ static int checkLen(Node inliningTarget, PRaiseNode.Lazy raiseNode, int len) {
}
@InliningCutoff
- private static void raiseLenGt0(Node inliningTarget, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.LEN_SHOULD_RETURN_GT_ZERO);
+ private static void raiseLenGt0(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.LEN_SHOULD_RETURN_GT_ZERO);
}
public static int convertAndCheckLen(VirtualFrame frame, Node inliningTarget, Object result, PyNumberIndexNode indexNode,
- CastToJavaIntLossyNode castLossy, PyNumberAsSizeNode asSizeNode, PRaiseNode.Lazy raiseNode) {
+ CastToJavaIntLossyNode castLossy, PyNumberAsSizeNode asSizeNode, PRaiseNode raiseNode) {
int len;
Object index = indexNode.execute(frame, inliningTarget, result);
try {
@@ -305,7 +304,7 @@ public static int convertAndCheckLen(VirtualFrame frame, Node inliningTarget, Ob
}
@InliningCutoff
- private static PException checkNegative(Node inliningTarget, CastToJavaIntLossyNode castLossy, Lazy raiseNode, PException e, Object index) {
+ private static PException checkNegative(Node inliningTarget, CastToJavaIntLossyNode castLossy, PRaiseNode raiseNode, PException e, Object index) {
int len;
len = castLossy.execute(inliningTarget, index);
checkLen(inliningTarget, raiseNode, len);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java
index 5225165777..f1d4f8ada2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java
@@ -237,7 +237,7 @@ static void callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused") Tp
@Specialization(guards = "!isNoValue(value)")
static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotMpAssSubscriptPython slot, Object self, Object key, Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached TernaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getSetitem();
if (callable == null) {
@@ -249,7 +249,7 @@ static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotM
@Specialization(guards = "isNoValue(value)")
@InliningCutoff
static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotMpAssSubscriptPython slot, Object self, Object key, @SuppressWarnings("unused") Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached BinaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getDelitem();
if (callable == null) {
@@ -259,8 +259,8 @@ static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotM
}
@InliningCutoff
- private static PException raiseAttributeError(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString attrName) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, attrName);
+ private static PException raiseAttributeError(Node inliningTarget, PRaiseNode raiseNode, TruffleString attrName) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, attrName);
}
@Specialization(replaces = "callCachedBuiltin")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java
index 910745cf17..a1a3a31715 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java
@@ -318,7 +318,7 @@ static void callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused") Tp
@Specialization(guards = "!isNoValue(value)")
static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotSetAttrPython slot, Object self, Object name, Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached TernaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getSetattr();
if (callable == null) {
@@ -330,7 +330,7 @@ static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotS
@Specialization(guards = "isNoValue(value)")
@InliningCutoff
static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotSetAttrPython slot, Object self, Object name, @SuppressWarnings("unused") Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached BinaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getDelattr();
if (callable == null) {
@@ -340,8 +340,8 @@ static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotS
}
@InliningCutoff
- private static PException raiseAttributeError(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString attrName) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, attrName);
+ private static PException raiseAttributeError(Node inliningTarget, PRaiseNode raiseNode, TruffleString attrName) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, attrName);
}
@Specialization(replaces = "callCachedBuiltin")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java
index 02e951b321..873f81a75e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java
@@ -314,7 +314,7 @@ static void callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused") Tp
@Specialization(guards = "!isNoValue(value)")
static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotSqAssItemPython slot, Object self, int key, Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached TernaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getSetitem();
if (callable == null) {
@@ -326,7 +326,7 @@ static void callPythonSimpleSet(VirtualFrame frame, Node inliningTarget, TpSlotS
@Specialization(guards = "isNoValue(value)")
@InliningCutoff
static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotSqAssItemPython slot, Object self, int key, @SuppressWarnings("unused") Object value,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached BinaryPythonSlotDispatcherNode callPythonFun) {
Object callable = slot.getDelitem();
if (callable == null) {
@@ -336,8 +336,8 @@ static void callPythonSimpleDel(VirtualFrame frame, Node inliningTarget, TpSlotS
}
@InliningCutoff
- private static PException raiseAttributeError(Node inliningTarget, PRaiseNode.Lazy raiseNode, TruffleString attrName) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.AttributeError, attrName);
+ private static PException raiseAttributeError(Node inliningTarget, PRaiseNode raiseNode, TruffleString attrName) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, attrName);
}
@Specialization(replaces = "callCachedBuiltin")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
index af05abce04..f4c492f342 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasBuiltins.java
@@ -348,8 +348,8 @@ abstract static class InstanceCheckNode extends PythonBinaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object check(PGenericAlias self, Object other,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ISINSTANCE_ARG_2_CANNOT_BE_A_PARAMETERIZED_GENERIC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ISINSTANCE_ARG_2_CANNOT_BE_A_PARAMETERIZED_GENERIC);
}
}
@@ -359,8 +359,8 @@ abstract static class SubclassCheckNode extends PythonBinaryBuiltinNode {
@Specialization
@SuppressWarnings("unused")
static Object check(PGenericAlias self, Object other,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.ISSUBCLASS_ARG_2_CANNOT_BE_A_PARAMETERIZED_GENERIC);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.ISSUBCLASS_ARG_2_CANNOT_BE_A_PARAMETERIZED_GENERIC);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
index 511f48bce1..bba33da549 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericAliasIteratorBuiltins.java
@@ -78,10 +78,11 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
abstract static class NextNode extends PythonUnaryBuiltinNode {
@Specialization
static Object next(PGenericAliasIterator self,
+ @Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode,
@Bind PythonLanguage language) {
if (self.isExhausted()) {
- throw raiseNode.raise(PythonBuiltinClassType.StopIteration);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
}
PGenericAlias alias = self.getObj();
PGenericAlias starredAlias = PFactory.createGenericAlias(language, alias.getOrigin(), alias.getArgs(), true);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
index f3429c434f..cd265a0b03 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/GenericTypeNodes.java
@@ -268,7 +268,7 @@ static Object[] subsParameters(Node node, Object self, PTuple args, PTuple param
SequenceStorage paramsStorage = parameters.getSequenceStorage();
int nparams = paramsStorage.length();
if (nparams == 0) {
- throw PRaiseNode.raiseUncached(node, TypeError, ErrorMessages.S_IS_NOT_A_GENERIC_CLASS, PyObjectReprAsTruffleStringNode.executeUncached(self));
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.S_IS_NOT_A_GENERIC_CLASS, PyObjectReprAsTruffleStringNode.executeUncached(self));
}
Object[] argitems = unpackArgs(item);
for (int i = 0; i < nparams; i++) {
@@ -280,9 +280,8 @@ static Object[] subsParameters(Node node, Object self, PTuple args, PTuple param
}
}
if (argitems.length != nparams) {
- throw PRaiseNode.raiseUncached(node, TypeError, ErrorMessages.TOO_S_ARGUMENTS_FOR_S_ACTUAL_D_EXPECTED_D,
- argitems.length > nparams ? "many" : "few", PyObjectReprAsTruffleStringNode.executeUncached(self),
- argitems.length, nparams);
+ throw PRaiseNode.raiseStatic(node, TypeError, ErrorMessages.TOO_S_ARGUMENTS_FOR_S_ACTUAL_D_EXPECTED_D, argitems.length > nparams ? "many" : "few",
+ PyObjectReprAsTruffleStringNode.executeUncached(self), argitems.length, nparams);
}
SequenceStorage argsStorage = args.getSequenceStorage();
List newargs = new ArrayList<>(argsStorage.length());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
index 2f9632bc54..f0e7343f7b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
@@ -219,13 +219,13 @@ static boolean check(VirtualFrame frame, PUnionType self, Object other,
@Bind("this") Node inliningTarget,
@Cached SequenceStorageNodes.GetItemScalarNode getItem,
@Cached BuiltinFunctions.IsInstanceNode isInstanceNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
SequenceStorage argsStorage = self.getArgs().getSequenceStorage();
boolean result = false;
for (int i = 0; i < argsStorage.length(); i++) {
Object arg = getItem.execute(inliningTarget, argsStorage, i);
if (arg instanceof PGenericAlias) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ISINSTANCE_ARG_2_CANNOT_CONTAIN_A_PARAMETERIZED_GENERIC);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ISINSTANCE_ARG_2_CANNOT_CONTAIN_A_PARAMETERIZED_GENERIC);
}
if (!result) {
result = isInstanceNode.executeWith(frame, other, arg);
@@ -245,16 +245,16 @@ static boolean check(VirtualFrame frame, PUnionType self, Object other,
@Cached TypeNodes.IsTypeNode isTypeNode,
@Cached SequenceStorageNodes.GetItemScalarNode getItem,
@Cached BuiltinFunctions.IsSubClassNode isSubClassNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isTypeNode.execute(inliningTarget, other)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ISSUBCLASS_ARG_1_MUST_BE_A_CLASS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ISSUBCLASS_ARG_1_MUST_BE_A_CLASS);
}
SequenceStorage argsStorage = self.getArgs().getSequenceStorage();
boolean result = false;
for (int i = 0; i < argsStorage.length(); i++) {
Object arg = getItem.execute(inliningTarget, argsStorage, i);
if (arg instanceof PGenericAlias) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ISSUBCLASS_ARG_2_CANNOT_CONTAIN_A_PARAMETERIZED_GENERIC);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ISSUBCLASS_ARG_2_CANNOT_CONTAIN_A_PARAMETERIZED_GENERIC);
}
if (!result) {
result = isSubClassNode.executeWith(frame, other, arg);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java
index a9f29ef5fb..6e3a92b444 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -58,6 +58,7 @@
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
+import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.strings.TruffleString;
@@ -604,15 +605,15 @@ private static ArrayList popStack(ArrayList blocks) {
}
// returns null if the jump is fine
- public String checkJump(List> stackElems, int from, int to) {
+ public String checkJump(Node node, List> stackElems, int from, int to) {
ArrayList blkFrom = stackElems.get(from);
if (blkFrom == null) {
// this should not happen
- PRaiseNode.getUncached().raise(PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, bciToLine(from));
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, bciToLine(from));
}
ArrayList blkTo = stackElems.get(to);
if (blkTo == null) {
- PRaiseNode.getUncached().raise(PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, bciToLine(from));
+ throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, bciToLine(from));
}
if (blkTo.size() > blkFrom.size()) {
return blkTo.get(blkTo.size() - 1).error;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Unparser.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Unparser.java
index 8f8502ff61..5bbd6d1753 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Unparser.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Unparser.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -652,7 +652,7 @@ public Void visit(ExprTy.FormattedValue node) {
conversion = "!s";
break;
default:
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.SystemError, ErrorMessages.UNKNOWN_F_VALUE_CONVERSION_KIND);
+ throw PRaiseNode.raiseStatic(null, PythonBuiltinClassType.SystemError, ErrorMessages.UNKNOWN_F_VALUE_CONVERSION_KIND);
}
appendStr(conversion);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/GetNextNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/GetNextNode.java
index e36648c901..136c62578d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/GetNextNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/GetNextNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -59,6 +59,7 @@
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
+import com.oracle.truffle.api.profiles.BranchProfile;
public abstract class GetNextNode extends PNodeWithContext {
public abstract Object execute(Frame frame, Object iterator);
@@ -78,11 +79,12 @@ public Object execute(Object iterator) {
private static final class GetNextCached extends GetNextNode {
@Child private LookupAndCallUnaryNode nextCall = LookupAndCallUnaryNode.create(SpecialMethodSlot.Next, () -> new NoAttributeHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object receiver) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
}
});
@@ -125,7 +127,7 @@ public Object execute(Frame frame, Object iterator) {
private Object executeImpl(Object iterator) {
Object nextMethod = LookupSpecialMethodSlotNode.getUncached(SpecialMethodSlot.Next).execute(null, GetClassNode.executeUncached(iterator), iterator);
if (nextMethod == PNone.NO_VALUE) {
- throw PRaiseNode.getUncached().raise(PythonErrorType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, iterator, T___NEXT__);
+ throw PRaiseNode.raiseStatic(null, PythonErrorType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, iterator, T___NEXT__);
}
return CallUnaryMethodNode.getUncached().executeObject(nextMethod, iterator);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyArgCheckPositionalNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyArgCheckPositionalNode.java
index dbc3fec985..70fa3f5d5b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyArgCheckPositionalNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyArgCheckPositionalNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -66,16 +66,16 @@ public final boolean execute(Node inliningTarget, TruffleString name, Object[] a
@Specialization
static boolean doGeneric(Node inliningTarget, TruffleString name, int nargs, int min, int max,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
assert min >= 0;
assert min <= max;
if (nargs < min) {
if (name != null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_EXPECTED_SD_ARGS_GOT_D,
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_EXPECTED_SD_ARGS_GOT_D,
name, (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, UNPACKED_TUPLE_SHOULD_HAVE_D_ELEMS,
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, UNPACKED_TUPLE_SHOULD_HAVE_D_ELEMS,
(min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
}
}
@@ -86,10 +86,10 @@ static boolean doGeneric(Node inliningTarget, TruffleString name, int nargs, int
if (nargs > max) {
if (name != null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_EXPECTED_SD_ARGS_GOT_D,
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_EXPECTED_SD_ARGS_GOT_D,
name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, UNPACKED_TUPLE_SHOULD_HAVE_D_ELEMS,
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, UNPACKED_TUPLE_SHOULD_HAVE_D_ELEMS,
(min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyConvertOptionalToSizeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyConvertOptionalToSizeNode.java
index 5fc303b88c..fab20906aa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyConvertOptionalToSizeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyConvertOptionalToSizeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -69,14 +69,14 @@ int doOptional(@SuppressWarnings("unused") PNone value, int defaultValue) {
@Specialization(guards = {"!isNone(value)", "!isNoValue(value)"})
static int doObject(VirtualFrame frame, Node inliningTarget, Object value, @SuppressWarnings("unused") int defaultValue,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode) {
int limit;
if (indexCheckNode.execute(inliningTarget, value)) {
limit = asSizeNode.executeExact(frame, inliningTarget, value);
} else {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, value);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ARG_SHOULD_BE_INT_OR_NONE, value);
}
return limit;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictDelItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictDelItem.java
index 4e65a647d1..db133c06ef 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictDelItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyDictDelItem.java
@@ -68,9 +68,9 @@ public abstract class PyDictDelItem extends Node {
@Specialization
static void delItem(VirtualFrame frame, Node inliningTarget, PDict dict, Object key,
@Cached HashingStorageDelItem delItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!delItem.execute(frame, inliningTarget, dict.getDictStorage(), key, dict)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, new Object[]{key});
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.KeyError, new Object[]{key});
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java
index 5f2d3f6a34..4419f196c0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java
@@ -133,7 +133,7 @@ static double doObject(VirtualFrame frame, Node inliningTarget, Object object,
@Cached PyNumberIndexNode indexNode,
@Cached PyLongAsDoubleNode asDoubleNode,
@Cached HandleFloatResultNode handleFloatResultNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_float() != null) {
@@ -147,7 +147,7 @@ static double doObject(VirtualFrame frame, Node inliningTarget, Object object,
Object index = indexNode.execute(frame, inliningTarget, object);
return asDoubleNode.execute(inliningTarget, index);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MUST_BE_REAL_NUMBER, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_REAL_NUMBER, object);
}
@InliningCutoff
@@ -172,11 +172,11 @@ static double handle(VirtualFrame frame, Object result, Object original,
@Cached IsSubtypeNode resultSubtypeNode,
@Cached CastToJavaDoubleNode cast,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object resultType = resultClassNode.execute(inliningTarget, result);
if (!resultProfile.profileClass(inliningTarget, resultType, PythonBuiltinClassType.PFloat)) {
if (!resultSubtypeNode.execute(resultType, PythonBuiltinClassType.PFloat)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NON_FLOAT, original, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NON_FLOAT, original, result);
} else {
warnNode.warnFormat(frame, null, DeprecationWarning, 1,
ErrorMessages.WARN_P_RETURNED_NON_P, original, T___FLOAT__, "float", result, "float");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatFromString.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatFromString.java
index 87542d43eb..3d4c9b99ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatFromString.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatFromString.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -82,7 +82,7 @@ public abstract class PyFloatFromString extends PNodeWithContext {
static double doString(VirtualFrame frame, Node inliningTarget, TruffleString object,
@Cached(inline = false) TruffleString.ToJavaStringNode toJavaStringNode,
@Shared @Cached PyObjectReprAsTruffleStringNode reprNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
return convertStringToDouble(frame, inliningTarget, toJavaStringNode.execute(object), object, reprNode, raiseNode);
}
@@ -93,7 +93,7 @@ static double doGeneric(VirtualFrame frame, Node inliningTarget, Object object,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary accessLib,
@Cached(inline = false) CastToJavaStringNode cast,
@Shared @Cached PyObjectReprAsTruffleStringNode reprNode,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
String string = null;
try {
string = cast.execute(object);
@@ -117,7 +117,7 @@ static double doGeneric(VirtualFrame frame, Node inliningTarget, Object object,
if (string != null) {
return convertStringToDouble(frame, inliningTarget, string, object, reprNode, raiseNode);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_NUMBER, "float()", object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_NUMBER, "float()", object);
}
@TruffleBoundary(allowInlining = true)
@@ -125,7 +125,7 @@ private static String newString(byte[] bytes, int offset, int length) {
return new String(bytes, offset, length);
}
- private static double convertStringToDouble(VirtualFrame frame, Node inliningTarget, String src, Object origObj, PyObjectReprAsTruffleStringNode reprNode, PRaiseNode.Lazy raiseNode) {
+ private static double convertStringToDouble(VirtualFrame frame, Node inliningTarget, String src, Object origObj, PyObjectReprAsTruffleStringNode reprNode, PRaiseNode raiseNode) {
String str = FloatUtils.removeUnicodeAndUnderscores(src);
// Adapted from CPython's float_from_string_inner
if (str != null) {
@@ -144,9 +144,9 @@ private static double convertStringToDouble(VirtualFrame frame, Node inliningTar
repr = reprNode.execute(frame, inliningTarget, origObj);
} catch (PException e) {
// Failed to format the message. Mirrors CPython behavior when the repr fails
- throw raiseNode.get(inliningTarget).raise(ValueError);
+ throw raiseNode.raise(inliningTarget, ValueError);
}
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.COULD_NOT_CONVERT_STRING_TO_FLOAT, repr);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.COULD_NOT_CONVERT_STRING_TO_FLOAT, repr);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportGetModule.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportGetModule.java
index 309647e411..76e4cfc828 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportGetModule.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyImportGetModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -70,10 +70,10 @@ static Object doGeneric(VirtualFrame frame, Node node, Object name,
@Bind("this") Node inliningTarget,
@Cached InlinedConditionProfile noSysModulesProfile,
@Cached(inline = false) DictBuiltins.GetItemNode getDictItemNode,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
final PDict sysModules = PythonContext.get(node).getSysModules();
if (noSysModulesProfile.profile(inliningTarget, sysModules == null)) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.RuntimeError, UNABLE_TO_GET_S, "sys.modules");
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, UNABLE_TO_GET_S, "sys.modules");
}
return getDictItemNode.execute(frame, sysModules, name);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
index 0c9af9ddc3..a3f0f97ebb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIterNextNode.java
@@ -100,10 +100,10 @@ static Object doGeneric(VirtualFrame frame, Object iterator,
@Cached(parameters = "Next") LookupSpecialMethodSlotNode lookupNext,
@Cached CallUnaryMethodNode callNext,
@Cached IsBuiltinObjectProfile stopIterationProfile,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object nextMethod = lookupNext.execute(frame, getClassNode.execute(inliningTarget, iterator), iterator);
if (nextMethod == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
}
try {
return callNext.executeObject(frame, nextMethod, iterator);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsDoubleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsDoubleNode.java
index 4f4efd8c6b..464655747d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsDoubleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsDoubleNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -97,14 +97,13 @@ static double doPInt(Node inliningTarget, PInt self) {
static double doNative(Node inliningTarget, @SuppressWarnings("unused") PythonAbstractNativeObject self,
@SuppressWarnings("unused") @Cached PyLongCheckNode check) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
}
@Fallback
@InliningCutoff
@SuppressWarnings("unused")
- static double fallback(Node inliningTarget, Object object,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ static double fallback(Node inliningTarget, Object object) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsIntNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsIntNode.java
index c230fe81ab..f4134e8506 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsIntNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsIntNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -45,7 +45,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -81,7 +80,7 @@ static int doInt(int object) {
@Specialization
static int doObject(VirtualFrame frame, Node inliningTarget, Object object,
@Cached PyLongAsLongAndOverflowNode pyLongAsLongAndOverflow,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
long result = pyLongAsLongAndOverflow.execute(frame, inliningTarget, object);
int intResult = (int) result;
@@ -95,7 +94,7 @@ static int doObject(VirtualFrame frame, Node inliningTarget, Object object,
}
@InliningCutoff
- private static PException raiseOverflow(Node inliningTarget, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "Java int");
+ private static PException raiseOverflow(Node inliningTarget, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "Java int");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongNode.java
index 1656ee5464..0e08ac4a5f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -73,11 +73,11 @@ public final long executeCached(Frame frame, Object object) {
@Specialization
static long doObject(VirtualFrame frame, Node inliningTarget, Object object,
@Cached PyLongAsLongAndOverflowNode pyLongAsLongAndOverflow,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return pyLongAsLongAndOverflow.execute(frame, inliningTarget, object);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "Java long");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "Java long");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
index 7ce2c7818b..9ee63ec787 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java
@@ -90,13 +90,13 @@ static Object doFinite(double value,
}
@Specialization(guards = "!isFinite(value)")
- static Object doInfinite(double value,
- @Cached(inline = false) PRaiseNode raiseNode) {
+ static Object doInfinite(Node inliningTarget, double value,
+ @Cached PRaiseNode raiseNode) {
if (Double.isNaN(value)) {
- throw raiseNode.raise(ValueError, ErrorMessages.CANNOT_CONVERT_FLOAT_NAN_TO_INTEGER);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.CANNOT_CONVERT_FLOAT_NAN_TO_INTEGER);
}
assert Double.isInfinite(value);
- throw raiseNode.raise(OverflowError, ErrorMessages.CANNOT_CONVERT_FLOAT_INFINITY_TO_INTEGER);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_CONVERT_FLOAT_INFINITY_TO_INTEGER);
}
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
index 2a543b400a..34f6d556eb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromUnicodeObject.java
@@ -127,17 +127,17 @@ static Object doGeneric(TruffleString numberTs, int base, byte[] originalBytes,
@Cached InlinedBranchProfile invalidBase,
@Cached InlinedBranchProfile notSimpleDecimalLiteralProfile,
@Cached InlinedBranchProfile invalidValueProfile,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached StringNodes.StringReprNode stringReprNode,
@Cached BytesNodes.BytesReprNode bytesReprNode) {
String number = toJavaStringNode.execute(numberTs);
if ((base != 0 && base < 2) || base > 36) {
invalidBase.enter(inliningTarget);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INT_BASE_MUST_BE_2_AND_36_OR_0);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INT_BASE_MUST_BE_2_AND_36_OR_0);
}
notSimpleDecimalLiteralProfile.enter(inliningTarget);
PythonContext context = PythonContext.get(inliningTarget);
- Object value = stringToIntInternal(number, base, context);
+ Object value = stringToIntInternal(inliningTarget, number, base, context);
if (value == null) {
invalidValueProfile.enter(inliningTarget);
Object repr;
@@ -146,15 +146,15 @@ static Object doGeneric(TruffleString numberTs, int base, byte[] originalBytes,
} else {
repr = bytesReprNode.execute(inliningTarget, PFactory.createBytes(context.getLanguage(inliningTarget), originalBytes, originalBytesLen));
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_LITERAL_FOR_INT_WITH_BASE, base, repr);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.INVALID_LITERAL_FOR_INT_WITH_BASE, base, repr);
}
return value;
}
@TruffleBoundary
- private static Object stringToIntInternal(String num, int base, PythonContext context) {
+ private static Object stringToIntInternal(Node inliningTarget, String num, int base, PythonContext context) {
try {
- BigInteger bi = asciiToBigInteger(num, base, context);
+ BigInteger bi = asciiToBigInteger(inliningTarget, num, base, context);
if (bi == null) {
return null;
}
@@ -169,7 +169,7 @@ private static Object stringToIntInternal(String num, int base, PythonContext co
}
@TruffleBoundary
- private static BigInteger asciiToBigInteger(String str, int possibleBase, PythonContext context) throws NumberFormatException {
+ private static BigInteger asciiToBigInteger(Node inliningTarget, String str, int possibleBase, PythonContext context) throws NumberFormatException {
int base = possibleBase;
int b = 0;
int e = str.length();
@@ -239,7 +239,7 @@ private static BigInteger asciiToBigInteger(String str, int possibleBase, Python
}
s = s.replace("_", "");
- checkMaxDigits(context, s.length(), base);
+ checkMaxDigits(inliningTarget, context, s.length(), base);
BigInteger bi;
if (sign == '-') {
@@ -254,11 +254,12 @@ private static BigInteger asciiToBigInteger(String str, int possibleBase, Python
return bi;
}
- private static void checkMaxDigits(PythonContext context, int digits, int base) {
+ private static void checkMaxDigits(Node inliningTarget, PythonContext context, int digits, int base) {
if (digits > SysModuleBuiltins.INT_MAX_STR_DIGITS_THRESHOLD && Integer.bitCount(base) != 1) {
int maxDigits = context.getIntMaxStrDigits();
if (maxDigits > 0 && digits > maxDigits) {
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION_D, maxDigits, digits);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION_D, maxDigits,
+ digits);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
index 9447f3c01a..d9a2ae7cfe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyMemoryViewFromObject.java
@@ -89,7 +89,7 @@ public abstract class PyMemoryViewFromObject extends PNodeWithContext {
@Specialization
static PMemoryView fromMemoryView(PMemoryView object,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
object.checkReleased(inliningTarget, raiseNode);
PythonContext context = PythonContext.get(inliningTarget);
return PFactory.createMemoryView(context.getLanguage(inliningTarget), context, object.getLifecycleManager(), object.getBuffer(), object.getOwner(), object.getLength(),
@@ -110,7 +110,7 @@ static PMemoryView fromPickleBuffer(VirtualFrame frame, PPickleBuffer object,
@Bind("this") Node inliningTarget,
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached PyMemoryViewFromObject recursive,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
/*
* PickleBuffer is just a buffer proxy for other objects, including native objects or other
* memoryviews, we need to process the delegate recursively.
@@ -120,7 +120,7 @@ static PMemoryView fromPickleBuffer(VirtualFrame frame, PPickleBuffer object,
owner = bufferLib.getOwner(object.getView());
}
if (owner == null) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.OP_FORBIDDEN_ON_OBJECT, "PickleBuffer");
}
return recursive.execute(frame, owner);
}
@@ -140,7 +140,7 @@ static PMemoryView fromManaged(VirtualFrame frame, Object object,
@Cached MemoryViewNodes.InitFlagsNode initFlagsNode,
@Cached TruffleString.CodePointLengthNode lengthNode,
@Cached TruffleString.CodePointAtIndexNode atIndexNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object typeObj = getClassNode.execute(inliningTarget, object);
assert typeObj instanceof PythonBuiltinClassType || typeObj instanceof PythonAbstractObject;
PythonAbstractObject type;
@@ -190,7 +190,7 @@ static PMemoryView fromManaged(VirtualFrame frame, Object object,
bufferLib.isReadonly(buffer),
bufferLib.getFormatString(buffer), lengthNode, atIndexNode);
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.MEMORYVIEW_A_BYTES_LIKE_OBJECT_REQUIRED_NOT_P, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MEMORYVIEW_A_BYTES_LIKE_OBJECT_REQUIRED_NOT_P, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAbsoluteNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAbsoluteNode.java
index 8d33936398..9c634f5901 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAbsoluteNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAbsoluteNode.java
@@ -92,13 +92,13 @@ static Object doObject(VirtualFrame frame, Object object,
@Cached GetClassNode getClassNode,
@Cached GetCachedTpSlotsNode getSlots,
@Cached CallSlotUnaryNode callSlot,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_absolute() != null) {
return callSlot.execute(frame, inliningTarget, slots.nb_absolute(), object);
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "abs()", "", object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "abs()", "", object);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 221c0d2270..d14256f4c6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -56,7 +56,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -175,7 +174,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached CallBinaryOp1Node callBinaryOp1Node,
@Cached InlinedBranchProfile hasNbAddResult,
@Cached CallSlotBinaryFuncNode callBinarySlotNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
@@ -196,8 +195,8 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
index 6f8083ce72..a355cc7ddd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -88,7 +88,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_and();
@@ -103,8 +103,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "&", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "&", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAsSizeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAsSizeNode.java
index 4f311bd2dd..483c15d20c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAsSizeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAsSizeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -124,12 +124,12 @@ static int doInt(int object, @SuppressWarnings("unused") Object errorClass) {
@Specialization
public static int doLongExact(Node inliningTarget, long object, PythonBuiltinClassType errorClass,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
int converted = (int) object;
if (object == converted) {
return converted;
}
- throw raiseNode.get(inliningTarget).raise(errorClass, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, object);
+ throw raiseNode.raise(inliningTarget, errorClass, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, object);
}
@Specialization
@@ -157,13 +157,13 @@ abstract static class PyNumberAsSizeObjectNode extends Node {
static int doObjectExact(VirtualFrame frame, Object object, PythonBuiltinClassType errorClass,
@Bind("this") Node inliningTarget,
@Exclusive @Cached PyNumberIndexNode indexNode,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached CastToJavaIntExactNode cast) {
Object index = indexNode.execute(frame, inliningTarget, object);
try {
return cast.execute(inliningTarget, index);
} catch (PException pe) {
- throw raiseNode.get(inliningTarget).raise(errorClass, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, object);
+ throw raiseNode.raise(inliningTarget, errorClass, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, object);
} catch (CannotCastException cannotCastException) {
throw CompilerDirectives.shouldNotReachHere("PyNumberIndexNode didn't return a python integer");
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
index fdf765a769..1b113ff484 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -78,7 +78,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_divmod();
@@ -93,8 +93,8 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "divmod()", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "divmod()", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
index dbce52a051..780808a84f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -116,7 +116,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_floor_divide();
@@ -131,8 +131,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "//", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "//", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberIndexNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberIndexNode.java
index 718c2a9d06..96b8dcd0f4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberIndexNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberIndexNode.java
@@ -104,7 +104,7 @@ static Object doCallIndex(VirtualFrame frame, Node inliningTarget, Object object
@Cached TpSlots.GetCachedTpSlotsNode getSlots,
@Cached CallSlotUnaryNode callIndex,
@Cached(inline = false) IsSubtypeNode isSubtype,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached PyLongCheckExactNode checkNode,
@Cached CheckIndexResultNotInt checkResult,
@Cached PyLongCopy copy) {
@@ -114,7 +114,7 @@ static Object doCallIndex(VirtualFrame frame, Node inliningTarget, Object object
}
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_index() == null) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, object);
}
Object result = callIndex.execute(frame, inliningTarget, slots.nb_index(), object);
if (checkNode.execute(inliningTarget, result)) {
@@ -138,11 +138,11 @@ static Object doGeneric(VirtualFrame frame, Object original, Object result,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached IsSubtypeNode isSubtype,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
@Cached PyLongCopy copy) {
if (!isSubtype.execute(getClassNode.execute(inliningTarget, result), PythonBuiltinClassType.PInt)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, result);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, result);
}
warnNode.warnFormat(frame, null, DeprecationWarning, 1,
ErrorMessages.WARN_P_RETURNED_NON_P, original, T___INDEX__, "int", result, "int");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
index e46d1003e8..7ef7f93f4c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
@@ -80,13 +80,13 @@ public static Object doObject(VirtualFrame frame, Object object,
@Cached GetClassNode getClassNode,
@Cached GetCachedTpSlotsNode getSlots,
@Cached CallSlotUnaryNode callSlot,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_invert() != null) {
return callSlot.execute(frame, inliningTarget, slots.nb_invert(), object);
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "~", object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "~", object);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLongNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLongNode.java
index 2b10b32afb..7023f671ae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLongNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLongNode.java
@@ -166,11 +166,11 @@ static Object doGeneric(VirtualFrame frame, Object original, Object result,
@Bind("this") Node inliningTarget,
@Cached GetClassNode getClassNode,
@Cached IsSubtypeNode isSubtype,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached WarningsModuleBuiltins.WarnNode warnNode,
@Cached PyLongCopy copy) {
if (!isSubtype.execute(getClassNode.execute(inliningTarget, result), PythonBuiltinClassType.PInt)) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.RETURNED_NON_INT, J___INT__, result);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.RETURNED_NON_INT, J___INT__, result);
}
warnNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
ErrorMessages.WARN_P_RETURNED_NON_P, original, J___INT__, "int", result, "int");
@@ -199,7 +199,7 @@ static Object doGeneric(VirtualFrame frame, Object object,
@Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached PyLongFromUnicodeObject fromUnicodeObject,
@Cached LongFromBufferNode fromBufferNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
Object truncMethod = lookup.execute(type, T___TRUNC__);
if (truncMethod != PNone.NO_VALUE) {
@@ -214,7 +214,7 @@ static Object doGeneric(VirtualFrame frame, Object object,
return longCopy.execute(inliningTarget, result);
}
if (!indexCheckNode.execute(inliningTarget, result)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NON_INTEGRAL, J___TRUNC__, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NON_INTEGRAL, J___TRUNC__, result);
}
return indexNode.execute(frame, inliningTarget, result);
}
@@ -228,7 +228,7 @@ static Object doGeneric(VirtualFrame frame, Object object,
return result;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_BYTELIKE_OR_NUMBER, "int()", object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_BYTELIKE_OR_NUMBER, "int()", object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
index 9a7f29497d..5174b5e343 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -96,7 +96,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_lshift();
@@ -111,8 +111,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "<<", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "<<", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
index 2076c14976..7595406b11 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -76,7 +76,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_matrix_multiply();
@@ -91,8 +91,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "@", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "@", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index 78ad860388..784deff635 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -49,7 +49,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -130,7 +129,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Cached CallSlotSizeArgFun callSlotNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
@@ -157,15 +156,15 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
}
private static Object sequenceRepeat(VirtualFrame frame, Node inliningTarget, TpSlot slot, Object seq, Object n,
PyIndexCheckNode indexCheckNode,
PyNumberAsSizeNode asSizeNode,
CallSlotSizeArgFun callSlotNode,
- PRaiseNode.Lazy raiseNode) {
+ PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, n)) {
int count = asSizeNode.execute(frame, inliningTarget, n, PythonBuiltinClassType.OverflowError);
return callSlotNode.execute(frame, inliningTarget, slot, seq, count);
@@ -175,8 +174,8 @@ private static Object sequenceRepeat(VirtualFrame frame, Node inliningTarget, Tp
}
@InliningCutoff
- private static PException raiseNonIntSqMul(Node inliningTarget, Object n, Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, n);
+ private static PException raiseNonIntSqMul(Node inliningTarget, Object n, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, n);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
index a11cae150f..5f0fcddf32 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
@@ -93,13 +93,13 @@ public static Object doObject(VirtualFrame frame, Object object,
@Cached GetClassNode getClassNode,
@Cached GetCachedTpSlotsNode getSlots,
@Cached CallSlotUnaryNode callSlot,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_negative() != null) {
return callSlot.execute(frame, inliningTarget, slots.nb_negative(), object);
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "-", object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "-", object);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
index 29a24b4396..d79c83a043 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -87,7 +87,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_or();
@@ -102,8 +102,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "|", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "|", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
index 9dee19a666..897fc6ae2a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
@@ -75,13 +75,13 @@ public static Object doObject(VirtualFrame frame, Object object,
@Cached GetClassNode getClassNode,
@Cached GetCachedTpSlotsNode getSlots,
@Cached CallSlotUnaryNode callSlot,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
TpSlots slots = getSlots.execute(inliningTarget, type);
if (slots.nb_positive() != null) {
return callSlot.execute(frame, inliningTarget, slots.nb_positive(), object);
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "+", object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary", "+", object);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
index 08567bf55d..fe4a46e0ce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
@@ -81,7 +81,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached GetCachedTpSlotsNode getVSlots,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached CallTernaryOpNode callTernaryOpNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_power();
@@ -94,11 +94,11 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Object z, PRaiseNode.Lazy raiseNode) {
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Object z, PRaiseNode raiseNode) {
if (z == PNone.NONE) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "** or pow()", v, w);
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "** or pow()", v, w);
} else {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, "** or pow()", v, w, z);
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, "** or pow()", v, w, z);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
index 9d1f89d2ef..e8af02f81c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
@@ -47,7 +47,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -93,7 +93,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_remainder();
@@ -108,8 +108,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "%", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "%", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
index cc39873f8d..a4b7d9be6f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
@@ -51,7 +51,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -93,7 +92,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_rshift();
@@ -108,17 +107,17 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
if (v instanceof PBuiltinMethod) {
handlePossiblePrint(inliningTarget, v, w);
}
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, ">>", v, w);
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, ">>", v, w);
}
@TruffleBoundary
private static void handlePossiblePrint(Node inliningTarget, Object v, Object w) {
if (v instanceof PBuiltinMethod method && method.getBuiltinFunction().getName().equalsUncached(T_PRINT, TS_ENCODING)) {
- throw PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P_PRINT, ">>", v, w);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P_PRINT, ">>", v, w);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
index 0711269403..87548bc511 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -122,7 +122,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_subtract();
@@ -137,8 +137,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "-", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "-", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
index f759484415..a4986c6c72 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -105,7 +105,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_true_divide();
@@ -120,8 +120,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "/", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "/", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
index 06c67afdf1..a7de7a2959 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
@@ -46,7 +46,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
+import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -87,7 +87,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached GetCachedTpSlotsNode getWSlots,
@Cached GetClassNode getWClass,
@Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_xor();
@@ -102,8 +102,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "^", v, w);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "^", v, w);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyOSFSPathNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyOSFSPathNode.java
index 9e7c546a56..dd49945815 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyOSFSPathNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyOSFSPathNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -94,17 +94,17 @@ static Object callFspath(VirtualFrame frame, Node inliningTarget, Object object,
@Cached GetClassNode getClassNode,
@Cached LookupSpecialMethodNode.Dynamic lookupFSPath,
@Cached(inline = false) CallUnaryMethodNode callFSPath,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, object);
Object fspathMethod = lookupFSPath.execute(frame, inliningTarget, type, T___FSPATH__, object);
if (fspathMethod == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, object);
}
Object result = callFSPath.executeObject(frame, fspathMethod, object);
assert !isJavaString(result);
if (result instanceof TruffleString || result instanceof PString || result instanceof PBytes) {
return result;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, object, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, object, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsFileDescriptor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsFileDescriptor.java
index c3c9d73083..3efcae5e8c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsFileDescriptor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsFileDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,7 +71,7 @@ public abstract class PyObjectAsFileDescriptor extends PNodeWithContext {
@Specialization
static int doInt(Node inliningTarget, @SuppressWarnings("unused") int object,
- @Exclusive @Cached PRaiseNode.Lazy raise) {
+ @Exclusive @Cached PRaiseNode raise) {
return checkResult(object, inliningTarget, raise);
}
@@ -79,7 +79,7 @@ static int doInt(Node inliningTarget, @SuppressWarnings("unused") int object,
static int doPyLong(VirtualFrame frame, @SuppressWarnings("unused") Node inliningTarget, Object object,
@SuppressWarnings("unused") @Exclusive @Cached PyLongCheckNode longCheckNode,
@Exclusive @Cached PyLongAsIntNode asIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raise) {
+ @Exclusive @Cached PRaiseNode raise) {
return checkResult(asIntNode.execute(frame, inliningTarget, object), inliningTarget, raise);
}
@@ -89,21 +89,21 @@ static int doNotLong(VirtualFrame frame, Node inliningTarget, Object object,
@Cached(inline = false) CallNode callFileno,
@Exclusive @Cached PyLongCheckNode checkResultNode,
@Exclusive @Cached PyLongAsIntNode asIntNode,
- @Exclusive @Cached PRaiseNode.Lazy raise) {
+ @Exclusive @Cached PRaiseNode raise) {
Object filenoMethod = lookupFileno.execute(frame, inliningTarget, object, T_FILENO);
if (filenoMethod != PNone.NO_VALUE) {
Object result = callFileno.execute(frame, filenoMethod);
if (checkResultNode.execute(inliningTarget, result)) {
return checkResult(asIntNode.execute(frame, inliningTarget, result), inliningTarget, raise);
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NON_INTEGER, "fileno()");
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NON_INTEGER, "fileno()");
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_MUST_BE_INT_OR_HAVE_FILENO_METHOD);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.ARG_MUST_BE_INT_OR_HAVE_FILENO_METHOD);
}
- private static int checkResult(int result, Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ private static int checkResult(int result, Node inliningTarget, PRaiseNode raiseNode) {
if (result < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.S_CANNOT_BE_NEGATIVE_INTEGER_D, "file descriptor", result);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.S_CANNOT_BE_NEGATIVE_INTEGER_D, "file descriptor", result);
}
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDelItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDelItem.java
index 2f5bb76803..dc74ce0ebe 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDelItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDelItem.java
@@ -54,6 +54,7 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
@@ -126,8 +127,8 @@ static void doSequence(VirtualFrame frame, Node inliningTarget, Object object, T
@Fallback
@InliningCutoff
static void error(Object object, @SuppressWarnings("unused") TpSlots slots, @SuppressWarnings("unused") Object key,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_DELETION, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_DELETION, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDir.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDir.java
index 2184d0bb60..93f75625cd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDir.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectDir.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,10 +71,10 @@ static PList dir(VirtualFrame frame, Node inliningTarget, Object object,
@Cached(inline = false) ListBuiltins.ListSortNode sortNode,
@Cached(inline = false) ListNodes.ConstructListNode constructListNode,
@Cached(value = "create(T___DIR__)", inline = false) LookupAndCallUnaryNode callDir,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = callDir.executeObject(frame, object);
if (result == PNone.NO_VALUE) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_DOES_NOT_PROVIDE_DIR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_DOES_NOT_PROVIDE_DIR);
}
PList list = constructListNode.execute(frame, result);
sortNode.execute(frame, list);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectFormat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectFormat.java
index c4c295dfea..4f8069bcbb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectFormat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectFormat.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -57,6 +57,7 @@
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.util.PythonUtils;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -120,15 +121,15 @@ static Object doLong(long obj, Object formatSpec) {
// Note: PRaiseNode is @Exclusive to workaround a bug in DSL
@Specialization(guards = "isString(formatSpec)")
- static Object doGeneric(VirtualFrame frame, Object obj, Object formatSpec,
+ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object obj, Object formatSpec,
@Cached(parameters = "Format", inline = false) LookupAndCallBinaryNode callFormat,
- @Exclusive @Cached(inline = false) PRaiseNode raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
Object res = callFormat.executeObject(frame, obj, formatSpec);
if (res == NO_VALUE) {
- throw raiseNode.raise(TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_FORMAT, obj);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_DOESNT_DEFINE_FORMAT, obj);
}
if (!PGuards.isString(res)) {
- throw raiseNode.raise(TypeError, ErrorMessages.S_MUST_RETURN_S_NOT_P, T___FORMAT__, "str", res);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_MUST_RETURN_S_NOT_P, T___FORMAT__, "str", res);
}
return res;
}
@@ -144,8 +145,8 @@ static Object doGenericUncached(VirtualFrame frame, Object obj, Object formatSpe
// Note: PRaiseNode is @Exclusive to workaround a bug in DSL
@Fallback
static Object doNonStringFormat(Object obj, Object formatSpec,
- @Exclusive @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.SystemError, ErrorMessages.S_MUST_BE_S_NOT_P, "Format specifier", "a string", formatSpec);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.S_MUST_BE_S_NOT_P, "Format specifier", "a string", formatSpec);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttr.java
index 1cbd75ed35..d3d27ab8f9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttr.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttr.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -108,7 +108,7 @@ static Object getDynamicAttr(Frame frame, Node inliningTarget, Object receiver,
Object result = PyObjectLookupAttr.readAttributeQuickly(type, slots, receiver, name, codePointLengthNode, codePointAtIndexNode);
if (result != null) {
if (result == PNone.NO_VALUE) {
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
}
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttrO.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttrO.java
index a2e0f0cd42..86d8f6da84 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttrO.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetAttrO.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -84,7 +84,7 @@ static Object getDynamicAttr(Frame frame, Node inliningTarget, Object receiver,
Object result = PyObjectLookupAttr.readAttributeQuickly(type, slots, receiver, tsName, codePointLengthNode, codePointAtIndexNode);
if (result != null) {
if (result == PNone.NO_VALUE) {
- throw PRaiseNode.getUncached().raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
}
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
index fbd4580f62..d995374dc0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java
@@ -157,7 +157,7 @@ static Object tryType(VirtualFrame frame, Node inliningTarget, Object maybeType,
@Cached PyObjectLookupAttr lookupClassGetItem,
@Cached IsBuiltinClassExactProfile isBuiltinClassProfile,
@Cached(inline = false) CallNode callClassGetItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (isTypeNode.execute(inliningTarget, maybeType)) {
Object classGetitem = lookupClassGetItem.execute(frame, inliningTarget, maybeType, T___CLASS_GETITEM__);
if (!(classGetitem instanceof PNone)) {
@@ -167,9 +167,9 @@ static Object tryType(VirtualFrame frame, Node inliningTarget, Object maybeType,
// Special case type[int], but disallow other types so str[int] fails
return PFactory.createGenericAlias(PythonLanguage.get(inliningTarget), maybeType, key);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_NOT_SUBSCRIPTABLE, maybeType);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_NOT_SUBSCRIPTABLE, maybeType);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_NOT_SUBSCRIPTABLE, maybeType);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_NOT_SUBSCRIPTABLE, maybeType);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
index 2b34a90c7a..3c800f40a5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetIter.java
@@ -96,7 +96,7 @@ static Object getIter(Frame frame, Node inliningTarget, Object receiver,
@Cached(parameters = "Iter", inline = false) LookupSpecialMethodSlotNode lookupIter,
@Cached PySequenceCheckNode sequenceCheckNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached(inline = false) CallUnaryMethodNode callIter,
@Cached PyIterCheckNode checkNode) {
Object type = getReceiverClass.execute(inliningTarget, receiver);
@@ -113,11 +113,11 @@ static Object getIter(Frame frame, Node inliningTarget, Object receiver,
} else {
Object result = callIter.executeObject(frame, iterMethod, receiver);
if (!checkNode.execute(inliningTarget, result)) {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NONITER, result);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NONITER, result);
}
return result;
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.OBJ_NOT_ITERABLE, receiver);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java
index 3940bb317b..8b2ce62621 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -120,7 +120,7 @@ static Object getFixedAttr(VirtualFrame frame, Node inliningTarget, Object recei
@Exclusive @Cached GetObjectSlotsNode getSlotsNode,
@Exclusive @Cached CallSlotDescrGet callGetNode,
@Shared("readAttr") @Cached(inline = false) ReadAttributeFromObjectNode readAttr,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached InlinedBranchProfile hasDescr,
@Cached InlinedBranchProfile returnDataDescr,
@Cached InlinedBranchProfile returnAttr,
@@ -163,7 +163,7 @@ static Object getFixedAttr(VirtualFrame frame, Node inliningTarget, Object recei
if (descr != PNone.NO_VALUE) {
return new BoundDescriptor(descr);
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
}
// No explicit branch profiling when we're looking up multiple things
@@ -178,7 +178,7 @@ static Object getDynamicAttr(Frame frame, Node inliningTarget, Object receiver,
@Exclusive @Cached GetObjectSlotsNode getSlotsNode,
@Exclusive @Cached CallSlotDescrGet callGetNode,
@Shared("readAttr") @Cached(inline = false) ReadAttributeFromObjectNode readAttr,
- /* Truffle bug: @Shared("raiseNode") */ @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ /* Truffle bug: @Shared("raiseNode") */ @Exclusive @Cached PRaiseNode raiseNode) {
boolean methodFound = false;
Object descr = lookupNode.execute(lazyClass, name);
TpSlot getMethod = null;
@@ -208,7 +208,7 @@ static Object getDynamicAttr(Frame frame, Node inliningTarget, Object receiver,
if (descr != PNone.NO_VALUE) {
return new BoundDescriptor(descr);
}
- throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
+ throw raiseNode.raise(inliningTarget, AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
}
@Specialization(guards = "isForeignObject(inliningTarget, isForeignObjectNode, receiver)", limit = "1")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java
index 72334ce735..e4af870bd4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -166,7 +166,7 @@ static long hash(VirtualFrame frame, Node inliningTarget, Object object,
@Cached MaybeBindDescriptorNode bindDescriptorNode,
@Cached(inline = false) CallUnaryMethodNode callHash,
@Cached CastUnsignedToJavaLongHashNode cast,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/* This combines the logic from abstract.c:PyObject_Hash and typeobject.c:slot_tp_hash */
Object type = getClassNode.execute(inliningTarget, object);
// We have to do the lookup and bind steps separately to avoid binding possible None
@@ -175,16 +175,16 @@ static long hash(VirtualFrame frame, Node inliningTarget, Object object,
try {
hashDescr = bindDescriptorNode.execute(frame, inliningTarget, hashDescr, object, type);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNHASHABLE_TYPE_P, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNHASHABLE_TYPE_P, object);
}
Object result = callHash.executeObject(frame, hashDescr, object);
try {
return avoidNegative1(cast.execute(inliningTarget, result));
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.HASH_SHOULD_RETURN_INTEGER);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.HASH_SHOULD_RETURN_INTEGER);
}
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNHASHABLE_TYPE_P, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNHASHABLE_TYPE_P, object);
}
public static PyObjectHashNode getUncached() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectReprAsObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectReprAsObjectNode.java
index 8dd2e460cc..640d2abfd4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectReprAsObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectReprAsObjectNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -105,7 +105,7 @@ static Object repr(VirtualFrame frame, Node inliningTarget, Object obj,
@Cached(inline = false) ObjectNodes.DefaultObjectReprNode defaultRepr,
@Cached InlinedConditionProfile isString,
@Cached InlinedConditionProfile isPString,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, obj);
Object reprMethod;
try {
@@ -128,8 +128,8 @@ static Object repr(VirtualFrame frame, Node inliningTarget, Object obj,
}
@InliningCutoff
- private static PException raiseTypeError(Node inliningTarget, Object obj, PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NON_STRING, T___REPR__, obj);
+ private static PException raiseTypeError(Node inliningTarget, Object obj, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NON_STRING, T___REPR__, obj);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectRichCompareBool.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectRichCompareBool.java
index e2091decdc..d7e7e3ccd2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectRichCompareBool.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectRichCompareBool.java
@@ -53,7 +53,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
@@ -121,7 +120,7 @@ protected boolean identityComparisonResult() {
throw CompilerDirectives.shouldNotReachHere("abstract method");
}
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
throw CompilerDirectives.shouldNotReachHere("abstract method");
}
}
@@ -265,7 +264,7 @@ static boolean doGeneric(VirtualFrame frame, Node inliningTarget, Object a, Obje
@Cached(inline = false) CallBinaryMethodNode callMethod,
@Cached(inline = false) CallBinaryMethodNode callReverseMethod,
@Cached PyObjectIsTrueNode isTrueNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (cmp.needsIdentityComparison()) {
if (isNode.execute(a, b)) {
return cmp.identityComparisonResult();
@@ -358,7 +357,7 @@ protected boolean identityComparisonResult() {
}
@Override
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
// Already compared for identity
return false;
}
@@ -443,7 +442,7 @@ protected boolean identityComparisonResult() {
@Override
@SuppressWarnings("unused")
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
// Already compared for identity
return true;
}
@@ -501,8 +500,8 @@ protected SpecialMethodSlot getReverseSlot() {
@Override
@SuppressWarnings("unused")
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<", a, b);
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<", a, b);
}
}
@@ -556,8 +555,8 @@ protected SpecialMethodSlot getReverseSlot() {
}
@Override
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<=", a, b);
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<=", a, b);
}
}
@@ -612,8 +611,8 @@ protected SpecialMethodSlot getReverseSlot() {
}
@Override
- protected boolean doDefault(Node inliningTarget, PRaiseNode.Lazy raiseNode, Object a, Object b) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">", a, b);
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">", a, b);
}
}
@@ -668,8 +667,8 @@ protected SpecialMethodSlot getReverseSlot() {
}
@Override
- protected boolean doDefault(Node inliningTarget, Lazy raiseNode, Object a, Object b) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">=", a, b);
+ protected boolean doDefault(Node inliningTarget, PRaiseNode raiseNode, Object a, Object b) {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, ">=", a, b);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
index f760e83822..36da362ca1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,7 +53,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.CallSlotSetAttrNode;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -104,7 +103,7 @@ public final void delete(Frame frame, Node inliningTarget, Object receiver, Truf
static void setFixedAttr(Frame frame, Node inliningTarget, Object self, @SuppressWarnings("unused") TruffleString name, Object value,
@SuppressWarnings("unused") @Cached("name") TruffleString cachedName,
@Shared @Cached GetObjectSlotsNode getSlotsNode,
- @Shared @Cached PRaiseNode.Lazy raise,
+ @Shared @Cached PRaiseNode raise,
@Shared @Cached CallSlotSetAttrNode callSetAttr) {
assert value != null; // should use PNone.NO_VALUE
TpSlots slots = getSlotsNode.execute(inliningTarget, self);
@@ -119,13 +118,13 @@ static void setFixedAttr(Frame frame, Node inliningTarget, Object self, @Suppres
@InliningCutoff
static void doDynamicAttr(Frame frame, Node inliningTarget, Object self, TruffleString name, Object value,
@Shared @Cached GetObjectSlotsNode getSlotsNode,
- @Shared @Cached PRaiseNode.Lazy raise,
+ @Shared @Cached PRaiseNode raise,
@Shared @Cached CallSlotSetAttrNode callSetAttr) {
setFixedAttr(frame, inliningTarget, self, name, value, name, getSlotsNode, raise, callSetAttr);
}
@InliningCutoff
- static void raiseNoSlotError(Node inliningTarget, Object self, Object name, Object value, Lazy raise, TpSlots slots) {
+ static void raiseNoSlotError(Node inliningTarget, Object self, Object name, Object value, PRaiseNode raise, TpSlots slots) {
TruffleString message;
boolean isDelete = value == PNone.NO_VALUE;
if (slots.combined_tp_getattro_getattr() == null) {
@@ -133,7 +132,7 @@ static void raiseNoSlotError(Node inliningTarget, Object self, Object name, Obje
} else {
message = isDelete ? P_HAS_RO_ATTRS_S_TO_DELETE : P_HAS_RO_ATTRS_S_TO_ASSIGN;
}
- throw raise.get(inliningTarget).raise(TypeError, message, self, name);
+ throw raise.raise(inliningTarget, TypeError, message, self, name);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttrO.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttrO.java
index 11f29f6414..562586b664 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttrO.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttrO.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -117,11 +117,11 @@ public abstract static class PyObjectSetAttrOGeneric extends Node {
static void doIt(Frame frame, Object self, Object nameObj, Object value,
@Bind("this") Node inliningTarget,
@Cached PyUnicodeCheckNode unicodeCheckNode,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached GetObjectSlotsNode getSlotsNode,
@Cached CallSlotSetAttrONode callSetAttr) {
if (!unicodeCheckNode.execute(inliningTarget, nameObj)) {
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ATTR_NAME_MUST_BE_STRING, nameObj);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ATTR_NAME_MUST_BE_STRING, nameObj);
}
assert value != null; // should use PNone.NO_VALUE
TpSlots slots = getSlotsNode.execute(inliningTarget, self);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetItem.java
index 1b5def6586..67e44e2ca2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetItem.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetItem.java
@@ -53,6 +53,7 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
@@ -133,8 +134,8 @@ static void doSequence(VirtualFrame frame, Node inliningTarget, Object object, T
@Fallback
@InliningCutoff
static void error(Object object, @SuppressWarnings("unused") TpSlots slots, @SuppressWarnings("unused") Object key, @SuppressWarnings("unused") Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, object);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeGenericNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeGenericNode.java
index c4fe6172d2..98ed0b50c5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeGenericNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeGenericNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -70,11 +70,11 @@ static int doIt(VirtualFrame frame, Object object,
@Bind("this") Node inliningTarget,
@Cached GetObjectSlotsNode getTpSlotsNode,
@Cached TpSlotLen.CallSlotLenNode callSlotLenNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getTpSlotsNode.execute(inliningTarget, object);
if (slots.combined_sq_mp_length() != null) {
return callSlotLenNode.execute(frame, inliningTarget, slots.combined_sq_mp_length(), object);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_HAS_NO_LEN, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_HAS_NO_LEN, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeNode.java
index c77ef6c297..612f8909b8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSizeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -146,9 +146,9 @@ static int doOthers(VirtualFrame frame, Object object,
return genericNode.execute(frame, object);
}
- static int checkLen(PRaiseNode raiseNode, int len) {
+ static int checkLen(Node inliningTarget, PRaiseNode raiseNode, int len) {
if (len < 0) {
- throw raiseNode.raise(ValueError, ErrorMessages.LEN_SHOULD_RETURN_GT_ZERO);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.LEN_SHOULD_RETURN_GT_ZERO);
}
return len;
}
@@ -167,10 +167,10 @@ public static int convertAndCheckLen(VirtualFrame frame, Node inliningTarget, Ob
* error.
*/
len = castLossy.execute(inliningTarget, index);
- checkLen(raiseNode, len);
+ checkLen(inliningTarget, raiseNode, len);
throw e;
}
- return checkLen(raiseNode, len);
+ return checkLen(inliningTarget, raiseNode, len);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectStrAsObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectStrAsObjectNode.java
index dfb4dfb002..a5b7c3f35e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectStrAsObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectStrAsObjectNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -116,7 +116,7 @@ static Object str(VirtualFrame frame, Node inliningTarget, Object obj,
@Cached(inline = false) CallUnaryMethodNode callStr,
@Cached GetClassNode getResultClassNode,
@Cached(inline = false) IsSubtypeNode isSubtypeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object type = getClassNode.execute(inliningTarget, obj);
Object strDescr = lookupStr.execute(frame, type, obj);
// All our objects should have __str__
@@ -126,7 +126,7 @@ static Object str(VirtualFrame frame, Node inliningTarget, Object obj,
if (result instanceof TruffleString || isSubtypeNode.execute(getResultClassNode.execute(inliningTarget, result), PythonBuiltinClassType.PString)) {
return result;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.RETURNED_NON_STRING, T___STR__, result);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NON_STRING, T___STR__, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
index dc0c42ef60..14c8941b9d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
@@ -120,7 +120,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached InlinedBranchProfile hasNbAddSlot,
@Cached InlinedBranchProfile hasNbAddResult,
@Cached CallSlotBinaryFuncNode callBinarySlotNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
if (slotsV.sq_concat() != null) {
@@ -144,7 +144,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
@InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, PRaiseNode.Lazy raiseNode) {
- return raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, v);
+ private static PException raiseNotSupported(Node inliningTarget, Object v, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, v);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java
index bb92067feb..582aa71259 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java
@@ -87,7 +87,7 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object object, in
@Cached GetObjectSlotsNode getSlotsNode,
@Cached IndexForSqSlotInt indexForSqSlot,
@Cached CallSlotSqAssItemNode callSetItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getSlotsNode.execute(inliningTarget, object);
index = indexForSqSlot.execute(frame, inliningTarget, object, slots, index);
if (slots.sq_ass_item() != null) {
@@ -98,11 +98,11 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object object, in
}
@InliningCutoff
- static PException raiseNotSupported(Object object, Node inliningTarget, PRaiseNode.Lazy raiseNode, TpSlots slots) {
+ static PException raiseNotSupported(Object object, Node inliningTarget, PRaiseNode raiseNode, TpSlots slots) {
TruffleString message = ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_DELETION;
if (slots.mp_subscript() != null) {
message = ErrorMessages.IS_NOT_A_SEQUENCE;
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, message, object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, message, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java
index 33462f56a3..0a5f9164a1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java
@@ -52,7 +52,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
@@ -90,7 +89,7 @@ static Object doGeneric(VirtualFrame frame, Object object, int index,
@Cached GetObjectSlotsNode getSlotsNode,
@Cached IndexForSqSlotInt indexForSqSlot,
@Cached CallSlotSizeArgFun callSqItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getSlotsNode.execute(inliningTarget, object);
index = indexForSqSlot.execute(frame, inliningTarget, object, slots, index);
if (slots.sq_item() != null) {
@@ -101,12 +100,12 @@ static Object doGeneric(VirtualFrame frame, Object object, int index,
}
@InliningCutoff
- private static PException raiseNotSupported(Object object, Node inliningTarget, Lazy raiseNode, TpSlots slots) {
+ private static PException raiseNotSupported(Object object, Node inliningTarget, PRaiseNode raiseNode, TpSlots slots) {
TruffleString message = ErrorMessages.OBJ_DOES_NOT_SUPPORT_INDEXING;
if (slots.mp_subscript() != null) {
message = ErrorMessages.IS_NOT_A_SEQUENCE;
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, message, object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, message, object);
}
@GenerateInline
@@ -153,9 +152,9 @@ static int doGeneric(VirtualFrame frame, Node inliningTarget, Object object, TpS
@Cached PyIndexCheckNode checkNode,
@Cached PyNumberAsSizeNode asSizeNode,
@Exclusive @Cached IndexForSqSlotInt indexForSqSlotInt,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!checkNode.execute(inliningTarget, indexObj)) {
- raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SEQUENCE_INDEX_MUST_BE_INT_NOT_P, indexObj);
+ raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SEQUENCE_INDEX_MUST_BE_INT_NOT_P, indexObj);
}
int index = asSizeNode.executeExact(frame, inliningTarget, indexObj, PythonBuiltinClassType.IndexError);
return indexForSqSlotInt.execute(frame, inliningTarget, object, slots, index);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceIterSearchNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceIterSearchNode.java
index 8d96d229df..b95177f102 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceIterSearchNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceIterSearchNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -91,7 +91,7 @@ public final int execute(Node inliningTarget, Object container, Object key, int
static int search(Frame frame, Node inliningTarget, Object container, Object key, int operation,
@Cached PyObjectGetIter getIter,
@Cached IsBuiltinObjectProfile noIterProfile,
- @Cached PRaiseNode.Lazy raiseNode,
+ @Cached PRaiseNode raiseNode,
@Cached GetClassNode getIterClass,
@Cached(parameters = "Next", inline = false) LookupSpecialMethodSlotNode lookupIternext,
@Cached IsBuiltinObjectProfile noNextProfile,
@@ -104,7 +104,7 @@ static int search(Frame frame, Node inliningTarget, Object container, Object key
iterator = getIter.execute(frame, inliningTarget, container);
} catch (PException e) {
e.expectTypeError(inliningTarget, noIterProfile);
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_CONTAINER, container);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A_CONTAINER, container);
}
Object next = PNone.NO_VALUE;
try {
@@ -113,7 +113,7 @@ static int search(Frame frame, Node inliningTarget, Object container, Object key
e.expect(inliningTarget, PythonBuiltinClassType.AttributeError, noNextProfile);
}
if (next instanceof PNone) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
}
int i = 0;
int n = 0;
@@ -130,7 +130,7 @@ static int search(Frame frame, Node inliningTarget, Object container, Object key
LoopNode.reportLoopCount(inliningTarget, wrapped ? Integer.MAX_VALUE : i + 1);
}
if (wrapped) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.OverflowError, ErrorMessages.INDEX_EXCEEDS_INT);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.OverflowError, ErrorMessages.INDEX_EXCEEDS_INT);
} else {
return i;
}
@@ -147,7 +147,7 @@ static int search(Frame frame, Node inliningTarget, Object container, Object key
LoopNode.reportLoopCount(inliningTarget, wrapped ? Integer.MAX_VALUE : i + 1);
}
if (opProfile.profile(inliningTarget, operation) == PY_ITERSEARCH_INDEX) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.X_NOT_IN_SEQUENCE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.X_NOT_IN_SEQUENCE);
}
return n;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java
index ae6e2e7b1f..aa3ccaab98 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java
@@ -86,7 +86,7 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object object, in
@Cached GetObjectSlotsNode getSlotsNode,
@Cached IndexForSqSlotInt indexForSqSlot,
@Cached CallSlotSqAssItemNode callSetItem,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
TpSlots slots = getSlotsNode.execute(inliningTarget, object);
index = indexForSqSlot.execute(frame, inliningTarget, object, slots, index);
if (slots.sq_ass_item() != null) {
@@ -97,11 +97,11 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object object, in
}
@InliningCutoff
- static PException raiseNotSupported(Object object, Node inliningTarget, PRaiseNode.Lazy raiseNode, TpSlots slots) {
+ static PException raiseNotSupported(Object object, Node inliningTarget, PRaiseNode raiseNode, TpSlots slots) {
TruffleString message = ErrorMessages.OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT;
if (slots.mp_subscript() != null) {
message = ErrorMessages.IS_NOT_A_SEQUENCE;
}
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, message, object);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, message, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java
index 652ec34014..b48b8b0a62 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -56,7 +56,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNode.Lazy;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
@@ -125,7 +124,7 @@ static int doPBytes(PBytesLike object) {
static int doOthers(Frame frame, Node inliningTarget, Object object,
@Cached GetObjectSlotsNode getTpSlotsNode,
@Cached TpSlotLen.CallSlotLenNode callSlotLenNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
TpSlots slots = getTpSlotsNode.execute(inliningTarget, object);
if (slots.sq_length() != null) {
return callSlotLenNode.execute((VirtualFrame) frame, inliningTarget, slots.sq_length(), object);
@@ -134,11 +133,11 @@ static int doOthers(Frame frame, Node inliningTarget, Object object,
}
@InliningCutoff
- private static PException raiseError(Object object, Node inliningTarget, Lazy raiseNode, TpSlots slots) {
+ private static PException raiseError(Object object, Node inliningTarget, PRaiseNode raiseNode, TpSlots slots) {
TruffleString error = ErrorMessages.OBJ_HAS_NO_LEN;
if (slots.mp_length() == null) {
error = ErrorMessages.IS_NOT_A_SEQUENCE;
}
- throw raiseNode.get(inliningTarget).raise(TypeError, error, object);
+ throw raiseNode.raise(inliningTarget, TypeError, error, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
index 629782b3bd..76f2d6e886 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -82,10 +82,10 @@ public enum RoundType {
@Specialization
static long doDouble(Node inliningTarget, double d, RoundType round, long unitToNs,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
// Implements _PyTime_FromDouble, rounding mode (HALF_UP) is hard-coded for now
if (Double.isNaN(d)) {
- throw raiseNode.get(inliningTarget).raise(ValueError, INVALID_VALUE_NAN);
+ throw raiseNode.raise(inliningTarget, ValueError, INVALID_VALUE_NAN);
}
double value = d * unitToNs;
@@ -102,25 +102,25 @@ static long doDouble(Node inliningTarget, double d, RoundType round, long unitTo
break;
}
if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {
- throw raiseTimeOverflow(raiseNode.get(inliningTarget));
+ throw raiseTimeOverflow(inliningTarget, raiseNode);
}
return (long) value;
}
@Specialization
static long doLong(Node inliningTarget, long l, @SuppressWarnings("unused") RoundType round, long unitToNs,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
try {
return PythonUtils.multiplyExact(l, unitToNs);
} catch (OverflowException e) {
- throw raiseTimeOverflow(raiseNode.get(inliningTarget));
+ throw raiseTimeOverflow(inliningTarget, raiseNode);
}
}
@Specialization
static long doOther(VirtualFrame frame, Node inliningTarget, Object value, RoundType round, long unitToNs,
@Cached CastToJavaDoubleNode castToDouble,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Cached PyLongAsLongAndOverflowNode asLongNode) {
try {
return doDouble(inliningTarget, castToDouble.execute(inliningTarget, value), round, unitToNs, raiseNode);
@@ -128,12 +128,12 @@ static long doOther(VirtualFrame frame, Node inliningTarget, Object value, Round
try {
return doLong(inliningTarget, asLongNode.execute(frame, inliningTarget, value), round, unitToNs, raiseNode);
} catch (OverflowException e1) {
- throw raiseTimeOverflow(raiseNode.get(inliningTarget));
+ throw raiseTimeOverflow(inliningTarget, raiseNode);
}
}
}
- private static PException raiseTimeOverflow(PRaiseNode raise) {
- throw raise.raise(PythonBuiltinClassType.OverflowError, TOO_LARGE_TO_CONVERT_TO, "timestamp", "long");
+ private static PException raiseTimeOverflow(Node inliningTarget, PRaiseNode raise) {
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.OverflowError, TOO_LARGE_TO_CONVERT_TO, "timestamp", "long");
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
index 3d8e435398..27cd29be60 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java
@@ -44,6 +44,7 @@
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_FLUSH;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITE;
import static com.oracle.graal.python.nodes.BuiltinNames.T_TRACEBACKLIMIT;
+import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC;
import static com.oracle.graal.python.nodes.StringLiterals.J_NEWLINE;
import static com.oracle.graal.python.nodes.StringLiterals.T_SPACE;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
@@ -56,6 +57,7 @@
import com.oracle.graal.python.PythonFileDetector;
import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.code.PCode;
import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes;
@@ -401,8 +403,8 @@ public void printTraceBack(VirtualFrame frame, PythonModule sys, Object out, PTr
@Specialization(guards = "!isPTraceback(tb)")
@SuppressWarnings("unused")
public void printTraceBack(VirtualFrame frame, PythonModule sys, Object out, Object tb,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raiseBadInternalCall();
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTupleSizeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTupleSizeNode.java
index b90c4c9b89..11dcd453dc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTupleSizeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTupleSizeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,7 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -86,8 +87,8 @@ static int sizeNative(Node inliningTarget, PythonAbstractNativeObject tuple,
@Fallback
@InliningCutoff
static int size(Object obj,
- @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, "PyTuple_Size");
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, BAD_ARG_TO_INTERNAL_FUNC_S, "PyTuple_Size");
}
protected boolean isTupleSubtype(Object obj, Node inliningTarget, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
index 7f33752253..44e1c12f05 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeAsEncodedString.java
@@ -128,7 +128,7 @@ static Object doRegistry(VirtualFrame frame, Node inliningTarget, Object unicode
@Cached InlinedConditionProfile isByteArrayProfile,
@Cached SequenceStorageNodes.CopyNode copyNode,
@Cached(inline = false) WarningsModuleBuiltins.WarnNode warnNode,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@SuppressWarnings("unused") @Shared("ts2js") @Cached(inline = false) TruffleString.ToJavaStringNode toJavaStringNode) {
final Object v = encodeNode.execute(frame, unicode, encoding, errors);
// the normal path
@@ -141,7 +141,7 @@ static Object doRegistry(VirtualFrame frame, Node inliningTarget, Object unicode
return PFactory.createBytes(PythonLanguage.get(inliningTarget), copyNode.execute(inliningTarget, ((PByteArray) v).getSequenceStorage()));
}
- throw raiseNode.get(inliningTarget).raise(TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, v);
+ throw raiseNode.raise(inliningTarget, TypeError, S_ENCODER_RETURNED_P_INSTEAD_OF_BYTES, encoding, v);
}
@Specialization(guards = {"isString(unicode)", "isNoValue(encoding)"})
@@ -153,7 +153,7 @@ static Object doNoEncoding(VirtualFrame frame, Object unicode, @SuppressWarnings
@Specialization(guards = "!isString(unicode)")
@SuppressWarnings("unused")
static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object unicode, Object encoding, Object errors,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raiseBadInternalCall();
+ @Exclusive @Cached PRaiseNode raiseNode) {
+ throw raiseNode.raiseBadInternalCall(inliningTarget);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeDecode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeDecode.java
index 4dac6d3f1a..fc22e2ecae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeDecode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeDecode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -73,10 +73,10 @@ public abstract class PyUnicodeDecode extends PNodeWithContext {
@Specialization(guards = "frame != null")
static Object doFast(VirtualFrame frame, Node inliningTarget, Object object, Object encoding, Object errors,
@Cached(inline = false) CodecsModuleBuiltins.DecodeNode decodeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
final Object unicode = decodeNode.execute(frame, object, encoding, errors);
if (!PGuards.isString(unicode)) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DECODER_S_RETURNED_P_INSTEAD_OF_STR, encoding, unicode);
+ throw raiseNode.raise(inliningTarget, TypeError, DECODER_S_RETURNED_P_INSTEAD_OF_STR, encoding, unicode);
}
return unicode;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFSDecoderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFSDecoderNode.java
index 6f73e45799..e75124026e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFSDecoderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFSDecoderNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -110,7 +110,7 @@ static TruffleString doPathLike(VirtualFrame frame, Object object,
private static TruffleString checkString(Node raisingNode, TruffleString str, TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode) {
if (byteIndexOfCodePointNode.execute(str, 0, 0, str.byteLength(TS_ENCODING), TS_ENCODING) >= 0) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
}
return str;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
index 70cc0d8e18..30858aa95d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java
@@ -57,7 +57,6 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -92,15 +91,15 @@ static Object doBytes(VirtualFrame frame, Node inliningTarget, PBytes object, Ob
@Specialization
@SuppressWarnings("unused")
static Object doString(VirtualFrame frame, TruffleString object, Object encoding, Object errors,
- @Shared @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, DECODING_STR_NOT_SUPPORTED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, DECODING_STR_NOT_SUPPORTED);
}
@Specialization
@SuppressWarnings("unused")
static Object doPString(VirtualFrame frame, PString object, Object encoding, Object errors,
- @Shared @Cached(inline = false) PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, DECODING_STR_NOT_SUPPORTED);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, DECODING_STR_NOT_SUPPORTED);
}
@Specialization(guards = {"!isPBytes(object)", "!isString(object)"}, limit = "3")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeReadCharNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeReadCharNode.java
index c34ceb59ad..789eda9bee 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeReadCharNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeReadCharNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -74,19 +74,19 @@ static int doGeneric(Node inliningTarget, Object type, long lindex,
@Cached CastToTruffleStringNode castToStringNode,
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
@Cached(inline = false) TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
TruffleString s = castToStringNode.execute(inliningTarget, type);
int index = PInt.intValueExact(lindex);
// avoid StringIndexOutOfBoundsException
if (index < 0 || index >= codePointLengthNode.execute(s, TS_ENCODING)) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
return codePointAtIndexNode.execute(s, index, TS_ENCODING);
} catch (CannotCastException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
index 5cf3878eec..c6b7288a57 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java
@@ -41,129 +41,165 @@
package com.oracle.graal.python.nodes;
import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC;
-import static com.oracle.graal.python.nodes.truffle.TruffleStringMigrationHelpers.assertNoJavaString;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
-import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
-import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
-import com.oracle.graal.python.nodes.PRaiseNodeGen.LazyNodeGen;
+import com.oracle.graal.python.lib.PyExceptionInstanceCheckNode;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.object.PFactory;
-import com.oracle.graal.python.util.PythonUtils;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
-import com.oracle.truffle.api.dsl.ImportStatic;
-import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
-@ImportStatic(PGuards.class)
+@GenerateInline
+@GenerateCached(false)
@GenerateUncached
-@SuppressWarnings("truffle-inlining") // footprint reduction 32 -> 13
public abstract class PRaiseNode extends Node {
- public final PException execute(Node raisingNode, PythonBuiltinClassType type, Object cause, Object format, Object[] arguments) {
- return execute(raisingNode, type, null, cause, format, arguments);
+ protected abstract void executeEnterProfile(Node inliningTarget);
+
+ @Specialization
+ static void doProfile(Node inliningTarget,
+ @Cached InlinedBranchProfile profile) {
+ profile.enter(inliningTarget);
}
- public abstract PException execute(Node raisingNode, PythonBuiltinClassType type, Object[] data, Object cause, Object format, Object[] arguments);
+ public final PException raise(Node inliningTarget, PythonBuiltinClassType type) {
+ executeEnterProfile(inliningTarget);
+ throw raiseStatic(inliningTarget, type);
+ }
- public final PException raise(PythonBuiltinClassType type) {
- throw execute(this, type, null, PNone.NO_VALUE, PNone.NO_VALUE, PythonUtils.EMPTY_OBJECT_ARRAY);
+ public static PException raiseStatic(Node node, PythonBuiltinClassType type) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type);
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raise(PythonBuiltinClassType type, TruffleString message) {
- throw execute(this, type, null, PNone.NO_VALUE, message, PythonUtils.EMPTY_OBJECT_ARRAY);
+ public final PException raise(Node inliningTarget, PythonBuiltinClassType type, TruffleString message) {
+ executeEnterProfile(inliningTarget);
+ throw raiseStatic(inliningTarget, type, message);
}
- public final PException raise(PythonBuiltinClassType type, TruffleString format, Object... arguments) {
- throw execute(this, type, null, PNone.NO_VALUE, format, arguments);
+ public static PException raiseStatic(Node node, PythonBuiltinClassType type, TruffleString message) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, message);
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raise(PythonBuiltinClassType type, Object[] arguments) {
- throw execute(this, type, null, PNone.NO_VALUE, PNone.NO_VALUE, arguments);
+ public final PException raise(Node inliningTarget, PythonBuiltinClassType type, TruffleString format, Object... formatArgs) {
+ executeEnterProfile(inliningTarget);
+ throw raiseStatic(inliningTarget, type, format, formatArgs);
}
- public final PException raiseWithData(PythonBuiltinClassType type, Object[] data, Object... arguments) {
- throw execute(this, type, data, PNone.NO_VALUE, PNone.NO_VALUE, arguments);
+ public static PException raiseStatic(Node node, PythonBuiltinClassType type, TruffleString message, Object... formatArgs) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, message, formatArgs);
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raise(PythonBuiltinClassType type, Exception e) {
- throw execute(this, type, null, PNone.NO_VALUE, getMessage(e), PythonUtils.EMPTY_OBJECT_ARRAY);
+ public final PException raise(Node inliningTarget, PythonBuiltinClassType type, Object[] arguments) {
+ executeEnterProfile(inliningTarget);
+ throw raiseStatic(inliningTarget, type, arguments);
}
- public final PException raiseWithCause(PythonBuiltinClassType type, Object cause, TruffleString format, Object... arguments) {
- throw execute(this, type, null, cause, format, arguments);
+ public static PException raiseStatic(Node node, PythonBuiltinClassType type, Object[] arguments) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, PFactory.createTuple(language, arguments));
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raiseWithCause(PythonBuiltinClassType errorType, PException e, TruffleString message, Object... arguments) {
- return raiseWithCause(errorType, e.getEscapedException(), message, arguments);
+ public final PException raiseWithData(Node inliningTarget, PythonBuiltinClassType type, Object[] data) {
+ executeEnterProfile(inliningTarget);
+ throw raiseWithDataStatic(inliningTarget, type, data);
}
- public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType exceptionType) {
- throw PRaiseNodeGen.getUncached().execute(raisingNode, exceptionType, null, PNone.NO_VALUE, PNone.NO_VALUE, PythonUtils.EMPTY_OBJECT_ARRAY);
+ public static PException raiseWithDataStatic(Node node, PythonBuiltinClassType type, Object[] data) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, data, null);
+ throw raiseExceptionObject(node, pythonException, language);
}
- public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType exceptionType, TruffleString message) {
- throw PRaiseNodeGen.getUncached().execute(raisingNode, exceptionType, null, PNone.NO_VALUE, assertNoJavaString(message), PythonUtils.EMPTY_OBJECT_ARRAY);
+ public final PException raiseWithData(Node inliningTarget, PythonBuiltinClassType type, Object[] data, Object... arguments) {
+ executeEnterProfile(inliningTarget);
+ throw raiseWithDataStatic(inliningTarget, type, data, arguments);
}
- public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType type, TruffleString format, Object... arguments) {
- throw PRaiseNodeGen.getUncached().execute(raisingNode, type, null, PNone.NO_VALUE, format, arguments);
+ public static PException raiseWithDataStatic(Node node, PythonBuiltinClassType type, Object[] data, Object[] arguments) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, data, PFactory.createTuple(language, arguments));
+ throw raiseExceptionObject(node, pythonException, language);
}
- public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType type, Exception e) {
- throw PRaiseNodeGen.getUncached().execute(raisingNode, type, null, PNone.NO_VALUE, getMessage(e), PythonUtils.EMPTY_OBJECT_ARRAY);
+ public final PException raise(Node inliningTarget, PythonBuiltinClassType type, Exception e) {
+ executeEnterProfile(inliningTarget);
+ throw raiseStatic(inliningTarget, type, e);
}
- /**
- * Raise an error saying that the {@code result} cannot fit into an index-sized integer. Use the
- * specified {@code type} as exception class.
- */
- public final PException raiseNumberTooLarge(PythonBuiltinClassType type, Object result) {
- return execute(this, type, null, PNone.NO_VALUE, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, new Object[]{result});
+ public static PException raiseStatic(Node node, PythonBuiltinClassType type, Exception e) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, ErrorMessages.M, new Object[]{e});
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raiseOverflow() {
- return raiseNumberTooLarge(OverflowError, 0);
+ private static void setCause(PBaseException pythonException, PException cause) {
+ // _PyErr_FormatFromCause sets both cause and context
+ Object causePythonException = cause.getEscapedException();
+ pythonException.setCause(causePythonException);
+ pythonException.setContext(causePythonException);
}
- public final PException raiseSystemExit(Object code) {
- return raiseWithData(PythonBuiltinClassType.SystemExit, new Object[]{code}, code);
+ public final PException raiseWithCause(Node inliningTarget, PythonBuiltinClassType type, PException cause, TruffleString format) {
+ executeEnterProfile(inliningTarget);
+ throw raiseWithCauseStatic(inliningTarget, type, cause, format);
}
- public final PException raiseStopIteration() {
- return raise(PythonBuiltinClassType.StopIteration);
+ public static PException raiseWithCauseStatic(Node node, PythonBuiltinClassType type, PException cause, TruffleString format) {
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, format);
+ setCause(pythonException, cause);
+ throw raiseExceptionObject(node, pythonException, language);
}
- public final PException raiseStopIteration(Object value) {
- final Object retVal = value != null ? value : PNone.NONE;
- final Object[] args = {retVal};
- return raiseWithData(PythonBuiltinClassType.StopIteration, args, retVal);
+ public final PException raiseWithCause(Node inliningTarget, PythonBuiltinClassType type, PException cause, TruffleString format, Object... arguments) {
+ assert PyExceptionInstanceCheckNode.executeUncached(cause);
+ executeEnterProfile(inliningTarget);
+ throw raiseWithCauseStatic(inliningTarget, type, cause, format, arguments);
+ }
+
+ public static PException raiseWithCauseStatic(Node node, PythonBuiltinClassType type, PException cause, TruffleString format, Object... formatArgs) {
+ assert PyExceptionInstanceCheckNode.executeUncached(cause);
+ PythonLanguage language = PythonLanguage.get(node);
+ PBaseException pythonException = PFactory.createBaseException(language, type, format, formatArgs);
+ setCause(pythonException, cause);
+ throw raiseExceptionObject(node, pythonException, language);
+ }
+
+ public final PException raiseOverflow(Node inliningTarget) {
+ throw raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, 0);
}
- public final PException raiseIntegerInterpretationError(Object result) {
- return raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, result);
+ public static PException raiseSystemExitStatic(Node inliningTarget, Object code) {
+ throw raiseWithDataStatic(inliningTarget, PythonBuiltinClassType.SystemExit, new Object[]{code}, new Object[]{code});
}
- public final PException raiseBadInternalCall() {
- return raise(PythonBuiltinClassType.SystemError, BAD_ARG_TO_INTERNAL_FUNC);
+ public final PException raiseStopIteration(Node inliningTarget, Object value) {
+ final Object retVal = value != null ? value : PNone.NONE;
+ final Object[] args = {retVal};
+ throw raiseWithData(inliningTarget, PythonBuiltinClassType.StopIteration, args, retVal);
}
- public final PException raiseMemoryError() {
- return raise(PythonBuiltinClassType.MemoryError);
+ public final PException raiseBadInternalCall(Node inliningTarget) {
+ throw raise(inliningTarget, PythonBuiltinClassType.SystemError, BAD_ARG_TO_INTERNAL_FUNC);
}
public final PException raiseExceptionObject(Object exc) {
@@ -174,6 +210,10 @@ public static PException raiseExceptionObject(Node raisingNode, Object exc) {
throw raiseExceptionObject(raisingNode, exc, PythonOptions.isPExceptionWithJavaStacktrace(PythonLanguage.get(raisingNode)));
}
+ public static PException raiseExceptionObject(Node raisingNode, Object exc, PythonLanguage language) {
+ throw raiseExceptionObject(raisingNode, exc, PythonOptions.isPExceptionWithJavaStacktrace(language));
+ }
+
public static PException raiseExceptionObject(Node raisingNode, Object exc, boolean withJavaStacktrace) {
if (raisingNode != null && raisingNode.isAdoptable()) {
throw PException.fromObject(exc, raisingNode, withJavaStacktrace);
@@ -182,93 +222,7 @@ public static PException raiseExceptionObject(Node raisingNode, Object exc, bool
}
}
- @Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0", "exceptionType == cachedType"}, limit = "8")
- static PException doPythonBuiltinTypeCached(Node raisingNode, @SuppressWarnings("unused") PythonBuiltinClassType exceptionType, Object[] data, @SuppressWarnings("unused") PNone cause,
- @SuppressWarnings("unused") PNone format,
- @SuppressWarnings("unused") Object[] arguments,
- @Cached("exceptionType") PythonBuiltinClassType cachedType,
- @Bind PythonLanguage language) {
- throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, cachedType, data));
- }
-
- @Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0"}, replaces = "doPythonBuiltinTypeCached")
- static PException doPythonBuiltinType(Node raisingNode, PythonBuiltinClassType exceptionType, Object[] data, @SuppressWarnings("unused") PNone cause,
- @SuppressWarnings("unused") PNone format,
- @SuppressWarnings("unused") Object[] arguments,
- @Bind PythonLanguage language) {
- throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, exceptionType, data));
- }
-
- @Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length > 0"})
- static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object[] data, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
- Object[] arguments,
- @Bind PythonLanguage language,
- @Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
- ensureNoJavaStrings(arguments, fromJavaStringNode);
- throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, type, data, PFactory.createTuple(language, arguments)));
- }
-
- @Specialization(guards = {"isNoValue(cause)"})
- static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object[] data, @SuppressWarnings("unused") PNone cause, TruffleString format, Object[] arguments,
- @Bind PythonLanguage language,
- @Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
- assert format != null;
- ensureNoJavaStrings(arguments, fromJavaStringNode);
- throw raiseExceptionObject(raisingNode, PFactory.createBaseException(language, type, data, format, arguments));
- }
-
- @Specialization(guards = {"!isNoValue(cause)"})
- static PException doBuiltinTypeWithCause(Node raisingNode, PythonBuiltinClassType type, Object[] data, PBaseException cause, TruffleString format, Object[] arguments,
- @Bind PythonLanguage language,
- @Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
- assert format != null;
- ensureNoJavaStrings(arguments, fromJavaStringNode);
- PBaseException baseException = PFactory.createBaseException(language, type, data, format, arguments);
- baseException.setContext(cause);
- baseException.setCause(cause);
- throw raiseExceptionObject(raisingNode, baseException);
- }
-
- @TruffleBoundary
- private static TruffleString getMessage(Exception e) {
- String msg = e.getMessage();
- return toTruffleStringUncached(msg != null ? msg : e.getClass().getSimpleName());
- }
-
- @NeverDefault
- public static PRaiseNode create() {
- return PRaiseNodeGen.create();
- }
-
public static PRaiseNode getUncached() {
return PRaiseNodeGen.getUncached();
}
-
- private static void ensureNoJavaStrings(Object[] arguments, TruffleString.FromJavaStringNode fromJavaStringNode) {
- for (int i = 0; i < arguments.length; i++) {
- if (arguments[i] instanceof String) {
- arguments[i] = fromJavaStringNode.execute((String) arguments[i], TS_ENCODING);
- }
- }
- }
-
- @GenerateInline
- @GenerateUncached
- @GenerateCached(false)
- public abstract static class Lazy extends Node {
- public static Lazy getUncached() {
- return LazyNodeGen.getUncached();
- }
-
- public final PRaiseNode get(Node inliningTarget) {
- return execute(inliningTarget);
- }
-
- abstract PRaiseNode execute(Node inliningTarget);
-
- @Specialization
- static PRaiseNode doIt(@Cached(inline = false) PRaiseNode node) {
- return node;
- }
- }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java
index 162112edf4..12e133ff45 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -407,6 +407,7 @@ public abstract PException execute(Object[] scope_w, Object callable, Signature
@ExplodeLoop
static PException doCached(Object[] scope_w, Object callable, Signature signature, int co_argcount, @SuppressWarnings("unused") int co_kwonlyargcount, int ndefaults, int avail,
boolean methodcall, int adjustCount,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raise,
@Shared @Cached TruffleString.EqualNode equalNode,
@Cached("co_kwonlyargcount") int cachedKwOnlyArgCount) {
@@ -418,11 +419,12 @@ static PException doCached(Object[] scope_w, Object callable, Signature signatur
}
boolean forgotSelf = methodcall && avail + 1 == co_argcount && (signature.getParameterIds().length == 0 || !equalNode.execute(signature.getParameterIds()[0], T_SELF, TS_ENCODING));
TruffleString name = signature.getRaiseErrorName().isEmpty() ? getName(callable) : signature.getRaiseErrorName();
- throw raiseTooManyArguments(name, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
+ throw raiseTooManyArguments(inliningTarget, name, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
}
@Specialization(replaces = "doCached")
static PException doUncached(Object[] scope_w, Object callable, Signature signature, int co_argcount, int co_kwonlyargcount, int ndefaults, int avail, boolean methodcall, int adjustCount,
+ @Bind("this") Node inliningTarget,
@Shared @Cached PRaiseNode raise,
@Shared @Cached TruffleString.EqualNode equalNode) {
int kwonly_given = 0;
@@ -433,14 +435,14 @@ static PException doUncached(Object[] scope_w, Object callable, Signature signat
}
boolean forgotSelf = methodcall && avail + 1 == co_argcount && (signature.getParameterIds().length == 0 || !equalNode.execute(signature.getParameterIds()[0], T_SELF, TS_ENCODING));
TruffleString name = signature.getRaiseErrorName().isEmpty() ? getName(callable) : signature.getRaiseErrorName();
- throw raiseTooManyArguments(name, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
+ throw raiseTooManyArguments(inliningTarget, name, co_argcount - adjustCount, ndefaults, avail - adjustCount, forgotSelf, kwonly_given, raise);
}
- private static PException raiseTooManyArguments(TruffleString name, int co_argcount, int ndefaults, int avail, boolean forgotSelf, int kwonly_given, PRaiseNode raise) {
+ private static PException raiseTooManyArguments(Node inliningTarget, TruffleString name, int co_argcount, int ndefaults, int avail, boolean forgotSelf, int kwonly_given, PRaiseNode raise) {
String forgotSelfMsg = forgotSelf ? ". Did you forget 'self' in the function definition?" : "";
if (ndefaults > 0) {
if (kwonly_given == 0) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_FROM_D_TO_D_POS_ARG_S_BUT_D_S_GIVEN_S,
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_FROM_D_TO_D_POS_ARG_S_BUT_D_S_GIVEN_S,
name,
co_argcount - ndefaults,
co_argcount,
@@ -449,7 +451,7 @@ private static PException raiseTooManyArguments(TruffleString name, int co_argco
avail == 1 ? "was" : "were",
forgotSelfMsg);
} else {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_FROM_D_TO_D_POS_ARG_S_BUT_D_POS_ARG_S,
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_FROM_D_TO_D_POS_ARG_S_BUT_D_POS_ARG_S,
name,
co_argcount - ndefaults,
co_argcount,
@@ -462,7 +464,7 @@ private static PException raiseTooManyArguments(TruffleString name, int co_argco
}
} else {
if (kwonly_given == 0) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_D_POS_ARG_S_BUT_GIVEN_S,
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_D_POS_ARG_S_BUT_GIVEN_S,
name,
co_argcount - ndefaults,
co_argcount == 1 ? "" : "s",
@@ -470,7 +472,7 @@ private static PException raiseTooManyArguments(TruffleString name, int co_argco
avail == 1 ? "was" : "were",
forgotSelfMsg);
} else {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_D_POS_ARG_S_BUT_D_POS_ARG_S,
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.TAKES_D_POS_ARG_S_BUT_D_POS_ARG_S,
name,
co_argcount,
co_argcount == 1 ? "" : "s",
@@ -501,10 +503,10 @@ static void doEnclosingTypeCheck(Node inliningTarget, @SuppressWarnings("unused"
@Bind("getSelf(scope_w)") Object self,
@Cached GetClassNode getClassNode,
@Cached(inline = false) IsSubtypeNode isSubtypeMRONode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (!isSubtypeMRONode.execute(getClassNode.execute(inliningTarget, self), callable.getEnclosingType())) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.DESCR_S_FOR_P_OBJ_DOESNT_APPLY_TO_P,
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.DESCR_S_FOR_P_OBJ_DOESNT_APPLY_TO_P,
callable.getName(), callable.getEnclosingType(), self);
}
}
@@ -623,7 +625,7 @@ static Object[] applyCached(Object callee, @SuppressWarnings("unused") Signature
}
} else {
if (PArguments.getArgument(arguments, kwIdx) != null) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_PAREN_GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_PAREN_GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
}
PArguments.setArgument(arguments, kwIdx, kwArg.getValue());
}
@@ -679,7 +681,7 @@ static Object[] applyUncached(Object callee, Signature calleeSignature, Object[]
}
} else {
if (PArguments.getArgument(arguments, kwIdx) != null) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_PAREN_GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_PAREN_GOT_MULTIPLE_VALUES_FOR_ARG, CreateArgumentsNode.getName(callee), name);
}
PArguments.setArgument(arguments, kwIdx, kwArg.getValue());
}
@@ -709,13 +711,13 @@ private static List addPosArgOnlyPassedAsKeyword(List posArgOnlyPassedAsKeywordNames, Node inliningTarget, InlinedBranchProfile posArgOnlyPassedAsKeywordProfile, PRaiseNode raise) {
if (tooManyKeywords == 1) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_UNEXPECTED_KEYWORD_ARG, CreateArgumentsNode.getName(callee), lastWrongKeyword);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.GOT_UNEXPECTED_KEYWORD_ARG, CreateArgumentsNode.getName(callee), lastWrongKeyword);
} else if (tooManyKeywords > 1) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_UNEXPECTED_KEYWORD_ARG, CreateArgumentsNode.getName(callee), tooManyKeywords);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.GOT_UNEXPECTED_KEYWORD_ARG, CreateArgumentsNode.getName(callee), tooManyKeywords);
} else if (posArgOnlyPassedAsKeywordNames != null) {
posArgOnlyPassedAsKeywordProfile.enter(inliningTarget);
TruffleString names = joinUncached(T_COMMA_SPACE, posArgOnlyPassedAsKeywordNames);
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD, CreateArgumentsNode.getName(callee), names);
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD, CreateArgumentsNode.getName(callee), names);
} else if (unusedKeywords != null) {
PArguments.setKeywordArguments(arguments, Arrays.copyOf(unusedKeywords, unusedKeywordCount));
}
@@ -771,8 +773,8 @@ static int uncached(TruffleString[] parameters, TruffleString name,
protected abstract static class FillBaseNode extends PNodeWithContext {
- protected static PException raiseMissing(Object callable, TruffleString[] missingNames, int missingCnt, TruffleString type, PRaiseNode raise) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_S,
+ protected static PException raiseMissing(Node inliningTarget, Object callable, TruffleString[] missingNames, int missingCnt, TruffleString type, PRaiseNode raise) {
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_S,
getName(callable),
missingCnt,
type,
@@ -849,7 +851,7 @@ static void doCached(Object callable, Signature signature, Object[] scope_w, Obj
}
}
if (missingProfile.profile(inliningTarget, missingCnt > 0)) {
- throw raiseMissing(callable, missingNames, missingCnt, toTruffleStringUncached("positional"), raise);
+ throw raiseMissing(inliningTarget, callable, missingNames, missingCnt, toTruffleStringUncached("positional"), raise);
}
}
@@ -873,7 +875,7 @@ static void doUncached(Object callable, Signature signature, Object[] scope_w, O
}
}
if (missingProfile.profile(inliningTarget, missingCnt > 0)) {
- throw raiseMissing(callable, missingNames, missingCnt, toTruffleStringUncached("positional"), raise);
+ throw raiseMissing(inliningTarget, callable, missingNames, missingCnt, toTruffleStringUncached("positional"), raise);
}
}
}
@@ -904,7 +906,7 @@ protected abstract static class FillKwDefaultsNode extends FillBaseNode {
static void doCached(Object callable, Object[] scope_w, Signature signature, PKeyword[] kwdefaults, @SuppressWarnings("unused") int co_argcount,
@SuppressWarnings("unused") int co_kwonlyargcount,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raise,
+ @Exclusive @Cached PRaiseNode raise,
@Exclusive @Cached FindKwDefaultNode findKwDefaultNode,
@Cached("co_argcount") int cachedArgcount,
@Cached("co_kwonlyargcount") int cachedKwOnlyArgcount,
@@ -925,14 +927,14 @@ static void doCached(Object callable, Object[] scope_w, Signature signature, PKe
}
}
if (missingProfile.profile(inliningTarget, missingCnt > 0)) {
- throw raiseMissing(callable, missingNames, missingCnt, toTruffleStringUncached("keyword-only"), raise.get(inliningTarget));
+ throw raiseMissing(inliningTarget, callable, missingNames, missingCnt, toTruffleStringUncached("keyword-only"), raise);
}
}
@Specialization(replaces = "doCached")
static void doUncached(Object callable, Object[] scope_w, Signature signature, PKeyword[] kwdefaults, int co_argcount, int co_kwonlyargcount,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raise,
+ @Exclusive @Cached PRaiseNode raise,
@Exclusive @Cached FindKwDefaultNode findKwDefaultNode,
@Exclusive @Cached InlinedConditionProfile missingProfile) {
TruffleString[] missingNames = new TruffleString[co_kwonlyargcount];
@@ -951,7 +953,7 @@ static void doUncached(Object callable, Object[] scope_w, Signature signature, P
}
}
if (missingProfile.profile(inliningTarget, missingCnt > 0)) {
- throw raiseMissing(callable, missingNames, missingCnt, toTruffleStringUncached("keyword-only"), raise.get(inliningTarget));
+ throw raiseMissing(inliningTarget, callable, missingNames, missingCnt, toTruffleStringUncached("keyword-only"), raise);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/ExpandKeywordStarargsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/ExpandKeywordStarargsNode.java
index 4e62c70612..76e6d8b836 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/ExpandKeywordStarargsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/ExpandKeywordStarargsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -75,13 +75,13 @@ static PKeyword[] convert(@SuppressWarnings("unused") Object starargs) {
@Specialization(guards = "!isNoValue(starargs)")
static PKeyword[] convert(VirtualFrame frame, Node inliningTarget, Object starargs,
@Cached MappingToKeywordsNode convertNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return convertNode.execute(frame, inliningTarget, starargs);
} catch (SameDictKeyException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, e.getKey());
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, e.getKey());
} catch (NonMappingException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_ISNT_MAPPING, starargs);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.OBJ_ISNT_MAPPING, starargs);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/MappingToKeywordsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/MappingToKeywordsNode.java
index 9f94f25a8c..23206eb134 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/MappingToKeywordsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/MappingToKeywordsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -118,7 +118,7 @@ public CopyKeywordsState add(Frame frame, @SuppressWarnings("unused") Node node,
try {
state.addKeyword(castToTruffleStringNode.execute(inliningTarget, key), value);
} catch (CannotCastException e) {
- throw raiseNode.raise(TypeError, ErrorMessages.KEYWORDS_S_MUST_BE_STRINGS);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.KEYWORDS_S_MUST_BE_STRINGS);
}
return state;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/positional/ExecutePositionalStarargsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/positional/ExecutePositionalStarargsNode.java
index c9b2e9118e..e6e59a5326 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/positional/ExecutePositionalStarargsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/positional/ExecutePositionalStarargsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -118,14 +118,14 @@ static Object[] doSet(PSet starargs,
@Specialization
static Object[] doNone(PNone none,
- @Shared("raise") @Cached PRaiseNode raise) {
- throw raise.raise(PythonErrorType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_ITERABLE, none);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_ITERABLE, none);
}
@Specialization
static Object[] starargs(VirtualFrame frame, Object object,
@Bind("this") Node inliningTarget,
- @Shared("raise") @Cached PRaiseNode raise,
+ @Cached PRaiseNode raise,
@Cached PyObjectGetIter getIter,
@Cached GetNextNode nextNode,
@Cached IsBuiltinObjectProfile errorProfile) {
@@ -141,7 +141,7 @@ static Object[] starargs(VirtualFrame frame, Object object,
}
}
}
- throw raise.raise(PythonErrorType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_ITERABLE, object);
+ throw raise.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_ITERABLE, object);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/release_callback/ArrowSchemaReleaseCallbackNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/release_callback/ArrowSchemaReleaseCallbackNode.java
index c7063bc21a..b2e5c0e079 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/release_callback/ArrowSchemaReleaseCallbackNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/release_callback/ArrowSchemaReleaseCallbackNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,9 @@
*/
package com.oracle.graal.python.nodes.arrow.release_callback;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARROW_SCHEMA_ALREADY_RELEASED;
+import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
+
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.arrow.ArrowSchema;
import com.oracle.graal.python.runtime.PythonContext;
@@ -50,9 +53,6 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARROW_SCHEMA_ALREADY_RELEASED;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
-
@GenerateCached(false)
@GenerateInline
@GenerateUncached
@@ -62,9 +62,9 @@ public abstract class ArrowSchemaReleaseCallbackNode extends Node {
@Specialization
static void release(Node inliningTarget, ArrowSchema arrowSchema,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (arrowSchema.isReleased()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ARROW_SCHEMA_ALREADY_RELEASED);
+ throw raiseNode.raise(inliningTarget, ValueError, ARROW_SCHEMA_ALREADY_RELEASED);
}
var unsafe = PythonContext.get(inliningTarget).getUnsafe();
/*
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/vector/VectorArrowArrayReleaseCallback.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/vector/VectorArrowArrayReleaseCallback.java
index 286334f1a5..a2088bb291 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/vector/VectorArrowArrayReleaseCallback.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/vector/VectorArrowArrayReleaseCallback.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,9 @@
*/
package com.oracle.graal.python.nodes.arrow.vector;
+import static com.oracle.graal.python.nodes.ErrorMessages.ARROW_ARRAY_ALREADY_RELEASED;
+import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
+
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.arrow.ArrowArray;
@@ -54,9 +57,6 @@
import com.oracle.truffle.api.library.ExportMessage;
import com.oracle.truffle.api.nodes.Node;
-import static com.oracle.graal.python.nodes.ErrorMessages.ARROW_ARRAY_ALREADY_RELEASED;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
-
@ExportLibrary(InteropLibrary.class)
public class VectorArrowArrayReleaseCallback implements TruffleObject {
@@ -71,10 +71,10 @@ static class Execute {
@Specialization(guards = "validateArgs(args)")
static Object doRelease(VectorArrowArrayReleaseCallback self, Object[] args,
@Bind("$node") Node inliningTarget,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
ArrowArray arrowArray = ArrowArray.wrap((long) args[0]);
if (arrowArray.isReleased()) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ARROW_ARRAY_ALREADY_RELEASED);
+ throw raiseNode.raise(inliningTarget, ValueError, ARROW_ARRAY_ALREADY_RELEASED);
}
arrowArray.markReleased();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java
index 012300b2b4..f2ebdb7050 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -151,7 +151,7 @@ boolean writeToDynamicStorageBuiltinType(PythonBuiltinClass klass, TruffleString
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode) {
if (PythonContext.get(this).isInitialized()) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, key, klass);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, key, klass);
} else {
return writeToDynamicStorageManagedClass(klass, key, value, inliningTarget, callAttrUpdate, dylib, codePointLengthNode, codePointAtIndexNode);
}
@@ -210,7 +210,7 @@ boolean writeToDictBuiltinType(PythonBuiltinClass klass, TruffleString key, Obje
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode) {
if (PythonContext.get(this).isInitialized()) {
- throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(key), klass);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(key), klass);
} else {
return writeToDictManagedClass(klass, dict, key, value, inliningTarget, callAttrUpdate, updateStorage, setHashingStorageItem, codePointLengthNode, codePointAtIndexNode);
}
@@ -292,7 +292,7 @@ static boolean writeNativeObject(PythonAbstractNativeObject object, TruffleStrin
@Shared("getDict") @Cached GetDictIfExistsNode getDict,
@Shared("setHashingStorageItem") @Cached HashingStorageSetItem setHashingStorageItem,
@Shared("updateStorage") @Cached InlinedBranchProfile updateStorage,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
+ @Cached PRaiseNode raiseNode) {
/*
* The dict of native objects that stores the object attributes is located at 'objectPtr
* + Py_TYPE(objectPtr)->tp_dictoffset'. 'PythonObjectLibrary.getDict' will exactly load
@@ -302,14 +302,14 @@ static boolean writeNativeObject(PythonAbstractNativeObject object, TruffleStrin
if (dict != null) {
return writeToDict(dict, key, value, inliningTarget, updateStorage, setHashingStorageItem);
}
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
@Specialization(guards = "isErrorCase(getDict, object)")
static boolean doError(Object object, TruffleString key, @SuppressWarnings("unused") Object value,
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
}
@@ -318,12 +318,12 @@ static boolean doError(Object object, TruffleString key, @SuppressWarnings("unus
@GenerateInline(false) // footprint reduction 132 -> 115
protected abstract static class WriteAttributeToObjectTpDictNode extends WriteAttributeToObjectNode {
- private static void checkNativeImmutable(PythonAbstractNativeObject object, TruffleString key,
+ private static void checkNativeImmutable(Node inliningTarget, PythonAbstractNativeObject object, TruffleString key,
CStructAccess.ReadI64Node getNativeFlags,
PRaiseNode raiseNode) {
long flags = getNativeFlags.readFromObj(object, CFields.PyTypeObject__tp_flags);
if ((flags & TypeFlags.IMMUTABLETYPE) != 0) {
- throw raiseNode.raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, key, object);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, key, object);
}
}
@@ -341,7 +341,7 @@ static boolean writeNativeClassSimple(PythonAbstractNativeObject object, Truffle
@Shared("raiseNode") @Cached PRaiseNode raiseNode,
@SuppressWarnings("unused") @Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
@SuppressWarnings("unused") @Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode) {
- checkNativeImmutable(object, key, getNativeFlags, raiseNode);
+ checkNativeImmutable(inliningTarget, object, key, getNativeFlags, raiseNode);
/*
* For native types, the type attributes are stored in a dict that is located in
* 'typePtr->tp_dict'. So, this is different to a native object (that is not a type) and
@@ -352,7 +352,7 @@ static boolean writeNativeClassSimple(PythonAbstractNativeObject object, Truffle
if (dict instanceof PDict) {
return writeToDict((PDict) dict, key, value, inliningTarget, updateStorage, setHashingStorageItem);
}
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
@Specialization(replaces = "writeNativeClassSimple")
@@ -369,7 +369,7 @@ static boolean writeNativeClassGeneric(PythonAbstractNativeObject object, Truffl
@Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
@Cached TruffleString.EqualNode equalNode) {
try {
- checkNativeImmutable(object, key, getNativeFlags, raiseNode);
+ checkNativeImmutable(inliningTarget, object, key, getNativeFlags, raiseNode);
/*
* For native types, the type attributes are stored in a dict that is located in
* 'typePtr->tp_dict'. So, this is different to a native object (that is not a type)
@@ -380,7 +380,7 @@ static boolean writeNativeClassGeneric(PythonAbstractNativeObject object, Truffl
if (dict instanceof PDict) {
return writeToDict((PDict) dict, key, value, inliningTarget, updateStorage, setHashingStorageItem);
}
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
} finally {
if (TpSlots.canBeSpecialMethod(key, codePointLengthNode, codePointAtIndexNode)) {
canBeSpecialSlot.enter(inliningTarget);
@@ -403,8 +403,8 @@ static boolean writeNativeClassGeneric(PythonAbstractNativeObject object, Truffl
@Specialization(guards = "isErrorCase(getDict, object)")
static boolean doError(Object object, TruffleString key, @SuppressWarnings("unused") Object value,
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
- @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
index 14f01bf355..bb5d974679 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java
@@ -119,9 +119,8 @@ static SequenceStorage doForeign(Node inliningTarget, Object seq,
}
@Fallback
- static SequenceStorage doFallback(Node inliningTarget, Object seq,
- @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "list", seq);
+ static SequenceStorage doFallback(Node inliningTarget, Object seq) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, DESCRIPTOR_REQUIRES_S_OBJ_RECEIVED_P, "list", seq);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java
index 49408f54df..251ea87c36 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -49,16 +49,17 @@
import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
public class AbstractKwargsNode extends PNodeWithContext {
- protected static PException handleNonMapping(VirtualFrame frame, PRaiseNode raise, int stackTop, NonMappingException e) {
+ protected static PException handleNonMapping(VirtualFrame frame, Node inliningTarget, PRaiseNode raise, int stackTop, NonMappingException e) {
Object functionName = AbstractKwargsNode.getFunctionName(frame, stackTop);
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_MAPPING, functionName, e.getObject());
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_MAPPING, functionName, e.getObject());
}
- protected static PException handleSameKey(VirtualFrame frame, PRaiseNode raise, int stackTop, SameDictKeyException e) {
+ protected static PException handleSameKey(VirtualFrame frame, Node inliningTarget, PRaiseNode raise, int stackTop, SameDictKeyException e) {
Object functionName = AbstractKwargsNode.getFunctionName(frame, stackTop);
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, functionName, e.getKey());
+ throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, functionName, e.getKey());
}
private static Object getFunctionName(VirtualFrame frame, int stackTop) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java
index 701a7839a8..debb8cbcac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -102,7 +102,7 @@ static boolean doGeneric(VirtualFrame frame, Object iterator, int stackTop,
@Cached PRaiseNode raiseNode) throws QuickeningGeneralizeException {
Object nextMethod = lookupNext.execute(frame, getClassNode.execute(inliningTarget, iterator), iterator);
if (nextMethod == PNone.NO_VALUE) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
}
try {
Object res = callNext.executeObject(frame, nextMethod, iterator);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java
index 06f8a9dabe..7429b330e9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -101,7 +101,7 @@ static boolean doGeneric(VirtualFrame frame, Object iterator, int stackTop,
assert iterator != null;
Object nextMethod = lookupNext.execute(frame, getClassNode.execute(inliningTarget, iterator), iterator);
if (nextMethod == PNone.NO_VALUE) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
+ throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, iterator);
}
try {
frame.setObject(stackTop, callNext.executeObject(frame, nextMethod, iterator));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAIterNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAIterNode.java
index 2465b85a28..2117964ea1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAIterNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAIterNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -83,7 +83,7 @@ Object doGeneric(Frame frame, Object receiver,
@Bind("this") Node inliningTarget,
@Cached(parameters = "AIter") LookupSpecialMethodSlotNode getAIter,
@Cached GetClassNode getAsyncIterType,
- @Cached PRaiseNode.Lazy raiseNoAIter,
+ @Cached PRaiseNode raiseNoAIter,
@Cached TypeNodes.GetNameNode getName,
@Cached InlinedBranchProfile errorProfile,
@Cached CallUnaryMethodNode callAIter,
@@ -93,13 +93,13 @@ Object doGeneric(Frame frame, Object receiver,
Object getter = getAIter.execute(frame, type, receiver);
if (getter == PNone.NO_VALUE) {
errorProfile.enter(this);
- throw raiseNoAIter.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_AITER, getName.execute(inliningTarget, type));
+ throw raiseNoAIter.raise(inliningTarget, PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_AITER, getName.execute(inliningTarget, type));
}
Object asyncIterator = callAIter.executeObject(frame, getter, receiver);
Object anext = lookupANext.execute(inliningTarget, asyncIterator, T___ANEXT__);
if (anext == PNone.NO_VALUE) {
errorProfile.enter(this);
- throw raiseNoAIter.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_INITIAL, getName.execute(inliningTarget, type));
+ throw raiseNoAIter.raise(inliningTarget, PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_INITIAL, getName.execute(inliningTarget, type));
}
return asyncIterator;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetANextNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetANextNode.java
index deb1141529..4718f84405 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetANextNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetANextNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -91,14 +91,14 @@ Object doGeneric(Frame frame, Object receiver,
Object getter = getANext.execute(frame, type, receiver);
if (getter == PNone.NO_VALUE) {
errorProfile.enter(inliningTarget);
- throw raiseNoANext.raise(PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_ITERATION, receiver);
+ throw raiseNoANext.raise(inliningTarget, PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_ITERATION, receiver);
}
Object anext = callANext.executeObject(frame, getter, receiver);
try {
return getAwaitable.execute(frame, anext);
} catch (PException e) {
errorProfile.enter(inliningTarget);
- throw raiseInvalidObject.raiseWithCause(PythonBuiltinClassType.TypeError, e, ANEXT_INVALID_OBJECT, anext);
+ throw raiseInvalidObject.raiseWithCause(inliningTarget, PythonBuiltinClassType.TypeError, e, ANEXT_INVALID_OBJECT, anext);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ImportStarNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ImportStarNode.java
index 5210ab2ea2..00e1ebba9e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ImportStarNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ImportStarNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -164,8 +164,8 @@ private void writeAttributeToLocals(VirtualFrame frame, Node inliningTarget, Tru
writeAttribute(frame, inliningTarget, locals, name, moduleAttr, dictWriteNode, setAttrNode);
}
} catch (CannotCastException cce) {
- throw PRaiseNode.raiseUncached(this, TypeError, fromAll ? ErrorMessages.ITEM_IN_S_MUST_BE_STRING : ErrorMessages.KEY_IN_S_MUST_BE_STRING,
- moduleName, fromAll ? T___ALL__ : T___DICT__, attrName);
+ TruffleString format = fromAll ? ErrorMessages.ITEM_IN_S_MUST_BE_STRING : ErrorMessages.KEY_IN_S_MUST_BE_STRING;
+ throw PRaiseNode.raiseStatic(this, TypeError, format, moduleName, fromAll ? T___ALL__ : T___DICT__, attrName);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java
index 5dd96fb4bf..480590e93a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -66,15 +66,15 @@ static PKeyword[] kwords(VirtualFrame frame, Object sourceCollection, int stackT
@Cached MappingToKeywordsNode expandKeywordStarargsNode,
@Cached InlinedBranchProfile keywordsError1,
@Cached InlinedBranchProfile keywordsError2,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
try {
return expandKeywordStarargsNode.execute(frame, inliningTarget, sourceCollection);
} catch (SameDictKeyException e) {
keywordsError1.enter(inliningTarget);
- throw handleSameKey(frame, raise.get(inliningTarget), stackTop, e);
+ throw handleSameKey(frame, inliningTarget, raise, stackTop, e);
} catch (NonMappingException e) {
keywordsError2.enter(inliningTarget);
- throw handleNonMapping(frame, raise.get(inliningTarget), stackTop, e);
+ throw handleNonMapping(frame, inliningTarget, raise, stackTop, e);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java
index f0326ea589..b6165bc651 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -65,7 +65,7 @@ public abstract class KwargsMergeNode extends AbstractKwargsNode {
static int merge(VirtualFrame frame, int initialStackTop,
@Bind("this") Node inliningTarget,
@Cached ConcatDictToStorageNode concatNode,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached InlinedBranchProfile keywordsError1,
@Cached InlinedBranchProfile keywordsError2) {
int stackTop = initialStackTop;
@@ -77,10 +77,10 @@ static int merge(VirtualFrame frame, int initialStackTop,
dict.setDictStorage(resultStorage);
} catch (SameDictKeyException e) {
keywordsError1.enter(inliningTarget);
- throw handleSameKey(frame, raise.get(inliningTarget), stackTop, e);
+ throw handleSameKey(frame, inliningTarget, raise, stackTop, e);
} catch (NonMappingException e) {
keywordsError2.enter(inliningTarget);
- throw handleNonMapping(frame, raise.get(inliningTarget), stackTop, e);
+ throw handleNonMapping(frame, inliningTarget, raise, stackTop, e);
}
return stackTop;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
index c94084db5b..260f08ab12 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java
@@ -93,7 +93,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
@Cached PRaiseNode raise) {
if (!isTypeNode.execute(inliningTarget, type)) {
- throw raise.raise(TypeError, ErrorMessages.CALLED_MATCH_PAT_MUST_BE_TYPE);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.CALLED_MATCH_PAT_MUST_BE_TYPE);
}
if (!isInstanceNode.executeWith(frame, subject, type)) {
@@ -111,7 +111,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
try {
matchArgs = getAttr.execute(frame, inliningTarget, type, T___MATCH_ARGS);
if (!tupleCheckExactNode.execute(inliningTarget, matchArgs)) {
- throw raise.raise(TypeError, ErrorMessages.P_MATCH_ARGS_MUST_BE_A_TUPLE_GOT_P, type, matchArgs);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.P_MATCH_ARGS_MUST_BE_A_TUPLE_GOT_P, type, matchArgs);
}
} catch (PException e) {
// _Py_TPFLAGS_MATCH_SELF is only acknowledged if the type does not
@@ -124,7 +124,7 @@ Object match(VirtualFrame frame, Object subject, Object type, int nargs, @NeverD
}
int allowed = matchSelf ? 1 : tupleSizeNode.execute(inliningTarget, matchArgs);
if (allowed < nargs) {
- throw raise.raise(TypeError, ErrorMessages.P_ACCEPTS_D_POS_SUBARG_S_D_GIVEN, type, allowed, (allowed == 1) ? "" : "s", nargs);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.P_ACCEPTS_D_POS_SUBARG_S_D_GIVEN, type, allowed, (allowed == 1) ? "" : "s", nargs);
}
if (matchSelf) {
// Easy. Copy the subject itself, and move on to kwargs.
@@ -150,9 +150,9 @@ private static void getArgs(VirtualFrame frame, Node inliningTarget, Object subj
for (int i = 0; i < nargs; i++) {
Object name = getItemNode.execute(frame, matchArgs, i);
if (!unicodeCheckNode.execute(inliningTarget, name)) {
- throw raise.raise(TypeError, ErrorMessages.MATCH_ARGS_ELEMENTS_MUST_BE_STRINGS_GOT_P, name);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.MATCH_ARGS_ELEMENTS_MUST_BE_STRINGS_GOT_P, name);
}
- setName(frame, type, name, seen, seenLength, eqStrNode, raise);
+ setName(frame, inliningTarget, type, name, seen, seenLength, eqStrNode, raise);
attrs[attrsLength[0]++] = getAttr.execute(frame, inliningTarget, subject, name);
}
}
@@ -165,14 +165,14 @@ private static void getKwArgs(VirtualFrame frame, Node inliningTarget, Object su
for (int i = 0; i < kwArgs.length; i++) {
TruffleString name = kwArgs[i];
CompilerAsserts.partialEvaluationConstant(name);
- setName(frame, type, name, seen, seenLength, eqStrNode, raise);
+ setName(frame, inliningTarget, type, name, seen, seenLength, eqStrNode, raise);
attrs[attrsLength[0]++] = getAttr.execute(frame, inliningTarget, subject, name);
}
}
- private static void setName(VirtualFrame frame, Object type, Object name, Object[] seen, int[] seenLength, StringBuiltins.EqNode eqNode, PRaiseNode raise) {
+ private static void setName(VirtualFrame frame, Node inliningTarget, Object type, Object name, Object[] seen, int[] seenLength, StringBuiltins.EqNode eqNode, PRaiseNode raise) {
if (seenLength[0] > 0 && contains(frame, seen, name, eqNode)) {
- throw raise.raise(TypeError, ErrorMessages.S_GOT_MULTIPLE_SUBPATTERNS_FOR_ATTR_S, type, name);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.S_GOT_MULTIPLE_SUBPATTERNS_FOR_ATTR_S, type, name);
}
seen[seenLength[0]++] = name;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
index b39adc032a..e377122bba 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchKeysNode.java
@@ -74,14 +74,14 @@ static Object matchCached(VirtualFrame frame, Object map, @NeverDefault Object[]
@Cached("keys.length") int keysLen,
@Shared @Cached PyObjectRichCompareBool.EqNode compareNode,
@Shared @Cached PyObjectCallMethodObjArgs callMethod,
- @Shared @Cached PRaiseNode.Lazy raise) {
+ @Shared @Cached PRaiseNode raise) {
Object[] values = getValues(frame, inliningTarget, map, keys, keysLen, compareNode, callMethod, raise);
return values != null ? PFactory.createTuple(PythonLanguage.get(inliningTarget), values) : PNone.NONE;
}
@ExplodeLoop
private static Object[] getValues(VirtualFrame frame, Node inliningTarget, Object map, Object[] keys, int keysLen, PyObjectRichCompareBool.EqNode compareNode, PyObjectCallMethodObjArgs callMethod,
- PRaiseNode.Lazy raise) {
+ PRaiseNode raise) {
CompilerAsserts.partialEvaluationConstant(keysLen);
Object[] values = new Object[keysLen];
Object dummy = new Object();
@@ -100,10 +100,10 @@ private static Object[] getValues(VirtualFrame frame, Node inliningTarget, Objec
}
@ExplodeLoop
- private static void checkSeen(VirtualFrame frame, Node inliningTarget, PRaiseNode.Lazy raise, Object[] seen, Object key, PyObjectRichCompareBool.EqNode compareNode) {
+ private static void checkSeen(VirtualFrame frame, Node inliningTarget, PRaiseNode raise, Object[] seen, Object key, PyObjectRichCompareBool.EqNode compareNode) {
for (int i = 0; i < seen.length; i++) {
if (seen[i] != null && compareNode.compare(frame, inliningTarget, seen[i], key)) {
- raise.get(inliningTarget).raise(ValueError, ErrorMessages.MAPPING_PATTERN_CHECKS_DUPE_KEY_S, key);
+ raise.raise(inliningTarget, ValueError, ErrorMessages.MAPPING_PATTERN_CHECKS_DUPE_KEY_S, key);
}
}
}
@@ -113,7 +113,7 @@ static Object match(VirtualFrame frame, Object map, Object[] keys,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectRichCompareBool.EqNode compareNode,
@Shared @Cached PyObjectCallMethodObjArgs callMethod,
- @Shared @Cached PRaiseNode.Lazy raise) {
+ @Shared @Cached PRaiseNode raise) {
if (keys.length == 0) {
return PFactory.createTuple(PythonLanguage.get(inliningTarget), PythonUtils.EMPTY_OBJECT_ARRAY);
}
@@ -122,7 +122,7 @@ static Object match(VirtualFrame frame, Object map, Object[] keys,
}
private static Object[] getValuesLongArray(VirtualFrame frame, Node inliningTarget, Object map, Object[] keys, PyObjectRichCompareBool.EqNode compareNode, PyObjectCallMethodObjArgs callMethod,
- PRaiseNode.Lazy raise) {
+ PRaiseNode raise) {
Object[] values = new Object[keys.length];
Object dummy = new Object();
Object[] seen = new Object[keys.length];
@@ -139,10 +139,10 @@ private static Object[] getValuesLongArray(VirtualFrame frame, Node inliningTarg
return values;
}
- private static void checkSeenLongArray(VirtualFrame frame, Node inliningTarget, PRaiseNode.Lazy raise, Object[] seen, Object key, PyObjectRichCompareBool.EqNode compareNode) {
+ private static void checkSeenLongArray(VirtualFrame frame, Node inliningTarget, PRaiseNode raise, Object[] seen, Object key, PyObjectRichCompareBool.EqNode compareNode) {
for (int i = 0; i < seen.length; i++) {
if (seen[i] != null && compareNode.compare(frame, inliningTarget, seen[i], key)) {
- raise.get(inliningTarget).raise(ValueError, ErrorMessages.MAPPING_PATTERN_CHECKS_DUPE_KEY_S, key);
+ raise.raise(inliningTarget, ValueError, ErrorMessages.MAPPING_PATTERN_CHECKS_DUPE_KEY_S, key);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index 8ba1f3fb38..925af3cb16 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -139,7 +139,6 @@
import com.oracle.graal.python.lib.PyObjectStrAsObjectNodeGen;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.PRaiseNodeGen;
import com.oracle.graal.python.nodes.PRootNode;
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode;
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNodeGen;
@@ -262,8 +261,8 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
private static final NodeSupplier NODE_IMPORT_STAR = ImportStarNode::create;
private static final NodeSupplier NODE_OBJECT_GET_ATTR = PyObjectGetAttr::create;
private static final PyObjectGetAttr UNCACHED_OBJECT_GET_ATTR = PyObjectGetAttr.getUncached();
- private static final NodeSupplier NODE_RAISE = PRaiseNode::create;
- private static final PRaiseNode UNCACHED_RAISE = PRaiseNode.getUncached();
+ private static final NodeSupplier NODE_RAISE = PRaiseCachedNode::create;
+ private static final PRaiseCachedNode UNCACHED_RAISE = PRaiseCachedNode.getUncached();
private static final NodeSupplier NODE_CALL = CallNode::create;
private static final CallNode UNCACHED_CALL = CallNode.getUncached();
private static final NodeSupplier NODE_CALL_QUATERNARY_METHOD = CallQuaternaryMethodNode::create;
@@ -2948,10 +2947,10 @@ private int traceLine(VirtualFrame virtualFrame, MutableLoopData mutableData, by
mutableData.setPastBci(bci);
if (newBci == CodeUnit.LINE_TO_BCI_LINE_AFTER_CODEBLOCK) {
// line after the code block
- throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, pyFrame.getLine());
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, pyFrame.getLine());
} else if (newBci == CodeUnit.LINE_TO_BCI_LINE_BEFORE_CODEBLOCK) {
// line before the code block
- throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, pyFrame.getJumpDestLine());
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, pyFrame.getJumpDestLine());
} else {
ret = computeJumpStackDifference(bci, newBci);
mutableData.setJumpBci(newBci);
@@ -2968,9 +2967,9 @@ private int traceLine(VirtualFrame virtualFrame, MutableLoopData mutableData, by
private int computeJumpStackDifference(int bci, int newBci) {
int ret;
var stacks = co.computeStackElems();
- String error = co.checkJump(stacks, bci, newBci);
+ String error = co.checkJump(this, stacks, bci, newBci);
if (error != null) {
- throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.CANT_JUMP_INTO_S, error);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.CANT_JUMP_INTO_S, error);
}
ret = stacks.get(newBci).size() - stacks.get(bci).size();
return ret;
@@ -3274,7 +3273,8 @@ private void chainPythonExceptions(PException current, PException context) {
private PException raiseUnknownBytecodeError(byte bc) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, toTruffleStringUncached("not implemented bytecode %s"), OpCodes.fromOpCode(bc));
+ TruffleString format = toTruffleStringUncached("not implemented bytecode %s");
+ throw PRaiseNode.raiseStatic(this, SystemError, format, OpCodes.fromOpCode(bc));
}
private void generalizeForIterI(int bci, QuickeningGeneralizeException e) {
@@ -3661,7 +3661,7 @@ private void bytecodeBinaryOpIII(VirtualFrame virtualFrame, int stackTop, int bc
@InliningCutoff
private void raiseDivOrModByZero(int bci, Node[] localNodes, boolean useCachedNodes) {
- PRaiseNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseNodeGen.class, NODE_RAISE, useCachedNodes);
+ PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes);
throw raiseNode.raise(ZeroDivisionError, ErrorMessages.S_DIVISION_OR_MODULO_BY_ZERO, "integer");
}
@@ -3811,7 +3811,7 @@ private void bytecodeBinaryOpDDO(VirtualFrame virtualFrame, int stackTop, int bc
@InliningCutoff
private void raiseDivByZero(int bci, Node[] localNodes, boolean useCachedNodes) {
- PRaiseNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseNodeGen.class, NODE_RAISE, useCachedNodes);
+ PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes);
throw raiseNode.raise(ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
}
@@ -4559,7 +4559,7 @@ private void bytecodeLoadFastO(VirtualFrame virtualFrame, Frame localFrame, int
@InliningCutoff
private PException raiseVarReferencedBeforeAssignment(Node[] localNodes, int bci, int index) {
- PRaiseNode raiseNode = insertChildNode(localNodes, bci, PRaiseNodeGen.class, NODE_RAISE);
+ PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, PRaiseCachedNodeGen.class, NODE_RAISE);
throw raiseNode.raise(PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, varnames[index]);
}
@@ -4846,7 +4846,7 @@ private void bytecodeDeleteName(VirtualFrame virtualFrame, Object globals, Objec
try {
delItemNode.executeCached(virtualFrame, locals, varname);
} catch (PException e) {
- PRaiseNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseNodeGen.class, NODE_RAISE, useCachedNodes);
+ PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes);
throw raiseNode.raise(NameError, ErrorMessages.NAME_NOT_DEFINED, varname);
}
} else {
@@ -5426,7 +5426,7 @@ private AbstractTruffleException bytecodeRaiseVarargs(VirtualFrame virtualFrame,
@InliningCutoff
private void raiseUnboundCell(Node[] localNodes, int bci, int oparg, boolean useCachedNodes) {
- PRaiseNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseNodeGen.class, NODE_RAISE, useCachedNodes);
+ PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes);
if (oparg < cellvars.length) {
throw raiseNode.raise(PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, cellvars[oparg]);
} else {
@@ -5683,7 +5683,7 @@ private int bytecodeCollectionAddCollection(VirtualFrame virtualFrame, int type,
}
default:
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.getUncached().raise(SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "COLLECTION_ADD_COLLECTION");
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "COLLECTION_ADD_COLLECTION");
}
virtualFrame.setObject(stackTop--, null);
virtualFrame.setObject(stackTop, result);
@@ -5716,7 +5716,7 @@ private int bytecodeAddToCollection(VirtualFrame virtualFrame, int initialStackT
}
default:
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.getUncached().raise(SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "ADD_TO_COLLECTION");
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "ADD_TO_COLLECTION");
}
virtualFrame.setObject(stackTop--, null);
return stackTop;
@@ -5889,7 +5889,7 @@ protected byte[] extractCode() {
*
* TODO We should revisit this when the AST interpreter is removed.
*/
- return MarshalModuleBuiltins.serializeCodeUnit(PythonContext.get(this), co);
+ return MarshalModuleBuiltins.serializeCodeUnit(this, PythonContext.get(this), co);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java
new file mode 100644
index 0000000000..965bae46d2
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.nodes.bytecode;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.strings.TruffleString;
+
+@GenerateUncached
+abstract class PRaiseCachedNode extends Node {
+ public final PException raise(PythonBuiltinClassType type, TruffleString format, Object... formatArgs) {
+ throw execute(type, format, formatArgs);
+ }
+
+ protected abstract PException execute(PythonBuiltinClassType type, TruffleString format, Object[] formatArgs);
+
+ @Specialization
+ PException doRaise(PythonBuiltinClassType type, TruffleString format, Object[] formatArgs) {
+ throw PRaiseNode.raiseStatic(this, type, format, formatArgs);
+ }
+
+ @NeverDefault
+ public static PRaiseCachedNode create() {
+ return PRaiseCachedNodeGen.create();
+ }
+
+ public static PRaiseCachedNode getUncached() {
+ return PRaiseCachedNodeGen.getUncached();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PrintExprNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PrintExprNode.java
index c8e0576ba8..a3a05f05f7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PrintExprNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PrintExprNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -74,7 +74,7 @@ void print(VirtualFrame frame, Object object,
Object displayhook = lookupAttr.execute(frame, inliningTarget, sysModule, BuiltinNames.T_DISPLAYHOOK);
if (displayhook == PNone.NO_VALUE) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, RuntimeError, ErrorMessages.LOST_SYSDISPLAYHOOK);
+ throw PRaiseNode.raiseStatic(this, RuntimeError, ErrorMessages.LOST_SYSDISPLAYHOOK);
}
callNode.execute(frame, displayhook, object);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/RaiseNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/RaiseNode.java
index 4202c74e1e..12066f8483 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/RaiseNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/RaiseNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -95,12 +95,11 @@ static void setCause(VirtualFrame frame, Object exception, Object causeClass,
@Exclusive @Cached InlinedBranchProfile baseCheckFailedProfile,
@Exclusive @Cached ValidExceptionNode validException,
@Exclusive @Cached CallNode callConstructor,
- @Exclusive @Cached PRaiseNode.Lazy raise,
@Exclusive @Cached PyExceptionInstanceCheckNode check,
@Exclusive @Cached ExceptionNodes.SetCauseNode setCauseNode) {
if (!validException.execute(frame, causeClass)) {
baseCheckFailedProfile.enter(inliningTarget);
- throw raise.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXCEPTION_CAUSES_MUST_DERIVE_FROM_BASE_EX);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.EXCEPTION_CAUSES_MUST_DERIVE_FROM_BASE_EX);
}
Object cause = callConstructor.execute(frame, causeClass);
if (check.execute(inliningTarget, cause)) {
@@ -118,11 +117,10 @@ static void setCause(VirtualFrame frame, Object exception, Object causeClass,
// raise * from
@Specialization(guards = {"!check.execute(inliningTarget, cause)", "!isTypeNode.execute(inliningTarget, cause)"}, limit = "1")
static void setCause(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object exception, @SuppressWarnings("unused") Object cause,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Exclusive @SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
@SuppressWarnings("unused") @Exclusive @Cached PyExceptionInstanceCheckNode check,
- @Cached PRaiseNode raise) {
- throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXCEPTION_CAUSES_MUST_DERIVE_FROM_BASE_EX);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.EXCEPTION_CAUSES_MUST_DERIVE_FROM_BASE_EX);
}
}
@@ -139,7 +137,7 @@ static void reraise(VirtualFrame frame, @SuppressWarnings("unused") PNone type,
} else if (caughtException != null) {
throw caughtException;
} else {
- throw raise.raise(RuntimeError, ErrorMessages.NO_ACTIVE_EX_TO_RERAISE);
+ throw raise.raise(inliningTarget, RuntimeError, ErrorMessages.NO_ACTIVE_EX_TO_RERAISE);
}
}
@@ -178,11 +176,11 @@ public static void doRaiseNative(@SuppressWarnings("unused") VirtualFrame frame,
throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
}
- private static void checkBaseClass(VirtualFrame frame, Node inliningTarget, Object pythonClass, ValidExceptionNode validException, PRaiseNode.Lazy raise,
+ private static void checkBaseClass(VirtualFrame frame, Node inliningTarget, Object pythonClass, ValidExceptionNode validException, PRaiseNode raise,
InlinedBranchProfile baseCheckFailedProfile) {
if (!validException.execute(frame, pythonClass)) {
baseCheckFailedProfile.enter(inliningTarget);
- throw raiseNoException(raise.get(inliningTarget));
+ throw raiseNoException(inliningTarget, raise);
}
}
@@ -195,13 +193,13 @@ public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Objec
@Exclusive @Cached CallNode callConstructor,
@Exclusive @Cached PyExceptionInstanceCheckNode check,
@Exclusive @Cached InlinedBranchProfile baseCheckFailedProfile,
- @Exclusive @Cached PRaiseNode.Lazy raise) {
+ @Exclusive @Cached PRaiseNode raise) {
checkBaseClass(frame, inliningTarget, pythonClass, validException, raise, baseCheckFailedProfile);
Object newException = callConstructor.execute(frame, pythonClass);
if (check.execute(inliningTarget, newException)) {
throw PRaiseNode.raiseExceptionObject(inliningTarget, newException);
} else {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, pythonClass, newException);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, pythonClass, newException);
}
}
@@ -211,7 +209,7 @@ public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Objec
@Bind("this") Node inliningTarget,
@Exclusive @SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
@Exclusive @Cached ValidExceptionNode validException,
- @Exclusive @Cached PRaiseNode.Lazy raise,
+ @Exclusive @Cached PRaiseNode raise,
@Exclusive @Cached CallNode callConstructor,
@Exclusive @Cached PyExceptionInstanceCheckNode check,
@Exclusive @Cached InlinedBranchProfile baseCheckFailedProfile,
@@ -222,7 +220,7 @@ public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Objec
setExceptionCauseNode.execute(frame, newException, cause);
throw PRaiseNode.raiseExceptionObject(inliningTarget, newException);
} else {
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, pythonClass, newException);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_HAVE_RETURNED_EXCEPTION, pythonClass, newException);
}
}
@@ -232,7 +230,7 @@ public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Objec
public static void doRaise(VirtualFrame frame, Object exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "1") InteropLibrary lib,
- @Exclusive @Cached PRaiseNode.Lazy raise) {
+ @Exclusive @Cached PRaiseNode raise) {
if (lib.isException(exception)) {
try {
throw lib.throwException(exception);
@@ -240,11 +238,11 @@ public static void doRaise(VirtualFrame frame, Object exception, Object cause, @
throw CompilerDirectives.shouldNotReachHere();
}
}
- throw raiseNoException(raise.get(inliningTarget));
+ throw raiseNoException(inliningTarget, raise);
}
- private static PException raiseNoException(PRaiseNode raise) {
- throw raise.raise(TypeError, ErrorMessages.EXCEPTIONS_MUST_DERIVE_FROM_BASE_EX);
+ private static PException raiseNoException(Node inliningTarget, PRaiseNode raise) {
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.EXCEPTIONS_MUST_DERIVE_FROM_BASE_EX);
}
public static RaiseNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java
index b680d4ea7e..a98c14d1b7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -79,11 +79,11 @@ static int setup(VirtualFrame frame, int stackTopIn,
Object type = getClassNode.execute(inliningTarget, contextManager);
Object enter = lookupAEnter.execute(frame, type, contextManager);
if (enter == PNone.NO_VALUE) {
- throw raiseNode.raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL, type);
}
Object exit = lookupAExit.execute(frame, type, contextManager);
if (exit == PNone.NO_VALUE) {
- throw raiseNode.raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL_AEXIT, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL_AEXIT, type);
}
Object res = callEnter.executeObject(frame, enter, contextManager);
frame.setObject(++stackTop, exit);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java
index ab61c3e4f6..3a70e3cadb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -79,11 +79,11 @@ static int setup(VirtualFrame frame, int stackTopIn,
Object type = getClassNode.execute(inliningTarget, contextManager);
Object enter = lookupEnter.execute(frame, type, contextManager);
if (enter == PNone.NO_VALUE) {
- throw raiseNode.raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL, type);
}
Object exit = lookupExit.execute(frame, type, contextManager);
if (exit == PNone.NO_VALUE) {
- throw raiseNode.raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL_EXIT, type);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL_EXIT, type);
}
Object res = callEnter.executeObject(frame, enter, contextManager);
frame.setObject(++stackTop, exit);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
index 1ea71fe6c4..581f455c90 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java
@@ -83,7 +83,7 @@ static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence s
@Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
@Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
CompilerAsserts.partialEvaluationConstant(countBefore);
CompilerAsserts.partialEvaluationConstant(countAfter);
int resultStackTop = initialStackTop + countBefore + 1 + countAfter;
@@ -92,7 +92,7 @@ static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence s
int len = storage.length();
int starLen = len - countBefore - countAfter;
if (starLen < 0) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, len);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, len);
}
stackTop = moveItemsToStack(frame, inliningTarget, storage, stackTop, 0, countBefore, getItemNode);
PList starList = PFactory.createList(language, getItemSliceNode.execute(storage, countBefore, countBefore + starLen, 1, starLen));
@@ -112,7 +112,7 @@ static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object coll
@Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
@Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode,
@Bind PythonLanguage language,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode) {
+ @Exclusive @Cached PRaiseNode raiseNode) {
CompilerAsserts.partialEvaluationConstant(countBefore);
CompilerAsserts.partialEvaluationConstant(countAfter);
int resultStackTop = initialStackTop + countBefore + 1 + countAfter;
@@ -122,14 +122,14 @@ static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object coll
iterator = getIter.execute(frame, inliningTarget, collection);
} catch (PException e) {
e.expectTypeError(inliningTarget, notIterableProfile);
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection);
}
stackTop = moveItemsToStack(frame, inliningTarget, iterator, stackTop, 0, countBefore, countBefore + countAfter, getNextNode, stopIterationProfile, raiseNode);
PList starAndAfter = constructListNode.execute(frame, iterator);
SequenceStorage storage = starAndAfter.getSequenceStorage();
int lenAfter = storage.length();
if (lenAfter < countAfter) {
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, countBefore + lenAfter);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, countBefore + lenAfter);
}
if (countAfter == 0) {
frame.setObject(stackTop, starAndAfter);
@@ -144,7 +144,7 @@ static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object coll
@ExplodeLoop
private static int moveItemsToStack(VirtualFrame frame, Node inliningTarget, Object iterator, int initialStackTop, int offset, int length, int totalLength, GetNextNode getNextNode,
- IsBuiltinObjectProfile stopIterationProfile, PRaiseNode.Lazy raiseNode) {
+ IsBuiltinObjectProfile stopIterationProfile, PRaiseNode raiseNode) {
CompilerAsserts.partialEvaluationConstant(length);
int stackTop = initialStackTop;
for (int i = 0; i < length; i++) {
@@ -153,7 +153,7 @@ private static int moveItemsToStack(VirtualFrame frame, Node inliningTarget, Obj
frame.setObject(stackTop--, item);
} catch (PException e) {
e.expectStopIteration(inliningTarget, stopIterationProfile);
- throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, totalLength, offset + i);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, totalLength, offset + i);
}
}
return stackTop;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java
index ba0058e701..fb9a606338 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -90,9 +90,9 @@ static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence s
}
} else {
if (len < count) {
- throw raiseNode.raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, len);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, len);
} else {
- throw raiseNode.raise(ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count);
}
}
return resultStackTop;
@@ -116,7 +116,7 @@ static int doUnpackIterable(Frame frame, int initialStackTop, Object collection,
iterator = getIter.execute(frame, inliningTarget, collection);
} catch (PException e) {
e.expectTypeError(inliningTarget, notIterableProfile);
- throw raiseNode.raise(TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection);
}
for (int i = 0; i < count; i++) {
try {
@@ -124,7 +124,7 @@ static int doUnpackIterable(Frame frame, int initialStackTop, Object collection,
frame.setObject(stackTop--, item);
} catch (PException e) {
e.expectStopIteration(inliningTarget, stopIterationProfile1);
- throw raiseNode.raise(ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, i);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, i);
}
}
try {
@@ -133,7 +133,7 @@ static int doUnpackIterable(Frame frame, int initialStackTop, Object collection,
e.expectStopIteration(inliningTarget, stopIterationProfile2);
return resultStackTop;
}
- throw raiseNode.raise(ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count);
+ throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count);
}
public static UnpackSequenceNode create() {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
index 05bd298067..2677b7ea7c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -165,7 +165,7 @@ protected static Object doType(VirtualFrame frame, PythonBuiltinClassType callab
@Shared("lookupCall") @Cached(parameters = "Call") LookupSpecialMethodSlotNode lookupCall,
@Shared("callCall") @Cached CallVarargsMethodNode callCallNode) {
Object call = lookupCall.execute(frame, getClassNode.execute(inliningTarget, callableObject), callableObject);
- return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, call);
+ return callCall(frame, inliningTarget, callableObject, arguments, keywords, raise, callCallNode, call);
}
@Specialization(guards = "isPythonClass(callableObject)", replaces = "doType")
@@ -176,7 +176,7 @@ protected static Object doPythonClass(VirtualFrame frame, Object callableObject,
@Shared("lookupCall") @Cached(parameters = "Call") LookupSpecialMethodSlotNode lookupCall,
@Shared("callCall") @Cached CallVarargsMethodNode callCallNode) {
Object call = lookupCall.execute(frame, getClassNode.execute(inliningTarget, callableObject), callableObject);
- return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, call);
+ return callCall(frame, inliningTarget, callableObject, arguments, keywords, raise, callCallNode, call);
}
@Specialization(guards = {"!isCallable(callableObject)", "!isForeignMethod(callableObject)"}, replaces = {"doType", "doPythonClass"})
@@ -187,14 +187,13 @@ protected static Object doObjectAndType(VirtualFrame frame, Object callableObjec
@Shared("lookupCall") @Cached(parameters = "Call") LookupSpecialMethodSlotNode lookupCall,
@Shared("callCall") @Cached CallVarargsMethodNode callCallNode) {
Object call = lookupCall.execute(frame, getClassNode.execute(inliningTarget, callableObject), callableObject);
- return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, call);
+ return callCall(frame, inliningTarget, callableObject, arguments, keywords, raise, callCallNode, call);
}
@Specialization
@InliningCutoff
protected static Object doForeignMethod(ForeignMethod callable, Object[] arguments, PKeyword[] keywords,
@Bind("this") Node inliningTarget,
- @Shared("raise") @Cached PRaiseNode raise,
@Cached PForeignToPTypeNode fromForeign,
@Cached InlinedBranchProfile keywordsError,
@Cached InlinedBranchProfile typeError,
@@ -202,14 +201,14 @@ protected static Object doForeignMethod(ForeignMethod callable, Object[] argumen
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop) {
if (keywords.length != 0) {
keywordsError.enter(inliningTarget);
- throw raise.raise(PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
}
gil.release(true);
try {
return fromForeign.executeConvert(interop.invokeMember(callable.receiver, callable.methodName, arguments));
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
typeError.enter(inliningTarget);
- throw raise.raise(TypeError, e);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, e);
} catch (UnknownIdentifierException e) {
// PyObjectGetMethod is supposed to have checked isMemberInvocable
throw CompilerDirectives.shouldNotReachHere("Cannot invoke member");
@@ -218,9 +217,10 @@ protected static Object doForeignMethod(ForeignMethod callable, Object[] argumen
}
}
- private static Object callCall(VirtualFrame frame, Object callableObject, Object[] arguments, PKeyword[] keywords, PRaiseNode raise, CallVarargsMethodNode callCallNode, Object call) {
+ private static Object callCall(VirtualFrame frame, Node inliningTarget, Object callableObject, Object[] arguments, PKeyword[] keywords, PRaiseNode raise, CallVarargsMethodNode callCallNode,
+ Object call) {
if (call == PNone.NO_VALUE) {
- throw raise.raise(TypeError, ErrorMessages.OBJ_ISNT_CALLABLE, callableObject);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.OBJ_ISNT_CALLABLE, callableObject);
}
return callCallNode.execute(frame, call, PythonUtils.prependArgument(callableObject, arguments), keywords);
}
@@ -311,7 +311,7 @@ protected static Object doGeneric(VirtualFrame frame, Object callableObject, Obj
inliningTarget, dispatch, createArgs, raise, getClassNode, lookupCall, callCallNode);
}
Object callableType = getClassNode.execute(inliningTarget, callableObject);
- return callCall(frame, callableObject, arguments, keywords, raise, callCallNode, lookupCall.execute(frame, callableType, callableObject));
+ return callCall(frame, inliningTarget, callableObject, arguments, keywords, raise, callCallNode, lookupCall.execute(frame, callableType, callableObject));
}
protected static boolean isForeignMethod(Object object) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
index eedc98b468..0d52b0e88b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
@@ -279,7 +279,7 @@ protected void raiseInvalidArgsNumUncached(boolean hasValidArgsNum, BuiltinMetho
@TruffleBoundary
private void raiseInvalidArgsNumUncached(BuiltinMethodDescriptor descr) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, EXPECTED_D_ARGS, descr.minNumOfPositionalArgs());
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, EXPECTED_D_ARGS, descr.minNumOfPositionalArgs());
}
protected static Object callUnaryBuiltin(VirtualFrame frame, PythonBuiltinBaseNode builtin, Object arg1) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleBinaryNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleBinaryNode.java
index 81d18936e9..b9151a55d3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleBinaryNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleBinaryNode.java
@@ -80,7 +80,6 @@ abstract class LookupAndCallReversibleBinaryNode extends LookupAndCallBinaryNode
protected final SpecialMethodSlot rslot;
private final boolean alwaysCheckReverse;
- @Child private PRaiseNode raiseNode;
@Child private GetNameNode getNameNode;
@Child private CallBinaryMethodNode reverseDispatchNode;
@@ -93,14 +92,6 @@ abstract class LookupAndCallReversibleBinaryNode extends LookupAndCallBinaryNode
this.alwaysCheckReverse = alwaysCheckReverse;
}
- private PRaiseNode ensureRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
-
private GetNameNode ensureGetNameNode() {
if (getNameNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -238,7 +229,7 @@ private Object dispatch(VirtualFrame frame, Node inliningTarget, CallBinaryMetho
// see descrobject.c/wrapperdescr_call()
Object enclosing = getEnclosingType.execute(inliningTarget, callable);
if (enclosing != null && !isSubtype.execute(leftClass, enclosing)) {
- throw ensureRaiseNode().raise(TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.getName(), ensureGetNameNode().executeCached(leftClass), leftValue);
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.DESCRIPTOR_S_REQUIRES_S_OBJ_RECEIVED_P, op.getName(), ensureGetNameNode().executeCached(leftClass), leftValue);
}
return dispatch.executeObject(frame, callable, leftValue, rightValue);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java
index 5522c20922..01f3c2587f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -335,13 +335,13 @@ static boolean fallback(VirtualFrame frame, Object derived, Object cls,
@Cached AbstractObjectIsSubclassNode abstractIsSubclassNode,
@Exclusive @Cached InlinedConditionProfile exceptionDerivedProfile,
@Exclusive @Cached InlinedConditionProfile exceptionClsProfile,
- @Cached PRaiseNode.Lazy raise) {
+ @Cached PRaiseNode raise) {
if (exceptionDerivedProfile.profile(inliningTarget, getBasesNode.execute(frame, derived) == null)) {
- throw raise.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.ARG_D_MUST_BE_S, "issubclass()", 1, "class");
+ throw raise.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ARG_D_MUST_BE_S, "issubclass()", 1, "class");
}
if (exceptionClsProfile.profile(inliningTarget, getBasesNode.execute(frame, cls) == null)) {
- throw raise.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.ISSUBCLASS_MUST_BE_CLASS_OR_TUPLE);
+ throw raise.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ISSUBCLASS_MUST_BE_CLASS_OR_TUPLE);
}
return abstractIsSubclassNode.execute(frame, derived, cls);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/ExceptMatchNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/ExceptMatchNode.java
index 589bae4724..3c71e78374 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/ExceptMatchNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/ExceptMatchNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -72,35 +72,30 @@
public abstract class ExceptMatchNode extends Node {
public abstract boolean executeMatch(Frame frame, Object exception, Object clause);
- private static void raiseIfNoException(VirtualFrame frame, Object clause, ValidExceptionNode isValidException, PRaiseNode raiseNode) {
+ private static void raiseIfNoException(VirtualFrame frame, Node inliningTarget, Object clause, ValidExceptionNode isValidException) {
if (!isValidException.execute(frame, clause)) {
- raiseNoException(raiseNode);
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonErrorType.TypeError, ErrorMessages.CATCHING_CLS_NOT_ALLOWED);
}
}
- private static void raiseNoException(PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonErrorType.TypeError, ErrorMessages.CATCHING_CLS_NOT_ALLOWED);
- }
-
@Specialization(guards = "!isPTuple(clause)")
public static boolean matchPythonSingle(VirtualFrame frame, PException e, Object clause,
@Bind("this") Node inliningTarget,
@Shared @Cached ValidExceptionNode isValidException,
@Cached GetClassNode getClassNode,
- @Cached IsSubtypeNode isSubtype,
- @Shared @Cached PRaiseNode raiseNode) {
- raiseIfNoException(frame, clause, isValidException, raiseNode);
+ @Cached IsSubtypeNode isSubtype) {
+ raiseIfNoException(frame, inliningTarget, clause, isValidException);
return isSubtype.execute(frame, getClassNode.execute(inliningTarget, e.getUnreifiedException()), clause);
}
@Specialization(guards = {"!isPTuple(clause)", "!isPException(e)"}, limit = "1")
public static boolean matchJava(VirtualFrame frame, AbstractTruffleException e, Object clause,
+ @Bind("this") Node inliningTarget,
@Shared @Cached ValidExceptionNode isValidException,
- @CachedLibrary("clause") InteropLibrary clauseLib,
- @Shared @Cached PRaiseNode raiseNode) {
+ @CachedLibrary("clause") InteropLibrary clauseLib) {
// n.b.: we can only allow Java exceptions in clauses, because we cannot tell for other
// foreign exception types if they *are* exception types
- raiseIfNoException(frame, clause, isValidException, raiseNode);
+ raiseIfNoException(frame, inliningTarget, clause, isValidException);
if (clauseLib.isMetaObject(clause)) {
try {
return clauseLib.isMetaInstance(clause, e);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
index 6f5d23cdbc..7de2eb29de 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
@@ -77,6 +77,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
@SuppressWarnings("truffle-inlining")
@@ -155,11 +156,12 @@ public abstract static class BinaryArithmeticNode extends BinaryOpNode {
static Supplier createHandler(String operator) {
return () -> new NotImplementedHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(VirtualFrame frame, Object arg, Object arg2) {
- throw raiseNode.raise(TypeError, getErrorMessage(arg), operator, arg, arg2);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, getErrorMessage(arg), operator, arg, arg2);
}
@CompilerDirectives.TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
index 535b57ecf4..63b453e941 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2022, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -49,20 +49,18 @@
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
@TypeSystemReference(PythonArithmeticTypes.class)
public abstract class BinaryComparisonNode extends BinaryOpNode {
private abstract static class ErrorNode extends BinaryComparisonNode {
- @Child private PRaiseNode raiseNode;
+ private final BranchProfile notSupportedProfile = BranchProfile.create();
protected final RuntimeException noSupported(Object left, Object right) {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, operator(), left, right);
+ notSupportedProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, operator(), left, right);
}
protected abstract String operator();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
index 2c74fe9c8c..0d5a521230 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CastToListExpressionNode.java
@@ -150,7 +150,7 @@ static PList starredGeneric(VirtualFrame frame, Object v,
return constructListNode.execute(frame, v);
} catch (PException e) {
e.expectAttributeError(inliningTarget, attrProfile);
- throw raise.raise(TypeError, ErrorMessages.OBJ_NOT_ITERABLE, v);
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.OBJ_NOT_ITERABLE, v);
} finally {
IndirectCallContext.exit(frame, language, context, state);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
index 4bf4b17619..7248ea944d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -78,6 +78,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
public enum InplaceArithmetic {
@@ -123,11 +124,12 @@ public enum InplaceArithmetic {
this.slot = slot;
this.notImplementedHandler = () -> new LookupAndCallInplaceNode.NotImplementedHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object arg, Object arg2) {
- throw raiseNode.raise(TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, operator, arg, arg2);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, operator, arg, arg2);
}
};
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
index 1a83d7d96e..142e626203 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -56,6 +56,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
public enum TernaryArithmetic {
@@ -67,14 +68,15 @@ public enum TernaryArithmetic {
TernaryArithmetic(TruffleString methodName, @SuppressWarnings("unused") String operator, String operatorFunction) {
this.methodName = methodName;
this.notImplementedHandler = () -> new NotImplementedHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object arg, Object arg2, Object arg3) {
+ errorProfile.enter();
if (arg3 instanceof PNone) {
- throw raiseNode.raise(TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_PR_S_P_AND_P, operator, operatorFunction, arg, arg2);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_PR_S_P_AND_P, operator, operatorFunction, arg, arg2);
} else {
- throw raiseNode.raise(TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, operatorFunction, arg, arg2, arg3);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, operatorFunction, arg, arg2, arg3);
}
}
};
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
index fc64f03be0..e3836dc3fd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
@@ -64,6 +64,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
+import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
public enum UnaryArithmetic {
@@ -132,11 +133,12 @@ public abstract static class UnaryArithmeticNode extends UnaryOpNode {
static Supplier createHandler(String operator) {
return () -> new NoAttributeHandler() {
- @Child private PRaiseNode raiseNode = PRaiseNode.create();
+ private final BranchProfile errorProfile = BranchProfile.create();
@Override
public Object execute(Object receiver) {
- throw raiseNode.raise(TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary ", operator, receiver);
+ errorProfile.enter();
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary ", operator, receiver);
}
};
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java
index 465481c0aa..d91eaef145 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -215,7 +215,7 @@ abstract class ReadBuiltinNode extends PNodeWithContext {
@Specialization(guards = "isSingleContext(this)")
Object returnBuiltinFromConstantModule(TruffleString attributeId,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached InlinedConditionProfile isBuiltinProfile,
@Shared @Cached ReadAttributeFromObjectNode readFromBuiltinsNode,
@SuppressWarnings("unused") @Cached("getBuiltins()") PythonModule builtins) {
@@ -223,15 +223,15 @@ Object returnBuiltinFromConstantModule(TruffleString attributeId,
}
@InliningCutoff
- private static PException raiseNameNotDefined(PRaiseNode raiseNode, TruffleString attributeId) {
- throw raiseNode.raise(NameError, ErrorMessages.NAME_NOT_DEFINED, attributeId);
+ private static PException raiseNameNotDefined(Node inliningTarget, PRaiseNode raiseNode, TruffleString attributeId) {
+ throw raiseNode.raise(inliningTarget, NameError, ErrorMessages.NAME_NOT_DEFINED, attributeId);
}
@InliningCutoff
@Specialization(replaces = "returnBuiltinFromConstantModule")
Object returnBuiltin(TruffleString attributeId,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached InlinedConditionProfile isBuiltinProfile,
@Shared @Cached ReadAttributeFromObjectNode readFromBuiltinsNode,
@Exclusive @Cached InlinedConditionProfile ctxInitializedProfile) {
@@ -239,14 +239,14 @@ Object returnBuiltin(TruffleString attributeId,
return returnBuiltinFromConstantModule(attributeId, inliningTarget, raiseNode, isBuiltinProfile, readFromBuiltinsNode, builtins);
}
- private static Object readBuiltinFromModule(TruffleString attributeId, PRaiseNode.Lazy raiseNode, Node inliningTarget,
+ private static Object readBuiltinFromModule(TruffleString attributeId, PRaiseNode raiseNode, Node inliningTarget,
InlinedConditionProfile isBuiltinProfile, PythonModule builtins,
ReadAttributeFromObjectNode readFromBuiltinsNode) {
Object builtin = readFromBuiltinsNode.execute(builtins, attributeId);
if (isBuiltinProfile.profile(inliningTarget, builtin != PNone.NO_VALUE)) {
return builtin;
} else {
- throw raiseNameNotDefined(raiseNode.get(inliningTarget), attributeId);
+ throw raiseNameNotDefined(inliningTarget, raiseNode, attributeId);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
index 5deb4769c2..94336bfc54 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonVarargsBuiltinNode.java
@@ -40,15 +40,10 @@
*/
package com.oracle.graal.python.nodes.function.builtins;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.function.PKeyword;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
-import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ControlFlowException;
-import com.oracle.truffle.api.strings.TruffleString;
/**
* Subclasses must override {@link #varArgExecute(VirtualFrame, Object, Object[], PKeyword[])} to
@@ -57,28 +52,6 @@
*/
public abstract class PythonVarargsBuiltinNode extends PythonBuiltinBaseNode {
- @Child private PRaiseNode raiseNode;
-
- protected final PRaiseNode getRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- if (isAdoptable()) {
- raiseNode = insert(PRaiseNode.create());
- } else {
- raiseNode = PRaiseNode.getUncached();
- }
- }
- return raiseNode;
- }
-
- public PException raise(PythonBuiltinClassType type, TruffleString string) {
- return getRaiseNode().raise(type, string);
- }
-
- public final PException raise(PythonBuiltinClassType type, TruffleString format, Object... arguments) {
- return getRaiseNode().raise(type, format, arguments);
- }
-
public static final class VarargsBuiltinDirectInvocationNotSupported extends ControlFlowException {
public static final VarargsBuiltinDirectInvocationNotSupported INSTANCE = new VarargsBuiltinDirectInvocationNotSupported();
private static final long serialVersionUID = 1L;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java
index 828d30d799..882fcf99ab 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -67,7 +67,6 @@
public final class WrapTpNew extends SlotWrapper {
@Child private IsTypeNode isType;
@Child private IsSubtypeNode isSubtype;
- @Child private PRaiseNode raiseNode;
@Child private LookupAttributeInMRONode lookupNewNode;
@CompilationFinal private ValueProfile builtinProfile;
@CompilationFinal private byte state = 0;
@@ -106,7 +105,7 @@ public Object execute(VirtualFrame frame) {
reportPolymorphicSpecialize();
state |= NOT_CLASS_STATE;
}
- throw getRaiseNode().raise(PythonBuiltinClassType.TypeError, ErrorMessages.NEW_X_ISNT_TYPE_OBJ, owner.getName(), cls);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.NEW_X_ISNT_TYPE_OBJ, owner.getName(), cls);
}
if (isSubtype == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -119,7 +118,7 @@ public Object execute(VirtualFrame frame) {
reportPolymorphicSpecialize();
state |= NOT_SUBTP_STATE;
}
- throw getRaiseNode().raise(PythonBuiltinClassType.TypeError,
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError,
ErrorMessages.IS_NOT_SUBTYPE_OF,
owner.getName(), cls, cls, owner.getName());
}
@@ -145,7 +144,7 @@ public Object execute(VirtualFrame frame) {
reportPolymorphicSpecialize();
state |= IS_UNSAFE_STATE;
}
- throw getRaiseNode().raise(PythonBuiltinClassType.TypeError, ErrorMessages.NEW_IS_NOT_SAFE_USE_ELSE, owner.getName(), cls, cls);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.NEW_IS_NOT_SAFE_USE_ELSE, owner.getName(), cls, cls);
}
}
// we explicitly allow non-Java functions to pass here, since a PythonBuiltinClass
@@ -177,12 +176,4 @@ private final Class extends PythonBuiltinBaseNode> getFactoryNodeClass(NodeFac
private static final Class extends PythonBuiltinBaseNode> getFactoryNodeClassUncached(NodeFactory extends PythonBuiltinBaseNode> factory) {
return factory.getNodeClass();
}
-
- private PRaiseNode getRaiseNode() {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
- return raiseNode;
- }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/CodePointConversionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/CodePointConversionNode.java
index 51625b80c1..0d85c0e369 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/CodePointConversionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/CodePointConversionNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -87,7 +87,7 @@ int doOthers(Object value,
@Cached CastToTruffleStringNode castToStringNode,
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
@Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
TruffleString str = castToStringNode.execute(inliningTarget, value);
if (codePointLengthNode.execute(str, TS_ENCODING) == 1) {
@@ -96,7 +96,7 @@ int doOthers(Object value,
} catch (CannotCastException ex) {
// handled below
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_S_NOT_P, builtinName, "unicode character", value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_S_NOT_P, builtinName, "unicode character", value);
}
@ClinicConverterFactory
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/SliceIndexConversionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/SliceIndexConversionNode.java
index cc1758b9b4..71c314477b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/SliceIndexConversionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/SliceIndexConversionNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -68,11 +68,11 @@ static int doOthers(VirtualFrame frame, Object value,
@Bind("this") Node inliningTarget,
@Cached PyIndexCheckNode indexCheckNode,
@Cached PyNumberAsSizeNode asSizeNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
if (indexCheckNode.execute(inliningTarget, value)) {
return asSizeNode.executeLossy(frame, inliningTarget, value);
}
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SLICE_INDICES_TYPE_ERROR);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SLICE_INDICES_TYPE_ERROR);
}
@ClinicConverterFactory(shortCircuitPrimitive = PrimitiveType.Int)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TruffleStringConverterNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TruffleStringConverterNode.java
index 23b5470c1e..5a54fe5b76 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TruffleStringConverterNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TruffleStringConverterNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,11 +71,11 @@ static Object doString(TruffleString value) {
Object doOthers(Object value,
@Bind("this") Node inliningTarget,
@Cached CastToTruffleStringNode castToStringNode,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return castToStringNode.execute(inliningTarget, value);
} catch (CannotCastException ex) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_S_NOT_P, builtinName, "str", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_S_NOT_P, builtinName, "str", value);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TupleConversionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TupleConversionNode.java
index e1f61306a5..173b0e94de 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TupleConversionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/TupleConversionNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -71,8 +71,8 @@ static Object[] doTuple(PTuple t,
@Fallback
static Object doOthers(Object value,
- @Cached PRaiseNode raiseNode) {
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, value, "a tuple", value);
+ @Bind("this") Node inliningTarget) {
+ throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, value, "a tuple", value);
}
@ClinicConverterFactory
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/WritableBufferConversionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/WritableBufferConversionNode.java
index eb793e1e79..1462c5e602 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/WritableBufferConversionNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/WritableBufferConversionNode.java
@@ -72,11 +72,11 @@ Object doObject(VirtualFrame frame, Object value,
@Bind PythonContext context,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("value") PythonBufferAcquireLibrary acquireLib,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return acquireLib.acquireWritable(value, frame, context, context.getLanguage(inliningTarget), indirectCallData);
} catch (PException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_READ_WRITE_BYTES_LIKE_NOT_P, builtinName, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_READ_WRITE_BYTES_LIKE_NOT_P, builtinName, value);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/interop/GetInteropBehaviorValueNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/interop/GetInteropBehaviorValueNode.java
index c7e5dfa45f..efa8715cf0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/interop/GetInteropBehaviorValueNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/interop/GetInteropBehaviorValueNode.java
@@ -77,7 +77,7 @@
@SuppressWarnings("truffle-inlining") // some of the cached nodes in the specialization are not
// inlineable
public abstract class GetInteropBehaviorValueNode extends PNodeWithContext {
- public final boolean executeBoolean(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaBooleanNode toBooleanNode, PRaiseNode.Lazy raiseNode,
+ public final boolean executeBoolean(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaBooleanNode toBooleanNode, PRaiseNode raiseNode,
PythonAbstractObject receiver, Object... extraArguments) {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
try {
@@ -85,76 +85,76 @@ public final boolean executeBoolean(Node inliningTarget, InteropBehavior behavio
try {
return toBooleanNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a boolean", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a boolean", value);
}
} catch (UnsupportedMessageException usm) {
return false;
}
}
- public final byte executeByte(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaByteNode toByteNode, PRaiseNode.Lazy raiseNode, PythonAbstractObject receiver,
+ public final byte executeByte(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaByteNode toByteNode, PRaiseNode raiseNode, PythonAbstractObject receiver,
Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toByteNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a byte", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a byte", value);
}
}
- public final short executeShort(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaShortNode toShortNode, PRaiseNode.Lazy raiseNode,
+ public final short executeShort(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaShortNode toShortNode, PRaiseNode raiseNode,
PythonAbstractObject receiver, Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toShortNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a short", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a short", value);
}
}
- public final int executeInt(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaIntExactNode toIntNode, PRaiseNode.Lazy raiseNode, PythonAbstractObject receiver,
+ public final int executeInt(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaIntExactNode toIntNode, PRaiseNode raiseNode, PythonAbstractObject receiver,
Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toIntNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "an int", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "an int", value);
}
}
- public final long executeLong(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaLongExactNode toLongNode, PRaiseNode.Lazy raiseNode,
+ public final long executeLong(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaLongExactNode toLongNode, PRaiseNode raiseNode,
PythonAbstractObject receiver, Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toLongNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a long", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a long", value);
}
}
- public final double executeDouble(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaDoubleNode toDoubleNode, PRaiseNode.Lazy raiseNode,
+ public final double executeDouble(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaDoubleNode toDoubleNode, PRaiseNode raiseNode,
PythonAbstractObject receiver, Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toDoubleNode.execute(inliningTarget, value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a double", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a double", value);
}
}
- public final String executeString(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaStringNode toStringNode, PRaiseNode.Lazy raiseNode,
+ public final String executeString(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, CastToJavaStringNode toStringNode, PRaiseNode raiseNode,
PythonAbstractObject receiver, Object... extraArguments) throws UnsupportedMessageException {
assert extraArguments.length == method.extraArguments : "number of passed arguments to GetInteropBehaviorValueNode does not match expected number of arguments for method";
Object value = execute(inliningTarget, behavior, method, receiver, extraArguments);
try {
return toStringNode.execute(value);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a string", value);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, S_MUST_BE_S_NOT_P, "return value", "a string", value);
}
}
@@ -209,7 +209,7 @@ static Object getValue(Node inliningTarget, InteropBehavior behavior, InteropBeh
static Object getValueComputedWrongArity(Node inliningTarget, InteropBehavior behavior, InteropBehaviorMethod method, PythonAbstractObject receiver, Object[] extraArguments,
@Cached PRaiseNode raiseNode) throws UnsupportedMessageException {
assert behavior.isDefined(method) : "interop behavior method is not defined!";
- throw raiseNode.raise(PythonBuiltinClassType.TypeError, FUNC_TAKES_EXACTLY_D_ARGS, method.extraArguments, extraArguments.length);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, FUNC_TAKES_EXACTLY_D_ARGS, method.extraArguments, extraArguments.length);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
index e705a89eb4..701091e9b3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java
@@ -144,7 +144,7 @@ PDict doNativeObject(PythonAbstractNativeObject object,
return dict;
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, dictObject);
+ throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.DICT_MUST_BE_SET_TO_DICT, dictObject);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
index b5d569ad8a..cdf3323ca0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java
@@ -99,7 +99,7 @@ static PDict doOther(Node inliningTarget, Object object,
PDict dict = getDict.execute(object);
if (dict == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, SystemError, ErrorMessages.UNABLE_SET_DICT_OF_OBJ, object);
+ throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.UNABLE_SET_DICT_OF_OBJ, object);
}
return dict;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
index 0b736e22e8..08631874bd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java
@@ -195,7 +195,7 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
} catch (PException e) {
// Catch the error to additionally print the collected classes and specify the error
// occurred during class creation
- throw PRaiseNode.getUncached().raiseWithCause(PythonBuiltinClassType.TypeError, e, ErrorMessages.INTEROP_CLASS_CREATION_NOT_POSSIBLE,
+ throw PRaiseNode.raiseWithCauseStatic(inliningTarget, PythonBuiltinClassType.TypeError, e, ErrorMessages.INTEROP_CLASS_CREATION_NOT_POSSIBLE,
interopLibrary.getMetaQualifiedName(metaObject),
Arrays.toString(basesWithForeign));
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
index 55e7bd700a..3679765bb6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java
@@ -118,14 +118,14 @@ public static PythonModule importModule(TruffleString name) {
PythonModule sysModule = context.lookupBuiltinModule(T_SYS);
Object modules = sysModule.getAttribute(T_MODULES);
if (modules == PNone.NO_VALUE) {
- throw PRaiseNode.getUncached().raise(RuntimeError, ErrorMessages.UNABLE_TO_GET_S, "sys.modules");
+ throw PRaiseNode.raiseStatic(null, RuntimeError, ErrorMessages.UNABLE_TO_GET_S, "sys.modules");
}
Object module = PyObjectGetItem.executeUncached(modules, name);
if (module instanceof PythonModule pythonModule) {
return pythonModule;
}
// FIXME CPython allows putting any object in sys.modules
- throw PRaiseNode.getUncached().raise(NotImplementedError, ErrorMessages.PUTTING_NON_MODULE_OBJECTS_IN_SYS_MODULES_IS_NOT_SUPPORTED);
+ throw PRaiseNode.raiseStatic(null, NotImplementedError, ErrorMessages.PUTTING_NON_MODULE_OBJECTS_IN_SYS_MODULES_IS_NOT_SUPPORTED);
}
protected final Object importModule(VirtualFrame frame, TruffleString name, Object globals, TruffleString[] fromList, int level, ImportName importNameNode) {
@@ -205,7 +205,7 @@ public abstract static class PyImportImportModuleLevelObject extends Node {
@SuppressWarnings("unused")
@Specialization(guards = "level < 0")
Object levelLtZero(VirtualFrame frame, PythonContext context, TruffleString name, Object globals, TruffleString[] fromList, int level) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, ErrorMessages.LEVEL_MUST_BE_AT_LEAST_ZERO);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.LEVEL_MUST_BE_AT_LEAST_ZERO);
}
protected static boolean containsDot(TruffleString name, TruffleString.CodePointLengthNode codePointLengthNode, TruffleString.IndexOfCodePointNode indexOfCodePointNode) {
@@ -217,7 +217,7 @@ public static Object levelZeroNoFromlist(VirtualFrame frame, PythonContext conte
@SuppressWarnings("unused") TruffleString[] fromList,
@SuppressWarnings("unused") int level,
@Bind("this") Node inliningTarget,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PyDictGetItem getModuleNode,
@Exclusive @Cached EnsureInitializedNode ensureInitialized,
@Exclusive @Cached FindAndLoad findAndLoad,
@@ -225,7 +225,7 @@ public static Object levelZeroNoFromlist(VirtualFrame frame, PythonContext conte
@Exclusive @Cached @SuppressWarnings("unused") TruffleString.IndexOfCodePointNode indexOfCodePointNode) {
final TruffleString absName = name;
if (name.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
}
PDict sysModules = context.getSysModules();
Object mod = getModuleNode.execute(frame, inliningTarget, sysModules, absName); // import_get_module
@@ -253,7 +253,7 @@ private ModuleFront(TruffleString front) {
static Object genericImport(VirtualFrame frame, PythonContext context, TruffleString name, Object globals, TruffleString[] fromList, int level,
@Bind("this") Node inliningTarget,
@Cached ResolveName resolveName,
- @Exclusive @Cached PRaiseNode.Lazy raiseNode,
+ @Exclusive @Cached PRaiseNode raiseNode,
@Exclusive @Cached PyDictGetItem getModuleNode,
@Exclusive @Cached EnsureInitializedNode ensureInitialized,
@Cached PyObjectLookupAttr getPathNode,
@@ -268,7 +268,7 @@ static Object genericImport(VirtualFrame frame, PythonContext context, TruffleSt
absName = resolveName.execute(frame, name, globals, level);
} else {
if (name.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
}
absName = name;
}
@@ -310,7 +310,7 @@ static Object genericImport(VirtualFrame frame, PythonContext context, TruffleSt
TruffleString toReturn = substringNode.execute(absName, 0, codePointLengthNode.execute(absName, TS_ENCODING) - cutoff, TS_ENCODING, true);
Object finalModule = getModuleNode.execute(frame, inliningTarget, sysModules, toReturn); // import_get_module
if (finalModule == null) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.KeyError, ErrorMessages.S_NOT_IN_SYS_MODS, toReturn);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.KeyError, ErrorMessages.S_NOT_IN_SYS_MODS, toReturn);
}
return finalModule;
}
@@ -331,7 +331,7 @@ static Object genericImport(VirtualFrame frame, PythonContext context, TruffleSt
}
static Object genericImportRecursion(VirtualFrame frame, Node inliningTarget, PythonContext context, ModuleFront front,
- PRaiseNode.Lazy raiseNode,
+ PRaiseNode raiseNode,
PyDictGetItem getModuleNode,
EnsureInitializedNode ensureInitialized,
FindAndLoad findAndLoad,
@@ -340,7 +340,7 @@ static Object genericImportRecursion(VirtualFrame frame, Node inliningTarget, Py
TruffleString.SubstringNode substringNode) {
TruffleString absName = front.front;
if (absName.isEmpty()) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.EMPTY_MOD_NAME);
}
PDict sysModules = context.getSysModules();
Object mod = getModuleNode.execute(frame, inliningTarget, sysModules, absName); // import_get_module
@@ -480,7 +480,7 @@ TruffleString resolveName(VirtualFrame frame, TruffleString name, Object globals
CompilerDirectives.transferToInterpreterAndInvalidate();
branchStates[0] |= CANNOT_CAST;
}
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, ErrorMessages.PACKAGE_MUST_BE_A_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.PACKAGE_MUST_BE_A_STRING);
}
if (spec != null && spec != PNone.NONE) {
if ((branchStates[0] & SPEC_IS_STH) == 0) {
@@ -506,7 +506,7 @@ TruffleString resolveName(VirtualFrame frame, TruffleString name, Object globals
CompilerDirectives.transferToInterpreterAndInvalidate();
branchStates[0] |= CANNOT_CAST;
}
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, ErrorMessages.SPEC_PARENT_MUST_BE_A_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.SPEC_PARENT_MUST_BE_A_STRING);
}
} else {
if ((branchStates[0] & NO_SPEC_PKG) == 0) {
@@ -526,7 +526,7 @@ TruffleString resolveName(VirtualFrame frame, TruffleString name, Object globals
CompilerDirectives.transferToInterpreterAndInvalidate();
branchStates[0] |= GOT_NO_NAME;
}
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.KeyError, ErrorMessages.NAME_NOT_IN_GLOBALS);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.KeyError, ErrorMessages.NAME_NOT_IN_GLOBALS);
}
try {
pkgString = castPackageNode.execute(inliningTarget, pkg);
@@ -535,7 +535,7 @@ TruffleString resolveName(VirtualFrame frame, TruffleString name, Object globals
CompilerDirectives.transferToInterpreterAndInvalidate();
branchStates[0] |= CANNOT_CAST;
}
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, ErrorMessages.NAME_MUST_BE_A_STRING);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.NAME_MUST_BE_A_STRING);
}
Object path = getPackageOrNameNode.execute(frame, inliningTarget, globalsDict, SpecialAttributeNames.T___PATH__);
if (path == null) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/BadOPCodeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/BadOPCodeNode.java
index 6bf32be4ca..9af5d0866a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/BadOPCodeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/BadOPCodeNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -66,7 +66,7 @@ public BadOPCodeNode(TruffleLanguage> language, TruffleString name) {
@Override
public Object execute(VirtualFrame frame) {
- throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.SystemError, ErrorMessages.UNKNOWN_OPCODE);
+ throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.SystemError, ErrorMessages.UNKNOWN_OPCODE);
}
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToByteNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToByteNode.java
index f3d49fb712..70db749531 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToByteNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToByteNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -53,7 +53,6 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.util.BiFunction;
import com.oracle.graal.python.util.OverflowException;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -61,18 +60,19 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.BranchProfile;
@ImportStatic(PGuards.class)
public abstract class CastToByteNode extends Node {
public static final CastToByteNode UNCACHED_INSTANCE = CastToByteNode.create();
- @Child private PRaiseNode raiseNode;
+ private final BranchProfile errorProfile = BranchProfile.create();
- private final BiFunction rangeErrorHandler;
- private final BiFunction typeErrorHandler;
+ private final BiFunction rangeErrorHandler;
+ private final BiFunction typeErrorHandler;
protected final boolean coerce;
- protected CastToByteNode(BiFunction rangeErrorHandler, BiFunction typeErrorHandler, boolean coerce) {
+ protected CastToByteNode(BiFunction rangeErrorHandler, BiFunction typeErrorHandler, boolean coerce) {
this.rangeErrorHandler = rangeErrorHandler;
this.typeErrorHandler = typeErrorHandler;
this.coerce = coerce;
@@ -170,27 +170,21 @@ protected byte doObject(VirtualFrame frame, Object value,
return doError(value);
}
- private byte doError(@SuppressWarnings("unused") Object val) {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
+ private byte doError(Object val) {
+ errorProfile.enter();
if (typeErrorHandler != null) {
- return typeErrorHandler.apply(val, raiseNode);
+ return typeErrorHandler.apply(this, val);
} else {
- throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED_GOT, val);
+ throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.INTEGER_REQUIRED_GOT, val);
}
}
private byte handleRangeError(Object val) {
- if (raiseNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- raiseNode = insert(PRaiseNode.create());
- }
+ errorProfile.enter();
if (rangeErrorHandler != null) {
- return rangeErrorHandler.apply(val, raiseNode);
+ return rangeErrorHandler.apply(this, val);
} else {
- throw raiseNode.raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
}
}
@@ -209,12 +203,7 @@ public static CastToByteNode create(boolean coerce) {
}
@NeverDefault
- public static CastToByteNode create(BiFunction rangeErrorHandler, BiFunction typeErrorHandler) {
+ public static CastToByteNode create(BiFunction rangeErrorHandler, BiFunction typeErrorHandler) {
return CastToByteNodeGen.create(rangeErrorHandler, typeErrorHandler, false);
}
-
- @NeverDefault
- public static CastToByteNode create(BiFunction rangeErrorHandler, BiFunction typeErrorHandler, boolean coerce) {
- return CastToByteNodeGen.create(rangeErrorHandler, typeErrorHandler, coerce);
- }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
index a51aebe08b..00e3280a87 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -101,7 +101,7 @@ protected static BigInteger fromPInt(PInt x) {
@Specialization
protected static BigInteger generic(Node inliningTarget, Object x,
- @Cached PRaiseNode.Lazy raise,
+ @Cached PRaiseNode raise,
@Cached(inline = false) CastToJavaBigIntegerNode rec,
@Cached GetClassNode getClassNode,
@Cached PyIndexCheckNode indexCheckNode,
@@ -109,6 +109,6 @@ protected static BigInteger generic(Node inliningTarget, Object x,
if (indexCheckNode.execute(inliningTarget, x)) {
return rec.execute(null, indexNode.execute(null, inliningTarget, x));
}
- throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, getClassNode.execute(inliningTarget, x));
+ throw raise.raise(inliningTarget, TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, getClassNode.execute(inliningTarget, x));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBooleanNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBooleanNode.java
index 40fa79e60c..78ee5de6ac 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBooleanNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBooleanNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -106,7 +106,7 @@ static boolean doNativeObject(Node inliningTarget, PythonNativeObject x,
@Shared @Cached(inline = false) IsSubtypeNode isSubtypeNode) {
if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, x), PythonBuiltinClassType.Boolean)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
}
// the object's type is not a subclass of 'int'
throw CannotCastException.INSTANCE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaByteNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaByteNode.java
index 4e90ebee00..84ecb014d8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaByteNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaByteNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -94,33 +94,33 @@ static byte fromPInt(PInt x) {
@Specialization(replaces = "fromInt")
@InliningCutoff
static byte fromIntErr(Node inliningTarget, int x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return PInt.byteValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
}
}
@Specialization(replaces = "fromLong")
@InliningCutoff
static byte fromLongErr(Node inliningTarget, long x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return PInt.byteValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
}
}
@Specialization(replaces = "fromPInt")
@InliningCutoff
static byte fromPIntErr(Node inliningTarget, PInt x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return x.byteValueExact();
} catch (ArithmeticException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntExactNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntExactNode.java
index 310b6d7e15..c9b3c77218 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntExactNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntExactNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -67,15 +67,15 @@
@GenerateCached
public abstract class CastToJavaIntExactNode extends CastToJavaIntNode {
- public final int executeWithThrowSystemError(Node inliningTarget, Object x, PRaiseNode.Lazy raiseNode) {
+ public final int executeWithThrowSystemError(Node inliningTarget, Object x, PRaiseNode raiseNode) {
return executeWithThrow(inliningTarget, x, raiseNode, SystemError);
}
- public final int executeWithThrow(Node inliningTarget, Object x, PRaiseNode.Lazy raiseNode, PythonBuiltinClassType errType) {
+ public final int executeWithThrow(Node inliningTarget, Object x, PRaiseNode raiseNode, PythonBuiltinClassType errType) {
try {
return execute(inliningTarget, x);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(errType, MUST_BE_S_NOT_P, "an int", x);
+ throw raiseNode.raise(inliningTarget, errType, MUST_BE_S_NOT_P, "an int", x);
}
}
@@ -117,21 +117,21 @@ static int pIntToInt(PInt x) throws OverflowException {
@Specialization(replaces = "longToInt")
static int longToIntOverflow(Node inliningTarget, long x,
- @Shared("raise") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raise") @Cached PRaiseNode raiseNode) {
try {
return PInt.intValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
}
}
@Specialization(replaces = "pIntToInt")
static int pIntToIntOverflow(Node inliningTarget, PInt x,
- @Shared("raise") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raise") @Cached PRaiseNode raiseNode) {
try {
return x.intValueExact();
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "int");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongExactNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongExactNode.java
index 5557e336df..0bae6be64f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongExactNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongExactNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -65,15 +65,15 @@
@GenerateCached(false)
public abstract class CastToJavaLongExactNode extends CastToJavaLongNode {
- public final long executeWithThrowSystemError(Node inliningTarget, Object x, PRaiseNode.Lazy raiseNode) {
+ public final long executeWithThrowSystemError(Node inliningTarget, Object x, PRaiseNode raiseNode) {
return executeWithThrow(inliningTarget, x, raiseNode, SystemError);
}
- public final long executeWithThrow(Node inliningTarget, Object x, PRaiseNode.Lazy raiseNode, PythonBuiltinClassType errType) {
+ public final long executeWithThrow(Node inliningTarget, Object x, PRaiseNode raiseNode, PythonBuiltinClassType errType) {
try {
return execute(inliningTarget, x);
} catch (CannotCastException cce) {
- throw raiseNode.get(inliningTarget).raise(errType, MUST_BE_S_NOT_P, "a long", x);
+ throw raiseNode.raise(inliningTarget, errType, MUST_BE_S_NOT_P, "a long", x);
}
}
@@ -88,11 +88,11 @@ protected static long toLongNoOverflow(PInt x) throws OverflowException {
@Specialization(replaces = "toLongNoOverflow")
protected static long toLong(Node inliningTarget, PInt x,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
try {
return x.longValueExact();
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "long");
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "long");
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongNode.java
index 65f49c412c..42d2c10365 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -94,7 +94,7 @@ static long doNativeObject(Node inliningTarget, PythonNativeObject x,
@Cached(inline = false) IsSubtypeNode isSubtypeNode) {
if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, x), PythonBuiltinClassType.PInt)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
+ throw PRaiseNode.raiseStatic(inliningTarget, NotImplementedError, ErrorMessages.CASTING_A_NATIVE_INT_OBJECT_IS_NOT_IMPLEMENTED_YET);
}
// the object's type is not a subclass of 'int'
throw CannotCastException.INSTANCE;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaShortNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaShortNode.java
index a5f9b5c724..44c254f575 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaShortNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaShortNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -92,31 +92,31 @@ static short fromPInt(PInt x) {
@Specialization(replaces = "fromInt")
static short fromIntErr(Node inliningTarget, int x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return PInt.shortValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
}
}
@Specialization(replaces = "fromLong")
static short fromLongErr(Node inliningTarget, long x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return PInt.shortValueExact(x);
} catch (OverflowException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
}
}
@Specialization(replaces = "fromPInt")
static short fromPIntErr(Node inliningTarget, PInt x,
- @Shared("raiseNode") @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared("raiseNode") @Cached PRaiseNode raiseNode) {
try {
return x.shortValueExact();
} catch (ArithmeticException e) {
- throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SHORT_MUST_BE_IN_RANGE);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
index 729cf92e31..44f8d1bf73 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -85,34 +85,33 @@ public static long executeUncached(Object arg) {
@Specialization
static long toUnsignedLong(Node inliningTarget, long x,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkNegative(x < 0, inliningTarget, raiseNode);
return x;
}
@Specialization
static long toUnsignedLong(Node inliningTarget, PInt x,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
+ @Shared @Cached PRaiseNode raiseNode) {
checkNegative(x.isNegative(), inliningTarget, raiseNode);
return convertBigInt(x.getValue(), inliningTarget);
}
@Fallback
- static long doUnsupported(Node inliningTarget, @SuppressWarnings("unused") Object x,
- @Shared @Cached PRaiseNode.Lazy raiseNode) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
+ static long doUnsupported(Node inliningTarget, @SuppressWarnings("unused") Object x) {
+ throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.INTEGER_REQUIRED);
}
- private static void checkNegative(boolean negative, Node inliningTarget, PRaiseNode.Lazy raiseNode) {
+ private static void checkNegative(boolean negative, Node inliningTarget, PRaiseNode raiseNode) {
if (negative) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
+ throw raiseNode.raise(inliningTarget, OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
}
}
@TruffleBoundary
private static long convertBigInt(BigInteger bi, Node nodeForRaise) {
if (bi.bitLength() > 64) {
- throw PRaiseNode.raiseUncached(nodeForRaise, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "unsigned long");
+ throw PRaiseNode.raiseStatic(nodeForRaise, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "unsigned long");
}
return bi.longValue();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
index 3d37ed59d9..94265ee82b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
@@ -93,7 +93,7 @@ static PComplex toComplex(VirtualFrame frame, Node inliningTarget, Object x,
@Cached(value = "create(T___COMPLEX__)", inline = false) LookupAndCallUnaryNode callComplexFunc,
@Cached PyFloatAsDoubleNode asDoubleNode,
@Bind PythonLanguage language,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
Object result = callComplexFunc.executeObject(frame, x);
if (result != PNone.NO_VALUE) {
if (result instanceof PComplex) {
@@ -104,7 +104,7 @@ static PComplex toComplex(VirtualFrame frame, Node inliningTarget, Object x,
// and may be removed in a future version of Python.
return (PComplex) result;
} else {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.SHOULD_RETURN, "__complex__", "complex object");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.SHOULD_RETURN, "__complex__", "complex object");
}
}
return PFactory.createComplex(language, asDoubleNode.execute(frame, inliningTarget, x), 0);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java
index f38d0d289a..4abb27fdc0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -1902,7 +1902,7 @@ public TruffleString crypt(TruffleString word, TruffleString salt,
cryptLibrary = InvokeNativeFunction.loadLibrary(this, PythonOS.getPythonOS() != PythonOS.PLATFORM_DARWIN ? "libcrypt.so" : null);
} catch (Throwable e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(invokeNode, PythonBuiltinClassType.SystemError, ErrorMessages.UNABLE_TO_LOAD_LIBCRYPT);
+ throw PRaiseNode.raiseStatic(invokeNode, PythonBuiltinClassType.SystemError, ErrorMessages.UNABLE_TO_LOAD_LIBCRYPT);
}
}
PosixNativeFunction function = PosixNativeFunction.crypt;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
index 2dc3794f47..4047597076 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java
@@ -2737,13 +2737,13 @@ public long getDeserializationId(TruffleString fileName) {
public void ensureLLVMLanguage(Node nodeForRaise) {
if (!env.getInternalLanguages().containsKey(J_LLVM_LANGUAGE)) {
- throw PRaiseNode.raiseUncached(nodeForRaise, PythonBuiltinClassType.SystemError, ErrorMessages.LLVM_NOT_AVAILABLE);
+ throw PRaiseNode.raiseStatic(nodeForRaise, PythonBuiltinClassType.SystemError, ErrorMessages.LLVM_NOT_AVAILABLE);
}
}
public void ensureNFILanguage(Node nodeForRaise, String optionName, String optionValue) {
if (!env.getInternalLanguages().containsKey(J_NFI_LANGUAGE)) {
- throw PRaiseNode.raiseUncached(nodeForRaise, PythonBuiltinClassType.SystemError, ErrorMessages.NFI_NOT_AVAILABLE, optionName, optionValue);
+ throw PRaiseNode.raiseStatic(nodeForRaise, PythonBuiltinClassType.SystemError, ErrorMessages.NFI_NOT_AVAILABLE, optionName, optionValue);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
index 5b16500d7c..692621f783 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/BytesFormatProcessor.java
@@ -100,7 +100,7 @@ char pop() {
try {
return (char) formatBytes[index++];
} catch (ArrayIndexOutOfBoundsException e) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.INCOMPLETE_FORMAT);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.INCOMPLETE_FORMAT);
}
}
@@ -132,7 +132,7 @@ protected double asFloat(Object arg) {
return super.asFloat(arg);
} catch (PException ex) {
// exactly like in CPython, all errors are translated to this
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.FLOAT_ARG_REQUIRED, arg);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.FLOAT_ARG_REQUIRED, arg);
}
}
@@ -182,7 +182,7 @@ protected Formatter handleSingleCharacterFormat(Spec spec) {
}
if (!foundByte) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.C_REQUIRES_INT_IN_BYTE_RANGE_OR_SINGLE_BYTE);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.C_REQUIRES_INT_IN_BYTE_RANGE_OR_SINGLE_BYTE);
}
BytesFormatter f = new BytesFormatter(buffer, spec, raisingNode);
@@ -191,7 +191,7 @@ protected Formatter handleSingleCharacterFormat(Spec spec) {
}
private PException raiseOverflow() {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE256_DECIMAL);
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE256_DECIMAL);
}
@Override
@@ -228,14 +228,14 @@ private byte[] asBytes(Object arg) {
if (attribute != PNone.NO_VALUE) {
Object bytesResult = call(attribute, arg);
if (!(bytesResult instanceof PBytes)) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__, arg);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__, arg);
}
return toBytes((PBytes) bytesResult);
}
// otherwise: use the buffer protocol
byte[] result = byteBufferAsBytesOrNull(arg);
if (result == null) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.B_REQUIRES_BYTES_OR_OBJ_THAT_IMPLEMENTS_S_NOT_P, T___BYTES__, arg);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.B_REQUIRES_BYTES_OR_OBJ_THAT_IMPLEMENTS_S_NOT_P, T___BYTES__, arg);
}
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
index 359ce10183..7d2bb423b9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java
@@ -128,7 +128,7 @@ Object getArg() {
break;
}
if (ret == null) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.NOT_ENOUGH_ARGS_FOR_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.NOT_ENOUGH_ARGS_FOR_FORMAT_STRING);
}
return ret;
}
@@ -140,11 +140,11 @@ int getNumber() {
try {
long value = CastToJavaLongLossyNode.executeUncached(o);
if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "size");
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "size");
}
return (int) value;
} catch (CannotCastException e) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.STAR_WANTS_INT);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.STAR_WANTS_INT);
}
} else {
if (Character.isDigit(c)) {
@@ -156,7 +156,7 @@ int getNumber() {
try {
return parseNumber(numStart, index);
} catch (NumberFormatException e) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.TOO_MANY_DECIMAL_DIGITS_IN_FORMAT_STRING);
}
}
index -= 1;
@@ -247,7 +247,7 @@ public T format(Object args1) {
try {
return formatImpl(args1);
} catch (OutOfMemoryError e) {
- throw PRaiseNode.raiseUncached(raisingNode, MemoryError);
+ throw PRaiseNode.raiseStatic(raisingNode, MemoryError);
}
}
@@ -311,7 +311,7 @@ private T formatImpl(Object args1) {
if (c == '(') {
// Mapping key, consisting of a parenthesised sequence of characters.
if (mapping == null) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.FORMAT_REQUIRES_MAPPING);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.FORMAT_REQUIRES_MAPPING);
}
// Scan along until a matching close parenthesis is found
int parens = 1;
@@ -450,9 +450,9 @@ private T formatImpl(Object args1) {
f = formatInteger(asNumber(arg, spec.type), spec);
if (f == null) {
if (allowsFloat(spec.type)) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.S_FORMAT_NUMBER_IS_REQUIRED_NOT_S, spec.type, arg);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.S_FORMAT_NUMBER_IS_REQUIRED_NOT_S, spec.type, arg);
} else {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.S_FORMAT_INTEGER_IS_REQUIRED_NOT_S, spec.type, arg);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.S_FORMAT_INTEGER_IS_REQUIRED_NOT_S, spec.type, arg);
}
}
break;
@@ -474,7 +474,7 @@ private T formatImpl(Object args1) {
default:
f = handleRemainingFormats(spec);
if (f == null) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.UNSUPPORTED_FORMAT_CHAR_AT_INDEX, spec.type, (int) spec.type, index - 1);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.UNSUPPORTED_FORMAT_CHAR_AT_INDEX, spec.type, (int) spec.type, index - 1);
}
}
@@ -490,7 +490,7 @@ private T formatImpl(Object args1) {
* that has not yet been used.
*/
if (argIndex == -1 || (argIndex >= 0 && PyObjectSizeNode.executeUncached(args1) >= argIndex + 1)) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.NOT_ALL_ARGS_CONVERTED_DURING_FORMATTING, getFormatType());
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.NOT_ALL_ARGS_CONVERTED_DURING_FORMATTING, getFormatType());
}
// Return the final buffer contents as a str or unicode as appropriate.
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/IntegerFormatter.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/IntegerFormatter.java
index 8d382e375d..d8b79363e7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/IntegerFormatter.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/IntegerFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) -2016 Jython Developers
*
* Licensed under PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -286,7 +286,7 @@ void format_b(BigInteger value) {
final void format_c(BigInteger value) {
assert !bytes; // for bytes we use directly BytesFormatter
if (value.signum() < 0 || value.compareTo(LIMIT_UNICODE) >= 0) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE, toHexString(LIMIT_UNICODE));
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE, toHexString(LIMIT_UNICODE));
}
result.appendCodePoint(value.intValue());
}
@@ -466,7 +466,7 @@ void format_b(int value) {
final void format_c(int value) {
assert !bytes; // for bytes we use directly BytesFormatter
if (value < 0 || value >= LIMIT_UNICODE.intValue()) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE, toHexString(LIMIT_UNICODE));
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.C_ARG_NOT_IN_RANGE, toHexString(LIMIT_UNICODE));
}
result.appendCodePoint(value);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java
index e9b7ef25a6..ca4d7e6df3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) -2016 Jython Developers
*
* Licensed under PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -508,7 +508,7 @@ protected void zeroPadAfterSignWithGroupingFixup(int groupSize, char comma) {
* @return exception to throw
*/
public static PException unknownFormat(char code, String forType, Node raisingNode) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.UNKNOWN_FORMAT_CODE, code, forType);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.UNKNOWN_FORMAT_CODE, code, forType);
}
/**
@@ -520,7 +520,7 @@ public static PException unknownFormat(char code, String forType, Node raisingNo
* @return exception to throw
*/
public PException precisionTooLarge(String type) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, ErrorMessages.FORMATED_S_TOO_LONG, type);
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, ErrorMessages.FORMATED_S_TOO_LONG, type);
}
}
@@ -806,7 +806,7 @@ Spec parse(char defaultType, char defaultAlignment, Node raisingNode) {
width = scanInteger();
} catch (NumberFormatException ex) {
// CPython seems to happily parse big ints and then it chokes on the allocation
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.WIDTH_TOO_BIG);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.WIDTH_TOO_BIG);
}
}
@@ -816,11 +816,11 @@ Spec parse(char defaultType, char defaultAlignment, Node raisingNode) {
}
if (scanPast('_')) {
if (specified(grouping)) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_BOTH_COMMA_AND_UNDERSCORE);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_BOTH_COMMA_AND_UNDERSCORE);
}
grouping = '_';
if (scanPast(',')) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_BOTH_COMMA_AND_UNDERSCORE);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_BOTH_COMMA_AND_UNDERSCORE);
}
}
@@ -830,10 +830,10 @@ Spec parse(char defaultType, char defaultAlignment, Node raisingNode) {
try {
precision = scanInteger();
} catch (NumberFormatException ex) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.PRECISION_TOO_BIG);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.PRECISION_TOO_BIG);
}
} else {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.FMT_SPECIFIER_MISSING_PRECISION);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.FMT_SPECIFIER_MISSING_PRECISION);
}
}
@@ -844,7 +844,7 @@ Spec parse(char defaultType, char defaultAlignment, Node raisingNode) {
// If we haven't reached the end, something is wrong
if (ptr != spec.length()) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.INVALID_CONVERSION_SPECIFICATION);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.INVALID_CONVERSION_SPECIFICATION);
}
// Some basic validation
@@ -875,7 +875,7 @@ Spec parse(char defaultType, char defaultAlignment, Node raisingNode) {
valid = false;
}
if (!valid) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_C_WITH_C, grouping, type);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.CANNOT_SPECIFY_C_WITH_C, grouping, type);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java
index 29d67a20a4..b16ebcdc2b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) -2016 Jython Developers
*
* Licensed under PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -45,7 +45,7 @@ public char pop() {
try {
return formatText.charAt(index++);
} catch (StringIndexOutOfBoundsException e) {
- throw PRaiseNode.raiseUncached(raisingNode, ValueError, ErrorMessages.INCOMPLETE_FORMAT);
+ throw PRaiseNode.raiseStatic(raisingNode, ValueError, ErrorMessages.INCOMPLETE_FORMAT);
}
}
@@ -91,7 +91,7 @@ protected InternalFormat.Formatter handleSingleCharacterFormat(Spec spec) {
} else {
f = formatInteger(asNumber(arg, spec.type), spec);
if (f == null) {
- throw PRaiseNode.raiseUncached(raisingNode, TypeError, ErrorMessages.REQUIRES_INT_OR_CHAR, spec.type);
+ throw PRaiseNode.raiseStatic(raisingNode, TypeError, ErrorMessages.REQUIRES_INT_OR_CHAR, spec.type);
}
}
return f;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
index 2d139cbe55..d071d14823 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
@@ -25,6 +25,8 @@
*/
package com.oracle.graal.python.runtime.object;
+import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
+
import java.lang.ref.ReferenceQueue;
import java.math.BigInteger;
import java.util.LinkedHashMap;
@@ -907,12 +909,12 @@ public static PBaseException createBaseException(PythonLanguage language, Object
* guarantee on how many. Therefore, it is important that this method is simple. In particular,
* do not add calls if that can be avoided.
*/
- public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, TruffleString format, Object[] args) {
- return createBaseException(language, cls, shape, null, format, args);
+ public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, TruffleString format, Object[] formatArgs) {
+ return createBaseException(language, cls, shape, null, format, formatArgs);
}
- public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, TruffleString format, Object[] args) {
- return createBaseException(language, type, type.getInstanceShape(language), null, format, args);
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, TruffleString format, Object[] formatArgs) {
+ return createBaseException(language, type, type.getInstanceShape(language), null, format, formatArgs);
}
public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, Object[] data, TruffleString format, Object[] args) {
@@ -932,12 +934,8 @@ public static PBaseException createBaseException(PythonLanguage language, Python
return create(language, () -> new PBaseException(type, type.getInstanceShape(language), null));
}
- public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, Object[] data) {
- return createBaseException(language, type, type.getInstanceShape(language), data);
- }
-
- public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data) {
- return create(language, () -> new PBaseException(cls, shape, data));
+ public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, TruffleString format) {
+ return create(language, () -> new PBaseException(type, type.getInstanceShape(language), null, format, EMPTY_OBJECT_ARRAY));
}
public static PBaseExceptionGroup createBaseExceptionGroup(PythonLanguage language, Object cls, Shape shape, TruffleString message, Object[] exceptions, Object[] args) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ForeignSequenceStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ForeignSequenceStorage.java
index 427909f13f..95dca71385 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ForeignSequenceStorage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ForeignSequenceStorage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,9 @@
*/
package com.oracle.graal.python.runtime.sequence.storage;
+import static com.oracle.graal.python.runtime.exception.PythonErrorType.IndexError;
+import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
+
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -63,9 +66,6 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.IndexError;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-
/*
* NOTE: We are not using IndirectCallContext here in this file because it seems unlikely that these interop messages
* would call back to Python and that we would also need precise frame info for that case.
@@ -131,14 +131,14 @@ public abstract static class ReadNoConversionNode extends PNodeWithContext {
static Object read(Node inliningTarget, ForeignSequenceStorage storage, int index,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
return interop.readArrayElement(storage.foreignArray, index);
} catch (UnsupportedMessageException ex) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_READABLE, index, storage.foreignArray);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_READABLE, index, storage.foreignArray);
} catch (InvalidArrayIndexException ex) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.INVALID_INDEX_S, index);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.INVALID_INDEX_S, index);
} finally {
gil.acquire();
}
@@ -172,16 +172,16 @@ public abstract static class WriteNode extends PNodeWithContext {
static void write(Node inliningTarget, ForeignSequenceStorage storage, int index, Object value,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
interop.writeArrayElement(storage.foreignArray, index, value);
} catch (InvalidArrayIndexException e) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.INVALID_INDEX_S, index);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.INVALID_INDEX_S, index);
} catch (UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_WRITABLE, index, storage.foreignArray);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_WRITABLE, index, storage.foreignArray);
} catch (UnsupportedTypeException e) {
- throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.TYPE_P_NOT_SUPPORTED_BY_FOREIGN_OBJ, value);
} finally {
gil.acquire();
}
@@ -199,12 +199,12 @@ public abstract static class RemoveNode extends PNodeWithContext {
static void remove(Node inliningTarget, ForeignSequenceStorage storage, int index,
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") InteropLibrary interop,
@Cached(inline = false) GilNode gil,
- @Cached PRaiseNode.Lazy raiseNode) {
+ @Cached PRaiseNode raiseNode) {
gil.release(true);
try {
interop.removeArrayElement(storage.foreignArray, index);
} catch (InvalidArrayIndexException | UnsupportedMessageException e) {
- throw raiseNode.get(inliningTarget).raise(IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_REMOVABLE, index, storage.foreignArray);
+ throw raiseNode.raise(inliningTarget, IndexError, ErrorMessages.ITEM_S_OF_S_OBJ_IS_NOT_REMOVABLE, index, storage.foreignArray);
} finally {
gil.acquire();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java
index 1d99d9a29f..adba7ba6bc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -127,7 +127,7 @@ static short floatToShortBits(double value, Node raisingNode) {
e = (int) fraction[1];
if (f < 0.5 || f >= 1.0) {
- throw PRaiseNode.raiseUncached(raisingNode, SystemError, RES_O_O_RANGE, "frexp()");
+ throw PRaiseNode.raiseStatic(raisingNode, SystemError, RES_O_O_RANGE, "frexp()");
}
// Normalize f to be in the range [1.0, 2.0)
@@ -135,7 +135,7 @@ static short floatToShortBits(double value, Node raisingNode) {
e--;
if (e >= 16) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "e");
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "e");
} else if (e < -25) {
// |x| < 2**-25. Underflow to zero.
f = 0.0;
@@ -162,7 +162,7 @@ static short floatToShortBits(double value, Node raisingNode) {
bits = 0;
++e;
if (e == 31) {
- throw PRaiseNode.raiseUncached(raisingNode, OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "e");
+ throw PRaiseNode.raiseStatic(raisingNode, OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "e");
}
}
}
@@ -391,7 +391,7 @@ public double getDouble(byte[] buffer, int index, int numBytes) throws IndexOutO
}
}
- public void putDouble(Node inliningTarget, byte[] buffer, int index, double value, int numBytes, PRaiseNode.Lazy raiseNode) throws IndexOutOfBoundsException {
+ public void putDouble(Node inliningTarget, byte[] buffer, int index, double value, int numBytes, PRaiseNode raiseNode) throws IndexOutOfBoundsException {
switch (numBytes) {
case 2:
putHalfFloat(buffer, index, value, inliningTarget);
@@ -399,7 +399,7 @@ public void putDouble(Node inliningTarget, byte[] buffer, int index, double valu
case 4:
final float fValue = (float) value;
if (Float.isInfinite(fValue) && Double.isFinite(value)) {
- throw raiseNode.get(inliningTarget).raise(OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "f");
+ throw raiseNode.raise(inliningTarget, OverflowError, FLOAT_TO_LARGE_TO_PACK_WITH_S_FMT, "f");
}
putFloat(buffer, index, fValue);
break;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
index 2700fa86c3..d47f9bf51f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java
@@ -471,7 +471,7 @@ public static int toIntError(long x) {
int r = (int) x;
if (r != x) {
CompilerDirectives.transferToInterpreterAndInvalidate();
- throw PRaiseNode.raiseUncached(null, SystemError, ErrorMessages.INTERNAL_INT_OVERFLOW);
+ throw PRaiseNode.raiseStatic(null, SystemError, ErrorMessages.INTERNAL_INT_OVERFLOW);
}
return r;
}
From 02e6a9012db1347facf61b4cf5a5f5902e76d6a1 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Mon, 10 Feb 2025 09:48:49 +0100
Subject: [PATCH 017/512] Don't use lambdas in PFactory for now
---
.../graal/python/runtime/object/PFactory.java | 457 +++++++++---------
1 file changed, 225 insertions(+), 232 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
index d071d14823..55aa0456f9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java
@@ -259,28 +259,25 @@ public final class PFactory {
private PFactory() {
}
- private static T create(PythonLanguage language, Supplier constructor) {
+ private static T trace(PythonLanguage language, T newInstance) {
AllocationReporter reporter = language.getAllocationReporter();
if (reporter.isActive()) {
- return createWithTrace(constructor, reporter);
- } else {
- return constructor.get();
+ doTrace(newInstance, reporter);
}
+ return newInstance;
}
@InliningCutoff
- private static T createWithTrace(Supplier constructor, AllocationReporter reporter) {
+ private static void doTrace(T newInstance, AllocationReporter reporter) {
reporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
- T allocatedObject = constructor.get();
- reporter.onReturnValue(allocatedObject, 0, AllocationReporter.SIZE_UNKNOWN);
- return allocatedObject;
+ reporter.onReturnValue(newInstance, 0, AllocationReporter.SIZE_UNKNOWN);
}
/*
* Python objects
*/
public static PythonObject createPythonObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> (new PythonObject(cls, shape)));
+ return trace(language, new PythonObject(cls, shape));
}
/**
@@ -288,15 +285,15 @@ public static PythonObject createPythonObject(PythonLanguage language, Object cl
* shape had been cached, due to the additional shape lookup.
*/
public static PythonObject createPythonHPyObject(PythonLanguage language, Object cls, Shape shape, Object hpyNativeSpace) {
- return create(language, () -> new PythonHPyObject(cls, shape, hpyNativeSpace));
+ return trace(language, new PythonHPyObject(cls, shape, hpyNativeSpace));
}
public static PythonNativeVoidPtr createNativeVoidPtr(PythonLanguage language, Object obj) {
- return create(language, () -> new PythonNativeVoidPtr(obj));
+ return trace(language, new PythonNativeVoidPtr(obj));
}
public static PythonNativeVoidPtr createNativeVoidPtr(PythonLanguage language, Object obj, long nativePtr) {
- return create(language, () -> new PythonNativeVoidPtr(obj, nativePtr));
+ return trace(language, new PythonNativeVoidPtr(obj, nativePtr));
}
public static SuperObject createSuperObject(PythonLanguage language) {
@@ -304,7 +301,7 @@ public static SuperObject createSuperObject(PythonLanguage language) {
}
public static SuperObject createSuperObject(PythonLanguage language, Object self, Shape shape) {
- return create(language, () -> new SuperObject(self, shape));
+ return trace(language, new SuperObject(self, shape));
}
public static PInt createInt(PythonLanguage language, long value) {
@@ -325,7 +322,7 @@ public static PInt createInt(PythonLanguage language, Object cls, Shape shape, l
}
public static PInt createInt(PythonLanguage language, Object cls, Shape shape, BigInteger value) {
- return create(language, () -> new PInt(cls, shape, value));
+ return trace(language, new PInt(cls, shape, value));
}
public static PFloat createFloat(PythonLanguage language, double value) {
@@ -333,7 +330,7 @@ public static PFloat createFloat(PythonLanguage language, double value) {
}
public static PFloat createFloat(PythonLanguage language, Object cls, Shape shape, double value) {
- return create(language, () -> new PFloat(cls, shape, value));
+ return trace(language, new PFloat(cls, shape, value));
}
public static PString createString(PythonLanguage language, TruffleString string) {
@@ -341,7 +338,7 @@ public static PString createString(PythonLanguage language, TruffleString string
}
public static PString createString(PythonLanguage language, Object cls, Shape shape, TruffleString string) {
- return create(language, () -> new PString(cls, shape, string));
+ return trace(language, new PString(cls, shape, string));
}
public static PString createString(PythonLanguage language, NativeCharSequence string) {
@@ -349,7 +346,7 @@ public static PString createString(PythonLanguage language, NativeCharSequence s
}
public static PString createString(PythonLanguage language, Object cls, Shape shape, NativeCharSequence string) {
- return create(language, () -> new PString(cls, shape, string));
+ return trace(language, new PString(cls, shape, string));
}
public static PBytes createEmptyBytes(PythonLanguage language) {
@@ -377,7 +374,7 @@ public static PBytes createBytes(PythonLanguage language, Object cls, Shape shap
}
public static PBytes createBytes(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage) {
- return create(language, () -> new PBytes(cls, shape, storage));
+ return trace(language, new PBytes(cls, shape, storage));
}
public static PTuple createEmptyTuple(PythonLanguage language) {
@@ -401,7 +398,7 @@ public static PTuple createTuple(PythonLanguage language, SequenceStorage store)
}
public static PTuple createTuple(PythonLanguage language, Object cls, Shape shape, SequenceStorage store) {
- return create(language, () -> new PTuple(cls, shape, store));
+ return trace(language, new PTuple(cls, shape, store));
}
public static PTuple createStructSeq(PythonLanguage language, BuiltinTypeDescriptor desc, Object... values) {
@@ -414,11 +411,11 @@ public static PTupleGetter createTupleGetter(PythonLanguage language, int index,
}
public static PTupleGetter createTupleGetter(PythonLanguage language, Object cls, Shape shape, int index, Object doc) {
- return create(language, () -> new PTupleGetter(cls, shape, index, doc));
+ return trace(language, new PTupleGetter(cls, shape, index, doc));
}
public static PComplex createComplex(PythonLanguage language, Object cls, Shape shape, double real, double imag) {
- return create(language, () -> new PComplex(cls, shape, real, imag));
+ return trace(language, new PComplex(cls, shape, real, imag));
}
public static PComplex createComplex(PythonLanguage language, double real, double imag) {
@@ -426,31 +423,31 @@ public static PComplex createComplex(PythonLanguage language, double real, doubl
}
public static PIntRange createIntRange(PythonLanguage language, int stop) {
- return create(language, () -> new PIntRange(language, 0, stop, 1, stop));
+ return trace(language, new PIntRange(language, 0, stop, 1, stop));
}
public static PIntRange createIntRange(PythonLanguage language, int start, int stop, int step, int len) {
- return create(language, () -> new PIntRange(language, start, stop, step, len));
+ return trace(language, new PIntRange(language, start, stop, step, len));
}
public static PBigRange createBigRange(PythonLanguage language, PInt start, PInt stop, PInt step, PInt len) {
- return create(language, () -> new PBigRange(language, start, stop, step, len));
+ return trace(language, new PBigRange(language, start, stop, step, len));
}
public static PIntSlice createIntSlice(PythonLanguage language, int start, int stop, int step) {
- return create(language, () -> new PIntSlice(language, start, stop, step));
+ return trace(language, new PIntSlice(language, start, stop, step));
}
public static PIntSlice createIntSlice(PythonLanguage language, int start, int stop, int step, boolean isStartNone, boolean isStepNone) {
- return create(language, () -> new PIntSlice(language, start, stop, step, isStartNone, isStepNone));
+ return trace(language, new PIntSlice(language, start, stop, step, isStartNone, isStepNone));
}
public static PObjectSlice createObjectSlice(PythonLanguage language, Object start, Object stop, Object step) {
- return create(language, () -> new PObjectSlice(language, start, stop, step));
+ return trace(language, new PObjectSlice(language, start, stop, step));
}
public static PRandom createRandom(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PRandom(cls, shape));
+ return trace(language, new PRandom(cls, shape));
}
/*
@@ -461,11 +458,11 @@ public static PRandom createRandom(PythonLanguage language, Object cls, Shape sh
* Only to be used during context creation
*/
public static PythonModule createPythonModule(PythonLanguage language, TruffleString name) {
- return create(language, () -> PythonModule.createInternal(name));
+ return trace(language, PythonModule.createInternal(name));
}
public static PythonModule createPythonModule(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PythonModule(cls, shape));
+ return trace(language, new PythonModule(cls, shape));
}
public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language, TruffleString name, Object base, PythonAbstractClass[] bases) {
@@ -473,7 +470,7 @@ public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language
}
public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language, Object metaclass, Shape metaclassShape, TruffleString name, Object base, PythonAbstractClass[] bases) {
- PythonClass result = create(language, () -> new PythonClass(language, metaclass, metaclassShape, name, base, bases));
+ PythonClass result = trace(language, new PythonClass(language, metaclass, metaclassShape, name, base, bases));
// Fixup tp slots
MroSequenceStorage mro = GetMroStorageNode.executeUncached(result);
SpecialMethodSlot.initializeSpecialMethodSlots(result, mro, language);
@@ -486,27 +483,27 @@ public static PythonClass createPythonClassAndFixupSlots(PythonLanguage language
public static PythonClass createPythonClass(PythonLanguage language, Object metaclass, Shape metaclassShape, TruffleString name, boolean invokeMro, Object base, PythonAbstractClass[] bases) {
// Note: called from type ctor, which itself will invoke setupSpecialMethodSlots at the
// right point
- return create(language, () -> new PythonClass(language, metaclass, metaclassShape, name, invokeMro, base, bases));
+ return trace(language, new PythonClass(language, metaclass, metaclassShape, name, invokeMro, base, bases));
}
public static PMemoryView createMemoryView(PythonLanguage language, PythonContext context, BufferLifecycleManager bufferLifecycleManager, Object buffer, Object owner,
int len, boolean readonly, int itemsize, BufferFormat format, TruffleString formatString, int ndim, Object bufPointer,
int offset, int[] shape, int[] strides, int[] suboffsets, int flags) {
PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
- return create(language, () -> new PMemoryView(cls, cls.getInstanceShape(language), context, bufferLifecycleManager, buffer, owner, len, readonly, itemsize, format, formatString,
+ return trace(language, new PMemoryView(cls, cls.getInstanceShape(language), context, bufferLifecycleManager, buffer, owner, len, readonly, itemsize, format, formatString,
ndim, bufPointer, offset, shape, strides, suboffsets, flags));
}
public static PMemoryView createMemoryViewForManagedObject(PythonLanguage language, Object buffer, Object owner, int itemsize, int length, boolean readonly, TruffleString format,
TruffleString.CodePointLengthNode lengthNode, TruffleString.CodePointAtIndexNode atIndexNode) {
PythonBuiltinClassType cls = PythonBuiltinClassType.PMemoryView;
- return create(language, () -> new PMemoryView(cls, cls.getInstanceShape(language), null, null, buffer, owner, length, readonly, itemsize,
+ return trace(language, new PMemoryView(cls, cls.getInstanceShape(language), null, null, buffer, owner, length, readonly, itemsize,
BufferFormat.forMemoryView(format, lengthNode, atIndexNode), format, 1, null, 0, new int[]{length / itemsize}, new int[]{itemsize}, null,
PMemoryView.FLAG_C | PMemoryView.FLAG_FORTRAN));
}
public static PMethod createMethod(PythonLanguage language, Object cls, Shape shape, Object self, Object function) {
- return create(language, () -> new PMethod(cls, shape, self, function));
+ return trace(language, new PMethod(cls, shape, self, function));
}
public static PMethod createMethod(PythonLanguage language, Object self, Object function) {
@@ -518,11 +515,11 @@ public static PMethod createBuiltinMethod(PythonLanguage language, Object self,
}
public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object cls, Shape shape, Object self, PBuiltinFunction function) {
- return create(language, () -> new PBuiltinMethod(cls, shape, self, function, null));
+ return trace(language, new PBuiltinMethod(cls, shape, self, function, null));
}
public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object self, PBuiltinFunction function, Object classObject) {
- return create(language, () -> new PBuiltinMethod(PythonBuiltinClassType.PBuiltinMethod, PythonBuiltinClassType.PBuiltinMethod.getInstanceShape(language), self, function, classObject));
+ return trace(language, new PBuiltinMethod(PythonBuiltinClassType.PBuiltinMethod, PythonBuiltinClassType.PBuiltinMethod.getInstanceShape(language), self, function, classObject));
}
public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object self, PBuiltinFunction function) {
@@ -530,82 +527,80 @@ public static PBuiltinMethod createBuiltinMethod(PythonLanguage language, Object
}
public static PFunction createFunction(PythonLanguage language, TruffleString name, PCode code, PythonObject globals, PCell[] closure) {
- return create(language, () -> new PFunction(language, name, name, code, globals, closure));
+ return trace(language, new PFunction(language, name, name, code, globals, closure));
}
public static PFunction createFunction(PythonLanguage language, TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
PCell[] closure) {
- return create(language, () -> new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure));
+ return trace(language, new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure));
}
public static PFunction createFunction(PythonLanguage language, TruffleString name, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
- return create(language, () -> new PFunction(language, name, name, code, globals, defaultValues, kwDefaultValues, closure));
+ return trace(language, new PFunction(language, name, name, code, globals, defaultValues, kwDefaultValues, closure));
}
public static PFunction createFunction(PythonLanguage language, TruffleString name, TruffleString qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
PCell[] closure,
Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
- return create(language, () -> new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure,
+ return trace(language, new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure,
codeStableAssumption, defaultsStableAssumption));
}
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget) {
- return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type,
+ return trace(language, new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type,
PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget));
}
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget) {
- return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type, defaults, kw, flags,
+ return trace(language, new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, type, defaults, kw, flags,
callTarget));
}
public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language, TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget, TpSlot slot,
PExternalFunctionWrapper slotWrapper) {
- return create(language, () -> new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type,
+ return trace(language, new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type,
PBuiltinFunction.generateDefaults(numDefaults), null, flags, callTarget, slot, slotWrapper));
}
public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language, TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget,
TpSlot slot, PExternalFunctionWrapper slotWrapper) {
- return create(language,
- () -> new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type, defaults, kw, flags,
- callTarget, slot, slotWrapper));
+ return trace(language, new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type, defaults, kw, flags,
+ callTarget, slot, slotWrapper));
}
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, PBuiltinFunction function, Object klass) {
PythonBuiltinClassType type = (PythonBuiltinClassType) function.getInitialPythonClass();
- return create(language, () -> new PBuiltinFunction(type, type.getInstanceShape(language), function.getName(), klass,
+ return trace(language, new PBuiltinFunction(type, type.getInstanceShape(language), function.getName(), klass,
function.getDefaults(), function.getKwDefaults(), function.getFlags(), function.getCallTarget(),
function.getSlot(), function.getSlotWrapper()));
}
public static GetSetDescriptor createGetSetDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type) {
- return create(language, () -> new GetSetDescriptor(language, get, set, name, type));
+ return trace(language, new GetSetDescriptor(language, get, set, name, type));
}
public static GetSetDescriptor createGetSetDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type, boolean allowsDelete) {
- return create(language, () -> new GetSetDescriptor(language, get, set, name, type, allowsDelete));
+ return trace(language, new GetSetDescriptor(language, get, set, name, type, allowsDelete));
}
public static GetSetDescriptor createMemberDescriptor(PythonLanguage language, Object get, Object set, TruffleString name, Object type) {
- return create(language,
- () -> new GetSetDescriptor(PythonBuiltinClassType.MemberDescriptor, PythonBuiltinClassType.MemberDescriptor.getInstanceShape(language), get, set, name, type, set != null));
+ return trace(language, new GetSetDescriptor(PythonBuiltinClassType.MemberDescriptor, PythonBuiltinClassType.MemberDescriptor.getInstanceShape(language), get, set, name, type, set != null));
}
public static IndexedSlotDescriptor createIndexedSlotDescriptor(PythonLanguage language, TruffleString name, int index, Object type) {
- return create(language, () -> new IndexedSlotDescriptor(language, name, index, type));
+ return trace(language, new IndexedSlotDescriptor(language, name, index, type));
}
public static PDecoratedMethod createClassmethod(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PDecoratedMethod(cls, shape));
+ return trace(language, new PDecoratedMethod(cls, shape));
}
public static PDecoratedMethod createClassmethodFromCallableObj(PythonLanguage language, Object callable) {
- return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PClassmethod, PythonBuiltinClassType.PClassmethod.getInstanceShape(language), callable));
+ return trace(language, new PDecoratedMethod(PythonBuiltinClassType.PClassmethod, PythonBuiltinClassType.PClassmethod.getInstanceShape(language), callable));
}
public static PDecoratedMethod createBuiltinClassmethodFromCallableObj(PythonLanguage language, Object callable) {
- return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PBuiltinClassMethod, PythonBuiltinClassType.PBuiltinClassMethod.getInstanceShape(language), callable));
+ return trace(language, new PDecoratedMethod(PythonBuiltinClassType.PBuiltinClassMethod, PythonBuiltinClassType.PBuiltinClassMethod.getInstanceShape(language), callable));
}
public static PDecoratedMethod createInstancemethod(PythonLanguage language) {
@@ -613,7 +608,7 @@ public static PDecoratedMethod createInstancemethod(PythonLanguage language) {
}
public static PDecoratedMethod createInstancemethod(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PDecoratedMethod(cls, shape));
+ return trace(language, new PDecoratedMethod(cls, shape));
}
public static PDecoratedMethod createStaticmethod(PythonLanguage language) {
@@ -621,7 +616,7 @@ public static PDecoratedMethod createStaticmethod(PythonLanguage language) {
}
public static PDecoratedMethod createStaticmethod(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PDecoratedMethod(cls, shape));
+ return trace(language, new PDecoratedMethod(cls, shape));
}
public static PDecoratedMethod createStaticmethodFromCallableObj(PythonLanguage language, Object callable) {
@@ -636,7 +631,7 @@ public static PDecoratedMethod createStaticmethodFromCallableObj(PythonLanguage
} else {
func = callable;
}
- return create(language, () -> new PDecoratedMethod(PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PStaticmethod.getInstanceShape(language), func));
+ return trace(language, new PDecoratedMethod(PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PStaticmethod.getInstanceShape(language), func));
}
/*
@@ -668,7 +663,7 @@ public static PList createList(PythonLanguage language, Object cls, Shape shape,
}
public static PList createList(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage, PList.ListOrigin origin) {
- return create(language, () -> new PList(cls, shape, storage, origin));
+ return trace(language, new PList(cls, shape, storage, origin));
}
public static PSet createSet(PythonLanguage language) {
@@ -684,7 +679,7 @@ public static PSet createSet(PythonLanguage language, Object cls, Shape shape) {
}
public static PSet createSet(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
- return create(language, () -> new PSet(cls, shape, storage));
+ return trace(language, new PSet(cls, shape, storage));
}
public static PFrozenSet createFrozenSet(PythonLanguage language) {
@@ -696,7 +691,7 @@ public static PFrozenSet createFrozenSet(PythonLanguage language, HashingStorage
}
public static PFrozenSet createFrozenSet(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
- return create(language, () -> new PFrozenSet(cls, shape, storage));
+ return trace(language, new PFrozenSet(cls, shape, storage));
}
public static PDict createDict(PythonLanguage language) {
@@ -712,31 +707,31 @@ public static PDict createDict(PythonLanguage language, HashingStorage storage)
}
public static PDict createDict(PythonLanguage language, Object cls, Shape shape, HashingStorage storage) {
- return create(language, () -> new PDict(cls, shape, storage));
+ return trace(language, new PDict(cls, shape, storage));
}
public static POrderedDict createOrderedDict(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new POrderedDict(cls, shape));
+ return trace(language, new POrderedDict(cls, shape));
}
public static PDictKeysView createOrderedDictKeys(PythonLanguage language, POrderedDict dict) {
PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictKeys;
- return create(language, () -> new PDictKeysView(cls, cls.getInstanceShape(language), dict));
+ return trace(language, new PDictKeysView(cls, cls.getInstanceShape(language), dict));
}
public static PDictValuesView createOrderedDictValues(PythonLanguage language, POrderedDict dict) {
PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictValues;
- return create(language, () -> new PDictValuesView(cls, cls.getInstanceShape(language), dict));
+ return trace(language, new PDictValuesView(cls, cls.getInstanceShape(language), dict));
}
public static PDictItemsView createOrderedDictItems(PythonLanguage language, POrderedDict dict) {
PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictItems;
- return create(language, () -> new PDictItemsView(cls, cls.getInstanceShape(language), dict));
+ return trace(language, new PDictItemsView(cls, cls.getInstanceShape(language), dict));
}
public static POrderedDictIterator createOrderedDictIterator(PythonLanguage language, POrderedDict dict, POrderedDictIterator.IteratorType type, boolean reversed) {
PythonBuiltinClassType cls = PythonBuiltinClassType.POrderedDictIterator;
- return create(language, () -> new POrderedDictIterator(cls, cls.getInstanceShape(language), dict, type, reversed));
+ return trace(language, new POrderedDictIterator(cls, cls.getInstanceShape(language), dict, type, reversed));
}
public static PDict createDictFromMap(PythonLanguage language, LinkedHashMap map) {
@@ -767,19 +762,19 @@ public static PSimpleNamespace createSimpleNamespace(PythonLanguage language) {
}
public static PSimpleNamespace createSimpleNamespace(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PSimpleNamespace(cls, shape));
+ return trace(language, new PSimpleNamespace(cls, shape));
}
public static PKeyWrapper createKeyWrapper(PythonLanguage language, Object cmp) {
- return create(language, () -> new PKeyWrapper(PythonBuiltinClassType.PKeyWrapper, PythonBuiltinClassType.PKeyWrapper.getInstanceShape(language), cmp));
+ return trace(language, new PKeyWrapper(PythonBuiltinClassType.PKeyWrapper, PythonBuiltinClassType.PKeyWrapper.getInstanceShape(language), cmp));
}
public static PPartial createPartial(PythonLanguage language, Object cls, Shape shape, Object function, Object[] args, PDict kwDict) {
- return create(language, () -> new PPartial(cls, shape, function, args, kwDict));
+ return trace(language, new PPartial(cls, shape, function, args, kwDict));
}
public static LruCacheObject createLruCacheObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new LruCacheObject(cls, shape));
+ return trace(language, new LruCacheObject(cls, shape));
}
public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape) {
@@ -787,7 +782,7 @@ public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls
}
public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape, Object defaultFactory) {
- return create(language, () -> new PDefaultDict(cls, shape, defaultFactory));
+ return trace(language, new PDefaultDict(cls, shape, defaultFactory));
}
public static PDefaultDict createDefaultDict(PythonLanguage language, Object defaultFactory, HashingStorage storage) {
@@ -795,31 +790,31 @@ public static PDefaultDict createDefaultDict(PythonLanguage language, Object def
}
public static PDefaultDict createDefaultDict(PythonLanguage language, Object cls, Shape shape, Object defaultFactory, HashingStorage storage) {
- return create(language, () -> new PDefaultDict(cls, shape, storage, defaultFactory));
+ return trace(language, new PDefaultDict(cls, shape, storage, defaultFactory));
}
public static PDictView createDictKeysView(PythonLanguage language, PHashingCollection dict) {
- return create(language, () -> new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict));
+ return trace(language, new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict));
}
public static PDictView createDictKeysView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
- return create(language, () -> new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict, foreignHashingStorage));
+ return trace(language, new PDictKeysView(PythonBuiltinClassType.PDictKeysView, PythonBuiltinClassType.PDictKeysView.getInstanceShape(language), dict, foreignHashingStorage));
}
public static PDictView createDictValuesView(PythonLanguage language, PHashingCollection dict) {
- return create(language, () -> new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict));
+ return trace(language, new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict));
}
public static PDictView createDictValuesView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
- return create(language, () -> new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict, foreignHashingStorage));
+ return trace(language, new PDictValuesView(PythonBuiltinClassType.PDictValuesView, PythonBuiltinClassType.PDictValuesView.getInstanceShape(language), dict, foreignHashingStorage));
}
public static PDictView createDictItemsView(PythonLanguage language, PHashingCollection dict) {
- return create(language, () -> new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict));
+ return trace(language, new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict));
}
public static PDictView createDictItemsView(PythonLanguage language, Object dict, ForeignHashingStorage foreignHashingStorage) {
- return create(language, () -> new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict, foreignHashingStorage));
+ return trace(language, new PDictItemsView(PythonBuiltinClassType.PDictItemsView, PythonBuiltinClassType.PDictItemsView.getInstanceShape(language), dict, foreignHashingStorage));
}
/*
@@ -827,24 +822,24 @@ public static PDictView createDictItemsView(PythonLanguage language, Object dict
*/
public static PGenerator createGenerator(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator));
+ return trace(language, PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator));
}
public static PGenerator createIterableCoroutine(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets,
Object[] arguments) {
- return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator, true));
+ return trace(language, PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator, true));
}
public static PGenerator createCoroutine(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return create(language, () -> PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PCoroutine));
+ return trace(language, PGenerator.create(language, name, qualname, rootNode, callTargets, arguments, PythonBuiltinClassType.PCoroutine));
}
public static PCoroutineWrapper createCoroutineWrapper(PythonLanguage language, PGenerator generator) {
- return create(language, () -> new PCoroutineWrapper(language, generator));
+ return trace(language, new PCoroutineWrapper(language, generator));
}
public static PAsyncGen createAsyncGenerator(PythonLanguage language, TruffleString name, TruffleString qualname, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) {
- return create(language, () -> PAsyncGen.create(language, name, qualname, rootNode, callTargets, arguments));
+ return trace(language, PAsyncGen.create(language, name, qualname, rootNode, callTargets, arguments));
}
public static PMappingproxy createMappingproxy(PythonLanguage language, Object object) {
@@ -852,15 +847,15 @@ public static PMappingproxy createMappingproxy(PythonLanguage language, Object o
}
public static PMappingproxy createMappingproxy(PythonLanguage language, Object cls, Shape shape, Object object) {
- return create(language, () -> new PMappingproxy(cls, shape, object));
+ return trace(language, new PMappingproxy(cls, shape, object));
}
public static PReferenceType createReferenceType(PythonLanguage language, Object cls, Shape shape, Object object, Object callback, ReferenceQueue queue) {
- return create(language, () -> new PReferenceType(cls, shape, object, callback, queue));
+ return trace(language, new PReferenceType(cls, shape, object, callback, queue));
}
public static PCell createCell(PythonLanguage language, Assumption effectivelyFinal) {
- return create(language, () -> new PCell(effectivelyFinal));
+ return trace(language, new PCell(effectivelyFinal));
}
/*
@@ -868,23 +863,23 @@ public static PCell createCell(PythonLanguage language, Assumption effectivelyFi
*/
public static PFrame createPFrame(PythonLanguage language, PFrame.Reference frameInfo, Node location, MaterializedFrame locals) {
- return create(language, () -> new PFrame(language, frameInfo, location, locals));
+ return trace(language, new PFrame(language, frameInfo, location, locals));
}
public static PFrame createPFrame(PythonLanguage language, Object threadState, PCode code, PythonObject globals, Object localsDict) {
- return create(language, () -> new PFrame(language, threadState, code, globals, localsDict));
+ return trace(language, new PFrame(language, threadState, code, globals, localsDict));
}
public static PTraceback createTraceback(PythonLanguage language, PFrame frame, int lineno, PTraceback next) {
- return create(language, () -> new PTraceback(language, frame, lineno, -1, next));
+ return trace(language, new PTraceback(language, frame, lineno, -1, next));
}
public static PTraceback createTracebackWithLasti(PythonLanguage language, PFrame frame, int lineno, int lasti, PTraceback next) {
- return create(language, () -> new PTraceback(language, frame, lineno, lasti, next));
+ return trace(language, new PTraceback(language, frame, lineno, lasti, next));
}
public static PTraceback createTraceback(PythonLanguage language, LazyTraceback tb) {
- return create(language, () -> new PTraceback(language, tb));
+ return trace(language, new PTraceback(language, tb));
}
public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, PTuple args) {
@@ -900,7 +895,7 @@ public static PBaseException createBaseException(PythonLanguage language, Python
}
public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data, PTuple args) {
- return create(language, () -> new PBaseException(cls, shape, data, args));
+ return trace(language, new PBaseException(cls, shape, data, args));
}
/*
@@ -923,23 +918,23 @@ public static PBaseException createBaseException(PythonLanguage language, Python
public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape, Object[] data, TruffleString format, Object[] args) {
assert format != null;
- return create(language, () -> new PBaseException(cls, shape, data, format, args));
+ return trace(language, new PBaseException(cls, shape, data, format, args));
}
public static PBaseException createBaseException(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PBaseException(cls, shape, null));
+ return trace(language, new PBaseException(cls, shape, null));
}
public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type) {
- return create(language, () -> new PBaseException(type, type.getInstanceShape(language), null));
+ return trace(language, new PBaseException(type, type.getInstanceShape(language), null));
}
public static PBaseException createBaseException(PythonLanguage language, PythonBuiltinClassType type, TruffleString format) {
- return create(language, () -> new PBaseException(type, type.getInstanceShape(language), null, format, EMPTY_OBJECT_ARRAY));
+ return trace(language, new PBaseException(type, type.getInstanceShape(language), null, format, EMPTY_OBJECT_ARRAY));
}
public static PBaseExceptionGroup createBaseExceptionGroup(PythonLanguage language, Object cls, Shape shape, TruffleString message, Object[] exceptions, Object[] args) {
- return create(language, () -> new PBaseExceptionGroup(cls, shape, message, exceptions, createTuple(language, args)));
+ return trace(language, new PBaseExceptionGroup(cls, shape, message, exceptions, createTuple(language, args)));
}
/*
@@ -948,7 +943,7 @@ public static PBaseExceptionGroup createBaseExceptionGroup(PythonLanguage langua
public static PArray createArray(PythonLanguage language, Object cls, Shape shape, TruffleString formatString, BufferFormat format) {
assert format != null;
- return create(language, () -> new PArray(cls, shape, formatString, format));
+ return trace(language, new PArray(cls, shape, formatString, format));
}
public static PArray createArray(PythonLanguage language, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
@@ -958,7 +953,7 @@ public static PArray createArray(PythonLanguage language, TruffleString formatSt
public static PArray createArray(PythonLanguage language, Object cls, Shape shape, TruffleString formatString, BufferFormat format, int length) throws OverflowException {
assert format != null;
int byteSize = PythonUtils.multiplyExact(length, format.bytesize);
- return create(language, () -> new PArray(cls, shape, formatString, format, byteSize));
+ return trace(language, new PArray(cls, shape, formatString, format, byteSize));
}
public static PByteArray createByteArray(PythonLanguage language, byte[] array) {
@@ -982,7 +977,7 @@ public static PByteArray createByteArray(PythonLanguage language, SequenceStorag
}
public static PByteArray createByteArray(PythonLanguage language, Object cls, Shape shape, SequenceStorage storage) {
- return create(language, () -> new PByteArray(cls, shape, storage));
+ return trace(language, new PByteArray(cls, shape, storage));
}
/*
@@ -990,31 +985,31 @@ public static PByteArray createByteArray(PythonLanguage language, Object cls, Sh
*/
public static PStringIterator createStringIterator(PythonLanguage language, TruffleString str) {
- return create(language, () -> new PStringIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), str));
+ return trace(language, new PStringIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), str));
}
public static PStringReverseIterator createStringReverseIterator(PythonLanguage language, Object cls, Shape shape, TruffleString str) {
- return create(language, () -> new PStringReverseIterator(cls, shape, str));
+ return trace(language, new PStringReverseIterator(cls, shape, str));
}
public static PIntegerSequenceIterator createIntegerSequenceIterator(PythonLanguage language, IntSequenceStorage storage, Object list) {
- return create(language, () -> new PIntegerSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ return trace(language, new PIntegerSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
}
public static PLongSequenceIterator createLongSequenceIterator(PythonLanguage language, LongSequenceStorage storage, Object list) {
- return create(language, () -> new PLongSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ return trace(language, new PLongSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
}
public static PDoubleSequenceIterator createDoubleSequenceIterator(PythonLanguage language, DoubleSequenceStorage storage, Object list) {
- return create(language, () -> new PDoubleSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ return trace(language, new PDoubleSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
}
public static PObjectSequenceIterator createObjectSequenceIterator(PythonLanguage language, ObjectSequenceStorage storage, Object list) {
- return create(language, () -> new PObjectSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
+ return trace(language, new PObjectSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), storage, list));
}
public static PSequenceIterator createSequenceIterator(PythonLanguage language, Object sequence) {
- return create(language, () -> new PSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), sequence));
+ return trace(language, new PSequenceIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), sequence));
}
public static PSequenceReverseIterator createSequenceReverseIterator(PythonLanguage language, Object sequence, int lengthHint) {
@@ -1022,7 +1017,7 @@ public static PSequenceReverseIterator createSequenceReverseIterator(PythonLangu
}
public static PSequenceReverseIterator createSequenceReverseIterator(PythonLanguage language, Object cls, Shape shape, Object sequence, int lengthHint) {
- return create(language, () -> new PSequenceReverseIterator(cls, shape, sequence, lengthHint));
+ return trace(language, new PSequenceReverseIterator(cls, shape, sequence, lengthHint));
}
public static PIntRangeIterator createIntRangeIterator(PythonLanguage language, PIntRange fastRange) {
@@ -1030,11 +1025,11 @@ public static PIntRangeIterator createIntRangeIterator(PythonLanguage language,
}
public static PIntRangeIterator createIntRangeIterator(PythonLanguage language, int start, int stop, int step, int len) {
- return create(language, () -> new PIntRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
+ return trace(language, new PIntRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
}
public static PBigRangeIterator createBigRangeIterator(PythonLanguage language, PInt start, PInt stop, PInt step, PInt len) {
- return create(language, () -> new PBigRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
+ return trace(language, new PBigRangeIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), start, stop, step, len));
}
public static PBigRangeIterator createBigRangeIterator(PythonLanguage language, PBigRange longRange) {
@@ -1046,58 +1041,58 @@ public static PBigRangeIterator createBigRangeIterator(PythonLanguage language,
}
public static PArrayIterator createArrayIterator(PythonLanguage language, PArray array) {
- return create(language, () -> new PArrayIterator(PythonBuiltinClassType.PArrayIterator, PythonBuiltinClassType.PArrayIterator.getInstanceShape(language), array));
+ return trace(language, new PArrayIterator(PythonBuiltinClassType.PArrayIterator, PythonBuiltinClassType.PArrayIterator.getInstanceShape(language), array));
}
public static PBaseSetIterator createBaseSetIterator(PythonLanguage language, PBaseSet set, HashingStorageNodes.HashingStorageIterator iterator, int initialSize) {
- return create(language, () -> new PBaseSetIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), set, iterator, initialSize));
+ return trace(language, new PBaseSetIterator(PythonBuiltinClassType.PIterator, PythonBuiltinClassType.PIterator.getInstanceShape(language), set, iterator, initialSize));
}
public static PDictItemIterator createDictItemIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return create(language, () -> new PDictItemIterator(PythonBuiltinClassType.PDictItemIterator, PythonBuiltinClassType.PDictItemIterator.getInstanceShape(language), iterator, hashingStorage,
+ return trace(language, new PDictItemIterator(PythonBuiltinClassType.PDictItemIterator, PythonBuiltinClassType.PDictItemIterator.getInstanceShape(language), iterator, hashingStorage,
initialSize));
}
public static PDictKeyIterator createDictKeyIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return create(language,
- () -> new PDictKeyIterator(PythonBuiltinClassType.PDictKeyIterator, PythonBuiltinClassType.PDictKeyIterator.getInstanceShape(language), iterator, hashingStorage, initialSize));
+ return trace(language,
+ new PDictKeyIterator(PythonBuiltinClassType.PDictKeyIterator, PythonBuiltinClassType.PDictKeyIterator.getInstanceShape(language), iterator, hashingStorage, initialSize));
}
public static PDictValueIterator createDictValueIterator(PythonLanguage language, HashingStorageNodes.HashingStorageIterator iterator, HashingStorage hashingStorage, int initialSize) {
- return create(language, () -> new PDictValueIterator(PythonBuiltinClassType.PDictValueIterator, PythonBuiltinClassType.PDictValueIterator.getInstanceShape(language), iterator, hashingStorage,
+ return trace(language, new PDictValueIterator(PythonBuiltinClassType.PDictValueIterator, PythonBuiltinClassType.PDictValueIterator.getInstanceShape(language), iterator, hashingStorage,
initialSize));
}
public static Object createSentinelIterator(PythonLanguage language, Object callable, Object sentinel) {
- return create(language, () -> new PSentinelIterator(PythonBuiltinClassType.PSentinelIterator, PythonBuiltinClassType.PSentinelIterator.getInstanceShape(language), callable, sentinel));
+ return trace(language, new PSentinelIterator(PythonBuiltinClassType.PSentinelIterator, PythonBuiltinClassType.PSentinelIterator.getInstanceShape(language), callable, sentinel));
}
public static PEnumerate createEnumerate(PythonLanguage language, Object cls, Shape shape, Object iterator, long start) {
- return create(language, () -> new PEnumerate(cls, shape, iterator, start));
+ return trace(language, new PEnumerate(cls, shape, iterator, start));
}
public static PEnumerate createEnumerate(PythonLanguage language, Object cls, Shape shape, Object iterator, PInt start) {
- return create(language, () -> new PEnumerate(cls, shape, iterator, start));
+ return trace(language, new PEnumerate(cls, shape, iterator, start));
}
public static PMap createMap(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PMap(cls, shape));
+ return trace(language, new PMap(cls, shape));
}
public static PZip createZip(PythonLanguage language, Object cls, Shape shape, Object[] iterables, boolean strict) {
- return create(language, () -> new PZip(cls, shape, iterables, strict));
+ return trace(language, new PZip(cls, shape, iterables, strict));
}
public static PCode createCode(PythonLanguage language, RootCallTarget ct) {
- return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct));
+ return trace(language, new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct));
}
public static PCode createCode(PythonLanguage language, RootCallTarget ct, int flags, int firstlineno, byte[] linetable, TruffleString filename) {
- return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct, flags, firstlineno, linetable, filename));
+ return trace(language, new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), ct, flags, firstlineno, linetable, filename));
}
public static PCode createCode(PythonLanguage language, RootCallTarget callTarget, Signature signature, CodeUnit codeUnit) {
- return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature, codeUnit));
+ return trace(language, new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature, codeUnit));
}
public static PCode createCode(PythonLanguage language, RootCallTarget callTarget, Signature signature, int nlocals,
@@ -1106,13 +1101,13 @@ public static PCode createCode(PythonLanguage language, RootCallTarget callTarge
TruffleString[] freevars, TruffleString[] cellvars,
TruffleString filename, TruffleString name, TruffleString qualname,
int firstlineno, byte[] linetable) {
- return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature,
+ return trace(language, new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), callTarget, signature,
nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars,
filename, name, qualname, firstlineno, linetable));
}
public static PCode createCode(PythonLanguage language, Supplier createCode, int flags, int firstlineno, byte[] lnotab, TruffleString filename) {
- return create(language, () -> new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), createCode, flags, firstlineno, lnotab, filename));
+ return trace(language, new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), createCode, flags, firstlineno, lnotab, filename));
}
/*
@@ -1120,7 +1115,7 @@ public static PCode createCode(PythonLanguage language, Supplier cre
*/
public static PSocket createSocket(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PSocket(cls, shape));
+ return trace(language, new PSocket(cls, shape));
}
/*
@@ -1128,7 +1123,7 @@ public static PSocket createSocket(PythonLanguage language, Object cls, Shape sh
*/
public static PThreadLocal createThreadLocal(PythonLanguage language, Object cls, Shape shape, Object[] args, PKeyword[] kwArgs) {
- return create(language, () -> new PThreadLocal(cls, shape, args, kwArgs));
+ return trace(language, new PThreadLocal(cls, shape, args, kwArgs));
}
public static PLock createLock(PythonLanguage language) {
@@ -1136,11 +1131,11 @@ public static PLock createLock(PythonLanguage language) {
}
public static PLock createLock(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PLock(cls, shape));
+ return trace(language, new PLock(cls, shape));
}
public static PRLock createRLock(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PRLock(cls, shape));
+ return trace(language, new PRLock(cls, shape));
}
public static PThread createPythonThread(PythonLanguage language, Thread thread) {
@@ -1148,11 +1143,11 @@ public static PThread createPythonThread(PythonLanguage language, Thread thread)
}
public static PThread createPythonThread(PythonLanguage language, Object cls, Shape shape, Thread thread) {
- return create(language, () -> new PThread(cls, shape, thread));
+ return trace(language, new PThread(cls, shape, thread));
}
public static PSemLock createSemLock(PythonLanguage language, Object cls, Shape shape, long handle, int kind, int maxValue, TruffleString name) {
- return create(language, () -> new PSemLock(cls, shape, handle, kind, maxValue, name));
+ return trace(language, new PSemLock(cls, shape, handle, kind, maxValue, name));
}
public static PGraalPySemLock createGraalPySemLock(PythonLanguage language, TruffleString name, int kind, Semaphore sharedSemaphore) {
@@ -1160,24 +1155,24 @@ public static PGraalPySemLock createGraalPySemLock(PythonLanguage language, Truf
}
public static PGraalPySemLock createGraalPySemLock(PythonLanguage language, Object cls, Shape shape, TruffleString name, int kind, Semaphore sharedSemaphore) {
- return create(language, () -> new PGraalPySemLock(cls, shape, name, kind, sharedSemaphore));
+ return trace(language, new PGraalPySemLock(cls, shape, name, kind, sharedSemaphore));
}
public static PScandirIterator createScandirIterator(PythonLanguage language, PythonContext context, Object dirStream, PosixFileHandle path, boolean needsRewind) {
- return create(language,
- () -> new PScandirIterator(PythonBuiltinClassType.PScandirIterator, PythonBuiltinClassType.PScandirIterator.getInstanceShape(language), context, dirStream, path, needsRewind));
+ return trace(language,
+ new PScandirIterator(PythonBuiltinClassType.PScandirIterator, PythonBuiltinClassType.PScandirIterator.getInstanceShape(language), context, dirStream, path, needsRewind));
}
public static PDirEntry createDirEntry(PythonLanguage language, Object dirEntryData, PosixFileHandle path) {
- return create(language, () -> new PDirEntry(PythonBuiltinClassType.PDirEntry, PythonBuiltinClassType.PDirEntry.getInstanceShape(language), dirEntryData, path));
+ return trace(language, new PDirEntry(PythonBuiltinClassType.PDirEntry, PythonBuiltinClassType.PDirEntry.getInstanceShape(language), dirEntryData, path));
}
public static PEncodingMap createEncodingMap(PythonLanguage language, int count2, int count3, byte[] level1, byte[] level23) {
- return create(language, () -> new PEncodingMap(PythonBuiltinClassType.PEncodingMap, PythonBuiltinClassType.PEncodingMap.getInstanceShape(language), count2, count3, level1, level23));
+ return trace(language, new PEncodingMap(PythonBuiltinClassType.PEncodingMap, PythonBuiltinClassType.PEncodingMap.getInstanceShape(language), count2, count3, level1, level23));
}
public static PMMap createMMap(PythonLanguage language, PythonContext context, Object cls, Shape shape, Object mmapHandle, int fd, long length, int access) {
- return create(language, () -> new PMMap(cls, shape, context, mmapHandle, fd, length, access));
+ return trace(language, new PMMap(cls, shape, context, mmapHandle, fd, length, access));
}
public static BZ2Object.BZ2Compressor createBZ2Compressor(PythonLanguage language) {
@@ -1185,7 +1180,7 @@ public static BZ2Object.BZ2Compressor createBZ2Compressor(PythonLanguage languag
}
public static BZ2Object.BZ2Compressor createBZ2Compressor(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> BZ2Object.createCompressor(cls, shape));
+ return trace(language, BZ2Object.createCompressor(cls, shape));
}
public static BZ2Object.BZ2Decompressor createBZ2Decompressor(PythonLanguage language) {
@@ -1193,7 +1188,7 @@ public static BZ2Object.BZ2Decompressor createBZ2Decompressor(PythonLanguage lan
}
public static BZ2Object.BZ2Decompressor createBZ2Decompressor(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> BZ2Object.createDecompressor(cls, shape));
+ return trace(language, BZ2Object.createDecompressor(cls, shape));
}
public static ZLibCompObject createJavaZLibCompObjectCompress(PythonLanguage language, Object stream, int level, int wbits, int strategy, byte[] zdict) {
@@ -1201,7 +1196,7 @@ public static ZLibCompObject createJavaZLibCompObjectCompress(PythonLanguage lan
}
public static ZLibCompObject createJavaZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object stream, int level, int wbits, int strategy, byte[] zdict) {
- return create(language, () -> ZLibCompObject.createJava(cls, shape, stream, level, wbits, strategy, zdict));
+ return trace(language, ZLibCompObject.createJava(cls, shape, stream, level, wbits, strategy, zdict));
}
public static ZLibCompObject createJavaZLibCompObjectDecompress(PythonLanguage language, Object stream, int wbits, byte[] zdict) {
@@ -1209,7 +1204,7 @@ public static ZLibCompObject createJavaZLibCompObjectDecompress(PythonLanguage l
}
public static ZLibCompObject createJavaZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object stream, int wbits, byte[] zdict) {
- return create(language, () -> ZLibCompObject.createJava(cls, shape, stream, wbits, zdict));
+ return trace(language, ZLibCompObject.createJava(cls, shape, stream, wbits, zdict));
}
public static ZLibCompObject createNativeZLibCompObjectCompress(PythonLanguage language, Object zst, NFIZlibSupport zlibSupport) {
@@ -1221,15 +1216,15 @@ public static ZLibCompObject createNativeZLibCompObjectDecompress(PythonLanguage
}
public static ZLibCompObject createNativeZLibCompObject(PythonLanguage language, Object cls, Shape shape, Object zst, NFIZlibSupport zlibSupport) {
- return create(language, () -> ZLibCompObject.createNative(cls, shape, zst, zlibSupport));
+ return trace(language, ZLibCompObject.createNative(cls, shape, zst, zlibSupport));
}
public static LZMAObject.LZMADecompressor createLZMADecompressor(PythonLanguage language, Object cls, Shape shape, boolean isNative) {
- return create(language, () -> LZMAObject.createDecompressor(cls, shape, isNative));
+ return trace(language, LZMAObject.createDecompressor(cls, shape, isNative));
}
public static LZMAObject.LZMACompressor createLZMACompressor(PythonLanguage language, Object cls, Shape shape, boolean isNative) {
- return create(language, () -> LZMAObject.createCompressor(cls, shape, isNative));
+ return trace(language, LZMAObject.createCompressor(cls, shape, isNative));
}
public static CSVReader createCSVReader(PythonLanguage language, Object inputIter, CSVDialect dialect) {
@@ -1237,7 +1232,7 @@ public static CSVReader createCSVReader(PythonLanguage language, Object inputIte
}
public static CSVReader createCSVReader(PythonLanguage language, Object cls, Shape shape, Object inputIter, CSVDialect dialect) {
- return create(language, () -> new CSVReader(cls, shape, inputIter, dialect));
+ return trace(language, new CSVReader(cls, shape, inputIter, dialect));
}
public static CSVWriter createCSVWriter(PythonLanguage language, Object write, CSVDialect dialect) {
@@ -1245,16 +1240,14 @@ public static CSVWriter createCSVWriter(PythonLanguage language, Object write, C
}
public static CSVWriter createCSVWriter(PythonLanguage language, Object cls, Shape shape, Object write, CSVDialect dialect) {
- return create(language, () -> new CSVWriter(cls, shape, write, dialect));
+ return trace(language, new CSVWriter(cls, shape, write, dialect));
}
public static CSVDialect createCSVDialect(PythonLanguage language, Object cls, Shape shape, TruffleString delimiter, int delimiterCodePoint, boolean doubleQuote, TruffleString escapeChar,
int escapeCharCodePoint,
TruffleString lineTerminator, TruffleString quoteChar, int quoteCharCodePoint, QuoteStyle quoting, boolean skipInitialSpace, boolean strict) {
- return create(language,
- () -> new CSVDialect(cls, shape, delimiter, delimiterCodePoint, doubleQuote, escapeChar, escapeCharCodePoint, lineTerminator, quoteChar, quoteCharCodePoint,
- quoting,
- skipInitialSpace, strict));
+ return trace(language, new CSVDialect(cls, shape, delimiter, delimiterCodePoint, doubleQuote, escapeChar, escapeCharCodePoint, lineTerminator, quoteChar, quoteCharCodePoint, quoting,
+ skipInitialSpace, strict));
}
public static PFileIO createFileIO(PythonLanguage language) {
@@ -1262,7 +1255,7 @@ public static PFileIO createFileIO(PythonLanguage language) {
}
public static PFileIO createFileIO(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PFileIO(cls, shape));
+ return trace(language, new PFileIO(cls, shape));
}
public static PChain createChain(PythonLanguage language) {
@@ -1270,31 +1263,31 @@ public static PChain createChain(PythonLanguage language) {
}
public static PChain createChain(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PChain(cls, shape));
+ return trace(language, new PChain(cls, shape));
}
public static PCount createCount(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PCount(cls, shape));
+ return trace(language, new PCount(cls, shape));
}
public static PIslice createIslice(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PIslice(cls, shape));
+ return trace(language, new PIslice(cls, shape));
}
public static PPairwise createPairwise(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PPairwise(cls, shape));
+ return trace(language, new PPairwise(cls, shape));
}
public static PPermutations createPermutations(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PPermutations(cls, shape));
+ return trace(language, new PPermutations(cls, shape));
}
public static PProduct createProduct(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PProduct(cls, shape));
+ return trace(language, new PProduct(cls, shape));
}
public static PRepeat createRepeat(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PRepeat(cls, shape));
+ return trace(language, new PRepeat(cls, shape));
}
public static PAccumulate createAccumulate(PythonLanguage language) {
@@ -1302,63 +1295,63 @@ public static PAccumulate createAccumulate(PythonLanguage language) {
}
public static PAccumulate createAccumulate(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PAccumulate(cls, shape));
+ return trace(language, new PAccumulate(cls, shape));
}
public static PDropwhile createDropwhile(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PDropwhile(cls, shape));
+ return trace(language, new PDropwhile(cls, shape));
}
public static PCombinations createCombinations(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PCombinations(cls, shape));
+ return trace(language, new PCombinations(cls, shape));
}
public static PCombinationsWithReplacement createCombinationsWithReplacement(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PCombinationsWithReplacement(cls, shape));
+ return trace(language, new PCombinationsWithReplacement(cls, shape));
}
public static PCompress createCompress(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PCompress(cls, shape));
+ return trace(language, new PCompress(cls, shape));
}
public static PCycle createCycle(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PCycle(cls, shape));
+ return trace(language, new PCycle(cls, shape));
}
public static PFilterfalse createFilterfalse(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PFilterfalse(cls, shape));
+ return trace(language, new PFilterfalse(cls, shape));
}
public static PGroupBy createGroupBy(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PGroupBy(cls, shape));
+ return trace(language, new PGroupBy(cls, shape));
}
public static PGrouper createGrouper(PythonLanguage language, PGroupBy parent, Object tgtKey) {
- return create(language, () -> new PGrouper(parent, tgtKey, PythonBuiltinClassType.PGrouper, PythonBuiltinClassType.PGrouper.getInstanceShape(language)));
+ return trace(language, new PGrouper(parent, tgtKey, PythonBuiltinClassType.PGrouper, PythonBuiltinClassType.PGrouper.getInstanceShape(language)));
}
public static PTee createTee(PythonLanguage language, PTeeDataObject dataObj, int index) {
- return create(language, () -> new PTee(dataObj, index, PythonBuiltinClassType.PTee, PythonBuiltinClassType.PTee.getInstanceShape(language)));
+ return trace(language, new PTee(dataObj, index, PythonBuiltinClassType.PTee, PythonBuiltinClassType.PTee.getInstanceShape(language)));
}
public static PStarmap createStarmap(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PStarmap(cls, shape));
+ return trace(language, new PStarmap(cls, shape));
}
public static PTakewhile createTakewhile(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PTakewhile(cls, shape));
+ return trace(language, new PTakewhile(cls, shape));
}
public static PTeeDataObject createTeeDataObject(PythonLanguage language) {
- return create(language, () -> new PTeeDataObject(PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
+ return trace(language, new PTeeDataObject(PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
}
public static PTeeDataObject createTeeDataObject(PythonLanguage language, Object it) {
- return create(language, () -> new PTeeDataObject(it, PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
+ return trace(language, new PTeeDataObject(it, PythonBuiltinClassType.PTeeDataObject, PythonBuiltinClassType.PTeeDataObject.getInstanceShape(language)));
}
public static PZipLongest createZipLongest(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PZipLongest(cls, shape));
+ return trace(language, new PZipLongest(cls, shape));
}
public static PTextIO createTextIO(PythonLanguage language) {
@@ -1366,15 +1359,15 @@ public static PTextIO createTextIO(PythonLanguage language) {
}
public static PTextIO createTextIO(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PTextIO(cls, shape));
+ return trace(language, new PTextIO(cls, shape));
}
public static PStringIO createStringIO(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PStringIO(cls, shape));
+ return trace(language, new PStringIO(cls, shape));
}
public static PBytesIO createBytesIO(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PBytesIO(cls, shape));
+ return trace(language, new PBytesIO(cls, shape));
}
public static PBytesIOBuffer createBytesIOBuf(PythonLanguage language, PBytesIO source) {
@@ -1382,7 +1375,7 @@ public static PBytesIOBuffer createBytesIOBuf(PythonLanguage language, PBytesIO
}
public static PBytesIOBuffer createBytesIOBuf(PythonLanguage language, Object cls, Shape shape, PBytesIO source) {
- return create(language, () -> new PBytesIOBuffer(cls, shape, source));
+ return trace(language, new PBytesIOBuffer(cls, shape, source));
}
public static PNLDecoder createNLDecoder(PythonLanguage language) {
@@ -1390,7 +1383,7 @@ public static PNLDecoder createNLDecoder(PythonLanguage language) {
}
public static PNLDecoder createNLDecoder(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PNLDecoder(cls, shape));
+ return trace(language, new PNLDecoder(cls, shape));
}
public static PBuffered createBufferedReader(PythonLanguage language) {
@@ -1398,7 +1391,7 @@ public static PBuffered createBufferedReader(PythonLanguage language) {
}
public static PBuffered createBufferedReader(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PBuffered(cls, shape, true, false));
+ return trace(language, new PBuffered(cls, shape, true, false));
}
public static PBuffered createBufferedWriter(PythonLanguage language) {
@@ -1406,7 +1399,7 @@ public static PBuffered createBufferedWriter(PythonLanguage language) {
}
public static PBuffered createBufferedWriter(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PBuffered(cls, shape, false, true));
+ return trace(language, new PBuffered(cls, shape, false, true));
}
public static PBuffered createBufferedRandom(PythonLanguage language) {
@@ -1414,15 +1407,15 @@ public static PBuffered createBufferedRandom(PythonLanguage language) {
}
public static PBuffered createBufferedRandom(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PBuffered(cls, shape, true, true));
+ return trace(language, new PBuffered(cls, shape, true, true));
}
public static PRWPair createRWPair(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PRWPair(cls, shape));
+ return trace(language, new PRWPair(cls, shape));
}
public static PyCArgObject createCArgObject(PythonLanguage language) {
- return create(language, () -> new PyCArgObject(PythonBuiltinClassType.CArgObject, PythonBuiltinClassType.CArgObject.getInstanceShape(language)));
+ return trace(language, new PyCArgObject(PythonBuiltinClassType.CArgObject, PythonBuiltinClassType.CArgObject.getInstanceShape(language)));
}
public static CThunkObject createCThunkObject(PythonLanguage language, int nArgs) {
@@ -1430,17 +1423,17 @@ public static CThunkObject createCThunkObject(PythonLanguage language, int nArgs
}
public static CThunkObject createCThunkObject(PythonLanguage language, Object cls, Shape shape, int nArgs) {
- return create(language, () -> new CThunkObject(cls, shape, nArgs));
+ return trace(language, new CThunkObject(cls, shape, nArgs));
}
// Don't use directly, use CtypesNodes.CreateCDataObjectNode
public static CDataObject createCDataObject(PythonLanguage language, Object cls, Shape shape, Pointer b_ptr, int b_size, boolean b_needsfree) {
- return create(language, () -> new CDataObject(cls, shape, b_ptr, b_size, b_needsfree));
+ return trace(language, new CDataObject(cls, shape, b_ptr, b_size, b_needsfree));
}
// Don't use directly, use CtypesNodes.CreateCDataObjectNode
public static PyCFuncPtrObject createPyCFuncPtrObject(PythonLanguage language, Object cls, Shape shape, Pointer b_ptr, int b_size, boolean b_needsfree) {
- return create(language, () -> new PyCFuncPtrObject(cls, shape, b_ptr, b_size, b_needsfree));
+ return trace(language, new PyCFuncPtrObject(cls, shape, b_ptr, b_size, b_needsfree));
}
public static CFieldObject createCFieldObject(PythonLanguage language) {
@@ -1448,7 +1441,7 @@ public static CFieldObject createCFieldObject(PythonLanguage language) {
}
public static CFieldObject createCFieldObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new CFieldObject(cls, shape));
+ return trace(language, new CFieldObject(cls, shape));
}
public static StgDictObject createStgDictObject(PythonLanguage language) {
@@ -1456,11 +1449,11 @@ public static StgDictObject createStgDictObject(PythonLanguage language) {
}
public static StgDictObject createStgDictObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new StgDictObject(cls, shape));
+ return trace(language, new StgDictObject(cls, shape));
}
public static PSSLContext createSSLContext(PythonLanguage language, Object cls, Shape shape, SSLMethod method, int verifyFlags, boolean checkHostname, int verifyMode, SSLContext context) {
- return create(language, () -> new PSSLContext(cls, shape, method, verifyFlags, checkHostname, verifyMode, context));
+ return trace(language, new PSSLContext(cls, shape, method, verifyFlags, checkHostname, verifyMode, context));
}
public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext context, SSLEngine engine, PSocket socket) {
@@ -1468,7 +1461,7 @@ public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext co
}
public static PSSLSocket createSSLSocket(PythonLanguage language, Object cls, Shape shape, PSSLContext context, SSLEngine engine, PSocket socket) {
- return create(language, () -> new PSSLSocket(cls, shape, context, engine, socket, createMemoryBIO(language), createMemoryBIO(language), createMemoryBIO(language)));
+ return trace(language, new PSSLSocket(cls, shape, context, engine, socket, createMemoryBIO(language), createMemoryBIO(language), createMemoryBIO(language)));
}
public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext context, SSLEngine engine, PMemoryBIO inbound, PMemoryBIO outbound) {
@@ -1476,23 +1469,23 @@ public static PSSLSocket createSSLSocket(PythonLanguage language, PSSLContext co
}
public static PSSLSocket createSSLSocket(PythonLanguage language, Object cls, Shape shape, PSSLContext context, SSLEngine engine, PMemoryBIO inbound, PMemoryBIO outbound) {
- return create(language, () -> new PSSLSocket(cls, shape, context, engine, null, inbound, outbound, createMemoryBIO(language)));
+ return trace(language, new PSSLSocket(cls, shape, context, engine, null, inbound, outbound, createMemoryBIO(language)));
}
public static PMemoryBIO createMemoryBIO(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PMemoryBIO(cls, shape));
+ return trace(language, new PMemoryBIO(cls, shape));
}
public static PMemoryBIO createMemoryBIO(PythonLanguage language) {
- return create(language, () -> new PMemoryBIO(PythonBuiltinClassType.PMemoryBIO, PythonBuiltinClassType.PMemoryBIO.getInstanceShape(language)));
+ return trace(language, new PMemoryBIO(PythonBuiltinClassType.PMemoryBIO, PythonBuiltinClassType.PMemoryBIO.getInstanceShape(language)));
}
public static PProperty createProperty(PythonLanguage language) {
- return create(language, () -> new PProperty(PythonBuiltinClassType.PProperty, PythonBuiltinClassType.PProperty.getInstanceShape(language)));
+ return trace(language, new PProperty(PythonBuiltinClassType.PProperty, PythonBuiltinClassType.PProperty.getInstanceShape(language)));
}
public static PProperty createProperty(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PProperty(cls, shape));
+ return trace(language, new PProperty(cls, shape));
}
// JSON
@@ -1501,54 +1494,54 @@ public static PProperty createProperty(PythonLanguage language, Object cls, Shap
@TruffleBoundary
public static PJSONScanner createJSONScanner(PythonLanguage language, Object cls, Shape shape, boolean strict, Object objectHook, Object objectPairsHook, Object parseFloat, Object parseInt,
Object parseConstant) {
- return create(language, () -> new PJSONScanner(cls, shape, strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant));
+ return trace(language, new PJSONScanner(cls, shape, strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant));
}
@TruffleBoundary
public static PJSONEncoder createJSONEncoder(PythonLanguage language, Object cls, Shape shape, Object markers, Object defaultFn, Object encoder, Object indent, TruffleString keySeparator,
TruffleString itemSeparator,
boolean sortKeys, boolean skipKeys, boolean allowNan, FastEncode fastEncode) {
- return create(language, () -> new PJSONEncoder(cls, shape, markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode));
+ return trace(language, new PJSONEncoder(cls, shape, markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode));
}
public static PDeque createDeque(PythonLanguage language) {
- return create(language, () -> new PDeque(PythonBuiltinClassType.PDeque, PythonBuiltinClassType.PDeque.getInstanceShape(language)));
+ return trace(language, new PDeque(PythonBuiltinClassType.PDeque, PythonBuiltinClassType.PDeque.getInstanceShape(language)));
}
public static PDeque createDeque(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PDeque(cls, shape));
+ return trace(language, new PDeque(cls, shape));
}
public static PDequeIter createDequeIter(PythonLanguage language, PDeque deque) {
- return create(language, () -> new PDequeIter(PythonBuiltinClassType.PDequeIter, PythonBuiltinClassType.PDequeIter.getInstanceShape(language), deque, false));
+ return trace(language, new PDequeIter(PythonBuiltinClassType.PDequeIter, PythonBuiltinClassType.PDequeIter.getInstanceShape(language), deque, false));
}
public static PDequeIter createDequeRevIter(PythonLanguage language, PDeque deque) {
- return create(language, () -> new PDequeIter(PythonBuiltinClassType.PDequeRevIter, PythonBuiltinClassType.PDequeRevIter.getInstanceShape(language), deque, true));
+ return trace(language, new PDequeIter(PythonBuiltinClassType.PDequeRevIter, PythonBuiltinClassType.PDequeRevIter.getInstanceShape(language), deque, true));
}
public static PSimpleQueue createSimpleQueue(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PSimpleQueue(cls, shape));
+ return trace(language, new PSimpleQueue(cls, shape));
}
public static PContextVar createContextVar(PythonLanguage language, TruffleString name, Object def) {
- return create(language, () -> new PContextVar(PythonBuiltinClassType.ContextVar, PythonBuiltinClassType.ContextVar.getInstanceShape(language), name, def));
+ return trace(language, new PContextVar(PythonBuiltinClassType.ContextVar, PythonBuiltinClassType.ContextVar.getInstanceShape(language), name, def));
}
public static PContextVarsContext createContextVarsContext(PythonLanguage language) {
- return create(language, () -> new PContextVarsContext(PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
+ return trace(language, new PContextVarsContext(PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
}
public static PContextIterator createContextIterator(PythonLanguage language, PContextVarsContext ctx, PContextIterator.ItemKind kind) {
- return create(language, () -> new PContextIterator(PythonBuiltinClassType.ContextIterator, PythonBuiltinClassType.ContextIterator.getInstanceShape(language), ctx, kind));
+ return trace(language, new PContextIterator(PythonBuiltinClassType.ContextIterator, PythonBuiltinClassType.ContextIterator.getInstanceShape(language), ctx, kind));
}
public static PContextVarsContext copyContextVarsContext(PythonLanguage language, PContextVarsContext original) {
- return create(language, () -> new PContextVarsContext(original, PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
+ return trace(language, new PContextVarsContext(original, PythonBuiltinClassType.ContextVarsContext, PythonBuiltinClassType.ContextVarsContext.getInstanceShape(language)));
}
public static PContextVarsToken createContextVarsToken(PythonLanguage language, PContextVar var, Object oldValue) {
- return create(language, () -> new PContextVarsToken(var, oldValue, PythonBuiltinClassType.ContextVarsToken, PythonBuiltinClassType.ContextVarsToken.getInstanceShape(language)));
+ return trace(language, new PContextVarsToken(var, oldValue, PythonBuiltinClassType.ContextVarsToken, PythonBuiltinClassType.ContextVarsToken.getInstanceShape(language)));
}
public static PGenericAlias createGenericAlias(PythonLanguage language, Object cls, Shape shape, Object origin, Object arguments, boolean starred) {
@@ -1558,7 +1551,7 @@ public static PGenericAlias createGenericAlias(PythonLanguage language, Object c
} else {
argumentsTuple = createTuple(language, new Object[]{arguments});
}
- return create(language, () -> new PGenericAlias(cls, shape, origin, argumentsTuple, starred));
+ return trace(language, new PGenericAlias(cls, shape, origin, argumentsTuple, starred));
}
public static PGenericAlias createGenericAlias(PythonLanguage language, Object origin, Object arguments, boolean starred) {
@@ -1570,15 +1563,15 @@ public static PGenericAlias createGenericAlias(PythonLanguage language, Object o
}
public static PGenericAliasIterator createGenericAliasIterator(PythonLanguage language, PGenericAlias object) {
- return create(language, () -> new PGenericAliasIterator(PythonBuiltinClassType.PGenericAliasIterator, PythonBuiltinClassType.PGenericAliasIterator.getInstanceShape(language), object));
+ return trace(language, new PGenericAliasIterator(PythonBuiltinClassType.PGenericAliasIterator, PythonBuiltinClassType.PGenericAliasIterator.getInstanceShape(language), object));
}
public static PUnionType createUnionType(PythonLanguage language, Object[] args) {
- return create(language, () -> new PUnionType(PythonBuiltinClassType.PUnionType, PythonBuiltinClassType.PUnionType.getInstanceShape(language), createTuple(language, args)));
+ return trace(language, new PUnionType(PythonBuiltinClassType.PUnionType, PythonBuiltinClassType.PUnionType.getInstanceShape(language), createTuple(language, args)));
}
public static DigestObject createDigestObject(PythonLanguage language, PythonBuiltinClassType type, String name, Object digest) {
- return create(language, () -> DigestObject.create(type, type.getInstanceShape(language), name, digest));
+ return trace(language, DigestObject.create(type, type.getInstanceShape(language), name, digest));
}
public static PyCapsule createCapsuleNativeName(PythonLanguage language, Object pointer, Object name) {
@@ -1590,23 +1583,23 @@ public static PyCapsule createCapsuleJavaName(PythonLanguage language, Object po
}
public static PyCapsule createCapsule(PythonLanguage language, PyCapsule.CapsuleData data) {
- return create(language, () -> new PyCapsule(language, data));
+ return trace(language, new PyCapsule(language, data));
}
public static MultibyteIncrementalDecoderObject createMultibyteIncrementalDecoderObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new MultibyteIncrementalDecoderObject(cls, shape));
+ return trace(language, new MultibyteIncrementalDecoderObject(cls, shape));
}
public static MultibyteIncrementalEncoderObject createMultibyteIncrementalEncoderObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new MultibyteIncrementalEncoderObject(cls, shape));
+ return trace(language, new MultibyteIncrementalEncoderObject(cls, shape));
}
public static MultibyteStreamReaderObject createMultibyteStreamReaderObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new MultibyteStreamReaderObject(cls, shape));
+ return trace(language, new MultibyteStreamReaderObject(cls, shape));
}
public static MultibyteStreamWriterObject createMultibyteStreamWriterObject(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new MultibyteStreamWriterObject(cls, shape));
+ return trace(language, new MultibyteStreamWriterObject(cls, shape));
}
public static MultibyteCodecObject createMultibyteCodecObject(PythonLanguage language, MultibyteCodec codec) {
@@ -1614,19 +1607,19 @@ public static MultibyteCodecObject createMultibyteCodecObject(PythonLanguage lan
}
public static MultibyteCodecObject createMultibyteCodecObject(PythonLanguage language, Object cls, Shape shape, MultibyteCodec codec) {
- return create(language, () -> new MultibyteCodecObject(cls, shape, codec));
+ return trace(language, new MultibyteCodecObject(cls, shape, codec));
}
public static PAsyncGenASend createAsyncGeneratorASend(PythonLanguage language, PAsyncGen receiver, Object message) {
- return create(language, () -> new PAsyncGenASend(language, receiver, message));
+ return trace(language, new PAsyncGenASend(language, receiver, message));
}
public static PAsyncGenAThrow createAsyncGeneratorAThrow(PythonLanguage language, PAsyncGen receiver, Object arg1, Object arg2, Object arg3) {
- return create(language, () -> new PAsyncGenAThrow(language, receiver, arg1, arg2, arg3));
+ return trace(language, new PAsyncGenAThrow(language, receiver, arg1, arg2, arg3));
}
public static PAsyncGenWrappedValue createAsyncGeneratorWrappedValue(PythonLanguage language, Object wrapped) {
- return create(language, () -> new PAsyncGenWrappedValue(language, wrapped));
+ return trace(language, new PAsyncGenWrappedValue(language, wrapped));
}
// pickle
@@ -1636,7 +1629,7 @@ public static PPickleBuffer createPickleBuffer(PythonLanguage language, Object v
}
public static PPickleBuffer createPickleBuffer(PythonLanguage language, Object view, Object cls, Shape shape) {
- return create(language, () -> new PPickleBuffer(cls, shape, view));
+ return trace(language, new PPickleBuffer(cls, shape, view));
}
public static PPickler createPickler(PythonLanguage language) {
@@ -1644,7 +1637,7 @@ public static PPickler createPickler(PythonLanguage language) {
}
public static PPickler createPickler(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PPickler(cls, shape));
+ return trace(language, new PPickler(cls, shape));
}
public static PUnpickler createUnpickler(PythonLanguage language) {
@@ -1652,7 +1645,7 @@ public static PUnpickler createUnpickler(PythonLanguage language) {
}
public static PUnpickler createUnpickler(PythonLanguage language, Object cls, Shape shape) {
- return create(language, () -> new PUnpickler(cls, shape));
+ return trace(language, new PUnpickler(cls, shape));
}
public static PPicklerMemoProxy createPicklerMemoProxy(PythonLanguage language, PPickler pickler) {
@@ -1660,7 +1653,7 @@ public static PPicklerMemoProxy createPicklerMemoProxy(PythonLanguage language,
}
public static PPicklerMemoProxy createPicklerMemoProxy(PythonLanguage language, PPickler pickler, Object cls, Shape shape) {
- return create(language, () -> new PPicklerMemoProxy(cls, shape, pickler));
+ return trace(language, new PPicklerMemoProxy(cls, shape, pickler));
}
public static PUnpicklerMemoProxy createUnpicklerMemoProxy(PythonLanguage language, PUnpickler unpickler) {
@@ -1668,15 +1661,15 @@ public static PUnpicklerMemoProxy createUnpicklerMemoProxy(PythonLanguage langua
}
public static PUnpicklerMemoProxy createUnpicklerMemoProxy(PythonLanguage language, PUnpickler unpickler, Object cls, Shape shape) {
- return create(language, () -> new PUnpicklerMemoProxy(cls, shape, unpickler));
+ return trace(language, new PUnpicklerMemoProxy(cls, shape, unpickler));
}
public static PStruct createStruct(PythonLanguage language, PStruct.StructInfo structInfo) {
- return create(language, () -> new PStruct(PythonBuiltinClassType.PStruct, PythonBuiltinClassType.PStruct.getInstanceShape(language), structInfo));
+ return trace(language, new PStruct(PythonBuiltinClassType.PStruct, PythonBuiltinClassType.PStruct.getInstanceShape(language), structInfo));
}
public static PStructUnpackIterator createStructUnpackIterator(PythonLanguage language, PStruct struct, Object buffer) {
- return create(language, () -> new PStructUnpackIterator(PythonBuiltinClassType.PStructUnpackIterator, PythonBuiltinClassType.PStructUnpackIterator.getInstanceShape(language), struct, buffer));
+ return trace(language, new PStructUnpackIterator(PythonBuiltinClassType.PStructUnpackIterator, PythonBuiltinClassType.PStructUnpackIterator.getInstanceShape(language), struct, buffer));
}
public static PTokenizerIter createTokenizerIter(PythonLanguage language, String sourceString) {
@@ -1684,10 +1677,10 @@ public static PTokenizerIter createTokenizerIter(PythonLanguage language, String
}
public static PTokenizerIter createTokenizerIter(PythonLanguage language, Object cls, Shape shape, String sourceString) {
- return create(language, () -> new PTokenizerIter(cls, shape, sourceString));
+ return trace(language, new PTokenizerIter(cls, shape, sourceString));
}
public static Profiler createProfiler(PythonLanguage language, Object cls, Shape shape, CPUSampler sampler) {
- return create(language, () -> new Profiler(cls, shape, sampler));
+ return trace(language, new Profiler(cls, shape, sampler));
}
}
From eadbc4bfb3ab5e49d69908b1af0c77ad5e28916b Mon Sep 17 00:00:00 2001
From: Tim Felgentreff
Date: Fri, 14 Feb 2025 15:45:20 +0100
Subject: [PATCH 018/512] Enable _PyObject_AssertFailed to print some info at
least when we fail.
---
.../com.oracle.graal.python.cext/src/object.c | 9 ++-
.../cpyext/module_with_exiting_functions.py | 68 ++++++++++++++++++
.../src/tests/cpyext/test_fatal_exit.py | 72 +++++++++++++++++++
.../objects/cext/capi/CApiFunction.java | 4 +-
4 files changed, 148 insertions(+), 5 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python.test/src/tests/cpyext/module_with_exiting_functions.py
create mode 100644 graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_fatal_exit.py
diff --git a/graalpython/com.oracle.graal.python.cext/src/object.c b/graalpython/com.oracle.graal.python.cext/src/object.c
index 9ad7908e8a..eb22c9e94d 100644
--- a/graalpython/com.oracle.graal.python.cext/src/object.c
+++ b/graalpython/com.oracle.graal.python.cext/src/object.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2018, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2022 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -2370,7 +2370,6 @@ _PyTrash_cond(PyObject *op, destructor dealloc)
}
-#if 0 // GraalPy change
void _Py_NO_RETURN
_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
const char *file, int line, const char *function)
@@ -2395,6 +2394,7 @@ _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
fprintf(stderr, "\n");
fflush(stderr);
+#if 0 // GraalPy change
if (_PyObject_IsFreed(obj)) {
/* It seems like the object memory has been freed:
don't access it to prevent a segmentation fault. */
@@ -2415,17 +2415,20 @@ _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
}
_PyMem_DumpTraceback(fileno(stderr), ptr);
+#endif // GraalPy change
/* This might succeed or fail, but we're about to abort, so at least
try to provide any extra info we can: */
+ if (obj) // GraalPy change, guard call to _PyObject_Dump
_PyObject_Dump(obj);
+#if 0 // GraalPy change
fprintf(stderr, "\n");
fflush(stderr);
}
+#endif // GraalPy change
Py_FatalError("_PyObject_AssertFailed");
}
-#endif // GraalPy change
void
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/module_with_exiting_functions.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/module_with_exiting_functions.py
new file mode 100644
index 0000000000..99b5e47fd4
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/module_with_exiting_functions.py
@@ -0,0 +1,68 @@
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# The Universal Permissive License (UPL), Version 1.0
+#
+# Subject to the condition set forth below, permission is hereby granted to any
+# person obtaining a copy of this software, associated documentation and/or
+# data (collectively the "Software"), free of charge and under any and all
+# copyright rights in the Software, and any and all patent rights owned or
+# freely licensable by each licensor hereunder covering either (i) the
+# unmodified Software as contributed to or provided by such licensor, or (ii)
+# the Larger Works (as defined below), to deal in both
+#
+# (a) the Software, and
+#
+# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+# one is included with the Software each a "Larger Work" to which the Software
+# is contributed by such licensors),
+#
+# without restriction, including without limitation the rights to copy, create
+# derivative works of, display, perform, and distribute the Software and make,
+# use, sell, offer for sale, import, export, have made, and have sold the
+# Software and the Larger Work(s), and to sublicense the foregoing rights on
+# either these or other terms.
+#
+# This license is subject to the following condition:
+#
+# The above copyright notice and either this complete permission notice or at a
+# minimum a reference to the UPL must be included in all copies or substantial
+# portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import sys
+import time
+
+from tests.cpyext import CPyExtType
+
+
+ExitObject = CPyExtType(
+ "ExitObjext",
+ """
+ static PyObject *test_FatalError(PyObject *self, PyObject *arg) {
+ Py_FatalError(PyUnicode_AsUTF8(arg));
+ return NULL;
+ }
+
+ static PyObject* test_assert_failure(PyObject *self, PyObject *arg) {
+ _PyObject_AssertFailed(arg, "0", PyUnicode_AsUTF8(arg), "filename", 0, "function");
+ return NULL;
+ }
+
+ """,
+ tp_methods='''
+ {"Py_FatalError", (PyCFunction)test_FatalError, METH_O, NULL},
+ {"_PyObject_ASSERT_WITH_MSG", (PyCFunction)test_assert_failure, METH_O, NULL}
+ '''
+ )
+
+
+if __name__ == "__main__":
+ getattr(ExitObject(), sys.argv[1])(sys.argv[2])
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_fatal_exit.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_fatal_exit.py
new file mode 100644
index 0000000000..0a27547b92
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_fatal_exit.py
@@ -0,0 +1,72 @@
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# The Universal Permissive License (UPL), Version 1.0
+#
+# Subject to the condition set forth below, permission is hereby granted to any
+# person obtaining a copy of this software, associated documentation and/or
+# data (collectively the "Software"), free of charge and under any and all
+# copyright rights in the Software, and any and all patent rights owned or
+# freely licensable by each licensor hereunder covering either (i) the
+# unmodified Software as contributed to or provided by such licensor, or (ii)
+# the Larger Works (as defined below), to deal in both
+#
+# (a) the Software, and
+#
+# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+# one is included with the Software each a "Larger Work" to which the Software
+# is contributed by such licensors),
+#
+# without restriction, including without limitation the rights to copy, create
+# derivative works of, display, perform, and distribute the Software and make,
+# use, sell, offer for sale, import, export, have made, and have sold the
+# Software and the Larger Work(s), and to sublicense the foregoing rights on
+# either these or other terms.
+#
+# This license is subject to the following condition:
+#
+# The above copyright notice and either this complete permission notice or at a
+# minimum a reference to the UPL must be included in all copies or substantial
+# portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import os
+import signal
+import subprocess
+from pathlib import Path
+
+import sys
+
+
+def call_in_subprocess(method, argument):
+ dir = Path(__file__).parent
+ module_path = dir / 'module_with_exiting_functions.py'
+ env = dict(os.environ)
+ env['PYTHONPATH'] = str(dir.parent.parent)
+ args = [sys.executable]
+ if sys.implementation.name == 'graalpy':
+ args += ['--experimental-options', '--python.EnableDebuggingBuiltins']
+ args += [str(module_path), method, argument]
+ return subprocess.run(args, env=env, capture_output=True, text=True)
+
+
+def test_fatal_error():
+ proc = call_in_subprocess("Py_FatalError", "my fatal error")
+ assert proc.returncode != 0
+ assert "my fatal error" in proc.stderr, proc.stderr
+
+
+def test_assert_failed():
+ proc = call_in_subprocess("_PyObject_ASSERT_WITH_MSG", "some assert failed")
+ assert proc.returncode != 0
+ assert "some assert failed" in proc.stderr, proc.stderr
+ assert "refcount" in proc.stderr, proc.stderr
+ assert "object type" in proc.stderr, proc.stderr
+ assert "object type name" in proc.stderr, proc.stderr
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
index 90e9394e37..d1a5ba18f0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
@@ -592,6 +592,8 @@ public final class CApiFunction {
@CApiBuiltin(name = "_PyLong_UnsignedLong_Converter", ret = Int, args = {PyObject, Pointer}, call = CImpl)
@CApiBuiltin(name = "_PyModule_Add", ret = Int, args = {PyObject, ConstCharPtrAsTruffleString, PyObject}, call = CImpl)
@CApiBuiltin(name = "_PyModule_CreateInitialized", ret = PyObject, args = {PYMODULEDEF_PTR, Int}, call = CImpl)
+ @CApiBuiltin(name = "_PyObject_AssertFailed", ret = VoidNoReturn, args = {PyObject, ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, Int,
+ ConstCharPtrAsTruffleString}, call = CImpl)
@CApiBuiltin(name = "_PyObject_CallFunction_SizeT", ret = PyObject, args = {PyObject, ConstCharPtrAsTruffleString, VARARGS}, call = CImpl)
@CApiBuiltin(name = "_PyObject_CallMethodIdObjArgs", ret = PyObject, args = {PyObject, _PY_IDENTIFIER_PTR, VARARGS}, call = CImpl)
@CApiBuiltin(name = "_PyObject_CallMethodIdObjArgs", ret = PyObject, args = {PyObject, _PY_IDENTIFIER_PTR, VARARGS}, call = CImpl)
@@ -1098,8 +1100,6 @@ public final class CApiFunction {
@CApiBuiltin(name = "_PyOS_IsMainThread", ret = Int, args = {}, call = NotImplemented)
@CApiBuiltin(name = "_PyOS_URandom", ret = Int, args = {Pointer, Py_ssize_t}, call = NotImplemented)
@CApiBuiltin(name = "_PyOS_URandomNonblock", ret = Int, args = {Pointer, Py_ssize_t}, call = NotImplemented)
- @CApiBuiltin(name = "_PyObject_AssertFailed", ret = VoidNoReturn, args = {PyObject, ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, Int,
- ConstCharPtrAsTruffleString}, call = NotImplemented)
@CApiBuiltin(name = "_PyObject_CallMethod", ret = PyObject, args = {PyObject, PyObject, ConstCharPtrAsTruffleString, VARARGS}, call = NotImplemented)
@CApiBuiltin(name = "_PyObject_CallMethodId", ret = PyObject, args = {PyObject, PY_IDENTIFIER, ConstCharPtrAsTruffleString, VARARGS}, call = NotImplemented)
@CApiBuiltin(name = "_PyObject_CallMethodId_SizeT", ret = PyObject, args = {PyObject, PY_IDENTIFIER, ConstCharPtrAsTruffleString, VARARGS}, call = NotImplemented)
From afcda3c988c9be7704dae29e9ea830b2ba580153 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Thu, 13 Feb 2025 13:31:38 +0100
Subject: [PATCH 019/512] Implement simple numeric binary inplace slots
---
.../oracle/graal/python/annotations/Slot.java | 24 +++
.../graal/python/processor/SlotsMapping.java | 21 ++-
.../src/tests/cpyext/test_tp_slots.py | 7 +-
.../builtins/PythonBuiltinClassType.java | 3 +-
.../builtins/modules/BuiltinFunctions.java | 6 +-
.../builtins/modules/MathModuleBuiltins.java | 4 +-
.../builtins/modules/PosixModuleBuiltins.java | 2 +-
.../cext/PythonCextAbstractBuiltins.java | 4 +-
.../modules/functools/KeyWrapperBuiltins.java | 2 +-
.../builtins/objects/array/ArrayBuiltins.java | 4 +-
.../objects/cext/capi/SlotMethodDef.java | 42 +----
.../objects/cext/capi/ToNativeTypeNode.java | 10 --
.../cext/hpy/GraalHPyArithmeticNode.java | 2 +-
.../objects/common/SequenceStorageNodes.java | 2 +-
.../builtins/objects/common/SortNodes.java | 4 +-
.../builtins/objects/dict/DictBuiltins.java | 5 +-
.../foreign/ForeignNumberBuiltins.java | 6 +-
.../mappingproxy/MappingproxyBuiltins.java | 9 +-
.../objects/object/ObjectBuiltins.java | 2 +-
.../ordereddict/OrderedDictBuiltins.java | 5 +-
.../referencetype/ReferenceTypeBuiltins.java | 4 +-
.../builtins/objects/set/SetBuiltins.java | 26 ++--
.../python/builtins/objects/type/TpSlots.java | 145 ++++++++++++++++++
.../objects/type/slots/TpSlotBinaryFunc.java | 3 +-
.../objects/type/slots/TpSlotBinaryOp.java | 75 +++++++++
.../objects/types/UnionTypeBuiltins.java | 2 +-
.../graal/python/lib/CallBinaryIOp1Node.java | 83 ++++++++++
.../graal/python/lib/CallBinaryIOpNode.java | 86 +++++++++++
.../graal/python/lib/CallBinaryOp1Node.java | 58 +++----
.../graal/python/lib/CallBinaryOpNode.java | 93 +++++++++++
.../graal/python/lib/PyNumberAddNode.java | 63 ++++----
.../graal/python/lib/PyNumberAndNode.java | 49 ++----
.../graal/python/lib/PyNumberDivmodNode.java | 39 +----
.../python/lib/PyNumberFloorDivideNode.java | 51 ++----
.../python/lib/PyNumberInplaceAndNode.java | 69 +++++++++
.../lib/PyNumberInplaceFloorDivideNode.java | 67 ++++++++
.../python/lib/PyNumberInplaceLshiftNode.java | 67 ++++++++
.../PyNumberInplaceMatrixMultiplyNode.java | 68 ++++++++
.../python/lib/PyNumberInplaceOrNode.java | 69 +++++++++
.../lib/PyNumberInplaceRemainderNode.java | 67 ++++++++
.../python/lib/PyNumberInplaceRshiftNode.java | 67 ++++++++
.../lib/PyNumberInplaceSubtractNode.java | 67 ++++++++
.../lib/PyNumberInplaceTrueDivideNode.java | 67 ++++++++
.../python/lib/PyNumberInplaceXorNode.java | 69 +++++++++
.../graal/python/lib/PyNumberLshiftNode.java | 48 ++----
.../lib/PyNumberMatrixMultiplyNode.java | 41 +----
.../python/lib/PyNumberMultiplyNode.java | 59 ++++---
.../graal/python/lib/PyNumberOrNode.java | 50 ++----
.../graal/python/lib/PyNumberPowerNode.java | 2 +-
.../python/lib/PyNumberRemainderNode.java | 48 ++----
.../graal/python/lib/PyNumberRshiftNode.java | 31 ++--
.../python/lib/PyNumberSubtractNode.java | 49 ++----
.../python/lib/PyNumberTrueDivideNode.java | 48 ++----
.../graal/python/lib/PyNumberXorNode.java | 50 ++----
.../graal/python/lib/PySequenceConcat.java | 15 +-
.../nodes/bytecode/PBytecodeRootNode.java | 72 ++++++---
.../nodes/expression/BinaryArithmetic.java | 2 +-
.../python/nodes/expression/BinaryOp.java | 4 +-
.../python/nodes/expression/BinaryOpNode.java | 4 +-
.../expression/LookupAndCallInplaceNode.java | 8 +-
.../graal/python/nodes/object/IsNode.java | 4 +-
61 files changed, 1515 insertions(+), 638 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOp1Node.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOpNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOpNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java
diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
index 4d9f5c834d..c6bbb59f74 100644
--- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
+++ b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
@@ -137,6 +137,30 @@ enum SlotKind {
nb_matrix_multiply("__matmul__, __rmatmul__"),
/** foo ** bar */
nb_power("__pow__, __rpow__"),
+ /** foo += bar */
+ nb_inplace_add("__iadd__"),
+ /** foo -= bar */
+ nb_inplace_subtract("__isub__"),
+ /** foo *= bar */
+ nb_inplace_multiply("__imul__"),
+ /** foo %= bar */
+ nb_inplace_remainder("__imod__"),
+ /** foo <<= bar */
+ nb_inplace_lshift("__ilshift__"),
+ /** foo >>= bar */
+ nb_inplace_rshift("__irshift__"),
+ /** foo &= bar */
+ nb_inplace_and("__iand__"),
+ /** foo ^= bar */
+ nb_inplace_xor("__ixor__"),
+ /** foo |= bar */
+ nb_inplace_or("__ior__"),
+ /** foo //= bar */
+ nb_inplace_floor_divide("__ifloordiv__"),
+ /** foo /= bar */
+ nb_inplace_true_divide("__itruediv__"),
+ /** foo @= bar */
+ nb_inplace_matrix_multiply("__imatmul__"),
/** sequence length/size */
sq_length("__len__"),
/** sequence item: read element at index */
diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
index a9281af8b7..5e2c1b93e7 100644
--- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
+++ b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
@@ -56,6 +56,10 @@ static String getSlotBaseClass(Slot s) {
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
"TpSlotBinaryOp.TpSlotBinaryOpBuiltin";
+ case nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
+ nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
+ nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply ->
+ "TpSlotBinaryOp.TpSlotBinaryIOpBuiltin";
case nb_power -> "TpSlotNbPower.TpSlotNbPowerBuiltin";
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
@@ -76,7 +80,10 @@ static String getSlotNodeBaseClass(Slot s) {
case nb_bool -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.NbBoolBuiltinNode";
case nb_index, nb_int, nb_float, nb_absolute, nb_positive, nb_negative, nb_invert -> "com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode";
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
- nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
+ nb_floor_divide, nb_true_divide, nb_matrix_multiply,
+ nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
+ nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
+ nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply ->
"com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
case nb_power -> "com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode";
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
@@ -146,6 +153,18 @@ public static String getExtraCtorArgs(TpSlotData slot) {
case nb_floor_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___FLOORDIV__";
case nb_true_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUEDIV__";
case nb_matrix_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___MATMUL__";
+ case nb_inplace_add -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__";
+ case nb_inplace_subtract -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ISUB__";
+ case nb_inplace_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__";
+ case nb_inplace_remainder -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMOD__";
+ case nb_inplace_lshift -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ILSHIFT__";
+ case nb_inplace_rshift -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IRSHIFT__";
+ case nb_inplace_and -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IAND__";
+ case nb_inplace_xor -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IXOR__";
+ case nb_inplace_or -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IOR__";
+ case nb_inplace_floor_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IFLOORDIV__";
+ case nb_inplace_true_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ITRUEDIV__";
+ case nb_inplace_matrix_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMATMUL__";
default -> "";
};
}
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index 0a7479f806..8ffd21fcb6 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -929,10 +929,9 @@ def __rmatmul__(self, other):
obj = NativeNbSlotProxy(PureSlotProxy(3))
obj /= 2
assert obj.delegate.delegate == 1.5
- # TODO fix on graalpy
- # obj = NativeNbSlotProxy(PureSlotProxy(ObjWithMatmul()))
- # obj @= 1
- # assert obj.delegate.delegate == '@'
+ obj = NativeNbSlotProxy(PureSlotProxy(ObjWithMatmul()))
+ obj @= 1
+ assert obj.delegate.delegate == '@'
def test_sq_slot_calls():
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
index 07881f7807..13c5fcb87c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java
@@ -160,6 +160,7 @@
import com.oracle.graal.python.builtins.objects.property.PropertyBuiltins;
import com.oracle.graal.python.builtins.objects.range.RangeBuiltins;
import com.oracle.graal.python.builtins.objects.set.BaseSetBuiltins;
+import com.oracle.graal.python.builtins.objects.set.SetBuiltins;
import com.oracle.graal.python.builtins.objects.str.StringBuiltins;
import com.oracle.graal.python.builtins.objects.superobject.SuperBuiltins;
import com.oracle.graal.python.builtins.objects.thread.ThreadLocalBuiltins;
@@ -263,7 +264,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
PReferenceType("ReferenceType", "_weakref"),
PSentinelIterator("callable_iterator", Flags.PRIVATE_DERIVED_WODICT),
PReverseIterator("reversed", J_BUILTINS),
- PSet("set", J_BUILTINS, SET_M_FLAGS, BaseSetBuiltins.SLOTS),
+ PSet("set", J_BUILTINS, SET_M_FLAGS, TpSlots.merge(BaseSetBuiltins.SLOTS, SetBuiltins.SLOTS)),
PSlice("slice", J_BUILTINS),
PString("str", J_BUILTINS, STRING_M_FLAGS, StringBuiltins.SLOTS),
PTraceback("traceback"),
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 98b69fb966..116d0aac2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -1619,7 +1619,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
isTrue = castToBooleanNode.execute(frame, e.getResult());
}
} else {
- isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
+ isTrue = castToBooleanNode.execute(frame, compare.execute(frame, nextKey, currentKey));
}
if (isTrue) {
currentKey = nextKey;
@@ -1663,7 +1663,7 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
isTrue = castToBooleanNode.execute(frame, e.getResult());
}
} else {
- isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
+ isTrue = castToBooleanNode.execute(frame, compare.execute(frame, nextKey, currentKey));
}
if (isTrue) {
currentKey = nextKey;
@@ -1683,7 +1683,7 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
isTrue = castToBooleanNode.execute(frame, e.getResult());
}
} else {
- isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
+ isTrue = castToBooleanNode.execute(frame, compare.execute(frame, nextKey, currentKey));
}
if (isTrue) {
currentKey = nextKey;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
index 19899dc92b..aec6c98c51 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
@@ -1158,7 +1158,7 @@ public static Object gcd(VirtualFrame frame, @SuppressWarnings("unused") Object
profile.profileCounted(args.length);
for (int i = 1; profile.inject(i < args.length); i++) {
Object b = indexNode.execute(frame, inliningTarget, args[i]);
- if ((boolean) eqNode.executeObject(frame, a, 0)) {
+ if ((boolean) eqNode.execute(frame, a, 0)) {
continue;
}
Object g = gcdNode.execute(frame, a, b);
@@ -2488,7 +2488,7 @@ public Object doGeneric(VirtualFrame frame, Object iterable, Object startIn,
e.expectStopIteration(inliningTarget, errorProfile);
return value;
}
- value = mul.executeObject(frame, value, nextValue);
+ value = mul.execute(frame, value, nextValue);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
index c49b42d59b..1720e5b837 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
@@ -3321,7 +3321,7 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, lon
@Cached(value = "createNotNormalized()", inline = false) GetItemNode getItemNode,
@Cached PyLongAsLongNode asLongNode,
@Cached PRaiseNode raiseNode) {
- Object divmod = callDivmod.executeObject(frame, value, BILLION);
+ Object divmod = callDivmod.execute(frame, value, BILLION);
if (!PGuards.isPTuple(divmod) || lenNode.execute(inliningTarget, (PSequence) divmod) != 2) {
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 2dfa351af1..0ccaff8da1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -332,7 +332,7 @@ abstract static class PyTruffleNumber_BinOp extends CApiTernaryBuiltinNode {
static Object doIntLikePrimitiveWrapper(Object left, Object right, @SuppressWarnings("unused") int op,
@Cached("op") @SuppressWarnings("unused") int cachedOp,
@Cached("createCallNode(op)") BinaryOpNode callNode) {
- return callNode.executeObject(null, left, right);
+ return callNode.execute(null, left, right);
}
/**
@@ -541,7 +541,7 @@ static Object repeat(Object obj, long n,
@Bind("this") Node inliningTarget,
@Cached PyObjectLookupAttr lookupNode,
@Cached CallNode callNode,
- @Cached("createMul()") PyNumberMultiplyNode mulNode,
+ @Cached PyNumberMultiplyNode mulNode,
@SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode) {
Object imulCallable = lookupNode.execute(null, inliningTarget, obj, T___IMUL__);
if (imulCallable != PNone.NO_VALUE) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
index 8a9614ee78..dfe4188108 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/functools/KeyWrapperBuiltins.java
@@ -116,7 +116,7 @@ BinaryComparisonNode createCmp() {
boolean doCompare(VirtualFrame frame, PKeyWrapper self, PKeyWrapper other,
@Cached PyObjectIsTrueNode isTrueNode) {
final Object cmpResult = ensureCallNode().execute(frame, self.getCmp(), self.getObject(), other.getObject());
- return isTrueNode.execute(frame, ensureComparisonNode().executeObject(frame, cmpResult, 0));
+ return isTrueNode.execute(frame, ensureComparisonNode().execute(frame, cmpResult, 0));
}
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
index 24deb2c7e2..fe7c0fcdff 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
@@ -405,7 +405,7 @@ static boolean cmpItems(VirtualFrame frame, Node inliningTarget, PArray left, PA
Object leftValue = getLeft.execute(inliningTarget, left, i);
Object rightValue = getRight.execute(inliningTarget, right, i);
if (!eqNode.compare(frame, inliningTarget, leftValue, rightValue)) {
- return coerceToBooleanNode.execute(frame, compareNode.executeObject(frame, leftValue, rightValue));
+ return coerceToBooleanNode.execute(frame, compareNode.execute(frame, leftValue, rightValue));
}
}
return op.cmpResultToBool(left.getLength() - right.getLength());
@@ -422,7 +422,7 @@ static boolean cmpDoubles(VirtualFrame frame, Node inliningTarget, PArray left,
double leftValue = (Double) getLeft.execute(inliningTarget, left, i);
double rightValue = (Double) getRight.execute(inliningTarget, right, i);
if (leftValue != rightValue) {
- return coerceToBooleanNode.execute(frame, compareNode.executeObject(frame, leftValue, rightValue));
+ return coerceToBooleanNode.execute(frame, compareNode.execute(frame, leftValue, rightValue));
}
}
return op.cmpResultToBool(left.getLength() - right.getLength());
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
index 1b0fb038d6..96624251a1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
@@ -44,17 +44,8 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_anext;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_await;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_add;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_and;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_floor_divide;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_lshift;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_multiply;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_or;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_power;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_remainder;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_rshift;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_subtract;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_true_divide;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_xor;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_as_number;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_call;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_hash;
@@ -70,29 +61,20 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IFLOORDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITER__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEXT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___TRUFFLE_RICHCOMPARE__;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.BinaryFuncWrapper;
+import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.CallFunctionWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.HashfuncWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.InitWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.RichcmpFunctionWrapper;
-import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.CallFunctionWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.UnaryFuncLegacyWrapper;
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
import com.oracle.graal.python.builtins.objects.type.MethodsFlags;
@@ -117,17 +99,8 @@ public enum SlotMethodDef {
/*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, CallFunctionWrapper::new, MethodsFlags.AM_SEND), */
NB_INPLACE_ADD(PyNumberMethods__nb_inplace_add, T___IADD__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_ADD),
- NB_INPLACE_AND(PyNumberMethods__nb_inplace_and, T___IAND__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_AND),
- NB_INPLACE_FLOOR_DIVIDE(PyNumberMethods__nb_inplace_floor_divide, T___IFLOORDIV__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_FLOOR_DIVIDE),
- NB_INPLACE_LSHIFT(PyNumberMethods__nb_inplace_lshift, T___ILSHIFT__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_LSHIFT),
NB_INPLACE_MULTIPLY(PyNumberMethods__nb_inplace_multiply, T___IMUL__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_MULTIPLY),
- NB_INPLACE_OR(PyNumberMethods__nb_inplace_or, T___IOR__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_OR),
- NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER),
- NB_INPLACE_REMAINDER(PyNumberMethods__nb_inplace_remainder, T___IMOD__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_REMAINDER),
- NB_INPLACE_RSHIFT(PyNumberMethods__nb_inplace_rshift, T___IRSHIFT__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_RSHIFT),
- NB_INPLACE_SUBTRACT(PyNumberMethods__nb_inplace_subtract, T___ISUB__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_SUBTRACT),
- NB_INPLACE_TRUE_DIVIDE(PyNumberMethods__nb_inplace_true_divide, T___ITRUEDIV__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_TRUE_DIVIDE),
- NB_INPLACE_XOR(PyNumberMethods__nb_inplace_xor, T___IXOR__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_XOR);
+ NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER);
public final TruffleString methodName;
public final Function wrapperFactory;
@@ -161,17 +134,8 @@ public enum SlotMethodDef {
initGroup(
PyTypeObject__tp_as_number,
NB_INPLACE_ADD,
- NB_INPLACE_AND,
- NB_INPLACE_FLOOR_DIVIDE,
- NB_INPLACE_LSHIFT,
NB_INPLACE_MULTIPLY,
- NB_INPLACE_OR,
- NB_INPLACE_POWER,
- NB_INPLACE_REMAINDER,
- NB_INPLACE_RSHIFT,
- NB_INPLACE_SUBTRACT,
- NB_INPLACE_TRUE_DIVIDE,
- NB_INPLACE_XOR);
+ NB_INPLACE_POWER);
}
private static void initGroup(CFields typeField, SlotMethodDef... slots) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index 2be40e1b3d..c56444436b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -152,18 +152,8 @@ private static Object allocatePyNumberMethods(PythonManagedClass obj, TpSlots sl
writeGroupSlots(CFields.PyTypeObject__tp_as_number, slots, writePointerNode, mem, nullValue);
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_add, getSlot(obj, SlotMethodDef.NB_INPLACE_ADD));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_and, getSlot(obj, SlotMethodDef.NB_INPLACE_AND));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_floor_divide, getSlot(obj, SlotMethodDef.NB_INPLACE_FLOOR_DIVIDE));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_lshift, getSlot(obj, SlotMethodDef.NB_INPLACE_LSHIFT));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_matrix_multiply, nullValue);
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_multiply, getSlot(obj, SlotMethodDef.NB_INPLACE_MULTIPLY));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_or, getSlot(obj, SlotMethodDef.NB_INPLACE_OR));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_power, getSlot(obj, SlotMethodDef.NB_INPLACE_POWER));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_remainder, getSlot(obj, SlotMethodDef.NB_INPLACE_REMAINDER));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_rshift, getSlot(obj, SlotMethodDef.NB_INPLACE_RSHIFT));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_subtract, getSlot(obj, SlotMethodDef.NB_INPLACE_SUBTRACT));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_true_divide, getSlot(obj, SlotMethodDef.NB_INPLACE_TRUE_DIVIDE));
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_xor, getSlot(obj, SlotMethodDef.NB_INPLACE_XOR));
return mem;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
index 1c01a5fdd6..35dd7429b0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
@@ -141,7 +141,7 @@ private HPyBinaryArithmeticCached(BinaryArithmetic operator) {
@Override
public Object execute(Object arg0, Object arg1) {
- return opNode.executeObject(null, arg0, arg1);
+ return opNode.execute(null, arg0, arg1);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index 2e9807b5f6..8c4a246fb1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -2015,7 +2015,7 @@ boolean doGeneric(VirtualFrame frame, SequenceStorage left, SequenceStorage righ
}
private boolean cmpGeneric(VirtualFrame frame, Object left, Object right) {
- return castToBoolean(frame, cmpOp.executeObject(frame, left, right));
+ return castToBoolean(frame, cmpOp.execute(frame, left, right));
}
private boolean castToBoolean(VirtualFrame frame, Object value) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java
index 241d0d724b..0b0b9510cc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java
@@ -131,9 +131,9 @@ public Object execute(VirtualFrame frame) {
Object[] arguments = frame.getArguments();
Object a = arguments[PArguments.USER_ARGUMENTS_OFFSET];
Object b = arguments[PArguments.USER_ARGUMENTS_OFFSET + 1];
- if (isTrueNode.execute(frame, ltNodeA.executeObject(frame, a, b))) {
+ if (isTrueNode.execute(frame, ltNodeA.execute(frame, a, b))) {
return Result.LT;
- } else if (isTrueNode.execute(frame, ltNodeB.executeObject(frame, b, a))) {
+ } else if (isTrueNode.execute(frame, ltNodeB.execute(frame, b, a))) {
return Result.GT;
} else {
return Result.EQ;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
index 325a06fd49..f5c7fcd4ae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
@@ -33,7 +33,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___CONTAINS__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
@@ -624,9 +623,9 @@ static Object or(Object self, Object other) {
}
}
- @Builtin(name = J___IOR__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends PythonBinaryBuiltinNode {
+ abstract static class IOrNode extends BinaryOpBuiltinNode {
@Specialization
Object or(VirtualFrame frame, Object self, Object other,
@Cached DictNodes.UpdateNode updateNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index f4dce3ab2a..b53ff2dc93 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -292,9 +292,9 @@ Object doGeneric(VirtualFrame frame, Object left, Object right,
Object unboxed = unboxNode.execute(inliningTarget, left);
if (unboxed != null) {
if (!reverse) {
- return op.executeObject(frame, unboxed, right);
+ return op.execute(frame, unboxed, right);
} else {
- return op.executeObject(frame, right, unboxed);
+ return op.execute(frame, right, unboxed);
}
} else {
return PNotImplemented.NOT_IMPLEMENTED;
@@ -324,7 +324,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object left, Object
if (newLeft == null || newRight == null) {
return PNotImplemented.NOT_IMPLEMENTED;
}
- return op.executeObject(frame, newLeft, newRight);
+ return op.execute(frame, newLeft, newRight);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
index 41fe34298e..2a2c2c902a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
@@ -35,7 +35,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___CONTAINS__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REVERSED__;
@@ -192,7 +191,7 @@ public abstract static class ContainsNode extends PythonBuiltinNode {
@Specialization
Object run(VirtualFrame frame, PMappingproxy self, Object key,
@Cached com.oracle.graal.python.nodes.expression.ContainsNode containsNode) {
- return containsNode.executeObject(frame, key, self.getMapping());
+ return containsNode.execute(frame, key, self.getMapping());
}
}
@@ -278,13 +277,13 @@ Object or(VirtualFrame frame, Object self, Object other) {
if (other instanceof PMappingproxy) {
other = ((PMappingproxy) other).getMapping();
}
- return orNode.executeObject(frame, self, other);
+ return orNode.execute(frame, self, other);
}
}
- @Builtin(name = J___IOR__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends PythonBinaryBuiltinNode {
+ abstract static class IOrNode extends BinaryOpBuiltinNode {
@Specialization
static Object or(Object self, @SuppressWarnings("unused") Object other,
@Bind("this") Node inliningTarget) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
index b76f4a73bc..c834e651c7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
@@ -702,7 +702,7 @@ boolean richcmp(VirtualFrame frame, Object left, Object right, @SuppressWarnings
return castToBooleanNode.execute(frame, e.getResult());
}
} else {
- return castToBooleanNode.execute(frame, node.executeObject(frame, left, right));
+ return castToBooleanNode.execute(frame, node.execute(frame, left, right));
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
index 19018ae0c8..4608ea7a72 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
@@ -48,7 +48,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J_VALUES;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___NE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REDUCE__;
@@ -271,9 +270,9 @@ static Object or(Object self, Object other) {
}
}
- @Builtin(name = J___IOR__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends PythonBinaryBuiltinNode {
+ abstract static class IOrNode extends BinaryOpBuiltinNode {
@Specialization
static Object or(VirtualFrame frame, POrderedDict self, Object other,
@Bind("this") Node inliningTarget,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
index a713daa3eb..35030b8572 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java
@@ -201,7 +201,7 @@ public abstract static class RefTypeEqNode extends PythonBuiltinNode {
@Specialization(guards = {"self.getObject() != null", "other.getObject() != null"})
Object eq(VirtualFrame frame, PReferenceType self, PReferenceType other,
@Cached BinaryComparisonNode.EqNode eqNode) {
- return eqNode.executeObject(frame, self.getObject(), other.getObject());
+ return eqNode.execute(frame, self.getObject(), other.getObject());
}
@Specialization(guards = "self.getObject() == null || other.getObject() == null")
@@ -223,7 +223,7 @@ public abstract static class RefTypeNeNode extends PythonBuiltinNode {
@Specialization(guards = {"self.getObject() != null", "other.getObject() != null"})
Object ne(VirtualFrame frame, PReferenceType self, PReferenceType other,
@Cached BinaryComparisonNode.NeNode neNode) {
- return neNode.executeObject(frame, self.getObject(), other.getObject());
+ return neNode.execute(frame, self.getObject(), other.getObject());
}
@Specialization(guards = "self.getObject() == null || other.getObject() == null")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
index 4cb3141a30..87287d8c35 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
@@ -26,17 +26,15 @@
package com.oracle.graal.python.builtins.objects.set;
import static com.oracle.graal.python.nodes.BuiltinNames.J_ADD;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IAND__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IOR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ISUB__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
import java.util.List;
import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.annotations.Slot;
+import com.oracle.graal.python.annotations.Slot.SlotKind;
import com.oracle.graal.python.builtins.Builtin;
import com.oracle.graal.python.builtins.CoreFunctions;
import com.oracle.graal.python.builtins.Python3Core;
@@ -61,6 +59,8 @@
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.dict.PDictView;
import com.oracle.graal.python.builtins.objects.str.PString;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.lib.GetNextNode;
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -101,6 +101,8 @@
@CoreFunctions(extendClasses = PythonBuiltinClassType.PSet)
public final class SetBuiltins extends PythonBuiltins {
+ public static final TpSlots SLOTS = SetBuiltinsSlotsGen.SLOTS;
+
@Override
public void initialize(Python3Core core) {
super.initialize(core);
@@ -181,9 +183,9 @@ public static Object add(VirtualFrame frame, PSet self, Object o,
}
}
- @Builtin(name = J___IOR__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- public abstract static class IOrNode extends PythonBinaryBuiltinNode {
+ public abstract static class IOrNode extends BinaryOpBuiltinNode {
@Specialization
Object doSet(VirtualFrame frame, PSet self, PBaseSet other,
@Bind("this") Node inliningTarget,
@@ -369,9 +371,9 @@ static PNone doSet(VirtualFrame frame, PSet self, Object other,
}
}
- @Builtin(name = J___IAND__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_and, isComplex = true)
@GenerateNodeFactory
- public abstract static class IAndNode extends PythonBinaryBuiltinNode {
+ public abstract static class IAndNode extends BinaryOpBuiltinNode {
@Specialization
static PBaseSet doPBaseSet(VirtualFrame frame, PSet left, PBaseSet right,
@@ -470,9 +472,9 @@ protected Object createResult(PSet self, HashingStorage result) {
}
}
- @Builtin(name = J___IXOR__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_xor, isComplex = true)
@GenerateNodeFactory
- public abstract static class IXorNode extends PythonBinaryBuiltinNode {
+ public abstract static class IXorNode extends BinaryOpBuiltinNode {
@Specialization
static Object doSet(VirtualFrame frame, PSet self, PBaseSet other,
@@ -556,9 +558,9 @@ static PNone doSetOther(VirtualFrame frame, PSet self, Object other,
}
}
- @Builtin(name = J___ISUB__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.nb_inplace_subtract, isComplex = true)
@GenerateNodeFactory
- abstract static class ISubNode extends PythonBinaryBuiltinNode {
+ abstract static class ISubNode extends BinaryOpBuiltinNode {
@Specialization
static PBaseSet doPBaseSet(VirtualFrame frame, PSet left, PBaseSet right,
@Bind("this") Node inliningTarget,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index 9c0aa4e47d..dc54a17acb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -54,9 +54,21 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETATTR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GET__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IFLOORDIV__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INDEX__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INVERT__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___LEN__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___LSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MATMUL__;
@@ -143,6 +155,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotPythonSingle;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.TpSlotBinaryFuncBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.TpSlotSqConcat;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotBinaryIOpBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotBinaryOpBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotReversiblePython;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.TpSlotDescrGetBuiltin;
@@ -263,6 +276,18 @@ public record TpSlots(TpSlot nb_bool, //
TpSlot nb_divmod, //
TpSlot nb_matrix_multiply, //
TpSlot nb_power, //
+ TpSlot nb_inplace_add, //
+ TpSlot nb_inplace_subtract, //
+ TpSlot nb_inplace_multiply, //
+ TpSlot nb_inplace_remainder, //
+ TpSlot nb_inplace_lshift, //
+ TpSlot nb_inplace_rshift, //
+ TpSlot nb_inplace_and, //
+ TpSlot nb_inplace_xor, //
+ TpSlot nb_inplace_or, //
+ TpSlot nb_inplace_floor_divide, //
+ TpSlot nb_inplace_true_divide, //
+ TpSlot nb_inplace_matrix_multiply, //
TpSlot sq_length, //
TpSlot sq_item, //
TpSlot sq_ass_item, //
@@ -537,6 +562,102 @@ public enum TpSlotMeta {
CFields.PyNumberMethods__nb_power,
PExternalFunctionWrapper.TERNARYFUNC,
NbPowerWrapper::new),
+ NB_INPLACE_ADD(
+ TpSlots::nb_inplace_add,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_add,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_SUBTRACT(
+ TpSlots::nb_inplace_subtract,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_subtract,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_MULTIPLY(
+ TpSlots::nb_inplace_multiply,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_multiply,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_REMAINDER(
+ TpSlots::nb_inplace_remainder,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_remainder,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_LSHIFT(
+ TpSlots::nb_inplace_lshift,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_lshift,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_RSHIFT(
+ TpSlots::nb_inplace_rshift,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_rshift,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_AND(
+ TpSlots::nb_inplace_and,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_and,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_XOR(
+ TpSlots::nb_inplace_xor,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_xor,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_OR(
+ TpSlots::nb_inplace_or,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_or,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_FLOOR_DIVIDE(
+ TpSlots::nb_inplace_floor_divide,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_floor_divide,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_TRUE_DIVIDE(
+ TpSlots::nb_inplace_true_divide,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_true_divide,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
+ NB_INPLACE_MATRIX_MULTIPLY(
+ TpSlots::nb_inplace_matrix_multiply,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_matrix_multiply,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
SQ_LENGTH(
TpSlots::sq_length,
TpSlotPythonSingle.class,
@@ -870,6 +991,18 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
addSlotDef(s, TpSlotMeta.NB_POWER,
TpSlotDef.withoutHPy(T___POW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC),
TpSlotDef.withoutHPy(T___RPOW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC_R));
+ // addSlotDef(s, TpSlotMeta.NB_INPLACE_ADD, TpSlotDef.withSimpleFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_SUBTRACT, TpSlotDef.withSimpleFunction(T___ISUB__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ // addSlotDef(s, TpSlotMeta.NB_INPLACE_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMUL__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_REMAINDER, TpSlotDef.withSimpleFunction(T___IMOD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_LSHIFT, TpSlotDef.withSimpleFunction(T___ILSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_RSHIFT, TpSlotDef.withSimpleFunction(T___IRSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_AND, TpSlotDef.withSimpleFunction(T___IAND__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_XOR, TpSlotDef.withSimpleFunction(T___IXOR__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_OR, TpSlotDef.withSimpleFunction(T___IOR__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_FLOOR_DIVIDE, TpSlotDef.withSimpleFunction(T___IFLOORDIV__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_TRUE_DIVIDE, TpSlotDef.withSimpleFunction(T___ITRUEDIV__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_MATRIX_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMATMUL__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_BOOL, TpSlotDef.withSimpleFunction(T___BOOL__, PExternalFunctionWrapper.INQUIRY));
addSlotDef(s, TpSlotMeta.NB_INDEX, TpSlotDef.withSimpleFunction(T___INDEX__, PExternalFunctionWrapper.UNARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INT, TpSlotDef.withSimpleFunction(T___INT__, PExternalFunctionWrapper.UNARYFUNC));
@@ -1490,6 +1623,18 @@ public TpSlots build() {
get(TpSlotMeta.NB_DIVMOD), //
get(TpSlotMeta.NB_MATRIX_MULTIPLY), //
get(TpSlotMeta.NB_POWER), //
+ get(TpSlotMeta.NB_INPLACE_ADD), //
+ get(TpSlotMeta.NB_INPLACE_SUBTRACT), //
+ get(TpSlotMeta.NB_INPLACE_MULTIPLY), //
+ get(TpSlotMeta.NB_INPLACE_REMAINDER), //
+ get(TpSlotMeta.NB_INPLACE_LSHIFT), //
+ get(TpSlotMeta.NB_INPLACE_RSHIFT), //
+ get(TpSlotMeta.NB_INPLACE_AND), //
+ get(TpSlotMeta.NB_INPLACE_XOR), //
+ get(TpSlotMeta.NB_INPLACE_OR), //
+ get(TpSlotMeta.NB_INPLACE_FLOOR_DIVIDE), //
+ get(TpSlotMeta.NB_INPLACE_TRUE_DIVIDE), //
+ get(TpSlotMeta.NB_INPLACE_MATRIX_MULTIPLY), //
get(TpSlotMeta.SQ_LENGTH), //
get(TpSlotMeta.SQ_ITEM), //
get(TpSlotMeta.SQ_ASS_ITEM), //
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java
index eeaee95aef..016ce83ae9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.objects.type.slots;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GETITEM__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
@@ -111,7 +112,7 @@ protected TpSlotMpSubscript(NodeFactory nodeFactory) {
public abstract static class TpSlotSqConcat extends TpSlotBinaryFuncBuiltin {
protected TpSlotSqConcat(NodeFactory nodeFactory) {
- super(nodeFactory, PExternalFunctionWrapper.BINARYFUNC, J___GETITEM__);
+ super(nodeFactory, PExternalFunctionWrapper.BINARYFUNC, J___ADD__);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
index 462a7da957..b8189ba239 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
@@ -44,6 +44,18 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AND__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DIVMOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___FLOORDIV__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IFLOORDIV__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___LSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MATMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MOD__;
@@ -91,6 +103,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotCExtNative;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotPython;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.TpSlotBinaryFuncBuiltin;
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
@@ -182,6 +195,61 @@ public static ReversibleSlot fromCallableNames(TruffleString[] names) {
}
}
+ public enum InplaceSlot {
+ NB_INPLACE_ADD(T___IADD__, ReversibleSlot.NB_ADD),
+ NB_INPLACE_SUBTRACT(T___ISUB__, ReversibleSlot.NB_SUBTRACT),
+ NB_INPLACE_MULTIPLY(T___IMUL__, ReversibleSlot.NB_MULTIPLY),
+ NB_INPLACE_REMAINDER(T___IMOD__, ReversibleSlot.NB_REMAINDER),
+ NB_INPLACE_LSHIFT(T___ILSHIFT__, ReversibleSlot.NB_LSHIFT),
+ NB_INPLACE_RSHIFT(T___IRSHIFT__, ReversibleSlot.NB_RSHIFT),
+ NB_INPLACE_AND(T___IAND__, ReversibleSlot.NB_AND),
+ NB_INPLACE_XOR(T___IXOR__, ReversibleSlot.NB_XOR),
+ NB_INPLACE_OR(T___IOR__, ReversibleSlot.NB_OR),
+ NB_INPLACE_FLOOR_DIVIDE(T___IFLOORDIV__, ReversibleSlot.NB_FLOOR_DIVIDE),
+ NB_INPLACE_TRUE_DIVIDE(T___ITRUEDIV__, ReversibleSlot.NB_TRUE_DIVIDE),
+ NB_INPLACE_MATRIX_MULTIPLY(T___IMATMUL__, ReversibleSlot.NB_MATRIX_MULTIPLY);
+
+ private static final InplaceSlot[] VALUES = values();
+ private final TruffleString name;
+ private final ReversibleSlot reversibleSlot;
+
+ InplaceSlot(TruffleString name, ReversibleSlot reversibleSlot) {
+ this.name = name;
+ this.reversibleSlot = reversibleSlot;
+ }
+
+ public TpSlot getSlotValue(TpSlots slots) {
+ // switch instead of using TpSlotMeta for better inlining on fast-path
+ return switch (this) {
+ case NB_INPLACE_ADD -> slots.nb_inplace_add();
+ case NB_INPLACE_SUBTRACT -> slots.nb_inplace_subtract();
+ case NB_INPLACE_MULTIPLY -> slots.nb_inplace_multiply();
+ case NB_INPLACE_REMAINDER -> slots.nb_inplace_remainder();
+ case NB_INPLACE_LSHIFT -> slots.nb_inplace_lshift();
+ case NB_INPLACE_RSHIFT -> slots.nb_inplace_rshift();
+ case NB_INPLACE_AND -> slots.nb_inplace_and();
+ case NB_INPLACE_XOR -> slots.nb_inplace_xor();
+ case NB_INPLACE_OR -> slots.nb_inplace_or();
+ case NB_INPLACE_FLOOR_DIVIDE -> slots.nb_inplace_floor_divide();
+ case NB_INPLACE_TRUE_DIVIDE -> slots.nb_inplace_true_divide();
+ case NB_INPLACE_MATRIX_MULTIPLY -> slots.nb_inplace_matrix_multiply();
+ };
+ }
+
+ public static InplaceSlot fromCallableNames(TruffleString[] names) {
+ for (InplaceSlot op : VALUES) {
+ if (names[0].equals(op.name)) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+ public ReversibleSlot getReversibleSlot() {
+ return reversibleSlot;
+ }
+ }
+
public abstract static class TpSlotBinaryOpBuiltin extends TpSlotBuiltin {
private final int callTargetIndex = TpSlotBuiltinCallTargetRegistry.getNextCallTargetIndex();
private final String builtinName;
@@ -216,6 +284,13 @@ private PBuiltinFunction createRBuiltin(Python3Core core, Object type, TruffleSt
}
}
+ public abstract static class TpSlotBinaryIOpBuiltin extends TpSlotBinaryFuncBuiltin {
+
+ protected TpSlotBinaryIOpBuiltin(NodeFactory nodeFactory, String builtinName) {
+ super(nodeFactory, PExternalFunctionWrapper.BINARYFUNC, builtinName);
+ }
+ }
+
static final class SwapArgumentsNode extends PythonBinaryBuiltinNode {
@Child private BinaryOpBuiltinNode wrapped;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
index f0e7343f7b..92cb0e4033 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
@@ -302,7 +302,7 @@ Object getitem(VirtualFrame frame, PUnionType self, Object item,
Object[] newargs = GenericTypeNodes.subsParameters(this, self, self.getArgs(), self.getParameters(), item);
Object result = newargs[0];
for (int i = 1; i < newargs.length; i++) {
- result = orNode.executeObject(frame, result, newargs[i]);
+ result = orNode.execute(frame, result, newargs[i]);
}
return result;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOp1Node.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOp1Node.java
new file mode 100644
index 0000000000..a873681881
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOp1Node.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.PNodeWithContext;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+
+/**
+ * Equivalent of cpython://Objects/abstract.c#binary_iop1.
+ */
+@GenerateInline
+@GenerateCached(false)
+@GenerateUncached
+public abstract class CallBinaryIOp1Node extends PNodeWithContext {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlots slotsV,
+ Object w, Object classW, TpSlots slotsW, InplaceSlot op);
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlots slotsV, Object w, Object classW, TpSlots slotsW, InplaceSlot iop,
+ @Cached CallSlotBinaryFuncNode callSlotNode,
+ @Cached InlinedBranchProfile resultProfile,
+ @Cached CallBinaryOp1Node callBinaryOp1Node) {
+ TpSlot slot = iop.getSlotValue(slotsV);
+ if (slot != null) {
+ Object result = callSlotNode.execute(frame, inliningTarget, slot, v, w);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ resultProfile.enter(inliningTarget);
+ return result;
+ }
+ }
+ return callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, iop.getReversibleSlot());
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOpNode.java
new file mode 100644
index 0000000000..b52455725d
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryIOpNode.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
+
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+/**
+ * Equivalent of cpython://Objects/abstract.c#binary_op.
+ */
+@GenerateInline
+@GenerateCached(false)
+@GenerateUncached
+public abstract class CallBinaryIOpNode extends Node {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, InplaceSlot slot, String opName);
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w, InplaceSlot slot, String opName,
+ @Cached GetClassNode getVClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Cached GetClassNode getWClass,
+ @Cached CallBinaryIOp1Node callBinaryIOp1Node,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ Object result = callBinaryIOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, slot);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
+ }
+ throw raiseNotSupported(inliningTarget, v, w, opName, raiseNode);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
index 3071008a18..8db781fbb2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOp1Node.java
@@ -41,16 +41,18 @@
package com.oracle.graal.python.lib;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.IsSameSlotNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.CallSlotBinaryOpNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@@ -62,9 +64,10 @@
*/
@GenerateInline
@GenerateCached(false)
+@GenerateUncached
public abstract class CallBinaryOp1Node extends PNodeWithContext {
- public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV,
- Object w, Object classW, TpSlot slotW, ReversibleSlot op);
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlots slotsV,
+ Object w, Object classW, TpSlots slotsW, ReversibleSlot op);
// CPython binary_op1 may end up calling SLOT1BINFULL - wrapper around the dunder methods, which
// duplicates some of the logic checking the right operand, its slot, and whether it is subtype.
@@ -86,47 +89,50 @@ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v
// we just try __rxxx__, again, without any subclass check.
@Specialization
- static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlot slotV, Object w, Object classW, TpSlot slotWIn, ReversibleSlot op,
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object classV, TpSlots slotsV, Object w, Object classW, TpSlots slotsW, ReversibleSlot op,
@Cached IsSameTypeNode isSameTypeNode,
@Cached IsSameSlotNode isSameSlotNode,
@Cached InlinedConditionProfile isSameTypeProfile,
@Cached InlinedConditionProfile isSameSlotProfile,
@Cached(inline = false) IsSubtypeNode isSubtypeNode,
- @Cached InlinedBranchProfile wResultBranch,
- @Cached InlinedBranchProfile vResultBranch,
+ @Cached InlinedConditionProfile vResultProfile,
+ @Cached InlinedConditionProfile wResultProfile,
@Cached InlinedBranchProfile notImplementedBranch,
@Cached CallSlotBinaryOpNode callSlotWNode,
@Cached CallSlotBinaryOpNode callSlotVNode) {
- TpSlot slotW = null;
- boolean sameTypes = isSameTypeProfile.profile(inliningTarget, isSameTypeNode.execute(inliningTarget, classW, classV));
- if (!sameTypes) {
- slotW = slotWIn;
- if (isSameSlotProfile.profile(inliningTarget, slotV != null && slotW != null && isSameSlotNode.execute(inliningTarget, slotW, slotV))) {
- slotW = null;
- }
- }
+ final TpSlot slotV = op.getSlotValue(slotsV);
+ final TpSlot slotW = op.getSlotValue(slotsW);
+ boolean skipReverse = false;
// Note: we call slotW with v as the receiver. This appears to be the semantics of
// CPython reversible binop slots. This is supposed to allow the slot to handle
// the reversible case, if the slot does not want to handle it, it should detect that
// the first receiver argument is not of the right type and just return NotImplemented.
if (slotV != null) {
- if (slotW != null && isSubtypeNode.execute(frame, classW, classV)) {
- assert !sameTypes;
- Object result = callSlotWNode.execute(frame, inliningTarget, slotW, v, classV, w, slotW, classW, false, op);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- wResultBranch.enter(inliningTarget);
- return result;
+ boolean sameTypes = false;
+ if (slotW != null) {
+ sameTypes = isSameTypeProfile.profile(inliningTarget, isSameTypeNode.execute(inliningTarget, classW, classV));
+ if (!sameTypes) {
+ if (!isSameSlotProfile.profile(inliningTarget, isSameSlotNode.execute(inliningTarget, slotW, slotV))) {
+ if (isSubtypeNode.execute(frame, classW, classV)) {
+ Object result = callSlotWNode.execute(frame, inliningTarget, slotW, v, classV, w, slotW, classW, false, op);
+ if (wResultProfile.profile(inliningTarget, result != PNotImplemented.NOT_IMPLEMENTED)) {
+ return result;
+ }
+ skipReverse = true;
+ }
+ } else {
+ skipReverse = true;
+ }
+ } else {
+ skipReverse = true;
}
- slotW = null;
}
- Object result = callSlotVNode.execute(frame, inliningTarget, slotV, v, classV, w, slotWIn, classW, sameTypes, op);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- vResultBranch.enter(inliningTarget);
+ Object result = callSlotVNode.execute(frame, inliningTarget, slotV, v, classV, w, slotW, classW, sameTypes, op);
+ if (vResultProfile.profile(inliningTarget, result != PNotImplemented.NOT_IMPLEMENTED)) {
return result;
}
}
- if (slotW != null) {
- assert !sameTypes;
+ if (slotW != null && !skipReverse) {
return callSlotWNode.execute(frame, inliningTarget, slotW, v, classV, w, slotW, classW, false, op);
}
notImplementedBranch.enter(inliningTarget);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOpNode.java
new file mode 100644
index 0000000000..e09fb2c59d
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallBinaryOpNode.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+/**
+ * Equivalent of cpython://Objects/abstract.c#binary_op.
+ */
+@GenerateInline
+@GenerateCached(false)
+@GenerateUncached
+public abstract class CallBinaryOpNode extends Node {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, ReversibleSlot slot, String opName);
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w, ReversibleSlot slot, String opName,
+ @Cached GetClassNode getVClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Cached GetClassNode getWClass,
+ @Cached CallBinaryOp1Node callBinaryOp1Node,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, slot);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
+ }
+ throw raiseNotSupported(inliningTarget, v, w, opName, raiseNode);
+ }
+
+ @InliningCutoff
+ static PException raiseNotSupported(Node inliningTarget, Object v, Object w, String opName, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, opName, v, w);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index d14256f4c6..a169ce7770 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -40,10 +40,10 @@
*/
package com.oracle.graal.python.lib;
+import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
@@ -51,22 +51,19 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
@@ -76,28 +73,13 @@
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
-@GenerateInline(inlineByDefault = true)
-public abstract class PyNumberAddNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return executeCached(frame, left, right);
- }
-
- public final Object executeCached(VirtualFrame frame, Object v, Object w) {
- return execute(frame, this, v, w);
- }
-
- public abstract int executeInt(VirtualFrame frame, Node inliningTarget, int left, int right) throws UnexpectedResultException;
-
- public abstract double executeDouble(VirtualFrame frame, Node inliningTarget, double left, double right) throws UnexpectedResultException;
+@GenerateCached(false)
+abstract class PyNumberAddBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, FloatBuiltins, ListBuiltins, ...
*/
-
@Specialization(rewriteOn = ArithmeticException.class)
public static int add(int left, int right) {
return Math.addExact(left, right);
@@ -137,6 +119,24 @@ public static double doDI(double left, int right) {
public static double doID(int left, double right) {
return left + right;
}
+}
+
+@GenerateInline(inlineByDefault = true)
+public abstract class PyNumberAddNode extends PyNumberAddBaseNode {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
+
+ @Override
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
+ return executeCached(frame, left, right);
+ }
+
+ public final Object executeCached(VirtualFrame frame, Object v, Object w) {
+ return execute(frame, this, v, w);
+ }
+
+ public abstract int executeInt(VirtualFrame frame, Node inliningTarget, int left, int right) throws UnexpectedResultException;
+
+ public abstract double executeDouble(VirtualFrame frame, Node inliningTarget, double left, double right) throws UnexpectedResultException;
@NeverDefault
protected static SequenceStorageNodes.ConcatNode createConcat() {
@@ -179,24 +179,15 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
Object classW = getWClass.execute(inliningTarget, w);
TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
- TpSlot slotV = slotsV.nb_add();
- TpSlot slotW = slotsW.nb_add();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_ADD);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- hasNbAddResult.enter(inliningTarget);
- return result;
- }
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, ReversibleSlot.NB_ADD);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbAddResult.enter(inliningTarget);
+ return result;
}
if (slotsV.sq_concat() != null) {
return callBinarySlotNode.execute(frame, inliningTarget, slotsV.sq_concat(), v, w);
}
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
+ return raiseNotSupported(inliningTarget, v, w, "+", raiseNode);
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
index a355cc7ddd..1a714d901b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
@@ -40,34 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberAndNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberAndBaseNode extends BinaryOpNode {
@Specialization
public static int op(int left, int right) {
@@ -78,33 +66,18 @@ public static int op(int left, int right) {
public static long op(long left, long right) {
return left & right;
}
+}
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberAndNode extends PyNumberAndBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_and();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_and();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_AND);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "&", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_AND, "&");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
index 1b113ff484..37f65cd7f9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
@@ -40,30 +40,23 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(inlineByDefault = true)
+@GenerateUncached
public abstract class PyNumberDivmodNode extends BinaryOpNode {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
@Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
return executeCached(frame, left, right);
}
@@ -72,29 +65,9 @@ public final Object executeCached(VirtualFrame frame, Object v, Object w) {
}
@Specialization
- static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_divmod();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_divmod();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_DIVMOD);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "divmod()", v, w);
+ public static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_DIVMOD, "divmod()");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
index 780808a84f..d0502ec191 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
@@ -40,35 +40,20 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.util.OverflowException;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberFloorDivideNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberFloorDivideBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
@@ -107,32 +92,16 @@ public static double doDD(double left, double right) throws OverflowException {
}
return Math.floor(left / right);
}
+}
- @Fallback
+@GenerateInline(false)
+public abstract class PyNumberFloorDivideNode extends PyNumberFloorDivideBaseNode {
+
+ @Specialization
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_floor_divide();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_floor_divide();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_FLOOR_DIVIDE);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "//", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_FLOOR_DIVIDE, "//");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java
new file mode 100644
index 0000000000..85992c10f8
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberInplaceAndNode extends PyNumberAndBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_AND, "&=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceAndNode create() {
+ return PyNumberInplaceAndNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java
new file mode 100644
index 0000000000..079c4c3796
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceFloorDivideNode extends PyNumberFloorDivideBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_FLOOR_DIVIDE, "//=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceFloorDivideNode create() {
+ return PyNumberInplaceFloorDivideNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java
new file mode 100644
index 0000000000..38bd68ff5c
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceLshiftNode extends PyNumberLshiftBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_LSHIFT, "<<=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceLshiftNode create() {
+ return PyNumberInplaceLshiftNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java
new file mode 100644
index 0000000000..8851785e01
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberInplaceMatrixMultiplyNode extends BinaryOpNode {
+ @Specialization
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_MATRIX_MULTIPLY, "@=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceMatrixMultiplyNode create() {
+ return PyNumberInplaceMatrixMultiplyNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java
new file mode 100644
index 0000000000..bf5d14e578
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberInplaceOrNode extends PyNumberOrBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_OR, "|=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceOrNode create() {
+ return PyNumberInplaceOrNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java
new file mode 100644
index 0000000000..c8cb9a6cdc
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceRemainderNode extends PyNumberRemainderBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_REMAINDER, "%=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceRemainderNode create() {
+ return PyNumberInplaceRemainderNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java
new file mode 100644
index 0000000000..3ae084345e
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceRshiftNode extends PyNumberRshiftBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_RSHIFT, ">>=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceRshiftNode create() {
+ return PyNumberInplaceRshiftNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java
new file mode 100644
index 0000000000..61be233988
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceSubtractNode extends PyNumberSubtractBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_SUBTRACT, "-=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceSubtractNode create() {
+ return PyNumberInplaceSubtractNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java
new file mode 100644
index 0000000000..b038bc42d0
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceTrueDivideNode extends PyNumberTrueDivideBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_TRUE_DIVIDE, "/=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceTrueDivideNode create() {
+ return PyNumberInplaceTrueDivideNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java
new file mode 100644
index 0000000000..0f5654ff61
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberInplaceXorNode extends PyNumberXorBaseNode {
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Cached CallBinaryIOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, InplaceSlot.NB_INPLACE_XOR, "^=");
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceXorNode create() {
+ return PyNumberInplaceXorNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
index 5174b5e343..e78acaab90 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
@@ -40,35 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberLshiftNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberLshiftBaseNode extends BinaryOpNode {
@Specialization(guards = {"right < 32", "right >= 0"}, rewriteOn = OverflowException.class)
public static int doII(int left, int right) throws OverflowException {
@@ -87,32 +74,17 @@ public static long doLL(long left, long right) throws OverflowException {
}
return result;
}
+}
+
+@GenerateInline(false)
+public abstract class PyNumberLshiftNode extends PyNumberLshiftBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_lshift();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_lshift();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_LSHIFT);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "<<", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_LSHIFT, "<<");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
index 7595406b11..a0e3f6041c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
@@ -40,59 +40,26 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberMatrixMultiplyNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
@Specialization
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_matrix_multiply();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_matrix_multiply();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_MATRIX_MULTIPLY);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "@", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_MATRIX_MULTIPLY, "@");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index 784deff635..ee19d86660 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -40,6 +40,8 @@
*/
package com.oracle.graal.python.lib;
+import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
@@ -56,6 +58,7 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
@@ -64,28 +67,13 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
-@GenerateInline(inlineByDefault = true)
-public abstract class PyNumberMultiplyNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return executeCached(frame, left, right);
- }
-
- public final Object executeCached(VirtualFrame frame, Object v, Object w) {
- return execute(frame, this, v, w);
- }
-
- public abstract int executeInt(VirtualFrame frame, Node inliningTarget, int left, int right) throws UnexpectedResultException;
-
- public abstract double executeDouble(VirtualFrame frame, Node inliningTarget, double left, double right) throws UnexpectedResultException;
+@GenerateCached(false)
+abstract class PyNumberMultiplyBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, FloatBuiltins, ListBuiltins, ...
*/
-
@Specialization(rewriteOn = ArithmeticException.class)
public static int doII(int x, int y) throws ArithmeticException {
return Math.multiplyExact(x, y);
@@ -115,6 +103,24 @@ public static double doLD(long left, double right) {
public static double doDD(double left, double right) {
return left * right;
}
+}
+
+@GenerateInline(inlineByDefault = true)
+public abstract class PyNumberMultiplyNode extends PyNumberMultiplyBaseNode {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
+
+ @Override
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
+ return executeCached(frame, left, right);
+ }
+
+ public final Object executeCached(VirtualFrame frame, Object v, Object w) {
+ return execute(frame, this, v, w);
+ }
+
+ public abstract int executeInt(VirtualFrame frame, Node inliningTarget, int left, int right) throws UnexpectedResultException;
+
+ public abstract double executeDouble(VirtualFrame frame, Node inliningTarget, double left, double right) throws UnexpectedResultException;
@Fallback
static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@@ -134,14 +140,10 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
Object classW = getWClass.execute(inliningTarget, w);
TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
- TpSlot slotV = slotsV.nb_multiply();
- TpSlot slotW = slotsW.nb_multiply();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_MULTIPLY);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- hasNbMulResult.enter(inliningTarget);
- return result;
- }
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, ReversibleSlot.NB_MULTIPLY);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbMulResult.enter(inliningTarget);
+ return result;
}
if (slotsV.sq_repeat() != null) {
vHasSqRepeat.enter(inliningTarget);
@@ -152,12 +154,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
return sequenceRepeat(frame, inliningTarget, slotsW.sq_repeat(), w, v,
indexCheckNode, asSizeNode, callSlotNode, raiseNode);
}
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "+", v, w);
+ return raiseNotSupported(inliningTarget, v, w, "*", raiseNode);
}
private static Object sequenceRepeat(VirtualFrame frame, Node inliningTarget, TpSlot slot, Object seq, Object n,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
index d79c83a043..2b66915680 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
@@ -40,34 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberOrNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberOrBaseNode extends BinaryOpNode {
@Specialization
public static int op(int left, int right) {
@@ -78,32 +66,18 @@ public static int op(int left, int right) {
public static long op(long left, long right) {
return left | right;
}
+}
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberOrNode extends PyNumberOrBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_or();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_or();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_OR);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "|", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_OR, "|");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
index fe4a46e0ce..18d3a87e3d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
@@ -66,7 +66,7 @@ public abstract class PyNumberPowerNode extends BinaryOpNode {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z);
@Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
return executeCached(frame, left, right, PNone.NONE);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
index e8af02f81c..78dba84ea7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
@@ -40,35 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberRemainderNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberRemainderBaseNode extends BinaryOpNode {
@Specialization(rewriteOn = ArithmeticException.class)
public static int doII(int left, int right) {
@@ -84,32 +71,17 @@ public static long doLL(long left, long right) {
public static double doDL(double left, long right) {
return FloatBuiltins.ModNode.mod(left, right);
}
+}
+
+@GenerateInline(false)
+public abstract class PyNumberRemainderNode extends PyNumberRemainderBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_remainder();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_remainder();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_REMAINDER);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "%", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_REMAINDER, "%");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
index a4b7d9be6f..9203c8a04d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
@@ -46,8 +46,8 @@
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -59,20 +59,15 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberRshiftNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberRshiftBaseNode extends BinaryOpNode {
@Specialization(guards = {"right < 32", "right >= 0"})
public static int doIISmall(int left, int right) {
@@ -83,6 +78,10 @@ public static int doIISmall(int left, int right) {
public static long doIISmall(long left, long right) {
return left >> right;
}
+}
+
+@GenerateInline(false)
+public abstract class PyNumberRshiftNode extends PyNumberRshiftBaseNode {
@Fallback
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -95,15 +94,13 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
@Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_rshift();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_rshift();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_RSHIFT);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, ReversibleSlot.NB_RSHIFT);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
}
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
+ throw raiseNotSupported(inliningTarget, v, w, raiseNode);
}
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
index 87548bc511..9144468818 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
@@ -40,40 +40,26 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberSubtractNode extends BinaryOpNode {
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
-
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
+@GenerateCached(false)
+abstract class PyNumberSubtractBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, FloatBuiltins, ListBuiltins, ...
*/
-
@Specialization(rewriteOn = ArithmeticException.class)
public static int doII(int x, int y) throws ArithmeticException {
return Math.subtractExact(x, y);
@@ -113,32 +99,17 @@ public static double doDI(double left, int right) {
public static double doID(int left, double right) {
return left - right;
}
+}
+
+@GenerateInline(false)
+public abstract class PyNumberSubtractNode extends PyNumberSubtractBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_subtract();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_subtract();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_SUBTRACT);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "-", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_SUBTRACT, "-");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
index a4986c6c72..bf9dff20a6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
@@ -40,35 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberTrueDivideNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberTrueDivideBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
@@ -96,32 +83,17 @@ public static double doDD(double left, double right) throws OverflowException {
}
return left / right;
}
+}
+
+@GenerateInline(false)
+public abstract class PyNumberTrueDivideNode extends PyNumberTrueDivideBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_true_divide();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_true_divide();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_TRUE_DIVIDE);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "/", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_TRUE_DIVIDE, "/");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
index a7de7a2959..5fb858c7a7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
@@ -40,34 +40,22 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(false)
-public abstract class PyNumberXorNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Object v, Object w);
-
- @Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
+@GenerateCached(false)
+abstract class PyNumberXorBaseNode extends BinaryOpNode {
@Specialization
public static int op(int left, int right) {
@@ -78,32 +66,18 @@ public static int op(int left, int right) {
public static long op(long left, long right) {
return left ^ right;
}
+}
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class PyNumberXorNode extends PyNumberXorBaseNode {
@Fallback
+ @InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
- @Cached GetClassNode getVClass,
- @Cached GetCachedTpSlotsNode getVSlots,
- @Cached GetCachedTpSlotsNode getWSlots,
- @Cached GetClassNode getWClass,
- @Cached CallBinaryOp1Node callBinaryOp1Node,
- @Cached PRaiseNode raiseNode) {
- Object classV = getVClass.execute(inliningTarget, v);
- Object classW = getWClass.execute(inliningTarget, w);
- TpSlot slotV = getVSlots.execute(inliningTarget, classV).nb_xor();
- TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_xor();
- if (slotV != null || slotW != null) {
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_XOR);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- return raiseNotSupported(inliningTarget, v, w, raiseNode);
- }
-
- @InliningCutoff
- private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, PRaiseNode raiseNode) {
- return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "^", v, w);
+ @Cached CallBinaryOpNode callBinaryOpNode) {
+ return callBinaryOpNode.execute(frame, inliningTarget, v, w, ReversibleSlot.NB_XOR, "^");
}
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
index 14c8941b9d..9b77279aa3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
@@ -51,7 +51,6 @@
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -129,15 +128,11 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
if (pySeqCheckV.execute(inliningTarget, v) && pySeqCheckW.execute(inliningTarget, w)) {
Object classW = getWClass.execute(inliningTarget, w);
TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
- TpSlot slotV = slotsV.nb_add();
- TpSlot slotW = slotsW.nb_add();
- if (slotV != null || slotW != null) {
- hasNbAddSlot.enter(inliningTarget);
- Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, ReversibleSlot.NB_ADD);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- hasNbAddResult.enter(inliningTarget);
- return result;
- }
+ hasNbAddSlot.enter(inliningTarget);
+ Object result = callBinaryOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, ReversibleSlot.NB_ADD);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbAddResult.enter(inliningTarget);
+ return result;
}
}
return raiseNotSupported(inliningTarget, v, raiseNode);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index 925af3cb16..767247dc68 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -109,9 +109,32 @@
import com.oracle.graal.python.compiler.QuickeningTypes;
import com.oracle.graal.python.compiler.RaisePythonExceptionErrorCallback;
import com.oracle.graal.python.compiler.UnaryOpsConstants;
+import com.oracle.graal.python.lib.PyNumberAddNode;
+import com.oracle.graal.python.lib.PyNumberAndNode;
+import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInplaceAndNode;
+import com.oracle.graal.python.lib.PyNumberInplaceFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInplaceLshiftNode;
+import com.oracle.graal.python.lib.PyNumberInplaceMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInplaceOrNode;
+import com.oracle.graal.python.lib.PyNumberInplaceRemainderNode;
+import com.oracle.graal.python.lib.PyNumberInplaceRshiftNode;
+import com.oracle.graal.python.lib.PyNumberInplaceSubtractNode;
+import com.oracle.graal.python.lib.PyNumberInplaceTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberInplaceXorNode;
import com.oracle.graal.python.lib.PyNumberInvertNode;
+import com.oracle.graal.python.lib.PyNumberLshiftNode;
+import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyNumberNegativeNode;
+import com.oracle.graal.python.lib.PyNumberOrNode;
import com.oracle.graal.python.lib.PyNumberPositiveNode;
+import com.oracle.graal.python.lib.PyNumberPowerNode;
+import com.oracle.graal.python.lib.PyNumberRemainderNode;
+import com.oracle.graal.python.lib.PyNumberRshiftNode;
+import com.oracle.graal.python.lib.PyNumberSubtractNode;
+import com.oracle.graal.python.lib.PyNumberTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberXorNode;
import com.oracle.graal.python.lib.PyObjectAsciiNode;
import com.oracle.graal.python.lib.PyObjectAsciiNodeGen;
import com.oracle.graal.python.lib.PyObjectDelItem;
@@ -167,7 +190,6 @@
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNodeGen;
import com.oracle.graal.python.nodes.exception.ExceptMatchNode;
import com.oracle.graal.python.nodes.exception.ExceptMatchNodeGen;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
import com.oracle.graal.python.nodes.expression.BinaryOp;
import com.oracle.graal.python.nodes.expression.ContainsNode;
@@ -413,57 +435,57 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
private static final IntNodeFunction BINARY_OP_FACTORY = (int op) -> {
switch (op) {
case BinaryOpsConstants.ADD:
- return BinaryArithmetic.Add.create();
+ return PyNumberAddNode.create();
case BinaryOpsConstants.SUB:
- return BinaryArithmetic.Sub.create();
+ return PyNumberSubtractNode.create();
case BinaryOpsConstants.MUL:
- return BinaryArithmetic.Mul.create();
+ return PyNumberMultiplyNode.create();
case BinaryOpsConstants.TRUEDIV:
- return BinaryArithmetic.TrueDiv.create();
+ return PyNumberTrueDivideNode.create();
case BinaryOpsConstants.FLOORDIV:
- return BinaryArithmetic.FloorDiv.create();
+ return PyNumberFloorDivideNode.create();
case BinaryOpsConstants.MOD:
- return BinaryArithmetic.Mod.create();
+ return PyNumberRemainderNode.create();
case BinaryOpsConstants.LSHIFT:
- return BinaryArithmetic.LShift.create();
+ return PyNumberLshiftNode.create();
case BinaryOpsConstants.RSHIFT:
- return BinaryArithmetic.RShift.create();
+ return PyNumberRshiftNode.create();
case BinaryOpsConstants.AND:
- return BinaryArithmetic.And.create();
+ return PyNumberAndNode.create();
case BinaryOpsConstants.OR:
- return BinaryArithmetic.Or.create();
+ return PyNumberOrNode.create();
case BinaryOpsConstants.XOR:
- return BinaryArithmetic.Xor.create();
+ return PyNumberXorNode.create();
case BinaryOpsConstants.POW:
- return BinaryArithmetic.Pow.create();
+ return PyNumberPowerNode.create();
case BinaryOpsConstants.MATMUL:
- return BinaryArithmetic.MatMul.create();
+ return PyNumberMatrixMultiplyNode.create();
case BinaryOpsConstants.INPLACE_ADD:
return InplaceArithmetic.IAdd.create();
case BinaryOpsConstants.INPLACE_SUB:
- return InplaceArithmetic.ISub.create();
+ return PyNumberInplaceSubtractNode.create();
case BinaryOpsConstants.INPLACE_MUL:
return InplaceArithmetic.IMul.create();
case BinaryOpsConstants.INPLACE_TRUEDIV:
- return InplaceArithmetic.ITrueDiv.create();
+ return PyNumberInplaceTrueDivideNode.create();
case BinaryOpsConstants.INPLACE_FLOORDIV:
- return InplaceArithmetic.IFloorDiv.create();
+ return PyNumberInplaceFloorDivideNode.create();
case BinaryOpsConstants.INPLACE_MOD:
- return InplaceArithmetic.IMod.create();
+ return PyNumberInplaceRemainderNode.create();
case BinaryOpsConstants.INPLACE_LSHIFT:
- return InplaceArithmetic.ILShift.create();
+ return PyNumberInplaceLshiftNode.create();
case BinaryOpsConstants.INPLACE_RSHIFT:
- return InplaceArithmetic.IRShift.create();
+ return PyNumberInplaceRshiftNode.create();
case BinaryOpsConstants.INPLACE_AND:
- return InplaceArithmetic.IAnd.create();
+ return PyNumberInplaceAndNode.create();
case BinaryOpsConstants.INPLACE_OR:
- return InplaceArithmetic.IOr.create();
+ return PyNumberInplaceOrNode.create();
case BinaryOpsConstants.INPLACE_XOR:
- return InplaceArithmetic.IXor.create();
+ return PyNumberInplaceXorNode.create();
case BinaryOpsConstants.INPLACE_POW:
return InplaceArithmetic.IPow.create();
case BinaryOpsConstants.INPLACE_MATMUL:
- return InplaceArithmetic.IMatMul.create();
+ return PyNumberInplaceMatrixMultiplyNode.create();
case BinaryOpsConstants.EQ:
return BinaryComparisonNode.EqNode.create();
case BinaryOpsConstants.NE:
@@ -3849,7 +3871,7 @@ private void bytecodeBinaryOpOOO(VirtualFrame virtualFrame, int stackTop, int bc
left = virtualFrame.getValue(stackTop - 1);
}
virtualFrame.setObject(stackTop, null);
- Object result = opNode.executeObject(virtualFrame, left, right);
+ Object result = opNode.execute(virtualFrame, left, right);
virtualFrame.setObject(stackTop - 1, result);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
index 7de2eb29de..e73fcb5874 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
@@ -134,7 +134,7 @@ protected Object doCall(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
callBinaryNode = insert(binaryOperator.create());
}
- return callBinaryNode.executeObject(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1));
+ return callBinaryNode.execute(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1));
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOp.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOp.java
index de1eb5746b..4dce665264 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOp.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOp.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,5 +43,5 @@
import com.oracle.truffle.api.frame.VirtualFrame;
public interface BinaryOp {
- Object executeObject(VirtualFrame frame, Object left, Object right);
+ Object execute(VirtualFrame frame, Object left, Object right);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOpNode.java
index f0b51431bd..86039e7a50 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOpNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryOpNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -30,5 +30,5 @@
public abstract class BinaryOpNode extends PNodeWithContext implements BinaryOp {
@Override
- public abstract Object executeObject(VirtualFrame frame, Object left, Object right);
+ public abstract Object execute(VirtualFrame frame, Object left, Object right);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
index 5753161223..098bf33c3d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -104,10 +104,6 @@ private LookupAndCallTernaryNode ensureLookupAndCallTernaryNode() {
}
@Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
- return execute(frame, left, right);
- }
-
public final Object execute(VirtualFrame frame, Object left, Object right) {
return executeTernary(frame, left, right, PNone.NO_VALUE);
}
@@ -142,7 +138,7 @@ Object doBinary(VirtualFrame frame, Object left, Object right, Object z,
// try non-inplace variant
boolean isBinary = PGuards.isPNone(z);
if (isBinary) {
- result = ensureLookupAndCallBinaryNode().executeObject(frame, left, right);
+ result = ensureLookupAndCallBinaryNode().execute(frame, left, right);
} else {
result = ensureLookupAndCallTernaryNode().execute(frame, left, right, z);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsNode.java
index fb5dd6d72e..ce311acf65 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -87,7 +87,7 @@ public abstract class IsNode extends Node implements BinaryOp {
protected abstract boolean executeInternal(boolean left, Object right);
@Override
- public final Object executeObject(VirtualFrame frame, Object left, Object right) {
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
return execute(left, right);
}
From d83de55c8322922fc3fea4bcebfe9eb1608c300d Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Fri, 14 Feb 2025 11:13:30 +0100
Subject: [PATCH 020/512] Implement sq_inplace_concat and nb_inplace_add slots
---
.../oracle/graal/python/annotations/Slot.java | 2 +
.../graal/python/processor/SlotsMapping.java | 14 ++-
.../src/tests/cpyext/test_tp_slots.py | 99 ++++++++++++++-
.../modules/OperatorModuleBuiltins.java | 12 ++
.../cext/PythonCextAbstractBuiltins.java | 23 +---
.../builtins/objects/array/ArrayBuiltins.java | 3 +-
.../objects/bytes/ByteArrayBuiltins.java | 3 +-
.../objects/cext/capi/SlotMethodDef.java | 4 -
.../objects/cext/capi/ToNativeTypeNode.java | 1 -
.../builtins/objects/deque/DequeBuiltins.java | 3 +-
.../builtins/objects/dict/DictBuiltins.java | 2 +-
.../builtins/objects/list/ListBuiltins.java | 3 +-
.../mappingproxy/MappingproxyBuiltins.java | 2 +-
.../ordereddict/OrderedDictBuiltins.java | 2 +-
.../builtins/objects/set/SetBuiltins.java | 9 +-
.../python/builtins/objects/type/TpSlots.java | 17 ++-
.../objects/type/slots/TpSlotBinaryOp.java | 54 +++------
.../python/lib/PyNumberInplaceAddNode.java | 107 ++++++++++++++++
.../python/lib/PySequenceInplaceConcat.java | 114 ++++++++++++++++++
.../nodes/bytecode/PBytecodeRootNode.java | 3 +-
20 files changed, 386 insertions(+), 91 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java
diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
index c6bbb59f74..8d0a2b14db 100644
--- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
+++ b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
@@ -171,6 +171,8 @@ enum SlotKind {
sq_concat("__add__"),
/** seq * number, nb_multiply is tried before */
sq_repeat("__mul__"),
+ /** seq += seq */
+ sq_inplace_concat("__iadd__"),
/** mapping length */
mp_length("__len__"),
/** mapping subscript, e.g. o[key], o[i:j] */
diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
index 5e2c1b93e7..2061b0b798 100644
--- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
+++ b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
@@ -58,7 +58,8 @@ static String getSlotBaseClass(Slot s) {
"TpSlotBinaryOp.TpSlotBinaryOpBuiltin";
case nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
- nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply ->
+ nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply,
+ sq_inplace_concat ->
"TpSlotBinaryOp.TpSlotBinaryIOpBuiltin";
case nb_power -> "TpSlotNbPower.TpSlotNbPowerBuiltin";
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
@@ -80,13 +81,15 @@ static String getSlotNodeBaseClass(Slot s) {
case nb_bool -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.NbBoolBuiltinNode";
case nb_index, nb_int, nb_float, nb_absolute, nb_positive, nb_negative, nb_invert -> "com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode";
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
- nb_floor_divide, nb_true_divide, nb_matrix_multiply,
- nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
- nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
- nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply ->
+ nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
"com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
case nb_power -> "com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode";
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
+ case nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
+ nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
+ nb_inplace_floor_divide, nb_inplace_true_divide, nb_inplace_matrix_multiply,
+ sq_inplace_concat ->
+ "com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode";
case sq_length, mp_length -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode";
case sq_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode";
case sq_ass_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.SqAssItemBuiltinNode";
@@ -165,6 +168,7 @@ public static String getExtraCtorArgs(TpSlotData slot) {
case nb_inplace_floor_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IFLOORDIV__";
case nb_inplace_true_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ITRUEDIV__";
case nb_inplace_matrix_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMATMUL__";
+ case sq_inplace_concat -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__";
default -> "";
};
}
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index 8ffd21fcb6..ba4e70da6d 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -293,14 +293,14 @@ def test_concat_vs_add():
x = SqAdd()
assert x + x is x
- # TODO: assert _operator.concat(x, x) is x when _operator.concat is implemented
+ assert operator.concat(x, x) is x
assert x.__add__(x) is x
class SqAddManaged(SqAdd): pass
x = SqAddManaged()
assert x + x is x
assert x.__add__(x) is x
- # TODO: assert _operator.concat(x, x) is x when _operator.concat is implemented
+ assert operator.concat(x, x) is x
SqAddAndNbAdd = CPyExtHeapType("SqAddAndNbAdd",
slots= [
@@ -314,7 +314,100 @@ class SqAddManaged(SqAdd): pass
x = SqAddAndNbAdd()
y = SqAddAndNbAdd()
assert x + y is y
- # TODO: assert _operator.concat(x, x) is x when _operator.concat is implemented
+ assert operator.concat(x, y) is x
+
+ SqAddAndNbAddNoImplemented = CPyExtHeapType("SqAddAndNbAddNoImplemented",
+ slots= [
+ '{Py_sq_concat, &concat}',
+ '{Py_nb_add, &myadd}',
+ ],
+ code=
+ 'PyObject* concat(PyObject* a, PyObject *b) { Py_INCREF(a); return a; }' +
+ 'PyObject* myadd(PyObject* a, PyObject *b) { Py_RETURN_NOTIMPLEMENTED; }')
+ x = SqAddAndNbAddNoImplemented()
+ assert x + 1 is x
+
+
+def test_sq_inplace_concat_vs_nb_inplace_add():
+ SqInplaceConcat = CPyExtHeapType(
+ "SqInplaceConcat",
+ slots=['{Py_sq_inplace_concat, &inplace_concat}'],
+ code='PyObject* inplace_concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_concat"); }',
+ )
+ x = SqInplaceConcat()
+ x += 1
+ assert x == "inplace_concat"
+ x = SqInplaceConcat()
+ assert operator.iconcat(x, []) == "inplace_concat"
+
+ SqInplaceConcatAndNbInplaceAdd = CPyExtHeapType(
+ "SqInplaceConcatAndNbInplaceAdd",
+ slots=['{Py_sq_inplace_concat, &inplace_concat}', '{Py_nb_inplace_add, &inplace_add}'],
+ code='''
+ PyObject* inplace_concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_concat"); }
+ PyObject* inplace_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_add"); }
+ ''',
+ )
+
+ x = SqInplaceConcatAndNbInplaceAdd()
+ x += 1
+ assert x == "inplace_add"
+ x = SqInplaceConcatAndNbInplaceAdd()
+ assert operator.iconcat(x, 1) == "inplace_concat"
+
+ SqInplaceConcatAndNbInplaceAddNotImplemented = CPyExtHeapType(
+ "InplaceConcatAddNotImpl",
+ slots=['{Py_sq_inplace_concat, &inplace_concat}', '{Py_nb_inplace_add, &inplace_add}'],
+ code='''
+ PyObject* inplace_concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_concat"); }
+ PyObject* inplace_add(PyObject* a, PyObject *b) { Py_RETURN_NOTIMPLEMENTED; }
+ ''',
+ )
+
+ x = SqInplaceConcatAndNbInplaceAddNotImplemented()
+ x += 1
+ assert x == "inplace_concat"
+
+ class InplaceConcatSubclass(SqInplaceConcat):
+ pass
+
+ x = InplaceConcatSubclass()
+ assert operator.iconcat(x, 1) == "inplace_concat"
+
+ SqConcat = CPyExtHeapType(
+ "SqConcat",
+ slots=['{Py_sq_concat, &concat}'],
+ code='PyObject* concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("concat"); }',
+ )
+
+ x = SqConcat()
+ x += 1
+ assert x == "concat"
+ x = SqConcat()
+ assert operator.iconcat(x, 1) == "concat"
+
+ NbInplaceAdd = CPyExtHeapType(
+ "NbInplaceAdd",
+ slots=['{Py_nb_inplace_add, &inplace_add}'],
+ code='PyObject* inplace_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_add"); }',
+ )
+
+ x = NbInplaceAdd()
+ assert_raises(TypeError, operator.iconcat, x, 1)
+ assert_raises(TypeError, operator.iconcat, x, [])
+
+ SequenceWithNbInplaceAdd = CPyExtHeapType(
+ "SequenceWithNbInplaceAdd",
+ slots=['{Py_nb_inplace_add, &inplace_add}', '{Py_sq_item, &item}'],
+ code='''
+ PyObject* inplace_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_add"); }
+ PyObject* item(PyObject* a, PyObject *b) { return PyUnicode_FromString("item"); }
+ ''',
+ )
+
+ x = SequenceWithNbInplaceAdd()
+ assert_raises(TypeError, operator.iconcat, x, 1)
+ assert operator.iconcat(x, []) == "inplace_add"
def test_incompatible_slots_assignment():
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
index d4ac204674..cb467297d7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
@@ -55,6 +55,7 @@
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.lib.PySequenceConcat;
+import com.oracle.graal.python.lib.PySequenceInplaceConcat;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -118,6 +119,17 @@ static Object doObject(VirtualFrame frame, Object left, Object right,
}
}
+ @Builtin(name = "iconcat", minNumOfPositionalArgs = 2)
+ @GenerateNodeFactory
+ abstract static class IConcatNode extends PythonBinaryBuiltinNode {
+ @Specialization
+ static Object doObject(VirtualFrame frame, Object left, Object right,
+ @Bind("this") Node inliningTarget,
+ @Cached PySequenceInplaceConcat concatNode) {
+ return concatNode.execute(frame, inliningTarget, left, right);
+ }
+ }
+
@Builtin(name = "mul", minNumOfPositionalArgs = 2)
@GenerateNodeFactory
abstract static class MulNode extends PythonBinaryBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 0ccaff8da1..b4e924537c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -59,7 +59,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_KEYS;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_VALUES;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -102,7 +101,6 @@
import com.oracle.graal.python.lib.GetNextNode;
import com.oracle.graal.python.lib.PyIndexCheckNode;
import com.oracle.graal.python.lib.PyIterCheckNode;
-import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
import com.oracle.graal.python.lib.PyNumberFloatNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
@@ -118,6 +116,7 @@
import com.oracle.graal.python.lib.PySequenceContainsNode;
import com.oracle.graal.python.lib.PySequenceDelItemNode;
import com.oracle.graal.python.lib.PySequenceGetItemNode;
+import com.oracle.graal.python.lib.PySequenceInplaceConcat;
import com.oracle.graal.python.lib.PySequenceIterSearchNode;
import com.oracle.graal.python.lib.PySequenceSetItemNode;
import com.oracle.graal.python.lib.PySequenceSizeNode;
@@ -572,25 +571,11 @@ Object doIt(Object s1, Object s2,
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
abstract static class PySequence_InPlaceConcat extends CApiBinaryBuiltinNode {
- @Specialization(guards = {"checkNode.execute(inliningTarget, s1)"}, limit = "1")
+ @Specialization
static Object concat(Object s1, Object s2,
@Bind("this") Node inliningTarget,
- @Cached PyObjectLookupAttr lookupNode,
- @Cached CallNode callNode,
- @Cached PyNumberAddNode addNode,
- @SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode) {
- Object iaddCallable = lookupNode.execute(null, inliningTarget, s1, T___IADD__);
- if (iaddCallable != PNone.NO_VALUE) {
- return callNode.executeWithoutFrame(iaddCallable, s2);
- }
- return addNode.execute(null, inliningTarget, s1, s2);
- }
-
- @Specialization(guards = "!checkNode.execute(inliningTarget, s1)", limit = "1")
- static Object concat(Object s1, @SuppressWarnings("unused") Object s2,
- @SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode,
- @Bind("this") Node inliningTarget) {
- throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, s1);
+ @Cached PySequenceInplaceConcat concat) {
+ return concat.execute(null, inliningTarget, s1, s2);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
index fe7c0fcdff..d2c9a7b11a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
@@ -44,7 +44,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
@@ -206,7 +205,7 @@ static Object error(@SuppressWarnings("unused") Object left, Object right,
}
}
- @Builtin(name = J___IADD__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_concat, isComplex = true)
@GenerateNodeFactory
abstract static class IAddNode extends PythonBinaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
index c48cd23418..1ae2c8c094 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
@@ -33,7 +33,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
@@ -426,7 +425,7 @@ static Object repr(PByteArray self,
}
}
- @Builtin(name = J___IADD__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_concat, isComplex = true)
@GenerateNodeFactory
public abstract static class IAddNode extends PythonBinaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
index 96624251a1..4db8393b60 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
@@ -43,7 +43,6 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_aiter;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_anext;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_await;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_add;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_multiply;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_power;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_as_number;
@@ -60,7 +59,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AWAIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
@@ -98,7 +96,6 @@ public enum SlotMethodDef {
// (mq) AM_SEND is an internal function and mostly called from within AWAIT, AITER, ANEXT.
/*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, CallFunctionWrapper::new, MethodsFlags.AM_SEND), */
- NB_INPLACE_ADD(PyNumberMethods__nb_inplace_add, T___IADD__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_ADD),
NB_INPLACE_MULTIPLY(PyNumberMethods__nb_inplace_multiply, T___IMUL__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_MULTIPLY),
NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER);
@@ -133,7 +130,6 @@ public enum SlotMethodDef {
static {
initGroup(
PyTypeObject__tp_as_number,
- NB_INPLACE_ADD,
NB_INPLACE_MULTIPLY,
NB_INPLACE_POWER);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index c56444436b..c5b136e96c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -151,7 +151,6 @@ private static Object allocatePyNumberMethods(PythonManagedClass obj, TpSlots sl
writeGroupSlots(CFields.PyTypeObject__tp_as_number, slots, writePointerNode, mem, nullValue);
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_add, getSlot(obj, SlotMethodDef.NB_INPLACE_ADD));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_multiply, getSlot(obj, SlotMethodDef.NB_INPLACE_MULTIPLY));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_power, getSlot(obj, SlotMethodDef.NB_INPLACE_POWER));
return mem;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
index 2715e62fde..740e3763a4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
@@ -57,7 +57,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
@@ -674,7 +673,7 @@ static int doGeneric(PDeque self) {
}
// deque.__iadd__(v)
- @Builtin(name = J___IADD__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_concat, isComplex = true)
@GenerateNodeFactory
public abstract static class DequeInplaceAddNode extends PythonBinaryBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
index f5c7fcd4ae..dea70bcd88 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java
@@ -625,7 +625,7 @@ static Object or(Object self, Object other) {
@Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends BinaryOpBuiltinNode {
+ abstract static class IOrNode extends PythonBinaryBuiltinNode {
@Specialization
Object or(VirtualFrame frame, Object self, Object other,
@Cached DictNodes.UpdateNode updateNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
index f3916c4527..604a1f8a3f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
@@ -33,7 +33,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
@@ -772,7 +771,7 @@ protected static SequenceStorageNodes.ConcatNode createConcat() {
}
}
- @Builtin(name = J___IADD__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_concat, isComplex = true)
@GenerateNodeFactory
abstract static class IAddNode extends PythonBinaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
index 2a2c2c902a..f4e552d8d0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
@@ -283,7 +283,7 @@ Object or(VirtualFrame frame, Object self, Object other) {
@Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends BinaryOpBuiltinNode {
+ abstract static class IOrNode extends PythonBinaryBuiltinNode {
@Specialization
static Object or(Object self, @SuppressWarnings("unused") Object other,
@Bind("this") Node inliningTarget) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
index 4608ea7a72..ca6ad00107 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ordereddict/OrderedDictBuiltins.java
@@ -272,7 +272,7 @@ static Object or(Object self, Object other) {
@Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- abstract static class IOrNode extends BinaryOpBuiltinNode {
+ abstract static class IOrNode extends PythonBinaryBuiltinNode {
@Specialization
static Object or(VirtualFrame frame, POrderedDict self, Object other,
@Bind("this") Node inliningTarget,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
index 87287d8c35..fa4f679213 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java
@@ -60,7 +60,6 @@
import com.oracle.graal.python.builtins.objects.dict.PDictView;
import com.oracle.graal.python.builtins.objects.str.PString;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.lib.GetNextNode;
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -185,7 +184,7 @@ public static Object add(VirtualFrame frame, PSet self, Object o,
@Slot(value = SlotKind.nb_inplace_or, isComplex = true)
@GenerateNodeFactory
- public abstract static class IOrNode extends BinaryOpBuiltinNode {
+ public abstract static class IOrNode extends PythonBinaryBuiltinNode {
@Specialization
Object doSet(VirtualFrame frame, PSet self, PBaseSet other,
@Bind("this") Node inliningTarget,
@@ -373,7 +372,7 @@ static PNone doSet(VirtualFrame frame, PSet self, Object other,
@Slot(value = SlotKind.nb_inplace_and, isComplex = true)
@GenerateNodeFactory
- public abstract static class IAndNode extends BinaryOpBuiltinNode {
+ public abstract static class IAndNode extends PythonBinaryBuiltinNode {
@Specialization
static PBaseSet doPBaseSet(VirtualFrame frame, PSet left, PBaseSet right,
@@ -474,7 +473,7 @@ protected Object createResult(PSet self, HashingStorage result) {
@Slot(value = SlotKind.nb_inplace_xor, isComplex = true)
@GenerateNodeFactory
- public abstract static class IXorNode extends BinaryOpBuiltinNode {
+ public abstract static class IXorNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doSet(VirtualFrame frame, PSet self, PBaseSet other,
@@ -560,7 +559,7 @@ static PNone doSetOther(VirtualFrame frame, PSet self, Object other,
@Slot(value = SlotKind.nb_inplace_subtract, isComplex = true)
@GenerateNodeFactory
- abstract static class ISubNode extends BinaryOpBuiltinNode {
+ abstract static class ISubNode extends PythonBinaryBuiltinNode {
@Specialization
static PBaseSet doPBaseSet(VirtualFrame frame, PSet left, PBaseSet right,
@Bind("this") Node inliningTarget,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index dc54a17acb..766168d131 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -60,7 +60,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INDEX__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INVERT__;
@@ -293,6 +292,7 @@ public record TpSlots(TpSlot nb_bool, //
TpSlot sq_ass_item, //
TpSlot sq_concat, //
TpSlot sq_repeat, //
+ TpSlot sq_inplace_concat, //
TpSlot mp_length, //
TpSlot mp_subscript, //
TpSlot mp_ass_subscript, //
@@ -698,6 +698,14 @@ public enum TpSlotMeta {
CFields.PySequenceMethods__sq_repeat,
PExternalFunctionWrapper.SSIZE_ARG,
SsizeargfuncSlotWrapper::new),
+ SQ_INPLACE_CONCAT(
+ TpSlots::sq_inplace_concat,
+ TpSlotPythonSingle.class,
+ TpSlotBinaryIOpBuiltin.class,
+ TpSlotGroup.AS_SEQUENCE,
+ CFields.PySequenceMethods__sq_inplace_concat,
+ PExternalFunctionWrapper.BINARYFUNC,
+ BinarySlotFuncWrapper::new),
MP_LENGTH(
TpSlots::mp_length,
TpSlotPythonSingle.class,
@@ -991,9 +999,10 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
addSlotDef(s, TpSlotMeta.NB_POWER,
TpSlotDef.withoutHPy(T___POW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC),
TpSlotDef.withoutHPy(T___RPOW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC_R));
- // addSlotDef(s, TpSlotMeta.NB_INPLACE_ADD, TpSlotDef.withSimpleFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_ADD, TpSlotDef.withSimpleFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_SUBTRACT, TpSlotDef.withSimpleFunction(T___ISUB__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
- // addSlotDef(s, TpSlotMeta.NB_INPLACE_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMUL__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ // addSlotDef(s, TpSlotMeta.NB_INPLACE_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMUL__,
+ // PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_REMAINDER, TpSlotDef.withSimpleFunction(T___IMOD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_LSHIFT, TpSlotDef.withSimpleFunction(T___ILSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_RSHIFT, TpSlotDef.withSimpleFunction(T___IRSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
@@ -1029,6 +1038,7 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
addSlotDef(s, TpSlotMeta.SQ_ASS_ITEM,
TpSlotDef.withoutHPy(T___SETITEM__, TpSlotSqAssItemPython::create, PExternalFunctionWrapper.SETITEM),
TpSlotDef.withoutHPy(T___DELITEM__, TpSlotSqAssItemPython::create, PExternalFunctionWrapper.DELITEM));
+ addSlotDef(s, TpSlotMeta.SQ_INPLACE_CONCAT, TpSlotDef.withNoFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC));
SLOTDEFS = s;
SPECIAL2SLOT = new HashMap<>(SLOTDEFS.size() * 2);
@@ -1640,6 +1650,7 @@ public TpSlots build() {
get(TpSlotMeta.SQ_ASS_ITEM), //
get(TpSlotMeta.SQ_CONCAT), //
get(TpSlotMeta.SQ_REPEAT), //
+ get(TpSlotMeta.SQ_INPLACE_CONCAT), //
get(TpSlotMeta.MP_LENGTH), //
get(TpSlotMeta.MP_SUBSCRIPT), //
get(TpSlotMeta.MP_ASS_SUBSCRIPT), //
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
index b8189ba239..fb7fbfb542 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java
@@ -44,18 +44,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AND__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DIVMOD__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___FLOORDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IFLOORDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___LSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MATMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MOD__;
@@ -196,25 +184,22 @@ public static ReversibleSlot fromCallableNames(TruffleString[] names) {
}
public enum InplaceSlot {
- NB_INPLACE_ADD(T___IADD__, ReversibleSlot.NB_ADD),
- NB_INPLACE_SUBTRACT(T___ISUB__, ReversibleSlot.NB_SUBTRACT),
- NB_INPLACE_MULTIPLY(T___IMUL__, ReversibleSlot.NB_MULTIPLY),
- NB_INPLACE_REMAINDER(T___IMOD__, ReversibleSlot.NB_REMAINDER),
- NB_INPLACE_LSHIFT(T___ILSHIFT__, ReversibleSlot.NB_LSHIFT),
- NB_INPLACE_RSHIFT(T___IRSHIFT__, ReversibleSlot.NB_RSHIFT),
- NB_INPLACE_AND(T___IAND__, ReversibleSlot.NB_AND),
- NB_INPLACE_XOR(T___IXOR__, ReversibleSlot.NB_XOR),
- NB_INPLACE_OR(T___IOR__, ReversibleSlot.NB_OR),
- NB_INPLACE_FLOOR_DIVIDE(T___IFLOORDIV__, ReversibleSlot.NB_FLOOR_DIVIDE),
- NB_INPLACE_TRUE_DIVIDE(T___ITRUEDIV__, ReversibleSlot.NB_TRUE_DIVIDE),
- NB_INPLACE_MATRIX_MULTIPLY(T___IMATMUL__, ReversibleSlot.NB_MATRIX_MULTIPLY);
-
- private static final InplaceSlot[] VALUES = values();
- private final TruffleString name;
+ NB_INPLACE_ADD(ReversibleSlot.NB_ADD),
+ NB_INPLACE_SUBTRACT(ReversibleSlot.NB_SUBTRACT),
+ NB_INPLACE_MULTIPLY(ReversibleSlot.NB_MULTIPLY),
+ NB_INPLACE_REMAINDER(ReversibleSlot.NB_REMAINDER),
+ NB_INPLACE_LSHIFT(ReversibleSlot.NB_LSHIFT),
+ NB_INPLACE_RSHIFT(ReversibleSlot.NB_RSHIFT),
+ NB_INPLACE_AND(ReversibleSlot.NB_AND),
+ NB_INPLACE_XOR(ReversibleSlot.NB_XOR),
+ NB_INPLACE_OR(ReversibleSlot.NB_OR),
+ NB_INPLACE_FLOOR_DIVIDE(ReversibleSlot.NB_FLOOR_DIVIDE),
+ NB_INPLACE_TRUE_DIVIDE(ReversibleSlot.NB_TRUE_DIVIDE),
+ NB_INPLACE_MATRIX_MULTIPLY(ReversibleSlot.NB_MATRIX_MULTIPLY);
+
private final ReversibleSlot reversibleSlot;
- InplaceSlot(TruffleString name, ReversibleSlot reversibleSlot) {
- this.name = name;
+ InplaceSlot(ReversibleSlot reversibleSlot) {
this.reversibleSlot = reversibleSlot;
}
@@ -236,15 +221,6 @@ public TpSlot getSlotValue(TpSlots slots) {
};
}
- public static InplaceSlot fromCallableNames(TruffleString[] names) {
- for (InplaceSlot op : VALUES) {
- if (names[0].equals(op.name)) {
- return op;
- }
- }
- return null;
- }
-
public ReversibleSlot getReversibleSlot() {
return reversibleSlot;
}
@@ -284,7 +260,7 @@ private PBuiltinFunction createRBuiltin(Python3Core core, Object type, TruffleSt
}
}
- public abstract static class TpSlotBinaryIOpBuiltin extends TpSlotBinaryFuncBuiltin {
+ public abstract static class TpSlotBinaryIOpBuiltin extends TpSlotBinaryFuncBuiltin {
protected TpSlotBinaryIOpBuiltin(NodeFactory nodeFactory, String builtinName) {
super(nodeFactory, PExternalFunctionWrapper.BINARYFUNC, builtinName);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java
new file mode 100644
index 0000000000..3e0798ba8e
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
+
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Cached.Exclusive;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceAddNode extends PyNumberAddBaseNode {
+
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Exclusive @Cached GetClassNode getVClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Exclusive @Cached GetClassNode getWClass,
+ @Cached CallBinaryIOp1Node callBinaryIOp1Node,
+ @Cached InlinedBranchProfile hasNbAddResult,
+ @Cached InlinedBranchProfile hasInplaceConcat,
+ @Cached InlinedBranchProfile hasConcat,
+ @Cached CallSlotBinaryFuncNode callBinarySlotNode,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ Object result = callBinaryIOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, InplaceSlot.NB_INPLACE_ADD);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbAddResult.enter(inliningTarget);
+ return result;
+ }
+ TpSlot concatSlot;
+ if (slotsV.sq_inplace_concat() != null) {
+ hasInplaceConcat.enter(inliningTarget);
+ concatSlot = slotsV.sq_inplace_concat();
+ } else if (slotsV.sq_concat() != null) {
+ hasConcat.enter(inliningTarget);
+ concatSlot = slotsV.sq_concat();
+ } else {
+ return raiseNotSupported(inliningTarget, v, w, "+=", raiseNode);
+ }
+ return callBinarySlotNode.execute(frame, inliningTarget, concatSlot, v, w);
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceAddNode create() {
+ return PyNumberInplaceAddNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java
new file mode 100644
index 0000000000..f7bde9967f
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PNodeWithContext;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+
+@GenerateInline
+@GenerateCached(false)
+public abstract class PySequenceInplaceConcat extends PNodeWithContext {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
+ @Cached GetClassNode getVClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Cached GetClassNode getWClass,
+ @Cached PySequenceCheckNode pySeqCheckV,
+ @Cached PySequenceCheckNode pySeqCheckW,
+ @Cached CallBinaryIOp1Node callBinaryIOp1Node,
+ @Cached InlinedBranchProfile hasInplaceConcat,
+ @Cached InlinedBranchProfile hasConcat,
+ @Cached InlinedBranchProfile hasNbAddSlot,
+ @Cached InlinedBranchProfile hasNbAddResult,
+ @Cached CallSlotBinaryFuncNode callBinarySlotNode,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlot concatSlot = null;
+ if (slotsV.sq_inplace_concat() != null) {
+ hasInplaceConcat.enter(inliningTarget);
+ concatSlot = slotsV.sq_inplace_concat();
+ } else if (slotsV.sq_concat() != null) {
+ hasConcat.enter(inliningTarget);
+ concatSlot = slotsV.sq_concat();
+ }
+ if (concatSlot != null) {
+ return callBinarySlotNode.execute(frame, inliningTarget, concatSlot, v, w);
+ }
+ if (pySeqCheckV.execute(inliningTarget, v) && pySeqCheckW.execute(inliningTarget, w)) {
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ hasNbAddSlot.enter(inliningTarget);
+ Object result = callBinaryIOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, InplaceSlot.NB_INPLACE_ADD);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbAddResult.enter(inliningTarget);
+ return result;
+ }
+ }
+ return raiseNotSupported(inliningTarget, v, raiseNode);
+ }
+
+ @InliningCutoff
+ private static PException raiseNotSupported(Node inliningTarget, Object v, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, v);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index 767247dc68..a6c9538c47 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -112,6 +112,7 @@
import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInplaceAddNode;
import com.oracle.graal.python.lib.PyNumberInplaceAndNode;
import com.oracle.graal.python.lib.PyNumberInplaceFloorDivideNode;
import com.oracle.graal.python.lib.PyNumberInplaceLshiftNode;
@@ -461,7 +462,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
case BinaryOpsConstants.MATMUL:
return PyNumberMatrixMultiplyNode.create();
case BinaryOpsConstants.INPLACE_ADD:
- return InplaceArithmetic.IAdd.create();
+ return PyNumberInplaceAddNode.create();
case BinaryOpsConstants.INPLACE_SUB:
return PyNumberInplaceSubtractNode.create();
case BinaryOpsConstants.INPLACE_MUL:
From d8d281b8e0024dcfb8ccd59a70f190f6ff88baf0 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Fri, 14 Feb 2025 16:54:01 +0100
Subject: [PATCH 021/512] Implement sq_inplace_repeat and nb_inplace_multiply
---
.../oracle/graal/python/annotations/Slot.java | 2 +
.../graal/python/processor/SlotsMapping.java | 7 +-
.../src/tests/cpyext/test_tp_slots.py | 252 ++++++++++++++++--
.../cext/PythonCextAbstractBuiltins.java | 27 +-
.../builtins/objects/array/ArrayBuiltins.java | 11 +-
.../objects/bytes/ByteArrayBuiltins.java | 29 +-
.../objects/cext/capi/SlotMethodDef.java | 5 -
.../objects/cext/capi/ToNativeTypeNode.java | 1 -
.../objects/common/SequenceStorageNodes.java | 22 --
.../builtins/objects/deque/DequeBuiltins.java | 14 +-
.../builtins/objects/list/ListBuiltins.java | 7 +-
.../python/builtins/objects/type/TpSlots.java | 15 +-
.../objects/type/slots/TpSlotSizeArgFun.java | 7 +-
.../lib/PyNumberInplaceMultiplyNode.java | 119 +++++++++
.../python/lib/PyNumberMultiplyNode.java | 34 +--
.../python/lib/PySequenceInplaceRepeat.java | 110 ++++++++
.../python/lib/SequenceRepeatHelperNode.java | 82 ++++++
.../nodes/bytecode/PBytecodeRootNode.java | 3 +-
18 files changed, 592 insertions(+), 155 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/SequenceRepeatHelperNode.java
diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
index 8d0a2b14db..dc664b5a35 100644
--- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
+++ b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
@@ -173,6 +173,8 @@ enum SlotKind {
sq_repeat("__mul__"),
/** seq += seq */
sq_inplace_concat("__iadd__"),
+ /** seq *= seq */
+ sq_inplace_repeat("__imul__"),
/** mapping length */
mp_length("__len__"),
/** mapping subscript, e.g. o[key], o[i:j] */
diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
index 2061b0b798..4b75ede981 100644
--- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
+++ b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
@@ -64,7 +64,7 @@ static String getSlotBaseClass(Slot s) {
case nb_power -> "TpSlotNbPower.TpSlotNbPowerBuiltin";
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
- case sq_item, sq_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
+ case sq_item, sq_repeat, sq_inplace_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
case sq_ass_item -> "TpSlotSqAssItem.TpSlotSqAssItemBuiltin";
case mp_subscript -> "TpSlotBinaryFunc.TpSlotMpSubscript";
case mp_ass_subscript -> "TpSlotMpAssSubscript.TpSlotMpAssSubscriptBuiltin";
@@ -93,7 +93,7 @@ static String getSlotNodeBaseClass(Slot s) {
case sq_length, mp_length -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode";
case sq_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode";
case sq_ass_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.SqAssItemBuiltinNode";
- case sq_repeat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqRepeatBuiltinNode";
+ case sq_repeat, sq_inplace_repeat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqRepeatBuiltinNode";
case mp_subscript -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode";
case mp_ass_subscript -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.MpAssSubscriptBuiltinNode";
case tp_getattro -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode";
@@ -168,7 +168,10 @@ public static String getExtraCtorArgs(TpSlotData slot) {
case nb_inplace_floor_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IFLOORDIV__";
case nb_inplace_true_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ITRUEDIV__";
case nb_inplace_matrix_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMATMUL__";
+ case sq_item -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___GETITEM__";
+ case sq_repeat -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___MUL__";
case sq_inplace_concat -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IADD__";
+ case sq_inplace_repeat -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__";
default -> "";
};
}
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index ba4e70da6d..534f2e2c4f 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -328,11 +328,51 @@ class SqAddManaged(SqAdd): pass
assert x + 1 is x
+def test_inplace_fallback():
+ WithSlot = CPyExtHeapType(
+ "NbAdd1",
+ slots=[
+ '{Py_nb_add, &nb_add}',
+ ],
+ code='''
+ PyObject* nb_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("add1"); }
+ ''',
+ )
+ WithInplaceSlot = CPyExtHeapType(
+ "NbInplaceAdd1",
+ slots=[
+ '{Py_nb_add, &nb_add}',
+ '{Py_nb_inplace_add, &nb_inplace_add}',
+ ],
+ code='''
+ PyObject* nb_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("add2"); }
+ PyObject* nb_inplace_add(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_add"); }
+ ''',
+ )
+ x = WithSlot()
+ y = WithInplaceSlot()
+ x += y
+ assert x == "add1"
+ x = WithSlot()
+ y += x
+ assert y == "inplace_add"
+ x = object()
+ y = WithInplaceSlot()
+ x += y
+ assert x == "add2"
+
+
def test_sq_inplace_concat_vs_nb_inplace_add():
SqInplaceConcat = CPyExtHeapType(
"SqInplaceConcat",
- slots=['{Py_sq_inplace_concat, &inplace_concat}'],
- code='PyObject* inplace_concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_concat"); }',
+ slots=[
+ '{Py_sq_concat, &concat}',
+ '{Py_sq_inplace_concat, &inplace_concat}',
+ ],
+ code='''
+ PyObject* concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("concat"); }
+ PyObject* inplace_concat(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_concat"); }
+ ''',
)
x = SqInplaceConcat()
x += 1
@@ -409,6 +449,179 @@ class InplaceConcatSubclass(SqInplaceConcat):
assert_raises(TypeError, operator.iconcat, x, 1)
assert operator.iconcat(x, []) == "inplace_add"
+CallRepeatHelper = CPyExtType(
+ "CallRepeatHelper",
+ code='''
+ PyObject* call_repeat(PyObject* unused, PyObject* args) {
+ PyObject* obj;
+ Py_ssize_t times;
+ if (!PyArg_ParseTuple(args, "On", &obj, ×))
+ return NULL;
+ return PySequence_Repeat(obj, times);
+ }
+ PyObject* call_inplace_repeat(PyObject* unused, PyObject* args) {
+ PyObject* obj;
+ Py_ssize_t times;
+ if (!PyArg_ParseTuple(args, "On", &obj, ×))
+ return NULL;
+ return PySequence_InPlaceRepeat(obj, times);
+ }
+ ''',
+ tp_methods='''
+ {"PySequence_Repeat", (PyCFunction)call_repeat, METH_VARARGS | METH_STATIC, ""},
+ {"PySequence_InPlaceRepeat", (PyCFunction)call_inplace_repeat, METH_VARARGS | METH_STATIC, ""}
+ '''
+)
+
+
+def test_repeat_vs_multiply():
+ SqRepeat = CPyExtHeapType(
+ "SqRepeat",
+ slots=['{Py_sq_repeat, &repeat}'],
+ code='PyObject* repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("repeat"); }',
+ )
+
+ x = SqRepeat()
+ assert x * 2 == "repeat"
+ assert 2 * x == "repeat"
+ assert CallRepeatHelper.PySequence_Repeat(x, 2) == "repeat"
+ assert x.__mul__(2) == "repeat"
+ assert x.__rmul__(2) == "repeat"
+ assert_raises(TypeError, operator.mul, x, x)
+
+ class SqRepeatManaged(SqRepeat): pass
+
+ x = SqRepeatManaged()
+ assert x * 2 == "repeat"
+ assert 2 * x == "repeat"
+ assert CallRepeatHelper.PySequence_Repeat(x, 2) == "repeat"
+ assert x.__mul__(2) == "repeat"
+ assert x.__rmul__(2) == "repeat"
+ assert_raises(TypeError, operator.mul, x, x)
+
+ SqRepeatAndNbMultiply = CPyExtHeapType(
+ "SqRepeatAndNbMultiply",
+ slots=[
+ '{Py_sq_repeat, &repeat}',
+ '{Py_nb_multiply, &mymultiply}',
+ ],
+ code='''
+ PyObject* repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("repeat"); }
+ PyObject* mymultiply(PyObject* a, PyObject *b) { return PyUnicode_FromString("multiply"); }
+ ''',
+ )
+
+ x = SqRepeatAndNbMultiply()
+ assert x * 2 == "multiply"
+ assert 2 * x == "multiply"
+ assert CallRepeatHelper.PySequence_Repeat(x, 2) == "repeat"
+
+ SqRepeatAndNbMultiplyNoImplemented = CPyExtHeapType(
+ "SqRepeatAndNbMultiplyNoImplemented",
+ slots=[
+ '{Py_sq_repeat, &repeat}',
+ '{Py_nb_multiply, &mymultiply}',
+ ],
+ code='''
+ PyObject* repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("repeat"); }
+ PyObject* mymultiply(PyObject* a, PyObject *b) { Py_RETURN_NOTIMPLEMENTED; }
+ ''',
+ )
+ x = SqRepeatAndNbMultiplyNoImplemented()
+ assert x * 2 == "repeat"
+
+
+def test_sq_inplace_repeat_vs_nb_inplace_multiply():
+ SqInplaceRepeat = CPyExtHeapType(
+ "SqInplaceRepeat",
+ slots=[
+ '{Py_sq_repeat, &repeat}',
+ '{Py_sq_inplace_repeat, &inplace_repeat}'
+ ],
+ code='''
+ PyObject* repeat(PyObject* a, PyObject *b) { return PyUnicode_FromString("repeat"); }
+ PyObject* inplace_repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("inplace_repeat"); }
+ ''',
+ )
+ x = SqInplaceRepeat()
+ x *= 1
+ assert x == "inplace_repeat"
+ x = SqInplaceRepeat()
+ assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "inplace_repeat"
+
+ x = 1
+ x *= SqInplaceRepeat()
+ assert x == "repeat"
+
+ SqInplaceRepeatAndNbInplaceMultiply = CPyExtHeapType(
+ "SqInplaceRepeatAndNbInplaceMultiply",
+ slots=['{Py_sq_inplace_repeat, &inplace_repeat}', '{Py_nb_inplace_multiply, &inplace_multiply}'],
+ code='''
+ PyObject* inplace_repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("inplace_repeat"); }
+ PyObject* inplace_multiply(PyObject* a, PyObject* b) { return PyUnicode_FromString("inplace_multiply"); }
+ ''',
+ )
+
+ x = SqInplaceRepeatAndNbInplaceMultiply()
+ x *= 1
+ assert x == "inplace_multiply"
+ x = SqInplaceRepeatAndNbInplaceMultiply()
+ assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "inplace_repeat"
+
+ SqInplaceRepeatAndNbInplaceMultiplyNotImplemented = CPyExtHeapType(
+ "SqInplaceRepeatAndNbInplaceMultiplyNotImplemented",
+ slots=['{Py_sq_inplace_repeat, &inplace_repeat}', '{Py_nb_inplace_multiply, &inplace_multiply}'],
+ code='''
+ PyObject* inplace_repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("inplace_repeat"); }
+ PyObject* inplace_multiply(PyObject* a, PyObject *b) { Py_RETURN_NOTIMPLEMENTED; }
+ ''',
+ )
+
+ x = SqInplaceRepeatAndNbInplaceMultiplyNotImplemented()
+ x *= 1
+ assert x == "inplace_repeat"
+
+ class InplaceRepeatSubclass(SqInplaceRepeat):
+ pass
+
+ x = InplaceRepeatSubclass()
+ assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "inplace_repeat"
+
+ SqRepeat = CPyExtHeapType(
+ "SqRepeat2",
+ slots=['{Py_sq_repeat, &repeat}'],
+ code='PyObject* repeat(PyObject* a, PyObject *b) { return PyUnicode_FromString("repeat"); }',
+ )
+
+ x = SqRepeat()
+ x *= 1
+ assert x == "repeat"
+ x = SqRepeat()
+ assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "repeat"
+
+ NbInplaceMultiply = CPyExtHeapType(
+ "NbInplaceMultiply",
+ slots=['{Py_nb_inplace_multiply, &inplace_multiply}'],
+ code='PyObject* inplace_multiply(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_multiply"); }',
+ )
+
+ x = NbInplaceMultiply()
+ assert_raises(TypeError, CallRepeatHelper.PySequence_InPlaceRepeat, x, 1)
+ assert_raises(TypeError, CallRepeatHelper.PySequence_InPlaceRepeat, x, [])
+
+ SequenceWithNbInplaceMultiply = CPyExtHeapType(
+ "SequenceWithNbInplaceMultiply",
+ slots=['{Py_nb_inplace_multiply, &inplace_multiply}', '{Py_sq_item, &item}'],
+ code='''
+ PyObject* inplace_multiply(PyObject* a, PyObject *b) { return PyUnicode_FromString("inplace_multiply"); }
+ PyObject* item(PyObject* a, PyObject *b) { return PyUnicode_FromString("item"); }
+ ''',
+ )
+
+ x = SequenceWithNbInplaceMultiply()
+ assert_raises(TypeError, CallRepeatHelper.PySequence_InPlaceRepeat, x, [])
+ assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "inplace_multiply"
+
def test_incompatible_slots_assignment():
def assert_type_error(code):
@@ -1152,30 +1365,27 @@ def __contains__(self, item):
obj = NativeSqSlotProxy([1])
assert obj + [2] == [1, 2]
- # TODO fix on graalpy
- # obj += [2]
- # assert obj.delegate == [1, 2]
+ obj += [2]
+ assert obj.delegate == [1, 2]
obj = NativeSqSlotProxy([1])
assert obj * 2 == [1, 1]
- # TODO fix on graalpy
- # obj *= 2
- # assert obj.delegate == [1, 1]
+ obj *= 2
+ assert obj.delegate == [1, 1]
obj = NativeSqSlotProxy([1])
assert_raises(TypeError, operator.mul, obj, "a")
assert_raises(OverflowError, operator.mul, obj, 1 << 65)
- # TODO fix on graalpy
- # try:
- # obj *= "a"
- # except TypeError:
- # pass
- # else:
- # assert False
- # try:
- # obj *= 1 << 65
- # except OverflowError:
- # pass
- # else:
- # assert False
+ try:
+ obj *= "a"
+ except TypeError:
+ pass
+ else:
+ assert False
+ try:
+ obj *= 1 << 65
+ except OverflowError:
+ pass
+ else:
+ assert False
assert get_delegate(obj) == [1]
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index b4e924537c..32e7520017 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -40,6 +40,7 @@
*/
package com.oracle.graal.python.builtins.modules.cext;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiCallPath.Direct;
@@ -59,7 +60,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_KEYS;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_VALUES;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
@@ -105,7 +105,6 @@
import com.oracle.graal.python.lib.PyNumberFloatNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
import com.oracle.graal.python.lib.PyNumberLongNode;
-import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetAttr;
@@ -117,6 +116,7 @@
import com.oracle.graal.python.lib.PySequenceDelItemNode;
import com.oracle.graal.python.lib.PySequenceGetItemNode;
import com.oracle.graal.python.lib.PySequenceInplaceConcat;
+import com.oracle.graal.python.lib.PySequenceInplaceRepeat;
import com.oracle.graal.python.lib.PySequenceIterSearchNode;
import com.oracle.graal.python.lib.PySequenceSetItemNode;
import com.oracle.graal.python.lib.PySequenceSizeNode;
@@ -535,26 +535,15 @@ static int contains(Object haystack, Object needle,
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Py_ssize_t}, call = Direct)
abstract static class PySequence_InPlaceRepeat extends CApiBinaryBuiltinNode {
- @Specialization(guards = {"checkNode.execute(inliningTarget, obj)"}, limit = "1")
+ @Specialization
static Object repeat(Object obj, long n,
@Bind("this") Node inliningTarget,
- @Cached PyObjectLookupAttr lookupNode,
- @Cached CallNode callNode,
- @Cached PyNumberMultiplyNode mulNode,
- @SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode) {
- Object imulCallable = lookupNode.execute(null, inliningTarget, obj, T___IMUL__);
- if (imulCallable != PNone.NO_VALUE) {
- Object ret = callNode.executeWithoutFrame(imulCallable, n);
- return ret;
+ @Cached PRaiseNode raiseNode,
+ @Cached PySequenceInplaceRepeat repeat) {
+ if (!PInt.isIntRange(n)) {
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
- return mulNode.execute(null, inliningTarget, obj, n);
- }
-
- @Specialization(guards = "!checkNode.execute(inliningTarget, obj)", limit = "1")
- static Object repeat(Object obj, @SuppressWarnings("unused") Object n,
- @SuppressWarnings("unused") @Exclusive @Cached PySequenceCheckNode checkNode,
- @Bind("this") Node inliningTarget) {
- throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.OBJ_CANT_BE_REPEATED, obj);
+ return repeat.execute(null, inliningTarget, obj, (int) n);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
index d2c9a7b11a..789313778e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java
@@ -44,7 +44,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
@@ -258,10 +257,9 @@ static PArray doZeroSize(Object self, @SuppressWarnings("unused") int value) {
}
}
- @Builtin(name = J___IMUL__, minNumOfPositionalArgs = 2, numOfPositionalOnlyArgs = 2, parameterNames = {"$self", "value"})
- @ArgumentClinic(name = "value", conversion = ArgumentClinic.ClinicConversion.Index)
+ @Slot(value = SlotKind.sq_inplace_repeat, isComplex = true)
@GenerateNodeFactory
- abstract static class IMulNode extends PythonBinaryClinicBuiltinNode {
+ abstract static class IMulNode extends SqRepeatBuiltinNode {
@Specialization
static Object concat(PArray self, int value,
@Bind("this") Node inliningTarget,
@@ -286,11 +284,6 @@ static Object concat(PArray self, int value,
throw PRaiseNode.raiseStatic(inliningTarget, MemoryError);
}
}
-
- @Override
- protected ArgumentClinicProvider getArgumentClinic() {
- return ArrayBuiltinsClinicProviders.IMulNodeClinicProviderGen.INSTANCE;
- }
}
@GenerateInline
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
index 1ae2c8c094..d4da0d121d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
@@ -33,7 +33,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LT__;
@@ -81,6 +80,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.MpAssSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqRepeatBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.SqAssItemBuiltinNode;
import com.oracle.graal.python.lib.PyByteArrayCheckNode;
import com.oracle.graal.python.lib.PyIndexCheckNode;
@@ -473,38 +473,19 @@ private static void updateSequenceStorage(PByteArray array, SequenceStorage s) {
}
}
- @Builtin(name = J___IMUL__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_repeat, isComplex = true)
@GenerateNodeFactory
- public abstract static class IMulNode extends PythonBinaryBuiltinNode {
+ public abstract static class IMulNode extends SqRepeatBuiltinNode {
@Specialization
static Object mul(VirtualFrame frame, PByteArray self, int times,
@Bind("this") Node inliningTarget,
- @Cached @Shared SequenceStorageNodes.RepeatNode repeatNode,
- @Exclusive @Cached PRaiseNode raiseNode) {
+ @Cached SequenceStorageNodes.RepeatNode repeatNode,
+ @Cached PRaiseNode raiseNode) {
self.checkCanResize(inliningTarget, raiseNode);
SequenceStorage res = repeatNode.execute(frame, self.getSequenceStorage(), times);
self.setSequenceStorage(res);
return self;
}
-
- @Specialization
- static Object mul(VirtualFrame frame, PByteArray self, Object times,
- @Bind("this") Node inliningTarget,
- @Cached PyNumberAsSizeNode asSizeNode,
- @Cached @Shared SequenceStorageNodes.RepeatNode repeatNode,
- @Exclusive @Cached PRaiseNode raiseNode) {
- self.checkCanResize(inliningTarget, raiseNode);
- SequenceStorage res = repeatNode.execute(frame, self.getSequenceStorage(), asSizeNode.executeExact(frame, inliningTarget, times));
- self.setSequenceStorage(res);
- return self;
- }
-
- @SuppressWarnings("unused")
- @Fallback
- static Object mul(Object self, Object other,
- @Bind("this") Node inliningTarget) {
- throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, other);
- }
}
@Builtin(name = "remove", minNumOfPositionalArgs = 2)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
index 4db8393b60..53f05294b0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
@@ -43,7 +43,6 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_aiter;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_anext;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_await;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_multiply;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_power;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_as_number;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_call;
@@ -59,7 +58,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AWAIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITER__;
@@ -68,7 +66,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___STR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___TRUFFLE_RICHCOMPARE__;
-import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.BinaryFuncWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.CallFunctionWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.HashfuncWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.InitWrapper;
@@ -96,7 +93,6 @@ public enum SlotMethodDef {
// (mq) AM_SEND is an internal function and mostly called from within AWAIT, AITER, ANEXT.
/*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, CallFunctionWrapper::new, MethodsFlags.AM_SEND), */
- NB_INPLACE_MULTIPLY(PyNumberMethods__nb_inplace_multiply, T___IMUL__, BinaryFuncWrapper::new, MethodsFlags.NB_INPLACE_MULTIPLY),
NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER);
public final TruffleString methodName;
@@ -130,7 +126,6 @@ public enum SlotMethodDef {
static {
initGroup(
PyTypeObject__tp_as_number,
- NB_INPLACE_MULTIPLY,
NB_INPLACE_POWER);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index c5b136e96c..14f79c2106 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -151,7 +151,6 @@ private static Object allocatePyNumberMethods(PythonManagedClass obj, TpSlots sl
writeGroupSlots(CFields.PyTypeObject__tp_as_number, slots, writePointerNode, mem, nullValue);
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_multiply, getSlot(obj, SlotMethodDef.NB_INPLACE_MULTIPLY));
writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_power, getSlot(obj, SlotMethodDef.NB_INPLACE_POWER));
return mem;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index 8c4a246fb1..0d9f1b9597 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -2515,8 +2515,6 @@ public static ExtendNode create(GenNodeSupplier genNodeProvider) {
}
public abstract static class RepeatNode extends SequenceStorageBaseNode {
- @Child private RepeatNode recursive;
-
/*
* CPython is inconsistent when too repeats are done. Most types raise MemoryError, but e.g.
* bytes raises OverflowError when the memory might be available but the size overflows
@@ -2528,8 +2526,6 @@ protected RepeatNode(PythonBuiltinClassType errorForOverflow) {
this.errorForOverflow = errorForOverflow;
}
- public abstract SequenceStorage execute(VirtualFrame frame, SequenceStorage left, Object times);
-
public abstract SequenceStorage execute(VirtualFrame frame, SequenceStorage left, int times);
@Specialization
@@ -2696,24 +2692,6 @@ SequenceStorage doGeneric(SequenceStorage s, int times,
}
}
- @Specialization(guards = "!isInt(times)")
- @SuppressWarnings("truffle-static-method")
- SequenceStorage doNonInt(VirtualFrame frame, SequenceStorage s, Object times,
- @Bind("this") Node inliningTarget,
- @Cached PyIndexCheckNode indexCheckNode,
- @Cached PyNumberAsSizeNode asSizeNode,
- @Shared @Cached PRaiseNode raiseNode) {
- if (!indexCheckNode.execute(inliningTarget, times)) {
- throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, times);
- }
- int i = asSizeNode.executeExact(frame, inliningTarget, times);
- if (recursive == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- recursive = insert(RepeatNodeGen.create(errorForOverflow));
- }
- return recursive.execute(frame, s, i);
- }
-
private static void repeat(Object dest, Object src, int len, int times) {
for (int i = 0; i < times; i++) {
PythonUtils.arraycopy(src, 0, dest, i * len, len);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
index 740e3763a4..51048cba13 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java
@@ -57,7 +57,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
@@ -89,7 +88,6 @@
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.IndexNodes.NormalizeIndexCustomMessageNode;
-import com.oracle.graal.python.builtins.objects.deque.DequeBuiltinsClinicProviders.DequeInplaceMulNodeClinicProviderGen;
import com.oracle.graal.python.builtins.objects.deque.DequeBuiltinsClinicProviders.DequeInsertNodeClinicProviderGen;
import com.oracle.graal.python.builtins.objects.deque.DequeBuiltinsClinicProviders.DequeRotateNodeClinicProviderGen;
import com.oracle.graal.python.builtins.objects.list.PList;
@@ -741,16 +739,10 @@ static PDeque doGeneric(PDeque self, Object other,
}
}
- // deque.__mul__(v)
- @Builtin(name = J___IMUL__, minNumOfPositionalArgs = 2, parameterNames = {"$self", "n"})
+ // deque.__imul__(v)
+ @Slot(value = SlotKind.sq_inplace_repeat, isComplex = true)
@GenerateNodeFactory
- @ArgumentClinic(name = "n", conversion = ClinicConversion.Index)
- public abstract static class DequeInplaceMulNode extends PythonBinaryClinicBuiltinNode {
-
- @Override
- protected ArgumentClinicProvider getArgumentClinic() {
- return DequeInplaceMulNodeClinicProviderGen.INSTANCE;
- }
+ public abstract static class DequeInplaceMulNode extends SqRepeatBuiltinNode {
@Specialization
PDeque doGeneric(PDeque self, int n) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
index 604a1f8a3f..ced67e1c9c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
@@ -33,7 +33,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GE__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INIT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___LE__;
@@ -819,11 +818,11 @@ static Object doPListInt(VirtualFrame frame, Object left, int right,
}
}
- @Builtin(name = J___IMUL__, minNumOfPositionalArgs = 2)
+ @Slot(value = SlotKind.sq_inplace_repeat, isComplex = true)
@GenerateNodeFactory
- abstract static class IMulNode extends PythonBinaryBuiltinNode {
+ abstract static class IMulNode extends SqRepeatBuiltinNode {
@Specialization
- static Object doGeneric(VirtualFrame frame, Object list, Object right,
+ static Object doGeneric(VirtualFrame frame, Object list, int right,
@Bind("this") Node inliningTarget,
@Cached GetListStorageNode getStorageNode,
@Cached ListNodes.UpdateListStorageNode updateStorageNode,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index 766168d131..96ea48f9f5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -60,6 +60,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMUL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INDEX__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INVERT__;
@@ -293,6 +294,7 @@ public record TpSlots(TpSlot nb_bool, //
TpSlot sq_concat, //
TpSlot sq_repeat, //
TpSlot sq_inplace_concat, //
+ TpSlot sq_inplace_repeat, //
TpSlot mp_length, //
TpSlot mp_subscript, //
TpSlot mp_ass_subscript, //
@@ -706,6 +708,14 @@ public enum TpSlotMeta {
CFields.PySequenceMethods__sq_inplace_concat,
PExternalFunctionWrapper.BINARYFUNC,
BinarySlotFuncWrapper::new),
+ SQ_INPLACE_REPEAT(
+ TpSlots::sq_inplace_repeat,
+ TpSlotPythonSingle.class,
+ TpSlotSizeArgFunBuiltin.class,
+ TpSlotGroup.AS_SEQUENCE,
+ CFields.PySequenceMethods__sq_inplace_repeat,
+ PExternalFunctionWrapper.SSIZE_ARG,
+ SsizeargfuncSlotWrapper::new),
MP_LENGTH(
TpSlots::mp_length,
TpSlotPythonSingle.class,
@@ -1001,8 +1011,7 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
TpSlotDef.withoutHPy(T___RPOW__, TpSlotReversiblePython::create, PExternalFunctionWrapper.TERNARYFUNC_R));
addSlotDef(s, TpSlotMeta.NB_INPLACE_ADD, TpSlotDef.withSimpleFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_SUBTRACT, TpSlotDef.withSimpleFunction(T___ISUB__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
- // addSlotDef(s, TpSlotMeta.NB_INPLACE_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMUL__,
- // PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMUL__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_REMAINDER, TpSlotDef.withSimpleFunction(T___IMOD__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_LSHIFT, TpSlotDef.withSimpleFunction(T___ILSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_RSHIFT, TpSlotDef.withSimpleFunction(T___IRSHIFT__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
@@ -1039,6 +1048,7 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
TpSlotDef.withoutHPy(T___SETITEM__, TpSlotSqAssItemPython::create, PExternalFunctionWrapper.SETITEM),
TpSlotDef.withoutHPy(T___DELITEM__, TpSlotSqAssItemPython::create, PExternalFunctionWrapper.DELITEM));
addSlotDef(s, TpSlotMeta.SQ_INPLACE_CONCAT, TpSlotDef.withNoFunction(T___IADD__, PExternalFunctionWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.SQ_INPLACE_REPEAT, TpSlotDef.withNoFunction(T___IMUL__, PExternalFunctionWrapper.SSIZE_ARG, HPySlotWrapper.INDEXARGFUNC));
SLOTDEFS = s;
SPECIAL2SLOT = new HashMap<>(SLOTDEFS.size() * 2);
@@ -1651,6 +1661,7 @@ public TpSlots build() {
get(TpSlotMeta.SQ_CONCAT), //
get(TpSlotMeta.SQ_REPEAT), //
get(TpSlotMeta.SQ_INPLACE_CONCAT), //
+ get(TpSlotMeta.SQ_INPLACE_REPEAT), //
get(TpSlotMeta.MP_LENGTH), //
get(TpSlotMeta.MP_SUBSCRIPT), //
get(TpSlotMeta.MP_ASS_SUBSCRIPT), //
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java
index 59685c5755..5557ec7820 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java
@@ -40,7 +40,6 @@
*/
package com.oracle.graal.python.builtins.objects.type.slots;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.J___GETITEM__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
import java.util.Objects;
@@ -100,9 +99,11 @@ private TpSlotSizeArgFun() {
public abstract static class TpSlotSizeArgFunBuiltin extends TpSlotBuiltin {
private final int callTargetIndex = TpSlotBuiltinCallTargetRegistry.getNextCallTargetIndex();
+ private final String name;
- protected TpSlotSizeArgFunBuiltin(NodeFactory nodeFactory) {
+ protected TpSlotSizeArgFunBuiltin(NodeFactory nodeFactory, String name) {
super(nodeFactory);
+ this.name = name;
}
final SizeArgFunBuiltinNode createSlotNode() {
@@ -111,7 +112,7 @@ final SizeArgFunBuiltinNode createSlotNode() {
@Override
public void initialize(PythonLanguage language) {
- RootCallTarget target = createBuiltinCallTarget(language, BuiltinSlotWrapperSignature.BINARY, getNodeFactory(), J___GETITEM__);
+ RootCallTarget target = createBuiltinCallTarget(language, BuiltinSlotWrapperSignature.BINARY, getNodeFactory(), name);
language.setBuiltinSlotCallTarget(callTargetIndex, target);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java
new file mode 100644
index 0000000000..93cf5564e8
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
+
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Cached.Exclusive;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+
+@GenerateInline(false)
+public abstract class PyNumberInplaceMultiplyNode extends PyNumberMultiplyBaseNode {
+
+ @Fallback
+ @InliningCutoff
+ public static Object doIt(VirtualFrame frame, Object v, Object w,
+ @Bind Node inliningTarget,
+ @Exclusive @Cached GetClassNode getVClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Exclusive @Cached GetClassNode getWClass,
+ @Cached CallBinaryIOp1Node callBinaryIOp1Node,
+ @Cached InlinedBranchProfile hasNbMultiplyResult,
+ @Cached InlinedBranchProfile hasInplaceRepeat,
+ @Cached InlinedBranchProfile hasRepeat,
+ @Cached InlinedBranchProfile wHasRepeat,
+ @Cached SequenceRepeatHelperNode sequenceRepeatNode,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlots slotsW = getWSlots.execute(inliningTarget, classW);
+ Object result = callBinaryIOp1Node.execute(frame, inliningTarget, v, classV, slotsV, w, classW, slotsW, InplaceSlot.NB_INPLACE_MULTIPLY);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbMultiplyResult.enter(inliningTarget);
+ return result;
+ }
+ if (slotsV.has_as_sequence()) {
+ TpSlot repeatSlot = null;
+ if (slotsV.sq_inplace_repeat() != null) {
+ hasInplaceRepeat.enter(inliningTarget);
+ repeatSlot = slotsV.sq_inplace_repeat();
+ } else if (slotsV.sq_repeat() != null) {
+ hasRepeat.enter(inliningTarget);
+ repeatSlot = slotsV.sq_repeat();
+ }
+ if (repeatSlot != null) {
+ return sequenceRepeatNode.execute(frame, repeatSlot, v, w);
+ }
+ } else if (slotsW.has_as_sequence()) {
+ /*
+ * Note that the right hand operand should not be mutated in this case so
+ * sq_inplace_repeat is not used.
+ */
+ if (slotsW.sq_repeat() != null) {
+ wHasRepeat.enter(inliningTarget);
+ return sequenceRepeatNode.execute(frame, slotsW.sq_repeat(), w, v);
+ }
+ }
+ return raiseNotSupported(inliningTarget, v, w, "*=", raiseNode);
+ }
+
+ @NeverDefault
+ public static PyNumberInplaceMultiplyNode create() {
+ return PyNumberInplaceMultiplyNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index ee19d86660..df047a134a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -42,19 +42,13 @@
import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
-import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
-import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.exception.PException;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
@@ -132,9 +126,7 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
@Cached InlinedBranchProfile hasNbMulResult,
@Cached InlinedBranchProfile vHasSqRepeat,
@Cached InlinedBranchProfile wHasSqRepeat,
- @Cached PyIndexCheckNode indexCheckNode,
- @Cached PyNumberAsSizeNode asSizeNode,
- @Cached CallSlotSizeArgFun callSlotNode,
+ @Cached SequenceRepeatHelperNode sequenceRepeatNode,
@Cached PRaiseNode raiseNode) {
Object classV = getVClass.execute(inliningTarget, v);
Object classW = getWClass.execute(inliningTarget, w);
@@ -147,34 +139,14 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
}
if (slotsV.sq_repeat() != null) {
vHasSqRepeat.enter(inliningTarget);
- return sequenceRepeat(frame, inliningTarget, slotsV.sq_repeat(), v, w,
- indexCheckNode, asSizeNode, callSlotNode, raiseNode);
+ return sequenceRepeatNode.execute(frame, slotsV.sq_repeat(), v, w);
} else if (slotsW.sq_repeat() != null) {
wHasSqRepeat.enter(inliningTarget);
- return sequenceRepeat(frame, inliningTarget, slotsW.sq_repeat(), w, v,
- indexCheckNode, asSizeNode, callSlotNode, raiseNode);
+ return sequenceRepeatNode.execute(frame, slotsW.sq_repeat(), w, v);
}
return raiseNotSupported(inliningTarget, v, w, "*", raiseNode);
}
- private static Object sequenceRepeat(VirtualFrame frame, Node inliningTarget, TpSlot slot, Object seq, Object n,
- PyIndexCheckNode indexCheckNode,
- PyNumberAsSizeNode asSizeNode,
- CallSlotSizeArgFun callSlotNode,
- PRaiseNode raiseNode) {
- if (indexCheckNode.execute(inliningTarget, n)) {
- int count = asSizeNode.execute(frame, inliningTarget, n, PythonBuiltinClassType.OverflowError);
- return callSlotNode.execute(frame, inliningTarget, slot, seq, count);
- } else {
- throw raiseNonIntSqMul(inliningTarget, n, raiseNode);
- }
- }
-
- @InliningCutoff
- private static PException raiseNonIntSqMul(Node inliningTarget, Object n, PRaiseNode raiseNode) {
- throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, n);
- }
-
@NeverDefault
public static PyNumberMultiplyNode create() {
return PyNumberMultiplyNodeGen.create();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java
new file mode 100644
index 0000000000..154171769c
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PNodeWithContext;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+
+@GenerateInline
+@GenerateCached(false)
+public abstract class PySequenceInplaceRepeat extends PNodeWithContext {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object o, int count);
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object o, int count,
+ @Cached GetClassNode getClassNode,
+ @Cached GetCachedTpSlotsNode slotsNode,
+ @Cached PySequenceCheckNode sequenceCheckNode,
+ @Cached CallBinaryIOp1Node callBinaryIOp1Node,
+ @Cached InlinedBranchProfile hasInplaceRepeat,
+ @Cached InlinedBranchProfile hasRepeat,
+ @Cached InlinedBranchProfile isSequence,
+ @Cached InlinedBranchProfile hasNbMultiplyResult,
+ @Cached CallSlotSizeArgFun callSlot,
+ @Cached PRaiseNode raiseNode) {
+ Object classV = getClassNode.execute(inliningTarget, o);
+ TpSlots slotsV = slotsNode.execute(inliningTarget, classV);
+ TpSlot repeatSlot = null;
+ if (slotsV.sq_inplace_repeat() != null) {
+ hasInplaceRepeat.enter(inliningTarget);
+ repeatSlot = slotsV.sq_inplace_repeat();
+ } else if (slotsV.sq_repeat() != null) {
+ hasRepeat.enter(inliningTarget);
+ repeatSlot = slotsV.sq_repeat();
+ }
+ if (repeatSlot != null) {
+ return callSlot.execute(frame, inliningTarget, repeatSlot, o, count);
+ }
+ if (sequenceCheckNode.execute(inliningTarget, o)) {
+ isSequence.enter(inliningTarget);
+ PythonBuiltinClassType countType = PythonBuiltinClassType.PInt;
+ Object result = callBinaryIOp1Node.execute(frame, inliningTarget, o, classV, slotsV, count, countType, countType.getSlots(), InplaceSlot.NB_INPLACE_MULTIPLY);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ hasNbMultiplyResult.enter(inliningTarget);
+ return result;
+ }
+ }
+ return raiseNotSupported(inliningTarget, o, raiseNode);
+ }
+
+ @InliningCutoff
+ private static PException raiseNotSupported(Node inliningTarget, Object v, PRaiseNode raiseNode) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANT_BE_REPEATED, v);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/SequenceRepeatHelperNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/SequenceRepeatHelperNode.java
new file mode 100644
index 0000000000..07213af746
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/SequenceRepeatHelperNode.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(false)
+@GenerateUncached
+public abstract class SequenceRepeatHelperNode extends Node {
+ abstract Object execute(VirtualFrame frame, TpSlot slot, Object seq, Object n);
+
+ @Specialization
+ static Object sequenceRepeat(VirtualFrame frame, TpSlot slot, Object seq, Object n,
+ @Bind Node inliningTarget,
+ @Cached PyIndexCheckNode indexCheckNode,
+ @Cached PyNumberAsSizeNode asSizeNode,
+ @Cached TpSlotSizeArgFun.CallSlotSizeArgFun callSlotNode,
+ @Cached PRaiseNode raiseNode) {
+ if (indexCheckNode.execute(inliningTarget, n)) {
+ int count = asSizeNode.execute(frame, inliningTarget, n, PythonBuiltinClassType.OverflowError);
+ return callSlotNode.execute(frame, inliningTarget, slot, seq, count);
+ } else {
+ throw raiseNonIntSqMul(inliningTarget, n, raiseNode);
+ }
+ }
+
+ @InliningCutoff
+ private static PException raiseNonIntSqMul(Node inliningTarget, Object n, PRaiseNode raiseNode) {
+ throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.CANT_MULTIPLY_SEQ_BY_NON_INT, n);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index a6c9538c47..e96afc0875 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -117,6 +117,7 @@
import com.oracle.graal.python.lib.PyNumberInplaceFloorDivideNode;
import com.oracle.graal.python.lib.PyNumberInplaceLshiftNode;
import com.oracle.graal.python.lib.PyNumberInplaceMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInplaceMultiplyNode;
import com.oracle.graal.python.lib.PyNumberInplaceOrNode;
import com.oracle.graal.python.lib.PyNumberInplaceRemainderNode;
import com.oracle.graal.python.lib.PyNumberInplaceRshiftNode;
@@ -466,7 +467,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
case BinaryOpsConstants.INPLACE_SUB:
return PyNumberInplaceSubtractNode.create();
case BinaryOpsConstants.INPLACE_MUL:
- return InplaceArithmetic.IMul.create();
+ return PyNumberInplaceMultiplyNode.create();
case BinaryOpsConstants.INPLACE_TRUEDIV:
return PyNumberInplaceTrueDivideNode.create();
case BinaryOpsConstants.INPLACE_FLOORDIV:
From e700a0bf405e9b3219af8d1271a60c86f64ee984 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Fri, 14 Feb 2025 16:54:24 +0100
Subject: [PATCH 022/512] Fix slot group inheritance
---
.../python/builtins/objects/type/TpSlots.java | 36 +++++++++++++++----
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index 96ea48f9f5..aeb3a22d75 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -370,18 +370,35 @@ public TpSlot create(Object[] callables, TruffleString[] names, Object klass) {
}
public enum TpSlotGroup {
- AS_NUMBER(CFields.PyTypeObject__tp_as_number),
- AS_SEQUENCE(CFields.PyTypeObject__tp_as_sequence),
- AS_MAPPING(CFields.PyTypeObject__tp_as_mapping),
- NO_GROUP(null); // Must be last
+ AS_NUMBER(TpSlots::has_as_number, CFields.PyTypeObject__tp_as_number),
+ AS_SEQUENCE(TpSlots::has_as_sequence, CFields.PyTypeObject__tp_as_sequence),
+ AS_MAPPING(TpSlots::has_as_mapping, CFields.PyTypeObject__tp_as_mapping),
+ NO_GROUP(null, null); // Must be last
public static final TpSlotGroup[] VALID_VALUES = Arrays.copyOf(values(), values().length - 1);
+ private final GroupGetter getter;
private final CFields cField;
- TpSlotGroup(CFields cField) {
+ TpSlotGroup(GroupGetter getter, CFields cField) {
+ this.getter = getter;
this.cField = cField;
}
+
+ public boolean getValue(TpSlots slots) {
+ assert this != NO_GROUP;
+ return getter.get(slots);
+ }
+
+ public boolean readFromNative(PythonAbstractNativeObject pythonClass) {
+ Object ptr = ReadPointerNode.getUncached().readFromObj(pythonClass, cField);
+ return !InteropLibrary.getUncached().isNull(ptr);
+ }
+ }
+
+ @FunctionalInterface
+ interface GroupGetter {
+ boolean get(TpSlots slot);
}
/**
@@ -1071,6 +1088,11 @@ public static TpSlots createEmpty() {
*/
public static TpSlots fromNative(PythonAbstractNativeObject pythonClass, PythonContext ctx) {
var builder = TpSlots.newBuilder();
+ for (TpSlotGroup group : TpSlotGroup.VALID_VALUES) {
+ if (group.readFromNative(pythonClass)) {
+ builder.setExplicitGroup(group);
+ }
+ }
for (TpSlotMeta def : TpSlotMeta.VALUES) {
if (!def.hasNativeWrapperFactory()) {
continue;
@@ -1518,7 +1540,9 @@ public Builder copy() {
result.set(def, def.getValue(this));
}
for (TpSlotGroup group : TpSlotGroup.VALID_VALUES) {
- result.setExplicitGroup(group);
+ if (group.getValue(this)) {
+ result.setExplicitGroup(group);
+ }
}
return result;
}
From 252198a27a7a94c973498a4c8a9161ba2afaa8d9 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Fri, 14 Feb 2025 17:15:52 +0100
Subject: [PATCH 023/512] Disable user-site in startup test
---
.../com.oracle.graal.python.test/src/tests/test_startup.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py b/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
index 5e0fb21c8a..68aaf4c87f 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/test_startup.py
@@ -84,7 +84,7 @@ def test_startup_nosite(self):
@unittest.skipUnless(sys.implementation.name == 'graalpy', "GraalPy-specific test")
def test_startup_full(self):
- result = subprocess.check_output([sys.executable, '--log.level=FINE', '-v', '-c', 'print("Hello")'], stderr=subprocess.STDOUT, text=True)
+ result = subprocess.check_output([sys.executable, '--log.level=FINE', '-s', '-v', '-c', 'print("Hello")'], stderr=subprocess.STDOUT, text=True)
assert 'Hello' in result
imports = re.findall("import '(\S+)'", result)
self.assertEqual(expected_full_startup_modules, imports)
From f1b71fdec9f65825984e0519df6e8ddc1cb5dcb3 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Mon, 17 Feb 2025 14:03:42 +0100
Subject: [PATCH 024/512] Shorten test class names to avoid long filenames on
windows
---
.../src/tests/cpyext/test_tp_slots.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index 534f2e2c4f..edf344dedf 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -517,7 +517,7 @@ class SqRepeatManaged(SqRepeat): pass
assert CallRepeatHelper.PySequence_Repeat(x, 2) == "repeat"
SqRepeatAndNbMultiplyNoImplemented = CPyExtHeapType(
- "SqRepeatAndNbMultiplyNoImplemented",
+ "RepeatAndMulNotImpl",
slots=[
'{Py_sq_repeat, &repeat}',
'{Py_nb_multiply, &mymultiply}',
@@ -554,7 +554,7 @@ def test_sq_inplace_repeat_vs_nb_inplace_multiply():
assert x == "repeat"
SqInplaceRepeatAndNbInplaceMultiply = CPyExtHeapType(
- "SqInplaceRepeatAndNbInplaceMultiply",
+ "SqInplaceRepeatAndNbInMul",
slots=['{Py_sq_inplace_repeat, &inplace_repeat}', '{Py_nb_inplace_multiply, &inplace_multiply}'],
code='''
PyObject* inplace_repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("inplace_repeat"); }
@@ -569,7 +569,7 @@ def test_sq_inplace_repeat_vs_nb_inplace_multiply():
assert CallRepeatHelper.PySequence_InPlaceRepeat(x, 1) == "inplace_repeat"
SqInplaceRepeatAndNbInplaceMultiplyNotImplemented = CPyExtHeapType(
- "SqInplaceRepeatAndNbInplaceMultiplyNotImplemented",
+ "InplaceRepeatAndMulNotImpl",
slots=['{Py_sq_inplace_repeat, &inplace_repeat}', '{Py_nb_inplace_multiply, &inplace_multiply}'],
code='''
PyObject* inplace_repeat(PyObject* a, Py_ssize_t times) { return PyUnicode_FromString("inplace_repeat"); }
From ae7f983de9179373f2659b1d091421ae25d0c9d1 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Mon, 17 Feb 2025 15:50:26 +0100
Subject: [PATCH 025/512] Fix PyObject_Bytes specialization consistency
Fixes #476
---
.../modules/cext/PythonCextBytesBuiltins.java | 40 +++-------
.../cext/PythonCextObjectBuiltins.java | 76 +++++++++----------
.../builtins/objects/bytes/BytesNodes.java | 4 +-
3 files changed, 46 insertions(+), 74 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
index b89d3af482..7dd9b9c07f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java
@@ -53,14 +53,11 @@
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_ssize_t;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyVarObject__ob_size;
-import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITER__;
import java.util.Arrays;
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.modules.BuiltinConstructors.BytesNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiCallPath;
@@ -88,13 +85,10 @@
import com.oracle.graal.python.builtins.objects.str.StringBuiltins.ModNode;
import com.oracle.graal.python.lib.PyBytesCheckNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
-import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.lib.PyObjectSizeNode;
import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.nodes.util.CastToByteNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
@@ -177,33 +171,17 @@ static Object fromFormat(TruffleString fmt, Object args,
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
abstract static class PyBytes_FromObject extends CApiUnaryBuiltinNode {
- @Specialization
- static Object fromObject(Object obj,
- @Bind("this") Node inliningTarget,
- @Cached GetClassNode getClassNode,
- @Cached IsSubtypeNode isSubtypeNode,
- @Cached BytesNode bytesNode,
- @Cached PyObjectLookupAttr lookupAttrNode,
- @Cached PRaiseNode raiseNode) {
- if (PGuards.isPBytes(obj)) {
- return obj;
- } else {
- Object klass = getClassNode.execute(inliningTarget, obj);
- if (isSubtypeNode.execute(klass, PythonBuiltinClassType.PBytes)) {
- return obj;
- } else if (isAcceptedSubtype(inliningTarget, obj, klass, isSubtypeNode, lookupAttrNode)) {
- return bytesNode.execute(null, PythonBuiltinClassType.PBytes, obj, PNone.NO_VALUE, PNone.NO_VALUE);
- } else {
- throw raiseNode.raise(inliningTarget, TypeError, CANNOT_CONVERT_P_OBJ_TO_S, obj, "bytes");
- }
- }
+ @Specialization(guards = "isBuiltinBytes(bytes)")
+ static Object bytes(PBytes bytes) {
+ return bytes;
}
- private static boolean isAcceptedSubtype(Node inliningTarget, Object obj, Object klass, IsSubtypeNode isSubtypeNode, PyObjectLookupAttr lookupAttrNode) {
- return isSubtypeNode.execute(klass, PythonBuiltinClassType.PList) ||
- isSubtypeNode.execute(klass, PythonBuiltinClassType.PTuple) ||
- isSubtypeNode.execute(klass, PythonBuiltinClassType.PMemoryView) ||
- (!isSubtypeNode.execute(klass, PythonBuiltinClassType.PString) && lookupAttrNode.execute(null, inliningTarget, obj, T___ITER__) != PNone.NO_VALUE);
+ @Fallback
+ static Object fromObject(Object obj,
+ @Bind("this") Node inliningTarget,
+ @Cached BytesNodes.BytesFromObject fromObject) {
+ byte[] bytes = fromObject.execute(null, obj);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), bytes);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
index d2ff8dc9e6..06f7b89603 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java
@@ -41,6 +41,7 @@
package com.oracle.graal.python.builtins.modules.cext;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.NotImplementedError;
+import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiCallPath.Direct;
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiCallPath.Ignored;
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.ConstCharPtrAsTruffleString;
@@ -66,7 +67,6 @@
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.modules.BuiltinConstructors.BytesNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.FormatNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.IsInstanceNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.IsSubClassNode;
@@ -79,11 +79,11 @@
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CastArgsNode;
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CastKwargsNode;
-import com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins.PyBytes_FromObject;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
-import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
+import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.cext.capi.CApiGuards;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ResolvePointerNode;
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper;
@@ -104,7 +104,9 @@
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins.GetAttributeNode;
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins.SetattrNode;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
+import com.oracle.graal.python.lib.PyBytesCheckNode;
import com.oracle.graal.python.lib.PyCallableCheckNode;
import com.oracle.graal.python.lib.PyLongCheckNode;
import com.oracle.graal.python.lib.PyObjectAsFileDescriptor;
@@ -116,7 +118,6 @@
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.lib.PyObjectHashNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
-import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.lib.PyObjectLookupAttrO;
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
import com.oracle.graal.python.lib.PyObjectSetItem;
@@ -127,7 +128,8 @@
import com.oracle.graal.python.nodes.StringLiterals;
import com.oracle.graal.python.nodes.argument.keywords.ExpandKeywordStarargsNode;
import com.oracle.graal.python.nodes.call.CallNode;
-import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
+import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
+import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.util.CannotCastException;
@@ -147,13 +149,15 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Exclusive;
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
+import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.strings.TruffleString;
public abstract class PythonCextObjectBuiltins {
@@ -503,40 +507,13 @@ static int isTrue(Object obj,
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
+ @ImportStatic(SpecialMethodSlot.class)
abstract static class PyObject_Bytes extends CApiUnaryBuiltinNode {
- @Specialization
- static Object bytes(PBytesLike bytes) {
- return bytes;
- }
-
- @Specialization(guards = {"!isBytes(bytes)", "isBytesSubtype(inliningTarget, bytes, getClassNode, isSubtypeNode)"}, limit = "1")
- static Object bytes(Object bytes,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Exclusive @Cached GetClassNode getClassNode,
- @SuppressWarnings("unused") @Exclusive @Cached IsSubtypeNode isSubtypeNode) {
+ @Specialization(guards = "isBuiltinBytes(bytes)")
+ static Object bytes(PBytes bytes) {
return bytes;
}
- @Specialization(guards = {"!isBytes(obj)", "!isBytesSubtype(this, obj, getClassNode, isSubtypeNode)", "!isNoValue(obj)", "hasBytes(inliningTarget, obj, lookupAttrNode)"}, limit = "1")
- static Object bytes(Object obj,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Exclusive @Cached GetClassNode getClassNode,
- @SuppressWarnings("unused") @Exclusive @Cached IsSubtypeNode isSubtypeNode,
- @SuppressWarnings("unused") @Exclusive @Cached PyObjectLookupAttr lookupAttrNode,
- @Cached BytesNode bytesNode) {
- return bytesNode.execute(null, PythonBuiltinClassType.PBytes, obj, PNone.NO_VALUE, PNone.NO_VALUE);
- }
-
- @Specialization(guards = {"!isBytes(obj)", "!isBytesSubtype(this, obj, getClassNode, isSubtypeNode)", "!isNoValue(obj)", "!hasBytes(inliningTarget, obj, lookupAttrNode)"}, limit = "1")
- static Object bytes(Object obj,
- @SuppressWarnings("unused") @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Exclusive @Cached GetClassNode getClassNode,
- @SuppressWarnings("unused") @Exclusive @Cached IsSubtypeNode isSubtypeNode,
- @SuppressWarnings("unused") @Exclusive @Cached PyObjectLookupAttr lookupAttrNode,
- @Cached PyBytes_FromObject fromObjectNode) {
- return fromObjectNode.execute(obj);
- }
-
@Specialization(guards = "isNoValue(obj)")
static Object bytesNoValue(@SuppressWarnings("unused") Object obj,
@Bind PythonLanguage language) {
@@ -547,12 +524,27 @@ static Object bytesNoValue(@SuppressWarnings("unused") Object obj,
return PFactory.createBytes(language, BytesUtils.NULL_STRING);
}
- protected static boolean hasBytes(Node inliningTarget, Object obj, PyObjectLookupAttr lookupAttrNode) {
- return lookupAttrNode.execute(null, inliningTarget, obj, T___BYTES__) != PNone.NO_VALUE;
- }
-
- protected static boolean isBytesSubtype(Node inliningTarget, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
- return isSubtypeNode.execute(getClassNode.execute(inliningTarget, obj), PythonBuiltinClassType.PBytes);
+ @Fallback
+ static Object doGeneric(Object obj,
+ @Bind("this") Node inliningTarget,
+ @Cached GetClassNode getClassNode,
+ @Cached InlinedConditionProfile hasBytes,
+ @Cached("create(Bytes)") LookupSpecialMethodSlotNode lookupBytes,
+ @Cached CallUnaryMethodNode callBytes,
+ @Cached PyBytesCheckNode check,
+ @Cached BytesNodes.BytesFromObject fromObject,
+ @Cached PRaiseNode raiseNode) {
+ Object bytesMethod = lookupBytes.execute(null, getClassNode.execute(inliningTarget, obj), obj);
+ if (hasBytes.profile(inliningTarget, bytesMethod != PNone.NO_VALUE)) {
+ Object bytes = callBytes.executeObject(null, bytesMethod, obj);
+ if (check.execute(inliningTarget, bytes)) {
+ return bytes;
+ } else {
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.RETURNED_NONBYTES, T___BYTES__, bytes);
+ }
+ }
+ byte[] bytes = fromObject.execute(null, obj);
+ return PFactory.createBytes(PythonLanguage.get(inliningTarget), bytes);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
index 21b49d787f..bfeaa560dd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java
@@ -83,6 +83,7 @@
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyOSFSPathNode;
import com.oracle.graal.python.lib.PyObjectGetIter;
+import com.oracle.graal.python.lib.PyUnicodeCheckNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -560,6 +561,7 @@ static byte[] doGeneric(VirtualFrame frame, Object object,
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Cached BytesNodes.IterableToByteNode iterableToByteNode,
@Cached IsBuiltinObjectProfile errorProfile,
+ @Cached PyUnicodeCheckNode unicodeCheckNode,
@Cached PRaiseNode raiseNode) {
if (bufferAcquireLib.hasBuffer(object)) {
// TODO PyBUF_FULL_RO
@@ -570,7 +572,7 @@ static byte[] doGeneric(VirtualFrame frame, Object object,
bufferLib.release(buffer, frame, indirectCallData);
}
}
- if (!PGuards.isString(object)) {
+ if (!unicodeCheckNode.execute(inliningTarget, object)) {
try {
return iterableToByteNode.execute(frame, object);
} catch (PException e) {
From 75c11f3c44513153aebb8ac519cd46b0efb06561 Mon Sep 17 00:00:00 2001
From: stepan
Date: Wed, 19 Feb 2025 14:27:35 +0100
Subject: [PATCH 026/512] Fix: Maven plugin incorrectly prints warning about
default resources directory. Fix few typos in warning messages.
---
.../src/tests/standalone/test_gradle_plugin.py | 6 +++++-
.../src/tests/standalone/test_maven_plugin.py | 2 ++
.../python/maven/plugin/ManageResourcesMojo.java | 4 ++--
.../java/org/graalvm/python/GraalPyGradlePlugin.java | 10 +++++-----
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
index 52d95fc704..b50be878dc 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
@@ -133,6 +133,8 @@ def check_gradle_generated_app(self, community):
cmd = gradlew_cmd + ["build"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir, logger=log)
util.check_ouput("BUILD SUCCESS", out, logger=log)
+ util.check_ouput("Virtual filesystem is deployed to default resources directory", out, logger=log)
+ util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem", out, logger=log)
self.check_filelist(target_dir, log)
cmd = gradlew_cmd + ["nativeCompile"]
@@ -413,7 +415,7 @@ def check_gradle_python_resources_dir_and_external_dir_error(self):
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
cmd = gradle_cmd + ["graalPyResources"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("Cannot set both 'externalDirectory' and 'resourcesDirectory' at the same time", out)
+ util.check_ouput("Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time", out)
assert return_code != 0, out
@@ -478,6 +480,8 @@ def check_gradle_namespaced_vfs(self):
app1_gradle_cmd = util.get_gradle_wrapper(app1_dir, self.env)
out, return_code = util.run_cmd(app1_gradle_cmd + ['publishToMavenLocal'], self.env, cwd=app1_dir)
+ util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=False)
+ util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem", out, contains=False)
assert return_code == 0, out
app2_gradle_cmd = util.get_gradle_wrapper(app2_dir, self.env)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
index 4b2cdb5c04..5c4f9e34cb 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
@@ -115,6 +115,8 @@ def check_generated_app(self, use_default_vfs_path, use_utils_pkg=False):
cmd = mvnw_cmd + ["package", "-Pnative", "-DmainClass=it.pkg.GraalPy"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
util.check_ouput("BUILD SUCCESS", out)
+ util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=use_default_vfs_path)
+ util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem.", out, contains=use_default_vfs_path)
# check fileslist.txt
fl_path = os.path.join(target_dir, "target", "classes", vfs_prefix, "fileslist.txt")
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
index bc2b69ceae..d81b78b861 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
@@ -145,7 +145,7 @@ public void execute() throws MojoExecutionException {
}
if (resourceDirectory == null) {
- if (externalDirectory != null) {
+ if (externalDirectory == null) {
getLog().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
"This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
"Consider adding GRAALPY-VFS/${project.groupId}/${project.artifactId} to your pom.xml, " +
@@ -162,7 +162,7 @@ public void execute() throws MojoExecutionException {
getLog().warn("The GraalPy plugin configuration setting was deprecated and has no effect anymore.\n" +
"For execution in jvm mode, the python language home is always available.\n" +
"When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
- "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources documentation.");
+ "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
}
manageVenv();
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
index f0ff56f0e1..0b964a9720 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
@@ -117,11 +117,11 @@ public void apply(Project project) {
if (extension.getPythonResourcesDirectory().isPresent() && extension.getExternalDirectory().isPresent()) {
throw new GradleException(
- "Cannot set both 'externalDirectory' and 'resourcesDirectory' at the same time. " +
+ "Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time. " +
"New property 'externalDirectory' is a replacement for deprecated 'pythonResourcesDirectory'. " +
"If you want to deploy the virtual environment into physical filesystem, use 'externalDirectory'. " +
"The deployment of the external directory alongside the application is not handled by the GraalPy Maven plugin in such case." +
- "If you wish to bundle the virtual filesystem in Java resources, use 'resourcesDirectory'. " +
+ "If you wish to bundle the virtual filesystem in Java resources, use 'resourceDirectory'. " +
"For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ");
}
@@ -132,9 +132,9 @@ public void apply(Project project) {
// Run the vfsFilesListTask conditionally only if 'externalDirectory' is not set
if (!extension.getPythonResourcesDirectory().isPresent() && !extension.getExternalDirectory().isPresent()) {
if (!extension.getResourceDirectory().isPresent()) {
- proj.getLogger().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
+ proj.getLogger().warn(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
"This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
- "Consider adding `resourcesDirectory = \"GRAALPY-VFS/${groupId}/${artifactId}\"` to your build.gradle script " +
+ "Consider adding `resourceDirectory = \"GRAALPY-VFS/${groupId}/${artifactId}\"` to your build.gradle script " +
"(replace the placeholders with values specific to your project), " +
"moving any existing sources from '%s' to '%s', and using VirtualFileSystem$Builder#resourceDirectory." +
"For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ",
@@ -192,7 +192,7 @@ private TaskProvider registerResourcesTask(Project project, Confi
t.getLogger().warn("The GraalPy plugin pythonHome configuration setting was deprecated and has no effect anymore.\n" +
"For execution in jvm mode, the python language home is always available.\n" +
"When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
- "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources documentation.");
+ "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
}
t.getPackages().set(extension.getPackages());
From 1ec809444b62db8d2de3b550aaaecd6ed2c8423b Mon Sep 17 00:00:00 2001
From: stepan
Date: Wed, 19 Feb 2025 14:51:56 +0100
Subject: [PATCH 027/512] Improve the GraalPyResources docs
---
.../python/embedding/GraalPyResources.java | 46 ++++++++++++-------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java b/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java
index 7efc01cd3a..fa26d06389 100644
--- a/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java
+++ b/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java
@@ -198,7 +198,12 @@ private GraalPyResources() {
* location
* /org.graalvm.python.vfs/src
- is set as the python sources location
*
- *
+ *
+ * When the virtual filesystem is located in other than the default resource directory,
+ * {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
+ * use {@link #contextBuilder(VirtualFileSystem)} and
+ * {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
+ * {@link VirtualFileSystem}.
*
* @return a new {@link Context} instance
* @since 24.2.0
@@ -233,6 +238,12 @@ public static Context createContext() {
* }
* }
*
+ *
+ * When the virtual filesystem is located in other than the default resource directory,
+ * {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
+ * use {@link #contextBuilder(VirtualFileSystem)} and
+ * {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
+ * {@link VirtualFileSystem}.
*
* @see PythonOptions
@@ -308,13 +319,14 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
/**
* Creates a GraalPy context preconfigured with GraalPy and polyglot Context configuration
- * options for use with resources located in a real filesystem.
+ * options for use with resources located in an external directory in real filesystem.
*
* Following resource paths are preconfigured:
*
- * ${resourcesDirectory}/venv
- is set as the python virtual environment
+ * ${externalResourcesDirectory}/venv
- is set as the python virtual
+ * environment location
+ * ${externalResourcesDirectory}/src
- is set as the python sources
* location
- * ${resourcesDirectory}/src
- is set as the python sources location
*
*
*
@@ -343,19 +355,20 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
*
*
*
- * @param resourcesDirectory the root directory with GraalPy specific embedding resources
+ * @param externalResourcesDirectory the root directory with GraalPy specific embedding
+ * resources
* @return a new {@link org.graalvm.polyglot.Context.Builder} instance
* @since 24.2.0
*/
- public static Context.Builder contextBuilder(Path resourcesDirectory) {
+ public static Context.Builder contextBuilder(Path externalResourcesDirectory) {
String execPath;
if (VirtualFileSystemImpl.isWindows()) {
- execPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("Scripts").resolve("python.exe").toAbsolutePath().toString();
+ execPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("Scripts").resolve("python.exe").toAbsolutePath().toString();
} else {
- execPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("bin").resolve("python").toAbsolutePath().toString();
+ execPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("bin").resolve("python").toAbsolutePath().toString();
}
- String srcPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
+ String srcPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
return createContextBuilder().
// allow all IO access
allowIO(IOAccess.ALL).
@@ -437,8 +450,9 @@ public static Path getNativeExecutablePath() {
* The structure of the created resource directory will stay the same like the embedded Python
* resources structure:
*
- * ${resourcesDirectory}/venv
- the python virtual environment location
- * ${resourcesDirectory}/src
- the python sources location
+ * ${externalResourcesDirectory}/venv
- the python virtual environment
+ * location
+ * ${externalResourcesDirectory}/src
- the python sources location
*
*
*
@@ -456,17 +470,17 @@ public static Path getNativeExecutablePath() {
*
*
* @param vfs the {@link VirtualFileSystem} from which resources are to be extracted
- * @param resourcesDirectory the target directory to extract the resources to
+ * @param externalResourcesDirectory the target directory to extract the resources to
* @throws IOException if resources isn't a directory
* @see #contextBuilder(Path)
* @see VirtualFileSystem.Builder#resourceLoadingClass(Class)
*
* @since 24.2.0
*/
- public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path resourcesDirectory) throws IOException {
- if (Files.exists(resourcesDirectory) && !Files.isDirectory(resourcesDirectory)) {
- throw new IOException(String.format("%s has to be a directory", resourcesDirectory.toString()));
+ public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path externalResourcesDirectory) throws IOException {
+ if (Files.exists(externalResourcesDirectory) && !Files.isDirectory(externalResourcesDirectory)) {
+ throw new IOException(String.format("%s has to be a directory", externalResourcesDirectory.toString()));
}
- vfs.impl.extractResources(resourcesDirectory);
+ vfs.impl.extractResources(externalResourcesDirectory);
}
}
From 00abb91c5ad06d11a5e2049c191bae5f380a2e0a Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Mon, 27 Jan 2025 18:18:39 +0100
Subject: [PATCH 028/512] Make dir(foreign_object) return both foreign methods
and Python methods
---
CHANGELOG.md | 3 ++
.../src/tests/test_interop.py | 8 +++
.../foreign/ForeignObjectBuiltins.java | 49 +++++++++++++++----
graalpython/lib-graalpython/_sre.py | 7 ++-
4 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 02b01a9454..a892ba0b0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,9 @@
This changelog summarizes major changes between GraalVM versions of the Python
language runtime. The main focus is on user-observable behavior of the engine.
+## Version 25.0.0
+* `dir(foreign_object)` now returns both foreign methods and Python methods (it used to return only foreign methods).
+
## Version 24.2.0
* Updated developer metadata of Maven artifacts.
* Added gradle plugin for polyglot embedding of Python packages into Java.
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py b/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py
index 6ea5c7e6f6..7d16bed853 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py
@@ -771,6 +771,14 @@ def test_java_array(self):
assert il == [1, 2, 3] # unchanged
+ def test_dir(self):
+ from java.util import ArrayList
+
+ l = ArrayList()
+ self.assertIn('addAll', dir(l)) # a Java method
+ self.assertIn('extend', dir(l)) # a Python method
+ self.assertEqual(sorted(dir(l)), dir(l))
+
def test_java_list(self):
from java.util import ArrayList
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
index 078ffd4076..f245425f3a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java
@@ -46,15 +46,21 @@
import com.oracle.graal.python.builtins.PythonBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
+import com.oracle.graal.python.builtins.objects.list.ListBuiltins;
+import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
import com.oracle.graal.python.builtins.objects.object.ObjectNodes;
+import com.oracle.graal.python.builtins.objects.set.PSet;
+import com.oracle.graal.python.builtins.objects.set.SetNodes;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.SetAttrBuiltinNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
+import com.oracle.graal.python.nodes.builtins.ListNodes;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -68,7 +74,6 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
-import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
@@ -83,6 +88,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.InteropLibrary;
+import com.oracle.truffle.api.interop.InvalidArrayIndexException;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
@@ -268,29 +274,54 @@ static void doDelete(Object object, Object key, @SuppressWarnings("unused") PNon
}
}
- // TODO dir(foreign) should list both foreign object members and attributes from class
@Builtin(name = J___DIR__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
abstract static class DirNode extends PythonUnaryBuiltinNode {
@Specialization
- protected Object doIt(Object object,
+ protected Object doIt(VirtualFrame frame, Object object,
@Bind("this") Node inliningTarget,
@CachedLibrary(limit = "3") InteropLibrary lib,
+ @CachedLibrary(limit = "3") InteropLibrary arrayInterop,
+ @CachedLibrary(limit = "3") InteropLibrary stringInterop,
+ @Cached TruffleString.SwitchEncodingNode switchEncodingNode,
@Cached GilNode gil,
- @Cached InlinedConditionProfile profile) {
+ @Cached InlinedConditionProfile profile,
+ @Cached GetClassNode getClassNode,
+ @Cached TypeBuiltins.DirNode typeDirNode,
+ @Cached SetNodes.AddNode addNode,
+ @Cached(inline = false) ListBuiltins.ListSortNode sortNode,
+ @Cached(inline = false) ListNodes.ConstructListNode constructListNode) {
+ // Inspired by ObjectBuiltins.DirNode
+ var pythonClass = getClassNode.execute(inliningTarget, object);
+ PSet attributes = typeDirNode.execute(frame, pythonClass);
+
if (profile.profile(inliningTarget, lib.hasMembers(object))) {
+ final Object members;
gil.release(true);
try {
- return lib.getMembers(object);
+ members = lib.getMembers(object);
} catch (UnsupportedMessageException e) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw new IllegalStateException("foreign object claims to have members, but does not return them");
+ throw CompilerDirectives.shouldNotReachHere("foreign object claims to have members, but does not return them");
} finally {
gil.acquire();
}
- } else {
- return PFactory.createList(PythonLanguage.get(inliningTarget));
+
+ try {
+ long size = arrayInterop.getArraySize(members);
+ for (int i = 0; i < size; i++) {
+ TruffleString memberString = stringInterop.asTruffleString(arrayInterop.readArrayElement(members, i));
+ memberString = switchEncodingNode.execute(memberString, TS_ENCODING);
+ addNode.execute(frame, attributes, memberString);
+ }
+ } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
+ throw CompilerDirectives.shouldNotReachHere(e);
+ }
}
+
+ // set to sorted list, like in PyObjectDir
+ PList list = constructListNode.execute(frame, attributes);
+ sortNode.execute(frame, list);
+ return list;
}
}
diff --git a/graalpython/lib-graalpython/_sre.py b/graalpython/lib-graalpython/_sre.py
index 316cb8af6f..e0f0be492d 100644
--- a/graalpython/lib-graalpython/_sre.py
+++ b/graalpython/lib-graalpython/_sre.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,9 @@
from sys import maxsize
+# This does not load _polyglot.py (as desired for faster startup), due to AbstractImportNode.importModule(),
+# when the context is not initialized, only looking up builtin modules (and not running their postInitialize()).
+import polyglot
def _check_pos(pos):
if pos > maxsize:
@@ -265,7 +268,7 @@ def __init__(self, pattern, flags):
self.groupindex = {}
self.__indexgroup = {}
else:
- group_names = dir(groups)
+ group_names = polyglot.__keys__(groups)
self.groupindex = _mappingproxy({name: getattr(groups, name) for name in group_names})
self.__indexgroup = {getattr(groups, name): name for name in group_names}
From bad6a4e9ee63a1b7eb3b50ca4576b96078554745 Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Wed, 12 Feb 2025 15:30:37 +0100
Subject: [PATCH 029/512] Also log imports when not using frozen modules
---
.../src/com/oracle/graal/python/builtins/Python3Core.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
index d785ce324b..e488973ee4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java
@@ -1318,6 +1318,8 @@ private void loadFile(TruffleString s, TruffleString prefix, PythonModule mod) {
LOGGER.log(Level.FINE, () -> "import '" + s + "' # ");
return;
}
+
+ LOGGER.log(Level.FINE, () -> "import '" + s + "'");
Supplier getCode = () -> {
Source source = getInternalSource(s, prefix);
return getLanguage().parse(getContext(), source, InputType.FILE, false, 0, false, null, EnumSet.noneOf(FutureFeature.class));
From 387115599b7b272f85ba8c2342b1c165a8ea0a4b Mon Sep 17 00:00:00 2001
From: Benoit Daloze
Date: Wed, 12 Feb 2025 15:49:11 +0100
Subject: [PATCH 030/512] Log files being parsed when --ParserLogFiles is given
* The option used to noop before this commit.
---
.../src/com/oracle/graal/python/PythonLanguage.java | 5 ++++-
.../graal/python/builtins/modules/BuiltinFunctions.java | 4 ++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
index 328fe43789..89417ea024 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java
@@ -312,7 +312,7 @@ private static boolean mimeTypesComplete(ArrayList mimeJavaStrings) {
public static final TruffleString[] T_DEFAULT_PYTHON_EXTENSIONS = new TruffleString[]{T_PY_EXTENSION, tsLiteral(".pyc")};
- private static final TruffleLogger LOGGER = TruffleLogger.getLogger(ID, PythonLanguage.class);
+ public static final TruffleLogger LOGGER = TruffleLogger.getLogger(ID, PythonLanguage.class);
private static final LanguageReference REFERENCE = LanguageReference.create(PythonLanguage.class);
@@ -671,6 +671,9 @@ public RootCallTarget parse(PythonContext context, Source source, InputType type
EnumSet futureFeatures) {
RaisePythonExceptionErrorCallback errorCb = new RaisePythonExceptionErrorCallback(source, PythonOptions.isPExceptionWithJavaStacktrace(this));
try {
+ if (context.getEnv().getOptions().get(PythonOptions.ParserLogFiles)) {
+ LOGGER.log(Level.FINE, () -> "parse '" + source.getName() + "'");
+ }
Parser parser = Compiler.createParser(source.getCharacters().toString(), errorCb, type, interactiveTerminal);
ModTy mod = (ModTy) parser.parse();
assert mod != null;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 116d0aac2c..b95cf26761 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -109,6 +109,7 @@
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
+import java.util.logging.Level;
import com.oracle.graal.python.PythonFileDetector;
import com.oracle.graal.python.PythonLanguage;
@@ -1079,6 +1080,9 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
if (featureVersion < 7) {
compilerFlags.add(AbstractParser.Flags.ASYNC_HACKS);
}
+ if (context.getEnv().getOptions().get(PythonOptions.ParserLogFiles)) {
+ PythonLanguage.LOGGER.log(Level.FINE, () -> "parse '" + source.getName() + "'");
+ }
Parser parser = Compiler.createParser(code.toJavaStringUncached(), errorCb, type, compilerFlags, featureVersion);
ModTy mod = (ModTy) parser.parse();
errorCb.triggerDeprecationWarnings();
From cf1d996c59d1a8c65ea74e1b8f42e0e26909bdba Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Tue, 18 Feb 2025 14:08:35 +0100
Subject: [PATCH 031/512] Implement nb_inplace_power
---
.../oracle/graal/python/annotations/Slot.java | 2 +
.../graal/python/processor/SlotsMapping.java | 3 +-
.../src/tests/cpyext/test_tp_slots.py | 7 +-
.../cext/PythonCextAbstractBuiltins.java | 23 +----
.../objects/cext/capi/PyProcsWrapper.java | 53 +++++++++-
.../objects/cext/capi/SlotMethodDef.java | 21 +---
.../objects/cext/capi/ToNativeTypeNode.java | 13 +--
.../python/builtins/objects/type/TpSlots.java | 13 +++
.../objects/type/slots/TpSlotNbPower.java | 37 +++++++
.../graal/python/lib/CallTernaryIOpNode.java | 85 ++++++++++++++++
.../python/lib/PyNumberInPlacePowerNode.java | 98 +++++++++++++++++++
.../nodes/bytecode/PBytecodeRootNode.java | 4 +-
12 files changed, 302 insertions(+), 57 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryIOpNode.java
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
index dc664b5a35..20e7d98081 100644
--- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
+++ b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java
@@ -161,6 +161,8 @@ enum SlotKind {
nb_inplace_true_divide("__itruediv__"),
/** foo @= bar */
nb_inplace_matrix_multiply("__imatmul__"),
+ /** foo **= bar */
+ nb_inplace_power("__ipow__"),
/** sequence length/size */
sq_length("__len__"),
/** sequence item: read element at index */
diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
index 4b75ede981..7f4296fcbf 100644
--- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
+++ b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java
@@ -62,6 +62,7 @@ static String getSlotBaseClass(Slot s) {
sq_inplace_concat ->
"TpSlotBinaryOp.TpSlotBinaryIOpBuiltin";
case nb_power -> "TpSlotNbPower.TpSlotNbPowerBuiltin";
+ case nb_inplace_power -> null; // No builtin implementations
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
case sq_item, sq_repeat, sq_inplace_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
@@ -83,7 +84,7 @@ static String getSlotNodeBaseClass(Slot s) {
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
"com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
- case nb_power -> "com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode";
+ case nb_power, nb_inplace_power -> "com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode";
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
case nb_inplace_add, nb_inplace_subtract, nb_inplace_multiply, nb_inplace_remainder,
nb_inplace_lshift, nb_inplace_rshift, nb_inplace_and, nb_inplace_xor, nb_inplace_or,
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
index edf344dedf..294a870f26 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_tp_slots.py
@@ -1210,10 +1210,9 @@ def __rmatmul__(self, other):
obj = NativeNbSlotProxy(PureSlotProxy(3))
obj %= 2
assert obj.delegate.delegate == 1
- # TODO fix on graalpy
- # obj = NativeNbSlotProxy(PureSlotProxy(3))
- # obj **= 2
- # assert obj.delegate.delegate == 9
+ obj = NativeNbSlotProxy(PureSlotProxy(3))
+ obj **= 2
+ assert obj.delegate.delegate == 9
obj = NativeNbSlotProxy(PureSlotProxy(3))
obj <<= 2
assert obj.delegate.delegate == 12
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 32e7520017..d7e831dc6b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -79,7 +79,6 @@
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode;
-import com.oracle.graal.python.builtins.objects.cext.capi.PrimitiveNativeWrapper;
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CStringWrapper;
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
import com.oracle.graal.python.builtins.objects.dict.DictBuiltins.ItemsNode;
@@ -103,6 +102,7 @@
import com.oracle.graal.python.lib.PyIterCheckNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
import com.oracle.graal.python.lib.PyNumberFloatNode;
+import com.oracle.graal.python.lib.PyNumberInPlacePowerNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
import com.oracle.graal.python.lib.PyNumberLongNode;
import com.oracle.graal.python.lib.PyNumberPowerNode;
@@ -126,7 +126,6 @@
import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
import com.oracle.graal.python.nodes.builtins.ListNodes.ConstructListNode;
import com.oracle.graal.python.nodes.call.CallNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
@@ -146,7 +145,6 @@
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
-import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -428,27 +426,16 @@ private static InplaceArithmetic getInplaceArithmetic(int op) {
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Direct)
abstract static class PyNumber_InPlacePower extends CApiTernaryBuiltinNode {
- @Specialization(guards = {"o1.isIntLike()", "o2.isIntLike()", "o3.isIntLike()"})
- static Object doIntLikePrimitiveWrapper(PrimitiveNativeWrapper o1, PrimitiveNativeWrapper o2, PrimitiveNativeWrapper o3,
- @Shared @Cached("createIPow()") LookupAndCallInplaceNode callNode) {
- return callNode.executeTernary(null, o1.getLong(), o2.getLong(), o3.getLong());
- }
-
- @Specialization(replaces = "doIntLikePrimitiveWrapper")
+ @Specialization
static Object doGeneric(Object o1, Object o2, Object o3,
- @Shared @Cached("createIPow()") LookupAndCallInplaceNode callNode) {
- return callNode.executeTernary(null, o1, o2, o3);
- }
-
- @NeverDefault
- static LookupAndCallInplaceNode createIPow() {
- return InplaceArithmetic.IPow.create();
+ @Bind Node inliningTarget,
+ @Cached PyNumberInPlacePowerNode powerNode) {
+ return powerNode.execute(null, inliningTarget, o1, o2, o3);
}
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Direct)
abstract static class PyNumber_Power extends CApiTernaryBuiltinNode {
- @Child private LookupAndCallTernaryNode callNode;
@Specialization
Object doGeneric(Object o1, Object o2, Object o3,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
index 5d97a74122..826b572f0f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java
@@ -65,7 +65,8 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CallSlotNbBoolNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.CallSlotLenNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.CallSlotMpAssSubscriptNode;
-import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower.CallSlotNbInPlacePowerNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower.CallSlotNbPowerNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.CallManagedSlotSetAttrNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.CallSlotSizeArgFun;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.CallSlotSqAssItemNode;
@@ -827,7 +828,7 @@ static Object execute(NbPowerWrapper self, Object[] arguments,
@Cached GetClassNode wGetClassNode,
@Cached IsSameTypeNode isSameTypeNode,
@Cached GetCachedTpSlotsNode wGetSlots,
- @Cached TpSlotNbPower.CallSlotNbPowerNode callSlot,
+ @Cached CallSlotNbPowerNode callSlot,
@Cached GilNode gil) {
boolean mustRelease = gil.acquire();
CApiTiming.enter();
@@ -861,6 +862,54 @@ protected String getSignature() {
}
}
+ @ExportLibrary(InteropLibrary.class)
+ public static final class NbInPlacePowerWrapper extends TpSlotWrapper {
+
+ public NbInPlacePowerWrapper(TpSlotManaged delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public TpSlotWrapper cloneWith(TpSlotManaged slot) {
+ return new NbInPlacePowerWrapper(slot);
+ }
+
+ @ExportMessage
+ static Object execute(NbInPlacePowerWrapper self, Object[] arguments,
+ @Bind("$node") Node inliningTarget,
+ @Cached NativeToPythonNode toJavaNode,
+ @Cached PythonToNativeNewRefNode toNativeNode,
+ @Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
+ @Cached CallSlotNbInPlacePowerNode callSlot,
+ @Cached GilNode gil) {
+ boolean mustRelease = gil.acquire();
+ CApiTiming.enter();
+ try {
+ try {
+ // convert args
+ Object v = toJavaNode.execute(arguments[0]);
+ Object w = toJavaNode.execute(arguments[1]);
+ Object z = toJavaNode.execute(arguments[2]);
+ Object result = callSlot.execute(null, inliningTarget, self.getSlot(), v, w, z);
+ return toNativeNode.execute(result);
+ } catch (Throwable t) {
+ throw checkThrowableBeforeNative(t, "NbInPlacePowerWrapper", self.getDelegate());
+ }
+ } catch (PException e) {
+ transformExceptionToNativeNode.execute(inliningTarget, e);
+ return PythonContext.get(gil).getNativeNull();
+ } finally {
+ CApiTiming.exit(self.timing);
+ gil.release(mustRelease);
+ }
+ }
+
+ @Override
+ protected String getSignature() {
+ return "(POINTER,POINTER,POINTER):POINTER";
+ }
+ }
+
@ExportLibrary(InteropLibrary.class)
public static final class RichcmpFunctionWrapper extends PyProcsWrapper {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
index 53f05294b0..2b87b1cbdf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/SlotMethodDef.java
@@ -43,8 +43,6 @@
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_aiter;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_anext;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyAsyncMethods__am_await;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyNumberMethods__nb_inplace_power;
-import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_as_number;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_call;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_hash;
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_init;
@@ -59,7 +57,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INIT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEXT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REPR__;
@@ -89,12 +86,10 @@ public enum SlotMethodDef {
AM_AWAIT(PyAsyncMethods__am_await, T___AWAIT__, UnaryFuncLegacyWrapper::new, MethodsFlags.AM_AWAIT),
AM_AITER(PyAsyncMethods__am_aiter, T___AITER__, UnaryFuncLegacyWrapper::new, MethodsFlags.AM_AITER),
- AM_ANEXT(PyAsyncMethods__am_anext, T___ANEXT__, PyProcsWrapper.UnaryFuncLegacyWrapper::new, MethodsFlags.AM_ANEXT),
+ AM_ANEXT(PyAsyncMethods__am_anext, T___ANEXT__, PyProcsWrapper.UnaryFuncLegacyWrapper::new, MethodsFlags.AM_ANEXT);
// (mq) AM_SEND is an internal function and mostly called from within AWAIT, AITER, ANEXT.
/*- AM_SEND(PyAsyncMethods__am_send, ASYNC_AM_SEND, CallFunctionWrapper::new, MethodsFlags.AM_SEND), */
- NB_INPLACE_POWER(PyNumberMethods__nb_inplace_power, T___IPOW__, CallFunctionWrapper::new, MethodsFlags.NB_INPLACE_POWER);
-
public final TruffleString methodName;
public final Function wrapperFactory;
public final long methodFlag;
@@ -122,18 +117,4 @@ public enum SlotMethodDef {
this.wrapperFactory = wrapperFactory;
this.methodFlag = methodFlag;
}
-
- static {
- initGroup(
- PyTypeObject__tp_as_number,
- NB_INPLACE_POWER);
- }
-
- private static void initGroup(CFields typeField, SlotMethodDef... slots) {
- for (SlotMethodDef slot : slots) {
- assert slot.methodsField == null && slot.typeField != null;
- slot.methodsField = slot.typeField;
- slot.typeField = typeField;
- }
- }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
index 14f79c2106..20bd1161a8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java
@@ -116,10 +116,6 @@ private static boolean hasAsyncMethods(PythonManagedClass obj) {
return (obj.getMethodsFlags() & MethodsFlags.ASYNC_METHODS) != 0;
}
- private static boolean hasSequenceMethods(PythonManagedClass obj) {
- return (obj.getMethodsFlags() & MethodsFlags.SEQUENCE_METHODS) != 0;
- }
-
private static Object allocatePyAsyncMethods(PythonManagedClass obj, Object nullValue) {
Object mem = CStructAccess.AllocateNode.allocUncached(CStructs.PyAsyncMethods);
CStructAccess.WritePointerNode writePointerNode = CStructAccess.WritePointerNode.getUncached();
@@ -145,13 +141,10 @@ private static Object allocatePyMappingMethods(TpSlots slots, Object nullValue)
return mem;
}
- private static Object allocatePyNumberMethods(PythonManagedClass obj, TpSlots slots, Object nullValue) {
+ private static Object allocatePyNumberMethods(TpSlots slots, Object nullValue) {
Object mem = CStructAccess.AllocateNode.allocUncached(CStructs.PyNumberMethods);
CStructAccess.WritePointerNode writePointerNode = CStructAccess.WritePointerNode.getUncached();
-
writeGroupSlots(CFields.PyTypeObject__tp_as_number, slots, writePointerNode, mem, nullValue);
-
- writePointerNode.write(mem, CFields.PyNumberMethods__nb_inplace_power, getSlot(obj, SlotMethodDef.NB_INPLACE_POWER));
return mem;
}
@@ -239,8 +232,8 @@ static void initializeType(PythonClassNativeWrapper obj, Object mem, boolean hea
weaklistoffset = lookupNativeI64MemberInMRO(clazz, PyTypeObject__tp_weaklistoffset, SpecialAttributeNames.T___WEAKLISTOFFSET__);
}
Object asAsync = hasAsyncMethods(clazz) ? allocatePyAsyncMethods(clazz, nullValue) : nullValue;
- Object asNumber = IsBuiltinClassExactProfile.profileClassSlowPath(clazz, PythonBuiltinClassType.PythonObject) ? nullValue : allocatePyNumberMethods(clazz, slots, nullValue);
- Object asSequence = (slots.has_as_sequence() || hasSequenceMethods(clazz)) ? allocatePySequenceMethods(slots, nullValue) : nullValue;
+ Object asNumber = slots.has_as_number() ? allocatePyNumberMethods(slots, nullValue) : nullValue;
+ Object asSequence = slots.has_as_sequence() ? allocatePySequenceMethods(slots, nullValue) : nullValue;
Object asMapping = slots.has_as_mapping() ? allocatePyMappingMethods(slots, nullValue) : nullValue;
Object asBuffer = lookup(clazz, PyTypeObject__tp_as_buffer, HiddenAttr.AS_BUFFER);
writeI64Node.write(mem, CFields.PyTypeObject__tp_weaklistoffset, weaklistoffset);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
index aeb3a22d75..b5901965ba 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java
@@ -65,6 +65,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INVERT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
@@ -127,6 +128,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.GetAttrWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.InquiryWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.LenfuncWrapper;
+import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.NbInPlacePowerWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.NbPowerWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.ObjobjargWrapper;
import com.oracle.graal.python.builtins.objects.cext.capi.PyProcsWrapper.SetattrWrapper;
@@ -288,6 +290,7 @@ public record TpSlots(TpSlot nb_bool, //
TpSlot nb_inplace_floor_divide, //
TpSlot nb_inplace_true_divide, //
TpSlot nb_inplace_matrix_multiply, //
+ TpSlot nb_inplace_power, //
TpSlot sq_length, //
TpSlot sq_item, //
TpSlot sq_ass_item, //
@@ -677,6 +680,14 @@ public enum TpSlotMeta {
CFields.PyNumberMethods__nb_inplace_matrix_multiply,
PExternalFunctionWrapper.BINARYFUNC,
BinarySlotFuncWrapper::new),
+ NB_INPLACE_POWER(
+ TpSlots::nb_inplace_power,
+ TpSlotPythonSingle.class,
+ null, // No builtin implementations
+ TpSlotGroup.AS_NUMBER,
+ CFields.PyNumberMethods__nb_inplace_power,
+ PExternalFunctionWrapper.TERNARYFUNC,
+ NbInPlacePowerWrapper::new),
SQ_LENGTH(
TpSlots::sq_length,
TpSlotPythonSingle.class,
@@ -1038,6 +1049,7 @@ private static void addSlotDef(LinkedHashMap defs, TpSl
addSlotDef(s, TpSlotMeta.NB_INPLACE_FLOOR_DIVIDE, TpSlotDef.withSimpleFunction(T___IFLOORDIV__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_TRUE_DIVIDE, TpSlotDef.withSimpleFunction(T___ITRUEDIV__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INPLACE_MATRIX_MULTIPLY, TpSlotDef.withSimpleFunction(T___IMATMUL__, PExternalFunctionWrapper.BINARYFUNC, HPySlotWrapper.BINARYFUNC));
+ addSlotDef(s, TpSlotMeta.NB_INPLACE_POWER, TpSlotDef.withSimpleFunction(T___IPOW__, PExternalFunctionWrapper.TERNARYFUNC));
addSlotDef(s, TpSlotMeta.NB_BOOL, TpSlotDef.withSimpleFunction(T___BOOL__, PExternalFunctionWrapper.INQUIRY));
addSlotDef(s, TpSlotMeta.NB_INDEX, TpSlotDef.withSimpleFunction(T___INDEX__, PExternalFunctionWrapper.UNARYFUNC));
addSlotDef(s, TpSlotMeta.NB_INT, TpSlotDef.withSimpleFunction(T___INT__, PExternalFunctionWrapper.UNARYFUNC));
@@ -1679,6 +1691,7 @@ public TpSlots build() {
get(TpSlotMeta.NB_INPLACE_FLOOR_DIVIDE), //
get(TpSlotMeta.NB_INPLACE_TRUE_DIVIDE), //
get(TpSlotMeta.NB_INPLACE_MATRIX_MULTIPLY), //
+ get(TpSlotMeta.NB_INPLACE_POWER), //
get(TpSlotMeta.SQ_LENGTH), //
get(TpSlotMeta.SQ_ITEM), //
get(TpSlotMeta.SQ_ASS_ITEM), //
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
index 0272498c35..ee5344f50f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java
@@ -41,6 +41,7 @@
package com.oracle.graal.python.builtins.objects.type.slots;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___POW__;
+import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
import com.oracle.graal.python.PythonLanguage;
@@ -58,9 +59,11 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.NodeFactoryUtils.WrapperNodeFactory;
+import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.BinaryPythonSlotDispatcherNode;
import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.TernaryPythonSlotDispatcherNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltin;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotCExtNative;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotPythonSingle;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.CallReversiblePythonSlotNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.TpSlotReversiblePython;
@@ -227,4 +230,38 @@ static Object callPythonAsTernary(VirtualFrame frame, TpSlotReversiblePython slo
return PNotImplemented.NOT_IMPLEMENTED;
}
}
+
+ @GenerateInline
+ @GenerateCached(false)
+ @GenerateUncached
+ public abstract static class CallSlotNbInPlacePowerNode extends Node {
+ private static final CApiTiming C_API_TIMING = CApiTiming.create(true, "ternaryfunc");
+
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, TpSlot slot, Object v, Object w, Object z);
+
+ // There are no builtin implementations
+
+ @Specialization
+ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotPythonSingle slot, Object v, Object w, @SuppressWarnings("unused") Object z,
+ @Cached BinaryPythonSlotDispatcherNode dispatcherNode) {
+ // CPython doesn't pass the third argument to __ipow__
+ return dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.getType(), v, w);
+ }
+
+ @Specialization
+ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object v, Object w, Object z,
+ @Cached GetThreadStateNode getThreadStateNode,
+ @Cached(inline = false) PythonToNativeNode vToNative,
+ @Cached(inline = false) PythonToNativeNode wToNative,
+ @Cached(inline = false) PythonToNativeNode zToNative,
+ @Cached ExternalFunctionInvokeNode externalInvokeNode,
+ @Cached(inline = false) NativeToPythonTransferNode toPythonNode,
+ @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) {
+ PythonContext ctx = PythonContext.get(inliningTarget);
+ PythonContext.PythonThreadState state = getThreadStateNode.execute(inliningTarget, ctx);
+ Object result = externalInvokeNode.call(frame, inliningTarget, state, C_API_TIMING, T___IPOW__, slot.callable,
+ vToNative.execute(v), wToNative.execute(w), zToNative.execute(z));
+ return checkResultNode.execute(state, T___IPOW__, toPythonNode.execute(result));
+ }
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryIOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryIOpNode.java
new file mode 100644
index 0000000000..eda627ab2d
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/CallTernaryIOpNode.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.type.TpSlots;
+import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlot;
+import com.oracle.graal.python.builtins.objects.type.slots.TpSlotNbPower.CallSlotNbInPlacePowerNode;
+import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateCached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline
+@GenerateCached(false)
+@GenerateUncached
+public abstract class CallTernaryIOpNode extends Node {
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z);
+
+ @Specialization
+ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z,
+ @Cached GetClassNode getVClass,
+ @Cached GetClassNode getWClass,
+ @Cached GetCachedTpSlotsNode getVSlots,
+ @Cached GetCachedTpSlotsNode getWSlots,
+ @Cached CallSlotNbInPlacePowerNode callInplacePower,
+ @Cached CallTernaryOpNode callTernaryOpNode) {
+ Object classV = getVClass.execute(inliningTarget, v);
+ TpSlots slotsV = getVSlots.execute(inliningTarget, classV);
+ TpSlot slotV = slotsV.nb_inplace_power();
+ if (slotV != null) {
+ Object result = callInplacePower.execute(frame, inliningTarget, slotV, v, w, z);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
+ }
+ }
+ slotV = slotsV.nb_power();
+ Object classW = getWClass.execute(inliningTarget, w);
+ TpSlot slotW = getWSlots.execute(inliningTarget, classW).nb_power();
+ return callTernaryOpNode.execute(frame, inliningTarget, v, classV, slotV, w, classW, slotW, z);
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
new file mode 100644
index 0000000000..9e9a2776bf
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.lib;
+
+import com.oracle.graal.python.builtins.PythonBuiltinClassType;
+import com.oracle.graal.python.builtins.objects.PNone;
+import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.nodes.ErrorMessages;
+import com.oracle.graal.python.nodes.PRaiseNode;
+import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.runtime.exception.PException;
+import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.Node;
+
+@GenerateInline(inlineByDefault = true)
+@GenerateUncached
+public abstract class PyNumberInPlacePowerNode extends BinaryOpNode {
+
+ public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z);
+
+ @Override
+ public final Object execute(VirtualFrame frame, Object left, Object right) {
+ return executeCached(frame, left, right, PNone.NONE);
+ }
+
+ public final Object executeCached(VirtualFrame frame, Object v, Object w, Object z) {
+ return execute(frame, this, v, w, z);
+ }
+
+ @Specialization
+ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z,
+ @Cached CallTernaryIOpNode callTernaryOpNode,
+ @Cached PRaiseNode raiseNode) {
+ Object result = callTernaryOpNode.execute(frame, inliningTarget, v, w, z);
+ if (result != PNotImplemented.NOT_IMPLEMENTED) {
+ return result;
+ }
+ return raiseNotSupported(inliningTarget, v, w, z, raiseNode);
+ }
+
+ @InliningCutoff
+ private static PException raiseNotSupported(Node inliningTarget, Object v, Object w, Object z, PRaiseNode raiseNode) {
+ if (z == PNone.NONE) {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, "**=", v, w);
+ } else {
+ return raiseNode.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, "**=", v, w, z);
+ }
+ }
+
+ @NeverDefault
+ public static PyNumberInPlacePowerNode create() {
+ return PyNumberInPlacePowerNodeGen.create();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index e96afc0875..4564907c50 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -112,6 +112,7 @@
import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlacePowerNode;
import com.oracle.graal.python.lib.PyNumberInplaceAddNode;
import com.oracle.graal.python.lib.PyNumberInplaceAndNode;
import com.oracle.graal.python.lib.PyNumberInplaceFloorDivideNode;
@@ -195,7 +196,6 @@
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
import com.oracle.graal.python.nodes.expression.BinaryOp;
import com.oracle.graal.python.nodes.expression.ContainsNode;
-import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.frame.DeleteGlobalNode;
import com.oracle.graal.python.nodes.frame.DeleteGlobalNodeGen;
@@ -485,7 +485,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
case BinaryOpsConstants.INPLACE_XOR:
return PyNumberInplaceXorNode.create();
case BinaryOpsConstants.INPLACE_POW:
- return InplaceArithmetic.IPow.create();
+ return PyNumberInPlacePowerNode.create();
case BinaryOpsConstants.INPLACE_MATMUL:
return PyNumberInplaceMatrixMultiplyNode.create();
case BinaryOpsConstants.EQ:
From 3d5ec84bac68b25e85c9fbb8ba12764858242fa2 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Tue, 18 Feb 2025 15:14:04 +0100
Subject: [PATCH 032/512] Remove use of NaryArithmetic enums from C API
---
.../src/abstract.c | 268 +++++------
.../builtins/modules/BuiltinFunctions.java | 2 +-
.../modules/OperatorModuleBuiltins.java | 8 +-
.../cext/PythonCextAbstractBuiltins.java | 436 ++++++++++++------
.../objects/cext/capi/CApiFunction.java | 27 --
.../cext/hpy/GraalHPyArithmeticNode.java | 2 +-
.../foreign/ForeignNumberBuiltins.java | 2 +-
.../objects/object/ObjectBuiltins.java | 5 +-
...dNode.java => PyNumberInPlaceAddNode.java} | 6 +-
...dNode.java => PyNumberInPlaceAndNode.java} | 6 +-
...va => PyNumberInPlaceFloorDivideNode.java} | 6 +-
...de.java => PyNumberInPlaceLshiftNode.java} | 6 +-
...=> PyNumberInPlaceMatrixMultiplyNode.java} | 6 +-
....java => PyNumberInPlaceMultiplyNode.java} | 6 +-
...OrNode.java => PyNumberInPlaceOrNode.java} | 6 +-
...java => PyNumberInPlaceRemainderNode.java} | 6 +-
...de.java => PyNumberInPlaceRshiftNode.java} | 6 +-
....java => PyNumberInPlaceSubtractNode.java} | 6 +-
...ava => PyNumberInPlaceTrueDivideNode.java} | 6 +-
...rNode.java => PyNumberInPlaceXorNode.java} | 6 +-
.../graal/python/lib/PyObjectIsTrueNode.java | 8 +-
...eConcat.java => PySequenceConcatNode.java} | 2 +-
....java => PySequenceInPlaceConcatNode.java} | 2 +-
....java => PySequenceInPlaceRepeatNode.java} | 2 +-
.../bytecode/NotNode.java} | 18 +-
.../nodes/bytecode/PBytecodeRootNode.java | 53 ++-
.../nodes/expression/UnaryArithmetic.java | 9 +-
.../python/nodes/expression/UnaryOpNode.java | 2 +-
28 files changed, 490 insertions(+), 428 deletions(-)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceAddNode.java => PyNumberInPlaceAddNode.java} (96%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceAndNode.java => PyNumberInPlaceAndNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceFloorDivideNode.java => PyNumberInPlaceFloorDivideNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceLshiftNode.java => PyNumberInPlaceLshiftNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceMatrixMultiplyNode.java => PyNumberInPlaceMatrixMultiplyNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceMultiplyNode.java => PyNumberInPlaceMultiplyNode.java} (96%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceOrNode.java => PyNumberInPlaceOrNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceRemainderNode.java => PyNumberInPlaceRemainderNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceRshiftNode.java => PyNumberInPlaceRshiftNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceSubtractNode.java => PyNumberInPlaceSubtractNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceTrueDivideNode.java => PyNumberInPlaceTrueDivideNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PyNumberInplaceXorNode.java => PyNumberInPlaceXorNode.java} (94%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PySequenceConcat.java => PySequenceConcatNode.java} (99%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PySequenceInplaceConcat.java => PySequenceInPlaceConcatNode.java} (98%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/{PySequenceInplaceRepeat.java => PySequenceInPlaceRepeatNode.java} (98%)
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/{lib/PyObjectIsNotTrueNode.java => nodes/bytecode/NotNode.java} (91%)
diff --git a/graalpython/com.oracle.graal.python.cext/src/abstract.c b/graalpython/com.oracle.graal.python.cext/src/abstract.c
index de966ccf55..2437c8433f 100644
--- a/graalpython/com.oracle.graal.python.cext/src/abstract.c
+++ b/graalpython/com.oracle.graal.python.cext/src/abstract.c
@@ -22,37 +22,6 @@
#include // offsetof()
-// GraalPy-specific
-typedef enum e_binop {
- ADD=0, SUB, MUL, TRUEDIV, LSHIFT, RSHIFT, OR, AND, XOR, FLOORDIV, MOD,
- INPLACE_OFFSET, MATRIX_MUL
-} BinOp;
-
-// GraalPy-specific
-typedef enum e_unaryop {
- POS=0, NEG, INVERT
-} UnaryOp;
-
-// GraalPy-specific
-static PyObject *
-do_unaryop(PyObject *v, UnaryOp unaryop)
-{
- return GraalPyTruffleNumber_UnaryOp(v, (int) unaryop);
-}
-
-// GraalPy-specific
-MUST_INLINE static PyObject *
-do_binop(PyObject *v, PyObject *w, BinOp binop)
-{
- return GraalPyTruffleNumber_BinOp(v, w, (int) binop);
-}
-
-// GraalPy-specific
-MUST_INLINE static PyObject *
-do_inplace_binop(PyObject *v, PyObject *w, BinOp binop)
-{
- return GraalPyTruffleNumber_InPlaceBinOp(v, w, (int) binop);
-}
/* Shorthands to return certain errors */
@@ -1117,16 +1086,26 @@ BINARY_FUNC(PyNumber_Lshift, nb_lshift, "<<")
BINARY_FUNC(PyNumber_Rshift, nb_rshift, ">>")
BINARY_FUNC(PyNumber_Subtract, nb_subtract, "-")
BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
-#endif // GraalPy change
PyObject *
PyNumber_Add(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, ADD);
+ PyObject *result = BINARY_OP1(v, w, NB_SLOT(nb_add), "+");
+ if (result != Py_NotImplemented) {
+ return result;
+ }
+ Py_DECREF(result);
+
+ PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence;
+ if (m && m->sq_concat) {
+ result = (*m->sq_concat)(v, w);
+ assert(_Py_CheckSlotResult(v, "+", result != NULL));
+ return result;
+ }
+
+ return binop_type_error(v, w, "+");
}
-#if 0 // GraalPy change
static PyObject *
sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
{
@@ -1145,44 +1124,50 @@ sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
assert(_Py_CheckSlotResult(seq, "*", res != NULL));
return res;
}
-#endif // GraalPy change
PyObject *
PyNumber_Multiply(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, MUL);
+ PyObject *result = BINARY_OP1(v, w, NB_SLOT(nb_multiply), "*");
+ if (result == Py_NotImplemented) {
+ PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence;
+ PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence;
+ Py_DECREF(result);
+ if (mv && mv->sq_repeat) {
+ return sequence_repeat(mv->sq_repeat, v, w);
+ }
+ else if (mw && mw->sq_repeat) {
+ return sequence_repeat(mw->sq_repeat, w, v);
+ }
+ result = binop_type_error(v, w, "*");
+ }
+ return result;
}
PyObject *
PyNumber_MatrixMultiply(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, MATRIX_MUL);
+ return binary_op(v, w, NB_SLOT(nb_matrix_multiply), "@");
}
PyObject *
PyNumber_FloorDivide(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, FLOORDIV);
+ return binary_op(v, w, NB_SLOT(nb_floor_divide), "//");
}
PyObject *
PyNumber_TrueDivide(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, TRUEDIV);
+ return binary_op(v, w, NB_SLOT(nb_true_divide), "/");
}
PyObject *
PyNumber_Remainder(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_binop(v, w, MOD);
+ return binary_op(v, w, NB_SLOT(nb_remainder), "%");
}
-#if 0 // GraalPy change
PyObject *
PyNumber_Power(PyObject *v, PyObject *w, PyObject *z)
{
@@ -1289,23 +1274,59 @@ INPLACE_BINOP(PyNumber_InPlaceMatrixMultiply, nb_inplace_matrix_multiply, nb_mat
INPLACE_BINOP(PyNumber_InPlaceFloorDivide, nb_inplace_floor_divide, nb_floor_divide, "//=")
INPLACE_BINOP(PyNumber_InPlaceTrueDivide, nb_inplace_true_divide, nb_true_divide, "/=")
INPLACE_BINOP(PyNumber_InPlaceRemainder, nb_inplace_remainder, nb_remainder, "%=")
-#endif // GraalPy change
PyObject *
PyNumber_InPlaceAdd(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_inplace_binop(v, w, ADD);
+ PyObject *result = BINARY_IOP1(v, w, NB_SLOT(nb_inplace_add),
+ NB_SLOT(nb_add), "+=");
+ if (result == Py_NotImplemented) {
+ PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence;
+ Py_DECREF(result);
+ if (m != NULL) {
+ binaryfunc func = m->sq_inplace_concat;
+ if (func == NULL)
+ func = m->sq_concat;
+ if (func != NULL) {
+ result = func(v, w);
+ assert(_Py_CheckSlotResult(v, "+=", result != NULL));
+ return result;
+ }
+ }
+ result = binop_type_error(v, w, "+=");
+ }
+ return result;
}
PyObject *
PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
{
- // GraalPy change: different implementation
- return do_inplace_binop(v, w, MUL);
+ PyObject *result = BINARY_IOP1(v, w, NB_SLOT(nb_inplace_multiply),
+ NB_SLOT(nb_multiply), "*=");
+ if (result == Py_NotImplemented) {
+ ssizeargfunc f = NULL;
+ PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence;
+ PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence;
+ Py_DECREF(result);
+ if (mv != NULL) {
+ f = mv->sq_inplace_repeat;
+ if (f == NULL)
+ f = mv->sq_repeat;
+ if (f != NULL)
+ return sequence_repeat(f, v, w);
+ }
+ else if (mw != NULL) {
+ /* Note that the right hand operand should not be
+ * mutated in this case so sq_inplace_repeat is not
+ * used. */
+ if (mw->sq_repeat)
+ return sequence_repeat(mw->sq_repeat, w, v);
+ }
+ result = binop_type_error(v, w, "*=");
+ }
+ return result;
}
-# if 0 // GraalPy change
PyObject *
PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z)
{
@@ -1318,7 +1339,6 @@ _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs)
{
return PyNumber_InPlacePower(lhs, rhs, Py_None);
}
-#endif // GraalPy change
/* Unary operators and functions */
@@ -1326,25 +1346,54 @@ _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs)
PyObject *
PyNumber_Negative(PyObject *o)
{
- // GraalPy change: different implementation
- return do_unaryop(o, NEG);
+ if (o == NULL) {
+ return null_error();
+ }
+
+ PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ if (m && m->nb_negative) {
+ PyObject *res = (*m->nb_negative)(o);
+ assert(_Py_CheckSlotResult(o, "__neg__", res != NULL));
+ return res;
+ }
+
+ return type_error("bad operand type for unary -: '%.200s'", o);
}
PyObject *
PyNumber_Positive(PyObject *o)
{
- // GraalPy change: different implementation
- return do_unaryop(o, POS);
+ if (o == NULL) {
+ return null_error();
+ }
+
+ PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ if (m && m->nb_positive) {
+ PyObject *res = (*m->nb_positive)(o);
+ assert(_Py_CheckSlotResult(o, "__pos__", res != NULL));
+ return res;
+ }
+
+ return type_error("bad operand type for unary +: '%.200s'", o);
}
PyObject *
PyNumber_Invert(PyObject *o)
{
- // GraalPy change: different implementation
- return do_unaryop(o, INVERT);
+ if (o == NULL) {
+ return null_error();
+ }
+
+ PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ if (m && m->nb_invert) {
+ PyObject *res = (*m->nb_invert)(o);
+ assert(_Py_CheckSlotResult(o, "__invert__", res != NULL));
+ return res;
+ }
+
+ return type_error("bad operand type for unary ~: '%.200s'", o);
}
-# if 0 // GraalPy change
PyObject *
PyNumber_Absolute(PyObject *o)
{
@@ -2964,103 +3013,6 @@ _Py_FreeCharPArray(char *const array[])
}
#endif // GraalPy change
-// GraalPy note: The following functions are declared in CPython via macros, so we declare them separate here
-PyObject *
-PyNumber_Subtract(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, SUB);
-}
-
-PyObject *
-PyNumber_Lshift(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, LSHIFT);
-}
-
-PyObject *
-PyNumber_Rshift(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, RSHIFT);
-}
-
-PyObject *
-PyNumber_Or(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, OR);
-}
-
-PyObject *
-PyNumber_And(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, AND);
-}
-
-PyObject *
-PyNumber_Xor(PyObject *v, PyObject *w)
-{
- return do_binop(v, w, XOR);
-}
-
-PyObject *
-PyNumber_InPlaceSubtract(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, SUB);
-}
-
-PyObject *
-PyNumber_InPlaceMatrixMultiply(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, MATRIX_MUL);
-}
-
-PyObject *
-PyNumber_InPlaceFloorDivide(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, FLOORDIV);
-}
-
-PyObject *
-PyNumber_InPlaceTrueDivide(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, TRUEDIV);
-}
-
-PyObject*
-PyNumber_InPlaceRemainder(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, MOD);
-}
-
-PyObject*
-PyNumber_InPlaceLshift(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, LSHIFT);
-}
-
-PyObject*
-PyNumber_InPlaceRshift(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, RSHIFT);
-}
-
-PyObject*
-PyNumber_InPlaceAnd(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, AND);
-}
-
-PyObject*
-PyNumber_InPlaceXor(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, XOR);
-}
-
-PyObject*
-PyNumber_InPlaceOr(PyObject *v, PyObject *w)
-{
- return do_inplace_binop(v, w, OR);
-}
-
// GraalPy additions
PyObject **
PyTruffleSequence_Fast_ITEMS(PyObject *o)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index b95cf26761..252a9e6740 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -333,7 +333,7 @@ public abstract static class AbsNode extends PythonUnaryBuiltinNode {
@Specialization
static Object absObject(VirtualFrame frame, Object object,
@Cached PyNumberAbsoluteNode absoluteNode) {
- return absoluteNode.executeCached(frame, object);
+ return absoluteNode.execute(frame, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
index cb467297d7..15921a5507 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
@@ -54,8 +54,8 @@
import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
-import com.oracle.graal.python.lib.PySequenceConcat;
-import com.oracle.graal.python.lib.PySequenceInplaceConcat;
+import com.oracle.graal.python.lib.PySequenceConcatNode;
+import com.oracle.graal.python.lib.PySequenceInPlaceConcatNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -114,7 +114,7 @@ abstract static class ConcatNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doObject(VirtualFrame frame, Object left, Object right,
@Bind("this") Node inliningTarget,
- @Cached PySequenceConcat concatNode) {
+ @Cached PySequenceConcatNode concatNode) {
return concatNode.execute(frame, inliningTarget, left, right);
}
}
@@ -125,7 +125,7 @@ abstract static class IConcatNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doObject(VirtualFrame frame, Object left, Object right,
@Bind("this") Node inliningTarget,
- @Cached PySequenceInplaceConcat concatNode) {
+ @Cached PySequenceInPlaceConcatNode concatNode) {
return concatNode.execute(frame, inliningTarget, left, right);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index d7e831dc6b..56e6b7ef98 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -100,23 +100,50 @@
import com.oracle.graal.python.lib.GetNextNode;
import com.oracle.graal.python.lib.PyIndexCheckNode;
import com.oracle.graal.python.lib.PyIterCheckNode;
+import com.oracle.graal.python.lib.PyNumberAddNode;
+import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
import com.oracle.graal.python.lib.PyNumberFloatNode;
+import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAddNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAndNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceLshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceOrNode;
import com.oracle.graal.python.lib.PyNumberInPlacePowerNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRemainderNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceSubtractNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceXorNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
+import com.oracle.graal.python.lib.PyNumberInvertNode;
import com.oracle.graal.python.lib.PyNumberLongNode;
+import com.oracle.graal.python.lib.PyNumberLshiftNode;
+import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberNegativeNode;
+import com.oracle.graal.python.lib.PyNumberOrNode;
+import com.oracle.graal.python.lib.PyNumberPositiveNode;
import com.oracle.graal.python.lib.PyNumberPowerNode;
+import com.oracle.graal.python.lib.PyNumberRemainderNode;
+import com.oracle.graal.python.lib.PyNumberRshiftNode;
+import com.oracle.graal.python.lib.PyNumberSubtractNode;
+import com.oracle.graal.python.lib.PyNumberTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberXorNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.lib.PySequenceCheckNode;
-import com.oracle.graal.python.lib.PySequenceConcat;
+import com.oracle.graal.python.lib.PySequenceConcatNode;
import com.oracle.graal.python.lib.PySequenceContainsNode;
import com.oracle.graal.python.lib.PySequenceDelItemNode;
import com.oracle.graal.python.lib.PySequenceGetItemNode;
-import com.oracle.graal.python.lib.PySequenceInplaceConcat;
-import com.oracle.graal.python.lib.PySequenceInplaceRepeat;
+import com.oracle.graal.python.lib.PySequenceInPlaceConcatNode;
+import com.oracle.graal.python.lib.PySequenceInPlaceRepeatNode;
import com.oracle.graal.python.lib.PySequenceIterSearchNode;
import com.oracle.graal.python.lib.PySequenceSetItemNode;
import com.oracle.graal.python.lib.PySequenceSizeNode;
@@ -126,12 +153,6 @@
import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode;
import com.oracle.graal.python.nodes.builtins.ListNodes.ConstructListNode;
import com.oracle.graal.python.nodes.call.CallNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
-import com.oracle.graal.python.nodes.expression.LookupAndCallInplaceNode;
-import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
-import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.truffle.PythonTypes;
@@ -288,139 +309,276 @@ static Object doGeneric(Object object,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Int}, call = Ignored)
- abstract static class PyTruffleNumber_UnaryOp extends CApiBinaryBuiltinNode {
- static int MAX_CACHE_SIZE = UnaryArithmetic.values().length;
-
- @Specialization(guards = {"cachedOp == op"}, limit = "MAX_CACHE_SIZE")
- static Object doIntLikePrimitiveWrapper(Object left, @SuppressWarnings("unused") int op,
- @Cached("op") @SuppressWarnings("unused") int cachedOp,
- @Cached("createCallNode(op)") UnaryOpNode callNode) {
- return callNode.executeCached(null, left);
- }
-
- /**
- * This needs to stay in sync with {@code abstract.c: enum e_unaryop}.
- */
- static UnaryOpNode createCallNode(int op) {
- UnaryArithmetic unaryArithmetic;
- switch (op) {
- case 0:
- unaryArithmetic = UnaryArithmetic.Pos;
- break;
- case 1:
- unaryArithmetic = UnaryArithmetic.Neg;
- break;
- case 2:
- unaryArithmetic = UnaryArithmetic.Invert;
- break;
- default:
- throw CompilerDirectives.shouldNotReachHere("invalid unary operator");
- }
- return unaryArithmetic.create();
- }
- }
-
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, Int}, call = Ignored)
- abstract static class PyTruffleNumber_BinOp extends CApiTernaryBuiltinNode {
- static int MAX_CACHE_SIZE = BinaryArithmetic.values().length;
-
- @Specialization(guards = {"cachedOp == op"}, limit = "MAX_CACHE_SIZE")
- static Object doIntLikePrimitiveWrapper(Object left, Object right, @SuppressWarnings("unused") int op,
- @Cached("op") @SuppressWarnings("unused") int cachedOp,
- @Cached("createCallNode(op)") BinaryOpNode callNode) {
- return callNode.execute(null, left, right);
- }
-
- /**
- * This needs to stay in sync with {@code abstract.c: enum e_binop}.
- */
- static BinaryOpNode createCallNode(int op) {
- return getBinaryArithmetic(op).create();
- }
-
- private static BinaryArithmetic getBinaryArithmetic(int op) {
- switch (op) {
- case 0:
- return BinaryArithmetic.Add;
- case 1:
- return BinaryArithmetic.Sub;
- case 2:
- return BinaryArithmetic.Mul;
- case 3:
- return BinaryArithmetic.TrueDiv;
- case 4:
- return BinaryArithmetic.LShift;
- case 5:
- return BinaryArithmetic.RShift;
- case 6:
- return BinaryArithmetic.Or;
- case 7:
- return BinaryArithmetic.And;
- case 8:
- return BinaryArithmetic.Xor;
- case 9:
- return BinaryArithmetic.FloorDiv;
- case 10:
- return BinaryArithmetic.Mod;
- case 12:
- return BinaryArithmetic.MatMul;
- default:
- throw CompilerDirectives.shouldNotReachHere("invalid binary operator");
- }
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
+ abstract static class PyNumber_Positive extends CApiUnaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object obj,
+ @Cached PyNumberPositiveNode positiveNode) {
+ return positiveNode.execute(null, obj);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
+ abstract static class PyNumber_Negative extends CApiUnaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object obj,
+ @Cached PyNumberNegativeNode negativeNode) {
+ return negativeNode.execute(null, obj);
}
+ }
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
+ abstract static class PyNumber_Invert extends CApiUnaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object obj,
+ @Cached PyNumberInvertNode invertNode) {
+ return invertNode.execute(null, obj);
+ }
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, Int}, call = Ignored)
- abstract static class PyTruffleNumber_InPlaceBinOp extends CApiTernaryBuiltinNode {
- static int MAX_CACHE_SIZE = InplaceArithmetic.values().length;
-
- @Specialization(guards = {"cachedOp == op"}, limit = "MAX_CACHE_SIZE")
- static Object doIntLikePrimitiveWrapper(Object left, Object right, @SuppressWarnings("unused") int op,
- @Cached("op") @SuppressWarnings("unused") int cachedOp,
- @Cached("createCallNode(op)") LookupAndCallInplaceNode callNode) {
- return callNode.execute(null, left, right);
- }
-
- /**
- * This needs to stay in sync with {@code abstract.c: enum e_binop}.
- */
- static LookupAndCallInplaceNode createCallNode(int op) {
- return getInplaceArithmetic(op).create();
- }
-
- private static InplaceArithmetic getInplaceArithmetic(int op) {
- switch (op) {
- case 0:
- return InplaceArithmetic.IAdd;
- case 1:
- return InplaceArithmetic.ISub;
- case 2:
- return InplaceArithmetic.IMul;
- case 3:
- return InplaceArithmetic.ITrueDiv;
- case 4:
- return InplaceArithmetic.ILShift;
- case 5:
- return InplaceArithmetic.IRShift;
- case 6:
- return InplaceArithmetic.IOr;
- case 7:
- return InplaceArithmetic.IAnd;
- case 8:
- return InplaceArithmetic.IXor;
- case 9:
- return InplaceArithmetic.IFloorDiv;
- case 10:
- return InplaceArithmetic.IMod;
- case 12:
- return InplaceArithmetic.IMatMul;
- default:
- throw CompilerDirectives.shouldNotReachHere("invalid binary operator");
- }
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Add extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Bind Node inliningTarget,
+ @Cached PyNumberAddNode addNode) {
+ return addNode.execute(null, inliningTarget, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Subtract extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberSubtractNode subtractNode) {
+ return subtractNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Multiply extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Bind Node inliningTarget,
+ @Cached PyNumberMultiplyNode multiplyNode) {
+ return multiplyNode.execute(null, inliningTarget, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Remainder extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberRemainderNode remainderNode) {
+ return remainderNode.execute(null, o1, o2);
}
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_TrueDivide extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberTrueDivideNode trueDivideNode) {
+ return trueDivideNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_FloorDivide extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberFloorDivideNode floorDivideNode) {
+ return floorDivideNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_And extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberAndNode andNode) {
+ return andNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Or extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberOrNode orNode) {
+ return orNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Xor extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberXorNode xorNode) {
+ return xorNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Lshift extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberLshiftNode lshiftNode) {
+ return lshiftNode.execute(null, o1, o2);
+ }
+ }
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_Rshift extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberRshiftNode rshiftNode) {
+ return rshiftNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_MatrixMultiply extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberMatrixMultiplyNode matrixMultiplyNode) {
+ return matrixMultiplyNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceAdd extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceAddNode addNode) {
+ return addNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceSubtract extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceSubtractNode subtractNode) {
+ return subtractNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceMultiply extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceMultiplyNode multiplyNode) {
+ return multiplyNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceRemainder extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceRemainderNode remainderNode) {
+ return remainderNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceTrueDivide extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceTrueDivideNode trueDivideNode) {
+ return trueDivideNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceFloorDivide extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceFloorDivideNode floorDivideNode) {
+ return floorDivideNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceAnd extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceAndNode andNode) {
+ return andNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceOr extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceOrNode orNode) {
+ return orNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceXor extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceXorNode xorNode) {
+ return xorNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceLshift extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceLshiftNode lshiftNode) {
+ return lshiftNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceRshift extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceRshiftNode rshiftNode) {
+ return rshiftNode.execute(null, o1, o2);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
+ abstract static class PyNumber_InPlaceMatrixMultiply extends CApiBinaryBuiltinNode {
+
+ @Specialization
+ static Object doGeneric(Object o1, Object o2,
+ @Cached PyNumberInPlaceMatrixMultiplyNode matrixMultiplyNode) {
+ return matrixMultiplyNode.execute(null, o1, o2);
+ }
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Direct)
@@ -526,7 +684,7 @@ abstract static class PySequence_InPlaceRepeat extends CApiBinaryBuiltinNode {
static Object repeat(Object obj, long n,
@Bind("this") Node inliningTarget,
@Cached PRaiseNode raiseNode,
- @Cached PySequenceInplaceRepeat repeat) {
+ @Cached PySequenceInPlaceRepeatNode repeat) {
if (!PInt.isIntRange(n)) {
throw raiseNode.raise(inliningTarget, OverflowError);
}
@@ -539,7 +697,7 @@ abstract static class PySequence_Concat extends CApiBinaryBuiltinNode {
@Specialization
Object doIt(Object s1, Object s2,
@Bind("this") Node inliningTarget,
- @Cached PySequenceConcat pySeqConcat) {
+ @Cached PySequenceConcatNode pySeqConcat) {
return pySeqConcat.execute(null, inliningTarget, s1, s2);
}
}
@@ -550,7 +708,7 @@ abstract static class PySequence_InPlaceConcat extends CApiBinaryBuiltinNode {
@Specialization
static Object concat(Object s1, Object s2,
@Bind("this") Node inliningTarget,
- @Cached PySequenceInplaceConcat concat) {
+ @Cached PySequenceInPlaceConcatNode concat) {
return concat.execute(null, inliningTarget, s1, s2);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
index d1a5ba18f0..0e07fa832d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
@@ -349,34 +349,7 @@ public final class CApiFunction {
@CApiBuiltin(name = "PyModule_GetDict", ret = PyObject, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyModule_GetName", ret = ConstCharPtrAsTruffleString, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyModule_GetState", ret = Pointer, args = {PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Add", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_And", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
@CApiBuiltin(name = "PyNumber_AsSsize_t", ret = Py_ssize_t, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_FloorDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceAdd", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceAnd", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceFloorDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceLshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceMatrixMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceOr", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceRemainder", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceRshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceSubtract", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceTrueDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_InPlaceXor", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Invert", ret = PyObject, args = {PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Lshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_MatrixMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Multiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Negative", ret = PyObject, args = {PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Or", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Positive", ret = PyObject, args = {PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Remainder", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Rshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Subtract", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_TrueDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
- @CApiBuiltin(name = "PyNumber_Xor", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
@CApiBuiltin(name = "PyOS_double_to_string", ret = CHAR_PTR, args = {Double, CHAR, Int, Int, INT_LIST}, call = CImpl)
@CApiBuiltin(name = "PyOS_mystricmp", ret = Int, args = {ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString}, call = CImpl)
@CApiBuiltin(name = "PyOS_mystrnicmp", ret = Int, args = {ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, Py_ssize_t}, call = CImpl)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
index 35dd7429b0..765d516527 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
@@ -83,7 +83,7 @@ private HPyUnaryArithmeticCached(UnaryArithmetic operator) {
@Override
public Object execute(Object object) {
- return opNode.executeCached(null, object);
+ return opNode.execute(null, object);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index b53ff2dc93..88f2b2a367 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -269,7 +269,7 @@ Object doGeneric(VirtualFrame frame, Object value,
@Cached UnboxNode unboxNode) {
Object unboxed = unboxNode.execute(inliningTarget, value);
if (unboxed != null) {
- return op.executeCached(frame, unboxed);
+ return op.execute(frame, unboxed);
} else {
return PNotImplemented.NOT_IMPLEMENTED;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
index c834e651c7..0b21e0e991 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java
@@ -104,7 +104,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrSet;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.SetAttrBuiltinNode;
-import com.oracle.graal.python.lib.PyObjectIsNotTrueNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
import com.oracle.graal.python.lib.PyObjectSizeNode;
@@ -318,12 +317,12 @@ public abstract static class NeNode extends PythonBinaryBuiltinNode {
@Specialization
static Object doGeneric(VirtualFrame frame, Object self, Object other,
@Cached(parameters = "Eq") LookupAndCallBinaryNode eqNode,
- @Cached PyObjectIsNotTrueNode ifFalseNode) {
+ @Cached PyObjectIsTrueNode isTrueNode) {
Object result = eqNode.executeObject(frame, self, other);
if (result == PNotImplemented.NOT_IMPLEMENTED) {
return result;
}
- return ifFalseNode.execute(frame, result);
+ return !isTrueNode.execute(frame, result);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
similarity index 96%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
index 3e0798ba8e..aa7c6a8613 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
@@ -62,7 +62,7 @@
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateInline(false)
-public abstract class PyNumberInplaceAddNode extends PyNumberAddBaseNode {
+public abstract class PyNumberInPlaceAddNode extends PyNumberAddBaseNode {
@Fallback
@InliningCutoff
@@ -101,7 +101,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceAddNode create() {
- return PyNumberInplaceAddNodeGen.create();
+ public static PyNumberInPlaceAddNode create() {
+ return PyNumberInPlaceAddNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
index 85992c10f8..3819e8dd73 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
@@ -53,7 +53,7 @@
@GenerateInline(false)
@GenerateUncached
-public abstract class PyNumberInplaceAndNode extends PyNumberAndBaseNode {
+public abstract class PyNumberInPlaceAndNode extends PyNumberAndBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -63,7 +63,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceAndNode create() {
- return PyNumberInplaceAndNodeGen.create();
+ public static PyNumberInPlaceAndNode create() {
+ return PyNumberInPlaceAndNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
index 079c4c3796..6ae4492358 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceFloorDivideNode extends PyNumberFloorDivideBaseNode {
+public abstract class PyNumberInPlaceFloorDivideNode extends PyNumberFloorDivideBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceFloorDivideNode create() {
- return PyNumberInplaceFloorDivideNodeGen.create();
+ public static PyNumberInPlaceFloorDivideNode create() {
+ return PyNumberInPlaceFloorDivideNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
index 38bd68ff5c..a8d32b4d1b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceLshiftNode extends PyNumberLshiftBaseNode {
+public abstract class PyNumberInPlaceLshiftNode extends PyNumberLshiftBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceLshiftNode create() {
- return PyNumberInplaceLshiftNodeGen.create();
+ public static PyNumberInPlaceLshiftNode create() {
+ return PyNumberInPlaceLshiftNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
index 8851785e01..890fc52a71 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
@@ -53,7 +53,7 @@
@GenerateInline(false)
@GenerateUncached
-public abstract class PyNumberInplaceMatrixMultiplyNode extends BinaryOpNode {
+public abstract class PyNumberInPlaceMatrixMultiplyNode extends BinaryOpNode {
@Specialization
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
@@ -62,7 +62,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceMatrixMultiplyNode create() {
- return PyNumberInplaceMatrixMultiplyNodeGen.create();
+ public static PyNumberInPlaceMatrixMultiplyNode create() {
+ return PyNumberInPlaceMatrixMultiplyNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
similarity index 96%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
index 93cf5564e8..c246a01add 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
@@ -61,7 +61,7 @@
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateInline(false)
-public abstract class PyNumberInplaceMultiplyNode extends PyNumberMultiplyBaseNode {
+public abstract class PyNumberInPlaceMultiplyNode extends PyNumberMultiplyBaseNode {
@Fallback
@InliningCutoff
@@ -113,7 +113,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceMultiplyNode create() {
- return PyNumberInplaceMultiplyNodeGen.create();
+ public static PyNumberInPlaceMultiplyNode create() {
+ return PyNumberInPlaceMultiplyNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
index bf5d14e578..b1c046876a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
@@ -53,7 +53,7 @@
@GenerateInline(false)
@GenerateUncached
-public abstract class PyNumberInplaceOrNode extends PyNumberOrBaseNode {
+public abstract class PyNumberInPlaceOrNode extends PyNumberOrBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -63,7 +63,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceOrNode create() {
- return PyNumberInplaceOrNodeGen.create();
+ public static PyNumberInPlaceOrNode create() {
+ return PyNumberInPlaceOrNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
index c8cb9a6cdc..4b7263eb99 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceRemainderNode extends PyNumberRemainderBaseNode {
+public abstract class PyNumberInPlaceRemainderNode extends PyNumberRemainderBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceRemainderNode create() {
- return PyNumberInplaceRemainderNodeGen.create();
+ public static PyNumberInPlaceRemainderNode create() {
+ return PyNumberInPlaceRemainderNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
index 3ae084345e..a7c44535aa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceRshiftNode extends PyNumberRshiftBaseNode {
+public abstract class PyNumberInPlaceRshiftNode extends PyNumberRshiftBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceRshiftNode create() {
- return PyNumberInplaceRshiftNodeGen.create();
+ public static PyNumberInPlaceRshiftNode create() {
+ return PyNumberInPlaceRshiftNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
index 61be233988..0909180b46 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceSubtractNode extends PyNumberSubtractBaseNode {
+public abstract class PyNumberInPlaceSubtractNode extends PyNumberSubtractBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceSubtractNode create() {
- return PyNumberInplaceSubtractNodeGen.create();
+ public static PyNumberInPlaceSubtractNode create() {
+ return PyNumberInPlaceSubtractNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
index b038bc42d0..6e09431bc4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInplaceTrueDivideNode extends PyNumberTrueDivideBaseNode {
+public abstract class PyNumberInPlaceTrueDivideNode extends PyNumberTrueDivideBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -61,7 +61,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceTrueDivideNode create() {
- return PyNumberInplaceTrueDivideNodeGen.create();
+ public static PyNumberInPlaceTrueDivideNode create() {
+ return PyNumberInPlaceTrueDivideNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
similarity index 94%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
index 0f5654ff61..4449af193d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInplaceXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
@@ -53,7 +53,7 @@
@GenerateInline(false)
@GenerateUncached
-public abstract class PyNumberInplaceXorNode extends PyNumberXorBaseNode {
+public abstract class PyNumberInPlaceXorNode extends PyNumberXorBaseNode {
@Fallback
@InliningCutoff
public static Object doIt(VirtualFrame frame, Object v, Object w,
@@ -63,7 +63,7 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
}
@NeverDefault
- public static PyNumberInplaceXorNode create() {
- return PyNumberInplaceXorNodeGen.create();
+ public static PyNumberInPlaceXorNode create() {
+ return PyNumberInPlaceXorNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java
index 97e9460cdf..8d05d54b82 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java
@@ -52,7 +52,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CallSlotNbBoolNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.CallSlotLenNode;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -77,14 +76,9 @@
@GenerateUncached
@GenerateInline(false)
@GenerateCached
-public abstract class PyObjectIsTrueNode extends UnaryOpNode {
+public abstract class PyObjectIsTrueNode extends PNodeWithContext {
public abstract boolean execute(Frame frame, Object object);
- @Override
- public final Object executeCached(VirtualFrame frame, Object value) {
- return execute(frame, value);
- }
-
public static boolean executeUncached(Object object) {
return getUncached().execute(null, object);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
similarity index 99%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
index 9b77279aa3..26699f9e77 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
@@ -77,7 +77,7 @@
@GenerateInline
@GenerateCached(false)
-public abstract class PySequenceConcat extends PNodeWithContext {
+public abstract class PySequenceConcatNode extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
@NeverDefault
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceConcatNode.java
similarity index 98%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceConcatNode.java
index f7bde9967f..e1b4970142 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceConcat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceConcatNode.java
@@ -63,7 +63,7 @@
@GenerateInline
@GenerateCached(false)
-public abstract class PySequenceInplaceConcat extends PNodeWithContext {
+public abstract class PySequenceInPlaceConcatNode extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceRepeatNode.java
similarity index 98%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceRepeatNode.java
index 154171769c..e33fe8544a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInplaceRepeat.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceInPlaceRepeatNode.java
@@ -63,7 +63,7 @@
@GenerateInline
@GenerateCached(false)
-public abstract class PySequenceInplaceRepeat extends PNodeWithContext {
+public abstract class PySequenceInPlaceRepeatNode extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object o, int count);
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsNotTrueNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/NotNode.java
similarity index 91%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsNotTrueNode.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/NotNode.java
index 4784aa8526..0da78402b5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsNotTrueNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/NotNode.java
@@ -38,7 +38,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package com.oracle.graal.python.lib;
+package com.oracle.graal.python.nodes.bytecode;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
@@ -46,6 +46,7 @@
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.set.PBaseSet;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
+import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNode.PyObjectIsTrueNodeGeneric;
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -55,7 +56,6 @@
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -63,16 +63,10 @@
/**
* Equivalent of a negation of CPython's {@code PyObject_IsTrue}. This class exists only so that we
* can have quickening fast-paths for this operation. The fast-paths should be synchronized with
- * {@link PyObjectIsNotTrueNode}.
+ * {@link PyObjectIsTrueNode}.
*/
@GenerateInline(false)
-public abstract class PyObjectIsNotTrueNode extends UnaryOpNode {
- public abstract boolean execute(Frame frame, Object object);
-
- @Override
- public final Object executeCached(VirtualFrame frame, Object value) {
- return execute(frame, value);
- }
+public abstract class NotNode extends UnaryOpNode {
@Specialization
public static boolean doBoolean(boolean object) {
@@ -138,7 +132,7 @@ public static boolean doOthers(VirtualFrame frame, Object object,
}
@NeverDefault
- public static PyObjectIsNotTrueNode create() {
- return PyObjectIsNotTrueNodeGen.create();
+ public static NotNode create() {
+ return NotNodeGen.create();
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
index 4564907c50..d1fda4b40f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java
@@ -112,19 +112,19 @@
import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAddNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAndNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceLshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceOrNode;
import com.oracle.graal.python.lib.PyNumberInPlacePowerNode;
-import com.oracle.graal.python.lib.PyNumberInplaceAddNode;
-import com.oracle.graal.python.lib.PyNumberInplaceAndNode;
-import com.oracle.graal.python.lib.PyNumberInplaceFloorDivideNode;
-import com.oracle.graal.python.lib.PyNumberInplaceLshiftNode;
-import com.oracle.graal.python.lib.PyNumberInplaceMatrixMultiplyNode;
-import com.oracle.graal.python.lib.PyNumberInplaceMultiplyNode;
-import com.oracle.graal.python.lib.PyNumberInplaceOrNode;
-import com.oracle.graal.python.lib.PyNumberInplaceRemainderNode;
-import com.oracle.graal.python.lib.PyNumberInplaceRshiftNode;
-import com.oracle.graal.python.lib.PyNumberInplaceSubtractNode;
-import com.oracle.graal.python.lib.PyNumberInplaceTrueDivideNode;
-import com.oracle.graal.python.lib.PyNumberInplaceXorNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRemainderNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceSubtractNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceXorNode;
import com.oracle.graal.python.lib.PyNumberInvertNode;
import com.oracle.graal.python.lib.PyNumberLshiftNode;
import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
@@ -150,7 +150,6 @@
import com.oracle.graal.python.lib.PyObjectGetIterNodeGen;
import com.oracle.graal.python.lib.PyObjectGetMethod;
import com.oracle.graal.python.lib.PyObjectGetMethodNodeGen;
-import com.oracle.graal.python.lib.PyObjectIsNotTrueNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNodeGen;
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
@@ -422,7 +421,7 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
private static final IntNodeFunction UNARY_OP_FACTORY = (int op) -> {
switch (op) {
case UnaryOpsConstants.NOT:
- return PyObjectIsNotTrueNode.create();
+ return NotNode.create();
case UnaryOpsConstants.POSITIVE:
return PyNumberPositiveNode.create();
case UnaryOpsConstants.NEGATIVE:
@@ -463,31 +462,31 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
case BinaryOpsConstants.MATMUL:
return PyNumberMatrixMultiplyNode.create();
case BinaryOpsConstants.INPLACE_ADD:
- return PyNumberInplaceAddNode.create();
+ return PyNumberInPlaceAddNode.create();
case BinaryOpsConstants.INPLACE_SUB:
- return PyNumberInplaceSubtractNode.create();
+ return PyNumberInPlaceSubtractNode.create();
case BinaryOpsConstants.INPLACE_MUL:
- return PyNumberInplaceMultiplyNode.create();
+ return PyNumberInPlaceMultiplyNode.create();
case BinaryOpsConstants.INPLACE_TRUEDIV:
- return PyNumberInplaceTrueDivideNode.create();
+ return PyNumberInPlaceTrueDivideNode.create();
case BinaryOpsConstants.INPLACE_FLOORDIV:
- return PyNumberInplaceFloorDivideNode.create();
+ return PyNumberInPlaceFloorDivideNode.create();
case BinaryOpsConstants.INPLACE_MOD:
- return PyNumberInplaceRemainderNode.create();
+ return PyNumberInPlaceRemainderNode.create();
case BinaryOpsConstants.INPLACE_LSHIFT:
- return PyNumberInplaceLshiftNode.create();
+ return PyNumberInPlaceLshiftNode.create();
case BinaryOpsConstants.INPLACE_RSHIFT:
- return PyNumberInplaceRshiftNode.create();
+ return PyNumberInPlaceRshiftNode.create();
case BinaryOpsConstants.INPLACE_AND:
- return PyNumberInplaceAndNode.create();
+ return PyNumberInPlaceAndNode.create();
case BinaryOpsConstants.INPLACE_OR:
- return PyNumberInplaceOrNode.create();
+ return PyNumberInPlaceOrNode.create();
case BinaryOpsConstants.INPLACE_XOR:
- return PyNumberInplaceXorNode.create();
+ return PyNumberInPlaceXorNode.create();
case BinaryOpsConstants.INPLACE_POW:
return PyNumberInPlacePowerNode.create();
case BinaryOpsConstants.INPLACE_MATMUL:
- return PyNumberInplaceMatrixMultiplyNode.create();
+ return PyNumberInPlaceMatrixMultiplyNode.create();
case BinaryOpsConstants.EQ:
return BinaryComparisonNode.EqNode.create();
case BinaryOpsConstants.NE:
@@ -4091,7 +4090,7 @@ private void bytecodeUnaryOpOO(VirtualFrame virtualFrame, int stackTop, int bci,
generalizeInputs(bci);
value = virtualFrame.getValue(stackTop);
}
- Object result = opNode.executeCached(virtualFrame, value);
+ Object result = opNode.execute(virtualFrame, value);
virtualFrame.setObject(stackTop, result);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
index e3836dc3fd..a60c3167d3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
@@ -62,7 +62,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -111,7 +110,7 @@ protected Object doCall(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
callUnaryNode = insert(unaryOperator.create());
}
- return callUnaryNode.executeCached(frame, PArguments.getArgument(frame, 0));
+ return callUnaryNode.execute(frame, PArguments.getArgument(frame, 0));
}
}
@@ -158,12 +157,6 @@ protected GenericUnaryArithmeticNode(TruffleString specialMethodName) {
this.specialMethodName = specialMethodName;
}
- public final Object execute(VirtualFrame frame, Node inliningTarget, Object value) {
- return execute(frame, value);
- }
-
- protected abstract Object execute(VirtualFrame frame, Object value);
-
@Specialization
public static Object doGeneric(VirtualFrame frame, Object arg,
@Cached("createCallNode()") LookupAndCallUnaryNode callNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryOpNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryOpNode.java
index 15e1bdd0ed..23d41297ca 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryOpNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryOpNode.java
@@ -29,5 +29,5 @@
import com.oracle.truffle.api.frame.VirtualFrame;
public abstract class UnaryOpNode extends PNodeWithContext {
- public abstract Object executeCached(VirtualFrame frame, Object value);
+ public abstract Object execute(VirtualFrame frame, Object value);
}
From fc369f3de050f0521793e5d11bb862c9f4c04b7c Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Tue, 18 Feb 2025 18:09:01 +0100
Subject: [PATCH 033/512] Add uncached node to PyNumberAddNode
---
.../objects/common/SequenceStorageNodes.java | 83 +++++++++++++++--
.../builtins/objects/ints/IntBuiltins.java | 44 ++++-----
.../builtins/objects/list/ListBuiltins.java | 9 +-
.../builtins/objects/tuple/TupleBuiltins.java | 13 +--
.../graal/python/lib/PyNumberAddNode.java | 90 ++++++++++++++-----
.../python/lib/PySequenceConcatNode.java | 19 ++--
6 files changed, 178 insertions(+), 80 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index 0d9f1b9597..1a2c29b059 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -2185,6 +2185,7 @@ static boolean isByteSequenceStorage(SequenceStorage s) {
}
@SuppressWarnings("truffle-inlining") // footprint reduction 68 -> 49
+ @GenerateUncached
public abstract static class ConcatBaseNode extends SequenceStorageBaseNode {
public abstract SequenceStorage execute(SequenceStorage dest, SequenceStorage left, SequenceStorage right);
@@ -2400,18 +2401,37 @@ public static ConcatNode createWithOverflowError() {
}
@NeverDefault
- public static ConcatNode create(TruffleString msg) {
- return create(() -> NoGeneralizationCustomMessageNode.create(msg), MemoryError);
+ private static ConcatNode create(Supplier genNodeProvider, PythonBuiltinClassType errorForOverflow) {
+ return ConcatNodeGen.create(genNodeProvider, errorForOverflow);
}
+ }
- @NeverDefault
- public static ConcatNode create(Supplier genNodeProvider) {
- return create(genNodeProvider, MemoryError);
- }
+ @GenerateInline
+ @GenerateCached(false)
+ @GenerateUncached
+ public abstract static class ConcatListOrTupleNode extends Node {
- @NeverDefault
- private static ConcatNode create(Supplier genNodeProvider, PythonBuiltinClassType errorForOverflow) {
- return ConcatNodeGen.create(genNodeProvider, errorForOverflow);
+ public abstract SequenceStorage execute(Node inliningTarget, SequenceStorage left, SequenceStorage right);
+
+ @Specialization
+ static SequenceStorage concat(Node inliningTarget, SequenceStorage left, SequenceStorage right,
+ @Cached CreateEmpty2Node create,
+ @Cached(inline = false) ConcatBaseNode concat,
+ @Cached PRaiseNode raiseNode) {
+ try {
+ int len1 = left.length();
+ int len2 = right.length();
+ int destlen = PythonUtils.addExact(len1, len2);
+ SequenceStorage empty = create.execute(inliningTarget, left, right, destlen);
+ empty.setNewLength(destlen);
+ try {
+ return concat.execute(empty, left, right);
+ } catch (SequenceStoreException e) {
+ throw CompilerDirectives.shouldNotReachHere();
+ }
+ } catch (OutOfMemoryError | OverflowException e) {
+ throw raiseNode.raise(inliningTarget, MemoryError);
+ }
}
}
@@ -3099,6 +3119,23 @@ static ArrayBasedSequenceStorage doIt(Node inliningTarget, SequenceStorage s, in
@GenerateInline
@GenerateCached(false)
+ @GenerateUncached
+ public abstract static class CreateEmpty2Node extends SequenceStorageBaseNode {
+
+ public abstract ArrayBasedSequenceStorage execute(Node inliningTarget, SequenceStorage s1, SequenceStorage s2, int cap);
+
+ @Specialization
+ static ArrayBasedSequenceStorage doIt(Node inliningTarget, SequenceStorage s1, SequenceStorage s2, int cap,
+ @Cached GetElementType getElementType1,
+ @Cached GetElementType getElementType2,
+ @Cached CreateEmptyForTypesNode create) {
+ return create.execute(inliningTarget, getElementType1.execute(inliningTarget, s1), getElementType2.execute(inliningTarget, s2), cap);
+ }
+ }
+
+ @GenerateInline
+ @GenerateCached(false)
+ @GenerateUncached
abstract static class CreateEmptyForTypeNode extends SequenceStorageBaseNode {
public abstract ArrayBasedSequenceStorage execute(Node inliningTarget, StorageType type, int cap);
@@ -3134,6 +3171,34 @@ static ObjectSequenceStorage doObject(@SuppressWarnings("unused") StorageType ty
}
}
+ @GenerateInline
+ @GenerateCached(false)
+ @GenerateUncached
+ abstract static class CreateEmptyForTypesNode extends SequenceStorageBaseNode {
+
+ public abstract ArrayBasedSequenceStorage execute(Node inliningTarget, StorageType type1, StorageType type2, int cap);
+
+ @Specialization(guards = "type1 == type2")
+ static ArrayBasedSequenceStorage doSame(Node inliningTarget, StorageType type1, @SuppressWarnings("unused") StorageType type2, int cap,
+ @Cached CreateEmptyForTypeNode create) {
+ return create.execute(inliningTarget, type1, cap);
+ }
+
+ @Specialization(guards = "generalizeToLong(type1, type2)")
+ static LongSequenceStorage doLong(@SuppressWarnings("unused") StorageType type1, @SuppressWarnings("unused") StorageType type2, int cap) {
+ return new LongSequenceStorage(cap);
+ }
+
+ @Fallback
+ static ObjectSequenceStorage doObject(@SuppressWarnings("unused") StorageType type1, @SuppressWarnings("unused") StorageType type2, int cap) {
+ return new ObjectSequenceStorage(cap);
+ }
+
+ protected static boolean generalizeToLong(StorageType type1, StorageType type2) {
+ return isInt(type1) && isLong(type2) || isLong(type1) && isInt(type2);
+ }
+ }
+
@GenerateUncached
@GenerateInline
@GenerateCached(false)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index fc97c6d276..cac36977a7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -364,62 +364,62 @@ public abstract static class AddNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@Specialization(rewriteOn = ArithmeticException.class)
- static int add(int left, int right) {
+ static int doII(int left, int right) {
return Math.addExact(left, right);
}
- @Specialization(rewriteOn = ArithmeticException.class)
- static long addLong(long left, long right) {
+ @Specialization(replaces = "doII", rewriteOn = ArithmeticException.class)
+ static long doLL(long left, long right) {
return Math.addExact(left, right);
}
- @Specialization
- static Object addLongWithOverflow(long x, long y,
+ @Specialization(replaces = "doLL")
+ static Object doLLOvf(long x, long y,
@Bind PythonLanguage language) {
/* Inlined version of Math.addExact(x, y) with BigInteger fallback. */
long r = x + y;
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
if (((x ^ r) & (y ^ r)) < 0) {
- return PFactory.createInt(language, op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ return PFactory.createInt(language, add(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
}
return r;
}
@Specialization(rewriteOn = OverflowException.class)
- static Object addPIntLongAndNarrow(PInt left, long right) throws OverflowException {
- return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
+ static Object doPLNarrow(PInt left, long right) throws OverflowException {
+ return PInt.longValueExact(add(left.getValue(), PInt.longToBigInteger(right)));
}
- @Specialization(replaces = "addPIntLongAndNarrow")
- static Object addPIntLong(PInt left, long right,
+ @Specialization(replaces = "doPLNarrow")
+ static Object doPL(PInt left, long right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, add(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
- static Object addLongPIntAndNarrow(long left, PInt right) throws OverflowException {
- return PInt.longValueExact(op(PInt.longToBigInteger(left), right.getValue()));
+ static Object doLPNarrow(long left, PInt right) throws OverflowException {
+ return PInt.longValueExact(add(PInt.longToBigInteger(left), right.getValue()));
}
- @Specialization(replaces = "addLongPIntAndNarrow")
- static Object addLongPInt(long left, PInt right,
+ @Specialization(replaces = "doLPNarrow")
+ static Object doLP(long left, PInt right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
+ return PFactory.createInt(language, add(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(rewriteOn = OverflowException.class)
- static Object addPIntPIntAndNarrow(PInt left, PInt right) throws OverflowException {
- return PInt.longValueExact(op(left.getValue(), right.getValue()));
+ static Object doPPNarrow(PInt left, PInt right) throws OverflowException {
+ return PInt.longValueExact(add(left.getValue(), right.getValue()));
}
- @Specialization(replaces = "addPIntPIntAndNarrow")
- static Object addPIntPInt(PInt left, PInt right,
+ @Specialization(replaces = "doPPNarrow")
+ static Object doPP(PInt left, PInt right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(left.getValue(), right.getValue()));
+ return PFactory.createInt(language, add(left.getValue(), right.getValue()));
}
@TruffleBoundary
- static BigInteger op(BigInteger left, BigInteger right) {
+ public static BigInteger add(BigInteger left, BigInteger right) {
return left.add(right);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
index ced67e1c9c..a29702df43 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java
@@ -749,7 +749,7 @@ static PList doPList(Object left, Object right,
@Cached PyListCheckNode isListNode,
@Cached GetListStorageNode getStorageNode,
@Cached GetClassForNewListNode getClassForNewListNode,
- @Cached("createConcat()") SequenceStorageNodes.ConcatNode concatNode,
+ @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language,
@Cached TypeNodes.GetInstanceShape getInstanceShape,
@Cached PRaiseNode raiseNode) {
@@ -759,15 +759,10 @@ static PList doPList(Object left, Object right,
var leftStorage = getStorageNode.execute(inliningTarget, left);
var rightStorage = getStorageNode.execute(inliningTarget, right);
- SequenceStorage newStore = concatNode.execute(leftStorage, rightStorage);
+ SequenceStorage newStore = concatNode.execute(inliningTarget, leftStorage, rightStorage);
Object newClass = getClassForNewListNode.execute(inliningTarget, left);
return PFactory.createList(language, newClass, getInstanceShape.execute(newClass), newStore);
}
-
- @NeverDefault
- protected static SequenceStorageNodes.ConcatNode createConcat() {
- return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
- }
}
@Slot(value = SlotKind.sq_inplace_concat, isComplex = true)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
index e8835f56b6..7a0bb1eb5b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java
@@ -62,8 +62,6 @@
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.CmpNode;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ConcatNode;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.SequenceStorageMpSubscriptNode;
import com.oracle.graal.python.builtins.objects.iterator.PDoubleSequenceIterator;
import com.oracle.graal.python.builtins.objects.iterator.PIntegerSequenceIterator;
@@ -456,17 +454,14 @@ static PTuple doTuple(Object left, Object right,
@SuppressWarnings("unused") @Cached PyTupleCheckNode checkRight,
@Cached GetTupleStorage getLeft,
@Cached GetTupleStorage getRight,
- @Cached("createConcat()") ConcatNode concatNode,
+ @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language) {
- SequenceStorage concatenated = concatNode.execute(getLeft.execute(inliningTarget, left), getRight.execute(inliningTarget, right));
+ SequenceStorage leftStorage = getLeft.execute(inliningTarget, left);
+ SequenceStorage rightStorage = getRight.execute(inliningTarget, right);
+ SequenceStorage concatenated = concatNode.execute(inliningTarget, leftStorage, rightStorage);
return PFactory.createTuple(language, concatenated);
}
- @NeverDefault
- protected static SequenceStorageNodes.ConcatNode createConcat() {
- return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
- }
-
@Fallback
static Object doGeneric(@SuppressWarnings("unused") Object left, Object right,
@Bind("this") Node inliningTarget) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index a169ce7770..5aed080f1e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -40,24 +40,27 @@
*/
package com.oracle.graal.python.lib;
+import static com.oracle.graal.python.builtins.objects.ints.IntBuiltins.AddNode.add;
import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
+import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
+import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
+import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -65,6 +68,8 @@
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -74,27 +79,76 @@
import com.oracle.truffle.api.strings.TruffleString;
@GenerateCached(false)
+@ImportStatic(PGuards.class)
abstract class PyNumberAddBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
- * in IntBuiltins, FloatBuiltins, ListBuiltins, ...
+ * in IntBuiltins, but it additionally needs to check PInts for only builtin ints
*/
+ // XXX this could benefit from the type system conversions, but that would also unpack PFloat
+ // which we don't want
+
@Specialization(rewriteOn = ArithmeticException.class)
- public static int add(int left, int right) {
+ static int doII(int left, int right) {
return Math.addExact(left, right);
}
- @Specialization
- public static long doIIOvf(int x, int y) {
- return x + (long) y;
+ @Specialization(replaces = "doII", rewriteOn = ArithmeticException.class)
+ static long doLL(long left, long right) {
+ return Math.addExact(left, right);
}
- @Specialization(rewriteOn = ArithmeticException.class)
- public static long addLong(long left, long right) {
- return Math.addExact(left, right);
+ @Specialization(replaces = "doLL")
+ static Object doLLOvf(long x, long y,
+ @Bind PythonLanguage language) {
+ /* Inlined version of Math.addExact(x, y) with BigInteger fallback. */
+ long r = x + y;
+ // HD 2-12 Overflow iff both arguments have the opposite sign of the result
+ if (((x ^ r) & (y ^ r)) < 0) {
+ return PFactory.createInt(language, add(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ }
+ return r;
}
+ @Specialization(guards = "isBuiltinPInt(left)", rewriteOn = OverflowException.class)
+ static Object doPLNarrow(PInt left, long right) throws OverflowException {
+ return PInt.longValueExact(add(left.getValue(), PInt.longToBigInteger(right)));
+ }
+
+ @Specialization(guards = "isBuiltinPInt(left)", replaces = "doPLNarrow")
+ static Object doPL(PInt left, long right,
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, add(left.getValue(), PInt.longToBigInteger(right)));
+ }
+
+ @Specialization(guards = "isBuiltinPInt(right)", rewriteOn = OverflowException.class)
+ static Object doLPNarrow(long left, PInt right) throws OverflowException {
+ return PInt.longValueExact(add(PInt.longToBigInteger(left), right.getValue()));
+ }
+
+ @Specialization(guards = "isBuiltinPInt(right)", replaces = "doLPNarrow")
+ static Object doLP(long left, PInt right,
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, add(PInt.longToBigInteger(left), right.getValue()));
+ }
+
+ @Specialization(guards = {"isBuiltinPInt(left)", "isBuiltinPInt(right)"}, rewriteOn = OverflowException.class)
+ static Object doPPNarrow(PInt left, PInt right) throws OverflowException {
+ return PInt.longValueExact(add(left.getValue(), right.getValue()));
+ }
+
+ @Specialization(guards = {"isBuiltinPInt(left)", "isBuiltinPInt(right)"}, replaces = "doPPNarrow")
+ static Object doPP(PInt left, PInt right,
+ @Bind PythonLanguage language) {
+ return PFactory.createInt(language, add(left.getValue(), right.getValue()));
+ }
+
+ /*
+ * All the following fast paths need to be kept in sync with the corresponding builtin functions
+ * in FloatBuiltins
+ */
+
@Specialization
public static double doDD(double left, double right) {
return left + right;
@@ -122,6 +176,7 @@ public static double doID(int left, double right) {
}
@GenerateInline(inlineByDefault = true)
+@GenerateUncached
public abstract class PyNumberAddNode extends PyNumberAddBaseNode {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
@@ -138,24 +193,19 @@ public final Object executeCached(VirtualFrame frame, Object v, Object w) {
public abstract double executeDouble(VirtualFrame frame, Node inliningTarget, double left, double right) throws UnexpectedResultException;
- @NeverDefault
- protected static SequenceStorageNodes.ConcatNode createConcat() {
- return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
- }
-
@Specialization(guards = {"isBuiltinList(left)", "isBuiltinList(right)"})
- static PList doPList(PList left, PList right,
- @Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
+ static PList doPList(Node inliningTarget, PList left, PList right,
+ @Shared @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language) {
- SequenceStorage newStore = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
+ SequenceStorage newStore = concatNode.execute(inliningTarget, left.getSequenceStorage(), right.getSequenceStorage());
return PFactory.createList(language, newStore);
}
@Specialization(guards = {"isBuiltinTuple(left)", "isBuiltinTuple(right)"})
- static PTuple doTuple(PTuple left, PTuple right,
- @Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
+ static PTuple doTuple(Node inliningTarget, PTuple left, PTuple right,
+ @Shared @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language) {
- SequenceStorage concatenated = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
+ SequenceStorage concatenated = concatNode.execute(inliningTarget, left.getSequenceStorage(), right.getSequenceStorage());
return PFactory.createTuple(language, concatenated);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
index 26699f9e77..e7984682bb 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceConcatNode.java
@@ -46,7 +46,6 @@
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
import com.oracle.graal.python.builtins.objects.list.PList;
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
@@ -68,7 +67,6 @@
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
-import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@@ -80,24 +78,19 @@
public abstract class PySequenceConcatNode extends PNodeWithContext {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
- @NeverDefault
- protected static SequenceStorageNodes.ConcatNode createConcat() {
- return SequenceStorageNodes.ConcatNode.create(ListGeneralizationNode::create);
- }
-
@Specialization(guards = {"isBuiltinList(left)", "isBuiltinList(right)"})
- static PList doPList(PList left, PList right,
- @Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
+ static PList doPList(Node inliningTarget, PList left, PList right,
+ @Shared @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language) {
- SequenceStorage newStore = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
+ SequenceStorage newStore = concatNode.execute(inliningTarget, left.getSequenceStorage(), right.getSequenceStorage());
return PFactory.createList(language, newStore);
}
@Specialization(guards = {"isBuiltinTuple(left)", "isBuiltinTuple(right)"})
- static PTuple doTuple(PTuple left, PTuple right,
- @Shared @Cached(value = "createConcat()", inline = false) SequenceStorageNodes.ConcatNode concatNode,
+ static PTuple doTuple(Node inliningTarget, PTuple left, PTuple right,
+ @Shared @Cached SequenceStorageNodes.ConcatListOrTupleNode concatNode,
@Bind PythonLanguage language) {
- SequenceStorage concatenated = concatNode.execute(left.getSequenceStorage(), right.getSequenceStorage());
+ SequenceStorage concatenated = concatNode.execute(inliningTarget, left.getSequenceStorage(), right.getSequenceStorage());
return PFactory.createTuple(language, concatenated);
}
From 12d1bc51ef8aef8058c6c7c46f8313f0e14dfa1a Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 09:49:11 +0100
Subject: [PATCH 034/512] Refactor bytes concat
---
.../objects/bytes/ByteArrayBuiltins.java | 45 +++++----
.../objects/bytes/BytesCommonBuiltins.java | 46 +++++----
.../objects/common/SequenceStorageNodes.java | 94 -------------------
.../graal/python/nodes/ErrorMessages.java | 1 +
4 files changed, 55 insertions(+), 131 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
index d4da0d121d..bd719d0915 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java
@@ -41,6 +41,7 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INIT__;
+import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
@@ -110,6 +111,8 @@
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.ComparisonOp;
+import com.oracle.graal.python.util.OverflowException;
+import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -431,44 +434,46 @@ public abstract static class IAddNode extends PythonBinaryBuiltinNode {
@Specialization
static PByteArray add(PByteArray self, PBytesLike other,
@Bind("this") Node inliningTarget,
- @Cached @Shared SequenceStorageNodes.ConcatNode concatNode,
+ @Shared @Cached SequenceStorageNodes.EnsureCapacityNode ensureCapacityNode,
+ @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PRaiseNode raiseNode) {
- self.checkCanResize(inliningTarget, raiseNode);
- SequenceStorage res = concatNode.execute(self.getSequenceStorage(), other.getSequenceStorage());
- updateSequenceStorage(self, res);
- return self;
+ return extendWithBuffer(self, other, inliningTarget, ensureCapacityNode, bufferLib, raiseNode);
}
@Specialization(guards = "!isBytes(other)", limit = "3")
static PByteArray add(VirtualFrame frame, PByteArray self, Object other,
@Bind("this") Node inliningTarget,
- @Bind PythonLanguage language,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@CachedLibrary("other") PythonBufferAcquireLibrary bufferAcquireLib,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached @Shared SequenceStorageNodes.ConcatNode concatNode,
+ @Shared @Cached SequenceStorageNodes.EnsureCapacityNode ensureCapacityNode,
+ @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
@Shared @Cached PRaiseNode raiseNode) {
- Object buffer;
+ Object otherBuffer;
try {
- buffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
+ otherBuffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
} catch (PException e) {
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
}
try {
- self.checkCanResize(inliningTarget, raiseNode);
- // TODO avoid copying
- PBytes bytes = PFactory.createBytes(language, bufferLib.getCopiedByteArray(buffer));
- SequenceStorage res = concatNode.execute(self.getSequenceStorage(), bytes.getSequenceStorage());
- updateSequenceStorage(self, res);
- return self;
+ return extendWithBuffer(self, otherBuffer, inliningTarget, ensureCapacityNode, bufferLib, raiseNode);
} finally {
- bufferLib.release(buffer, frame, indirectCallData);
+ bufferLib.release(otherBuffer, frame, indirectCallData);
}
}
- private static void updateSequenceStorage(PByteArray array, SequenceStorage s) {
- if (array.getSequenceStorage() != s) {
- array.setSequenceStorage(s);
+ private static PByteArray extendWithBuffer(PByteArray self, Object otherBuffer, Node inliningTarget, SequenceStorageNodes.EnsureCapacityNode ensureCapacityNode,
+ PythonBufferAccessLibrary bufferLib, PRaiseNode raiseNode) {
+ self.checkCanResize(inliningTarget, raiseNode);
+ try {
+ int len = self.getSequenceStorage().length();
+ int otherLen = bufferLib.getBufferLength(otherBuffer);
+ int newLen = PythonUtils.addExact(len, otherLen);
+ ensureCapacityNode.execute(inliningTarget, self.getSequenceStorage(), newLen);
+ self.getSequenceStorage().setNewLength(newLen);
+ bufferLib.readIntoBuffer(otherBuffer, 0, self, len, otherLen, bufferLib);
+ return self;
+ } catch (OverflowException e) {
+ throw raiseNode.raise(inliningTarget, MemoryError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
index 9e4733c4d3..fad33a8aa9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
@@ -289,11 +289,11 @@ public abstract static class ConcatNode extends SqConcatBuiltinNode {
@Specialization
static PBytesLike add(PBytesLike self, PBytesLike other,
- @Bind("this") Node node,
- @Cached("createWithOverflowError()") @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Cached @Exclusive BytesNodes.CreateBytesNode create) {
- SequenceStorage res = concatNode.execute(self.getSequenceStorage(), other.getSequenceStorage());
- return create.execute(node, self, res);
+ @Bind Node inliningTarget,
+ @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
+ @Shared @Cached BytesNodes.CreateBytesNode create,
+ @Shared @Cached PRaiseNode raiseNode) {
+ return concatBuffers(self, self, other, inliningTarget, bufferLib, create, raiseNode);
}
@Specialization(limit = "3")
@@ -302,23 +302,35 @@ static PBytesLike add(VirtualFrame frame, Object self, Object other,
@Cached("createFor(this)") IndirectCallData indirectCallData,
@Cached GetBytesStorage getBytesStorage,
@CachedLibrary("other") PythonBufferAcquireLibrary bufferAcquireLib,
- @CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
- @Cached("createWithOverflowError()") @Shared SequenceStorageNodes.ConcatNode concatNode,
- @Cached @Exclusive BytesNodes.CreateBytesNode create,
- @Cached PRaiseNode raiseNode) {
- Object buffer;
+ @Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
+ @Shared @Cached BytesNodes.CreateBytesNode create,
+ @Shared @Cached PRaiseNode raiseNode) {
+ Object otherBuffer;
try {
- buffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
+ otherBuffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);
} catch (PException e) {
- throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_CONCAT_P_TO_S, other, "bytearray");
+ throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_CONCAT_P_TO_P, other, self);
}
try {
- // TODO avoid copying
- byte[] bytes = bufferLib.getCopiedByteArray(buffer);
- SequenceStorage res = concatNode.execute(getBytesStorage.execute(inliningTarget, self), new ByteSequenceStorage(bytes));
- return create.execute(inliningTarget, self, res);
+ SequenceStorage selfBuffer = getBytesStorage.execute(inliningTarget, self);
+ return concatBuffers(self, selfBuffer, otherBuffer, inliningTarget, bufferLib, create, raiseNode);
} finally {
- bufferLib.release(buffer, frame, indirectCallData);
+ bufferLib.release(otherBuffer, frame, indirectCallData);
+ }
+ }
+
+ private static PBytesLike concatBuffers(Object self, Object selfBuffer, Object otherBuffer, Node inliningTarget, PythonBufferAccessLibrary bufferLib, BytesNodes.CreateBytesNode create,
+ PRaiseNode raiseNode) {
+ try {
+ int len = bufferLib.getBufferLength(selfBuffer);
+ int otherLen = bufferLib.getBufferLength(otherBuffer);
+ int newLen = PythonUtils.addExact(len, otherLen);
+ byte[] newBytes = new byte[newLen];
+ bufferLib.readIntoByteArray(selfBuffer, 0, newBytes, 0, len);
+ bufferLib.readIntoByteArray(otherBuffer, 0, newBytes, len, otherLen);
+ return create.execute(inliningTarget, self, new ByteSequenceStorage(newBytes));
+ } catch (OverflowException e) {
+ throw raiseNode.raise(inliningTarget, OverflowError);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
index 1a2c29b059..b432d53661 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java
@@ -45,7 +45,6 @@
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
@@ -57,8 +56,6 @@
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetSequenceStorageNode;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.AppendNodeGen;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.CmpNodeGen;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ConcatBaseNodeGen;
-import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ConcatNodeGen;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.CreateStorageFromIteratorNodeFactory.CreateStorageFromIteratorNodeCachedNodeGen;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.DeleteNodeGen;
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ExtendNodeGen;
@@ -2315,97 +2312,6 @@ private static void concat(Object dest, Object arr1, int len1, Object arr2, int
}
}
- /**
- * Concatenates two sequence storages; creates a storage of a suitable type and writes the
- * result to the new storage.
- */
- public abstract static class ConcatNode extends SequenceStorageBaseNode {
- private static final TruffleString DEFAULT_ERROR_MSG = ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP;
-
- @Child private ConcatBaseNode concatBaseNode = ConcatBaseNodeGen.create();
- @Child private GeneralizationNode genNode;
-
- private final Supplier genNodeProvider;
-
- /*
- * CPython is inconsistent when too repeats are done. Most types raise MemoryError, but e.g.
- * bytes raises OverflowError when the memory might be available but the size overflows
- * sys.maxint
- */
- private final PythonBuiltinClassType errorForOverflow;
-
- ConcatNode(Supplier genNodeProvider, PythonBuiltinClassType errorForOverflow) {
- this.genNodeProvider = genNodeProvider;
- this.errorForOverflow = errorForOverflow;
- }
-
- public abstract SequenceStorage execute(SequenceStorage left, SequenceStorage right);
-
- @Specialization
- SequenceStorage doRight(SequenceStorage left, SequenceStorage right,
- @Bind("this") Node inliningTarget,
- @Cached CreateEmptyNode createEmptyNode,
- @Cached InlinedConditionProfile shouldOverflow,
- @Cached PRaiseNode raiseNode) {
- int destlen = 0;
- try {
- int len1 = left.length();
- int len2 = right.length();
- // we eagerly generalize the store to avoid possible cascading generalizations
- destlen = PythonUtils.addExact(len1, len2);
- if (errorForOverflow == OverflowError && shouldOverflow.profile(inliningTarget, destlen >= SysModuleBuiltins.MAXSIZE)) {
- // cpython raises an overflow error when this happens
- throw raiseNode.raise(inliningTarget, OverflowError);
- }
- SequenceStorage generalized = generalizeStore(createEmpty(createEmptyNode, inliningTarget, left, right, destlen), right);
- return doConcat(generalized, left, right);
- } catch (OutOfMemoryError e) {
- throw raiseNode.raise(inliningTarget, MemoryError);
- } catch (OverflowException e) {
- throw raiseNode.raise(inliningTarget, errorForOverflow);
- }
- }
-
- private SequenceStorage createEmpty(CreateEmptyNode createEmptyNode, Node inliningTarget, SequenceStorage l, SequenceStorage r, int len) {
- if (l instanceof EmptySequenceStorage) {
- return createEmptyNode.execute(inliningTarget, r, len, -1);
- }
- return createEmptyNode.execute(inliningTarget, l, len, len);
- }
-
- private SequenceStorage doConcat(SequenceStorage dest, SequenceStorage leftProfiled, SequenceStorage rightProfiled) {
- try {
- return concatBaseNode.execute(dest, leftProfiled, rightProfiled);
- } catch (SequenceStoreException e) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- throw new IllegalStateException("generalized sequence storage cannot take value: " + e.getIndicationValue());
- }
- }
-
- private SequenceStorage generalizeStore(SequenceStorage storage, Object value) {
- if (genNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- genNode = insert(genNodeProvider.get());
- }
- return genNode.executeCached(storage, value);
- }
-
- @NeverDefault
- public static ConcatNode create() {
- return create(() -> NoGeneralizationCustomMessageNode.create(DEFAULT_ERROR_MSG), MemoryError);
- }
-
- @NeverDefault
- public static ConcatNode createWithOverflowError() {
- return create(() -> NoGeneralizationCustomMessageNode.create(DEFAULT_ERROR_MSG), OverflowError);
- }
-
- @NeverDefault
- private static ConcatNode create(Supplier genNodeProvider, PythonBuiltinClassType errorForOverflow) {
- return ConcatNodeGen.create(genNodeProvider, errorForOverflow);
- }
- }
-
@GenerateInline
@GenerateCached(false)
@GenerateUncached
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
index 7804fc3b01..3dc120280a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java
@@ -205,6 +205,7 @@ public abstract class ErrorMessages {
public static final TruffleString CANNOT_CONVERT_FLOAT_NAN_TO_INTEGER = tsLiteral("cannot convert float NaN to integer");
public static final TruffleString CANT_CAPTURE_NAME_UNDERSCORE_IN_PATTERNS = tsLiteral("can't capture name '_' in patterns");
public static final TruffleString CANT_CONCAT_P_TO_S = tsLiteral("can't concat %p to %s");
+ public static final TruffleString CANT_CONCAT_P_TO_P = tsLiteral("can't concat %p to %p");
public static final TruffleString CANT_CONVERT_TO_STR_IMPLICITLY = tsLiteral("Can't convert '%p' object to str implicitly");
public static final TruffleString CANT_COMPARE = tsLiteral("Can't compare %p and %p");
public static final TruffleString CAN_T_DELETE_NUMERIC_CHAR_ATTRIBUTE = tsLiteral("can't delete numeric/char attribute");
From ea93541af29e8a37e7cafeb436f5f816818cc3c7 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 11:16:01 +0100
Subject: [PATCH 035/512] Split PythonArithmeticTypes
---
.../builtins/modules/BuiltinFunctions.java | 16 +----
.../builtins/modules/CmathModuleBuiltins.java | 18 +++---
.../modules/GraalPythonModuleBuiltins.java | 5 --
.../builtins/modules/MathModuleBuiltins.java | 30 ++++-----
.../modules/OperatorModuleBuiltins.java | 3 -
.../modules/PolyglotModuleBuiltins.java | 5 +-
.../builtins/modules/PosixModuleBuiltins.java | 14 +++--
.../builtins/modules/SREModuleBuiltins.java | 6 --
.../modules/ThreadModuleBuiltins.java | 13 ++--
.../builtins/modules/TimeModuleBuiltins.java | 12 +---
.../cext/PythonCextUnicodeBuiltins.java | 4 +-
.../modules/io/BufferedIOMixinBuiltins.java | 3 -
.../builtins/modules/io/BufferedIONodes.java | 4 +-
.../builtins/modules/io/StringIOBuiltins.java | 3 -
.../modules/lzma/LZMACompressorBuiltins.java | 15 ++---
.../lzma/LZMADecompressorBuiltins.java | 8 ---
.../modules/lzma/LZMAModuleBuiltins.java | 5 --
.../modules/zlib/ZLibModuleBuiltins.java | 3 -
.../builtins/objects/bool/BoolBuiltins.java | 12 ++--
.../objects/bytes/BytesCommonBuiltins.java | 4 --
.../objects/complex/ComplexBuiltins.java | 4 +-
.../objects/floats/FloatBuiltins.java | 4 --
.../function/BuiltinFunctionBuiltins.java | 3 -
.../objects/function/FunctionBuiltins.java | 3 -
.../function/MethodDescriptorBuiltins.java | 3 -
.../function/WrapperDescriptorBuiltins.java | 3 -
.../builtins/objects/ints/IntBuiltins.java | 62 +++++++++----------
.../builtins/objects/mmap/MMapBuiltins.java | 5 --
.../objects/random/RandomBuiltins.java | 4 +-
.../builtins/objects/range/RangeBuiltins.java | 4 +-
.../objects/ssl/SSLContextBuiltins.java | 5 --
.../builtins/objects/str/StringBuiltins.java | 6 --
.../graal/python/lib/PyNumberAddNode.java | 15 +----
.../python/lib/PyTimeFromObjectNode.java | 4 +-
.../expression/BinaryComparisonNode.java | 4 +-
.../truffle/PythonIntegerAndFloatTypes.java | 59 ++++++++++++++++++
...eticTypes.java => PythonIntegerTypes.java} | 46 ++------------
.../nodes/util/CastToJavaBigIntegerNode.java | 3 -
.../nodes/util/CastToJavaDoubleNode.java | 6 +-
.../python/nodes/util/CastToJavaIntNode.java | 6 +-
.../util/CastToJavaUnsignedLongNode.java | 4 +-
.../nodes/util/CoerceToComplexNode.java | 4 +-
mx.graalpython/copyrights/overrides | 2 +-
43 files changed, 180 insertions(+), 262 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerAndFloatTypes.java
rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/{PythonArithmeticTypes.java => PythonIntegerTypes.java} (50%)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 252a9e6740..1669baa4b4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -231,7 +231,7 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
@@ -552,7 +552,7 @@ static boolean doObject(VirtualFrame frame, Object object,
@GenerateInline
@GenerateCached(false)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class BinOctHexHelperNode extends Node {
@FunctionalInterface
@@ -593,13 +593,6 @@ static TruffleString doL(Node inliningTarget, long x, TruffleString prefix, int
return buildString(x < 0, prefix, fromJavaStringNode.execute(longToString.convert(Math.abs(x)), TS_ENCODING));
}
- @Specialization
- @SuppressWarnings("unused")
- static TruffleString doD(double x, TruffleString prefix, int radix, LongToString longToString,
- @Bind("this") Node inliningTarget) {
- throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, (Object) x);
- }
-
@Specialization
static TruffleString doPI(PInt x, TruffleString prefix, int radix, @SuppressWarnings("unused") LongToString longToString,
@Shared @Cached(inline = false) TruffleString.FromJavaStringNode fromJavaStringNode) {
@@ -607,7 +600,7 @@ static TruffleString doPI(PInt x, TruffleString prefix, int radix, @SuppressWarn
return buildString(value.signum() < 0, prefix, fromJavaStringNode.execute(bigToString(radix, PInt.abs(value)), TS_ENCODING));
}
- @Specialization(replaces = {"doL", "doD", "doPI"})
+ @Specialization(replaces = {"doL", "doPI"})
static TruffleString doO(VirtualFrame frame, Node inliningTarget, Object x, TruffleString prefix, int radix, LongToString longToString,
@Exclusive @Cached InlinedConditionProfile isMinLong,
@Cached PyNumberIndexNode indexNode,
@@ -635,7 +628,6 @@ static TruffleString doO(VirtualFrame frame, Node inliningTarget, Object x, Truf
// bin(object)
@Builtin(name = J_BIN, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class BinNode extends PythonUnaryBuiltinNode {
static final TruffleString T_BIN_PREFIX = tsLiteral("0b");
@@ -655,7 +647,6 @@ private static String longToString(long x) {
// oct(object)
@Builtin(name = J_OCT, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class OctNode extends PythonUnaryBuiltinNode {
static final TruffleString T_OCT_PREFIX = tsLiteral("0o");
@@ -675,7 +666,6 @@ private static String longToString(long x) {
// hex(object)
@Builtin(name = J_HEX, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class HexNode extends PythonUnaryBuiltinNode {
static final TruffleString T_HEX_PREFIX = tsLiteral("0x");
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
index 1d20d28c2c..13b7746df0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java
@@ -28,7 +28,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.nodes.util.CoerceToComplexNode;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.CompilerDirectives;
@@ -167,7 +167,7 @@ static SpecialType ofDouble(double d) {
@GenerateInline
@GenerateCached(false)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
abstract static class CmathComplexUnaryHelperNode extends Node {
@@ -208,7 +208,7 @@ static PComplex doGeneral(VirtualFrame frame, Node inliningTarget, Object value,
}
}
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateInline
@GenerateCached(false)
@@ -277,7 +277,7 @@ static boolean doIt(VirtualFrame frame, Object o,
}
@Builtin(name = "phase", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class PhaseNode extends PythonUnaryBuiltinNode {
@@ -306,7 +306,7 @@ static double doGeneral(VirtualFrame frame, Object value,
}
@Builtin(name = "polar", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class PolarNode extends PythonUnaryBuiltinNode {
@@ -346,7 +346,7 @@ private static PTuple toPolar(PComplex value, ComplexBuiltins.AbsNode absNode, P
}
@Builtin(name = "rect", minNumOfPositionalArgs = 2)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class RectNode extends PythonBinaryBuiltinNode {
@@ -421,7 +421,7 @@ private static PComplex rect(Node raisingNode, double r, double phi) {
}
@Builtin(name = "log", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class LogNode extends PythonBinaryBuiltinNode {
@@ -516,7 +516,7 @@ private double computeRealPart(double real, double imag) {
}
@Builtin(name = "log10", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class Log10Node extends PythonUnaryBuiltinNode {
@@ -1093,7 +1093,7 @@ static ComplexValue compute(Node inliningTarget, double real, double imag, PRais
}
@Builtin(name = "isclose", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 2, varArgsMarker = true, keywordOnlyNames = {"rel_tol", "abs_tol"})
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
abstract static class IsCloseNode extends PythonBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
index 9cc60db297..882a36875c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java
@@ -156,7 +156,6 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.nodes.util.ToNativePrimitiveStorageNode;
import com.oracle.graal.python.runtime.ExecutionContext;
@@ -188,7 +187,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
@@ -595,7 +593,6 @@ public Object doIt(PFunction func) {
}
@Builtin(name = "get_toolchain_tools_for_venv")
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class GetToolchainToolsForVenv extends PythonBuiltinNode {
private static final class Tool {
@@ -668,7 +665,6 @@ Object getToolPath() {
}
@Builtin(name = "get_toolchain_tool_path", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class GetToolPathNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -686,7 +682,6 @@ protected Object getToolPath(TruffleString tool) {
}
@Builtin(name = "get_toolchain_paths", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class GetToolchainPathsNode extends PythonUnaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
index aec6c98c51..38a0d39fad 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
@@ -79,7 +79,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.nodes.util.NarrowBigIntegerNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -145,7 +145,7 @@ static void checkMathDomainErrorUncached(boolean con, Node raisingNode) {
@GenerateInline
@GenerateCached(false)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
public abstract static class MathUnaryHelperNode extends Node {
@@ -405,7 +405,7 @@ static Object factorialObject(VirtualFrame frame, Object value,
}
@Builtin(name = "comb", minNumOfPositionalArgs = 2)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class CombNode extends PythonBinaryBuiltinNode {
@@ -475,7 +475,7 @@ static Object comb(VirtualFrame frame, Object n, Object k,
}
@Builtin(name = "perm", minNumOfPositionalArgs = 1, parameterNames = {"n", "k"})
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class PermNode extends PythonBinaryBuiltinNode {
@@ -717,7 +717,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
@Builtin(name = "isnan", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
public abstract static class IsNanNode extends PythonUnaryBuiltinNode {
@@ -783,7 +783,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Builtin(name = "ldexp", minNumOfPositionalArgs = 2, numOfPositionalOnlyArgs = 2, parameterNames = {"x", "i"})
@ArgumentClinic(name = "x", conversion = ArgumentClinic.ClinicConversion.Double)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
public abstract static class LdexpNode extends PythonBinaryClinicBuiltinNode {
@@ -1033,7 +1033,7 @@ public int gcdKeywords(Object self, Object[] args, PKeyword[] keywords) {
}
}
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
public abstract static class Gcd2Node extends Node {
@@ -1193,7 +1193,7 @@ public int gcdKeywords(Object self, Object[] args, PKeyword[] keywords) {
@Builtin(name = "nextafter", minNumOfPositionalArgs = 2, parameterNames = {"start", "direction"})
@ArgumentClinic(name = "start", conversion = ArgumentClinic.ClinicConversion.Double)
@ArgumentClinic(name = "direction", conversion = ArgumentClinic.ClinicConversion.Double)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class NextAfterNode extends PythonBinaryClinicBuiltinNode {
@@ -1211,7 +1211,7 @@ static double nextAfter(double start, double direction) {
@Builtin(name = "ulp", minNumOfPositionalArgs = 1, parameterNames = {"x"})
@ArgumentClinic(name = "x", conversion = ArgumentClinic.ClinicConversion.Double)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class UlpNode extends PythonUnaryClinicBuiltinNode {
@@ -1442,7 +1442,7 @@ private static double compute(Node inliningTarget, double value, PRaiseNode rais
}
@Builtin(name = "asinh", minNumOfPositionalArgs = 1, doc = "Return the inverse hyperbolic sine of x.")
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
public abstract static class AsinhNode extends PythonUnaryBuiltinNode {
@@ -1464,7 +1464,7 @@ public static AsinhNode create() {
}
@Builtin(name = "isfinite", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
public abstract static class IsFiniteNode extends PythonUnaryBuiltinNode {
@@ -1493,7 +1493,7 @@ public static boolean isinf(VirtualFrame frame, Object value,
}
@Builtin(name = "isinf", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
public abstract static class IsInfNode extends PythonUnaryBuiltinNode {
@@ -1522,7 +1522,7 @@ public static boolean isinf(VirtualFrame frame, Object value,
}
@Builtin(name = "log", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(MathGuards.class)
@GenerateNodeFactory
@SuppressWarnings("truffle-static-method")
@@ -1980,7 +1980,7 @@ private static double compute(Node inliningTarget, double value, PRaiseNode rais
}
@Builtin(name = "hypot", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, declaresExplicitSelf = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class HypotNode extends PythonVarargsBuiltinNode {
@@ -2400,7 +2400,7 @@ private static double compute(Node inliningTarget, double x, PRaiseNode raiseNod
}
@Builtin(name = "isqrt", minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
public abstract static class IsqrtNode extends PythonUnaryBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
index 15921a5507..8ad0cd329e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java
@@ -61,7 +61,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
@@ -72,7 +71,6 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
@@ -143,7 +141,6 @@ static Object doObject(VirtualFrame frame, Object left, Object right,
// _compare_digest
@Builtin(name = "_compare_digest", minNumOfPositionalArgs = 2)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class CompareDigestNode extends PythonBinaryBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
index e5ed3dad0c..9f2a8457b8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java
@@ -114,7 +114,7 @@
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.GetForeignObjectClassNode;
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
import com.oracle.graal.python.runtime.PythonContext;
@@ -1146,7 +1146,7 @@ static Object remove(Object receiver,
@Builtin(name = "__element_info__", minNumOfPositionalArgs = 3)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class ArrayElementInfoNode extends PythonBuiltinNode {
@Specialization
static boolean keyInfo(Object receiver, long member, TruffleString info,
@@ -1171,7 +1171,6 @@ static boolean keyInfo(Object receiver, long member, TruffleString info,
@Builtin(name = "storage", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class StorageNode extends PythonUnaryBuiltinNode {
@Specialization
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
index 1720e5b837..b83c26208c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
@@ -110,7 +110,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.GilNode;
@@ -148,7 +147,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
@@ -2635,10 +2633,10 @@ static TruffleString getStrError(int code,
}
}
- @Builtin(name = "_exit", minNumOfPositionalArgs = 1)
+ @Builtin(name = "_exit", minNumOfPositionalArgs = 1, parameterNames = {"status"})
+ @ArgumentClinic(name = "status", conversion = ClinicConversion.Int)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
- public abstract static class ExitNode extends PythonUnaryBuiltinNode {
+ public abstract static class ExitNode extends PythonUnaryClinicBuiltinNode {
@TruffleBoundary
@Specialization
Object exit(int status) {
@@ -2667,6 +2665,11 @@ protected void perform(Access access) {
}
throw new ThreadDeath();
}
+
+ @Override
+ protected ArgumentClinicProvider getArgumentClinic() {
+ return PosixModuleBuiltinsClinicProviders.ExitNodeClinicProviderGen.INSTANCE;
+ }
}
@Builtin(name = "waitpid", minNumOfPositionalArgs = 2, parameterNames = {"pid", "options"})
@@ -2916,7 +2919,6 @@ static int system(PBytes command,
@Builtin(name = "urandom", minNumOfPositionalArgs = 1, numOfPositionalOnlyArgs = 1, parameterNames = {"size"})
@ArgumentClinic(name = "size", conversion = ClinicConversion.Index)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class URandomNode extends PythonUnaryClinicBuiltinNode {
@Specialization(guards = "size >= 0")
static PBytes urandom(int size,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
index 5f929437c2..8ff287face 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java
@@ -82,7 +82,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonSenaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.IndirectCallData;
@@ -104,7 +103,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.ExceptionType;
@@ -462,7 +460,6 @@ public int hashCode() {
}
@Builtin(name = "tregex_init_cache", minNumOfPositionalArgs = 3)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class TRegexInitCache extends PythonTernaryBuiltinNode {
@@ -479,7 +476,6 @@ Object call(VirtualFrame frame, PythonObject patternObject, Object pattern, Obje
}
@Builtin(name = "tregex_compile", minNumOfPositionalArgs = 3)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
@ImportStatic(PythonMethod.class)
abstract static class TRegexCompile extends PythonTernaryBuiltinNode {
@@ -625,7 +621,6 @@ protected Object lookupMatchConstructor() {
}
@Builtin(name = "tregex_search", minNumOfPositionalArgs = 6)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
@ImportStatic(PythonMethod.class)
abstract static class TRegexSearch extends PythonSenaryBuiltinNode {
@@ -783,7 +778,6 @@ private PyObjectGetItem getGetItemNode() {
}
@Builtin(name = "tregex_call_exec", minNumOfPositionalArgs = 3)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class TRegexCallExec extends PythonTernaryBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
index e7aef1644f..39da448c39 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ThreadModuleBuiltins.java
@@ -64,6 +64,7 @@
import com.oracle.graal.python.builtins.objects.thread.PThread;
import com.oracle.graal.python.builtins.objects.thread.PThreadLocal;
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
+import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.WriteUnraisableNode;
@@ -77,7 +78,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
@@ -88,10 +88,10 @@
import com.oracle.truffle.api.TruffleThreadBuilder;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
+import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -188,18 +188,19 @@ long getCount(PythonModule self) {
@Builtin(name = "stack_size", minNumOfPositionalArgs = 0, maxNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class GetThreadStackSizeNode extends PythonUnaryBuiltinNode {
- @Specialization
+ @Specialization(guards = "isNoValue(stackSize)")
long getStackSize(@SuppressWarnings("unused") PNone stackSize) {
return getContext().getPythonThreadStackSize();
}
- @Specialization
- static long getStackSize(long stackSize,
+ @Fallback
+ static long getStackSize(VirtualFrame frame, Object stackSizeObj,
@Bind("this") Node inliningTarget,
+ @Cached PyNumberAsSizeNode asSizeNode,
@Cached PRaiseNode raiseNode) {
+ int stackSize = asSizeNode.executeExact(frame, inliningTarget, stackSizeObj);
if (stackSize < 0) {
throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, ErrorMessages.SIZE_MUST_BE_D_OR_S, 0, "a positive value");
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
index 10f9383697..18dcd246ea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java
@@ -49,7 +49,6 @@
import java.util.List;
import java.util.TimeZone;
-import com.oracle.graal.python.nodes.statement.AbstractImportNode;
import org.graalvm.nativeimage.ImageInfo;
import com.oracle.graal.python.PythonLanguage;
@@ -87,7 +86,8 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.statement.AbstractImportNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
import com.oracle.graal.python.runtime.GilNode;
@@ -312,7 +312,6 @@ private static void check(Node inliningTarget, double time, PRaiseNode raiseNode
// time.gmtime([seconds])
@Builtin(name = "gmtime", maxNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class PythonGMTimeNode extends PythonBuiltinNode {
@Specialization
@@ -348,7 +347,6 @@ Object tzset() {
// time.localtime([seconds])
@Builtin(name = "localtime", maxNumOfPositionalArgs = 2, declaresExplicitSelf = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class PythonLocalTimeNode extends PythonBinaryBuiltinNode {
@Specialization
@@ -452,7 +450,6 @@ public long counter() {
@Builtin(name = "process_time", minNumOfPositionalArgs = 1, declaresExplicitSelf = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ProcessTimeNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
@@ -464,7 +461,6 @@ Object getProcesTime(PythonModule self) {
@Builtin(name = "process_time_ns", minNumOfPositionalArgs = 1, declaresExplicitSelf = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ProcessTimeNsNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
@@ -476,7 +472,6 @@ Object getProcesNsTime(PythonModule self) {
@Builtin(name = "thread_time")
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ThreadTimeNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
@@ -487,7 +482,6 @@ Object getProcesTime() {
@Builtin(name = "thread_time_ns")
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ThreadTimeNsNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
@@ -498,7 +492,7 @@ Object getProcesNsTime() {
@Builtin(name = "sleep", minNumOfPositionalArgs = 2, declaresExplicitSelf = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
abstract static class SleepNode extends PythonBuiltinNode {
// see: https://github.com/python/cpython/blob/master/Modules/timemodule.c#L1741
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
index 340340700e..7e162ce88c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
@@ -145,7 +145,6 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
@@ -1115,10 +1114,9 @@ static Object doNative(PythonAbstractNativeObject s,
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Int}, call = Ignored)
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class PyTruffle_Unicode_AsWideChar extends CApiBinaryBuiltinNode {
@Specialization
- static Object doUnicode(Object s, long elementSize,
+ static Object doUnicode(Object s, int elementSize,
@Bind("this") Node inliningTarget,
@Cached UnicodeAsWideCharNode asWideCharNode,
@Cached CastToTruffleStringNode castStr,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
index 2d56ea743f..f94807b80d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java
@@ -105,7 +105,6 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.dsl.Bind;
@@ -115,7 +114,6 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -255,7 +253,6 @@ static Object none(@SuppressWarnings("unused") Object self, @SuppressWarnings("u
@ArgumentClinic(name = "whence", conversion = ArgumentClinic.ClinicConversion.Int, defaultValue = "BufferedIOUtil.SEEK_SET", useDefaultForNone = true)
@GenerateNodeFactory
@ImportStatic(IONodes.class)
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class SeekNode extends PythonTernaryClinicBuiltinNode {
@Override
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
index 7dbf414744..37c778a932 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java
@@ -73,7 +73,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.runtime.GilNode;
@@ -166,7 +166,7 @@ static boolean isSeekable(VirtualFrame frame, PBuffered self,
}
@ImportStatic(PGuards.class)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateInline
@GenerateCached(false)
// PyNumber_AsOff_t
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
index 5cefff275f..186ec651cf 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/StringIOBuiltins.java
@@ -115,7 +115,6 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectExactProfile;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -127,7 +126,6 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -435,7 +433,6 @@ static TruffleString readline(PStringIO self, int size,
@Builtin(name = J_TRUNCATE, minNumOfPositionalArgs = 1, parameterNames = {"$self", "size"})
@ArgumentClinic(name = "size", defaultValue = "PNone.NONE", useDefaultForNone = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class TruncateNode extends ClosedCheckPythonBinaryClinicBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
index 875ca50e13..6f3e42d57a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java
@@ -77,7 +77,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -92,7 +91,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@@ -109,7 +107,6 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@ArgumentClinic(name = "check", conversion = ClinicConversion.Int, defaultValue = "-1", useDefaultForNone = true)
@ArgumentClinic(name = "preset", conversionClass = ExpectUINT32Node.class, defaultValue = "PNone.NO_VALUE")
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class InitNode extends PythonClinicBuiltinNode {
@Override
@@ -135,26 +132,26 @@ static PNone init(VirtualFrame frame, LZMACompressor self, int format, int check
@Specialization(guards = "badIntegrity(format, check)")
@SuppressWarnings("unused")
- static PNone integrityError(LZMACompressor self, long format, long check, Object preset, Object filters,
+ static PNone integrityError(LZMACompressor self, int format, int check, Object preset, Object filters,
@Bind("this") Node inliningTarget) {
throw PRaiseNode.raiseStatic(inliningTarget, ValueError, INTEGRITY_CHECKS_ONLY_SUPPORTED_BY);
}
@Specialization(guards = {"!badIntegrity(format, check)", "badPresetFilters(preset, filters)"})
@SuppressWarnings("unused")
- static PNone presetError(LZMACompressor self, long format, long check, Object preset, Object filters,
+ static PNone presetError(LZMACompressor self, int format, int check, Object preset, Object filters,
@Bind("this") Node inliningTarget) {
throw PRaiseNode.raiseStatic(inliningTarget, ValueError, CANNOT_SPECIFY_PREST_AND_FILTER_CHAIN);
}
@Specialization(guards = {"!badIntegrity(format, check)", "!badPresetFilters(preset, filters)", "badRawFilter(format, filters)"})
@SuppressWarnings("unused")
- static PNone rawError(LZMACompressor self, long format, long check, Object preset, PNone filters,
+ static PNone rawError(LZMACompressor self, int format, int check, Object preset, PNone filters,
@Bind("this") Node inliningTarget) {
throw PRaiseNode.raiseStatic(inliningTarget, ValueError, MUST_SPECIFY_FILTERS);
}
- protected static boolean badIntegrity(long format, long check) {
+ protected static boolean badIntegrity(int format, int check) {
return format != FORMAT_XZ && check != -1 && check != CHECK_NONE;
}
@@ -166,14 +163,13 @@ protected static boolean badRawFilter(long format, Object filters) {
return format == FORMAT_RAW && PGuards.isPNone(filters);
}
- protected static boolean isValid(long format, long check, Object preset, Object filters) {
+ protected static boolean isValid(int format, int check, Object preset, Object filters) {
return !badIntegrity(format, check) && !badPresetFilters(preset, filters) && !badRawFilter(format, filters);
}
}
@Builtin(name = "compress", minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class CompressNode extends PythonBinaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
@@ -221,7 +217,6 @@ static ArrayAndLength doObject(VirtualFrame frame, Object data,
@Builtin(name = "flush", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class FlushNode extends PythonUnaryBuiltinNode {
@Specialization(guards = {"!self.isFlushed()"})
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
index be0e92dd3f..ee3b3138e5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java
@@ -76,7 +76,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.object.PFactory;
@@ -88,7 +87,6 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@@ -104,7 +102,6 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Builtin(name = J___INIT__, minNumOfPositionalArgs = 1, parameterNames = {"$self", "format", "memlimit", "filters"})
@ArgumentClinic(name = "format", conversion = ArgumentClinic.ClinicConversion.Int, defaultValue = "LZMAModuleBuiltins.FORMAT_AUTO", useDefaultForNone = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class InitNode extends PythonQuaternaryClinicBuiltinNode {
@Override
@@ -195,7 +192,6 @@ protected static boolean isRaw(int format) {
@Builtin(name = "decompress", minNumOfPositionalArgs = 2, parameterNames = {"$self", "$data", "max_length"}, needsFrame = true)
@ArgumentClinic(name = "max_length", conversion = ArgumentClinic.ClinicConversion.Int, defaultValue = "-1", useDefaultForNone = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class DecompressNode extends PythonTernaryClinicBuiltinNode {
@Override
@@ -236,7 +232,6 @@ static Object err(LZMADecompressor self, Object data, int maxLength,
@Builtin(name = "eof", minNumOfPositionalArgs = 1, parameterNames = {"self"}, isGetter = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class EofNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -248,7 +243,6 @@ boolean doEof(LZMADecompressor self) {
@Builtin(name = "needs_input", minNumOfPositionalArgs = 1, parameterNames = {"self"}, isGetter = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class NeedsInputNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -260,7 +254,6 @@ boolean doNeedsInput(LZMADecompressor self) {
@Builtin(name = "check", minNumOfPositionalArgs = 1, parameterNames = {"self"}, isGetter = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class CheckNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -278,7 +271,6 @@ static int doCheck(@SuppressWarnings("unused") LZMADecompressor.Java self,
@Builtin(name = "unused_data", minNumOfPositionalArgs = 1, parameterNames = {"self"}, isGetter = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class UnusedDataNode extends PythonUnaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
index 7574a24ee4..6fad856c29 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java
@@ -95,7 +95,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
import com.oracle.graal.python.runtime.NFILZMASupport;
import com.oracle.graal.python.runtime.NativeLibrary;
@@ -107,7 +106,6 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -291,7 +289,6 @@ LZMAObject doNew(Object cls, @SuppressWarnings("unused") Object arg,
@Builtin(name = "is_check_supported", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class IsCheckSupportedNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -305,7 +302,6 @@ static boolean doInt(VirtualFrame frame, Object checkID,
@Builtin(name = "_encode_filter_properties", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class EncodeFilterPropertiesNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -318,7 +314,6 @@ static PBytes encode(VirtualFrame frame, Object filter,
@Builtin(name = "_decode_filter_properties", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class DecodeFilterPropertiesNode extends PythonBinaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
index 6eae81e755..b0986e0b33 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java
@@ -86,7 +86,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.NFIZlibSupport;
import com.oracle.graal.python.runtime.NativeLibrary;
@@ -106,7 +105,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.NonIdempotent;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
@@ -402,7 +400,6 @@ long nativeCrc32(byte[] bytes, int len, int value,
// zlib.adler32(data[, value])
@Builtin(name = "adler32", minNumOfPositionalArgs = 1, numOfPositionalOnlyArgs = 2, parameterNames = {"data", "value"})
@ArgumentClinic(name = "value", conversionClass = ZLibModuleBuiltins.ExpectIntNode.class, defaultValue = "PNone.NO_VALUE", useDefaultForNone = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class Adler32Node extends PythonBinaryClinicBuiltinNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bool/BoolBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bool/BoolBuiltins.java
index c418fc27cc..39d1418252 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bool/BoolBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bool/BoolBuiltins.java
@@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -65,9 +65,14 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
}
@Builtin(name = J___STR__, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
abstract static class StrNode extends PythonBuiltinNode {
+ @Specialization
+ static TruffleString doBoolean(boolean self) {
+ return self ? T_TRUE : T_FALSE;
+ }
+
@Specialization
public static TruffleString doLong(long self) {
return self == 1 ? T_TRUE : T_FALSE;
@@ -85,7 +90,6 @@ abstract static class RepNode extends StrNode {
}
@Slot(value = SlotKind.nb_and, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class AndNode extends BinaryOpBuiltinNode {
@Specialization
@@ -101,7 +105,6 @@ static Object doOther(VirtualFrame frame, Object self, Object other,
}
@Slot(value = SlotKind.nb_or, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class OrNode extends BinaryOpBuiltinNode {
@Specialization
@@ -117,7 +120,6 @@ static Object doOther(VirtualFrame frame, Object self, Object other,
}
@Slot(value = SlotKind.nb_xor, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class XorNode extends BinaryOpBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
index fad33a8aa9..73c05dea87 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java
@@ -124,7 +124,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
@@ -152,7 +151,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
@@ -1665,7 +1663,6 @@ private static PList getBytesResult(List bytes, ListNodes.AppendNode app
@ArgumentClinic(name = "sep", conversionClass = ExpectByteLikeNode.class, defaultValue = "BytesCommonBuiltins.AbstractSplitNode.WHITESPACE")
@ArgumentClinic(name = "maxsplit", conversionClass = ExpectIntNode.class, defaultValue = "Integer.MAX_VALUE")
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class SplitNode extends AbstractSplitNode {
protected int find(byte[] bytes, int len, byte[] sep, int start, int end) {
@@ -1760,7 +1757,6 @@ protected List splitDelimiter(byte[] bytes, int len, byte[] sep, int max
@ArgumentClinic(name = "sep", conversionClass = ExpectByteLikeNode.class, defaultValue = "BytesCommonBuiltins.AbstractSplitNode.WHITESPACE")
@ArgumentClinic(name = "maxsplit", conversionClass = ExpectIntNode.class, defaultValue = "Integer.MAX_VALUE")
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class RSplitNode extends AbstractSplitNode {
protected int find(byte[] bytes, int len, byte[] sep, int start, int end) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
index a14a8f779e..94785edf82 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java
@@ -97,7 +97,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.formatting.ComplexFormatter;
import com.oracle.graal.python.runtime.formatting.InternalFormat;
@@ -611,7 +611,7 @@ private static PComplex complexToComplexBoundary(double leftRead, double leftIma
@GenerateInline
@GenerateCached(false)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerAndFloatTypes.class)
abstract static class ComplexEqNode extends Node {
public abstract Object execute(Node inliningTarget, Object left, Object right);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
index fd44d02fcc..17854e35d6 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java
@@ -88,7 +88,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -480,7 +479,6 @@ protected Object op(double self) {
@Builtin(name = "fromhex", minNumOfPositionalArgs = 2, isClassmethod = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class FromHexNode extends PythonBuiltinNode {
@TruffleBoundary
@@ -909,7 +907,6 @@ protected Object op(double arg) {
@Builtin(name = J___FLOOR__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class FloorNode extends PythonUnaryBuiltinNode {
@Specialization
static Object floor(Object self,
@@ -922,7 +919,6 @@ static Object floor(Object self,
@Builtin(name = J___CEIL__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class CeilNode extends PythonUnaryBuiltinNode {
@Specialization
static Object ceil(Object self,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
index 3b7cf6e569..80081e8bea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java
@@ -58,7 +58,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
@@ -68,7 +67,6 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -112,7 +110,6 @@ static TruffleString setQualname(@SuppressWarnings("unused") PBuiltinFunction se
}
@Builtin(name = J___OBJCLASS__, minNumOfPositionalArgs = 1, isGetter = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
public abstract static class ObjclassNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.getEnclosingType() == null")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
index fde1aecc90..bfaf3ba982 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java
@@ -76,7 +76,6 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -88,7 +87,6 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -118,7 +116,6 @@ static Object doFunction(PFunction self, @SuppressWarnings("unused") PNone insta
}
@Builtin(name = J___REPR__, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class ReprNode extends PythonUnaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
index 591a6b8b28..cb85579bf7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/MethodDescriptorBuiltins.java
@@ -59,7 +59,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.DescrGetBuiltinNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -67,7 +66,6 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.strings.TruffleString;
@CoreFunctions(extendClasses = PythonBuiltinClassType.PBuiltinFunction)
@@ -114,7 +112,6 @@ static Object doBuiltinFunction(PBuiltinFunction self, Object instance, Object k
}
@Builtin(name = J___REPR__, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class ReprNode extends PythonUnaryBuiltinNode {
@Specialization(guards = "self.getEnclosingType() == null")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
index 973253baff..ce2ee82afd 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/WrapperDescriptorBuiltins.java
@@ -59,7 +59,6 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.DescrGetBuiltinNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -67,7 +66,6 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.strings.TruffleString;
@CoreFunctions(extendClasses = PythonBuiltinClassType.WrapperDescriptor)
@@ -108,7 +106,6 @@ static Object doBuiltinFunction(PBuiltinFunction self, Object instance, Object k
}
@Builtin(name = J___REPR__, minNumOfPositionalArgs = 1)
- @TypeSystemReference(PythonArithmeticTypes.class)
@GenerateNodeFactory
abstract static class ReprNode extends PythonUnaryBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index cac36977a7..6681cda914 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -112,7 +112,7 @@
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.formatting.FloatFormatter;
@@ -177,7 +177,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Builtin(name = J___ROUND__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)
@GenerateNodeFactory
@ImportStatic(MathGuards.class)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class RoundNode extends PythonBinaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization
@@ -359,7 +359,7 @@ private static BigDecimal op(BigInteger arg, int n) {
@Slot(value = SlotKind.nb_add, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class AddNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@@ -443,7 +443,7 @@ public static AddNode create() {
@Slot(value = SlotKind.nb_subtract, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class SubNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@@ -527,7 +527,7 @@ public static SubNode create() {
@Slot(value = SlotKind.nb_true_divide, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class TrueDivNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@@ -637,7 +637,7 @@ public static TrueDivNode create() {
}
@Slot(value = SlotKind.nb_floor_divide, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class FloorDivNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@@ -810,7 +810,7 @@ static Object doGeneric(VirtualFrame frame, Object left, Object right,
}
@Slot(value = SlotKind.nb_remainder, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class ModNode extends BinaryOpBuiltinNode {
public abstract int executeInt(int left, int right) throws UnexpectedResultException;
@@ -972,7 +972,7 @@ public static ModNode create() {
@Slot(value = SlotKind.nb_multiply, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class MulNode extends BinaryOpBuiltinNode {
public abstract Object execute(int left, int right);
@@ -1084,7 +1084,7 @@ public static MulNode create() {
@Slot(value = SlotKind.nb_power, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@ImportStatic(MathGuards.class)
@ReportPolymorphism
public abstract static class PowNode extends PythonTernaryBuiltinNode {
@@ -1423,7 +1423,7 @@ static int absBoolean(boolean arg) {
@Builtin(name = J___CEIL__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class CeilNode extends PythonUnaryBuiltinNode {
@Specialization
static int ceil(int arg) {
@@ -1443,7 +1443,7 @@ static PInt ceil(PInt arg) {
@Builtin(name = J___FLOOR__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class FloorNode extends PythonUnaryBuiltinNode {
@Specialization
static int floor(int arg) {
@@ -1568,7 +1568,7 @@ static BigInteger not(BigInteger value) {
@Slot(value = SlotKind.nb_lshift, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class LShiftNode extends BinaryOpBuiltinNode {
public abstract int executeInt(int left, int right) throws UnexpectedResultException;
@@ -1795,7 +1795,7 @@ public static LShiftNode create() {
}
@Slot(value = SlotKind.nb_rshift, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class RShiftNode extends BinaryOpBuiltinNode {
public abstract int executeInt(int left, int right) throws UnexpectedResultException;
@@ -2017,7 +2017,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
}
@Slot(value = SlotKind.nb_and, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class AndNode extends BinaryBitwiseNode {
@@ -2044,7 +2044,7 @@ public static AndNode create() {
}
@Slot(value = SlotKind.nb_or, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class OrNode extends BinaryBitwiseNode {
@@ -2071,7 +2071,7 @@ public static OrNode create() {
}
@Slot(value = SlotKind.nb_xor, isComplex = true)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@GenerateNodeFactory
public abstract static class XorNode extends BinaryBitwiseNode {
@Override
@@ -2098,7 +2098,7 @@ public static XorNode create() {
@Builtin(name = J___EQ__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class EqNode extends PythonBinaryBuiltinNode {
@Specialization
static boolean eqLL(long a, long b) {
@@ -2234,7 +2234,7 @@ static PNotImplemented eq(Object a, Object b) {
@Builtin(name = J___NE__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class NeNode extends PythonBinaryBuiltinNode {
@Specialization
static boolean eqLL(long a, long b) {
@@ -2283,7 +2283,7 @@ static PNotImplemented eq(Object a, Object b) {
@Builtin(name = J___LT__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
@ImportStatic(FromNativeSubclassNode.class)
public abstract static class LtNode extends PythonBinaryBuiltinNode {
@Specialization
@@ -2365,7 +2365,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
@Builtin(name = J___LE__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class LeNode extends PythonBinaryBuiltinNode {
@Specialization
static boolean doII(int left, int right) {
@@ -2409,7 +2409,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
@Builtin(name = J___GT__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class GtNode extends PythonBinaryBuiltinNode {
@Specialization
@@ -2454,7 +2454,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
@Builtin(name = J___GE__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class GeNode extends PythonBinaryBuiltinNode {
@Specialization
@@ -2499,7 +2499,7 @@ static PNotImplemented doGeneric(Object a, Object b) {
@GenerateInline
@GenerateCached(false)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class RichCompareHelperNode extends Node {
abstract Object execute(Node inliningTarget, Object left, Object right, ComparisonOp op);
@@ -2568,7 +2568,7 @@ static Object doCached(Object left, Object right, @SuppressWarnings("unused") in
@ArgumentClinic(name = "signed", conversion = ClinicConversion.Boolean, defaultValue = "false")
@GenerateNodeFactory
@SuppressWarnings("unused")
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class ToBytesNode extends PythonClinicBuiltinNode {
@TruffleBoundary
@@ -2828,7 +2828,7 @@ static boolean toBoolean(PythonNativeVoidPtr self,
@Builtin(name = J___STR__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class StrNode extends PythonBuiltinNode {
@Specialization
@@ -2906,7 +2906,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
return FormatNodeClinicProviderGen.INSTANCE;
}
- // We cannot use PythonArithmeticTypes, because for empty format string we need to call the
+ // We cannot use PythonIntegerTypes, because for empty format string we need to call the
// boolean's __str__ and not int's __str__ (that specialization is inherited)
@Specialization(guards = "!formatString.isEmpty()")
static TruffleString formatB(boolean self, TruffleString formatString,
@@ -3003,7 +3003,7 @@ private static void validateIntegerSpec(Node inliningTarget, PRaiseNode raiseNod
@Builtin(name = J___HASH__, minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class HashNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -3043,7 +3043,7 @@ private static long hashCodeBoundary(Object object) {
@Builtin(name = "bit_count", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class BitCountNode extends PythonBuiltinNode {
@Specialization
static int bitCount(int i) {
@@ -3064,7 +3064,7 @@ static int bitCount(PInt i) {
@Builtin(name = "bit_length", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class BitLengthNode extends PythonUnaryBuiltinNode {
public abstract int execute(Object argument);
@@ -3087,7 +3087,7 @@ static int bitLength(PInt argument) {
@Builtin(name = "is_integer", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class IsIntegerNode extends PythonUnaryBuiltinNode {
@Specialization
static boolean doLong(long argument) {
@@ -3180,7 +3180,7 @@ static Object doI(Object self,
@Slot(value = SlotKind.nb_float, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class FloatNode extends PythonUnaryBuiltinNode {
@Specialization
static double doBoolean(boolean self) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
index 370ecb228a..e40525b5af 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java
@@ -114,7 +114,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.function.builtins.clinic.LongIndexConverterNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.runtime.AsyncHandler;
import com.oracle.graal.python.runtime.IndirectCallData;
import com.oracle.graal.python.runtime.PosixSupport;
@@ -135,7 +134,6 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
@@ -471,7 +469,6 @@ static long readline(PMMap self) {
@Builtin(name = "read_byte", minNumOfPositionalArgs = 1)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ReadByteNode extends PythonUnaryBuiltinNode {
@Specialization
@@ -496,7 +493,6 @@ static int readByte(VirtualFrame frame, PMMap self,
@Builtin(name = "read", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class ReadNode extends PythonBuiltinNode {
@Specialization
@@ -659,7 +655,6 @@ static Object seek(PMMap self, long dist, int how,
@Builtin(name = "find", minNumOfPositionalArgs = 2, parameterNames = {"$self", "sub", "start", "end"})
@ArgumentClinic(name = "sub", conversion = ClinicConversion.ReadableBuffer)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class FindNode extends PythonQuaternaryClinicBuiltinNode {
private static final int BUFFER_SIZE = 1024; // keep in sync with test_mmap.py
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
index beed98da00..bf12a815e4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/random/RandomBuiltins.java
@@ -67,7 +67,7 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.object.PFactory;
@@ -91,7 +91,7 @@ protected List extends NodeFactory extends PythonBuiltinBaseNode>> getNodeFa
@Builtin(name = "seed", minNumOfPositionalArgs = 1, parameterNames = {"$self", "seed"})
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
public abstract static class SeedNode extends PythonBuiltinNode {
@Specialization
@TruffleBoundary
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
index 79c58f9caa..3e678b5c7a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java
@@ -88,7 +88,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaBigIntegerNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -631,7 +631,7 @@ public static GetItemNode getUncached() {
@Builtin(name = J___CONTAINS__, minNumOfPositionalArgs = 2)
@GenerateNodeFactory
@ImportStatic(PGuards.class)
- @TypeSystemReference(PythonArithmeticTypes.class)
+ @TypeSystemReference(PythonIntegerTypes.class)
abstract static class ContainsNode extends PythonBinaryBuiltinNode {
private static final BigInteger MINUS_ONE = BigInteger.ONE.negate();
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
index 86d8a854e1..812fbc7876 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java
@@ -122,7 +122,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
@@ -143,7 +142,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
@@ -551,7 +549,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
@Builtin(name = "num_tickets", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class NumTicketsNode extends PythonBinaryBuiltinNode {
@SuppressWarnings("unused")
@Specialization(guards = "isNoValue(value)")
@@ -712,7 +709,6 @@ static Object storeStats(VirtualFrame frame, PSSLContext self,
@Builtin(name = "load_verify_locations", minNumOfPositionalArgs = 1, parameterNames = {"$self", "cafile", "capath", "cadata"})
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class LoadVerifyLocationsNode extends PythonQuaternaryBuiltinNode {
@Specialization
Object load(VirtualFrame frame, PSSLContext self, Object cafile, Object capath, Object cadata,
@@ -835,7 +831,6 @@ private static Collection> fromBytesLike(byte[] bytes) {
@Builtin(name = "load_cert_chain", minNumOfPositionalArgs = 2, parameterNames = {"$self", "certfile", "keyfile", "password"})
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class LoadCertChainNode extends PythonQuaternaryBuiltinNode {
@Specialization
Object load(VirtualFrame frame, PSSLContext self, Object certfile, Object keyfile, Object passwordObj,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
index a525f5a831..91aa28c98c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java
@@ -154,7 +154,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
@@ -184,7 +183,6 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@@ -234,7 +232,6 @@ static TruffleString doGeneric(Object self,
@Builtin(name = J___FORMAT__, minNumOfPositionalArgs = 2, parameterNames = {"$self", "format_spec"})
@ArgumentClinic(name = "format_spec", conversion = ClinicConversion.TString)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class FormatNode extends FormatNodeBase {
@Override
protected ArgumentClinicProvider getArgumentClinic() {
@@ -1763,7 +1760,6 @@ static int rindex(Object selfObj, Object subObj, int start, int end,
@ArgumentClinic(name = "encoding", conversion = ClinicConversion.TString, defaultValue = "T_UTF8", useDefaultForNone = true)
@ArgumentClinic(name = "errors", conversion = ClinicConversion.TString, defaultValue = "T_STRICT", useDefaultForNone = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class EncodeNode extends PythonTernaryClinicBuiltinNode {
@Override
@@ -1794,7 +1790,6 @@ static Object doIt(VirtualFrame frame, Object selfObj, TruffleString encoding, T
@Slot(value = SlotKind.sq_repeat, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
abstract static class MulNode extends SqRepeatBuiltinNode {
@Specialization(guards = "right <= 0")
@@ -2412,7 +2407,6 @@ static Object doIt(VirtualFrame frame, Object self, int index,
@Slot(value = SlotKind.mp_subscript, isComplex = true)
@GenerateNodeFactory
- @TypeSystemReference(PythonArithmeticTypes.class)
public abstract static class StrGetItemNode extends MpSubscriptBuiltinNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 5aed080f1e..2c0ccc6716 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -58,6 +58,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
import com.oracle.graal.python.util.OverflowException;
@@ -72,6 +73,7 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
@@ -80,14 +82,13 @@
@GenerateCached(false)
@ImportStatic(PGuards.class)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberAddBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, but it additionally needs to check PInts for only builtin ints
*/
- // XXX this could benefit from the type system conversions, but that would also unpack PFloat
- // which we don't want
@Specialization(rewriteOn = ArithmeticException.class)
static int doII(int left, int right) {
@@ -163,16 +164,6 @@ public static double doDL(double left, long right) {
public static double doLD(long left, double right) {
return left + right;
}
-
- @Specialization
- public static double doDI(double left, int right) {
- return left + right;
- }
-
- @Specialization
- public static double doID(int left, double right) {
- return left + right;
- }
}
@GenerateInline(inlineByDefault = true)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
index 76f2d6e886..ebd030ea24 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTimeFromObjectNode.java
@@ -47,7 +47,7 @@
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -66,7 +66,7 @@
/**
* Equivalent of {@code _PyTime_FromObject} from CPython.
*/
-@TypeSystemReference(PythonArithmeticTypes.class)
+@TypeSystemReference(PythonIntegerAndFloatTypes.class)
@GenerateInline
@GenerateCached(false)
public abstract class PyTimeFromObjectNode extends PNodeWithContext {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
index 63b453e941..8e0bf95150 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java
@@ -41,7 +41,7 @@
import com.oracle.graal.python.nodes.expression.BinaryComparisonNodeFactory.LtNodeGen;
import com.oracle.graal.python.nodes.expression.BinaryComparisonNodeFactory.NeNodeGen;
import com.oracle.graal.python.nodes.object.IsNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -52,7 +52,7 @@
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
-@TypeSystemReference(PythonArithmeticTypes.class)
+@TypeSystemReference(PythonIntegerTypes.class)
public abstract class BinaryComparisonNode extends BinaryOpNode {
private abstract static class ErrorNode extends BinaryComparisonNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerAndFloatTypes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerAndFloatTypes.java
new file mode 100644
index 0000000000..fe6433b80f
--- /dev/null
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerAndFloatTypes.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.oracle.graal.python.nodes.truffle;
+
+import com.oracle.graal.python.builtins.objects.floats.PFloat;
+import com.oracle.truffle.api.dsl.ImplicitCast;
+import com.oracle.truffle.api.dsl.TypeSystem;
+
+/**
+ * Type system that automatically unpacks PFloat object to the contained double value. Should only
+ * be used in nodes where CPython directly accesses f_val.
+ */
+@TypeSystem
+public class PythonIntegerAndFloatTypes extends PythonIntegerTypes {
+ @ImplicitCast
+ public static double PFloatToDouble(PFloat value) {
+ // NOTE: That's correct because we just use it in arithmetic operations where CPython also
+ // access the value ('f_val') directly. So, even if the object is subclassed, it is ignored.
+ return value.getValue();
+ }
+}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonArithmeticTypes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerTypes.java
similarity index 50%
rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonArithmeticTypes.java
rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerTypes.java
index c8b5d6b682..054c7a4508 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonArithmeticTypes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerTypes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2022, Oracle and/or its affiliates.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
@@ -25,34 +25,16 @@
*/
package com.oracle.graal.python.nodes.truffle;
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject;
-import com.oracle.graal.python.builtins.objects.floats.PFloat;
-import com.oracle.graal.python.nodes.PGuards;
import com.oracle.truffle.api.dsl.ImplicitCast;
-import com.oracle.truffle.api.dsl.TypeCast;
-import com.oracle.truffle.api.dsl.TypeCheck;
import com.oracle.truffle.api.dsl.TypeSystem;
/**
* This type system is supposed to be used in builtin nodes to reduce the number of specializations
- * due to type combinations. A node that needs to handle all combinations of Python {@code int} and
- * {@code float} types can just use the most general primitive type, i.e., in case of Python type
- * {@code int} use Java {@code long} and in case of Python type {@code float} use Java
- * {@code double}. {@code PInt} needs to be treated separately because of its arbitrary precision.
- *
- * Only use in nodes where it is known that {@code PInt} and {@code PFloat} objects are not
- * subclassed!
+ * due to type combinations. Booleans and ints are converted to long. PInt needs to be handled
+ * separately.
*/
@TypeSystem
-public abstract class PythonArithmeticTypes {
-
- @ImplicitCast
- public static double PFloatToDouble(PFloat value) {
- // NOTE: That's correct because we just use it in arithmetic operations where CPython also
- // access the value ('f_val') directly. So, even if the object is subclassed, it is ignored.
- return value.getValue();
- }
+public abstract class PythonIntegerTypes {
@ImplicitCast
public static int booleanToInt(boolean value) {
@@ -68,24 +50,4 @@ public static long booleanToLong(boolean value) {
public static long intToLong(int value) {
return value;
}
-
- @TypeCheck(PythonNativeObject.class)
- public static boolean isNativeObject(Object object) {
- return PythonNativeObject.isInstance(object);
- }
-
- @TypeCast(PythonNativeObject.class)
- public static PythonNativeObject asNativeObject(Object object) {
- return PythonNativeObject.cast(object);
- }
-
- @TypeCheck(PythonNativeClass.class)
- public static boolean isNativeClass(Object object) {
- return PGuards.isNativeClass(object);
- }
-
- @TypeCast(PythonNativeClass.class)
- public static PythonNativeClass asNativeClass(Object object) {
- return PythonNativeClass.cast(object);
- }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
index 00e3280a87..2b1f875931 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaBigIntegerNode.java
@@ -51,7 +51,6 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -59,10 +58,8 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
-@TypeSystemReference(PythonArithmeticTypes.class)
@GenerateUncached
@GenerateInline(inlineByDefault = true)
@GenerateCached
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaDoubleNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaDoubleNode.java
index baadf51e10..7f9f6b80e1 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaDoubleNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaDoubleNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,7 +50,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Cached;
@@ -73,8 +73,8 @@
@GenerateUncached
@GenerateInline
@GenerateCached(false)
-@TypeSystemReference(PythonArithmeticTypes.class)
@ImportStatic(MathGuards.class)
+@TypeSystemReference(PythonIntegerAndFloatTypes.class)
public abstract class CastToJavaDoubleNode extends PNodeWithContext {
public abstract double execute(Node inliningTarget, Object x);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntNode.java
index d9584d01b7..7ab4b8ba5f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaIntNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -42,7 +42,7 @@
import com.oracle.graal.python.builtins.modules.MathGuards;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
@@ -51,7 +51,7 @@
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
-@TypeSystemReference(PythonArithmeticTypes.class)
+@TypeSystemReference(PythonIntegerTypes.class)
@ImportStatic(MathGuards.class)
@GenerateInline
@GenerateCached(false)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
index 44f8d1bf73..c825a8e1ae 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNode.java
@@ -49,7 +49,7 @@
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -72,7 +72,7 @@
* Note that since Java {@code long} is signed, the values in the between 2^63 and 2^64-1 are
* returned as negative numbers.
*/
-@TypeSystemReference(PythonArithmeticTypes.class)
+@TypeSystemReference(PythonIntegerTypes.class)
@GenerateUncached
@GenerateInline
@GenerateCached(false)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
index 94265ee82b..848adfa7c2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CoerceToComplexNode.java
@@ -51,7 +51,7 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
-import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerAndFloatTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -65,7 +65,7 @@
@GenerateInline
@GenerateCached(false)
-@TypeSystemReference(PythonArithmeticTypes.class)
+@TypeSystemReference(PythonIntegerAndFloatTypes.class)
@ImportStatic(PGuards.class)
public abstract class CoerceToComplexNode extends PNodeWithContext {
diff --git a/mx.graalpython/copyrights/overrides b/mx.graalpython/copyrights/overrides
index 99a7d617eb..e385ca0023 100644
--- a/mx.graalpython/copyrights/overrides
+++ b/mx.graalpython/copyrights/overrides
@@ -697,7 +697,7 @@ graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/BuiltinFunctionRootNode.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/PythonBuiltinNode.java,zippy.copyright
-graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonArithmeticTypes.java,zippy.copyright
+graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerTypes.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java,zippy.copyright
From e0be41d49f0adeec7b6212b483a709f8ab6a457b Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 12:07:13 +0100
Subject: [PATCH 036/512] Remove PythonTypes
---
.../cext/PythonCextAbstractBuiltins.java | 3 -
.../modules/cext/PythonCextSetBuiltins.java | 3 -
.../cext/PythonCextUnicodeBuiltins.java | 14 ++---
.../cext/capi/ExternalFunctionNodes.java | 5 +-
.../builtins/objects/type/TypeBuiltins.java | 18 +++---
.../builtins/objects/type/TypeNodes.java | 5 +-
.../graal/python/nodes/call/CallNode.java | 3 -
.../call/special/AbstractCallMethodNode.java | 3 -
.../python/nodes/object/GetClassNode.java | 5 +-
.../nodes/object/IsForeignObjectNode.java | 5 +-
.../python/nodes/truffle/PythonTypes.java | 63 -------------------
mx.graalpython/copyrights/overrides | 1 -
12 files changed, 15 insertions(+), 113 deletions(-)
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 56e6b7ef98..6cfaff3a52 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -155,7 +155,6 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
@@ -167,7 +166,6 @@
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -645,7 +643,6 @@ static Object setItem(Object obj, long key, Object value,
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Py_ssize_t, Py_ssize_t}, call = Direct)
- @TypeSystemReference(PythonTypes.class)
abstract static class PySequence_GetSlice extends CApiTernaryBuiltinNode {
@Specialization(guards = "checkNode.execute(inliningTarget, obj)", limit = "1")
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
index e52002b3f0..e3468a04ed 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java
@@ -79,14 +79,12 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
@@ -134,7 +132,6 @@ int fallback(@SuppressWarnings("unused") Object anyset, @SuppressWarnings("unuse
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Py_ssize_t}, call = Ignored)
- @TypeSystemReference(PythonTypes.class)
abstract static class _PyTruffleSet_NextEntry extends CApiBinaryBuiltinNode {
@Specialization(guards = "pos < size(inliningTarget, set, sizeNode)")
static Object nextEntry(PSet set, long pos,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
index 7e162ce88c..35a98ccc94 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java
@@ -145,7 +145,6 @@
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.exception.PException;
@@ -160,7 +159,6 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.CachedLibrary;
@@ -377,11 +375,10 @@ static Object find(Object format, @SuppressWarnings("unused") Object args,
}
@CApiBuiltin(ret = Py_ssize_t, args = {PyObject, PY_UCS4, Py_ssize_t, Py_ssize_t, Int}, call = Direct)
- @TypeSystemReference(PythonTypes.class)
@ImportStatic(PythonCextUnicodeBuiltins.class)
abstract static class PyUnicode_FindChar extends CApi5BuiltinNode {
@Specialization(guards = {"isString(string) || isStringSubtype(inliningTarget, string, getClassNode, isSubtypeNode)", "direction > 0"})
- static Object find(Object string, Object c, long start, long end, @SuppressWarnings("unused") long direction,
+ static Object find(Object string, Object c, long start, long end, @SuppressWarnings("unused") int direction,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached ChrNode chrNode,
@Cached FindNode findNode,
@@ -391,7 +388,7 @@ static Object find(Object string, Object c, long start, long end, @SuppressWarni
}
@Specialization(guards = {"isString(string) || isStringSubtype(inliningTarget, string, getClassNode, isSubtypeNode)", "direction <= 0"})
- static Object find(Object string, Object c, long start, long end, @SuppressWarnings("unused") long direction,
+ static Object find(Object string, Object c, long start, long end, @SuppressWarnings("unused") int direction,
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
@Shared @Cached ChrNode chrNode,
@Cached RFindNode rFindNode,
@@ -411,7 +408,6 @@ static Object find(Object string, @SuppressWarnings("unused") Object c, @Suppres
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Py_ssize_t, Py_ssize_t}, call = Direct)
- @TypeSystemReference(PythonTypes.class)
@ImportStatic(PythonCextUnicodeBuiltins.class)
abstract static class PyUnicode_Substring extends CApiTernaryBuiltinNode {
@Specialization(guards = {"isString(s) || isStringSubtype(s, inliningTarget, getClassNode, isSubtypeNode)"}, limit = "1")
@@ -526,11 +522,10 @@ static Object compare(Object left, Object right,
}
@CApiBuiltin(ret = Py_ssize_t, args = {PyObject, PyObject, Py_ssize_t, Py_ssize_t, Int}, call = Direct)
- @TypeSystemReference(PythonTypes.class)
@ImportStatic(PythonCextUnicodeBuiltins.class)
abstract static class PyUnicode_Tailmatch extends CApi5BuiltinNode {
@Specialization(guards = {"isAnyString(inliningTarget, string, getClassNode, isSubtypeNode)", "isAnyString(inliningTarget, substring, getClassNode, isSubtypeNode)", "direction > 0"})
- static int tailmatch(Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
+ static int tailmatch(Object string, Object substring, long start, long end, @SuppressWarnings("unused") int direction,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectLookupAttr lookupAttrNode,
@Shared @Cached PySliceNew sliceNode,
@@ -544,7 +539,7 @@ static int tailmatch(Object string, Object substring, long start, long end, @Sup
}
@Specialization(guards = {"isAnyString(inliningTarget, string, getClassNode, isSubtypeNode)", "isAnyString(inliningTarget, substring, getClassNode, isSubtypeNode)", "direction <= 0"})
- static int tailmatch(Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
+ static int tailmatch(Object string, Object substring, long start, long end, @SuppressWarnings("unused") int direction,
@Bind("this") Node inliningTarget,
@Shared @Cached PyObjectLookupAttr lookupAttrNode,
@Shared @Cached PySliceNew sliceNode,
@@ -589,7 +584,6 @@ static Object encode(@SuppressWarnings("unused") Object obj, @SuppressWarnings("
}
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject, Py_ssize_t}, call = Direct)
- @TypeSystemReference(PythonTypes.class)
@ImportStatic(PythonCextUnicodeBuiltins.class)
abstract static class PyUnicode_Replace extends CApiQuaternaryBuiltinNode {
@Specialization(guards = {"isString(s)", "isString(substr)", "isString(replstr)"})
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
index 419eabe0a2..a90f7e1ce4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java
@@ -118,7 +118,6 @@
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
@@ -152,7 +151,6 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.exception.AbstractTruffleException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ArityException;
@@ -2255,7 +2253,6 @@ static void doObjectGeneric(NativeObjectSequenceStorage storage,
* Special helper nodes that materializes any primitive that would leak the wrapper if the
* reference is owned by managed code only.
*/
- @TypeSystemReference(PythonTypes.class)
@GenerateInline(false)
abstract static class MaterializePrimitiveNode extends Node {
@@ -2268,7 +2265,7 @@ static PInt doInteger(PythonLanguage language, int i) {
return PFactory.createInt(language, i);
}
- @Specialization(replaces = "doInteger")
+ @Specialization
static PInt doLong(PythonLanguage language, long l) {
return PFactory.createInt(language, l);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
index 9268bd9af5..46d1be5146 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java
@@ -92,7 +92,6 @@
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper;
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
@@ -168,7 +167,6 @@
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.nodes.util.SplitArgsNode;
@@ -194,7 +192,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -278,7 +275,7 @@ static Object getDoc(VirtualFrame frame, PythonClass self, @SuppressWarnings("un
}
@Specialization
- static Object getDoc(PythonNativeClass self, @SuppressWarnings("unused") PNone value) {
+ static Object getDoc(PythonAbstractNativeObject self, @SuppressWarnings("unused") PNone value) {
return ReadAttributeFromObjectNode.getUncachedForceType().execute(self, T___DOC__);
}
@@ -559,7 +556,7 @@ protected Object doIt1(VirtualFrame frame, @SuppressWarnings("unused") PythonAbs
@Shared @Cached BindNew bindNew,
@Shared @Cached PRaiseNode raiseNode) {
checkFlags(self, inliningTarget, getTypeFlagsNode, raiseNode);
- return op(frame, inliningTarget, PythonNativeClass.cast(cachedSelf), arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
+ return op(frame, inliningTarget, cachedSelf, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
@Specialization(replaces = "doIt1")
@@ -572,7 +569,7 @@ protected Object doItIndirect1(VirtualFrame frame, PythonAbstractNativeObject se
@Shared @Cached BindNew bindNew,
@Shared @Cached PRaiseNode raiseNode) {
checkFlags(self, inliningTarget, getTypeFlagsNode, raiseNode);
- return op(frame, inliningTarget, PythonNativeClass.cast(self), arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
+ return op(frame, inliningTarget, self, arguments, keywords, getInstanceClassNode, hasInit, gotInitResult, bindNew, raiseNode);
}
private void checkFlags(PythonAbstractNativeObject self, Node inliningTarget, GetTypeFlagsNode getTypeFlagsNode, PRaiseNode raiseNode) {
@@ -907,7 +904,7 @@ static Object doManaged(PythonManagedClass self,
}
@Specialization
- static Object doNative(PythonNativeClass self,
+ static Object doNative(PythonAbstractNativeObject self,
@Cached CStructAccess.ReadObjectNode getTpDictNode) {
return getTpDictNode.readFromObj(self, CFields.PyTypeObject__tp_dict);
}
@@ -1050,7 +1047,6 @@ static PList getSubclasses(Object cls,
}
@GenerateNodeFactory
- @TypeSystemReference(PythonTypes.class)
abstract static class AbstractSlotNode extends PythonBinaryBuiltinNode {
}
@@ -1194,7 +1190,7 @@ static Object setModule(PythonClass cls, Object value,
}
@Specialization(guards = "isNoValue(value)")
- static Object getModule(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
+ static Object getModule(PythonAbstractNativeObject cls, @SuppressWarnings("unused") PNone value,
@Bind("this") Node inliningTarget,
@Cached("createForceType()") ReadAttributeFromObjectNode readAttr,
@Shared @Cached GetTypeFlagsNode getFlags,
@@ -1223,7 +1219,7 @@ static Object getModule(PythonNativeClass cls, @SuppressWarnings("unused") PNone
}
@Specialization(guards = "!isNoValue(value)")
- static Object setNative(PythonNativeClass cls, Object value,
+ static Object setNative(PythonAbstractNativeObject cls, Object value,
@Bind("this") Node inliningTarget,
@Shared @Cached GetTypeFlagsNode getFlags,
@Cached("createForceType()") WriteAttributeToObjectNode writeAttr,
@@ -1263,7 +1259,7 @@ static TruffleString getName(PythonManagedClass cls, @SuppressWarnings("unused")
}
@Specialization(guards = "isNoValue(value)")
- static Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
+ static Object getNative(PythonAbstractNativeObject cls, @SuppressWarnings("unused") PNone value,
@Cached GetTypeFlagsNode getTypeFlagsNode,
@Cached CStructAccess.ReadObjectNode getHtName,
@Cached CStructAccess.ReadCharPtrNode getTpNameNode,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
index d10697b51f..89d5bf5c7c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java
@@ -200,7 +200,6 @@
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
@@ -232,7 +231,6 @@
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -767,7 +765,6 @@ static TruffleString getQualName(Node inliningTarget, PythonAbstractNativeObject
}
}
- @TypeSystemReference(PythonTypes.class)
@GenerateUncached
@GenerateInline
@GenerateCached(false)
@@ -820,7 +817,7 @@ static PDict doPythonClass(Node inliningTarget, PythonBuiltinClassType obj) {
}
@Specialization
- static PDict doNativeClass(Node inliningTarget, PythonNativeClass obj,
+ static PDict doNativeClass(Node inliningTarget, PythonAbstractNativeObject obj,
@Cached(inline = false) CStructAccess.ReadObjectNode getTpSubclassesNode,
@Cached InlinedExactClassProfile profile) {
Object tpSubclasses = getTpSubclassesNode.readFromObj(obj, PyTypeObject__tp_subclasses);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
index 2677b7ea7c..3c7b04830e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java
@@ -59,7 +59,6 @@
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.util.PythonUtils;
@@ -75,7 +74,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.ReportPolymorphism.Megamorphic;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ArityException;
@@ -87,7 +85,6 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
-@TypeSystemReference(PythonTypes.class)
@ImportStatic({PGuards.class, SpecialMethodNames.class})
@GenerateUncached
@SuppressWarnings("truffle-inlining") // footprint reduction 60 -> 44
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
index 0d52b0e88b..62545c1325 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java
@@ -67,7 +67,6 @@
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.util.PythonUtils.NodeCounterWithLimit;
import com.oracle.truffle.api.CompilerAsserts;
@@ -77,12 +76,10 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.NodeField;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
-@TypeSystemReference(PythonTypes.class)
@ImportStatic({PythonOptions.class, PGuards.class})
@NodeField(name = "maxSizeExceeded", type = boolean.class)
abstract class AbstractCallMethodNode extends PNodeWithContext {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java
index 966bcf711b..accbcc9309 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -55,7 +55,6 @@
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -65,12 +64,10 @@
import com.oracle.truffle.api.dsl.Idempotent;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;
-@TypeSystemReference(PythonTypes.class)
@GenerateUncached
@GenerateInline(inlineByDefault = true)
public abstract class GetClassNode extends PNodeWithContext {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsForeignObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsForeignObjectNode.java
index b34fda5084..8dfe622eb8 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsForeignObjectNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsForeignObjectNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,13 +43,11 @@
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.truffle.PythonTypes;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
@@ -57,7 +55,6 @@
* Checks whether the object is a foreign object, i.e. is neither a python primitive value, nor a
* python object.
*/
-@TypeSystemReference(PythonTypes.class)
@GenerateUncached
@GenerateInline
@GenerateCached(false)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java
deleted file mode 100644
index 7815ff437a..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2017, 2022, Oracle and/or its affiliates.
- * Copyright (c) 2013, Regents of the University of California
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.oracle.graal.python.nodes.truffle;
-
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
-import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject;
-import com.oracle.graal.python.nodes.PGuards;
-import com.oracle.truffle.api.dsl.ImplicitCast;
-import com.oracle.truffle.api.dsl.TypeCast;
-import com.oracle.truffle.api.dsl.TypeCheck;
-import com.oracle.truffle.api.dsl.TypeSystem;
-
-@TypeSystem
-public abstract class PythonTypes {
-
- @ImplicitCast
- public static long intToLong(int value) {
- return value;
- }
-
- @TypeCheck(PythonNativeObject.class)
- public static boolean isNativeObject(Object object) {
- return PythonNativeObject.isInstance(object);
- }
-
- @TypeCast(PythonNativeObject.class)
- public static PythonNativeObject asNativeObject(Object object) {
- return PythonNativeObject.cast(object);
- }
-
- @TypeCheck(PythonNativeClass.class)
- public static boolean isNativeClass(Object object) {
- return PGuards.isNativeClass(object);
- }
-
- @TypeCast(PythonNativeClass.class)
- public static PythonNativeClass asNativeClass(Object object) {
- return PythonNativeClass.cast(object);
- }
-}
diff --git a/mx.graalpython/copyrights/overrides b/mx.graalpython/copyrights/overrides
index e385ca0023..c7a5988bd7 100644
--- a/mx.graalpython/copyrights/overrides
+++ b/mx.graalpython/copyrights/overrides
@@ -698,7 +698,6 @@ graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/Read
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/BuiltinFunctionRootNode.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/PythonBuiltinNode.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonIntegerTypes.java,zippy.copyright
-graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/truffle/PythonTypes.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java,zippy.copyright
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PythonErrorType.java,zippy.copyright
From 53a21571443cb815dbda50d4370c5604d03e1485 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 15:11:05 +0100
Subject: [PATCH 037/512] Add uncached for PyNumber nodes
---
.../builtins/objects/ints/IntBuiltins.java | 99 +++++++------------
.../graal/python/lib/PyNumberAddNode.java | 41 +-------
.../graal/python/lib/PyNumberAndNode.java | 8 ++
.../python/lib/PyNumberFloorDivideNode.java | 47 +++++----
.../python/lib/PyNumberInPlaceAddNode.java | 2 +
.../lib/PyNumberInPlaceFloorDivideNode.java | 2 +
.../python/lib/PyNumberInPlaceLshiftNode.java | 11 ++-
.../lib/PyNumberInPlaceMultiplyNode.java | 2 +
.../lib/PyNumberInPlaceRemainderNode.java | 2 +
.../python/lib/PyNumberInPlaceRshiftNode.java | 2 +
.../lib/PyNumberInPlaceSubtractNode.java | 2 +
.../lib/PyNumberInPlaceTrueDivideNode.java | 2 +
.../graal/python/lib/PyNumberLshiftNode.java | 33 +------
.../python/lib/PyNumberMultiplyNode.java | 41 +++++++-
.../graal/python/lib/PyNumberOrNode.java | 8 ++
.../python/lib/PyNumberRemainderNode.java | 19 ++--
.../graal/python/lib/PyNumberRshiftNode.java | 5 +
.../python/lib/PyNumberSubtractNode.java | 46 ++++++---
.../python/lib/PyNumberTrueDivideNode.java | 40 +++++---
.../graal/python/lib/PyNumberXorNode.java | 8 ++
20 files changed, 223 insertions(+), 197 deletions(-)
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
index 6681cda914..9e811dce30 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java
@@ -157,15 +157,14 @@
public final class IntBuiltins extends PythonBuiltins {
public static final TpSlots SLOTS = IntBuiltinsSlotsGen.SLOTS;
- private static void raiseDivisionByZero(Node inliningTarget, boolean cond, InlinedBranchProfile divisionByZeroProfile, PRaiseNode raiseNode) {
+ private static void raiseDivisionByZero(Node inliningTarget, boolean cond, PRaiseNode raiseNode) {
if (cond) {
- raiseDivisionByZero(inliningTarget, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, raiseNode);
}
}
@InliningCutoff
- private static void raiseDivisionByZero(Node inliningTarget, InlinedBranchProfile divisionByZeroProfile, PRaiseNode raiseNode) {
- divisionByZeroProfile.enter(inliningTarget);
+ private static void raiseDivisionByZero(Node inliningTarget, PRaiseNode raiseNode) {
throw raiseNode.raise(inliningTarget, PythonErrorType.ZeroDivisionError, ErrorMessages.S_DIVISION_OR_MODULO_BY_ZERO, "integer");
}
@@ -452,7 +451,7 @@ static int doII(int x, int y) throws ArithmeticException {
return Math.subtractExact(x, y);
}
- @Specialization
+ @Specialization(replaces = "doII")
static long doIIOvf(int x, int y) {
return (long) x - (long) y;
}
@@ -462,7 +461,7 @@ static long doLL(long x, long y) throws ArithmeticException {
return Math.subtractExact(x, y);
}
- @Specialization
+ @Specialization(replaces = "doLL")
static Object doLongWithOverflow(long x, long y,
@Bind("this") Node inliningTarget) {
/* Inlined version of Math.subtractExact(x, y) with BigInteger fallback. */
@@ -470,46 +469,46 @@ static Object doLongWithOverflow(long x, long y,
// HD 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of x
if (((x ^ y) & (x ^ r)) < 0) {
- return PFactory.createInt(PythonLanguage.get(inliningTarget), op(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), sub(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
}
return r;
}
@Specialization(rewriteOn = OverflowException.class)
static long doPIntLongAndNarrow(PInt left, long right) throws OverflowException {
- return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
+ return PInt.longValueExact(sub(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(replaces = "doPIntLongAndNarrow")
static PInt doPIntLong(PInt left, long right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
+ return PFactory.createInt(language, sub(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
static long doLongPIntAndNarrow(long left, PInt right) throws OverflowException {
- return PInt.longValueExact(op(PInt.longToBigInteger(left), right.getValue()));
+ return PInt.longValueExact(sub(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(replaces = "doLongPIntAndNarrow")
static PInt doLongPInt(long left, PInt right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
+ return PFactory.createInt(language, sub(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(rewriteOn = OverflowException.class)
static long doPIntPIntAndNarrow(PInt left, PInt right) throws OverflowException {
- return PInt.longValueExact(op(left.getValue(), right.getValue()));
+ return PInt.longValueExact(sub(left.getValue(), right.getValue()));
}
@Specialization(replaces = "doPIntPIntAndNarrow")
static PInt doPIntPInt(PInt left, PInt right,
@Bind PythonLanguage language) {
- return PFactory.createInt(language, op(left.getValue(), right.getValue()));
+ return PFactory.createInt(language, sub(left.getValue(), right.getValue()));
}
@TruffleBoundary
- private static BigInteger op(BigInteger left, BigInteger right) {
+ public static BigInteger sub(BigInteger left, BigInteger right) {
return left.subtract(right);
}
@@ -616,7 +615,7 @@ private static double op(Node raisingNode, BigInteger a, BigInteger b) {
return d;
}
- protected static boolean fitsIntoDouble(long x) {
+ public static boolean fitsIntoDouble(long x) {
return x < (1L << 52) && x > -(1L << 52);
}
@@ -648,10 +647,9 @@ public abstract static class FloorDivNode extends BinaryOpBuiltinNode {
@Specialization
static Object doII(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
if (left == Integer.MIN_VALUE && right == -1) {
overflowValueProfile.enter();
return INT_OVERFLOW_VALUE;
@@ -662,10 +660,9 @@ static Object doII(int left, int right,
@Specialization
static Object doLL(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
if (left == Long.MIN_VALUE && right == -1) {
overflowValueProfile.enter();
return PFactory.createInt(PythonLanguage.get(inliningTarget), LONG_OVERFLOW_VALUE);
@@ -676,12 +673,11 @@ static Object doLL(long left, long right,
@Specialization
static Object doIPi(int left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
@Shared @Cached PRaiseNode raiseNode) {
try {
int rightValue = right.intValueExact();
- raiseDivisionByZero(inliningTarget, rightValue == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, rightValue == 0, raiseNode);
if (left == Integer.MIN_VALUE && rightValue == -1) {
overflowValueProfile.enter();
return INT_OVERFLOW_VALUE;
@@ -695,12 +691,11 @@ static Object doIPi(int left, PInt right,
@Specialization
static Object doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached BranchProfile overflowValueProfile,
@Shared @Cached PRaiseNode raiseNode) {
try {
long rightValue = right.longValueExact();
- raiseDivisionByZero(inliningTarget, rightValue == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, rightValue == 0, raiseNode);
if (left == Long.MIN_VALUE && rightValue == -1) {
overflowValueProfile.enter();
return PFactory.createInt(PythonLanguage.get(inliningTarget), LONG_OVERFLOW_VALUE);
@@ -714,9 +709,8 @@ static Object doLPi(long left, PInt right,
@Specialization(rewriteOn = OverflowException.class)
static long doPiIAndNarrow(PInt left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -724,18 +718,16 @@ static long doPiIAndNarrow(PInt left, int right,
static PInt doPiI(PInt left, int right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
static long doPiLAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -743,18 +735,16 @@ static long doPiLAndNarrow(PInt left, long right,
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(rewriteOn = OverflowException.class)
static long doPiPiAndNarrow(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PInt.longValueExact(op(left.getValue(), right.getValue()));
}
@@ -762,9 +752,8 @@ static long doPiPiAndNarrow(PInt left, PInt right,
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@@ -820,27 +809,24 @@ public abstract static class ModNode extends BinaryOpBuiltinNode {
@Specialization
static int doII(int left, int right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return Math.floorMod(left, right);
}
@Specialization
static long doLL(long left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return Math.floorMod(left, right);
}
@Specialization(guards = "right.isZeroOrPositive()", rewriteOn = OverflowException.class)
static long doLPiAndNarrow(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PInt.longValueExact(op(PInt.longToBigInteger(left), right.getValue()));
}
@@ -848,18 +834,16 @@ static long doLPiAndNarrow(long left, PInt right,
static PInt doLPi(long left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PFactory.createInt(language, op(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(guards = "!right.isZeroOrPositive()", rewriteOn = OverflowException.class)
static long doLPiNegativeAndNarrow(long left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PInt.longValueExact(opNeg(PInt.longToBigInteger(left), right.getValue()));
}
@@ -867,18 +851,16 @@ static long doLPiNegativeAndNarrow(long left, PInt right,
static PInt doLPiNegative(long left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PFactory.createInt(language, opNeg(PInt.longToBigInteger(left), right.getValue()));
}
@Specialization(guards = "right >= 0", rewriteOn = OverflowException.class)
static long doPiLAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PInt.longValueExact(op(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -886,18 +868,16 @@ static long doPiLAndNarrow(PInt left, long right,
static PInt doPiL(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PFactory.createInt(language, op(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(guards = "right < 0", rewriteOn = OverflowException.class)
static long doPiLNegAndNarrow(PInt left, long right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PInt.longValueExact(opNeg(left.getValue(), PInt.longToBigInteger(right)));
}
@@ -905,18 +885,16 @@ static long doPiLNegAndNarrow(PInt left, long right,
static PInt doPiLNeg(PInt left, long right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right == 0, divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right == 0, raiseNode);
return PFactory.createInt(language, opNeg(left.getValue(), PInt.longToBigInteger(right)));
}
@Specialization(guards = "right.isZeroOrPositive()", rewriteOn = OverflowException.class)
static long doPiPiAndNarrow(PInt left, PInt right,
@Bind("this") Node inliningTarget,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) throws OverflowException {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PInt.longValueExact(op(left.getValue(), right.getValue()));
}
@@ -924,9 +902,8 @@ static long doPiPiAndNarrow(PInt left, PInt right,
static PInt doPiPi(PInt left, PInt right,
@Bind("this") Node inliningTarget,
@Bind PythonLanguage language,
- @Shared @Cached InlinedBranchProfile divisionByZeroProfile,
@Shared @Cached PRaiseNode raiseNode) {
- raiseDivisionByZero(inliningTarget, right.isZero(), divisionByZeroProfile, raiseNode);
+ raiseDivisionByZero(inliningTarget, right.isZero(), raiseNode);
return PFactory.createInt(language, op(left.getValue(), right.getValue()));
}
@@ -991,7 +968,7 @@ static long doLL(long x, long y) {
return Math.multiplyExact(x, y);
}
- @Specialization
+ @Specialization(replaces = "doLL")
static Object doLongWithOverflow(long x, long y,
@Bind("this") Node inliningTarget) {
/* Inlined version of Math.multiplyExact(x, y) with BigInteger fallback. */
@@ -1052,7 +1029,7 @@ static PInt doPIntPInt(PInt left, PInt right,
}
@TruffleBoundary
- static BigInteger mul(BigInteger a, BigInteger b) {
+ public static BigInteger mul(BigInteger a, BigInteger b) {
if (!BigInteger.ZERO.equals(b) && b.and(b.subtract(BigInteger.ONE)).equals(BigInteger.ZERO)) {
return bigIntegerShift(a, b.getLowestSetBit());
} else {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 2c0ccc6716..2d51703278 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -54,14 +54,12 @@
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.CallSlotBinaryFuncNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
-import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
-import com.oracle.graal.python.util.OverflowException;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -70,7 +68,6 @@
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
-import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.TypeSystemReference;
@@ -81,15 +78,13 @@
import com.oracle.truffle.api.strings.TruffleString;
@GenerateCached(false)
-@ImportStatic(PGuards.class)
@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberAddBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
- * in IntBuiltins, but it additionally needs to check PInts for only builtin ints
+ * in IntBuiltins
*/
-
@Specialization(rewriteOn = ArithmeticException.class)
static int doII(int left, int right) {
return Math.addExact(left, right);
@@ -112,44 +107,10 @@ static Object doLLOvf(long x, long y,
return r;
}
- @Specialization(guards = "isBuiltinPInt(left)", rewriteOn = OverflowException.class)
- static Object doPLNarrow(PInt left, long right) throws OverflowException {
- return PInt.longValueExact(add(left.getValue(), PInt.longToBigInteger(right)));
- }
-
- @Specialization(guards = "isBuiltinPInt(left)", replaces = "doPLNarrow")
- static Object doPL(PInt left, long right,
- @Bind PythonLanguage language) {
- return PFactory.createInt(language, add(left.getValue(), PInt.longToBigInteger(right)));
- }
-
- @Specialization(guards = "isBuiltinPInt(right)", rewriteOn = OverflowException.class)
- static Object doLPNarrow(long left, PInt right) throws OverflowException {
- return PInt.longValueExact(add(PInt.longToBigInteger(left), right.getValue()));
- }
-
- @Specialization(guards = "isBuiltinPInt(right)", replaces = "doLPNarrow")
- static Object doLP(long left, PInt right,
- @Bind PythonLanguage language) {
- return PFactory.createInt(language, add(PInt.longToBigInteger(left), right.getValue()));
- }
-
- @Specialization(guards = {"isBuiltinPInt(left)", "isBuiltinPInt(right)"}, rewriteOn = OverflowException.class)
- static Object doPPNarrow(PInt left, PInt right) throws OverflowException {
- return PInt.longValueExact(add(left.getValue(), right.getValue()));
- }
-
- @Specialization(guards = {"isBuiltinPInt(left)", "isBuiltinPInt(right)"}, replaces = "doPPNarrow")
- static Object doPP(PInt left, PInt right,
- @Bind PythonLanguage language) {
- return PFactory.createInt(language, add(left.getValue(), right.getValue()));
- }
-
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in FloatBuiltins
*/
-
@Specialization
public static double doDD(double left, double right) {
return left + right;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
index 1a714d901b..b804237704 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
@@ -42,6 +42,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -51,12 +52,19 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberAndBaseNode extends BinaryOpNode {
+ @Specialization
+ public static boolean op(boolean left, boolean right) {
+ return left && right;
+ }
+
@Specialization
public static int op(int left, int right) {
return left & right;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
index d0502ec191..c3afbf9219 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
@@ -42,59 +42,66 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.util.OverflowException;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberFloorDivideBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, FloatBuiltins, ...
*/
- @Specialization(rewriteOn = OverflowException.class)
- public static int doII(int left, int right) throws OverflowException {
- if (right == 0 || (left == Integer.MIN_VALUE && right == -1)) {
- throw OverflowException.INSTANCE;
- }
+ @Specialization(guards = "!specialCase(left, right)")
+ public static int doII(int left, int right) {
return Math.floorDiv(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static long doLL(long left, long right) throws OverflowException {
- if (right == 0 || (left == Long.MIN_VALUE && right == -1)) {
- throw OverflowException.INSTANCE;
- }
+ @Specialization(guards = "!specialCase(left, right)")
+ public static long doLL(long left, long right) {
return Math.floorDiv(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doID(int left, double right) throws OverflowException {
+ @Specialization(guards = "!isZero(right)")
+ public static double doLD(long left, double right) {
return doDD(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doDI(double left, int right) throws OverflowException {
+ @Specialization(guards = "right != 0")
+ public static double doDL(double left, long right) {
return doDD(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doDD(double left, double right) throws OverflowException {
- if (right == 0.0) {
- throw OverflowException.INSTANCE;
- }
+ @Specialization(guards = "!isZero(right)")
+ public static double doDD(double left, double right) {
return Math.floor(left / right);
}
+
+ protected static boolean specialCase(int left, int right) {
+ return right == 0 || left == Integer.MIN_VALUE && right == -1;
+ }
+
+ protected static boolean specialCase(long left, long right) {
+ return right == 0 || left == Long.MIN_VALUE && right == -1;
+ }
+
+ protected static boolean isZero(double right) {
+ return right == 0.0;
+ }
}
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberFloorDivideNode extends PyNumberFloorDivideBaseNode {
@Specialization
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
index aa7c6a8613..5bad03d7aa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
@@ -56,12 +56,14 @@
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceAddNode extends PyNumberAddBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
index 6ae4492358..d48df26c10 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
@@ -46,11 +46,13 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceFloorDivideNode extends PyNumberFloorDivideBaseNode {
@Fallback
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
index a8d32b4d1b..360a60c7ca 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
@@ -41,19 +41,20 @@
package com.oracle.graal.python.lib;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.InplaceSlot;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
+import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
-public abstract class PyNumberInPlaceLshiftNode extends PyNumberLshiftBaseNode {
- @Fallback
- @InliningCutoff
+@GenerateUncached
+public abstract class PyNumberInPlaceLshiftNode extends BinaryOpNode {
+ @Specialization
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
@Cached CallBinaryIOpNode callBinaryOpNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
index c246a01add..8ec92574e7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
@@ -55,12 +55,14 @@
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceMultiplyNode extends PyNumberMultiplyBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
index 4b7263eb99..7d4d0ceb25 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
@@ -46,11 +46,13 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceRemainderNode extends PyNumberRemainderBaseNode {
@Fallback
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
index a7c44535aa..92e716a405 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
@@ -46,11 +46,13 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceRshiftNode extends PyNumberRshiftBaseNode {
@Fallback
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
index 0909180b46..ef43c8ba2c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
@@ -46,11 +46,13 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceSubtractNode extends PyNumberSubtractBaseNode {
@Fallback
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
index 6e09431bc4..231b052dd0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
@@ -46,11 +46,13 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberInPlaceTrueDivideNode extends PyNumberTrueDivideBaseNode {
@Fallback
@InliningCutoff
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
index e78acaab90..b792a9b2bc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
@@ -42,45 +42,20 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.util.OverflowException;
-import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Fallback;
-import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateCached(false)
-abstract class PyNumberLshiftBaseNode extends BinaryOpNode {
-
- @Specialization(guards = {"right < 32", "right >= 0"}, rewriteOn = OverflowException.class)
- public static int doII(int left, int right) throws OverflowException {
- int result = left << right;
- if (left != result >> right) {
- throw OverflowException.INSTANCE;
- }
- return result;
- }
-
- @Specialization(guards = {"right < 64", "right >= 0"}, rewriteOn = OverflowException.class)
- public static long doLL(long left, long right) throws OverflowException {
- long result = left << right;
- if (left != result >> right) {
- throw OverflowException.INSTANCE;
- }
- return result;
- }
-}
-
@GenerateInline(false)
-public abstract class PyNumberLshiftNode extends PyNumberLshiftBaseNode {
+@GenerateUncached
+public abstract class PyNumberLshiftNode extends BinaryOpNode {
- @Fallback
- @InliningCutoff
+ @Specialization
public static Object doIt(VirtualFrame frame, Object v, Object w,
@Bind Node inliningTarget,
@Cached CallBinaryOpNode callBinaryOpNode) {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index df047a134a..643081f0da 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -40,49 +40,81 @@
*/
package com.oracle.graal.python.lib;
+import static com.oracle.graal.python.builtins.objects.ints.IntBuiltins.MulNode.mul;
import static com.oracle.graal.python.lib.CallBinaryOpNode.raiseNotSupported;
+import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
+import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.type.TpSlots;
import com.oracle.graal.python.builtins.objects.type.TpSlots.GetCachedTpSlotsNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
+import com.oracle.graal.python.runtime.object.PFactory;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberMultiplyBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
- * in IntBuiltins, FloatBuiltins, ListBuiltins, ...
+ * in IntBuiltins
*/
@Specialization(rewriteOn = ArithmeticException.class)
- public static int doII(int x, int y) throws ArithmeticException {
+ static int doII(int x, int y) throws ArithmeticException {
return Math.multiplyExact(x, y);
}
@Specialization(replaces = "doII")
- public static long doIIL(int x, int y) {
+ static long doIIL(int x, int y) {
return x * (long) y;
}
@Specialization(rewriteOn = ArithmeticException.class)
- public static long doLL(long x, long y) {
+ static long doLL(long x, long y) {
return Math.multiplyExact(x, y);
}
+ @Specialization(replaces = "doLL")
+ static Object doLongWithOverflow(long x, long y,
+ @Bind("this") Node inliningTarget) {
+ /* Inlined version of Math.multiplyExact(x, y) with BigInteger fallback. */
+ long r = x * y;
+ long ax = Math.abs(x);
+ long ay = Math.abs(y);
+ if (((ax | ay) >>> 31 != 0)) {
+ // Some bits greater than 2^31 that might cause overflow
+ // Check the result using the divide operator
+ // and check for the special case of Long.MIN_VALUE * -1
+ if (((y != 0) && (r / y != x)) ||
+ (x == Long.MIN_VALUE && y == -1)) {
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), mul(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ }
+ }
+ return r;
+ }
+
+ /*
+ * All the following fast paths need to be kept in sync with the corresponding builtin functions
+ * in FloatBuiltins
+ */
@Specialization
public static double doDL(double left, long right) {
return left * right;
@@ -100,6 +132,7 @@ public static double doDD(double left, double right) {
}
@GenerateInline(inlineByDefault = true)
+@GenerateUncached
public abstract class PyNumberMultiplyNode extends PyNumberMultiplyBaseNode {
public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
index 2b66915680..5136d6640f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
@@ -42,6 +42,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -51,12 +52,19 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberOrBaseNode extends BinaryOpNode {
+ @Specialization
+ public static boolean op(boolean left, boolean right) {
+ return left || right;
+ }
+
@Specialization
public static int op(int left, int right) {
return left | right;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
index 78dba84ea7..403269c6fc 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
@@ -40,40 +40,39 @@
*/
package com.oracle.graal.python.lib;
-import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberRemainderBaseNode extends BinaryOpNode {
- @Specialization(rewriteOn = ArithmeticException.class)
- public static int doII(int left, int right) {
- return Math.floorMod(left, right);
- }
-
- @Specialization(rewriteOn = ArithmeticException.class)
- public static long doLL(long left, long right) {
+ @Specialization(guards = "right != 0")
+ static int doII(int left, int right) {
return Math.floorMod(left, right);
}
@Specialization(guards = "right != 0")
- public static double doDL(double left, long right) {
- return FloatBuiltins.ModNode.mod(left, right);
+ static long doLL(long left, long right) {
+ return Math.floorMod(left, right);
}
}
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberRemainderNode extends PyNumberRemainderBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
index 9203c8a04d..8e36dad6e2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
@@ -53,6 +53,7 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -61,12 +62,15 @@
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberRshiftBaseNode extends BinaryOpNode {
@Specialization(guards = {"right < 32", "right >= 0"})
@@ -81,6 +85,7 @@ public static long doIISmall(long left, long right) {
}
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberRshiftNode extends PyNumberRshiftBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
index 9144468818..3f392cc598 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
@@ -40,41 +40,66 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.PythonLanguage;
+import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
+import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
+import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberSubtractBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
- * in IntBuiltins, FloatBuiltins, ListBuiltins, ...
+ * in IntBuiltins
*/
@Specialization(rewriteOn = ArithmeticException.class)
- public static int doII(int x, int y) throws ArithmeticException {
+ static int doII(int x, int y) throws ArithmeticException {
return Math.subtractExact(x, y);
}
- @Specialization
- public static long doIIOvf(int x, int y) {
+ @Specialization(replaces = "doII")
+ static long doIIOvf(int x, int y) {
return (long) x - (long) y;
}
@Specialization(rewriteOn = ArithmeticException.class)
- public static long doLL(long x, long y) throws ArithmeticException {
+ static long doLL(long x, long y) throws ArithmeticException {
return Math.subtractExact(x, y);
}
+ @Specialization(replaces = "doLL")
+ static Object doLongWithOverflow(long x, long y,
+ @Bind("this") Node inliningTarget) {
+ /* Inlined version of Math.subtractExact(x, y) with BigInteger fallback. */
+ long r = x - y;
+ // HD 2-12 Overflow iff the arguments have different signs and
+ // the sign of the result is different than the sign of x
+ if (((x ^ y) & (x ^ r)) < 0) {
+ return PFactory.createInt(PythonLanguage.get(inliningTarget), IntBuiltins.SubNode.sub(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
+ }
+ return r;
+ }
+
+ /*
+ * All the following fast paths need to be kept in sync with the corresponding builtin functions
+ * in FloatBuiltins
+ */
@Specialization
public static double doDD(double left, double right) {
return left - right;
@@ -89,19 +114,10 @@ public static double doDL(double left, long right) {
public static double doLD(long left, double right) {
return left - right;
}
-
- @Specialization
- public static double doDI(double left, int right) {
- return left - right;
- }
-
- @Specialization
- public static double doID(int left, double right) {
- return left - right;
- }
}
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberSubtractNode extends PyNumberSubtractBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
index bf9dff20a6..8f59f003a7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
@@ -40,52 +40,66 @@
*/
package com.oracle.graal.python.lib;
+import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.util.OverflowException;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
+import com.oracle.truffle.api.dsl.GenerateUncached;
+import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
+@ImportStatic(IntBuiltins.TrueDivNode.class)
abstract class PyNumberTrueDivideBaseNode extends BinaryOpNode {
/*
* All the following fast paths need to be kept in sync with the corresponding builtin functions
* in IntBuiltins, FloatBuiltins, ...
*/
- @Specialization(rewriteOn = OverflowException.class)
- public static double doII(int left, int right) throws OverflowException {
+
+ @Specialization(guards = "!isZero(right)")
+ public static double doDD(double left, double right) {
+ return left / right;
+ }
+
+ @Specialization(guards = "right != 0")
+ public static double doDL(double left, long right) {
return doDD(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doDI(double left, int right) throws OverflowException {
+ @Specialization(guards = "!isZero(right)")
+ public static double doLD(long left, double right) {
return doDD(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doID(int left, double right) throws OverflowException {
+ @Specialization(guards = "right != 0")
+ public static double doII(int left, int right) {
return doDD(left, right);
}
- @Specialization(rewriteOn = OverflowException.class)
- public static double doDD(double left, double right) throws OverflowException {
- if (right == 0.0) {
- throw OverflowException.INSTANCE;
- }
- return left / right;
+ @Specialization(guards = {"right != 0", "fitsIntoDouble(left)", "fitsIntoDouble(right)"})
+ public static double doLL(long left, long right) {
+ return doDD(left, right);
+ }
+
+ protected static boolean isZero(double right) {
+ return right == 0.0;
}
}
@GenerateInline(false)
+@GenerateUncached
public abstract class PyNumberTrueDivideNode extends PyNumberTrueDivideBaseNode {
@Fallback
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
index 5fb858c7a7..18633e77f2 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
@@ -42,6 +42,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.ReversibleSlot;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
+import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -51,12 +52,19 @@
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
@GenerateCached(false)
+@TypeSystemReference(PythonIntegerTypes.class)
abstract class PyNumberXorBaseNode extends BinaryOpNode {
+ @Specialization
+ public static boolean op(boolean left, boolean right) {
+ return left != right;
+ }
+
@Specialization
public static int op(int left, int right) {
return left ^ right;
From 3415eb88868139de525daa76cf1c944bffed47c3 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 15:44:46 +0100
Subject: [PATCH 038/512] Remove GraalHPyArithmeticNode
---
.../cext/PythonCextAbstractBuiltins.java | 3 +-
.../cext/hpy/GraalHPyArithmeticNode.java | 441 ------------------
.../cext/hpy/GraalHPyContextFunctions.java | 182 ++++----
.../graal/python/lib/PyNumberAddNode.java | 4 +
.../graal/python/lib/PyNumberAndNode.java | 4 +
.../graal/python/lib/PyNumberDivmodNode.java | 4 +
.../python/lib/PyNumberFloorDivideNode.java | 4 +
.../python/lib/PyNumberInPlaceAddNode.java | 4 +
.../python/lib/PyNumberInPlaceAndNode.java | 4 +
.../lib/PyNumberInPlaceFloorDivideNode.java | 4 +
.../python/lib/PyNumberInPlaceLshiftNode.java | 4 +
.../PyNumberInPlaceMatrixMultiplyNode.java | 4 +
.../lib/PyNumberInPlaceMultiplyNode.java | 4 +
.../python/lib/PyNumberInPlaceOrNode.java | 4 +
.../python/lib/PyNumberInPlacePowerNode.java | 18 +-
.../lib/PyNumberInPlaceRemainderNode.java | 4 +
.../python/lib/PyNumberInPlaceRshiftNode.java | 4 +
.../lib/PyNumberInPlaceSubtractNode.java | 4 +
.../lib/PyNumberInPlaceTrueDivideNode.java | 4 +
.../python/lib/PyNumberInPlaceXorNode.java | 4 +
.../graal/python/lib/PyNumberInvertNode.java | 4 +
.../graal/python/lib/PyNumberLshiftNode.java | 4 +
.../lib/PyNumberMatrixMultiplyNode.java | 4 +
.../python/lib/PyNumberMultiplyNode.java | 4 +
.../python/lib/PyNumberNegativeNode.java | 4 +
.../graal/python/lib/PyNumberOrNode.java | 4 +
.../python/lib/PyNumberPositiveNode.java | 4 +
.../graal/python/lib/PyNumberPowerNode.java | 4 +
.../python/lib/PyNumberRemainderNode.java | 4 +
.../graal/python/lib/PyNumberRshiftNode.java | 4 +
.../python/lib/PyNumberSubtractNode.java | 4 +
.../python/lib/PyNumberTrueDivideNode.java | 4 +
.../graal/python/lib/PyNumberXorNode.java | 4 +
33 files changed, 216 insertions(+), 544 deletions(-)
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 6cfaff3a52..013bafe4d5 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -584,9 +584,8 @@ abstract static class PyNumber_InPlacePower extends CApiTernaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2, Object o3,
- @Bind Node inliningTarget,
@Cached PyNumberInPlacePowerNode powerNode) {
- return powerNode.execute(null, inliningTarget, o1, o2, o3);
+ return powerNode.execute(null, o1, o2, o3);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
deleted file mode 100644
index 765d516527..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyArithmeticNode.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.builtins.objects.cext.hpy;
-
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.nodes.call.GenericInvokeNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
-import com.oracle.graal.python.nodes.expression.LookupAndCallInplaceNode;
-import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
-import com.oracle.graal.python.nodes.expression.UnaryOpNode;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.RootCallTarget;
-import com.oracle.truffle.api.dsl.NeverDefault;
-import com.oracle.truffle.api.nodes.Node;
-
-public abstract class GraalHPyArithmeticNode {
-
- private GraalHPyArithmeticNode() {
- }
-
- public abstract static class HPyUnaryArithmeticNode extends Node {
-
- public abstract Object execute(Object object);
-
- @NeverDefault
- public static HPyUnaryArithmeticNode create(UnaryArithmetic operator) {
- return new HPyUnaryArithmeticCached(operator);
- }
-
- public static HPyUnaryArithmeticNode getUncached(UnaryArithmetic operator) {
- return HPyUnaryArithmeticUncached.UNCACHEDS[operator.ordinal()];
- }
- }
-
- static final class HPyUnaryArithmeticCached extends HPyUnaryArithmeticNode {
- @Child private UnaryOpNode opNode;
-
- private HPyUnaryArithmeticCached(UnaryArithmetic operator) {
- opNode = operator.create();
- }
-
- @Override
- public Object execute(Object object) {
- return opNode.execute(null, object);
- }
- }
-
- private static final class HPyUnaryArithmeticUncached extends HPyUnaryArithmeticNode {
- final UnaryArithmetic operator;
-
- public HPyUnaryArithmeticUncached(UnaryArithmetic operator) {
- this.operator = operator;
- }
-
- @TruffleBoundary
- @Override
- public Object execute(Object object) {
- Object[] pythonArguments = PArguments.create(1);
- PArguments.setArgument(pythonArguments, 0, object);
- RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
- return GenericInvokeNode.invokeUncached(callTarget, pythonArguments);
- }
-
- @Override
- public boolean isAdoptable() {
- return false;
- }
-
- private static final HPyUnaryArithmeticUncached[] UNCACHEDS;
- static {
- UnaryArithmetic[] values = UnaryArithmetic.values();
- UNCACHEDS = new HPyUnaryArithmeticUncached[values.length];
- for (int i = 0; i < values.length; i++) {
- UNCACHEDS[i] = new HPyUnaryArithmeticUncached(values[i]);
- }
- }
- }
-
- public abstract static class HPyBinaryArithmeticNode extends Node {
-
- public abstract Object execute(Object arg0, Object arg1);
-
- @NeverDefault
- public static HPyBinaryArithmeticNode create(BinaryArithmetic operator) {
- return new HPyBinaryArithmeticCached(operator);
- }
-
- public static HPyBinaryArithmeticNode getUncached(BinaryArithmetic operator) {
- return HPyBinaryArithmeticUncached.UNCACHEDS[operator.ordinal()];
- }
- }
-
- private static final class HPyBinaryArithmeticCached extends HPyBinaryArithmeticNode {
- @Child private BinaryOpNode opNode;
-
- private HPyBinaryArithmeticCached(BinaryArithmetic operator) {
- opNode = operator.create();
- }
-
- @Override
- public Object execute(Object arg0, Object arg1) {
- return opNode.execute(null, arg0, arg1);
- }
- }
-
- private static final class HPyBinaryArithmeticUncached extends HPyBinaryArithmeticNode {
- final BinaryArithmetic operator;
-
- public HPyBinaryArithmeticUncached(BinaryArithmetic operator) {
- this.operator = operator;
- }
-
- @TruffleBoundary
- @Override
- public Object execute(Object arg0, Object arg1) {
- Object[] pythonArguments = PArguments.create(2);
- PArguments.setArgument(pythonArguments, 0, arg0);
- PArguments.setArgument(pythonArguments, 1, arg1);
- RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
- return GenericInvokeNode.invokeUncached(callTarget, pythonArguments);
- }
-
- @Override
- public boolean isAdoptable() {
- return false;
- }
-
- private static final HPyBinaryArithmeticUncached[] UNCACHEDS;
- static {
- BinaryArithmetic[] values = BinaryArithmetic.values();
- UNCACHEDS = new HPyBinaryArithmeticUncached[values.length];
- for (int i = 0; i < values.length; i++) {
- UNCACHEDS[i] = new HPyBinaryArithmeticUncached(values[i]);
- }
- }
- }
-
- public abstract static class HPyInplaceArithmeticNode extends Node {
-
- public abstract Object execute(Object arg0, Object arg1, Object arg2);
-
- public final Object execute(Object arg0, Object arg1) {
- return execute(arg0, arg1, PNone.NO_VALUE);
- }
-
- @NeverDefault
- public static HPyInplaceArithmeticNode create(InplaceArithmetic operator) {
- return new HPyInplaceArithmeticCached(operator);
- }
-
- public static HPyInplaceArithmeticNode getUncached(InplaceArithmetic operator) {
- return HPyInplaceArithmeticUncached.UNCACHEDS[operator.ordinal()];
- }
- }
-
- private static final class HPyInplaceArithmeticCached extends HPyInplaceArithmeticNode {
- @Child private LookupAndCallInplaceNode opNode;
-
- private final boolean isTernary;
-
- private HPyInplaceArithmeticCached(InplaceArithmetic operator) {
- opNode = operator.create();
- this.isTernary = operator.isTernary();
- }
-
- @Override
- public Object execute(Object arg0, Object arg1, Object arg2) {
- if (isTernary) {
- return opNode.executeTernary(null, arg0, arg1, arg2);
- } else {
- return opNode.execute(null, arg0, arg1);
- }
- }
- }
-
- private static final class HPyInplaceArithmeticUncached extends HPyInplaceArithmeticNode {
- final InplaceArithmetic operator;
-
- public HPyInplaceArithmeticUncached(InplaceArithmetic operator) {
- this.operator = operator;
- }
-
- @TruffleBoundary
- @Override
- public Object execute(Object arg0, Object arg1, Object arg2) {
- Object[] pythonArguments = PArguments.create(3);
- PArguments.setArgument(pythonArguments, 0, arg0);
- PArguments.setArgument(pythonArguments, 1, arg1);
- PArguments.setArgument(pythonArguments, 2, arg2);
- RootCallTarget callTarget = PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
- return GenericInvokeNode.invokeUncached(callTarget, pythonArguments);
- }
-
- @Override
- public boolean isAdoptable() {
- return false;
- }
-
- private static final HPyInplaceArithmeticUncached[] UNCACHEDS;
- static {
- InplaceArithmetic[] values = InplaceArithmetic.values();
- UNCACHEDS = new HPyInplaceArithmeticUncached[values.length];
- for (int i = 0; i < values.length; i++) {
- UNCACHEDS[i] = new HPyInplaceArithmeticUncached(values[i]);
- }
- }
- }
-
-// @NeverDefault
-// public static GraalHPyBinaryArithmeticCached create(BinaryArithmetic operator) {
-// return new GraalHPyBinaryArithmeticCached(operator);
-// }
-//
-// public static GraalHPyBinaryArithmeticUncached getUncached(BinaryArithmetic operator) {
-// return GraalHPyBinaryArithmeticUncached.UNCACHEDS[operator.ordinal()];
-// }
-//
-// static final class GraalHPyBinaryArithmeticCached extends GraalHPyArithmeticCachedNode {
-// @Child private BinaryOpNode opNode;
-//
-// GraalHPyBinaryArithmeticCached(BinaryArithmetic operator) {
-// opNode = operator.create();
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// checkArity(arguments, EXPECTED_ARITY_BINARY);
-// }
-//
-// @Override
-// Object doOperator(Object[] arguments) {
-// return opNode.executeObject(null, asPythonObjectNode.execute(arguments[1]),
-// asPythonObjectNode.execute(arguments[2]));
-// }
-// }
-//
-// private static final class GraalHPyBinaryArithmeticUncached extends
-// GraalHPyArithmeticUncachedNode {
-// final BinaryArithmetic operator;
-//
-// public GraalHPyBinaryArithmeticUncached(BinaryArithmetic operator) {
-// this.operator = operator;
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// checkArity(arguments, EXPECTED_ARITY_BINARY);
-// }
-//
-// @Override
-// RootCallTarget ensureCallTarget() {
-// return PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
-// }
-//
-// private static final GraalHPyBinaryArithmeticUncached[] UNCACHEDS;
-// static {
-// BinaryArithmetic[] values = BinaryArithmetic.values();
-// UNCACHEDS = new GraalHPyBinaryArithmeticUncached[values.length];
-// for (int i = 0; i < values.length; i++) {
-// UNCACHEDS[i] = new GraalHPyBinaryArithmeticUncached(values[i]);
-// }
-// }
-// }
-//
-// @NeverDefault
-// public static GraalHPyTernaryArithmeticCached create(TernaryArithmetic operator) {
-// return new GraalHPyTernaryArithmeticCached(operator);
-// }
-//
-// public static GraalHPyTernaryArithmeticUncached getUncached(TernaryArithmetic operator) {
-// return GraalHPyTernaryArithmeticUncached.UNCACHEDS[operator.ordinal()];
-// }
-//
-// static final class GraalHPyTernaryArithmeticCached extends GraalHPyArithmeticCachedNode {
-// @Child private LookupAndCallTernaryNode opNode;
-//
-// GraalHPyTernaryArithmeticCached(TernaryArithmetic operator) {
-// opNode = operator.create();
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// checkArity(arguments, EXPECTED_ARITY_TERNARY);
-// }
-//
-// @Override
-// Object doOperator(Object[] arguments) {
-// return opNode.execute(null, asPythonObjectNode.execute(arguments[1]),
-// asPythonObjectNode.execute(arguments[2]), asPythonObjectNode.execute(arguments[3]));
-// }
-// }
-//
-// private static final class GraalHPyTernaryArithmeticUncached extends
-// GraalHPyArithmeticUncachedNode {
-// final TernaryArithmetic operator;
-//
-// public GraalHPyTernaryArithmeticUncached(TernaryArithmetic operator) {
-// this.operator = operator;
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// checkArity(arguments, EXPECTED_ARITY_TERNARY);
-// }
-//
-// @Override
-// RootCallTarget ensureCallTarget() {
-// return PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
-// }
-//
-// private static final GraalHPyTernaryArithmeticUncached[] UNCACHEDS;
-// static {
-// TernaryArithmetic[] values = TernaryArithmetic.values();
-// UNCACHEDS = new GraalHPyTernaryArithmeticUncached[values.length];
-// for (int i = 0; i < values.length; i++) {
-// UNCACHEDS[i] = new GraalHPyTernaryArithmeticUncached(values[i]);
-// }
-// }
-// }
-//
-// @NeverDefault
-// public static GraalHPyInplaceArithmeticCached create(InplaceArithmetic operator) {
-// return new GraalHPyInplaceArithmeticCached(operator);
-// }
-//
-// public static GraalHPyInplaceArithmeticUncached getUncached(InplaceArithmetic operator) {
-// return GraalHPyInplaceArithmeticUncached.UNCACHEDS[operator.ordinal()];
-// }
-//
-// static final class GraalHPyInplaceArithmeticCached extends GraalHPyArithmeticCachedNode {
-// @Child private LookupAndCallInplaceNode opNode;
-// private final boolean ternary;
-//
-// GraalHPyInplaceArithmeticCached(InplaceArithmetic operator) {
-// opNode = operator.create();
-// ternary = operator.isTernary();
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// GraalHPyInplaceArithmeticCached.checkInplaceArity(arguments, ternary);
-// }
-//
-// private static void checkInplaceArity(Object[] arguments, boolean ternary) throws ArityException
-// {
-// // we also need to account for the HPy context
-// if (ternary && arguments.length != 4) {
-// CompilerDirectives.transferToInterpreterAndInvalidate();
-// throw ArityException.create(EXPECTED_ARITY_TERNARY, EXPECTED_ARITY_TERNARY, arguments.length);
-// }
-// if (!ternary && arguments.length != 3) {
-// CompilerDirectives.transferToInterpreterAndInvalidate();
-// throw ArityException.create(EXPECTED_ARITY_BINARY, EXPECTED_ARITY_BINARY, arguments.length);
-// }
-// }
-//
-// @Override
-// Object doOperator(Object[] arguments) {
-// return opNode.execute(null, asPythonObjectNode.execute(arguments[1]),
-// asPythonObjectNode.execute(arguments[2]));
-// }
-// }
-//
-// private static final class GraalHPyInplaceArithmeticUncached extends
-// GraalHPyArithmeticUncachedNode {
-// final InplaceArithmetic operator;
-//
-// public GraalHPyInplaceArithmeticUncached(InplaceArithmetic operator) {
-// this.operator = operator;
-// }
-//
-// @Override
-// void checkArity(Object[] arguments) throws ArityException {
-// GraalHPyInplaceArithmeticCached.checkInplaceArity(arguments, operator.isTernary());
-// }
-//
-// @Override
-// RootCallTarget ensureCallTarget() {
-// return PythonLanguage.get(null).createCachedCallTarget(operator::createRootNode, operator);
-// }
-//
-// private static final GraalHPyInplaceArithmeticUncached[] UNCACHEDS;
-// static {
-// InplaceArithmetic[] values = InplaceArithmetic.values();
-// UNCACHEDS = new GraalHPyInplaceArithmeticUncached[values.length];
-// for (int i = 0; i < values.length; i++) {
-// UNCACHEDS[i] = new GraalHPyInplaceArithmeticUncached(values[i]);
-// }
-// }
-// }
-//
-// static void checkArity(Object[] arguments, int expectedArity) throws ArityException {
-// if (arguments.length != expectedArity) {
-// CompilerDirectives.transferToInterpreterAndInvalidate();
-// throw ArityException.create(expectedArity, expectedArity, arguments.length);
-// }
-// }
-
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
index 872b8ea638..e5ef187d6d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java
@@ -95,9 +95,6 @@
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.ClearCurrentExceptionNode;
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.EncodeNativeStringNode;
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.ReadUnicodeArrayNode;
-import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyBinaryArithmeticNode;
-import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyInplaceArithmeticNode;
-import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyArithmeticNode.HPyUnaryArithmeticNode;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctionsFactory.GraalHPyASCIINodeGen;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctionsFactory.GraalHPyAbsoluteNodeGen;
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctionsFactory.GraalHPyAddNodeGen;
@@ -310,9 +307,38 @@
import com.oracle.graal.python.lib.PyExceptionInstanceCheckNode;
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
import com.oracle.graal.python.lib.PyLongAsDoubleNode;
+import com.oracle.graal.python.lib.PyNumberAddNode;
+import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberCheckNode;
+import com.oracle.graal.python.lib.PyNumberDivmodNode;
+import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAddNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceAndNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceFloorDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceLshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceOrNode;
+import com.oracle.graal.python.lib.PyNumberInPlacePowerNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRemainderNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceRshiftNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceSubtractNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberInPlaceXorNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
+import com.oracle.graal.python.lib.PyNumberInvertNode;
+import com.oracle.graal.python.lib.PyNumberLshiftNode;
+import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberMultiplyNode;
+import com.oracle.graal.python.lib.PyNumberNegativeNode;
+import com.oracle.graal.python.lib.PyNumberOrNode;
+import com.oracle.graal.python.lib.PyNumberPositiveNode;
import com.oracle.graal.python.lib.PyNumberPowerNode;
+import com.oracle.graal.python.lib.PyNumberRemainderNode;
+import com.oracle.graal.python.lib.PyNumberRshiftNode;
+import com.oracle.graal.python.lib.PyNumberSubtractNode;
+import com.oracle.graal.python.lib.PyNumberTrueDivideNode;
+import com.oracle.graal.python.lib.PyNumberXorNode;
import com.oracle.graal.python.lib.PyObjectDelItem;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectGetAttrO;
@@ -344,9 +370,6 @@
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.InplaceArithmetic;
-import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode;
import com.oracle.graal.python.nodes.object.IsNode;
@@ -830,193 +853,179 @@ static int doGeneric(@SuppressWarnings("unused") Object hpyContext, Object handl
@HPyContextFunction("ctx_Positive")
@GenerateUncached
- @ImportStatic(UnaryArithmetic.class)
public abstract static class GraalHPyPositive extends HPyBinaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg,
- @Cached(parameters = "Pos") HPyUnaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg);
+ @Cached PyNumberPositiveNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg);
}
}
@HPyContextFunction("ctx_Negative")
@GenerateUncached
- @ImportStatic(UnaryArithmetic.class)
public abstract static class GraalHPyNegative extends HPyBinaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg,
- @Cached(parameters = "Neg") HPyUnaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg);
+ @Cached PyNumberNegativeNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg);
}
}
@HPyContextFunction("ctx_Invert")
@GenerateUncached
- @ImportStatic(UnaryArithmetic.class)
public abstract static class GraalHPyInvert extends HPyBinaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg,
- @Cached(parameters = "Invert") HPyUnaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg);
+ @Cached PyNumberInvertNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg);
}
}
@HPyContextFunction("ctx_Add")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyAdd extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Add") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Bind Node inliningTarget,
+ @Cached PyNumberAddNode arithmeticNode) {
+ return arithmeticNode.execute(null, inliningTarget, arg0, arg1);
}
}
@HPyContextFunction("ctx_Subtract")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPySubtract extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Sub") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberSubtractNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Multiply")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyMultiply extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Mul") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Bind Node inliningTarget,
+ @Cached PyNumberMultiplyNode arithmeticNode) {
+ return arithmeticNode.execute(null, inliningTarget, arg0, arg1);
}
}
@HPyContextFunction("ctx_MatrixMultiply")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyMatrixMultiply extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "MatMul") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberMatrixMultiplyNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_FloorDivide")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyFloorDivide extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "FloorDiv") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberFloorDivideNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_TrueDivide")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyTrueDivide extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "TrueDiv") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberTrueDivideNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Remainder")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyRemainder extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Mod") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberRemainderNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Divmod")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyDivmod extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "DivMod") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberDivmodNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_And")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyAnd extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "And") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberAndNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Xor")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyXor extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Xor") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberXorNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Or")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyOr extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "Or") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberOrNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Lshift")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyLshift extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "LShift") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberLshiftNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_Rshift")
@GenerateUncached
- @ImportStatic(BinaryArithmetic.class)
public abstract static class GraalHPyRshift extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "RShift") HPyBinaryArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberRshiftNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@@ -1034,157 +1043,144 @@ static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object ar
@HPyContextFunction("ctx_InPlaceAdd")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceAdd extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IAdd") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceAddNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceSubtract")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceSubtract extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "ISub") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceSubtractNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceMultiply")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceMultiply extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IMul") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceMultiplyNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceMatrixMultiply")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceMatrixMultiply extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IMatMul") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceMatrixMultiplyNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceFloorDivide")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceFloorDivide extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IFloorDiv") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceFloorDivideNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceTrueDivide")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceTrueDivide extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "ITrueDiv") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceTrueDivideNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceRemainder")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceRemainder extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IMod") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceRemainderNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlacePower")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlacePower extends HPyQuaternaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1, Object arg2,
- @Cached(parameters = "IPow") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1, arg2);
+ @Cached PyNumberInPlacePowerNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1, arg2);
}
}
@HPyContextFunction("ctx_InPlaceLshift")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceLshift extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "ILShift") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceLshiftNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceRshift")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceRshift extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IRShift") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceRshiftNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceAnd")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceAnd extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IAnd") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceAndNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceXor")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceXor extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IXor") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceXorNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
@HPyContextFunction("ctx_InPlaceOr")
@GenerateUncached
- @ImportStatic(InplaceArithmetic.class)
public abstract static class GraalHPyInPlaceOr extends HPyTernaryContextFunction {
@Specialization
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
- @Cached(parameters = "IOr") HPyInplaceArithmeticNode arithmeticNode) {
- return arithmeticNode.execute(arg0, arg1);
+ @Cached PyNumberInPlaceOrNode arithmeticNode) {
+ return arithmeticNode.execute(null, arg0, arg1);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
index 2d51703278..d46dc198c3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAddNode.java
@@ -196,4 +196,8 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
public static PyNumberAddNode create() {
return PyNumberAddNodeGen.create();
}
+
+ public static PyNumberAddNode getUncached() {
+ return PyNumberAddNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
index b804237704..be1c30f26d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberAndNode.java
@@ -92,4 +92,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberAndNode create() {
return PyNumberAndNodeGen.create();
}
+
+ public static PyNumberAndNode getUncached() {
+ return PyNumberAndNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
index 37f65cd7f9..0cc37fd903 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberDivmodNode.java
@@ -74,4 +74,8 @@ public static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Obj
public static PyNumberDivmodNode create() {
return PyNumberDivmodNodeGen.create();
}
+
+ public static PyNumberDivmodNode getUncached() {
+ return PyNumberDivmodNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
index c3afbf9219..f484ad823e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloorDivideNode.java
@@ -115,4 +115,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberFloorDivideNode create() {
return PyNumberFloorDivideNodeGen.create();
}
+
+ public static PyNumberFloorDivideNode getUncached() {
+ return PyNumberFloorDivideNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
index 5bad03d7aa..12a554c883 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAddNode.java
@@ -106,4 +106,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceAddNode create() {
return PyNumberInPlaceAddNodeGen.create();
}
+
+ public static PyNumberInPlaceAddNode getUncached() {
+ return PyNumberInPlaceAddNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
index 3819e8dd73..deb370d592 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceAndNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceAndNode create() {
return PyNumberInPlaceAndNodeGen.create();
}
+
+ public static PyNumberInPlaceAndNode getUncached() {
+ return PyNumberInPlaceAndNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
index d48df26c10..7f0d0f321a 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceFloorDivideNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceFloorDivideNode create() {
return PyNumberInPlaceFloorDivideNodeGen.create();
}
+
+ public static PyNumberInPlaceFloorDivideNode getUncached() {
+ return PyNumberInPlaceFloorDivideNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
index 360a60c7ca..e0342b4be0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceLshiftNode.java
@@ -65,4 +65,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceLshiftNode create() {
return PyNumberInPlaceLshiftNodeGen.create();
}
+
+ public static PyNumberInPlaceLshiftNode getUncached() {
+ return PyNumberInPlaceLshiftNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
index 890fc52a71..3f65419a60 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMatrixMultiplyNode.java
@@ -65,4 +65,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceMatrixMultiplyNode create() {
return PyNumberInPlaceMatrixMultiplyNodeGen.create();
}
+
+ public static PyNumberInPlaceMatrixMultiplyNode getUncached() {
+ return PyNumberInPlaceMatrixMultiplyNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
index 8ec92574e7..532bce5be3 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceMultiplyNode.java
@@ -118,4 +118,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceMultiplyNode create() {
return PyNumberInPlaceMultiplyNodeGen.create();
}
+
+ public static PyNumberInPlaceMultiplyNode getUncached() {
+ return PyNumberInPlaceMultiplyNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
index b1c046876a..856b0f582c 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceOrNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceOrNode create() {
return PyNumberInPlaceOrNodeGen.create();
}
+
+ public static PyNumberInPlaceOrNode getUncached() {
+ return PyNumberInPlaceOrNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
index 9e9a2776bf..f984f6c890 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlacePowerNode.java
@@ -48,6 +48,7 @@
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
+import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -56,23 +57,20 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
-@GenerateInline(inlineByDefault = true)
+@GenerateInline(false)
@GenerateUncached
public abstract class PyNumberInPlacePowerNode extends BinaryOpNode {
- public abstract Object execute(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z);
+ public abstract Object execute(VirtualFrame frame, Object v, Object w, Object z);
@Override
public final Object execute(VirtualFrame frame, Object left, Object right) {
- return executeCached(frame, left, right, PNone.NONE);
- }
-
- public final Object executeCached(VirtualFrame frame, Object v, Object w, Object z) {
- return execute(frame, this, v, w, z);
+ return execute(frame, left, right, PNone.NONE);
}
@Specialization
- static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z,
+ static Object doIt(VirtualFrame frame, Object v, Object w, Object z,
+ @Bind Node inliningTarget,
@Cached CallTernaryIOpNode callTernaryOpNode,
@Cached PRaiseNode raiseNode) {
Object result = callTernaryOpNode.execute(frame, inliningTarget, v, w, z);
@@ -95,4 +93,8 @@ private static PException raiseNotSupported(Node inliningTarget, Object v, Objec
public static PyNumberInPlacePowerNode create() {
return PyNumberInPlacePowerNodeGen.create();
}
+
+ public static PyNumberInPlacePowerNode getUncached() {
+ return PyNumberInPlacePowerNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
index 7d4d0ceb25..ff1dc9027e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRemainderNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceRemainderNode create() {
return PyNumberInPlaceRemainderNodeGen.create();
}
+
+ public static PyNumberInPlaceRemainderNode getUncached() {
+ return PyNumberInPlaceRemainderNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
index 92e716a405..a65c78118b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceRshiftNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceRshiftNode create() {
return PyNumberInPlaceRshiftNodeGen.create();
}
+
+ public static PyNumberInPlaceRshiftNode getUncached() {
+ return PyNumberInPlaceRshiftNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
index ef43c8ba2c..01f0922d5b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceSubtractNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceSubtractNode create() {
return PyNumberInPlaceSubtractNodeGen.create();
}
+
+ public static PyNumberInPlaceSubtractNode getUncached() {
+ return PyNumberInPlaceSubtractNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
index 231b052dd0..6283e33d15 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceTrueDivideNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceTrueDivideNode create() {
return PyNumberInPlaceTrueDivideNodeGen.create();
}
+
+ public static PyNumberInPlaceTrueDivideNode getUncached() {
+ return PyNumberInPlaceTrueDivideNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
index 4449af193d..066f430cec 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInPlaceXorNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberInPlaceXorNode create() {
return PyNumberInPlaceXorNodeGen.create();
}
+
+ public static PyNumberInPlaceXorNode getUncached() {
+ return PyNumberInPlaceXorNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
index 7ef7f93f4c..a920f76837 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberInvertNode.java
@@ -93,4 +93,8 @@ public static Object doObject(VirtualFrame frame, Object object,
public static PyNumberInvertNode create() {
return PyNumberInvertNodeGen.create();
}
+
+ public static PyNumberInvertNode getUncached() {
+ return PyNumberInvertNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
index b792a9b2bc..0ce424836e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberLshiftNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberLshiftNode create() {
return PyNumberLshiftNodeGen.create();
}
+
+ public static PyNumberLshiftNode getUncached() {
+ return PyNumberLshiftNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
index a0e3f6041c..0262c2ad33 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMatrixMultiplyNode.java
@@ -66,4 +66,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberMatrixMultiplyNode create() {
return PyNumberMatrixMultiplyNodeGen.create();
}
+
+ public static PyNumberMatrixMultiplyNode getUncached() {
+ return PyNumberMatrixMultiplyNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
index 643081f0da..f8818b387f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberMultiplyNode.java
@@ -184,4 +184,8 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object v, Object w,
public static PyNumberMultiplyNode create() {
return PyNumberMultiplyNodeGen.create();
}
+
+ public static PyNumberMultiplyNode getUncached() {
+ return PyNumberMultiplyNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
index 5f0fcddf32..cca2839be7 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberNegativeNode.java
@@ -106,4 +106,8 @@ public static Object doObject(VirtualFrame frame, Object object,
public static PyNumberNegativeNode create() {
return PyNumberNegativeNodeGen.create();
}
+
+ public static PyNumberNegativeNode getUncached() {
+ return PyNumberNegativeNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
index 5136d6640f..07e1a56b8d 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberOrNode.java
@@ -92,4 +92,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberOrNode create() {
return PyNumberOrNodeGen.create();
}
+
+ public static PyNumberOrNode getUncached() {
+ return PyNumberOrNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
index 897fc6ae2a..833297afea 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPositiveNode.java
@@ -88,4 +88,8 @@ public static Object doObject(VirtualFrame frame, Object object,
public static PyNumberPositiveNode create() {
return PyNumberPositiveNodeGen.create();
}
+
+ public static PyNumberPositiveNode getUncached() {
+ return PyNumberPositiveNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
index 18d3a87e3d..4920cd8347 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberPowerNode.java
@@ -106,4 +106,8 @@ private static PException raiseNotSupported(Node inliningTarget, Object v, Objec
public static PyNumberPowerNode create() {
return PyNumberPowerNodeGen.create();
}
+
+ public static PyNumberPowerNode getUncached() {
+ return PyNumberPowerNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
index 403269c6fc..786f3ac78b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRemainderNode.java
@@ -87,4 +87,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberRemainderNode create() {
return PyNumberRemainderNodeGen.create();
}
+
+ public static PyNumberRemainderNode getUncached() {
+ return PyNumberRemainderNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
index 8e36dad6e2..3ee97ad394 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberRshiftNode.java
@@ -127,4 +127,8 @@ private static void handlePossiblePrint(Node inliningTarget, Object v, Object w)
public static PyNumberRshiftNode create() {
return PyNumberRshiftNodeGen.create();
}
+
+ public static PyNumberRshiftNode getUncached() {
+ return PyNumberRshiftNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
index 3f392cc598..4d853bb56f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberSubtractNode.java
@@ -132,4 +132,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberSubtractNode create() {
return PyNumberSubtractNodeGen.create();
}
+
+ public static PyNumberSubtractNode getUncached() {
+ return PyNumberSubtractNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
index 8f59f003a7..c81523634b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberTrueDivideNode.java
@@ -114,4 +114,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberTrueDivideNode create() {
return PyNumberTrueDivideNodeGen.create();
}
+
+ public static PyNumberTrueDivideNode getUncached() {
+ return PyNumberTrueDivideNodeGen.getUncached();
+ }
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
index 18633e77f2..247d296251 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberXorNode.java
@@ -92,4 +92,8 @@ public static Object doIt(VirtualFrame frame, Object v, Object w,
public static PyNumberXorNode create() {
return PyNumberXorNodeGen.create();
}
+
+ public static PyNumberXorNode getUncached() {
+ return PyNumberXorNodeGen.getUncached();
+ }
}
From fc87def07fe840a255f5976d6a1fbc3a22f5d253 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 16:28:07 +0100
Subject: [PATCH 039/512] Remove arithmetic root nodes and
LookupAndCallReversibleTernary
---
...LookupAndCallNonReversibleTernaryNode.java | 16 +-
.../LookupAndCallReversibleTernaryNode.java | 206 ------------------
.../special/LookupAndCallTernaryNode.java | 33 +--
.../nodes/expression/BinaryArithmetic.java | 50 -----
.../nodes/expression/InplaceArithmetic.java | 195 -----------------
.../expression/LookupAndCallInplaceNode.java | 154 -------------
.../nodes/expression/TernaryArithmetic.java | 133 -----------
.../nodes/expression/UnaryArithmetic.java | 47 ----
8 files changed, 2 insertions(+), 832 deletions(-)
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleTernaryNode.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallNonReversibleTernaryNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallNonReversibleTernaryNode.java
index e6b0a0413f..d6b23ded91 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallNonReversibleTernaryNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallNonReversibleTernaryNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,9 +41,7 @@
package com.oracle.graal.python.nodes.call.special;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
-import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.TernaryBuiltinDescriptor;
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
@@ -68,10 +66,6 @@ public abstract class LookupAndCallNonReversibleTernaryNode extends LookupAndCal
super(name);
}
- LookupAndCallNonReversibleTernaryNode(SpecialMethodSlot slot) {
- super(slot);
- }
-
protected static PythonBuiltinClassType getBuiltinClass(Node inliningTarget, Object receiver, GetClassNode getClassNode) {
Object clazz = getClassNode.execute(inliningTarget, receiver);
return clazz instanceof PythonBuiltinClassType ? (PythonBuiltinClassType) clazz : null;
@@ -82,14 +76,6 @@ protected static boolean isClazz(Node inliningTarget, PythonBuiltinClassType cla
}
protected final PythonTernaryBuiltinNode getTernaryBuiltin(PythonBuiltinClassType clazz) {
- if (slot != null) {
- Object attribute = slot.getValue(clazz);
- if (attribute instanceof TernaryBuiltinDescriptor) {
- return ((TernaryBuiltinDescriptor) attribute).createNode();
- }
- // If the slot does not contain builtin, full lookup wouldn't find a builtin either
- return null;
- }
Object attribute = LookupAttributeInMRONode.Dynamic.getUncached().execute(clazz, name);
if (attribute instanceof PBuiltinFunction) {
PBuiltinFunction builtinFunction = (PBuiltinFunction) attribute;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleTernaryNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleTernaryNode.java
deleted file mode 100644
index 9bf7623ace..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallReversibleTernaryNode.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.call.special;
-
-import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
-import com.oracle.graal.python.nodes.SpecialMethodNames;
-import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.dsl.Bind;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.Cached.Exclusive;
-import com.oracle.truffle.api.dsl.ImportStatic;
-import com.oracle.truffle.api.dsl.ReportPolymorphism.Megamorphic;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.Node;
-import com.oracle.truffle.api.profiles.InlinedBranchProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-
-@ImportStatic({SpecialMethodNames.class, PythonOptions.class})
-public abstract class LookupAndCallReversibleTernaryNode extends LookupAndCallTernaryNode {
-
- @Child private CallTernaryMethodNode reverseDispatchNode;
- @Child private CallTernaryMethodNode thirdDispatchNode;
- @Child protected LookupSpecialMethodNode getThirdAttrNode;
-
- @Child protected NotImplementedHandler handler;
- protected final Supplier handlerFactory;
-
- LookupAndCallReversibleTernaryNode(TruffleString name, Supplier handlerFactory) {
- super(name);
- this.handlerFactory = handlerFactory;
- }
-
- public LookupAndCallReversibleTernaryNode(SpecialMethodSlot slot, Supplier handlerFactory) {
- super(slot);
- this.handlerFactory = handlerFactory;
- }
-
- @Specialization(guards = "v.getClass() == cachedVClass", limit = "getCallSiteInlineCacheMaxDepth()")
- @SuppressWarnings("truffle-static-method")
- Object callObjectR(VirtualFrame frame, Object v, Object w, Object z,
- @Bind("this") Node inliningTarget,
- @SuppressWarnings("unused") @Cached("v.getClass()") Class> cachedVClass,
- @Exclusive @Cached("createLookup()") LookupSpecialBaseNode getattr,
- @Exclusive @Cached("createLookup()") LookupSpecialBaseNode getattrR,
- @Exclusive @Cached GetClassNode getClass,
- @Exclusive @Cached GetClassNode getClassR,
- @Exclusive @Cached GetClassNode getThirdClass,
- @Exclusive @Cached IsSubtypeNode isSubtype,
- @Exclusive @Cached IsSameTypeNode isSameTypeNode,
- @Exclusive @Cached InlinedBranchProfile notImplementedBranch,
- @Exclusive @Cached CallTernaryMethodNode dispatchNode) {
- return doCallObjectR(frame, inliningTarget, v, w, z, getattr, getattrR, getClass, getClassR, getThirdClass, isSubtype, isSameTypeNode, notImplementedBranch, dispatchNode);
- }
-
- @Specialization(replaces = "callObjectR")
- @Megamorphic
- @SuppressWarnings("truffle-static-method")
- Object callObjectRMegamorphic(VirtualFrame frame, Object v, Object w, Object z,
- @Bind("this") Node inliningTarget,
- @Exclusive @Cached("createLookup()") LookupSpecialBaseNode getattr,
- @Exclusive @Cached("createLookup()") LookupSpecialBaseNode getattrR,
- @Exclusive @Cached GetClassNode getClass,
- @Exclusive @Cached GetClassNode getClassR,
- @Exclusive @Cached GetClassNode getThirdClass,
- @Exclusive @Cached IsSubtypeNode isSubtype,
- @Exclusive @Cached IsSameTypeNode isSameTypeNode,
- @Exclusive @Cached InlinedBranchProfile notImplementedBranch,
- @Exclusive @Cached CallTernaryMethodNode dispatchNode) {
- return doCallObjectR(frame, inliningTarget, v, w, z, getattr, getattrR, getClass, getClassR, getThirdClass, isSubtype, isSameTypeNode, notImplementedBranch, dispatchNode);
- }
-
- private Object doCallObjectR(VirtualFrame frame, Node inliningTarget, Object v, Object w, Object z, LookupSpecialBaseNode getattr,
- LookupSpecialBaseNode getattrR, GetClassNode getClass, GetClassNode getClassR, GetClassNode getThirdClass,
- IsSubtypeNode isSubtype, IsSameTypeNode isSameTypeNode, InlinedBranchProfile notImplementedBranch,
- CallTernaryMethodNode dispatchNode) {
- // c.f. mostly slot_nb_power and wrap_ternaryfunc_r. like
- // cpython://Object/abstract.c#ternary_op we try all three combinations, and the structure
- // of this method is modeled after this. However, this method also merges the logic from
- // slot_nb_power/wrap_ternaryfunc_r in that it swaps arguments around. The reversal is
- // undone for builtin functions in BuiltinFunctionRootNode, just like it would be undone in
- // CPython using its slot wrappers
- Object leftClass = getClass.execute(inliningTarget, v);
- Object rightClass = getClassR.execute(inliningTarget, w);
-
- Object result = PNotImplemented.NOT_IMPLEMENTED;
- Object leftCallable = getattr.execute(frame, leftClass, v);
- Object rightCallable = PNone.NO_VALUE;
-
- if (!isSameTypeNode.execute(inliningTarget, leftClass, rightClass)) {
- rightCallable = getattrR.execute(frame, rightClass, w);
- if (rightCallable == leftCallable) {
- rightCallable = PNone.NO_VALUE;
- }
- }
- if (leftCallable != PNone.NO_VALUE) {
- if (rightCallable != PNone.NO_VALUE && isSubtype.execute(frame, rightClass, leftClass)) {
- result = ensureReverseDispatch().execute(frame, rightCallable, v, w, z);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- rightCallable = PNone.NO_VALUE;
- }
- result = dispatchNode.execute(frame, leftCallable, v, w, z);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
- if (rightCallable != PNone.NO_VALUE) {
- result = ensureReverseDispatch().execute(frame, rightCallable, v, w, z);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
-
- Object zCallable = ensureGetAttrZ().execute(frame, getThirdClass.execute(inliningTarget, z), z);
- if (zCallable != PNone.NO_VALUE && zCallable != leftCallable && zCallable != rightCallable) {
- result = ensureThirdDispatch().execute(frame, zCallable, v, w, z);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
-
- notImplementedBranch.enter(inliningTarget);
- if (handlerFactory != null) {
- if (handler == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- handler = insert(handlerFactory.get());
- }
- return handler.execute(v, w, z);
- }
- return result;
- }
-
- protected CallTernaryMethodNode ensureReverseDispatch() {
- // this also serves as a branch profile
- if (reverseDispatchNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- reverseDispatchNode = insert(CallTernaryMethodNode.create());
- }
- return reverseDispatchNode;
- }
-
- protected CallTernaryMethodNode ensureThirdDispatch() {
- // this also serves as a branch profile
- if (thirdDispatchNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- thirdDispatchNode = insert(CallTernaryMethodNode.create());
- }
- return thirdDispatchNode;
- }
-
- protected LookupSpecialMethodNode ensureGetAttrZ() {
- // this also serves as a branch profile
- if (getThirdAttrNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- getThirdAttrNode = insert(LookupSpecialMethodNode.create(name));
- }
- return getThirdAttrNode;
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java
index 07ca21e71c..51be3c8c75 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -41,25 +41,18 @@
package com.oracle.graal.python.nodes.call.special;
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.runtime.PythonOptions;
-import com.oracle.graal.python.util.Supplier;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.strings.TruffleString;
-// actual implementation is in the subclasses: one for reversible, other for non-reversible.
@ImportStatic({SpecialMethodNames.class, PythonOptions.class})
public abstract class LookupAndCallTernaryNode extends Node {
- public abstract static class NotImplementedHandler extends PNodeWithContext {
- public abstract Object execute(Object arg, Object arg2, Object arg3);
- }
protected final TruffleString name;
- protected final SpecialMethodSlot slot;
public abstract Object execute(VirtualFrame frame, Object arg1, Object arg2, Object arg3);
@@ -72,36 +65,12 @@ public static LookupAndCallTernaryNode create(TruffleString name) {
return LookupAndCallNonReversibleTernaryNodeGen.create(name);
}
- @NeverDefault
- public static LookupAndCallTernaryNode create(SpecialMethodSlot slot) {
- return LookupAndCallNonReversibleTernaryNodeGen.create(slot);
- }
-
- @NeverDefault
- public static LookupAndCallTernaryNode createReversible(TruffleString name, Supplier handlerFactory) {
- return LookupAndCallReversibleTernaryNodeGen.create(name, handlerFactory);
- }
-
- @NeverDefault
- public static LookupAndCallTernaryNode createReversible(SpecialMethodSlot slot, Supplier handlerFactory) {
- return LookupAndCallReversibleTernaryNodeGen.create(slot, handlerFactory);
- }
-
LookupAndCallTernaryNode(TruffleString name) {
this.name = name;
- this.slot = null;
- }
-
- LookupAndCallTernaryNode(SpecialMethodSlot slot) {
- this.slot = slot;
- this.name = slot.getName();
}
@NeverDefault
protected final LookupSpecialBaseNode createLookup() {
- if (slot != null) {
- return LookupSpecialMethodSlotNode.create(slot);
- }
return LookupSpecialMethodNode.create(name);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
index e73fcb5874..cc8c33b374 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
@@ -43,11 +43,7 @@
import static com.oracle.graal.python.nodes.BuiltinNames.T_PRINT;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
-import static com.oracle.graal.python.util.PythonUtils.tsArray;
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.builtins.objects.function.Signature;
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
import com.oracle.graal.python.lib.PyNumberAddNode;
@@ -76,7 +72,6 @@
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -107,50 +102,11 @@ interface CreateBinaryOp {
this.create = create;
}
- /**
- * A helper root node that dispatches to {@link LookupAndCallBinaryNode} to execute the provided
- * ternary operator. Note: this is just a root node and won't do any signature checking.
- */
- static final class CallBinaryArithmeticRootNode extends CallArithmeticRootNode {
- static final Signature SIGNATURE_BINARY = new Signature(2, false, -1, false, tsArray("$self", "other"), null);
-
- @Child private BinaryOpNode callBinaryNode;
-
- private final BinaryArithmetic binaryOperator;
-
- CallBinaryArithmeticRootNode(PythonLanguage language, BinaryArithmetic binaryOperator) {
- super(language);
- this.binaryOperator = binaryOperator;
- }
-
- @Override
- public Signature getSignature() {
- return SIGNATURE_BINARY;
- }
-
- @Override
- protected Object doCall(VirtualFrame frame) {
- if (callBinaryNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callBinaryNode = insert(binaryOperator.create());
- }
- return callBinaryNode.execute(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1));
- }
- }
-
@NeverDefault
public BinaryOpNode create() {
return create.create();
}
- /**
- * Creates a root node for this binary operator such that the operator can be executed via a
- * full call.
- */
- public RootNode createRootNode(PythonLanguage language) {
- return new CallBinaryArithmeticRootNode(language, this);
- }
-
@ImportStatic(SpecialMethodNames.class)
public abstract static class BinaryArithmeticNode extends BinaryOpNode {
@@ -174,12 +130,6 @@ private TruffleString getErrorMessage(Object arg) {
};
}
- @NeverDefault
- public static LookupAndCallBinaryNode createCallNode(SpecialMethodSlot slot, Supplier handler) {
- assert slot.getReverse() != null;
- return LookupAndCallBinaryNode.createReversible(slot, slot.getReverse(), handler);
- }
-
}
public abstract static class GenericBinaryArithmeticNode extends BinaryArithmeticNode {
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
deleted file mode 100644
index 7248ea944d..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.expression;
-
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ADD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___FLOORDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IFLOORDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ILSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMATMUL__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IMOD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IOR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IPOW__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IRSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ISUB__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ITRUEDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IXOR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___LSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MATMUL__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MOD__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___MUL__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___OR__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___POW__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSHIFT__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SUB__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___TRUEDIV__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___XOR__;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.builtins.objects.function.Signature;
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic.CallBinaryArithmeticRootNode;
-import com.oracle.graal.python.nodes.expression.TernaryArithmetic.CallTernaryArithmeticRootNode;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.RootNode;
-import com.oracle.truffle.api.profiles.BranchProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-
-public enum InplaceArithmetic {
- IAdd(SpecialMethodSlot.IAdd, T___ADD__, "+=", BinaryArithmetic.Add),
- ISub(T___ISUB__, T___SUB__, "-=", BinaryArithmetic.Sub),
- IMul(SpecialMethodSlot.IMul, T___MUL__, "*=", BinaryArithmetic.Mul),
- ITrueDiv(T___ITRUEDIV__, T___TRUEDIV__, "/=", BinaryArithmetic.TrueDiv),
- IFloorDiv(T___IFLOORDIV__, T___FLOORDIV__, "//=", BinaryArithmetic.FloorDiv),
- IMod(T___IMOD__, T___MOD__, "%=", BinaryArithmetic.Mod),
- IPow(T___IPOW__, T___POW__, "**=", BinaryArithmetic.Pow, true),
- ILShift(T___ILSHIFT__, T___LSHIFT__, "<<=", BinaryArithmetic.LShift),
- IRShift(T___IRSHIFT__, T___RSHIFT__, ">>=", BinaryArithmetic.RShift),
- IAnd(T___IAND__, T___AND__, "&=", BinaryArithmetic.And),
- IOr(T___IOR__, T___OR__, "|=", BinaryArithmetic.Or),
- IXor(T___IXOR__, T___XOR__, "^=", BinaryArithmetic.Xor),
- IMatMul(T___IMATMUL__, T___MATMUL__, "@", BinaryArithmetic.MatMul);
-
- final TruffleString methodName;
- final SpecialMethodSlot slot;
- final boolean isTernary;
- final Supplier notImplementedHandler;
- final BinaryArithmetic binary;
- final TruffleString binaryOpName;
-
- InplaceArithmetic(TruffleString methodName, TruffleString binaryOpName, String operator, BinaryArithmetic binary) {
- this(methodName, binaryOpName, operator, binary, false);
- }
-
- InplaceArithmetic(SpecialMethodSlot slot, TruffleString binaryOpName, String operator, BinaryArithmetic binary) {
- this(slot.getName(), binaryOpName, operator, binary, false, slot);
- }
-
- InplaceArithmetic(TruffleString methodName, TruffleString binaryOpName, String operator, BinaryArithmetic binary, boolean isTernary) {
- this(methodName, binaryOpName, operator, binary, isTernary, null);
- }
-
- InplaceArithmetic(TruffleString methodName, TruffleString binaryOpName, @SuppressWarnings("unused") String operator, BinaryArithmetic binary, boolean isTernary, SpecialMethodSlot slot) {
- assert methodName.toJavaStringUncached().startsWith("__i") && methodName.toJavaStringUncached().substring(3).equals(binaryOpName.toJavaStringUncached().substring(2));
- this.methodName = methodName;
- this.binary = binary;
- this.isTernary = isTernary;
- this.binaryOpName = binaryOpName;
- this.slot = slot;
-
- this.notImplementedHandler = () -> new LookupAndCallInplaceNode.NotImplementedHandler() {
- private final BranchProfile errorProfile = BranchProfile.create();
-
- @Override
- public Object execute(Object arg, Object arg2) {
- errorProfile.enter();
- throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P, operator, arg, arg2);
- }
- };
- }
-
- public TruffleString getMethodName() {
- return methodName;
- }
-
- public boolean isTernary() {
- return isTernary;
- }
-
- /**
- * A helper root node that dispatches to {@link LookupAndCallInplaceNode} to execute the
- * provided in-place operator. This node is mostly useful to use such operators from a location
- * without a frame (e.g. from interop). Note: this is just a root node and won't do any
- * signature checking.
- */
- static final class CallInplaceArithmeticRootNode extends CallArithmeticRootNode {
-
- @Child private LookupAndCallInplaceNode callInplaceNode;
-
- private final InplaceArithmetic inplaceOperator;
-
- CallInplaceArithmeticRootNode(PythonLanguage language, InplaceArithmetic inplaceOperator) {
- super(language);
- this.inplaceOperator = inplaceOperator;
- }
-
- @Override
- public Signature getSignature() {
- if (inplaceOperator.isTernary()) {
- return CallTernaryArithmeticRootNode.SIGNATURE_TERNARY;
- }
- return CallBinaryArithmeticRootNode.SIGNATURE_BINARY;
- }
-
- @Override
- protected Object doCall(VirtualFrame frame) {
- if (callInplaceNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callInplaceNode = insert(inplaceOperator.create());
- }
- // most of the in-place operators are binary but there can also be ternary
- if (inplaceOperator.isTernary()) {
- return callInplaceNode.executeTernary(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1), PArguments.getArgument(frame, 2));
- }
- return callInplaceNode.execute(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1));
- }
- }
-
- public LookupAndCallInplaceNode create() {
- return LookupAndCallInplaceNode.create(this);
- }
-
- /**
- * Creates a root node for this in-place operator such that the operator can be executed via a
- * full call.
- */
- public RootNode createRootNode(PythonLanguage language) {
- return new CallInplaceArithmeticRootNode(language, this);
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
deleted file mode 100644
index 098bf33c3d..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/LookupAndCallInplaceNode.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.expression;
-
-import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.PNotImplemented;
-import com.oracle.graal.python.nodes.PGuards;
-import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
-import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
-import com.oracle.graal.python.nodes.attributes.LookupInMROBaseNode;
-import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.dsl.Bind;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.NeverDefault;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.Node;
-
-public abstract class LookupAndCallInplaceNode extends PNodeWithContext implements BinaryOp {
-
- public abstract static class NotImplementedHandler extends PNodeWithContext {
- public abstract Object execute(Object arg, Object arg2);
- }
-
- @Child private CallBinaryMethodNode callBinaryMethodNode;
- @Child private BinaryOpNode binaryOpNode;
- @Child private LookupAndCallTernaryNode lookupAndCallTernaryNode;
- @Child private NotImplementedHandler handler;
-
- final InplaceArithmetic arithmetic;
-
- LookupAndCallInplaceNode(InplaceArithmetic arithmetic) {
- this.arithmetic = arithmetic;
- }
-
- public static LookupAndCallInplaceNode create(InplaceArithmetic arithmetic) {
- return LookupAndCallInplaceNodeGen.create(arithmetic);
- }
-
- private CallBinaryMethodNode ensureBinaryCallNode() {
- if (callBinaryMethodNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callBinaryMethodNode = insert(CallBinaryMethodNode.create());
- }
- return callBinaryMethodNode;
- }
-
- private BinaryOpNode ensureLookupAndCallBinaryNode() {
- if (binaryOpNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- binaryOpNode = insert(arithmetic.binary.create());
- }
- return binaryOpNode;
- }
-
- private LookupAndCallTernaryNode ensureLookupAndCallTernaryNode() {
- if (lookupAndCallTernaryNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- lookupAndCallTernaryNode = insert(LookupAndCallTernaryNode.createReversible(arithmetic.binaryOpName, null));
- }
- return lookupAndCallTernaryNode;
- }
-
- @Override
- public final Object execute(VirtualFrame frame, Object left, Object right) {
- return executeTernary(frame, left, right, PNone.NO_VALUE);
- }
-
- public abstract Object executeTernary(VirtualFrame frame, Object x, Object y, Object z);
-
- @NeverDefault
- protected final LookupInMROBaseNode createInplaceLookup() {
- if (arithmetic.slot != null) {
- return LookupCallableSlotInMRONode.create(arithmetic.slot);
- } else {
- return LookupAttributeInMRONode.create(arithmetic.methodName);
- }
- }
-
- @Specialization
- Object doBinary(VirtualFrame frame, Object left, Object right, Object z,
- @Bind("this") Node inliningTarget,
- @Cached GetClassNode getClassNode,
- @Cached("createInplaceLookup()") LookupInMROBaseNode lookupInplace) {
- Object result;
- Object inplaceCallable = lookupInplace.execute(getClassNode.execute(inliningTarget, left));
- if (inplaceCallable != PNone.NO_VALUE) {
- // nb.: The only ternary in-place operator is '__ipow__' but according to 'typeobject.c:
- // slot_nb_inplace_power', this is always called as binary.
- result = ensureBinaryCallNode().executeObject(frame, inplaceCallable, left, right);
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- }
-
- // try non-inplace variant
- boolean isBinary = PGuards.isPNone(z);
- if (isBinary) {
- result = ensureLookupAndCallBinaryNode().execute(frame, left, right);
- } else {
- result = ensureLookupAndCallTernaryNode().execute(frame, left, right, z);
- }
- if (result != PNotImplemented.NOT_IMPLEMENTED) {
- return result;
- }
- if (handler == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- handler = insert(arithmetic.notImplementedHandler.get());
- }
- return handler.execute(left, right);
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
deleted file mode 100644
index 142e626203..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/TernaryArithmetic.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.expression;
-
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-import static com.oracle.graal.python.util.PythonUtils.tsArray;
-
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.objects.PNone;
-import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.builtins.objects.function.Signature;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.SpecialMethodNames;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode.NotImplementedHandler;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.RootNode;
-import com.oracle.truffle.api.profiles.BranchProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-
-public enum TernaryArithmetic {
- Pow(SpecialMethodNames.T___POW__, "**", "pow");
-
- private final TruffleString methodName;
- private final Supplier notImplementedHandler;
-
- TernaryArithmetic(TruffleString methodName, @SuppressWarnings("unused") String operator, String operatorFunction) {
- this.methodName = methodName;
- this.notImplementedHandler = () -> new NotImplementedHandler() {
- private final BranchProfile errorProfile = BranchProfile.create();
-
- @Override
- public Object execute(Object arg, Object arg2, Object arg3) {
- errorProfile.enter();
- if (arg3 instanceof PNone) {
- throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_PR_S_P_AND_P, operator, operatorFunction, arg, arg2);
- } else {
- throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_P_P, operatorFunction, arg, arg2, arg3);
- }
- }
- };
- }
-
- public TruffleString getMethodName() {
- return methodName;
- }
-
- /**
- * A helper root node that dispatches to {@link LookupAndCallTernaryNode} to execute the
- * provided ternary operator. This node is mostly useful to use such operators from a location
- * without a frame (e.g. from interop). Note: this is just a root node and won't do any
- * signature checking.
- */
- static final class CallTernaryArithmeticRootNode extends CallArithmeticRootNode {
- static final Signature SIGNATURE_TERNARY = new Signature(3, false, -1, false, tsArray("x", "y", "z"), null);
-
- @Child private LookupAndCallTernaryNode callTernaryNode;
-
- private final TernaryArithmetic ternaryOperator;
-
- private CallTernaryArithmeticRootNode(PythonLanguage language, TernaryArithmetic ternaryOperator) {
- super(language);
- this.ternaryOperator = ternaryOperator;
- }
-
- @Override
- public Signature getSignature() {
- return SIGNATURE_TERNARY;
- }
-
- @Override
- protected Object doCall(VirtualFrame frame) {
- if (callTernaryNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callTernaryNode = insert(ternaryOperator.create());
- }
- return callTernaryNode.execute(frame, PArguments.getArgument(frame, 0), PArguments.getArgument(frame, 1), PArguments.getArgument(frame, 2));
- }
- }
-
- public LookupAndCallTernaryNode create() {
- return LookupAndCallTernaryNode.createReversible(methodName, notImplementedHandler);
- }
-
- /**
- * Creates a root node for this ternary operator such that the operator can be executed via a
- * full call.
- */
- public RootNode createRootNode(PythonLanguage language) {
- return new CallTernaryArithmeticRootNode(language, this);
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
index a60c3167d3..f6d45c140b 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
@@ -41,11 +41,7 @@
package com.oracle.graal.python.nodes.expression;
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-import static com.oracle.graal.python.util.PythonUtils.tsArray;
-import com.oracle.graal.python.PythonLanguage;
-import com.oracle.graal.python.builtins.objects.function.PArguments;
-import com.oracle.graal.python.builtins.objects.function.Signature;
import com.oracle.graal.python.lib.PyNumberInvertNode;
import com.oracle.graal.python.lib.PyNumberNegativeNode;
import com.oracle.graal.python.lib.PyNumberPositiveNode;
@@ -55,14 +51,12 @@
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.NoAttributeHandler;
import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
@@ -81,51 +75,10 @@ interface CreateUnaryOp {
this.create = create;
}
- /**
- * A helper root node that dispatches to {@link LookupAndCallUnaryNode} to execute the provided
- * unary operator. This node is mostly useful to use such operators from a location without a
- * frame (e.g. from interop). Note: this is just a root node and won't do any signature
- * checking.
- */
- static final class CallUnaryArithmeticRootNode extends CallArithmeticRootNode {
- private static final Signature SIGNATURE_UNARY = new Signature(1, false, -1, false, tsArray("$self"), null);
-
- @Child private UnaryOpNode callUnaryNode;
-
- private final UnaryArithmetic unaryOperator;
-
- CallUnaryArithmeticRootNode(PythonLanguage language, UnaryArithmetic unaryOperator) {
- super(language);
- this.unaryOperator = unaryOperator;
- }
-
- @Override
- public Signature getSignature() {
- return SIGNATURE_UNARY;
- }
-
- @Override
- protected Object doCall(VirtualFrame frame) {
- if (callUnaryNode == null) {
- CompilerDirectives.transferToInterpreterAndInvalidate();
- callUnaryNode = insert(unaryOperator.create());
- }
- return callUnaryNode.execute(frame, PArguments.getArgument(frame, 0));
- }
- }
-
public UnaryOpNode create() {
return create.create();
}
- /**
- * Creates a root node for this unary operator such that the operator can be executed via a full
- * call.
- */
- public RootNode createRootNode(PythonLanguage language) {
- return new CallUnaryArithmeticRootNode(language, this);
- }
-
@ImportStatic(SpecialMethodNames.class)
public abstract static class UnaryArithmeticNode extends UnaryOpNode {
From 56b614a5984e1156d6947f5bec2c81e7118bdcd2 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 16:36:45 +0100
Subject: [PATCH 040/512] Remove old delattr slot
---
.../builtins/modules/AbcModuleBuiltins.java | 8 +-
.../builtins/modules/BuiltinFunctions.java | 5 +-
.../objects/type/SpecialMethodSlot.java | 8 --
.../graal/python/lib/PyObjectSetAttr.java | 4 +
.../nodes/attributes/DeleteAttributeNode.java | 76 -------------------
.../python/nodes/frame/DeleteGlobalNode.java | 12 +--
6 files changed, 15 insertions(+), 98 deletions(-)
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
index 51a5c1bbc3..ac6be1a5ce 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AbcModuleBuiltins.java
@@ -58,10 +58,10 @@
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesAsArrayNode;
import com.oracle.graal.python.lib.PyObjectLookupAttr;
+import com.oracle.graal.python.lib.PyObjectSetAttr;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.HiddenAttr;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.attributes.DeleteAttributeNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -70,7 +70,6 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
-import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
@@ -94,8 +93,7 @@ abstract static class AbcInitCollectionFlagsNode extends PythonUnaryBuiltinNode
@TruffleBoundary
@Specialization
static Object init(Object object,
- @Bind("this") Node inliningTarget,
- @Cached DeleteAttributeNode deleteAttributeNode) {
+ @Bind("this") Node inliningTarget) {
if (TypeNodes.IsTypeNode.executeUncached(object)) {
Object flags = PyObjectLookupAttr.executeUncached(object, ABC_TPFLAGS);
long val;
@@ -117,7 +115,7 @@ static Object init(Object object,
type = (PythonAbstractObject) object;
}
HiddenAttr.WriteNode.executeUncached(type, HiddenAttr.FLAGS, tpFlags);
- deleteAttributeNode.execute(null, inliningTarget, object, ABC_TPFLAGS);
+ PyObjectSetAttr.deleteUncached(object, ABC_TPFLAGS);
}
return PNone.NONE;
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
index 1669baa4b4..721debf322 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java
@@ -200,7 +200,6 @@
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.StringLiterals;
import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
-import com.oracle.graal.python.nodes.attributes.DeleteAttributeNode;
import com.oracle.graal.python.nodes.attributes.GetAttributeNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.builtins.ListNodes;
@@ -1276,8 +1275,8 @@ abstract static class DelAttrNode extends PythonBinaryBuiltinNode {
@Specialization
Object delattr(VirtualFrame frame, Object object, Object name,
@Bind("this") Node inliningTarget,
- @Cached DeleteAttributeNode delNode) {
- delNode.execute(frame, inliningTarget, object, name);
+ @Cached PyObjectSetAttrO setAttr) {
+ setAttr.execute(frame, inliningTarget, object, name, NO_VALUE);
return PNone.NONE;
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
index 6e3969706a..f46ae14faa 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java
@@ -57,7 +57,6 @@
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BYTES__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CONTAINS__;
-import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DELATTR__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ENTER__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___EQ__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___EXIT__;
@@ -151,8 +150,6 @@
* initialized.
*/
public enum SpecialMethodSlot {
- DelAttr(T___DELATTR__),
-
Dict(T___DICT__),
Iter(T___ITER__),
@@ -750,11 +747,6 @@ public static SpecialMethodSlot findSpecialSlot(TruffleString name, TruffleStrin
return SetName;
}
break;
- case 'd' * 26 + 'e': // de
- if (eqNode.execute(name, T___DELATTR__, TS_ENCODING)) {
- return DelAttr;
- }
- break;
case 'd' * 26 + 'i': // di
if (eqNode.execute(name, T___DICT__, TS_ENCODING)) {
return Dict;
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
index 36da362ca1..21b82c45a0 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectSetAttr.java
@@ -95,6 +95,10 @@ public final void deleteCached(Frame frame, Object receiver, TruffleString name)
execute(frame, null, receiver, name, PNone.NO_VALUE);
}
+ public static void deleteUncached(Object receiver, TruffleString name) {
+ executeUncached(receiver, name, PNone.NO_VALUE);
+ }
+
public final void delete(Frame frame, Node inliningTarget, Object receiver, TruffleString name) {
execute(frame, inliningTarget, receiver, name, PNone.NO_VALUE);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java
deleted file mode 100644
index 0878e51610..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.attributes;
-
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
-import com.oracle.graal.python.nodes.object.GetClassNode;
-import com.oracle.graal.python.util.PythonUtils;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.GenerateCached;
-import com.oracle.truffle.api.dsl.GenerateInline;
-import com.oracle.truffle.api.dsl.GenerateUncached;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.nodes.Node;
-
-@GenerateUncached
-@GenerateInline
-@GenerateCached(false)
-public abstract class DeleteAttributeNode extends PNodeWithContext {
- public abstract void execute(VirtualFrame frame, Node inliningTarget, Object object, Object key);
-
- @Specialization
- protected void doIt(VirtualFrame frame, Object object, Object key,
- @Cached(value = "create(DelAttr)", inline = false) LookupAndCallBinaryNode call) {
- call.executeObject(frame, object, key);
- }
-
- @Specialization(replaces = "doIt")
- protected void doItUncached(VirtualFrame frame, Object object, Object key) {
- PythonUtils.assertUncached();
- Object klass = GetClassNode.executeUncached(object);
- Object method = LookupCallableSlotInMRONode.getUncached(SpecialMethodSlot.DelAttr).execute(klass);
- CallBinaryMethodNode.getUncached().executeObject(frame, method, object, key);
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DeleteGlobalNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DeleteGlobalNode.java
index e24332f33f..8c5589cc2f 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DeleteGlobalNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DeleteGlobalNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,8 +43,8 @@
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.builtins.objects.module.PythonModule;
import com.oracle.graal.python.lib.PyObjectDelItem;
+import com.oracle.graal.python.lib.PyObjectSetAttr;
import com.oracle.graal.python.nodes.PNodeWithContext;
-import com.oracle.graal.python.nodes.attributes.DeleteAttributeNode;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
@@ -88,14 +88,14 @@ static void deleteDict(VirtualFrame frame, PDict globals, TruffleString attribut
static void deleteModuleCached(VirtualFrame frame, @SuppressWarnings("unused") PythonModule globals, TruffleString attributeId,
@Bind("this") Node inliningTarget,
@Cached(value = "globals", weak = true) PythonModule cachedGlobals,
- @Shared @Cached DeleteAttributeNode storeNode) {
- storeNode.execute(frame, inliningTarget, cachedGlobals, attributeId);
+ @Shared @Cached PyObjectSetAttr setAttr) {
+ setAttr.delete(frame, inliningTarget, cachedGlobals, attributeId);
}
@Specialization(replaces = "deleteModuleCached")
static void deleteModule(VirtualFrame frame, PythonModule globals, TruffleString attributeId,
@Bind("this") Node inliningTarget,
- @Shared @Cached DeleteAttributeNode storeNode) {
- storeNode.execute(frame, inliningTarget, globals, attributeId);
+ @Shared @Cached PyObjectSetAttr setAttr) {
+ setAttr.delete(frame, inliningTarget, globals, attributeId);
}
}
From 81460392dac5e06d3e1bda6d7a772ebf054e38c7 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Wed, 19 Feb 2025 17:07:44 +0100
Subject: [PATCH 041/512] Remove *naryArithmetic classes
---
.../builtins/modules/MathModuleBuiltins.java | 9 +-
.../builtins/modules/PosixModuleBuiltins.java | 9 +-
.../foreign/ForeignNumberBuiltins.java | 52 +++---
.../mappingproxy/MappingproxyBuiltins.java | 7 +-
.../objects/types/UnionTypeBuiltins.java | 7 +-
.../call/special/LookupAndCallUnaryNode.java | 10 +-
.../nodes/expression/BinaryArithmetic.java | 159 ------------------
.../nodes/expression/UnaryArithmetic.java | 129 --------------
8 files changed, 55 insertions(+), 327 deletions(-)
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
index 38a0d39fad..33cde1d47e 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java
@@ -56,6 +56,7 @@
import com.oracle.graal.python.lib.PyLongFromDoubleNode;
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
+import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyObjectGetIter;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PGuards;
@@ -65,9 +66,7 @@
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -2469,14 +2468,14 @@ private static void raiseIfNegative(Node inliningTarget, boolean condition, PRai
public abstract static class ProdNode extends PythonBuiltinNode {
@Child private LookupAndCallUnaryNode callNextNode = LookupAndCallUnaryNode.create(SpecialMethodSlot.Next);
- @Child private BinaryOpNode mul = BinaryArithmetic.Mul.create();
@Specialization
public Object doGeneric(VirtualFrame frame, Object iterable, Object startIn,
@Bind("this") Node inliningTarget,
@Cached IsBuiltinObjectProfile errorProfile,
@Cached InlinedConditionProfile startIsNoValueProfile,
- @Cached PyObjectGetIter getIter) {
+ @Cached PyObjectGetIter getIter,
+ @Cached PyNumberMultiplyNode multiplyNode) {
Object start = startIsNoValueProfile.profile(inliningTarget, PGuards.isNoValue(startIn)) ? 1 : startIn;
Object iterator = getIter.execute(frame, inliningTarget, iterable);
Object value = start;
@@ -2488,7 +2487,7 @@ public Object doGeneric(VirtualFrame frame, Object iterable, Object startIn,
e.expectStopIteration(inliningTarget, errorProfile);
return value;
}
- value = mul.execute(frame, value, nextValue);
+ value = multiplyNode.execute(frame, inliningTarget, value, nextValue);
}
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
index b83c26208c..0877f1c927 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java
@@ -88,6 +88,7 @@
import com.oracle.graal.python.lib.PyLongAsLongAndOverflowNode;
import com.oracle.graal.python.lib.PyLongAsLongNode;
import com.oracle.graal.python.lib.PyLongCheckNode;
+import com.oracle.graal.python.lib.PyNumberDivmodNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
import com.oracle.graal.python.lib.PyOSFSPathNode;
import com.oracle.graal.python.lib.PyObjectAsFileDescriptor;
@@ -98,8 +99,6 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
@@ -3300,7 +3299,7 @@ static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, lon
*/
@GenerateInline
@GenerateCached(false)
- @ImportStatic({BinaryArithmetic.class, PGuards.class})
+ @ImportStatic(PGuards.class)
abstract static class SplitLongToSAndNsNode extends ConvertToTimespecBaseNode {
private static final long BILLION = 1000000000;
@@ -3318,12 +3317,12 @@ static void doLong(long value, long[] timespec, int offset) {
@Specialization(guards = {"!isInteger(value)"})
static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, long[] timespec, int offset,
- @Cached(value = "DivMod.create()", inline = false) BinaryOpNode callDivmod,
+ @Cached PyNumberDivmodNode divmodNode,
@Cached LenNode lenNode,
@Cached(value = "createNotNormalized()", inline = false) GetItemNode getItemNode,
@Cached PyLongAsLongNode asLongNode,
@Cached PRaiseNode raiseNode) {
- Object divmod = callDivmod.execute(frame, value, BILLION);
+ Object divmod = divmodNode.execute(frame, inliningTarget, value, BILLION);
if (!PGuards.isPTuple(divmod) || lenNode.execute(inliningTarget, (PSequence) divmod) != 2) {
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod);
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
index 88f2b2a367..9cff1707f4 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java
@@ -65,8 +65,10 @@
import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberAndNode;
import com.oracle.graal.python.lib.PyNumberDivmodNode;
+import com.oracle.graal.python.lib.PyNumberFloatNode;
import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
import com.oracle.graal.python.lib.PyNumberInvertNode;
+import com.oracle.graal.python.lib.PyNumberLongNode;
import com.oracle.graal.python.lib.PyNumberLshiftNode;
import com.oracle.graal.python.lib.PyNumberMultiplyNode;
import com.oracle.graal.python.lib.PyNumberNegativeNode;
@@ -83,9 +85,8 @@
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
+import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
-import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -268,11 +269,8 @@ Object doGeneric(VirtualFrame frame, Object value,
@Bind("this") Node inliningTarget,
@Cached UnboxNode unboxNode) {
Object unboxed = unboxNode.execute(inliningTarget, value);
- if (unboxed != null) {
- return op.execute(frame, unboxed);
- } else {
- return PNotImplemented.NOT_IMPLEMENTED;
- }
+ assert unboxed != null;
+ return op.execute(frame, unboxed);
}
}
@@ -393,7 +391,7 @@ abstract static class AbsNode extends ForeignUnaryNode {
@GenerateNodeFactory
abstract static class CeilNode extends ForeignUnaryNode {
CeilNode() {
- super(UnaryArithmetic.GenericUnaryArithmeticNode.create(SpecialMethodNames.T___CEIL__));
+ super(LookupAndCallUnaryNode.create(SpecialMethodNames.T___CEIL__));
}
}
@@ -401,7 +399,7 @@ abstract static class CeilNode extends ForeignUnaryNode {
@GenerateNodeFactory
abstract static class FloorNode extends ForeignUnaryNode {
FloorNode() {
- super(UnaryArithmetic.GenericUnaryArithmeticNode.create(SpecialMethodNames.T___FLOOR__));
+ super(LookupAndCallUnaryNode.create(SpecialMethodNames.T___FLOOR__));
}
}
@@ -409,23 +407,33 @@ abstract static class FloorNode extends ForeignUnaryNode {
@GenerateNodeFactory
abstract static class TruncNode extends ForeignUnaryNode {
TruncNode() {
- super(UnaryArithmetic.GenericUnaryArithmeticNode.create(SpecialMethodNames.T___TRUNC__));
+ super(LookupAndCallUnaryNode.create(SpecialMethodNames.T___TRUNC__));
}
}
@Slot(value = SlotKind.nb_int, isComplex = true)
@GenerateNodeFactory
- abstract static class IntNode extends ForeignUnaryNode {
- IntNode() {
- super(UnaryArithmetic.GenericUnaryArithmeticNode.create(SpecialMethodNames.T___INT__));
+ abstract static class IntNode extends PythonUnaryBuiltinNode {
+ @Specialization
+ Object doGeneric(VirtualFrame frame, Object self,
+ @Bind("this") Node inliningTarget,
+ @Cached UnboxNode unboxNode,
+ @Cached PyNumberLongNode longNode) {
+ Object unboxed = unboxNode.execute(inliningTarget, self);
+ return longNode.execute(frame, inliningTarget, unboxed);
}
}
@Slot(value = SlotKind.nb_float, isComplex = true)
@GenerateNodeFactory
- abstract static class FloatNode extends ForeignUnaryNode {
- FloatNode() {
- super(UnaryArithmetic.GenericUnaryArithmeticNode.create(SpecialMethodNames.T___FLOAT__));
+ abstract static class FloatNode extends PythonUnaryBuiltinNode {
+ @Specialization
+ Object doGeneric(VirtualFrame frame, Object self,
+ @Bind("this") Node inliningTarget,
+ @Cached UnboxNode unboxNode,
+ @Cached PyNumberFloatNode floatNode) {
+ Object unboxed = unboxNode.execute(inliningTarget, self);
+ return floatNode.execute(frame, inliningTarget, unboxed);
}
}
@@ -598,9 +606,15 @@ static Object doIt(VirtualFrame frame, Object v, Object w, Object z,
@Builtin(name = J___ROUND__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)
@GenerateNodeFactory
- abstract static class RoundNode extends ForeignBinaryNode {
- RoundNode() {
- super(BinaryArithmetic.GenericBinaryArithmeticNode.create(SpecialMethodSlot.Round), false);
+ abstract static class RoundNode extends PythonBinaryBuiltinNode {
+
+ @Specialization
+ Object doGeneric(VirtualFrame frame, Object self, Object n,
+ @Bind("this") Node inliningTarget,
+ @Cached UnboxNode unboxNode,
+ @Cached("create(Round)") LookupAndCallBinaryNode callRound) {
+ Object unboxed = unboxNode.execute(inliningTarget, self);
+ return callRound.executeObject(frame, unboxed, n);
}
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
index f4e552d8d0..6d7c857758 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java
@@ -61,6 +61,7 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode;
+import com.oracle.graal.python.lib.PyNumberOrNode;
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
import com.oracle.graal.python.lib.PyObjectGetItem;
import com.oracle.graal.python.lib.PyObjectGetIter;
@@ -70,8 +71,6 @@
import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -267,10 +266,10 @@ static Object classGetItem(Object cls, Object key,
@Slot(value = SlotKind.nb_or, isComplex = true)
@GenerateNodeFactory
abstract static class OrNode extends BinaryOpBuiltinNode {
- @Child BinaryOpNode orNode = BinaryArithmetic.Or.create();
@Specialization
- Object or(VirtualFrame frame, Object self, Object other) {
+ static Object or(VirtualFrame frame, Object self, Object other,
+ @Cached PyNumberOrNode orNode) {
if (self instanceof PMappingproxy) {
self = ((PMappingproxy) self).getMapping();
}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
index 92cb0e4033..f638494029 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/types/UnionTypeBuiltins.java
@@ -73,14 +73,13 @@
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode;
+import com.oracle.graal.python.lib.PyNumberOrNode;
import com.oracle.graal.python.lib.PyObjectGetAttr;
import com.oracle.graal.python.lib.PyObjectHashNode;
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.StringLiterals;
-import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
-import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -289,12 +288,12 @@ Object eq(Object self, Object other) {
@Slot(value = SlotKind.mp_subscript, isComplex = true)
@GenerateNodeFactory
abstract static class GetItemNode extends MpSubscriptBuiltinNode {
- @Child BinaryOpNode orNode = BinaryArithmetic.Or.create();
@Specialization
Object getitem(VirtualFrame frame, PUnionType self, Object item,
@Bind("this") Node inliningTarget,
- @Cached InlinedBranchProfile createProfile) {
+ @Cached InlinedBranchProfile createProfile,
+ @Cached PyNumberOrNode orNode) {
if (self.getParameters() == null) {
createProfile.enter(inliningTarget);
self.setParameters(PFactory.createTuple(PythonLanguage.get(inliningTarget), GenericTypeNodes.makeParameters(self.getArgs())));
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java
index 6b0549a2b0..e906b0a994 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
+import com.oracle.graal.python.nodes.expression.UnaryOpNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.runtime.PythonOptions;
@@ -66,7 +67,7 @@
import com.oracle.truffle.api.strings.TruffleString;
@ImportStatic(PythonOptions.class)
-public abstract class LookupAndCallUnaryNode extends Node {
+public abstract class LookupAndCallUnaryNode extends UnaryOpNode {
public abstract static class NoAttributeHandler extends PNodeWithContext {
public abstract Object execute(Object receiver);
@@ -79,6 +80,11 @@ public abstract static class NoAttributeHandler extends PNodeWithContext {
public abstract Object executeObject(VirtualFrame frame, Object receiver);
+ @Override
+ public Object execute(VirtualFrame frame, Object receiver) {
+ return executeObject(frame, receiver);
+ }
+
@NeverDefault
public static LookupAndCallUnaryNode create(TruffleString name) {
return LookupAndCallUnaryNodeGen.create(name, null);
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
deleted file mode 100644
index cc8c33b374..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.expression;
-
-import static com.oracle.graal.python.nodes.BuiltinNames.T_PRINT;
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
-
-import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
-import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
-import com.oracle.graal.python.lib.PyNumberAddNode;
-import com.oracle.graal.python.lib.PyNumberAndNode;
-import com.oracle.graal.python.lib.PyNumberDivmodNode;
-import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
-import com.oracle.graal.python.lib.PyNumberLshiftNode;
-import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
-import com.oracle.graal.python.lib.PyNumberMultiplyNode;
-import com.oracle.graal.python.lib.PyNumberOrNode;
-import com.oracle.graal.python.lib.PyNumberPowerNode;
-import com.oracle.graal.python.lib.PyNumberRemainderNode;
-import com.oracle.graal.python.lib.PyNumberRshiftNode;
-import com.oracle.graal.python.lib.PyNumberSubtractNode;
-import com.oracle.graal.python.lib.PyNumberTrueDivideNode;
-import com.oracle.graal.python.lib.PyNumberXorNode;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.SpecialMethodNames;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode.NotImplementedHandler;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.ImportStatic;
-import com.oracle.truffle.api.dsl.NeverDefault;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.profiles.BranchProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-
-@SuppressWarnings("truffle-inlining")
-public enum BinaryArithmetic {
- Add(PyNumberAddNode::create),
- Sub(PyNumberSubtractNode::create),
- Mul(PyNumberMultiplyNode::create),
- TrueDiv(PyNumberTrueDivideNode::create),
- FloorDiv(PyNumberFloorDivideNode::create),
- Mod(PyNumberRemainderNode::create),
- LShift(PyNumberLshiftNode::create),
- RShift(PyNumberRshiftNode::create),
- And(PyNumberAndNode::create),
- Or(PyNumberOrNode::create),
- Xor(PyNumberXorNode::create),
- MatMul(PyNumberMatrixMultiplyNode::create),
- Pow(PyNumberPowerNode::create),
- DivMod(PyNumberDivmodNode::create);
-
- interface CreateBinaryOp {
- BinaryOpNode create();
- }
-
- private final CreateBinaryOp create;
-
- BinaryArithmetic(CreateBinaryOp create) {
- this.create = create;
- }
-
- @NeverDefault
- public BinaryOpNode create() {
- return create.create();
- }
-
- @ImportStatic(SpecialMethodNames.class)
- public abstract static class BinaryArithmeticNode extends BinaryOpNode {
-
- static Supplier createHandler(String operator) {
- return () -> new NotImplementedHandler() {
- private final BranchProfile errorProfile = BranchProfile.create();
-
- @Override
- public Object execute(VirtualFrame frame, Object arg, Object arg2) {
- errorProfile.enter();
- throw PRaiseNode.raiseStatic(this, TypeError, getErrorMessage(arg), operator, arg, arg2);
- }
-
- @CompilerDirectives.TruffleBoundary
- private TruffleString getErrorMessage(Object arg) {
- if (operator.equals(">>") && arg instanceof PBuiltinMethod && ((PBuiltinMethod) arg).getBuiltinFunction().getName().equalsUncached(T_PRINT, TS_ENCODING)) {
- return ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P_PRINT;
- }
- return ErrorMessages.UNSUPPORTED_OPERAND_TYPES_FOR_S_P_AND_P;
- }
- };
- }
-
- }
-
- public abstract static class GenericBinaryArithmeticNode extends BinaryArithmeticNode {
-
- private final SpecialMethodSlot slot;
-
- protected GenericBinaryArithmeticNode(SpecialMethodSlot slot) {
- this.slot = slot;
- }
-
- @Specialization
- public static Object doGeneric(VirtualFrame frame, Object left, Object right,
- @Cached("createCallNode()") LookupAndCallBinaryNode callNode) {
- return callNode.executeObject(frame, left, right);
- }
-
- @NeverDefault
- protected LookupAndCallBinaryNode createCallNode() {
- return LookupAndCallBinaryNode.create(slot, createHandler(slot.getName().toString()));
- }
-
- @NeverDefault
- public static GenericBinaryArithmeticNode create(SpecialMethodSlot slot) {
- return BinaryArithmeticFactory.GenericBinaryArithmeticNodeGen.create(slot);
- }
- }
-}
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
deleted file mode 100644
index f6d45c140b..0000000000
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/UnaryArithmetic.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.oracle.graal.python.nodes.expression;
-
-import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
-
-import com.oracle.graal.python.lib.PyNumberInvertNode;
-import com.oracle.graal.python.lib.PyNumberNegativeNode;
-import com.oracle.graal.python.lib.PyNumberPositiveNode;
-import com.oracle.graal.python.nodes.ErrorMessages;
-import com.oracle.graal.python.nodes.PRaiseNode;
-import com.oracle.graal.python.nodes.SpecialMethodNames;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
-import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.NoAttributeHandler;
-import com.oracle.graal.python.util.Supplier;
-import com.oracle.truffle.api.dsl.Cached;
-import com.oracle.truffle.api.dsl.GenerateCached;
-import com.oracle.truffle.api.dsl.ImportStatic;
-import com.oracle.truffle.api.dsl.NeverDefault;
-import com.oracle.truffle.api.dsl.Specialization;
-import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.profiles.BranchProfile;
-import com.oracle.truffle.api.strings.TruffleString;
-
-public enum UnaryArithmetic {
- Pos(PyNumberPositiveNode::create),
- Neg(PyNumberNegativeNode::create),
- Invert(PyNumberInvertNode::create);
-
- interface CreateUnaryOp {
- UnaryOpNode create();
- }
-
- private final CreateUnaryOp create;
-
- UnaryArithmetic(CreateUnaryOp create) {
- this.create = create;
- }
-
- public UnaryOpNode create() {
- return create.create();
- }
-
- @ImportStatic(SpecialMethodNames.class)
- public abstract static class UnaryArithmeticNode extends UnaryOpNode {
-
- static Supplier createHandler(String operator) {
-
- return () -> new NoAttributeHandler() {
- private final BranchProfile errorProfile = BranchProfile.create();
-
- @Override
- public Object execute(Object receiver) {
- errorProfile.enter();
- throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.BAD_OPERAND_FOR, "unary ", operator, receiver);
- }
- };
- }
-
- @NeverDefault
- public static LookupAndCallUnaryNode createCallNode(TruffleString name, Supplier handler) {
- return LookupAndCallUnaryNode.create(name, handler);
- }
- }
-
- @GenerateCached
- public abstract static class GenericUnaryArithmeticNode extends UnaryArithmeticNode {
-
- private final TruffleString specialMethodName;
-
- protected GenericUnaryArithmeticNode(TruffleString specialMethodName) {
- this.specialMethodName = specialMethodName;
- }
-
- @Specialization
- public static Object doGeneric(VirtualFrame frame, Object arg,
- @Cached("createCallNode()") LookupAndCallUnaryNode callNode) {
- return callNode.executeObject(frame, arg);
- }
-
- @NeverDefault
- protected LookupAndCallUnaryNode createCallNode() {
- return createCallNode(specialMethodName, createHandler(specialMethodName.toString()));
- }
-
- @NeverDefault
- public static GenericUnaryArithmeticNode create(TruffleString specialMethodName) {
- return UnaryArithmeticFactory.GenericUnaryArithmeticNodeGen.create(specialMethodName);
- }
- }
-}
From a9632e4ef2a22408a2d1676cde8377faf4f03ad3 Mon Sep 17 00:00:00 2001
From: Michael Simacek
Date: Thu, 20 Feb 2025 14:36:56 +0100
Subject: [PATCH 042/512] Try to avoid upcalls for numeric ops on managed
objects
---
.../src/abstract.c | 59 +++++-
.../com.oracle.graal.python.cext/src/call.c | 4 +-
.../cext/PythonCextAbstractBuiltins.java | 192 ++++++------------
.../objects/cext/capi/CApiFunction.java | 33 +++
4 files changed, 150 insertions(+), 138 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.cext/src/abstract.c b/graalpython/com.oracle.graal.python.cext/src/abstract.c
index 2437c8433f..f121109d7e 100644
--- a/graalpython/com.oracle.graal.python.cext/src/abstract.c
+++ b/graalpython/com.oracle.graal.python.cext/src/abstract.c
@@ -7,8 +7,8 @@
#include "Python.h"
#include "capi.h" // GraalPy change
-#if 0 // GraalPy change
#include "pycore_abstract.h" // _PyIndex_Check()
+#if 0 // GraalPy change
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_object.h" // _Py_CheckSlotResult()
@@ -844,6 +844,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
Py_XDECREF(empty);
return result;
}
+#endif // GraalPy
/* Operations on numbers */
int
@@ -854,7 +855,6 @@ PyNumber_Check(PyObject *o)
PyNumberMethods *nb = Py_TYPE(o)->tp_as_number;
return nb && (nb->nb_index || nb->nb_int || nb->nb_float || PyComplex_Check(o));
}
-#endif // GraalPy
/* Binary operators */
@@ -1072,13 +1072,16 @@ ternary_op(PyObject *v,
return NULL;
}
+// GraalPy change: upcall when both managed to save on doing multiple upcalls
#define BINARY_FUNC(func, op, op_name) \
PyObject * \
func(PyObject *v, PyObject *w) { \
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) { \
+ return GraalPyTruffle##func(v, w); \
+ } \
return binary_op(v, w, NB_SLOT(op), op_name); \
}
-#if 0 // GraalPy
BINARY_FUNC(PyNumber_Or, nb_or, "|")
BINARY_FUNC(PyNumber_Xor, nb_xor, "^")
BINARY_FUNC(PyNumber_And, nb_and, "&")
@@ -1090,6 +1093,10 @@ BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
PyObject *
PyNumber_Add(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_Add(v, w);
+ }
PyObject *result = BINARY_OP1(v, w, NB_SLOT(nb_add), "+");
if (result != Py_NotImplemented) {
return result;
@@ -1128,6 +1135,10 @@ sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
PyObject *
PyNumber_Multiply(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_Multiply(v, w);
+ }
PyObject *result = BINARY_OP1(v, w, NB_SLOT(nb_multiply), "*");
if (result == Py_NotImplemented) {
PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence;
@@ -1147,30 +1158,50 @@ PyNumber_Multiply(PyObject *v, PyObject *w)
PyObject *
PyNumber_MatrixMultiply(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_MatrixMultiply(v, w);
+ }
return binary_op(v, w, NB_SLOT(nb_matrix_multiply), "@");
}
PyObject *
PyNumber_FloorDivide(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_FloorDivide(v, w);
+ }
return binary_op(v, w, NB_SLOT(nb_floor_divide), "//");
}
PyObject *
PyNumber_TrueDivide(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_TrueDivide(v, w);
+ }
return binary_op(v, w, NB_SLOT(nb_true_divide), "/");
}
PyObject *
PyNumber_Remainder(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_Remainder(v, w);
+ }
return binary_op(v, w, NB_SLOT(nb_remainder), "%");
}
PyObject *
PyNumber_Power(PyObject *v, PyObject *w, PyObject *z)
{
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) {
+ return GraalPyTrufflePyNumber_Power(v, w, z);
+ }
return ternary_op(v, w, z, NB_SLOT(nb_power), "** or pow()");
}
@@ -1258,9 +1289,13 @@ ternary_iop(PyObject *v, PyObject *w, PyObject *z, const int iop_slot, const int
return ternary_op(v, w, z, op_slot, op_name);
}
+// GraalPy change: upcall when v is managed to avoid multiple upcalls
#define INPLACE_BINOP(func, iop, op, op_name) \
PyObject * \
func(PyObject *v, PyObject *w) { \
+ if (points_to_py_handle_space(v)) { \
+ return GraalPyTruffle##func(v, w); \
+ } \
return binary_iop(v, w, NB_SLOT(iop), NB_SLOT(op), op_name); \
}
@@ -1278,6 +1313,10 @@ INPLACE_BINOP(PyNumber_InPlaceRemainder, nb_inplace_remainder, nb_remainder, "%=
PyObject *
PyNumber_InPlaceAdd(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
+ if (points_to_py_handle_space(v)) {
+ return GraalPyTrufflePyNumber_InPlaceAdd(v, w);
+ }
PyObject *result = BINARY_IOP1(v, w, NB_SLOT(nb_inplace_add),
NB_SLOT(nb_add), "+=");
if (result == Py_NotImplemented) {
@@ -1301,6 +1340,10 @@ PyNumber_InPlaceAdd(PyObject *v, PyObject *w)
PyObject *
PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
{
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
+ if (points_to_py_handle_space(v)) {
+ return GraalPyTrufflePyNumber_InPlaceMultiply(v, w);
+ }
PyObject *result = BINARY_IOP1(v, w, NB_SLOT(nb_inplace_multiply),
NB_SLOT(nb_multiply), "*=");
if (result == Py_NotImplemented) {
@@ -1330,6 +1373,10 @@ PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
PyObject *
PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z)
{
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
+ if (points_to_py_handle_space(v)) {
+ return GraalPyTrufflePyNumber_InPlacePower(v, w, z);
+ }
return ternary_iop(v, w, z, NB_SLOT(nb_inplace_power),
NB_SLOT(nb_power), "**=");
}
@@ -1340,7 +1387,6 @@ _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs)
return PyNumber_InPlacePower(lhs, rhs, Py_None);
}
-
/* Unary operators and functions */
PyObject *
@@ -1419,6 +1465,7 @@ PyIndex_Check(PyObject *obj)
}
+#if 0 // GraalPy change
/* Return a Python int from the object item.
Can return an instance of int subclass.
Raise TypeError if the result is not an int
@@ -3027,6 +3074,6 @@ PyTruffleSequence_Fast_ITEMS(PyObject *o)
PyObject*
PyTruffleSequence_ITEM(PyObject* obj, Py_ssize_t index)
{
- PySequenceMethods* methods = Py_TYPE(obj)->tp_as_sequence;
- return methods->sq_item(obj, index);
+ PySequenceMethods* methods = Py_TYPE(obj)->tp_as_sequence;
+ return methods->sq_item(obj, index);
}
diff --git a/graalpython/com.oracle.graal.python.cext/src/call.c b/graalpython/com.oracle.graal.python.cext/src/call.c
index edcdbe0aa0..bd837d6827 100644
--- a/graalpython/com.oracle.graal.python.cext/src/call.c
+++ b/graalpython/com.oracle.graal.python.cext/src/call.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
+/* Copyright (c) 2023, 2025, Oracle and/or its affiliates.
* Copyright (C) 1996-2022 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -87,7 +87,6 @@ _Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
}
-#if 0 // GraalPy change
int
_Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
{
@@ -110,7 +109,6 @@ _Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
}
return 1;
}
-#endif // GraalPy change
/* --- Core PyObject call functions ------------------------------- */
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
index 013bafe4d5..c06e057308 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java
@@ -64,9 +64,7 @@
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.TupleNode;
-import com.oracle.graal.python.builtins.modules.BuiltinFunctions.AbsNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.BinNode;
-import com.oracle.graal.python.builtins.modules.BuiltinFunctions.DivModNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.HexNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.NextNode;
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.OctNode;
@@ -98,11 +96,10 @@
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.CallSlotMpAssSubscriptNode;
import com.oracle.graal.python.lib.GetNextNode;
-import com.oracle.graal.python.lib.PyIndexCheckNode;
import com.oracle.graal.python.lib.PyIterCheckNode;
import com.oracle.graal.python.lib.PyNumberAddNode;
import com.oracle.graal.python.lib.PyNumberAndNode;
-import com.oracle.graal.python.lib.PyNumberCheckNode;
+import com.oracle.graal.python.lib.PyNumberDivmodNode;
import com.oracle.graal.python.lib.PyNumberFloatNode;
import com.oracle.graal.python.lib.PyNumberFloorDivideNode;
import com.oracle.graal.python.lib.PyNumberInPlaceAddNode;
@@ -119,14 +116,11 @@
import com.oracle.graal.python.lib.PyNumberInPlaceTrueDivideNode;
import com.oracle.graal.python.lib.PyNumberInPlaceXorNode;
import com.oracle.graal.python.lib.PyNumberIndexNode;
-import com.oracle.graal.python.lib.PyNumberInvertNode;
import com.oracle.graal.python.lib.PyNumberLongNode;
import com.oracle.graal.python.lib.PyNumberLshiftNode;
import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode;
import com.oracle.graal.python.lib.PyNumberMultiplyNode;
-import com.oracle.graal.python.lib.PyNumberNegativeNode;
import com.oracle.graal.python.lib.PyNumberOrNode;
-import com.oracle.graal.python.lib.PyNumberPositiveNode;
import com.oracle.graal.python.lib.PyNumberPowerNode;
import com.oracle.graal.python.lib.PyNumberRemainderNode;
import com.oracle.graal.python.lib.PyNumberRshiftNode;
@@ -172,30 +166,8 @@
public final class PythonCextAbstractBuiltins {
- /////// PyIndex ///////
-
- @CApiBuiltin(ret = Int, args = {PyObject}, call = Direct)
- abstract static class PyIndex_Check extends CApiUnaryBuiltinNode {
- @Specialization
- static Object check(Object obj,
- @Bind("this") Node inliningTarget,
- @Cached PyIndexCheckNode checkNode) {
- return checkNode.execute(inliningTarget, obj) ? 1 : 0;
- }
- }
-
/////// PyNumber ///////
- @CApiBuiltin(ret = Int, args = {PyObject}, call = Direct)
- abstract static class PyNumber_Check extends CApiUnaryBuiltinNode {
- @Specialization
- static Object check(Object obj,
- @Bind("this") Node inliningTarget,
- @Cached PyNumberCheckNode checkNode) {
- return PInt.intValue(checkNode.execute(inliningTarget, obj));
- }
- }
-
@CApiBuiltin(name = "_PyNumber_Index", ret = PyObjectTransfer, args = {PyObject}, call = Direct)
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
abstract static class PyNumber_Index extends CApiUnaryBuiltinNode {
@@ -220,24 +192,6 @@ static Object nlong(Object object,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
- abstract static class PyNumber_Absolute extends CApiUnaryBuiltinNode {
- @Specialization
- static Object abs(Object obj,
- @Cached AbsNode absNode) {
- return absNode.execute(null, obj);
- }
- }
-
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Divmod extends CApiBinaryBuiltinNode {
- @Specialization
- static Object div(Object a, Object b,
- @Cached DivModNode divNode) {
- return divNode.execute(null, a, b);
- }
- }
-
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, Int}, call = Direct)
abstract static class PyNumber_ToBase extends CApiBinaryBuiltinNode {
@Specialization(guards = "base == 2")
@@ -307,38 +261,8 @@ static Object doGeneric(Object object,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
- abstract static class PyNumber_Positive extends CApiUnaryBuiltinNode {
-
- @Specialization
- static Object doGeneric(Object obj,
- @Cached PyNumberPositiveNode positiveNode) {
- return positiveNode.execute(null, obj);
- }
- }
-
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
- abstract static class PyNumber_Negative extends CApiUnaryBuiltinNode {
-
- @Specialization
- static Object doGeneric(Object obj,
- @Cached PyNumberNegativeNode negativeNode) {
- return negativeNode.execute(null, obj);
- }
- }
-
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Direct)
- abstract static class PyNumber_Invert extends CApiUnaryBuiltinNode {
-
- @Specialization
- static Object doGeneric(Object obj,
- @Cached PyNumberInvertNode invertNode) {
- return invertNode.execute(null, obj);
- }
- }
-
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Add extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Add extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -348,8 +272,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Subtract extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Subtract extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -358,8 +282,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Multiply extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Multiply extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -369,8 +293,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Remainder extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Remainder extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -379,8 +303,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_TrueDivide extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_TrueDivide extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -389,8 +313,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_FloorDivide extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_FloorDivide extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -399,8 +323,18 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_And extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Divmod extends CApiBinaryBuiltinNode {
+ @Specialization
+ static Object div(Object a, Object b,
+ @Bind Node inliningTarget,
+ @Cached PyNumberDivmodNode divmodNode) {
+ return divmodNode.execute(null, inliningTarget, a, b);
+ }
+ }
+
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_And extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -409,8 +343,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Or extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Or extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -419,8 +353,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Xor extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Xor extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -429,8 +363,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Lshift extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Lshift extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -439,8 +373,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Rshift extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Rshift extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -449,8 +383,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_MatrixMultiply extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_MatrixMultiply extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -459,8 +393,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceAdd extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceAdd extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -469,8 +403,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceSubtract extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceSubtract extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -479,8 +413,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceMultiply extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceMultiply extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -489,8 +423,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceRemainder extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceRemainder extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -499,8 +433,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceTrueDivide extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceTrueDivide extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -509,8 +443,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceFloorDivide extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceFloorDivide extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -519,8 +453,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceAnd extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceAnd extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -529,8 +463,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceOr extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceOr extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -539,8 +473,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceXor extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceXor extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -549,8 +483,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceLshift extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceLshift extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -559,8 +493,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceRshift extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceRshift extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -569,8 +503,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlaceMatrixMultiply extends CApiBinaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlaceMatrixMultiply extends CApiBinaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2,
@@ -579,8 +513,8 @@ static Object doGeneric(Object o1, Object o2,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_InPlacePower extends CApiTernaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_InPlacePower extends CApiTernaryBuiltinNode {
@Specialization
static Object doGeneric(Object o1, Object o2, Object o3,
@@ -589,8 +523,8 @@ static Object doGeneric(Object o1, Object o2, Object o3,
}
}
- @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Direct)
- abstract static class PyNumber_Power extends CApiTernaryBuiltinNode {
+ @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject}, call = Ignored)
+ abstract static class PyTrufflePyNumber_Power extends CApiTernaryBuiltinNode {
@Specialization
Object doGeneric(Object o1, Object o2, Object o3,
diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
index 0e07fa832d..d71eb1b0f9 100644
--- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
+++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java
@@ -296,6 +296,7 @@ public final class CApiFunction {
@CApiBuiltin(name = "PyImport_AddModule", ret = PyObject, args = {ConstCharPtrAsTruffleString}, call = CImpl)
@CApiBuiltin(name = "PyImport_AddModuleObject", ret = PyObject, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyImport_ImportModuleLevel", ret = PyObject, args = {ConstCharPtrAsTruffleString, PyObject, PyObject, PyObject, Int}, call = CImpl)
+ @CApiBuiltin(name = "PyIndex_Check", ret = Int, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyInstanceMethod_Function", ret = PyObject, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyInterpreterState_GetDict", ret = PyObject, args = {PyInterpreterState}, call = CImpl)
@CApiBuiltin(name = "PyInterpreterState_GetID", ret = INT64_T, args = {PyInterpreterState}, call = CImpl)
@@ -349,7 +350,39 @@ public final class CApiFunction {
@CApiBuiltin(name = "PyModule_GetDict", ret = PyObject, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyModule_GetName", ret = ConstCharPtrAsTruffleString, args = {PyObject}, call = CImpl)
@CApiBuiltin(name = "PyModule_GetState", ret = Pointer, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Absolute", ret = PyObject, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Add", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_And", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
@CApiBuiltin(name = "PyNumber_AsSsize_t", ret = Py_ssize_t, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Check", ret = Int, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Divmod", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_FloorDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceAdd", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceAnd", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceFloorDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceLshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceMatrixMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceOr", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlacePower", ret = PyObject, args = {PyObject, PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceRemainder", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceRshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceSubtract", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceTrueDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_InPlaceXor", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Invert", ret = PyObject, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Lshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_MatrixMultiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Multiply", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Negative", ret = PyObject, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Or", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Positive", ret = PyObject, args = {PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Power", ret = PyObject, args = {PyObject, PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Remainder", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Rshift", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Subtract", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_TrueDivide", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
+ @CApiBuiltin(name = "PyNumber_Xor", ret = PyObject, args = {PyObject, PyObject}, call = CImpl)
@CApiBuiltin(name = "PyOS_double_to_string", ret = CHAR_PTR, args = {Double, CHAR, Int, Int, INT_LIST}, call = CImpl)
@CApiBuiltin(name = "PyOS_mystricmp", ret = Int, args = {ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString}, call = CImpl)
@CApiBuiltin(name = "PyOS_mystrnicmp", ret = Int, args = {ConstCharPtrAsTruffleString, ConstCharPtrAsTruffleString, Py_ssize_t}, call = CImpl)
From 44cf93171490efc87197a37acf8089115752d866 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Mon, 30 Dec 2024 11:53:31 +0100
Subject: [PATCH 043/512] made VFSUtils.delete private
---
.../src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index 46637889eb..a3b9ec66ab 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -186,7 +186,7 @@ public interface Log {
void info(String s);
}
- public static void delete(Path dir) throws IOException {
+ private static void delete(Path dir) throws IOException {
if (!Files.exists(dir)) {
return;
}
From 5ff17063e3160c6fd1d27a280db3f402daa8da1c Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Fri, 3 Jan 2025 15:01:09 +0100
Subject: [PATCH 044/512] merged VFSUtil.Log and SubprocessLog
---
.../cext/test/MultiContextCExtTest.java | 16 ++--
.../maven/plugin/ManageResourcesMojo.java | 2 +-
.../python/maven/plugin/MavenDelegateLog.java | 10 +--
.../embedding/tools/exec/BuildToolLog.java | 45 ++++++++++
.../embedding/tools/exec/GraalPyRunner.java | 24 ++---
.../embedding/tools/exec/SubprocessLog.java | 87 -------------------
.../python/embedding/tools/vfs/VFSUtils.java | 41 ++++-----
.../java/org/graalvm/python/GradleLogger.java | 8 +-
.../graalvm/python/tasks/ResourcesTask.java | 2 +-
.../python/jbang/JBangIntegration.java | 9 +-
10 files changed, 97 insertions(+), 147 deletions(-)
create mode 100644 graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
delete mode 100644 graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/SubprocessLog.java
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
index 86165c3fa0..56b8a0c3cb 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
@@ -61,13 +61,12 @@
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
-import org.graalvm.python.embedding.tools.vfs.VFSUtils.Log;
import org.junit.Test;
public class MultiContextCExtTest {
- static final class TestLog extends Handler implements SubprocessLog, Log {
+ static final class TestLog extends Handler implements BuildToolLog {
final StringBuilder logCharSequence = new StringBuilder();
final StringBuilder logThrowable = new StringBuilder();
final StringBuilder stderr = new StringBuilder();
@@ -81,13 +80,8 @@ static void println(CharSequence... args) {
}
}
- public void log(CharSequence txt) {
- println("[log]", txt);
- logCharSequence.append(txt);
- }
-
- public void log(CharSequence txt, Throwable t) {
- println("[log]", txt);
+ public void warning(CharSequence txt, Throwable t) {
+ println("[warning]", txt);
println("[throwable]", t.getMessage());
logThrowable.append(txt).append(t.getMessage());
}
@@ -128,7 +122,7 @@ private static Path createVenv(TestLog log, String... packages) throws IOExcepti
deleteDirOnShutdown(tmpdir);
var venvdir = tmpdir.resolve("venv");
try {
- VFSUtils.createVenv(venvdir, Arrays.asList(packages), tmpdir.resolve("graalpy.exe"), () -> getClasspath(), "", log, log);
+ VFSUtils.createVenv(venvdir, Arrays.asList(packages), tmpdir.resolve("graalpy.exe"), () -> getClasspath(), "", log);
} catch (RuntimeException e) {
System.err.println(getClasspath());
throw e;
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
index d81b78b861..51868cbf9b 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
@@ -230,7 +230,7 @@ private void manageVenv() throws MojoExecutionException {
return;
}
- VFSUtils.createVenv(venvDirectory, new ArrayList(packages), getLauncherPath(), () -> calculateLauncherClasspath(project), getGraalPyVersion(project), new MavenDelegateLog(getLog()), (s) -> getLog().info(s));
+ VFSUtils.createVenv(venvDirectory, new ArrayList(packages), getLauncherPath(), () -> calculateLauncherClasspath(project), getGraalPyVersion(project), new MavenDelegateLog(getLog()));
} catch (IOException e) {
throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
}
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
index 139f7b13fa..9fdb21178a 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
@@ -41,20 +41,20 @@
package org.graalvm.python.maven.plugin;
import org.apache.maven.plugin.logging.Log;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
-final class MavenDelegateLog implements SubprocessLog {
+final class MavenDelegateLog implements BuildToolLog {
private final Log delegate;
MavenDelegateLog(Log delegate) {
this.delegate = delegate;
}
- public void log(CharSequence var1) {
+ public void info(String var1) {
delegate.info(var1);
}
- public void log(CharSequence var1, Throwable t) {
- delegate.error(var1, t);
+ public void warning(String var1, Throwable t) {
+ delegate.warn(var1, t);
}
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
new file mode 100644
index 0000000000..877a9c09f3
--- /dev/null
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
@@ -0,0 +1,45 @@
+package org.graalvm.python.embedding.tools.exec;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public interface BuildToolLog {
+ default void subProcessOut(CharSequence out) {
+ System.out.println(out);
+ }
+
+ default void subProcessErr(CharSequence err) {
+ System.err.println(err);
+ }
+
+ default void info(String s) {
+ System.out.println(s);
+ };
+
+ default void warning(String s) {
+ System.out.println(s);
+ }
+
+ default void warning(String s, Throwable t) {
+ System.out.println(s);
+ t.printStackTrace();
+ }
+
+ final class CollectOutputLog implements BuildToolLog {
+ private final List output = new ArrayList<>();
+
+ public List getOutput() {
+ return output;
+ }
+
+ @Override
+ public void subProcessOut(CharSequence var1) {
+ output.add(var1.toString());
+ }
+
+ @Override
+ public void subProcessErr(CharSequence var1) {
+ System.err.println(var1);
+ }
+ }
+}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
index f9bef8a7b3..4e0af653a4 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
@@ -60,11 +60,11 @@ public class GraalPyRunner {
private static final String BIN_DIR = IS_WINDOWS ? "Scripts" : "bin";
private static final String EXE_SUFFIX = IS_WINDOWS ? ".exe" : "";
- public static void run(Set classpath, SubprocessLog log, String... args) throws IOException, InterruptedException {
+ public static void run(Set classpath, BuildToolLog log, String... args) throws IOException, InterruptedException {
run(String.join(File.pathSeparator, classpath), log, args);
}
- public static void run(String classpath, SubprocessLog log, String... args) throws IOException, InterruptedException {
+ public static void run(String classpath, BuildToolLog log, String... args) throws IOException, InterruptedException {
String workdir = System.getProperty("exec.workingdir");
Path java = Paths.get(System.getProperty("java.home"), "bin", "java");
List cmd = new ArrayList<>();
@@ -77,20 +77,20 @@ public static void run(String classpath, SubprocessLog log, String... args) thro
if (workdir != null) {
pb.directory(new File(workdir));
}
- log.log(String.format("Running GraalPy: %s", String.join(" ", cmd)));
+ log.info(String.format("Running GraalPy: %s", String.join(" ", cmd)));
runProcess(pb, log);
}
- public static void runLauncher(String launcherPath, SubprocessLog log, String... args) throws IOException, InterruptedException {
+ public static void runLauncher(String launcherPath, BuildToolLog log, String... args) throws IOException, InterruptedException {
var cmd = new ArrayList();
cmd.add(launcherPath);
cmd.addAll(List.of(args));
- log.log(String.format("Running: %s", String.join(" ", cmd)));
+ log.info(String.format("Running: %s", String.join(" ", cmd)));
var pb = new ProcessBuilder(cmd);
runProcess(pb, log);
}
- public static void runPip(Path venvDirectory, String command, SubprocessLog log, String... args) throws IOException, InterruptedException {
+ public static void runPip(Path venvDirectory, String command, BuildToolLog log, String... args) throws IOException, InterruptedException {
var newArgs = new ArrayList();
newArgs.add("-m");
newArgs.add("pip");
@@ -101,15 +101,15 @@ public static void runPip(Path venvDirectory, String command, SubprocessLog log,
runVenvBin(venvDirectory, "graalpy", log, newArgs);
}
- public static void runVenvBin(Path venvDirectory, String command, SubprocessLog log, String... args) throws IOException, InterruptedException {
+ public static void runVenvBin(Path venvDirectory, String command, BuildToolLog log, String... args) throws IOException, InterruptedException {
runVenvBin(venvDirectory, command, log, List.of(args));
}
- private static void runVenvBin(Path venvDirectory, String command, SubprocessLog log, List args) throws IOException, InterruptedException {
+ private static void runVenvBin(Path venvDirectory, String command, BuildToolLog log, List args) throws IOException, InterruptedException {
var cmd = new ArrayList();
cmd.add(venvDirectory.resolve(BIN_DIR).resolve(command + EXE_SUFFIX).toString());
cmd.addAll(args);
- log.log(String.join(" ", cmd));
+ log.info(String.join(" ", cmd));
var pb = new ProcessBuilder(cmd);
runProcess(pb, log);
}
@@ -139,7 +139,7 @@ private static String fixProtocol(String proxyAddress, String protocol) {
return proxyAddress.startsWith(protocol) ? proxyAddress : protocol + "://" + proxyAddress;
}
- private static void runProcess(ProcessBuilder pb, SubprocessLog log) throws IOException, InterruptedException {
+ private static void runProcess(ProcessBuilder pb, BuildToolLog log) throws IOException, InterruptedException {
pb.redirectError();
pb.redirectOutput();
Process process = pb.start();
@@ -152,7 +152,7 @@ private static void runProcess(ProcessBuilder pb, SubprocessLog log) throws IOEx
} catch (IOException e) {
// Do nothing for now. Probably is not good idea to stop the
// execution at this moment
- log.log("exception while reading subprocess out", e);
+ log.warning("exception while reading subprocess out", e);
}
});
outputReader.start();
@@ -167,7 +167,7 @@ private static void runProcess(ProcessBuilder pb, SubprocessLog log) throws IOEx
} catch (IOException e) {
// Do nothing for now. Probably is not good idea to stop the
// execution at this moment
- log.log("exception while reading subprocess err", e);
+ log.warning("exception while reading subprocess err", e);
}
});
errorReader.start();
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/SubprocessLog.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/SubprocessLog.java
deleted file mode 100644
index 1bedf4d2a9..0000000000
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/SubprocessLog.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * The Universal Permissive License (UPL), Version 1.0
- *
- * Subject to the condition set forth below, permission is hereby granted to any
- * person obtaining a copy of this software, associated documentation and/or
- * data (collectively the "Software"), free of charge and under any and all
- * copyright rights in the Software, and any and all patent rights owned or
- * freely licensable by each licensor hereunder covering either (i) the
- * unmodified Software as contributed to or provided by such licensor, or (ii)
- * the Larger Works (as defined below), to deal in both
- *
- * (a) the Software, and
- *
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
- * one is included with the Software each a "Larger Work" to which the Software
- * is contributed by such licensors),
- *
- * without restriction, including without limitation the rights to copy, create
- * derivative works of, display, perform, and distribute the Software and make,
- * use, sell, offer for sale, import, export, have made, and have sold the
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
- * either these or other terms.
- *
- * This license is subject to the following condition:
- *
- * The above copyright notice and either this complete permission notice or at a
- * minimum a reference to the UPL must be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package org.graalvm.python.embedding.tools.exec;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public interface SubprocessLog {
-
- default void subProcessOut(CharSequence out) {
- System.out.println(out);
- }
-
- default void subProcessErr(CharSequence err) {
- System.err.println(err);
- }
-
- default void log(CharSequence txt) {
- System.out.println(txt);
- }
-
- default void log(CharSequence txt, Throwable t) {
- System.out.println(txt);
- t.printStackTrace();
- }
-
- final class CollectOutputLog implements SubprocessLog {
- private final List output = new ArrayList<>();
-
- public List getOutput() {
- return output;
- }
-
- @Override
- public void subProcessOut(CharSequence var1) {
- output.add(var1.toString());
- }
-
- @Override
- public void subProcessErr(CharSequence var1) {
- System.err.println(var1);
- }
-
- @Override
- public void log(CharSequence var1) {
- }
- }
-
-}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index a3b9ec66ab..3224de3d9d 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -58,9 +58,9 @@
import java.util.TreeSet;
import java.util.function.Consumer;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog.CollectOutputLog;
import org.graalvm.python.embedding.tools.exec.GraalPyRunner;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog.CollectOutputLog;
public final class VFSUtils {
@@ -182,10 +182,6 @@ public interface LauncherClassPath {
Set get() throws IOException;
}
- public interface Log {
- void info(String s);
- }
-
private static void delete(Path dir) throws IOException {
if (!Files.exists(dir)) {
return;
@@ -199,12 +195,12 @@ private static void delete(Path dir) throws IOException {
}
}
- public static void createVenv(Path venvDirectory, List packages, Path launcher, LauncherClassPath launcherClassPath, String graalPyVersion, SubprocessLog subprocessLog, Log log)
+ public static void createVenv(Path venvDirectory, List packages, Path launcher, LauncherClassPath launcherClassPath, String graalPyVersion, BuildToolLog log)
throws IOException {
Path launcherPath = launcher;
String externalLauncher = System.getProperty("graalpy.vfs.venvLauncher");
if (externalLauncher == null || externalLauncher.trim().isEmpty()) {
- generateLaunchers(launcherPath, launcherClassPath, subprocessLog, log);
+ generateLaunchers(launcherPath, launcherClassPath, log);
} else {
launcherPath = Path.of(externalLauncher);
}
@@ -239,15 +235,15 @@ public static void createVenv(Path venvDirectory, List packages, Path la
if (!Files.exists(venvDirectory)) {
log.info(String.format("Creating GraalPy %s venv", graalPyVersion));
- runLauncher(launcherPath.toString(), subprocessLog, "-m", "venv", venvDirectory.toString(), "--without-pip");
- runVenvBin(venvDirectory, "graalpy", subprocessLog, "-I", "-m", "ensurepip");
+ runLauncher(launcherPath.toString(), log, "-m", "venv", venvDirectory.toString(), "--without-pip");
+ runVenvBin(venvDirectory, "graalpy", log, "-I", "-m", "ensurepip");
}
Iterable frozenPkgs = null;
if (packages != null) {
boolean needsUpdate = false;
- needsUpdate |= deleteUnwantedPackages(venvDirectory, packages, installedPackages, subprocessLog);
- needsUpdate |= installWantedPackages(venvDirectory, packages, installedPackages, subprocessLog);
+ needsUpdate |= deleteUnwantedPackages(venvDirectory, packages, installedPackages, log);
+ needsUpdate |= installWantedPackages(venvDirectory, packages, installedPackages, log);
if (needsUpdate) {
var freezeLog = new CollectOutputLog();
runPip(venvDirectory, "freeze", freezeLog, "--local");
@@ -269,7 +265,7 @@ public static void createVenv(Path venvDirectory, List packages, Path la
}
}
- private static void checkLauncher(Path venvDirectory, Path launcherPath, Log log) throws IOException {
+ private static void checkLauncher(Path venvDirectory, Path launcherPath, BuildToolLog log) throws IOException {
if (!Files.exists(launcherPath)) {
throw new IOException(String.format("Launcher file does not exist '%s'", launcherPath));
}
@@ -301,7 +297,7 @@ private static void checkLauncher(Path venvDirectory, Path launcherPath, Log log
}
}
- private static void generateLaunchers(Path laucherPath, LauncherClassPath launcherClassPath, SubprocessLog subprocessLog, Log log) throws IOException {
+ private static void generateLaunchers(Path laucherPath, LauncherClassPath launcherClassPath, BuildToolLog log) throws IOException {
if (!Files.exists(laucherPath)) {
log.info("Generating GraalPy launchers");
createParentDirectories(laucherPath);
@@ -356,7 +352,7 @@ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
}
try {
- GraalPyRunner.run(classpath, subprocessLog, tmp.getAbsolutePath());
+ GraalPyRunner.run(classpath, log, tmp.getAbsolutePath());
} catch (InterruptedException e) {
throw new IOException(String.format("failed to run Graalpy launcher"), e);
}
@@ -364,28 +360,29 @@ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
}
}
- private static boolean installWantedPackages(Path venvDirectory, List packages, List installedPackages, SubprocessLog subprocessLog) throws IOException {
+ private static boolean installWantedPackages(Path venvDirectory, List packages, List installedPackages, BuildToolLog log) throws IOException {
Set pkgsToInstall = new HashSet<>(packages);
pkgsToInstall.removeAll(installedPackages);
if (pkgsToInstall.isEmpty()) {
return false;
}
- runPip(venvDirectory, "install", subprocessLog, pkgsToInstall.toArray(new String[pkgsToInstall.size()]));
+ runPip(venvDirectory, "install", log, pkgsToInstall.toArray(new String[pkgsToInstall.size()]));
return true;
}
- private static boolean deleteUnwantedPackages(Path venvDirectory, List packages, List installedPackages, SubprocessLog subprocessLog) throws IOException {
+ private static boolean deleteUnwantedPackages(Path venvDirectory, List packages, List installedPackages, BuildToolLog log) throws IOException {
List args = new ArrayList<>(installedPackages);
args.removeAll(packages);
if (args.isEmpty()) {
return false;
}
args.add(0, "-y");
- runPip(venvDirectory, "uninstall", subprocessLog, args.toArray(new String[args.size()]));
+
+ runPip(venvDirectory, "uninstall", log, args.toArray(new String[args.size()]));
return true;
}
- private static void runLauncher(String launcherPath, SubprocessLog log, String... args) throws IOException {
+ private static void runLauncher(String launcherPath, BuildToolLog log, String... args) throws IOException {
try {
GraalPyRunner.runLauncher(launcherPath, log, args);
} catch (IOException | InterruptedException e) {
@@ -393,7 +390,7 @@ private static void runLauncher(String launcherPath, SubprocessLog log, String..
}
}
- private static void runPip(Path venvDirectory, String command, SubprocessLog log, String... args) throws IOException {
+ private static void runPip(Path venvDirectory, String command, BuildToolLog log, String... args) throws IOException {
try {
GraalPyRunner.runPip(venvDirectory, command, log, args);
} catch (IOException | InterruptedException e) {
@@ -401,7 +398,7 @@ private static void runPip(Path venvDirectory, String command, SubprocessLog log
}
}
- private static void runVenvBin(Path venvDirectory, String bin, SubprocessLog log, String... args) throws IOException {
+ private static void runVenvBin(Path venvDirectory, String bin, BuildToolLog log, String... args) throws IOException {
try {
GraalPyRunner.runVenvBin(venvDirectory, bin, log, args);
} catch (IOException | InterruptedException e) {
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
index 1612dc9ffa..ccd03c80da 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
@@ -40,10 +40,10 @@
*/
package org.graalvm.python;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.gradle.api.logging.Logger;
-public class GradleLogger implements SubprocessLog {
+public class GradleLogger implements BuildToolLog {
private Logger logger;
private GradleLogger(Logger logger) {
@@ -61,12 +61,12 @@ public void subProcessErr(CharSequence err) {
}
@Override
- public void log(CharSequence txt) {
+ public void info(String txt) {
logger.lifecycle(txt.toString());
}
@Override
- public void log(CharSequence txt, Throwable t) {
+ public void warning(String txt, Throwable t) {
logger.lifecycle(txt.toString(), t);
}
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
index 132e3ee43b..e9721ec9ad 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
@@ -132,7 +132,7 @@ private void manageVenv() {
List packages = getPackages().getOrElse(null);
try {
VFSUtils.createVenv(getVenvDirectory(), new ArrayList(packages), getLauncherPath(), this::calculateLauncherClasspath, getPolyglotVersion().get(),
- GradleLogger.of(getLogger()), (s) -> getLogger().lifecycle(s));
+ GradleLogger.of(getLogger()));
} catch (IOException e) {
throw new GradleException(String.format("failed to create venv %s", getVenvDirectory()), e);
}
diff --git a/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java b/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
index 17822c07b3..60f71f8bbe 100644
--- a/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
+++ b/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
@@ -41,7 +41,7 @@
package org.graalvm.python.jbang;
-import org.graalvm.python.embedding.tools.exec.SubprocessLog;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
import java.io.File;
@@ -75,8 +75,9 @@ public class JBangIntegration {
private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
private static final String LAUNCHER = IS_WINDOWS ? "graalpy.exe" : "graalpy.sh";
- private static final SubprocessLog LOG = new SubprocessLog() {
+ private static final BuildToolLog BUILD_TOOL_LOG = new BuildToolLog() {
};
+
private static final String JBANG_COORDINATES = "org.graalvm.python:jbang:jar";
/**
@@ -170,7 +171,7 @@ private static void handleVenv(Path venv, List> dependen
// perhaps already checked by jbang
throw new IllegalStateException("could not resolve parent for venv path: " + venv);
}
- VFSUtils.createVenv(venv, pkgs, getLauncherPath(venvParent.toString()), () -> calculateClasspath(dependencies), graalPyVersion, LOG, (txt) -> LOG.log(txt));
+ VFSUtils.createVenv(venv, pkgs, getLauncherPath(venvParent.toString()), () -> calculateClasspath(dependencies), graalPyVersion, BUILD_TOOL_LOG);
if (dropPip) {
try {
@@ -234,6 +235,6 @@ private static HashSet calculateClasspath(List>
}
private static void log(String txt) {
- LOG.log("[graalpy jbang integration] " + txt);
+ BUILD_TOOL_LOG.info("[graalpy jbang integration] " + txt);
}
}
From d88dec55c7e3e79c2cd2f07fff7d9c5deeae43ad Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Thu, 16 Jan 2025 11:12:28 +0100
Subject: [PATCH 045/512] fixed VirtualFileSystemTest to run also on windows
---
.../embedding/test/VirtualFileSystemTest.java | 218 +++++++++++-------
1 file changed, 135 insertions(+), 83 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
index b4b4fc19a9..c7189d6269 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
@@ -171,7 +171,9 @@ public void toRealPath() throws Exception {
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
assertTrue(Files.isSameFile(realFSPath, fs.toRealPath(realFSPath)));
withCWD(fs, realFSDir, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.getParent().getFileName().toString(), "extractme")))));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.toString())))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.toString())))));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.toRealPath(realFSPath), "expected error for no host io fs");
}
@@ -227,8 +229,10 @@ public void toAbsolutePath() throws Exception {
// absolute path starting with VFS, pointing to real FS
// /VFS_ROOT/../real/fs/path/
- p = Path.of(VFS_MOUNT_POINT, "..", realFSPath.toString());
- assertEquals(p, fs.toAbsolutePath(p));
+ if (!IS_WINDOWS) {
+ p = Path.of(VFS_MOUNT_POINT, "..", realFSPath.toString());
+ assertEquals(p, fs.toAbsolutePath(p));
+ }
// absolute path starting with real FS, pointing to VFS
// /real/fs/path/../../../VFS_MOUNT_POINT
@@ -242,9 +246,11 @@ public void toAbsolutePath() throws Exception {
// no CWD set, so relative path starting in real FS, pointing to VFS
// ../../../VFS_ROOT
Path cwd = Path.of(".").toAbsolutePath();
- p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME));
- assertTrue(p.isAbsolute());
- assertEquals(VFS_ROOT_PATH, p.normalize());
+ if (!IS_WINDOWS) {
+ p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME));
+ assertTrue(p.isAbsolute());
+ assertEquals(VFS_ROOT_PATH, p.normalize());
+ }
// ../../../VFS_ROOT/../real/fs/path
p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME, "..", realFSPath.toString()));
@@ -253,11 +259,13 @@ public void toAbsolutePath() throws Exception {
// CWD is VFS_ROOT, relative path pointing to real FS
// ../real/fs/path
- withCWD(fs, VFS_ROOT_PATH, (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("..", realFSPath.toString()));
- assertTrue(pp.isAbsolute());
- assertEquals(realFSPath, pp.normalize());
- });
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("..", realFSPath.toString()));
+ assertTrue(pp.isAbsolute());
+ assertEquals(realFSPath, pp.normalize());
+ });
+ }
// CWD is VFS_ROOT, relative path pointing through real FS back to VFS
// ../some/path/../../VFS_ROOT_PATH
@@ -379,7 +387,9 @@ public void checkAccess() throws Exception {
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
fs.checkAccess(realFSPath, Set.of(AccessMode.READ));
withCWD(fs, realFSPath.getParent(), (fst) -> fst.checkAccess(realFSPath.getFileName(), Set.of(AccessMode.READ)));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.checkAccess(Path.of("..", realFSPath.toString()), Set.of(AccessMode.READ)));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.checkAccess(Path.of("..", realFSPath.toString()), Set.of(AccessMode.READ)));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.checkAccess(realFSPath, Set.of(AccessMode.READ)), "expected error for no host io fs");
}
@@ -440,12 +450,14 @@ public void createDirectory() throws Exception {
fs.createDirectory(newDir2.getFileName());
assertTrue(Files.exists(newDir2));
});
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> {
- Path newDir3 = newDir.getParent().resolve("newdir3");
- assertFalse(Files.exists(newDir3));
- fs.createDirectory(Path.of("..", newDir3.toString()));
- assertTrue(Files.exists(newDir3));
- });
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> {
+ Path newDir3 = newDir.getParent().resolve("newdir3");
+ assertFalse(Files.exists(newDir3));
+ fs.createDirectory(Path.of("..", newDir3.toString()));
+ assertTrue(Files.exists(newDir3));
+ });
+ }
}
@Test
@@ -479,10 +491,12 @@ public void delete() throws Exception {
withCWD(rwHostIOVFS, realFSPath.getParent(), (fs) -> rwHostIOVFS.delete(realFSPath.getFileName()));
assertFalse(Files.exists(realFSPath));
- Files.createFile(realFSPath);
- assertTrue(Files.exists(realFSPath));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.delete(Path.of("..", realFSPath.toString())));
- assertFalse(Files.exists(realFSPath));
+ if (!IS_WINDOWS) {
+ Files.createFile(realFSPath);
+ assertTrue(Files.exists(realFSPath));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.delete(Path.of("..", realFSPath.toString())));
+ assertFalse(Files.exists(realFSPath));
+ }
}
private static void deleteVFS(FileSystem fs, String pathPrefix) {
@@ -515,13 +529,17 @@ public void newByteChannel() throws Exception {
Path realFSPath = Files.createTempDirectory("graalpy.vfs.test").resolve("extractme");
Files.createFile(realFSPath);
checkException(SecurityException.class, () -> rHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE)), "cant write into a read-only host FS");
- rwHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("text".getBytes()));
+ }
assertTrue(Files.exists(realFSPath));
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
newByteChannelRealFS(fs, realFSPath, "text");
withCWD(fs, realFSPath.getParent(), (fst) -> newByteChannelRealFS(fs, realFSPath.getFileName(), "text"));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newByteChannelRealFS(fs, Path.of("..", realFSPath.toString()), "text"));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newByteChannelRealFS(fs, Path.of("..", realFSPath.toString()), "text"));
+ }
}
}
@@ -544,26 +562,28 @@ private static void newByteChannelVFS(FileSystem fs, String pathPrefix) throws I
}
private static void newByteChannelVFS(FileSystem fs, Path path, Set options) throws IOException {
- SeekableByteChannel bch = fs.newByteChannel(path, options);
- ByteBuffer buffer = ByteBuffer.allocate(1024);
- bch.read(buffer);
- String s = new String(buffer.array());
- String[] ss = s.split(System.lineSeparator());
- assertTrue(ss.length >= 2);
- assertEquals("text1", ss[0]);
- assertEquals("text2", ss[1]);
- checkException(NonWritableChannelException.class, () -> bch.write(buffer), "should not be able to write to VFS");
- checkException(NonWritableChannelException.class, () -> bch.truncate(0), "should not be able to write to VFS");
+ try (SeekableByteChannel bch = fs.newByteChannel(path, options)) {
+ ByteBuffer buffer = ByteBuffer.allocate(1024);
+ bch.read(buffer);
+ String s = new String(buffer.array());
+ String[] ss = s.split(System.lineSeparator());
+ assertTrue(ss.length >= 2);
+ assertEquals("text1", ss[0]);
+ assertEquals("text2", ss[1]);
+ checkException(NonWritableChannelException.class, () -> bch.write(buffer), "should not be able to write to VFS");
+ checkException(NonWritableChannelException.class, () -> bch.truncate(0), "should not be able to write to VFS");
+ }
}
private static void newByteChannelRealFS(FileSystem fs, Path path, String expectedText) throws IOException {
- SeekableByteChannel bch = fs.newByteChannel(path, Set.of(StandardOpenOption.READ));
- ByteBuffer buffer = ByteBuffer.allocate(expectedText.length());
- bch.read(buffer);
- String s = new String(buffer.array());
- String[] ss = s.split(System.lineSeparator());
- assertTrue(ss.length >= 1);
- assertEquals(expectedText, ss[0]);
+ try (SeekableByteChannel bch = fs.newByteChannel(path, Set.of(StandardOpenOption.READ))) {
+ ByteBuffer buffer = ByteBuffer.allocate(expectedText.length());
+ bch.read(buffer);
+ String s = new String(buffer.array());
+ String[] ss = s.split(System.lineSeparator());
+ assertTrue(ss.length >= 1);
+ assertEquals(expectedText, ss[0]);
+ }
}
private static void checkCanOnlyRead(FileSystem fs, Path path, StandardOpenOption... options) {
@@ -590,11 +610,13 @@ public void newDirectoryStream() throws Exception {
checkException(NotDirectoryException.class, () -> fs.newDirectoryStream(realFSFile, (p) -> true));
newDirectoryStreamRealFS(fs, realFSDir, realFSFile);
withCWD(fs, realFSDir.getParent(), (fst) -> newDirectoryStreamRealFS(fs, realFSDir.getFileName(), realFSFile));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
- // from real fs to VFS
- withCWD(fs, realFSDir, (fst) -> newDirectoryStreamVFS(fs, Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT).toString()));
- // from VFS to real FS
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ // from real fs to VFS
+ withCWD(fs, realFSDir, (fst) -> newDirectoryStreamVFS(fs, Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT).toString()));
+ // from VFS to real FS
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.newDirectoryStream(realFSDir, null), "expected error for no host io fs");
}
@@ -645,7 +667,9 @@ public void readAttributes() throws Exception {
for (FileSystem fs : new FileSystem[]{rHostIOVFS, rwHostIOVFS}) {
assertTrue(((FileTime) fs.readAttributes(realFSPath, "creationTime").get("creationTime")).toMillis() > 0);
withCWD(fs, realFSPath.getParent(), (fst) -> assertTrue(((FileTime) fs.readAttributes(realFSPath.getFileName(), "creationTime").get("creationTime")).toMillis() > 0));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(((FileTime) fs.readAttributes(Path.of("..", realFSPath.toString()), "creationTime").get("creationTime")).toMillis() > 0));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(((FileTime) fs.readAttributes(Path.of("..", realFSPath.toString()), "creationTime").get("creationTime")).toMillis() > 0));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.readAttributes(realFSPath, "creationTime"), "expected error for no host io fs");
@@ -822,8 +846,10 @@ public void getMimeType() throws Exception {
checkException(NullPointerException.class, () -> fs.getMimeType(null));
Assert.assertNull(fs.getMimeType(VFS_ROOT_PATH));
fs.getMimeType(realFSPath);
- // whatever the return value, just check it does not fail
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getMimeType(Path.of("..", realFSPath.toString())));
+ if (!IS_WINDOWS) {
+ // whatever the return value, just check it does not fail
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getMimeType(Path.of("..", realFSPath.toString())));
+ }
}
}
@@ -835,8 +861,10 @@ public void getEncoding() throws Exception {
checkException(NullPointerException.class, () -> fs.getEncoding(null));
Assert.assertNull(fs.getEncoding(VFS_ROOT_PATH));
fs.getEncoding(realFSPath);
- // whatever the return value, just check it does not fail
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getEncoding(Path.of("..", realFSPath.toString())));
+ if (!IS_WINDOWS) {
+ // whatever the return value, just check it does not fail
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getEncoding(Path.of("..", realFSPath.toString())));
+ }
}
}
@@ -853,7 +881,9 @@ public void setAttribute() throws Exception {
// just check it does not fail for real FS paths
rwHostIOVFS.setAttribute(realFSPath, "creationTime", FileTime.fromMillis(42));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.setAttribute(Path.of("..", realFSPath.toString()), "creationTime", FileTime.fromMillis(43)));
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.setAttribute(Path.of("..", realFSPath.toString()), "creationTime", FileTime.fromMillis(43)));
+ }
}
@Test
@@ -871,9 +901,13 @@ public void isSameFile() throws Exception {
assertFalse(fs.isSameFile(realFSDir, VFS_ROOT_PATH));
assertFalse(fs.isSameFile(VFS_ROOT_PATH, realFSDir));
if (fs == noHostIOVFS) {
- withCWD(fs, VFS_ROOT_PATH, (fst) -> checkException(SecurityException.class, () -> fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> checkException(SecurityException.class, () -> fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ }
} else {
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ }
withCWD(fs, realFSDir, (fst) -> assertTrue(fs.isSameFile(realFSFile1.getFileName(), realFSFile1.getFileName())));
withCWD(fs, realFSDir, (fst) -> assertFalse(fs.isSameFile(realFSFile1.getFileName(), realFSFile2.getFileName())));
}
@@ -901,8 +935,10 @@ public void createLink() throws Exception {
assertTrue(Files.exists(link));
Path link2 = realFSDir.resolve("link2");
assertFalse(Files.exists(link2));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.createLink(Path.of("..", link2.toString()), Path.of("..", realFSFile.toString())));
- assertTrue(Files.exists(link2));
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.createLink(Path.of("..", link2.toString()), Path.of("..", realFSFile.toString())));
+ assertTrue(Files.exists(link2));
+ }
checkException(SecurityException.class, () -> rHostIOVFS.createLink(realFSDir.resolve("link3"), realFSFile));
checkException(SecurityException.class, () -> noHostIOVFS.createLink(realFSDir.resolve("link4"), realFSFile));
@@ -931,10 +967,12 @@ public void createAndReadSymbolicLink() throws Exception {
rwHostIOVFS.createSymbolicLink(symlink, realFSLinkTarget);
checkSymlink(realFSDir, realFSLinkTarget, symlink);
- Files.delete(symlink);
- assertFalse(Files.exists(symlink));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.createSymbolicLink(Path.of("..", symlink.toString()), realFSLinkTarget));
- checkSymlink(realFSDir, realFSLinkTarget, symlink);
+ if (!IS_WINDOWS) {
+ Files.delete(symlink);
+ assertFalse(Files.exists(symlink));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.createSymbolicLink(Path.of("..", symlink.toString()), realFSLinkTarget));
+ checkSymlink(realFSDir, realFSLinkTarget, symlink);
+ }
}
private void checkSymlink(Path dir, Path target, Path symlink) throws Exception {
@@ -942,8 +980,10 @@ private void checkSymlink(Path dir, Path target, Path symlink) throws Exception
checkException(SecurityException.class, () -> noHostIOVFS.readSymbolicLink(symlink));
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
assertEquals(target, fs.readSymbolicLink(symlink));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of("..", symlink.toString()))));
- withCWD(fs, dir, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of(dotdot(dir.getNameCount()), "..", VFS_MOUNT_POINT, "..", symlink.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of("..", symlink.toString()))));
+ withCWD(fs, dir, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of(dotdot(dir.getNameCount()), "..", VFS_MOUNT_POINT, "..", symlink.toString()))));
+ }
}
}
@@ -986,7 +1026,9 @@ public void move() throws Exception {
checkException(SecurityException.class, () -> fs.move(VFS_ROOT_PATH.resolve("file1"), VFS_ROOT_PATH.resolve("file2")));
}
- rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("moved text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("moved text".getBytes()));
+ }
assertTrue(Files.exists(realFSSource));
assertFalse(Files.exists(realFSTarget));
rwHostIOVFS.move(realFSSource, realFSTarget);
@@ -999,12 +1041,15 @@ public void move() throws Exception {
assertTrue(Files.exists(realFSSource2));
assertFalse(Files.exists(realFSTarget2));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.move(Path.of("..", realFSSource2.toString()), Path.of("..", realFSTarget2.toString())));
- assertFalse(Files.exists(realFSSource2));
- assertTrue(Files.exists(realFSTarget2));
- newByteChannelRealFS(rwHostIOVFS, realFSSource, "moved text");
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.move(Path.of("..", realFSSource2.toString()), Path.of("..", realFSTarget2.toString())));
+ assertFalse(Files.exists(realFSSource2));
+ assertTrue(Files.exists(realFSTarget2));
+ newByteChannelRealFS(rwHostIOVFS, realFSSource, "moved text");
+ }
- checkException(IOException.class, () -> rHostIOVFS.move(realFSSource2, realFSTarget2));
+ Class> exCls = IS_WINDOWS ? SecurityException.class : IOException.class;
+ checkException(exCls, () -> rHostIOVFS.move(realFSSource2, realFSTarget2));
checkException(SecurityException.class, () -> noHostIOVFS.move(realFSSource2, realFSTarget2));
}
@@ -1028,7 +1073,9 @@ public void copy() throws Exception {
checkException(SecurityException.class, () -> noHostIOVFS.copy(realFSSource, realFSTarget));
Files.createFile(realFSSource);
- rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("copied text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("copied text".getBytes()));
+ }
assertTrue(Files.exists(realFSSource));
rwHostIOVFS.copy(realFSSource, realFSTarget);
@@ -1036,11 +1083,13 @@ public void copy() throws Exception {
assertTrue(Files.exists(realFSTarget));
newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
- Files.delete(realFSTarget);
- assertFalse(Files.exists(realFSTarget));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("..", realFSSource.toString()), Path.of("..", realFSTarget.toString())));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
+ if (!IS_WINDOWS) {
+ Files.delete(realFSTarget);
+ assertFalse(Files.exists(realFSTarget));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("..", realFSSource.toString()), Path.of("..", realFSTarget.toString())));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
+ }
Files.delete(realFSTarget);
assertFalse(Files.exists(realFSTarget));
@@ -1054,11 +1103,13 @@ public void copy() throws Exception {
assertTrue(Files.exists(realFSTarget));
newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
- Files.delete(realFSTarget);
- assertFalse(Files.exists(realFSTarget));
- withCWD(rwHostIOVFS, realFSDir, (fs) -> fs.copy(Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT, "file1"), realFSTarget));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ if (!IS_WINDOWS) {
+ Files.delete(realFSTarget);
+ assertFalse(Files.exists(realFSTarget));
+ withCWD(rwHostIOVFS, realFSDir, (fs) -> fs.copy(Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT, "file1"), realFSTarget));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ }
Files.delete(realFSTarget);
assertFalse(Files.exists(realFSTarget));
@@ -1073,10 +1124,11 @@ public void copy() throws Exception {
assertFalse(Files.exists(realFSTarget));
// no host IO
-
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("..", realFSTarget.toString())));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("..", realFSTarget.toString())));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ }
}
From 42dc7443d8008f09cacd0593fe51249984f763a3 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Thu, 16 Jan 2025 11:16:32 +0100
Subject: [PATCH 046/512] improved logging in GraalPyRunner
---
.../graalvm/python/embedding/tools/exec/GraalPyRunner.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
index 4e0af653a4..a39260e6a0 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -109,7 +109,7 @@ private static void runVenvBin(Path venvDirectory, String command, BuildToolLog
var cmd = new ArrayList();
cmd.add(venvDirectory.resolve(BIN_DIR).resolve(command + EXE_SUFFIX).toString());
cmd.addAll(args);
- log.info(String.join(" ", cmd));
+ log.info("executing: " + String.join(" ", cmd));
var pb = new ProcessBuilder(cmd);
runProcess(pb, log);
}
From 89286569567f4d9c60a733e1e716044ed4d07044 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Thu, 16 Jan 2025 11:17:33 +0100
Subject: [PATCH 047/512] more methods in BuildToolLog
---
.../python/maven/plugin/MavenDelegateLog.java | 26 +++++++--
.../embedding/tools/exec/BuildToolLog.java | 53 +++++++++++++++++++
.../java/org/graalvm/python/GradleLogger.java | 14 ++++-
3 files changed, 86 insertions(+), 7 deletions(-)
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
index 9fdb21178a..2f09c511d5 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -50,11 +50,27 @@ final class MavenDelegateLog implements BuildToolLog {
this.delegate = delegate;
}
- public void info(String var1) {
- delegate.info(var1);
+ public void info(String txt) {
+ delegate.info(txt);
}
- public void warning(String var1, Throwable t) {
- delegate.warn(var1, t);
+ public void warning(String txt) {
+ delegate.warn(txt);
+ }
+
+ public void warning(String txt, Throwable t) {
+ delegate.warn(txt, t);
+ }
+
+ public void error(String txt) {
+ delegate.error(txt);
+ }
+
+ public boolean isDebugEnabled() {
+ return delegate.isDebugEnabled();
+ }
+
+ public void debug(String txt) {
+ delegate.debug(txt);
}
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
index 877a9c09f3..e64a35d99c 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
@@ -1,3 +1,44 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
package org.graalvm.python.embedding.tools.exec;
import java.util.ArrayList;
@@ -25,6 +66,18 @@ default void warning(String s, Throwable t) {
t.printStackTrace();
}
+ default void error(String s) {
+ System.err.println(s);
+ }
+
+ default public boolean isDebugEnabled() {
+ return false;
+ }
+
+ default void debug(String s) {
+ System.out.println(s);
+ }
+
final class CollectOutputLog implements BuildToolLog {
private final List output = new ArrayList<>();
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
index ccd03c80da..dd21a8ce8d 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GradleLogger.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -67,7 +67,17 @@ public void info(String txt) {
@Override
public void warning(String txt, Throwable t) {
- logger.lifecycle(txt.toString(), t);
+ logger.warn(txt, t);
+ }
+
+ @Override
+ public void warning(String txt) {
+ logger.warn(txt);
+ }
+
+ @Override
+ public void error(String txt) {
+ logger.error(txt);
}
public static GradleLogger of(Logger logger) {
From a595a6d23d1878bbd5c561ae65301df384c94e3b Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Fri, 24 Jan 2025 15:29:27 +0100
Subject: [PATCH 048/512] minor javadoc improvement
---
.../embedding/test/integration/GraalPyResourcesUtilsTests.java | 2 +-
.../integration/VirtualFileSystemIntegrationUtilsTest.java | 2 +-
.../python/embedding/test/VirtualFileSystemUtilsTest.java | 3 ++-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/GraalPyResourcesUtilsTests.java b/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/GraalPyResourcesUtilsTests.java
index 50e91ed4b8..2402887d80 100644
--- a/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/GraalPyResourcesUtilsTests.java
+++ b/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/GraalPyResourcesUtilsTests.java
@@ -48,7 +48,7 @@
import java.nio.file.Path;
/**
- * Siple copy of GraalPyResourcesTests to test also the deprecated
+ * Simple copy of GraalPyResourcesTests to test also the deprecated
* org.graalvm.python.embedding.utils pkg
*/
@SuppressWarnings("deprecation")
diff --git a/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/VirtualFileSystemIntegrationUtilsTest.java b/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/VirtualFileSystemIntegrationUtilsTest.java
index 8033697bc0..287884b39b 100644
--- a/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/VirtualFileSystemIntegrationUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/VirtualFileSystemIntegrationUtilsTest.java
@@ -71,7 +71,7 @@
import static org.junit.Assert.assertTrue;
/**
- * Siple copy of VirtualFileSystemIntegrationTest to test also the deprecated
+ * Simple copy of VirtualFileSystemIntegrationTest to test also the deprecated
* org.graalvm.python.embedding.utils pkg
*/
@SuppressWarnings("deprecation")
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
index b662bc2b5b..d21538f877 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
@@ -90,9 +90,10 @@
import static org.junit.Assert.assertTrue;
/**
- * Siple copy of VirtualFileSystemTest to test also the deprecated
+ * Simple copy of VirtualFileSystemTest to test also the deprecated
* org.graalvm.python.embedding.utils pkg
*/
+@SuppressWarnings("deprecation")
public class VirtualFileSystemUtilsTest {
private static String MOUNT_POINT_NAME = "test_mount_point";
From fa0ddb4baf2852ce9b5af8c5601c97f21080aef5 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Fri, 24 Jan 2025 15:23:12 +0100
Subject: [PATCH 049/512] handle requirements files in VFSUtils.createVenv()
---
.../cext/test/MultiContextCExtTest.java | 79 +--
.../embedding/test/EmbeddingTestUtils.java | 111 +++
.../embedding/vfs/test/VFSUtilsTest.java | 645 ++++++++++++++++++
.../standalone/test_jbang_integration.py | 5 +-
.../maven/plugin/ManageResourcesMojo.java | 16 +-
.../embedding/tools/exec/BuildToolLog.java | 2 +-
.../python/embedding/tools/vfs/VFSUtils.java | 401 +++++++++--
.../graalvm/python/GraalPyGradlePlugin.java | 18 +-
.../graalvm/python/tasks/ResourcesTask.java | 9 +-
.../python/jbang/JBangIntegration.java | 17 +-
mx.graalpython/mx_graalpython.py | 7 +-
11 files changed, 1172 insertions(+), 138 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
create mode 100644 graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
index 56b8a0c3cb..d9472b3652 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -46,14 +46,10 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
@@ -62,9 +58,11 @@
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.graalvm.python.embedding.tools.exec.BuildToolLog;
-import org.graalvm.python.embedding.tools.vfs.VFSUtils;
import org.junit.Test;
+import static org.graalvm.python.embedding.test.EmbeddingTestUtils.deleteDirOnShutdown;
+import static org.graalvm.python.embedding.test.EmbeddingTestUtils.createVenv;
+
public class MultiContextCExtTest {
static final class TestLog extends Handler implements BuildToolLog {
final StringBuilder logCharSequence = new StringBuilder();
@@ -117,61 +115,30 @@ public void close() {
}
}
- private static Path createVenv(TestLog log, String... packages) throws IOException {
- var tmpdir = Files.createTempDirectory("graalpytest");
- deleteDirOnShutdown(tmpdir);
- var venvdir = tmpdir.resolve("venv");
- try {
- VFSUtils.createVenv(venvdir, Arrays.asList(packages), tmpdir.resolve("graalpy.exe"), () -> getClasspath(), "", log);
- } catch (RuntimeException e) {
- System.err.println(getClasspath());
- throw e;
- }
- return venvdir;
- }
-
- private static void deleteDirOnShutdown(Path tmpdir) {
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- try (var fs = Files.walk(tmpdir)) {
- fs.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
- } catch (IOException e) {
- }
- }));
- }
-
- private static Set getClasspath() {
- var sb = new ArrayList();
- var modPath = System.getProperty("jdk.module.path");
- if (modPath != null) {
- sb.add(modPath);
- }
- var classPath = System.getProperty("java.class.path");
- if (classPath != null) {
- sb.add(classPath);
- }
- var cp = String.join(File.pathSeparator, sb);
- return Set.copyOf(Arrays.stream(cp.split(File.pathSeparator)).toList());
- }
-
@Test
public void testCreatingVenvForMulticontext() throws IOException {
var log = new TestLog();
- Path venv;
+ Path tmpdir = Files.createTempDirectory("MultiContextCExtTest");
+ Path venvDir = tmpdir.resolve("venv");
+ deleteDirOnShutdown(tmpdir);
String pythonNative;
String exe;
if (System.getProperty("os.name").toLowerCase().contains("win")) {
pythonNative = "python-native.dll";
- venv = createVenv(log, "delvewheel==1.9.0");
- exe = venv.resolve("Scripts").resolve("python.exe").toString().replace('\\', '/');
+ createVenv(venvDir, "0.1", log, "delvewheel==1.9.0");
+
+ exe = venvDir.resolve("Scripts").resolve("python.exe").toString().replace('\\', '/');
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
pythonNative = "libpython-native.dylib";
- venv = createVenv(log);
- exe = venv.resolve("bin").resolve("python").toString();
+ createVenv(venvDir, "0.1", log);
+
+ exe = venvDir.resolve("bin").resolve("python").toString();
} else {
pythonNative = "libpython-native.so";
- venv = createVenv(log, "patchelf");
- exe = venv.resolve("bin").resolve("python").toString();
+ createVenv(venvDir, "0.1", log, "patchelf");
+
+ exe = venvDir.resolve("bin").resolve("python").toString();
}
var engine = Engine.newBuilder("python").logHandler(log).build();
@@ -182,11 +149,11 @@ public void testCreatingVenvForMulticontext() throws IOException {
Context c0, c1, c2, c3, c4, c5;
contexts.add(c0 = builder.build());
c0.initialize("python");
- c0.eval("python", String.format("__graalpython__.replicate_extensions_in_venv('%s', 2)", venv.toString().replace('\\', '/')));
+ c0.eval("python", String.format("__graalpython__.replicate_extensions_in_venv('%s', 2)", venvDir.toString().replace('\\', '/')));
- assertTrue("created a copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup0")));
- assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup1")));
- assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
+ assertTrue("created a copy of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup0")));
+ assertTrue("created another copy of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup1")));
+ assertFalse("created no more copies of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
builder.option("python.IsolateNativeModules", "true");
contexts.add(c1 = builder.build());
@@ -205,7 +172,7 @@ public void testCreatingVenvForMulticontext() throws IOException {
// First one works
var r1 = c1.eval(code);
assertEquals("tiny_sha3", r1.asString());
- assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
+ assertFalse("created no more copies of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
// Second one works because of isolation
var r2 = c2.eval(code);
assertEquals("tiny_sha3", r2.asString());
@@ -215,10 +182,10 @@ public void testCreatingVenvForMulticontext() throws IOException {
// first context is unaffected
r1 = c1.eval(code);
assertEquals("tiny_sha3", r1.asString());
- assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
+ assertFalse("created no more copies of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
// Third one works and triggers a dynamic relocation
c3.eval(code);
- assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
+ assertTrue("created another copy of the capi", Files.list(venvDir).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
// Fourth one does not work because we changed the sys.prefix
c4.eval("python", "import sys; sys.prefix = 12");
try {
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
new file mode 100644
index 0000000000..bb4014c785
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.graalvm.python.embedding.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Set;
+
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils.Launcher;
+
+public final class EmbeddingTestUtils {
+ private EmbeddingTestUtils() {
+ }
+
+ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, String... packages) throws IOException {
+ createVenv(venvDir, graalPyVersion, log, null, null, null, packages);
+ }
+
+ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, Path requirements, String iconsistentPackagesError, String wrongPackageVersionError, String... packages)
+ throws IOException {
+ try {
+ log.info("<<< creating test venv <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+
+ Path launcherFile = venvDir.getParent().resolve(VFSUtils.LAUNCHER_NAME);
+ Launcher launcher = new Launcher(launcherFile) {
+ public Set computeClassPath() {
+ return getClasspath();
+ };
+ };
+ if (requirements != null) {
+ VFSUtils.createVenv(venvDir, Arrays.asList(packages), requirements, iconsistentPackagesError, wrongPackageVersionError, launcher, graalPyVersion, log);
+ } else {
+ VFSUtils.createVenv(venvDir, Arrays.asList(packages), launcher, graalPyVersion, log);
+ }
+ } catch (RuntimeException e) {
+ System.err.println(getClasspath());
+ throw e;
+ } finally {
+ log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ }
+ }
+
+ public static void deleteDirOnShutdown(Path tmpdir) {
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try (var fs = Files.walk(tmpdir)) {
+ fs.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ } catch (IOException e) {
+ }
+ }));
+ }
+
+ private static Set getClasspath() {
+ var sb = new ArrayList();
+ var modPath = System.getProperty("jdk.module.path");
+ if (modPath != null) {
+ sb.add(modPath);
+ }
+ var classPath = System.getProperty("java.class.path");
+ if (classPath != null) {
+ sb.add(classPath);
+ }
+ var cp = String.join(File.pathSeparator, sb);
+ return Set.copyOf(Arrays.stream(cp.split(File.pathSeparator)).toList());
+ }
+}
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
new file mode 100644
index 0000000000..7f3249535f
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
@@ -0,0 +1,645 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.graalvm.python.embedding.vfs.test;
+
+import org.graalvm.python.embedding.test.EmbeddingTestUtils;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.graalvm.python.embedding.test.EmbeddingTestUtils.deleteDirOnShutdown;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class VFSUtilsTest {
+
+ private static final String REQUIREMENTS_HEADER = "generated by graalpy tests\nwith a two line header";
+ private static final String INCONSISTENT_PKGS_ERROR = "inconsistent package %s";
+ private static final String WRONG_PKG_VERSION_ERROR = "wrong package version %s";
+
+ private static final class TestLog implements BuildToolLog {
+ private final StringBuilder output = new StringBuilder();
+
+ private void addLine(String s) {
+ this.output.append('\n').append(s);
+ }
+
+ private void clearOutput() {
+ output.delete(0, output.length());
+ }
+
+ public void subProcessOut(CharSequence s) {
+ System.out.println(s);
+ addLine(s.toString());
+ }
+
+ public void subProcessErr(CharSequence s) {
+ System.err.println(s);
+ addLine(s.toString());
+ }
+
+ public void info(String s) {
+ System.out.println(s);
+ addLine(s);
+ };
+
+ public void warning(String s) {
+ System.out.println(s);
+ addLine(s);
+ }
+
+ public void warning(String s, Throwable t) {
+ System.out.println(s);
+ t.printStackTrace();
+ addLine(s);
+ }
+
+ public void error(String s) {
+ System.err.println(s);
+ addLine(s);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+
+ public String getOutput() {
+ return output.toString();
+ }
+ }
+
+ /**
+ * tests scenarios when packages are declared only in plugin config
+ */
+ @Test
+ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_testWithPackagesOnlyFromPluginConfig");
+ Path venvDir = tmpDir.resolve("venv");
+ deleteDirOnShutdown(tmpDir);
+
+ // test with a not existing requirements path
+ // the maven and gradle plugins always send the default requirements path, no matter if the
+ // file exists or not
+ Path requirements = tmpDir.resolve("requirements.txt");
+ Path contents = venvDir.resolve("contents");
+
+ // no packages, requirements file does not exist - does nothing
+ log.clearOutput();
+ createVenv(venvDir, "0.1", log, requirements);
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+
+ // install packages
+ log.clearOutput();
+ createVenv(venvDir, "0.1", log, requirements, "hello-world", "tiny-tiny");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
+ checkVenvContentsFile(contents, "0.1", "hello-world", "tiny-tiny");
+
+ // install packages again, assert that venv wasn't created and packages weren't installed
+ log.clearOutput();
+ createVenv(venvDir, "0.1", log, requirements, "hello-world", "tiny-tiny");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.output.toString().contains("hello-world"));
+ assertFalse(log.output.toString().contains("tiny-tiny"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
+ checkVenvContentsFile(contents, "0.1", "hello-world", "tiny-tiny");
+
+ // remove tiny-tiny, assert that venv wasn't created and only tiny-tiny was removed
+ log.clearOutput();
+ createVenv(venvDir, "0.1", log, requirements, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.output.toString().contains("hello-world"));
+ assertTrue(log.output.toString().contains("Uninstalling tiny-tiny"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+
+ // install only hello-world again, assert that venv wasn't created and packages weren't
+ // installed
+ log.clearOutput();
+ createVenv(venvDir, "0.1", log, requirements, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.output.toString().contains("hello-world"));
+ assertFalse(log.output.toString().contains("tiny-tiny"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+
+ // change version, assert that new venv created and packages installed
+ log.clearOutput();
+ createVenv(venvDir, "0.2", log, requirements, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.output.toString().contains("pip install"));
+ assertTrue(log.output.toString().contains("hello-world"));
+ assertFalse(log.output.toString().contains("tiny-tiny"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.2", "hello-world");
+ }
+
+ /**
+ * when called from jbang, which does not work with requirements file
+ */
+ @Test
+ public void testWithoutRequirementsFile() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_testWithoutRequirementsFile");
+ Path venvDir = tmpDir.resolve("venv");
+ Path contents = venvDir.resolve("contents");
+ deleteDirOnShutdown(tmpDir);
+
+ createVenv(venvDir, "0.1", log);
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ log.clearOutput();
+
+ createVenv(venvDir, "0.1", log, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+ log.clearOutput();
+
+ createVenv(venvDir, "0.1", log, "hello-world==0.1");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1");
+ log.clearOutput();
+
+ createVenv(venvDir, "0.1", log, "hello-world", "tiny-tiny");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
+ checkVenvContentsFile(contents, "0.1", "hello-world", "tiny-tiny");
+ log.clearOutput();
+
+ createVenv(venvDir, "0.1", log, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+ log.clearOutput();
+
+ // new graalPy version
+ createVenv(venvDir, "0.2", log, "hello-world");
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.2", "hello-world");
+ log.clearOutput();
+ }
+
+ @Test
+ public void emptyRequirements() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_emptyRequirements");
+ Path venvDir = tmpDir.resolve("venv");
+ Path contents = venvDir.resolve("contents");
+ deleteDirOnShutdown(tmpDir);
+
+ Path requirements = tmpDir.resolve("requirements.txt");
+ Files.createFile(requirements);
+
+ checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world"));
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
+ assertFalse(log.output.toString().contains("pip install"));
+ log.clearOutput();
+
+ createVenv(venvDir, "0.1", log, requirements);
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ log.clearOutput();
+
+ createVenv(venvDir, "0.2", log, requirements);
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ log.clearOutput();
+ }
+
+ /**
+ * python packages managed only by requirements file
+ */
+ @Test
+ public void onlyRequirementsFile() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_onlyRequirementsFile");
+ Path venvDir = tmpDir.resolve("venv");
+ Path contents = venvDir.resolve("contents");
+ deleteDirOnShutdown(tmpDir);
+
+ Path requirements = tmpDir.resolve("requirements.txt");
+
+ writeRequirementsFile(requirements);
+ createVenv(venvDir, "0.1", log, requirements);
+ assertFalse(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(Files.exists(venvDir.resolve("installed.txt")));
+ log.clearOutput();
+
+ writeRequirementsFile(requirements, "hello-world");
+ createVenv(venvDir, "0.1", log, requirements);
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("pip install -r"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1");
+ log.clearOutput();
+
+ writeRequirementsFile(requirements, "tiny-tiny");
+ createVenv(venvDir, "0.1", log, requirements);
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install -r"));
+ assertTrue(log.output.toString().contains("pip uninstall"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "tiny-tiny");
+ checkVenvContentsFile(contents, "0.1");
+ log.clearOutput();
+
+ writeRequirementsFile(requirements, "tiny-tiny", "hello-world");
+ createVenv(venvDir, "0.1", log, requirements);
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install -r"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
+ checkVenvContentsFile(contents, "0.1");
+ log.clearOutput();
+
+ writeRequirementsFile(requirements, "tiny-tiny==0.1", "hello-world");
+ createVenv(venvDir, "0.1", log, requirements);
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install -r"));
+ assertTrue(log.output.toString().contains("pip uninstall"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny==0.1");
+ checkVenvContentsFile(contents, "0.1");
+ log.clearOutput();
+
+ // new graalpy version
+ createVenv(venvDir, "0.2", log, requirements);
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.output.toString().contains("pip install -r"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny==0.1");
+ checkVenvContentsFile(contents, "0.2");
+ log.clearOutput();
+
+ // check that freeze rewrites an existing requirements file
+ writeRequirementsFile(requirements); // no packages
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "hello-world", "tiny-tiny==0.1");
+ log.clearOutput();
+ }
+
+ private void writeRequirementsFile(Path requirements, String... packages) throws IOException {
+ List lines = new ArrayList<>(Arrays.asList("# " + String.join("\n# ", REQUIREMENTS_HEADER.split("\n"))));
+ lines.addAll(Arrays.asList(packages));
+ Files.write(requirements, lines, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ }
+
+ @Test
+ public void installAndFreeze() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_installAndFreeze");
+ Path venvDir = tmpDir.resolve("venv");
+ Path contents = venvDir.resolve("contents");
+ deleteDirOnShutdown(tmpDir);
+
+ Path requirements = tmpDir.resolve("requirements.txt");
+
+ // install package from plugin config
+ createVenv(venvDir, "0.1", log, requirements, "hello-world");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+ // freeze requirements
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "hello-world");
+ log.clearOutput();
+
+ // reinstall without exact version declared - fails
+ checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world"));
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
+ assertFalse(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world");
+ log.clearOutput();
+
+ // reinstall with exact version declared - ok
+ Files.delete(requirements);
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1");
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1");
+ log.clearOutput();
+ // freeze requirements
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "hello-world==0.1");
+ log.clearOutput();
+
+ // add tiny-tiny - fails because inconsistent with requirements file
+ assert Files.exists(requirements);
+ checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2"));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'tiny-tiny==0.2'")));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1");
+
+ // delete requirements and try again tiny-tiny - now ok
+ Files.delete(requirements);
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2");
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ // freeze requirements - hello-world, tiny-tiny
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "hello-world==0.1", "tiny-tiny==0.2");
+ log.clearOutput();
+
+ // install again - OK
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2");
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ log.clearOutput();
+
+ // update hello-world version - fails
+ checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2"));
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'hello-world==0.2'", requirements)));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ log.clearOutput();
+
+ // delete requirements and try again new hello-world version - now ok
+ Files.delete(requirements);
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvCreate(log.getOutput(), false);
+ assertTrue(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.2", "tiny-tiny==0.2");
+ log.clearOutput();
+ // freeze requirements with new hello-world
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "hello-world==0.2", "tiny-tiny==0.2");
+ log.clearOutput();
+
+ // install again - OK
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvCreate(log.getOutput(), false);
+ assertFalse(log.output.toString().contains("pip install"));
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.2", "tiny-tiny==0.2");
+ log.clearOutput();
+
+ // reinstall with new graalpy version
+ createVenv(venvDir, "0.2", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvCreate(log.getOutput(), true);
+ assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.output.toString().contains("pip install -r")); // requirements file is used
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
+ checkVenvContentsFile(contents, "0.2", "hello-world==0.2", "tiny-tiny==0.2");
+ log.clearOutput();
+ }
+
+ @Test
+ public void invalidVersionFormatTest() throws Exception {
+ TestLog log = new TestLog();
+
+ checkWrongPkgVersionFormat("", log);
+ checkWrongPkgVersionFormat("==2.2", log);
+ checkWrongPkgVersionFormat("==", log);
+ checkWrongPkgVersionFormat("somepkg==", log);
+
+ checkWrongPkgVersionFormat("somepkg", log);
+ checkWrongPkgVersionFormat("somepkg==2.*", log);
+ checkWrongPkgVersionFormat("==*", log);
+ for (String v : new String[]{"", "<=", ">=", "~="}) {
+ checkWrongPkgVersionFormat("somepkg" + v + "2.2.0", log);
+ }
+ }
+
+ private static void checkWrongPkgVersionFormat(String pkg, TestLog log) {
+ checkException(IOException.class, () -> VFSUtils.checkVersionFormat(Arrays.asList(pkg), WRONG_PKG_VERSION_ERROR, log));
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'" + pkg + "'")));
+ log.clearOutput();
+ }
+
+ @Test
+ public void packageConsistency() throws Exception {
+ TestLog log = new TestLog();
+
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_packageConsistency");
+ deleteDirOnShutdown(tmpDir);
+ Path requirements = tmpDir.resolve("requirements.txt");
+ Files.createFile(requirements);
+
+ callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST);
+ assertFalse(log.output.toString().contains("inconsistent package"));
+
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST, "pkg1"));
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
+ log.clearOutput();
+
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST, "pkg1==1"));
+ assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg1==1'", requirements)));
+ log.clearOutput();
+
+ final List requirementsList = Arrays.asList("pkg1==1.0.0");
+ Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
+
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1"));
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
+ log.clearOutput();
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg2"));
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
+ log.clearOutput();
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg2==1"));
+ assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==1'", requirements)));
+ log.clearOutput();
+ callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1==1.0");
+ log.clearOutput();
+ callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1==1.0.0");
+ log.clearOutput();
+
+ final List requirementsList2 = Arrays.asList("pkg1==1.0.0", "pkg2==1.0.0");
+ Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
+
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg2"));
+ assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
+ log.clearOutput();
+ checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg2==2"));
+ assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==2'", requirements)));
+ log.clearOutput();
+ callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg1==1.0");
+ log.clearOutput();
+ callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg1==1.0", "pkg2==1.0.0");
+ log.clearOutput();
+ }
+
+ private static void callPackageConsistencyCheck(Path requirements, TestLog log, List requirementsList, String... packages)
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Method m = VFSUtils.class.getDeclaredMethod("checkPackagesConsistent", List.class, Path.class, List.class, String.class, String.class, BuildToolLog.class);
+ m.setAccessible(true);
+ m.invoke(VFSUtils.class, Arrays.asList(packages), requirements, requirementsList, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, log);
+ }
+
+ private interface ExceptionCall {
+ void call() throws Exception;
+ }
+
+ private static void checkException(Class> cls, ExceptionCall c) {
+ try {
+ c.call();
+ } catch (Exception e) {
+ if (e instanceof InvocationTargetException) {
+ assertEquals(cls, e.getCause().getClass());
+ } else {
+ assertEquals(cls, e.getClass());
+ }
+ }
+ }
+
+ private static void checkVenvCreate(String output, boolean b) {
+ if (b) {
+ assertTrue(output.contains("-m venv"));
+ assertTrue(output.contains("-m ensurepip"));
+ } else {
+ assertFalse(output.contains("-m venv"));
+ assertFalse(output.contains("-m ensurepip"));
+ }
+ }
+
+ private static void checkInstalledPackages(Path requirements, String... packages) throws IOException {
+ checkPackages(requirements, null, packages);
+ }
+
+ private static void checkRequirementsFile(Path requirements, String... packages) throws IOException {
+ checkPackages(requirements, REQUIREMENTS_HEADER, packages);
+ }
+
+ private static void checkPackages(Path file, String header, String... packages) throws IOException {
+ assertTrue(Files.exists(file));
+ List lines = Files.readAllLines(file);
+
+ if (header != null) {
+ String[] h = header.split("\n");
+ assertTrue(lines.size() >= h.length);
+ for (int i = 0; i < h.length; i++) {
+ assertEquals("# " + h[i], lines.get(i));
+ }
+ }
+
+ lines = lines.stream().filter(line -> !line.trim().startsWith("#")).toList();
+ assertEquals(packages.length, lines.size());
+ for (String pkg : packages) {
+ boolean found = false;
+ String pkgDef = pkg.indexOf("==") >= 0 ? pkgDef = pkg : pkg + "==";
+ for (String line : lines) {
+ assert line.contains("==");
+ if (line.startsWith(pkgDef)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ fail("file " + file + " does not contain package " + pkg);
+ }
+ }
+ }
+
+ private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, String... packages) throws IOException {
+ EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, packages);
+ }
+
+ private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path requirements, String... packages) throws IOException {
+ EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, requirements, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, packages);
+ }
+
+ private static void checkVenvContentsFile(Path contents, String graalPyVersion, String... packages) throws IOException {
+ assertTrue(Files.exists(contents));
+ List lines = Files.readAllLines(contents);
+
+ assertEquals(graalPyVersion, lines.get(0));
+ lines.remove(0);
+ assertEquals(packages.length, lines.size());
+ assertTrue(lines.containsAll(Arrays.asList(packages)));
+ }
+
+}
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py
index e9f1e02c8f..1fee24f38c 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
@@ -401,7 +401,8 @@ def test_no_pkgs_but_resource_dir(self):
self.assertTrue(result == 0, f"Execution failed with code {result}\n command: {command}\n stdout: {out}")
self.assertFalse("[graalpy jbang integration] python packages" in out, f"Did not expect text:\n[graalpy jbang integration] python packages")
self.assertTrue("[graalpy jbang integration] python resources directory: python-resources" in out, f"Expected text:\n[graalpy jbang integration] python resources directory: python-resources")
- self.assertTrue("-m ensurepip" in out, f"-m ensurepip")
+ self.assertFalse("-m ensurepip" in out)
+ self.assertFalse("pip install" in out)
@unittest.skipUnless(is_enabled, "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true")
def test_two_resource_dirs(self):
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
index 51868cbf9b..979c2ab9e3 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
@@ -55,11 +55,15 @@
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.*;
import org.eclipse.aether.graph.Dependency;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils.Launcher;
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.GRAALPY_GROUP_ID;
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.LAUNCHER_NAME;
@@ -172,7 +176,7 @@ public void execute() throws MojoExecutionException {
for(Resource r : project.getBuild().getResources()) {
if (Files.exists(Path.of(r.getDirectory(), resourceDirectory, "proj"))) {
getLog().warn(String.format("usage of %s is deprecated, use %s instead", Path.of(resourceDirectory, "proj"), Path.of(resourceDirectory, "src")));
- }
+ }
if (!Files.exists(Path.of(r.getDirectory(), resourceDirectory)) && Files.exists(Path.of(r.getDirectory(), "vfs", "proj"))) {
// there isn't the actual vfs resource root "org.graalvm.python.vfs" (VFS_ROOT), and there is only the outdated "vfs/proj"
// => looks like a project created < 24.1.0
@@ -229,8 +233,14 @@ private void manageVenv() throws MojoExecutionException {
delete(venvDirectory);
return;
}
-
- VFSUtils.createVenv(venvDirectory, new ArrayList(packages), getLauncherPath(), () -> calculateLauncherClasspath(project), getGraalPyVersion(project), new MavenDelegateLog(getLog()));
+
+ Launcher launcher = new Launcher( getLauncherPath()) {
+ public Set computeClassPath() throws IOException {
+ return calculateLauncherClasspath(project);
+ }
+ };
+
+ VFSUtils.createVenv(venvDirectory, new ArrayList(packages), launcher, getGraalPyVersion(project), new MavenDelegateLog(getLog()));
} catch (IOException e) {
throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
index e64a35d99c..6edc062f55 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
@@ -77,7 +77,7 @@ default public boolean isDebugEnabled() {
default void debug(String s) {
System.out.println(s);
}
-
+
final class CollectOutputLog implements BuildToolLog {
private final List output = new ArrayList<>();
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index 3224de3d9d..c1deae3898 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -50,13 +50,17 @@
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.graalvm.python.embedding.tools.exec.BuildToolLog.CollectOutputLog;
@@ -86,6 +90,8 @@ public final class VFSUtils {
private static final String GRAALPY_MAIN_CLASS = "com.oracle.graal.python.shell.GraalPythonMain";
+ private static final String FOR_MORE_INFO_REFERENCE_MSG = "For more information, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools";
+
public static void writeNativeImageConfig(Path metaInfRoot, String pluginId) throws IOException {
writeNativeImageConfig(metaInfRoot, pluginId, VFS_ROOT);
}
@@ -177,11 +183,6 @@ private static String makeDirPath(Path p) {
return ret;
}
- @FunctionalInterface
- public interface LauncherClassPath {
- Set get() throws IOException;
- }
-
private static void delete(Path dir) throws IOException {
if (!Files.exists(dir)) {
return;
@@ -195,42 +196,194 @@ private static void delete(Path dir) throws IOException {
}
}
- public static void createVenv(Path venvDirectory, List packages, Path launcher, LauncherClassPath launcherClassPath, String graalPyVersion, BuildToolLog log)
- throws IOException {
- Path launcherPath = launcher;
- String externalLauncher = System.getProperty("graalpy.vfs.venvLauncher");
- if (externalLauncher == null || externalLauncher.trim().isEmpty()) {
- generateLaunchers(launcherPath, launcherClassPath, log);
- } else {
- launcherPath = Path.of(externalLauncher);
+ public static void warnMissingRequirementsFile(Path requirementsFile, String missingRequirementsFileWarning, BuildToolLog log) {
+ if (!Files.exists(requirementsFile)) {
+ warning(String.format(missingRequirementsFileWarning, requirementsFile) + "\n" + FOR_MORE_INFO_REFERENCE_MSG, log);
}
+ }
- if (packages != null) {
- trim(packages);
+ public static abstract class Launcher {
+ private final Path launcherPath;
+
+ protected Launcher(Path launcherPath) {
+ Objects.requireNonNull(launcherPath);
+ this.launcherPath = launcherPath;
}
- List installedPackages = new ArrayList<>();
- var tag = venvDirectory.resolve("contents");
+ protected abstract Set computeClassPath() throws IOException;
+ }
- if (Files.exists(venvDirectory)) {
- checkLauncher(venvDirectory, launcherPath, log);
+ private static class InstalledPackages {
+ final Path venvDirectory;
+ final Path installedFile;
+ List packages;
- if (Files.isReadable(tag)) {
- List lines = null;
- try {
- lines = Files.readAllLines(tag);
- } catch (IOException e) {
- throw new IOException(String.format("failed to read tag file %s", tag), e);
+ private InstalledPackages(Path venvDirectory, Path installedFile, List packages) {
+ this.venvDirectory = venvDirectory;
+ this.installedFile = venvDirectory.resolve("installed.txt");
+ this.packages = packages;
+ }
+
+ static InstalledPackages fromVenv(Path venvDirectory) throws IOException {
+ Path installed = venvDirectory.resolve("installed.txt");
+ List pkgs = Files.exists(installed) ? readPackagesFromFile(installed) : Collections.EMPTY_LIST;
+ return new InstalledPackages(venvDirectory, installed, pkgs);
+ }
+
+ void freeze(BuildToolLog log) throws IOException {
+ CollectOutputLog collectOutputLog = new CollectOutputLog();
+ runPip(venvDirectory, "freeze", collectOutputLog, "--local");
+ packages = new ArrayList<>(collectOutputLog.getOutput());
+
+ String toWrite = "# Generated by GraalPy Maven or Gradle plugin using pip freeze\n" +
+ "# This file is used by GraalPy VirtualFileSystem\n" +
+ String.join("\n", packages);
+ Files.write(installedFile, toWrite.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+
+ if (log.isDebugEnabled()) {
+ log.debug("VFSUtils.createVenv installed python packages:");
+ for (String p : packages) {
+ log.debug(" " + p);
}
- if (lines.isEmpty() || !graalPyVersion.equals(lines.get(0))) {
- log.info(String.format("Stale GraalPy venv, updating to %s", graalPyVersion));
- delete(venvDirectory);
- } else {
- for (int i = 1; i < lines.size(); i++) {
- installedPackages.add(lines.get(i));
- }
+ }
+ }
+ }
+
+ private static class VenvContents {
+ private final static String CONTENTS_FILE_NAME = "contents";
+ final Path contentsFile;
+ List packages;
+ final String graalPyVersion;
+
+ private VenvContents(Path contentsFile, List packages, String graalPyVersion) {
+ this.contentsFile = contentsFile;
+ this.packages = packages;
+ this.graalPyVersion = graalPyVersion;
+ }
+
+ static VenvContents create(Path venvDirectory, String graalPyVersion) {
+ return new VenvContents(venvDirectory.resolve(CONTENTS_FILE_NAME), Collections.EMPTY_LIST, graalPyVersion);
+ }
+
+ static VenvContents fromVenv(Path venvDirectory) throws IOException {
+ Path contentsFile = venvDirectory.resolve(CONTENTS_FILE_NAME);
+ List packages = new ArrayList<>();
+ String graalPyVersion = null;
+ if (Files.isReadable(contentsFile)) {
+ List lines = Files.readAllLines(contentsFile);
+ if (lines.isEmpty()) {
+ return null;
+ }
+ Iterator it = lines.iterator();
+ graalPyVersion = it.next();
+ while (it.hasNext()) {
+ packages.add(it.next());
}
}
+ return new VenvContents(contentsFile, packages, graalPyVersion);
+ }
+
+ void write(List packages) throws IOException {
+ Files.write(contentsFile, List.of(graalPyVersion), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ if (packages != null) {
+ Files.write(contentsFile, packages, StandardOpenOption.APPEND);
+ this.packages = packages;
+ }
+ }
+ }
+
+ public static void createVenv(Path venvDirectory, List packagesArgs, Launcher launcherArgs, String graalPyVersion, BuildToolLog log) throws IOException {
+ createVenv(venvDirectory, packagesArgs, null, null, null, launcherArgs, graalPyVersion, log);
+ }
+
+ public static void createVenv(Path venvDirectory, List packages, Path requirementsFile, String inconsistentPackagesError, String wrongPackageVersionFormatError,
+ Launcher launcherArgs, String graalPyVersion, BuildToolLog log) throws IOException {
+ Objects.requireNonNull(venvDirectory);
+ Objects.requireNonNull(packages);
+ Objects.requireNonNull(launcherArgs);
+ Objects.requireNonNull(graalPyVersion);
+ Objects.requireNonNull(log);
+
+ logVenvArgs(venvDirectory, packages, requirementsFile, launcherArgs, graalPyVersion, log);
+
+ List pluginPackages = trim(packages);
+ List requirementsPackages = requirementsFile != null && Files.exists(requirementsFile) ? readPackagesFromFile(requirementsFile) : null;
+ if (!checkPackages(venvDirectory, pluginPackages, requirementsPackages, requirementsFile, inconsistentPackagesError, wrongPackageVersionFormatError, log)) {
+ return;
+ }
+
+ VenvContents venvContents = ensureVenv(venvDirectory, graalPyVersion, log, ensureLauncher(launcherArgs, log));
+
+ boolean installed = requirementsPackages != null ? install(venvDirectory, requirementsFile, requirementsPackages, log) : install(venvDirectory, pluginPackages, venvContents, log);
+ if (installed) {
+ venvContents.write(pluginPackages);
+ }
+ }
+
+ private static void logVenvArgs(Path venvDirectory, List packages, Path requirementsFile, Launcher launcherArgs, String graalPyVersion, BuildToolLog log)
+ throws IOException {
+ if (log.isDebugEnabled()) {
+ Set lcp = launcherArgs.computeClassPath();
+ log.debug("VFSUtils.createVenv():");
+ log.debug(" graalPyVersion: " + graalPyVersion);
+ log.debug(" venvDirectory: " + venvDirectory);
+ log.debug(" packages: " + packages);
+ log.debug(" requirements file: " + requirementsFile);
+ log.debug(" launcher: " + launcherArgs.launcherPath);
+ log.debug(" launcher classpath: " + lcp);
+ }
+ }
+
+ private static boolean checkPackages(Path venvDirectory, List pluginPackages, List requirementsPackages, Path requirementsFile, String inconsistentPackagesError,
+ String wrongPackageVersionFormatError, BuildToolLog log) throws IOException {
+ if (requirementsPackages != null) {
+ checkPackagesConsistent(pluginPackages, requirementsPackages, inconsistentPackagesError, wrongPackageVersionFormatError, log);
+ logPackages(requirementsPackages, requirementsFile, log);
+ return needVenv(venvDirectory, requirementsPackages, log);
+ } else {
+ logPackages(pluginPackages, null, log);
+ return needVenv(venvDirectory, pluginPackages, log);
+ }
+ }
+
+ private static boolean needVenv(Path venvDirectory, List packages, BuildToolLog log) throws IOException {
+ if ((packages.isEmpty())) {
+ if (Files.exists(venvDirectory)) {
+ log.info(String.format("No packages to install, deleting venv"));
+ delete(venvDirectory);
+ } else {
+ log.debug("VFSUtils.createVenv: skipping - no package or requirements file provided");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private static void logPackages(List packages, Path requirementsFile, BuildToolLog log) {
+ if (requirementsFile != null) {
+ log.info(String.format("Installing %s python packages from requirements file: %s", packages.size(), requirementsFile));
+ } else {
+ log.info(String.format("Installing %s python packages from GraalPy plugin configuration", packages.size()));
+ }
+ }
+
+ private static List readPackagesFromFile(Path file) throws IOException {
+ return Files.readAllLines(file).stream().filter((s) -> s != null && !s.trim().startsWith("#")).toList();
+ }
+
+ private static VenvContents ensureVenv(Path venvDirectory, String graalPyVersion, BuildToolLog log, Path launcherPath) throws IOException {
+ VenvContents contents = null;
+ if (Files.exists(venvDirectory)) {
+ checkVenvLauncher(venvDirectory, launcherPath, log);
+ contents = VenvContents.fromVenv(venvDirectory);
+ if (contents == null) {
+ log.warning(String.format("Reinstalling GraalPy venv due to corrupt contents file"));
+ delete(venvDirectory);
+ } else if (!graalPyVersion.equals(contents.graalPyVersion)) {
+ contents = null;
+ log.info(String.format("Stale GraalPy venv, updating to %s", graalPyVersion));
+ delete(venvDirectory);
+ }
}
if (!Files.exists(venvDirectory)) {
@@ -239,33 +392,130 @@ public static void createVenv(Path venvDirectory, List packages, Path la
runVenvBin(venvDirectory, "graalpy", log, "-I", "-m", "ensurepip");
}
- Iterable frozenPkgs = null;
- if (packages != null) {
- boolean needsUpdate = false;
- needsUpdate |= deleteUnwantedPackages(venvDirectory, packages, installedPackages, log);
- needsUpdate |= installWantedPackages(venvDirectory, packages, installedPackages, log);
- if (needsUpdate) {
- var freezeLog = new CollectOutputLog();
- runPip(venvDirectory, "freeze", freezeLog, "--local");
- frozenPkgs = freezeLog.getOutput();
+ if (contents == null) {
+ contents = VenvContents.create(venvDirectory, graalPyVersion);
+ }
+
+ return contents;
+ }
+
+ private static boolean install(Path venvDirectory, Path requirementsFile, List requiredPkgs, BuildToolLog log) throws IOException {
+ InstalledPackages installedPackages = InstalledPackages.fromVenv(venvDirectory);
+ if (installedPackages.packages.size() != requiredPkgs.size() || deleteUnwantedPackages(venvDirectory, requiredPkgs, installedPackages.packages, log)) {
+ runPip(venvDirectory, "install", log, "-r", requirementsFile.toString());
+ installedPackages.freeze(log);
+ return true;
+ } else {
+ log.info("Python packages up to date, skipping install from requirements file");
+ }
+ return false;
+ }
+
+ private static boolean install(Path venvDirectory, List newPackages, VenvContents venvContents, BuildToolLog log) throws IOException {
+ boolean needsUpdate = false;
+ needsUpdate |= deleteUnwantedPackages(venvDirectory, newPackages, venvContents.packages, log);
+ needsUpdate |= installWantedPackages(venvDirectory, newPackages, venvContents.packages, log);
+ if (needsUpdate) {
+ InstalledPackages.fromVenv(venvDirectory).freeze(log);
+ return true;
+ }
+ return false;
+ }
+
+ public static void createRequirementsFile(Path venvDirectory, Path requirementsFile, String requirementsFileHeader, BuildToolLog log) throws IOException {
+ Objects.requireNonNull(venvDirectory);
+ Objects.requireNonNull(requirementsFile);
+ Objects.requireNonNull(requirementsFileHeader);
+ Objects.requireNonNull(log);
+
+ assert Files.exists(venvDirectory);
+
+ log.info(String.format("Creating %s", requirementsFile));
+
+ InstalledPackages installedPackages = InstalledPackages.fromVenv(venvDirectory);
+ List header = getHeaderList(requirementsFileHeader);
+ Files.write(requirementsFile, header, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ Files.write(requirementsFile, installedPackages.packages, StandardOpenOption.APPEND);
+
+ if (log.isDebugEnabled()) {
+ log.debug("VFSUtils created requirements file: " + requirementsFile);
+ for (String p : installedPackages.packages) {
+ log.debug(" " + p);
}
}
+ }
- try {
- Files.write(tag, List.of(graalPyVersion), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
- Files.write(tag, packages, StandardOpenOption.APPEND);
- if (frozenPkgs != null) {
- String toWrite = "# Generated by GraalPy Maven or Gradle plugin using pip freeze\n" +
- "# This file is used by GraalPy VirtualFileSystem\n" +
- String.join("\n", frozenPkgs);
- Files.write(venvDirectory.resolve("installed.txt"), toWrite.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ private static List getHeaderList(String requirementsFileHeader) {
+ List list = new ArrayList<>();
+ String[] lines = requirementsFileHeader.split("\n");
+ for (String l : lines) {
+ list.add("# " + l);
+ }
+ return list;
+ }
+
+ public static void checkVersionFormat(List packages, String wrongPackageVersionFormatError, BuildToolLog log) throws IOException {
+ Objects.requireNonNull(packages);
+ Objects.requireNonNull(wrongPackageVersionFormatError);
+ Objects.requireNonNull(log);
+
+ StringBuilder sb = new StringBuilder();
+ for (String pkg : packages) {
+ if (!checkValidPackageVersion(pkg)) {
+ sb.append(!sb.isEmpty() ? ", " : "").append("'").append(pkg).append("'");
}
- } catch (IOException e) {
- throw new IOException(String.format("failed to write tag file %s", tag), e);
+ }
+ if (!sb.isEmpty()) {
+ wrongPackageVersionError(sb.toString(), wrongPackageVersionFormatError, log);
}
}
- private static void checkLauncher(Path venvDirectory, Path launcherPath, BuildToolLog log) throws IOException {
+ private static boolean checkValidPackageVersion(String pkg) throws IOException {
+ int idx = pkg.indexOf("==");
+ if (idx <= 0) {
+ return false;
+ } else {
+ String version = pkg.substring(idx + 2).trim();
+ if (version.isEmpty() || version.contains("*")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static void wrongPackageVersionError(String pkgs, String wrongPackageVersionFormatError, BuildToolLog log) throws IOException {
+ error(String.format(wrongPackageVersionFormatError, pkgs) + "\n" + FOR_MORE_INFO_REFERENCE_MSG, log);
+ throw new IOException("invalid package format: " + pkgs);
+ }
+
+ private static void checkPackagesConsistent(List packages, Path requirementsFile, List requiredPackages, String inconsistentPackagesError,
+ String wrongPackageVersionFormatError, BuildToolLog log) throws IOException {
+ if (packages.isEmpty()) {
+ return;
+ }
+
+ checkVersionFormat(packages, wrongPackageVersionFormatError, log);
+
+ Map requiredPackagesMap = requiredPackages.stream().filter(p -> p.contains("==")).map(p -> p.split("==")).collect(Collectors.toMap(parts -> parts[0], parts -> parts[1]));
+ StringBuilder sb = new StringBuilder();
+ for (String pkg : packages) {
+ String[] s = pkg.split("==");
+ String pName = s[0];
+ String pVersion = s[1];
+ String rVersion = requiredPackagesMap.get(pName);
+ if (rVersion != null && rVersion.startsWith(pVersion)) {
+ continue;
+ }
+ sb.append(!sb.isEmpty() ? ", " : "").append("'").append(pkg).append("'");
+ }
+
+ if (!sb.isEmpty()) {
+ error(String.format(inconsistentPackagesError, sb) + "\n" + FOR_MORE_INFO_REFERENCE_MSG, log);
+ throw new IOException("inconsistent packages");
+ }
+ }
+
+ private static void checkVenvLauncher(Path venvDirectory, Path launcherPath, BuildToolLog log) throws IOException {
if (!Files.exists(launcherPath)) {
throw new IOException(String.format("Launcher file does not exist '%s'", launcherPath));
}
@@ -293,16 +543,26 @@ private static void checkLauncher(Path venvDirectory, Path launcherPath, BuildTo
throw new IOException(String.format("failed to read config file %s", cfg), e);
}
} else {
- log.info(String.format("missing venv config file: '%s'", cfg));
+ log.info(String.format("Missing venv config file: '%s'", cfg));
}
}
- private static void generateLaunchers(Path laucherPath, LauncherClassPath launcherClassPath, BuildToolLog log) throws IOException {
- if (!Files.exists(laucherPath)) {
+ private static Path ensureLauncher(Launcher launcherArgs, BuildToolLog log) throws IOException {
+ String externalLauncher = System.getProperty("graalpy.vfs.venvLauncher");
+ if (externalLauncher == null || externalLauncher.trim().isEmpty()) {
+ generateLaunchers(launcherArgs, log);
+ return launcherArgs.launcherPath;
+ } else {
+ return Path.of(externalLauncher);
+ }
+ }
+
+ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) throws IOException {
+ if (!Files.exists(launcherArgs.launcherPath)) {
log.info("Generating GraalPy launchers");
- createParentDirectories(laucherPath);
+ createParentDirectories(launcherArgs.launcherPath);
Path java = Paths.get(System.getProperty("java.home"), "bin", "java");
- String classpath = String.join(File.pathSeparator, launcherClassPath.get());
+ String classpath = String.join(File.pathSeparator, launcherArgs.computeClassPath());
if (!IS_WINDOWS) {
var script = String.format("""
#!/usr/bin/env bash
@@ -312,12 +572,12 @@ private static void generateLaunchers(Path laucherPath, LauncherClassPath launch
String.join(File.pathSeparator, classpath),
GRAALPY_MAIN_CLASS);
try {
- Files.writeString(laucherPath, script);
- var perms = Files.getPosixFilePermissions(laucherPath);
+ Files.writeString(launcherArgs.launcherPath, script);
+ var perms = Files.getPosixFilePermissions(launcherArgs.launcherPath);
perms.addAll(List.of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_EXECUTE));
- Files.setPosixFilePermissions(laucherPath, perms);
+ Files.setPosixFilePermissions(launcherArgs.launcherPath, perms);
} catch (IOException e) {
- throw new IOException(String.format("failed to create launcher %s", laucherPath), e);
+ throw new IOException(String.format("failed to create launcher %s", launcherArgs.launcherPath), e);
}
} else {
// on windows, generate a venv launcher that executes our mvn target
@@ -334,7 +594,7 @@ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
f.write('venvlauncher_command = ')
f.write(cmd)
""",
- laucherPath,
+ launcherArgs.launcherPath,
java,
classpath,
GRAALPY_MAIN_CLASS);
@@ -416,4 +676,21 @@ public static List trim(List l) {
}
return l;
}
+
+ private static void warning(String txt, BuildToolLog log) {
+ String prefix = txt.startsWith("WARNING:") ? "WARNING:" : "";
+ log.warning("");
+ for (String t : txt.split("\n")) {
+ log.warning(t.startsWith(prefix) ? t : prefix + " " + t);
+ }
+ log.warning("");
+ }
+
+ private static void error(String txt, BuildToolLog log) {
+ log.error("");
+ for (String t : txt.split("\n")) {
+ log.error(t);
+ }
+ log.error("");
+ }
}
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
index 0b964a9720..eebba107aa 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
@@ -194,17 +194,17 @@ private TaskProvider registerResourcesTask(Project project, Confi
"When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
"For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
}
- t.getPackages().set(extension.getPackages());
+ t.getPackages().set(extension.getPackages());
- t.getOutput().convention(
- extension.getExternalDirectory().orElse(
- extension.getPythonResourcesDirectory()
- .orElse(project.getLayout().getBuildDirectory().dir(DEFAULT_RESOURCES_DIRECTORY))));
- t.getIncludeVfsRoot().convention(extension.getExternalDirectory().map(d -> false)
- .orElse(extension.getPythonResourcesDirectory().map(d -> false).orElse(true)));
- t.getResourceDirectory().set(extension.getResourceDirectory());
+ t.getOutput().convention(
+ extension.getExternalDirectory().orElse(
+ extension.getPythonResourcesDirectory()
+ .orElse(project.getLayout().getBuildDirectory().dir(DEFAULT_RESOURCES_DIRECTORY))));
+ t.getIncludeVfsRoot().convention(extension.getExternalDirectory().map(d -> false)
+ .orElse(extension.getPythonResourcesDirectory().map(d -> false).orElse(true)));
+ t.getResourceDirectory().set(extension.getResourceDirectory());
- t.setGroup(GRAALPY_GRADLE_PLUGIN_TASK_GROUP);
+ t.setGroup(GRAALPY_GRADLE_PLUGIN_TASK_GROUP);
});
}
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
index e9721ec9ad..72dc897bf2 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
@@ -44,6 +44,7 @@
import org.graalvm.python.GradleLogger;
import org.graalvm.python.dsl.GraalPyExtension;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils.Launcher;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.ConfigurableFileCollection;
@@ -131,8 +132,12 @@ public void exec() throws IOException {
private void manageVenv() {
List packages = getPackages().getOrElse(null);
try {
- VFSUtils.createVenv(getVenvDirectory(), new ArrayList(packages), getLauncherPath(), this::calculateLauncherClasspath, getPolyglotVersion().get(),
- GradleLogger.of(getLogger()));
+ Launcher launcher = new Launcher( getLauncherPath()) {
+ public Set computeClassPath() {
+ return calculateLauncherClasspath();
+ }
+ };
+ VFSUtils.createVenv(getVenvDirectory(), new ArrayList(packages), launcher, getPolyglotVersion().get(), GradleLogger.of(getLogger()));
} catch (IOException e) {
throw new GradleException(String.format("failed to create venv %s", getVenvDirectory()), e);
}
diff --git a/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java b/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
index 60f71f8bbe..e5d64c5d15 100644
--- a/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
+++ b/graalpython/org.graalvm.python.jbang/src/org/graalvm/python/jbang/JBangIntegration.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils.Launcher;
import java.io.File;
import java.io.IOException;
@@ -58,6 +59,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -76,6 +78,12 @@ public class JBangIntegration {
private static final String LAUNCHER = IS_WINDOWS ? "graalpy.exe" : "graalpy.sh";
private static final BuildToolLog BUILD_TOOL_LOG = new BuildToolLog() {
+ private static final boolean debugEnabled = Boolean.getBoolean("org.graalvm.python.jbang.log.debug");
+
+ @Override
+ public boolean isDebugEnabled() {
+ return debugEnabled;
+ }
};
private static final String JBANG_COORDINATES = "org.graalvm.python:jbang:jar";
@@ -171,7 +179,12 @@ private static void handleVenv(Path venv, List> dependen
// perhaps already checked by jbang
throw new IllegalStateException("could not resolve parent for venv path: " + venv);
}
- VFSUtils.createVenv(venv, pkgs, getLauncherPath(venvParent.toString()), () -> calculateClasspath(dependencies), graalPyVersion, BUILD_TOOL_LOG);
+ Launcher launcher = new Launcher(getLauncherPath(venvParent.toString())) {
+ public Set computeClassPath() {
+ return calculateClasspath(dependencies);
+ };
+ };
+ VFSUtils.createVenv(venv, pkgs, launcher, graalPyVersion, BUILD_TOOL_LOG);
if (dropPip) {
try {
diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py
index 7f00af0ec6..e52c7987ad 100644
--- a/mx.graalpython/mx_graalpython.py
+++ b/mx.graalpython/mx_graalpython.py
@@ -415,6 +415,10 @@ def __str__(self):
TestConfig("multi-cext", vm_args + ['org.graalvm.python.embedding.cext.test'] + args + (["--use-graalvm"] if has_compiler else []), True),
)
+ configs.append(
+ TestConfig("vfsutil", vm_args + ['org.graalvm.python.embedding.vfs.test'] + args + (["--use-graalvm"] if has_compiler else []), True),
+ )
+
if '--regex' not in args:
async_regex = ['--regex', r'com\.oracle\.graal\.python\.test\.integration\.advanced\.AsyncActionThreadingTest']
configs.append(TestConfig("async", vm_args + ['-Dpython.AutomaticAsyncActions=false', 'com.oracle.graal.python.test', 'org.graalvm.python.embedding.test'] + async_regex + args, True, False))
@@ -1209,7 +1213,7 @@ def graalpython_gate_runner(args, tasks):
"--verbose",
"--no-leak-tests",
"--regex",
- r'((graal\.python\.test\.integration)|(graal\.python\.test\.(builtin|interop|util)))'
+ r'((graal\.python\.test\.integration)|(graal\.python\.test\.(builtin|interop|util))|(org\.graalvm\.python\.embedding\.(test|test\.integration))|(org\.graalvm\.python\.embedding\.vfs\.test))'
],
report=True
)
@@ -2985,6 +2989,7 @@ def apply(self, config):
mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.py/*=ALL-UNNAMED']) # for Python internals
mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.py.launcher/*=ALL-UNNAMED']) # for Python launcher internals
mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.python.embedding/*=ALL-UNNAMED'])
+ mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.python.embedding.tools/*=ALL-UNNAMED'])
if not PythonMxUnittestConfig.useResources:
vmArgs.append('-Dorg.graalvm.language.python.home=' + mx.dependency("GRAALPYTHON_GRAALVM_SUPPORT").get_output())
if mx._opts.verbose:
From aa6850d63fb54897ac2d8e8faf95ad929a073a61 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Fri, 24 Jan 2025 18:13:36 +0100
Subject: [PATCH 050/512] added support for requirement file to maven plugin
---
.../src/tests/standalone/check_home_pom.xml | 6 +-
.../tests/standalone/check_packages_pom.xml | 10 +-
.../standalone/check_plugin_configuration.xml | 88 ++++
.../src/tests/standalone/test_maven_plugin.py | 133 ++++--
.../maven/plugin/AbstractGraalPyMojo.java | 380 ++++++++++++++++++
.../plugin/FreezeInstalledPackagesMojo.java | 117 ++++++
.../maven/plugin/ManageResourcesMojo.java | 304 +-------------
7 files changed, 701 insertions(+), 337 deletions(-)
create mode 100644 graalpython/com.oracle.graal.python.test/src/tests/standalone/check_plugin_configuration.xml
create mode 100644 graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
create mode 100644 graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_home_pom.xml b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_home_pom.xml
index 37b5a27ec3..b8ae79cddc 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_home_pom.xml
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_home_pom.xml
@@ -72,14 +72,14 @@ SOFTWARE.
${env.GRAALPY_VERSION}
-
-
-
process-graalpy-resources
+
+
+
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_packages_pom.xml b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_packages_pom.xml
index fd3468edcc..9e380b16be 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_packages_pom.xml
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_packages_pom.xml
@@ -72,16 +72,16 @@ SOFTWARE.
${env.GRAALPY_VERSION}
-
-
-
-
-
process-graalpy-resources
+
+
+
+
+
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_plugin_configuration.xml b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_plugin_configuration.xml
new file mode 100644
index 0000000000..90d0557729
--- /dev/null
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/check_plugin_configuration.xml
@@ -0,0 +1,88 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.plugin.my.unit
+ project-check-packages
+ 1.0-SNAPSHOT
+ jar
+ Test MyMojo
+
+
+
+ org.graalvm.polyglot
+ python-community
+ ${env.GRAALPY_VERSION}
+ pom
+
+
+ org.graalvm.python
+ python-launcher
+ ${env.GRAALPY_VERSION}
+
+
+
+
+
+
+ org.graalvm.python
+ graalpy-maven-plugin
+ ${env.GRAALPY_VERSION}
+
+
+
+ process-graalpy-resources
+
+
+
+ termcolor
+
+
+
+
+
+
+
+
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
index 5c4f9e34cb..4f3806ca72 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py
@@ -181,6 +181,104 @@ def test_generated_app_with_default_vfs_path(self):
def test_generated_app_utils_pkg(self):
self.check_generated_app(use_default_vfs_path=True, use_utils_pkg=True)
+ @unittest.skipUnless(util.is_maven_plugin_test_enabled, "ENABLE_MAVEN_PLUGIN_UNITTESTS is not true")
+ def test_wrong_configuration(self):
+ with util.TemporaryTestDirectory() as tmpdir:
+
+ target_name = "test_wrong_configuration"
+ target_dir = os.path.join(str(tmpdir), target_name)
+ pom_template = os.path.join(os.path.dirname(__file__), "check_plugin_configuration.xml")
+ self.generate_app(tmpdir, target_dir, target_name, pom_template)
+
+ mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
+ cmd = mvnw_cmd + ["org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out, contains=False)
+ util.check_ouput("In order to run the freeze-installed-packages goal there have to be python packages declared in the graalpy-maven-plugin configuration", out, contains=True)
+ assert not os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ @unittest.skipUnless(util.is_maven_plugin_test_enabled, "ENABLE_MAVEN_PLUGIN_UNITTESTS is not true")
+ def test_freeze_requirements(self):
+ with util.TemporaryTestDirectory() as tmpdir:
+
+ target_name = "test_freeze_requirements"
+ target_dir = os.path.join(str(tmpdir), target_name)
+ self.generate_app(tmpdir, target_dir, target_name)
+
+ mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
+ # run with java asserts on
+ if self.env.get("MAVEN_OPTS"):
+ self.env["MAVEN_OPTS"] = self.env.get("MAVEN_OPTS") + " -ea -esa"
+ else:
+ self.env["MAVEN_OPTS"] = "-ea -esa"
+
+ # start with requests package without version
+ util.replace_in_file(os.path.join(target_dir, "pom.xml"), "termcolor==2.2", "requests")
+
+ # build
+ cmd = mvnw_cmd + ["package", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("pip install", out)
+ util.check_ouput("BUILD SUCCESS", out)
+ util.check_ouput("Missing python requirements file", out)
+ assert not os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ # freeze - fails due to no version
+ cmd = mvnw_cmd + ["org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out, contains=False)
+ util.check_ouput("Missing python requirements file", out, contains=False)
+ util.check_ouput("Some python package(s) in graalpy-maven-plugin configuration have no exact version declared", out)
+ assert not os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ # freeze with correct version
+ util.replace_in_file(os.path.join(target_dir, "pom.xml"), "requests", "requests==2.32.3")
+ cmd = mvnw_cmd + ["org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out, contains=True)
+ util.check_ouput("Missing python requirements file", out, contains=False)
+ assert os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ # add termcolor and build - fails as it is not part of requirements
+ util.replace_in_file(os.path.join(target_dir, "pom.xml"), "", "termcolor==2.2 \n")
+ cmd = mvnw_cmd + ["package", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out, contains=False)
+ util.check_ouput("are either missing or have a different version in python requirements file", out)
+ assert os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ # freeze with termcolor
+ cmd = mvnw_cmd + ["org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages", "-DrequirementsFile=test-requirements.txt"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out, contains=True)
+ util.check_ouput("Missing python requirements file", out, contains=False)
+ assert os.path.exists(os.path.join(target_dir, "test-requirements.txt"))
+
+ # rebuild with requirements and exec
+ cmd = mvnw_cmd + ["package", "exec:java", "-DrequirementsFile=test-requirements.txt", "-Dexec.mainClass=it.pkg.GraalPy"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out)
+ util.check_ouput("pip install", out, False)
+ util.check_ouput("hello java", out)
+ util.check_ouput("Missing python requirements file", out, contains=False)
+
+ # disable packages config in pom
+ util.replace_in_file(os.path.join(target_dir, "pom.xml"), "", "")
+
+ # should be able to import ujson if installed
+ util.replace_in_file(os.path.join(target_dir, "src", "main", "java", "it", "pkg", "GraalPy.java"),
+ "import hello",
+ "import requests; import hello")
+
+ # clean and rebuild with requirements and exec
+ cmd = mvnw_cmd + ["clean", "package", "exec:java", "-DrequirementsFile=test-requirements.txt", "-Dexec.mainClass=it.pkg.GraalPy"]
+ out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
+ util.check_ouput("BUILD SUCCESS", out)
+ util.check_ouput("pip install", out)
+ util.check_ouput("hello java", out)
+ util.check_ouput("Missing python requirements file", out, contains=False)
+
@unittest.skipUnless(util.is_maven_plugin_test_enabled, "ENABLE_MAVEN_PLUGIN_UNITTESTS is not true")
def test_generated_app_external_resources(self):
with util.TemporaryTestDirectory() as tmpdir:
@@ -251,41 +349,6 @@ def test_fail_without_graalpy_dep(self):
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
util.check_ouput("Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python", out)
- @unittest.skipUnless(util.is_maven_plugin_test_enabled, "ENABLE_MAVEN_PLUGIN_UNITTESTS is not true")
- def test_gen_launcher_and_venv(self):
- with util.TemporaryTestDirectory() as tmpdir:
- target_name = "gen_launcher_and_venv_test"
- target_dir = os.path.join(str(tmpdir), target_name)
- pom_template = os.path.join(os.path.dirname(__file__), "prepare_venv_pom.xml")
- self.generate_app(tmpdir, target_dir, target_name, pom_template)
-
- mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
-
- cmd = mvnw_cmd + ["process-resources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out)
- util.check_ouput("-m ensurepip",out)
- util.check_ouput("ujson", out)
- util.check_ouput("termcolor", out)
-
- # run again and assert that we do not regenerate the venv
- cmd = mvnw_cmd + ["process-resources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out, False)
- util.check_ouput("-m ensurepip", out, False)
- util.check_ouput("ujson", out, False)
- util.check_ouput("termcolor", out, False)
-
- # remove ujson pkg from plugin config and check if unistalled
- util.replace_in_file(os.path.join(target_dir, "pom.xml"), "ujson ", "")
-
- cmd = mvnw_cmd + ["process-resources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out, False)
- util.check_ouput("-m ensurepip", out, False)
- util.check_ouput("Uninstalling ujson", out)
- util.check_ouput("termcolor", out, False)
-
@unittest.skipUnless(util.is_maven_plugin_test_enabled, "ENABLE_MAVEN_PLUGIN_UNITTESTS is not true")
def test_check_home_warning(self):
with util.TemporaryTestDirectory() as tmpdir:
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
new file mode 100644
index 0000000000..383daf396f
--- /dev/null
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.graalvm.python.maven.plugin;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.*;
+import org.eclipse.aether.graph.Dependency;
+import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static org.graalvm.python.embedding.tools.vfs.VFSUtils.*;
+
+public abstract class AbstractGraalPyMojo extends AbstractMojo {
+
+ private static final String PYTHON_LAUNCHER_ARTIFACT_ID = "python-launcher";
+
+ private static final String POLYGLOT_GROUP_ID = "org.graalvm.polyglot";
+ private static final String PYTHON_COMMUNITY_ARTIFACT_ID = "python-community";
+ private static final String PYTHON_ARTIFACT_ID = "python";
+ private static final String GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID = "graalpy-maven-plugin";
+
+ protected static final String REQUIREMENTS_FILE_HEADER = """
+ generated by maven goal 'org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages'
+
+ A complete list of python packages declared in graalpy-maven-plugin configuration and
+ their transitive dependencies which are to be installed in GraalPy virtual filessytem.
+ """;
+
+ protected static final String MISSING_REQUIREMENTS_FILE_WARNING = """
+ Missing python requirements file '%s'.
+
+ It is highly recommended to freeze transitive python dependencies by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages'
+ """;
+
+ protected static final String WRONG_PACKAGE_VERSION_FORMAT_ERROR = """
+ Some python package(s) in graalpy-maven-plugin configuration have no exact version declared: %s
+
+ When using the graalpy-maven-plugin together with a python requirements file, it is necessary to declare python packages in format [package_name]==[version].
+ """;
+
+ protected static final String INCONSISTENT_PACKAGES_ERROR = """
+ Some python package(s) from graalpy-maven-plugin configuration are either missing or have a different version in python requirements file: %s.
+
+ The requirements file can be refreshed by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages'.
+ """;
+
+ @Parameter(defaultValue = "${project}", required = true, readonly = true)
+ MavenProject project;
+
+ @Parameter
+ String pythonResourcesDirectory;
+
+ @Parameter(property = "externalDirectory")
+ String externalDirectory;
+
+ @Parameter(property = "resourceDirectory")
+ String resourceDirectory;
+
+ @Parameter(property = "requirementsFile", defaultValue = "requirements.txt")
+ String requirementsFile;
+
+ @Parameter
+ List packages;
+
+ public static class PythonHome {
+ private List includes;
+ private List excludes;
+ }
+
+ @Parameter
+ PythonHome pythonHome;
+
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
+ private MavenSession session;
+
+ @Component
+ private ProjectBuilder projectBuilder;
+
+ private Set launcherClassPath;
+
+ protected void manageNativeImageConfig() throws MojoExecutionException {
+ try {
+ VFSUtils.writeNativeImageConfig(Path.of(project.getBuild().getOutputDirectory(), "META-INF"), GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID, resourceDirectory);
+ } catch (IOException e) {
+ throw new MojoExecutionException("failed to create native image configuration files", e);
+ }
+ }
+
+ protected void listGraalPyResources() throws MojoExecutionException {
+ Path vfs = Path.of(project.getBuild().getOutputDirectory(), resourceDirectory);
+ if (Files.exists(vfs)) {
+ try {
+ VFSUtils.generateVFSFilesList(Path.of(project.getBuild().getOutputDirectory()), vfs);
+ } catch (IOException e) {
+ throw new MojoExecutionException(String.format("Failed to generate files list in '%s'", vfs), e);
+ }
+ }
+ }
+
+ protected void preExec() throws MojoExecutionException {
+ pythonResourcesDirectory = normalizeEmpty(pythonResourcesDirectory);
+ externalDirectory = normalizeEmpty(externalDirectory);
+ resourceDirectory = normalizeEmpty(resourceDirectory);
+ requirementsFile = normalizeEmpty(requirementsFile);
+ packages = packages != null ? new ArrayList<>(packages) : Collections.EMPTY_LIST;
+
+ if(pythonResourcesDirectory != null) {
+ if (externalDirectory != null) {
+ throw new MojoExecutionException(
+ "Cannot use and at the same time. " +
+ "New option is a replacement for deprecated . " +
+ "If you want to deploy the virtual environment into physical filesystem, use . " +
+ "The deployment of the external directory alongside the application is not handled by the GraalPy Maven plugin in such case." +
+ "If you want to bundle the virtual filesystem in Java resources, use . " +
+ "For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ");
+ }
+ getLog().warn("Option is deprecated and will be removed. Use instead.");
+ externalDirectory = pythonResourcesDirectory;
+ }
+
+ if (resourceDirectory != null) {
+ if (resourceDirectory.startsWith("/") || resourceDirectory.endsWith("/")) {
+ throw new MojoExecutionException(
+ "Value of should be relative resources path, i.e., without the leading '/', and it also must not end with trailing '/'");
+ }
+ }
+
+ if (resourceDirectory == null) {
+ if (externalDirectory == null) {
+ getLog().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
+ "This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
+ "Consider adding GRAALPY-VFS/${project.groupId}/${project.artifactId} to your pom.xml, " +
+ "moving any existing sources from '%s' to '%s', and using VirtualFileSystem$Builder#resourceDirectory." +
+ "For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ",
+ VFS_ROOT,
+ Path.of(VFS_ROOT, "src"),
+ Path.of("GRAALPY-VFS", project.getGroupId(), project.getArtifactId())));
+ }
+ resourceDirectory = VFS_ROOT;
+ }
+
+ if(pythonHome != null) {
+ getLog().warn("The GraalPy plugin configuration setting was deprecated and has no effect anymore.\n" +
+ "For execution in jvm mode, the python language home is always available.\n" +
+ "When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
+ "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
+ }
+ }
+
+ protected void postExec() throws MojoExecutionException {
+ for(Resource r : project.getBuild().getResources()) {
+ if (Files.exists(Path.of(r.getDirectory(), resourceDirectory, "proj"))) {
+ getLog().warn(String.format("usage of %s is deprecated, use %s instead", Path.of(resourceDirectory, "proj"), Path.of(resourceDirectory, "src")));
+ }
+ if (!Files.exists(Path.of(r.getDirectory(), resourceDirectory)) && Files.exists(Path.of(r.getDirectory(), "vfs", "proj"))) {
+ // there isn't the actual vfs resource root "org.graalvm.python.vfs" (VFS_ROOT), and there is only the outdated "vfs/proj"
+ // => looks like a project created < 24.1.0
+ throw new MojoExecutionException(String.format(
+ "Wrong virtual filesystem root!\n" +
+ "Since 24.1.0 the virtual filesystem root has to be '%s'.\n" +
+ "Please rename the resource directory '%s' to '%s'", resourceDirectory, Path.of(r.getDirectory(), "vfs"), Path.of(r.getDirectory(), resourceDirectory)));
+ }
+ Path srcPath = Path.of(r.getDirectory(), resourceDirectory, "src");
+ if (externalDirectory != null && Files.exists(srcPath)) {
+ getLog().warn(String.format(
+ "Found Java resources directory %s, however, the GraalPy Maven plugin is configured to use instead of Java resources. " +
+ "The files from %s will not be available in Contexts created using GraalPyResources#contextBuilder(Path). Move them to '%s' if " +
+ "you want to make them available when using external directory, or use Java resources by removing option.",
+ srcPath,
+ srcPath,
+ Path.of(externalDirectory, "src")
+ ));
+ }
+ }
+ }
+
+ protected Path getVenvDirectory() {
+ Path venvDirectory;
+ if(externalDirectory == null) {
+ venvDirectory = Path.of(project.getBuild().getOutputDirectory(), resourceDirectory, VFS_VENV);
+ } else {
+ venvDirectory = Path.of(externalDirectory, VFS_VENV);
+ }
+ return venvDirectory;
+ }
+
+ private static String normalizeEmpty(String s) {
+ if (s == null) {
+ return s;
+ }
+ String trimmed = s.trim();
+ return trimmed.isEmpty() ? null : trimmed;
+ }
+
+ protected Launcher createLauncher() {
+ Launcher launcherArg = new Launcher(getLauncherPath()) {
+ public Set computeClassPath() throws IOException {
+ return calculateLauncherClasspath(project);
+ }
+ };
+ return launcherArg;
+ }
+
+ protected Path getRequirementsFile() {
+ Path rfp = Path.of(requirementsFile);
+ if(rfp.isAbsolute()) {
+ return rfp;
+ } else {
+ return project.getBasedir().toPath().resolve(requirementsFile);
+ }
+ }
+
+ private void delete(Path dir) throws MojoExecutionException {
+ try {
+ try (var s = Files.walk(dir)) {
+ s.sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
+ } catch (IOException e) {
+ new MojoExecutionException(String.format("failed to delete %s", dir), e);
+ }
+ }
+
+ private Path getLauncherPath() {
+ return Paths.get(project.getBuild().getDirectory(), LAUNCHER_NAME);
+ }
+
+ protected static String getGraalPyVersion(MavenProject project) throws IOException {
+ DefaultArtifact a = (DefaultArtifact) getGraalPyArtifact(project);
+ String version = a.getVersion();
+ if(a.isSnapshot()) {
+ // getVersion for a snapshot artefact returns base version + timestamp - e.g. 24.2.0-20240808.200816-1
+ // and there might be snapshot artefacts with different timestamps in the repository.
+ // We should use $baseVersion + "-SNAPSHOT" as maven is in such case
+ // able to properly resolve all project artefacts.
+ version = a.getBaseVersion();
+ if(!version.endsWith("-SNAPSHOT")) {
+ // getBaseVersion is expected to return a version without any additional metadata, e.g. 24.2.0-20240808.200816-1 -> 24.2.0,
+ // but also saw getBaseVersion() already returning version with -SNAPSHOT suffix
+ version = version + "-SNAPSHOT";
+ }
+ }
+ return version;
+ }
+
+ private static Artifact getGraalPyArtifact(MavenProject project) throws IOException {
+ var projectArtifacts = resolveProjectDependencies(project);
+ Artifact graalPyArtifact = projectArtifacts.stream().
+ filter(a -> isPythonArtifact(a))
+ .findFirst()
+ .orElse(null);
+ return Optional.ofNullable(graalPyArtifact).orElseThrow(() -> new IOException("Missing GraalPy dependency. Please add to your pom either %s:%s or %s:%s".formatted(POLYGLOT_GROUP_ID, PYTHON_COMMUNITY_ARTIFACT_ID, POLYGLOT_GROUP_ID, PYTHON_ARTIFACT_ID)));
+ }
+
+ private static boolean isPythonArtifact(Artifact a) {
+ return (POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId())) &&
+ (PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId()) || PYTHON_ARTIFACT_ID.equals(a.getArtifactId()));
+ }
+
+ private static Collection resolveProjectDependencies(MavenProject project) {
+ return project.getArtifacts()
+ .stream()
+ .filter(a -> !"test".equals(a.getScope()))
+ .collect(Collectors.toList());
+ }
+
+ private Set calculateLauncherClasspath(MavenProject project) throws IOException {
+ if(launcherClassPath == null) {
+ String version = getGraalPyVersion(project);
+ launcherClassPath = new HashSet();
+
+ // 1.) python-launcher and transitive dependencies
+ // get the artifact from its direct dependency in graalpy-maven-plugin
+ getLog().debug("calculateLauncherClasspath based on " + GRAALPY_GROUP_ID + ":" + GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID + ":" + version);
+ DefaultArtifact mvnPlugin = new DefaultArtifact(GRAALPY_GROUP_ID, GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID, version, "compile", "jar", null, new DefaultArtifactHandler("pom"));
+ ProjectBuildingResult result = buildProjectFromArtifact(mvnPlugin);
+ Artifact graalPyLauncherArtifact = result.getProject().getArtifacts().stream().filter(a -> GRAALPY_GROUP_ID.equals(a.getGroupId()) && PYTHON_LAUNCHER_ARTIFACT_ID.equals(a.getArtifactId()))
+ .findFirst()
+ .orElse(null);
+ // python-launcher artifact
+ launcherClassPath.add(graalPyLauncherArtifact.getFile().getAbsolutePath());
+ // and transitively all its dependencies
+ launcherClassPath.addAll(resolveDependencies(graalPyLauncherArtifact));
+
+ // 2.) graalpy dependencies
+ Artifact graalPyArtifact = getGraalPyArtifact(project);
+ assert graalPyArtifact != null;
+ launcherClassPath.addAll(resolveDependencies(graalPyArtifact));
+ }
+ return launcherClassPath;
+ }
+
+ private Set resolveDependencies(Artifact artifact) throws IOException {
+ Set dependencies = new HashSet<>();
+ ProjectBuildingResult result = buildProjectFromArtifact(artifact);
+ for(Dependency d : result.getDependencyResolutionResult().getResolvedDependencies()) {
+ addDependency(d, dependencies);
+ }
+ return dependencies;
+ }
+
+ private ProjectBuildingResult buildProjectFromArtifact(Artifact artifact) throws IOException{
+ try{
+ ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
+ buildingRequest.setProject(null);
+ buildingRequest.setResolveDependencies(true);
+ buildingRequest.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
+ buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
+
+ return projectBuilder.build(artifact, buildingRequest);
+ } catch (ProjectBuildingException e) {
+ throw new IOException("Error while building project", e);
+ }
+ }
+
+ private void addDependency(Dependency d, Set dependencies) {
+ File f = d.getArtifact().getFile();
+ if(f != null) {
+ dependencies.add(f.getAbsolutePath());
+ } else {
+ getLog().warn("could not retrieve local file for artifact " + d.getArtifact());
+ }
+ }
+}
+
+
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
new file mode 100644
index 0000000000..b4b85155db
--- /dev/null
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * The Universal Permissive License (UPL), Version 1.0
+ *
+ * Subject to the condition set forth below, permission is hereby granted to any
+ * person obtaining a copy of this software, associated documentation and/or
+ * data (collectively the "Software"), free of charge and under any and all
+ * copyright rights in the Software, and any and all patent rights owned or
+ * freely licensable by each licensor hereunder covering either (i) the
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
+ * the Larger Works (as defined below), to deal in both
+ *
+ * (a) the Software, and
+ *
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
+ * one is included with the Software each a "Larger Work" to which the Software
+ * is contributed by such licensors),
+ *
+ * without restriction, including without limitation the rights to copy, create
+ * derivative works of, display, perform, and distribute the Software and make,
+ * use, sell, offer for sale, import, export, have made, and have sold the
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
+ * either these or other terms.
+ *
+ * This license is subject to the following condition:
+ *
+ * The above copyright notice and either this complete permission notice or at a
+ * minimum a reference to the UPL must be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.graalvm.python.maven.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+import org.graalvm.python.embedding.tools.vfs.VFSUtils;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+@Mojo(name = "freeze-installed-packages",
+ requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME,
+ requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
+public class FreezeInstalledPackagesMojo extends AbstractGraalPyMojo {
+
+ public void execute() throws MojoExecutionException {
+ checkEmptyPackages();
+
+ preExec();
+
+ manageVenv();
+ listGraalPyResources();
+
+ postExec();
+ }
+
+ protected void manageVenv() throws MojoExecutionException {
+ Path venvDirectory = getVenvDirectory();
+ MavenDelegateLog log = new MavenDelegateLog(getLog());
+ Path requirements = getRequirementsFile();
+
+ try {
+ VFSUtils.checkVersionFormat(packages, WRONG_PACKAGE_VERSION_FORMAT_ERROR, log);
+
+ VFSUtils.createVenv(venvDirectory, packages, createLauncher(), getGraalPyVersion(project), log);
+
+ if(Files.exists(venvDirectory)) {
+ VFSUtils.createRequirementsFile(venvDirectory, requirements, REQUIREMENTS_FILE_HEADER, log);
+ } else {
+ // how comes?
+ log.warning("did not generate new python requirements file due to missing venv");
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
+ }
+ }
+
+ private void checkEmptyPackages() throws MojoExecutionException {
+ if((packages == null || packages.isEmpty())) {
+ getLog().error("");
+ getLog().error("In order to run the freeze-installed-packages goal there have to be python packages declared in the graalpy-maven-plugin configuration.");
+ getLog().error("");
+ getLog().error("NOTE that the section has to be declared for the whole graalpy-maven-plugin");
+ getLog().error("and not specifically for the process-graalpy-resources execution goal.");
+ getLog().error("");
+ getLog().error("Please add the section to your configuration as follows:");
+ getLog().error("");
+ getLog().error(" org.graalvm.python ");
+ getLog().error(" graalpy-maven-plugin ");
+ getLog().error(" ");
+ getLog().error(" ");
+ getLog().error(" {package_name}=={package_version} ");
+ getLog().error(" ");
+ getLog().error(" ...");
+ getLog().error(" ");
+ getLog().error("");
+
+ getLog().error("For more information, please refer to https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md");
+ getLog().error("");
+
+ throw new MojoExecutionException("missing packages");
+ }
+ }
+}
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
index 979c2ab9e3..93082fad94 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
@@ -40,324 +40,40 @@
*/
package org.graalvm.python.maven.plugin;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
-
-import org.apache.maven.plugins.annotations.*;
-import org.apache.maven.project.*;
-import org.eclipse.aether.graph.Dependency;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
-import org.graalvm.python.embedding.tools.vfs.VFSUtils.Launcher;
-
-import static org.graalvm.python.embedding.tools.vfs.VFSUtils.GRAALPY_GROUP_ID;
-import static org.graalvm.python.embedding.tools.vfs.VFSUtils.LAUNCHER_NAME;
-import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_ROOT;
-import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_VENV;
+import java.io.IOException;
+import java.nio.file.Path;
@Mojo(name = "process-graalpy-resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
-public class ManageResourcesMojo extends AbstractMojo {
-
- private static final String PYTHON_LAUNCHER_ARTIFACT_ID = "python-launcher";
-
- private static final String POLYGLOT_GROUP_ID = "org.graalvm.polyglot";
- private static final String PYTHON_COMMUNITY_ARTIFACT_ID = "python-community";
- private static final String PYTHON_ARTIFACT_ID = "python";
- private static final String GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID = "graalpy-maven-plugin";
-
- @Parameter(defaultValue = "${project}", required = true, readonly = true)
- MavenProject project;
-
- @Parameter
- String pythonResourcesDirectory;
-
- @Parameter
- String externalDirectory;
-
- @Parameter
- String resourceDirectory;
-
- @Parameter
- List packages;
-
- public static class PythonHome {
- private List includes;
- private List excludes;
- }
-
- @Parameter
- PythonHome pythonHome;
-
- @Parameter(defaultValue = "${session}", readonly = true, required = true)
- private MavenSession session;
-
- @Component
- private ProjectBuilder projectBuilder;
-
- private Set launcherClassPath;
-
- private static String normalizeEmpty(String s) {
- if (s == null) {
- return s;
- }
- String trimmed = s.trim();
- return trimmed.isEmpty() ? null : trimmed;
- }
+public class ManageResourcesMojo extends AbstractGraalPyMojo {
public void execute() throws MojoExecutionException {
- pythonResourcesDirectory = normalizeEmpty(pythonResourcesDirectory);
- externalDirectory = normalizeEmpty(externalDirectory);
- resourceDirectory = normalizeEmpty(resourceDirectory);
-
- if(pythonResourcesDirectory != null) {
- if (externalDirectory != null) {
- throw new MojoExecutionException(
- "Cannot use and at the same time. " +
- "New option is a replacement for deprecated . " +
- "If you want to deploy the virtual environment into physical filesystem, use . " +
- "The deployment of the external directory alongside the application is not handled by the GraalPy Maven plugin in such case." +
- "If you want to bundle the virtual filesystem in Java resources, use . " +
- "For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ");
- }
- getLog().warn("Option is deprecated and will be removed. Use instead.");
- externalDirectory = pythonResourcesDirectory;
- }
-
- if (resourceDirectory != null) {
- if (resourceDirectory.startsWith("/") || resourceDirectory.endsWith("/")) {
- throw new MojoExecutionException(
- "Value of should be relative resources path, i.e., without the leading '/', and it also must not end with trailing '/'");
- }
- }
-
- if (resourceDirectory == null) {
- if (externalDirectory == null) {
- getLog().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
- "This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
- "Consider adding GRAALPY-VFS/${project.groupId}/${project.artifactId} to your pom.xml, " +
- "moving any existing sources from '%s' to '%s', and using VirtualFileSystem$Builder#resourceDirectory." +
- "For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ",
- VFS_ROOT,
- Path.of(VFS_ROOT, "src"),
- Path.of("GRAALPY-VFS", project.getGroupId(), project.getArtifactId())));
- }
- resourceDirectory = VFS_ROOT;
- }
-
- if(pythonHome != null) {
- getLog().warn("The GraalPy plugin configuration setting was deprecated and has no effect anymore.\n" +
- "For execution in jvm mode, the python language home is always available.\n" +
- "When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
- "For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
- }
+ preExec();
manageVenv();
listGraalPyResources();
manageNativeImageConfig();
- for(Resource r : project.getBuild().getResources()) {
- if (Files.exists(Path.of(r.getDirectory(), resourceDirectory, "proj"))) {
- getLog().warn(String.format("usage of %s is deprecated, use %s instead", Path.of(resourceDirectory, "proj"), Path.of(resourceDirectory, "src")));
- }
- if (!Files.exists(Path.of(r.getDirectory(), resourceDirectory)) && Files.exists(Path.of(r.getDirectory(), "vfs", "proj"))) {
- // there isn't the actual vfs resource root "org.graalvm.python.vfs" (VFS_ROOT), and there is only the outdated "vfs/proj"
- // => looks like a project created < 24.1.0
- throw new MojoExecutionException(String.format(
- "Wrong virtual filesystem root!\n" +
- "Since 24.1.0 the virtual filesystem root has to be '%s'.\n" +
- "Please rename the resource directory '%s' to '%s'", resourceDirectory, Path.of(r.getDirectory(), "vfs"), Path.of(r.getDirectory(), resourceDirectory)));
- }
- Path srcPath = Path.of(r.getDirectory(), resourceDirectory, "src");
- if (externalDirectory != null && Files.exists(srcPath)) {
- getLog().warn(String.format(
- "Found Java resources directory %s, however, the GraalPy Maven plugin is configured to use instead of Java resources. " +
- "The files from %s will not be available in Contexts created using GraalPyResources#contextBuilder(Path). Move them to '%s' if " +
- "you want to make them available when using external directory, or use Java resources by removing option.",
- srcPath,
- srcPath,
- Path.of(externalDirectory, "src")
- ));
- }
- }
-
- }
-
- private void manageNativeImageConfig() throws MojoExecutionException {
- try {
- VFSUtils.writeNativeImageConfig(Path.of(project.getBuild().getOutputDirectory(), "META-INF"), GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID, resourceDirectory);
- } catch (IOException e) {
- throw new MojoExecutionException("failed to create native image configuration files", e);
- }
- }
-
- private void listGraalPyResources() throws MojoExecutionException {
- Path vfs = Path.of(project.getBuild().getOutputDirectory(), resourceDirectory);
- if (Files.exists(vfs)) {
- try {
- VFSUtils.generateVFSFilesList(Path.of(project.getBuild().getOutputDirectory()), vfs);
- } catch (IOException e) {
- throw new MojoExecutionException(String.format("Failed to generate files list in '%s'", vfs), e);
- }
- }
+ postExec();
}
private void manageVenv() throws MojoExecutionException {
- Path venvDirectory;
- if(externalDirectory == null) {
- venvDirectory = Path.of(project.getBuild().getOutputDirectory(), resourceDirectory, VFS_VENV);
- } else {
- venvDirectory = Path.of(externalDirectory, VFS_VENV);
- }
-
+ Path venvDirectory = getVenvDirectory();
+ MavenDelegateLog log = new MavenDelegateLog(getLog());
+ Path requirements = getRequirementsFile();
try {
- if (packages == null && externalDirectory == null) {
- getLog().info(String.format("No venv packages declared, deleting %s", venvDirectory));
- delete(venvDirectory);
- return;
- }
-
- Launcher launcher = new Launcher( getLauncherPath()) {
- public Set computeClassPath() throws IOException {
- return calculateLauncherClasspath(project);
- }
- };
-
- VFSUtils.createVenv(venvDirectory, new ArrayList(packages), launcher, getGraalPyVersion(project), new MavenDelegateLog(getLog()));
+ VFSUtils.createVenv(venvDirectory, packages, requirements, INCONSISTENT_PACKAGES_ERROR, WRONG_PACKAGE_VERSION_FORMAT_ERROR, createLauncher(), getGraalPyVersion(project), log);
+ VFSUtils.warnMissingRequirementsFile(requirements, MISSING_REQUIREMENTS_FILE_WARNING, log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
}
}
- private void delete(Path dir) throws MojoExecutionException {
- try {
- try (var s = Files.walk(dir)) {
- s.sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
- }
- } catch (IOException e) {
- new MojoExecutionException(String.format("failed to delete %s", dir), e);
- }
- }
-
- private Path getLauncherPath() {
- return Paths.get(project.getBuild().getDirectory(), LAUNCHER_NAME);
- }
-
- private static String getGraalPyVersion(MavenProject project) throws IOException {
- DefaultArtifact a = (DefaultArtifact) getGraalPyArtifact(project);
- String version = a.getVersion();
- if(a.isSnapshot()) {
- // getVersion for a snapshot artefact returns base version + timestamp - e.g. 24.2.0-20240808.200816-1
- // and there might be snapshot artefacts with different timestamps in the repository.
- // We should use $baseVersion + "-SNAPSHOT" as maven is in such case
- // able to properly resolve all project artefacts.
- version = a.getBaseVersion();
- if(!version.endsWith("-SNAPSHOT")) {
- // getBaseVersion is expected to return a version without any additional metadata, e.g. 24.2.0-20240808.200816-1 -> 24.2.0,
- // but also saw getBaseVersion() already returning version with -SNAPSHOT suffix
- version = version + "-SNAPSHOT";
- }
- }
- return version;
- }
-
- private static Artifact getGraalPyArtifact(MavenProject project) throws IOException {
- var projectArtifacts = resolveProjectDependencies(project);
- Artifact graalPyArtifact = projectArtifacts.stream().
- filter(a -> isPythonArtifact(a))
- .findFirst()
- .orElse(null);
- return Optional.ofNullable(graalPyArtifact).orElseThrow(() -> new IOException("Missing GraalPy dependency. Please add to your pom either %s:%s or %s:%s".formatted(POLYGLOT_GROUP_ID, PYTHON_COMMUNITY_ARTIFACT_ID, POLYGLOT_GROUP_ID, PYTHON_ARTIFACT_ID)));
- }
-
- private static boolean isPythonArtifact(Artifact a) {
- return (POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId())) &&
- (PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId()) || PYTHON_ARTIFACT_ID.equals(a.getArtifactId()));
- }
-
- private static Collection resolveProjectDependencies(MavenProject project) {
- return project.getArtifacts()
- .stream()
- .filter(a -> !"test".equals(a.getScope()))
- .collect(Collectors.toList());
- }
-
- private Set calculateLauncherClasspath(MavenProject project) throws IOException {
- if(launcherClassPath == null) {
- String version = getGraalPyVersion(project);
- launcherClassPath = new HashSet();
-
- // 1.) python-launcher and transitive dependencies
- // get the artifact from its direct dependency in graalpy-maven-plugin
- getLog().debug("calculateLauncherClasspath based on " + GRAALPY_GROUP_ID + ":" + GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID + ":" + version);
- DefaultArtifact mvnPlugin = new DefaultArtifact(GRAALPY_GROUP_ID, GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID, version, "compile", "jar", null, new DefaultArtifactHandler("pom"));
- ProjectBuildingResult result = buildProjectFromArtifact(mvnPlugin);
- Artifact graalPyLauncherArtifact = result.getProject().getArtifacts().stream().filter(a -> GRAALPY_GROUP_ID.equals(a.getGroupId()) && PYTHON_LAUNCHER_ARTIFACT_ID.equals(a.getArtifactId()))
- .findFirst()
- .orElse(null);
- // python-launcher artifact
- launcherClassPath.add(graalPyLauncherArtifact.getFile().getAbsolutePath());
- // and transitively all its dependencies
- launcherClassPath.addAll(resolveDependencies(graalPyLauncherArtifact));
-
- // 2.) graalpy dependencies
- Artifact graalPyArtifact = getGraalPyArtifact(project);
- assert graalPyArtifact != null;
- launcherClassPath.addAll(resolveDependencies(graalPyArtifact));
- }
- return launcherClassPath;
- }
-
- private Set resolveDependencies(Artifact artifact) throws IOException {
- Set dependencies = new HashSet<>();
- ProjectBuildingResult result = buildProjectFromArtifact(artifact);
- for(Dependency d : result.getDependencyResolutionResult().getResolvedDependencies()) {
- addDependency(d, dependencies);
- }
- return dependencies;
- }
-
- private ProjectBuildingResult buildProjectFromArtifact(Artifact artifact) throws IOException{
- try{
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
- buildingRequest.setProject(null);
- buildingRequest.setResolveDependencies(true);
- buildingRequest.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
- buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
-
- return projectBuilder.build(artifact, buildingRequest);
- } catch (ProjectBuildingException e) {
- throw new IOException("Error while building project", e);
- }
- }
-
- private void addDependency(Dependency d, Set dependencies) {
- File f = d.getArtifact().getFile();
- if(f != null) {
- dependencies.add(f.getAbsolutePath());
- } else {
- getLog().warn("could not retrieve local file for artifact " + d.getArtifact());
- }
- }
}
-
-
From d4476c1d1e48f7fe87c2c02be72de393afa2bdb8 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Mon, 27 Jan 2025 14:51:51 +0100
Subject: [PATCH 051/512] fixed VirtualFileSystemTest to run also on windows
---
.../embedding/test/VirtualFileSystemTest.java | 48 ++-
.../test/VirtualFileSystemUtilsTest.java | 283 +++++++++++-------
.../embedding/vfs/test/VFSUtilsTest.java | 30 +-
.../python/embedding/tools/vfs/VFSUtils.java | 2 +-
4 files changed, 206 insertions(+), 157 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
index c7189d6269..d4225c11d6 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemTest.java
@@ -250,21 +250,36 @@ public void toAbsolutePath() throws Exception {
p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME));
assertTrue(p.isAbsolute());
assertEquals(VFS_ROOT_PATH, p.normalize());
- }
- // ../../../VFS_ROOT/../real/fs/path
- p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME, "..", realFSPath.toString()));
- assertTrue(p.isAbsolute());
- assertEquals(realFSPath, p.normalize());
+ // ../../../VFS_ROOT/../real/fs/path
+ p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME, "..", realFSPath.toString()));
+ assertTrue(p.isAbsolute());
+ assertEquals(realFSPath, p.normalize());
- // CWD is VFS_ROOT, relative path pointing to real FS
- // ../real/fs/path
- if (!IS_WINDOWS) {
+ // CWD is VFS_ROOT, relative path pointing to real FS
+ // ../real/fs/path
withCWD(fs, VFS_ROOT_PATH, (fst) -> {
Path pp = fst.toAbsolutePath(Path.of("..", realFSPath.toString()));
assertTrue(pp.isAbsolute());
assertEquals(realFSPath, pp.normalize());
});
+
+ // CWD is real FS, relative path pointing to VFS
+ // real/fs/path/../../
+ withCWD(fs, realFSPath.getParent(), (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME));
+ assertTrue(pp.isAbsolute());
+ assertEquals(VFS_ROOT_PATH, pp.normalize());
+ });
+
+ // CWD is real FS, relative path pointing through VFS to real FS
+ // real/fs/path/../../../VFS
+ withCWD(fs, realFSPath.getParent(),
+ (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME, "..", realFSPath.toString()));
+ assertTrue(pp.isAbsolute());
+ assertEquals(realFSPath, pp.normalize());
+ });
}
// CWD is VFS_ROOT, relative path pointing through real FS back to VFS
@@ -275,23 +290,6 @@ public void toAbsolutePath() throws Exception {
assertEquals(VFS_ROOT_PATH, pp.normalize());
});
- // CWD is real FS, relative path pointing to VFS
- // real/fs/path/../../
- withCWD(fs, realFSPath.getParent(), (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME));
- assertTrue(pp.isAbsolute());
- assertEquals(VFS_ROOT_PATH, pp.normalize());
- });
-
- // CWD is real FS, relative path pointing through VFS to real FS
- // real/fs/path/../../../VFS
- withCWD(fs, realFSPath.getParent(),
- (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME, "..", realFSPath.toString()));
- assertTrue(pp.isAbsolute());
- assertEquals(realFSPath, pp.normalize());
- });
-
assertEquals(Path.of("extractme").toAbsolutePath(), fs.toAbsolutePath(Path.of("extractme")));
withCWD(fs, realFSPath.getParent(), (fst) -> assertEquals(realFSPath, fst.toAbsolutePath(realFSPath.getFileName())));
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
index d21538f877..26413f70a1 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
@@ -88,6 +88,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Simple copy of VirtualFileSystemTest to test also the deprecated
@@ -132,23 +133,23 @@ public VirtualFileSystemUtilsTest() {
@Before
public void initFS() throws Exception {
rwHostIOVFS = getDelegatingFS(VirtualFileSystem.newBuilder().//
- allowHostIO(READ_WRITE).//
+ allowHostIO(VirtualFileSystem.HostIO.READ_WRITE).//
unixMountPoint(VFS_UNIX_MOUNT_POINT).//
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
extractFilter(p -> p.getFileName().toString().endsWith("extractme")).//
- resourceLoadingClass(VirtualFileSystemUtilsTest.class).build());
+ resourceLoadingClass(VirtualFileSystemTest.class).build());
rHostIOVFS = getDelegatingFS(VirtualFileSystem.newBuilder().//
- allowHostIO(READ).//
+ allowHostIO(VirtualFileSystem.HostIO.READ).//
unixMountPoint(VFS_UNIX_MOUNT_POINT).//
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
extractFilter(p -> p.getFileName().toString().endsWith("extractme")).//
- resourceLoadingClass(VirtualFileSystemUtilsTest.class).build());
+ resourceLoadingClass(VirtualFileSystemTest.class).build());
noHostIOVFS = getDelegatingFS(VirtualFileSystem.newBuilder().//
- allowHostIO(NONE).//
+ allowHostIO(VirtualFileSystem.HostIO.NONE).//
unixMountPoint(VFS_UNIX_MOUNT_POINT).//
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
extractFilter(p -> p.getFileName().toString().endsWith("extractme")).//
- resourceLoadingClass(VirtualFileSystemUtilsTest.class).build());
+ resourceLoadingClass(VirtualFileSystemTest.class).build());
}
@After
@@ -176,7 +177,9 @@ public void toRealPath() throws Exception {
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
assertTrue(Files.isSameFile(realFSPath, fs.toRealPath(realFSPath)));
withCWD(fs, realFSDir, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.getParent().getFileName().toString(), "extractme")))));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.toString())))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(Files.isSameFile(realFSPath, fst.toRealPath(Path.of("..", realFSPath.toString())))));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.toRealPath(realFSPath), "expected error for no host io fs");
}
@@ -232,8 +235,10 @@ public void toAbsolutePath() throws Exception {
// absolute path starting with VFS, pointing to real FS
// /VFS_ROOT/../real/fs/path/
- p = Path.of(VFS_MOUNT_POINT, "..", realFSPath.toString());
- assertEquals(p, fs.toAbsolutePath(p));
+ if (!IS_WINDOWS) {
+ p = Path.of(VFS_MOUNT_POINT, "..", realFSPath.toString());
+ assertEquals(p, fs.toAbsolutePath(p));
+ }
// absolute path starting with real FS, pointing to VFS
// /real/fs/path/../../../VFS_MOUNT_POINT
@@ -247,22 +252,41 @@ public void toAbsolutePath() throws Exception {
// no CWD set, so relative path starting in real FS, pointing to VFS
// ../../../VFS_ROOT
Path cwd = Path.of(".").toAbsolutePath();
- p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME));
- assertTrue(p.isAbsolute());
- assertEquals(VFS_ROOT_PATH, p.normalize());
-
- // ../../../VFS_ROOT/../real/fs/path
- p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME, "..", realFSPath.toString()));
- assertTrue(p.isAbsolute());
- assertEquals(realFSPath, p.normalize());
-
- // CWD is VFS_ROOT, relative path pointing to real FS
- // ../real/fs/path
- withCWD(fs, VFS_ROOT_PATH, (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("..", realFSPath.toString()));
- assertTrue(pp.isAbsolute());
- assertEquals(realFSPath, pp.normalize());
- });
+ if (!IS_WINDOWS) {
+ p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME));
+ assertTrue(p.isAbsolute());
+ assertEquals(VFS_ROOT_PATH, p.normalize());
+
+ // ../../../VFS_ROOT/../real/fs/path
+ p = fs.toAbsolutePath(Path.of(dotdot(cwd.getNameCount()).toString(), MOUNT_POINT_NAME, "..", realFSPath.toString()));
+ assertTrue(p.isAbsolute());
+ assertEquals(realFSPath, p.normalize());
+
+ // CWD is VFS_ROOT, relative path pointing to real FS
+ // ../real/fs/path
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("..", realFSPath.toString()));
+ assertTrue(pp.isAbsolute());
+ assertEquals(realFSPath, pp.normalize());
+ });
+
+ // CWD is real FS, relative path pointing to VFS
+ // real/fs/path/../../
+ withCWD(fs, realFSPath.getParent(), (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME));
+ assertTrue(pp.isAbsolute());
+ assertEquals(VFS_ROOT_PATH, pp.normalize());
+ });
+
+ // CWD is real FS, relative path pointing through VFS to real FS
+ // real/fs/path/../../../VFS
+ withCWD(fs, realFSPath.getParent(),
+ (fst) -> {
+ Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME, "..", realFSPath.toString()));
+ assertTrue(pp.isAbsolute());
+ assertEquals(realFSPath, pp.normalize());
+ });
+ }
// CWD is VFS_ROOT, relative path pointing through real FS back to VFS
// ../some/path/../../VFS_ROOT_PATH
@@ -272,23 +296,6 @@ public void toAbsolutePath() throws Exception {
assertEquals(VFS_ROOT_PATH, pp.normalize());
});
- // CWD is real FS, relative path pointing to VFS
- // real/fs/path/../../
- withCWD(fs, realFSPath.getParent(), (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME));
- assertTrue(pp.isAbsolute());
- assertEquals(VFS_ROOT_PATH, pp.normalize());
- });
-
- // CWD is real FS, relative path pointing through VFS to real FS
- // real/fs/path/../../../VFS
- withCWD(fs, realFSPath.getParent(),
- (fst) -> {
- Path pp = fst.toAbsolutePath(Path.of("dir", dotdot(realFSDirDir.getNameCount()), MOUNT_POINT_NAME, "..", realFSPath.toString()));
- assertTrue(pp.isAbsolute());
- assertEquals(realFSPath, pp.normalize());
- });
-
assertEquals(Path.of("extractme").toAbsolutePath(), fs.toAbsolutePath(Path.of("extractme")));
withCWD(fs, realFSPath.getParent(), (fst) -> assertEquals(realFSPath, fst.toAbsolutePath(realFSPath.getFileName())));
@@ -384,7 +391,9 @@ public void checkAccess() throws Exception {
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
fs.checkAccess(realFSPath, Set.of(AccessMode.READ));
withCWD(fs, realFSPath.getParent(), (fst) -> fst.checkAccess(realFSPath.getFileName(), Set.of(AccessMode.READ)));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.checkAccess(Path.of("..", realFSPath.toString()), Set.of(AccessMode.READ)));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.checkAccess(Path.of("..", realFSPath.toString()), Set.of(AccessMode.READ)));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.checkAccess(realFSPath, Set.of(AccessMode.READ)), "expected error for no host io fs");
}
@@ -445,12 +454,14 @@ public void createDirectory() throws Exception {
fs.createDirectory(newDir2.getFileName());
assertTrue(Files.exists(newDir2));
});
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> {
- Path newDir3 = newDir.getParent().resolve("newdir3");
- assertFalse(Files.exists(newDir3));
- fs.createDirectory(Path.of("..", newDir3.toString()));
- assertTrue(Files.exists(newDir3));
- });
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> {
+ Path newDir3 = newDir.getParent().resolve("newdir3");
+ assertFalse(Files.exists(newDir3));
+ fs.createDirectory(Path.of("..", newDir3.toString()));
+ assertTrue(Files.exists(newDir3));
+ });
+ }
}
@Test
@@ -484,10 +495,12 @@ public void delete() throws Exception {
withCWD(rwHostIOVFS, realFSPath.getParent(), (fs) -> rwHostIOVFS.delete(realFSPath.getFileName()));
assertFalse(Files.exists(realFSPath));
- Files.createFile(realFSPath);
- assertTrue(Files.exists(realFSPath));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.delete(Path.of("..", realFSPath.toString())));
- assertFalse(Files.exists(realFSPath));
+ if (!IS_WINDOWS) {
+ Files.createFile(realFSPath);
+ assertTrue(Files.exists(realFSPath));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.delete(Path.of("..", realFSPath.toString())));
+ assertFalse(Files.exists(realFSPath));
+ }
}
private static void deleteVFS(FileSystem fs, String pathPrefix) {
@@ -520,13 +533,17 @@ public void newByteChannel() throws Exception {
Path realFSPath = Files.createTempDirectory("graalpy.vfs.test").resolve("extractme");
Files.createFile(realFSPath);
checkException(SecurityException.class, () -> rHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE)), "cant write into a read-only host FS");
- rwHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSPath, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("text".getBytes()));
+ }
assertTrue(Files.exists(realFSPath));
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
newByteChannelRealFS(fs, realFSPath, "text");
withCWD(fs, realFSPath.getParent(), (fst) -> newByteChannelRealFS(fs, realFSPath.getFileName(), "text"));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newByteChannelRealFS(fs, Path.of("..", realFSPath.toString()), "text"));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newByteChannelRealFS(fs, Path.of("..", realFSPath.toString()), "text"));
+ }
}
}
@@ -549,26 +566,28 @@ private static void newByteChannelVFS(FileSystem fs, String pathPrefix) throws I
}
private static void newByteChannelVFS(FileSystem fs, Path path, Set options) throws IOException {
- SeekableByteChannel bch = fs.newByteChannel(path, options);
- ByteBuffer buffer = ByteBuffer.allocate(1024);
- bch.read(buffer);
- String s = new String(buffer.array());
- String[] ss = s.split(System.lineSeparator());
- assertTrue(ss.length >= 2);
- assertEquals("text1", ss[0]);
- assertEquals("text2", ss[1]);
- checkException(NonWritableChannelException.class, () -> bch.write(buffer), "should not be able to write to VFS");
- checkException(NonWritableChannelException.class, () -> bch.truncate(0), "should not be able to write to VFS");
+ try (SeekableByteChannel bch = fs.newByteChannel(path, options)) {
+ ByteBuffer buffer = ByteBuffer.allocate(1024);
+ bch.read(buffer);
+ String s = new String(buffer.array());
+ String[] ss = s.split(System.lineSeparator());
+ assertTrue(ss.length >= 2);
+ assertEquals("text1", ss[0]);
+ assertEquals("text2", ss[1]);
+ checkException(NonWritableChannelException.class, () -> bch.write(buffer), "should not be able to write to VFS");
+ checkException(NonWritableChannelException.class, () -> bch.truncate(0), "should not be able to write to VFS");
+ }
}
private static void newByteChannelRealFS(FileSystem fs, Path path, String expectedText) throws IOException {
- SeekableByteChannel bch = fs.newByteChannel(path, Set.of(StandardOpenOption.READ));
- ByteBuffer buffer = ByteBuffer.allocate(expectedText.length());
- bch.read(buffer);
- String s = new String(buffer.array());
- String[] ss = s.split(System.lineSeparator());
- assertTrue(ss.length >= 1);
- assertEquals(expectedText, ss[0]);
+ try (SeekableByteChannel bch = fs.newByteChannel(path, Set.of(StandardOpenOption.READ))) {
+ ByteBuffer buffer = ByteBuffer.allocate(expectedText.length());
+ bch.read(buffer);
+ String s = new String(buffer.array());
+ String[] ss = s.split(System.lineSeparator());
+ assertTrue(ss.length >= 1);
+ assertEquals(expectedText, ss[0]);
+ }
}
private static void checkCanOnlyRead(FileSystem fs, Path path, StandardOpenOption... options) {
@@ -595,11 +614,13 @@ public void newDirectoryStream() throws Exception {
checkException(NotDirectoryException.class, () -> fs.newDirectoryStream(realFSFile, (p) -> true));
newDirectoryStreamRealFS(fs, realFSDir, realFSFile);
withCWD(fs, realFSDir.getParent(), (fst) -> newDirectoryStreamRealFS(fs, realFSDir.getFileName(), realFSFile));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
- // from real fs to VFS
- withCWD(fs, realFSDir, (fst) -> newDirectoryStreamVFS(fs, Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT).toString()));
- // from VFS to real FS
- withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ // from real fs to VFS
+ withCWD(fs, realFSDir, (fst) -> newDirectoryStreamVFS(fs, Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT).toString()));
+ // from VFS to real FS
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> newDirectoryStreamRealFS(fs, Path.of("..", realFSDir.toString()), realFSFile));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.newDirectoryStream(realFSDir, null), "expected error for no host io fs");
}
@@ -650,7 +671,9 @@ public void readAttributes() throws Exception {
for (FileSystem fs : new FileSystem[]{rHostIOVFS, rwHostIOVFS}) {
assertTrue(((FileTime) fs.readAttributes(realFSPath, "creationTime").get("creationTime")).toMillis() > 0);
withCWD(fs, realFSPath.getParent(), (fst) -> assertTrue(((FileTime) fs.readAttributes(realFSPath.getFileName(), "creationTime").get("creationTime")).toMillis() > 0));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(((FileTime) fs.readAttributes(Path.of("..", realFSPath.toString()), "creationTime").get("creationTime")).toMillis() > 0));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(((FileTime) fs.readAttributes(Path.of("..", realFSPath.toString()), "creationTime").get("creationTime")).toMillis() > 0));
+ }
}
checkException(SecurityException.class, () -> noHostIOVFS.readAttributes(realFSPath, "creationTime"), "expected error for no host io fs");
@@ -683,7 +706,7 @@ public void libsExtract() throws Exception {
unixMountPoint(VFS_MOUNT_POINT).//
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
extractFilter(p -> p.getFileName().toString().endsWith(".tso")).//
- resourceLoadingClass(VirtualFileSystemUtilsTest.class).build()) {
+ resourceLoadingClass(VirtualFileSystemTest.class).build()) {
FileSystem fs = getDelegatingFS(vfs);
Path p = fs.toRealPath(VFS_ROOT_PATH.resolve("site-packages/testpkg/file.tso"));
checkExtractedFile(p, null);
@@ -721,7 +744,7 @@ public void noExtractFilter() throws Exception {
unixMountPoint(VFS_MOUNT_POINT).//
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
extractFilter(null).//
- resourceLoadingClass(VirtualFileSystemUtilsTest.class).build()) {
+ resourceLoadingClass(VirtualFileSystemTest.class).build()) {
FileSystem fs = getDelegatingFS(vfs);
assertEquals(23, checkNotExtracted(fs, VFS_ROOT_PATH));
}
@@ -827,8 +850,10 @@ public void getMimeType() throws Exception {
checkException(NullPointerException.class, () -> fs.getMimeType(null));
Assert.assertNull(fs.getMimeType(VFS_ROOT_PATH));
fs.getMimeType(realFSPath);
- // whatever the return value, just check it does not fail
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getMimeType(Path.of("..", realFSPath.toString())));
+ if (!IS_WINDOWS) {
+ // whatever the return value, just check it does not fail
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getMimeType(Path.of("..", realFSPath.toString())));
+ }
}
}
@@ -840,8 +865,10 @@ public void getEncoding() throws Exception {
checkException(NullPointerException.class, () -> fs.getEncoding(null));
Assert.assertNull(fs.getEncoding(VFS_ROOT_PATH));
fs.getEncoding(realFSPath);
- // whatever the return value, just check it does not fail
- withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getEncoding(Path.of("..", realFSPath.toString())));
+ if (!IS_WINDOWS) {
+ // whatever the return value, just check it does not fail
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> fst.getEncoding(Path.of("..", realFSPath.toString())));
+ }
}
}
@@ -858,7 +885,9 @@ public void setAttribute() throws Exception {
// just check it does not fail for real FS paths
rwHostIOVFS.setAttribute(realFSPath, "creationTime", FileTime.fromMillis(42));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.setAttribute(Path.of("..", realFSPath.toString()), "creationTime", FileTime.fromMillis(43)));
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.setAttribute(Path.of("..", realFSPath.toString()), "creationTime", FileTime.fromMillis(43)));
+ }
}
@Test
@@ -876,9 +905,13 @@ public void isSameFile() throws Exception {
assertFalse(fs.isSameFile(realFSDir, VFS_ROOT_PATH));
assertFalse(fs.isSameFile(VFS_ROOT_PATH, realFSDir));
if (fs == noHostIOVFS) {
- withCWD(fs, VFS_ROOT_PATH, (fst) -> checkException(SecurityException.class, () -> fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> checkException(SecurityException.class, () -> fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ }
} else {
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertTrue(fst.isSameFile(realFSDir, Path.of("..", realFSDir.toString()))));
+ }
withCWD(fs, realFSDir, (fst) -> assertTrue(fs.isSameFile(realFSFile1.getFileName(), realFSFile1.getFileName())));
withCWD(fs, realFSDir, (fst) -> assertFalse(fs.isSameFile(realFSFile1.getFileName(), realFSFile2.getFileName())));
}
@@ -906,8 +939,10 @@ public void createLink() throws Exception {
assertTrue(Files.exists(link));
Path link2 = realFSDir.resolve("link2");
assertFalse(Files.exists(link2));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.createLink(Path.of("..", link2.toString()), Path.of("..", realFSFile.toString())));
- assertTrue(Files.exists(link2));
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> rwHostIOVFS.createLink(Path.of("..", link2.toString()), Path.of("..", realFSFile.toString())));
+ assertTrue(Files.exists(link2));
+ }
checkException(SecurityException.class, () -> rHostIOVFS.createLink(realFSDir.resolve("link3"), realFSFile));
checkException(SecurityException.class, () -> noHostIOVFS.createLink(realFSDir.resolve("link4"), realFSFile));
@@ -936,10 +971,12 @@ public void createAndReadSymbolicLink() throws Exception {
rwHostIOVFS.createSymbolicLink(symlink, realFSLinkTarget);
checkSymlink(realFSDir, realFSLinkTarget, symlink);
- Files.delete(symlink);
- assertFalse(Files.exists(symlink));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.createSymbolicLink(Path.of("..", symlink.toString()), realFSLinkTarget));
- checkSymlink(realFSDir, realFSLinkTarget, symlink);
+ if (!IS_WINDOWS) {
+ Files.delete(symlink);
+ assertFalse(Files.exists(symlink));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fst) -> fst.createSymbolicLink(Path.of("..", symlink.toString()), realFSLinkTarget));
+ checkSymlink(realFSDir, realFSLinkTarget, symlink);
+ }
}
private void checkSymlink(Path dir, Path target, Path symlink) throws Exception {
@@ -947,8 +984,10 @@ private void checkSymlink(Path dir, Path target, Path symlink) throws Exception
checkException(SecurityException.class, () -> noHostIOVFS.readSymbolicLink(symlink));
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS}) {
assertEquals(target, fs.readSymbolicLink(symlink));
- withCWD(fs, VFS_ROOT_PATH, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of("..", symlink.toString()))));
- withCWD(fs, dir, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of(dotdot(dir.getNameCount()), "..", VFS_MOUNT_POINT, "..", symlink.toString()))));
+ if (!IS_WINDOWS) {
+ withCWD(fs, VFS_ROOT_PATH, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of("..", symlink.toString()))));
+ withCWD(fs, dir, (fst) -> assertEquals(target, fst.readSymbolicLink(Path.of(dotdot(dir.getNameCount()), "..", VFS_MOUNT_POINT, "..", symlink.toString()))));
+ }
}
}
@@ -991,7 +1030,9 @@ public void move() throws Exception {
checkException(SecurityException.class, () -> fs.move(VFS_ROOT_PATH.resolve("file1"), VFS_ROOT_PATH.resolve("file2")));
}
- rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("moved text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("moved text".getBytes()));
+ }
assertTrue(Files.exists(realFSSource));
assertFalse(Files.exists(realFSTarget));
rwHostIOVFS.move(realFSSource, realFSTarget);
@@ -1004,12 +1045,15 @@ public void move() throws Exception {
assertTrue(Files.exists(realFSSource2));
assertFalse(Files.exists(realFSTarget2));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.move(Path.of("..", realFSSource2.toString()), Path.of("..", realFSTarget2.toString())));
- assertFalse(Files.exists(realFSSource2));
- assertTrue(Files.exists(realFSTarget2));
- newByteChannelRealFS(rwHostIOVFS, realFSSource, "moved text");
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.move(Path.of("..", realFSSource2.toString()), Path.of("..", realFSTarget2.toString())));
+ assertFalse(Files.exists(realFSSource2));
+ assertTrue(Files.exists(realFSTarget2));
+ newByteChannelRealFS(rwHostIOVFS, realFSSource, "moved text");
+ }
- checkException(IOException.class, () -> rHostIOVFS.move(realFSSource2, realFSTarget2));
+ Class> exCls = IS_WINDOWS ? SecurityException.class : IOException.class;
+ checkException(exCls, () -> rHostIOVFS.move(realFSSource2, realFSTarget2));
checkException(SecurityException.class, () -> noHostIOVFS.move(realFSSource2, realFSTarget2));
}
@@ -1033,7 +1077,9 @@ public void copy() throws Exception {
checkException(SecurityException.class, () -> noHostIOVFS.copy(realFSSource, realFSTarget));
Files.createFile(realFSSource);
- rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE)).write(ByteBuffer.wrap("copied text".getBytes()));
+ try (SeekableByteChannel ch = rwHostIOVFS.newByteChannel(realFSSource, Set.of(StandardOpenOption.WRITE))) {
+ ch.write(ByteBuffer.wrap("copied text".getBytes()));
+ }
assertTrue(Files.exists(realFSSource));
rwHostIOVFS.copy(realFSSource, realFSTarget);
@@ -1041,11 +1087,13 @@ public void copy() throws Exception {
assertTrue(Files.exists(realFSTarget));
newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
- Files.delete(realFSTarget);
- assertFalse(Files.exists(realFSTarget));
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("..", realFSSource.toString()), Path.of("..", realFSTarget.toString())));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
+ if (!IS_WINDOWS) {
+ Files.delete(realFSTarget);
+ assertFalse(Files.exists(realFSTarget));
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("..", realFSSource.toString()), Path.of("..", realFSTarget.toString())));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "copied text");
+ }
Files.delete(realFSTarget);
assertFalse(Files.exists(realFSTarget));
@@ -1059,11 +1107,13 @@ public void copy() throws Exception {
assertTrue(Files.exists(realFSTarget));
newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
- Files.delete(realFSTarget);
- assertFalse(Files.exists(realFSTarget));
- withCWD(rwHostIOVFS, realFSDir, (fs) -> fs.copy(Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT, "file1"), realFSTarget));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ if (!IS_WINDOWS) {
+ Files.delete(realFSTarget);
+ assertFalse(Files.exists(realFSTarget));
+ withCWD(rwHostIOVFS, realFSDir, (fs) -> fs.copy(Path.of(dotdot(realFSDir.getNameCount()), VFS_MOUNT_POINT, "file1"), realFSTarget));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ }
Files.delete(realFSTarget);
assertFalse(Files.exists(realFSTarget));
@@ -1078,10 +1128,11 @@ public void copy() throws Exception {
assertFalse(Files.exists(realFSTarget));
// no host IO
-
- withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("..", realFSTarget.toString())));
- assertTrue(Files.exists(realFSTarget));
- newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ if (!IS_WINDOWS) {
+ withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("..", realFSTarget.toString())));
+ assertTrue(Files.exists(realFSTarget));
+ newByteChannelRealFS(rwHostIOVFS, realFSTarget, "text1");
+ }
}
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
index 7f3249535f..5c77509d4d 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
@@ -510,54 +510,54 @@ public void packageConsistency() throws Exception {
Path requirements = tmpDir.resolve("requirements.txt");
Files.createFile(requirements);
- callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST);
+ callPackageConsistencyCheck(log, Collections.EMPTY_LIST);
assertFalse(log.output.toString().contains("inconsistent package"));
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST, "pkg1"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, Collections.EMPTY_LIST, "pkg1"));
assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
log.clearOutput();
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, Collections.EMPTY_LIST, "pkg1==1"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, Collections.EMPTY_LIST, "pkg1==1"));
assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg1==1'", requirements)));
log.clearOutput();
final List requirementsList = Arrays.asList("pkg1==1.0.0");
Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg1"));
assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
log.clearOutput();
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg2"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg2"));
assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
log.clearOutput();
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList, "pkg2==1"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg2==1"));
assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==1'", requirements)));
log.clearOutput();
- callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1==1.0");
+ callPackageConsistencyCheck(log, requirementsList, "pkg1==1.0");
log.clearOutput();
- callPackageConsistencyCheck(requirements, log, requirementsList, "pkg1==1.0.0");
+ callPackageConsistencyCheck(log, requirementsList, "pkg1==1.0.0");
log.clearOutput();
final List requirementsList2 = Arrays.asList("pkg1==1.0.0", "pkg2==1.0.0");
Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg2"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList2, "pkg2"));
assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
log.clearOutput();
- checkException(IOException.class, () -> callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg2==2"));
+ checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList2, "pkg2==2"));
assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==2'", requirements)));
log.clearOutput();
- callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg1==1.0");
+ callPackageConsistencyCheck(log, requirementsList2, "pkg1==1.0");
log.clearOutput();
- callPackageConsistencyCheck(requirements, log, requirementsList2, "pkg1==1.0", "pkg2==1.0.0");
+ callPackageConsistencyCheck(log, requirementsList2, "pkg1==1.0", "pkg2==1.0.0");
log.clearOutput();
}
- private static void callPackageConsistencyCheck(Path requirements, TestLog log, List requirementsList, String... packages)
+ private static void callPackageConsistencyCheck(TestLog log, List requirementsList, String... packages)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- Method m = VFSUtils.class.getDeclaredMethod("checkPackagesConsistent", List.class, Path.class, List.class, String.class, String.class, BuildToolLog.class);
+ Method m = VFSUtils.class.getDeclaredMethod("checkPackagesConsistent", List.class, List.class, String.class, String.class, BuildToolLog.class);
m.setAccessible(true);
- m.invoke(VFSUtils.class, Arrays.asList(packages), requirements, requirementsList, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, log);
+ m.invoke(VFSUtils.class, Arrays.asList(packages), requirementsList, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, log);
}
private interface ExceptionCall {
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index c1deae3898..cf6fa0d8b1 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -488,7 +488,7 @@ private static void wrongPackageVersionError(String pkgs, String wrongPackageVer
throw new IOException("invalid package format: " + pkgs);
}
- private static void checkPackagesConsistent(List packages, Path requirementsFile, List requiredPackages, String inconsistentPackagesError,
+ private static void checkPackagesConsistent(List packages, List requiredPackages, String inconsistentPackagesError,
String wrongPackageVersionFormatError, BuildToolLog log) throws IOException {
if (packages.isEmpty()) {
return;
From 8b57b5ee873578b35de1444e2bfc07c5629ce2fa Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Tue, 28 Jan 2025 13:53:13 +0100
Subject: [PATCH 052/512] renamed ResourcesTask to InstallPackagesTask
---
.../tests/standalone/test_gradle_plugin.py | 53 ++-----------------
.../graalvm/python/GraalPyGradlePlugin.java | 18 +++----
...rcesTask.java => InstallPackagesTask.java} | 18 +++++--
3 files changed, 26 insertions(+), 63 deletions(-)
rename graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/{ResourcesTask.java => InstallPackagesTask.java} (92%)
diff --git a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
index b50be878dc..384d01a04e 100644
--- a/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
+++ b/graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py
@@ -236,43 +236,6 @@ def check_gradle_generated_app_external_resources(self):
def check_gradle_fail_with_mismatching_graalpy_dep(self):
pass # TODO: once the CI job builds enterprise
- def check_gradle_gen_launcher_and_venv(self, community):
- with TemporaryTestDirectory() as tmpdir:
- target_dir = os.path.join(str(tmpdir), "gradle_gen_launcher_and_venv" + self.target_dir_name_sufix())
- self.generate_app(target_dir)
-
- build_file = os.path.join(target_dir, self.build_file_name)
-
- gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
-
- append(build_file, self.packages_termcolor_ujson(community))
-
- cmd = gradle_cmd + ["graalPyResources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out)
- util.check_ouput("-m ensurepip",out)
- util.check_ouput("ujson", out)
- util.check_ouput("termcolor", out)
-
- # run again and assert that we do not regenerate the venv
- cmd = gradle_cmd + ["graalPyResources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out, False)
- util.check_ouput("-m ensurepip", out, False)
- util.check_ouput("ujson", out, False)
- util.check_ouput("termcolor", out, False)
-
- # remove ujson pkg from plugin config and check if unistalled
- self.copy_build_files(target_dir)
- append(build_file, self.packages_termcolor(community))
-
- cmd = gradle_cmd + ["graalPyResources"]
- out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
- util.check_ouput("-m venv", out, False)
- util.check_ouput("-m ensurepip", out, False)
- util.check_ouput("Uninstalling ujson", out)
- util.check_ouput("termcolor", out, False)
-
def check_tagfile(self, home, expected, log=''):
with open(os.path.join(home, "tagfile")) as f:
lines = f.readlines()
@@ -286,7 +249,7 @@ def check_gradle_check_home_warning(self, community):
build_file = os.path.join(target_dir, self.build_file_name)
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
- process_resources_cmd = gradle_cmd + ["--stacktrace", "graalPyResources"]
+ process_resources_cmd = gradle_cmd + ["--stacktrace", "graalPyInstallPackages"]
# 1. process-resources with no pythonHome config - no warning printed
log = Logger()
@@ -364,7 +327,7 @@ def check_gradle_empty_packages(self):
append(build_file, self.empty_packages())
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
- cmd = gradle_cmd + ["graalPyResources"]
+ cmd = gradle_cmd + ["graalPyInstallPackages"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
util.check_ouput("BUILD SUCCESS", out)
assert return_code == 0, out
@@ -388,7 +351,7 @@ def check_gradle_python_resources_dir_deprecation(self):
''')
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
- cmd = gradle_cmd + ["graalPyResources"]
+ cmd = gradle_cmd + ["graalPyInstallPackages"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
util.check_ouput("Property 'pythonResourcesDirectory' is deprecated and will be removed. Use property 'externalDirectory' instead.", out)
assert return_code == 0, out
@@ -413,7 +376,7 @@ def check_gradle_python_resources_dir_and_external_dir_error(self):
''')
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
- cmd = gradle_cmd + ["graalPyResources"]
+ cmd = gradle_cmd + ["graalPyInstallPackages"]
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
util.check_ouput("Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time", out)
assert return_code != 0, out
@@ -515,10 +478,6 @@ def test_gradle_generated_app(self):
def test_gradle_generated_app_external_resources(self):
self.check_gradle_generated_app_external_resources()
- @unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
- def test_gradle_gen_launcher_and_venv(self):
- self.check_gradle_gen_launcher_and_venv(community=True)
-
@unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
def test_gradle_check_home_warning(self):
self.check_gradle_check_home_warning(community=True)
@@ -689,10 +648,6 @@ def test_gradle_generated_app(self):
def test_gradle_generated_app_external_resources(self):
self.check_gradle_generated_app_external_resources()
- @unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
- def test_gradle_gen_launcher_and_venv(self):
- self.check_gradle_gen_launcher_and_venv(community=True)
-
@unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
def test_gradle_check_home_warning(self):
self.check_gradle_check_home_warning(community=True)
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
index eebba107aa..a528edf000 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java
@@ -42,7 +42,7 @@
import org.graalvm.python.dsl.GraalPyExtension;
import org.graalvm.python.tasks.MetaInfTask;
-import org.graalvm.python.tasks.ResourcesTask;
+import org.graalvm.python.tasks.InstallPackagesTask;
import org.graalvm.python.tasks.VFSFilesListTask;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
@@ -84,7 +84,7 @@ public abstract class GraalPyGradlePlugin implements Plugin {
private static final String DEFAULT_RESOURCES_DIRECTORY = "generated" + File.separator + "graalpy" + File.separator + "resources";
private static final String DEFAULT_FILESLIST_DIRECTORY = "generated" + File.separator + "graalpy" + File.separator + "fileslist";
private static final String GRAALPY_META_INF_DIRECTORY = "generated" + File.separator + "graalpy" + File.separator + "META-INF";
- private static final String GRAALPY_RESOURCES_TASK = "graalPyResources";
+ private static final String GRAALPY_INSTALL_PACKAGES_TASK = "graalPyInstallPackages";
private static final String GRAALPY_META_INF_TASK_TASK = "graalPyMetaInf";
private static final String GRAALPY_VFS_FILESLIST_TASK = "graalPyVFSFilesList";
@@ -102,12 +102,12 @@ public void apply(Project project) {
var launcherClasspath = createLauncherClasspath();
var javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
- var resourcesTask = registerResourcesTask(project, launcherClasspath, extension);
+ TaskProvider installPackagesTask = registerInstallPackagesTask(project, launcherClasspath, extension);
registerMetaInfTask(extension);
- var vfsFilesListTask = registerCreateVfsFilesListTask(resourcesTask, javaPluginExtension, extension);
+ var vfsFilesListTask = registerCreateVfsFilesListTask(installPackagesTask, javaPluginExtension, extension);
var mainSourceSet = javaPluginExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
- mainSourceSet.getResources().srcDir(resourcesTask);
+ mainSourceSet.getResources().srcDir(installPackagesTask);
addDependencies();
project.afterEvaluate(proj -> {
@@ -153,12 +153,12 @@ public void apply(Project project) {
* @param resourcesTask the resources task
* @return the task provider
*/
- private TaskProvider registerCreateVfsFilesListTask(TaskProvider resourcesTask, JavaPluginExtension javaPluginExtension, GraalPyExtension extension) {
+ private TaskProvider registerCreateVfsFilesListTask(TaskProvider installPackagesTask, JavaPluginExtension javaPluginExtension, GraalPyExtension extension) {
var srcDirs = javaPluginExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSrcDirs();
return project.getTasks().register(GRAALPY_VFS_FILESLIST_TASK, VFSFilesListTask.class, t -> {
t.setGroup(GRAALPY_GRADLE_PLUGIN_TASK_GROUP);
t.getResourceDirectory().set(extension.getResourceDirectory());
- t.getVfsDirectories().from(resourcesTask.flatMap(ResourcesTask::getOutput));
+ t.getVfsDirectories().from(installPackagesTask.flatMap(InstallPackagesTask::getOutput));
srcDirs.forEach(t.getVfsDirectories()::from);
t.getVfsFilesListOutputDir().convention(project.getLayout().getBuildDirectory().dir(DEFAULT_FILESLIST_DIRECTORY));
});
@@ -182,8 +182,8 @@ private void registerMetaInfTask(GraalPyExtension extension) {
* @param launcherClasspath the classpath of the Python launcher
* @return the resources task provider
*/
- private TaskProvider registerResourcesTask(Project project, Configuration launcherClasspath, GraalPyExtension extension) {
- return project.getTasks().register(GRAALPY_RESOURCES_TASK, ResourcesTask.class, t -> {
+ private TaskProvider registerInstallPackagesTask(Project project, Configuration launcherClasspath, GraalPyExtension extension) {
+ return project.getTasks().register(GRAALPY_INSTALL_PACKAGES_TASK, InstallPackagesTask.class, t -> {
t.getLauncherClasspath().from(launcherClasspath);
t.getLauncherDirectory().convention(project.getLayout().getBuildDirectory().dir("python-launcher"));
t.getPolyglotVersion().convention(extension.getPolyglotVersion().orElse(determineGraalPyDefaultVersion()));
diff --git a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/InstallPackagesTask.java
similarity index 92%
rename from graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
rename to graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/InstallPackagesTask.java
index 72dc897bf2..12fdb5b6e0 100644
--- a/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/ResourcesTask.java
+++ b/graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks/InstallPackagesTask.java
@@ -40,7 +40,6 @@
*/
package org.graalvm.python.tasks;
-import org.graalvm.python.GraalPyGradlePlugin;
import org.graalvm.python.GradleLogger;
import org.graalvm.python.dsl.GraalPyExtension;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
@@ -74,12 +73,21 @@
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_VENV;
/**
- * This task is responsible for setting up the Python launcher and installing the dependencies which
- * were requested by the user. This is either done in generated resources folder or in external
- * directory provided by the user in {@link GraalPyExtension#getExternalDirectory()}.
+ * This task is responsible installing the dependencies which were requested by the user.
+ * This is either done in generated resources folder or in external directory provided by the user
+ * in {@link GraalPyExtension#getExternalDirectory()}.
+ *
+ *
+ * In scope of this task:
+ *
+ * The GraalPy launcher is set up.
+ * A python venv is created.
+ * Python packages are installed into the venv.
+ *
+ *
*/
@CacheableTask
-public abstract class ResourcesTask extends DefaultTask {
+public abstract class InstallPackagesTask extends DefaultTask {
/** @see #getOutput() */
@Input
From a753ad433b3626bf4e15f1bdfbba477c289e6df2 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Wed, 29 Jan 2025 14:07:39 +0100
Subject: [PATCH 053/512] fixed minor spelling typo in GraalPyRunner loggin
message
---
.../org/graalvm/python/embedding/tools/exec/GraalPyRunner.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
index a39260e6a0..1d1a275e2c 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/GraalPyRunner.java
@@ -109,7 +109,7 @@ private static void runVenvBin(Path venvDirectory, String command, BuildToolLog
var cmd = new ArrayList();
cmd.add(venvDirectory.resolve(BIN_DIR).resolve(command + EXE_SUFFIX).toString());
cmd.addAll(args);
- log.info("executing: " + String.join(" ", cmd));
+ log.info("Executing: " + String.join(" ", cmd));
var pb = new ProcessBuilder(cmd);
runProcess(pb, log);
}
From 3c409d434ed1e9317ee992c6fff648e6555c40fd Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Wed, 29 Jan 2025 19:39:48 +0100
Subject: [PATCH 054/512] added missing requirements file check to
VFSUtil.createVenv()
---
.../embedding/test/EmbeddingTestUtils.java | 17 +-
.../embedding/vfs/test/VFSUtilsTest.java | 164 ++++++++++++------
.../maven/plugin/AbstractGraalPyMojo.java | 5 +-
.../maven/plugin/ManageResourcesMojo.java | 3 +-
.../python/embedding/tools/vfs/VFSUtils.java | 26 +--
5 files changed, 139 insertions(+), 76 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
index bb4014c785..adce95adee 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
@@ -59,10 +59,11 @@ private EmbeddingTestUtils() {
}
public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, String... packages) throws IOException {
- createVenv(venvDir, graalPyVersion, log, null, null, null, packages);
+ createVenv(venvDir, graalPyVersion, log, null, null, null, null, packages);
}
- public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, Path requirements, String iconsistentPackagesError, String wrongPackageVersionError, String... packages)
+ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, Path requirements, String iconsistentPackagesError, String wrongPackageVersionError,
+ String missingRequirementsFileWarning, String... packages)
throws IOException {
try {
log.info("<<< creating test venv <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
@@ -74,7 +75,7 @@ public Set computeClassPath() {
};
};
if (requirements != null) {
- VFSUtils.createVenv(venvDir, Arrays.asList(packages), requirements, iconsistentPackagesError, wrongPackageVersionError, launcher, graalPyVersion, log);
+ VFSUtils.createVenv(venvDir, Arrays.asList(packages), requirements, iconsistentPackagesError, wrongPackageVersionError, missingRequirementsFileWarning, launcher, graalPyVersion, log);
} else {
VFSUtils.createVenv(venvDir, Arrays.asList(packages), launcher, graalPyVersion, log);
}
@@ -88,13 +89,19 @@ public Set computeClassPath() {
public static void deleteDirOnShutdown(Path tmpdir) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- try (var fs = Files.walk(tmpdir)) {
- fs.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ try {
+ delete(tmpdir);
} catch (IOException e) {
}
}));
}
+ public static void delete(Path dir) throws IOException {
+ try (var fs = Files.walk(dir)) {
+ fs.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ }
+ }
+
private static Set getClasspath() {
var sb = new ArrayList();
var modPath = System.getProperty("jdk.module.path");
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
index 5c77509d4d..20fc0ba4c9 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
@@ -57,6 +57,7 @@
import java.util.Collections;
import java.util.List;
+import static org.graalvm.python.embedding.test.EmbeddingTestUtils.delete;
import static org.graalvm.python.embedding.test.EmbeddingTestUtils.deleteDirOnShutdown;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -68,6 +69,7 @@ public class VFSUtilsTest {
private static final String REQUIREMENTS_HEADER = "generated by graalpy tests\nwith a two line header";
private static final String INCONSISTENT_PKGS_ERROR = "inconsistent package %s";
private static final String WRONG_PKG_VERSION_ERROR = "wrong package version %s";
+ private static final String MISSING_REQUIREMENTS_FILE_WARNING = "missing requirements file";
private static final class TestLog implements BuildToolLog {
private final StringBuilder output = new StringBuilder();
@@ -142,14 +144,14 @@ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
// install packages
log.clearOutput();
createVenv(venvDir, "0.1", log, requirements, "hello-world", "tiny-tiny");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
checkVenvContentsFile(contents, "0.1", "hello-world", "tiny-tiny");
@@ -158,9 +160,9 @@ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
createVenv(venvDir, "0.1", log, requirements, "hello-world", "tiny-tiny");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
- assertFalse(log.output.toString().contains("hello-world"));
- assertFalse(log.output.toString().contains("tiny-tiny"));
+ assertFalse(log.getOutput().contains("pip install"));
+ assertFalse(log.getOutput().contains("hello-world"));
+ assertFalse(log.getOutput().contains("tiny-tiny"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
checkVenvContentsFile(contents, "0.1", "hello-world", "tiny-tiny");
@@ -169,9 +171,9 @@ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
createVenv(venvDir, "0.1", log, requirements, "hello-world");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
- assertFalse(log.output.toString().contains("hello-world"));
- assertTrue(log.output.toString().contains("Uninstalling tiny-tiny"));
+ assertFalse(log.getOutput().contains("pip install"));
+ assertFalse(log.getOutput().contains("hello-world"));
+ assertTrue(log.getOutput().contains("Uninstalling tiny-tiny"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.1", "hello-world");
@@ -181,9 +183,9 @@ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
createVenv(venvDir, "0.1", log, requirements, "hello-world");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
- assertFalse(log.output.toString().contains("hello-world"));
- assertFalse(log.output.toString().contains("tiny-tiny"));
+ assertFalse(log.getOutput().contains("pip install"));
+ assertFalse(log.getOutput().contains("hello-world"));
+ assertFalse(log.getOutput().contains("tiny-tiny"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.1", "hello-world");
@@ -192,10 +194,10 @@ public void testWithPackagesOnlyFromPluginConfig() throws IOException {
createVenv(venvDir, "0.2", log, requirements, "hello-world");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
- assertTrue(log.output.toString().contains("pip install"));
- assertTrue(log.output.toString().contains("hello-world"));
- assertFalse(log.output.toString().contains("tiny-tiny"));
+ assertTrue(log.getOutput().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.getOutput().contains("pip install"));
+ assertTrue(log.getOutput().contains("hello-world"));
+ assertFalse(log.getOutput().contains("tiny-tiny"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.2", "hello-world");
}
@@ -214,7 +216,7 @@ public void testWithoutRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log);
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
log.clearOutput();
createVenv(venvDir, "0.1", log, "hello-world");
@@ -248,7 +250,7 @@ public void testWithoutRequirementsFile() throws IOException {
// new graalPy version
createVenv(venvDir, "0.2", log, "hello-world");
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.getOutput().contains("Stale GraalPy venv, updating to"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.2", "hello-world");
log.clearOutput();
@@ -268,20 +270,20 @@ public void emptyRequirements() throws IOException {
checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world"));
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
- assertFalse(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
+ assertFalse(log.getOutput().contains("pip install"));
log.clearOutput();
createVenv(venvDir, "0.1", log, requirements);
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
log.clearOutput();
createVenv(venvDir, "0.2", log, requirements);
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
log.clearOutput();
}
@@ -302,7 +304,7 @@ public void onlyRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertFalse(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
assertFalse(Files.exists(venvDir.resolve("installed.txt")));
log.clearOutput();
@@ -310,7 +312,7 @@ public void onlyRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("pip install -r"));
+ assertTrue(log.getOutput().contains("pip install -r"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.1");
log.clearOutput();
@@ -319,8 +321,8 @@ public void onlyRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install -r"));
- assertTrue(log.output.toString().contains("pip uninstall"));
+ assertTrue(log.getOutput().contains("pip install -r"));
+ assertTrue(log.getOutput().contains("pip uninstall"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "tiny-tiny");
checkVenvContentsFile(contents, "0.1");
log.clearOutput();
@@ -329,7 +331,7 @@ public void onlyRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install -r"));
+ assertTrue(log.getOutput().contains("pip install -r"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny");
checkVenvContentsFile(contents, "0.1");
log.clearOutput();
@@ -338,8 +340,8 @@ public void onlyRequirementsFile() throws IOException {
createVenv(venvDir, "0.1", log, requirements);
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install -r"));
- assertTrue(log.output.toString().contains("pip uninstall"));
+ assertTrue(log.getOutput().contains("pip install -r"));
+ assertTrue(log.getOutput().contains("pip uninstall"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny==0.1");
checkVenvContentsFile(contents, "0.1");
log.clearOutput();
@@ -347,8 +349,8 @@ public void onlyRequirementsFile() throws IOException {
// new graalpy version
createVenv(venvDir, "0.2", log, requirements);
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
- assertTrue(log.output.toString().contains("pip install -r"));
+ assertTrue(log.getOutput().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.getOutput().contains("pip install -r"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world", "tiny-tiny==0.1");
checkVenvContentsFile(contents, "0.2");
log.clearOutput();
@@ -366,6 +368,42 @@ private void writeRequirementsFile(Path requirements, String... packages) throws
Files.write(requirements, lines, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
+ @Test
+ public void missingRequirementsWarning() throws IOException {
+ TestLog log = new TestLog();
+ Path tmpDir = Files.createTempDirectory("VFSUtilsTest_missingRequirementsWarning");
+ Path venvDir = tmpDir.resolve("venv");
+ Path contents = venvDir.resolve("contents");
+ deleteDirOnShutdown(tmpDir);
+
+ Path requirements = tmpDir.resolve("requirements.txt");
+
+ // install request, it pulls in transitive pkgs and we get the missing requirements file
+ // warning
+ createVenv(venvDir, "0.1", log, requirements, "requests==2.32.3");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.3", "charset-normalizer", "idna", "urllib3", "certifi");
+ checkVenvContentsFile(contents, "0.1", "requests==2.32.3");
+ assertTrue(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ log.clearOutput();
+
+ // freeze requirements
+ VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ checkRequirementsFile(requirements, "requests==2.32.3", "charset-normalizer", "idna", "urllib3", "certifi");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ log.clearOutput();
+
+ // install again - no more warning
+ delete(venvDir);
+ createVenv(venvDir, "0.1", log, requirements, "requests==2.32.3");
+ assertTrue(Files.exists(venvDir));
+ checkVenvCreate(log.getOutput(), true);
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.3", "charset-normalizer", "idna", "urllib3", "certifi");
+ checkVenvContentsFile(contents, "0.1", "requests==2.32.3");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ }
+
@Test
public void installAndFreeze() throws IOException {
TestLog log = new TestLog();
@@ -382,104 +420,120 @@ public void installAndFreeze() throws IOException {
checkVenvCreate(log.getOutput(), true);
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.1", "hello-world");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
// freeze requirements
VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
checkRequirementsFile(requirements, "hello-world");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+
log.clearOutput();
// reinstall without exact version declared - fails
checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world"));
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
- assertFalse(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
+ assertFalse(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
checkVenvContentsFile(contents, "0.1", "hello-world");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// reinstall with exact version declared - ok
Files.delete(requirements);
createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1");
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1");
checkVenvContentsFile(contents, "0.1", "hello-world==0.1");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// freeze requirements
VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
checkRequirementsFile(requirements, "hello-world==0.1");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// add tiny-tiny - fails because inconsistent with requirements file
assert Files.exists(requirements);
checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2"));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
- assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'tiny-tiny==0.2'")));
+ assertFalse(log.getOutput().contains("pip install"));
+ assertTrue(log.getOutput().contains(String.format(INCONSISTENT_PKGS_ERROR, "'tiny-tiny==0.2'")));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1");
checkVenvContentsFile(contents, "0.1", "hello-world==0.1");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ log.clearOutput();
// delete requirements and try again tiny-tiny - now ok
Files.delete(requirements);
createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2");
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
// freeze requirements - hello-world, tiny-tiny
VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
checkRequirementsFile(requirements, "hello-world==0.1", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// install again - OK
createVenv(venvDir, "0.1", log, requirements, "hello-world==0.1", "tiny-tiny==0.2");
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// update hello-world version - fails
checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2"));
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
- assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'hello-world==0.2'", requirements)));
+ assertFalse(log.getOutput().contains("pip install"));
+ assertTrue(log.getOutput().contains(String.format(INCONSISTENT_PKGS_ERROR, "'hello-world==0.2'", requirements)));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.1", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// delete requirements and try again new hello-world version - now ok
Files.delete(requirements);
createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
checkVenvCreate(log.getOutput(), false);
- assertTrue(log.output.toString().contains("pip install"));
+ assertTrue(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.1", "hello-world==0.2", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// freeze requirements with new hello-world
VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
checkRequirementsFile(requirements, "hello-world==0.2", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// install again - OK
createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
checkVenvCreate(log.getOutput(), false);
- assertFalse(log.output.toString().contains("pip install"));
+ assertFalse(log.getOutput().contains("pip install"));
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.1", "hello-world==0.2", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// reinstall with new graalpy version
createVenv(venvDir, "0.2", log, requirements, "hello-world==0.2", "tiny-tiny==0.2");
checkVenvCreate(log.getOutput(), true);
- assertTrue(log.output.toString().contains("Stale GraalPy venv, updating to"));
- assertTrue(log.output.toString().contains("pip install -r")); // requirements file is used
+ assertTrue(log.getOutput().contains("Stale GraalPy venv, updating to"));
+ assertTrue(log.getOutput().contains("pip install -r")); // requirements file is used
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2", "tiny-tiny==0.2");
checkVenvContentsFile(contents, "0.2", "hello-world==0.2", "tiny-tiny==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
}
@Test
- public void invalidVersionFormatTest() throws Exception {
+ public void invalidVersionFormatTest() {
TestLog log = new TestLog();
checkWrongPkgVersionFormat("", log);
@@ -497,7 +551,7 @@ public void invalidVersionFormatTest() throws Exception {
private static void checkWrongPkgVersionFormat(String pkg, TestLog log) {
checkException(IOException.class, () -> VFSUtils.checkVersionFormat(Arrays.asList(pkg), WRONG_PKG_VERSION_ERROR, log));
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'" + pkg + "'")));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'" + pkg + "'")));
log.clearOutput();
}
@@ -511,27 +565,27 @@ public void packageConsistency() throws Exception {
Files.createFile(requirements);
callPackageConsistencyCheck(log, Collections.EMPTY_LIST);
- assertFalse(log.output.toString().contains("inconsistent package"));
+ assertFalse(log.getOutput().contains("inconsistent package"));
checkException(IOException.class, () -> callPackageConsistencyCheck(log, Collections.EMPTY_LIST, "pkg1"));
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
log.clearOutput();
checkException(IOException.class, () -> callPackageConsistencyCheck(log, Collections.EMPTY_LIST, "pkg1==1"));
- assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg1==1'", requirements)));
+ assertTrue(log.getOutput().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg1==1'", requirements)));
log.clearOutput();
final List requirementsList = Arrays.asList("pkg1==1.0.0");
Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg1"));
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg1'")));
log.clearOutput();
checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg2"));
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
log.clearOutput();
checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList, "pkg2==1"));
- assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==1'", requirements)));
+ assertTrue(log.getOutput().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==1'", requirements)));
log.clearOutput();
callPackageConsistencyCheck(log, requirementsList, "pkg1==1.0");
log.clearOutput();
@@ -542,10 +596,10 @@ public void packageConsistency() throws Exception {
Files.write(requirements, requirementsList, StandardOpenOption.TRUNCATE_EXISTING);
checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList2, "pkg2"));
- assertTrue(log.output.toString().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
+ assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'pkg2'")));
log.clearOutput();
checkException(IOException.class, () -> callPackageConsistencyCheck(log, requirementsList2, "pkg2==2"));
- assertTrue(log.output.toString().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==2'", requirements)));
+ assertTrue(log.getOutput().contains(String.format(INCONSISTENT_PKGS_ERROR, "'pkg2==2'", requirements)));
log.clearOutput();
callPackageConsistencyCheck(log, requirementsList2, "pkg1==1.0");
log.clearOutput();
@@ -610,7 +664,7 @@ private static void checkPackages(Path file, String header, String... packages)
assertEquals(packages.length, lines.size());
for (String pkg : packages) {
boolean found = false;
- String pkgDef = pkg.indexOf("==") >= 0 ? pkgDef = pkg : pkg + "==";
+ String pkgDef = pkg.indexOf("==") >= 0 ? pkg : pkg + "==";
for (String line : lines) {
assert line.contains("==");
if (line.startsWith(pkgDef)) {
@@ -629,7 +683,7 @@ private static void createVenv(Path venvDir, String graalPyVersion, TestLog log,
}
private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path requirements, String... packages) throws IOException {
- EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, requirements, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, packages);
+ EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, requirements, INCONSISTENT_PKGS_ERROR, WRONG_PKG_VERSION_ERROR, MISSING_REQUIREMENTS_FILE_WARNING, packages);
}
private static void checkVenvContentsFile(Path contents, String graalPyVersion, String... packages) throws IOException {
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
index 383daf396f..dd63bf33ad 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java
@@ -80,9 +80,10 @@ public abstract class AbstractGraalPyMojo extends AbstractMojo {
""";
protected static final String MISSING_REQUIREMENTS_FILE_WARNING = """
- Missing python requirements file '%s'.
+ Missing python requirements file.
+ It looks like some transitive python dependencies were installed together with the packages declared in graalpy-maven-plugin configuration.
- It is highly recommended to freeze transitive python dependencies by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages'
+ It is highly recommended to freeze python dependencies by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:freeze-installed-packages'.
""";
protected static final String WRONG_PACKAGE_VERSION_FORMAT_ERROR = """
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
index 93082fad94..590d1ff994 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java
@@ -69,8 +69,7 @@ private void manageVenv() throws MojoExecutionException {
MavenDelegateLog log = new MavenDelegateLog(getLog());
Path requirements = getRequirementsFile();
try {
- VFSUtils.createVenv(venvDirectory, packages, requirements, INCONSISTENT_PACKAGES_ERROR, WRONG_PACKAGE_VERSION_FORMAT_ERROR, createLauncher(), getGraalPyVersion(project), log);
- VFSUtils.warnMissingRequirementsFile(requirements, MISSING_REQUIREMENTS_FILE_WARNING, log);
+ VFSUtils.createVenv(venvDirectory, packages, requirements, INCONSISTENT_PACKAGES_ERROR, WRONG_PACKAGE_VERSION_FORMAT_ERROR, MISSING_REQUIREMENTS_FILE_WARNING, createLauncher(), getGraalPyVersion(project), log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index cf6fa0d8b1..93a66185c1 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -196,12 +196,6 @@ private static void delete(Path dir) throws IOException {
}
}
- public static void warnMissingRequirementsFile(Path requirementsFile, String missingRequirementsFileWarning, BuildToolLog log) {
- if (!Files.exists(requirementsFile)) {
- warning(String.format(missingRequirementsFileWarning, requirementsFile) + "\n" + FOR_MORE_INFO_REFERENCE_MSG, log);
- }
- }
-
public static abstract class Launcher {
private final Path launcherPath;
@@ -230,7 +224,7 @@ static InstalledPackages fromVenv(Path venvDirectory) throws IOException {
return new InstalledPackages(venvDirectory, installed, pkgs);
}
- void freeze(BuildToolLog log) throws IOException {
+ List freeze(BuildToolLog log) throws IOException {
CollectOutputLog collectOutputLog = new CollectOutputLog();
runPip(venvDirectory, "freeze", collectOutputLog, "--local");
packages = new ArrayList<>(collectOutputLog.getOutput());
@@ -246,6 +240,7 @@ void freeze(BuildToolLog log) throws IOException {
log.debug(" " + p);
}
}
+ return packages;
}
}
@@ -293,10 +288,11 @@ void write(List packages) throws IOException {
}
public static void createVenv(Path venvDirectory, List packagesArgs, Launcher launcherArgs, String graalPyVersion, BuildToolLog log) throws IOException {
- createVenv(venvDirectory, packagesArgs, null, null, null, launcherArgs, graalPyVersion, log);
+ createVenv(venvDirectory, packagesArgs, null, null, null, null, launcherArgs, graalPyVersion, log);
}
- public static void createVenv(Path venvDirectory, List packages, Path requirementsFile, String inconsistentPackagesError, String wrongPackageVersionFormatError,
+ public static void createVenv(Path venvDirectory, List packages, Path requirementsFile,
+ String inconsistentPackagesError, String wrongPackageVersionFormatError, String missingRequirementsFileWarning,
Launcher launcherArgs, String graalPyVersion, BuildToolLog log) throws IOException {
Objects.requireNonNull(venvDirectory);
Objects.requireNonNull(packages);
@@ -314,7 +310,8 @@ public static void createVenv(Path venvDirectory, List packages, Path re
VenvContents venvContents = ensureVenv(venvDirectory, graalPyVersion, log, ensureLauncher(launcherArgs, log));
- boolean installed = requirementsPackages != null ? install(venvDirectory, requirementsFile, requirementsPackages, log) : install(venvDirectory, pluginPackages, venvContents, log);
+ boolean installed = requirementsPackages != null ? install(venvDirectory, requirementsFile, requirementsPackages, log)
+ : install(venvDirectory, pluginPackages, venvContents, missingRequirementsFileWarning, log);
if (installed) {
venvContents.write(pluginPackages);
}
@@ -411,12 +408,17 @@ private static boolean install(Path venvDirectory, Path requirementsFile, List newPackages, VenvContents venvContents, BuildToolLog log) throws IOException {
+ private static boolean install(Path venvDirectory, List newPackages, VenvContents venvContents, String missingRequirementsFileWarning, BuildToolLog log) throws IOException {
boolean needsUpdate = false;
needsUpdate |= deleteUnwantedPackages(venvDirectory, newPackages, venvContents.packages, log);
needsUpdate |= installWantedPackages(venvDirectory, newPackages, venvContents.packages, log);
if (needsUpdate) {
- InstalledPackages.fromVenv(venvDirectory).freeze(log);
+ List installedPackages = InstalledPackages.fromVenv(venvDirectory).freeze(log);
+ if (missingRequirementsFileWarning != null && !Boolean.getBoolean("graalpy.vfs.skipMissingRequirementsWarning")) {
+ if (installedPackages.size() != newPackages.size()) {
+ warning(String.format(missingRequirementsFileWarning) + "\n" + FOR_MORE_INFO_REFERENCE_MSG, log);
+ }
+ }
return true;
}
return false;
From a39edca8f7b6f992f63df124d2a8f4d73889cfaf Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Wed, 29 Jan 2025 21:56:12 +0100
Subject: [PATCH 055/512] added VFSUtils.freezePackages
---
.../embedding/test/EmbeddingTestUtils.java | 15 ++++----
.../embedding/vfs/test/VFSUtilsTest.java | 35 ++++++++++++-------
.../plugin/FreezeInstalledPackagesMojo.java | 12 ++-----
.../python/embedding/tools/vfs/VFSUtils.java | 26 ++++++++++----
4 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
index adce95adee..808d766cb7 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
@@ -68,12 +68,7 @@ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog
try {
log.info("<<< creating test venv <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Path launcherFile = venvDir.getParent().resolve(VFSUtils.LAUNCHER_NAME);
- Launcher launcher = new Launcher(launcherFile) {
- public Set computeClassPath() {
- return getClasspath();
- };
- };
+ Launcher launcher = createLauncher(venvDir);
if (requirements != null) {
VFSUtils.createVenv(venvDir, Arrays.asList(packages), requirements, iconsistentPackagesError, wrongPackageVersionError, missingRequirementsFileWarning, launcher, graalPyVersion, log);
} else {
@@ -87,6 +82,14 @@ public Set computeClassPath() {
}
}
+ public static Launcher createLauncher(Path venvDir) {
+ return new Launcher(venvDir.getParent().resolve(VFSUtils.LAUNCHER_NAME)) {
+ public Set computeClassPath() {
+ return getClasspath();
+ };
+ };
+ }
+
public static void deleteDirOnShutdown(Path tmpdir) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
index 20fc0ba4c9..d1deda87de 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
@@ -57,6 +57,7 @@
import java.util.Collections;
import java.util.List;
+import static org.graalvm.python.embedding.test.EmbeddingTestUtils.createLauncher;
import static org.graalvm.python.embedding.test.EmbeddingTestUtils.delete;
import static org.graalvm.python.embedding.test.EmbeddingTestUtils.deleteDirOnShutdown;
import static org.junit.Assert.assertEquals;
@@ -357,11 +358,15 @@ public void onlyRequirementsFile() throws IOException {
// check that freeze rewrites an existing requirements file
writeRequirementsFile(requirements); // no packages
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
- checkRequirementsFile(requirements, "hello-world", "tiny-tiny==0.1");
+ freeze(venvDir, requirements, log, "hello-world==0.1", "tiny-tiny==0.1");
+ checkRequirementsFile(requirements, "hello-world==0.1", "tiny-tiny==0.1");
log.clearOutput();
}
+ private static void freeze(Path venvDir, Path requirements, TestLog log, String... packages) throws IOException {
+ VFSUtils.freezePackages(venvDir, Arrays.asList(packages), requirements, REQUIREMENTS_HEADER, WRONG_PKG_VERSION_ERROR, createLauncher(venvDir), "0.1", log);
+ }
+
private void writeRequirementsFile(Path requirements, String... packages) throws IOException {
List lines = new ArrayList<>(Arrays.asList("# " + String.join("\n# ", REQUIREMENTS_HEADER.split("\n"))));
lines.addAll(Arrays.asList(packages));
@@ -389,7 +394,7 @@ public void missingRequirementsWarning() throws IOException {
log.clearOutput();
// freeze requirements
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ freeze(venvDir, requirements, log, "requests==2.32.3");
checkRequirementsFile(requirements, "requests==2.32.3", "charset-normalizer", "idna", "urllib3", "certifi");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
@@ -415,17 +420,23 @@ public void installAndFreeze() throws IOException {
Path requirements = tmpDir.resolve("requirements.txt");
// install package from plugin config
- createVenv(venvDir, "0.1", log, requirements, "hello-world");
+ createVenv(venvDir, "0.1", log, requirements, "hello-world==0.2");
assertTrue(Files.exists(venvDir));
checkVenvCreate(log.getOutput(), true);
checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
- checkVenvContentsFile(contents, "0.1", "hello-world");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.2");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ log.clearOutput();
+
// freeze requirements
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
- checkRequirementsFile(requirements, "hello-world");
+ checkException(IOException.class, () -> freeze(venvDir, requirements, log, "hello-world"));
+ assertFalse(Files.exists(requirements));
+ assertFalse(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "hello-world")));
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
+ freeze(venvDir, requirements, log, "hello-world==0.2");
+ checkRequirementsFile(requirements, "hello-world==0.2");
+ assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// reinstall without exact version declared - fails
@@ -433,8 +444,8 @@ public void installAndFreeze() throws IOException {
checkVenvCreate(log.getOutput(), false);
assertTrue(log.getOutput().contains(String.format(WRONG_PKG_VERSION_ERROR, "'hello-world'")));
assertFalse(log.getOutput().contains("pip install"));
- checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world");
- checkVenvContentsFile(contents, "0.1", "hello-world");
+ checkInstalledPackages(venvDir.resolve("installed.txt"), "hello-world==0.2");
+ checkVenvContentsFile(contents, "0.1", "hello-world==0.2");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
@@ -448,7 +459,7 @@ public void installAndFreeze() throws IOException {
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// freeze requirements
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ freeze(venvDir, requirements, log, "hello-world==0.1");
checkRequirementsFile(requirements, "hello-world==0.1");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
@@ -473,7 +484,7 @@ public void installAndFreeze() throws IOException {
checkVenvContentsFile(contents, "0.1", "hello-world==0.1", "tiny-tiny==0.2");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
// freeze requirements - hello-world, tiny-tiny
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ freeze(venvDir, requirements, log, "hello-world==0.1", "tiny-tiny==0.2");
checkRequirementsFile(requirements, "hello-world==0.1", "tiny-tiny==0.2");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
@@ -507,7 +518,7 @@ public void installAndFreeze() throws IOException {
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
// freeze requirements with new hello-world
- VFSUtils.createRequirementsFile(venvDir, requirements, REQUIREMENTS_HEADER, log);
+ freeze(venvDir, requirements, log, "hello-world==0.2", "tiny-tiny==0.2");
checkRequirementsFile(requirements, "hello-world==0.2", "tiny-tiny==0.2");
assertFalse(log.getOutput().contains(MISSING_REQUIREMENTS_FILE_WARNING));
log.clearOutput();
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
index b4b85155db..c33159a14e 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/FreezeInstalledPackagesMojo.java
@@ -45,6 +45,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.graalvm.python.embedding.tools.exec.BuildToolLog;
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
import java.io.IOException;
@@ -73,16 +74,7 @@ protected void manageVenv() throws MojoExecutionException {
Path requirements = getRequirementsFile();
try {
- VFSUtils.checkVersionFormat(packages, WRONG_PACKAGE_VERSION_FORMAT_ERROR, log);
-
- VFSUtils.createVenv(venvDirectory, packages, createLauncher(), getGraalPyVersion(project), log);
-
- if(Files.exists(venvDirectory)) {
- VFSUtils.createRequirementsFile(venvDirectory, requirements, REQUIREMENTS_FILE_HEADER, log);
- } else {
- // how comes?
- log.warning("did not generate new python requirements file due to missing venv");
- }
+ VFSUtils.freezePackages(venvDirectory, packages, requirements, REQUIREMENTS_FILE_HEADER, WRONG_PACKAGE_VERSION_FORMAT_ERROR, createLauncher(), getGraalPyVersion(project), log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e);
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
index 93a66185c1..0e847fd463 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java
@@ -293,14 +293,14 @@ public static void createVenv(Path venvDirectory, List packagesArgs, Lau
public static void createVenv(Path venvDirectory, List packages, Path requirementsFile,
String inconsistentPackagesError, String wrongPackageVersionFormatError, String missingRequirementsFileWarning,
- Launcher launcherArgs, String graalPyVersion, BuildToolLog log) throws IOException {
+ Launcher launcher, String graalPyVersion, BuildToolLog log) throws IOException {
Objects.requireNonNull(venvDirectory);
Objects.requireNonNull(packages);
- Objects.requireNonNull(launcherArgs);
+ Objects.requireNonNull(launcher);
Objects.requireNonNull(graalPyVersion);
Objects.requireNonNull(log);
- logVenvArgs(venvDirectory, packages, requirementsFile, launcherArgs, graalPyVersion, log);
+ logVenvArgs(venvDirectory, packages, requirementsFile, launcher, graalPyVersion, log);
List pluginPackages = trim(packages);
List requirementsPackages = requirementsFile != null && Files.exists(requirementsFile) ? readPackagesFromFile(requirementsFile) : null;
@@ -308,7 +308,7 @@ public static void createVenv(Path venvDirectory, List packages, Path re
return;
}
- VenvContents venvContents = ensureVenv(venvDirectory, graalPyVersion, log, ensureLauncher(launcherArgs, log));
+ VenvContents venvContents = ensureVenv(venvDirectory, graalPyVersion, log, ensureLauncher(launcher, log));
boolean installed = requirementsPackages != null ? install(venvDirectory, requirementsFile, requirementsPackages, log)
: install(venvDirectory, pluginPackages, venvContents, missingRequirementsFileWarning, log);
@@ -317,6 +317,20 @@ public static void createVenv(Path venvDirectory, List packages, Path re
}
}
+ public static void freezePackages(Path venvDirectory, List packages, Path requirementsFile, String requirementsHeader, String wrongPackageVersionFormatError, Launcher launcher,
+ String graalPyVersion, BuildToolLog log) throws IOException {
+ checkVersionFormat(packages, wrongPackageVersionFormatError, log);
+
+ createVenv(venvDirectory, packages, launcher, graalPyVersion, log);
+
+ if (Files.exists(venvDirectory)) {
+ VFSUtils.createRequirementsFile(venvDirectory, requirementsFile, requirementsHeader, log);
+ } else {
+ // how comes?
+ log.warning("did not generate new python requirements file due to missing venv");
+ }
+ }
+
private static void logVenvArgs(Path venvDirectory, List packages, Path requirementsFile, Launcher launcherArgs, String graalPyVersion, BuildToolLog log)
throws IOException {
if (log.isDebugEnabled()) {
@@ -403,7 +417,7 @@ private static boolean install(Path venvDirectory, Path requirementsFile, List newPackages, Ven
return false;
}
- public static void createRequirementsFile(Path venvDirectory, Path requirementsFile, String requirementsFileHeader, BuildToolLog log) throws IOException {
+ private static void createRequirementsFile(Path venvDirectory, Path requirementsFile, String requirementsFileHeader, BuildToolLog log) throws IOException {
Objects.requireNonNull(venvDirectory);
Objects.requireNonNull(requirementsFile);
Objects.requireNonNull(requirementsFileHeader);
From e336defb42dee6e7b859ff53ad8a6dc50a70b930 Mon Sep 17 00:00:00 2001
From: Tomas Stupka
Date: Thu, 30 Jan 2025 14:23:58 +0100
Subject: [PATCH 056/512] improved logging in VFSTestUtils
---
.../cext/test/MultiContextCExtTest.java | 50 +++++++-
.../embedding/test/EmbeddingTestUtils.java | 12 +-
.../test/VirtualFileSystemUtilsTest.java | 4 -
.../embedding/vfs/test/VFSUtilsTest.java | 54 ++++++--
.../python/maven/plugin/MavenDelegateLog.java | 25 +++-
.../embedding/tools/exec/BuildToolLog.java | 93 ++++++++++----
.../embedding/tools/exec/GraalPyRunner.java | 37 +++++-
.../python/embedding/tools/vfs/VFSUtils.java | 121 +++++++++++-------
.../java/org/graalvm/python/GradleLogger.java | 42 +++++-
.../python/jbang/JBangIntegration.java | 44 ++++++-
10 files changed, 377 insertions(+), 105 deletions(-)
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
index d9472b3652..6bfcc08be6 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java
@@ -70,6 +70,8 @@ static final class TestLog extends Handler implements BuildToolLog {
final StringBuilder stderr = new StringBuilder();
final StringBuilder stdout = new StringBuilder();
final StringBuilder info = new StringBuilder();
+ final StringBuilder warn = new StringBuilder();
+ final StringBuilder debug = new StringBuilder();
final StringBuilder truffleLog = new StringBuilder();
static void println(CharSequence... args) {
@@ -78,27 +80,69 @@ static void println(CharSequence... args) {
}
}
- public void warning(CharSequence txt, Throwable t) {
+ @Override
+ public void warning(String txt, Throwable t) {
println("[warning]", txt);
println("[throwable]", t.getMessage());
logThrowable.append(txt).append(t.getMessage());
}
- public void subProcessErr(CharSequence err) {
+ @Override
+ public void error(String s) {
+ println("[err]", s);
+ stderr.append(s);
+ }
+
+ @Override
+ public void debug(String s) {
+ println("[debug]", s);
+ debug.append(s);
+ }
+
+ @Override
+ public void subProcessErr(String err) {
println("[err]", err);
stderr.append(err);
}
- public void subProcessOut(CharSequence out) {
+ @Override
+ public void subProcessOut(String out) {
println("[out]", out);
stdout.append(out);
}
+ @Override
public void info(String s) {
println("[info]", s);
info.append(s);
}
+ @Override
+ public void warning(String s) {
+ println("[warning]", s);
+ warn.append(s);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isWarningEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return true;
+ }
+
@Override
public void publish(LogRecord record) {
var msg = String.format("[%s] %s: %s", record.getLoggerName(), record.getLevel().getName(), String.format(record.getMessage(), record.getParameters()));
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
index 808d766cb7..1d4c431301 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java
@@ -66,7 +66,7 @@ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog
String missingRequirementsFileWarning, String... packages)
throws IOException {
try {
- log.info("<<< creating test venv <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ info(log, "<<<<<< create test venv %s <<<<<<", venvDir);
Launcher launcher = createLauncher(venvDir);
if (requirements != null) {
@@ -78,7 +78,13 @@ public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog
System.err.println(getClasspath());
throw e;
} finally {
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ info(log, ">>>>>> create test venv %s >>>>>>", venvDir);
+ }
+ }
+
+ private static void info(BuildToolLog log, String txt, Object... args) {
+ if (log.isInfoEnabled()) {
+ log.info(String.format(txt, args));
}
}
@@ -86,7 +92,7 @@ public static Launcher createLauncher(Path venvDir) {
return new Launcher(venvDir.getParent().resolve(VFSUtils.LAUNCHER_NAME)) {
public Set computeClassPath() {
return getClasspath();
- };
+ }
};
}
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
index 26413f70a1..3c73392695 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/VirtualFileSystemUtilsTest.java
@@ -81,14 +81,10 @@
import java.util.stream.Stream;
import static com.oracle.graal.python.test.integration.Utils.IS_WINDOWS;
-import static org.graalvm.python.embedding.utils.VirtualFileSystem.HostIO.NONE;
-import static org.graalvm.python.embedding.utils.VirtualFileSystem.HostIO.READ;
-import static org.graalvm.python.embedding.utils.VirtualFileSystem.HostIO.READ_WRITE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
/**
* Simple copy of VirtualFileSystemTest to test also the deprecated
diff --git a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
index d1deda87de..71a58ac697 100644
--- a/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
+++ b/graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java
@@ -83,45 +83,76 @@ private void clearOutput() {
output.delete(0, output.length());
}
- public void subProcessOut(CharSequence s) {
- System.out.println(s);
+ public void subProcessOut(String s) {
+ println("[subout] ", s);
addLine(s.toString());
}
- public void subProcessErr(CharSequence s) {
- System.err.println(s);
+ public void subProcessErr(String s) {
+ println("[suberr] ", s);
addLine(s.toString());
}
public void info(String s) {
- System.out.println(s);
+ println("[info] ", s);
addLine(s);
- };
+ }
public void warning(String s) {
- System.out.println(s);
+ println("[warn] ", s);
addLine(s);
}
public void warning(String s, Throwable t) {
- System.out.println(s);
+ println("[warn] ", s);
t.printStackTrace();
addLine(s);
}
public void error(String s) {
- System.err.println(s);
+ println("[err] ", s);
addLine(s);
}
@Override
- public boolean isDebugEnabled() {
+ public void debug(String s) {
+ println("[debug] ", s);
+ addLine(s);
+ }
+
+ @Override
+ public boolean isWarningEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
return true;
}
+ @Override
+ public boolean isDebugEnabled() {
+ return isVerbose();
+ }
+
public String getOutput() {
return output.toString();
}
+
+ static void println(String... args) {
+ if (isVerbose()) {
+ System.out.println(String.join(" ", args));
+ }
+ }
+
+ private static boolean isVerbose() {
+ return Boolean.getBoolean("com.oracle.graal.python.test.verbose");
+ }
}
/**
@@ -262,7 +293,6 @@ public void emptyRequirements() throws IOException {
TestLog log = new TestLog();
Path tmpDir = Files.createTempDirectory("VFSUtilsTest_emptyRequirements");
Path venvDir = tmpDir.resolve("venv");
- Path contents = venvDir.resolve("contents");
deleteDirOnShutdown(tmpDir);
Path requirements = tmpDir.resolve("requirements.txt");
@@ -367,7 +397,7 @@ private static void freeze(Path venvDir, Path requirements, TestLog log, String.
VFSUtils.freezePackages(venvDir, Arrays.asList(packages), requirements, REQUIREMENTS_HEADER, WRONG_PKG_VERSION_ERROR, createLauncher(venvDir), "0.1", log);
}
- private void writeRequirementsFile(Path requirements, String... packages) throws IOException {
+ private static void writeRequirementsFile(Path requirements, String... packages) throws IOException {
List lines = new ArrayList<>(Arrays.asList("# " + String.join("\n# ", REQUIREMENTS_HEADER.split("\n"))));
lines.addAll(Arrays.asList(packages));
Files.write(requirements, lines, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
diff --git a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
index 2f09c511d5..dac3e20f3c 100644
--- a/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
+++ b/graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/MavenDelegateLog.java
@@ -50,27 +50,48 @@ final class MavenDelegateLog implements BuildToolLog {
this.delegate = delegate;
}
+ @Override
public void info(String txt) {
delegate.info(txt);
}
+ @Override
public void warning(String txt) {
delegate.warn(txt);
}
+ @Override
public void warning(String txt, Throwable t) {
delegate.warn(txt, t);
}
+ @Override
public void error(String txt) {
delegate.error(txt);
}
+ @Override
+ public void debug(String txt) {
+ delegate.debug(txt);
+ }
+
+ @Override
public boolean isDebugEnabled() {
return delegate.isDebugEnabled();
}
- public void debug(String txt) {
- delegate.debug(txt);
+ @Override
+ public boolean isWarningEnabled() {
+ return delegate.isWarnEnabled();
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return delegate.isErrorEnabled();
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return delegate.isInfoEnabled();
}
}
diff --git a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
index 6edc062f55..1fdf4268ec 100644
--- a/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
+++ b/graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/exec/BuildToolLog.java
@@ -45,54 +45,97 @@
import java.util.List;
public interface BuildToolLog {
- default void subProcessOut(CharSequence out) {
+ default void subProcessOut(String out) {
System.out.println(out);
}
- default void subProcessErr(CharSequence err) {
+ default void subProcessErr(String err) {
System.err.println(err);
}
- default void info(String s) {
- System.out.println(s);
- };
+ void info(String s);
- default void warning(String s) {
- System.out.println(s);
- }
+ void warning(String s);
- default void warning(String s, Throwable t) {
- System.out.println(s);
- t.printStackTrace();
- }
+ void warning(String s, Throwable t);
- default void error(String s) {
- System.err.println(s);
- }
+ void error(String s);
- default public boolean isDebugEnabled() {
- return false;
- }
+ void debug(String s);
- default void debug(String s) {
- System.out.println(s);
- }
+ boolean isWarningEnabled();
+
+ boolean isInfoEnabled();
+
+ boolean isErrorEnabled();
+
+ boolean isDebugEnabled();
final class CollectOutputLog implements BuildToolLog {
private final List output = new ArrayList<>();
+ private final BuildToolLog delegate;
+
+ public CollectOutputLog(BuildToolLog delegate) {
+ this.delegate = delegate;
+ }
public List