| 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.world; | 5 library dart2js.world; |
| 6 | 6 |
| 7 import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX; | 7 import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX; |
| 8 import 'common/backend_api.dart' show BackendClasses; | 8 import 'common/backend_api.dart' show BackendClasses; |
| 9 import 'common.dart'; | 9 import 'common.dart'; |
| 10 import 'constants/constant_system.dart'; | 10 import 'constants/constant_system.dart'; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 /// Adds the closure class [cls] to the inference world. The class is | 357 /// Adds the closure class [cls] to the inference world. The class is |
| 358 /// considered directly instantiated. | 358 /// considered directly instantiated. |
| 359 void registerClosureClass(ClassElement cls); | 359 void registerClosureClass(ClassElement cls); |
| 360 } | 360 } |
| 361 | 361 |
| 362 abstract class OpenWorld implements World { | 362 abstract class OpenWorld implements World { |
| 363 /// Called to add [cls] to the set of known classes. | 363 /// Called to add [cls] to the set of known classes. |
| 364 /// | 364 /// |
| 365 /// This ensures that class hierarchy queries can be performed on [cls] and | 365 /// This ensures that class hierarchy queries can be performed on [cls] and |
| 366 /// classes that extend or implement it. | 366 /// classes that extend or implement it. |
| 367 void registerClass(ClassElement cls); | 367 void registerClass(ClassEntity cls); |
| 368 | 368 |
| 369 void registerUsedElement(MemberElement element); | 369 void registerUsedElement(MemberEntity element); |
| 370 void registerTypedef(TypedefElement typedef); | 370 void registerTypedef(TypedefElement typedef); |
| 371 | 371 |
| 372 ClosedWorld closeWorld(DiagnosticReporter reporter); | 372 ClosedWorld closeWorld(DiagnosticReporter reporter); |
| 373 | 373 |
| 374 /// Returns an iterable over all mixin applications that mixin [cls]. | 374 /// Returns an iterable over all mixin applications that mixin [cls]. |
| 375 Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls); | 375 Iterable<ClassEntity> allMixinUsesOf(ClassEntity cls); |
| 376 } | 376 } |
| 377 | 377 |
| 378 /// Enum values defining subset of classes included in queries. | 378 /// Enum values defining subset of classes included in queries. |
| 379 enum ClassQuery { | 379 enum ClassQuery { |
| 380 /// Only the class itself is included. | 380 /// Only the class itself is included. |
| 381 EXACT, | 381 EXACT, |
| 382 | 382 |
| 383 /// The class and all subclasses (transitively) are included. | 383 /// The class and all subclasses (transitively) are included. |
| 384 SUBCLASS, | 384 SUBCLASS, |
| 385 | 385 |
| 386 /// The class and all classes that implement or subclass it (transitively) | 386 /// The class and all classes that implement or subclass it (transitively) |
| 387 /// are included. | 387 /// are included. |
| 388 SUBTYPE, | 388 SUBTYPE, |
| 389 } | 389 } |
| 390 | 390 |
| 391 class ClosedWorldImpl implements ClosedWorld, ClosedWorldRefiner { | 391 class ClosedWorldImpl implements ClosedWorld, ClosedWorldRefiner { |
| 392 final JavaScriptBackend _backend; | 392 final JavaScriptBackend _backend; |
| 393 BackendClasses get backendClasses => _backend.backendClasses; | 393 BackendClasses get backendClasses => _backend.backendClasses; |
| 394 InterceptorData get interceptorData => _backend.interceptorData; | 394 InterceptorData get interceptorData => _backend.interceptorData; |
| 395 FunctionSet _allFunctions; | 395 FunctionSet _allFunctions; |
| 396 | 396 |
| 397 final Iterable<TypedefElement> _allTypedefs; | 397 final Iterable<TypedefElement> _allTypedefs; |
| 398 | 398 |
| 399 final Map<ClassElement, Set<MixinApplicationElement>> _mixinUses; | 399 final Map<ClassEntity, Set<ClassEntity>> _mixinUses; |
| 400 Map<ClassElement, List<MixinApplicationElement>> _liveMixinUses; | 400 Map<ClassElement, List<MixinApplicationElement>> _liveMixinUses; |
| 401 | 401 |
| 402 final Map<ClassElement, Set<ClassElement>> _typesImplementedBySubclasses; | 402 final Map<ClassEntity, Set<ClassEntity>> _typesImplementedBySubclasses; |
| 403 | 403 |
| 404 // We keep track of subtype and subclass relationships in four | 404 // We keep track of subtype and subclass relationships in four |
| 405 // distinct sets to make class hierarchy analysis faster. | 405 // distinct sets to make class hierarchy analysis faster. |
| 406 final Map<ClassElement, ClassHierarchyNode> _classHierarchyNodes; | 406 final Map<ClassEntity, ClassHierarchyNode> _classHierarchyNodes; |
| 407 final Map<ClassElement, ClassSet> _classSets; | 407 final Map<ClassEntity, ClassSet> _classSets; |
| 408 | 408 |
| 409 final Map<ClassElement, Map<ClassElement, bool>> _subtypeCoveredByCache = | 409 final Map<ClassElement, Map<ClassElement, bool>> _subtypeCoveredByCache = |
| 410 <ClassElement, Map<ClassElement, bool>>{}; | 410 <ClassElement, Map<ClassElement, bool>>{}; |
| 411 | 411 |
| 412 final Set<Element> functionsCalledInLoop = new Set<Element>(); | 412 final Set<Element> functionsCalledInLoop = new Set<Element>(); |
| 413 final Map<Element, SideEffects> sideEffects = new Map<Element, SideEffects>(); | 413 final Map<Element, SideEffects> sideEffects = new Map<Element, SideEffects>(); |
| 414 | 414 |
| 415 final Set<Element> sideEffectsFreeElements = new Set<Element>(); | 415 final Set<Element> sideEffectsFreeElements = new Set<Element>(); |
| 416 | 416 |
| 417 final Set<Element> elementsThatCannotThrow = new Set<Element>(); | 417 final Set<Element> elementsThatCannotThrow = new Set<Element>(); |
| 418 | 418 |
| 419 final Set<Element> functionsThatMightBePassedToApply = | 419 final Set<Element> functionsThatMightBePassedToApply = |
| 420 new Set<FunctionElement>(); | 420 new Set<FunctionElement>(); |
| 421 | 421 |
| 422 CommonMasks _commonMasks; | 422 CommonMasks _commonMasks; |
| 423 | 423 |
| 424 final CommonElements commonElements; | 424 final CommonElements commonElements; |
| 425 | 425 |
| 426 final ResolutionWorldBuilder _resolverWorld; | 426 final ResolutionWorldBuilder _resolverWorld; |
| 427 | 427 |
| 428 bool get isClosed => true; | 428 bool get isClosed => true; |
| 429 | 429 |
| 430 ClosedWorldImpl( | 430 ClosedWorldImpl( |
| 431 {JavaScriptBackend backend, | 431 {JavaScriptBackend backend, |
| 432 this.commonElements, | 432 this.commonElements, |
| 433 ResolutionWorldBuilder resolutionWorldBuilder, | 433 ResolutionWorldBuilder resolutionWorldBuilder, |
| 434 FunctionSetBuilder functionSetBuilder, | 434 FunctionSetBuilder functionSetBuilder, |
| 435 Iterable<TypedefElement> allTypedefs, | 435 Iterable<TypedefElement> allTypedefs, |
| 436 Map<ClassElement, Set<MixinApplicationElement>> mixinUses, | 436 Map<ClassEntity, Set<ClassEntity>> mixinUses, |
| 437 Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses, | 437 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, |
| 438 Map<ClassElement, ClassHierarchyNode> classHierarchyNodes, | 438 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, |
| 439 Map<ClassElement, ClassSet> classSets}) | 439 Map<ClassEntity, ClassSet> classSets}) |
| 440 : this._backend = backend, | 440 : this._backend = backend, |
| 441 this._resolverWorld = resolutionWorldBuilder, | 441 this._resolverWorld = resolutionWorldBuilder, |
| 442 this._allTypedefs = allTypedefs, | 442 this._allTypedefs = allTypedefs, |
| 443 this._mixinUses = mixinUses, | 443 this._mixinUses = mixinUses, |
| 444 this._typesImplementedBySubclasses = typesImplementedBySubclasses, | 444 this._typesImplementedBySubclasses = typesImplementedBySubclasses, |
| 445 this._classHierarchyNodes = classHierarchyNodes, | 445 this._classHierarchyNodes = classHierarchyNodes, |
| 446 this._classSets = classSets { | 446 this._classSets = classSets { |
| 447 _commonMasks = new CommonMasks(this); | 447 _commonMasks = new CommonMasks(this); |
| 448 _allFunctions = functionSetBuilder.close(this); | 448 _allFunctions = functionSetBuilder.close(this); |
| 449 } | 449 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 _subtypeCoveredByCache[x] ??= <ClassElement, bool>{}; | 907 _subtypeCoveredByCache[x] ??= <ClassElement, bool>{}; |
| 908 return secondMap[y] ??= subtypesOf(x).every((ClassElement cls) => | 908 return secondMap[y] ??= subtypesOf(x).every((ClassElement cls) => |
| 909 isSubclassOf(cls, y) || isSubclassOfMixinUseOf(cls, y)); | 909 isSubclassOf(cls, y) || isSubclassOfMixinUseOf(cls, y)); |
| 910 } | 910 } |
| 911 | 911 |
| 912 /// Returns `true` if any subclass of [superclass] implements [type]. | 912 /// Returns `true` if any subclass of [superclass] implements [type]. |
| 913 bool hasAnySubclassThatImplements( | 913 bool hasAnySubclassThatImplements( |
| 914 ClassElement superclass, ClassElement type) { | 914 ClassElement superclass, ClassElement type) { |
| 915 assert(isClosed); | 915 assert(isClosed); |
| 916 | 916 |
| 917 Set<ClassElement> subclasses = | 917 Set<ClassEntity> subclasses = |
| 918 _typesImplementedBySubclasses[superclass.declaration]; | 918 _typesImplementedBySubclasses[superclass.declaration]; |
| 919 if (subclasses == null) return false; | 919 if (subclasses == null) return false; |
| 920 return subclasses.contains(type); | 920 return subclasses.contains(type); |
| 921 } | 921 } |
| 922 | 922 |
| 923 @override | 923 @override |
| 924 bool hasElementIn(ClassElement cls, Selector selector, Element element) { | 924 bool hasElementIn(ClassElement cls, Selector selector, Element element) { |
| 925 // Use [:implementation:] of [element] | 925 // Use [:implementation:] of [element] |
| 926 // because our function set only stores declarations. | 926 // because our function set only stores declarations. |
| 927 Element result = findMatchIn(cls, selector); | 927 Element result = findMatchIn(cls, selector); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 return getMightBePassedToApply(element.expression); | 1192 return getMightBePassedToApply(element.expression); |
| 1193 } | 1193 } |
| 1194 return functionsThatMightBePassedToApply.contains(element); | 1194 return functionsThatMightBePassedToApply.contains(element); |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 @override | 1197 @override |
| 1198 bool getCurrentlyKnownMightBePassedToApply(Element element) { | 1198 bool getCurrentlyKnownMightBePassedToApply(Element element) { |
| 1199 return getMightBePassedToApply(element); | 1199 return getMightBePassedToApply(element); |
| 1200 } | 1200 } |
| 1201 } | 1201 } |
| OLD | NEW |