Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
| 8 | 8 |
| 9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
| 10 | 10 |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 // TODO(ngeoffray): Type intercepted calls. | 1605 // TODO(ngeoffray): Type intercepted calls. |
| 1606 if (node.isInterceptorCall) return defaultSelector; | 1606 if (node.isInterceptorCall) return defaultSelector; |
| 1607 // If [JSInvocationMirror.invokeOn] has been called, we must not create a | 1607 // If [JSInvocationMirror.invokeOn] has been called, we must not create a |
| 1608 // typed selector based on the receiver type. | 1608 // typed selector based on the receiver type. |
| 1609 if (node.element == null && // Invocation is not exact. | 1609 if (node.element == null && // Invocation is not exact. |
| 1610 backend.compiler.enabledInvokeOn) { | 1610 backend.compiler.enabledInvokeOn) { |
| 1611 return defaultSelector; | 1611 return defaultSelector; |
| 1612 } | 1612 } |
| 1613 HType receiverHType = types[node.inputs[0]]; | 1613 HType receiverHType = types[node.inputs[0]]; |
| 1614 DartType receiverType = receiverHType.computeType(compiler); | 1614 DartType receiverType = receiverHType.computeType(compiler); |
| 1615 if (receiverType != null) { | 1615 if (receiverType != null && |
| 1616 !identical(receiverType.kind, TypeKind.MALFORMED_TYPE)) { | |
|
ngeoffray
2012/12/05 15:43:46
Is that important? If it's malformed, it will say
Johnni Winther
2012/12/05 18:33:51
It is to make a distinction between List<SomeMalfo
ngeoffray
2012/12/05 18:37:38
What I'm trying to understand is whether that will
Johnni Winther
2012/12/05 19:11:20
It's the latter.
| |
| 1616 return new TypedSelector(receiverType, defaultSelector); | 1617 return new TypedSelector(receiverType, defaultSelector); |
| 1617 } else { | 1618 } else { |
| 1618 return defaultSelector; | 1619 return defaultSelector; |
| 1619 } | 1620 } |
| 1620 } | 1621 } |
| 1621 | 1622 |
| 1622 visitInvokeDynamicSetter(HInvokeDynamicSetter node) { | 1623 visitInvokeDynamicSetter(HInvokeDynamicSetter node) { |
| 1623 use(node.receiver); | 1624 use(node.receiver); |
| 1624 Selector setter = node.selector; | 1625 Selector setter = node.selector; |
| 1625 String name = backend.namer.setterName(setter.library, setter.name); | 1626 String name = backend.namer.setterName(setter.library, setter.name); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1729 || node.element == backend.jsStringLength) { | 1730 || node.element == backend.jsStringLength) { |
| 1730 // We're accessing a native JavaScript property called 'length' | 1731 // We're accessing a native JavaScript property called 'length' |
| 1731 // on a JS String or a JS array. Therefore, the name of that | 1732 // on a JS String or a JS array. Therefore, the name of that |
| 1732 // property should not be mangled. | 1733 // property should not be mangled. |
| 1733 push(new js.PropertyAccess.field(pop(), 'length'), node); | 1734 push(new js.PropertyAccess.field(pop(), 'length'), node); |
| 1734 } else { | 1735 } else { |
| 1735 String name = _fieldPropertyName(node.element); | 1736 String name = _fieldPropertyName(node.element); |
| 1736 push(new js.PropertyAccess.field(pop(), name), node); | 1737 push(new js.PropertyAccess.field(pop(), name), node); |
| 1737 HType receiverHType = types[node.receiver]; | 1738 HType receiverHType = types[node.receiver]; |
| 1738 DartType type = receiverHType.computeType(compiler); | 1739 DartType type = receiverHType.computeType(compiler); |
| 1739 if (type != null) { | 1740 if (type != null && !identical(type.kind, TypeKind.MALFORMED_TYPE)) { |
|
ngeoffray
2012/12/05 15:43:46
ditto
| |
| 1740 world.registerFieldGetter( | 1741 world.registerFieldGetter( |
| 1741 node.element.name, node.element.getLibrary(), type); | 1742 node.element.name, node.element.getLibrary(), type); |
| 1742 } | 1743 } |
| 1743 } | 1744 } |
| 1744 } | 1745 } |
| 1745 | 1746 |
| 1746 visitFieldSet(HFieldSet node) { | 1747 visitFieldSet(HFieldSet node) { |
| 1747 String name = _fieldPropertyName(node.element); | 1748 String name = _fieldPropertyName(node.element); |
| 1748 DartType type = types[node.receiver].computeType(compiler); | 1749 DartType type = types[node.receiver].computeType(compiler); |
| 1749 if (type != null) { | 1750 if (type != null && !identical(type.kind, TypeKind.MALFORMED_TYPE)) { |
|
ngeoffray
2012/12/05 15:43:46
ditto
| |
| 1750 // Field setters in the generative constructor body are handled in a | 1751 // Field setters in the generative constructor body are handled in a |
| 1751 // step "SsaConstructionFieldTypes" in the ssa optimizer. | 1752 // step "SsaConstructionFieldTypes" in the ssa optimizer. |
| 1752 if (!work.element.isGenerativeConstructorBody()) { | 1753 if (!work.element.isGenerativeConstructorBody()) { |
| 1753 world.registerFieldSetter( | 1754 world.registerFieldSetter( |
| 1754 node.element.name, node.element.getLibrary(), type); | 1755 node.element.name, node.element.getLibrary(), type); |
| 1755 backend.registerFieldSetter( | 1756 backend.registerFieldSetter( |
| 1756 work.element, node.element, types[node.value]); | 1757 work.element, node.element, types[node.value]); |
| 1757 } | 1758 } |
| 1758 } | 1759 } |
| 1759 use(node.receiver); | 1760 use(node.receiver); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2073 backend.registerNonCallStaticUse(node); | 2074 backend.registerNonCallStaticUse(node); |
| 2074 if (node.element.isFunction()) { | 2075 if (node.element.isFunction()) { |
| 2075 world.registerInstantiatedClass(compiler.functionClass); | 2076 world.registerInstantiatedClass(compiler.functionClass); |
| 2076 } | 2077 } |
| 2077 } else if (instr.target != node) { | 2078 } else if (instr.target != node) { |
| 2078 backend.registerNonCallStaticUse(node); | 2079 backend.registerNonCallStaticUse(node); |
| 2079 } | 2080 } |
| 2080 }); | 2081 }); |
| 2081 Element element = node.element; | 2082 Element element = node.element; |
| 2082 world.registerStaticUse(element); | 2083 world.registerStaticUse(element); |
| 2083 ClassElement cls = element.getEnclosingClass(); | 2084 ClassElement cls = element.getEnclosingClass(); |
| 2084 if (element.isGenerativeConstructor() | 2085 if (element.isGenerativeConstructor() |
| 2085 || (element.isFactoryConstructor() && cls == compiler.listClass)) { | 2086 || (element.isFactoryConstructor() && cls == compiler.listClass)) { |
| 2086 world.registerInstantiatedClass(cls); | 2087 world.registerInstantiatedClass(cls); |
| 2087 } | 2088 } |
| 2088 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); | 2089 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); |
| 2089 } | 2090 } |
| 2090 | 2091 |
| 2091 void visitLazyStatic(HLazyStatic node) { | 2092 void visitLazyStatic(HLazyStatic node) { |
| 2092 Element element = node.element; | 2093 Element element = node.element; |
| 2093 world.registerStaticUse(element); | 2094 world.registerStaticUse(element); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2267 js.Expression functionTest = pop(); | 2268 js.Expression functionTest = pop(); |
| 2268 checkObject(input, '==='); | 2269 checkObject(input, '==='); |
| 2269 js.Expression objectTest = pop(); | 2270 js.Expression objectTest = pop(); |
| 2270 checkType(input, type); | 2271 checkType(input, type); |
| 2271 push(new js.Binary('||', | 2272 push(new js.Binary('||', |
| 2272 functionTest, | 2273 functionTest, |
| 2273 new js.Binary('&&', objectTest, pop()))); | 2274 new js.Binary('&&', objectTest, pop()))); |
| 2274 } | 2275 } |
| 2275 | 2276 |
| 2276 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2277 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
| 2278 assert(invariant(input, !type.isMalformed, | |
| 2279 message: 'Attempt to check malformed type $type')); | |
| 2277 world.registerIsCheck(type); | 2280 world.registerIsCheck(type); |
| 2278 Element element = type.element; | 2281 Element element = type.element; |
| 2279 use(input); | 2282 use(input); |
| 2280 js.PropertyAccess field = | 2283 js.PropertyAccess field = |
| 2281 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); | 2284 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); |
| 2282 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { | 2285 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { |
| 2283 push(new js.Call(field, <js.Expression>[])); | 2286 push(new js.Call(field, <js.Expression>[])); |
| 2284 if (negative) push(new js.Prefix('!', pop())); | 2287 if (negative) push(new js.Prefix('!', pop())); |
| 2285 } else { | 2288 } else { |
| 2286 // We always negate at least once so that the result is boolified. | 2289 // We always negate at least once so that the result is boolified. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2420 arguments = arguments.tail; | 2423 arguments = arguments.tail; |
| 2421 } | 2424 } |
| 2422 push(result, node); | 2425 push(result, node); |
| 2423 } | 2426 } |
| 2424 if (node.nullOk) { | 2427 if (node.nullOk) { |
| 2425 checkNull(input); | 2428 checkNull(input); |
| 2426 push(new js.Binary('||', pop(), pop()), node); | 2429 push(new js.Binary('||', pop(), pop()), node); |
| 2427 } | 2430 } |
| 2428 } | 2431 } |
| 2429 | 2432 |
| 2433 // TODO(johnniwinther): Refactor this method. | |
| 2430 void visitTypeConversion(HTypeConversion node) { | 2434 void visitTypeConversion(HTypeConversion node) { |
| 2431 Map<String, SourceString> castNames = const <String, SourceString> { | 2435 Map<String, SourceString> castNames = const <String, SourceString> { |
| 2432 "stringTypeCheck": | 2436 "stringTypeCheck": |
| 2433 const SourceString("stringTypeCast"), | 2437 const SourceString("stringTypeCast"), |
| 2434 "doubleTypeCheck": | 2438 "doubleTypeCheck": |
| 2435 const SourceString("doubleTypeCast"), | 2439 const SourceString("doubleTypeCast"), |
| 2436 "numTypeCheck": | 2440 "numTypeCheck": |
| 2437 const SourceString("numTypeCast"), | 2441 const SourceString("numTypeCast"), |
| 2438 "boolTypeCheck": | 2442 "boolTypeCheck": |
| 2439 const SourceString("boolTypeCast"), | 2443 const SourceString("boolTypeCast"), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2451 const SourceString("stringSuperTypeCast"), | 2455 const SourceString("stringSuperTypeCast"), |
| 2452 "listTypeCheck": | 2456 "listTypeCheck": |
| 2453 const SourceString("listTypeCast"), | 2457 const SourceString("listTypeCast"), |
| 2454 "listSuperNativeTypeCheck": | 2458 "listSuperNativeTypeCheck": |
| 2455 const SourceString("listSuperNativeTypeCast"), | 2459 const SourceString("listSuperNativeTypeCast"), |
| 2456 "listSuperTypeCheck": | 2460 "listSuperTypeCheck": |
| 2457 const SourceString("listSuperTypeCast"), | 2461 const SourceString("listSuperTypeCast"), |
| 2458 "callTypeCheck": | 2462 "callTypeCheck": |
| 2459 const SourceString("callTypeCast"), | 2463 const SourceString("callTypeCast"), |
| 2460 "propertyTypeCheck": | 2464 "propertyTypeCheck": |
| 2461 const SourceString("propertyTypeCast") | 2465 const SourceString("propertyTypeCast"), |
| 2466 // TODO(johnniwinther): Add a malformedTypeCast which produces a TypeError | |
| 2467 // with another message. | |
| 2468 "malformedTypeCheck": | |
| 2469 const SourceString("malformedTypeCheck") | |
| 2462 }; | 2470 }; |
| 2463 | 2471 |
| 2464 if (node.isChecked) { | 2472 if (node.isChecked) { |
| 2465 DartType type = node.type.computeType(compiler); | 2473 DartType type = node.type.computeType(compiler); |
| 2466 Element element = type.element; | 2474 Element element = type.element; |
| 2467 world.registerIsCheck(type); | 2475 world.registerIsCheck(type); |
| 2468 | 2476 |
| 2469 if (node.isArgumentTypeCheck) { | 2477 if (node.isArgumentTypeCheck) { |
| 2470 if (element == compiler.intClass) { | 2478 if (element == compiler.intClass) { |
| 2471 checkInt(node.checkedInput, '!=='); | 2479 checkInt(node.checkedInput, '!=='); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2492 helper = backend.getCheckedModeHelper(type); | 2500 helper = backend.getCheckedModeHelper(type); |
| 2493 if (node.isCastTypeCheck) { | 2501 if (node.isCastTypeCheck) { |
| 2494 helper = castNames[helper.stringValue]; | 2502 helper = castNames[helper.stringValue]; |
| 2495 } | 2503 } |
| 2496 } | 2504 } |
| 2497 FunctionElement helperElement = compiler.findHelper(helper); | 2505 FunctionElement helperElement = compiler.findHelper(helper); |
| 2498 world.registerStaticUse(helperElement); | 2506 world.registerStaticUse(helperElement); |
| 2499 List<js.Expression> arguments = <js.Expression>[]; | 2507 List<js.Expression> arguments = <js.Expression>[]; |
| 2500 use(node.checkedInput); | 2508 use(node.checkedInput); |
| 2501 arguments.add(pop()); | 2509 arguments.add(pop()); |
| 2502 if (helperElement.computeSignature(compiler).parameterCount != 1) { | 2510 int parameterCount = |
| 2511 helperElement.computeSignature(compiler).parameterCount; | |
| 2512 if (parameterCount == 2) { | |
| 2513 // 2 arguments implies that the method is either [propertyTypeCheck] | |
| 2514 // or [propertyTypeCast]. | |
| 2515 assert(!type.isMalformed); | |
| 2503 String additionalArgument = backend.namer.operatorIs(element); | 2516 String additionalArgument = backend.namer.operatorIs(element); |
| 2504 arguments.add(new js.LiteralString("'$additionalArgument'")); | 2517 arguments.add(new js.LiteralString("'$additionalArgument'")); |
| 2518 } else if (parameterCount == 3) { | |
| 2519 // 3 arguments implies that the method is [malformedTypeCheck]. | |
| 2520 assert(type.isMalformed); | |
| 2521 String reasons = fetchReasonsFromMalformedType(type); | |
| 2522 arguments.add(new js.LiteralString("'$type'")); | |
| 2523 // TODO(johnniwinther): Handle escaping correctly. | |
| 2524 arguments.add(new js.LiteralString("'$reasons'")); | |
| 2525 } else { | |
| 2526 assert(!type.isMalformed); | |
| 2505 } | 2527 } |
| 2506 String helperName = backend.namer.isolateAccess(helperElement); | 2528 String helperName = backend.namer.isolateAccess(helperElement); |
| 2507 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2529 push(new js.Call(new js.VariableUse(helperName), arguments)); |
| 2508 } else { | 2530 } else { |
| 2509 use(node.checkedInput); | 2531 use(node.checkedInput); |
| 2510 } | 2532 } |
| 2511 } | 2533 } |
| 2512 } | 2534 } |
| 2513 | 2535 |
| 2514 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2536 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3034 if (leftType.canBeNull() && rightType.canBeNull()) { | 3056 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 3035 if (left.isConstantNull() || right.isConstantNull() || | 3057 if (left.isConstantNull() || right.isConstantNull() || |
| 3036 (leftType.isPrimitive() && leftType == rightType)) { | 3058 (leftType.isPrimitive() && leftType == rightType)) { |
| 3037 return '=='; | 3059 return '=='; |
| 3038 } | 3060 } |
| 3039 return null; | 3061 return null; |
| 3040 } else { | 3062 } else { |
| 3041 return '==='; | 3063 return '==='; |
| 3042 } | 3064 } |
| 3043 } | 3065 } |
| OLD | NEW |