From d38c09ed222f3db50a2a48fd28cca841c5d12621 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 12 Sep 2013 10:55:24 -0400 Subject: [PATCH] go.tools/oracle: set AllASTs=true always, and simplify. Every one of the oracle's query modes needs to have typed ASTs available, at least transiently, so that the -pos flag can be interpreted. (The only mode that doesn't need the -pos flag is callgraph, but that needs PTA.) So we hard-code it to true. This change fixes a bug in the 'implements' query that causes -pos parsing to fail. (This wasn't exposed by the tests because they are degenerate in that the query always occurs in the main package, which is specified ad-hoc, i.e. as a source file not an import path. That's unfortunate, but this change renders the distinction uninteresting in future.) R=crawshaw, dominik.honnef CC=golang-dev https://golang.org/cl/13334050 --- oracle/oracle.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/oracle/oracle.go b/oracle/oracle.go index 5b70ee84..d2602c14 100644 --- a/oracle/oracle.go +++ b/oracle/oracle.go @@ -50,14 +50,16 @@ type oracle struct { } // A set of bits indicating the analytical requirements of each mode. -// Typed ASTs for the queried package are always available. +// +// Typed ASTs for the whole program are always constructed +// transiently; they are retained only for the queried package unless +// AllTypeInfo is set. const ( - Pos = 1 << iota // needs a position - ExactPos // needs an exact AST selection; implies Pos - AllASTs // needs ASTs (not just object types) for whole program - AllTypeInfo // needs to retain type info for all ASTs in the program - SSA // needs ssa.Packages for whole program - PTA = AllASTs | SSA // needs pointer analysis + Pos = 1 << iota // needs a position + ExactPos // needs an exact AST selection; implies Pos + AllTypeInfo // needs to retain type info for all ASTs in the program + SSA // needs ssa.Packages for whole program + PTA = SSA // needs pointer analysis ) type modeInfo struct { @@ -71,10 +73,10 @@ var modes = map[string]modeInfo{ "callgraph": modeInfo{PTA, callgraph}, "callstack": modeInfo{PTA | Pos, callstack}, "describe": modeInfo{PTA | ExactPos, describe}, - "freevars": modeInfo{AllASTs | Pos, freevars}, + "freevars": modeInfo{Pos, freevars}, "implements": modeInfo{Pos, implements}, "peers": modeInfo{PTA | Pos, peers}, - "referrers": modeInfo{AllTypeInfo | AllASTs | Pos, referrers}, + "referrers": modeInfo{AllTypeInfo | Pos, referrers}, } type printfFunc func(pos interface{}, format string, args ...interface{}) @@ -132,9 +134,6 @@ func Query(args []string, mode, pos string, ptalog io.Writer, buildContext *buil return nil, fmt.Errorf("invalid mode type: %q", mode) } - if minfo.needs&AllASTs == 0 { - buildContext = nil - } imp := importer.New(&importer.Config{Build: buildContext}) o := &oracle{ prog: ssa.NewProgram(imp.Fset, 0),