1
0
mirror of https://github.com/golang/go synced 2024-10-01 16:38:34 -06:00
Commit Graph

124 Commits

Author SHA1 Message Date
Alan Donovan
c24b2413c0 go.tools/ssa: use go/types.LookupFieldOrMethod, and simplify.
Added tests.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/10830043
2013-07-01 15:17:36 -04:00
Alan Donovan
86b0a65b65 go.tools/ssa: emit ChangeType when using method as function in f := T.meth.
Previously: typeOf(f).Signature.Recv == T
       Now: typeOf(f).Signature.Params.At(0) == T

Added test.

BUG=5781

R=gri
CC=golang-dev
https://golang.org/cl/10622043
2013-06-26 13:18:31 -04:00
Alan Donovan
b68a029040 go.tools/ssa: un-export Function.FullName. Use String.
R=gri
CC=golang-dev
https://golang.org/cl/10604044
2013-06-26 12:38:08 -04:00
Alan Donovan
8097dad724 go.tools/ssa: Select now returns received values by tuple, not interface.
Before, all values received on some channel by Select would
flow to an empty interface, creating a spurious confluence for
flow analyses.  Now, the tuple returned by Select has one
component for each 'receive' case.

Also, fixes:
- Removed workarounds for now-fixed typechecker bug in FuncLit+TypeAssert.
- sanity check that all Value Instructions have non-nil Type().
- Convert: document and sanity-check that at least one of the types is basic.

Also, other things to help clients:
- Define CallInstruction interface: common parts of Call, Go, Defer.
- Add CallCommon.Signature() method.
- Literal.Pos() is now populated.

R=gri
CC=golang-dev
https://golang.org/cl/10505043
2013-06-24 14:15:13 -04:00
Alan Donovan
f1d4d01fed go.tools/ssa: memoize synthesis of all wrapper methods.
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
2013-06-14 15:50:37 -04:00
Alan Donovan
0f26bbae8f go.tools/ssa: fix bug in code emitted for ast.TypeAssertExpr.
var x I = ...
x.(E) may fail dynamically (iff x is nil).

Added a testcase.

R=gri
CC=golang-dev
https://golang.org/cl/10237045
2013-06-13 17:31:32 -04:00
Alan Donovan
341a07a3aa go.tools/ssa: small changes accumulated during gri's vacation. :)
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
2013-06-13 14:43:35 -04:00
Robert Griesemer
221795b447 go.tools/go/types: Factories for all objects
R=adonovan
CC=golang-dev
https://golang.org/cl/9794044
2013-06-04 15:15:41 -04:00
Alan Donovan
fc4c97d1f1 go.tools/ssa: refactoring: eliminate Builder from API.
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
2013-06-03 16:46:57 -04:00
Alan Donovan
4d628a0312 go.tools/ssa: refactoring to make Builder stateless.
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
2013-06-03 14:15:19 -04:00
Alan Donovan
1f2812fe9b go.tools/ssa: fix bug in makeBridgeMethod for promoted interfaces.
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
2013-05-31 16:36:03 -04:00
Alan Donovan
be28dbb86f go.types/ssa: split the load/parse/typecheck logic off into a separate package.
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
2013-05-31 16:14:13 -04:00
Robert Griesemer
3cad037e2f go.tools/go/types: replace ObjSet with improved Scope
- 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
2013-05-30 21:58:14 -07:00
Alan Donovan
18f85da60d go.tools/ssa: fix breakage caused by CL 9839045 to go/types.
This removes the ast.CaseClase hack for implicit variables.

R=gri
CC=golang-dev
https://golang.org/cl/9863045
2013-05-30 13:18:07 -04:00
Alan Donovan
4e0d6858c8 go.types/ssa: inline all calls to objKind().
R=gri
CC=golang-dev
https://golang.org/cl/9740052
2013-05-30 12:13:42 -04:00
Alan Donovan
6c7ce1c2d3 go.tools/ssa: Value.Pos() method + remaining source position plumbing.
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
2013-05-30 09:59:17 -04:00
Alan Donovan
20029fe5f7 go.tools/ssa: utility functions mapping source intervals to ast.Nodes.
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
2013-05-28 15:28:46 -04:00
Robert Griesemer
98bcbfbab7 go.tools/ssa: print identifer location if not found in TypeInfo
R=adonovan, r
CC=golang-dev
https://golang.org/cl/9703044
2013-05-25 10:04:20 -07:00
Robert Griesemer
7a48931508 go.tools/ssa: fix debug printing
R=adonovan, r
CC=golang-dev
https://golang.org/cl/9774043
2013-05-25 09:51:29 -07:00
Alan Donovan
8cdf1f1cb1 go.tools/ssa: add support for bound-method closures.
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
2013-05-22 17:56:18 -04:00
Alan Donovan
113d6d30b1 code.google.com/p/go.tools/ssa: include ssa.Package and init() function in example output.
Also:
- remove redundant text in doc.go.
- fix (yet more) cases of missing parens in Printf, fallout from
  go/types accessors refactoring.
- don't mix spaces and tabs within lines printed by ssa.Function.DumpTo:
  it makes it too hard to constructed expected outputs for tests.
  (Tabs may appear at line start though.)

Sadly godoc -play won't run this program; it complains it
can't import "code.google.com/p/go.exp/ssa".  Any idea why?

R=gri
CC=golang-dev
https://golang.org/cl/9481044
2013-05-17 17:33:09 -04:00
Rob Pike
87334f402b go.tools: bring up to date
Repo was copied from old point.  Bad r.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9504043
2013-05-17 14:02:47 -07:00
Rob Pike
83f21b9226 go.tools: add missing files ssa/*.go
R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9500043
2013-05-17 13:25:48 -07:00
Rob Pike
01f8cd246d go.tools: add go/types, ssa, and cmd/vet
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
2013-05-17 13:20:39 -07:00