1
0
mirror of https://github.com/golang/go synced 2024-09-23 17:10:13 -06:00
go/test
Russ Cox b1678e508b cmd/compile: handle simple inlined calls in staticinit
Global variable initializers like

	var myErr error = &myError{"msg"}

have been converted to statically initialized data
from the earliest days of Go: there is no init-time
execution or allocation for that line of code.

But if the expression is moved into an inlinable function,
the static initialization no longer happens.
That is, this code has always executed and allocated
at init time, even after we added inlining to the compiler,
which should in theory make this code equivalent to
the original:

	func NewError(s string) error { return &myError{s} }
	var myErr2 = NewError("msg")

This CL makes the static initialization rewriter understand
inlined functions consisting of a single return statement,
like in this example, so that myErr2 can be implemented as
statically initialized data too, just like myErr, with no init-time
execution or allocation.

A real example of code that benefits from this rewrite is
all globally declared errors created with errors.New, like

	package io
	var EOF = errors.New("EOF")

Package io no longer has to allocate and initialize EOF each
time a program starts.

Another example of code that benefits is any globally declared
godebug setting (using the API from CL 449504), like

	package http
	var http2server = godebug.New("http2server")

These are no longer allocated and initialized at program startup either.

The list of functions that are inlined into static initializers when
compiling std and cmd (along with how many times each occurs) is:

	cmd/compile/internal/ssa.StringToAux (3)
	cmd/compile/internal/walk.mkmapnames (4)
	errors.New (360)
	go/ast.NewIdent (1)
	go/constant.MakeBool (4)
	go/constant.MakeInt64 (3)
	image.NewUniform (4)
	image/color.ModelFunc (11)
	internal/godebug.New (12)
	vendor/golang.org/x/text/unicode/bidi.newBidiTrie (1)
	vendor/golang.org/x/text/unicode/norm.newNfcTrie (1)
	vendor/golang.org/x/text/unicode/norm.newNfkcTrie (1)

For the cmd/go binary, this CL cuts the number of init-time
allocations from about 1920 to about 1620 (a 15% reduction).

The total executable code footprint of init functions is reduced
by 24kB, from 137kB to 113kB (an 18% reduction).
The overall binary size is reduced by 45kB,
from 15.335MB to 15.290MB (a 0.3% reduction).
(The binary size savings is larger than the executable code savings
because every byte of executable code also requires corresponding
runtime tables for unwinding, source-line mapping, and so on.)

Also merge test/sinit_run.go, which had stopped testing anything
at all as of CL 161337 (Feb 2019) and initempty.go into a new test
noinit.go.

Fixes #30820.

