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

Side by Side Diff: pkg/compiler/lib/src/world.dart

Issue 2975433002: Assert that we don't mix K and J elements (Closed)
Patch Set: Updated cf. comments Created 3 years, 5 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
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 dart2js.world; 5 library dart2js.world;
6 6
7 import 'closure.dart' show ClosureClassElement; 7 import 'closure.dart' show ClosureClassElement;
8 import 'common.dart'; 8 import 'common.dart';
9 import 'constants/constant_system.dart'; 9 import 'constants/constant_system.dart';
10 import 'common_elements.dart' show CommonElements, ElementEnvironment; 10 import 'common_elements.dart' show CommonElements, ElementEnvironment;
11 import 'elements/entities.dart'; 11 import 'elements/entities.dart';
12 import 'elements/elements.dart' 12 import 'elements/elements.dart'
13 show 13 show
14 ClassElement, 14 ClassElement,
15 Element, 15 Element,
16 MemberElement, 16 MemberElement,
17 MethodElement, 17 MethodElement,
18 MixinApplicationElement, 18 MixinApplicationElement,
19 TypedefElement; 19 TypedefElement;
20 import 'elements/resolution_types.dart'; 20 import 'elements/resolution_types.dart';
21 import 'elements/types.dart'; 21 import 'elements/types.dart';
22 import 'js_backend/backend_usage.dart' show BackendUsage; 22 import 'js_backend/backend_usage.dart' show BackendUsage;
23 import 'js_backend/interceptor_data.dart' show InterceptorData; 23 import 'js_backend/interceptor_data.dart' show InterceptorData;
24 import 'js_backend/native_data.dart' show NativeData; 24 import 'js_backend/native_data.dart' show NativeData;
25 import 'js_backend/runtime_types.dart'
26 show RuntimeTypesNeed, RuntimeTypesNeedBuilder;
25 import 'ordered_typeset.dart'; 27 import 'ordered_typeset.dart';
28 import 'options.dart';
26 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; 29 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask;
27 import 'universe/class_set.dart'; 30 import 'universe/class_set.dart';
28 import 'universe/function_set.dart' show FunctionSet; 31 import 'universe/function_set.dart' show FunctionSet;
29 import 'universe/selector.dart' show Selector; 32 import 'universe/selector.dart' show Selector;
30 import 'universe/side_effects.dart' show SideEffects; 33 import 'universe/side_effects.dart' show SideEffects;
34 import 'universe/world_builder.dart';
31 import 'util/util.dart' show Link; 35 import 'util/util.dart' show Link;
32 36
33 /// Common superinterface for [OpenWorld] and [ClosedWorld]. 37 /// Common superinterface for [OpenWorld] and [ClosedWorld].
34 abstract class World {} 38 abstract class World {}
35 39
36 /// The [ClosedWorld] represents the information known about a program when 40 /// The [ClosedWorld] represents the information known about a program when
37 /// compiling with closed-world semantics. 41 /// compiling with closed-world semantics.
38 /// 42 ///
39 /// Given the entrypoint of an application, we can track what's reachable from 43 /// Given the entrypoint of an application, we can track what's reachable from
40 /// it, what functions are called, what classes are allocated, which native 44 /// it, what functions are called, what classes are allocated, which native
(...skipping 10 matching lines...) Expand all
51 ElementEnvironment get elementEnvironment; 55 ElementEnvironment get elementEnvironment;
52 56
53 DartTypes get dartTypes; 57 DartTypes get dartTypes;
54 58
55 CommonElements get commonElements; 59 CommonElements get commonElements;
56 60
57 CommonMasks get commonMasks; 61 CommonMasks get commonMasks;
58 62
59 ConstantSystem get constantSystem; 63 ConstantSystem get constantSystem;
60 64
65 RuntimeTypesNeed get rtiNeed;
66
67 Iterable<ClassEntity> get liveNativeClasses;
68
61 /// Returns `true` if [cls] is either directly or indirectly instantiated. 69 /// Returns `true` if [cls] is either directly or indirectly instantiated.
62 bool isInstantiated(ClassEntity cls); 70 bool isInstantiated(ClassEntity cls);
63 71
64 /// Returns `true` if [cls] is directly instantiated. This means that at 72 /// Returns `true` if [cls] is directly instantiated. This means that at
65 /// runtime instances of exactly [cls] are assumed to exist. 73 /// runtime instances of exactly [cls] are assumed to exist.
66 bool isDirectlyInstantiated(ClassEntity cls); 74 bool isDirectlyInstantiated(ClassEntity cls);
67 75
68 /// Returns `true` if [cls] is abstractly instantiated. This means that at 76 /// Returns `true` if [cls] is abstractly instantiated. This means that at
69 /// runtime instances of [cls] or unknown subclasses of [cls] are assumed to 77 /// runtime instances of [cls] or unknown subclasses of [cls] are assumed to
70 /// exist. 78 /// exist.
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 final CommonElements commonElements; 452 final CommonElements commonElements;
445 453
446 // TODO(johnniwinther): Can this be derived from [ClassSet]s? 454 // TODO(johnniwinther): Can this be derived from [ClassSet]s?
447 final Set<ClassEntity> _implementedClasses; 455 final Set<ClassEntity> _implementedClasses;
448 456
449 final Iterable<MemberEntity> liveInstanceMembers; 457 final Iterable<MemberEntity> liveInstanceMembers;
450 458
451 /// Members that are written either directly or through a setter selector. 459 /// Members that are written either directly or through a setter selector.
452 final Iterable<MemberEntity> assignedInstanceMembers; 460 final Iterable<MemberEntity> assignedInstanceMembers;
453 461
462 final Iterable<ClassEntity> liveNativeClasses;
463
454 ClosedWorldBase( 464 ClosedWorldBase(
455 this.elementEnvironment, 465 this.elementEnvironment,
456 this.dartTypes, 466 this.dartTypes,
457 this.commonElements, 467 this.commonElements,
458 this.constantSystem, 468 this.constantSystem,
459 this.nativeData, 469 this.nativeData,
460 this.interceptorData, 470 this.interceptorData,
461 this.backendUsage, 471 this.backendUsage,
462 Set<ClassEntity> implementedClasses, 472 Set<ClassEntity> implementedClasses,
473 this.liveNativeClasses,
463 this.liveInstanceMembers, 474 this.liveInstanceMembers,
464 this.assignedInstanceMembers, 475 this.assignedInstanceMembers,
465 Set<TypedefElement> allTypedefs, 476 Set<TypedefElement> allTypedefs,
466 this.mixinUses, 477 this.mixinUses,
467 this.typesImplementedBySubclasses, 478 this.typesImplementedBySubclasses,
468 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, 479 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
469 Map<ClassEntity, ClassSet> classSets) 480 Map<ClassEntity, ClassSet> classSets)
470 : this._implementedClasses = implementedClasses, 481 : this._implementedClasses = implementedClasses,
471 this._allTypedefs = allTypedefs, 482 this._allTypedefs = allTypedefs,
472 this._classHierarchyNodes = classHierarchyNodes, 483 this._classHierarchyNodes = classHierarchyNodes,
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 sb.write("Classes in the closed world related to $cls:\n"); 1171 sb.write("Classes in the closed world related to $cls:\n");
1161 } else { 1172 } else {
1162 sb.write("Instantiated classes in the closed world:\n"); 1173 sb.write("Instantiated classes in the closed world:\n");
1163 } 1174 }
1164 getClassHierarchyNode(commonElements.objectClass) 1175 getClassHierarchyNode(commonElements.objectClass)
1165 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls); 1176 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls);
1166 return sb.toString(); 1177 return sb.toString();
1167 } 1178 }
1168 } 1179 }
1169 1180
1170 class ClosedWorldImpl extends ClosedWorldBase { 1181 class ClosedWorldImpl extends ClosedWorldBase with ClosedWorldRtiNeedMixin {
1171 ClosedWorldImpl( 1182 ClosedWorldImpl(
1172 {ElementEnvironment elementEnvironment, 1183 {CompilerOptions options,
1184 ElementEnvironment elementEnvironment,
1173 DartTypes dartTypes, 1185 DartTypes dartTypes,
1174 CommonElements commonElements, 1186 CommonElements commonElements,
1175 ConstantSystem constantSystem, 1187 ConstantSystem constantSystem,
1176 NativeData nativeData, 1188 NativeData nativeData,
1177 InterceptorData interceptorData, 1189 InterceptorData interceptorData,
1178 BackendUsage backendUsage, 1190 BackendUsage backendUsage,
1191 ResolutionWorldBuilder resolutionWorldBuilder,
1192 RuntimeTypesNeedBuilder rtiNeedBuilder,
1179 Set<ClassEntity> implementedClasses, 1193 Set<ClassEntity> implementedClasses,
1194 Iterable<ClassEntity> liveNativeClasses,
1180 Iterable<MemberEntity> liveInstanceMembers, 1195 Iterable<MemberEntity> liveInstanceMembers,
1181 Iterable<MemberEntity> assignedInstanceMembers, 1196 Iterable<MemberEntity> assignedInstanceMembers,
1182 Set<TypedefElement> allTypedefs, 1197 Set<TypedefElement> allTypedefs,
1183 Map<ClassEntity, Set<ClassEntity>> mixinUses, 1198 Map<ClassEntity, Set<ClassEntity>> mixinUses,
1184 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, 1199 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
1185 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, 1200 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
1186 Map<ClassEntity, ClassSet> classSets}) 1201 Map<ClassEntity, ClassSet> classSets})
1187 : super( 1202 : super(
1188 elementEnvironment, 1203 elementEnvironment,
1189 dartTypes, 1204 dartTypes,
1190 commonElements, 1205 commonElements,
1191 constantSystem, 1206 constantSystem,
1192 nativeData, 1207 nativeData,
1193 interceptorData, 1208 interceptorData,
1194 backendUsage, 1209 backendUsage,
1195 implementedClasses, 1210 implementedClasses,
1211 liveNativeClasses,
1196 liveInstanceMembers, 1212 liveInstanceMembers,
1197 assignedInstanceMembers, 1213 assignedInstanceMembers,
1198 allTypedefs, 1214 allTypedefs,
1199 mixinUses, 1215 mixinUses,
1200 typesImplementedBySubclasses, 1216 typesImplementedBySubclasses,
1201 classHierarchyNodes, 1217 classHierarchyNodes,
1202 classSets); 1218 classSets) {
1219 computeRtiNeed(resolutionWorldBuilder, rtiNeedBuilder,
1220 enableTypeAssertions: options.enableTypeAssertions);
1221 }
1203 1222
1204 bool checkClass(ClassElement cls) => cls.isDeclaration; 1223 bool checkClass(ClassElement cls) => cls.isDeclaration;
1205 1224
1206 bool checkEntity(Element element) => element.isDeclaration; 1225 bool checkEntity(Element element) => element.isDeclaration;
1207 1226
1208 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { 1227 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) {
1209 assert(cls.isDeclaration, failedAt(cls, '$cls must be the declaration.')); 1228 assert(cls.isDeclaration, failedAt(cls, '$cls must be the declaration.'));
1210 assert(cls.isResolved, failedAt(cls, '$cls must be resolved.')); 1229 assert(cls.isResolved, failedAt(cls, '$cls must be resolved.'));
1211 1230
1212 // TODO(johnniwinther): Reinsert this or similar invariant. Currently 1231 // TODO(johnniwinther): Reinsert this or similar invariant. Currently
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 // does not see generative constructor bodies because they are 1327 // does not see generative constructor bodies because they are
1309 // created by the backend. Also, it does not make any distinction 1328 // created by the backend. Also, it does not make any distinction
1310 // between a constructor and its body for side effects. This 1329 // between a constructor and its body for side effects. This
1311 // implies that currently, the side effects of a constructor body 1330 // implies that currently, the side effects of a constructor body
1312 // contain the side effects of the initializers. 1331 // contain the side effects of the initializers.
1313 assert(!element.isGenerativeConstructorBody); 1332 assert(!element.isGenerativeConstructorBody);
1314 assert(!element.isField); 1333 assert(!element.isField);
1315 return super.getSideEffectsOfElement(element); 1334 return super.getSideEffectsOfElement(element);
1316 } 1335 }
1317 } 1336 }
1337
1338 abstract class ClosedWorldRtiNeedMixin implements ClosedWorld {
1339 RuntimeTypesNeed _rtiNeed;
1340
1341 void computeRtiNeed(ResolutionWorldBuilder resolutionWorldBuilder,
1342 RuntimeTypesNeedBuilder rtiNeedBuilder,
1343 {bool enableTypeAssertions}) {
1344 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed(
1345 resolutionWorldBuilder, this,
1346 enableTypeAssertions: enableTypeAssertions);
1347 }
1348
1349 RuntimeTypesNeed get rtiNeed => _rtiNeed;
1350 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/world_builder.dart ('k') | tests/compiler/dart2js/equivalence/check_functions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698