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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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 @@ -250,9 +250,9 @@ abstract static class GraalPyPrivate_Module_AddFunctionToModule extends CApi7Bui
static Object moduleFunction(Object methodDefPtr, PythonModule mod, TruffleString name, Object cfunc, int flags, int wrapper, Object doc,
@Bind Node inliningTarget,
@Cached ObjectBuiltins.SetattrNode setattrNode,
@Cached ReadAttributeFromPythonObjectNode readAttrNode,
@Cached(inline = true) ReadAttributeFromPythonObjectNode readAttrNode,
@Cached CFunctionNewExMethodNode cFunctionNewExMethodNode) {
Object modName = readAttrNode.execute(mod, T___NAME__, null);
Object modName = readAttrNode.execute(inliningTarget, mod, T___NAME__, null);
assert modName != null : "module name is missing!";
Object func = cFunctionNewExMethodNode.execute(inliningTarget, methodDefPtr, name, cfunc, flags, wrapper, mod, modName, doc);
setattrNode.executeSetAttr(null, mod, name, func);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -108,12 +108,7 @@ public DynamicObject getStore() {
}

protected static Object[] keyArray(DynamicObjectStorage self) {
return DynamicObjectStorage.keyArray(self.store.getShape());
}

@TruffleBoundary
protected static Object[] keyArray(Shape shape) {
return shape.getKeyList().toArray();
return DynamicObject.GetKeyArrayNode.getUncached().execute(self.store);
}

@GenerateUncached
Expand All @@ -131,32 +126,26 @@ public abstract static class LengthNode extends Node {
static int cachedLen(DynamicObjectStorage self,
@SuppressWarnings("unused") @Cached("self.store.getShape()") Shape cachedShape,
@Cached(value = "keyArray(self)", dimensions = 1) Object[] keys,
@Shared @Cached ReadAttributeFromPythonObjectNode readNode) {
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readNode) {
int len = 0;
for (Object key : keys) {
len = incrementLen(self, readNode, len, key);
}
return len;
}

@Specialization(replaces = "cachedLen", guards = {"cachedShape == self.store.getShape()"}, limit = "3")
static int cachedKeys(DynamicObjectStorage self,
@SuppressWarnings("unused") @Cached("self.store.getShape()") Shape cachedShape,
@Cached(value = "keyArray(self)", dimensions = 1) Object[] keys,
@Shared @Cached ReadAttributeFromPythonObjectNode readNode) {
@Specialization(replaces = "cachedLen")
static int length(DynamicObjectStorage self,
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readNode,
@Cached DynamicObject.GetKeyArrayNode keyArrayNode) {
Object[] keys = keyArrayNode.execute(self.store);
int len = 0;
for (Object key : keys) {
len = incrementLen(self, readNode, len, key);
}
return len;
}

@Specialization(replaces = "cachedKeys")
static int length(DynamicObjectStorage self,
@Shared @Cached ReadAttributeFromPythonObjectNode readNode) {
return cachedKeys(self, self.store.getShape(), keyArray(self), readNode);
}

private static boolean hasStringKey(DynamicObjectStorage self, TruffleString key, ReadAttributeFromPythonObjectNode readNode) {
return readNode.execute(self.store, key, PNone.NO_VALUE) != PNone.NO_VALUE;
}
Expand Down Expand Up @@ -186,19 +175,19 @@ abstract static class GetItemNode extends Node {

@Specialization
static Object string(Node inliningTarget, DynamicObjectStorage self, TruffleString key, @SuppressWarnings("unused") long keyHash,
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
@Exclusive @Cached InlinedConditionProfile noValueProfile) {
Object result = readKey.execute(self.store, key, PNone.NO_VALUE);
@Shared @Cached ReadAttributeFromPythonObjectNode readKey,
@Shared @Cached InlinedConditionProfile noValueProfile) {
Object result = readKey.execute(inliningTarget, self.store, key, PNone.NO_VALUE);
return noValueProfile.profile(inliningTarget, result == PNone.NO_VALUE) ? null : result;
}

@Specialization(guards = "isBuiltinString.execute(inliningTarget, key)", limit = "1")
@Specialization(guards = "isBuiltinString.execute(inliningTarget, key)")
@InliningCutoff
static Object pstring(Node inliningTarget, DynamicObjectStorage self, PString key, @SuppressWarnings("unused") long keyHash,
@SuppressWarnings("unused") @Cached PyUnicodeCheckExactNode isBuiltinString,
@Cached CastToTruffleStringNode castStr,
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
@Exclusive @Cached InlinedConditionProfile noValueProfile) {
@SuppressWarnings("unused") @Shared @Cached PyUnicodeCheckExactNode isBuiltinString,
@Cached(inline = false) CastToTruffleStringNode castStr,
@Shared @Cached ReadAttributeFromPythonObjectNode readKey,
@Shared @Cached InlinedConditionProfile noValueProfile) {
return string(inliningTarget, self, castStr.execute(inliningTarget, key), -1, readKey, noValueProfile);
}

Expand All @@ -219,9 +208,9 @@ abstract static class GetItemNoStringKeyNode extends Node {
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
static Object notString(Frame frame, DynamicObjectStorage self, Object key, long hashIn,
@Bind Node inliningTarget,
@Shared("readKey") @Cached ReadAttributeFromPythonObjectNode readKey,
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
@Exclusive @Cached("self.store.getShape()") Shape cachedShape,
@Exclusive @Cached(value = "keyArray(cachedShape)", dimensions = 1) Object[] keyList,
@Exclusive @Cached(value = "keyArray(self)", dimensions = 1) Object[] keyList,
@Shared("eqNode") @Cached PyObjectRichCompareBool eqNode,
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
@Shared("noValueProfile") @Cached InlinedConditionProfile noValueProfile) {
Expand All @@ -240,7 +229,7 @@ static Object notString(Frame frame, DynamicObjectStorage self, Object key, long
@Specialization(replaces = "notString")
static Object notStringLoop(Frame frame, DynamicObjectStorage self, Object key, long hashIn,
@Bind Node inliningTarget,
@Shared("readKey") @Cached ReadAttributeFromPythonObjectNode readKey,
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
@Shared("eqNode") @Cached PyObjectRichCompareBool eqNode,
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
@Shared("noValueProfile") @Cached InlinedConditionProfile noValueProfile) {
Expand Down Expand Up @@ -280,7 +269,7 @@ void setStringKey(TruffleString key, Object value, DynamicObject.PutNode putNode
}

boolean shouldTransitionOnPut() {
// For now we do not use SIZE_THRESHOLD condition to transition storages that wrap
// For now, we do not use SIZE_THRESHOLD condition to transition storages that wrap
// dictionaries retrieved via object's __dict__
boolean notDunderDict = store instanceof Store;
int propertyCount = store.getShape().getPropertyCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
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.attributes.ReadAttributeFromPythonObjectNode;
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
import com.oracle.graal.python.nodes.util.CastBuiltinStringToTruffleStringNode;
Expand Down Expand Up @@ -146,6 +147,46 @@ static Object foreign(Node inliningTarget, ForeignHashingStorage self, Object ke
}
}

@GenerateUncached
@GenerateInline
@GenerateCached(false)
public abstract static class HashingStorageGetItemStringKey extends Node {
public abstract Object execute(Node inliningTarget, HashingStorage self, TruffleString key);

@Specialization
static Object economicMap(Node inliningTarget, EconomicMapStorage self, TruffleString key,
@Cached TruffleString.HashCodeNode hashCodeNode,
@Cached ObjectHashMap.GetNode getNode) {
return getNode.execute(null, inliningTarget, self.map, key, PyObjectHashNode.hash(key, hashCodeNode));
}

@Specialization
static Object dom(Node inliningTarget, DynamicObjectStorage self, TruffleString key,
@Cached ReadAttributeFromPythonObjectNode readKey,
@Cached InlinedConditionProfile noValueProfile) {
return DynamicObjectStorage.GetItemNode.string(inliningTarget, self, key, -1, readKey, noValueProfile);
}

@Specialization
@SuppressWarnings("unused")
static Object empty(EmptyStorage self, TruffleString key) {
return null;
}

@Specialization
@InliningCutoff
static Object keywords(Node inliningTarget, KeywordsStorage self, TruffleString key,
@Cached GetKeywordsStorageItemNode getNode) {
return getNode.execute(null, inliningTarget, self, key, -1);
}

@Specialization
static Object foreign(Node inliningTarget, ForeignHashingStorage self, TruffleString key,
@Cached ForeignHashingStorage.GetNode getNode) {
return getNode.execute(inliningTarget, self, key);
}
}

@GenerateUncached
@GenerateInline
@GenerateCached(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -360,15 +360,15 @@ int getExceptionExitStatus(
@Cached CastToJavaIntExactNode castToInt,
@Bind Node inliningTarget,
@Exclusive @Cached GetClassNode getClassNode,
@Cached ReadAttributeFromPythonObjectNode readNode,
@Cached(inline = true) ReadAttributeFromPythonObjectNode readNode,
@Exclusive @Cached InlinedBranchProfile unsupportedProfile,
@Shared("gil") @Cached GilNode gil) throws UnsupportedMessageException {
boolean mustRelease = gil.acquire();
try {
if (getExceptionType(inliningTarget, getClassNode, gil) == ExceptionType.EXIT) {
try {
// Avoiding getattr because this message shouldn't have side-effects
Object code = readNode.execute(this, T_CODE);
Object code = readNode.execute(inliningTarget, this, T_CODE);
if (code == PNone.NO_VALUE) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ static Object getModule(VirtualFrame frame, PBuiltinMethod self, @SuppressWarnin
@Bind Node inliningTarget,
@Cached("createFor($node)") BoundaryCallData boundaryCallData,
@Cached PyObjectLookupAttr lookup,
@Cached ReadAttributeFromPythonObjectNode readAttrNode) {
@Cached(inline = true) ReadAttributeFromPythonObjectNode readAttrNode) {
// No profiling, performance here is not very important
Object module = readAttrNode.execute(self, T___MODULE__, PNone.NO_VALUE);
Object module = readAttrNode.execute(inliningTarget, self, T___MODULE__, PNone.NO_VALUE);
if (module != PNone.NO_VALUE) {
return module;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -86,7 +86,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.attributes.MergedObjectTypeModuleGetAttributeNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromModuleNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
Expand Down Expand Up @@ -238,7 +237,8 @@ static Object doError(Object self, @SuppressWarnings("unused") Object dict,
@GenerateNodeFactory
public abstract static class ModuleGetattributeNode extends GetAttrBuiltinNode {
/**
* Keep in sync with {@link MergedObjectTypeModuleGetAttributeNode}
* Keep in sync with
* {@link com.oracle.graal.python.nodes.attributes.MergedObjectTypeModuleGetFixedAttributeNode}
*/
@Specialization
static Object getattribute(VirtualFrame frame, PythonModule self, Object keyObj,
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) 2014, Regents of the University of California
*
* All rights reserved.
Expand Down Expand Up @@ -119,7 +119,6 @@
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
import com.oracle.graal.python.nodes.attributes.MergedObjectTypeModuleGetAttributeNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
import com.oracle.graal.python.nodes.builtins.ListNodes;
Expand Down Expand Up @@ -510,7 +509,8 @@ public abstract static class GetAttributeNode extends GetAttrBuiltinNode {
* Keep in sync with
* {@link com.oracle.graal.python.builtins.objects.type.TypeBuiltins.GetattributeNode} and
* {@link com.oracle.graal.python.builtins.objects.thread.ThreadLocalBuiltins.GetAttributeNode}
* and {@link MergedObjectTypeModuleGetAttributeNode}
* and
* {@link com.oracle.graal.python.nodes.attributes.MergedObjectTypeModuleGetFixedAttributeNode}
*/
@Specialization
@SuppressWarnings("truffle-static-method")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,10 +55,8 @@

import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
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;
Expand Down Expand Up @@ -586,30 +584,6 @@ public static int getCodePoint(String characterName) {
}
}

/**
* Like {@link com.oracle.truffle.api.strings.TruffleString.EqualNode} but with the proper
* {@link InliningCutoff} since {@link com.oracle.truffle.api.strings.TruffleString.EqualNode}
* is too big for host inlining, at least when used in node guards.
*/
@GenerateInline
@GenerateCached(false)
@GenerateUncached
public abstract static class EqualNode extends Node {
public abstract boolean execute(Node inliningTarget, TruffleString left, TruffleString right);

@Specialization(guards = "left == right")
static boolean doIdentity(TruffleString left, TruffleString right) {
return true;
}

@InliningCutoff
@Fallback
static boolean doEquality(TruffleString left, TruffleString right,
@Cached TruffleString.EqualNode equalNode) {
return equalNode.execute(left, right, TS_ENCODING);
}
}

public static int codepointIndexToByteIndex(int codepointIndex) {
assert TS_ENCODING == TruffleString.Encoding.UTF_32 : "must be adapted when switching to a different encoding";
return codepointIndex << 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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 @@ -72,7 +72,6 @@
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.attributes.MergedObjectTypeModuleGetAttributeNode;
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;
Expand Down Expand Up @@ -141,7 +140,8 @@ public abstract static class GetAttributeNode extends GetAttrBuiltinNode {
* Keep in sync with
* {@link com.oracle.graal.python.builtins.objects.object.ObjectBuiltins.GetAttributeNode}
* and {@link com.oracle.graal.python.builtins.objects.type.TypeBuiltins.GetattributeNode}
* and {@link MergedObjectTypeModuleGetAttributeNode}
* and
* {@link com.oracle.graal.python.nodes.attributes.MergedObjectTypeModuleGetFixedAttributeNode}
*/
@Specialization
Object doIt(VirtualFrame frame, PThreadLocal object, Object keyObj,
Expand Down
Loading
Loading