Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23967,7 +23967,7 @@ private boolean genLookahead__tmp_328_rule(boolean match) {
return (result != null) == match;
}


@Override
protected SSTNode runParser(InputType inputType) {
SSTNode result = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 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
Expand Down Expand Up @@ -51,7 +51,7 @@ private static String getSuffix(boolean isComplex) {

static String getSlotBaseClass(Slot s) {
return switch (s.value()) {
case nb_bool -> "TpSlotInquiry.TpSlotInquiryBuiltin";
case nb_bool -> "TpSlotInquiry.TpSlotInquiryBuiltin" + getSuffix(s.isComplex());
case nb_index, nb_int, nb_float, nb_absolute, nb_positive, nb_negative, nb_invert,
tp_iter, tp_str, tp_repr, am_aiter, am_anext, am_await ->
"TpSlotUnaryFunc.TpSlotUnaryFuncBuiltin";
Expand Down Expand Up @@ -128,10 +128,7 @@ static String getUncachedExecuteSignature(SlotKind s) {
}

static boolean supportsComplex(SlotKind s) {
return switch (s) {
case nb_bool -> false;
default -> true;
};
return true;
}

static boolean supportsSimple(SlotKind s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,10 @@ public long cacheKeyForBytecode(byte[] code) {
.build();
@CompilationFinal private Object cachedTRegexLineBreakRegex;

public Object getCachedTRegexLineBreakRegex(PythonContext context) {
public Object getCachedTRegexLineBreakRegex(Node location, PythonContext context) {
if (cachedTRegexLineBreakRegex == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
cachedTRegexLineBreakRegex = context.getEnv().parseInternal(LINEBREAK_REGEX_SOURCE).call();
cachedTRegexLineBreakRegex = context.getEnv().parseInternal(LINEBREAK_REGEX_SOURCE).call(location);
}
return cachedTRegexLineBreakRegex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,11 +1389,11 @@ static PTuple doCreate(long arrowArrayAddr, long arrowSchemaAddr,
@Cached PythonCextCapsuleBuiltins.PyCapsuleNewNode pyCapsuleNewNode) {
var ctx = getContext(inliningTarget);

long arrayDestructor = ctx.arrowSupport.getArrowArrayDestructor();
long arrayDestructor = ctx.arrowSupport.getArrowArrayDestructor(inliningTarget);
var arrayCapsuleName = new CArrayWrappers.CByteArrayWrapper(ArrowArray.CAPSULE_NAME);
PyCapsule arrowArrayCapsule = pyCapsuleNewNode.execute(inliningTarget, arrowArrayAddr, arrayCapsuleName, arrayDestructor);

long schemaDestructor = ctx.arrowSupport.getArrowSchemaDestructor();
long schemaDestructor = ctx.arrowSupport.getArrowSchemaDestructor(inliningTarget);
var schemaCapsuleName = new CArrayWrappers.CByteArrayWrapper(ArrowSchema.CAPSULE_NAME);
PyCapsule arrowSchemaCapsule = pyCapsuleNewNode.execute(inliningTarget, arrowSchemaAddr, schemaCapsuleName, schemaDestructor);
return PFactory.createTuple(ctx.getLanguage(inliningTarget), new Object[]{arrowSchemaCapsule, arrowArrayCapsule});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static com.oracle.graal.python.util.PythonUtils.EMPTY_BYTE_ARRAY;
import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.callCallTarget;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;

import java.io.IOException;
Expand All @@ -82,8 +83,8 @@
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.PolyglotModuleBuiltinsClinicProviders.RegisterInteropTypeNodeClinicProviderGen;
import com.oracle.graal.python.builtins.modules.PolyglotModuleBuiltinsClinicProviders.EnterForeignCriticalRegionNodeClinicProviderGen;
import com.oracle.graal.python.builtins.modules.PolyglotModuleBuiltinsClinicProviders.RegisterInteropTypeNodeClinicProviderGen;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
Expand Down Expand Up @@ -287,7 +288,7 @@ Object eval(Object pathObj, Object stringObj, Object languageObj) {
if (mimeType != null) {
builder = builder.mimeType(mimeType);
}
Object result = env.parsePublic(builder.build()).call();
Object result = callCallTarget(env.parsePublic(builder.build()), this);
return PForeignToPTypeNode.getUncached().executeConvert(result);
} catch (AbstractTruffleException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
*/
package com.oracle.graal.python.builtins.modules.re;

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;
import static com.oracle.graal.python.util.PythonUtils.callCallTarget;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

import org.graalvm.collections.EconomicMap;

import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
import com.oracle.graal.python.nodes.ErrorMessages;
Expand All @@ -57,15 +68,6 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.strings.TruffleString;
import org.graalvm.collections.EconomicMap;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

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;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;

public final class TRegexCache {

Expand Down Expand Up @@ -302,7 +304,7 @@ public Object compile(Node node, PythonContext context, PythonMethod method, boo
Object compiledRegex;
try {
Source regexSource = Source.newBuilder("regex", options + '/' + pattern + '/' + flags, "re").mimeType("application/tregex").internal(true).build();
compiledRegex = context.getEnv().parseInternal(regexSource).call();
compiledRegex = callCallTarget(context.getEnv().parseInternal(regexSource), node);
assert !lib.isNull(compiledRegex) : "This shouldn't happen";
} catch (RuntimeException e) {
throw handleCompilationError(node, e, lib);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
*/
package com.oracle.graal.python.builtins.modules.weakref;

import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ReferenceError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___BYTES__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BYTES__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DELITEM__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SETITEM__;
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.Builtin;
import com.oracle.graal.python.annotations.Slot;
Expand Down Expand Up @@ -133,18 +145,6 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.strings.TruffleString;

import java.util.List;

import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ReferenceError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___BYTES__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BYTES__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DELITEM__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REVERSED__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SETITEM__;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;

@CoreFunctions(extendClasses = PythonBuiltinClassType.PProxyType)
public final class ProxyTypeBuiltins extends PythonBuiltins {

Expand Down Expand Up @@ -311,17 +311,15 @@ static Object richCmp(VirtualFrame frame, PProxyType self, Object other, RichCmp
}
}

@Slot(value = Slot.SlotKind.nb_bool)
@Slot(value = Slot.SlotKind.nb_bool, isComplex = true)
@GenerateUncached
@GenerateNodeFactory
public abstract static class BoolNode extends TpSlotInquiry.NbBoolBuiltinNode {

@Specialization
@TruffleBoundary
static boolean bool(PProxyType self,
@Bind Node inliningTarget) {
Object object = unwrap(self, inliningTarget);
return PyObjectIsTrueNode.executeUncached(object);
static boolean bool(VirtualFrame frame, PProxyType self,
@Bind Node inliningTarget,
@Cached PyObjectIsTrueNode isTrueNode) {
return isTrueNode.execute(frame, unwrap(self, inliningTarget));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
Expand Down Expand Up @@ -1502,7 +1502,7 @@ static PList doStringKeepends(Node inliningTarget, TruffleString self, boolean k
@Cached TRegexUtil.InvokeGetGroupBoundariesMethodNode getEndNode,
@Cached TruffleString.SubstringByteIndexNode substringNode,
@Cached AppendNode appendNode) {
Object lineBreakRegex = PythonLanguage.get(inliningTarget).getCachedTRegexLineBreakRegex(PythonContext.get(inliningTarget));
Object lineBreakRegex = PythonLanguage.get(inliningTarget).getCachedTRegexLineBreakRegex(inliningTarget, PythonContext.get(inliningTarget));
CompilerAsserts.partialEvaluationConstant(lineBreakRegex);
PList list = PFactory.createList(PythonLanguage.get(inliningTarget));
int lastEnd = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 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
Expand Down Expand Up @@ -41,25 +41,31 @@
package com.oracle.graal.python.builtins.objects.type.slots;

import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___BOOL__;
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BOOL__;

import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.CheckInquiryResultNode;
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.transitions.CApiTiming;
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.type.slots.PythonDispatchers.UnaryPythonSlotDispatcherNode;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltinBase;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotNative;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotPythonSingle;
import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotSimpleBuiltinBase;
import com.oracle.graal.python.lib.PyBoolCheckNode;
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.call.CallDispatchers;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
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.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.GenerateCached;
Expand All @@ -74,16 +80,44 @@ public abstract class TpSlotInquiry {
private TpSlotInquiry() {
}

public abstract static class TpSlotInquiryBuiltin<T extends InquiryBuiltinNode> extends TpSlotSimpleBuiltinBase<T> {
public abstract static sealed class TpSlotInquiryBuiltin<T extends InquiryBuiltinNode> extends
TpSlotBuiltinBase<T> permits TpSlotInquiryBuiltinSimple, TpSlotInquiryBuiltinComplex {
static final BuiltinSlotWrapperSignature SIGNATURE = BuiltinSlotWrapperSignature.UNARY;

protected TpSlotInquiryBuiltin(NodeFactory<T> nodeFactory) {
super(nodeFactory, BuiltinSlotWrapperSignature.UNARY, PExternalFunctionWrapper.INQUIRY);
super(nodeFactory, SIGNATURE, PExternalFunctionWrapper.INQUIRY);
}

final InquiryBuiltinNode createSlotNode() {
return createNode();
}
}

public abstract static non-sealed class TpSlotInquiryBuiltinSimple<T extends InquiryBuiltinNode> extends TpSlotInquiryBuiltin<T> {
protected TpSlotInquiryBuiltinSimple(NodeFactory<T> nodeFactory) {
super(nodeFactory);
}

protected abstract boolean executeUncached(Object self);

@Override
public final void initialize(PythonLanguage language) {
// nop
}
}

public abstract static non-sealed class TpSlotInquiryBuiltinComplex<T extends InquiryBuiltinNode> extends TpSlotInquiryBuiltin<T> {
private final int callTargetIndex = TpSlotBuiltinCallTargetRegistry.getNextCallTargetIndex();

protected TpSlotInquiryBuiltinComplex(NodeFactory<T> nodeFactory) {
super(nodeFactory);
}

@Override
public final void initialize(PythonLanguage language) {
RootCallTarget callTarget = createSlotCallTarget(language, SIGNATURE, getNodeFactory(), J___BOOL__);
language.setBuiltinSlotCallTarget(callTargetIndex, callTarget);
}
}

@GenerateInline(value = false, inherit = true)
Expand Down Expand Up @@ -116,13 +150,6 @@ static boolean callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused")
return slotNode.executeBool(frame, self);
}

@Specialization(replaces = "callCachedBuiltin")
static boolean callGenericSimpleBuiltin(TpSlotInquiryBuiltin slot, Object self) {
// All nb_bool builtins are known to be simple enough to not require PE for good
// performance, so we call them uncached
return slot.executeUncached(self);
}

@Specialization
static boolean callPython(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
@Cached(inline = false) CallNbBoolPythonNode callSlotNode) {
Expand All @@ -140,6 +167,23 @@ static boolean callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative
Object result = externalInvokeNode.call(frame, inliningTarget, threadState, C_API_TIMING, T___BOOL__, slot.callable, toNativeNode.execute(self));
return checkResultNode.executeBool(threadState, T___BOOL__, result);
}

@Specialization(replaces = "callCachedBuiltin")
static boolean callGenericSimpleBuiltin(TpSlotInquiryBuiltinSimple<?> slot, Object self) {
// Most nb_bool builtins are known to be simple enough to not require PE for good
// performance, so we call them uncached
return slot.executeUncached(self);
}

@Specialization(replaces = "callCachedBuiltin")
@InliningCutoff
static boolean callGenericComplexBuiltin(VirtualFrame frame, Node inliningTarget, TpSlotInquiryBuiltinComplex<?> slot, Object self,
@Cached CallDispatchers.SimpleIndirectInvokeNode invoke) {
Object[] arguments = PArguments.create(1);
PArguments.setArgument(arguments, 0, self);
RootCallTarget callTarget = PythonLanguage.get(inliningTarget).getBuiltinSlotCallTarget(slot.callTargetIndex);
return (boolean) invoke.execute(frame, inliningTarget, callTarget, arguments);
}
}

@GenerateUncached
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 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
Expand Down Expand Up @@ -70,7 +70,7 @@ public final void executeCached(long releaseCallback, long baseStructure) {
@Specialization
static void doIt(Node inliningTarget, long releaseCallback, long baseStructure,
@Bind("getContext(inliningTarget)") PythonContext ctx,
@Cached(value = "createReleaseCallbackSignature(ctx)", allowUncached = true) Object callbackSignature,
@Cached(value = "createReleaseCallbackSignature($node, ctx)", allowUncached = true) Object callbackSignature,
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary) {
try {
signatureLibrary.call(callbackSignature, new NativePointer(releaseCallback), baseStructure);
Expand All @@ -80,8 +80,8 @@ static void doIt(Node inliningTarget, long releaseCallback, long baseStructure,
}

@NeverDefault
static Object createReleaseCallbackSignature(PythonContext context) {
return ArrowUtil.createNfiSignature("(UINT64):VOID", context);
static Object createReleaseCallbackSignature(Node location, PythonContext context) {
return ArrowUtil.createNfiSignature(location, "(UINT64):VOID", context);
}

@GenerateCached(false)
Expand Down
Loading
Loading