@@ -1633,23 +1633,17 @@ public int len(VirtualFrame frame, Object obj,
16331633 }
16341634 }
16351635
1636- public abstract static class MinMaxNode extends PythonBuiltinNode {
1637- @ NeverDefault
1638- protected final BinaryComparisonNode createComparison () {
1639- if (this instanceof MaxNode ) {
1640- return BinaryComparisonNode .GtNode .create ();
1641- } else {
1642- return BinaryComparisonNode .LtNode .create ();
1643- }
1644- }
1636+ @ GenerateInline
1637+ @ GenerateCached (false )
1638+ public abstract static class MinMaxNode extends Node {
1639+
1640+ abstract Object execute (VirtualFrame frame , Node inliningTarget , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal , String name , BinaryComparisonNode comparisonNode );
16451641
16461642 @ Specialization (guards = "args.length == 0" )
1647- @ SuppressWarnings ("truffle-static-method" ) // TODO: inh
1648- Object minmaxSequenceWithKey (VirtualFrame frame , Object arg1 , @ SuppressWarnings ("unused" ) Object [] args , Object keywordArgIn , Object defaultVal ,
1649- @ Bind ("this" ) Node inliningTarget ,
1643+ static Object minmaxSequenceWithKey (VirtualFrame frame , Node inliningTarget , Object arg1 , @ SuppressWarnings ("unused" ) Object [] args , Object keywordArgIn , Object defaultVal , String name ,
1644+ BinaryComparisonNode compare ,
16501645 @ Exclusive @ Cached PyObjectGetIter getIter ,
1651- @ Cached GetNextNode nextNode ,
1652- @ Shared @ Cached ("createComparison()" ) BinaryComparisonNode compare ,
1646+ @ Cached (inline = false ) GetNextNode nextNode ,
16531647 @ Exclusive @ Cached CoerceToBooleanNode .YesNode castToBooleanNode ,
16541648 @ Exclusive @ Cached CallNode .Lazy keyCall ,
16551649 @ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
@@ -1668,7 +1662,7 @@ Object minmaxSequenceWithKey(VirtualFrame frame, Object arg1, @SuppressWarnings(
16681662 } catch (PException e ) {
16691663 e .expectStopIteration (inliningTarget , errorProfile1 );
16701664 if (hasDefaultProfile .profile (inliningTarget , isNoValue (defaultVal ))) {
1671- throw raiseNode .get (inliningTarget ).raise (PythonErrorType .ValueError , ErrorMessages .ARG_IS_EMPTY_SEQ , getName () );
1665+ throw raiseNode .get (inliningTarget ).raise (PythonErrorType .ValueError , ErrorMessages .ARG_IS_EMPTY_SEQ , name );
16721666 } else {
16731667 return defaultVal ;
16741668 }
@@ -1708,15 +1702,8 @@ Object minmaxSequenceWithKey(VirtualFrame frame, Object arg1, @SuppressWarnings(
17081702 return currentValue ;
17091703 }
17101704
1711- private String getName () {
1712- return this instanceof MaxNode ? "max" : "min" ;
1713- }
1714-
17151705 @ Specialization (guards = {"args.length != 0" })
1716- @ SuppressWarnings ("truffle-static-method" ) // TODO: inh
1717- Object minmaxBinaryWithKey (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1718- @ Bind ("this" ) Node inliningTarget ,
1719- @ Shared @ Cached ("createComparison()" ) BinaryComparisonNode compare ,
1706+ static Object minmaxBinaryWithKey (VirtualFrame frame , Node inliningTarget , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal , String name , BinaryComparisonNode compare ,
17201707 @ Exclusive @ Cached CallNode .Lazy keyCall ,
17211708 @ Exclusive @ Cached CoerceToBooleanNode .YesNode castToBooleanNode ,
17221709 @ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
@@ -1730,7 +1717,7 @@ Object minmaxBinaryWithKey(VirtualFrame frame, Object arg1, Object[] args, Objec
17301717 Object keywordArg = kwArgsAreNone ? null : keywordArgIn ;
17311718
17321719 if (!hasDefaultProfile .profile (inliningTarget , isNoValue (defaultVal ))) {
1733- throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .TypeError , ErrorMessages .CANNOT_SPECIFY_DEFAULT_FOR_S , getName () );
1720+ throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .TypeError , ErrorMessages .CANNOT_SPECIFY_DEFAULT_FOR_S , name );
17341721 }
17351722 Object currentValue = arg1 ;
17361723 Object currentKey = applyKeyFunction (frame , inliningTarget , keywordArg , keyCall , currentValue );
@@ -1787,16 +1774,29 @@ private static Object applyKeyFunction(VirtualFrame frame, Node inliningTarget,
17871774 "max(arg1, arg2, *args, *[, key=func]) -> value\n \n " + "With a single iterable argument, return its biggest item. The\n " +
17881775 "default keyword-only argument specifies an object to return if\n " + "the provided iterable is empty.\n " + "With two or more arguments, return the largest argument." )
17891776 @ GenerateNodeFactory
1790- public abstract static class MaxNode extends MinMaxNode {
1777+ public abstract static class MaxNode extends PythonBuiltinNode {
17911778
1779+ @ Specialization
1780+ static Object max (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1781+ @ Bind ("this" ) Node inliningTarget ,
1782+ @ Cached MinMaxNode minMaxNode ,
1783+ @ Cached BinaryComparisonNode .GtNode gtNode ) {
1784+ return minMaxNode .execute (frame , inliningTarget , arg1 , args , keywordArgIn , defaultVal , "max" , gtNode );
1785+ }
17921786 }
17931787
17941788 // min(iterable, *[, key])
17951789 // min(arg1, arg2, *args[, key])
17961790 @ Builtin (name = J_MIN , minNumOfPositionalArgs = 1 , takesVarArgs = true , keywordOnlyNames = {"key" , "default" })
17971791 @ GenerateNodeFactory
1798- public abstract static class MinNode extends MinMaxNode {
1799-
1792+ public abstract static class MinNode extends PythonBuiltinNode {
1793+ @ Specialization
1794+ static Object min (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1795+ @ Bind ("this" ) Node inliningTarget ,
1796+ @ Cached MinMaxNode minMaxNode ,
1797+ @ Cached BinaryComparisonNode .LtNode ltNode ) {
1798+ return minMaxNode .execute (frame , inliningTarget , arg1 , args , keywordArgIn , defaultVal , "min" , ltNode );
1799+ }
18001800 }
18011801
18021802 // next(iterator[, default])
0 commit comments