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

Unified 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 side-by-side diff with in-line comments
Download patch
« pkg/compiler/tool/graph.dart ('K') | « pkg/compiler/tool/graph.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/tool/util.dart
diff --git a/pkg/compiler/tool/util.dart b/pkg/compiler/tool/util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c3091f5b9f6911893cf460e998b45da4fcea69d7
--- /dev/null
+++ b/pkg/compiler/tool/util.dart
@@ -0,0 +1,96 @@
+library compiler.tool.util;
+
+import 'package:compiler/src/info/info.dart';
+import 'graph.dart';
+
+/// Computes a graph of dependencies from [info].
+Graph<Info> graphFromInfo(AllInfo info) {
+ // Note: currently we build two graphs to debug the differences between to
Johnni Winther 2015/08/18 13:17:11 'between to' -> 'between two' ?
Siggi Cherem (dart-lang) 2015/08/18 19:13:18 Done.
+ // places where we collect this information in dump-info.
+ // TODO(sigmund): fix inconsistencies between graphs, stick with one of them.
+ // TODO(sigmund): create a concrete implementation of InfoGraph, instead of
+ // using the EdgeListGraph.
+ var g1 = new EdgeListGraph<Info>();
+ var g2 = new EdgeListGraph<Info>();
+ var g3 = new EdgeListGraph<Info>();
+ for (var f in info.functions) {
+ g1.addNode(f);
+ g3.addNode(f);
+ for (var g in f.uses) {
+ g1.addEdge(f, g.target);
+ g3.addEdge(f, g.target);
+ }
+ g2.addNode(f);
+ if (info.dependencies[f] != null) {
+ for (var g in info.dependencies[f]) {
+ g2.addEdge(f, g);
+ g3.addEdge(f, g);
+ }
+ }
+ }
+
+ for (var f in info.fields) {
+ g1.addNode(f);
+ g3.addNode(f);
+ for (var g in f.uses) {
+ g1.addEdge(f, g.target);
+ g3.addEdge(f, g.target);
+ }
+ g2.addNode(f);
+ if (info.dependencies[f] != null) {
+ for (var g in info.dependencies[f]) {
+ g2.addEdge(f, g);
+ g3.addEdge(f, g);
+ }
+ }
+ }
+
+ // Note: these checks right now show that 'uses' links are computed
+ // differently than 'deps' links
+ int more1 = 0;
+ int more2 = 0;
+ int more1b = 0;
+ int more2b = 0;
+ _sameEdges(f) {
+ var targets1 = g1.targetsOf(f).toSet();
+ var targets2 = g2.targetsOf(f).toSet();
+ var len1 = targets1.length;
+ var len2 = targets2.length;
+ if (len1 > len2) more1b++;
+ if (len1 < len2) more2b++;
+ var diff1 = targets1.difference(targets2);
+ var diff2 = targets2.difference(targets1);
+ if (diff1.isNotEmpty) {
+ more1++;
+ }
+ if (diff2.isNotEmpty) {
+ more2++;
+ }
+ return true;
+ }
+ info.functions.forEach(_sameEdges);
+ info.fields.forEach(_sameEdges);
+ if (more1 > 0 || more2 > 0 || more1b > 0 || more2b > 0) {
+ print("Dep graph is not consistent: $more1 $more2");
+ }
+
+ return g3;
+}
+
+/// Provide a unique long name associated with [info].
+// TODO(sigmund): guarantee that the name is actually unique.
+String longName(Info info) {
+ var sb = new StringBuffer();
+ helper(i) {
+ if (i.parent == null) {
+ // TODO(sigmund): ensure `i is LibraryInfo`, we still don't set parents
+ // for closure classes correctly.
+ sb.write('${i.name}..');
+ } else {
+ helper(i.parent);
+ sb.write('.${i.name}');
+ }
+ }
+ helper(info);
+ return sb.toString();
+}
« 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