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

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

Issue 2921933002: Only call MirrorsData.retainMetadata* from codegen (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/mirrors_data.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.mirrors_handler; 5 library dart2js.mirrors_handler;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart'; 8 import '../common/resolution.dart';
9 import '../compiler.dart'; 9 import '../compiler.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // necessary, but the backend relies on them being resolved. 119 // necessary, but the backend relies on them being resolved.
120 enqueuer.applyImpact( 120 enqueuer.applyImpact(
121 _computeImpactForReflectiveStaticFields(_findStaticFieldTargets())); 121 _computeImpactForReflectiveStaticFields(_findStaticFieldTargets()));
122 } 122 }
123 123
124 if (_mirrorsData.mustPreserveNames) _reporter.log('Preserving names.'); 124 if (_mirrorsData.mustPreserveNames) _reporter.log('Preserving names.');
125 125
126 if (_mirrorsData.mustRetainMetadata) { 126 if (_mirrorsData.mustRetainMetadata) {
127 _reporter.log('Retaining metadata.'); 127 _reporter.log('Retaining metadata.');
128 128
129 for (LibraryEntity library in _compiler.libraryLoader.libraries) { 129 /// Register the constant value of [metadata] as live in resolution.
130 _mirrorsData.retainMetadataOfLibrary(library, 130 void registerMetadataConstant(MetadataAnnotation metadata) {
131 addForEmission: !enqueuer.isResolutionQueue); 131 metadata.ensureResolved(_compiler.resolution);
132 ConstantValue constant =
133 _constants.getConstantValueForMetadata(metadata);
134 Dependency dependency =
135 new Dependency(constant, metadata.annotatedElement);
136 _metadataConstants.add(dependency);
137 _impactBuilder.registerConstantUse(new ConstantUse.mirrors(constant));
132 } 138 }
133 139
134 if (!enqueuer.queueIsClosed) { 140 // TODO(johnniwinther): We should have access to all recently processed
135 /// Register the constant value of [metadata] as live in resolution. 141 // elements and process these instead.
136 void registerMetadataConstant(MetadataAnnotation metadata) { 142 processMetadata(enqueuer.processedEntities, registerMetadataConstant);
137 ConstantValue constant =
138 _constants.getConstantValueForMetadata(metadata);
139 Dependency dependency =
140 new Dependency(constant, metadata.annotatedElement);
141 _metadataConstants.add(dependency);
142 _impactBuilder.registerConstantUse(new ConstantUse.mirrors(constant));
143 }
144
145 // TODO(johnniwinther): We should have access to all recently processed
146 // elements and process these instead.
147 processMetadata(enqueuer.processedEntities, registerMetadataConstant);
148 } else {
149 for (Dependency dependency in _metadataConstants) {
150 _impactBuilder.registerConstantUse(
151 new ConstantUse.mirrors(dependency.constant));
152 }
153 _metadataConstants.clear();
154 }
155 enqueuer.applyImpact(_impactBuilder.flush());
156 } 143 }
157 } 144 }
158 145
159 /// Call [registerMetadataConstant] on all metadata from [entities]. 146 /// Call [registerMetadataConstant] on all metadata from [entities].
160 void processMetadata( 147 void processMetadata(
161 Iterable<Entity> entities, void onMetadata(MetadataAnnotation metadata)) { 148 Iterable<Entity> entities, void onMetadata(MetadataAnnotation metadata)) {
162 void processLibraryMetadata(LibraryElement library) { 149 void processLibraryMetadata(LibraryElement library) {
163 if (_registeredMetadata.add(library)) { 150 if (_registeredMetadata.add(library)) {
164 library.metadata.forEach(onMetadata); 151 library.metadata.forEach(onMetadata);
165 library.entryCompilationUnit.metadata.forEach(onMetadata); 152 library.entryCompilationUnit.metadata.forEach(onMetadata);
(...skipping 13 matching lines...) Expand all
179 } 166 }
180 } 167 }
181 if (element.enclosingClass != null) { 168 if (element.enclosingClass != null) {
182 // Only process library of top level fields/methods 169 // Only process library of top level fields/methods
183 // (and not for classes). 170 // (and not for classes).
184 // TODO(johnniwinther): Fix this: We are missing some metadata on 171 // TODO(johnniwinther): Fix this: We are missing some metadata on
185 // libraries (example: in co19/Language/Metadata/before_export_t01). 172 // libraries (example: in co19/Language/Metadata/before_export_t01).
186 if (element.enclosingElement is ClassElement) { 173 if (element.enclosingElement is ClassElement) {
187 // Use [enclosingElement] instead of [enclosingClass] to ensure that 174 // Use [enclosingElement] instead of [enclosingClass] to ensure that
188 // we process patch class metadata for patch and injected members. 175 // we process patch class metadata for patch and injected members.
189 processElementMetadata(element.enclosingElement);
190 } 176 }
191 } else { 177 processElementMetadata(element.enclosingClass);
192 processLibraryMetadata(element.library);
193 } 178 }
179 processLibraryMetadata(element.library);
194 } 180 }
195 } 181 }
196 182
197 entities.forEach((MemberElement member) => processElementMetadata(member)); 183 entities.forEach((MemberElement member) => processElementMetadata(member));
198 } 184 }
199 185
200 void onResolutionComplete() { 186 void onResolutionComplete() {
201 _registeredMetadata.clear(); 187 _registeredMetadata.clear();
202 } 188 }
203 189
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 465
480 /// Records that [constant] is used by the element behind [registry]. 466 /// Records that [constant] is used by the element behind [registry].
481 class Dependency { 467 class Dependency {
482 final ConstantValue constant; 468 final ConstantValue constant;
483 final Element annotatedElement; 469 final Element annotatedElement;
484 470
485 const Dependency(this.constant, this.annotatedElement); 471 const Dependency(this.constant, this.annotatedElement);
486 472
487 String toString() => '$annotatedElement:${constant.toStructuredText()}'; 473 String toString() => '$annotatedElement:${constant.toStructuredText()}';
488 } 474 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/mirrors_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698