TBR: gri
I cannot create an issue on the tracker for some reason, so here it is:
go vet contains this snippet:
if types.IsAssignableTo(typ, errorType) || types.IsAssignableTo(typ, stringerType) {
It's getting the wrong answer: It claims
interface {
f()
}
or even
interface {
f() float64
}
matches the Error and Stringer interfaces. Both of them. This causes a test failure:
$ go test code.google.com/p/go.tools/cmd/vet
BUG: errchk: testdata/print.go:124: missing expected error: '"for printf verb %s of wrong type"'
$
This worked until very recently.
R=gri
CC=golang-dev
https://golang.org/cl/12398043
The old code only got it right for Stringers (etc.) and a few other simple cases.
But the rule used by fmt.Printf for non-Stringers is that pointers to structs
print as pointers, the rest must satisfy the format verb element-wise.
Thus for example
struct {a int, b []byte}
prints with %d and %q (sic) but not %g.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12340043
This is useful for situations where one only cares about
exports, for instance (as in the goapi checker).
R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12292043
e.g.
type T int
func (T) f() {}
var t T
_ = t.f // method value: should have signature "func()", no receiver
Also:
- ssa: add sanity check that helped diagnose this.
R=gri
CC=golang-dev
https://golang.org/cl/12283043
Remove its 'name' field and treat it just like any other
ssa.Register: it gets a temp name like "t1".
Instead, give it a comment field holding its purpose, e.g, "x"
for a source-level vare, or "new", "slicelit", "complit" or
"varargs".
This improves usability of tools whose UI needs to refer to a
particular allocation site.
R=gri
CC=golang-dev
https://golang.org/cl/12273043
Moving misc/dashboard to its new home. It will be deleted
(except for misc/dashboard/codereview) from its current home
if this is approved.
R=golang-dev, bradfitz, cmang, adg
CC=golang-dev
https://golang.org/cl/12180043
Fixed several bugs:
- lhs blank identifier may be parenthesized: (_) = 0 is ok
- constant shift counts in non-constant shifts must be >= 0
- init functions must have a body
Classified currently failing tests:
- 10 classes of errors not checked at the moment
R=adonovan, r
CC=golang-dev
https://golang.org/cl/11952046
The required changes were surprisingly minimal (I was hoping for a net
code deletion) because ssa is essentially doing its own type inference
for the three value,ok operators---and it continues to have to do so.
To see why, consider:
var i interface{}; var ok bool
i, ok := (map[string]string)(nil)[""]
Before, go/types inferred interface{} for the RHS of the assignment,
and now it infers (interface{}, bool), yet neither of these is what
ssa needs: it needs to know that the map values were strings so
that it can emit a lookup of the right type followed by a conversion
from string to interface{}.
TBR=gri
CC=golang-dev
https://golang.org/cl/11988044
CanonicalPos was inadequate since many pairs of instruction share the same pos (e.g. Allocs and Phis). Instead, we generalize the DebugRef instruction to associate not just Idents but Exprs with ssa.Values.
We no longer store any DebugRefs for constant expressions, to save space. (The type and value of such expressions can be obtained by other means, at a cost in complexity.)
Function.ValueForExpr queries the DebugRef info to return the ssa.Value of a given Expr.
Added tests.
Also:
- the DebugInfo flag is now per package, not global.
It must be set between Create and Build phases if desired.
- {Value,Instruction}.Pos() documentation updated: we still maintain
this information in the instruction stream even in non-debug mode,
but we make fewer claims about its invariants.
- Go and Defer instructions can now use their respective go/defer
token positions (not the call's lparen), so they do.
- SelectState:
Posn token.Pos indicates the <- position
DebugNode ast.Expr is the send stmt or receive expr.
- In building SelectStmt, we introduce extra temporaries in debug
mode to hold the result of the receive in 'case <-ch' even though
this value isn't ordinarily needed.
- Use *SelectState (indirectly) since the struct is getting bigger.
- Document some missing instructions in doc.go.
R=gri
CC=golang-dev
https://golang.org/cl/12147043
- added corresponding api tests
- support tuple comparison with IsIdentical
This CL will require some adjustments to SSA.
R=adonovan
CC=golang-dev
https://golang.org/cl/12024046
stdlib_test runs the builder (in sanity-checking mode) over
the Go standard library. It also prints some stats about
the time and memory usage.
Also:
- importer.LoadPackage too (not just doImport) must consult
the cache to avoid creating duplicate Package instances for
the same import path when called serially from a test.
- importer: skip empty directories without an error.
- importer: print all errors, not just the first.
- visit.go: added AllFunctions utility for enumerating all
Functions in a Program.
- ssa.MethodSet is not safe to expose from the package since
it must be accessed under an (inaccessible) lock. (!!!)
This CL makes it unexported and restricts its use to the
single function Program.LookupMethod().
- Program.MethodSet() has gone.
Clients should instead iterate over the types.MethodSet
and call LookupMethod.
- Package.DumpTo(): improved efficiency of methodset printing
(by not creating wrappers) and accuracy (by showing * on
receiver type only when necessary).
- Program.CreatePackage: documented precondition and added
assertion.
R=gri
CC=golang-dev
https://golang.org/cl/12058048
Also move some common code from main.go to handlers.go, and
exclude remotesearch.go from the appengine build (it is only
relevant to the command line interface).
R=bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/12001049
The analysis for types.Array was just missing. It's the same as a slice,
but we can't share code easily because the types differ, so we just dup it.
R=dsymonds
CC=golang-dev
https://golang.org/cl/12041045
First, %v and %T accept any arguments, so they should never warn.
Second, pointer types were not handled in matchArgType.
Third, the default response for matchArgType should be false.
R=r
CC=adonovan, golang-dev
https://golang.org/cl/12038050
Also:
- Implement Program.FuncValue for interface methods (+ test).
- go/types.Object.String(): don't package-qualify names unless
they are package level objects---otherwise you see "main.x" for
locals, struct fields, etc.
- go/types.Func.String(): don't assume Type() is *Signature;
it could be *Builtin.
R=gri
CC=golang-dev
https://golang.org/cl/12058045
buildDecl was visiting all decls in source order, but the spec
calls for visiting all vars and init() funcs in order, then
all remaining functions. These two passes are now called
buildInit(), buildFuncDecl().
+ Test.
Also:
- Added workaround to gcimporter for Func with pkg==nil.
- Prog.concreteMethods has been merged into Pkg.values.
- Prog.concreteMethod() renamed declaredFunc().
- s/mfunc/obj/ (name cleanup from recent gri CL)
R=gri
CC=golang-dev
https://golang.org/cl/12030044
A Method corresponds to a MethodVal Selection;
so the explicit Method object is not needed anymore.
- moved Selection code into separate file
- implemented Selection.String()
- improved and more consistent documentation
R=adonovan
CC=golang-dev
https://golang.org/cl/11950043
methprom.go covers method promotion.
Found bug: receiver() requires a following load under some
circumstances.
ifaceconv.go covers interface conversion.
Found bug: confusion about infallible and fallible conversions
led to use of TypeAssert in emitConv, which should never fail.
Changed semantics of ChangeInterface to make it infallible
and made some simplifications.
Also in this CL:
- SelectState.Pos now records the position of the
the '<-' operator for sends/receives done by a Select.
R=gri
CC=golang-dev
https://golang.org/cl/11931044
Should make it easier for clients to deal with
selector expressions.
Removed Field type: The respective information
is now reported in Info.Selections.
R=adonovan
CC=golang-dev
https://golang.org/cl/11942043
We now use LookupFieldOrMethod for all SelectorExprs, and
simplify the logic to discriminate the various cases.
We inline static calls to promoted/indirected functions,
dramatically reducing the number of functions created.
More tests are needed, but I'd like to submit this as-is.
In this CL, we:
- rely less on Id strings. Internally we now use
*types.Method (and its components) almost everywhere.
- stop thinking of types.Methods as objects. They don't
have stable identities. (Hopefully they will become
plain-old structs soon.)
- eliminate receiver indirection wrappers:
indirection and promotion are handled together by makeWrapper.
- Handle the interactions of promotion, indirection and
abstract methods much more cleanly.
- support receiver-bound interface method closures.
- break up builder.selectField so we can re-use parts
(emitFieldSelection).
- add importer.PackageInfo.classifySelector utility.
- delete interfaceMethodIndex()
- delete namedTypeMethodIndex()
- delete isSuperInterface() (replaced by types.IsAssignable)
- call memberFromObject on each declared concrete method's
*types.Func, not on every Method frem each method set, in the
CREATE phase for packages loaded by gcimporter.
go/types:
- document Func, Signature.Recv() better.
- use fmt in {Package,Label}.String
- reimplement Func.String to be prettier and to include method
receivers.
API changes:
- Function.method now holds the types.Method (soon to be
not-an-object) for synthetic wrappers.
- CallCommon.Method now contains an abstract (interface)
method object; was an abstract method index.
- CallCommon.MethodId() gone.
- Program.LookupMethod now takes a *Method not an Id string.
R=gri
CC=golang-dev
https://golang.org/cl/11674043