Commit Graph

17 Commits

Author SHA1 Message Date
Alan Donovan e779aa49e3 go/ssa/interp: make tests fast and robust
The go/ssa/interp tests have been a maintenance nightmare for years
because the interpreter requires intrinsics for all low-level or
non-Go code functions, and the set of such functions in the standard
library naturally changes from day to day.

This CL finally drops support for interpreting real packages (which
has anyway been broken for ages) and restricts the test suite to small
programs that use a handful of simple functions in packages bytes,
strings, errors, runtime, reflect, and unicode. These functions are
declared in a tiny fake standard libary in testdata/src, and the
implementations of these functions are provided by interpreter
intrinsics that delegate to the real Go implementation---all their
parameters and results are basic datatypes.

The test suite is now very fast and should be easy to maintain going
forward. It is still possible that a change to some file in
$GOROOT/test/*.go adds a dependency to a symbol not present in our
standard library, but this is rare. I will either delete the test or
add the intrinsic on a case-by-case basis.

We no longer attempt to interpret major functionality like
fmt.Sprintf or "testing".

The interpreter always pretends to be in linux/amd64 mode.

Happy Christmas, Brad. ;)

Fixes golang/go#27292

Change-Id: I715cf63e3534e2e0dab4666a5d7c669bf1d92674
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168898
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-22 17:29:27 +00:00
David R. Jenni 718875e4f9 x/tools: simplify and format code
Semi-mechanical changes using gofmt -s
and honnef.co/go/tools/cmd/gosimple.

Change-Id: I41bcf4bea5b16c4776b7cf6534b76aa59b3c022d
Reviewed-on: https://go-review.googlesource.com/37447
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-28 14:15:42 +00:00
Alan Donovan bd8de46c84 go/ssa/interp/testdata: remove comment about now-fixed go/types bug
Change-Id: I55372a40c0049368a74247fe1819be384313f838
Reviewed-on: https://go-review.googlesource.com/7666
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-03-17 17:28:01 +00:00
Alan Donovan 868c429971 go/ssa/interp: fix bug causing subelements of aggregates to change address.
Since all SSA values are immutable, no value copying is required for
any operations except those that load from or store to a variable;
those operations must do an aggregate copy, i.e., descend into struct
and array elements.  All other calls to copyVal have been removed;
they were pieces of duct tape, as I had long suspected.

The descent must be based on the static type information, not the
"shape" of the dynamic value, since two reflect.Value structs may have
different internal shapes.  We clobber the true definition of
reflect.Value's underlying type, replacing it with struct{interface{},
interface{}}, which is close enough to make the load/store functions
work.

+ Test

Change-Id: I5e239d91ed0cb2a669a9f75766024fe1f9a5c347
Reviewed-on: https://go-review.googlesource.com/7532
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-03-13 18:22:38 +00:00
Alan Donovan 43a6897047 go/ssa: simplify make([]T, len, k) to new([k]T)[:len] for constant k
+ test.

Change-Id: I0255e38a0f95af95a32dc1d9cf18b26db85af36f
Reviewed-on: https://go-review.googlesource.com/1519
Reviewed-by: Robert Griesemer <gri@golang.org>
2014-12-29 21:06:17 +00:00
Alan Donovan d3f2df4854 go.tools/go/ssa/interp: some fixes to tests
- 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
2014-08-07 10:57:00 -04:00
Alan Donovan b2ea2e8560 go.tools/go/ssa: permit "for range x"
+ test

Also: don't generate init() functions for packages loaded from export data.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/111200043
2014-07-15 17:34:50 +01:00
Alan Donovan 6db8a00c75 go.tools/go/ssa: write zero value when storing a composite literal in-place if necessary
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
2014-06-16 12:29:30 -04:00
Alan Donovan de23e2b0c2 go/ssa: make Builtin capable of representing non-spec-defined intrinsics.
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
2014-06-13 17:34:07 -04:00
Robert Griesemer 0fa48054ca go.tools/go/types: comma-ok expressions return bool rather than untyped bool
Per the current spec.

Fixes golang/go#8188.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101200043
2014-06-11 15:03:38 -07:00
Peter Collingbourne cd36f52558 go.tools/go/ssa: add Max to Slice's SSA operand list
LGTM=adonovan
R=adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/101160043
2014-06-11 16:16:19 -04:00
Robert Griesemer 3827909f21 go.tools/go/types: compute correct initialization order
- 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.

Fixes golang/go#7964.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91450043
2014-06-11 09:15:31 -07:00
Peter Collingbourne afea1b1755 go.tools/go/ssa: fix range iteration over values of pointer to named array type
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/107800045
2014-06-05 17:19:58 -04:00
Robert Griesemer 30b1abe2f7 go.tools: fix various typos
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/97920045
2014-05-02 14:38:08 -07:00
Alan Donovan 7d1d69032b go.tools/go/ssa: don't attempt fusion on single-pred blocks with φ-nodes
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.

Fixes golang/go#7840

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/90620043
2014-04-24 09:08:21 -04:00
Alan Donovan b3dbe56610 go.tools/go/ssa: support 3-operand x[lo:hi:max] slices.
+ very basic test ($GOROOT/test/slice3.go needs unsafe.Pointer)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/60030043
2014-02-05 17:54:51 -05:00
Alan Donovan 3fc0fc1310 go.tools: rename packages.
Was:		Now:
ssa		go/ssa
importer	go/loader
pointer		go/pointer

Next CL: call -> go/callgraph (requires more care)

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/52960043
2014-01-16 09:33:58 -05:00