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

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

Issue 1284843002: dart2js: add simple script to compute dependency queries. Currently only (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
« pkg/compiler/tool/graph.dart ('K') | « pkg/compiler/tool/graph.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (g.target == null) print(g.toJson());
Harry Terkelsen 2015/08/11 22:57:42 only for debugging?
Siggi Cherem (dart-lang) 2015/08/12 00:06:01 True. removed
21 g1.addEdge(f, g.target);
22 g3.addEdge(f, g.target);
23 }
24 g2.addNode(f);
25 if (info.dependencies[f] != null) {
26 for (var g in info.dependencies[f]) {
27 g2.addEdge(f, g);
28 g3.addEdge(f, g);
29 }
30 }
31 }
32
33 for (var f in info.fields) {
34 g1.addNode(f);
35 g3.addNode(f);
36 for (var g in f.uses) {
37 g1.addEdge(f, g.target);
38 g3.addEdge(f, g.target);
39 }
40 g2.addNode(f);
41 g3.addNode(f);
Harry Terkelsen 2015/08/11 22:57:42 already added f to g3 above
Siggi Cherem (dart-lang) 2015/08/12 00:06:01 Good catch. Done
42 if (info.dependencies[f] != null) {
43 for (var g in info.dependencies[f]) {
44 g2.addEdge(f, g);
45 g3.addEdge(f, g);
46 }
47 }
48 }
49
50 // Note: these checks right now show that 'uses' links are computed
51 // differently than 'deps' links
52 int more1 = 0;
53 int more2 = 0;
54 int more1b = 0;
55 int more2b = 0;
56 _sameEdges(f) {
57 var targets1 = g1.targetsOf(f).toSet();
58 var targets2 = g2.targetsOf(f).toSet();
59 var len1 = targets1.length;
60 var len2 = targets2.length;
61 if (len1 > len2) more1b++;
62 if (len1 < len2) more2b++;
63 var diff1 = targets1.difference(targets2);
64 var diff2 = targets2.difference(targets1);
65 if (diff1.isNotEmpty) {
66 more1++;
67 }
68 if (diff2.isNotEmpty) {
69 more2++;
70 }
71 return true;
72 }
73 info.functions.forEach(_sameEdges);
74 info.fields.forEach(_sameEdges);
75 if (more1 > 0 || more2 > 0 || more1b > 0 || more2b > 0) {
76 print("Dep graph is not consistent: $more1 $more2");
77 }
78
79 return g3;
80 }
81
82 /// Provide a unique long name associated with [info].
83 // TODO(sigmund): guarantee that the name is actually unique.
84 String longName(Info info) {
85 var sb = new StringBuffer();
86 helper(i) {
87 if (i.parent == null) {
88 // TODO(sigmund): ensure `i is LibraryInfo`, we still don't set parents
89 // for closure classes correctly.
90 sb.write('${i.name}..');
91 } else {
92 helper(i.parent);
93 sb.write('.${i.name}');
94 }
95 }
96 helper(info);
97 return sb.toString();
98 }
OLDNEW
« pkg/compiler/tool/graph.dart ('K') | « pkg/compiler/tool/graph.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698