aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorMarco Vanotti <mvanotti@users.noreply.github.com>2018-11-20 17:37:06 -0800
committerDmitry Vyukov <dvyukov@google.com>2018-11-21 02:37:06 +0100
commit37a6ea34f16615595e07bbbacdd842d511f962a6 (patch)
treeb17215d87fe35a854c43cb742a9719dcde292899 /sys
parentcb04e409f842fc2548d3d090583eb582069900b9 (diff)
pkg/compiler: add error handler in CollectUnused
* pkg/compiler: Add error handler in `CollectUnused`. This commit adds an error handler for the `CollectUnused` function. The error handler just panics on any error, but is useful for debugging. The error handler is used any time `comp` finds an error, and if it's missing, it will panic due to a `nil` pointer dereference. At least now we get a better understanding of the errors. The only user of `CollectUnused` is `sys/fuchsia/fidlgen`, which is failing now and will be fixed in a future commit. The output message looks like this: ``` panic: could not collect unused nodes. fidl_net-stack.txt:110:15: unknown type zx_chan_zircon_ethernet_Device_client ``` * pkg/compiler Better error handling in CollectUnused This commit changes the default error handler for compiler to `ast.LoggingHandler`, meaning that if `nil` is passed as an error handler, `LoggingHandler` will be used instead. `CollectUnused` now returns an error if any of the subfunctions produce errors. `fidlgen` is the only caller of `CollectUnused`, and now checks for errors as well. * pkg/compiler Add tests for CollectUnused This commit adds basic tests for the CollectUnused function. There's one test that checks that it returns the right nodes, and another one that makes sure that it returns errors when needed. To make the test clearer, I had to add the error handler as an explicit parameter in `CollectUnunsed`, instead of using the default one. This avoid printing garbage in the logs. The `TestCollectUnusedError` function uses a nopErrorHandler to avoid printing anything. * pkg/compiler fix presubmit warnings
Diffstat (limited to 'sys')
-rw-r--r--sys/fuchsia/fidlgen/main.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go
index 6b3d0f702..dc187b49f 100644
--- a/sys/fuchsia/fidlgen/main.go
+++ b/sys/fuchsia/fidlgen/main.go
@@ -104,7 +104,13 @@ func main() {
}
unused := make(map[ast.Node]bool)
- for _, n := range compiler.CollectUnused(desc, target) {
+
+ nodes, err := compiler.CollectUnused(desc, target, nil)
+ if err != nil {
+ failf("collect unused nodes failed: %v", err)
+ }
+
+ for _, n := range nodes {
unused[n] = true
}