Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: pkg/compiler/lib/src/universe/function_set.dart

Issue 2314703002: Split World usage into open, inference, and closed world. (Closed)
Patch Set: Updated cf. comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/types/union_type_mask.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 universe.function_set; 5 library universe.function_set;
6 6
7 import '../common/names.dart' show Identifiers, Selectors; 7 import '../common/names.dart' show Identifiers, Selectors;
8 import '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../types/types.dart'; 10 import '../types/types.dart';
11 import '../util/util.dart' show Hashing, Setlet; 11 import '../util/util.dart' show Hashing, Setlet;
12 import '../world.dart' show ClassWorld; 12 import '../world.dart' show ClassWorld;
13 import 'selector.dart' show Selector; 13 import 'selector.dart' show Selector;
14 import 'universe.dart' show ReceiverConstraint; 14 import 'universe.dart' show ReceiverConstraint;
15 15
16 // TODO(kasperl): This actually holds getters and setters just fine 16 // TODO(kasperl): This actually holds getters and setters just fine
17 // too and stricly they aren't functions. Maybe this needs a better 17 // too and stricly they aren't functions. Maybe this needs a better
18 // name -- something like ElementSet seems a bit too generic. 18 // name -- something like ElementSet seems a bit too generic.
19 class FunctionSet { 19 class FunctionSet {
20 final Compiler compiler; 20 final Compiler compiler;
21 final Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>(); 21 final Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>();
22 FunctionSet(this.compiler); 22 FunctionSet(this.compiler);
23 23
24 ClassWorld get classWorld => compiler.world; 24 ClassWorld get classWorld => compiler.closedWorld;
25 25
26 FunctionSetNode newNode(String name) => new FunctionSetNode(name); 26 FunctionSetNode newNode(String name) => new FunctionSetNode(name);
27 27
28 void add(Element element) { 28 void add(Element element) {
29 assert(element.isInstanceMember); 29 assert(element.isInstanceMember);
30 assert(!element.isAbstract); 30 assert(!element.isAbstract);
31 String name = element.name; 31 String name = element.name;
32 FunctionSetNode node = nodes.putIfAbsent(name, () => newNode(name)); 32 FunctionSetNode node = nodes.putIfAbsent(name, () => newNode(name));
33 node.add(element); 33 node.add(element);
34 } 34 }
(...skipping 29 matching lines...) Expand all
64 /// set of classes that actually implement the selected member or implement 64 /// set of classes that actually implement the selected member or implement
65 /// the handling 'noSuchMethod' where the selected member is unimplemented. 65 /// the handling 'noSuchMethod' where the selected member is unimplemented.
66 TypeMask receiverType(Selector selector, ReceiverConstraint constraint) { 66 TypeMask receiverType(Selector selector, ReceiverConstraint constraint) {
67 return query(selector, constraint).computeMask(classWorld); 67 return query(selector, constraint).computeMask(classWorld);
68 } 68 }
69 69
70 SelectorMask _createSelectorMask( 70 SelectorMask _createSelectorMask(
71 Selector selector, ReceiverConstraint constraint, ClassWorld classWorld) { 71 Selector selector, ReceiverConstraint constraint, ClassWorld classWorld) {
72 return constraint != null 72 return constraint != null
73 ? new SelectorMask(selector, constraint) 73 ? new SelectorMask(selector, constraint)
74 : new SelectorMask(selector, 74 : new SelectorMask(
75 new TypeMask.subclass(classWorld.objectClass, classWorld)); 75 selector,
76 new TypeMask.subclass(
77 classWorld.coreClasses.objectClass, classWorld));
76 } 78 }
77 79
78 /// Returns the set of functions that can be the target of a call to 80 /// Returns the set of functions that can be the target of a call to
79 /// [selector] on a receiver constrained by [constraint] including 81 /// [selector] on a receiver constrained by [constraint] including
80 /// 'noSuchMethod' methods where applicable. 82 /// 'noSuchMethod' methods where applicable.
81 FunctionSetQuery query(Selector selector, ReceiverConstraint constraint) { 83 FunctionSetQuery query(Selector selector, ReceiverConstraint constraint) {
82 String name = selector.name; 84 String name = selector.name;
83 SelectorMask selectorMask = 85 SelectorMask selectorMask =
84 _createSelectorMask(selector, constraint, classWorld); 86 _createSelectorMask(selector, constraint, classWorld);
85 SelectorMask noSuchMethodMask = 87 SelectorMask noSuchMethodMask =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 class FullFunctionSetQuery implements FunctionSetQuery { 271 class FullFunctionSetQuery implements FunctionSetQuery {
270 @override 272 @override
271 final Iterable<Element> functions; 273 final Iterable<Element> functions;
272 274
273 TypeMask _mask; 275 TypeMask _mask;
274 276
275 FullFunctionSetQuery(this.functions); 277 FullFunctionSetQuery(this.functions);
276 278
277 @override 279 @override
278 TypeMask computeMask(ClassWorld classWorld) { 280 TypeMask computeMask(ClassWorld classWorld) {
279 assert(classWorld.hasAnyStrictSubclass(classWorld.objectClass)); 281 assert(classWorld.hasAnyStrictSubclass(classWorld.coreClasses.objectClass));
280 if (_mask != null) return _mask; 282 if (_mask != null) return _mask;
281 return _mask = new TypeMask.unionOf( 283 return _mask = new TypeMask.unionOf(
282 functions.expand((element) { 284 functions.expand((element) {
283 ClassElement cls = element.enclosingClass; 285 ClassElement cls = element.enclosingClass;
284 return [cls]..addAll(classWorld.mixinUsesOf(cls)); 286 return [cls]..addAll(classWorld.mixinUsesOf(cls));
285 }).map((cls) { 287 }).map((cls) {
286 if (classWorld.backend.isNullImplementation(cls)) { 288 if (classWorld.backend.isNullImplementation(cls)) {
287 return const TypeMask.empty(); 289 return const TypeMask.empty();
288 } else if (classWorld.isInstantiated(cls.declaration)) { 290 } else if (classWorld.isInstantiated(cls.declaration)) {
289 return new TypeMask.nonNullSubclass(cls.declaration, classWorld); 291 return new TypeMask.nonNullSubclass(cls.declaration, classWorld);
290 } else { 292 } else {
291 // TODO(johnniwinther): Avoid the need for this case. 293 // TODO(johnniwinther): Avoid the need for this case.
292 return const TypeMask.empty(); 294 return const TypeMask.empty();
293 } 295 }
294 }), 296 }),
295 classWorld); 297 classWorld);
296 } 298 }
297 } 299 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/types/union_type_mask.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698