| 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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class EnqueueTask extends CompilerTask { | 7 class EnqueueTask extends CompilerTask { |
| 8 final ResolutionEnqueuer resolution; | 8 final ResolutionEnqueuer resolution; |
| 9 final CodegenEnqueuer codegen; | 9 final CodegenEnqueuer codegen; |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 if (!addElementToWorkList(element, elements)) return; | 123 if (!addElementToWorkList(element, elements)) return; |
| 124 | 124 |
| 125 // Enable runtime type support if we discover a getter called runtimeType. | 125 // Enable runtime type support if we discover a getter called runtimeType. |
| 126 // We have to enable runtime type before hitting the codegen, so | 126 // We have to enable runtime type before hitting the codegen, so |
| 127 // that constructors know whether they need to generate code for | 127 // that constructors know whether they need to generate code for |
| 128 // runtime type. | 128 // runtime type. |
| 129 if (element.isGetter() && element.name == Compiler.RUNTIME_TYPE) { | 129 if (element.isGetter() && element.name == Compiler.RUNTIME_TYPE) { |
| 130 compiler.enabledRuntimeType = true; | 130 compiler.enabledRuntimeType = true; |
| 131 // TODO(ahe): Record precise dependency here. | 131 // TODO(ahe): Record precise dependency here. |
| 132 compiler.backend.registerRuntimeType(compiler.globalDependencies); | 132 compiler.backend.registerRuntimeType(this, compiler.globalDependencies); |
| 133 } else if (element == compiler.functionApplyMethod) { | 133 } else if (element == compiler.functionApplyMethod) { |
| 134 compiler.enabledFunctionApply = true; | 134 compiler.enabledFunctionApply = true; |
| 135 } else if (element == compiler.invokeOnMethod) { | 135 } else if (element == compiler.invokeOnMethod) { |
| 136 compiler.enabledInvokeOn = true; | 136 compiler.enabledInvokeOn = true; |
| 137 } | 137 } |
| 138 | 138 |
| 139 nativeEnqueuer.registerElement(element); | 139 nativeEnqueuer.registerElement(element); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // All field initializers must be resolved as they could | 245 // All field initializers must be resolved as they could |
| 246 // have an observable side-effect (and cannot be tree-shaken | 246 // have an observable side-effect (and cannot be tree-shaken |
| 247 // away). | 247 // away). |
| 248 addToWorkList(member); | 248 addToWorkList(member); |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 } else if (member.kind == ElementKind.FUNCTION) { | 251 } else if (member.kind == ElementKind.FUNCTION) { |
| 252 if (member.name == Compiler.NO_SUCH_METHOD) { | 252 if (member.name == Compiler.NO_SUCH_METHOD) { |
| 253 enableNoSuchMethod(member); | 253 enableNoSuchMethod(member); |
| 254 } | 254 } |
| 255 if (member.name == Compiler.CALL_OPERATOR_NAME) { |
| 256 if (!cls.typeVariables.isEmpty) { |
| 257 registerGenericCallMethod(member, compiler.globalDependencies); |
| 258 } |
| 259 } |
| 260 if (universe.hasInvocation(member, compiler)) { |
| 261 return addToWorkList(member); |
| 262 } |
| 255 // If there is a property access with the same name as a method we | 263 // If there is a property access with the same name as a method we |
| 256 // need to emit the method. | 264 // need to emit the method. |
| 257 if (universe.hasInvokedGetter(member, compiler)) { | 265 if (universe.hasInvokedGetter(member, compiler)) { |
| 258 // We will emit a closure, so make sure the bound closure class is | 266 if (!cls.typeVariables.isEmpty) { |
| 267 registerGenericClosure(member, compiler.globalDependencies); |
| 268 } |
| 269 // We will emit a closure, so make sure the closure class is |
| 259 // generated. | 270 // generated. |
| 260 registerInstantiatedClass(compiler.boundClosureClass, | 271 registerInstantiatedClass(compiler.boundClosureClass, |
| 261 // Precise dependency is not important here. | 272 // Precise dependency is not important here. |
| 262 compiler.globalDependencies); | 273 compiler.globalDependencies); |
| 263 return addToWorkList(member); | 274 return addToWorkList(member); |
| 264 } | 275 } |
| 265 // Store the member in [instanceFunctionsByName] to catch | 276 // Store the member in [instanceFunctionsByName] to catch |
| 266 // getters on the function. | 277 // getters on the function. |
| 267 Link<Element> members = instanceFunctionsByName.putIfAbsent( | 278 Link<Element> members = instanceFunctionsByName.putIfAbsent( |
| 268 memberName, () => const Link<Element>()); | 279 memberName, () => const Link<Element>()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 /// Called when [:new Symbol(...):] is seen. | 415 /// Called when [:new Symbol(...):] is seen. |
| 405 void registerNewSymbol(TreeElements elements) { | 416 void registerNewSymbol(TreeElements elements) { |
| 406 } | 417 } |
| 407 | 418 |
| 408 processLink(Map<String, Link<Element>> map, | 419 processLink(Map<String, Link<Element>> map, |
| 409 SourceString n, | 420 SourceString n, |
| 410 bool f(Element e)) { | 421 bool f(Element e)) { |
| 411 String memberName = n.slowToString(); | 422 String memberName = n.slowToString(); |
| 412 Link<Element> members = map[memberName]; | 423 Link<Element> members = map[memberName]; |
| 413 if (members != null) { | 424 if (members != null) { |
| 425 map[memberName] = const Link<Element>(); |
| 414 LinkBuilder<Element> remaining = new LinkBuilder<Element>(); | 426 LinkBuilder<Element> remaining = new LinkBuilder<Element>(); |
| 415 for (; !members.isEmpty; members = members.tail) { | 427 for (; !members.isEmpty; members = members.tail) { |
| 416 if (!f(members.head)) remaining.addLast(members.head); | 428 if (!f(members.head)) remaining.addLast(members.head); |
| 417 } | 429 } |
| 418 map[memberName] = remaining.toLink(); | 430 map[memberName] = remaining.toLink(map[memberName]); |
| 419 } | 431 } |
| 420 } | 432 } |
| 421 | 433 |
| 422 processInstanceMembers(SourceString n, bool f(Element e)) { | 434 processInstanceMembers(SourceString n, bool f(Element e)) { |
| 423 processLink(instanceMembersByName, n, f); | 435 processLink(instanceMembersByName, n, f); |
| 424 } | 436 } |
| 425 | 437 |
| 426 processInstanceFunctions(SourceString n, bool f(Element e)) { | 438 processInstanceFunctions(SourceString n, bool f(Element e)) { |
| 427 processLink(instanceFunctionsByName, n, f); | 439 processLink(instanceFunctionsByName, n, f); |
| 428 } | 440 } |
| 429 | 441 |
| 430 void handleUnseenSelector(SourceString methodName, Selector selector) { | 442 void handleUnseenSelector(SourceString methodName, Selector selector) { |
| 431 processInstanceMembers(methodName, (Element member) { | 443 processInstanceMembers(methodName, (Element member) { |
| 432 if (selector.appliesUnnamed(member, compiler)) { | 444 if (selector.appliesUnnamed(member, compiler)) { |
| 445 if (member.isFunction() && selector.isGetter()) { |
| 446 if (!member.getEnclosingClass().typeVariables.isEmpty) { |
| 447 registerGenericClosure(member, compiler.globalDependencies); |
| 448 } |
| 449 } |
| 433 if (member.isField() && member.getEnclosingClass().isNative()) { | 450 if (member.isField() && member.getEnclosingClass().isNative()) { |
| 434 if (selector.isGetter() || selector.isCall()) { | 451 if (selector.isGetter() || selector.isCall()) { |
| 435 nativeEnqueuer.registerFieldLoad(member); | 452 nativeEnqueuer.registerFieldLoad(member); |
| 436 // We have to also handle storing to the field because we only get | 453 // We have to also handle storing to the field because we only get |
| 437 // one look at each member and there might be a store we have not | 454 // one look at each member and there might be a store we have not |
| 438 // seen yet. | 455 // seen yet. |
| 439 // TODO(sra): Process fields for storing separately. | 456 // TODO(sra): Process fields for storing separately. |
| 440 nativeEnqueuer.registerFieldStore(member); | 457 nativeEnqueuer.registerFieldStore(member); |
| 441 } else { | 458 } else { |
| 442 assert(selector.isSetter()); | 459 assert(selector.isSetter()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 550 |
| 534 void registerFieldGetter(Element element) { | 551 void registerFieldGetter(Element element) { |
| 535 universe.fieldGetters.add(element); | 552 universe.fieldGetters.add(element); |
| 536 } | 553 } |
| 537 | 554 |
| 538 void registerFieldSetter(Element element) { | 555 void registerFieldSetter(Element element) { |
| 539 universe.fieldSetters.add(element); | 556 universe.fieldSetters.add(element); |
| 540 } | 557 } |
| 541 | 558 |
| 542 void registerIsCheck(DartType type, TreeElements elements) { | 559 void registerIsCheck(DartType type, TreeElements elements) { |
| 560 type = type.unalias(compiler); |
| 543 // Even in checked mode, type annotations for return type and argument | 561 // Even in checked mode, type annotations for return type and argument |
| 544 // types do not imply type checks, so there should never be a check | 562 // types do not imply type checks, so there should never be a check |
| 545 // against the type variable of a typedef. | 563 // against the type variable of a typedef. |
| 546 assert(type.kind != TypeKind.TYPE_VARIABLE || | 564 assert(type.kind != TypeKind.TYPE_VARIABLE || |
| 547 !type.element.enclosingElement.isTypedef()); | 565 !type.element.enclosingElement.isTypedef()); |
| 548 universe.isChecks.add(type); | 566 if (!type.isMalformed) { |
| 567 universe.isChecks.add(type); |
| 568 } |
| 549 compiler.backend.registerIsCheck(type, this, elements); | 569 compiler.backend.registerIsCheck(type, this, elements); |
| 550 } | 570 } |
| 551 | 571 |
| 552 /** | 572 /** |
| 553 * If a factory constructor is used with type arguments, we lose track | 573 * If a factory constructor is used with type arguments, we lose track |
| 554 * which arguments could be used to create instances of classes that use their | 574 * which arguments could be used to create instances of classes that use their |
| 555 * type variables as expressions, so we have to remember if we saw such a use. | 575 * type variables as expressions, so we have to remember if we saw such a use. |
| 556 */ | 576 */ |
| 557 void registerFactoryWithTypeArguments(TreeElements elements) { | 577 void registerFactoryWithTypeArguments(TreeElements elements) { |
| 558 universe.usingFactoryWithTypeArguments = true; | 578 universe.usingFactoryWithTypeArguments = true; |
| 559 } | 579 } |
| 560 | 580 |
| 561 void registerAsCheck(DartType type, TreeElements elements) { | 581 void registerAsCheck(DartType type, TreeElements elements) { |
| 562 registerIsCheck(type, elements); | 582 registerIsCheck(type, elements); |
| 563 compiler.backend.registerAsCheck(type, elements); | 583 compiler.backend.registerAsCheck(type, elements); |
| 564 } | 584 } |
| 565 | 585 |
| 586 void registerGenericCallMethod(Element element, TreeElements elements) { |
| 587 compiler.backend.registerGenericCallMethod(element, this, elements); |
| 588 universe.genericCallMethods.add(element); |
| 589 } |
| 590 |
| 591 void registerGenericClosure(Element element, TreeElements elements) { |
| 592 compiler.backend.registerGenericClosure(element, this, elements); |
| 593 universe.closurizedGenericMembers.add(element); |
| 594 } |
| 595 |
| 566 void forEach(f(WorkItem work)); | 596 void forEach(f(WorkItem work)); |
| 567 | 597 |
| 568 void forEachPostProcessTask(f(PostProcessTask work)) {} | 598 void forEachPostProcessTask(f(PostProcessTask work)) {} |
| 569 | 599 |
| 570 void logSummary(log(message)) { | 600 void logSummary(log(message)) { |
| 571 _logSpecificSummary(log); | 601 _logSpecificSummary(log); |
| 572 nativeEnqueuer.logSummary(log); | 602 nativeEnqueuer.logSummary(log); |
| 573 } | 603 } |
| 574 | 604 |
| 575 /// Log summary specific to the concrete enqueuer. | 605 /// Log summary specific to the concrete enqueuer. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 while(!queue.isEmpty) { | 799 while(!queue.isEmpty) { |
| 770 // TODO(johnniwinther): Find an optimal process order for codegen. | 800 // TODO(johnniwinther): Find an optimal process order for codegen. |
| 771 f(queue.removeLast()); | 801 f(queue.removeLast()); |
| 772 } | 802 } |
| 773 } | 803 } |
| 774 | 804 |
| 775 void _logSpecificSummary(log(message)) { | 805 void _logSpecificSummary(log(message)) { |
| 776 log('Compiled ${generatedCode.length} methods.'); | 806 log('Compiled ${generatedCode.length} methods.'); |
| 777 } | 807 } |
| 778 } | 808 } |
| OLD | NEW |