- 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
Before:
math/big/nat_test.go:688: arg r for printf verb %s of wrong type: ..Word
After:
math/big/nat_test.go:688: arg r for printf verb %s of wrong type: big.Word
R=gri
CC=golang-dev
https://golang.org/cl/10400044
A trailing % resulted in a bad error message.
Also clean up a couple of dregs left over from the
refactoring to add indexed formats.
R=dsymonds
CC=golang-dev
https://golang.org/cl/10336044
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 number will allow us to give a conventional meaning to "coverage":
the percentage of executable statements visited by the test.
R=adonovan
CC=golang-dev
https://golang.org/cl/10271045
We are going to need one more piece of data, so rather than create
a third variable let's just put it all in one struct. The interface gets
easier too.
R=adonovan
CC=golang-dev
https://golang.org/cl/10271044
Method sets:
- Simplify CallCommon.
Avoid the implicit copy when calling a T method on a *T
receiver. This simplifies clients. Instead we generate
"indirection wrapper" functions that do this (like gc does).
New invariant:
m's receiver type is exactly T for all m in MethodSet(T)
- MakeInterface no longer holds the concrete type's MethodSet.
We can defer its computation this way.
- ssa.Type now just wraps a types.TypeName object.
MethodSets are computed as needed, not eagerly.
Position info:
- new CanonicalPos utility maps ast.Expr to canonical
token.Pos, as returned by {Instruction,Value}.Pos() methods.
- Don't set posn for implicit operations (e.g. varargs array alloc)
- Set position info for ChangeInterface and Slice instructions.
Cosmetic:
- add Member.Token() method
- simplify isPointer
- Omit words "interface", "slice" when printing MakeInterface,
MakeSlice; the type is enough.
- Comments on PathEnclosingInterval.
- Remove Function.FullName() where implicit String() suffices.
Also:
- Exposed NewLiteral to clients.
- Added ssa.Instruction.Parent() *Function
Added ssa.BasicBlock.Parent() *Function.
Added Sanity checks for above.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/10166045
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
This is just the tool proper; stitching into "go test" will be a separate CL.
Tests are missing - they'll come once it's integrated - but it can handle,
perhaps correctly, all of src/pkg/...
The basic approach is to rewrite the source to add annotations that will
track coverage; the rewritten source must of course be compiled and
run after this tool has done its job.
R=adonovan
CC=golang-dev
https://golang.org/cl/10102043
Details:
- builder is now un-exported and is now a per-package entity.
- Package.nTo1Vars is now part of builder, where it belongs.
- CREATE phase code split out into its own file, create.go
- Context type is gone; it had become trivial after the
Importer refactoring.
- importer.PackageInfo.Imports() now encapsulates iteration
over imports.
Typical usage is now:
prog := ssa.NewProgram(imp.Fset, mode)
prog.CreatePackages(imp)
prog.BuildAll()
Builder.BuildPackage(Package) is now Package.Build()
Builder.BuildAllPackages() is now Program.BuildAll()
R=iant, gri
CC=golang-dev
https://golang.org/cl/9970044
A Builder is now just a Program and a Context.
Details of this CL:
- Builder.imp field removed.
- Builder.globals split up into Package.values and Prog.Builtins.
- Builder.packages moved to Prog.packages.
- Builder.PackageFor moved to Program.Package(types.Object)
- Program.Lookup() func replaces Builder.globals map.
- also: keep Package.info field around until end of BuildPackage.
Planned follow-ups to eliminate Builder from API:
- split NewBuilder up into NewProgram and Program.CreatePackages(...)
- move Builder.BuildAllPackages -> Program.BuildAll(Context)
- move Builder.BuildPackage -> Package.Build(Context)
R=gri, iant
CC=golang-dev
https://golang.org/cl/9966044
The method index was hard-coded to zero, which works some of
the time. Apparently I just forgot to implement the
method-table lookup...
Added regression test.
R=gri
CC=golang-dev
https://golang.org/cl/9916043
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
Rewrite the checker to be more flexible and better documented, being
more explicit about parsed format vs. checked arguments.
No attempt yet to do check indexed formats; this just paves the way.
All tests still pass.
R=gri
CC=golang-dev
https://golang.org/cl/9881044
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
Implement Pos() method for
Values: Parameter, Capture, Phi. (Not Literal, Builtin.)
Instructions: UnOp, BinOp, Store.
'address' (an lvalue) now needs position of '*' in "*addr".
Also:
- Un-export fields Pos_ Type_ Name_ Block_ from various values/instructions.
Define NewFunction() as a temporary measure.
Will try to eliminate calls from clients...
- Remove Implements{Value,Member,Interface} marker methods.
I've decided I don't like them.
- Func.addParamObj helper.
- Various comment fixes.
R=gri
CC=golang-dev
https://golang.org/cl/9740046
Can't reproduce the failure outside the builder, but attempt a fix
by changing the criterion for failure: FAIL iff the output contains "BUG".
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/9798050
Simplify the code a bit, get it working after recent go/types changes,
and handle "%*%" just in case. Preparation for handling argument indexing.
R=gri
CC=golang-dev
https://golang.org/cl/9747045
PathEnclosingInterval: maps a source position to an ast.Node.
EnclosingFunction: finds ssa.Function enclosing an ast.Node.
HasEnclosingFunction: cheaper impl of EnclosingFunction()!=nil
NodeDescription: user friendly node type descriptions.
+ tests.
Also: make ssa.Package.TypeInfo field a pointer.
R=gri, r
CC=golang-dev
https://golang.org/cl/9639045
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
Extracted Builder.findMethod function to handle
methodset/receiver logic common to
function calls (Builder.setCall) and
bound method closure creation (Builder.selector).
Capture: added explicit Name, Type fields to Capture instead
of relying on Outer field, which is now un-exported since its
only purpose is to let Builder.expr(case *ast.FuncLit) know
which values to put in the closure; it is nilled immediately
after.
Simplified Function.lookup() logic: there's no need to walk
the Outer chain each time to set Alloc.Heap=true, as it's
already set during creation of the outermost
Capture{outer:*Alloc}.
Added interp/testdata/boundmeth.go test.
Cosmetic changes:
- add support for bound method thunks to Function.FullName().
- Simplified {Literal,Global,Builtin,Function}.String()
- doc: Captures are no longer necessarily addresses.
- added yet another missing pair of "()" (go/types accessors).
- print "Synthetic" not "Declared at -" for synthetic functions.
- use '$' not center-dot in synthetic identifiers (easier to type).
R=gri
CC=golang-dev
https://golang.org/cl/9654043
- remove Makefile
- move test data into a subdirectory
- encapsulate the invocation of errchk into a standard Test using os.exec
R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/9509045