222 return ((ScriptObject)base).getArray().getOptimisticType();
223 }
224 } else if (expr instanceof CallNode) {
225 // Currently, we'll only try to guess the return type of immediately invoked function expressions with no
226 // parameters, that is (function() { ... })(). We could do better, but these are all heuristics and we can
227 // gradually introduce them as needed. An easy one would be to do the same for .call(this) idiom.
228 final CallNode callExpr = (CallNode)expr;
229 final Expression fnExpr = callExpr.getFunction();
230 // Skip evaluation if running with eager compilation as we may violate constraints in RecompilableScriptFunctionData
231 if (fnExpr instanceof FunctionNode && compiler.getContext().getEnv()._lazy_compilation) {
232 final FunctionNode fn = (FunctionNode)fnExpr;
233 if (callExpr.getArgs().isEmpty()) {
234 final RecompilableScriptFunctionData data = compiler.getScriptFunctionData(fn.getId());
235 if (data != null) {
236 final Type returnType = Type.typeFor(data.getReturnType(EMPTY_INVOCATION_TYPE, runtimeScope));
237 if (returnType == Type.BOOLEAN) {
238 // We don't have optimistic booleans. In fact, optimistic call sites getting back boolean
239 // currently deoptimize all the way to Object.
240 return Type.OBJECT;
241 }
242 assert returnType == Type.INT || returnType == Type.LONG || returnType == Type.NUMBER || returnType == Type.OBJECT;
243 return returnType;
244 }
245 }
246 }
247 }
248
249 return null;
250 }
251 }
|
222 return ((ScriptObject)base).getArray().getOptimisticType();
223 }
224 } else if (expr instanceof CallNode) {
225 // Currently, we'll only try to guess the return type of immediately invoked function expressions with no
226 // parameters, that is (function() { ... })(). We could do better, but these are all heuristics and we can
227 // gradually introduce them as needed. An easy one would be to do the same for .call(this) idiom.
228 final CallNode callExpr = (CallNode)expr;
229 final Expression fnExpr = callExpr.getFunction();
230 // Skip evaluation if running with eager compilation as we may violate constraints in RecompilableScriptFunctionData
231 if (fnExpr instanceof FunctionNode && compiler.getContext().getEnv()._lazy_compilation) {
232 final FunctionNode fn = (FunctionNode)fnExpr;
233 if (callExpr.getArgs().isEmpty()) {
234 final RecompilableScriptFunctionData data = compiler.getScriptFunctionData(fn.getId());
235 if (data != null) {
236 final Type returnType = Type.typeFor(data.getReturnType(EMPTY_INVOCATION_TYPE, runtimeScope));
237 if (returnType == Type.BOOLEAN) {
238 // We don't have optimistic booleans. In fact, optimistic call sites getting back boolean
239 // currently deoptimize all the way to Object.
240 return Type.OBJECT;
241 }
242 assert returnType == Type.INT || returnType == Type.NUMBER || returnType == Type.OBJECT;
243 return returnType;
244 }
245 }
246 }
247 }
248
249 return null;
250 }
251 }
|