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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/full_emitter/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.full_emitter; 5 library dart2js.js_emitter.full_emitter;
6 6
7 import 'dart:collection' show HashMap; 7 import 'dart:collection' show HashMap;
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
(...skipping 22 matching lines...) Expand all
33 JavaScriptBackend, 33 JavaScriptBackend,
34 Namer, 34 Namer,
35 SetterName, 35 SetterName,
36 TypeVariableCodegenAnalysis; 36 TypeVariableCodegenAnalysis;
37 import '../../js_backend/native_data.dart'; 37 import '../../js_backend/native_data.dart';
38 import '../../universe/call_structure.dart' show CallStructure; 38 import '../../universe/call_structure.dart' show CallStructure;
39 import '../../universe/selector.dart' show Selector; 39 import '../../universe/selector.dart' show Selector;
40 import '../../universe/world_builder.dart' show CodegenWorldBuilder; 40 import '../../universe/world_builder.dart' show CodegenWorldBuilder;
41 import '../../util/uri_extras.dart' show relativize; 41 import '../../util/uri_extras.dart' show relativize;
42 import '../../world.dart' show ClosedWorld; 42 import '../../world.dart' show ClosedWorld;
43 import '../constant_ordering.dart' show deepCompareConstants; 43 import '../constant_ordering.dart' show ConstantOrdering;
44 import '../headers.dart'; 44 import '../headers.dart';
45 import '../js_emitter.dart' hide Emitter, EmitterFactory; 45 import '../js_emitter.dart' hide Emitter, EmitterFactory;
46 import '../js_emitter.dart' as js_emitter show EmitterBase, EmitterFactory; 46 import '../js_emitter.dart' as js_emitter show EmitterBase, EmitterFactory;
47 import '../model.dart'; 47 import '../model.dart';
48 import '../program_builder/program_builder.dart'; 48 import '../program_builder/program_builder.dart';
49 import '../sorter.dart'; 49 import '../sorter.dart';
50 50
51 import 'class_builder.dart'; 51 import 'class_builder.dart';
52 import 'class_emitter.dart'; 52 import 'class_emitter.dart';
53 import 'container_builder.dart'; 53 import 'container_builder.dart';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // collector. 90 // collector.
91 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists; 91 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists;
92 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists; 92 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists;
93 List<TypedefEntity> typedefsNeededForReflection; 93 List<TypedefEntity> typedefsNeededForReflection;
94 94
95 final ContainerBuilder containerBuilder = new ContainerBuilder(); 95 final ContainerBuilder containerBuilder = new ContainerBuilder();
96 final ClassEmitter classEmitter; 96 final ClassEmitter classEmitter;
97 final NsmEmitter nsmEmitter; 97 final NsmEmitter nsmEmitter;
98 final InterceptorEmitter interceptorEmitter; 98 final InterceptorEmitter interceptorEmitter;
99 final Sorter _sorter; 99 final Sorter _sorter;
100 final ConstantOrdering _constantOrdering;
100 101
101 // TODO(johnniwinther): Wrap these fields in a caching strategy. 102 // TODO(johnniwinther): Wrap these fields in a caching strategy.
102 final List<jsAst.Statement> cachedEmittedConstantsAst = <jsAst.Statement>[]; 103 final List<jsAst.Statement> cachedEmittedConstantsAst = <jsAst.Statement>[];
103 104
104 bool needsClassSupport = false; 105 bool needsClassSupport = false;
105 bool needsMixinSupport = false; 106 bool needsMixinSupport = false;
106 bool needsLazyInitializer = false; 107 bool needsLazyInitializer = false;
107 108
108 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", 109 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info",
109 /// that is, some function was needed for reflection, had stubs, or had a 110 /// that is, some function was needed for reflection, had stubs, or had a
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // this map. 163 // this map.
163 final Map<Fragment, Map<LibraryEntity, ClassBuilder>> libraryDescriptors = 164 final Map<Fragment, Map<LibraryEntity, ClassBuilder>> libraryDescriptors =
164 new Map<Fragment, Map<LibraryEntity, ClassBuilder>>(); 165 new Map<Fragment, Map<LibraryEntity, ClassBuilder>>();
165 166
166 final Map<Fragment, Map<ClassEntity, ClassBuilder>> classDescriptors = 167 final Map<Fragment, Map<ClassEntity, ClassBuilder>> classDescriptors =
167 new Map<Fragment, Map<ClassEntity, ClassBuilder>>(); 168 new Map<Fragment, Map<ClassEntity, ClassBuilder>>();
168 169
169 final bool generateSourceMap; 170 final bool generateSourceMap;
170 171
171 Emitter(this.compiler, this.namer, this._closedWorld, this.generateSourceMap, 172 Emitter(this.compiler, this.namer, this._closedWorld, this.generateSourceMap,
172 this.task, this._sorter) 173 this.task, Sorter sorter)
173 : classEmitter = new ClassEmitter(_closedWorld), 174 : classEmitter = new ClassEmitter(_closedWorld),
174 interceptorEmitter = new InterceptorEmitter(_closedWorld), 175 interceptorEmitter = new InterceptorEmitter(_closedWorld),
175 nsmEmitter = new NsmEmitter(_closedWorld) { 176 nsmEmitter = new NsmEmitter(_closedWorld),
177 _sorter = sorter,
178 _constantOrdering = new ConstantOrdering(sorter) {
176 constantEmitter = new ConstantEmitter( 179 constantEmitter = new ConstantEmitter(
177 compiler.options, 180 compiler.options,
178 _closedWorld.commonElements, 181 _closedWorld.commonElements,
179 compiler.codegenWorldBuilder, 182 compiler.codegenWorldBuilder,
180 _closedWorld.rtiNeed, 183 _closedWorld.rtiNeed,
181 compiler.backend.rtiEncoder, 184 compiler.backend.rtiEncoder,
182 namer, 185 namer,
183 task, 186 task,
184 this.constantReference, 187 this.constantReference,
185 constantListGenerator); 188 constantListGenerator);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (a.isInterceptor != b.isInterceptor) { 232 if (a.isInterceptor != b.isInterceptor) {
230 return a.isInterceptor ? -1 : 1; 233 return a.isInterceptor ? -1 : 1;
231 } 234 }
232 235
233 // Sorting by the long name clusters constants with the same constructor 236 // Sorting by the long name clusters constants with the same constructor
234 // which compresses a tiny bit better. 237 // which compresses a tiny bit better.
235 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); 238 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b));
236 if (r != 0) return r; 239 if (r != 0) return r;
237 240
238 // Resolve collisions in the long name by using a structural order. 241 // Resolve collisions in the long name by using a structural order.
239 return deepCompareConstants(a, b); 242 return _constantOrdering.compare(a, b);
240 } 243 }
241 244
242 @override 245 @override
243 jsAst.Expression constantReference(ConstantValue value) { 246 jsAst.Expression constantReference(ConstantValue value) {
244 if (value.isFunction) { 247 if (value.isFunction) {
245 FunctionConstantValue functionConstant = value; 248 FunctionConstantValue functionConstant = value;
246 return isolateStaticClosureAccess(functionConstant.element); 249 return isolateStaticClosureAccess(functionConstant.element);
247 } 250 }
248 251
249 // We are only interested in the "isInlined" part, but it does not hurt to 252 // We are only interested in the "isInlined" part, but it does not hurt to
(...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 // data. 1947 // data.
1945 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 1948 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
1946 "needed for a given deferred library import."; 1949 "needed for a given deferred library import.";
1947 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 1950 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
1948 compiler.outputProvider.createOutputSink( 1951 compiler.outputProvider.createOutputSink(
1949 compiler.options.deferredMapUri.path, '', OutputType.info) 1952 compiler.options.deferredMapUri.path, '', OutputType.info)
1950 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 1953 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
1951 ..close(); 1954 ..close();
1952 } 1955 }
1953 } 1956 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698