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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 2070493003: Revert "Remove Registry from registerMetadataConstant" and "Serialize metadata" (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 part of js_backend; 5 part of js_backend;
6 6
7 const VERBOSE_OPTIMIZER_HINTS = false; 7 const VERBOSE_OPTIMIZER_HINTS = false;
8 8
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { 9 class JavaScriptItemCompilationContext extends ItemCompilationContext {
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>();
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 /// True if a core-library function requires the preamble file to function. 442 /// True if a core-library function requires the preamble file to function.
443 bool requiresPreamble = false; 443 bool requiresPreamble = false;
444 444
445 /// True if the html library has been loaded. 445 /// True if the html library has been loaded.
446 bool htmlLibraryIsLoaded = false; 446 bool htmlLibraryIsLoaded = false;
447 447
448 /// List of constants from metadata. If metadata must be preserved, 448 /// List of constants from metadata. If metadata must be preserved,
449 /// these constants must be registered. 449 /// these constants must be registered.
450 final List<Dependency> metadataConstants = <Dependency>[]; 450 final List<Dependency> metadataConstants = <Dependency>[];
451 451
452 /// Set of elements for which metadata has been registered as dependencies.
453 final Set<Element> _registeredMetadata = new Set<Element>();
454
455 /// List of elements that the user has requested for reflection. 452 /// List of elements that the user has requested for reflection.
456 final Set<Element> targetsUsed = new Set<Element>(); 453 final Set<Element> targetsUsed = new Set<Element>();
457 454
458 /// List of annotations provided by user that indicate that the annotated 455 /// List of annotations provided by user that indicate that the annotated
459 /// element must be retained. 456 /// element must be retained.
460 final Set<Element> metaTargetsUsed = new Set<Element>(); 457 final Set<Element> metaTargetsUsed = new Set<Element>();
461 458
462 /// Set of methods that are needed by reflection. Computed using 459 /// Set of methods that are needed by reflection. Computed using
463 /// [computeMembersNeededForReflection] on first use. 460 /// [computeMembersNeededForReflection] on first use.
464 Set<Element> _membersNeededForReflection = null; 461 Set<Element> _membersNeededForReflection = null;
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 // helper so we register a use of that. 1047 // helper so we register a use of that.
1051 registry.registerStaticUse(new StaticUse.staticInvoke( 1048 registry.registerStaticUse(new StaticUse.staticInvoke(
1052 // TODO(johnniwinther): Find the right [CallStructure]. 1049 // TODO(johnniwinther): Find the right [CallStructure].
1053 1050
1054 helpers.createRuntimeType, 1051 helpers.createRuntimeType,
1055 null)); 1052 null));
1056 } 1053 }
1057 } 1054 }
1058 } 1055 }
1059 1056
1057 void registerMetadataConstant(MetadataAnnotation metadata,
1058 Element annotatedElement, Registry registry) {
1059 assert(registry.isForResolution);
1060 ConstantValue constant = constants.getConstantValueForMetadata(metadata);
1061 registerCompileTimeConstant(constant, registry);
1062 metadataConstants.add(new Dependency(constant, annotatedElement));
1063 }
1064
1060 void registerInstantiatedClass( 1065 void registerInstantiatedClass(
1061 ClassElement cls, Enqueuer enqueuer, Registry registry) { 1066 ClassElement cls, Enqueuer enqueuer, Registry registry) {
1062 _processClass(cls, enqueuer, registry); 1067 _processClass(cls, enqueuer, registry);
1063 } 1068 }
1064 1069
1065 void registerImplementedClass( 1070 void registerImplementedClass(
1066 ClassElement cls, Enqueuer enqueuer, Registry registry) { 1071 ClassElement cls, Enqueuer enqueuer, Registry registry) {
1067 _processClass(cls, enqueuer, registry); 1072 _processClass(cls, enqueuer, registry);
1068 } 1073 }
1069 1074
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 enqueueInResolution(traceHelper, registry); 1265 enqueueInResolution(traceHelper, registry);
1261 } 1266 }
1262 enqueueInResolution(helpers.assertUnreachableMethod, registry); 1267 enqueueInResolution(helpers.assertUnreachableMethod, registry);
1263 registerCheckedModeHelpers(registry); 1268 registerCheckedModeHelpers(registry);
1264 } 1269 }
1265 1270
1266 onResolutionComplete() { 1271 onResolutionComplete() {
1267 super.onResolutionComplete(); 1272 super.onResolutionComplete();
1268 computeMembersNeededForReflection(); 1273 computeMembersNeededForReflection();
1269 rti.computeClassesNeedingRti(); 1274 rti.computeClassesNeedingRti();
1270 _registeredMetadata.clear();
1271 } 1275 }
1272 1276
1273 onTypeInferenceComplete() { 1277 onTypeInferenceComplete() {
1274 super.onTypeInferenceComplete(); 1278 super.onTypeInferenceComplete();
1275 noSuchMethodRegistry.onTypeInferenceComplete(); 1279 noSuchMethodRegistry.onTypeInferenceComplete();
1276 } 1280 }
1277 1281
1278 void registerGetRuntimeTypeArgument(Registry registry) { 1282 void registerGetRuntimeTypeArgument(Registry registry) {
1279 enqueueImpact( 1283 enqueueImpact(
1280 compiler.enqueuer.resolution, impacts.getRuntimeTypeArgument, registry); 1284 compiler.enqueuer.resolution, impacts.getRuntimeTypeArgument, registry);
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 // necessary, but the backend relies on them being resolved. 2297 // necessary, but the backend relies on them being resolved.
2294 enqueuer.enqueueReflectiveStaticFields(_findStaticFieldTargets()); 2298 enqueuer.enqueueReflectiveStaticFields(_findStaticFieldTargets());
2295 } 2299 }
2296 2300
2297 if (mustPreserveNames) reporter.log('Preserving names.'); 2301 if (mustPreserveNames) reporter.log('Preserving names.');
2298 2302
2299 if (mustRetainMetadata) { 2303 if (mustRetainMetadata) {
2300 reporter.log('Retaining metadata.'); 2304 reporter.log('Retaining metadata.');
2301 2305
2302 compiler.libraryLoader.libraries.forEach(retainMetadataOf); 2306 compiler.libraryLoader.libraries.forEach(retainMetadataOf);
2303 2307 for (Dependency dependency in metadataConstants) {
2304 if (enqueuer.isResolutionQueue) { 2308 registerCompileTimeConstant(dependency.constant,
2305 /// Register the constant value of [metadata] as live in resolution. 2309 new EagerRegistry('EagerRegistry for ${dependency}', enqueuer));
2306 void registerMetadataConstant(MetadataAnnotation metadata) { 2310 }
2307 ConstantValue constant = 2311 if (!enqueuer.isResolutionQueue) {
2308 constants.getConstantValueForMetadata(metadata);
2309 Dependency dependency =
2310 new Dependency(constant, metadata.annotatedElement);
2311 metadataConstants.add(dependency);
2312 registerCompileTimeConstant(dependency.constant,
2313 new EagerRegistry('EagerRegistry for ${dependency}', enqueuer));
2314 }
2315
2316 // TODO(johnniwinther): We should have access to all recently processed
2317 // elements and process these instead.
2318 processMetadata(compiler.enqueuer.resolution.processedElements,
2319 registerMetadataConstant);
2320 } else {
2321 for (Dependency dependency in metadataConstants) {
2322 registerCompileTimeConstant(dependency.constant,
2323 new EagerRegistry('EagerRegistry for ${dependency}', enqueuer));
2324 }
2325 metadataConstants.clear(); 2312 metadataConstants.clear();
2326 } 2313 }
2327 } 2314 }
2328 return true; 2315 return true;
2329 } 2316 }
2330 2317
2331 /// Call [registerMetadataConstant] on all metadata from [elements].
2332 void processMetadata(Iterable<Element> elements,
2333 void onMetadata(MetadataAnnotation metadata)) {
2334 void processLibraryMetadata(LibraryElement library) {
2335 if (_registeredMetadata.add(library)) {
2336 library.metadata.forEach(onMetadata);
2337 for (ImportElement import in library.imports) {
2338 import.metadata.forEach(onMetadata);
2339 }
2340 }
2341 }
2342
2343 void processElementMetadata(Element element) {
2344 if (_registeredMetadata.add(element)) {
2345 element.metadata.forEach(onMetadata);
2346 if (element.enclosingClass != null) {
2347 processElementMetadata(element.enclosingClass);
2348 } else {
2349 processLibraryMetadata(element.library);
2350 }
2351 }
2352 }
2353
2354 elements.forEach(processElementMetadata);
2355 }
2356
2357 void onQueueClosed() { 2318 void onQueueClosed() {
2358 lookupMapAnalysis.onQueueClosed(); 2319 lookupMapAnalysis.onQueueClosed();
2359 jsInteropAnalysis.onQueueClosed(); 2320 jsInteropAnalysis.onQueueClosed();
2360 } 2321 }
2361 2322
2362 void onCodegenStart() { 2323 void onCodegenStart() {
2363 lookupMapAnalysis.onCodegenStart(); 2324 lookupMapAnalysis.onCodegenStart();
2364 } 2325 }
2365 2326
2366 @override 2327 @override
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
3069 return transformed; 3030 return transformed;
3070 } 3031 }
3071 } 3032 }
3072 3033
3073 /// Records that [constant] is used by the element behind [registry]. 3034 /// Records that [constant] is used by the element behind [registry].
3074 class Dependency { 3035 class Dependency {
3075 final ConstantValue constant; 3036 final ConstantValue constant;
3076 final Element annotatedElement; 3037 final Element annotatedElement;
3077 3038
3078 const Dependency(this.constant, this.annotatedElement); 3039 const Dependency(this.constant, this.annotatedElement);
3079
3080 String toString() => '$annotatedElement:${constant.toStructuredText()}';
3081 } 3040 }
3082 3041
3083 class JavaScriptImpactStrategy extends ImpactStrategy { 3042 class JavaScriptImpactStrategy extends ImpactStrategy {
3084 final Resolution resolution; 3043 final Resolution resolution;
3085 final DumpInfoTask dumpInfoTask; 3044 final DumpInfoTask dumpInfoTask;
3086 final bool supportDeferredLoad; 3045 final bool supportDeferredLoad;
3087 final bool supportDumpInfo; 3046 final bool supportDumpInfo;
3088 final bool supportSerialization; 3047 final bool supportSerialization;
3089 3048
3090 JavaScriptImpactStrategy(this.resolution, this.dumpInfoTask, 3049 JavaScriptImpactStrategy(this.resolution, this.dumpInfoTask,
(...skipping 25 matching lines...) Expand all
3116 3075
3117 @override 3076 @override
3118 void onImpactUsed(ImpactUseCase impactUse) { 3077 void onImpactUsed(ImpactUseCase impactUse) {
3119 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { 3078 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) {
3120 // TODO(johnniwinther): Allow emptying when serialization has been 3079 // TODO(johnniwinther): Allow emptying when serialization has been
3121 // performed. 3080 // performed.
3122 resolution.emptyCache(); 3081 resolution.emptyCache();
3123 } 3082 }
3124 } 3083 }
3125 } 3084 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | pkg/compiler/lib/src/js_backend/constant_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698