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

Side by Side Diff: pkg/compiler/lib/src/dump_info.dart

Issue 1182913003: Split TypedSelector into Selector and TypeMask. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 6 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
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/dart_backend.dart ('k') | pkg/compiler/lib/src/enqueue.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dump_info; 5 library dump_info;
6 6
7 import 'dart:convert' show 7 import 'dart:convert' show
8 HtmlEscape, 8 HtmlEscape,
9 JsonEncoder, 9 JsonEncoder,
10 StringConversionSink, 10 StringConversionSink,
11 ChunkedConversionSink; 11 ChunkedConversionSink;
12 12
13 import 'elements/elements.dart'; 13 import 'elements/elements.dart';
14 import 'elements/visitor.dart'; 14 import 'elements/visitor.dart';
15 import 'dart2jslib.dart' show 15 import 'dart2jslib.dart' show
16 Backend, 16 Backend,
17 CodeBuffer, 17 CodeBuffer,
18 Compiler, 18 Compiler,
19 CompilerTask, 19 CompilerTask,
20 MessageKind; 20 MessageKind;
21 import 'types/types.dart' show TypeMask; 21 import 'types/types.dart' show TypeMask;
22 import 'deferred_load.dart' show OutputUnit; 22 import 'deferred_load.dart' show OutputUnit;
23 import 'js_backend/js_backend.dart' show JavaScriptBackend; 23 import 'js_backend/js_backend.dart' show JavaScriptBackend;
24 import 'js/js.dart' as jsAst; 24 import 'js/js.dart' as jsAst;
25 import 'universe/universe.dart' show Selector; 25 import 'universe/universe.dart' show Selector, UniverseSelector;
26 import 'util/util.dart' show NO_LOCATION_SPANNABLE; 26 import 'util/util.dart' show NO_LOCATION_SPANNABLE;
27 27
28 /// Maps objects to an id. Supports lookups in 28 /// Maps objects to an id. Supports lookups in
29 /// both directions. 29 /// both directions.
30 class IdMapper<T>{ 30 class IdMapper<T>{
31 Map<int, T> _idToElement = {}; 31 Map<int, T> _idToElement = {};
32 Map<T, int> _elementToId = {}; 32 Map<T, int> _elementToId = {};
33 int _idCounter = 0; 33 int _idCounter = 0;
34 final String name; 34 final String name;
35 35
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 'inlinedCount': inlinedCount, 382 'inlinedCount': inlinedCount,
383 'code': emittedCode == null ? null : '$emittedCode', 383 'code': emittedCode == null ? null : '$emittedCode',
384 'type': element.type.toString(), 384 'type': element.type.toString(),
385 'outputUnit': mapper._outputUnit.add(outputUnit) 385 'outputUnit': mapper._outputUnit.add(outputUnit)
386 }; 386 };
387 } 387 }
388 } 388 }
389 389
390 class Selection { 390 class Selection {
391 final Element selectedElement; 391 final Element selectedElement;
392 final Selector selector; 392 final TypeMask mask;
393 Selection(this.selectedElement, this.selector); 393 Selection(this.selectedElement, this.mask);
394 } 394 }
395 395
396 class DumpInfoTask extends CompilerTask { 396 class DumpInfoTask extends CompilerTask {
397 DumpInfoTask(Compiler compiler) 397 DumpInfoTask(Compiler compiler)
398 : super(compiler); 398 : super(compiler);
399 399
400 String get name => "Dump Info"; 400 String get name => "Dump Info";
401 401
402 ElementToJsonVisitor infoCollector; 402 ElementToJsonVisitor infoCollector;
403 403
404 /// The size of the generated output. 404 /// The size of the generated output.
405 int _programSize; 405 int _programSize;
406 406
407 // A set of javascript AST nodes that we care about the size of. 407 // A set of javascript AST nodes that we care about the size of.
408 // This set is automatically populated when registerElementAst() 408 // This set is automatically populated when registerElementAst()
409 // is called. 409 // is called.
410 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>(); 410 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>();
411 // A mapping from Dart Elements to Javascript AST Nodes. 411 // A mapping from Dart Elements to Javascript AST Nodes.
412 final Map<Element, List<jsAst.Node>> _elementToNodes = 412 final Map<Element, List<jsAst.Node>> _elementToNodes =
413 <Element, List<jsAst.Node>>{}; 413 <Element, List<jsAst.Node>>{};
414 // A mapping from Javascript AST Nodes to the size of their 414 // A mapping from Javascript AST Nodes to the size of their
415 // pretty-printed contents. 415 // pretty-printed contents.
416 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{}; 416 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{};
417 417
418 final Map<Element, Set<Selector>> selectorsFromElement = {}; 418 final Map<Element, Set<UniverseSelector>> selectorsFromElement = {};
419 final Map<Element, int> inlineCount = <Element, int>{}; 419 final Map<Element, int> inlineCount = <Element, int>{};
420 // A mapping from an element to a list of elements that are 420 // A mapping from an element to a list of elements that are
421 // inlined inside of it. 421 // inlined inside of it.
422 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{}; 422 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{};
423 423
424 /// Register the size of the generated output. 424 /// Register the size of the generated output.
425 void reportSize(int programSize) { 425 void reportSize(int programSize) {
426 _programSize = programSize; 426 _programSize = programSize;
427 } 427 }
428 428
429 void registerInlined(Element element, Element inlinedFrom) { 429 void registerInlined(Element element, Element inlinedFrom) {
430 inlineCount.putIfAbsent(element, () => 0); 430 inlineCount.putIfAbsent(element, () => 0);
431 inlineCount[element] += 1; 431 inlineCount[element] += 1;
432 inlineMap.putIfAbsent(inlinedFrom, () => new List<Element>()); 432 inlineMap.putIfAbsent(inlinedFrom, () => new List<Element>());
433 inlineMap[inlinedFrom].add(element); 433 inlineMap[inlinedFrom].add(element);
434 } 434 }
435 435
436 /** 436 /**
437 * Registers that a function uses a selector in the 437 * Registers that a function uses a selector in the
438 * function body 438 * function body
439 */ 439 */
440 void elementUsesSelector(Element element, Selector selector) { 440 void elementUsesSelector(Element element, UniverseSelector selector) {
441 if (compiler.dumpInfo) { 441 if (compiler.dumpInfo) {
442 selectorsFromElement 442 selectorsFromElement
443 .putIfAbsent(element, () => new Set<Selector>()) 443 .putIfAbsent(element, () => new Set<UniverseSelector>())
444 .add(selector); 444 .add(selector);
445 } 445 }
446 } 446 }
447 447
448 /** 448 /**
449 * Returns an iterable of [Selection]s that are used by 449 * Returns an iterable of [Selection]s that are used by
450 * [element]. Each [Selection] contains an element that is 450 * [element]. Each [Selection] contains an element that is
451 * used and the selector that selected the element. 451 * used and the selector that selected the element.
452 */ 452 */
453 Iterable<Selection> getRetaining(Element element) { 453 Iterable<Selection> getRetaining(Element element) {
454 if (!selectorsFromElement.containsKey(element)) { 454 if (!selectorsFromElement.containsKey(element)) {
455 return const <Selection>[]; 455 return const <Selection>[];
456 } else { 456 } else {
457 return selectorsFromElement[element].expand( 457 return selectorsFromElement[element].expand(
458 (selector) { 458 (UniverseSelector selector) {
459 return compiler.world.allFunctions.filter(selector).map((element) { 459 return compiler.world.allFunctions.filter(
460 return new Selection(element, selector); 460 selector.selector, selector.mask)
461 .map((element) {
462 return new Selection(element, selector.mask);
461 }); 463 });
462 }); 464 });
463 } 465 }
464 } 466 }
465 467
466 // Returns true if we care about tracking the size of 468 // Returns true if we care about tracking the size of
467 // this node. 469 // this node.
468 bool isTracking(jsAst.Node code) { 470 bool isTracking(jsAst.Node code) {
469 if (compiler.dumpInfo) { 471 if (compiler.dumpInfo) {
470 return _tracking.contains(code); 472 return _tracking.contains(code);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // Don't bother recording an empty list of dependencies. 558 // Don't bother recording an empty list of dependencies.
557 if (pulling.length > 0) { 559 if (pulling.length > 0) {
558 String fnId = infoCollector.idOf(fn); 560 String fnId = infoCollector.idOf(fn);
559 // Some dart2js builtin functions are not 561 // Some dart2js builtin functions are not
560 // recorded. Don't register these. 562 // recorded. Don't register these.
561 if (fnId != null) { 563 if (fnId != null) {
562 holding[fnId] = pulling 564 holding[fnId] = pulling
563 .map((selection) { 565 .map((selection) {
564 return <String, String>{ 566 return <String, String>{
565 "id": infoCollector.idOf(selection.selectedElement), 567 "id": infoCollector.idOf(selection.selectedElement),
566 "mask": selection.selector.mask.toString() 568 "mask": selection.mask.toString()
567 }; 569 };
568 }) 570 })
569 // Filter non-null ids for the same reason as above. 571 // Filter non-null ids for the same reason as above.
570 .where((a) => a['id'] != null) 572 .where((a) => a['id'] != null)
571 .toList(); 573 .toList();
572 } 574 }
573 } 575 }
574 } 576 }
575 577
576 // Track dependencies that come from inlining. 578 // Track dependencies that come from inlining.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ChunkedConversionSink<Object> sink = 634 ChunkedConversionSink<Object> sink =
633 encoder.startChunkedConversion( 635 encoder.startChunkedConversion(
634 new StringConversionSink.fromStringSink(buffer)); 636 new StringConversionSink.fromStringSink(buffer));
635 sink.add(outJson); 637 sink.add(outJson);
636 compiler.reportInfo(NO_LOCATION_SPANNABLE, 638 compiler.reportInfo(NO_LOCATION_SPANNABLE,
637 const MessageKind( 639 const MessageKind(
638 "View the dumped .info.json file at " 640 "View the dumped .info.json file at "
639 "https://dart-lang.github.io/dump-info-visualizer")); 641 "https://dart-lang.github.io/dump-info-visualizer"));
640 } 642 }
641 } 643 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/dart_backend.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698