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 688202ff33..1d555d7ee8 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 @@ -113,7 +113,6 @@ import com.oracle.graal.python.builtins.objects.cext.copying.NativeLibraryToolException; 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.code.CodeNodes; 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; @@ -147,7 +146,6 @@ 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.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallNode; @@ -614,37 +612,27 @@ PBytes doString(VirtualFrame frame, Object filenameObj, public abstract static class DumpTruffleAstNode extends PythonUnaryBuiltinNode { @Specialization @TruffleBoundary - public TruffleString doIt(PFunction func) { - return toTruffleStringUncached(NodeUtil.printTreeToString(GetCallTargetNode.getUncached().execute(func).getRootNode())); - } - - @Specialization(guards = "isFunction(method.getFunction())") - @TruffleBoundary - public TruffleString doIt(PMethod method) { - return toTruffleStringUncached(NodeUtil.printTreeToString(GetCallTargetNode.getUncached().execute(method).getRootNode())); - } - - @Specialization - @TruffleBoundary - public TruffleString doIt(PGenerator gen) { - return toTruffleStringUncached(NodeUtil.printTreeToString(gen.getCurrentCallTarget().getRootNode())); - } - - @Specialization - @TruffleBoundary - public TruffleString doIt(PCode code) { - return toTruffleStringUncached(NodeUtil.printTreeToString(CodeNodes.GetCodeRootNode.executeUncached(code))); - } - - @Fallback - @TruffleBoundary - public TruffleString doit(Object object) { + public TruffleString doIt(Object object) { + if (object instanceof PFunction func) { + return toTruffleStringUncached(NodeUtil.printTreeToString(func.getCode().getRootNode())); + } + if (object instanceof PBuiltinFunction func) { + return toTruffleStringUncached(NodeUtil.printTreeToString(func.getFunctionRootNode())); + } + if (object instanceof PMethod method) { + return doIt(method.getFunction()); + } + if (object instanceof PBuiltinMethod method) { + return doIt(method.getBuiltinFunction()); + } + if (object instanceof PGenerator gen) { + return toTruffleStringUncached(NodeUtil.printTreeToString(gen.getCurrentCallTarget().getRootNode())); + } + if (object instanceof PCode code) { + return toTruffleStringUncached(NodeUtil.printTreeToString(code.getRootNode())); + } return toTruffleStringUncached("truffle ast dump not supported for " + object.toString()); } - - protected static boolean isFunction(Object callee) { - return callee instanceof PFunction; - } } @Builtin(name = "current_import", minNumOfPositionalArgs = 0) @@ -829,7 +817,7 @@ public Object doIt(VirtualFrame frame, PFunction func, @TruffleBoundary public synchronized PFunction convertToBuiltin(PFunction func) { - RootNode rootNode = CodeNodes.GetCodeRootNode.executeUncached(func.getCode()); + RootNode rootNode = func.getCode().getRootNode(); if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { if (rootNode instanceof PBytecodeDSLRootNode r) { r.setPythonInternal(true); @@ -846,10 +834,8 @@ public synchronized PFunction convertToBuiltin(PFunction func) { @GenerateNodeFactory public abstract static class BuiltinMethodNode extends PythonUnaryBuiltinNode { @Specialization - public Object doIt(PFunction func, - @Bind Node inliningTarget, - @Cached CodeNodes.GetCodeRootNode getRootNode) { - RootNode rootNode = getRootNode.execute(inliningTarget, func.getCode()); + public Object doIt(PFunction func) { + RootNode rootNode = func.getCode().getRootNode(); if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { if (rootNode instanceof PBytecodeDSLRootNode r) { r.setPythonInternal(true); 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 d26d848a8e..07bc3e63f1 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 @@ -44,7 +44,6 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; -import com.oracle.graal.python.builtins.objects.code.CodeNodesFactory.GetCodeRootNodeGen; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.function.Signature; import com.oracle.graal.python.compiler.BytecodeCodeUnit; @@ -271,22 +270,4 @@ static Signature doCode(PCode code) { return code.getSignature(); } } - - @GenerateUncached - @GenerateInline - @GenerateCached(false) - public abstract static class GetCodeRootNode extends Node { - - public abstract RootNode execute(Node inliningTarget, PCode code); - - public static RootNode executeUncached(PCode code) { - return GetCodeRootNodeGen.getUncached().execute(null, code); - } - - @Specialization - static RootNode doIt(Node inliningTarget, PCode code, - @Cached GetCodeCallTargetNode getCodeCallTargetNode) { - return getCodeCallTargetNode.execute(inliningTarget, code).getRootNode(); - } - } } 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 55acb7cb66..4d27588750 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 @@ -317,7 +317,7 @@ private static CodeUnit getCodeUnit(RootNode node) { return null; } - RootNode getRootNode() { + public RootNode getRootNode() { return rootNode; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java index c245c9e399..cf04a9fc5c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java @@ -42,7 +42,6 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeRootNode; import com.oracle.graal.python.builtins.objects.code.PCode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PFunction; @@ -227,7 +226,7 @@ public PFrame(PythonLanguage lang, @SuppressWarnings("unused") long threadState, // TODO: frames: extract the information from the threadState object this.globals = globals; this.code = code; - this.location = GetCodeRootNode.executeUncached(code); + this.location = code.getRootNode(); Reference curFrameInfo = new Reference(location != null ? location.getRootNode() : null, null); this.virtualFrameInfo = curFrameInfo; curFrameInfo.setPyFrame(this); 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 392fd0ee4f..32d6f00b9f 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 @@ -48,6 +48,7 @@ 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; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.RootCallTarget; @@ -81,6 +82,8 @@ public final class PBuiltinFunction extends PythonBuiltinObject implements Bound @CompilationFinal(dimensions = 1) private final Object[] defaults; @CompilationFinal(dimensions = 1) private final PKeyword[] kwDefaults; + @CompilationFinal private RootCallTarget callTarget; + public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, int flags, RootNode functionRootNode, Signature signature, TpSlot slot, PExternalFunctionWrapper slotWrapper) { @@ -196,7 +199,24 @@ public Signature getSignature() { } public RootCallTarget getCallTarget() { - return functionRootNode.getCallTarget(); + RootCallTarget ct = callTarget; + if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, ct == null)) { + if (CompilerDirectives.inCompiledCode() && CompilerDirectives.isPartialEvaluationConstant(this)) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + } + ct = initializeCallTarget(); + } + return ct; + } + + @TruffleBoundary + private RootCallTarget initializeCallTarget() { + RootCallTarget ct = callTarget; + if (ct == null) { + ct = functionRootNode.getCallTarget(); + callTarget = ct; + } + return ct; } public boolean declaresExplicitSelf() { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java index a23486255d..48007923fa 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java @@ -29,13 +29,11 @@ import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cell.PCell; -import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeCallTargetNode; import com.oracle.graal.python.builtins.objects.code.PCode; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.lib.PyUnicodeCheckNode; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.runtime.GilNode; import com.oracle.graal.python.util.PythonUtils; import com.oracle.truffle.api.Assumption; @@ -45,14 +43,12 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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.Cached.Shared; import com.oracle.truffle.api.interop.InteropLibrary; 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.nodes.RootNode; import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.strings.TruffleString; @@ -221,7 +217,7 @@ public void setKwDefaults(PKeyword[] defaults) { @TruffleBoundary String getSourceCode() { - RootNode rootNode = GetCallTargetNode.getUncached().execute(this).getRootNode(); + RootNode rootNode = getCode().getRootNode(); SourceSection sourceSection = rootNode.getSourceSection(); if (sourceSection != null) { return sourceSection.getCharacters().toString(); @@ -248,12 +244,10 @@ String getExecutableName(@Shared("gil") @Cached GilNode gil, @ExportMessage public SourceSection getSourceLocation( - @Bind Node inliningTarget, - @Shared("getCt") @Cached GetCodeCallTargetNode getCt, @Shared("gil") @Cached GilNode gil) throws UnsupportedMessageException { boolean mustRelease = gil.acquire(); try { - SourceSection result = getSourceLocationDirect(inliningTarget, getCt); + SourceSection result = getSourceLocationDirect(); if (result == null) { throw UnsupportedMessageException.create(); } else { @@ -265,8 +259,8 @@ public SourceSection getSourceLocation( } @TruffleBoundary - private SourceSection getSourceLocationDirect(Node inliningTarget, GetCodeCallTargetNode getCt) { - RootNode rootNode = getCt.execute(inliningTarget, code).getRootNode(); + private SourceSection getSourceLocationDirect() { + RootNode rootNode = code.getRootNode(); SourceSection result; if (rootNode instanceof PRootNode) { result = ((PRootNode) rootNode).getSourceSection(); @@ -283,12 +277,10 @@ private static SourceSection getForeignSourceSection(RootNode rootNode) { @ExportMessage public boolean hasSourceLocation( - @Bind Node inliningTarget, - @Shared("getCt") @Cached GetCodeCallTargetNode getCt, @Shared("gil") @Cached GilNode gil) { boolean mustRelease = gil.acquire(); try { - return getSourceLocationDirect(inliningTarget, getCt) != null; + return getSourceLocationDirect() != null; } finally { gil.release(mustRelease); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/FunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/FunctionNodes.java index 1e6df8ffd6..3fc04f24cc 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/FunctionNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/FunctionNodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, Oracle and/or 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,15 +51,12 @@ import com.oracle.graal.python.builtins.objects.method.PMethodBase; import com.oracle.graal.python.nodes.PGuards; import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetCallTargetNodeGen; import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetSignatureNodeGen; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; -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.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; @@ -278,54 +275,4 @@ public static GetSignatureNode getUncached() { return GetSignatureNodeGen.getUncached(); } } - - @ImportStatic(PGuards.class) - @GenerateUncached - @GenerateInline(false) // used lazily - public abstract static class GetCallTargetNode extends PNodeWithContext { - - public abstract RootCallTarget execute(Object function); - - @Specialization - static RootCallTarget doFunction(PFunction function, - @Bind Node inliningTarget, - @Shared("getCode") @Cached GetFunctionCodeNode getFunctionCodeNode, - @Shared("getCt") @Cached CodeNodes.GetCodeCallTargetNode getCt) { - return getCt.execute(inliningTarget, getFunctionCodeNode.execute(inliningTarget, function)); - } - - @Specialization - static RootCallTarget doBuiltinFunction(PBuiltinFunction builtinFunction) { - return builtinFunction.getCallTarget(); - } - - @Specialization(guards = "isPFunction(function)") - static RootCallTarget doMethod(@SuppressWarnings("unused") PMethod method, - @Bind Node inliningTarget, - @Bind("method.getFunction()") Object function, - @Shared("getCode") @Cached GetFunctionCodeNode getFunctionCodeNode, - @Shared("getCt") @Cached CodeNodes.GetCodeCallTargetNode getCt) { - return getCt.execute(inliningTarget, getFunctionCodeNode.execute(inliningTarget, (PFunction) function)); - } - - @Specialization(guards = "isPBuiltinFunction(method.getFunction())") - static RootCallTarget doMethod(@SuppressWarnings("unused") PMethod method, - @Bind("method.getFunction()") Object function) { - return ((PBuiltinFunction) function).getCallTarget(); - } - - @Specialization - static RootCallTarget doBuiltinMethod(PBuiltinMethod builtinMethod) { - return builtinMethod.getBuiltinFunction().getCallTarget(); - } - - @Fallback - static RootCallTarget fallback(@SuppressWarnings("unused") Object callable) { - return null; - } - - public static GetCallTargetNode getUncached() { - return GetCallTargetNodeGen.getUncached(); - } - } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index 4f556bd6f3..3076dd8ef3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -1778,7 +1778,7 @@ protected static boolean isSingleContext(Node node) { @NeverDefault static Assumption getCodeStableAssumption(PCode code) { - PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) code.getRootCallTarget().getRootNode(); + PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) code.getRootNode(); return rootNode.getFunctionCodeFinalAssumption(); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java index 5f5628e329..796808c5e5 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java @@ -75,6 +75,7 @@ import com.oracle.truffle.api.nodes.DirectCallNode; import com.oracle.truffle.api.nodes.IndirectCallNode; import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.profiles.InlinedConditionProfile; public class CallDispatchers { @@ -192,8 +193,9 @@ static Object callBuiltinFunctionCached(VirtualFrame frame, Node inliningTarget, return invoke.execute(frame, inliningTarget, callNode, arguments); } - @Specialization(guards = "sameCallTarget(callee.getCallTarget(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached") + @Specialization(guards = "callee.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached") static Object callBuiltinFunctionCachedCt(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PBuiltinFunction callee, Object[] arguments, + @SuppressWarnings("unused") @Cached(value = "callee.getFunctionRootNode()", adopt = false) RootNode rootNode, @Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode, @Exclusive @Cached SimpleDirectInvokeNode invoke) { return invoke.execute(frame, inliningTarget, callNode, arguments); @@ -231,8 +233,9 @@ static Object callBuiltinFunctionCached(VirtualFrame frame, Node inliningTarget, return invoke.execute(frame, inliningTarget, callNode, pArguments); } - @Specialization(guards = "sameCallTarget(callee.getCallTarget(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached") + @Specialization(guards = "callee.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached") static Object callBuiltinFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PBuiltinFunction callee, Object[] arguments, PKeyword[] keywords, + @SuppressWarnings("unused") @Cached(value = "callee.getFunctionRootNode()", adopt = false) RootNode rootNode, @Exclusive @Cached CreateArgumentsNode createArgs, @Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode, @Exclusive @Cached SimpleDirectInvokeNode invoke) { @@ -287,9 +290,10 @@ static Object callBuiltinMethodCached(VirtualFrame frame, Node inliningTarget, @ return invoke.execute(frame, inliningTarget, callNode, pArguments); } - @Specialization(guards = "sameCallTarget(function.getCallTarget(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinMethodCached") + @Specialization(guards = "function.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinMethodCached") static Object callBuiltinMethodCachedCt(VirtualFrame frame, Node inliningTarget, PBuiltinMethod callee, Object[] arguments, PKeyword[] keywords, @Bind("callee.getBuiltinFunction()") PBuiltinFunction function, + @SuppressWarnings("unused") @Cached(value = "function.getFunctionRootNode()", adopt = false) RootNode rootNode, @Exclusive @Cached CreateArgumentsNode createArgs, @Cached("createDirectCallNodeFor(function)") DirectCallNode callNode, @Exclusive @Cached SimpleDirectInvokeNode invoke) { @@ -390,8 +394,9 @@ static Object callFunctionCached(VirtualFrame frame, Node inliningTarget, @Suppr } // We have multiple contexts, don't cache the objects so that contexts can be cleaned up - @Specialization(guards = {"sameCallTarget(callee.getCallTarget(), callNode)"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached") + @Specialization(guards = {"callee.getCode().getRootNode() == rootNode"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached") static Object callFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PFunction callee, Object[] arguments, + @SuppressWarnings("unused") @Cached(value = "callee.getCode().getRootNode()", adopt = false) RootNode rootNode, @Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode, @Exclusive @Cached FunctionDirectInvokeNode invoke) { return invoke.execute(frame, inliningTarget, callNode, callee, arguments); @@ -408,7 +413,7 @@ static Object callFunctionMegamorphic(VirtualFrame frame, Node inliningTarget, P /** * Node for calling python functions with an inline cache on the function object and a secondary - * inline cache on the call target. Takes PArguments + * inline cache on the call target. */ @GenerateInline @GenerateCached(false) @@ -430,8 +435,9 @@ static Object callFunctionCached(VirtualFrame frame, Node inliningTarget, @Suppr } // We have multiple contexts, don't cache the objects so that contexts can be cleaned up - @Specialization(guards = {"sameCallTarget(callee.getCallTarget(), callNode)"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached") + @Specialization(guards = {"callee.getCode().getRootNode() == rootNode"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached") static Object callFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PFunction callee, Object[] arguments, PKeyword[] keywords, + @SuppressWarnings("unused") @Cached(value = "callee.getCode().getRootNode()", adopt = false) RootNode rootNode, @Exclusive @Cached CreateArgumentsNode createArgs, @Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode, @Exclusive @Cached FunctionDirectInvokeNode invoke) { 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 ef35d0ed11..e181ef1826 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 @@ -45,11 +45,9 @@ 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; -import com.oracle.graal.python.builtins.objects.method.PMethod; import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltin; import com.oracle.graal.python.nodes.PGuards; import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; 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.PythonQuaternaryBuiltinNode; @@ -58,7 +56,6 @@ import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NodeFactory; import com.oracle.truffle.api.dsl.NodeField; @@ -155,14 +152,6 @@ protected static boolean takesSelfArg(Object func) { return true; } - protected static RootCallTarget getCallTarget(PMethod meth, GetCallTargetNode getCtNode) { - return getCtNode.execute(meth.getFunction()); - } - - protected static RootCallTarget getCallTarget(PBuiltinMethod meth, GetCallTargetNode getCtNode) { - return getCtNode.execute(meth.getFunction()); - } - protected static Object callUnaryBuiltin(VirtualFrame frame, PythonBuiltinBaseNode builtin, Object arg1) { CompilerAsserts.partialEvaluationConstant(builtin); if (builtin instanceof PythonUnaryBuiltinNode) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java index 220e12751f..97183b4883 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or 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,16 +43,13 @@ import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.nodes.call.BoundDescriptor; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; 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.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.NeverDefault; @@ -61,6 +58,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.nodes.RootNode; import com.oracle.truffle.api.nodes.UnexpectedResultException; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @@ -95,10 +93,10 @@ static Object callObjectSingleContext(VirtualFrame frame, @SuppressWarnings("unu return callBinaryBuiltin(frame, builtinNode, arg1, arg2); } - @Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, // + @Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, // limit = "getCallSiteInlineCacheMaxDepth()") static Object callObject(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, - @SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode, @Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) { return callBinaryBuiltin(frame, builtinNode, arg1, arg2); } @@ -111,10 +109,9 @@ static Object callMethodSingleContext(VirtualFrame frame, @SuppressWarnings("unu return callBinaryBuiltin(frame, builtinNode, arg1, arg2); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") static Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 2)") PythonBuiltinBaseNode builtinNode) { return callBinaryBuiltin(frame, builtinNode, arg1, arg2); @@ -128,10 +125,9 @@ static Object callMethodSingleContextSelf(VirtualFrame frame, @SuppressWarnings( return callTernaryBuiltin(frame, builtinNode, cachedFunc.getSelf(), arg1, arg2); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") static Object callMethodSelf(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 3)") PythonBuiltinBaseNode builtinNode) { return callTernaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java index 89e8ce6ec6..d985582d1e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or 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,10 @@ import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.nodes.call.BoundDescriptor; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; 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.GenerateUncached; @@ -57,6 +55,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.nodes.RootNode; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @GenerateUncached @@ -80,10 +79,10 @@ Object callSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFuncti return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4); } - @Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, // + @Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, // limit = "getCallSiteInlineCacheMaxDepth()") Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4, - @SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode, @Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode) { return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4); } @@ -96,10 +95,9 @@ Object callMethodSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltin return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4, - @SuppressWarnings("unused") @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 4)") PythonBuiltinBaseNode builtinNode) { return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java index f0ac256134..022e23a351 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or 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,15 +43,12 @@ import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.nodes.call.BoundDescriptor; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; 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.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.ReportPolymorphism.Megamorphic; @@ -59,6 +56,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.nodes.RootNode; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @GenerateUncached @@ -81,10 +79,10 @@ static Object doBuiltinFunctionCached(VirtualFrame frame, @SuppressWarnings("unu return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3); } - @Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, // + @Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, // limit = "getCallSiteInlineCacheMaxDepth()") static Object doBuiltinFunctionCtCached(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, - @SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode, @Cached("getBuiltin(frame, func, 3)") PythonBuiltinBaseNode builtinNode) { return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3); } @@ -97,10 +95,9 @@ static Object doBuiltinMethodCached(VirtualFrame frame, @SuppressWarnings("unuse return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") static Object doBuiltinMethodCtCached(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 3)") PythonBuiltinBaseNode builtinNode) { return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3); @@ -114,10 +111,9 @@ static Object callSelfMethodSingleContext(VirtualFrame frame, @SuppressWarnings( return callQuaternaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2, arg3); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") static Object callSelfMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 4)") PythonBuiltinBaseNode builtinNode) { return callQuaternaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2, arg3); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallUnaryMethodNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallUnaryMethodNode.java index 7430ea5264..245bda2270 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallUnaryMethodNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallUnaryMethodNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or 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,17 +43,14 @@ import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod; -import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode; import com.oracle.graal.python.nodes.call.BoundDescriptor; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; import com.oracle.graal.python.util.PythonUtils; 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.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.ReportPolymorphism.Megamorphic; @@ -61,6 +58,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.nodes.RootNode; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @GenerateUncached @@ -89,10 +87,10 @@ Object callObjectSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltin return callUnaryBuiltin(frame, builtinNode, receiver); } - @Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, // + @Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, // limit = "getCallSiteInlineCacheMaxDepth()") Object callObject(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object receiver, - @SuppressWarnings("unused") @Cached(value = "func.getCallTarget()") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode, @Cached("getBuiltin(frame, func, 1)") PythonBuiltinBaseNode builtinNode) { return callUnaryBuiltin(frame, builtinNode, receiver); } @@ -105,10 +103,9 @@ Object callMethodSingleContext(VirtualFrame frame, @SuppressWarnings("unused") P return callUnaryBuiltin(frame, builtinNode, receiver); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object receiver, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 1)") PythonBuiltinBaseNode builtinNode) { return callUnaryBuiltin(frame, builtinNode, receiver); @@ -122,10 +119,9 @@ Object callSelfMethodSingleContext(VirtualFrame frame, @SuppressWarnings("unused return callBinaryBuiltin(frame, builtinNode, func.getSelf(), arg); } - @Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()") Object callSelfMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg, - @SuppressWarnings("unused") @Shared @Cached GetCallTargetNode getCt, - @SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct, + @SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode, @SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg, @Cached("getBuiltin(frame, func.getBuiltinFunction(), 2)") PythonBuiltinBaseNode builtinNode) { return callBinaryBuiltin(frame, builtinNode, func.getSelf(), arg); diff --git a/graalpython/lib-graalpython/patches/metadata.toml b/graalpython/lib-graalpython/patches/metadata.toml index ac35b422e1..c3e63fa42b 100644 --- a/graalpython/lib-graalpython/patches/metadata.toml +++ b/graalpython/lib-graalpython/patches/metadata.toml @@ -892,6 +892,12 @@ patch = 'scikit-learn-1.1.3.patch' license = 'BSD-3-Clause' dist-type = 'sdist' +[[scipy.rules]] +version = '>= 1.17.0' +patch = 'scipy-1.17.0.patch' +license = 'BSD-3-Clause' +dist-type = 'sdist' + [[scipy.rules]] version = '== 1.10.1' install-priority = 0 diff --git a/graalpython/lib-graalpython/patches/pyarrow-24.0.0.patch b/graalpython/lib-graalpython/patches/pyarrow-24.0.0.patch index 6f4ffbf10b..c04818891e 100644 --- a/graalpython/lib-graalpython/patches/pyarrow-24.0.0.patch +++ b/graalpython/lib-graalpython/patches/pyarrow-24.0.0.patch @@ -45,17 +45,16 @@ new file mode 100644 index 0000000..fd43d65 --- /dev/null +++ b/pyarrow_build_backend.py -@@ -0,0 +1,93 @@ +@@ -0,0 +1,89 @@ +import os +import re -+import sys +import tarfile +import subprocess +import tempfile -+import shutil +import tarfile +import urllib.request +from pathlib import Path ++from scikit_build_core.build import build_wheel as scikit_build_wheel + +VERSION = re.search(r'set\(PYARROW_VERSION "([^"]+)"\)', Path("CMakeLists.txt").read_text()).group(1) + @@ -120,25 +119,22 @@ index 0000000..fd43d65 + subprocess.check_call([ + 'cmake', '--install', str(build_dir), + ]) -+ env = os.environ.copy() -+ env['ARROW_HOME'] = str(arrow_dist) -+ env['CMAKE_PREFIX_PATH'] = str(arrow_dist) -+ env['PYARROW_WITH_DATASET'] = '1' -+ env['PYARROW_WITH_PARQUET'] = '1' -+ env['PYARROW_WITH_PARQUET_ENCRYPTION'] = '1' -+ env['PYARROW_WITH_GANDIVA'] = '1' -+ env['PYARROW_BUNDLE_ARROW_CPP'] = '1' -+ env['PYARROW_BUNDLE_CYTHON_CPP'] = '1' -+ subprocess.run( -+ [sys.executable, 'setup.py', 'bdist_wheel'], -+ env=env, -+ check=True, -+ ) -+ wheels = list(Path('dist').glob('*.whl')) -+ assert len(wheels) == 1, f"Expected 1 wheel, found {len(wheels)}" -+ wheel = wheels[0] -+ shutil.copyfile(wheel, wheel_directory / wheel.name) -+ return str(wheel.name) ++ old_env = os.environ.copy() ++ os.environ.update({ ++ 'ARROW_HOME': str(arrow_dist), ++ 'CMAKE_PREFIX_PATH': str(arrow_dist), ++ 'PYARROW_WITH_DATASET': '1', ++ 'PYARROW_WITH_PARQUET': '1', ++ 'PYARROW_WITH_PARQUET_ENCRYPTION': '1', ++ 'PYARROW_WITH_GANDIVA': '1', ++ 'PYARROW_BUNDLE_ARROW_CPP': '1', ++ 'PYARROW_BUNDLE_CYTHON_CPP': '1', ++ }) ++ try: ++ return scikit_build_wheel(wheel_directory, config_settings, metadata_directory) ++ finally: ++ os.environ.clear() ++ os.environ.update(old_env) diff --git a/pyproject.toml b/pyproject.toml index 2fbe78e..7a80e39 100644 --- a/pyproject.toml diff --git a/graalpython/lib-graalpython/patches/scipy-1.17.0.patch b/graalpython/lib-graalpython/patches/scipy-1.17.0.patch new file mode 100644 index 0000000000..d6b853a1c5 --- /dev/null +++ b/graalpython/lib-graalpython/patches/scipy-1.17.0.patch @@ -0,0 +1,33 @@ +diff --git a/scipy/_lib/_util.py b/scipy/_lib/_util.py +index fd8130a..f97a696 100644 +--- a/scipy/_lib/_util.py ++++ b/scipy/_lib/_util.py +@@ -639,11 +639,12 @@ class MapWrapper: + self.pool = pool + self._mapfunc = self.pool + else: +- from multiprocessing import get_context, get_start_method ++ from multiprocessing import get_all_start_methods, get_context, get_start_method + + method = get_start_method(allow_none=True) + +- if method is None and os.name=='posix' and sys.version_info < (3, 14): ++ if (method is None and os.name=='posix' and sys.version_info < (3, 14) ++ and 'forkserver' in get_all_start_methods()): + # Python 3.13 and older used "fork" on posix, which can lead to + # deadlocks. This backports that fix to older Python versions. + method = 'forkserver' +diff --git a/scipy/conftest.py b/scipy/conftest.py +index 6367669..21fa175 100644 +--- a/scipy/conftest.py ++++ b/scipy/conftest.py +@@ -91,7 +91,8 @@ def pytest_configure(config): + "iterations(n): run the given test function `n` times in each thread", + ) + +- if os.name == 'posix' and sys.version_info < (3, 14): ++ if (os.name == 'posix' and sys.version_info < (3, 14) ++ and 'forkserver' in multiprocessing.get_all_start_methods()): + # On POSIX, Python 3.13 and older uses the 'fork' context by + # default. Calling fork() from multiple threads leads to + # deadlocks. This has been changed in 3.14 to 'forkserver'.