Godoc depends on go.talks/pkg/present by way of go.tools/pkg/blog.
Better to keep all godoc dependencies in one place.
R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/13656047
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
Defer parsing of blog content until accessed for faster startup.
Fall back on redirect if blog content unavailable locally.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13335052
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
- This change implements the correct type-based equivalence
relation for aggregate types. e.g. comparison of struct
types no longer compares the anonymous fields. We do
analogous things for hash().
- equals() and eqnil() have been separated: the former panics
for uncomparable types, the latter permits comparisons of
slice/map/func types against a literal nil and is intended
for use only by "static" ssa.BinOp(EQL), not "dynamic" slice
comparisons encountered during (e.g.) interface comparisons,
which should panic regardless of operand nilness.
- we use a (global) typemap.Hasher to compute type hashes;
hashing the Type.String() value was not sound.
+ tests.
NB, this change unearthed a bug in defer/recover within
init(); it will be fixed in a followup change.
R=gri, crawshaw
CC=golang-dev
https://golang.org/cl/13719043
Core:
reflect.TypeOf
reflect.ValueOf
reflect.Zero
reflect.Value.Interface
Maps:
(reflect.Value).MapIndex
(reflect.Value).MapKeys
(reflect.Value).SetMapIndex
(*reflect.rtype).Elem
(*reflect.rtype).Key
+ tests:
pointer/testdata/mapreflect.go.
oracle/testdata/src/main/reflection.go.
Interface objects (T, V...) have been renamed "tagged objects".
Abstraction: we model reflect.Value similar to
interface{}---as a pointer that points only to tagged
objects---but a reflect.Value may also point to an "indirect
tagged object", one in which the payload V is of type *T not T.
These are required because reflect.Values can hold lvalues,
e.g. when derived via Field() or Elem(), though we won't use
them till we get to structs and pointers.
Solving: each reflection intrinsic defines a new constraint
and resolution rule. Because of the nature of reflection,
generalizing across types, the resolution rules dynamically
create additional complex constraints during solving, where
previously only simple (copy) constraints were created.
This requires some solver changes:
The work done before the main solver loop (to attach new
constraints to the graph) is now done before each iteration,
in processNewConstraints.
Its loop over constraints is broken into two passes:
the first handles base (addr-of) constraints,
the second handles simple and complex constraints.
constraint.init() has been inlined. The only behaviour that
varies across constraints is ptr()
Sadly this will pessimize presolver optimisations, when we get
there; such is the price of reflection.
Objects: reflection intrinsics create objects (i.e. cause
memory allocations) with no SSA operation. We will represent
them as the cgnode of the instrinsic (e.g. reflect.New), so we
extend Labels and node.data to represent objects as a product
(not sum) of ssa.Value and cgnode and pull this out into its
own type, struct object. This simplifies a number of
invariants and saves space. The ntObject flag is now
represented by obj!=nil; the other flags are moved into
object.
cgnodes are now always recorded in objects/Labels for which it
is appropriate (all but those for globals, constants and the
shared contours for functions).
Also:
- Prepopulate the flattenMemo cache to consider reflect.Value
a fake pointer, not a struct.
- Improve accessors and documentation on type Label.
- @conctypes assertions renamed @types (since dyn. types needn't be concrete).
- add oracle 'describe' test on an interface (missing, an oversight).
R=crawshaw
CC=golang-dev
https://golang.org/cl/13418048
Remove References section heading.
Add redirects from old paths to new content.
Add a link to the SubRepositories wiki page from package list.
Add styles for "pop-out" link.
R=r
CC=golang-dev
https://golang.org/cl/13356047
Previously these helpers were added by a private deployment script.
There's no reason why they shouldn't be part of godoc proper now
that it's in the go.tools repository.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13722043
Define a minor mode called go-oracle-mode. Right now its sole
purpose is to define a keymap but it might later be used to add
hooks or add other features to go-mode.
R=adonovan
CC=golang-dev
https://golang.org/cl/13412048
Running the interpreter on (most of) the tests package in
"encoding" unearthed a couple of ssa.builder bugs, already
fixed. This CL contains the interpreter fixes that were
required. (The "encoding" tests aren't added to the suite
since they're slow.)
Added intrinsics for:
math.Exp
math.Min
hash/crc32.haveSSE42
(reflect.Type).Field
(reflect.Type).NumField
(reflect.Type).NumMethod
reflect.New
(reflect.Value).NumMethod
syscall.RawSyscall (returns ENOSYS)
reflect.Set (a no-op)
Treat unsafe.Pointer -> *T conversions by returning new(T).
This is incorrect but at least preserves type-safety,
which is sufficient for these tests.
hashmap: treat nil *hashmap as an empty map.
R=gri
CC=golang-dev
https://golang.org/cl/12901046
The existing check rejected only free identifiers defined in
file scope, i.e. just imports.
+ regression test.
R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/13256050
This is a short-term usability measure.
Longer term, we need to audit each conversion to decide
whether it should be ignored or modelled by an analytic
summary.
R=crawshaw
CC=golang-dev
https://golang.org/cl/13263050
Every one of the oracle's query modes needs to have typed ASTs
available, at least transiently, so that the -pos flag can be
interpreted. (The only mode that doesn't need the -pos flag
is callgraph, but that needs PTA.) So we hard-code it to true.
This change fixes a bug in the 'implements' query that causes
-pos parsing to fail. (This wasn't exposed by the tests
because they are degenerate in that the query always occurs in
the main package, which is specified ad-hoc, i.e. as a source
file not an import path. That's unfortunate, but this
change renders the distinction uninteresting in future.)
R=crawshaw, dominik.honnef
CC=golang-dev
https://golang.org/cl/13334050
* Added --tool flag that allows user to specify "gccgo" as the tool to build.
* Added builderEnv struct to abstract away setting up the build.
* Made envv and envvWindows methods of the builderEnv struct.
* Modified Builder.envv() to wrap envv and envvWindows
* Added internal builderEnv in Builder.
R=adg
CC=golang-dev
https://golang.org/cl/13240044
All have been audited to ensure that they have NoEffect on
aliasing. Also: clarify the requirements for NoEffect to
explicitly disclaim trivial loads/stores.
R=crawshaw
CC=golang-dev
https://golang.org/cl/13314045
+ test.
Also:
- provide non-nil map to Importer.doImport0() to avoid a crash.
- reorganize oracle "needs" bits.
- reduce "needs" of 'freevars' and 'implements' queries by avoiding
ssa.Packages when types.Package suffices.
R=crawshaw
CC=golang-dev
https://golang.org/cl/13421046
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
Background: some ssa.Values represent lvalues, e.g.
var g = new(string)
the *ssa.Global g is a **string, the address of what users
think of as the global g.
Querying pts(g) returns a singleton containing the object g, a
*string. What users really want to see is what that in turn
points to, i.e. the label for the call to new().
This change now lets users make "indirect" pointer queries,
i.e. for pts(*v) where v is an ssa.Value. The oracle makes an
indirect query if the type of the ssa.Value differs from the
source expression type by a pointer, i.e. it's an lvalue.
In other words, we're hiding the fact that compilers (e.g. ssa) internally represent globals by their address.
+ Tests.
This serendipitously fixed an outstanding bug mentioned in the
describe.go
R=crawshaw
CC=golang-dev
https://golang.org/cl/13532043
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
Motivation: pointer analysis tools (like the oracle) want the
user to specify a set of initial packages, like 'go test'.
This change enables the user to specify a set of packages on
the command line using importer.LoadInitialPackages(args).
Each argument is interpreted as either:
- a comma-separated list of *.go source files together
comprising one non-importable ad-hoc package.
e.g. "src/pkg/net/http/triv.go" gives us [main].
- an import path, denoting both the imported package
and its non-importable external test package, if any.
e.g. "fmt" gives us [fmt, fmt_test].
Current type-checker limitations mean that only the first
import path may contribute tests: multiple packages augmented
by *_test.go files could create import cycles, which 'go test'
avoids by building a separate executable for each one.
That approach is less attractive for static analysis.
Details: (many files touched, but importer.go is the crux)
importer:
- PackageInfo.Importable boolean indicates whether
package is importable.
- un-expose Importer.Packages; expose AllPackages() instead.
- CreatePackageFromArgs has become LoadInitialPackages.
- imports() moved to util.go, renamed importsOf().
- InitialPackagesUsage usage message exported to clients.
- the package name for ad-hoc packages now comes from the
'package' decl, not "main".
ssa.Program:
- added CreatePackages() method
- PackagesByPath un-exposed, renamed 'imported'.
- expose AllPackages and ImportedPackage accessors.
oracle:
- describe: explain and workaround a go/types bug.
Misc:
- Removed various unnecessary error.Error() calls in Printf args.
R=crawshaw
CC=golang-dev
https://golang.org/cl/13579043
Until now, the name of the captured ssa.Value, not
types.Var was used, leading to confusing disassembly
when it was a numbered register. See:
https://code.google.com/p/go/issues/detail?id=6337
Now the output is:
# Free variables:
# 0: a *int
# 1: b *int
func func@6.9() int:
.0.entry:
t0 = *b
t1 = *a
t2 = *b
etc...
BUG=6337
R=crawshaw
CC=golang-dev
https://golang.org/cl/13249049