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

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

Issue 2060183002: Serialize metadata (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// [ConstantCompilerTask] for compilation of constants for the JavaScript 7 /// [ConstantCompilerTask] for compilation of constants for the JavaScript
8 /// backend. 8 /// backend.
9 /// 9 ///
10 /// Since this task needs to distinguish between frontend and backend constants 10 /// Since this task needs to distinguish between frontend and backend constants
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); 108 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>();
109 109
110 // TODO(johnniwinther): Move this to the backend constant handler. 110 // TODO(johnniwinther): Move this to the backend constant handler.
111 /** Caches the statics where the initial value cannot be eagerly compiled. */ 111 /** Caches the statics where the initial value cannot be eagerly compiled. */
112 final Set<VariableElement> lazyStatics = new Set<VariableElement>(); 112 final Set<VariableElement> lazyStatics = new Set<VariableElement>();
113 113
114 // Constants computed for constant expressions. 114 // Constants computed for constant expressions.
115 final Map<Node, ConstantExpression> nodeConstantMap = 115 final Map<Node, ConstantExpression> nodeConstantMap =
116 new Map<Node, ConstantExpression>(); 116 new Map<Node, ConstantExpression>();
117 117
118 // Constants computed for metadata.
119 final Map<MetadataAnnotation, ConstantExpression> metadataConstantMap =
120 new Map<MetadataAnnotation, ConstantExpression>();
121
122 JavaScriptConstantCompiler(Compiler compiler) 118 JavaScriptConstantCompiler(Compiler compiler)
123 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM); 119 : super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM);
124 120
125 ConstantExpression compileVariableWithDefinitions( 121 ConstantExpression compileVariableWithDefinitions(
126 VariableElement element, TreeElements definitions, 122 VariableElement element, TreeElements definitions,
127 {bool isConst: false, bool checkType: true}) { 123 {bool isConst: false, bool checkType: true}) {
128 if (!isConst && lazyStatics.contains(element)) { 124 if (!isConst && lazyStatics.contains(element)) {
129 return null; 125 return null;
130 } 126 }
131 ConstantExpression value = super.compileVariableWithDefinitions( 127 ConstantExpression value = super.compileVariableWithDefinitions(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 201
206 ConstantExpression getConstantForNode(Node node, TreeElements definitions) { 202 ConstantExpression getConstantForNode(Node node, TreeElements definitions) {
207 ConstantExpression constant = nodeConstantMap[node]; 203 ConstantExpression constant = nodeConstantMap[node];
208 if (constant != null) { 204 if (constant != null) {
209 return constant; 205 return constant;
210 } 206 }
211 return definitions.getConstant(node); 207 return definitions.getConstant(node);
212 } 208 }
213 209
214 ConstantValue getConstantValueForMetadata(MetadataAnnotation metadata) { 210 ConstantValue getConstantValueForMetadata(MetadataAnnotation metadata) {
215 return getConstantValue(metadataConstantMap[metadata]); 211 return getConstantValue(metadata.constant);
216 }
217
218 ConstantExpression compileMetadata(
219 MetadataAnnotation metadata, Node node, TreeElements elements) {
220 ConstantExpression constant =
221 super.compileMetadata(metadata, node, elements);
222 metadataConstantMap[metadata] = constant;
223 return constant;
224 } 212 }
225 213
226 void forgetElement(Element element) { 214 void forgetElement(Element element) {
227 super.forgetElement(element); 215 super.forgetElement(element);
228 const ForgetConstantElementVisitor().visit(element, this); 216 const ForgetConstantElementVisitor().visit(element, this);
229 if (element is AstElement && element.hasNode) { 217 if (element is AstElement && element.hasNode) {
230 element.node.accept(new ForgetConstantNodeVisitor(this)); 218 element.node.accept(new ForgetConstantNodeVisitor(this));
231 } 219 }
232 } 220 }
233
234 @override
235 ConstantValue getConstantValue(ConstantExpression expression) {
236 assert(invariant(CURRENT_ELEMENT_SPANNABLE, expression != null,
237 message: "ConstantExpression is null in getConstantValue."));
238 // TODO(johhniwinther): ensure expressions have been evaluated at this
239 // point. This can't be enabled today due to dartbug.com/26406.
240 if (compiler.serialization.supportsDeserialization) {
241 evaluate(expression);
242 }
243 ConstantValue value = super.getConstantValue(expression);
244 if (value == null &&
245 expression != null &&
246 expression.kind == ConstantExpressionKind.ERRONEOUS) {
247 // TODO(johnniwinther): When the Dart constant system sees a constant
248 // expression as erroneous but the JavaScript constant system finds it ok
249 // we have store a constant value for the erroneous constant expression.
250 // Ensure the computed constant expressions are always the same; that only
251 // the constant values may be different.
252 value = new NullConstantValue();
253 }
254 return value;
255 }
256 } 221 }
257 222
258 class ForgetConstantElementVisitor 223 class ForgetConstantElementVisitor
259 extends BaseElementVisitor<dynamic, JavaScriptConstantCompiler> { 224 extends BaseElementVisitor<dynamic, JavaScriptConstantCompiler> {
260 const ForgetConstantElementVisitor(); 225 const ForgetConstantElementVisitor();
261 226
262 void visitElement(Element e, JavaScriptConstantCompiler constants) { 227 void visitElement(Element e, JavaScriptConstantCompiler constants) {
263 for (MetadataAnnotation data in e.implementation.metadata) { 228 for (MetadataAnnotation data in e.implementation.metadata) {
264 constants.metadataConstantMap.remove(data);
265 if (data.hasNode) { 229 if (data.hasNode) {
266 data.node.accept(new ForgetConstantNodeVisitor(constants)); 230 data.node.accept(new ForgetConstantNodeVisitor(constants));
267 } 231 }
268 } 232 }
269 } 233 }
270 234
271 void visitFunctionElement( 235 void visitFunctionElement(
272 FunctionElement e, JavaScriptConstantCompiler constants) { 236 FunctionElement e, JavaScriptConstantCompiler constants) {
273 super.visitFunctionElement(e, constants); 237 super.visitFunctionElement(e, constants);
274 if (e.hasFunctionSignature) { 238 if (e.hasFunctionSignature) {
(...skipping 14 matching lines...) Expand all
289 // TODO(ahe): This doesn't belong here. Rename this class and generalize. 253 // TODO(ahe): This doesn't belong here. Rename this class and generalize.
290 var closureClassMap = constants 254 var closureClassMap = constants
291 .compiler.closureToClassMapper.closureMappingCache 255 .compiler.closureToClassMapper.closureMappingCache
292 .remove(node); 256 .remove(node);
293 if (closureClassMap != null) { 257 if (closureClassMap != null) {
294 closureClassMap 258 closureClassMap
295 .removeMyselfFrom(constants.compiler.enqueuer.codegen.universe); 259 .removeMyselfFrom(constants.compiler.enqueuer.codegen.universe);
296 } 260 }
297 } 261 }
298 } 262 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/constant_emitter.dart ('k') | pkg/compiler/lib/src/js_backend/js_interop_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698