Given a built-in call f(args), Info.Types now maps f to the call-site
specific type of f (by looking at the argument types) if the built-in
call is not producing a constant (at typecheck time) result. If the
result is constant, the recorded type is invalid (a back-end won't
need it).
R=adonovan
CC=golang-dev
https://golang.org/cl/14598045
Catch ... errors earlier and in case of error, type-check all
arguments anyway for better type reporting and fewer "declared
but not used" errors.
R=adonovan
CC=golang-dev
https://golang.org/cl/14600043
Assignments to "comma, ok" expressions on the lhs of an
assignment are not permitted unless we have map index
"comma, ok" expression. Created new operand mode 'mapindex'
to distinguish this case. Renamed mode 'valueok' to the more
commonly used 'commaok' term, which also makes it easier to
distinguish from simply 'value'.
Added corresponding tests.
Fixes a TODO.
R=adonovan
CC=golang-dev
https://golang.org/cl/14526049
- removed support for nil constants from go/exact
- instead define a singleton Nil Object (the nil _value_)
- in assignments, follow more closely spec wording
(pending spec CL 14415043)
- removed use of goto in checker.unary
- cleanup around handling of isRepresentable for
constants, with better error messages
- fix missing checks in checker.convertUntyped
- added isTyped (== !isUntyped) and isInterface predicates
- fixed hasNil predicate: unsafe.Pointer also has nil
- adjusted ssa per adonovan
- implememted types.Implements (wrapper arounfd types.MissingMethod)
- use types.Implements in vet (and fix a bug)
R=adonovan, r
CC=golang-dev
https://golang.org/cl/14438052
- factor out argument extraction logic
- cleaned up error handling in builtin.go (no need for goto's anymore)
- lots of additional test cases
- various cleanups, better documentation
Fixesgolang/go#5795.
R=adonovan
CC=golang-dev
https://golang.org/cl/14312044
It would be nice to be able to use this package
as a dependency (or other go utilities in the
ecosystem that depend on this package) in
environments which have not (or cannot) for
whatever reason upgraded to newer versions of
golang.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14283043
Revision f280b8a485fd of the std library changed the
gc export format: anonymous fields may be qualified
with a package.
R=rsc
TBR=rsc
CC=golang-dev
https://golang.org/cl/14312043
- permit ERROR markers to be in full or line comments
- don't require ""s in /* ERROR "foo" */
- enable more std tests
- some minor cleanups
R=adonovan
CC=golang-dev
https://golang.org/cl/14169044
In general, if a break or continue label is not found, we don't
know if a correspondingly named label was not declared, was declared
but is not visible, or will be declared (and won't be visible).
Complain about "invalid" rather than "not declared" label.
Added more tests.
R=adonovan
CC=golang-dev
https://golang.org/cl/14149043
This CL temporarily removes some preliminary label checks.
They will be implemented completely in a subsequent CL.
R=adonovan
CC=golang-dev
https://golang.org/cl/14055043
This change affects the API: Func objects now always have a *Signature
as type (never a *Builtin). Instead, built-ins now appear as *Builtin
objects. Only the built-in name is exposed, other fields are now private
to go/types.
Several bugs are fixed:
- correctly checking for built-ins permitted in statement context
- expression statements that are calls are not type-checked twice anymore
- go/defer statements report call types and provide good error messages now
This CL will briefly break the build until CL 13848043 is submitted.
R=adonovan
CC=golang-dev
https://golang.org/cl/13813043
also:
- initial code for unused label errors
- some cleanups, better names
- additional tests
TODO: Dot-imported packages are not handled yet; i.e., they
are always considered used for now.
R=adonovan
CC=golang-dev
https://golang.org/cl/13768043
Also:
- added more tests
- removed Var.Used accessor: it's not meaningful for clients since
it does not reflect actual use/def information
- fixed position for short variable declaration errors
R=adonovan
CC=golang-dev
https://golang.org/cl/13240051
- updated all tests to conform to stricter rules
- TODO: check for implicitly declared variables in type switches
R=adonovan
CC=golang-dev
https://golang.org/cl/13695046
1. handle return statements with zero (but expected) return values
2. indices provided for array or slice composite literals must be integer constants
Added additional test cases.
R=adonovan
CC=golang-dev
https://golang.org/cl/13734043
And: add accessor to get the primary from a secondary Package.
This change documents a surprising fact about the current
go/types resolver implementation, namely that each ast.ImportSpec
import "fmt"
creates a new ("secondary") Package object for fmt with the
same String, Name, Path and Scope as the canonical ("primary")
fmt package, but with a different identity.
This change also adds an accessor Package.Primary() that
returns the primary package associated with a secondary
package object, if any.
IMHO the current design is wrong, and the resolver should not
create secondary packages at all. Even if a package is
imported under a non-default name, as in
import f "fmt"
...
f.Print
we should just regard f as a reference to the existing package
"fmt", not as the defining identifier for a secondary package.
What we would lose by such a change (the connection of the two
f's in 'f.Print' and 'import f "fmt"') seems a small price to
pay.
This CL is thus just a minimal change to permit clients to
make progress under the status quo.
R=r, gri, crawshaw
CC=golang-dev
https://golang.org/cl/13626043
Make compliant with gc. Spec is not very clear.
Also: Fix error handling (don't destroy x before
using it in error message).
Fixesgolang/go#6326.
R=adonovan
CC=golang-dev
https://golang.org/cl/13632043
Add support for logging commands for Mercurial and Subversion as well as the ability to create/log a repo at a certain revision.
- Exported Cmd.LogCmd
- Exported Cmd.CreateAtRev
- Exported Cmd.Log
- Exported Cmd.LogAtRev
R=adg
CC=golang-dev
https://golang.org/cl/13060044
The test would nuke the entire contents of os.TempDir on completion.
This change corrects the code to use ioutil.TempDir.
R=r, adg
CC=golang-dev
https://golang.org/cl/12796045
go/vcs exposes cmd/go/vcs.go from the `go get` command.
- Exported global variables `Verbose` and `ShowCmd` to replace `buildV` and `buildX` from cmd/go/main.go.
- Moved environment building code (envForDir, mergeEnvLists)from cmd/go/main.go to env.go
- Exported Cmd and its methods: Create, Download, Ping, TagSync, and Tags
- Exported ByCmd and FromDir functions for constructing Cmd
- Exported TagCmd
- Exported RepoRoot
- Exported RepoRootForImport* functions for constructing RepoRoot
R=golang-dev, adg, cmang, bradfitz
CC=golang-dev
https://golang.org/cl/12058054
- cleaned up surrounding code
- adjusted error message positions for too few/many argument errors
- added more conversion tests
- added all tests under test/ken to std tests
R=adonovan, r
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12711043
- support Info.Scopes mapping that maps ast.Nodes
to the respective *Scope
- remove old node link from *Scope
- added corresponding API test
Also: re-enable debug mode (the faster version was
only important for the go api tool, which has its
own version now).
R=adonovan, r
CC=golang-dev
https://golang.org/cl/12552047
Provide fewer guarantees regarding the collected result
type information in types.Info if there are type errors.
Specifically, don't record nil objects in the Objects map
in case of a declaration error; instead, simply omit them.
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12553043
If a method cannot type check, we end up with the interface variable
m to hold <*Func, nil>. Don't put that in the map because it defeats
the usual != nil check.
R=gri, dsymonds
CC=golang-dev
https://golang.org/cl/12506043
Was broken by CL 12378043.
- factored out some error checking code
- adjusted error positions
R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12401043
They use stuff in syscall that doesn't exist on Windows, and this test does not
parse build tags (not that we make that easy) to automatically skip them.
R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/12453043
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
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
- 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
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
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
Also: Fixes a couple of places where scopes instead
of objsets were used (missed in previous CL).
R=adonovan
CC=golang-dev
https://golang.org/cl/11419047
Now, in a "switch y := x.(type)", there is no object for the
outer y, only implicit objects, one per case (including
default).
Also: don't set obj=nil for blank idents (workaround suggested by gri).
R=gri
CC=golang-dev
https://golang.org/cl/11564046
Fixes go tool vet breakage when applied to files
with incomplete type information for anonymous
fields.
R=adonovan
CC=golang-dev
https://golang.org/cl/11773043
- implemented objset for tracking duplicates of fields and methods
which permitted a simpler and faster scope implementation in turn
- related cleanups and internal renames
- fixed a couple of identifier reporting bugs
Speed of type-checking itself increased by almost 10%
(from ~71Kloc/s to ~78Kloc/s on one machine, measured
via go test -run=Self).
R=adonovan
CC=golang-dev
https://golang.org/cl/11750043
- more consistent naming of some internal data types and methods
- better factoring of some error reporting code
- cleanup around association of methods with receiver base types
- more tests
R=adonovan
CC=golang-dev
https://golang.org/cl/11726043
- treat receivers like ordinary parameters when checking signatures;
concentrate all respective checks in one place
- continue to type-check methods even if receiver base type does not
satisfy receiver type criteria (comes for free)
- don't ignore blank _ methods anymore
- various related cleanups
As a consequence, the resolving needs one less internal phase.
R=adonovan
CC=golang-dev
https://golang.org/cl/11591045
Temporarily remove Field objects in favor of Vars for struct fields.
In forthcoming CL, Fields will play the symmetric role to Methods, and
serve as lookup results including index information.
R=adonovan
CC=golang-dev
https://golang.org/cl/11594043
Allmost all uses of go/types that wanted the type
information computed, installed callback functions
that stored the information in maps. Most of the
time this is the only thing that could be done because
there is no guarantee that types are completely set
up before the end of type-checking.
This CL removes the respective Context callbacks in favor
of corresponding maps that collect the desired information
on demand, grouped together in an optional Info struct.
R=adonovan
CC=golang-dev
https://golang.org/cl/11530044
- fixed method set computation
- lazily compute it for a type on demand
- lazy allocation of various temporary maps
Also:
- removed Interface.IsEmpty, Scope.IsEmpty
(these convenience functions didn't carry their weight)
- cosmetic changes
Next:
- consolidate various lookup APIs
- use lazily computed method sets for various checks
instead of individual lookups
R=adonovan
CC=golang-dev
https://golang.org/cl/11385044
- removed a number of obsolete TODO(gri) comments.
- bring ssa.DefaultType back into sync with types.defaultType.
- re-enable types.Package.Path()!="" assertion.
- use Path() (not reflect pointer) in sort routine.
- make interp.checkInterface use types.MissingMethod.
- un-export ssa.MakeId function.
- inline pointer() into all callers, and delete.
- enable two more interp_tests: $GOROOT/test/{method3,cmp}.go
- add links to bugs to other interp_tests.
- add runtime.NumCPU to ssa/interp/externals.go
R=gri
CC=golang-dev
https://golang.org/cl/11353043
- now represent ...T parameter type as []T (rather than T)
- simplified call checking
- added missing check and test for x... arguments (x must be slice)
This CL will temporarily break ssa and ssa/interp.
R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/11317043
Objects:
- provide IsExported, SameName, uniqueName methods
- clean up a lot of dependent code
Scopes:
- don't add children to Universe scope (!)
- document Node, WriteTo
Types:
- remove Deref in favor of internal function deref
ssa, ssa/interp:
- introduced local deref, adjusted code
- fixed some "Underlying" bugs (pun intended)
R=adonovan
CC=golang-dev
https://golang.org/cl/11232043
Eval and EvalNode permit the evaluation of an expression
or type literal string (or AST node in case of EvalNode)
within a given context (package and scope).
Also:
- track nested (children) scopes for all scopes
- provide a mechanism to iterate over nested scopes
- permit recursive printing of scopes
TODO: more tests
R=adonovan
CC=golang-dev
https://golang.org/cl/10748044
Tested implictly since its simply calling the
internal isAssignableTo which is used in every
assignment when testing the std library.
R=adonovan
CC=golang-dev
https://golang.org/cl/11189043
Yields a ~20% improvement in SSA construction time.
Also: better names for promotion wrapper functions.
R=gri
CC=golang-dev
https://golang.org/cl/11050043
go/types.Type has an equivalence relation (IsIdentical) that
is not consistent with the equivalence relation implemented by
Go's == operator for Types. Therefore extra work is required
to build a map whose keys are types. This package does that
work.
Has simple unit test. More tests might be good.
R=gri
CC=golang-dev
https://golang.org/cl/9649044
- consolited remainign assignment check routines
- removed more dead code
- fixed incorrect scope hierarchy in case of errors for some statements
- fixed scope of key iteration variable for range clauses
R=adonovan
CC=golang-dev
https://golang.org/cl/10694044
Various bug fixes:
- don't allow := to redeclare non-variables
- don't permit a comma-ok expression as a two-value function return
Lots of dead code removed.
Fixesgolang/go#5500.
R=adonovan
CC=golang-dev
https://golang.org/cl/10792044
Instead of passing around iota everywhere, keep track of the
current value in the checker, and update it when entering
different declarations. This is less explicit, but the improvement
over all code is so significant that it is worth it.
R=adonovan
CC=golang-dev
https://golang.org/cl/10814044
- moved ident and typ expr checking into typexpr.go
- as a result, fewer parameters are needed for expr checking
- forward-chain type decls of the form type ( A B; B C; C *A) etc.
so that cycles are getting the right types in all cases
- fixed several corner case bugs, added more test cases
R=adonovan
CC=golang-dev
https://golang.org/cl/10773043
Fixed one aspect of issue 5090. Fixing it completely
requires a bit more work around the representation of
interface types.
R=adonovan
CC=golang-dev
https://golang.org/cl/10678045
Removed special case for testdata/test.go file in favor of
a simpler, more flexible, and explicit flag for one-off test
packages.
R=adonovan
CC=golang-dev
https://golang.org/cl/10618044
- LookupFieldOrMethod now computes if any indirection was found on the
way to an embedded field/method: this is the only information required
to determine if a result method is in the method set.
- Scopes now provide a link to the ast.Node responsible for them.
Also:
- don't permit unsafe.Offsetof on method values
- report ambiguities in field/method lookup errors
- added some missing checks for anonymous fields
- lots of new tests
Fixesgolang/go#5499.
R=adonovan
CC=golang-dev
https://golang.org/cl/10411045
- much simpler lookup
- more result information
- will make tracking of pointer-ness easier
TODO: apply the same changes to method set computation
R=adonovan
CC=golang-dev
https://golang.org/cl/10379049
- moved single field and method lookup functionality
from operand.go to new file lookup.go and cleaned
up the lookup implementation
- implemented method set computation using the same
basic structure as for field/method lookup, in new
file methodset.go
- minor related changes
- the method set computation ignores pointer-ness of
the receiver type at the moment (next CL)
- fixed a couple of bugs (missing pkg info for imported
embedded types, wrong test for method expressions)
The method set computation is currently verified by
comparing a regular method lookup with a method-set
based method lookup.
R=adonovan
CC=golang-dev
https://golang.org/cl/10235049
methodIndex() utility was split and specialized to its two
cases, *Interface vs *Named, which are logically quite
different.
We can't memoize promotion wrappers yet; we need typemap.
Terminology:
- "thunks" are now "wrappers"
- "bridge methods" are now "promotion wrappers"
Where the diff is messy it's just because of indentation.
R=gri
CC=golang-dev
https://golang.org/cl/10282043
This partially reverts a previous change, using a []*Field is a better
representation for struct fields than a *Scope, after all; however
*Fields remain Objects.
Fixesgolang/go#5670.
R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/10207043
- Imported objects that are explicitly exported may have a nil package;
don't use it for qualified name computation (it's not needed).
- isAssignable must check all possibilities before declaring failure.
Fixesgolang/go#5675.
R=adonovan
CC=golang-dev
https://golang.org/cl/10141044
PLEASE NOTE: the APIs for both "importer" and "ssa" packages
will continue to evolve and both need some polishing; the key
thing is that this CL splits them.
The go.types/importer package contains contains the Importer,
which takes care of the mechanics of loading a set of packages
and type-checking them. It exposes for each package a
PackageInfo containing:
- the package's ASTs (i.e. the input to the typechecker)
- the types.Package object
- the memoization of the typechecker callbacks for identifier
resolution, constant folding and expression type inference.
Method-set computation (and hence bridge-method creation) is
now moved to after creation of all packages: since they are no
longer created in topological order, we can't guarantee the
needed delegate methods exist yet.
ssa.Package no longer has public TypeOf, ObjectOf, ValueOf methods.
The private counterparts are valid only during the build phase.
Also:
- added to go/types an informative error (not crash) for an
importer() returning nil without error.
- removed Package.Name(), barely needed.
- changed Package.String() slightly.
- flag what looks like a bug in makeBridgeMethod. Will follow up.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9898043
- First step towards unified use of scopes. Will enable
further simplifications.
- Removed various ForEach iterators in favor of the existing
accessor methods, for a thinner API.
- Renamed outer/Outer to parent/Parent for scopes.
- Removed check.lookup in favor of Scope.LookupParent.
R=adonovan
CC=golang-dev
https://golang.org/cl/9862044
Also:
- more cleanup of new identifier resolution code
- removed residue Object.Pos() code
- two separate, equally formatted error messages for redeclaration
errors for easier tool support
- initial support for labels
- enabled several disabled tests
Thic CL will break go.tools/ssa/interp, but the pending
CL 9863045 fixes that.
Fixesgolang/go#5504.
R=adonovan
CC=golang-dev
https://golang.org/cl/9839045
By setting resolve = true in check.go, the type checker
will do all identifier resolution during type checking
time and ignore (and not depend on) parser objects. This
permits the type checker to run easily on ASTs that are
not generated with invariants guaranteed by the parser.
There is a lot of new code; much of it slightly modified
copies of old code. There is also a lot of duplication.
After removing the dead code resulting from resolve = true
permanently (and removing the flag as well), it will be
easier to perform a thorough cleanup. As is, there are
too many intertwined code paths.
For now resolve = false. To be enabled in a successor CL.
R=adonovan
CC=golang-dev
https://golang.org/cl/9606045
They will be deleted from their current homes once this has landed.
Changes made to import paths to make the code compile, and to find
errchk in the right place in cmd/vet's Makefile.
TODO in a later CL: tidy up vet.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9495043