- use import path not file path in go/buildutil.FakeContext OpenFile;
- use regexp to compare error messages in TestErrors, because
they contain windows file paths;
- use OS file path (not unix path), when checking move results
in TestMoves.
Change-Id: Ib62d344acb551fb612d8a0773ae1ab5f18341294
Reviewed-on: https://go-review.googlesource.com/3171
Reviewed-by: Alan Donovan <adonovan@google.com>
And log its value in godoc -analysis.
Related to issue 8968
Change-Id: I96a96922a3fa5c434c69e0faff1cc8ec4686b6f2
Reviewed-on: https://go-review.googlesource.com/3154
Reviewed-by: Robert Griesemer <gri@golang.org>
Details:
- rename (*Program).TypesWithMethodSets() to RuntimeTypes()
- delete (*Package).TypesWithMethodSets() method and simplify
- move code to methods.go
- update test to use
1-2% improvement in space and time (though I barely trust this data
because the GC at tip is in such terrible state).
Change-Id: I38eab78b11e0ad0ff16e0530e775b6ff6a2ab246
Reviewed-on: https://go-review.googlesource.com/3148
Reviewed-by: Robert Griesemer <gri@golang.org>
...to avoid namespace conflicts.
Also make its name "main", since it defines func main().
And fix 2 typos.
Change-Id: I7cf7894d6bed134907b3d2742255e5a82426071b
Reviewed-on: https://go-review.googlesource.com/3150
Reviewed-by: Robert Griesemer <gri@golang.org>
This refactoring of the tests of go/loader and refactor/rename made it
possible to write some loader tests I wanted, but the new tests reveal
bugs so they're commented out for now. I will fix them in a follow-up.
Change-Id: Iae3a20681a0a0791076debd4b82bb5ed74b0c577
Reviewed-on: https://go-review.googlesource.com/2825
Reviewed-by: Robert Griesemer <gri@golang.org>
See loader.go comments for orientation.
This is what happens when you use start using Dmitry's new trace tool. :)
Tests:
- added test of cycles
- load/parse/typecheck of 'godoc' is ~2.5x faster
- race detector finds no errors.
Change-Id: Icb5712c7825002342baf471b216252cecd9149d6
Reviewed-on: https://go-review.googlesource.com/1582
Reviewed-by: Robert Griesemer <gri@golang.org>
PackageCreated is a hook called when a types.Package
is created but before it has been populated.
The package's import Path() and Scope() are defined,
but not its Name() since no package declaration has
been seen yet.
Clients may use this to insert synthetic items into
the package scope, for example.
Change-Id: I210a0c4c766f03f715f03f26d5cd765f15f56e04
Reviewed-on: https://go-review.googlesource.com/2138
Reviewed-by: Alan Donovan <adonovan@google.com>
Classic Go pitfall: "defer" in a loop does not do what you might expect.
+ test case
Fixes issue 9570
Fixes issue 9569
Change-Id: Iec05420872ef71190083a7192f76c92f54f4a2a1
Reviewed-on: https://go-review.googlesource.com/2655
Reviewed-by: Robert Griesemer <gri@golang.org>
The parser was assuming it would find <body> or </head>.
If the entire response is just <meta> tags, it finds EOF and
treats that as an error. It's not.
This is the same change as in https://golang.org/cl/68520044.
Fixes#9556.
Change-Id: If51ed36e7364c15788311039caf8323eb5fe9a6c
Reviewed-on: https://go-review.googlesource.com/2650
Reviewed-by: Minux Ma <minux@golang.org>
Also: Better position for error messages related to wrong use of ... .
Fixes#9473.
Change-Id: I90565f51a42897b7292f651a84a23611a5d8f359
Reviewed-on: https://go-review.googlesource.com/2390
Reviewed-by: Alan Donovan <adonovan@google.com>
It is sometimes useful for API clients to be able to disable the unused
import check, although for good reason this should not be exposed as part of
a user-facing interface. There are at least two use cases that I am aware of:
1) It allows for automated test case reduction tools such as delta or C-Reduce
to be more easily applied to type checker input. Disabling the check
makes it possible for the tool to identify and remove code that depends
on imported packages without any specific knowledge of Go, as the import
need not be removed simultaneously with the code.
2) Interactive tools (such as REPLs) that may have previously received a
list of imports and subsequently receive a line of code that may use any
number of these imports. It is simpler for such tools to import all the
packages in its list than to try to identify the correct set of imports.
Change-Id: I00091a4e5c8e1bd664efd82a636f255eaaa5a2db
Reviewed-on: https://go-review.googlesource.com/2136
Reviewed-by: Robert Griesemer <gri@golang.org>
The new interface makes the functions more useful by allowing clients to
check the various properties that TypeAndValue provides.
Change-Id: I8b41a27316081bea24a18ffe6fa1812e809d6f67
Reviewed-on: https://go-review.googlesource.com/2134
Reviewed-by: Robert Griesemer <gri@golang.org>
+ Tests:
Extend function name uniqueness check to exported wrappers.
Check that expected synthetic functions are created, reachable, and not duplicated.
Change-Id: I0e87ebb2712e33e1f49da3fa9a9dde0085bf3850
Reviewed-on: https://go-review.googlesource.com/2013
Reviewed-by: Robert Griesemer <gri@golang.org>
+ test
Change-Id: Ie37835577ffcdd764cf6a0b611e02f04386755cf
Reviewed-on: https://go-review.googlesource.com/1580
Reviewed-by: Robert Griesemer <gri@golang.org>
...like we do for "runtime" functions, so that they fail informatively
if executed. They all need intrinsics, but only some are yet defined.
Also:
- added test for issue 9462
- "BUG" in test output is now a failure in all tests (not just $GOROOT tests)
- added intrinsic for reflect.SliceOf
- show dynamic type of panic value
Fixes issue 9462
Change-Id: I3a504c7faeed81e922fedc7dd59222717f3a7e95
Reviewed-on: https://go-review.googlesource.com/2145
Reviewed-by: Robert Griesemer <gri@golang.org>
Fixes various problems reported by go vet.
Change-Id: I12a6fdba8f911b21805d8e42903f8f6a5033790a
Reviewed-on: https://go-review.googlesource.com/2163
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
"static" ignores dynamic calls altogether.
"cha" uses Class Hierarchy Analysis, which assumes that a
dynamic call may dispatch to any func or method that satisfies
the type.
Both these algorithms can work on partial programs,
e.g. libraries without a main function or tests.
(This feature was requested after my talk last night.)
+ Tests.
LGTM=sameer
R=sameer, minux
CC=golang-codereviews, gri
https://golang.org/cl/176780043
Also use type assertions in a more defensive
way (check for != nil rather than ok).
LGTM=dsymonds, adonovan
R=adonovan, dsymonds
CC=golang-codereviews
https://golang.org/cl/169480043
This is an algorithm for callgraph construction that is faster
but much less precise than pointer analysis.
(I evaluated this for the Go Oracle last year but shelved it,
but it's a natural fit for the work Brian is doing on
automatic program minimization.)
LGTM=sameer
R=gri, crawshaw, sameer
CC=bwkster, golang-codereviews
https://golang.org/cl/124690043
Rewrite performed with this command:
sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \
$(grep -lr 'code.google.com/p/go.' *)
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/170920043
See regression test for explanation.
I audited the code for similar issues and found none.
Many thanks to Daniel Morsing for providing a small
reproducible test case, a rarity for PTA bugs!
Fixesgolang/go#9002
LGTM=crawshaw
R=crawshaw
CC=daniel.morsing, golang-codereviews
https://golang.org/cl/163350043
Also removes a potential race condition regarding the
used flag of Var objects when type-checking packages
concurrently.
Implementation: Rather than marking all used dot-imported
objects and then deduce which corresponding package was used,
now we consider all dot-imported packages as unused and remove
each package from the unused packages map as objects are used.
Now only objects that can be marked as used have a used field
(variables, labels, and packages).
As a result, the code became cleaner and simpler.
Fixesgolang/go#8969.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/163740043
The previous logic would descend into (e.g.) .git repositories
and vendored packages with "_"-prefixed names.
Fixesgolang/go#8907
LGTM=gri
R=gri
CC=golang-codereviews, shurcool
https://golang.org/cl/157800043
The type-checker depended on (token.Pos) position information of
the presented files to determine source order. That information
is determined by the parse order of the files rather than the
order in which the files are presented to the type-checker.
Introduced an order number strictly determined by the file
order as presented to the type-checker and the AST structure
of each file; thus providing source order information even in
the absence of (token.Pos) position information.
Added test case (provided by adonovan).
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/151160043
- ParseFile (core of go/loader's parseFiles(); also used by refactor/rename)
- ContainingPackage (core of Oracle's guessImportPath; also used by refactor/rename)
- Accessors for effective "methods" of build.Context:
FileExists, OpenFile, IsAbsPath, JoinPath.
LGTM=sameer
R=dave, sameer
CC=golang-codereviews, gri
https://golang.org/cl/146120043
The needMethods cache logic was wrong: it would treat any
previous call as a cache hit, even if 'skip' was true for that
call. As a result it could fail to generate methods for some
'skip' types, i.e. anonymous structs.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/144750043
This CL is the first refactoring automated by "gorename". :)
Though I had to update the comments and run 'hg gofmt'. :(
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/142930043
It now has a main() function, which was confusing the logic to find the entry point.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/142860044
This function has been copied at least 6 times throughout
go.tools. This implementation is superior since it does
all I/O through the virtualized go/build file system, and it
is highly parallel (and much faster).
We expose two flavours, simple (for existing tests) and
parallel (for high-performance tools such as gorename).
This CL creates the go/buildutil package, which is intended for
utilities related to go/build.
+ test.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/137430043
- for unused packages where base(package path) != package name
- for conflicts between imported packages or dot-imported objects
and local declarations
Per suggestions from adonovan, inspired by the gc error messages.
LGTM=adonovan
R=adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/135550043
(godoc is excluded from this CL since it will continue to use
/src/pkg in its URL namespace, making the necessary cleanup
more subtle.)
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141770043
Recent changes in the runtime caused the interpreter to call 'getg',
and it should never have gotten that far.
Also, delete bodies of "runtime" functions, since they're too magical.
This makes missing intrinsics cause very obvious failures.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/135330043
It returns the value formerly returned by Pkg(), i.e. the imported package.
Pkg() now returns the package enclosing the import statement,
which is consistent with all other Objects.
Fixesgolang/go#8628.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/136090043
Also: Added Config.Strict flag to enable type checker tests
beyond the Go 1 specification.
Fixesgolang/go#8561.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/134050043
LookupFieldOrMethod now also decides whether a found
method is actually in the method set. Simplifies call
sites. Added corresponding API tests.
TODO (separate CL): Decide what the correct value for
the indirect result should be (as required for code
generation). For now, the result value for indirect
is unchanged from before if a field/method is found.
Fixesgolang/go#8584.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/132260043
(1) support Example functions defined in programs that don't
import "testing". We emit code to testmain.main() to call
them directly, since we can't call testing.Main.
(2) expose a FindTests function which reports the set of
Test, Example and Benchmark functions it finds.
Certain clients need this.
Added test for logic in FindTests.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/115290048
Previously these were recorded in the PackageInfo, but not
reported to the user's error handler (types.Config.Error),
which is typically what prints them.
Minor subtlety: that function must now be able to handle error
values that are not of type types.Error.
+ Test (and renamed it).
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/121290043
- Break out parts of coverage.go into more specific files.
- Re-enable test of nil interface-to-interface conversion.
- Update initorder test to reflect spec ambiguity and gc vs go/types variance.
- Re-enable test dependent on now-fixed bug 8189 ("value,ok" yields an untyped bool)
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/119530043
And serialize the printing of each item with a mutex.
It is the formatted output of this tool, after all.
Also: minor doc tweaks.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/114620044
Examples:
- "foo$1" becomes "pkg.foo$1"
- "init$1" (meaning the first declared "init" function) becomes "init#1",
to distinguish it from "init$1" (meaning the first anonymous function
within the synthetic "init" function that initializes package-level vars).
It is now an invariant that all source-level (non-synthetic)
functions have distinct names, and that all names include the
enclosing package. Added test for this.
+ updated various clients.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/122750043
It was missing from the four conversions and the Make* instructions.
(Experiments with pure bytes.Buffer-based printing were not faster; various TODOs removed.)
LGTM=crawshaw
R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/58040043
This transforms the virtualized directory (build.Context).Dir to a physical one,
for proprietary build systems that distinguish them.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/116230043
Users need only add an extra file to the package to specify
additional imports and initialization steps in testmain, to
match their build system.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/120090043
Without it, no value appears to be sent on NewTicker/NewTimer channels.
+ test
Also:
- add (callgraph.Edge).{Description,Pos} convenience methods
to simplify client code when Site==nil.
LGTM=gri
R=gri, friestein68503
CC=golang-codereviews
https://golang.org/cl/112610043
If an expression is addressable, we compute its address then load, rather than
extracting the value of subelements. For aggregates this avoids large copies.
Example:
var x [2]struct{y [3]int}
print(x[1].y[2])
Was:
t0 = local [3]struct{x [5]int} (x) *[3]struct{x [5]int}
t1 = *t0 [3]struct{x [5]int}
t2 = t1[1:int] struct{x [5]int}
t3 = t2.x [#0] [5]int
t4 = t3[2:int] int
Now:
t1 = &t0[1:int] *struct{x [5]int}
t2 = &t1.x [#0] *[5]int
t3 = &t2[2:int] *int
t4 = *t3 int
Also:
- make emitFieldSelections responsible for calling emitDebugRef, as
one of its two calls was forgetting to do it.
- relax the specification of (*Program).VarValue because not all
subexpressions are materalized as values now.
- fix up the objlookup.go test expectations to match.
go/ssa/interp test runs 10% faster.
Thanks to Peter Collingbourne for pointing this out.
LGTM=pcc
R=pcc, gri
CC=golang-codereviews
https://golang.org/cl/109710043
PackageInfo:
- deleted IsType
- inlined + deleted: ValueOf, TypeCaseVar, ImportSpecPkg
- on failure, TypeOf accessor now returns nil (was: panic)
go/ssa: avoid extra map lookups by using Uses or Defs directly when safe to do so,
and keeping the TypeAndValue around in expr0().
LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/107650043
The InitOrder needs to be reset.
+ Test.
This bug manifested itself in duplicate HTML in the godoc -analysis view,
e.g. "f((x)" or "funcfunc f()"
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/107660044
This extends the sanity checker to identify and report referrers
which do not appear in the function's instruction lists, and fixes two
bugs in the lifting algorithm which were caught by the sanity check.
LGTM=adonovan
R=adonovan
CC=axwalk, golang-codereviews
https://golang.org/cl/110210045
We introduce a method (*Interface).Complete(), which is intended
to be called from clients after all embedded interfaces have been
fully defined. For importers, this will definitely be the case
after the import has finished, so each importer have been updated
to do so, with the exception of the gcimporter, which does not use
embedded interfaces, therefore Complete() can be called immediately
after construction.
Building the method set separately from the constructor type caused
some problems with go/importer, which copies the types.Interface
object, leading to there existing two almost-identical interface
types referenced from interface method receivers, only one of which
has been completed. To avoid this situation, the importer has been
modified to construct the interface object only once.
Fixesgolang/go#8177.
LGTM=gri
R=gri, dave, gordon.klaus, adonovan
CC=golang-codereviews
https://golang.org/cl/105060044
This method was deemed unfit for the API. See the original CL for discussion.
««« original CL description
go.tools/go/loader: Add Program.FilePath convenience method for getting the full path of a source file.
LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/107160049
»»»
LGTM=gri
R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/107570043
This builtin is a little weird in this form as it is (to my knowledge)
the only function that takes a variadic argument of non-slice
type. The language provides no syntax to express this, so we pick
a stringification for such arguments that does not appear in the
language. Specifically, use T... instead of ...T to distinguish it
from the normal case where the type is a slice.
This change lets the go/ssa package produce more efficient IR by
avoiding an extra conversion of the second argument.
LGTM=gri
R=gri
CC=adonovan, golang-codereviews
https://golang.org/cl/108230044
+ regression test.
Fixesgolang/go#8172
Also: return error (not panic) when called with empty input.
LGTM=gri
R=crawshaw, gri
CC=golang-codereviews, jon
https://golang.org/cl/104270043
Clients such as compilers need this information in order
to correctly link against imported packages.
This also adds support for the condensed import data format
where the priority information is stored as a suffix of the
condensed import data, as well as support for archive files.
LGTM=gri
R=gri
CC=golang-codereviews, iant
https://golang.org/cl/78740043
Bare init functions omit calls to dependent init functions and the
use of an init guard. They are useful in cases where the client uses
a different calling convention for init functions, or cases where
it is easier for a client to analyze bare init functions.
LGTM=adonovan
R=adonovan
CC=golang-codereviews, iant
https://golang.org/cl/78780043
This reduces solver time by about 40%.
See hvn.go for detailed description.
Also in this CL:
- Update package docs.
- Added various global opt/debug options for maintainer convenience.
- Added logging of phase timing.
- Added stdlib_test, disabled by default, that runs the analysis
on all tests in $GOROOT.
- include types when dumping solution
LGTM=crawshaw
R=crawshaw, dannyb
CC=golang-codereviews
https://golang.org/cl/96650048
New invariant: all user-defined objects have an associated package.
Added a check of this invariant to stdlib_test.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/104170043
Previously, statements such as:
type T struct { a, b int }
[...]
x = T{}
x = T{b: 1}
would only affect the aggregate members mentioned in the composite
literal and leave the other members unchanged. This change causes us
to write a zero value to the target in cases where the target is not
already known to hold a zero value and the number of initializers in
the composite literal differs from the number of elements in its type.
Author: Peter Collingbourne. (hg clpatch got confused)
LGTM=pcc
R=pcc
CC=golang-codereviews
https://golang.org/cl/107980045
Godoc depends on this package.
Packages that use unsafe cannot be deployed to App Engine.
Packages that use reflect can.
This package needn't use unsafe, so don't.
LGTM=adonovan, rsc
R=rsc, adonovan
CC=golang-codereviews
https://golang.org/cl/105960043
Also, define ssa:wrapnilchk intrinsic to check and gracefully
fail when a T method is dynamically invoked via a nil *T receiver.
+ Test.
A follow-up CL will add another intrinsic, ssa:memclr.
+ minor cleanups.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/101170044
It is easier for clients to recover from panics if the recover block
is always present. Otherwise, the client has to work around the lack
of a recover block by synthesizing a zero value return.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/87210044
Before, Load() would just fail. Now, it gathers all frontend
errors (not just the first go/types error) in PackageInfo.Errors.
There are still cases where Load() can fail hard, e.g. errors in x_test.go
files. That case is trickier to fix and remains a TODO item.
Also, make godoc display all scanner/parser/type errors in the source view.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/108940043
Blocks dominated by "if false" should be retained in the
initial SSA form so they remain visible to subsequent source
code analysis tools.
In any case, true compilers already need a stronger version of
this optimization so they can simplify CFGs such as this:
const x, y = ...
switch x {case y:...}
where a branch is constant but the comparison of constants
does not occur within an expression.
LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/101250043
The SSA builder shouldn't be in the business of
interprocedural optimization, especially in the presence of
concurrency.
This causes the instruction count to increase by 0.03%.
LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/105020045
It was making the unsound assumption that cgn==nil => v is one
of {Global,Function,Const,Capture} to avoid checking v's type,
which is what it now does. This caused more expensive
constraints to be generated, which is suboptimal though not
wrong exactly.
In one benchmark, this change reduces the number of complex
constraints by about 23% of loads and 53% of stores, and
increases the number of (simple) copy constraints by about 5%.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/106940043
Files that import "C" are not valid Go source files and
require preprocessing. Until now, the loader has simply
hard-coded CGO_ENABLED=0 (in effect) which causes go/build to
use build tags select pure Go implementations where they exist
(e.g. in $GOROOT). Where they don't (e.g. arbitrary user
code) this leads to masses of spurious type errors.
(Reported by Guillaume Charmes, private correspondence.)
This change causes the loader to invoke the cgo preprocessor
on such files and to load the preprocessed files instead,
using the original names. This means that the syntax offset
position information is garbage, although thanks to //line
directives, the line numbers at least should be good.
See comment in cgo.go for details.
This CL changes the loader's default behaviour and may make it slower.
CGO_ENABLED=0 enables the old behaviour.
Tested via stdlib_test, which now loads all standard packages
using cgo, and also exercises CGO_ENABLED=0 for "net" and "os/user".
LGTM=gri
R=gri, rsc
CC=golang-codereviews, guillaume.charmes
https://golang.org/cl/86140043
Also:
- extend Parent() to all Values and add to interface:
(Builtin/Const/Global => nil; Function => Enclosing)
- hide Function.Enclosing since it's now redundant wrt Parent()
- make (*Function).String robust for synthetics without pkg object
LGTM=gri
R=gri
CC=golang-codereviews, khr
https://golang.org/cl/87580044
This optimization reduces solve time (typically >90% of the
total) by about 78% when analysing real programs. It also
makes the solver 100% deterministic since all iterations are
ordered.
Also:
- remove unnecessary nodeid parameter to solve() method.
- don't add a fieldInfo for singleton tuples (cosmetic fix).
- inline+simplify "worklist" type.
- replace "constraintset" type by a slice.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/95240043
Until now, the same Function was used to represent a method
(T)func() and the "method expression" function func(T) formed
from it. So the SSA code for this:
var buf bytes.Buffer
f := Buffer.Bytes
f(buf)
buf.Bytes()
would involve an implicit cast (ChangeType) on line 2.
However, compilers based on go/ssa may want to use different
calling conventions for them, like gccgo does (see issue
7839). This change decouples them by using an anonymous
function called a "thunk", rather like this:
f := func(r *bytes.Buffer) []byte { return r.Bytes() }
Thunks are similar to method wrappers; both are created by
makeWrapper.
"Interface method wrappers" were a special case of thunks for
direct calls (no indirection/fields) of interface methods.
They are now subsumed by thunks and have been deleted. Now
that only the needed thunks are built, we don't need to
populate the concrete method sets of interface types at all,
so (*Program).Method and LookupMethod return nil for them.
This results in a slight reduction in function count (>1%) and
instruction count (<<1%).
Details:
go/ssa:
- API: ChangeType no longer supports func/method conversions.
- API: (*Program).FuncValue now returns nil for abstract
(interface) methods.
- API: (*Function).RelString simplified.
"$bound" is now a suffix not a prefix, and the receiver
type is rendered package-relative.
- API: Function.Object is now defined for all wrappers too.
- API: (*Program).Method and LookupMethod return nil for
abstract methods.
- emitConv no longer permits (non-identical)
Signature->Signature conversions. Added assertion.
- add and use isInterface helper
- sanity: we check packages after Build, not Create, otherwise
cross-package refs might fail.
go/pointer:
- update tests for new function strings.
- pointer_test: don't add non-pointerlike probes to analysis.
(The error was checked, but too late, causing a panic.)
- fixed a minor bug: if a test probe print(x) was the sole
reference to x, no nodes were generated for x.
- (reflect.Type).MethodByName: updated due to ssa API changes.
Also, fixed incorrect testdata/funcreflect.go expectation
for MethodByName on interfaces.
oracle:
- fix for new FuncValue semantics.
- a "pointsto" query on an I.f thunk now returns an error.
Fixesgolang/go#7839
LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/93780044
- Replaced check.initDependencies with check.initOrder;
this is the only semantic change, it affects only the
value of Info.InitOrder.
- Added additional init order test cases and adjusted
existing tests.
- Moved orderedSetObjects from resolver.go to ordering.go.
Fixesgolang/go#7964.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91450043
Programs such as this cause the PtrTo solver to attempt to
enumerate an infinite set of types {T, *T, ..., *******T, etc}.
t := reflect.TypeOf(T{})
for {
t = reflect.PtrTo(t)
}
The fix is to bound the depth of reflectively created types at
about 4 map/chan/slice/pointer constructors.
+ test.
LGTM=gri
R=gri
CC=crawshaw, golang-codereviews
https://golang.org/cl/102030044
go/types doesn't correctly round the largest possible
float32 literal values and fails. Instead of relying
on Rat.Float64 and float32 conversion, we need a
Rat.Float32 implementation with correct rounding.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96540045
Very long instructions caused the printf width spec to go
negative, which causes right-padding, often several lines'
worth.
Also: print the basic block comment once on the RHS. It's too
verbose to print it each time we mention the block.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/97490046
The previous implementation would cause the graph to contain
many duplicate edges resulting in very large cross products,
so that for some inputs (and random map iteration orders) the
running time of DeleteSyntheticNodes was many minutes---more
than the pointer analysis!
Duplicate edges can arise from an interface call that
dispatches to several different wrapper functions each
wrapping the same declared method.
For example, in the callgraph for go/types, a call to
Object.Pos() dispatches to the synthetic functions (*Type).Pos
and (*Var).Pos, each of which wrap (*object).Pos(). After
DeleteSyntheticNodes, Object.Pos() appeared to call
(*object).Pos() twice.
This change builds the set of all edges and avoids adding
edges already in the set.
Also, document findings.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/96100043
Method expressions T.f are reported as having type (T)func(T),
i.e. T appears twice, as a receiver and a regular parameter.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/96780044
During block optimization, degenerate conditional logic such
as "false && x" may result in single-predecessor blocks
containing φ-nodes. (Ideally such φ-nodes would be replaced
by their sole operand, but that requires Referrers information
which isn't computed until later.) It is obviously not safe
to fuse such blocks, so now we don't.
Fixesgolang/go#7840
LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/90620043
GccgoInstallation.InitFromDriver currently parses
the output of gccgo -### to get the gcc version,
target triple, and library paths. At least with
Ubuntu's stock libgo5 package, the search path for
.gox files derived from the version is incorrect.
gccgo uses the DEFAULT_TARGET_VERSION macro when
constructing the search path; this value can be
retrieved from gccgo via the "-dumpversion" flag.
Fixesgolang/go#7772.
LGTM=iant, gri
R=golang-codereviews, iant, gri
CC=golang-codereviews
https://golang.org/cl/88150043
Otherwise on Windows the enumerated package "net\\http" will
be distinct from the imported package "net/http" leading to
strange errors. (A similar bug was fixed in go/ssa/stdlib_test.go.)
Fixesgolang/go#7189
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/86170043
Side-effect: Because interfaces are now type-checked in reverse order,
cycle errors in interface declarations appear at the "end" rather than
at the "beginning" of the cycle in the source code. This is harmless.
Eventually we may want to do dependency order determination and thus
cycle detection for all types before fully type-checking them, which
might simplify some code and also produce consistently positioned cycle
errors again.
Fixesgolang/go#7158.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/83640043
This avoids confusion when trying to read correctly
encoded export data that happens to be encoded in
a different format (debug vs product).
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82090043
Existing tools use the default value of zero; their behaviour is unchanged.
(*Config).ParseFile is used only from tests.
LGTM=crawshaw, rsc, gri
R=crawshaw, gri, rsc
CC=golang-codereviews
https://golang.org/cl/79290044
Also, add loader.Config.DisplayPath hook, which allows the
filename returned by build.Context.Import() to be transformed
prior to attaching to the AST. This allows a virtual file
system to be used without leaking into the user interface.
Eliminate parsePackageFiles hook; I don't think we need it any
more. The test that was using it has been rewritten to use
the build.Context hooks.
LGTM=gri
R=gri, crawshaw
CC=daniel.morsing, golang-codereviews, rsc
https://golang.org/cl/75520046
With this CL, an Object.Parent() Scope is always the scope in
which the object was originally declared. For dot-imported
objects, that is the package scope of the package from which
the objects are imported (not the file scope into which they
are imported).
Also:
- Changed Scope.Insert to be agnostic regarding blank
identifiers - blank identifiers must be handled outside.
- Fixed handling of blank labels: they are never declared.
Fixesgolang/go#7537.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/75570043
e.g. file foo.go scope {...}
package math scope {...}
function f scope {...}
if scope {...}
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/74320043
This change renumbers nodes so that addressable ones
(that may appear in a points-to set) all have lower
numbers than non-addressable ones----initially at least:
reflection, SetFinalizer, etc add new nodes during
solving.
This improves the efficiency of sparse PTS
representations (to be added later). The largest int in
a PTS is now about 20% of the previous max.
Overview:
- move constraint stuff into constraint.go.
- add two methods to constraint:
(1) renumber(): renumbers all nodeids. The
implementations are very repetitive but simple. I
thought hard about other ways (mixins, reflection)
but decided this one was fine.
(2) indirect(): report the set of nodeids whose
points-to relations depend on the solver, not just
the initial constraint graph.
(This method is currently unused and is logically
part of a forthcoming change to implement PE/LE
presolver optimizations. (Perhaps I should comment
it out/remove it for now.)
- split up the population of the intrinsics map by file.
- delete analysis.probes (unused field)
- remove state="..." from panic message; unnecessary.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/73320043
Now that go/types permits files to be added to a package
incrementally (fixing bug 7114), this CL extends the loader
to load and augment multiple test packages at once.
TESTED:
- go/loader/stdlib_test runs the type-checker on the entire
standard library loaded from source in a single gulp, with
each package augmented by tests.
- Manually tested on:
% ssadump -test -run unicode encoding/ascii85
Both sets of tests are run (and pass).
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61060043
With this CL, it is now possible to type-check additional
package files to an already type-checked package through
repeated calls to Checker.Files.
Fixesgolang/go#7114.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/72730043
Provide an extra field, "Soft" in types.Error.
A client may want to filter out soft errors and
only abort if there are "hard" errors.
Qualified a first set of errors as "soft".
Fixesgolang/go#7360.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71800043
Also:
- slightly better error messages for return statements
- more AST validity checking of parameter lists
- use secondary error message for clarifying message in type switch errors
Fixesgolang/go#7469.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71780044
The parser may return error positions referring to positions
immediately after rather than at a token position. Provide
mechanism to identify those positions in test cases.
Also: Don't compute position strings for each token in test
cases. Should speed up Check test.
Pending CL 70190046 in main repo.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/71330043
(On Windows the two are not the same.)
Fixesgolang/go#7189.
Also: remove exception for code.google.com subtree; this was
an artifact of my unusual setup.
LGTM=gri
R=alex.brainman, gri
CC=golang-codereviews
https://golang.org/cl/70060048
Before, they were named func@line:col which made them easy to find in the source if you know the file, but hard if you don't, and it made tests fragile.
Now, they are named outer$1, outer$2, etc, which makes them
more informative in a UI since "outer" has meaning.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/65630048
This is to avoid an internal error in pointer analysis from
bringing down a long-lived application such as godoc.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/68930046
An identifier X in anonymous struct field struct{X} is both a
definition of a field (*Var) and reference to a type
(*TypeName). Now that we have split the map, we can capture
both of these aspects.
Interestingly, every client but one was going to extra effort
to iterate over just the uses or just the defs; this
simplifies them.
Also, fix two bug related to tagless switches:
- An entry was being recorded in the Object map for a piece of
synthetic syntax.
- The "true" identifier was being looked up in the current scope,
which allowed perverse users to locally redefine it. Now
we use the bool (not untyped boolean) constant true, per the
consequent clarification of the spec (issue 7404).
+ tests.
Fixesgolang/go#7276
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68270044
If a -pos argument is specified, a 'callgraph' query reports only the
functions within the query package. This produces a far more manageable
amount of information, and because we don't need to package-qualify the
names, the result is easier to read.
Added tests:
- callgraph query with/without -pos
(The test driver was extended to allow "nopos" queries.)
- callers and callees queries don't return wrappers
Also, in go/callgraph:
- (*Node).String, (*Edge).String
- (*Graph).DeleteSyntheticNodes eliminates synthetic wrapper functions,
preserving topology. Used in all four oracle "call*" queries.
- (*Graph).DeleteNode
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66240044
- clearer separation between package-level and object-level state
- lazy allocation of various package-level maps
- NewPackage automatically allocates a package scope
- steps towards enabling incremental checking of extra (test) files
after the (non-test) package is type-checked (not yet exposed)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/66230044
1) We remove context sensitivity from API. The pointer analysis is
not sufficiently context-sensitive for the context information to
be worth exposing. (The actual analysis precision still benefits
from being context-sensitive, though.) Since all clients would
discard the context info, we now do that for them.
2) Make the graph doubly-linked. Edges are now shared by the Nodes
at both ends of the edge so it's possible to navigate more easily
(e.g. to the callers).
3) Graph and Node are now concrete, not interfaces.
Less code in every file!
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66460043
Previously, each {Indirect,}Query would return a set of Pointers, one per context; now it returns (at most) one Pointer combining information from all contexts.
The old API was more faithful to the implementation concepts, but the analysis is not sufficiently context-sensitive that it makes sense: all existing clients simply throw away the context information---so now we do that for them.
(I may remove the context-sensitivity from the callgraph too, but I'll benchmark that first to see if it reduces precision.)
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66130044
- pre-poluate typIndex and typList using a predefined list of types
- no need to handle basic types explicitly anymore
- removed basicTag
- go/types: exported UniverseByte and UniverseRune for now
LGTM=adonovan
R=adonovan
CC=cmang, golang-codereviews
https://golang.org/cl/65920044
If this flag is set, (*Config).Load will not return an
error even if some packages had type errors. Each individual
PackageInfo can be queried for its error state, now exposed as
TypeError.
In addition, each PackageInfo exposes whether it is
"transitively error-free". ssa.Create skips packages without
this flag since it is required for SSA construction.
+ Test.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/62000045
Observation: not all alias facts are interesting.
- A channel-peers query also cares about pointers of kind chan.
- An oracle "points-to" query on an expression of kind map
only cares about maps.
- We always care about func, interface and reflect.Value,
since they're needed for sound analysis of dynamic dispatch.
We needn't bother collecting alias information for
uninteresting pointers, and this massively reduces the number
of labels flowing in to the constraint system.
The only constraints that create new labels are addressOf
and offsetAddr; both are now selectively emitted by type.
We compute the set of type kinds to track, based on the
{Indirect,}Query types. (We could enable tracking at an
even finer grain if we want.)
This requires that we can see all the {Indirect,}Query
value types a priori, which is not the case for the PrintCalls
mechanism used in the tests, so I have rewritten the latter
to use {Indirect,}Query instead.
This reduces the solver-phase time for the entire standard
library and tests from >8m to <2m. Similar speedups are
obtained on small and medium-sized programs.
Details:
- shouldTrack inspects the flattened form of a type to see if
it contains fields we must track. It memoizes the result.
- added precondition checks to (*Config).Add{,Indirect}Query.
- added (*ssa.Program).LookupMethod convenience method.
- added Example of how to use the Query mechanism.
- removed code made dead by a recent invariant:
the only pointerlike Const value is nil.
- don't generate constraints for any functions in "reflect".
(we had forgotten to skip synthetic wrappers too).
- write PTA warnings to the log.
- add annotations for more intrinsics.
LGTM=gri, crawshaw
R=crawshaw, gri
CC=golang-codereviews
https://golang.org/cl/62540043
Method Signatures (types.Signatures with a non-nil receiver) behave
like ordinary func Signatures in the hash function/equivalence relation
used by typemap.M, which leads to surprising incomplete traversal
over the type graph if an M is used to remember types already
visited.
This change avoids ever putting method Signatures in a typemap.
% go test -v code.google.com/p/go.tools/go/ssa
now repeatedly shows the exact same number of functions and
instructions.
(We should discuss how to avoid this problem more generally.)
Also:
- recur over the params/results of all the methods of
each type when computing necessary method sets.
- there's no longer any need to treat declarations of unexported
methods as a root for traversal. Added test case.
- enable SourceImports flag in stdlib_test, which was dropped
during a recent refactoring (d'oh).
- doc tweaks
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65450043
This CL adds no-op stubs for intrinsics now required by tests:
runtime.Goexit
sync.runtime_Sem{acquire,release}
sync/atomic.AddUint{32,64}
Goexit needs more thought; for now I've disabled the interpreted
tests of the "testing" package to make the build green again.
TBR=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/65480044
- Add math.{Log,Ldexp} to externals
- Test now uses FromArgs
- Scan all initial packages for tests, don't assume Created[0] exists.
(It doesn't if we import a package that has only in-package tests.)
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/62010044
Previously, each word could be a package import path or a
comma-separated list of *.go file names. Now, if the
first word ends with ".go", all words are assumed to be
Go source files. This makes it impossible to specify
two ad-hoc packages from source files, but no-one needs that.
FromArgs also takes a boolean indicating whether tests
are wanted or not.
Also: ssadump: add -test flag to set that boolean.
For the oracle it's always true.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61470047
Method-set caching is now performed externally using a MethodSetCache (if desired), not by the Types themselves.
This a minor deoptimization due to the extra maps, but avoids a situation in which method-sets are computed and frozen prematurely. (See b/7114)
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61430045
Move mutation of program to the final step.
+ 2 assertions;
+ switches.go: comment fix.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61510044
The "static bool" parameter to Implements was confusing; typically we think about interface implementation and type assertion as separate but related concepts, but here they were merged.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/58540044
- Centralize "visited" check in check.objDecl.
- Assert that object-specific declX functions
are only called with objects that have no
type associated with them, yet.
- Added test case.
Thanks to Richard Musiol (neelance@gmail.com) for
finding the bug and providing an easy test case.
For a discussion of the bug see the issue.
Fixesgolang/go#7245.
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59210043
- consistently set underlying types of incoming named types in typInternal
- use underlying() helper function to resolve forward chains
- related consistency cleanups
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53870044
This is (a) more efficient and (b) avoids the need for
constant error handling, since buffer writes can't fail.
Also:
- added WriteFunction and WritePackage functions,
similar to types.WriteFoo.
- *Function and *Package now implement io.WriterTo.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57930044