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

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

Issue 830463003: dart2js: collect static-non-final fields in the task. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.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) 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 dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter"); 7 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter");
8 8
9 /** 9 /**
10 * Generates the code for all used classes in the program. Static fields (even 10 * Generates the code for all used classes in the program. Static fields (even
11 * in classes) are ignored, since they can be treated as non-class elements. 11 * in classes) are ignored, since they can be treated as non-class elements.
12 * 12 *
13 * The code for the containing (used) methods must exist in the [:universe:]. 13 * The code for the containing (used) methods must exist in the [:universe:].
14 */ 14 */
15 class CodeEmitterTask extends CompilerTask { 15 class CodeEmitterTask extends CompilerTask {
16 // TODO(floitsch): the code-emitter task should not need a namer. 16 // TODO(floitsch): the code-emitter task should not need a namer.
17 final Namer namer; 17 final Namer namer;
18 final TypeTestRegistry typeTestRegistry; 18 final TypeTestRegistry typeTestRegistry;
19 NativeEmitter nativeEmitter; 19 NativeEmitter nativeEmitter;
20 OldEmitter oldEmitter; 20 OldEmitter oldEmitter;
21 Emitter emitter; 21 Emitter emitter;
22 22
23 final Set<ClassElement> neededClasses = new Set<ClassElement>(); 23 final Set<ClassElement> neededClasses = new Set<ClassElement>();
24 final Map<OutputUnit, List<ClassElement>> outputClassLists = 24 final Map<OutputUnit, List<ClassElement>> outputClassLists =
25 new Map<OutputUnit, List<ClassElement>>(); 25 new Map<OutputUnit, List<ClassElement>>();
26 final Map<OutputUnit, List<ConstantValue>> outputConstantLists = 26 final Map<OutputUnit, List<ConstantValue>> outputConstantLists =
27 new Map<OutputUnit, List<ConstantValue>>(); 27 new Map<OutputUnit, List<ConstantValue>>();
28 final Map<OutputUnit, List<Element>> outputStaticLists = 28 final Map<OutputUnit, List<Element>> outputStaticLists =
29 new Map<OutputUnit, List<Element>>(); 29 new Map<OutputUnit, List<Element>>();
30 final Map<OutputUnit, List<VariableElement>> outputStaticNonFinalFieldLists =
31 new Map<OutputUnit, List<VariableElement>>();
30 final Map<OutputUnit, Set<LibraryElement>> outputLibraryLists = 32 final Map<OutputUnit, Set<LibraryElement>> outputLibraryLists =
31 new Map<OutputUnit, Set<LibraryElement>>(); 33 new Map<OutputUnit, Set<LibraryElement>>();
32 34
33 /// True, if the output contains a constant list. 35 /// True, if the output contains a constant list.
34 /// 36 ///
35 /// This flag is updated in [computeNeededConstants]. 37 /// This flag is updated in [computeNeededConstants].
36 bool outputContainsConstantList = false; 38 bool outputContainsConstantList = false;
37 39
38 final List<ClassElement> nativeClasses = <ClassElement>[]; 40 final List<ClassElement> nativeClasses = <ClassElement>[];
39 41
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 355 }
354 356
355 void computeNeededStatics() { 357 void computeNeededStatics() {
356 bool isStaticFunction(Element element) => 358 bool isStaticFunction(Element element) =>
357 !element.isInstanceMember && !element.isField; 359 !element.isInstanceMember && !element.isField;
358 360
359 Iterable<Element> elements = 361 Iterable<Element> elements =
360 backend.generatedCode.keys.where(isStaticFunction); 362 backend.generatedCode.keys.where(isStaticFunction);
361 363
362 for (Element element in Elements.sortedByPosition(elements)) { 364 for (Element element in Elements.sortedByPosition(elements)) {
363 outputStaticLists.putIfAbsent( 365 List<Element> list = outputStaticLists.putIfAbsent(
364 compiler.deferredLoadTask.outputUnitForElement(element), 366 compiler.deferredLoadTask.outputUnitForElement(element),
365 () => new List<Element>()) 367 () => new List<Element>());
366 .add(element); 368 list.add(element);
367 } 369 }
368 } 370 }
369 371
372 void computeNeededStaticNonFinalFields() {
373 JavaScriptConstantCompiler handler = backend.constants;
374 Iterable<VariableElement> staticNonFinalFields =
375 handler.getStaticNonFinalFieldsForEmission();
376 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
377 List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent(
378 compiler.deferredLoadTask.outputUnitForElement(element),
379 () => new List<VariableElement>());
380 list.add(element);
381 }
382 }
383
370 void computeNeededLibraries() { 384 void computeNeededLibraries() {
371 void addSurroundingLibraryToSet(Element element) { 385 void addSurroundingLibraryToSet(Element element) {
372 OutputUnit unit = compiler.deferredLoadTask.outputUnitForElement(element); 386 OutputUnit unit = compiler.deferredLoadTask.outputUnitForElement(element);
373 LibraryElement library = element.library; 387 LibraryElement library = element.library;
374 outputLibraryLists.putIfAbsent(unit, () => new Set<LibraryElement>()) 388 outputLibraryLists.putIfAbsent(unit, () => new Set<LibraryElement>())
375 .add(library); 389 .add(library);
376 } 390 }
377 391
378 backend.generatedCode.keys.forEach(addSurroundingLibraryToSet); 392 backend.generatedCode.keys.forEach(addSurroundingLibraryToSet);
379 neededClasses.forEach(addSurroundingLibraryToSet); 393 neededClasses.forEach(addSurroundingLibraryToSet);
380 } 394 }
381 395
382 void computeAllNeededEntities() { 396 void computeAllNeededEntities() {
383 // Compute the required type checks to know which classes need a 397 // Compute the required type checks to know which classes need a
384 // 'is$' method. 398 // 'is$' method.
385 typeTestRegistry.computeRequiredTypeChecks(); 399 typeTestRegistry.computeRequiredTypeChecks();
386 400
387 computeNeededDeclarations(); 401 computeNeededDeclarations();
388 computeNeededConstants(); 402 computeNeededConstants();
389 computeNeededStatics(); 403 computeNeededStatics();
404 computeNeededStaticNonFinalFields();
390 computeNeededLibraries(); 405 computeNeededLibraries();
391 } 406 }
392 407
393 int assembleProgram() { 408 int assembleProgram() {
394 return measure(() { 409 return measure(() {
395 emitter.invalidateCaches(); 410 emitter.invalidateCaches();
396 411
397 computeAllNeededEntities(); 412 computeAllNeededEntities();
398 413
399 Program program; 414 Program program;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 jsAst.Expression interceptorClassAccess(ClassElement e); 456 jsAst.Expression interceptorClassAccess(ClassElement e);
442 457
443 /// Returns the JS expression representing the type [e]. 458 /// Returns the JS expression representing the type [e].
444 jsAst.Expression typeAccess(Element e); 459 jsAst.Expression typeAccess(Element e);
445 460
446 int compareConstants(ConstantValue a, ConstantValue b); 461 int compareConstants(ConstantValue a, ConstantValue b);
447 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); 462 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant);
448 463
449 void invalidateCaches(); 464 void invalidateCaches();
450 } 465 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698