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

Side by Side Diff: pkg/compiler/tool/util.dart

Issue 1298553002: dart2js: switch to use dart2js_info/info.dart (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
(Empty)
1 library compiler.tool.util;
2
3 import 'package:compiler/src/info/info.dart';
4 import 'graph.dart';
5
6 /// Computes a graph of dependencies from [info].
7 Graph<Info> graphFromInfo(AllInfo info) {
8 // Note: currently we build two graphs to debug the differences between to
9 // places where we collect this information in dump-info.
10 // TODO(sigmund): fix inconsistencies between graphs, stick with one of them.
11 // TODO(sigmund): create a concrete implementation of InfoGraph, instead of
12 // using the EdgeListGraph.
13 var g1 = new EdgeListGraph<Info>();
14 var g2 = new EdgeListGraph<Info>();
15 var g3 = new EdgeListGraph<Info>();
16 for (var f in info.functions) {
17 g1.addNode(f);
18 g3.addNode(f);
19 for (var g in f.uses) {
20 g1.addEdge(f, g.target);
21 g3.addEdge(f, g.target);
22 }
23 g2.addNode(f);
24 if (info.dependencies[f] != null) {
25 for (var g in info.dependencies[f]) {
26 g2.addEdge(f, g);
27 g3.addEdge(f, g);
28 }
29 }
30 }
31
32 for (var f in info.fields) {
33 g1.addNode(f);
34 g3.addNode(f);
35 for (var g in f.uses) {
36 g1.addEdge(f, g.target);
37 g3.addEdge(f, g.target);
38 }
39 g2.addNode(f);
40 if (info.dependencies[f] != null) {
41 for (var g in info.dependencies[f]) {
42 g2.addEdge(f, g);
43 g3.addEdge(f, g);
44 }
45 }
46 }
47
48 // Note: these checks right now show that 'uses' links are computed
49 // differently than 'deps' links
50 int more1 = 0;
51 int more2 = 0;
52 int more1b = 0;
53 int more2b = 0;
54 _sameEdges(f) {
55 var targets1 = g1.targetsOf(f).toSet();
56 var targets2 = g2.targetsOf(f).toSet();
57 var len1 = targets1.length;
58 var len2 = targets2.length;
59 if (len1 > len2) more1b++;
60 if (len1 < len2) more2b++;
61 var diff1 = targets1.difference(targets2);
62 var diff2 = targets2.difference(targets1);
63 if (diff1.isNotEmpty) {
64 more1++;
65 }
66 if (diff2.isNotEmpty) {
67 more2++;
68 }
69 return true;
70 }
71 info.functions.forEach(_sameEdges);
72 info.fields.forEach(_sameEdges);
73 if (more1 > 0 || more2 > 0 || more1b > 0 || more2b > 0) {
74 print("Dep graph is not consistent: $more1 $more2");
75 }
76
77 return g3;
78 }
79
80 /// Provide a unique long name associated with [info].
81 // TODO(sigmund): guarantee that the name is actually unique.
82 String longName(Info info) {
83 var sb = new StringBuffer();
84 helper(i) {
85 if (i.parent == null) {
86 // TODO(sigmund): ensure `i is LibraryInfo`, we still don't set parents
87 // for closure classes correctly.
88 sb.write('${i.name}..');
89 } else {
90 helper(i.parent);
91 sb.write('.${i.name}');
92 }
93 }
94 helper(info);
95 return sb.toString();
96 }
OLDNEW
« no previous file with comments | « pkg/compiler/tool/library_size_split.dart ('k') | tests/compiler/dart2js/analyze_unused_dart2js_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698