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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 1137883002: dart2js: compile metadata lazily in the lazy emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart ('k') | no next file » | 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) 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 library dart2js.new_js_emitter.model_emitter; 5 library dart2js.new_js_emitter.model_emitter;
6 6
7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; 7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue;
8 import '../../dart2jslib.dart' show Compiler; 8 import '../../dart2jslib.dart' show Compiler;
9 import '../../dart_types.dart' show DartType; 9 import '../../dart_types.dart' show DartType;
10 import '../../elements/elements.dart' show ClassElement, FunctionElement; 10 import '../../elements/elements.dart' show ClassElement, FunctionElement;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return type; 445 return type;
446 }''', {"typesAccess": generateEmbeddedGlobalAccess(TYPES)}); 446 }''', {"typesAccess": generateEmbeddedGlobalAccess(TYPES)});
447 } 447 }
448 448
449 js.Template get templateForReadType { 449 js.Template get templateForReadType {
450 // TODO(floitsch): make sure that no local variable shadows the access to 450 // TODO(floitsch): make sure that no local variable shadows the access to
451 // the readMetadataType function. 451 // the readMetadataType function.
452 return js.js.expressionTemplateFor('$readMetadataTypeName(#)'); 452 return js.js.expressionTemplateFor('$readMetadataTypeName(#)');
453 } 453 }
454 454
455 static final String readMetadataName = "readLazyMetadata";
456 static final String lazyMetadataName = "lazy_$METADATA";
457
458 js.Statement get readMetadataFunction {
459 // Types are non-evaluated and must be compiled at first use.
460 // Compiled strings are guaranteed not to be strings, and it's thus safe
461 // to use a type-test to determine if a type has already been compiled.
462 return js.js.statement('''function $readMetadataName(index) {
463 var lazyMetadata = #lazyMetadataAccess[index];
464 if (typeof lazyMetadata == 'string') {
465 #metadataAccess[index] = expressionCompile(lazyMetadata);
466 #lazyMetadataAccess[index] = null;
467 }
468 return #metadataAccess[index];
469 }''', {
470 "lazyMetadataAccess": generateEmbeddedGlobalAccess(lazyMetadataName),
471 "metadataAccess": generateEmbeddedGlobalAccess(METADATA)
472 });
473 }
474
475 js.Template get templateForReadMetadata {
476 // TODO(floitsch): make sure that no local variable shadows the access to
477 // the readMetadata function.
478 return js.js.expressionTemplateFor('$readMetadataName(#)');
479 }
480
455 List<js.Property> emitMetadata(Program program) { 481 List<js.Property> emitMetadata(Program program) {
482 // Unparses all given js-expressions (suitable for `expressionCompile`) and
483 // returns the result in a js-array.
484 // If the given [expressions] is null returns the empty js-array.
485 js.ArrayInitializer unparseExpressions(List<js.Expression> expressions) {
486 if (expressions == null) expressions = <js.Expression>[];
487 List<js.LiteralString> unparsedExpressions = expressions
488 .map((expr) => unparse(compiler, expr, protectForEval: false))
489 .toList();
490 return new js.ArrayInitializer(unparsedExpressions);
491 }
492
456 List<js.Property> metadataGlobals = <js.Property>[]; 493 List<js.Property> metadataGlobals = <js.Property>[];
457 metadataGlobals.add(new js.Property( 494
458 js.string(METADATA), new js.ArrayInitializer(program.metadata))); 495 js.ArrayInitializer unparsedMetadata = unparseExpressions(program.metadata);
496 metadataGlobals.add(new js.Property(js.string(lazyMetadataName),
497 unparsedMetadata));
498 metadataGlobals.add(new js.Property(js.string(METADATA),
499 new js.ArrayInitializer([])));
500
459 List<js.Expression> types = 501 List<js.Expression> types =
460 program.metadataTypes[program.fragments.first.outputUnit]; 502 program.metadataTypes[program.fragments.first.outputUnit];
461 if (types == null) types = <js.Expression>[]; 503 metadataGlobals.add(new js.Property(js.string(TYPES),
462 List<js.LiteralString> unparsedTypes = types 504 unparseExpressions(types)));
463 .map((type) => unparse(compiler, type, protectForEval: false)) 505
464 .toList();
465 js.ArrayInitializer typesArray = new js.ArrayInitializer(unparsedTypes);
466 metadataGlobals.add(new js.Property(js.string(TYPES), typesArray));
467 return metadataGlobals; 506 return metadataGlobals;
468 } 507 }
469 508
470 js.Expression emitDeferredFragment(List<js.Expression> types, 509 js.Expression emitDeferredFragment(List<js.Expression> types,
471 DeferredFragment fragment, 510 DeferredFragment fragment,
472 List<Holder> holders) { 511 List<Holder> holders) {
473 // TODO(floitsch): initialize eager classes. 512 // TODO(floitsch): initialize eager classes.
474 // TODO(floitsch): the hash must depend on the output. 513 // TODO(floitsch): the hash must depend on the output.
475 int hash = fragment.hashCode; 514 int hash = fragment.hashCode;
476 515
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1253
1215 var end = Date.now(); 1254 var end = Date.now();
1216 // print('Setup: ' + (end - start) + ' ms.'); 1255 // print('Setup: ' + (end - start) + ' ms.');
1217 1256
1218 #invokeMain; // Start main. 1257 #invokeMain; // Start main.
1219 1258
1220 }(Date.now(), #code) 1259 }(Date.now(), #code)
1221 }"""; 1260 }""";
1222 1261
1223 } 1262 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698