| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import '../common/codegen.dart' show CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenWorkItem; |
| 6 import '../compiler.dart' show Compiler; | 6 import '../compiler.dart' show Compiler; |
| 7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../js_backend/backend_helpers.dart' show BackendHelpers; | 10 import '../js_backend/backend_helpers.dart' show BackendHelpers; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 293 } |
| 294 | 294 |
| 295 // Try computing a constant interceptor. | 295 // Try computing a constant interceptor. |
| 296 HInstruction constantInterceptor = | 296 HInstruction constantInterceptor = |
| 297 tryComputeConstantInterceptor(receiver, interceptedClasses); | 297 tryComputeConstantInterceptor(receiver, interceptedClasses); |
| 298 if (constantInterceptor != null) { | 298 if (constantInterceptor != null) { |
| 299 node.block.rewrite(node, constantInterceptor); | 299 node.block.rewrite(node, constantInterceptor); |
| 300 return false; | 300 return false; |
| 301 } | 301 } |
| 302 | 302 |
| 303 // If it is a conditional constant interceptor and was not strengthened to a |
| 304 // constant interceptor then there is nothing more we can do. |
| 305 if (node.isConditionalConstantInterceptor) return false; |
| 306 |
| 303 // Do we have an 'almost constant' interceptor? The receiver could be | 307 // Do we have an 'almost constant' interceptor? The receiver could be |
| 304 // `null` but not any other JavaScript falsy value, `null` values cause | 308 // `null` but not any other JavaScript falsy value, `null` values cause |
| 305 // `NoSuchMethodError`s, and if the receiver was not null we would have a | 309 // `NoSuchMethodError`s, and if the receiver was not null we would have a |
| 306 // constant interceptor `C`. Then we can use `(receiver && C)` for the | 310 // constant interceptor `C`. Then we can use `(receiver && C)` for the |
| 307 // interceptor. | 311 // interceptor. |
| 308 if (receiver.canBeNull() && !node.isConditionalConstantInterceptor) { | 312 if (receiver.canBeNull()) { |
| 309 if (!interceptedClasses.contains(helpers.jsNullClass)) { | 313 if (!interceptedClasses.contains(helpers.jsNullClass)) { |
| 310 // Can use `(receiver && C)` only if receiver is either null or truthy. | 314 // Can use `(receiver && C)` only if receiver is either null or truthy. |
| 311 if (!(receiver.canBePrimitiveNumber(compiler) || | 315 if (!(receiver.canBePrimitiveNumber(compiler) || |
| 312 receiver.canBePrimitiveBoolean(compiler) || | 316 receiver.canBePrimitiveBoolean(compiler) || |
| 313 receiver.canBePrimitiveString(compiler))) { | 317 receiver.canBePrimitiveString(compiler))) { |
| 314 ClassElement interceptorClass = tryComputeConstantInterceptorFromType( | 318 ClassElement interceptorClass = tryComputeConstantInterceptorFromType( |
| 315 receiver.instructionType.nonNullable(), interceptedClasses); | 319 receiver.instructionType.nonNullable(), interceptedClasses); |
| 316 if (interceptorClass != null) { | 320 if (interceptorClass != null) { |
| 317 HInstruction constantInstruction = graph.addConstant( | 321 HInstruction constantInstruction = graph.addConstant( |
| 318 new InterceptorConstantValue(interceptorClass.thisType), | 322 new InterceptorConstantValue(interceptorClass.thisType), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 instruction = new HInvokeDynamicMethod( | 419 instruction = new HInvokeDynamicMethod( |
| 416 selector, mask, inputs, node.instructionType, true); | 420 selector, mask, inputs, node.instructionType, true); |
| 417 } | 421 } |
| 418 | 422 |
| 419 HBasicBlock block = node.block; | 423 HBasicBlock block = node.block; |
| 420 block.addAfter(node, instruction); | 424 block.addAfter(node, instruction); |
| 421 block.rewrite(node, instruction); | 425 block.rewrite(node, instruction); |
| 422 return true; | 426 return true; |
| 423 } | 427 } |
| 424 } | 428 } |
| OLD | NEW |