Skip to content

Commit be8d513

Browse files
committed
removed PythonObjectLibrary usages in ItertoolsModuleBuiltins
1 parent 309a34f commit be8d513

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ItertoolsModuleBuiltins.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
import com.oracle.graal.python.builtins.objects.itertools.PChain;
4343
import com.oracle.graal.python.builtins.objects.itertools.PRepeat;
4444
import com.oracle.graal.python.builtins.objects.itertools.PTeeDataObject;
45-
import com.oracle.graal.python.builtins.objects.itertools.TeeBuiltins.NewNode;
46-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
45+
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
4746
import com.oracle.graal.python.lib.PyCallableCheckNode;
4847
import com.oracle.graal.python.lib.PyObjectLookupAttr;
4948
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -60,7 +59,6 @@
6059
import com.oracle.truffle.api.dsl.NodeFactory;
6160
import com.oracle.truffle.api.dsl.Specialization;
6261
import com.oracle.truffle.api.frame.VirtualFrame;
63-
import com.oracle.truffle.api.library.CachedLibrary;
6462
import com.oracle.truffle.api.profiles.BranchProfile;
6563

6664
@CoreFunctions(defineModule = "itertools")
@@ -97,14 +95,15 @@ protected Object tee(VirtualFrame frame, Object iterable, int n,
9795
@Cached IterNode iterNode,
9896
@Cached PyObjectLookupAttr getAttrNode,
9997
@Cached PyCallableCheckNode callableCheckNode,
100-
@Cached NewNode newNode,
10198
@Cached CallVarargsMethodNode callNode,
10299
@Cached BranchProfile notCallableProfile) {
103100
Object it = iterNode.execute(frame, iterable, PNone.NO_VALUE);
104101
Object copyCallable = getAttrNode.execute(frame, it, __COPY__);
105102
if (!callableCheckNode.execute(copyCallable)) {
106103
notCallableProfile.enter();
107-
it = newNode.execute(frame, PythonBuiltinClassType.PTee, it);
104+
// as in Tee.__NEW__()
105+
PTeeDataObject dataObj = factory().createTeeDataObject(it);
106+
it = factory().createTee(dataObj, 0);
108107
}
109108

110109
// return tuple([it] + [it.__copy__() for i in range(1, n)])
@@ -124,14 +123,16 @@ protected Object tee(VirtualFrame frame, Object iterable, int n,
124123
@GenerateNodeFactory
125124
public abstract static class TeeDataObjectNode extends PythonVarargsBuiltinNode {
126125
@SuppressWarnings("unused")
127-
@Specialization(guards = "lib.isLazyPythonClass(cls)")
128-
protected PTeeDataObject construct(Object cls, Object[] arguments, PKeyword[] keywords, @CachedLibrary(limit = "3") PythonObjectLibrary lib) {
126+
@Specialization(guards = "isTypeNode.execute(cls)", limit = "1")
127+
protected PTeeDataObject construct(Object cls, Object[] arguments, PKeyword[] keywords,
128+
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode) {
129129
return factory().createTeeDataObject();
130130
}
131131

132132
@Fallback
133133
@SuppressWarnings("unused")
134-
protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords) {
134+
protected Object notype(Object cls, Object[] arguments, PKeyword[] keywords,
135+
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode) {
135136
throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
136137
}
137138
}
@@ -141,14 +142,15 @@ protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords)
141142
@GenerateNodeFactory
142143
public abstract static class RepeatNode extends PythonVarargsBuiltinNode {
143144
@SuppressWarnings("unused")
144-
@Specialization(guards = "lib.isLazyPythonClass(cls)")
145-
protected PRepeat construct(Object cls, Object[] arguments, PKeyword[] keywords, @CachedLibrary(limit = "3") PythonObjectLibrary lib) {
145+
@Specialization(guards = "isTypeNode.execute(cls)", limit = "1")
146+
protected PRepeat construct(Object cls, Object[] arguments, PKeyword[] keywords,
147+
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode) {
146148
return factory().createRepeat();
147149
}
148150

149151
@Fallback
150152
@SuppressWarnings("unused")
151-
protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords) {
153+
protected Object notype(Object cls, Object[] arguments, PKeyword[] keywords) {
152154
throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
153155
}
154156
}
@@ -158,14 +160,15 @@ protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords)
158160
@GenerateNodeFactory
159161
public abstract static class ChainNode extends PythonVarargsBuiltinNode {
160162
@SuppressWarnings("unused")
161-
@Specialization(guards = "lib.isLazyPythonClass(cls)")
162-
protected PChain construct(Object cls, Object[] arguments, PKeyword[] keywords, @CachedLibrary(limit = "3") PythonObjectLibrary lib) {
163+
@Specialization(guards = "isTypeNode.execute(cls)", limit = "1")
164+
protected PChain construct(Object cls, Object[] arguments, PKeyword[] keywords,
165+
@SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode) {
163166
return factory().createChain();
164167
}
165168

166169
@Fallback
167170
@SuppressWarnings("unused")
168-
protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords) {
171+
protected Object notype(Object cls, Object[] arguments, PKeyword[] keywords) {
169172
throw raise(TypeError, ErrorMessages.IS_NOT_TYPE_OBJ, "'cls'", cls);
170173
}
171174
}

0 commit comments

Comments
 (0)