(Motivation: "Literal" is a syntactic property, not a semantic one.)
Also: delete a "TODO: opt" that the lifting pass already does for us.
R=gri
CC=golang-dev
https://golang.org/cl/11351043
- 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
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
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
This exposed a bug: we weren't creating Functions for methods
of imported named types.
Also:
- simplification: 'candidate' no longer contains 'concrete *Function'.
We look this up on demand.
NB: this CL contains a copy of CL 10935047 (use of typemap);
will submit/sync/resolve soon.
R=gri
CC=golang-dev
https://golang.org/cl/11051043
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
Details:
- reintroduce interp.asUint64: it's not sound to use only the
low 32 bits of y, which is what asInt gives us, when GOARCH=386.
- instead, emit a uint64 conversion when y is not unsigned
(i.e. a signed var, or an untyped constant).
Tested on 386 & x86-64.
R=gri
CC=golang-dev
https://golang.org/cl/11023043
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
We use the new field to determine whether or not a function is
synthetic, not Pos() == 0, so synthetic functions can have
positions too.
R=gri
CC=golang-dev
https://golang.org/cl/10916044
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
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
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
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
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
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
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
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
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