From baf49b2523e8f58f7e64fd385d7e69b338828c6e Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Thu, 24 Oct 2019 15:53:39 +1100 Subject: [PATCH] show struct dependency cycles in error & update module cycle error (#2517) --- vlib/compiler/cgen.v | 4 +++- vlib/compiler/depgraph.v | 46 +++++++++++++++++++++++----------------- vlib/compiler/main.v | 3 +-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/vlib/compiler/cgen.v b/vlib/compiler/cgen.v index 1dfc8d52db..c0441d67d9 100644 --- a/vlib/compiler/cgen.v +++ b/vlib/compiler/cgen.v @@ -361,7 +361,9 @@ fn sort_structs(types []Type) []Type { // sort graph dep_graph_sorted := dep_graph.resolve() if !dep_graph_sorted.acyclic { - verror('error: cgen.sort_structs() DGNAC.\nplease create a new issue here: https://github.com/vlang/v/issues and tag @joe-conigliaro') + verror('cgen.sort_structs(): the following structs form a dependancy cycle:\n' + + dep_graph_sorted.display_cycles() + + '\nif you feel this is an error, please create a new issue here: https://github.com/vlang/v/issues and tag @joe-conigliaro') } // sort types mut types_sorted := []Type diff --git a/vlib/compiler/depgraph.v b/vlib/compiler/depgraph.v index f0e94b8455..59bc3544e1 100644 --- a/vlib/compiler/depgraph.v +++ b/vlib/compiler/depgraph.v @@ -11,7 +11,6 @@ struct DepGraphNode { mut: name string deps []string - last_cycle string } struct DepGraph { @@ -84,13 +83,8 @@ pub fn(graph &DepGraph) resolve() &DepGraph { if ready_set.size() == 0 { mut g := new_dep_graph() g.acyclic = false - ndk := node_deps.keys() - for name, _ in node_deps { - mut node := node_names[name] - if name == ndk[node_deps.size-1] { - node.last_cycle = node_deps[name].items[node_deps[name].items.len-1] - } - g.nodes << node + for name, _ in node_deps { + g.nodes << node_names[name] } return g } @@ -112,19 +106,31 @@ pub fn(graph &DepGraph) last_node() DepGraphNode { return graph.nodes[graph.nodes.len-1] } -pub fn(graph &DepGraph) last_cycle() string { - return graph.last_node().last_cycle -} - -pub fn(graph &DepGraph) display() { - for i:=0; i