@@ -77,7 +77,6 @@ public static CreateArgumentsNode create() {
77
77
}
78
78
79
79
@ Specialization (guards = {"isMethod(method)" , "method == cachedMethod" }, limit = "getVariableArgumentInlineCacheLimit()" )
80
- @ ExplodeLoop
81
80
Object [] doMethodCached (PythonObject method , Object [] userArguments , PKeyword [] keywords ,
82
81
@ Cached ("create()" ) CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
83
82
@ Cached ("method" ) @ SuppressWarnings ("unused" ) PythonObject cachedMethod ) {
@@ -93,8 +92,7 @@ Object[] doMethodCached(PythonObject method, Object[] userArguments, PKeyword[]
93
92
94
93
@ Specialization (guards = {"isMethod(method)" , "getFunction(method) == cachedFunction" ,
95
94
"getSelf(method) == cachedSelf" }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "doMethodCached" )
96
- @ ExplodeLoop
97
- Object [] doMethodFunctionCached (PythonObject method , Object [] userArguments , PKeyword [] keywords ,
95
+ Object [] doMethodFunctionAndSelfCached (PythonObject method , Object [] userArguments , PKeyword [] keywords ,
98
96
@ Cached ("create()" ) CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
99
97
@ Cached ("getFunction(method)" ) @ SuppressWarnings ("unused" ) Object cachedFunction ,
100
98
@ Cached ("getSelf(method)" ) Object cachedSelf ) {
@@ -107,8 +105,21 @@ Object[] doMethodFunctionCached(PythonObject method, Object[] userArguments, PKe
107
105
return createAndCheckArgumentsNode .execute (method , userArguments , keywords , arity , cachedSelf , defaults , kwdefaults , isMethodCall (cachedSelf ));
108
106
}
109
107
108
+ @ Specialization (guards = {"isMethod(method)" , "getFunction(method) == cachedFunction" }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "doMethodFunctionAndSelfCached" )
109
+ Object [] doMethodFunctionCached (PythonObject method , Object [] userArguments , PKeyword [] keywords ,
110
+ @ Cached ("create()" ) CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
111
+ @ Cached ("getFunction(method)" ) @ SuppressWarnings ("unused" ) Object cachedFunction ) {
112
+
113
+ // We do not directly cache these objects because they are compilation final anyway and the
114
+ // getter check the appropriate assumptions.
115
+ Arity arity = getArity (cachedFunction );
116
+ Object [] defaults = getDefaults (cachedFunction );
117
+ PKeyword [] kwdefaults = getKwDefaults (cachedFunction );
118
+ Object self = getSelf (method );
119
+ return createAndCheckArgumentsNode .execute (method , userArguments , keywords , arity , self , defaults , kwdefaults , isMethodCall (self ));
120
+ }
121
+
110
122
@ Specialization (guards = {"isFunction(callable)" , "callable == cachedCallable" }, limit = "getVariableArgumentInlineCacheLimit()" )
111
- @ ExplodeLoop
112
123
Object [] doFunctionCached (PythonObject callable , Object [] userArguments , PKeyword [] keywords ,
113
124
@ Cached ("create()" ) CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
114
125
@ Cached ("callable" ) @ SuppressWarnings ("unused" ) PythonObject cachedCallable ) {
@@ -121,17 +132,17 @@ Object[] doFunctionCached(PythonObject callable, Object[] userArguments, PKeywor
121
132
return createAndCheckArgumentsNode .execute (callable , userArguments , keywords , arity , null , defaults , kwdefaults , false );
122
133
}
123
134
124
- @ Specialization (replaces = {"doFunctionCached" , "doMethodCached" , "doMethodFunctionCached" })
135
+ @ Specialization (replaces = {"doFunctionCached" , "doMethodCached" , "doMethodFunctionAndSelfCached" , " doMethodFunctionCached" })
125
136
Object [] uncached (PythonObject callable , Object [] userArguments , PKeyword [] keywords ,
126
137
@ Cached ("create()" ) CreateAndCheckArgumentsNode createAndCheckArgumentsNode ) {
127
138
128
139
// mostly we will be calling proper functions directly here,
129
140
// but sometimes also methods that have functions directly.
130
141
// In all other cases, the arguments
131
142
132
- Arity arity = getArity (callable );
133
- Object [] defaults = getDefaults (callable );
134
- PKeyword [] kwdefaults = getKwDefaults (callable );
143
+ Arity arity = getArityUncached (callable );
144
+ Object [] defaults = getDefaultsUncached (callable );
145
+ PKeyword [] kwdefaults = getKwDefaultsUncached (callable );
135
146
Object self = getSelf (callable );
136
147
boolean methodcall = !(self instanceof PythonModule );
137
148
@@ -560,6 +571,18 @@ public static FindKwDefaultNode create() {
560
571
}
561
572
}
562
573
574
+ protected static Arity getArityUncached (Object callable ) {
575
+ return getProperty (callable , UncachedArityGetter .INSTANCE );
576
+ }
577
+
578
+ protected static Object [] getDefaultsUncached (Object callable ) {
579
+ return getProperty (callable , UncachedDefaultsGetter .INSTANCE );
580
+ }
581
+
582
+ protected static PKeyword [] getKwDefaultsUncached (Object callable ) {
583
+ return getProperty (callable , UncachedKwDefaultsGetter .INSTANCE );
584
+ }
585
+
563
586
protected static Arity getArity (Object callable ) {
564
587
return getProperty (callable , ArityGetter .INSTANCE );
565
588
}
@@ -670,6 +693,48 @@ public PKeyword[] fromPBuiltinFunction(PBuiltinFunction fun) {
670
693
}
671
694
}
672
695
696
+ private static final class UncachedArityGetter extends Getter <Arity > {
697
+ private static final UncachedArityGetter INSTANCE = new UncachedArityGetter ();
698
+
699
+ @ Override
700
+ public Arity fromPFunction (PFunction fun ) {
701
+ return fun .getUncachedCode ().getArity ();
702
+ }
703
+
704
+ @ Override
705
+ public Arity fromPBuiltinFunction (PBuiltinFunction fun ) {
706
+ return fun .getArity ();
707
+ }
708
+ }
709
+
710
+ private static final class UncachedDefaultsGetter extends Getter <Object []> {
711
+ private static final UncachedDefaultsGetter INSTANCE = new UncachedDefaultsGetter ();
712
+
713
+ @ Override
714
+ public Object [] fromPFunction (PFunction fun ) {
715
+ return fun .getUncachedDefaultValues ();
716
+ }
717
+
718
+ @ Override
719
+ public Object [] fromPBuiltinFunction (PBuiltinFunction fun ) {
720
+ return fun .getDefaults ();
721
+ }
722
+ }
723
+
724
+ private static final class UncachedKwDefaultsGetter extends Getter <PKeyword []> {
725
+ private static final UncachedKwDefaultsGetter INSTANCE = new UncachedKwDefaultsGetter ();
726
+
727
+ @ Override
728
+ public PKeyword [] fromPFunction (PFunction fun ) {
729
+ return fun .getUncachedKwDefaults ();
730
+ }
731
+
732
+ @ Override
733
+ public PKeyword [] fromPBuiltinFunction (PBuiltinFunction fun ) {
734
+ return fun .getKwDefaults ();
735
+ }
736
+ }
737
+
673
738
private static final class NameGetter extends Getter <String > {
674
739
private static final NameGetter INSTANCE = new NameGetter ();
675
740
0 commit comments