Change-Id: I52f7275b1ac2a0a32e22c29f9095071c7b1fac20
Reviewed-on: https://go-review.googlesource.com/c/go/+/450136
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-11-16 04:04:52 +00:00
..
abi
alias3.dir
asmhdr.dir cmd/compile: use exact constant in go_asm.h 2022-01-10 21:27:19 +00:00
bench test/bench/go1: eliminate start-up time 2022-11-01 17:07:14 +00:00
chan
closure3.dir test: relax closure name matching in closure3.go 2022-10-01 01:52:16 +00:00
closure5.dir test: use dot-relative imports where appropriate 2022-03-24 02:14:15 +00:00
codegen cmd/compile: merge zero constant ISEL in PPC64 lateLower pass 2022-11-14 19:44:47 +00:00
ddd2.dir
dwarf
fixedbugs cmd/compile: fix missing typecheck for static initialization slice 2022-11-15 17:35:03 +00:00
import2.dir
import4.dir go/types, types2: use "and not used" instead of "but not used" in error messages 2022-09-27 21:10:19 +00:00
interface cmd/compile: use "missing method m" instead of "missing m method" 2022-09-24 17:04:15 +00:00
intrinsic.dir runtime: replace all uses of CtzXX with TrailingZerosXX 2022-10-18 18:06:27 +00:00
ken test/ken/slicearray.go: correct type width in comment 2021-12-05 12:50:44 +00:00
linkname.dir test: compile source files as if from "test" module 2022-03-24 17:50:47 +00:00
method4.dir
retjmp.dir cmd/internal/obj: fix tail call in non-zero frame leaf function on MIPS and S390X 2021-12-13 22:42:08 +00:00
runtime
stress
syntax go/parser: adjustments to error messages 2022-09-01 22:37:04 +00:00
typeparam test: enable issue47631.go for Unified IR 2022-09-30 23:00:20 +00:00
uintptrescapes.dir
64bit.go
235.go
alg.go
alias1.go
alias2.go cmd/compile: use "cannot use %s as %s value in %s: %s" error message 2022-09-28 22:28:39 +00:00
alias3.go
alias.go
align.go
append1.go cmd/compile: use "cannot use %s as %s value in %s: %s" error message 2022-09-28 22:28:39 +00:00
append.go
args.go
armimm.go
asmhdr.go
assign1.go
assign.go
atomicload.go
bigalg.go
bigmap.go
blank1.go
blank.go
bom.go
bombad.go
bounds.go
cannotassign.go
chancap.go
chanlinear.go
char_lit1.go
char_lit.go
checkbce.go
clearfat.go
closedchan.go
closure1.go
closure2.go
closure3.go
closure4.go
closure5.go
closure6.go
closure7.go
closure.go
cmp6.go
cmp.go
cmplx.go
cmplxdivide1.go
cmplxdivide.c
cmplxdivide.go
complit1.go
complit.go
compos.go
const1.go
const2.go
const3.go
const4.go
const5.go
const6.go
const7.go go/types, types2: check integer constant literal overflow 2022-08-16 01:11:29 +00:00
const8.go test: add more tests for const decls with ommitted RHS expressions 2022-06-28 18:11:31 +00:00
const.go
convert1.go
convert2.go go/types, types2: implement slice-to-array conversions 2022-09-08 15:55:44 +00:00
convert3.go
convert4.go cmd/compile: implement slice-to-array conversions 2022-09-19 18:58:26 +00:00
convert.go
convlit1.go
convlit.go
convT2X.go
copy1.go
copy.go
crlf.go
ddd1.go cmd/compile: use "cannot use %s as %s value in %s: %s" error message 2022-09-28 22:28:39 +00:00
ddd2.go
ddd.go
decl.go
declbad.go
defer.go
defererrcheck.go
deferfin.go
defernil.go
deferprint.go
deferprint.out
devirt.go
directive2.go cmd/compile: restrict //go:notinheap to runtime/internal/sys 2022-09-02 06:22:23 +00:00
directive.go cmd/compile: restrict //go:notinheap to runtime/internal/sys 2022-09-02 06:22:23 +00:00
divide.go
divmod.go
embedfunc.go
embedvers.go
empty.go
env.go
eof1.go
eof.go
escape2.go
escape2n.go
escape3.go
escape4.go test: skip inlining check in escape4.go 2022-10-01 01:52:17 +00:00
escape5.go
escape_array.go
escape_calls.go
escape_closure.go
escape_field.go
escape_goto.go
escape_hash_maphash.go
escape_iface_nounified.go [dev.unified] test: break escape_iface.go into unified/nounified variants 2022-06-30 18:41:26 +00:00
escape_iface_unified.go [dev.unified] cmd/compile/internal/noder: implicit conversions for multi-valued expressions 2022-06-30 18:42:24 +00:00
escape_iface.go [dev.unified] test: break escape_iface.go into unified/nounified variants 2022-06-30 18:41:26 +00:00
escape_indir.go
escape_level.go
escape_map.go
escape_param.go
escape_runtime_atomic.go
escape_selfassign.go
escape_slice.go cmd/compile: implement slice-to-array conversions 2022-09-19 18:58:26 +00:00
escape_struct_param1.go
escape_struct_param2.go
escape_struct_return.go
escape_sync_atomic.go
escape_unsafe.go test: fix typo in escape_unsafe.go 2022-09-07 17:25:59 +00:00
escape.go
fibo.go
finprofiled.go
float_lit2.go
float_lit3.go test: re-enable a bunch of tests with types2 2021-12-03 16:24:32 +00:00
float_lit.go
floatcmp.go
for.go
func1.go
func2.go
func3.go
func4.go
func5.go
func6.go
func7.go
func8.go
func.go
funcdup2.go
funcdup.go
fuse.go
gc1.go
gc2.go
gc.go
gcgort.go
gcstring.go
goprint.go
goprint.out
goto.go
heapsampling.go test/heapsampling.go: slow down allocation rate and reduce iterations 2022-05-27 21:36:06 +00:00
helloworld.go
helloworld.out
if.go
import1.go go/types, types2: use "and not used" instead of "but not used" in error messages 2022-09-27 21:10:19 +00:00
import2.go
import4.go
import5.go
import6.go test: re-enable most go/tests that were disabled because of types2 differences 2022-01-11 02:26:58 +00:00
import.go
index0.go
index1.go
index2.go
index.go
indirect1.go
indirect.go
init1.go
init.go
initcomma.go
initexp.go cmd/compile: use "init... cycle" instead of "init... loop" in error messages 2022-09-23 20:27:09 +00:00
initialize.go cmd/compile: handle simple inlined calls in staticinit 2022-11-16 04:04:52 +00:00
initializerr.go test: re-enable most go/tests that were disabled because of types2 differences 2022-01-11 02:26:58 +00:00
initloop.go
inline_big.go
inline_caller.go
inline_callers.go
inline_endian.go cmd/compile: make encoding/binary appends cheaper to inline 2022-09-15 21:05:02 +00:00
inline_literal.go
inline_math_bits_rotate.go
inline_nounified.go [dev.unified] test: extract different inline test between unified and non-unified 2022-06-15 21:22:56 +00:00
inline_sync.go sync: convert RWMutex.{readerCount,readerWait} to atomic type 2022-09-09 18:28:35 +00:00
inline_unified.go cmd/compile/internal/noder: fix inlined function literal positions 2022-08-25 18:46:22 +00:00
inline_variadic.go
inline.go cmd/compile: handle simple inlined calls in staticinit 2022-11-16 04:04:52 +00:00
int_lit.go
intcvt.go
intrinsic_atomic.go misc, test: fix test error for loong64 2022-05-20 16:16:37 +00:00
intrinsic.go
iota.go
label1.go
label.go
linkmain_run.go test: update test/run.go and some tests to use importcfg 2022-10-12 23:16:41 +00:00
linkmain.go
linkname3.go test: re-enable a bunch of tests with types2 2021-12-03 16:24:32 +00:00
linkname.go
linkobj.go test: update test/run.go and some tests to use importcfg 2022-10-12 23:16:41 +00:00
linkx_run.go
linkx.go
literal2.go
literal.go
live1.go
live2.go
live_regabi.go cmd/compile: stop using VARKILL 2022-08-18 17:36:38 +00:00
live_uintptrkeepalive.go all: fix spelling 2022-05-17 19:51:29 +00:00
live.go cmd/compile: stop using VARKILL 2022-08-18 17:36:38 +00:00
loopbce.go cmd/compile: tighten bounds for induction variables in strided loops 2022-08-31 22:04:55 +00:00
mainsig.go
makechan.go
makemap.go
makenew.go
makeslice.go
mallocfin.go
map1.go
map.go
mapclear.go
maplinear.go
maymorestack.go
mergemul.go
method1.go cmd/compile: use "method T.m already declared" for method redeclaration errors 2022-09-27 21:59:19 +00:00
method2.go go/types, types2: better error message when using *interface instead of interface 2022-01-10 22:48:40 +00:00
method3.go
method4.go
method5.go
method6.go
method7.go
method.go
named1.go
named.go
nil.go
nilcheck.go [dev.unified] test: tweak nilcheck test 2022-06-30 18:41:59 +00:00
nilptr2.go
nilptr3.go
nilptr4.go
nilptr5_aix.go
nilptr5_wasm.go
nilptr5.go cmd/compile: handle partially overlapping assignments 2022-08-23 19:56:32 +00:00
nilptr_aix.go
nilptr.go
noinit.go cmd/compile: handle simple inlined calls in staticinit 2022-11-16 04:04:52 +00:00
nosplit.go misc, test: fix test error for loong64 2022-05-20 16:16:37 +00:00
nowritebarrier.go
nul1.go
opt_branchlikely.go
parentype.go
peano.go
phiopt.go
print.go
print.out
printbig.go
printbig.out
prove_constant_folding.go cmd/compile: fold constants found by prove 2022-05-04 20:30:17 +00:00
prove.go cmd/compile: recognize when the result of append has a constant length 2022-10-27 17:09:50 +00:00
range.go
README.md
recover1.go
recover2.go
recover3.go
recover4.go
recover5.go
recover.go
reflectmethod1.go
reflectmethod2.go
reflectmethod3.go
reflectmethod4.go
reflectmethod5.go
reflectmethod6.go
reflectmethod7.go
reflectmethod8.go
rename1.go
rename.go
reorder2.go
reorder.go
retjmp.go
return.go
rotate0.go
rotate1.go
rotate2.go
rotate3.go
rotate.go
run.go cmd/compile: fix transitive inlining of generic functions 2022-11-08 21:26:09 +00:00
rune.go
runtime.go
shift1.go test: re-enable a bunch of tests with types2 2021-12-03 16:24:32 +00:00
shift2.go
shift3.go cmd/compile: adjust types2 shift check to match go/types (cleanup) 2022-04-07 17:19:55 +00:00
sieve.go
sigchld.go
sigchld.out
simassign.go
sizeof.go
slice3.go
slice3err.go
slicecap.go
sliceopt.go
solitaire.go
stack.go
stackobj2.go
stackobj3.go
stackobj.go
strcopy.go
strength.go
string_lit.go
stringrange.go
struct0.go
switch2.go go/parser: adjustments to error messages 2022-09-01 22:37:04 +00:00
switch3.go
switch4.go
switch5.go
switch6.go cmd/compile: use "missing method m" instead of "missing m method" 2022-09-24 17:04:15 +00:00
switch7.go
switch.go [dev.unified] test: add switch test case for tricky nil handling 2022-07-19 23:30:49 +00:00
tinyfin.go
torture.go
turing.go
typecheck.go test: re-enable most go/tests that were disabled because of types2 differences 2022-01-11 02:26:58 +00:00
typecheckloop.go cmd/compile: use "init... cycle" instead of "init... loop" in error messages 2022-09-23 20:27:09 +00:00
typeswitch1.go
typeswitch2.go
typeswitch2b.go go/types, types2: use "and not used" instead of "but not used" in error messages 2022-09-27 21:10:19 +00:00
typeswitch3.go
typeswitch.go
uintptrescapes2.go
uintptrescapes3.go
uintptrescapes.go
uintptrkeepalive.go cmd/compile: add //go:uintptrkeepalive 2022-04-21 18:06:38 +00:00
undef.go
unsafe_slice_data.go cmd/compile: add support for unsafe.{String,StringData,SliceData} 2022-08-31 17:15:15 +00:00
unsafe_string_data.go cmd/compile: add support for unsafe.{String,StringData,SliceData} 2022-08-31 17:15:15 +00:00
unsafe_string.go cmd/compile: add support for unsafe.{String,StringData,SliceData} 2022-08-31 17:15:15 +00:00
unsafebuiltins.go cmd/compile: add support for unsafe.{String,StringData,SliceData} 2022-08-31 17:15:15 +00:00
used.go
utf.go
varerr.go
varinit.go
winbatch.go
writebarrier.go
zerodivide.go

The test directory contains tests of the Go tool chain and runtime. It includes black box tests, regression tests, and error output tests. They are run as part of all.bash.

To run just these tests, execute:

../bin/go run run.go

To run just tests from specified files in this directory, execute:

../bin/go run run.go -- file1.go file2.go ...

Standard library tests should be written as regular Go tests in the appropriate package.

The tool chain and runtime also have regular Go tests in their packages. The main reasons to add a new test to this directory are:

  • it is most naturally expressed using the test runner; or
  • it is also applicable to gccgo and other Go tool chains.