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

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

Issue 3011803002: dart2js kernel: Sort constants
Patch Set: implement DartType ordering Created 3 years, 3 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 library dart2js.js_emitter.lazy_emitter.model_emitter; 5 library dart2js.js_emitter.lazy_emitter.model_emitter;
6 6
7 import 'package:js_runtime/shared/embedded_names.dart' 7 import 'package:js_runtime/shared/embedded_names.dart'
8 show 8 show
9 CREATE_NEW_ISOLATE, 9 CREATE_NEW_ISOLATE,
10 DEFERRED_LIBRARY_URIS, 10 DEFERRED_LIBRARY_URIS,
(...skipping 12 matching lines...) Expand all
23 import '../../../compiler_new.dart'; 23 import '../../../compiler_new.dart';
24 import '../../compiler.dart' show Compiler; 24 import '../../compiler.dart' show Compiler;
25 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; 25 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue;
26 import '../../common_elements.dart' show CommonElements; 26 import '../../common_elements.dart' show CommonElements;
27 import '../../elements/elements.dart' show ClassElement, MethodElement; 27 import '../../elements/elements.dart' show ClassElement, MethodElement;
28 import '../../js/js.dart' as js; 28 import '../../js/js.dart' as js;
29 import '../../js_backend/js_backend.dart' 29 import '../../js_backend/js_backend.dart'
30 show JavaScriptBackend, Namer, ConstantEmitter; 30 show JavaScriptBackend, Namer, ConstantEmitter;
31 import '../../js_backend/interceptor_data.dart'; 31 import '../../js_backend/interceptor_data.dart';
32 import '../../world.dart'; 32 import '../../world.dart';
33 import '../constant_ordering.dart' show deepCompareConstants; 33 import '../constant_ordering.dart' show ConstantOrdering;
34 import '../code_emitter_task.dart'; 34 import '../code_emitter_task.dart';
35 import '../js_emitter.dart' show NativeEmitter; 35 import '../js_emitter.dart' show NativeEmitter;
36 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode; 36 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
37 import '../model.dart'; 37 import '../model.dart';
38 import '../sorter.dart' show Sorter;
38 39
39 class ModelEmitter { 40 class ModelEmitter {
40 final Compiler compiler; 41 final Compiler compiler;
41 final Namer namer; 42 final Namer namer;
42 ConstantEmitter constantEmitter; 43 ConstantEmitter constantEmitter;
43 final NativeEmitter nativeEmitter; 44 final NativeEmitter nativeEmitter;
44 final ClosedWorld _closedWorld; 45 final ClosedWorld _closedWorld;
46 final ConstantOrdering _constantOrdering;
45 47
46 JavaScriptBackend get backend => compiler.backend; 48 JavaScriptBackend get backend => compiler.backend;
47 49
48 /// For deferred loading we communicate the initializers via this global var. 50 /// For deferred loading we communicate the initializers via this global var.
49 static const String deferredInitializersGlobal = 51 static const String deferredInitializersGlobal =
50 r"$__dart_deferred_initializers__"; 52 r"$__dart_deferred_initializers__";
51 53
52 static const String deferredExtension = "part.js"; 54 static const String deferredExtension = "part.js";
53 55
54 static const String typeNameProperty = r"builtin$cls"; 56 static const String typeNameProperty = r"builtin$cls";
55 57
56 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, this._closedWorld, 58 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, this._closedWorld,
57 CodeEmitterTask task) { 59 Sorter sorter, CodeEmitterTask task)
60 : _constantOrdering = new ConstantOrdering(sorter) {
58 this.constantEmitter = new ConstantEmitter( 61 this.constantEmitter = new ConstantEmitter(
59 compiler.options, 62 compiler.options,
60 _closedWorld.commonElements, 63 _closedWorld.commonElements,
61 compiler.codegenWorldBuilder, 64 compiler.codegenWorldBuilder,
62 _closedWorld.rtiNeed, 65 _closedWorld.rtiNeed,
63 compiler.backend.rtiEncoder, 66 compiler.backend.rtiEncoder,
64 namer, 67 namer,
65 task, 68 task,
66 this.generateConstantReference, 69 this.generateConstantReference,
67 constantListGenerator); 70 constantListGenerator);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (a.isInterceptor != b.isInterceptor) { 110 if (a.isInterceptor != b.isInterceptor) {
108 return a.isInterceptor ? -1 : 1; 111 return a.isInterceptor ? -1 : 1;
109 } 112 }
110 113
111 // Sorting by the long name clusters constants with the same constructor 114 // Sorting by the long name clusters constants with the same constructor
112 // which compresses a tiny bit better. 115 // which compresses a tiny bit better.
113 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); 116 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b));
114 if (r != 0) return r; 117 if (r != 0) return r;
115 118
116 // Resolve collisions in the long name by using a structural order. 119 // Resolve collisions in the long name by using a structural order.
117 return deepCompareConstants(a, b); 120 return _constantOrdering.compare(a, b);
118 } 121 }
119 122
120 js.Expression generateStaticClosureAccess(MethodElement element) { 123 js.Expression generateStaticClosureAccess(MethodElement element) {
121 return js.js('#.#()', [ 124 return js.js('#.#()', [
122 namer.globalObjectForMember(element), 125 namer.globalObjectForMember(element),
123 namer.staticClosureName(element) 126 namer.staticClosureName(element)
124 ]); 127 ]);
125 } 128 }
126 129
127 js.Expression generateConstantReference(ConstantValue value) { 130 js.Expression generateConstantReference(ConstantValue value) {
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 #eagerClasses; 1286 #eagerClasses;
1284 1287
1285 var end = Date.now(); 1288 var end = Date.now();
1286 // print('Setup: ' + (end - start) + ' ms.'); 1289 // print('Setup: ' + (end - start) + ' ms.');
1287 1290
1288 #invokeMain; // Start main. 1291 #invokeMain; // Start main.
1289 1292
1290 })(Date.now(), #code) 1293 })(Date.now(), #code)
1291 }"""; 1294 }""";
1292 } 1295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698