56
56
import com .oracle .graal .python .nodes .builtins .FunctionNodesFactory .GetKeywordDefaultsNodeGen ;
57
57
import com .oracle .graal .python .nodes .builtins .FunctionNodesFactory .GetSignatureNodeGen ;
58
58
import com .oracle .truffle .api .Assumption ;
59
+ import com .oracle .truffle .api .dsl .Bind ;
59
60
import com .oracle .truffle .api .dsl .Cached ;
61
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
60
62
import com .oracle .truffle .api .dsl .GenerateUncached ;
61
63
import com .oracle .truffle .api .dsl .ImportStatic ;
62
64
import com .oracle .truffle .api .dsl .Specialization ;
63
65
64
66
public abstract class FunctionNodes {
65
67
@ GenerateUncached
66
68
public abstract static class GetFunctionDefaultsNode extends PNodeWithContext {
69
+
67
70
public abstract Object [] execute (PFunction function );
68
71
69
72
@ Specialization (guards = {"self == cachedSelf" }, assumptions = {"singleContextAssumption()" , "defaultsStableAssumption" })
@@ -78,42 +81,41 @@ Object[] getDefaultsCached(@SuppressWarnings("unused") PFunction self,
78
81
Object [] getDefaults (PFunction self ) {
79
82
return self .getDefaults ();
80
83
}
81
-
82
- public static GetFunctionDefaultsNode create () {
83
- return GetFunctionDefaultsNodeGen .create ();
84
- }
85
84
}
86
85
87
86
@ ImportStatic (PGuards .class )
88
87
@ GenerateUncached
89
88
public abstract static class GetDefaultsNode extends PNodeWithContext {
90
- private static Object [] doFunctionInternal (GetFunctionDefaultsNode getFunctionDefaultsNode , PFunction function ) {
91
- return getFunctionDefaultsNode .execute (function );
92
- }
93
89
94
90
public abstract Object [] execute (Object function );
95
91
96
92
@ Specialization
97
93
Object [] doFunction (PFunction function ,
98
- @ Cached ( "create()" ) GetFunctionDefaultsNode getFunctionDefaultsNode ) {
99
- return doFunctionInternal ( getFunctionDefaultsNode , function );
94
+ @ Shared ( "get" ) @ Cached GetFunctionDefaultsNode getFunctionDefaultsNode ) {
95
+ return getFunctionDefaultsNode . execute ( function );
100
96
}
101
97
102
98
@ Specialization
103
99
Object [] doBuiltinFunction (PBuiltinFunction builtinFunction ) {
104
100
return builtinFunction .getDefaults ();
105
101
}
106
102
107
- @ Specialization (guards = "!isSameObject(method, method.getFunction())" )
108
- Object [] doMethod (PMethod method ,
109
- @ Cached ("create()" ) GetDefaultsNode getDefaultsNode ) {
110
- return getDefaultsNode .execute (method .getFunction ());
103
+ @ Specialization (guards = "isPFunction(function)" )
104
+ Object [] doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
105
+ @ Bind ("method.getFunction()" ) Object function ,
106
+ @ Shared ("get" ) @ Cached GetFunctionDefaultsNode getFunctionDefaultsNode ) {
107
+ return getFunctionDefaultsNode .execute ((PFunction ) function );
111
108
}
112
109
113
- @ Specialization (guards = "!isSameObject(builtinMethod, builtinMethod.getFunction())" )
114
- Object [] doBuiltinMethod (PBuiltinMethod builtinMethod ,
115
- @ Cached ("create()" ) GetDefaultsNode getDefaultsNode ) {
116
- return getDefaultsNode .execute (builtinMethod .getFunction ());
110
+ @ Specialization (guards = "isPBuiltinFunction(method.getFunction())" )
111
+ Object [] doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
112
+ @ Bind ("method.getFunction()" ) Object function ) {
113
+ return ((PBuiltinFunction ) function ).getDefaults ();
114
+ }
115
+
116
+ @ Specialization
117
+ Object [] doBuiltinMethod (PBuiltinMethod builtinMethod ) {
118
+ return builtinMethod .getFunction ().getDefaults ();
117
119
}
118
120
119
121
public static GetDefaultsNode create () {
@@ -123,6 +125,7 @@ public static GetDefaultsNode create() {
123
125
124
126
@ GenerateUncached
125
127
public abstract static class GetFunctionKeywordDefaultsNode extends PNodeWithContext {
128
+
126
129
public abstract PKeyword [] execute (PFunction function );
127
130
128
131
@ Specialization (guards = {"self == cachedSelf" }, assumptions = {"singleContextAssumption()" , "defaultsStableAssumption" })
@@ -137,42 +140,41 @@ PKeyword[] getKwDefaultsCached(@SuppressWarnings("unused") PFunction self,
137
140
PKeyword [] getKwDefaults (PFunction self ) {
138
141
return self .getKwDefaults ();
139
142
}
140
-
141
- public static GetFunctionKeywordDefaultsNode create () {
142
- return GetFunctionKeywordDefaultsNodeGen .create ();
143
- }
144
143
}
145
144
146
145
@ ImportStatic (PGuards .class )
147
146
@ GenerateUncached
148
147
public abstract static class GetKeywordDefaultsNode extends PNodeWithContext {
149
- private static PKeyword [] doFunctionInternal (GetFunctionKeywordDefaultsNode getFunctionKeywordDefaultsNode , PFunction function ) {
150
- return getFunctionKeywordDefaultsNode .execute (function );
151
- }
152
148
153
149
public abstract PKeyword [] execute (Object function );
154
150
155
151
@ Specialization
156
152
PKeyword [] doFunction (PFunction function ,
157
- @ Cached ( "create()" ) GetFunctionKeywordDefaultsNode getFunctionKeywordDefaultsNode ) {
158
- return doFunctionInternal ( getFunctionKeywordDefaultsNode , function );
153
+ @ Shared ( "get" ) @ Cached GetFunctionKeywordDefaultsNode getFunctionKeywordDefaultsNode ) {
154
+ return getFunctionKeywordDefaultsNode . execute ( function );
159
155
}
160
156
161
157
@ Specialization
162
158
PKeyword [] doBuiltinFunction (PBuiltinFunction builtinFunction ) {
163
159
return builtinFunction .getKwDefaults ();
164
160
}
165
161
166
- @ Specialization (guards = "!isSameObject(method, method.getFunction())" )
167
- PKeyword [] doMethod (PMethod method ,
168
- @ Cached ("create()" ) GetKeywordDefaultsNode getKeywordDefaultsNode ) {
169
- return getKeywordDefaultsNode .execute (method .getFunction ());
162
+ @ Specialization (guards = "isPFunction(function)" )
163
+ PKeyword [] doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
164
+ @ Bind ("method.getFunction()" ) Object function ,
165
+ @ Shared ("get" ) @ Cached GetFunctionKeywordDefaultsNode getFunctionKeywordDefaultsNode ) {
166
+ return getFunctionKeywordDefaultsNode .execute ((PFunction ) function );
167
+ }
168
+
169
+ @ Specialization (guards = "isPBuiltinFunction(method.getFunction())" )
170
+ PKeyword [] doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
171
+ @ Bind ("method.getFunction()" ) Object function ) {
172
+ return ((PBuiltinFunction ) function ).getKwDefaults ();
170
173
}
171
174
172
- @ Specialization (guards = "!isSameObject(builtinMethod, builtinMethod.getFunction())" )
173
- PKeyword [] doBuiltinMethod (PBuiltinMethod builtinMethod ,
174
- @ Cached ("create()" ) GetKeywordDefaultsNode getKeywordDefaultsNode ) {
175
- return getKeywordDefaultsNode .execute (builtinMethod .getFunction ());
175
+ @ Specialization
176
+ PKeyword [] doBuiltinMethod (PBuiltinMethod builtinMethod ) {
177
+ return builtinMethod .getFunction ().getKwDefaults ();
176
178
}
177
179
178
180
public static GetKeywordDefaultsNode create () {
@@ -182,6 +184,7 @@ public static GetKeywordDefaultsNode create() {
182
184
183
185
@ GenerateUncached
184
186
public abstract static class GetFunctionCodeNode extends PNodeWithContext {
187
+
185
188
public abstract PCode execute (PFunction function );
186
189
187
190
@ Specialization (guards = {"self == cachedSelf" }, assumptions = {"singleContextAssumption()" , "codeStableAssumption" })
@@ -196,43 +199,41 @@ PCode getCodeCached(@SuppressWarnings("unused") PFunction self,
196
199
PCode getCodeUncached (PFunction self ) {
197
200
return self .getCode ();
198
201
}
199
-
200
- public static GetFunctionCodeNode create () {
201
- return GetFunctionCodeNodeGen .create ();
202
- }
203
202
}
204
203
205
204
@ ImportStatic (PGuards .class )
206
205
@ GenerateUncached
207
206
public abstract static class GetSignatureNode extends PNodeWithContext {
208
- private static Signature doFunctionInternal (GetFunctionCodeNode getFunctionCodeNode , PFunction function ) {
209
- PCode code = getFunctionCodeNode .execute (function );
210
- return code .getSignature ();
211
- }
212
207
213
208
public abstract Signature execute (Object function );
214
209
215
210
@ Specialization
216
211
Signature doFunction (PFunction function ,
217
- @ Cached ( "create()" ) GetFunctionCodeNode getFunctionCodeNode ) {
218
- return doFunctionInternal ( getFunctionCodeNode , function );
212
+ @ Shared ( "get" ) @ Cached GetFunctionCodeNode getFunctionCodeNode ) {
213
+ return getFunctionCodeNode . execute ( function ). getSignature ( );
219
214
}
220
215
221
216
@ Specialization
222
217
Signature doBuiltinFunction (PBuiltinFunction builtinFunction ) {
223
218
return builtinFunction .getSignature ();
224
219
}
225
220
226
- @ Specialization (guards = "!isSameObject(method, method.getFunction())" )
227
- Signature doMethod (PMethod method ,
228
- @ Cached ("create()" ) GetSignatureNode getSignatureNode ) {
229
- return getSignatureNode .execute (method .getFunction ());
221
+ @ Specialization (guards = "isPFunction(function)" )
222
+ Signature doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
223
+ @ Bind ("method.getFunction()" ) Object function ,
224
+ @ Shared ("get" ) @ Cached GetFunctionCodeNode getFunctionCodeNode ) {
225
+ return getFunctionCodeNode .execute ((PFunction ) function ).getSignature ();
230
226
}
231
227
232
- @ Specialization (guards = "!isSameObject(builtinMethod, builtinMethod.getFunction())" )
233
- Signature doBuiltinMethod (PBuiltinMethod builtinMethod ,
234
- @ Cached ("create()" ) GetSignatureNode getSignatureNode ) {
235
- return getSignatureNode .execute (builtinMethod .getFunction ());
228
+ @ Specialization (guards = "isPBuiltinFunction(method.getFunction())" )
229
+ Signature doMethod (@ SuppressWarnings ("unused" ) PMethod method ,
230
+ @ Bind ("method.getFunction()" ) Object function ) {
231
+ return ((PBuiltinFunction ) function ).getSignature ();
232
+ }
233
+
234
+ @ Specialization
235
+ Signature doBuiltinMethod (PBuiltinMethod builtinMethod ) {
236
+ return builtinMethod .getFunction ().getSignature ();
236
237
}
237
238
238
239
public static GetSignatureNode create () {
0 commit comments