| 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 library dart2js.enqueue; | 5 library dart2js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import 'common/names.dart' show Identifiers; | 9 import 'common/names.dart' show Identifiers; |
| 10 import 'common/resolution.dart' show Resolution; | 10 import 'common/resolution.dart' show Resolution; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 if (member.isField) { | 221 if (member.isField) { |
| 222 // The obvious thing to test here would be "member.isNative", | 222 // The obvious thing to test here would be "member.isNative", |
| 223 // however, that only works after metadata has been parsed/analyzed, | 223 // however, that only works after metadata has been parsed/analyzed, |
| 224 // and that may not have happened yet. | 224 // and that may not have happened yet. |
| 225 // So instead we use the enclosing class, which we know have had | 225 // So instead we use the enclosing class, which we know have had |
| 226 // its metadata parsed and analyzed. | 226 // its metadata parsed and analyzed. |
| 227 // Note: this assumes that there are no non-native fields on native | 227 // Note: this assumes that there are no non-native fields on native |
| 228 // classes, which may not be the case when a native class is subclassed. | 228 // classes, which may not be the case when a native class is subclassed. |
| 229 if (compiler.backend.isNative(cls)) { | 229 if (compiler.backend.isNative(cls)) { |
| 230 compiler.world.registerUsedElement(member); | 230 compiler.openWorld.registerUsedElement(member); |
| 231 if (universe.hasInvokedGetter(member, compiler.world) || | 231 if (universe.hasInvokedGetter(member, compiler.openWorld) || |
| 232 universe.hasInvocation(member, compiler.world)) { | 232 universe.hasInvocation(member, compiler.openWorld)) { |
| 233 addToWorkList(member); | 233 addToWorkList(member); |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 if (universe.hasInvokedSetter(member, compiler.world)) { | 236 if (universe.hasInvokedSetter(member, compiler.openWorld)) { |
| 237 addToWorkList(member); | 237 addToWorkList(member); |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 // Native fields need to go into instanceMembersByName as they | 240 // Native fields need to go into instanceMembersByName as they |
| 241 // are virtual instantiation points and escape points. | 241 // are virtual instantiation points and escape points. |
| 242 } else { | 242 } else { |
| 243 // All field initializers must be resolved as they could | 243 // All field initializers must be resolved as they could |
| 244 // have an observable side-effect (and cannot be tree-shaken | 244 // have an observable side-effect (and cannot be tree-shaken |
| 245 // away). | 245 // away). |
| 246 addToWorkList(member); | 246 addToWorkList(member); |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 } else if (member.isFunction) { | 249 } else if (member.isFunction) { |
| 250 FunctionElement function = member; | 250 FunctionElement function = member; |
| 251 function.computeType(resolution); | 251 function.computeType(resolution); |
| 252 if (function.name == Identifiers.noSuchMethod_) { | 252 if (function.name == Identifiers.noSuchMethod_) { |
| 253 registerNoSuchMethod(function); | 253 registerNoSuchMethod(function); |
| 254 } | 254 } |
| 255 if (function.name == Identifiers.call && !cls.typeVariables.isEmpty) { | 255 if (function.name == Identifiers.call && !cls.typeVariables.isEmpty) { |
| 256 registerCallMethodWithFreeTypeVariables(function); | 256 registerCallMethodWithFreeTypeVariables(function); |
| 257 } | 257 } |
| 258 // If there is a property access with the same name as a method we | 258 // If there is a property access with the same name as a method we |
| 259 // need to emit the method. | 259 // need to emit the method. |
| 260 if (universe.hasInvokedGetter(function, compiler.world)) { | 260 if (universe.hasInvokedGetter(function, compiler.openWorld)) { |
| 261 registerClosurizedMember(function); | 261 registerClosurizedMember(function); |
| 262 addToWorkList(function); | 262 addToWorkList(function); |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 // Store the member in [instanceFunctionsByName] to catch | 265 // Store the member in [instanceFunctionsByName] to catch |
| 266 // getters on the function. | 266 // getters on the function. |
| 267 instanceFunctionsByName | 267 instanceFunctionsByName |
| 268 .putIfAbsent(memberName, () => new Set<Element>()) | 268 .putIfAbsent(memberName, () => new Set<Element>()) |
| 269 .add(member); | 269 .add(member); |
| 270 if (universe.hasInvocation(function, compiler.world)) { | 270 if (universe.hasInvocation(function, compiler.openWorld)) { |
| 271 addToWorkList(function); | 271 addToWorkList(function); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 } else if (member.isGetter) { | 274 } else if (member.isGetter) { |
| 275 FunctionElement getter = member; | 275 FunctionElement getter = member; |
| 276 getter.computeType(resolution); | 276 getter.computeType(resolution); |
| 277 if (universe.hasInvokedGetter(getter, compiler.world)) { | 277 if (universe.hasInvokedGetter(getter, compiler.openWorld)) { |
| 278 addToWorkList(getter); | 278 addToWorkList(getter); |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 // We don't know what selectors the returned closure accepts. If | 281 // We don't know what selectors the returned closure accepts. If |
| 282 // the set contains any selector we have to assume that it matches. | 282 // the set contains any selector we have to assume that it matches. |
| 283 if (universe.hasInvocation(getter, compiler.world)) { | 283 if (universe.hasInvocation(getter, compiler.openWorld)) { |
| 284 addToWorkList(getter); | 284 addToWorkList(getter); |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 } else if (member.isSetter) { | 287 } else if (member.isSetter) { |
| 288 FunctionElement setter = member; | 288 FunctionElement setter = member; |
| 289 setter.computeType(resolution); | 289 setter.computeType(resolution); |
| 290 if (universe.hasInvokedSetter(setter, compiler.world)) { | 290 if (universe.hasInvokedSetter(setter, compiler.openWorld)) { |
| 291 addToWorkList(setter); | 291 addToWorkList(setter); |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 // The element is not yet used. Add it to the list of instance | 296 // The element is not yet used. Add it to the list of instance |
| 297 // members to still be processed. | 297 // members to still be processed. |
| 298 instanceMembersByName | 298 instanceMembersByName |
| 299 .putIfAbsent(memberName, () => new Set<Element>()) | 299 .putIfAbsent(memberName, () => new Set<Element>()) |
| 300 .add(member); | 300 .add(member); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 530 } |
| 531 | 531 |
| 532 void handleUnseenSelector(DynamicUse universeSelector) { | 532 void handleUnseenSelector(DynamicUse universeSelector) { |
| 533 strategy.processDynamicUse(this, universeSelector); | 533 strategy.processDynamicUse(this, universeSelector); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void handleUnseenSelectorInternal(DynamicUse dynamicUse) { | 536 void handleUnseenSelectorInternal(DynamicUse dynamicUse) { |
| 537 Selector selector = dynamicUse.selector; | 537 Selector selector = dynamicUse.selector; |
| 538 String methodName = selector.name; | 538 String methodName = selector.name; |
| 539 processInstanceMembers(methodName, (Element member) { | 539 processInstanceMembers(methodName, (Element member) { |
| 540 if (dynamicUse.appliesUnnamed(member, compiler.world)) { | 540 if (dynamicUse.appliesUnnamed(member, compiler.openWorld)) { |
| 541 if (member.isFunction && selector.isGetter) { | 541 if (member.isFunction && selector.isGetter) { |
| 542 registerClosurizedMember(member); | 542 registerClosurizedMember(member); |
| 543 } | 543 } |
| 544 addToWorkList(member); | 544 addToWorkList(member); |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 return false; | 547 return false; |
| 548 }); | 548 }); |
| 549 if (selector.isGetter) { | 549 if (selector.isGetter) { |
| 550 processInstanceFunctions(methodName, (Element member) { | 550 processInstanceFunctions(methodName, (Element member) { |
| 551 if (dynamicUse.appliesUnnamed(member, compiler.world)) { | 551 if (dynamicUse.appliesUnnamed(member, compiler.openWorld)) { |
| 552 registerClosurizedMember(member); | 552 registerClosurizedMember(member); |
| 553 return true; | 553 return true; |
| 554 } | 554 } |
| 555 return false; | 555 return false; |
| 556 }); | 556 }); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 | 559 |
| 560 /** | 560 /** |
| 561 * Documentation wanted -- johnniwinther | 561 * Documentation wanted -- johnniwinther |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 if (element.isMalformed) return false; | 715 if (element.isMalformed) return false; |
| 716 | 716 |
| 717 assert(invariant(element, element is AnalyzableElement, | 717 assert(invariant(element, element is AnalyzableElement, |
| 718 message: 'Element $element is not analyzable.')); | 718 message: 'Element $element is not analyzable.')); |
| 719 if (hasBeenProcessed(element)) return false; | 719 if (hasBeenProcessed(element)) return false; |
| 720 if (queueIsClosed) { | 720 if (queueIsClosed) { |
| 721 throw new SpannableAssertionFailure( | 721 throw new SpannableAssertionFailure( |
| 722 element, "Resolution work list is closed. Trying to add $element."); | 722 element, "Resolution work list is closed. Trying to add $element."); |
| 723 } | 723 } |
| 724 | 724 |
| 725 compiler.world.registerUsedElement(element); | 725 compiler.openWorld.registerUsedElement(element); |
| 726 | 726 |
| 727 ResolutionWorkItem workItem = compiler.resolution.createWorkItem(element); | 727 ResolutionWorkItem workItem = compiler.resolution.createWorkItem(element); |
| 728 queue.add(workItem); | 728 queue.add(workItem); |
| 729 | 729 |
| 730 // Enable isolate support if we start using something from the isolate | 730 // Enable isolate support if we start using something from the isolate |
| 731 // library, or timers for the async library. We exclude constant fields, | 731 // library, or timers for the async library. We exclude constant fields, |
| 732 // which are ending here because their initializing expression is compiled. | 732 // which are ending here because their initializing expression is compiled. |
| 733 LibraryElement library = element.library; | 733 LibraryElement library = element.library; |
| 734 if (!compiler.hasIsolateSupport && (!element.isField || !element.isConst)) { | 734 if (!compiler.hasIsolateSupport && (!element.isField || !element.isConst)) { |
| 735 String uri = library.canonicalUri.toString(); | 735 String uri = library.canonicalUri.toString(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 } | 901 } |
| 902 | 902 |
| 903 typedef void _DeferredActionFunction(); | 903 typedef void _DeferredActionFunction(); |
| 904 | 904 |
| 905 class _DeferredAction { | 905 class _DeferredAction { |
| 906 final Element element; | 906 final Element element; |
| 907 final _DeferredActionFunction action; | 907 final _DeferredActionFunction action; |
| 908 | 908 |
| 909 _DeferredAction(this.element, this.action); | 909 _DeferredAction(this.element, this.action); |
| 910 } | 910 } |
| OLD | NEW |