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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/startup_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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.startup_emitter.model_emitter; 5 library dart2js.js_emitter.startup_emitter.model_emitter;
6 6
7 import 'dart:convert' show JsonEncoder; 7 import 'dart:convert' show JsonEncoder;
8 import 'dart:math' show Random; 8 import 'dart:math' show Random;
9 9
10 import 'package:js_runtime/shared/embedded_names.dart' 10 import 'package:js_runtime/shared/embedded_names.dart'
(...skipping 30 matching lines...) Expand all
41 import '../../hash/sha1.dart' show Hasher; 41 import '../../hash/sha1.dart' show Hasher;
42 import '../../io/code_output.dart'; 42 import '../../io/code_output.dart';
43 import '../../io/location_provider.dart' show LocationCollector; 43 import '../../io/location_provider.dart' show LocationCollector;
44 import '../../io/source_map_builder.dart' show SourceMapBuilder; 44 import '../../io/source_map_builder.dart' show SourceMapBuilder;
45 import '../../js/js.dart' as js; 45 import '../../js/js.dart' as js;
46 import '../../js_backend/js_backend.dart' 46 import '../../js_backend/js_backend.dart'
47 show JavaScriptBackend, Namer, ConstantEmitter, StringBackedName; 47 show JavaScriptBackend, Namer, ConstantEmitter, StringBackedName;
48 import '../../js_backend/interceptor_data.dart'; 48 import '../../js_backend/interceptor_data.dart';
49 import '../../world.dart'; 49 import '../../world.dart';
50 import '../code_emitter_task.dart'; 50 import '../code_emitter_task.dart';
51 import '../constant_ordering.dart' show deepCompareConstants; 51 import '../constant_ordering.dart' show ConstantOrdering;
52 import '../headers.dart'; 52 import '../headers.dart';
53 import '../js_emitter.dart' show NativeEmitter; 53 import '../js_emitter.dart' show NativeEmitter;
54 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; 54 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator;
55 import '../model.dart'; 55 import '../model.dart';
56 import '../sorter.dart' show Sorter;
56 57
57 part 'deferred_fragment_hash.dart'; 58 part 'deferred_fragment_hash.dart';
58 part 'fragment_emitter.dart'; 59 part 'fragment_emitter.dart';
59 60
60 class ModelEmitter { 61 class ModelEmitter {
61 final Compiler compiler; 62 final Compiler compiler;
62 final Namer namer; 63 final Namer namer;
63 ConstantEmitter constantEmitter; 64 ConstantEmitter constantEmitter;
64 final NativeEmitter nativeEmitter; 65 final NativeEmitter nativeEmitter;
65 final bool shouldGenerateSourceMap; 66 final bool shouldGenerateSourceMap;
66 final ClosedWorld _closedWorld; 67 final ClosedWorld _closedWorld;
68 final ConstantOrdering _constantOrdering;
67 69
68 // The full code that is written to each hunk part-file. 70 // The full code that is written to each hunk part-file.
69 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; 71 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{};
70 72
71 JavaScriptBackend get backend => compiler.backend; 73 JavaScriptBackend get backend => compiler.backend;
72 74
73 /// For deferred loading we communicate the initializers via this global var. 75 /// For deferred loading we communicate the initializers via this global var.
74 static const String deferredInitializersGlobal = 76 static const String deferredInitializersGlobal =
75 r"$__dart_deferred_initializers__"; 77 r"$__dart_deferred_initializers__";
76 78
77 static const String partExtension = "part"; 79 static const String partExtension = "part";
78 static const String deferredExtension = "part.js"; 80 static const String deferredExtension = "part.js";
79 81
80 static const String typeNameProperty = r"builtin$cls"; 82 static const String typeNameProperty = r"builtin$cls";
81 83
82 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, this._closedWorld, 84 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, this._closedWorld,
83 CodeEmitterTask task, this.shouldGenerateSourceMap) { 85 Sorter sorter, CodeEmitterTask task, this.shouldGenerateSourceMap)
86 : _constantOrdering = new ConstantOrdering(sorter) {
84 this.constantEmitter = new ConstantEmitter( 87 this.constantEmitter = new ConstantEmitter(
85 compiler.options, 88 compiler.options,
86 _closedWorld.commonElements, 89 _closedWorld.commonElements,
87 compiler.codegenWorldBuilder, 90 compiler.codegenWorldBuilder,
88 _closedWorld.rtiNeed, 91 _closedWorld.rtiNeed,
89 compiler.backend.rtiEncoder, 92 compiler.backend.rtiEncoder,
90 namer, 93 namer,
91 task, 94 task,
92 this.generateConstantReference, 95 this.generateConstantReference,
93 constantListGenerator); 96 constantListGenerator);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if (a.isInterceptor != b.isInterceptor) { 132 if (a.isInterceptor != b.isInterceptor) {
130 return a.isInterceptor ? -1 : 1; 133 return a.isInterceptor ? -1 : 1;
131 } 134 }
132 135
133 // Sorting by the long name clusters constants with the same constructor 136 // Sorting by the long name clusters constants with the same constructor
134 // which compresses a tiny bit better. 137 // which compresses a tiny bit better.
135 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); 138 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b));
136 if (r != 0) return r; 139 if (r != 0) return r;
137 140
138 // Resolve collisions in the long name by using a structural order. 141 // Resolve collisions in the long name by using a structural order.
139 return deepCompareConstants(a, b); 142 return _constantOrdering.compare(a, b);
140 } 143 }
141 144
142 js.Expression generateStaticClosureAccess(MethodElement element) { 145 js.Expression generateStaticClosureAccess(MethodElement element) {
143 return js.js('#.#()', [ 146 return js.js('#.#()', [
144 namer.globalObjectForMember(element), 147 namer.globalObjectForMember(element),
145 namer.staticClosureName(element) 148 namer.staticClosureName(element)
146 ]); 149 ]);
147 } 150 }
148 151
149 js.Expression generateConstantReference(ConstantValue value) { 152 js.Expression generateConstantReference(ConstantValue value) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // data. 399 // data.
397 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 400 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
398 "needed for a given deferred library import."; 401 "needed for a given deferred library import.";
399 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 402 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
400 compiler.outputProvider.createOutputSink( 403 compiler.outputProvider.createOutputSink(
401 compiler.options.deferredMapUri.path, '', OutputType.info) 404 compiler.options.deferredMapUri.path, '', OutputType.info)
402 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 405 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
403 ..close(); 406 ..close();
404 } 407 }
405 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698