4141package com .oracle .graal .python .builtins .objects .itertools ;
4242
4343import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
44- import static com .oracle .graal .python .builtins .modules .ItertoolsModuleBuiltins .warnPickleDeprecated ;
4544import static com .oracle .graal .python .nodes .ErrorMessages .ARGUMENTS_MUST_BE_ITERATORS ;
4645import static com .oracle .graal .python .nodes .ErrorMessages .IS_NOT_A ;
4746import static com .oracle .graal .python .nodes .SpecialMethodNames .J___CLASS_GETITEM__ ;
5150import java .util .List ;
5251
5352import com .oracle .graal .python .PythonLanguage ;
53+ import com .oracle .graal .python .annotations .Builtin ;
5454import com .oracle .graal .python .annotations .Slot ;
5555import com .oracle .graal .python .annotations .Slot .SlotKind ;
5656import com .oracle .graal .python .annotations .Slot .SlotSignature ;
57- import com .oracle .graal .python .annotations .Builtin ;
5857import com .oracle .graal .python .builtins .CoreFunctions ;
5958import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
6059import com .oracle .graal .python .builtins .PythonBuiltins ;
60+ import com .oracle .graal .python .builtins .modules .ItertoolsModuleBuiltins .DeprecatedReduceBuiltin ;
61+ import com .oracle .graal .python .builtins .modules .ItertoolsModuleBuiltins .DeprecatedSetStateBuiltin ;
6162import com .oracle .graal .python .builtins .objects .PNone ;
6263import com .oracle .graal .python .builtins .objects .function .PKeyword ;
6364import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
64- import com .oracle .graal .python .builtins .objects .tuple .TupleBuiltins .GetItemNode ;
65- import com .oracle .graal .python .builtins .objects .tuple .TupleBuiltins .LenNode ;
6665import com .oracle .graal .python .builtins .objects .type .TpSlots ;
6766import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
6867import com .oracle .graal .python .builtins .objects .type .slots .TpSlotIterNext .TpIterNextBuiltin ;
6968import com .oracle .graal .python .lib .IteratorExhausted ;
7069import com .oracle .graal .python .lib .PyIterCheckNode ;
7170import com .oracle .graal .python .lib .PyIterNextNode ;
7271import com .oracle .graal .python .lib .PyObjectGetIter ;
72+ import com .oracle .graal .python .lib .PyTupleGetItem ;
73+ import com .oracle .graal .python .lib .PyTupleSizeNode ;
7374import com .oracle .graal .python .nodes .ErrorMessages ;
7475import com .oracle .graal .python .nodes .PRaiseNode ;
7576import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
8788import com .oracle .truffle .api .frame .VirtualFrame ;
8889import com .oracle .truffle .api .nodes .Node ;
8990import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
90- import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
9191import com .oracle .truffle .api .profiles .InlinedLoopConditionProfile ;
9292
9393@ CoreFunctions (extendClasses = {PythonBuiltinClassType .PChain })
@@ -195,19 +195,14 @@ static Object fromIter(VirtualFrame frame, @SuppressWarnings("unused") Object cl
195195
196196 @ Builtin (name = J___REDUCE__ , minNumOfPositionalArgs = 1 )
197197 @ GenerateNodeFactory
198- public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
198+ public abstract static class ReduceNode extends DeprecatedReduceBuiltin {
199199 @ Specialization
200- static Object reducePos (PChain self ,
201- @ Bind Node inliningTarget ,
202- @ Cached GetClassNode getClass ,
203- @ Cached InlinedConditionProfile hasSourceProfile ,
204- @ Cached InlinedConditionProfile hasActiveProfile ,
205- @ Bind PythonLanguage language ) {
206- warnPickleDeprecated ();
207- Object type = getClass .execute (inliningTarget , self );
200+ static Object reducePos (PChain self ) {
201+ Object type = GetClassNode .executeUncached (self );
202+ PythonLanguage language = PythonLanguage .get (null );
208203 PTuple empty = PFactory .createEmptyTuple (language );
209- if (hasSourceProfile . profile ( inliningTarget , self .getSource () != PNone .NONE ) ) {
210- if (hasActiveProfile . profile ( inliningTarget , self .getActive () != PNone .NONE ) ) {
204+ if (self .getSource () != PNone .NONE ) {
205+ if (self .getActive () != PNone .NONE ) {
211206 PTuple tuple = PFactory .createTuple (language , new Object []{self .getSource (), self .getActive ()});
212207 return PFactory .createTuple (language , new Object []{type , empty , tuple });
213208 } else {
@@ -222,38 +217,31 @@ static Object reducePos(PChain self,
222217
223218 @ Builtin (name = J___SETSTATE__ , minNumOfPositionalArgs = 2 )
224219 @ GenerateNodeFactory
225- public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
220+ public abstract static class SetStateNode extends DeprecatedSetStateBuiltin {
226221 @ Specialization
227- static Object setState (VirtualFrame frame , PChain self , Object state ,
228- @ Bind Node inliningTarget ,
229- @ Cached LenNode lenNode ,
230- @ Cached GetItemNode getItemNode ,
231- @ Cached InlinedBranchProfile len2Profile ,
232- @ Cached PyIterCheckNode iterCheckNode ,
233- @ Cached PRaiseNode raiseNode ) {
234- warnPickleDeprecated ();
222+ static Object setState (PChain self , Object state ,
223+ @ Bind Node node ) {
235224 if (!(state instanceof PTuple )) {
236- throw raiseNode . raise ( inliningTarget , TypeError , IS_NOT_A , "state" , "a length 1 or 2 tuple" );
225+ throw PRaiseNode . raiseStatic ( node , TypeError , IS_NOT_A , "state" , "a length 1 or 2 tuple" );
237226 }
238- int len = ( int ) lenNode . execute ( frame , state );
227+ int len = PyTupleSizeNode . executeUncached ( state );
239228 if (len < 1 || len > 2 ) {
240- throw raiseNode . raise ( inliningTarget , TypeError , IS_NOT_A , "state" , "a length 1 or 2 tuple" );
229+ throw PRaiseNode . raiseStatic ( node , TypeError , IS_NOT_A , "state" , "a length 1 or 2 tuple" );
241230 }
242- Object source = getItemNode . execute ( frame , state , 0 );
243- checkIterator (inliningTarget , iterCheckNode , source , raiseNode );
231+ Object source = PyTupleGetItem . executeUncached ( state , 0 );
232+ checkIterator (node , source );
244233 self .setSource (source );
245234 if (len == 2 ) {
246- len2Profile .enter (inliningTarget );
247- Object active = getItemNode .execute (frame , state , 1 );
248- checkIterator (inliningTarget , iterCheckNode , active , raiseNode );
235+ Object active = PyTupleGetItem .executeUncached (state , 1 );
236+ checkIterator (node , active );
249237 self .setActive (active );
250238 }
251239 return PNone .NONE ;
252240 }
253241
254- private static void checkIterator (Node inliningTarget , PyIterCheckNode iterCheckNode , Object obj , PRaiseNode raiseNode ) throws PException {
255- if (!iterCheckNode . execute ( inliningTarget , obj )) {
256- throw raiseNode . raise ( inliningTarget , TypeError , ARGUMENTS_MUST_BE_ITERATORS );
242+ private static void checkIterator (Node node , Object obj ) throws PException {
243+ if (!PyIterCheckNode . executeUncached ( obj )) {
244+ throw PRaiseNode . raiseStatic ( node , TypeError , ARGUMENTS_MUST_BE_ITERATORS );
257245 }
258246 }
259247 }
0 commit comments