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

Side by Side Diff: pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 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
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 /// Analysis to determine how to generate code for `LookupMap`s. 5 /// Analysis to determine how to generate code for `LookupMap`s.
6 library compiler.src.js_backend.lookup_map_analysis; 6 library compiler.src.js_backend.lookup_map_analysis;
7 7
8 import 'package:pub_semver/pub_semver.dart'; 8 import 'package:pub_semver/pub_semver.dart';
9 9
10 import '../common.dart'; 10 import '../common.dart';
11 import '../compiler.dart' show Compiler; 11 import '../compiler.dart' show Compiler;
12 import '../constants/values.dart' 12 import '../constants/values.dart'
13 show 13 show
14 ConstantValue, 14 ConstantValue,
15 ConstructedConstantValue, 15 ConstructedConstantValue,
16 ListConstantValue, 16 ListConstantValue,
17 NullConstantValue, 17 NullConstantValue,
18 StringConstantValue, 18 StringConstantValue,
19 TypeConstantValue; 19 TypeConstantValue;
20 import '../elements/resolution_types.dart' show DartType; 20 import '../elements/resolution_types.dart' show ResolutionDartType;
21 import '../elements/resolution_types.dart' show InterfaceType; 21 import '../elements/resolution_types.dart' show ResolutionInterfaceType;
22 import '../elements/elements.dart' 22 import '../elements/elements.dart'
23 show ClassElement, FieldElement, LibraryElement, VariableElement; 23 show ClassElement, FieldElement, LibraryElement, VariableElement;
24 import '../universe/use.dart' show StaticUse; 24 import '../universe/use.dart' show StaticUse;
25 import '../universe/world_impact.dart' 25 import '../universe/world_impact.dart'
26 show WorldImpact, StagedWorldImpactBuilder; 26 show WorldImpact, StagedWorldImpactBuilder;
27 import 'js_backend.dart' show JavaScriptBackend; 27 import 'js_backend.dart' show JavaScriptBackend;
28 28
29 /// An analysis and optimization to remove unused entries from a `LookupMap`. 29 /// An analysis and optimization to remove unused entries from a `LookupMap`.
30 /// 30 ///
31 /// `LookupMaps` are defined in `package:lookup_map/lookup_map.dart`. They are 31 /// `LookupMaps` are defined in `package:lookup_map/lookup_map.dart`. They are
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 257 }
258 258
259 /// Callback from the enqueuer, invoked when [element] is instantiated. 259 /// Callback from the enqueuer, invoked when [element] is instantiated.
260 void registerInstantiatedClass(ClassElement element) { 260 void registerInstantiatedClass(ClassElement element) {
261 if (!_isEnabled || !_inCodegen) return; 261 if (!_isEnabled || !_inCodegen) return;
262 // TODO(sigmund): only add if .runtimeType is ever used 262 // TODO(sigmund): only add if .runtimeType is ever used
263 _addClassUse(element); 263 _addClassUse(element);
264 } 264 }
265 265
266 /// Callback from the enqueuer, invoked when [type] is instantiated. 266 /// Callback from the enqueuer, invoked when [type] is instantiated.
267 void registerInstantiatedType(InterfaceType type) { 267 void registerInstantiatedType(ResolutionInterfaceType type) {
268 if (!_isEnabled || !_inCodegen) return; 268 if (!_isEnabled || !_inCodegen) return;
269 // TODO(sigmund): only add if .runtimeType is ever used 269 // TODO(sigmund): only add if .runtimeType is ever used
270 _addClassUse(type.element); 270 _addClassUse(type.element);
271 // TODO(sigmund): only do this when type-argument expressions are used? 271 // TODO(sigmund): only do this when type-argument expressions are used?
272 _addGenerics(type); 272 _addGenerics(type);
273 } 273 }
274 274
275 /// Records generic type arguments in [type], in case they are retrieved and 275 /// Records generic type arguments in [type], in case they are retrieved and
276 /// returned using a type-argument expression. 276 /// returned using a type-argument expression.
277 void _addGenerics(InterfaceType type) { 277 void _addGenerics(ResolutionInterfaceType type) {
278 if (!type.isGeneric) return; 278 if (!type.isGeneric) return;
279 for (var arg in type.typeArguments) { 279 for (var arg in type.typeArguments) {
280 if (arg is InterfaceType) { 280 if (arg is ResolutionInterfaceType) {
281 _addClassUse(arg.element); 281 _addClassUse(arg.element);
282 // Note: this call was needed to generate correct code for 282 // Note: this call was needed to generate correct code for
283 // type_lookup_map/generic_type_test 283 // type_lookup_map/generic_type_test
284 // TODO(sigmund): can we get rid of this? 284 // TODO(sigmund): can we get rid of this?
285 backend.computeImpactForInstantiatedConstantType( 285 backend.computeImpactForInstantiatedConstantType(
286 backend.backendClasses.typeImplementation.rawType, 286 backend.backendClasses.typeImplementation.rawType,
287 impactBuilderForCodegen); 287 impactBuilderForCodegen);
288 _addGenerics(arg); 288 _addGenerics(arg);
289 } 289 }
290 } 290 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 assert(!usedEntries.containsKey(key)); 424 assert(!usedEntries.containsKey(key));
425 ConstantValue constant = unusedEntries.remove(key); 425 ConstantValue constant = unusedEntries.remove(key);
426 usedEntries[key] = constant; 426 usedEntries[key] = constant;
427 analysis.backend.computeImpactForCompileTimeConstant( 427 analysis.backend.computeImpactForCompileTimeConstant(
428 constant, analysis.impactBuilderForCodegen, false); 428 constant, analysis.impactBuilderForCodegen, false);
429 } 429 }
430 430
431 /// Restores [original] to contain all of the entries marked as possibly used. 431 /// Restores [original] to contain all of the entries marked as possibly used.
432 void _prepareForEmission() { 432 void _prepareForEmission() {
433 ListConstantValue originalEntries = original.fields[analysis.entriesField]; 433 ListConstantValue originalEntries = original.fields[analysis.entriesField];
434 DartType listType = originalEntries.type; 434 ResolutionDartType listType = originalEntries.type;
435 List<ConstantValue> keyValuePairs = <ConstantValue>[]; 435 List<ConstantValue> keyValuePairs = <ConstantValue>[];
436 usedEntries.forEach((key, value) { 436 usedEntries.forEach((key, value) {
437 keyValuePairs.add(key); 437 keyValuePairs.add(key);
438 keyValuePairs.add(value); 438 keyValuePairs.add(value);
439 }); 439 });
440 440
441 // Note: we are restoring the entries here, see comment in [original]. 441 // Note: we are restoring the entries here, see comment in [original].
442 if (singlePair) { 442 if (singlePair) {
443 assert(keyValuePairs.length == 0 || keyValuePairs.length == 2); 443 assert(keyValuePairs.length == 0 || keyValuePairs.length == 2);
444 if (keyValuePairs.length == 2) { 444 if (keyValuePairs.length == 2) {
445 original.fields[analysis.keyField] = keyValuePairs[0]; 445 original.fields[analysis.keyField] = keyValuePairs[0];
446 original.fields[analysis.valueField] = keyValuePairs[1]; 446 original.fields[analysis.valueField] = keyValuePairs[1];
447 } 447 }
448 } else { 448 } else {
449 original.fields[analysis.entriesField] = 449 original.fields[analysis.entriesField] =
450 new ListConstantValue(listType, keyValuePairs); 450 new ListConstantValue(listType, keyValuePairs);
451 } 451 }
452 } 452 }
453 } 453 }
454 454
455 final _validLookupMapVersionConstraint = new VersionConstraint.parse('^0.0.1'); 455 final _validLookupMapVersionConstraint = new VersionConstraint.parse('^0.0.1');
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_interop_analysis.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698