aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-22 15:35:11 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-22 16:32:37 -0800
commit6e46c8fbb5ba440cc503193220476c204100fb40 (patch)
tree67472f55b9b1f5ab66cbcfd39cf154c1f8c2011c /src/cmd
parente4ef30a66751c39bdd24764763531f1a4c325845 (diff)
parent7e0a81d2806b073c6455f73b10fbf2c811703f46 (diff)
downloadgo-6e46c8fbb5ba440cc503193220476c204100fb40.tar.gz
go-6e46c8fbb5ba440cc503193220476c204100fb40.zip
[dev.typeparams] all: merge dev.regabi (7e0a81d) into dev.typeparams
As with CL 285875, this required resolving some conflicts around handling of //go:embed directives. Still further work is needed to reject uses of //go:embed in files that don't import "embed", so this is left as a TODO. (When this code was written for dev.typeparams, we were still leaning towards not requiring the "embed" import.) Also, the recent support for inlining closures (CL 283112) interacts poorly with -G=3 mode. There are some known issues with this code already (#43818), so for now this CL disables inlining of closures when in -G=3 mode with a TODO to revisit this once closure inlining is working fully. Conflicts: - src/cmd/compile/internal/noder/noder.go - src/cmd/compile/internal/typecheck/dcl.go - src/cmd/compile/internal/typecheck/func.go - test/run.go Merge List: + 2021-01-22 7e0a81d280 [dev.regabi] all: merge master (dab3e5a) into dev.regabi + 2021-01-22 dab3e5affe runtime: switch runtime to libc for openbsd/amd64 + 2021-01-22 a1b53d85da cmd/go: add documentation for test and xtest fields output by go list + 2021-01-22 b268b60774 runtime: remove pthread_kill/pthread_self for openbsd + 2021-01-22 ec4051763d runtime: fix typo in mgcscavenge.go + 2021-01-22 7ece3a7b17 net/http: fix flaky TestDisableKeepAliveUpgrade + 2021-01-22 50cba0506f time: clarify Timer.Reset behavior on AfterFunc Timers + 2021-01-22 cf10e69f17 doc/go1.16: mention net/http.Transport.GetProxyConnectHeader + 2021-01-22 ec1b945265 doc/go1.16: mention path/filepath.WalkDir + 2021-01-22 11def3d40b doc/go1.16: mention syscall.AllThreadsSyscall + 2021-01-21 07b0235609 doc/go1.16: add notes about package-specific fs.FS changes + 2021-01-21 e2b4f1fea5 doc/go1.16: minor formatting fix + 2021-01-21 9f43a9e07b doc/go1.16: mention new debug/elf constants + 2021-01-21 3c2f11ba5b cmd/go: overwrite program name with full path + 2021-01-21 953d1feca9 all: introduce and use internal/execabs + 2021-01-21 b186e4d70d cmd/go: add test case for cgo CC setting + 2021-01-21 5a8a2265fb cmd/cgo: report exec errors a bit more clearly + 2021-01-21 46e2e2e9d9 cmd/go: pass resolved CC, GCCGO to cgo + 2021-01-21 3d40895e36 runtime: switch openbsd/arm64 to pthreads + 2021-01-21 d95ca91380 crypto/elliptic: fix P-224 field reduction + 2021-01-21 d7e71c01ad [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for dwarf + 2021-01-21 5248f59a22 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for SSA + 2021-01-21 970d8b6cb2 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet in inlining + 2021-01-21 68a4664475 [dev.regabi] cmd/compile: remove tempAssigns in walkCall1 + 2021-01-21 fd9a391cdd [dev.regabi] cmd/compile: remove CallExpr.Rargs + 2021-01-21 19a6db6b63 [dev.regabi] cmd/compile: make sure mkcall* passed non-nil init + 2021-01-21 9f036844db [dev.regabi] cmd/compile: use ir.DoChildren directly in inlining + 2021-01-21 213c3905e9 [dev.regabi] cmd/compile: use node walked flag to prevent double walk for walkSelect + 2021-01-20 1760d736f6 [dev.regabi] cmd/compile: exporting, importing, and inlining functions with OCLOSURE + 2021-01-20 ecf4ebf100 cmd/internal/moddeps: check content of all modules in GOROOT + 2021-01-20 92cb157cf3 [dev.regabi] cmd/compile: late expansion of return values + 2021-01-20 d2d155d1ae runtime: don't adjust timer pp field in timerWaiting status + 2021-01-20 803d18fc6c cmd/go: set Incomplete field on go list output if no files match embed + 2021-01-20 6e243ce71d cmd/go: have go mod vendor copy embedded files in subdirs + 2021-01-20 be28e5abc5 cmd/go: fix mod_get_fallback test + 2021-01-20 928bda4f4a runtime: convert openbsd/amd64 locking to libc + 2021-01-19 824f2d635c cmd/go: allow go fmt to complete when embedded file is missing + 2021-01-19 0575e35e50 cmd/compile: require 'go 1.16' go.mod line for //go:embed + 2021-01-19 9423d50d53 [dev.regabi] cmd/compile: use '%q' for printing rune values less than 128 + 2021-01-19 ccb2e90688 cmd/link: exit before Asmb2 if error + 2021-01-19 ca5774a5a5 embed: treat uninitialized FS as empty + 2021-01-19 d047c91a6c cmd/link,runtime: switch openbsd/amd64 to pthreads + 2021-01-19 61debffd97 runtime: factor out usesLibcall + 2021-01-19 9fed39d281 runtime: factor out mStackIsSystemAllocated + 2021-01-19 a2f825c542 [dev.regabi] cmd/compile: directly create go.map and go.track symbols + 2021-01-19 4a4212c0e5 [dev.regabi] cmd/compile: refactor Linksym creation + 2021-01-19 4f5c603c0f [dev.regabi] cmd/compile: cleanup callTargetLSym + 2021-01-18 dbab079835 runtime: free Windows event handles after last lock is dropped + 2021-01-18 5a8fbb0d2d os: do not close syscall.Stdin in TestReadStdin + 2021-01-18 422f38fb6c [dev.regabi] cmd/compile: move stack objects to liveness + 2021-01-18 6113db0bb4 [dev.regabi] cmd/compile: convert OPANIC argument to interface{} during typecheck + 2021-01-18 4c835f9169 [dev.regabi] cmd/compile: use LinksymOffsetExpr in TypePtr/ItabAddr + 2021-01-18 0ffa1ead6e [dev.regabi] cmd/compile: use *obj.LSym instead of *ir.Name for staticdata functions + 2021-01-17 7e0fa38aad [dev.regabi] cmd/compile: remove unneeded packages from ir.Pkgs + 2021-01-17 99a5db11ac [dev.regabi] cmd/compile: use LinksymOffsetExpr in walkConvInterface + 2021-01-17 87845d14f9 [dev.regabi] cmd/compile: add ir.TailCallStmt + 2021-01-17 e3027c6828 [dev.regabi] cmd/compile: fix linux-amd64-noopt builder + 2021-01-17 59ff93fe64 [dev.regabi] cmd/compile: rename NameOffsetExpr to LinksymOffsetExpr + 2021-01-17 82b9cae700 [dev.regabi] cmd/compile: change ir.NameOffsetExpr to use *obj.LSym instead of *Name + 2021-01-17 88956fc4b1 [dev.regabi] cmd/compile: stop analyze NameOffsetExpr.Name_ in escape analysis + 2021-01-17 7ce2a8383d [dev.regabi] cmd/compile: simplify stack temp initialization + 2021-01-17 ba0e8a92fa [dev.regabi] cmd/compile: refactor temp construction in walk + 2021-01-17 78e5aabcdb [dev.regabi] cmd/compile: replace Node.HasCall with walk.mayCall + 2021-01-16 6de9423445 [dev.regabi] cmd/compile: cleanup OAS2FUNC ordering + 2021-01-16 a956a0e909 [dev.regabi] cmd/compile, runtime: fix up comments/error messages from recent renames + 2021-01-16 ab3b67abfd [dev.regabi] cmd/compile: remove ONEWOBJ + 2021-01-16 c9b1445ac8 [dev.regabi] cmd/compile: remove TypeAssertExpr {Src,Dst}Type fields + 2021-01-15 682a1d2176 runtime: detect errors in DuplicateHandle + 2021-01-15 9f83418b83 cmd/link: remove GOROOT write in TestBuildForTvOS + 2021-01-15 ec9470162f cmd/compile: allow embed into any string or byte slice type + 2021-01-15 54198b04db cmd/compile: disallow embed of var inside func + 2021-01-15 b386c735e7 cmd/go: fix go generate docs + 2021-01-15 bb5075a525 syscall: remove RtlGenRandom and move it into internal/syscall + 2021-01-15 1deae0b597 os: invoke processKiller synchronously in testKillProcess + 2021-01-15 03a875137f [dev.regabi] cmd/compile: unexport reflectdata.WriteType + 2021-01-15 14537e6e54 [dev.regabi] cmd/compile: move stkobj symbol generation to SSA + 2021-01-15 ab523fc510 [dev.regabi] cmd/compile: don't promote Byval CaptureVars if Addrtaken + 2021-01-15 ff196c3e84 crypto/x509: update iOS bundled roots to version 55188.40.9 + 2021-01-15 b7a698c73f [dev.regabi] test: disable test on windows because expected contains path separators. + 2021-01-15 4be7af23f9 [dev.regabi] cmd/compile: fix ICE during ir.Dump + 2021-01-14 e125ccd10e cmd/go: in 'go mod edit', validate versions given to -retract and -exclude + 2021-01-14 eb330020dc cmd/dist, cmd/go: pass -arch for C compilation on Darwin + 2021-01-14 84e8a06f62 cmd/cgo: remove unnecessary space in cgo export header + 2021-01-14 0c86b999c3 cmd/test2json: document passing -test.paniconexit0 + 2021-01-14 9135795891 cmd/go/internal/load: report positions for embed errors + 2021-01-14 35b9c66601 [dev.regabi] cmd/compile,cmd/link: additional code review suggestions for CL 270863 + 2021-01-14 d9b79e53bb cmd/compile: fix wrong complement for arm64 floating-point comparisons + 2021-01-14 c73232d08f cmd/go/internal/load: refactor setErrorPos to PackageError.setPos + 2021-01-14 6aa28d3e06 go/build: report positions for go:embed directives + 2021-01-14 9734fd482d [dev.regabi] cmd/compile: use node walked flag to prevent double walk for walkSwitch + 2021-01-14 f97983249a [dev.regabi] cmd/compile: move more PAUTOHEAP to SSA construction + 2021-01-14 4476300425 [dev.regabi] cmd/compile: use byte for CallExpr.Use + 2021-01-14 5a5ab24689 [dev.regabi] cmd/compile: do not rely on CallExpr.Rargs for detect already walked calls + 2021-01-14 983ac4b086 [dev.regabi] cmd/compile: fix ICE when initializing blank vars + 2021-01-13 7eb31d999c cmd/go: add hints to more missing sum error messages + 2021-01-13 d6d4673728 [dev.regabi] cmd/compile: fix GOEXPERIMENT=regabi builder + 2021-01-13 c41b999ad4 [dev.regabi] cmd/compile: refactor abiutils from "gc" into new "abi" + 2021-01-13 861707a8c8 [dev.regabi] cmd/compile: added limited //go:registerparams pragma for new ABI dev + 2021-01-13 c1370e918f [dev.regabi] cmd/compile: add code to support register ABI spills around morestack calls + 2021-01-13 2abd24f3b7 [dev.regabi] test: make run.go error messages slightly more informative + 2021-01-13 9a19481acb [dev.regabi] cmd/compile: make ordering for InvertFlags more stable + 2021-01-12 ba76567bc2 cmd/go/internal/modload: delete unused *mvsReqs.next method + 2021-01-12 665def2c11 encoding/asn1: document unmarshaling behavior for IMPLICIT string fields + 2021-01-11 81ea89adf3 cmd/go: fix non-script staleness checks interacting badly with GOFLAGS + 2021-01-11 759309029f doc: update editors.html for Go 1.16 + 2021-01-11 c3b4c7093a cmd/internal/objfile: don't require runtime.symtab symbol for XCOFF + 2021-01-08 59bfc18e34 cmd/go: add hint to read 'go help vcs' to GOVCS errors + 2021-01-08 cd6f3a54e4 cmd/go: revise 'go help' documentation for modules + 2021-01-08 6192b98751 cmd/go: make hints in error messages more consistent + 2021-01-08 25886cf4bd cmd/go: preserve sums for indirect deps fetched by 'go mod download' + 2021-01-08 6250833911 runtime/metrics: mark histogram metrics as cumulative + 2021-01-08 8f6a9acbb3 runtime/metrics: remove unused StopTheWorld Description field + 2021-01-08 6598c65646 cmd/compile: fix exponential-time init-cycle reporting + 2021-01-08 fefad1dc85 test: fix timeout code for invoking compiler + 2021-01-08 6728118e0a cmd/go: pass signals forward during "go tool" + 2021-01-08 e65c543f3c go/build/constraint: add parser for build tag constraint expressions + 2021-01-08 0c5afc4fb7 testing/fstest,os: clarify racy behavior of TestFS + 2021-01-08 32afcc9436 runtime/metrics: change unit on *-by-size metrics to match bucket unit + 2021-01-08 c6513bca5a io/fs: minor corrections to Glob doc + 2021-01-08 304f769ffc cmd/compile: don't short-circuit copies whose source is volatile + 2021-01-08 ae97717133 runtime,runtime/metrics: use explicit histogram boundaries + 2021-01-08 a9ccd2d795 go/build: skip string literal while findEmbed + 2021-01-08 d92f8add32 archive/tar: fix typo in comment + 2021-01-08 cab1202183 cmd/link: accept extra blocks in TestFallocate + 2021-01-08 ee4d32249b io/fs: minor corrections to Glob release date + 2021-01-08 54bd1ccce2 cmd: update to latest golang.org/x/tools + 2021-01-07 9ec21a8f34 Revert "reflect: support multiple keys in struct tags" + 2021-01-07 091414b5b7 io/fs: correct WalkDirFunc documentation + 2021-01-07 9b55088d6b doc/go1.16: add release note for disallowing non-ASCII import paths + 2021-01-07 fa90aaca7d cmd/compile: fix late expand_calls leaf type for OpStructSelect/OpArraySelect + 2021-01-07 7cee66d4cb cmd/go: add documentation for Embed fields in go list output + 2021-01-07 e60cffa4ca html/template: attach functions to namespace + 2021-01-07 6da2d3b7d7 cmd/link: fix typo in asm.go + 2021-01-07 df81a15819 runtime: check mips64 VDSO clock_gettime return code + 2021-01-06 4787e906cf crypto/x509: rollback new CertificateRequest fields + 2021-01-06 c9658bee93 cmd/go: make module suggestion more friendly + 2021-01-06 4c668b25c6 runtime/metrics: fix panic message for Float64Histogram + 2021-01-06 d2131704a6 net/http/httputil: fix deadlock in DumpRequestOut + 2021-01-05 3e1e13ce6d cmd/go: set cfg.BuildMod to "readonly" by default with no module root + 2021-01-05 0b0d004983 cmd/go: pass embedcfg to gccgo if supported + 2021-01-05 1b85e7c057 cmd/go: don't scan gccgo standard library packages for imports + 2021-01-05 6b37b15d95 runtime: don't take allglock in tracebackothers + 2021-01-04 9eef49cfa6 math/rand: fix typo in comment + 2021-01-04 b01fb2af9e testing/fstest: fix typo in error message + 2021-01-01 3dd5867605 doc: 2021 is the Year of the Gopher + 2020-12-31 95ce805d14 io/fs: remove darwin/arm64 special condition + 2020-12-30 20d0991b86 lib/time, time/tzdata: update tzdata to 2020f + 2020-12-30 ed301733bb misc/cgo/testcarchive: remove special flags for Darwin/ARM + 2020-12-30 0ae2e032f2 misc/cgo/test: enable TestCrossPackageTests on darwin/arm64 + 2020-12-29 780b4de16b misc/ios: fix wording for command line instructions + 2020-12-29 b4a71c95d2 doc/go1.16: reference misc/ios/README for how to build iOS programs + 2020-12-29 f83e0f6616 misc/ios: add to README how to build ios executables + 2020-12-28 4fd9455882 io/fs: fix typo in comment Change-Id: If24bb93f1e1e7deb1d92ba223c85940ab93b2732
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/api/goapi.go2
-rw-r--r--src/cmd/api/run.go2
-rw-r--r--src/cmd/asm/internal/asm/parse.go2
-rw-r--r--src/cmd/cgo/gcc.go7
-rw-r--r--src/cmd/cgo/out.go6
-rw-r--r--src/cmd/cgo/util.go6
-rw-r--r--src/cmd/compile/internal/abi/abiutils.go (renamed from src/cmd/compile/internal/gc/abiutils.go)42
-rw-r--r--src/cmd/compile/internal/arm64/ssa.go20
-rw-r--r--src/cmd/compile/internal/base/base.go4
-rw-r--r--src/cmd/compile/internal/base/flag.go2
-rw-r--r--src/cmd/compile/internal/base/link.go36
-rw-r--r--src/cmd/compile/internal/base/print.go2
-rw-r--r--src/cmd/compile/internal/bitvec/bv.go2
-rw-r--r--src/cmd/compile/internal/deadcode/deadcode.go2
-rw-r--r--src/cmd/compile/internal/dwarfgen/dwarf.go36
-rw-r--r--src/cmd/compile/internal/escape/escape.go192
-rw-r--r--src/cmd/compile/internal/gc/compile.go21
-rw-r--r--src/cmd/compile/internal/gc/main.go24
-rw-r--r--src/cmd/compile/internal/gc/obj.go6
-rw-r--r--src/cmd/compile/internal/inline/inl.go372
-rw-r--r--src/cmd/compile/internal/ir/const.go2
-rw-r--r--src/cmd/compile/internal/ir/expr.go47
-rw-r--r--src/cmd/compile/internal/ir/fmt.go52
-rw-r--r--src/cmd/compile/internal/ir/func.go9
-rw-r--r--src/cmd/compile/internal/ir/mini.go7
-rw-r--r--src/cmd/compile/internal/ir/name.go48
-rw-r--r--src/cmd/compile/internal/ir/node.go41
-rw-r--r--src/cmd/compile/internal/ir/node_gen.go65
-rw-r--r--src/cmd/compile/internal/ir/op_string.go143
-rw-r--r--src/cmd/compile/internal/ir/sizeof_test.go2
-rw-r--r--src/cmd/compile/internal/ir/stmt.go34
-rw-r--r--src/cmd/compile/internal/ir/symtab.go20
-rw-r--r--src/cmd/compile/internal/liveness/bvset.go2
-rw-r--r--src/cmd/compile/internal/liveness/plive.go59
-rw-r--r--src/cmd/compile/internal/noder/decl.go8
-rw-r--r--src/cmd/compile/internal/noder/import.go2
-rw-r--r--src/cmd/compile/internal/noder/lex.go3
-rw-r--r--src/cmd/compile/internal/noder/noder.go42
-rw-r--r--src/cmd/compile/internal/objw/prog.go2
-rw-r--r--src/cmd/compile/internal/pkginit/init.go4
-rw-r--r--src/cmd/compile/internal/pkginit/initorder.go18
-rw-r--r--src/cmd/compile/internal/reflectdata/alg.go2
-rw-r--r--src/cmd/compile/internal/reflectdata/reflect.go147
-rw-r--r--src/cmd/compile/internal/ssa/deadstore.go22
-rw-r--r--src/cmd/compile/internal/ssa/expand_calls.go81
-rw-r--r--src/cmd/compile/internal/ssa/func.go9
-rw-r--r--src/cmd/compile/internal/ssa/gen/386.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/AMD64.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/ARM.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/ARM64.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/ARM64Ops.go32
-rw-r--r--src/cmd/compile/internal/ssa/gen/PPC64.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/S390X.rules2
-rw-r--r--src/cmd/compile/internal/ssa/gen/generic.rules4
-rw-r--r--src/cmd/compile/internal/ssa/html.go2
-rw-r--r--src/cmd/compile/internal/ssa/location.go26
-rw-r--r--src/cmd/compile/internal/ssa/op.go10
-rw-r--r--src/cmd/compile/internal/ssa/opGen.go40
-rw-r--r--src/cmd/compile/internal/ssa/rewrite.go43
-rw-r--r--src/cmd/compile/internal/ssa/rewrite386.go12
-rw-r--r--src/cmd/compile/internal/ssa/rewriteAMD64.go16
-rw-r--r--src/cmd/compile/internal/ssa/rewriteARM.go4
-rw-r--r--src/cmd/compile/internal/ssa/rewriteARM64.go8
-rw-r--r--src/cmd/compile/internal/ssa/rewritePPC64.go16
-rw-r--r--src/cmd/compile/internal/ssa/rewriteS390X.go16
-rw-r--r--src/cmd/compile/internal/ssa/rewritegeneric.go8
-rw-r--r--src/cmd/compile/internal/ssagen/abi.go14
-rw-r--r--src/cmd/compile/internal/ssagen/nowb.go4
-rw-r--r--src/cmd/compile/internal/ssagen/pgen.go2
-rw-r--r--src/cmd/compile/internal/ssagen/ssa.go465
-rw-r--r--src/cmd/compile/internal/staticdata/data.go70
-rw-r--r--src/cmd/compile/internal/staticdata/embed.go58
-rw-r--r--src/cmd/compile/internal/staticinit/sched.go60
-rw-r--r--src/cmd/compile/internal/test/abiutils_test.go (renamed from src/cmd/compile/internal/gc/abiutils_test.go)10
-rw-r--r--src/cmd/compile/internal/test/abiutilsaux_test.go (renamed from src/cmd/compile/internal/gc/abiutilsaux_test.go)19
-rw-r--r--src/cmd/compile/internal/test/testdata/reproducible/issue38068.go2
-rw-r--r--src/cmd/compile/internal/typebits/typebits.go12
-rw-r--r--src/cmd/compile/internal/typecheck/const.go2
-rw-r--r--src/cmd/compile/internal/typecheck/dcl.go12
-rw-r--r--src/cmd/compile/internal/typecheck/expr.go6
-rw-r--r--src/cmd/compile/internal/typecheck/func.go44
-rw-r--r--src/cmd/compile/internal/typecheck/iexport.go52
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go92
-rw-r--r--src/cmd/compile/internal/typecheck/stmt.go8
-rw-r--r--src/cmd/compile/internal/typecheck/subr.go10
-rw-r--r--src/cmd/compile/internal/typecheck/syms.go15
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go16
-rw-r--r--src/cmd/compile/internal/types/alg.go4
-rw-r--r--src/cmd/compile/internal/types/fmt.go2
-rw-r--r--src/cmd/compile/internal/types/size.go41
-rw-r--r--src/cmd/compile/internal/types/sym.go47
-rw-r--r--src/cmd/compile/internal/types/type.go4
-rw-r--r--src/cmd/compile/internal/types2/stdlib_test.go2
-rw-r--r--src/cmd/compile/internal/walk/assign.go55
-rw-r--r--src/cmd/compile/internal/walk/builtin.go37
-rw-r--r--src/cmd/compile/internal/walk/closure.go2
-rw-r--r--src/cmd/compile/internal/walk/compare.go4
-rw-r--r--src/cmd/compile/internal/walk/complit.go46
-rw-r--r--src/cmd/compile/internal/walk/convert.go42
-rw-r--r--src/cmd/compile/internal/walk/expr.go60
-rw-r--r--src/cmd/compile/internal/walk/order.go97
-rw-r--r--src/cmd/compile/internal/walk/race.go9
-rw-r--r--src/cmd/compile/internal/walk/range.go24
-rw-r--r--src/cmd/compile/internal/walk/select.go15
-rw-r--r--src/cmd/compile/internal/walk/stmt.go23
-rw-r--r--src/cmd/compile/internal/walk/switch.go7
-rw-r--r--src/cmd/compile/internal/walk/temp.go40
-rw-r--r--src/cmd/compile/internal/walk/walk.go300
-rw-r--r--src/cmd/cover/func.go2
-rw-r--r--src/cmd/cover/testdata/toolexec.go2
-rw-r--r--src/cmd/dist/buildtool.go4
-rw-r--r--src/cmd/doc/dirs.go2
-rw-r--r--src/cmd/fix/typecheck.go2
-rw-r--r--src/cmd/go.mod4
-rw-r--r--src/cmd/go.sum8
-rw-r--r--src/cmd/go/alldocs.go862
-rw-r--r--src/cmd/go/go_test.go5
-rw-r--r--src/cmd/go/internal/base/base.go2
-rw-r--r--src/cmd/go/internal/bug/bug.go2
-rw-r--r--src/cmd/go/internal/fmtcmd/fmt.go3
-rw-r--r--src/cmd/go/internal/generate/generate.go20
-rw-r--r--src/cmd/go/internal/get/get.go2
-rw-r--r--src/cmd/go/internal/help/helpdoc.go19
-rw-r--r--src/cmd/go/internal/list/list.go12
-rw-r--r--src/cmd/go/internal/load/pkg.go134
-rw-r--r--src/cmd/go/internal/load/test.go8
-rw-r--r--src/cmd/go/internal/modcmd/download.go4
-rw-r--r--src/cmd/go/internal/modcmd/edit.go4
-rw-r--r--src/cmd/go/internal/modcmd/graph.go2
-rw-r--r--src/cmd/go/internal/modcmd/init.go2
-rw-r--r--src/cmd/go/internal/modcmd/tidy.go2
-rw-r--r--src/cmd/go/internal/modcmd/vendor.go78
-rw-r--r--src/cmd/go/internal/modcmd/verify.go2
-rw-r--r--src/cmd/go/internal/modcmd/why.go2
-rw-r--r--src/cmd/go/internal/modfetch/codehost/codehost.go2
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git.go2
-rw-r--r--src/cmd/go/internal/modfetch/fetch.go108
-rw-r--r--src/cmd/go/internal/modfetch/proxy.go61
-rw-r--r--src/cmd/go/internal/modget/get.go127
-rw-r--r--src/cmd/go/internal/modget/query.go4
-rw-r--r--src/cmd/go/internal/modload/help.go484
-rw-r--r--src/cmd/go/internal/modload/import.go82
-rw-r--r--src/cmd/go/internal/modload/import_test.go13
-rw-r--r--src/cmd/go/internal/modload/init.go75
-rw-r--r--src/cmd/go/internal/modload/load.go31
-rw-r--r--src/cmd/go/internal/modload/modfile.go4
-rw-r--r--src/cmd/go/internal/modload/mvs.go16
-rw-r--r--src/cmd/go/internal/modload/vendor.go2
-rw-r--r--src/cmd/go/internal/test/genflags.go2
-rw-r--r--src/cmd/go/internal/test/test.go2
-rw-r--r--src/cmd/go/internal/test/testflag.go2
-rw-r--r--src/cmd/go/internal/tool/tool.go17
-rw-r--r--src/cmd/go/internal/vcs/vcs.go4
-rw-r--r--src/cmd/go/internal/vet/vetflag.go2
-rw-r--r--src/cmd/go/internal/work/action.go3
-rw-r--r--src/cmd/go/internal/work/build.go7
-rw-r--r--src/cmd/go/internal/work/buildid.go2
-rw-r--r--src/cmd/go/internal/work/exec.go44
-rw-r--r--src/cmd/go/internal/work/gccgo.go8
-rw-r--r--src/cmd/go/testdata/addmod.go2
-rw-r--r--src/cmd/go/testdata/script/build_darwin_cc_arch.txt24
-rw-r--r--src/cmd/go/testdata/script/cgo_path.txt35
-rw-r--r--src/cmd/go/testdata/script/embed.txt45
-rw-r--r--src/cmd/go/testdata/script/embed_fmt.txt22
-rw-r--r--src/cmd/go/testdata/script/govcs.txt52
-rw-r--r--src/cmd/go/testdata/script/mod_bad_domain.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_edit.txt6
-rw-r--r--src/cmd/go/testdata/script/mod_get_fallback.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_get_promote_implicit.txt10
-rw-r--r--src/cmd/go/testdata/script/mod_get_replaced.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_get_retract.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_gobuild_import.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_init_tidy.txt4
-rw-r--r--src/cmd/go/testdata/script/mod_install_pkg_version.txt11
-rw-r--r--src/cmd/go/testdata/script/mod_invalid_path.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_list_bad_import.txt2
-rw-r--r--src/cmd/go/testdata/script/mod_readonly.txt10
-rw-r--r--src/cmd/go/testdata/script/mod_replace_readonly.txt6
-rw-r--r--src/cmd/go/testdata/script/mod_sum_ambiguous.txt22
-rw-r--r--src/cmd/go/testdata/script/mod_sum_readonly.txt12
-rw-r--r--src/cmd/go/testdata/script/mod_vendor_auto.txt6
-rw-r--r--src/cmd/go/testdata/script/mod_vendor_embed.txt179
-rw-r--r--src/cmd/go/testdata/script/mod_versions.txt6
-rw-r--r--src/cmd/go/testdata/script/test_exit.txt17
-rw-r--r--src/cmd/go/testdata/script/test_flag.txt6
-rw-r--r--src/cmd/internal/browser/browser.go2
-rw-r--r--src/cmd/internal/diff/diff.go2
-rw-r--r--src/cmd/internal/dwarf/dwarf.go2
-rw-r--r--src/cmd/internal/goobj/mkbuiltin.go4
-rw-r--r--src/cmd/internal/moddeps/moddeps_test.go400
-rw-r--r--src/cmd/internal/obj/link.go38
-rw-r--r--src/cmd/internal/obj/textflag.go2
-rw-r--r--src/cmd/internal/obj/x86/obj6.go10
-rw-r--r--src/cmd/internal/objfile/xcoff.go4
-rw-r--r--src/cmd/internal/pkgpath/pkgpath.go2
-rw-r--r--src/cmd/link/internal/arm64/asm.go2
-rw-r--r--src/cmd/link/internal/ld/data.go4
-rw-r--r--src/cmd/link/internal/ld/execarchive.go2
-rw-r--r--src/cmd/link/internal/ld/fallocate_test.go8
-rw-r--r--src/cmd/link/internal/ld/lib.go14
-rw-r--r--src/cmd/link/internal/ld/main.go15
-rw-r--r--src/cmd/link/internal/ld/symtab.go2
-rw-r--r--src/cmd/link/link_test.go1
-rw-r--r--src/cmd/objdump/objdump_test.go5
-rw-r--r--src/cmd/test2json/main.go8
-rw-r--r--src/cmd/trace/pprof.go2
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/rule.go30
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/diagnostic.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/help.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go94
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go4
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go4
-rw-r--r--src/cmd/vendor/modules.txt4
219 files changed, 3550 insertions, 3669 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index ba42812fa6..efc2696f8f 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -16,10 +16,10 @@ import (
"go/parser"
"go/token"
"go/types"
+ exec "internal/execabs"
"io"
"log"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go
index a36f1179c1..ecb1d0f81a 100644
--- a/src/cmd/api/run.go
+++ b/src/cmd/api/run.go
@@ -10,9 +10,9 @@ package main
import (
"fmt"
+ exec "internal/execabs"
"log"
"os"
- "os/exec"
"path/filepath"
"runtime"
"strings"
diff --git a/src/cmd/asm/internal/asm/parse.go b/src/cmd/asm/internal/asm/parse.go
index 154cf9c7a7..f1d37bc2c8 100644
--- a/src/cmd/asm/internal/asm/parse.go
+++ b/src/cmd/asm/internal/asm/parse.go
@@ -305,7 +305,7 @@ func (p *Parser) pseudo(word string, operands [][]lex.Token) bool {
// references and writes symabis information to w.
//
// The symabis format is documented at
-// cmd/compile/internal/gc.readSymABIs.
+// cmd/compile/internal/ssagen.ReadSymABIs.
func (p *Parser) symDefRef(w io.Writer, word string, operands [][]lex.Token) {
switch word {
case "TEXT":
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 111a309eb5..b5e28e3254 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -1549,7 +1549,14 @@ func (p *Package) gccBaseCmd() []string {
func (p *Package) gccMachine() []string {
switch goarch {
case "amd64":
+ if goos == "darwin" {
+ return []string{"-arch", "x86_64", "-m64"}
+ }
return []string{"-m64"}
+ case "arm64":
+ if goos == "darwin" {
+ return []string{"-arch", "arm64"}
+ }
case "386":
return []string{"-m32"}
case "arm":
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go
index 11c53facf8..8e83f02202 100644
--- a/src/cmd/cgo/out.go
+++ b/src/cmd/cgo/out.go
@@ -14,10 +14,10 @@ import (
"go/ast"
"go/printer"
"go/token"
+ exec "internal/execabs"
"internal/xcoff"
"io"
"os"
- "os/exec"
"path/filepath"
"regexp"
"sort"
@@ -953,9 +953,9 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
// Build the wrapper function compiled by gcc.
gccExport := ""
if goos == "windows" {
- gccExport = "__declspec(dllexport)"
+ gccExport = "__declspec(dllexport) "
}
- s := fmt.Sprintf("%s %s %s(", gccExport, gccResult, exp.ExpName)
+ s := fmt.Sprintf("%s%s %s(", gccExport, gccResult, exp.ExpName)
if fn.Recv != nil {
s += p.cgoType(fn.Recv.List[0].Type).C.String()
s += " recv"
diff --git a/src/cmd/cgo/util.go b/src/cmd/cgo/util.go
index 921306b7aa..00d931b98a 100644
--- a/src/cmd/cgo/util.go
+++ b/src/cmd/cgo/util.go
@@ -8,9 +8,9 @@ import (
"bytes"
"fmt"
"go/token"
+ exec "internal/execabs"
"io/ioutil"
"os"
- "os/exec"
)
// run runs the command argv, feeding in stdin on standard input.
@@ -63,7 +63,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
p.Env = append(os.Environ(), "TERM=dumb")
err := p.Run()
if _, ok := err.(*exec.ExitError); err != nil && !ok {
- fatalf("%s", err)
+ fatalf("exec %s: %s", argv[0], err)
}
ok = p.ProcessState.Success()
stdout, stderr = bout.Bytes(), berr.Bytes()
@@ -88,7 +88,7 @@ func fatalf(msg string, args ...interface{}) {
// If we've already printed other errors, they might have
// caused the fatal condition. Assume they're enough.
if nerrors == 0 {
- fmt.Fprintf(os.Stderr, msg+"\n", args...)
+ fmt.Fprintf(os.Stderr, "cgo: "+msg+"\n", args...)
}
os.Exit(2)
}
diff --git a/src/cmd/compile/internal/gc/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go
index 5822c088f9..3ac59e6f75 100644
--- a/src/cmd/compile/internal/gc/abiutils.go
+++ b/src/cmd/compile/internal/abi/abiutils.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package gc
+package abi
import (
"cmd/compile/internal/types"
@@ -28,7 +28,35 @@ type ABIParamResultInfo struct {
intSpillSlots int
floatSpillSlots int
offsetToSpillArea int64
- config ABIConfig // to enable String() method
+ config *ABIConfig // to enable String() method
+}
+
+func (a *ABIParamResultInfo) InParams() []ABIParamAssignment {
+ return a.inparams
+}
+
+func (a *ABIParamResultInfo) OutParams() []ABIParamAssignment {
+ return a.outparams
+}
+
+func (a *ABIParamResultInfo) InParam(i int) ABIParamAssignment {
+ return a.inparams[i]
+}
+
+func (a *ABIParamResultInfo) OutParam(i int) ABIParamAssignment {
+ return a.outparams[i]
+}
+
+func (a *ABIParamResultInfo) IntSpillCount() int {
+ return a.intSpillSlots
+}
+
+func (a *ABIParamResultInfo) FloatSpillCount() int {
+ return a.floatSpillSlots
+}
+
+func (a *ABIParamResultInfo) SpillAreaOffset() int64 {
+ return a.offsetToSpillArea
}
// RegIndex stores the index into the set of machine registers used by
@@ -66,11 +94,17 @@ type ABIConfig struct {
regAmounts RegAmounts
}
+// NewABIConfig returns a new ABI configuration for an architecture with
+// iRegsCount integer/pointer registers and fRegsCount floating point registers.
+func NewABIConfig(iRegsCount, fRegsCount int) *ABIConfig {
+ return &ABIConfig{RegAmounts{iRegsCount, fRegsCount}}
+}
+
// ABIAnalyze takes a function type 't' and an ABI rules description
// 'config' and analyzes the function to determine how its parameters
// and results will be passed (in registers or on the stack), returning
// an ABIParamResultInfo object that holds the results of the analysis.
-func ABIAnalyze(t *types.Type, config ABIConfig) ABIParamResultInfo {
+func ABIAnalyze(t *types.Type, config *ABIConfig) ABIParamResultInfo {
setup()
s := assignState{
rTotal: config.regAmounts,
@@ -124,7 +158,7 @@ func (c *RegAmounts) regString(r RegIndex) string {
// toString method renders an ABIParamAssignment in human-readable
// form, suitable for debugging or unit testing.
-func (ri *ABIParamAssignment) toString(config ABIConfig) string {
+func (ri *ABIParamAssignment) toString(config *ABIConfig) string {
regs := "R{"
for _, r := range ri.Registers {
regs += " " + config.regAmounts.regString(r)
diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go
index 8d25fa8592..73e74e1219 100644
--- a/src/cmd/compile/internal/arm64/ssa.go
+++ b/src/cmd/compile/internal/arm64/ssa.go
@@ -1056,7 +1056,11 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssa.OpARM64LessThanF,
ssa.OpARM64LessEqualF,
ssa.OpARM64GreaterThanF,
- ssa.OpARM64GreaterEqualF:
+ ssa.OpARM64GreaterEqualF,
+ ssa.OpARM64NotLessThanF,
+ ssa.OpARM64NotLessEqualF,
+ ssa.OpARM64NotGreaterThanF,
+ ssa.OpARM64NotGreaterEqualF:
// generate boolean values using CSET
p := s.Prog(arm64.ACSET)
p.From.Type = obj.TYPE_REG // assembler encodes conditional bits in Reg
@@ -1100,10 +1104,16 @@ var condBits = map[ssa.Op]int16{
ssa.OpARM64GreaterThanU: arm64.COND_HI,
ssa.OpARM64GreaterEqual: arm64.COND_GE,
ssa.OpARM64GreaterEqualU: arm64.COND_HS,
- ssa.OpARM64LessThanF: arm64.COND_MI,
- ssa.OpARM64LessEqualF: arm64.COND_LS,
- ssa.OpARM64GreaterThanF: arm64.COND_GT,
- ssa.OpARM64GreaterEqualF: arm64.COND_GE,
+ ssa.OpARM64LessThanF: arm64.COND_MI, // Less than
+ ssa.OpARM64LessEqualF: arm64.COND_LS, // Less than or equal to
+ ssa.OpARM64GreaterThanF: arm64.COND_GT, // Greater than
+ ssa.OpARM64GreaterEqualF: arm64.COND_GE, // Greater than or equal to
+
+ // The following condition codes have unordered to handle comparisons related to NaN.
+ ssa.OpARM64NotLessThanF: arm64.COND_PL, // Greater than, equal to, or unordered
+ ssa.OpARM64NotLessEqualF: arm64.COND_HI, // Greater than or unordered
+ ssa.OpARM64NotGreaterThanF: arm64.COND_LE, // Less than, equal to or unordered
+ ssa.OpARM64NotGreaterEqualF: arm64.COND_LT, // Less than or unordered
}
var blockJump = map[ssa.BlockKind]struct {
diff --git a/src/cmd/compile/internal/base/base.go b/src/cmd/compile/internal/base/base.go
index 5a30fa6a33..3b9bc3a8af 100644
--- a/src/cmd/compile/internal/base/base.go
+++ b/src/cmd/compile/internal/base/base.go
@@ -6,12 +6,8 @@ package base
import (
"os"
-
- "cmd/internal/obj"
)
-var Ctxt *obj.Link
-
var atExitFuncs []func()
func AtExit(f func()) {
diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go
index 3602fb947d..d8ca9885cb 100644
--- a/src/cmd/compile/internal/base/flag.go
+++ b/src/cmd/compile/internal/base/flag.go
@@ -175,7 +175,7 @@ func ParseFlags() {
if (*Flag.Shared || *Flag.Dynlink || *Flag.LinkShared) && !Ctxt.Arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.PPC64, sys.RISCV64, sys.S390X) {
log.Fatalf("%s/%s does not support -shared", objabi.GOOS, objabi.GOARCH)
}
- parseSpectre(Flag.Spectre) // left as string for recordFlags
+ parseSpectre(Flag.Spectre) // left as string for RecordFlags
Ctxt.Flag_shared = Ctxt.Flag_dynlink || Ctxt.Flag_shared
Ctxt.Flag_optimize = Flag.N == 0
diff --git a/src/cmd/compile/internal/base/link.go b/src/cmd/compile/internal/base/link.go
new file mode 100644
index 0000000000..49fe4352b2
--- /dev/null
+++ b/src/cmd/compile/internal/base/link.go
@@ -0,0 +1,36 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import (
+ "cmd/internal/obj"
+)
+
+var Ctxt *obj.Link
+
+// TODO(mdempsky): These should probably be obj.Link methods.
+
+// PkgLinksym returns the linker symbol for name within the given
+// package prefix. For user packages, prefix should be the package
+// path encoded with objabi.PathToPrefix.
+func PkgLinksym(prefix, name string, abi obj.ABI) *obj.LSym {
+ if name == "_" {
+ // TODO(mdempsky): Cleanup callers and Fatalf instead.
+ return linksym(prefix, "_", abi)
+ }
+ return linksym(prefix, prefix+"."+name, abi)
+}
+
+// Linkname returns the linker symbol for the given name as it might
+// appear within a //go:linkname directive.
+func Linkname(name string, abi obj.ABI) *obj.LSym {
+ return linksym("_", name, abi)
+}
+
+// linksym is an internal helper function for implementing the above
+// exported APIs.
+func linksym(pkg, name string, abi obj.ABI) *obj.LSym {
+ return Ctxt.LookupABIInit(name, abi, func(r *obj.LSym) { r.Pkg = pkg })
+}
diff --git a/src/cmd/compile/internal/base/print.go b/src/cmd/compile/internal/base/print.go
index 9855dfdad0..668c600d31 100644
--- a/src/cmd/compile/internal/base/print.go
+++ b/src/cmd/compile/internal/base/print.go
@@ -121,7 +121,7 @@ func ErrorfAt(pos src.XPos, format string, args ...interface{}) {
lasterror.syntax = pos
} else {
// only one of multiple equal non-syntax errors per line
- // (flusherrors shows only one of them, so we filter them
+ // (FlushErrors shows only one of them, so we filter them
// here as best as we can (they may not appear in order)
// so that we don't count them here and exit early, and
// then have nothing to show for.)
diff --git a/src/cmd/compile/internal/bitvec/bv.go b/src/cmd/compile/internal/bitvec/bv.go
index 1e084576d1..bcac1fe351 100644
--- a/src/cmd/compile/internal/bitvec/bv.go
+++ b/src/cmd/compile/internal/bitvec/bv.go
@@ -37,7 +37,7 @@ func NewBulk(nbit int32, count int32) Bulk {
nword := (nbit + wordBits - 1) / wordBits
size := int64(nword) * int64(count)
if int64(int32(size*4)) != size*4 {
- base.Fatalf("bvbulkalloc too big: nbit=%d count=%d nword=%d size=%d", nbit, count, nword, size)
+ base.Fatalf("NewBulk too big: nbit=%d count=%d nword=%d size=%d", nbit, count, nword, size)
}
return Bulk{
words: make([]uint32, size),
diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go
index c409320fc4..520203787f 100644
--- a/src/cmd/compile/internal/deadcode/deadcode.go
+++ b/src/cmd/compile/internal/deadcode/deadcode.go
@@ -75,7 +75,7 @@ func stmts(nn *ir.Nodes) {
// might be the target of a goto. See issue 28616.
if body := body; len(body) != 0 {
switch body[(len(body) - 1)].Op() {
- case ir.ORETURN, ir.ORETJMP, ir.OPANIC:
+ case ir.ORETURN, ir.OTAILCALL, ir.OPANIC:
if i > lastLabel {
cut = true
}
diff --git a/src/cmd/compile/internal/dwarfgen/dwarf.go b/src/cmd/compile/internal/dwarfgen/dwarf.go
index ff249c1f4e..dd22c033cc 100644
--- a/src/cmd/compile/internal/dwarfgen/dwarf.go
+++ b/src/cmd/compile/internal/dwarfgen/dwarf.go
@@ -28,7 +28,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
if fn.Nname != nil {
expect := fn.Linksym()
if fnsym.ABI() == obj.ABI0 {
- expect = fn.Sym().LinksymABI0()
+ expect = fn.LinksymABI(obj.ABI0)
}
if fnsym != expect {
base.Fatalf("unexpected fnsym: %v != %v", fnsym, expect)
@@ -136,7 +136,7 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
// Collect a raw list of DWARF vars.
var vars []*dwarf.Var
var decls []*ir.Name
- var selected map[*ir.Name]bool
+ var selected ir.NameSet
if base.Ctxt.Flag_locationlists && base.Ctxt.Flag_optimize && fn.DebugInfo != nil && complexOK {
decls, vars, selected = createComplexVars(fnsym, fn)
} else {
@@ -161,7 +161,7 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
// For non-SSA-able arguments, however, the correct information
// is known -- they have a single home on the stack.
for _, n := range dcl {
- if _, found := selected[n]; found {
+ if selected.Has(n) {
continue
}
c := n.Sym().Name[0]
@@ -186,19 +186,11 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
isReturnValue := (n.Class == ir.PPARAMOUT)
if n.Class == ir.PPARAM || n.Class == ir.PPARAMOUT {
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
- } else if n.Class == ir.PAUTOHEAP {
- // If dcl in question has been promoted to heap, do a bit
- // of extra work to recover original class (auto or param);
- // see issue 30908. This insures that we get the proper
- // signature in the abstract function DIE, but leaves a
- // misleading location for the param (we want pointer-to-heap
- // and not stack).
+ }
+ if n.Esc() == ir.EscHeap {
+ // The variable in question has been promoted to the heap.
+ // Its address is in n.Heapaddr.
// TODO(thanm): generate a better location expression
- stackcopy := n.Stackcopy
- if stackcopy != nil && (stackcopy.Class == ir.PPARAM || stackcopy.Class == ir.PPARAMOUT) {
- abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
- isReturnValue = (stackcopy.Class == ir.PPARAMOUT)
- }
}
inlIndex := 0
if base.Flag.GenDwarfInl > 1 {
@@ -252,10 +244,10 @@ func preInliningDcls(fnsym *obj.LSym) []*ir.Name {
// createSimpleVars creates a DWARF entry for every variable declared in the
// function, claiming that they are permanently on the stack.
-func createSimpleVars(fnsym *obj.LSym, apDecls []*ir.Name) ([]*ir.Name, []*dwarf.Var, map[*ir.Name]bool) {
+func createSimpleVars(fnsym *obj.LSym, apDecls []*ir.Name) ([]*ir.Name, []*dwarf.Var, ir.NameSet) {
var vars []*dwarf.Var
var decls []*ir.Name
- selected := make(map[*ir.Name]bool)
+ var selected ir.NameSet
for _, n := range apDecls {
if ir.IsAutoTmp(n) {
continue
@@ -263,7 +255,7 @@ func createSimpleVars(fnsym *obj.LSym, apDecls []*ir.Name) ([]*ir.Name, []*dwarf
decls = append(decls, n)
vars = append(vars, createSimpleVar(fnsym, n))
- selected[n] = true
+ selected.Add(n)
}
return decls, vars, selected
}
@@ -320,19 +312,19 @@ func createSimpleVar(fnsym *obj.LSym, n *ir.Name) *dwarf.Var {
// createComplexVars creates recomposed DWARF vars with location lists,
// suitable for describing optimized code.
-func createComplexVars(fnsym *obj.LSym, fn *ir.Func) ([]*ir.Name, []*dwarf.Var, map[*ir.Name]bool) {
+func createComplexVars(fnsym *obj.LSym, fn *ir.Func) ([]*ir.Name, []*dwarf.Var, ir.NameSet) {
debugInfo := fn.DebugInfo.(*ssa.FuncDebug)
// Produce a DWARF variable entry for each user variable.
var decls []*ir.Name
var vars []*dwarf.Var
- ssaVars := make(map[*ir.Name]bool)
+ var ssaVars ir.NameSet
for varID, dvar := range debugInfo.Vars {
n := dvar
- ssaVars[n] = true
+ ssaVars.Add(n)
for _, slot := range debugInfo.VarSlots[varID] {
- ssaVars[debugInfo.Slots[slot].N] = true
+ ssaVars.Add(debugInfo.Slots[slot].N)
}
if dvar := createComplexVar(fnsym, fn, ssa.VarID(varID)); dvar != nil {
diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go
index bee3878f10..883e68a730 100644
--- a/src/cmd/compile/internal/escape/escape.go
+++ b/src/cmd/compile/internal/escape/escape.go
@@ -218,6 +218,10 @@ func Batch(fns []*ir.Func, recursive bool) {
// Construct data-flow graph from syntax trees.
for _, fn := range fns {
+ if base.Flag.W > 1 {
+ s := fmt.Sprintf("\nbefore escape %v", fn)
+ ir.Dump(s, fn)
+ }
b.initFunc(fn)
}
for _, fn := range fns {
@@ -534,8 +538,8 @@ func (e *escape) stmt(n ir.Node) {
e.stmts(n.Call.Init())
e.call(nil, n.Call, n)
- case ir.ORETJMP:
- // TODO(mdempsky): What do? esc.go just ignores it.
+ case ir.OTAILCALL:
+ // TODO(mdempsky): Treat like a normal call? esc.go used to just ignore it.
}
}
@@ -585,7 +589,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
default:
base.Fatalf("unexpected expr: %v", n)
- case ir.OLITERAL, ir.ONIL, ir.OGETG, ir.OTYPE, ir.OMETHEXPR:
+ case ir.OLITERAL, ir.ONIL, ir.OGETG, ir.OTYPE, ir.OMETHEXPR, ir.OLINKSYMOFFSET:
// nop
case ir.ONAME:
@@ -598,10 +602,6 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
}
e.flow(k, e.oldLoc(n))
- case ir.ONAMEOFFSET:
- n := n.(*ir.NameOffsetExpr)
- e.expr(k, n.Name_)
-
case ir.OPLUS, ir.ONEG, ir.OBITNOT, ir.ONOT:
n := n.(*ir.UnaryExpr)
e.discard(n.X)
@@ -856,7 +856,7 @@ func (e *escape) discards(l ir.Nodes) {
}
}
-// addr evaluates an addressable expression n and returns an EscHole
+// addr evaluates an addressable expression n and returns a hole
// that represents storing into the represented location.
func (e *escape) addr(n ir.Node) hole {
if n == nil || ir.IsBlank(n) {
@@ -875,9 +875,8 @@ func (e *escape) addr(n ir.Node) hole {
break
}
k = e.oldLoc(n).asHole()
- case ir.ONAMEOFFSET:
- n := n.(*ir.NameOffsetExpr)
- k = e.addr(n.Name_)
+ case ir.OLINKSYMOFFSET:
+ break
case ir.ODOT:
n := n.(*ir.SelectorExpr)
k = e.addr(n.X)
@@ -1658,7 +1657,14 @@ func (b *batch) finish(fns []*ir.Func) {
// Update n.Esc based on escape analysis results.
if loc.escapes {
- if n.Op() != ir.ONAME {
+ if n.Op() == ir.ONAME {
+ if base.Flag.CompilingRuntime {
+ base.ErrorfAt(n.Pos(), "%v escapes to heap, not allowed in runtime", n)
+ }
+ if base.Flag.LowerM != 0 {
+ base.WarnfAt(n.Pos(), "moved to heap: %v", n)
+ }
+ } else {
if base.Flag.LowerM != 0 {
base.WarnfAt(n.Pos(), "%v escapes to heap", n)
}
@@ -1668,7 +1674,6 @@ func (b *batch) finish(fns []*ir.Func) {
}
}
n.SetEsc(ir.EscHeap)
- addrescapes(n)
} else {
if base.Flag.LowerM != 0 && n.Op() != ir.ONAME {
base.WarnfAt(n.Pos(), "%v does not escape", n)
@@ -1779,7 +1784,7 @@ func (l leaks) Encode() string {
return s
}
-// parseLeaks parses a binary string representing an EscLeaks.
+// parseLeaks parses a binary string representing a leaks
func parseLeaks(s string) leaks {
var l leaks
if !strings.HasPrefix(s, "esc:") {
@@ -2014,165 +2019,6 @@ func HeapAllocReason(n ir.Node) string {
return ""
}
-// addrescapes tags node n as having had its address taken
-// by "increasing" the "value" of n.Esc to EscHeap.
-// Storage is allocated as necessary to allow the address
-// to be taken.
-func addrescapes(n ir.Node) {
- switch n.Op() {
- default:
- // Unexpected Op, probably due to a previous type error. Ignore.
-
- case ir.ODEREF, ir.ODOTPTR:
- // Nothing to do.
-
- case ir.ONAME:
- n := n.(*ir.Name)
- if n == ir.RegFP {
- break
- }
-
- // if this is a tmpname (PAUTO), it was tagged by tmpname as not escaping.
- // on PPARAM it means something different.
- if n.Class == ir.PAUTO && n.Esc() == ir.EscNever {
- break
- }
-
- // If a closure reference escapes, mark the outer variable as escaping.
- if n.IsClosureVar() {
- addrescapes(n.Defn)
- break
- }
-
- if n.Class != ir.PPARAM && n.Class != ir.PPARAMOUT && n.Class != ir.PAUTO {
- break
- }
-
- // This is a plain parameter or local variable that needs to move to the heap,
- // but possibly for the function outside the one we're compiling.
- // That is, if we have:
- //
- // func f(x int) {
- // func() {
- // global = &x
- // }
- // }
- //
- // then we're analyzing the inner closure but we need to move x to the
- // heap in f, not in the inner closure. Flip over to f before calling moveToHeap.
- oldfn := ir.CurFunc
- ir.CurFunc = n.Curfn
- ln := base.Pos
- base.Pos = ir.CurFunc.Pos()
- moveToHeap(n)
- ir.CurFunc = oldfn
- base.Pos = ln
-
- // ODOTPTR has already been introduced,
- // so these are the non-pointer ODOT and OINDEX.
- // In &x[0], if x is a slice, then x does not
- // escape--the pointer inside x does, but that
- // is always a heap pointer anyway.
- case ir.ODOT:
- n := n.(*ir.SelectorExpr)
- addrescapes(n.X)
- case ir.OINDEX:
- n := n.(*ir.IndexExpr)
- if !n.X.Type().IsSlice() {
- addrescapes(n.X)
- }
- case ir.OPAREN:
- n := n.(*ir.ParenExpr)
- addrescapes(n.X)
- case ir.OCONVNOP:
- n := n.(*ir.ConvExpr)
- addrescapes(n.X)
- }
-}
-
-// moveToHeap records the parameter or local variable n as moved to the heap.
-func moveToHeap(n *ir.Name) {
- if base.Flag.LowerR != 0 {
- ir.Dump("MOVE", n)
- }
- if base.Flag.CompilingRuntime {
- base.Errorf("%v escapes to heap, not allowed in runtime", n)
- }
- if n.Class == ir.PAUTOHEAP {
- ir.Dump("n", n)
- base.Fatalf("double move to heap")
- }
-
- // Allocate a local stack variable to hold the pointer to the heap copy.
- // temp will add it to the function declaration list automatically.
- heapaddr := typecheck.Temp(types.NewPtr(n.Type()))
- heapaddr.SetSym(typecheck.Lookup("&" + n.Sym().Name))
- heapaddr.SetPos(n.Pos())
-
- // Unset AutoTemp to persist the &foo variable name through SSA to
- // liveness analysis.
- // TODO(mdempsky/drchase): Cleaner solution?
- heapaddr.SetAutoTemp(false)
-
- // Parameters have a local stack copy used at function start/end
- // in addition to the copy in the heap that may live longer than
- // the function.
- if n.Class == ir.PPARAM || n.Class == ir.PPARAMOUT {
- if n.FrameOffset() == types.BADWIDTH {
- base.Fatalf("addrescapes before param assignment")
- }
-
- // We rewrite n below to be a heap variable (indirection of heapaddr).
- // Preserve a copy so we can still write code referring to the original,
- // and substitute that copy into the function declaration list
- // so that analyses of the local (on-stack) variables use it.
- stackcopy := typecheck.NewName(n.Sym())
- stackcopy.SetType(n.Type())
- stackcopy.SetFrameOffset(n.FrameOffset())
- stackcopy.Class = n.Class
- stackcopy.Heapaddr = heapaddr
- if n.Class == ir.PPARAMOUT {
- // Make sure the pointer to the heap copy is kept live throughout the function.
- // The function could panic at any point, and then a defer could recover.
- // Thus, we need the pointer to the heap copy always available so the
- // post-deferreturn code can copy the return value back to the stack.
- // See issue 16095.
- heapaddr.SetIsOutputParamHeapAddr(true)
- }
- n.Stackcopy = stackcopy
-
- // Substitute the stackcopy into the function variable list so that
- // liveness and other analyses use the underlying stack slot
- // and not the now-pseudo-variable n.
- found := false
- for i, d := range ir.CurFunc.Dcl {
- if d == n {
- ir.CurFunc.Dcl[i] = stackcopy
- found = true
- break
- }
- // Parameters are before locals, so can stop early.
- // This limits the search even in functions with many local variables.
- if d.Class == ir.PAUTO {
- break
- }
- }
- if !found {
- base.Fatalf("cannot find %v in local variable list", n)
- }
- ir.CurFunc.Dcl = append(ir.CurFunc.Dcl, n)
- }
-
- // Modify n in place so that uses of n now mean indirection of the heapaddr.
- n.Class = ir.PAUTOHEAP
- n.SetFrameOffset(0)
- n.Heapaddr = heapaddr
- n.SetEsc(ir.EscHeap)
- if base.Flag.LowerM != 0 {
- base.WarnfAt(n.Pos(), "moved to heap: %v", n)
- }
-}
-
// This special tag is applied to uintptr variables
// that we believe may hold unsafe.Pointers for
// calls into assembly functions.
diff --git a/src/cmd/compile/internal/gc/compile.go b/src/cmd/compile/internal/gc/compile.go
index 410b3e90ea..ba67c58c45 100644
--- a/src/cmd/compile/internal/gc/compile.go
+++ b/src/cmd/compile/internal/gc/compile.go
@@ -13,7 +13,6 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/liveness"
- "cmd/compile/internal/reflectdata"
"cmd/compile/internal/ssagen"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
@@ -73,7 +72,7 @@ func enqueueFunc(fn *ir.Func) {
func prepareFunc(fn *ir.Func) {
// Set up the function's LSym early to avoid data races with the assemblers.
// Do this before walk, as walk needs the LSym to set attributes/relocations
- // (e.g. in markTypeUsedInInterface).
+ // (e.g. in MarkTypeUsedInInterface).
ssagen.InitLSym(fn, true)
// Calculate parameter offsets.
@@ -84,24 +83,6 @@ func prepareFunc(fn *ir.Func) {
walk.Walk(fn)
ir.CurFunc = nil // enforce no further uses of CurFunc
typecheck.DeclContext = ir.PEXTERN
-
- // Make sure type syms are declared for all types that might
- // be types of stack objects. We need to do this here
- // because symbols must be allocated before the parallel
- // phase of the compiler.
- for _, n := range fn.Dcl {
- switch n.Class {
- case ir.PPARAM, ir.PPARAMOUT, ir.PAUTO:
- if liveness.ShouldTrack(n) && n.Addrtaken() {
- reflectdata.WriteType(n.Type())
- // Also make sure we allocate a linker symbol
- // for the stack object data, for the same reason.
- if fn.LSym.Func().StackObjects == nil {
- fn.LSym.Func().StackObjects = base.Ctxt.Lookup(fn.LSym.Name + ".stkobj")
- }
- }
- }
- }
}
// compileFunctions compiles all functions in compilequeue.
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index 9ecdd510b1..726a0685d5 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -96,16 +96,6 @@ func Main(archInit func(*ssagen.ArchInfo)) {
ir.Pkgs.Itab = types.NewPkg("go.itab", "go.itab")
ir.Pkgs.Itab.Prefix = "go.itab" // not go%2eitab
- ir.Pkgs.Itablink = types.NewPkg("go.itablink", "go.itablink")
- ir.Pkgs.Itablink.Prefix = "go.itablink" // not go%2eitablink
-
- ir.Pkgs.Track = types.NewPkg("go.track", "go.track")
- ir.Pkgs.Track.Prefix = "go.track" // not go%2etrack
-
- // pseudo-package used for map zero values
- ir.Pkgs.Map = types.NewPkg("go.map", "go.map")
- ir.Pkgs.Map.Prefix = "go.map"
-
// pseudo-package used for methods with anonymous receivers
ir.Pkgs.Go = types.NewPkg("go", "")
@@ -121,7 +111,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
log.Fatalf("compiler not built with support for -t")
}
- // Enable inlining (after recordFlags, to avoid recording the rewritten -l). For now:
+ // Enable inlining (after RecordFlags, to avoid recording the rewritten -l). For now:
// default: inlining on. (Flag.LowerL == 1)
// -l: inlining off (Flag.LowerL == 0)
// -l=2, -l=3: inlining on again, with extra debugging (Flag.LowerL > 1)
@@ -160,12 +150,6 @@ func Main(archInit func(*ssagen.ArchInfo)) {
ssagen.Arch.LinkArch.Init(base.Ctxt)
startProfile()
- if base.Flag.Race {
- ir.Pkgs.Race = types.NewPkg("runtime/race", "")
- }
- if base.Flag.MSan {
- ir.Pkgs.Msan = types.NewPkg("runtime/msan", "")
- }
if base.Flag.Race || base.Flag.MSan {
base.Flag.Cfg.Instrumenting = true
}
@@ -193,7 +177,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
typecheck.Target = new(ir.Package)
typecheck.NeedITab = func(t, iface *types.Type) { reflectdata.ITabAddr(t, iface) }
- typecheck.NeedRuntimeType = reflectdata.NeedRuntimeType // TODO(rsc): typenamesym for lock?
+ typecheck.NeedRuntimeType = reflectdata.NeedRuntimeType // TODO(rsc): TypeSym for lock?
base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
@@ -261,7 +245,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
escape.Funcs(typecheck.Target.Decls)
// Collect information for go:nowritebarrierrec
- // checking. This must happen before transformclosure.
+ // checking. This must happen before transforming closures during Walk
// We'll do the final check after write barriers are
// inserted.
if base.Flag.CompilingRuntime {
@@ -269,7 +253,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
}
// Prepare for SSA compilation.
- // This must be before peekitabs, because peekitabs
+ // This must be before CompileITabs, because CompileITabs
// can trigger function compilation.
typecheck.InitRuntime()
ssagen.InitConfig()
diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go
index 753db80f76..0472af7441 100644
--- a/src/cmd/compile/internal/gc/obj.go
+++ b/src/cmd/compile/internal/gc/obj.go
@@ -111,7 +111,6 @@ func dumpdata() {
numDecls := len(typecheck.Target.Decls)
dumpglobls(typecheck.Target.Externs)
- staticdata.WriteFuncSyms()
reflectdata.CollectPTabs()
numExports := len(typecheck.Target.Exports)
addsignats(typecheck.Target.Externs)
@@ -122,7 +121,7 @@ func dumpdata() {
reflectdata.WriteBasicTypes()
dumpembeds()
- // Calls to dumpsignats can generate functions,
+ // Calls to WriteRuntimeTypes can generate functions,
// like method wrappers and hash and equality routines.
// Compile any generated functions, process any new resulting types, repeat.
// This can't loop forever, because there is no way to generate an infinite
@@ -147,10 +146,11 @@ func dumpdata() {
dumpglobls(typecheck.Target.Externs[numExterns:])
if reflectdata.ZeroSize > 0 {
- zero := ir.Pkgs.Map.Lookup("zero").Linksym()
+ zero := base.PkgLinksym("go.map", "zero", obj.ABI0)
objw.Global(zero, int32(reflectdata.ZeroSize), obj.DUPOK|obj.RODATA)
}
+ staticdata.WriteFuncSyms()
addGCLocals()
if numExports != len(typecheck.Target.Exports) {
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index 6f5f6499ce..f0be169f56 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -4,7 +4,7 @@
//
// The inlining facility makes 2 passes: first caninl determines which
// functions are suitable for inlining, and for those that are it
-// saves a copy of the body. Then inlcalls walks each function body to
+// saves a copy of the body. Then InlineCalls walks each function body to
// expand calls to inlinable functions.
//
// The Debug.l flag controls the aggressiveness. Note that main() swaps level 0 and 1,
@@ -27,7 +27,6 @@
package inline
import (
- "errors"
"fmt"
"go/constant"
"strings"
@@ -74,12 +73,12 @@ func InlinePackage() {
})
}
-// Caninl determines whether fn is inlineable.
+// CanInline determines whether fn is inlineable.
// If so, CanInline saves fn->nbody in fn->inl and substitutes it with a copy.
// fn and ->nbody will already have been typechecked.
func CanInline(fn *ir.Func) {
if fn.Nname == nil {
- base.Fatalf("caninl no nname %+v", fn)
+ base.Fatalf("CanInline no nname %+v", fn)
}
var reason string // reason, if any, that the function was not inlined
@@ -144,7 +143,7 @@ func CanInline(fn *ir.Func) {
}
if fn.Typecheck() == 0 {
- base.Fatalf("caninl on non-typechecked function %v", fn)
+ base.Fatalf("CanInline on non-typechecked function %v", fn)
}
n := fn.Nname
@@ -170,7 +169,6 @@ func CanInline(fn *ir.Func) {
visitor := hairyVisitor{
budget: inlineMaxBudget,
extraCallCost: cc,
- usedLocals: make(map[*ir.Name]bool),
}
if visitor.tooHairy(fn) {
reason = visitor.reason
@@ -180,7 +178,7 @@ func CanInline(fn *ir.Func) {
n.Func.Inl = &ir.Inline{
Cost: inlineMaxBudget - visitor.budget,
Dcl: pruneUnusedAutos(n.Defn.(*ir.Func).Dcl, &visitor),
- Body: ir.DeepCopyList(src.NoXPos, fn.Body),
+ Body: inlcopylist(fn.Body),
}
if base.Flag.LowerM > 1 {
@@ -200,11 +198,11 @@ func Inline_Flood(n *ir.Name, exportsym func(*ir.Name)) {
return
}
if n.Op() != ir.ONAME || n.Class != ir.PFUNC {
- base.Fatalf("inlFlood: unexpected %v, %v, %v", n, n.Op(), n.Class)
+ base.Fatalf("Inline_Flood: unexpected %v, %v, %v", n, n.Op(), n.Class)
}
fn := n.Func
if fn == nil {
- base.Fatalf("inlFlood: missing Func on %v", n)
+ base.Fatalf("Inline_Flood: missing Func on %v", n)
}
if fn.Inl == nil {
return
@@ -217,10 +215,8 @@ func Inline_Flood(n *ir.Name, exportsym func(*ir.Name)) {
typecheck.ImportedBody(fn)
- // Recursively identify all referenced functions for
- // reexport. We want to include even non-called functions,
- // because after inlining they might be callable.
- ir.VisitList(ir.Nodes(fn.Inl.Body), func(n ir.Node) {
+ var doFlood func(n ir.Node)
+ doFlood = func(n ir.Node) {
switch n.Op() {
case ir.OMETHEXPR, ir.ODOTMETH:
Inline_Flood(ir.MethodExprName(n), exportsym)
@@ -239,15 +235,16 @@ func Inline_Flood(n *ir.Name, exportsym func(*ir.Name)) {
// Okay, because we don't yet inline indirect
// calls to method values.
case ir.OCLOSURE:
- // If the closure is inlinable, we'll need to
- // flood it too. But today we don't support
- // inlining functions that contain closures.
- //
- // When we do, we'll probably want:
- // inlFlood(n.Func.Closure.Func.Nname)
- base.Fatalf("unexpected closure in inlinable function")
+ // VisitList doesn't visit closure bodies, so force a
+ // recursive call to VisitList on the body of the closure.
+ ir.VisitList(n.(*ir.ClosureExpr).Func.Body, doFlood)
}
- })
+ }
+
+ // Recursively identify all referenced functions for
+ // reexport. We want to include even non-called functions,
+ // because after inlining they might be callable.
+ ir.VisitList(ir.Nodes(fn.Inl.Body), doFlood)
}
// hairyVisitor visits a function body to determine its inlining
@@ -256,18 +253,13 @@ type hairyVisitor struct {
budget int32
reason string
extraCallCost int32
- usedLocals map[*ir.Name]bool
- do func(ir.Node) error
+ usedLocals ir.NameSet
+ do func(ir.Node) bool
}
-var errBudget = errors.New("too expensive")
-
func (v *hairyVisitor) tooHairy(fn *ir.Func) bool {
v.do = v.doNode // cache closure
-
- err := errChildren(fn, v.do)
- if err != nil {
- v.reason = err.Error()
+ if ir.DoChildren(fn, v.do) {
return true
}
if v.budget < 0 {
@@ -277,11 +269,10 @@ func (v *hairyVisitor) tooHairy(fn *ir.Func) bool {
return false
}
-func (v *hairyVisitor) doNode(n ir.Node) error {
+func (v *hairyVisitor) doNode(n ir.Node) bool {
if n == nil {
- return nil
+ return false
}
-
switch n.Op() {
// Call is okay if inlinable and we have the budget for the body.
case ir.OCALLFUNC:
@@ -295,7 +286,8 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
if name.Class == ir.PFUNC && types.IsRuntimePkg(name.Sym().Pkg) {
fn := name.Sym().Name
if fn == "getcallerpc" || fn == "getcallersp" {
- return errors.New("call to " + fn)
+ v.reason = "call to " + fn
+ return true
}
if fn == "throw" {
v.budget -= inlineExtraThrowCost
@@ -346,38 +338,61 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
v.budget -= v.extraCallCost
case ir.OPANIC:
+ n := n.(*ir.UnaryExpr)
+ if n.X.Op() == ir.OCONVIFACE && n.X.(*ir.ConvExpr).Implicit() {
+ // Hack to keep reflect.flag.mustBe inlinable for TestIntendedInlining.
+ // Before CL 284412, these conversions were introduced later in the
+ // compiler, so they didn't count against inlining budget.
+ v.budget++
+ }
v.budget -= inlineExtraPanicCost
case ir.ORECOVER:
// recover matches the argument frame pointer to find
// the right panic value, so it needs an argument frame.
- return errors.New("call to recover")
+ v.reason = "call to recover"
+ return true
+
+ case ir.OCLOSURE:
+ // TODO(danscales,mdempsky): Get working with -G.
+ // Probably after #43818 is fixed.
+ if base.Flag.G > 0 {
+ v.reason = "inlining closures not yet working with -G"
+ return true
+ }
- case ir.OCLOSURE,
- ir.ORANGE,
+ // TODO(danscales) - fix some bugs when budget is lowered below 30
+ // Maybe make budget proportional to number of closure variables, e.g.:
+ //v.budget -= int32(len(n.(*ir.ClosureExpr).Func.ClosureVars) * 3)
+ v.budget -= 30
+
+ case ir.ORANGE,
ir.OSELECT,
ir.OGO,
ir.ODEFER,
ir.ODCLTYPE, // can't print yet
- ir.ORETJMP:
- return errors.New("unhandled op " + n.Op().String())
+ ir.OTAILCALL:
+ v.reason = "unhandled op " + n.Op().String()
+ return true
case ir.OAPPEND:
v.budget -= inlineExtraAppendCost
case ir.ODCLCONST, ir.OFALL:
// These nodes don't produce code; omit from inlining budget.
- return nil
+ return false
case ir.OFOR, ir.OFORUNTIL:
n := n.(*ir.ForStmt)
if n.Label != nil {
- return errors.New("labeled control")
+ v.reason = "labeled control"
+ return true
}
case ir.OSWITCH:
n := n.(*ir.SwitchStmt)
if n.Label != nil {
- return errors.New("labeled control")
+ v.reason = "labeled control"
+ return true
}
// case ir.ORANGE, ir.OSELECT in "unhandled" above
@@ -393,22 +408,15 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
if ir.IsConst(n.Cond, constant.Bool) {
// This if and the condition cost nothing.
// TODO(rsc): It seems strange that we visit the dead branch.
- if err := errList(n.Init(), v.do); err != nil {
- return err
- }
- if err := errList(n.Body, v.do); err != nil {
- return err
- }
- if err := errList(n.Else, v.do); err != nil {
- return err
- }
- return nil
+ return doList(n.Init(), v.do) ||
+ doList(n.Body, v.do) ||
+ doList(n.Else, v.do)
}
case ir.ONAME:
n := n.(*ir.Name)
if n.Class == ir.PAUTO {
- v.usedLocals[n] = true
+ v.usedLocals.Add(n)
}
case ir.OBLOCK:
@@ -428,10 +436,11 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
// When debugging, don't stop early, to get full cost of inlining this function
if v.budget < 0 && base.Flag.LowerM < 2 && !logopt.Enabled() {
- return errBudget
+ v.reason = "too expensive"
+ return true
}
- return errChildren(n, v.do)
+ return ir.DoChildren(n, v.do)
}
func isBigFunc(fn *ir.Func) bool {
@@ -442,6 +451,52 @@ func isBigFunc(fn *ir.Func) bool {
})
}
+// inlcopylist (together with inlcopy) recursively copies a list of nodes, except
+// that it keeps the same ONAME, OTYPE, and OLITERAL nodes. It is used for copying
+// the body and dcls of an inlineable function.
+func inlcopylist(ll []ir.Node) []ir.Node {
+ s := make([]ir.Node, len(ll))
+ for i, n := range ll {
+ s[i] = inlcopy(n)
+ }
+ return s
+}
+
+// inlcopy is like DeepCopy(), but does extra work to copy closures.
+func inlcopy(n ir.Node) ir.Node {
+ var edit func(ir.Node) ir.Node
+ edit = func(x ir.Node) ir.Node {
+ switch x.Op() {
+ case ir.ONAME, ir.OTYPE, ir.OLITERAL, ir.ONIL:
+ return x
+ }
+ m := ir.Copy(x)
+ ir.EditChildren(m, edit)
+ if x.Op() == ir.OCLOSURE {
+ x := x.(*ir.ClosureExpr)
+ // Need to save/duplicate x.Func.Nname,
+ // x.Func.Nname.Ntype, x.Func.Dcl, x.Func.ClosureVars, and
+ // x.Func.Body for iexport and local inlining.
+ oldfn := x.Func
+ newfn := ir.NewFunc(oldfn.Pos())
+ if oldfn.ClosureCalled() {
+ newfn.SetClosureCalled(true)
+ }
+ m.(*ir.ClosureExpr).Func = newfn
+ newfn.Nname = ir.NewNameAt(oldfn.Nname.Pos(), oldfn.Nname.Sym())
+ // XXX OK to share fn.Type() ??
+ newfn.Nname.SetType(oldfn.Nname.Type())
+ newfn.Nname.Ntype = inlcopy(oldfn.Nname.Ntype).(ir.Ntype)
+ newfn.Body = inlcopylist(oldfn.Body)
+ // Make shallow copy of the Dcl and ClosureVar slices
+ newfn.Dcl = append([]*ir.Name(nil), oldfn.Dcl...)
+ newfn.ClosureVars = append([]*ir.Name(nil), oldfn.ClosureVars...)
+ }
+ return m
+ }
+ return edit(n)
+}
+
// Inlcalls/nodelist/node walks fn's statements and expressions and substitutes any
// calls made to inlineable functions. This is the external entry point.
func InlineCalls(fn *ir.Func) {
@@ -762,13 +817,6 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
if ln.Class == ir.PPARAMOUT { // return values handled below.
continue
}
- if ir.IsParamStackCopy(ln) { // ignore the on-stack copy of a parameter that moved to the heap
- // TODO(mdempsky): Remove once I'm confident
- // this never actually happens. We currently
- // perform inlining before escape analysis, so
- // nothing should have moved to the heap yet.
- base.Fatalf("impossible: %v", ln)
- }
inlf := typecheck.Expr(inlvar(ln)).(*ir.Name)
inlvars[ln] = inlf
if base.Flag.GenDwarfInl > 0 {
@@ -925,6 +973,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
inlvars: inlvars,
bases: make(map[*src.PosBase]*src.PosBase),
newInlIndex: newIndex,
+ fn: fn,
}
subst.edit = subst.node
@@ -1031,6 +1080,12 @@ type inlsubst struct {
newInlIndex int
edit func(ir.Node) ir.Node // cached copy of subst.node method value closure
+
+ // If non-nil, we are inside a closure inside the inlined function, and
+ // newclofn is the Func of the new inlined closure.
+ newclofn *ir.Func
+
+ fn *ir.Func // For debug -- the func that is being inlined
}
// list inlines a list of nodes.
@@ -1042,6 +1097,157 @@ func (subst *inlsubst) list(ll ir.Nodes) []ir.Node {
return s
}
+// fields returns a list of the fields of a struct type representing receiver,
+// params, or results, after duplicating the field nodes and substituting the
+// Nname nodes inside the field nodes.
+func (subst *inlsubst) fields(oldt *types.Type) []*types.Field {
+ oldfields := oldt.FieldSlice()
+ newfields := make([]*types.Field, len(oldfields))
+ for i := range oldfields {
+ newfields[i] = oldfields[i].Copy()
+ if oldfields[i].Nname != nil {
+ newfields[i].Nname = subst.node(oldfields[i].Nname.(*ir.Name))
+ }
+ }
+ return newfields
+}
+
+// clovar creates a new ONAME node for a local variable or param of a closure
+// inside a function being inlined.
+func (subst *inlsubst) clovar(n *ir.Name) *ir.Name {
+ // TODO(danscales): want to get rid of this shallow copy, with code like the
+ // following, but it is hard to copy all the necessary flags in a maintainable way.
+ // m := ir.NewNameAt(n.Pos(), n.Sym())
+ // m.Class = n.Class
+ // m.SetType(n.Type())
+ // m.SetTypecheck(1)
+ //if n.IsClosureVar() {
+ // m.SetIsClosureVar(true)
+ //}
+ m := &ir.Name{}
+ *m = *n
+ m.Curfn = subst.newclofn
+ if n.Defn != nil && n.Defn.Op() == ir.ONAME {
+ if !n.IsClosureVar() {
+ base.FatalfAt(n.Pos(), "want closure variable, got: %+v", n)
+ }
+ if n.Sym().Pkg != types.LocalPkg {
+ // If the closure came from inlining a function from
+ // another package, must change package of captured
+ // variable to localpkg, so that the fields of the closure
+ // struct are local package and can be accessed even if
+ // name is not exported. If you disable this code, you can
+ // reproduce the problem by running 'go test
+ // go/internal/srcimporter'. TODO(mdempsky) - maybe change
+ // how we create closure structs?
+ m.SetSym(types.LocalPkg.Lookup(n.Sym().Name))
+ }
+ // Make sure any inlvar which is the Defn
+ // of an ONAME closure var is rewritten
+ // during inlining. Don't substitute
+ // if Defn node is outside inlined function.
+ if subst.inlvars[n.Defn.(*ir.Name)] != nil {
+ m.Defn = subst.node(n.Defn)
+ }
+ }
+ if n.Outer != nil {
+ // Either the outer variable is defined in function being inlined,
+ // and we will replace it with the substituted variable, or it is
+ // defined outside the function being inlined, and we should just
+ // skip the outer variable (the closure variable of the function
+ // being inlined).
+ s := subst.node(n.Outer).(*ir.Name)
+ if s == n.Outer {
+ s = n.Outer.Outer
+ }
+ m.Outer = s
+ }
+ return m
+}
+
+// closure does the necessary substitions for a ClosureExpr n and returns the new
+// closure node.
+func (subst *inlsubst) closure(n *ir.ClosureExpr) ir.Node {
+ m := ir.Copy(n)
+ m.SetPos(subst.updatedPos(m.Pos()))
+ ir.EditChildren(m, subst.edit)
+
+ //fmt.Printf("Inlining func %v with closure into %v\n", subst.fn, ir.FuncName(ir.CurFunc))
+
+ // The following is similar to funcLit
+ oldfn := n.Func
+ newfn := ir.NewFunc(oldfn.Pos())
+ // These three lines are not strictly necessary, but just to be clear
+ // that new function needs to redo typechecking and inlinability.
+ newfn.SetTypecheck(0)
+ newfn.SetInlinabilityChecked(false)
+ newfn.Inl = nil
+ newfn.SetIsHiddenClosure(true)
+ newfn.Nname = ir.NewNameAt(n.Pos(), ir.BlankNode.Sym())
+ newfn.Nname.Func = newfn
+ newfn.Nname.Ntype = subst.node(oldfn.Nname.Ntype).(ir.Ntype)
+ newfn.Nname.Defn = newfn
+
+ m.(*ir.ClosureExpr).Func = newfn
+ newfn.OClosure = m.(*ir.ClosureExpr)
+
+ if subst.newclofn != nil {
+ //fmt.Printf("Inlining a closure with a nested closure\n")
+ }
+ prevxfunc := subst.newclofn
+
+ // Mark that we are now substituting within a closure (within the
+ // inlined function), and create new nodes for all the local
+ // vars/params inside this closure.
+ subst.newclofn = newfn
+ newfn.Dcl = nil
+ newfn.ClosureVars = nil
+ for _, oldv := range oldfn.Dcl {
+ newv := subst.clovar(oldv)
+ subst.inlvars[oldv] = newv
+ newfn.Dcl = append(newfn.Dcl, newv)
+ }
+ for _, oldv := range oldfn.ClosureVars {
+ newv := subst.clovar(oldv)
+ subst.inlvars[oldv] = newv
+ newfn.ClosureVars = append(newfn.ClosureVars, newv)
+ }
+
+ // Need to replace ONAME nodes in
+ // newfn.Type().FuncType().Receiver/Params/Results.FieldSlice().Nname
+ oldt := oldfn.Type()
+ newrecvs := subst.fields(oldt.Recvs())
+ var newrecv *types.Field
+ if len(newrecvs) > 0 {
+ newrecv = newrecvs[0]
+ }
+ newt := types.NewSignature(oldt.Pkg(), newrecv,
+ subst.fields(oldt.Params()), subst.fields(oldt.Results()))
+
+ newfn.Nname.SetType(newt)
+ newfn.Body = subst.list(oldfn.Body)
+
+ // Remove the nodes for the current closure from subst.inlvars
+ for _, oldv := range oldfn.Dcl {
+ delete(subst.inlvars, oldv)
+ }
+ for _, oldv := range oldfn.ClosureVars {
+ delete(subst.inlvars, oldv)
+ }
+ // Go back to previous closure func
+ subst.newclofn = prevxfunc
+
+ // Actually create the named function for the closure, now that
+ // the closure is inlined in a specific function.
+ m.SetTypecheck(0)
+ if oldfn.ClosureCalled() {
+ typecheck.Callee(m)
+ } else {
+ typecheck.Expr(m)
+ }
+ return m
+}
+
// node recursively copies a node from the saved pristine body of the
// inlined function, substituting references to input/output
// parameters with ones to the tmpnames, and substituting returns with
@@ -1056,13 +1262,17 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
n := n.(*ir.Name)
// Handle captured variables when inlining closures.
- if n.IsClosureVar() {
+ if n.IsClosureVar() && subst.newclofn == nil {
o := n.Outer
+ // Deal with case where sequence of closures are inlined.
+ // TODO(danscales) - write test case to see if we need to
+ // go up multiple levels.
+ if o.Curfn != ir.CurFunc {
+ o = o.Outer
+ }
+
// make sure the outer param matches the inlining location
- // NB: if we enabled inlining of functions containing OCLOSURE or refined
- // the reassigned check via some sort of copy propagation this would most
- // likely need to be changed to a loop to walk up to the correct Param
if o == nil || o.Curfn != ir.CurFunc {
base.Fatalf("%v: unresolvable capture %v\n", ir.Line(n), n)
}
@@ -1098,6 +1308,10 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
}
case ir.ORETURN:
+ if subst.newclofn != nil {
+ // Don't do special substitutions if inside a closure
+ break
+ }
// Since we don't handle bodies with closures,
// this return is guaranteed to belong to the current inlined function.
n := n.(*ir.ReturnStmt)
@@ -1136,6 +1350,10 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
return m
case ir.OLABEL:
+ if subst.newclofn != nil {
+ // Don't do special substitutions if inside a closure
+ break
+ }
n := n.(*ir.LabelStmt)
m := ir.Copy(n).(*ir.LabelStmt)
m.SetPos(subst.updatedPos(m.Pos()))
@@ -1143,10 +1361,10 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
p := fmt.Sprintf("%s·%d", n.Label.Name, inlgen)
m.Label = typecheck.Lookup(p)
return m
- }
- if n.Op() == ir.OCLOSURE {
- base.Fatalf("cannot inline function containing closure: %+v", n)
+ case ir.OCLOSURE:
+ return subst.closure(n.(*ir.ClosureExpr))
+
}
m := ir.Copy(n)
@@ -1171,7 +1389,7 @@ func pruneUnusedAutos(ll []*ir.Name, vis *hairyVisitor) []*ir.Name {
s := make([]*ir.Name, 0, len(ll))
for _, n := range ll {
if n.Class == ir.PAUTO {
- if _, found := vis.usedLocals[n]; !found {
+ if !vis.usedLocals.Has(n) {
continue
}
}
@@ -1191,21 +1409,13 @@ func numNonClosures(list []*ir.Func) int {
return count
}
-// TODO(mdempsky): Update inl.go to use ir.DoChildren directly.
-func errChildren(n ir.Node, do func(ir.Node) error) (err error) {
- ir.DoChildren(n, func(x ir.Node) bool {
- err = do(x)
- return err != nil
- })
- return
-}
-func errList(list []ir.Node, do func(ir.Node) error) error {
+func doList(list []ir.Node, do func(ir.Node) bool) bool {
for _, x := range list {
if x != nil {
- if err := do(x); err != nil {
- return err
+ if do(x) {
+ return true
}
}
}
- return nil
+ return false
}
diff --git a/src/cmd/compile/internal/ir/const.go b/src/cmd/compile/internal/ir/const.go
index bfa0136232..eaa4d5b6b1 100644
--- a/src/cmd/compile/internal/ir/const.go
+++ b/src/cmd/compile/internal/ir/const.go
@@ -77,7 +77,7 @@ func ConstOverflow(v constant.Value, t *types.Type) bool {
ft := types.FloatForComplex(t)
return ConstOverflow(constant.Real(v), ft) || ConstOverflow(constant.Imag(v), ft)
}
- base.Fatalf("doesoverflow: %v, %v", v, t)
+ base.Fatalf("ConstOverflow: %v, %v", v, t)
panic("unreachable")
}
diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go
index 51425db42d..b32ed71260 100644
--- a/src/cmd/compile/internal/ir/expr.go
+++ b/src/cmd/compile/internal/ir/expr.go
@@ -8,6 +8,7 @@ import (
"bytes"
"cmd/compile/internal/base"
"cmd/compile/internal/types"
+ "cmd/internal/obj"
"cmd/internal/src"
"fmt"
"go/constant"
@@ -32,8 +33,7 @@ type miniExpr struct {
}
const (
- miniExprHasCall = 1 << iota
- miniExprNonNil
+ miniExprNonNil = 1 << iota
miniExprTransient
miniExprBounded
miniExprImplicit // for use by implementations; not supported by every Expr
@@ -44,8 +44,6 @@ func (*miniExpr) isExpr() {}
func (n *miniExpr) Type() *types.Type { return n.typ }
func (n *miniExpr) SetType(x *types.Type) { n.typ = x }
-func (n *miniExpr) HasCall() bool { return n.flags&miniExprHasCall != 0 }
-func (n *miniExpr) SetHasCall(b bool) { n.flags.set(miniExprHasCall, b) }
func (n *miniExpr) NonNil() bool { return n.flags&miniExprNonNil != 0 }
func (n *miniExpr) MarkNonNil() { n.flags |= miniExprNonNil }
func (n *miniExpr) Transient() bool { return n.flags&miniExprTransient != 0 }
@@ -145,7 +143,7 @@ func (n *BinaryExpr) SetOp(op Op) {
}
// A CallUse records how the result of the call is used:
-type CallUse int
+type CallUse byte
const (
_ CallUse = iota
@@ -161,7 +159,6 @@ type CallExpr struct {
origNode
X Node
Args Nodes
- Rargs Nodes // TODO(rsc): Delete.
KeepAlive []*Name // vars to be kept alive until call returns
IsDDD bool
Use CallUse
@@ -464,21 +461,35 @@ func NewResultExpr(pos src.XPos, typ *types.Type, offset int64) *ResultExpr {
return n
}
-// A NameOffsetExpr refers to an offset within a variable.
+// A LinksymOffsetExpr refers to an offset within a global variable.
// It is like a SelectorExpr but without the field name.
-type NameOffsetExpr struct {
+type LinksymOffsetExpr struct {
miniExpr
- Name_ *Name
+ Linksym *obj.LSym
Offset_ int64
}
-func NewNameOffsetExpr(pos src.XPos, name *Name, offset int64, typ *types.Type) *NameOffsetExpr {
- n := &NameOffsetExpr{Name_: name, Offset_: offset}
+func NewLinksymOffsetExpr(pos src.XPos, lsym *obj.LSym, offset int64, typ *types.Type) *LinksymOffsetExpr {
+ n := &LinksymOffsetExpr{Linksym: lsym, Offset_: offset}
n.typ = typ
- n.op = ONAMEOFFSET
+ n.op = OLINKSYMOFFSET
return n
}
+// NewLinksymExpr is NewLinksymOffsetExpr, but with offset fixed at 0.
+func NewLinksymExpr(pos src.XPos, lsym *obj.LSym, typ *types.Type) *LinksymOffsetExpr {
+ return NewLinksymOffsetExpr(pos, lsym, 0, typ)
+}
+
+// NewNameOffsetExpr is NewLinksymOffsetExpr, but taking a *Name
+// representing a global variable instead of an *obj.LSym directly.
+func NewNameOffsetExpr(pos src.XPos, name *Name, offset int64, typ *types.Type) *LinksymOffsetExpr {
+ if name == nil || IsBlank(name) || !(name.Op() == ONAME && name.Class == PEXTERN) {
+ base.FatalfAt(pos, "cannot take offset of nil, blank name or non-global variable: %v", name)
+ }
+ return NewLinksymOffsetExpr(pos, name.Linksym(), offset, typ)
+}
+
// A SelectorExpr is a selector expression X.Sel.
type SelectorExpr struct {
miniExpr
@@ -612,11 +623,9 @@ type TypeAssertExpr struct {
X Node
Ntype Ntype
- // Runtime type information provided by walkDotType.
- // Caution: These aren't always populated; see walkDotType.
- SrcType *AddrExpr `mknode:"-"` // *runtime._type for X's type
- DstType *AddrExpr `mknode:"-"` // *runtime._type for Type
- Itab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type
+ // Runtime type information provided by walkDotType for
+ // assertions from non-empty interface to concrete type.
+ Itab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type
}
func NewTypeAssertExpr(pos src.XPos, x Node, typ Ntype) *TypeAssertExpr {
@@ -656,7 +665,7 @@ func (n *UnaryExpr) SetOp(op Op) {
case OBITNOT, ONEG, ONOT, OPLUS, ORECV,
OALIGNOF, OCAP, OCLOSE, OIMAG, OLEN, ONEW,
OOFFSETOF, OPANIC, OREAL, OSIZEOF,
- OCHECKNIL, OCFUNC, OIDATA, OITAB, ONEWOBJ, OSPTR, OVARDEF, OVARKILL, OVARLIVE:
+ OCHECKNIL, OCFUNC, OIDATA, OITAB, OSPTR, OVARDEF, OVARKILL, OVARLIVE:
n.op = op
}
}
@@ -728,7 +737,7 @@ func IsAddressable(n Node) bool {
}
return true
- case ONAMEOFFSET:
+ case OLINKSYMOFFSET:
return true
}
diff --git a/src/cmd/compile/internal/ir/fmt.go b/src/cmd/compile/internal/ir/fmt.go
index a4e769f508..1a05079dac 100644
--- a/src/cmd/compile/internal/ir/fmt.go
+++ b/src/cmd/compile/internal/ir/fmt.go
@@ -378,9 +378,9 @@ func stmtFmt(n Node, s fmt.State) {
n := n.(*ReturnStmt)
fmt.Fprintf(s, "return %.v", n.Results)
- case ORETJMP:
- n := n.(*BranchStmt)
- fmt.Fprintf(s, "retjmp %v", n.Label)
+ case OTAILCALL:
+ n := n.(*TailCallStmt)
+ fmt.Fprintf(s, "tailcall %v", n.Target)
case OINLMARK:
n := n.(*InlineMarkStmt)
@@ -589,20 +589,20 @@ func exprFmt(n Node, s fmt.State, prec int) {
}
if n.Type() == types.UntypedRune {
- switch x, ok := constant.Int64Val(n.Val()); {
+ switch x, ok := constant.Uint64Val(n.Val()); {
case !ok:
fallthrough
default:
fmt.Fprintf(s, "('\\x00' + %v)", n.Val())
- case ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'':
- fmt.Fprintf(s, "'%c'", int(x))
+ case x < utf8.RuneSelf:
+ fmt.Fprintf(s, "%q", x)
- case 0 <= x && x < 1<<16:
- fmt.Fprintf(s, "'\\u%04x'", uint(int(x)))
+ case x < 1<<16:
+ fmt.Fprintf(s, "'\\u%04x'", x)
- case 0 <= x && x <= utf8.MaxRune:
- fmt.Fprintf(s, "'\\U%08x'", uint64(x))
+ case x <= utf8.MaxRune:
+ fmt.Fprintf(s, "'\\U%08x'", x)
}
} else {
fmt.Fprint(s, types.FmtConst(n.Val(), s.Flag('#')))
@@ -632,9 +632,9 @@ func exprFmt(n Node, s fmt.State, prec int) {
case OPACK, ONONAME:
fmt.Fprint(s, n.Sym())
- case ONAMEOFFSET:
- n := n.(*NameOffsetExpr)
- fmt.Fprintf(s, "(%v)(%v@%d)", n.Type(), n.Name_, n.Offset_)
+ case OLINKSYMOFFSET:
+ n := n.(*LinksymOffsetExpr)
+ fmt.Fprintf(s, "(%v)(%s@%d)", n.Type(), n.Linksym.Name, n.Offset_)
case OTYPE:
if n.Type() == nil && n.Sym() != nil {
@@ -1020,6 +1020,15 @@ func dumpNodeHeader(w io.Writer, n Node) {
fmt.Fprintf(w, " defn(%p)", n.Name().Defn)
}
+ if base.Debug.DumpPtrs != 0 && n.Name() != nil && n.Name().Curfn != nil {
+ // Useful to see where Defn is set and what node it points to
+ fmt.Fprintf(w, " curfn(%p)", n.Name().Curfn)
+ }
+ if base.Debug.DumpPtrs != 0 && n.Name() != nil && n.Name().Outer != nil {
+ // Useful to see where Defn is set and what node it points to
+ fmt.Fprintf(w, " outer(%p)", n.Name().Outer)
+ }
+
if EscFmt != nil {
if esc := EscFmt(n); esc != "" {
fmt.Fprintf(w, " %s", esc)
@@ -1119,6 +1128,11 @@ func dumpNode(w io.Writer, n Node, depth int) {
return
}
+ if n == nil {
+ fmt.Fprint(w, "NilIrNode")
+ return
+ }
+
if len(n.Init()) != 0 {
fmt.Fprintf(w, "%+v-init", n.Op())
dumpNodes(w, n.Init(), depth+1)
@@ -1182,6 +1196,18 @@ func dumpNode(w io.Writer, n Node, depth int) {
dumpNode(w, dcl, depth+1)
}
}
+ if len(fn.ClosureVars) > 0 {
+ indent(w, depth)
+ fmt.Fprintf(w, "%+v-ClosureVars", n.Op())
+ for _, cv := range fn.ClosureVars {
+ dumpNode(w, cv, depth+1)
+ }
+ }
+ if len(fn.Enter) > 0 {
+ indent(w, depth)
+ fmt.Fprintf(w, "%+v-Enter", n.Op())
+ dumpNodes(w, fn.Enter, depth+1)
+ }
if len(fn.Body) > 0 {
indent(w, depth)
fmt.Fprintf(w, "%+v-body", n.Op())
diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go
index 30cddd298e..0a9db92d96 100644
--- a/src/cmd/compile/internal/ir/func.go
+++ b/src/cmd/compile/internal/ir/func.go
@@ -63,7 +63,7 @@ type Func struct {
Exit Nodes
// ONAME nodes for all params/locals for this func/closure, does NOT
- // include closurevars until transformclosure runs.
+ // include closurevars until transforming closures during walk.
// Names must be listed PPARAMs, PPARAMOUTs, then PAUTOs,
// with PPARAMs and PPARAMOUTs in order corresponding to the function signature.
// However, as anonymous or blank PPARAMs are not actually declared,
@@ -133,9 +133,10 @@ func (n *Func) copy() Node { panic(n.no("copy")) }
func (n *Func) doChildren(do func(Node) bool) bool { return doNodes(n.Body, do) }
func (n *Func) editChildren(edit func(Node) Node) { editNodes(n.Body, edit) }
-func (f *Func) Type() *types.Type { return f.Nname.Type() }
-func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
-func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
+func (f *Func) Type() *types.Type { return f.Nname.Type() }
+func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
+func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
+func (f *Func) LinksymABI(abi obj.ABI) *obj.LSym { return f.Nname.LinksymABI(abi) }
// An Inline holds fields used for function bodies that can be inlined.
type Inline struct {
diff --git a/src/cmd/compile/internal/ir/mini.go b/src/cmd/compile/internal/ir/mini.go
index 4dd9a8807a..a7ff4ac9c7 100644
--- a/src/cmd/compile/internal/ir/mini.go
+++ b/src/cmd/compile/internal/ir/mini.go
@@ -57,7 +57,7 @@ const (
miniWalkdefShift = 0 // TODO(mdempsky): Move to Name.flags.
miniTypecheckShift = 2
miniDiag = 1 << 4
- miniHasCall = 1 << 5 // for miniStmt
+ miniWalked = 1 << 5 // to prevent/catch re-walking
)
func (n *miniNode) Typecheck() uint8 { return n.bits.get2(miniTypecheckShift) }
@@ -71,6 +71,9 @@ func (n *miniNode) SetTypecheck(x uint8) {
func (n *miniNode) Diag() bool { return n.bits&miniDiag != 0 }
func (n *miniNode) SetDiag(x bool) { n.bits.set(miniDiag, x) }
+func (n *miniNode) Walked() bool { return n.bits&miniWalked != 0 }
+func (n *miniNode) SetWalked(x bool) { n.bits.set(miniWalked, x) }
+
// Empty, immutable graph structure.
func (n *miniNode) Init() Nodes { return Nodes{} }
@@ -85,7 +88,5 @@ func (n *miniNode) Name() *Name { return nil }
func (n *miniNode) Sym() *types.Sym { return nil }
func (n *miniNode) Val() constant.Value { panic(n.no("Val")) }
func (n *miniNode) SetVal(v constant.Value) { panic(n.no("SetVal")) }
-func (n *miniNode) HasCall() bool { return false }
-func (n *miniNode) SetHasCall(bool) { panic(n.no("SetHasCall")) }
func (n *miniNode) NonNil() bool { return false }
func (n *miniNode) MarkNonNil() { panic(n.no("MarkNonNil")) }
diff --git a/src/cmd/compile/internal/ir/name.go b/src/cmd/compile/internal/ir/name.go
index 514b303893..fa0639600c 100644
--- a/src/cmd/compile/internal/ir/name.go
+++ b/src/cmd/compile/internal/ir/name.go
@@ -58,9 +58,6 @@ type Name struct {
Ntype Ntype
Heapaddr *Name // temp holding heap address of param
- // ONAME PAUTOHEAP
- Stackcopy *Name // the PPARAM/PPARAMOUT on-stack slot (moved func params only)
-
// ONAME closure linkage
// Consider:
//
@@ -150,12 +147,7 @@ func (n *Name) TypeDefn() *types.Type {
// RecordFrameOffset records the frame offset for the name.
// It is used by package types when laying out function arguments.
func (n *Name) RecordFrameOffset(offset int64) {
- if n.Stackcopy != nil {
- n.Stackcopy.SetFrameOffset(offset)
- n.SetFrameOffset(0)
- } else {
- n.SetFrameOffset(offset)
- }
+ n.SetFrameOffset(offset)
}
// NewNameAt returns a new ONAME Node associated with symbol s at position pos.
@@ -234,7 +226,8 @@ func (n *Name) SetWalkdef(x uint8) {
n.bits.set2(miniWalkdefShift, x)
}
-func (n *Name) Linksym() *obj.LSym { return n.sym.Linksym() }
+func (n *Name) Linksym() *obj.LSym { return n.sym.Linksym() }
+func (n *Name) LinksymABI(abi obj.ABI) *obj.LSym { return n.sym.LinksymABI(abi) }
func (*Name) CanBeNtype() {}
func (*Name) CanBeAnSSASym() {}
@@ -292,6 +285,21 @@ func (n *Name) SetInlLocal(b bool) { n.flags.set(nameInlLocal, b) }
func (n *Name) SetOpenDeferSlot(b bool) { n.flags.set(nameOpenDeferSlot, b) }
func (n *Name) SetLibfuzzerExtraCounter(b bool) { n.flags.set(nameLibfuzzerExtraCounter, b) }
+// OnStack reports whether variable n may reside on the stack.
+func (n *Name) OnStack() bool {
+ if n.Op() == ONAME {
+ switch n.Class {
+ case PPARAM, PPARAMOUT, PAUTO:
+ return n.Esc() != EscHeap
+ case PEXTERN, PAUTOHEAP:
+ return false
+ }
+ }
+ // Note: fmt.go:dumpNodeHeader calls all "func() bool"-typed
+ // methods, but it can only recover from panics, not Fatalf.
+ panic(fmt.Sprintf("%v: not a variable: %v", base.FmtPos(n.Pos()), n))
+}
+
// MarkReadonly indicates that n is an ONAME with readonly contents.
func (n *Name) MarkReadonly() {
if n.Op() != ONAME {
@@ -501,24 +509,4 @@ func NewPkgName(pos src.XPos, sym *types.Sym, pkg *types.Pkg) *PkgName {
return p
}
-// IsParamStackCopy reports whether this is the on-stack copy of a
-// function parameter that moved to the heap.
-func IsParamStackCopy(n Node) bool {
- if n.Op() != ONAME {
- return false
- }
- name := n.(*Name)
- return (name.Class == PPARAM || name.Class == PPARAMOUT) && name.Heapaddr != nil
-}
-
-// IsParamHeapCopy reports whether this is the on-heap copy of
-// a function parameter that moved to the heap.
-func IsParamHeapCopy(n Node) bool {
- if n.Op() != ONAME {
- return false
- }
- name := n.(*Name)
- return name.Class == PAUTOHEAP && name.Stackcopy != nil
-}
-
var RegFP *Name
diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go
index a2b6e7203b..ffa7daf6b2 100644
--- a/src/cmd/compile/internal/ir/node.go
+++ b/src/cmd/compile/internal/ir/node.go
@@ -52,8 +52,6 @@ type Node interface {
SetTypecheck(x uint8)
NonNil() bool
MarkNonNil()
- HasCall() bool
- SetHasCall(x bool)
}
// Line returns n's position as a string. If n has been inlined,
@@ -216,7 +214,6 @@ const (
OAND // Left & Right
OANDNOT // Left &^ Right
ONEW // new(Left); corresponds to calls to new in source code
- ONEWOBJ // runtime.newobject(n.Type); introduced by walk; Left is type descriptor
ONOT // !Left
OBITNOT // ^Left
OPLUS // +Left
@@ -294,23 +291,27 @@ const (
OTSLICE // []int
// misc
- OINLCALL // intermediary representation of an inlined call.
- OEFACE // itable and data words of an empty-interface value.
- OITAB // itable word of an interface value.
- OIDATA // data word of an interface value in Left
- OSPTR // base pointer of a slice or string.
- OCFUNC // reference to c function pointer (not go func value)
- OCHECKNIL // emit code to ensure pointer/interface not nil
- OVARDEF // variable is about to be fully initialized
- OVARKILL // variable is dead
- OVARLIVE // variable is alive
- ORESULT // result of a function call; Xoffset is stack offset
- OINLMARK // start of an inlined body, with file/line of caller. Xoffset is an index into the inline tree.
- ONAMEOFFSET // offset within a name
+ // intermediate representation of an inlined call. Uses Init (assignments
+ // for the captured variables, parameters, retvars, & INLMARK op),
+ // Body (body of the inlined function), and ReturnVars (list of
+ // return values)
+ OINLCALL // intermediary representation of an inlined call.
+ OEFACE // itable and data words of an empty-interface value.
+ OITAB // itable word of an interface value.
+ OIDATA // data word of an interface value in Left
+ OSPTR // base pointer of a slice or string.
+ OCFUNC // reference to c function pointer (not go func value)
+ OCHECKNIL // emit code to ensure pointer/interface not nil
+ OVARDEF // variable is about to be fully initialized
+ OVARKILL // variable is dead
+ OVARLIVE // variable is alive
+ ORESULT // result of a function call; Xoffset is stack offset
+ OINLMARK // start of an inlined body, with file/line of caller. Xoffset is an index into the inline tree.
+ OLINKSYMOFFSET // offset within a name
// arch-specific opcodes
- ORETJMP // return to other function
- OGETG // runtime.getg() (read g pointer)
+ OTAILCALL // tail call to another function
+ OGETG // runtime.getg() (read g pointer)
OEND
)
@@ -452,6 +453,9 @@ const (
// Go command pragmas
GoBuildPragma
+
+ RegisterParams // TODO remove after register abi is working
+
)
func AsNode(n types.Object) Node {
@@ -542,7 +546,6 @@ func InitExpr(init []Node, expr Node) Node {
}
n.PtrInit().Prepend(init...)
- n.SetHasCall(true)
return n
}
diff --git a/src/cmd/compile/internal/ir/node_gen.go b/src/cmd/compile/internal/ir/node_gen.go
index f1b0a21628..fe436867b2 100644
--- a/src/cmd/compile/internal/ir/node_gen.go
+++ b/src/cmd/compile/internal/ir/node_gen.go
@@ -250,7 +250,6 @@ func (n *CallExpr) copy() Node {
c := *n
c.init = copyNodes(c.init)
c.Args = copyNodes(c.Args)
- c.Rargs = copyNodes(c.Rargs)
c.KeepAlive = copyNames(c.KeepAlive)
return &c
}
@@ -264,9 +263,6 @@ func (n *CallExpr) doChildren(do func(Node) bool) bool {
if doNodes(n.Args, do) {
return true
}
- if doNodes(n.Rargs, do) {
- return true
- }
if doNames(n.KeepAlive, do) {
return true
}
@@ -278,7 +274,6 @@ func (n *CallExpr) editChildren(edit func(Node) Node) {
n.X = edit(n.X).(Node)
}
editNodes(n.Args, edit)
- editNodes(n.Rargs, edit)
editNames(n.KeepAlive, edit)
}
@@ -734,6 +729,22 @@ func (n *LabelStmt) editChildren(edit func(Node) Node) {
editNodes(n.init, edit)
}
+func (n *LinksymOffsetExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
+func (n *LinksymOffsetExpr) copy() Node {
+ c := *n
+ c.init = copyNodes(c.init)
+ return &c
+}
+func (n *LinksymOffsetExpr) doChildren(do func(Node) bool) bool {
+ if doNodes(n.init, do) {
+ return true
+ }
+ return false
+}
+func (n *LinksymOffsetExpr) editChildren(edit func(Node) Node) {
+ editNodes(n.init, edit)
+}
+
func (n *LogicalExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
func (n *LogicalExpr) copy() Node {
c := *n
@@ -815,28 +826,6 @@ func (n *MapType) editChildren(edit func(Node) Node) {
func (n *Name) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
-func (n *NameOffsetExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
-func (n *NameOffsetExpr) copy() Node {
- c := *n
- c.init = copyNodes(c.init)
- return &c
-}
-func (n *NameOffsetExpr) doChildren(do func(Node) bool) bool {
- if doNodes(n.init, do) {
- return true
- }
- if n.Name_ != nil && do(n.Name_) {
- return true
- }
- return false
-}
-func (n *NameOffsetExpr) editChildren(edit func(Node) Node) {
- editNodes(n.init, edit)
- if n.Name_ != nil {
- n.Name_ = edit(n.Name_).(*Name)
- }
-}
-
func (n *NilExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
func (n *NilExpr) copy() Node {
c := *n
@@ -1233,6 +1222,28 @@ func (n *SwitchStmt) editChildren(edit func(Node) Node) {
editNodes(n.Compiled, edit)
}
+func (n *TailCallStmt) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
+func (n *TailCallStmt) copy() Node {
+ c := *n
+ c.init = copyNodes(c.init)
+ return &c
+}
+func (n *TailCallStmt) doChildren(do func(Node) bool) bool {
+ if doNodes(n.init, do) {
+ return true
+ }
+ if n.Target != nil && do(n.Target) {
+ return true
+ }
+ return false
+}
+func (n *TailCallStmt) editChildren(edit func(Node) Node) {
+ editNodes(n.init, edit)
+ if n.Target != nil {
+ n.Target = edit(n.Target).(*Name)
+ }
+}
+
func (n *TypeAssertExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
func (n *TypeAssertExpr) copy() Node {
c := *n
diff --git a/src/cmd/compile/internal/ir/op_string.go b/src/cmd/compile/internal/ir/op_string.go
index b54b4785a2..15c60baf44 100644
--- a/src/cmd/compile/internal/ir/op_string.go
+++ b/src/cmd/compile/internal/ir/op_string.go
@@ -91,81 +91,80 @@ func _() {
_ = x[OAND-80]
_ = x[OANDNOT-81]
_ = x[ONEW-82]
- _ = x[ONEWOBJ-83]
- _ = x[ONOT-84]
- _ = x[OBITNOT-85]
- _ = x[OPLUS-86]
- _ = x[ONEG-87]
- _ = x[OOROR-88]
- _ = x[OPANIC-89]
- _ = x[OPRINT-90]
- _ = x[OPRINTN-91]
- _ = x[OPAREN-92]
- _ = x[OSEND-93]
- _ = x[OSLICE-94]
- _ = x[OSLICEARR-95]
- _ = x[OSLICESTR-96]
- _ = x[OSLICE3-97]
- _ = x[OSLICE3ARR-98]
- _ = x[OSLICEHEADER-99]
- _ = x[ORECOVER-100]
- _ = x[ORECV-101]
- _ = x[ORUNESTR-102]
- _ = x[OSELRECV2-103]
- _ = x[OIOTA-104]
- _ = x[OREAL-105]
- _ = x[OIMAG-106]
- _ = x[OCOMPLEX-107]
- _ = x[OALIGNOF-108]
- _ = x[OOFFSETOF-109]
- _ = x[OSIZEOF-110]
- _ = x[OMETHEXPR-111]
- _ = x[OSTMTEXPR-112]
- _ = x[OBLOCK-113]
- _ = x[OBREAK-114]
- _ = x[OCASE-115]
- _ = x[OCONTINUE-116]
- _ = x[ODEFER-117]
- _ = x[OFALL-118]
- _ = x[OFOR-119]
- _ = x[OFORUNTIL-120]
- _ = x[OGOTO-121]
- _ = x[OIF-122]
- _ = x[OLABEL-123]
- _ = x[OGO-124]
- _ = x[ORANGE-125]
- _ = x[ORETURN-126]
- _ = x[OSELECT-127]
- _ = x[OSWITCH-128]
- _ = x[OTYPESW-129]
- _ = x[OTCHAN-130]
- _ = x[OTMAP-131]
- _ = x[OTSTRUCT-132]
- _ = x[OTINTER-133]
- _ = x[OTFUNC-134]
- _ = x[OTARRAY-135]
- _ = x[OTSLICE-136]
- _ = x[OINLCALL-137]
- _ = x[OEFACE-138]
- _ = x[OITAB-139]
- _ = x[OIDATA-140]
- _ = x[OSPTR-141]
- _ = x[OCFUNC-142]
- _ = x[OCHECKNIL-143]
- _ = x[OVARDEF-144]
- _ = x[OVARKILL-145]
- _ = x[OVARLIVE-146]
- _ = x[ORESULT-147]
- _ = x[OINLMARK-148]
- _ = x[ONAMEOFFSET-149]
- _ = x[ORETJMP-150]
- _ = x[OGETG-151]
- _ = x[OEND-152]
+ _ = x[ONOT-83]
+ _ = x[OBITNOT-84]
+ _ = x[OPLUS-85]
+ _ = x[ONEG-86]
+ _ = x[OOROR-87]
+ _ = x[OPANIC-88]
+ _ = x[OPRINT-89]
+ _ = x[OPRINTN-90]
+ _ = x[OPAREN-91]
+ _ = x[OSEND-92]
+ _ = x[OSLICE-93]
+ _ = x[OSLICEARR-94]
+ _ = x[OSLICESTR-95]
+ _ = x[OSLICE3-96]
+ _ = x[OSLICE3ARR-97]
+ _ = x[OSLICEHEADER-98]
+ _ = x[ORECOVER-99]
+ _ = x[ORECV-100]
+ _ = x[ORUNESTR-101]
+ _ = x[OSELRECV2-102]
+ _ = x[OIOTA-103]
+ _ = x[OREAL-104]
+ _ = x[OIMAG-105]
+ _ = x[OCOMPLEX-106]
+ _ = x[OALIGNOF-107]
+ _ = x[OOFFSETOF-108]
+ _ = x[OSIZEOF-109]
+ _ = x[OMETHEXPR-110]
+ _ = x[OSTMTEXPR-111]
+ _ = x[OBLOCK-112]
+ _ = x[OBREAK-113]
+ _ = x[OCASE-114]
+ _ = x[OCONTINUE-115]
+ _ = x[ODEFER-116]
+ _ = x[OFALL-117]
+ _ = x[OFOR-118]
+ _ = x[OFORUNTIL-119]
+ _ = x[OGOTO-120]
+ _ = x[OIF-121]
+ _ = x[OLABEL-122]
+ _ = x[OGO-123]
+ _ = x[ORANGE-124]
+ _ = x[ORETURN-125]
+ _ = x[OSELECT-126]
+ _ = x[OSWITCH-127]
+ _ = x[OTYPESW-128]
+ _ = x[OTCHAN-129]
+ _ = x[OTMAP-130]
+ _ = x[OTSTRUCT-131]
+ _ = x[OTINTER-132]
+ _ = x[OTFUNC-133]
+ _ = x[OTARRAY-134]
+ _ = x[OTSLICE-135]
+ _ = x[OINLCALL-136]
+ _ = x[OEFACE-137]
+ _ = x[OITAB-138]
+ _ = x[OIDATA-139]
+ _ = x[OSPTR-140]
+ _ = x[OCFUNC-141]
+ _ = x[OCHECKNIL-142]
+ _ = x[OVARDEF-143]
+ _ = x[OVARKILL-144]
+ _ = x[OVARLIVE-145]
+ _ = x[ORESULT-146]
+ _ = x[OINLMARK-147]
+ _ = x[OLINKSYMOFFSET-148]
+ _ = x[OTAILCALL-149]
+ _ = x[OGETG-150]
+ _ = x[OEND-151]
}
-const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNEWOBJNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKNAMEOFFSETRETJMPGETGEND"
+const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETTAILCALLGETGEND"
-var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 477, 480, 486, 490, 493, 497, 502, 507, 513, 518, 522, 527, 535, 543, 549, 558, 569, 576, 580, 587, 595, 599, 603, 607, 614, 621, 629, 635, 643, 651, 656, 661, 665, 673, 678, 682, 685, 693, 697, 699, 704, 706, 711, 717, 723, 729, 735, 740, 744, 751, 757, 762, 768, 774, 781, 786, 790, 795, 799, 804, 812, 818, 825, 832, 838, 845, 855, 861, 865, 868}
+var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 474, 480, 484, 487, 491, 496, 501, 507, 512, 516, 521, 529, 537, 543, 552, 563, 570, 574, 581, 589, 593, 597, 601, 608, 615, 623, 629, 637, 645, 650, 655, 659, 667, 672, 676, 679, 687, 691, 693, 698, 700, 705, 711, 717, 723, 729, 734, 738, 745, 751, 756, 762, 768, 775, 780, 784, 789, 793, 798, 806, 812, 819, 826, 832, 839, 852, 860, 864, 867}
func (i Op) String() string {
if i >= Op(len(_Op_index)-1) {
diff --git a/src/cmd/compile/internal/ir/sizeof_test.go b/src/cmd/compile/internal/ir/sizeof_test.go
index 553dc53760..d8c1518b90 100644
--- a/src/cmd/compile/internal/ir/sizeof_test.go
+++ b/src/cmd/compile/internal/ir/sizeof_test.go
@@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
_64bit uintptr // size on 64bit platforms
}{
{Func{}, 188, 328},
- {Name{}, 116, 208},
+ {Name{}, 112, 200},
}
for _, tt := range tests {
diff --git a/src/cmd/compile/internal/ir/stmt.go b/src/cmd/compile/internal/ir/stmt.go
index b13c6b7795..c304867e1d 100644
--- a/src/cmd/compile/internal/ir/stmt.go
+++ b/src/cmd/compile/internal/ir/stmt.go
@@ -50,11 +50,9 @@ type miniStmt struct {
func (*miniStmt) isStmt() {}
-func (n *miniStmt) Init() Nodes { return n.init }
-func (n *miniStmt) SetInit(x Nodes) { n.init = x }
-func (n *miniStmt) PtrInit() *Nodes { return &n.init }
-func (n *miniStmt) HasCall() bool { return n.bits&miniHasCall != 0 }
-func (n *miniStmt) SetHasCall(b bool) { n.bits.set(miniHasCall, b) }
+func (n *miniStmt) Init() Nodes { return n.init }
+func (n *miniStmt) SetInit(x Nodes) { n.init = x }
+func (n *miniStmt) PtrInit() *Nodes { return &n.init }
// An AssignListStmt is an assignment statement with
// more than one item on at least one side: Lhs = Rhs.
@@ -146,9 +144,6 @@ func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt {
}
// A BranchStmt is a break, continue, fallthrough, or goto statement.
-//
-// For back-end code generation, Op may also be RETJMP (return+jump),
-// in which case the label names another function entirely.
type BranchStmt struct {
miniStmt
Label *types.Sym // label if present
@@ -156,7 +151,7 @@ type BranchStmt struct {
func NewBranchStmt(pos src.XPos, op Op, label *types.Sym) *BranchStmt {
switch op {
- case OBREAK, OCONTINUE, OFALL, OGOTO, ORETJMP:
+ case OBREAK, OCONTINUE, OFALL, OGOTO:
// ok
default:
panic("NewBranch " + op.String())
@@ -343,7 +338,7 @@ type SelectStmt struct {
HasBreak bool
// TODO(rsc): Instead of recording here, replace with a block?
- Compiled Nodes // compiled form, after walkswitch
+ Compiled Nodes // compiled form, after walkSwitch
}
func NewSelectStmt(pos src.XPos, cases []*CommClause) *SelectStmt {
@@ -376,7 +371,7 @@ type SwitchStmt struct {
HasBreak bool
// TODO(rsc): Instead of recording here, replace with a block?
- Compiled Nodes // compiled form, after walkswitch
+ Compiled Nodes // compiled form, after walkSwitch
}
func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseClause) *SwitchStmt {
@@ -386,6 +381,23 @@ func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseClause) *SwitchStmt {
return n
}
+// A TailCallStmt is a tail call statement, which is used for back-end
+// code generation to jump directly to another function entirely.
+type TailCallStmt struct {
+ miniStmt
+ Target *Name
+}
+
+func NewTailCallStmt(pos src.XPos, target *Name) *TailCallStmt {
+ if target.Op() != ONAME || target.Class != PFUNC {
+ base.FatalfAt(pos, "tail call to non-func %v", target)
+ }
+ n := &TailCallStmt{Target: target}
+ n.pos = pos
+ n.op = OTAILCALL
+ return n
+}
+
// A TypeSwitchGuard is the [Name :=] X.(type) in a type switch.
type TypeSwitchGuard struct {
miniNode
diff --git a/src/cmd/compile/internal/ir/symtab.go b/src/cmd/compile/internal/ir/symtab.go
index df694f6c84..61727fb1c4 100644
--- a/src/cmd/compile/internal/ir/symtab.go
+++ b/src/cmd/compile/internal/ir/symtab.go
@@ -9,12 +9,6 @@ import (
"cmd/internal/obj"
)
-// Names holds known names.
-var Names struct {
- Staticuint64s *Name
- Zerobase *Name
-}
-
// Syms holds known symbols.
var Syms struct {
AssertE2I *obj.LSym
@@ -46,6 +40,7 @@ var Syms struct {
Racewriterange *obj.LSym
// Wasm
SigPanic *obj.LSym
+ Staticuint64s *obj.LSym
Typedmemclr *obj.LSym
Typedmemmove *obj.LSym
Udiv *obj.LSym
@@ -70,13 +65,8 @@ var Syms struct {
// Pkgs holds known packages.
var Pkgs struct {
- Go *types.Pkg
- Itab *types.Pkg
- Itablink *types.Pkg
- Map *types.Pkg
- Msan *types.Pkg
- Race *types.Pkg
- Runtime *types.Pkg
- Track *types.Pkg
- Unsafe *types.Pkg
+ Go *types.Pkg
+ Itab *types.Pkg
+ Runtime *types.Pkg
+ Unsafe *types.Pkg
}
diff --git a/src/cmd/compile/internal/liveness/bvset.go b/src/cmd/compile/internal/liveness/bvset.go
index 21bc1fee4d..3431f54ede 100644
--- a/src/cmd/compile/internal/liveness/bvset.go
+++ b/src/cmd/compile/internal/liveness/bvset.go
@@ -47,7 +47,7 @@ func (m *bvecSet) grow() {
m.index = newIndex
}
-// add adds bv to the set and returns its index in m.extractUniqe.
+// add adds bv to the set and returns its index in m.extractUnique.
// The caller must not modify bv after this.
func (m *bvecSet) add(bv bitvec.BitVec) int {
if len(m.uniq)*4 >= len(m.index) {
diff --git a/src/cmd/compile/internal/liveness/plive.go b/src/cmd/compile/internal/liveness/plive.go
index 8d1754c813..53ae797fce 100644
--- a/src/cmd/compile/internal/liveness/plive.go
+++ b/src/cmd/compile/internal/liveness/plive.go
@@ -17,12 +17,14 @@ package liveness
import (
"crypto/md5"
"fmt"
+ "sort"
"strings"
"cmd/compile/internal/base"
"cmd/compile/internal/bitvec"
"cmd/compile/internal/ir"
"cmd/compile/internal/objw"
+ "cmd/compile/internal/reflectdata"
"cmd/compile/internal/ssa"
"cmd/compile/internal/typebits"
"cmd/compile/internal/types"
@@ -174,14 +176,14 @@ type progeffectscache struct {
initialized bool
}
-// ShouldTrack reports whether the liveness analysis
+// shouldTrack reports whether the liveness analysis
// should track the variable n.
// We don't care about variables that have no pointers,
// nor do we care about non-local variables,
// nor do we care about empty structs (handled by the pointer check),
// nor do we care about the fake PAUTOHEAP variables.
-func ShouldTrack(n *ir.Name) bool {
- return (n.Class == ir.PAUTO || n.Class == ir.PPARAM || n.Class == ir.PPARAMOUT) && n.Type().HasPointers()
+func shouldTrack(n *ir.Name) bool {
+ return (n.Class == ir.PAUTO && n.Esc() != ir.EscHeap || n.Class == ir.PPARAM || n.Class == ir.PPARAMOUT) && n.Type().HasPointers()
}
// getvariables returns the list of on-stack variables that we need to track
@@ -189,7 +191,7 @@ func ShouldTrack(n *ir.Name) bool {
func getvariables(fn *ir.Func) ([]*ir.Name, map[*ir.Name]int32) {
var vars []*ir.Name
for _, n := range fn.Dcl {
- if ShouldTrack(n) {
+ if shouldTrack(n) {
vars = append(vars, n)
}
}
@@ -788,7 +790,7 @@ func (lv *liveness) epilogue() {
if n.Class == ir.PPARAM {
continue // ok
}
- base.Fatalf("bad live variable at entry of %v: %L", lv.fn.Nname, n)
+ base.FatalfAt(n.Pos(), "bad live variable at entry of %v: %L", lv.fn.Nname, n)
}
// Record live variables.
@@ -1060,7 +1062,7 @@ func (lv *liveness) printDebug() {
func (lv *liveness) emit() (argsSym, liveSym *obj.LSym) {
// Size args bitmaps to be just large enough to hold the largest pointer.
// First, find the largest Xoffset node we care about.
- // (Nodes without pointers aren't in lv.vars; see livenessShouldTrack.)
+ // (Nodes without pointers aren't in lv.vars; see ShouldTrack.)
var maxArgNode *ir.Name
for _, n := range lv.vars {
switch n.Class {
@@ -1179,9 +1181,54 @@ func Compute(curfn *ir.Func, f *ssa.Func, stkptrsize int64, pp *objw.Progs) Map
p.To.Name = obj.NAME_EXTERN
p.To.Sym = fninfo.GCLocals
+ if x := lv.emitStackObjects(); x != nil {
+ p := pp.Prog(obj.AFUNCDATA)
+ p.From.SetConst(objabi.FUNCDATA_StackObjects)
+ p.To.Type = obj.TYPE_MEM
+ p.To.Name = obj.NAME_EXTERN
+ p.To.Sym = x
+ }
+
return lv.livenessMap
}
+func (lv *liveness) emitStackObjects() *obj.LSym {
+ var vars []*ir.Name
+ for _, n := range lv.fn.Dcl {
+ if shouldTrack(n) && n.Addrtaken() && n.Esc() != ir.EscHeap {
+ vars = append(vars, n)
+ }
+ }
+ if len(vars) == 0 {
+ return nil
+ }
+
+ // Sort variables from lowest to highest address.
+ sort.Slice(vars, func(i, j int) bool { return vars[i].FrameOffset() < vars[j].FrameOffset() })
+
+ // Populate the stack object data.
+ // Format must match runtime/stack.go:stackObjectRecord.
+ x := base.Ctxt.Lookup(lv.fn.LSym.Name + ".stkobj")
+ lv.fn.LSym.Func().StackObjects = x
+ off := 0
+ off = objw.Uintptr(x, off, uint64(len(vars)))
+ for _, v := range vars {
+ // Note: arguments and return values have non-negative Xoffset,
+ // in which case the offset is relative to argp.
+ // Locals have a negative Xoffset, in which case the offset is relative to varp.
+ off = objw.Uintptr(x, off, uint64(v.FrameOffset()))
+ off = objw.SymPtr(x, off, reflectdata.TypeLinksym(v.Type()), 0)
+ }
+
+ if base.Flag.Live != 0 {
+ for _, v := range vars {
+ base.WarnfAt(v.Pos(), "stack object %v %v", v, v.Type())
+ }
+ }
+
+ return x
+}
+
// isfat reports whether a variable of type t needs multiple assignments to initialize.
// For example:
//
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index 4d20f410bc..c41b77c100 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -48,6 +48,9 @@ func (g *irgen) importDecl(p *noder, decl *syntax.ImportDecl) {
if ipkg == ir.Pkgs.Unsafe {
p.importedUnsafe = true
}
+ if ipkg.Path == "embed" {
+ p.importedEmbed = true
+ }
}
func (g *irgen) constDecl(out *ir.Nodes, decl *syntax.ConstDecl) {
@@ -164,9 +167,8 @@ func (g *irgen) varDecl(out *ir.Nodes, decl *syntax.VarDecl) {
if decl.Pragma != nil {
pragma := decl.Pragma.(*pragmas)
- if err := varEmbed(g.makeXPos, names[0], decl, pragma); err != nil {
- base.ErrorfAt(g.pos(decl), "%s", err.Error())
- }
+ // TODO(mdempsky): Plumb noder.importedEmbed through to here.
+ varEmbed(g.makeXPos, names[0], decl, pragma, true)
g.reportUnused(pragma)
}
diff --git a/src/cmd/compile/internal/noder/import.go b/src/cmd/compile/internal/noder/import.go
index ac7bc8bbf0..aa02c01cff 100644
--- a/src/cmd/compile/internal/noder/import.go
+++ b/src/cmd/compile/internal/noder/import.go
@@ -428,7 +428,7 @@ func clearImports() {
if types.IsDotAlias(s) {
// throw away top-level name left over
// from previous import . "x"
- // We'll report errors after type checking in checkDotImports.
+ // We'll report errors after type checking in CheckDotImports.
s.Def = nil
continue
}
diff --git a/src/cmd/compile/internal/noder/lex.go b/src/cmd/compile/internal/noder/lex.go
index 1095f3344a..cdca9e55f3 100644
--- a/src/cmd/compile/internal/noder/lex.go
+++ b/src/cmd/compile/internal/noder/lex.go
@@ -28,6 +28,7 @@ const (
ir.Nosplit |
ir.Noinline |
ir.NoCheckPtr |
+ ir.RegisterParams | // TODO remove after register abi is working
ir.CgoUnsafeArgs |
ir.UintptrEscapes |
ir.Systemstack |
@@ -79,6 +80,8 @@ func pragmaFlag(verb string) ir.PragmaFlag {
// in the argument list.
// Used in syscall/dll_windows.go.
return ir.UintptrEscapes
+ case "go:registerparams": // TODO remove after register abi is working
+ return ir.RegisterParams
case "go:notinheap":
return ir.NotInHeap
}
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go
index e1ae2569e0..887205b9fb 100644
--- a/src/cmd/compile/internal/noder/noder.go
+++ b/src/cmd/compile/internal/noder/noder.go
@@ -5,7 +5,6 @@
package noder
import (
- "errors"
"fmt"
"go/constant"
"go/token"
@@ -136,7 +135,15 @@ func LoadPackage(filenames []string) {
for i := 0; i < len(typecheck.Target.Decls); i++ {
n := typecheck.Target.Decls[i]
if n.Op() == ir.ODCLFUNC {
+ if base.Flag.W > 1 {
+ s := fmt.Sprintf("\nbefore typecheck %v", n)
+ ir.Dump(s, n)
+ }
typecheck.FuncBody(n.(*ir.Func))
+ if base.Flag.W > 1 {
+ s := fmt.Sprintf("\nafter typecheck %v", n)
+ ir.Dump(s, n)
+ }
fcount++
}
}
@@ -385,9 +392,7 @@ func (p *noder) varDecl(decl *syntax.VarDecl) []ir.Node {
exprs := p.exprList(decl.Values)
if pragma, ok := decl.Pragma.(*pragmas); ok {
- if err := varEmbed(p.makeXPos, names[0], decl, pragma); err != nil {
- p.errorAt(decl.Pos(), "%s", err.Error())
- }
+ varEmbed(p.makeXPos, names[0], decl, pragma, p.importedEmbed)
p.checkUnused(pragma)
}
@@ -555,7 +560,7 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {
}
} else {
f.Shortname = name
- name = ir.BlankNode.Sym() // filled in by typecheckfunc
+ name = ir.BlankNode.Sym() // filled in by tcFunc
}
f.Nname = ir.NewNameAt(p.pos(fun.Name), name)
@@ -1001,7 +1006,7 @@ func (p *noder) stmtsFall(stmts []syntax.Stmt, fallOK bool) []ir.Node {
if s == nil {
} else if s.Op() == ir.OBLOCK && len(s.(*ir.BlockStmt).List) > 0 {
// Inline non-empty block.
- // Empty blocks must be preserved for checkreturn.
+ // Empty blocks must be preserved for CheckReturn.
nodes = append(nodes, s.(*ir.BlockStmt).List...)
} else {
nodes = append(nodes, s)
@@ -1774,7 +1779,7 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
fn := ir.NewFunc(p.pos(expr))
fn.SetIsHiddenClosure(ir.CurFunc != nil)
- fn.Nname = ir.NewNameAt(p.pos(expr), ir.BlankNode.Sym()) // filled in by typecheckclosure
+ fn.Nname = ir.NewNameAt(p.pos(expr), ir.BlankNode.Sym()) // filled in by tcClosure
fn.Nname.Func = fn
fn.Nname.Ntype = xtype
fn.Nname.Defn = fn
@@ -1829,29 +1834,35 @@ func oldname(s *types.Sym) ir.Node {
return n
}
-func varEmbed(makeXPos func(syntax.Pos) src.XPos, name *ir.Name, decl *syntax.VarDecl, pragma *pragmas) error {
+func varEmbed(makeXPos func(syntax.Pos) src.XPos, name *ir.Name, decl *syntax.VarDecl, pragma *pragmas, haveEmbed bool) {
if pragma.Embeds == nil {
- return nil
+ return
}
pragmaEmbeds := pragma.Embeds
pragma.Embeds = nil
+ pos := makeXPos(pragmaEmbeds[0].Pos)
- if base.Flag.Cfg.Embed.Patterns == nil {
- return errors.New("invalid go:embed: build system did not supply embed configuration")
+ if !haveEmbed {
+ base.ErrorfAt(pos, "go:embed only allowed in Go files that import \"embed\"")
+ return
}
if len(decl.NameList) > 1 {
- return errors.New("go:embed cannot apply to multiple vars")
+ base.ErrorfAt(pos, "go:embed cannot apply to multiple vars")
+ return
}
if decl.Values != nil {
- return errors.New("go:embed cannot apply to var with initializer")
+ base.ErrorfAt(pos, "go:embed cannot apply to var with initializer")
+ return
}
if decl.Type == nil {
// Should not happen, since Values == nil now.
- return errors.New("go:embed cannot apply to var without type")
+ base.ErrorfAt(pos, "go:embed cannot apply to var without type")
+ return
}
if typecheck.DeclContext != ir.PEXTERN {
- return errors.New("go:embed cannot apply to var inside func")
+ base.ErrorfAt(pos, "go:embed cannot apply to var inside func")
+ return
}
var embeds []ir.Embed
@@ -1860,5 +1871,4 @@ func varEmbed(makeXPos func(syntax.Pos) src.XPos, name *ir.Name, decl *syntax.Va
}
typecheck.Target.Embeds = append(typecheck.Target.Embeds, name)
name.Embed = &embeds
- return nil
}
diff --git a/src/cmd/compile/internal/objw/prog.go b/src/cmd/compile/internal/objw/prog.go
index 8d24f94aa5..b5ac4dda1e 100644
--- a/src/cmd/compile/internal/objw/prog.go
+++ b/src/cmd/compile/internal/objw/prog.go
@@ -205,7 +205,7 @@ func (pp *Progs) Append(p *obj.Prog, as obj.As, ftype obj.AddrType, freg int16,
func (pp *Progs) SetText(fn *ir.Func) {
if pp.Text != nil {
- base.Fatalf("Progs.settext called twice")
+ base.Fatalf("Progs.SetText called twice")
}
ptxt := pp.Prog(obj.ATEXT)
pp.Text = ptxt
diff --git a/src/cmd/compile/internal/pkginit/init.go b/src/cmd/compile/internal/pkginit/init.go
index 5bc66c7e1b..7cad262214 100644
--- a/src/cmd/compile/internal/pkginit/init.go
+++ b/src/cmd/compile/internal/pkginit/init.go
@@ -60,10 +60,10 @@ func Task() *ir.Name {
fns = append(fns, fn.Linksym())
}
if typecheck.InitTodoFunc.Dcl != nil {
- // We only generate temps using initTodo if there
+ // We only generate temps using InitTodoFunc if there
// are package-scope initialization statements, so
// something's weird if we get here.
- base.Fatalf("initTodo still has declarations")
+ base.Fatalf("InitTodoFunc still has declarations")
}
typecheck.InitTodoFunc = nil
diff --git a/src/cmd/compile/internal/pkginit/initorder.go b/src/cmd/compile/internal/pkginit/initorder.go
index bdefd594ff..97d69629fb 100644
--- a/src/cmd/compile/internal/pkginit/initorder.go
+++ b/src/cmd/compile/internal/pkginit/initorder.go
@@ -113,7 +113,7 @@ func initOrder(l []ir.Node) []ir.Node {
// first.
base.ExitIfErrors()
- o.findInitLoopAndExit(firstLHS(n), new([]*ir.Name))
+ o.findInitLoopAndExit(firstLHS(n), new([]*ir.Name), new(ir.NameSet))
base.Fatalf("initialization unfinished, but failed to identify loop")
}
}
@@ -184,10 +184,7 @@ func (o *InitOrder) flushReady(initialize func(ir.Node)) {
// path points to a slice used for tracking the sequence of
// variables/functions visited. Using a pointer to a slice allows the
// slice capacity to grow and limit reallocations.
-func (o *InitOrder) findInitLoopAndExit(n *ir.Name, path *[]*ir.Name) {
- // We implement a simple DFS loop-finding algorithm. This
- // could be faster, but initialization cycles are rare.
-
+func (o *InitOrder) findInitLoopAndExit(n *ir.Name, path *[]*ir.Name, ok *ir.NameSet) {
for i, x := range *path {
if x == n {
reportInitLoopAndExit((*path)[i:])
@@ -204,12 +201,19 @@ func (o *InitOrder) findInitLoopAndExit(n *ir.Name, path *[]*ir.Name) {
*path = append(*path, n)
for _, ref := range refers {
// Short-circuit variables that were initialized.
- if ref.Class == ir.PEXTERN && o.order[ref.Defn] == orderDone {
+ if ref.Class == ir.PEXTERN && o.order[ref.Defn] == orderDone || ok.Has(ref) {
continue
}
- o.findInitLoopAndExit(ref, path)
+ o.findInitLoopAndExit(ref, path, ok)
}
+
+ // n is not involved in a cycle.
+ // Record that fact to avoid checking it again when reached another way,
+ // or else this traversal will take exponential time traversing all paths
+ // through the part of the package's call graph implicated in the cycle.
+ ok.Add(n)
+
*path = (*path)[:len(*path)-1]
}
diff --git a/src/cmd/compile/internal/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go
index d576053753..fcd824f164 100644
--- a/src/cmd/compile/internal/reflectdata/alg.go
+++ b/src/cmd/compile/internal/reflectdata/alg.go
@@ -689,7 +689,7 @@ func EqString(s, t ir.Node) (eqlen *ir.BinaryExpr, eqmem *ir.CallExpr) {
// eqtab must be evaluated before eqdata, and shortcircuiting is required.
func EqInterface(s, t ir.Node) (eqtab *ir.BinaryExpr, eqdata *ir.CallExpr) {
if !types.Identical(s.Type(), t.Type()) {
- base.Fatalf("eqinterface %v %v", s.Type(), t.Type())
+ base.Fatalf("EqInterface %v %v", s.Type(), t.Type())
}
// func ifaceeq(tab *uintptr, x, y unsafe.Pointer) (ret bool)
// func efaceeq(typ *uintptr, x, y unsafe.Pointer) (ret bool)
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go
index 30857fff6d..3ff14c87f4 100644
--- a/src/cmd/compile/internal/reflectdata/reflect.go
+++ b/src/cmd/compile/internal/reflectdata/reflect.go
@@ -32,7 +32,7 @@ type itabEntry struct {
// symbols of each method in
// the itab, sorted by byte offset;
- // filled in by peekitabs
+ // filled in by CompileITabs
entries []*obj.LSym
}
@@ -401,7 +401,7 @@ func dimportpath(p *types.Pkg) {
}
// If we are compiling the runtime package, there are two runtime packages around
- // -- localpkg and Runtimepkg. We don't want to produce import path symbols for
+ // -- localpkg and Pkgs.Runtime. We don't want to produce import path symbols for
// both of them, so just produce one for localpkg.
if base.Ctxt.Pkgpath == "runtime" && p == ir.Pkgs.Runtime {
return
@@ -562,7 +562,7 @@ func dextratype(lsym *obj.LSym, ot int, t *types.Type, dataAdd int) int {
}
for _, a := range m {
- WriteType(a.type_)
+ writeType(a.type_)
}
ot = dgopkgpathOff(lsym, ot, typePkg(t))
@@ -613,7 +613,7 @@ func dextratypeData(lsym *obj.LSym, ot int, t *types.Type) int {
nsym := dname(a.name.Name, "", pkg, exported)
ot = objw.SymPtrOff(lsym, ot, nsym)
- ot = dmethodptrOff(lsym, ot, WriteType(a.mtype))
+ ot = dmethodptrOff(lsym, ot, writeType(a.mtype))
ot = dmethodptrOff(lsym, ot, a.isym)
ot = dmethodptrOff(lsym, ot, a.tsym)
}
@@ -690,7 +690,7 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int {
if t.Sym() != nil || methods(tptr) != nil {
sptrWeak = false
}
- sptr = WriteType(tptr)
+ sptr = writeType(tptr)
}
gcsym, useGCProg, ptrdata := dgcsym(t)
@@ -791,7 +791,7 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int {
// TrackSym returns the symbol for tracking use of field/method f, assumed
// to be a member of struct/interface type t.
func TrackSym(t *types.Type, f *types.Field) *obj.LSym {
- return ir.Pkgs.Track.Lookup(t.ShortString() + "." + f.Sym.Name).Linksym()
+ return base.PkgLinksym("go.track", t.ShortString()+"."+f.Sym.Name, obj.ABI0)
}
func TypeSymPrefix(prefix string, t *types.Type) *types.Sym {
@@ -811,7 +811,7 @@ func TypeSymPrefix(prefix string, t *types.Type) *types.Sym {
func TypeSym(t *types.Type) *types.Sym {
if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() {
- base.Fatalf("typenamesym %v", t)
+ base.Fatalf("TypeSym %v", t)
}
if t.Kind() == types.TFUNC && t.Recv() != nil {
base.Fatalf("misuse of method type: %v", t)
@@ -836,39 +836,22 @@ func TypeLinksym(t *types.Type) *obj.LSym {
}
func TypePtr(t *types.Type) *ir.AddrExpr {
- s := TypeSym(t)
- if s.Def == nil {
- n := ir.NewNameAt(src.NoXPos, s)
- n.SetType(types.Types[types.TUINT8])
- n.Class = ir.PEXTERN
- n.SetTypecheck(1)
- s.Def = n
- }
-
- n := typecheck.NodAddr(ir.AsNode(s.Def))
- n.SetType(types.NewPtr(s.Def.Type()))
- n.SetTypecheck(1)
- return n
+ n := ir.NewLinksymExpr(base.Pos, TypeLinksym(t), types.Types[types.TUINT8])
+ return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
}
func ITabAddr(t, itype *types.Type) *ir.AddrExpr {
if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() || !itype.IsInterface() || itype.IsEmptyInterface() {
- base.Fatalf("itabname(%v, %v)", t, itype)
- }
- s := ir.Pkgs.Itab.Lookup(t.ShortString() + "," + itype.ShortString())
- if s.Def == nil {
- n := typecheck.NewName(s)
- n.SetType(types.Types[types.TUINT8])
- n.Class = ir.PEXTERN
- n.SetTypecheck(1)
- s.Def = n
- itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: n.Linksym()})
- }
-
- n := typecheck.NodAddr(ir.AsNode(s.Def))
- n.SetType(types.NewPtr(s.Def.Type()))
- n.SetTypecheck(1)
- return n
+ base.Fatalf("ITabAddr(%v, %v)", t, itype)
+ }
+ s, existed := ir.Pkgs.Itab.LookupOK(t.ShortString() + "," + itype.ShortString())
+ if !existed {
+ itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: s.Linksym()})
+ }
+
+ lsym := s.Linksym()
+ n := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8])
+ return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
}
// needkeyupdate reports whether map updates with t as a key
@@ -933,10 +916,10 @@ func formalType(t *types.Type) *types.Type {
return t
}
-func WriteType(t *types.Type) *obj.LSym {
+func writeType(t *types.Type) *obj.LSym {
t = formalType(t)
if t.IsUntyped() {
- base.Fatalf("dtypesym %v", t)
+ base.Fatalf("writeType %v", t)
}
s := types.TypeSym(t)
@@ -983,9 +966,9 @@ func WriteType(t *types.Type) *obj.LSym {
case types.TARRAY:
// ../../../../runtime/type.go:/arrayType
- s1 := WriteType(t.Elem())
+ s1 := writeType(t.Elem())
t2 := types.NewSlice(t.Elem())
- s2 := WriteType(t2)
+ s2 := writeType(t2)
ot = dcommontype(lsym, t)
ot = objw.SymPtr(lsym, ot, s1, 0)
ot = objw.SymPtr(lsym, ot, s2, 0)
@@ -994,14 +977,14 @@ func WriteType(t *types.Type) *obj.LSym {
case types.TSLICE:
// ../../../../runtime/type.go:/sliceType
- s1 := WriteType(t.Elem())
+ s1 := writeType(t.Elem())
ot = dcommontype(lsym, t)
ot = objw.SymPtr(lsym, ot, s1, 0)
ot = dextratype(lsym, ot, t, 0)
case types.TCHAN:
// ../../../../runtime/type.go:/chanType
- s1 := WriteType(t.Elem())
+ s1 := writeType(t.Elem())
ot = dcommontype(lsym, t)
ot = objw.SymPtr(lsym, ot, s1, 0)
ot = objw.Uintptr(lsym, ot, uint64(t.ChanDir()))
@@ -1009,15 +992,15 @@ func WriteType(t *types.Type) *obj.LSym {
case types.TFUNC:
for _, t1 := range t.Recvs().Fields().Slice() {
- WriteType(t1.Type)
+ writeType(t1.Type)
}
isddd := false
for _, t1 := range t.Params().Fields().Slice() {
isddd = t1.IsDDD()
- WriteType(t1.Type)
+ writeType(t1.Type)
}
for _, t1 := range t.Results().Fields().Slice() {
- WriteType(t1.Type)
+ writeType(t1.Type)
}
ot = dcommontype(lsym, t)
@@ -1037,20 +1020,20 @@ func WriteType(t *types.Type) *obj.LSym {
// Array of rtype pointers follows funcType.
for _, t1 := range t.Recvs().Fields().Slice() {
- ot = objw.SymPtr(lsym, ot, WriteType(t1.Type), 0)
+ ot = objw.SymPtr(lsym, ot, writeType(t1.Type), 0)
}
for _, t1 := range t.Params().Fields().Slice() {
- ot = objw.SymPtr(lsym, ot, WriteType(t1.Type), 0)
+ ot = objw.SymPtr(lsym, ot, writeType(t1.Type), 0)
}
for _, t1 := range t.Results().Fields().Slice() {
- ot = objw.SymPtr(lsym, ot, WriteType(t1.Type), 0)
+ ot = objw.SymPtr(lsym, ot, writeType(t1.Type), 0)
}
case types.TINTER:
m := imethods(t)
n := len(m)
for _, a := range m {
- WriteType(a.type_)
+ writeType(a.type_)
}
// ../../../../runtime/type.go:/interfaceType
@@ -1078,14 +1061,14 @@ func WriteType(t *types.Type) *obj.LSym {
nsym := dname(a.name.Name, "", pkg, exported)
ot = objw.SymPtrOff(lsym, ot, nsym)
- ot = objw.SymPtrOff(lsym, ot, WriteType(a.type_))
+ ot = objw.SymPtrOff(lsym, ot, writeType(a.type_))
}
// ../../../../runtime/type.go:/mapType
case types.TMAP:
- s1 := WriteType(t.Key())
- s2 := WriteType(t.Elem())
- s3 := WriteType(MapBucketType(t))
+ s1 := writeType(t.Key())
+ s2 := writeType(t.Elem())
+ s3 := writeType(MapBucketType(t))
hasher := genhash(t.Key())
ot = dcommontype(lsym, t)
@@ -1132,7 +1115,7 @@ func WriteType(t *types.Type) *obj.LSym {
}
// ../../../../runtime/type.go:/ptrType
- s1 := WriteType(t.Elem())
+ s1 := writeType(t.Elem())
ot = dcommontype(lsym, t)
ot = objw.SymPtr(lsym, ot, s1, 0)
@@ -1143,7 +1126,7 @@ func WriteType(t *types.Type) *obj.LSym {
case types.TSTRUCT:
fields := t.Fields().Slice()
for _, t1 := range fields {
- WriteType(t1.Type)
+ writeType(t1.Type)
}
// All non-exported struct field names within a struct
@@ -1171,7 +1154,7 @@ func WriteType(t *types.Type) *obj.LSym {
for _, f := range fields {
// ../../../../runtime/type.go:/structField
ot = dnameField(lsym, ot, spkg, f)
- ot = objw.SymPtr(lsym, ot, WriteType(f.Type), 0)
+ ot = objw.SymPtr(lsym, ot, writeType(f.Type), 0)
offsetAnon := uint64(f.Offset) << 1
if offsetAnon>>1 != uint64(f.Offset) {
base.Fatalf("%v: bad field offset for %s", t, f.Sym.Name)
@@ -1275,7 +1258,7 @@ func genfun(t, it *types.Type) []*obj.LSym {
}
// ITabSym uses the information gathered in
-// peekitabs to de-virtualize interface methods.
+// CompileITabs to de-virtualize interface methods.
// Since this is called by the SSA backend, it shouldn't
// generate additional Nodes, Syms, etc.
func ITabSym(it *obj.LSym, offset int64) *obj.LSym {
@@ -1312,7 +1295,7 @@ func NeedRuntimeType(t *types.Type) {
}
func WriteRuntimeTypes() {
- // Process signatset. Use a loop, as dtypesym adds
+ // Process signatset. Use a loop, as writeType adds
// entries to signatset while it is being processed.
signats := make([]typeAndStr, len(signatslice))
for len(signatslice) > 0 {
@@ -1326,9 +1309,9 @@ func WriteRuntimeTypes() {
sort.Sort(typesByString(signats))
for _, ts := range signats {
t := ts.t
- WriteType(t)
+ writeType(t)
if t.Sym() != nil {
- WriteType(types.NewPtr(t))
+ writeType(types.NewPtr(t))
}
}
}
@@ -1345,8 +1328,8 @@ func WriteTabs() {
// _ [4]byte
// fun [1]uintptr // variable sized
// }
- o := objw.SymPtr(i.lsym, 0, WriteType(i.itype), 0)
- o = objw.SymPtr(i.lsym, o, WriteType(i.t), 0)
+ o := objw.SymPtr(i.lsym, 0, writeType(i.itype), 0)
+ o = objw.SymPtr(i.lsym, o, writeType(i.t), 0)
o = objw.Uint32(i.lsym, o, types.TypeHash(i.t)) // copy of type hash
o += 4 // skip unused field
for _, fn := range genfun(i.t, i.itype) {
@@ -1373,7 +1356,7 @@ func WriteTabs() {
if p.Class != ir.PFUNC {
t = types.NewPtr(t)
}
- tsym := WriteType(t)
+ tsym := writeType(t)
ot = objw.SymPtrOff(s, ot, nsym)
ot = objw.SymPtrOff(s, ot, tsym)
// Plugin exports symbols as interfaces. Mark their types
@@ -1407,16 +1390,16 @@ func WriteBasicTypes() {
// but using runtime means fewer copies in object files.
if base.Ctxt.Pkgpath == "runtime" {
for i := types.Kind(1); i <= types.TBOOL; i++ {
- WriteType(types.NewPtr(types.Types[i]))
+ writeType(types.NewPtr(types.Types[i]))
}
- WriteType(types.NewPtr(types.Types[types.TSTRING]))
- WriteType(types.NewPtr(types.Types[types.TUNSAFEPTR]))
+ writeType(types.NewPtr(types.Types[types.TSTRING]))
+ writeType(types.NewPtr(types.Types[types.TUNSAFEPTR]))
// emit type structs for error and func(error) string.
// The latter is the type of an auto-generated wrapper.
- WriteType(types.NewPtr(types.ErrorType))
+ writeType(types.NewPtr(types.ErrorType))
- WriteType(types.NewSignature(types.NoPkg, nil, []*types.Field{
+ writeType(types.NewSignature(types.NoPkg, nil, []*types.Field{
types.NewField(base.Pos, nil, types.ErrorType),
}, []*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TSTRING]),
@@ -1426,11 +1409,12 @@ func WriteBasicTypes() {
dimportpath(ir.Pkgs.Runtime)
if base.Flag.Race {
- dimportpath(ir.Pkgs.Race)
+ dimportpath(types.NewPkg("runtime/race", ""))
}
if base.Flag.MSan {
- dimportpath(ir.Pkgs.Msan)
+ dimportpath(types.NewPkg("runtime/msan", ""))
}
+
dimportpath(types.NewPkg("main", ""))
}
}
@@ -1617,13 +1601,13 @@ func (p *gcProg) emit(t *types.Type, offset int64) {
}
switch t.Kind() {
default:
- base.Fatalf("GCProg.emit: unexpected type %v", t)
+ base.Fatalf("gcProg.emit: unexpected type %v", t)
case types.TSTRING:
p.w.Ptr(offset / int64(types.PtrSize))
case types.TINTER:
- // Note: the first word isn't a pointer. See comment in plive.go:onebitwalktype1.
+ // Note: the first word isn't a pointer. See comment in typebits.Set
p.w.Ptr(offset/int64(types.PtrSize) + 1)
case types.TSLICE:
@@ -1632,7 +1616,7 @@ func (p *gcProg) emit(t *types.Type, offset int64) {
case types.TARRAY:
if t.NumElem() == 0 {
// should have been handled by haspointers check above
- base.Fatalf("GCProg.emit: empty array")
+ base.Fatalf("gcProg.emit: empty array")
}
// Flatten array-of-array-of-array to just a big array by multiplying counts.
@@ -1670,18 +1654,9 @@ func ZeroAddr(size int64) ir.Node {
if ZeroSize < size {
ZeroSize = size
}
- s := ir.Pkgs.Map.Lookup("zero")
- if s.Def == nil {
- x := typecheck.NewName(s)
- x.SetType(types.Types[types.TUINT8])
- x.Class = ir.PEXTERN
- x.SetTypecheck(1)
- s.Def = x
- }
- z := typecheck.NodAddr(ir.AsNode(s.Def))
- z.SetType(types.NewPtr(types.Types[types.TUINT8]))
- z.SetTypecheck(1)
- return z
+ lsym := base.PkgLinksym("go.map", "zero", obj.ABI0)
+ x := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8])
+ return typecheck.Expr(typecheck.NodAddr(x))
}
func CollectPTabs() {
@@ -1794,7 +1769,7 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym {
}
as := ir.NewAssignStmt(base.Pos, nthis, typecheck.ConvNop(left, rcvr))
fn.Body.Append(as)
- fn.Body.Append(ir.NewBranchStmt(base.Pos, ir.ORETJMP, ir.MethodSym(methodrcvr, method.Sym)))
+ fn.Body.Append(ir.NewTailCallStmt(base.Pos, method.Nname.(*ir.Name)))
} else {
fn.SetWrapper(true) // ignore frame for panic+recover matching
call := ir.NewCallExpr(base.Pos, ir.OCALL, dot, nil)
diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go
index 530918da4d..0cf9931dbc 100644
--- a/src/cmd/compile/internal/ssa/deadstore.go
+++ b/src/cmd/compile/internal/ssa/deadstore.go
@@ -139,7 +139,7 @@ func dse(f *Func) {
func elimDeadAutosGeneric(f *Func) {
addr := make(map[*Value]*ir.Name) // values that the address of the auto reaches
elim := make(map[*Value]*ir.Name) // values that could be eliminated if the auto is
- used := make(map[*ir.Name]bool) // used autos that must be kept
+ var used ir.NameSet // used autos that must be kept
// visit the value and report whether any of the maps are updated
visit := func(v *Value) (changed bool) {
@@ -178,8 +178,8 @@ func elimDeadAutosGeneric(f *Func) {
if !ok || n.Class != ir.PAUTO {
return
}
- if !used[n] {
- used[n] = true
+ if !used.Has(n) {
+ used.Add(n)
changed = true
}
return
@@ -212,8 +212,8 @@ func elimDeadAutosGeneric(f *Func) {
if v.Type.IsMemory() || v.Type.IsFlags() || v.Op == OpPhi || v.MemoryArg() != nil {
for _, a := range args {
if n, ok := addr[a]; ok {
- if !used[n] {
- used[n] = true
+ if !used.Has(n) {
+ used.Add(n)
changed = true
}
}
@@ -224,7 +224,7 @@ func elimDeadAutosGeneric(f *Func) {
// Propagate any auto addresses through v.
var node *ir.Name
for _, a := range args {
- if n, ok := addr[a]; ok && !used[n] {
+ if n, ok := addr[a]; ok && !used.Has(n) {
if node == nil {
node = n
} else if node != n {
@@ -233,7 +233,7 @@ func elimDeadAutosGeneric(f *Func) {
// multiple pointers (e.g. NeqPtr, Phi etc.).
// This is rare, so just propagate the first
// value to keep things simple.
- used[n] = true
+ used.Add(n)
changed = true
}
}
@@ -249,7 +249,7 @@ func elimDeadAutosGeneric(f *Func) {
}
if addr[v] != node {
// This doesn't happen in practice, but catch it just in case.
- used[node] = true
+ used.Add(node)
changed = true
}
return
@@ -269,8 +269,8 @@ func elimDeadAutosGeneric(f *Func) {
}
// keep the auto if its address reaches a control value
for _, c := range b.ControlValues() {
- if n, ok := addr[c]; ok && !used[n] {
- used[n] = true
+ if n, ok := addr[c]; ok && !used.Has(n) {
+ used.Add(n)
changed = true
}
}
@@ -282,7 +282,7 @@ func elimDeadAutosGeneric(f *Func) {
// Eliminate stores to unread autos.
for v, n := range elim {
- if used[n] {
+ if used.Has(n) {
continue
}
// replace with OpCopy
diff --git a/src/cmd/compile/internal/ssa/expand_calls.go b/src/cmd/compile/internal/ssa/expand_calls.go
index e1c657d4a4..af994d4b5b 100644
--- a/src/cmd/compile/internal/ssa/expand_calls.go
+++ b/src/cmd/compile/internal/ssa/expand_calls.go
@@ -24,6 +24,10 @@ type offsetKey struct {
pt *types.Type
}
+func isBlockMultiValueExit(b *Block) bool {
+ return (b.Kind == BlockRet || b.Kind == BlockRetJmp) && len(b.Controls) > 0 && b.Controls[0].Op == OpMakeResult
+}
+
// expandCalls converts LE (Late Expansion) calls that act like they receive value args into a lower-level form
// that is more oriented to a platform's ABI. The SelectN operations that extract results are rewritten into
// more appropriate forms, and any StructMake or ArrayMake inputs are decomposed until non-struct values are
@@ -194,7 +198,8 @@ func expandCalls(f *Func) {
}
break
}
- if leaf.Op == OpIData {
+ switch leaf.Op {
+ case OpIData, OpStructSelect, OpArraySelect:
leafType = removeTrivialWrapperTypes(leaf.Type)
}
aux := selector.Aux
@@ -624,6 +629,24 @@ func expandCalls(f *Func) {
return x
}
+ rewriteDereference := func(b *Block, base, a, mem *Value, offset, size int64, typ *types.Type, pos src.XPos) *Value {
+ source := a.Args[0]
+ dst := offsetFrom(base, offset, source.Type)
+ if a.Uses == 1 && a.Block == b {
+ a.reset(OpMove)
+ a.Pos = pos
+ a.Type = types.TypeMem
+ a.Aux = typ
+ a.AuxInt = size
+ a.SetArgs3(dst, source, mem)
+ mem = a
+ } else {
+ mem = b.NewValue3A(pos, OpMove, types.TypeMem, typ, dst, source, mem)
+ mem.AuxInt = size
+ }
+ return mem
+ }
+
// rewriteArgs removes all the Args from a call and converts the call args into appropriate
// stores (or later, register movement). Extra args for interface and closure calls are ignored,
// but removed.
@@ -631,7 +654,7 @@ func expandCalls(f *Func) {
// Thread the stores on the memory arg
aux := v.Aux.(*AuxCall)
pos := v.Pos.WithNotStmt()
- m0 := v.Args[len(v.Args)-1]
+ m0 := v.MemoryArg()
mem := m0
for i, a := range v.Args {
if i < firstArg {
@@ -647,20 +670,7 @@ func expandCalls(f *Func) {
}
// "Dereference" of addressed (probably not-SSA-eligible) value becomes Move
// TODO this will be more complicated with registers in the picture.
- source := a.Args[0]
- dst := f.ConstOffPtrSP(source.Type, aux.OffsetOfArg(auxI), sp)
- if a.Uses == 1 && a.Block == v.Block {
- a.reset(OpMove)
- a.Pos = pos
- a.Type = types.TypeMem
- a.Aux = aux.TypeOfArg(auxI)
- a.AuxInt = aux.SizeOfArg(auxI)
- a.SetArgs3(dst, source, mem)
- mem = a
- } else {
- mem = v.Block.NewValue3A(pos, OpMove, types.TypeMem, aux.TypeOfArg(auxI), dst, source, mem)
- mem.AuxInt = aux.SizeOfArg(auxI)
- }
+ mem = rewriteDereference(v.Block, sp, a, mem, aux.OffsetOfArg(auxI), aux.SizeOfArg(auxI), aux.TypeOfArg(auxI), pos)
} else {
if debug {
fmt.Printf("storeArg %s, %v, %d\n", a.LongString(), aux.TypeOfArg(auxI), aux.OffsetOfArg(auxI))
@@ -692,6 +702,45 @@ func expandCalls(f *Func) {
v.SetArgs2(code, mem)
}
}
+ if isBlockMultiValueExit(b) {
+ // Very similar to code in rewriteArgs, but results instead of args.
+ v := b.Controls[0]
+ m0 := v.MemoryArg()
+ mem := m0
+ aux := f.OwnAux
+ pos := v.Pos.WithNotStmt()
+ for j, a := range v.Args {
+ i := int64(j)
+ if a == m0 {
+ break
+ }
+ auxType := aux.TypeOfResult(i)
+ auxBase := b.NewValue2A(v.Pos, OpLocalAddr, types.NewPtr(auxType), aux.results[i].Name, sp, mem)
+ auxOffset := int64(0)
+ auxSize := aux.SizeOfResult(i)
+ if a.Op == OpDereference {
+ // Avoid a self-move, and if one is detected try to remove the already-inserted VarDef for the assignment that won't happen.
+ if dAddr, dMem := a.Args[0], a.Args[1]; dAddr.Op == OpLocalAddr && dAddr.Args[0].Op == OpSP &&
+ dAddr.Args[1] == dMem && dAddr.Aux == aux.results[i].Name {
+ if dMem.Op == OpVarDef && dMem.Aux == dAddr.Aux {
+ dMem.copyOf(dMem.MemoryArg()) // elide the VarDef
+ }
+ continue
+ }
+ mem = rewriteDereference(v.Block, auxBase, a, mem, auxOffset, auxSize, auxType, pos)
+ } else {
+ if a.Op == OpLoad && a.Args[0].Op == OpLocalAddr {
+ addr := a.Args[0]
+ if addr.MemoryArg() == a.MemoryArg() && addr.Aux == aux.results[i].Name {
+ continue
+ }
+ }
+ mem = storeArgOrLoad(v.Pos, b, auxBase, a, mem, aux.TypeOfResult(i), auxOffset)
+ }
+ }
+ b.SetControl(mem)
+ v.reset(OpInvalid) // otherwise it can have a mem operand which will fail check(), even though it is dead.
+ }
}
for i, name := range f.Names {
diff --git a/src/cmd/compile/internal/ssa/func.go b/src/cmd/compile/internal/ssa/func.go
index e6c4798a78..de99a8d4af 100644
--- a/src/cmd/compile/internal/ssa/func.go
+++ b/src/cmd/compile/internal/ssa/func.go
@@ -58,6 +58,11 @@ type Func struct {
// of keys to make iteration order deterministic.
Names []LocalSlot
+ // RegArgs is a slice of register-memory pairs that must be spilled and unspilled in the uncommon path of function entry.
+ RegArgs []ArgPair
+ // AuxCall describing parameters and results for this function.
+ OwnAux *AuxCall
+
// WBLoads is a list of Blocks that branch on the write
// barrier flag. Safe-points are disabled from the OpLoad that
// reads the write-barrier flag until the control flow rejoins
@@ -771,7 +776,7 @@ func DebugNameMatch(evname, name string) bool {
}
func (f *Func) spSb() (sp, sb *Value) {
- initpos := f.Entry.Pos
+ initpos := src.NoXPos // These are originally created with no position in ssa.go; if they are optimized out then recreated, should be the same.
for _, v := range f.Entry.Values {
if v.Op == OpSB {
sb = v
@@ -780,7 +785,7 @@ func (f *Func) spSb() (sp, sb *Value) {
sp = v
}
if sb != nil && sp != nil {
- break
+ return
}
}
if sb == nil {
diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules
index fbc12fd672..df03cb71a6 100644
--- a/src/cmd/compile/internal/ssa/gen/386.rules
+++ b/src/cmd/compile/internal/ssa/gen/386.rules
@@ -475,7 +475,7 @@
(CMPB (MOVLconst [c]) x) => (InvertFlags (CMPBconst x [int8(c)]))
// Canonicalize the order of arguments to comparisons - helps with CSE.
-(CMP(L|W|B) x y) && x.ID > y.ID => (InvertFlags (CMP(L|W|B) y x))
+(CMP(L|W|B) x y) && canonLessThan(x,y) => (InvertFlags (CMP(L|W|B) y x))
// strength reduction
// Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf:
diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules
index a866a967b9..7d46266411 100644
--- a/src/cmd/compile/internal/ssa/gen/AMD64.rules
+++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules
@@ -916,7 +916,7 @@
(CMPB (MOVLconst [c]) x) => (InvertFlags (CMPBconst x [int8(c)]))
// Canonicalize the order of arguments to comparisons - helps with CSE.
-(CMP(Q|L|W|B) x y) && x.ID > y.ID => (InvertFlags (CMP(Q|L|W|B) y x))
+(CMP(Q|L|W|B) x y) && canonLessThan(x,y) => (InvertFlags (CMP(Q|L|W|B) y x))
// Using MOVZX instead of AND is cheaper.
(AND(Q|L)const [ 0xFF] x) => (MOVBQZX x)
diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules
index 11c36b5da3..de0df363e4 100644
--- a/src/cmd/compile/internal/ssa/gen/ARM.rules
+++ b/src/cmd/compile/internal/ssa/gen/ARM.rules
@@ -507,7 +507,7 @@
(TEQ x (MOVWconst [c])) => (TEQconst [c] x)
// Canonicalize the order of arguments to comparisons - helps with CSE.
-(CMP x y) && x.ID > y.ID => (InvertFlags (CMP y x))
+(CMP x y) && canonLessThan(x,y) => (InvertFlags (CMP y x))
// don't extend after proper load
// MOVWreg instruction is not emitted if src and dst registers are same, but it ensures the type.
diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules
index 3f4d0c1c52..a0e2a0d5e2 100644
--- a/src/cmd/compile/internal/ssa/gen/ARM64.rules
+++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules
@@ -1151,7 +1151,7 @@
(CMPW (MOVDconst [c]) x) => (InvertFlags (CMPWconst [int32(c)] x))
// Canonicalize the order of arguments to comparisons - helps with CSE.
-((CMP|CMPW) x y) && x.ID > y.ID => (InvertFlags ((CMP|CMPW) y x))
+((CMP|CMPW) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW) y x))
// mul-neg => mneg
(NEG (MUL x y)) => (MNEG x y)
diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
index 87db2b7c9d..b0bc9c78ff 100644
--- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
+++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
@@ -478,20 +478,24 @@ func init() {
// pseudo-ops
{name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpg}}, nilCheck: true, faultOnNilArg0: true}, // panic if arg0 is nil. arg1=mem.
- {name: "Equal", argLength: 1, reg: readflags}, // bool, true flags encode x==y false otherwise.
- {name: "NotEqual", argLength: 1, reg: readflags}, // bool, true flags encode x!=y false otherwise.
- {name: "LessThan", argLength: 1, reg: readflags}, // bool, true flags encode signed x<y false otherwise.
- {name: "LessEqual", argLength: 1, reg: readflags}, // bool, true flags encode signed x<=y false otherwise.
- {name: "GreaterThan", argLength: 1, reg: readflags}, // bool, true flags encode signed x>y false otherwise.
- {name: "GreaterEqual", argLength: 1, reg: readflags}, // bool, true flags encode signed x>=y false otherwise.
- {name: "LessThanU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x<y false otherwise.
- {name: "LessEqualU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x<=y false otherwise.
- {name: "GreaterThanU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x>y false otherwise.
- {name: "GreaterEqualU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x>=y false otherwise.
- {name: "LessThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<y false otherwise.
- {name: "LessEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<=y false otherwise.
- {name: "GreaterThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>y false otherwise.
- {name: "GreaterEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>=y false otherwise.
+ {name: "Equal", argLength: 1, reg: readflags}, // bool, true flags encode x==y false otherwise.
+ {name: "NotEqual", argLength: 1, reg: readflags}, // bool, true flags encode x!=y false otherwise.
+ {name: "LessThan", argLength: 1, reg: readflags}, // bool, true flags encode signed x<y false otherwise.
+ {name: "LessEqual", argLength: 1, reg: readflags}, // bool, true flags encode signed x<=y false otherwise.
+ {name: "GreaterThan", argLength: 1, reg: readflags}, // bool, true flags encode signed x>y false otherwise.
+ {name: "GreaterEqual", argLength: 1, reg: readflags}, // bool, true flags encode signed x>=y false otherwise.
+ {name: "LessThanU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x<y false otherwise.
+ {name: "LessEqualU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x<=y false otherwise.
+ {name: "GreaterThanU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x>y false otherwise.
+ {name: "GreaterEqualU", argLength: 1, reg: readflags}, // bool, true flags encode unsigned x>=y false otherwise.
+ {name: "LessThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<y false otherwise.
+ {name: "LessEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<=y false otherwise.
+ {name: "GreaterThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>y false otherwise.
+ {name: "GreaterEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>=y false otherwise.
+ {name: "NotLessThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>=y || x is unordered with y, false otherwise.
+ {name: "NotLessEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x>y || x is unordered with y, false otherwise.
+ {name: "NotGreaterThanF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<=y || x is unordered with y, false otherwise.
+ {name: "NotGreaterEqualF", argLength: 1, reg: readflags}, // bool, true flags encode floating-point x<y || x is unordered with y, false otherwise.
// duffzero
// arg0 = address of memory to zero
// arg1 = mem
diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules
index c064046172..a762be65d4 100644
--- a/src/cmd/compile/internal/ssa/gen/PPC64.rules
+++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules
@@ -1088,7 +1088,7 @@
(CMPWU (MOVDconst [c]) y) && isU16Bit(c) => (InvertFlags (CMPWUconst y [int32(c)]))
// Canonicalize the order of arguments to comparisons - helps with CSE.
-((CMP|CMPW|CMPU|CMPWU) x y) && x.ID > y.ID => (InvertFlags ((CMP|CMPW|CMPU|CMPWU) y x))
+((CMP|CMPW|CMPU|CMPWU) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW|CMPU|CMPWU) y x))
// ISEL auxInt values 0=LT 1=GT 2=EQ arg2 ? arg0 : arg1
// ISEL auxInt values 4=GE 5=LE 6=NE arg2 ? arg1 : arg0
diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules
index 384f2e807e..c3421da0a2 100644
--- a/src/cmd/compile/internal/ssa/gen/S390X.rules
+++ b/src/cmd/compile/internal/ssa/gen/S390X.rules
@@ -785,7 +785,7 @@
=> (RISBGZ x {s390x.NewRotateParams(r.Start, r.Start, -r.Start&63)})
// Canonicalize the order of arguments to comparisons - helps with CSE.
-((CMP|CMPW|CMPU|CMPWU) x y) && x.ID > y.ID => (InvertFlags ((CMP|CMPW|CMPU|CMPWU) y x))
+((CMP|CMPW|CMPU|CMPWU) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW|CMPU|CMPWU) y x))
// Use sign/zero extend instead of RISBGZ.
(RISBGZ x {r}) && r == s390x.NewRotateParams(56, 63, 0) => (MOVBZreg x)
diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules
index 81568b7b7a..1784923224 100644
--- a/src/cmd/compile/internal/ssa/gen/generic.rules
+++ b/src/cmd/compile/internal/ssa/gen/generic.rules
@@ -2512,7 +2512,7 @@
(Move {t1} [s] dst tmp1 midmem:(Move {t2} [s] tmp2 src _))
&& t1.Compare(t2) == types.CMPeq
&& isSamePtr(tmp1, tmp2)
- && isStackPtr(src)
+ && isStackPtr(src) && !isVolatile(src)
&& disjoint(src, s, tmp2, s)
&& (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
=> (Move {t1} [s] dst src midmem)
@@ -2521,7 +2521,7 @@
(Move {t1} [s] dst tmp1 midmem:(VarDef (Move {t2} [s] tmp2 src _)))
&& t1.Compare(t2) == types.CMPeq
&& isSamePtr(tmp1, tmp2)
- && isStackPtr(src)
+ && isStackPtr(src) && !isVolatile(src)
&& disjoint(src, s, tmp2, s)
&& (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
=> (Move {t1} [s] dst src midmem)
diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go
index a9d52fa4ee..c06b5808e1 100644
--- a/src/cmd/compile/internal/ssa/html.go
+++ b/src/cmd/compile/internal/ssa/html.go
@@ -9,9 +9,9 @@ import (
"cmd/internal/src"
"fmt"
"html"
+ exec "internal/execabs"
"io"
"os"
- "os/exec"
"path/filepath"
"strconv"
"strings"
diff --git a/src/cmd/compile/internal/ssa/location.go b/src/cmd/compile/internal/ssa/location.go
index 69f90d9ab4..4cd0ac8d77 100644
--- a/src/cmd/compile/internal/ssa/location.go
+++ b/src/cmd/compile/internal/ssa/location.go
@@ -87,3 +87,29 @@ func (t LocPair) String() string {
}
return fmt.Sprintf("<%s,%s>", n0, n1)
}
+
+type ArgPair struct {
+ reg *Register
+ mem LocalSlot
+}
+
+func (ap *ArgPair) Reg() int16 {
+ return ap.reg.objNum
+}
+
+func (ap *ArgPair) Type() *types.Type {
+ return ap.mem.Type
+}
+
+func (ap *ArgPair) Mem() *LocalSlot {
+ return &ap.mem
+}
+
+func (t ArgPair) String() string {
+ n0 := "nil"
+ if t.reg != nil {
+ n0 = t.reg.String()
+ }
+ n1 := t.mem.String()
+ return fmt.Sprintf("<%s,%s>", n0, n1)
+}
diff --git a/src/cmd/compile/internal/ssa/op.go b/src/cmd/compile/internal/ssa/op.go
index 5e6ce2b508..c64b145107 100644
--- a/src/cmd/compile/internal/ssa/op.go
+++ b/src/cmd/compile/internal/ssa/op.go
@@ -5,6 +5,7 @@
package ssa
import (
+ "cmd/compile/internal/ir"
"cmd/compile/internal/types"
"cmd/internal/obj"
"fmt"
@@ -70,7 +71,8 @@ type auxType int8
type Param struct {
Type *types.Type
- Offset int32 // TODO someday this will be a register
+ Offset int32 // Offset of Param if not in a register.
+ Name *ir.Name // For OwnAux, need to prepend stores with Vardefs
}
type AuxCall struct {
@@ -199,6 +201,12 @@ func ClosureAuxCall(args []Param, results []Param) *AuxCall {
func (*AuxCall) CanBeAnSSAAux() {}
+// OwnAuxCall returns a function's own AuxCall
+func OwnAuxCall(args []Param, results []Param) *AuxCall {
+ // TODO if this remains identical to ClosureAuxCall above after new ABI is done, should deduplicate.
+ return &AuxCall{Fn: nil, args: args, results: results}
+}
+
const (
auxNone auxType = iota
auxBool // auxInt is 0/1 for false/true
diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go
index 83d35cf7e1..e590f6ba5d 100644
--- a/src/cmd/compile/internal/ssa/opGen.go
+++ b/src/cmd/compile/internal/ssa/opGen.go
@@ -1564,6 +1564,10 @@ const (
OpARM64LessEqualF
OpARM64GreaterThanF
OpARM64GreaterEqualF
+ OpARM64NotLessThanF
+ OpARM64NotLessEqualF
+ OpARM64NotGreaterThanF
+ OpARM64NotGreaterEqualF
OpARM64DUFFZERO
OpARM64LoweredZero
OpARM64DUFFCOPY
@@ -20799,6 +20803,42 @@ var opcodeTable = [...]opInfo{
},
},
{
+ name: "NotLessThanF",
+ argLen: 1,
+ reg: regInfo{
+ outputs: []outputInfo{
+ {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30
+ },
+ },
+ },
+ {
+ name: "NotLessEqualF",
+ argLen: 1,
+ reg: regInfo{
+ outputs: []outputInfo{
+ {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30
+ },
+ },
+ },
+ {
+ name: "NotGreaterThanF",
+ argLen: 1,
+ reg: regInfo{
+ outputs: []outputInfo{
+ {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30
+ },
+ },
+ },
+ {
+ name: "NotGreaterEqualF",
+ argLen: 1,
+ reg: regInfo{
+ outputs: []outputInfo{
+ {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30
+ },
+ },
+ },
+ {
name: "DUFFZERO",
auxType: auxInt64,
argLen: 2,
diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go
index 9abfe0938b..e82aa84cdf 100644
--- a/src/cmd/compile/internal/ssa/rewrite.go
+++ b/src/cmd/compile/internal/ssa/rewrite.go
@@ -521,6 +521,18 @@ func shiftIsBounded(v *Value) bool {
return v.AuxInt != 0
}
+// canonLessThan returns whether x is "ordered" less than y, for purposes of normalizing
+// generated code as much as possible.
+func canonLessThan(x, y *Value) bool {
+ if x.Op != y.Op {
+ return x.Op < y.Op
+ }
+ if !x.Pos.SameFileAndLine(y.Pos) {
+ return x.Pos.Before(y.Pos)
+ }
+ return x.ID < y.ID
+}
+
// truncate64Fto32F converts a float64 value to a float32 preserving the bit pattern
// of the mantissa. It will panic if the truncation results in lost information.
func truncate64Fto32F(f float64) float32 {
@@ -984,9 +996,10 @@ func flagArg(v *Value) *Value {
}
// arm64Negate finds the complement to an ARM64 condition code,
-// for example Equal -> NotEqual or LessThan -> GreaterEqual
+// for example !Equal -> NotEqual or !LessThan -> GreaterEqual
//
-// TODO: add floating-point conditions
+// For floating point, it's more subtle because NaN is unordered. We do
+// !LessThanF -> NotLessThanF, the latter takes care of NaNs.
func arm64Negate(op Op) Op {
switch op {
case OpARM64LessThan:
@@ -1010,13 +1023,21 @@ func arm64Negate(op Op) Op {
case OpARM64NotEqual:
return OpARM64Equal
case OpARM64LessThanF:
- return OpARM64GreaterEqualF
- case OpARM64GreaterThanF:
- return OpARM64LessEqualF
+ return OpARM64NotLessThanF
+ case OpARM64NotLessThanF:
+ return OpARM64LessThanF
case OpARM64LessEqualF:
+ return OpARM64NotLessEqualF
+ case OpARM64NotLessEqualF:
+ return OpARM64LessEqualF
+ case OpARM64GreaterThanF:
+ return OpARM64NotGreaterThanF
+ case OpARM64NotGreaterThanF:
return OpARM64GreaterThanF
case OpARM64GreaterEqualF:
- return OpARM64LessThanF
+ return OpARM64NotGreaterEqualF
+ case OpARM64NotGreaterEqualF:
+ return OpARM64GreaterEqualF
default:
panic("unreachable")
}
@@ -1027,8 +1048,6 @@ func arm64Negate(op Op) Op {
// that the same result would be produced if the arguments
// to the flag-generating instruction were reversed, e.g.
// (InvertFlags (CMP x y)) -> (CMP y x)
-//
-// TODO: add floating-point conditions
func arm64Invert(op Op) Op {
switch op {
case OpARM64LessThan:
@@ -1057,6 +1076,14 @@ func arm64Invert(op Op) Op {
return OpARM64GreaterEqualF
case OpARM64GreaterEqualF:
return OpARM64LessEqualF
+ case OpARM64NotLessThanF:
+ return OpARM64NotGreaterThanF
+ case OpARM64NotGreaterThanF:
+ return OpARM64NotLessThanF
+ case OpARM64NotLessEqualF:
+ return OpARM64NotGreaterEqualF
+ case OpARM64NotGreaterEqualF:
+ return OpARM64NotLessEqualF
default:
panic("unreachable")
}
diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go
index 2acdccd568..4e7fdb9e63 100644
--- a/src/cmd/compile/internal/ssa/rewrite386.go
+++ b/src/cmd/compile/internal/ssa/rewrite386.go
@@ -1785,12 +1785,12 @@ func rewriteValue386_Op386CMPB(v *Value) bool {
return true
}
// match: (CMPB x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPB y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(Op386InvertFlags)
@@ -2078,12 +2078,12 @@ func rewriteValue386_Op386CMPL(v *Value) bool {
return true
}
// match: (CMPL x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPL y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(Op386InvertFlags)
@@ -2386,12 +2386,12 @@ func rewriteValue386_Op386CMPW(v *Value) bool {
return true
}
// match: (CMPW x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPW y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(Op386InvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go
index 75d4ff7357..db2dc7a004 100644
--- a/src/cmd/compile/internal/ssa/rewriteAMD64.go
+++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go
@@ -6749,12 +6749,12 @@ func rewriteValueAMD64_OpAMD64CMPB(v *Value) bool {
return true
}
// match: (CMPB x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPB y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpAMD64InvertFlags)
@@ -7135,12 +7135,12 @@ func rewriteValueAMD64_OpAMD64CMPL(v *Value) bool {
return true
}
// match: (CMPL x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPL y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpAMD64InvertFlags)
@@ -7544,12 +7544,12 @@ func rewriteValueAMD64_OpAMD64CMPQ(v *Value) bool {
return true
}
// match: (CMPQ x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPQ y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpAMD64InvertFlags)
@@ -8106,12 +8106,12 @@ func rewriteValueAMD64_OpAMD64CMPW(v *Value) bool {
return true
}
// match: (CMPW x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPW y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpAMD64InvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go
index d9d439fa63..c958aae2c4 100644
--- a/src/cmd/compile/internal/ssa/rewriteARM.go
+++ b/src/cmd/compile/internal/ssa/rewriteARM.go
@@ -3728,12 +3728,12 @@ func rewriteValueARM_OpARMCMP(v *Value) bool {
return true
}
// match: (CMP x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMP y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpARMInvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go
index 5d5e526add..ff1156d901 100644
--- a/src/cmd/compile/internal/ssa/rewriteARM64.go
+++ b/src/cmd/compile/internal/ssa/rewriteARM64.go
@@ -2772,12 +2772,12 @@ func rewriteValueARM64_OpARM64CMP(v *Value) bool {
return true
}
// match: (CMP x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMP y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpARM64InvertFlags)
@@ -2941,12 +2941,12 @@ func rewriteValueARM64_OpARM64CMPW(v *Value) bool {
return true
}
// match: (CMPW x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPW y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpARM64InvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go
index 455f9b1388..98f748e5fa 100644
--- a/src/cmd/compile/internal/ssa/rewritePPC64.go
+++ b/src/cmd/compile/internal/ssa/rewritePPC64.go
@@ -4777,12 +4777,12 @@ func rewriteValuePPC64_OpPPC64CMP(v *Value) bool {
return true
}
// match: (CMP x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMP y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpPPC64InvertFlags)
@@ -4834,12 +4834,12 @@ func rewriteValuePPC64_OpPPC64CMPU(v *Value) bool {
return true
}
// match: (CMPU x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPU y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpPPC64InvertFlags)
@@ -4964,12 +4964,12 @@ func rewriteValuePPC64_OpPPC64CMPW(v *Value) bool {
return true
}
// match: (CMPW x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPW y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpPPC64InvertFlags)
@@ -5045,12 +5045,12 @@ func rewriteValuePPC64_OpPPC64CMPWU(v *Value) bool {
return true
}
// match: (CMPWU x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPWU y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpPPC64InvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go
index a9722b820c..b52a1b6745 100644
--- a/src/cmd/compile/internal/ssa/rewriteS390X.go
+++ b/src/cmd/compile/internal/ssa/rewriteS390X.go
@@ -6332,12 +6332,12 @@ func rewriteValueS390X_OpS390XCMP(v *Value) bool {
return true
}
// match: (CMP x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMP y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpS390XInvertFlags)
@@ -6389,12 +6389,12 @@ func rewriteValueS390X_OpS390XCMPU(v *Value) bool {
return true
}
// match: (CMPU x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPU y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpS390XInvertFlags)
@@ -6624,12 +6624,12 @@ func rewriteValueS390X_OpS390XCMPW(v *Value) bool {
return true
}
// match: (CMPW x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPW y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpS390XInvertFlags)
@@ -6721,12 +6721,12 @@ func rewriteValueS390X_OpS390XCMPWU(v *Value) bool {
return true
}
// match: (CMPWU x y)
- // cond: x.ID > y.ID
+ // cond: canonLessThan(x,y)
// result: (InvertFlags (CMPWU y x))
for {
x := v_0
y := v_1
- if !(x.ID > y.ID) {
+ if !(canonLessThan(x, y)) {
break
}
v.reset(OpS390XInvertFlags)
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go
index 4cb9a8f328..958e24d29f 100644
--- a/src/cmd/compile/internal/ssa/rewritegeneric.go
+++ b/src/cmd/compile/internal/ssa/rewritegeneric.go
@@ -13637,7 +13637,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
return true
}
// match: (Move {t1} [s] dst tmp1 midmem:(Move {t2} [s] tmp2 src _))
- // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
+ // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
// result: (Move {t1} [s] dst src midmem)
for {
s := auxIntToInt64(v.AuxInt)
@@ -13651,7 +13651,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
t2 := auxToType(midmem.Aux)
src := midmem.Args[1]
tmp2 := midmem.Args[0]
- if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
+ if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
break
}
v.reset(OpMove)
@@ -13661,7 +13661,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
return true
}
// match: (Move {t1} [s] dst tmp1 midmem:(VarDef (Move {t2} [s] tmp2 src _)))
- // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
+ // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
// result: (Move {t1} [s] dst src midmem)
for {
s := auxIntToInt64(v.AuxInt)
@@ -13679,7 +13679,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
t2 := auxToType(midmem_0.Aux)
src := midmem_0.Args[1]
tmp2 := midmem_0.Args[0]
- if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
+ if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
break
}
v.reset(OpMove)
diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go
index dc27ec3a29..5bebce1db5 100644
--- a/src/cmd/compile/internal/ssagen/abi.go
+++ b/src/cmd/compile/internal/ssagen/abi.go
@@ -138,13 +138,12 @@ func ReadSymABIs(file, myimportpath string) {
// For body-less functions, we only create the LSym; for functions
// with bodies call a helper to setup up / populate the LSym.
func InitLSym(f *ir.Func, hasBody bool) {
- staticdata.NeedFuncSym(f.Sym())
-
// FIXME: for new-style ABI wrappers, we set up the lsym at the
// point the wrapper is created.
if f.LSym != nil && base.Flag.ABIWrap {
return
}
+ staticdata.NeedFuncSym(f.Sym())
selectLSym(f, hasBody)
if hasBody {
setupTextLSym(f, 0)
@@ -155,18 +154,18 @@ func InitLSym(f *ir.Func, hasBody bool) {
// makes calls to helpers to create ABI wrappers if needed.
func selectLSym(f *ir.Func, hasBody bool) {
if f.LSym != nil {
- base.FatalfAt(f.Pos(), "Func.initLSym called twice on %v", f)
+ base.FatalfAt(f.Pos(), "InitLSym called twice on %v", f)
}
if nam := f.Nname; !ir.IsBlank(nam) {
var wrapperABI obj.ABI
needABIWrapper := false
- defABI, hasDefABI := symabiDefs[nam.Sym().LinksymName()]
+ defABI, hasDefABI := symabiDefs[nam.Linksym().Name]
if hasDefABI && defABI == obj.ABI0 {
// Symbol is defined as ABI0. Create an
// Internal -> ABI0 wrapper.
- f.LSym = nam.Sym().LinksymABI0()
+ f.LSym = nam.LinksymABI(obj.ABI0)
needABIWrapper, wrapperABI = true, obj.ABIInternal
} else {
f.LSym = nam.Linksym()
@@ -302,8 +301,9 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {
// extra work in typecheck/walk/ssa, might want to add a new node
// OTAILCALL or something to this effect.
var tail ir.Node
- if tfn.Type().NumResults() == 0 && tfn.Type().NumParams() == 0 && tfn.Type().NumRecvs() == 0 {
- tail = ir.NewBranchStmt(base.Pos, ir.ORETJMP, f.Nname.Sym())
+ if tfn.Type().NumResults() == 0 && tfn.Type().NumParams() == 0 && tfn.Type().NumRecvs() == 0 && !(base.Ctxt.Arch.Name == "ppc64le" && base.Ctxt.Flag_dynlink) {
+
+ tail = ir.NewTailCallStmt(base.Pos, f.Nname)
} else {
call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil)
call.Args = ir.ParamNames(tfn.Type())
diff --git a/src/cmd/compile/internal/ssagen/nowb.go b/src/cmd/compile/internal/ssagen/nowb.go
index 60cfb2f698..a2434366a0 100644
--- a/src/cmd/compile/internal/ssagen/nowb.go
+++ b/src/cmd/compile/internal/ssagen/nowb.go
@@ -45,7 +45,7 @@ type nowritebarrierrecCall struct {
}
// newNowritebarrierrecChecker creates a nowritebarrierrecChecker. It
-// must be called before transformclosure and walk.
+// must be called before walk
func newNowritebarrierrecChecker() *nowritebarrierrecChecker {
c := &nowritebarrierrecChecker{
extraCalls: make(map[*ir.Func][]nowritebarrierrecCall),
@@ -54,7 +54,7 @@ func newNowritebarrierrecChecker() *nowritebarrierrecChecker {
// Find all systemstack calls and record their targets. In
// general, flow analysis can't see into systemstack, but it's
// important to handle it for this check, so we model it
- // directly. This has to happen before transformclosure since
+ // directly. This has to happen before transforming closures in walk since
// it's a lot harder to work out the argument after.
for _, n := range typecheck.Target.Decls {
if n.Op() != ir.ODCLFUNC {
diff --git a/src/cmd/compile/internal/ssagen/pgen.go b/src/cmd/compile/internal/ssagen/pgen.go
index bbd319d735..182f8408cf 100644
--- a/src/cmd/compile/internal/ssagen/pgen.go
+++ b/src/cmd/compile/internal/ssagen/pgen.go
@@ -96,7 +96,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
if n, ok := v.Aux.(*ir.Name); ok {
switch n.Class {
case ir.PPARAM, ir.PPARAMOUT:
- // Don't modify nodfp; it is a global.
+ // Don't modify RegFP; it is a global.
if n != ir.RegFP {
n.SetUsed(true)
}
diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go
index 54bde20f1c..ecf3294082 100644
--- a/src/cmd/compile/internal/ssagen/ssa.go
+++ b/src/cmd/compile/internal/ssagen/ssa.go
@@ -124,6 +124,7 @@ func InitConfig() {
ir.Syms.X86HasFMA = typecheck.LookupRuntimeVar("x86HasFMA") // bool
ir.Syms.ARMHasVFPv4 = typecheck.LookupRuntimeVar("armHasVFPv4") // bool
ir.Syms.ARM64HasATOMICS = typecheck.LookupRuntimeVar("arm64HasATOMICS") // bool
+ ir.Syms.Staticuint64s = typecheck.LookupRuntimeVar("staticuint64s")
ir.Syms.Typedmemclr = typecheck.LookupRuntimeFunc("typedmemclr")
ir.Syms.Typedmemmove = typecheck.LookupRuntimeFunc("typedmemmove")
ir.Syms.Udiv = typecheck.LookupRuntimeVar("udiv") // asm func with special ABI
@@ -356,6 +357,13 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
if fn.Pragma&ir.Nosplit != 0 {
s.f.NoSplit = true
}
+ if fn.Pragma&ir.RegisterParams != 0 { // TODO remove after register abi is working
+ if strings.Contains(name, ".") {
+ base.ErrorfAt(fn.Pos(), "Calls to //go:registerparams method %s won't work, remove the pragma from the declaration.", name)
+ }
+ s.f.Warnl(fn.Pos(), "declared function %v has register params", fn)
+ }
+
s.panics = map[funcLine]*ssa.Block{}
s.softFloat = s.config.SoftFloat
@@ -392,11 +400,20 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
}
if s.hasOpenDefers && len(s.curfn.Exit) > 0 {
// Skip doing open defers if there is any extra exit code (likely
- // copying heap-allocated return values or race detection), since
- // we will not generate that code in the case of the extra
- // deferreturn/ret segment.
+ // race detection), since we will not generate that code in the
+ // case of the extra deferreturn/ret segment.
s.hasOpenDefers = false
}
+ if s.hasOpenDefers {
+ // Similarly, skip if there are any heap-allocated result
+ // parameters that need to be copied back to their stack slots.
+ for _, f := range s.curfn.Type().Results().FieldSlice() {
+ if !f.Nname.(*ir.Name).OnStack() {
+ s.hasOpenDefers = false
+ break
+ }
+ }
+ }
if s.hasOpenDefers &&
s.curfn.NumReturns*s.curfn.NumDefers > 15 {
// Since we are generating defer calls at every exit for
@@ -442,24 +459,15 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
args = append(args, ssa.Param{Type: n.Type(), Offset: int32(n.FrameOffset())})
case ir.PPARAMOUT:
s.decladdrs[n] = s.entryNewValue2A(ssa.OpLocalAddr, types.NewPtr(n.Type()), n, s.sp, s.startmem)
- results = append(results, ssa.Param{Type: n.Type(), Offset: int32(n.FrameOffset())})
- if s.canSSA(n) {
- // Save ssa-able PPARAMOUT variables so we can
- // store them back to the stack at the end of
- // the function.
- s.returns = append(s.returns, n)
- }
+ results = append(results, ssa.Param{Type: n.Type(), Offset: int32(n.FrameOffset()), Name: n})
case ir.PAUTO:
// processed at each use, to prevent Addr coming
// before the decl.
- case ir.PAUTOHEAP:
- // moved to heap - already handled by frontend
- case ir.PFUNC:
- // local function - already handled by frontend
default:
s.Fatalf("local variable with class %v unimplemented", n.Class)
}
}
+ s.f.OwnAux = ssa.OwnAuxCall(args, results)
// Populate SSAable arguments.
for _, n := range fn.Dcl {
@@ -481,38 +489,35 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
}
offset = types.Rnd(offset, typ.Alignment())
- r := s.newValue1I(ssa.OpOffPtr, types.NewPtr(typ), offset, clo)
+ ptr := s.newValue1I(ssa.OpOffPtr, types.NewPtr(typ), offset, clo)
offset += typ.Size()
- if n.Byval() && TypeOK(n.Type()) {
- // If it is a small variable captured by value, downgrade it to PAUTO.
- r = s.load(n.Type(), r)
-
+ // If n is a small variable captured by value, promote
+ // it to PAUTO so it can be converted to SSA.
+ //
+ // Note: While we never capture a variable by value if
+ // the user took its address, we may have generated
+ // runtime calls that did (#43701). Since we don't
+ // convert Addrtaken variables to SSA anyway, no point
+ // in promoting them either.
+ if n.Byval() && !n.Addrtaken() && TypeOK(n.Type()) {
n.Class = ir.PAUTO
- } else {
- if !n.Byval() {
- r = s.load(typ, r)
- }
-
- // Declare variable holding address taken from closure.
- addr := ir.NewNameAt(fn.Pos(), &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg})
- addr.SetType(types.NewPtr(n.Type()))
- addr.Class = ir.PAUTO
- addr.SetUsed(true)
- addr.Curfn = fn
- types.CalcSize(addr.Type())
-
- n.Heapaddr = addr
- n = addr
+ fn.Dcl = append(fn.Dcl, n)
+ s.assign(n, s.load(n.Type(), ptr), false, 0)
+ continue
}
- fn.Dcl = append(fn.Dcl, n)
- s.assign(n, r, false, 0)
+ if !n.Byval() {
+ ptr = s.load(typ, ptr)
+ }
+ s.setHeapaddr(fn.Pos(), n, ptr)
}
}
// Convert the AST-based IR to the SSA-based IR
s.stmtList(fn.Enter)
+ s.zeroResults()
+ s.paramsToHeap()
s.stmtList(fn.Body)
// fallthrough to exit
@@ -528,6 +533,8 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
}
}
+ s.f.HTMLWriter.WritePhase("before insert phis", "before insert phis")
+
s.insertPhis()
// Main call to ssa package to compile function
@@ -540,6 +547,100 @@ func buildssa(fn *ir.Func, worker int) *ssa.Func {
return s.f
}
+// zeroResults zeros the return values at the start of the function.
+// We need to do this very early in the function. Defer might stop a
+// panic and show the return values as they exist at the time of
+// panic. For precise stacks, the garbage collector assumes results
+// are always live, so we need to zero them before any allocations,
+// even allocations to move params/results to the heap.
+func (s *state) zeroResults() {
+ for _, f := range s.curfn.Type().Results().FieldSlice() {
+ n := f.Nname.(*ir.Name)
+ if !n.OnStack() {
+ // The local which points to the return value is the
+ // thing that needs zeroing. This is already handled
+ // by a Needzero annotation in plive.go:(*liveness).epilogue.
+ continue
+ }
+ // Zero the stack location containing f.
+ if typ := n.Type(); TypeOK(typ) {
+ s.assign(n, s.zeroVal(typ), false, 0)
+ } else {
+ s.vars[memVar] = s.newValue1A(ssa.OpVarDef, types.TypeMem, n, s.mem())
+ s.zero(n.Type(), s.decladdrs[n])
+ }
+ }
+}
+
+// paramsToHeap produces code to allocate memory for heap-escaped parameters
+// and to copy non-result parameters' values from the stack.
+func (s *state) paramsToHeap() {
+ do := func(params *types.Type) {
+ for _, f := range params.FieldSlice() {
+ if f.Nname == nil {
+ continue // anonymous or blank parameter
+ }
+ n := f.Nname.(*ir.Name)
+ if ir.IsBlank(n) || n.OnStack() {
+ continue
+ }
+ s.newHeapaddr(n)
+ if n.Class == ir.PPARAM {
+ s.move(n.Type(), s.expr(n.Heapaddr), s.decladdrs[n])
+ }
+ }
+ }
+
+ typ := s.curfn.Type()
+ do(typ.Recvs())
+ do(typ.Params())
+ do(typ.Results())
+}
+
+// newHeapaddr allocates heap memory for n and sets its heap address.
+func (s *state) newHeapaddr(n *ir.Name) {
+ s.setHeapaddr(n.Pos(), n, s.newObject(n.Type()))
+}
+
+// setHeapaddr allocates a new PAUTO variable to store ptr (which must be non-nil)
+// and then sets it as n's heap address.
+func (s *state) setHeapaddr(pos src.XPos, n *ir.Name, ptr *ssa.Value) {
+ if !ptr.Type.IsPtr() || !types.Identical(n.Type(), ptr.Type.Elem()) {
+ base.FatalfAt(n.Pos(), "setHeapaddr %L with type %v", n, ptr.Type)
+ }
+
+ // Declare variable to hold address.
+ addr := ir.NewNameAt(pos, &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg})
+ addr.SetType(types.NewPtr(n.Type()))
+ addr.Class = ir.PAUTO
+ addr.SetUsed(true)
+ addr.Curfn = s.curfn
+ s.curfn.Dcl = append(s.curfn.Dcl, addr)
+ types.CalcSize(addr.Type())
+
+ if n.Class == ir.PPARAMOUT {
+ addr.SetIsOutputParamHeapAddr(true)
+ }
+
+ n.Heapaddr = addr
+ s.assign(addr, ptr, false, 0)
+}
+
+// newObject returns an SSA value denoting new(typ).
+func (s *state) newObject(typ *types.Type) *ssa.Value {
+ if typ.Size() == 0 {
+ return s.newValue1A(ssa.OpAddr, types.NewPtr(typ), ir.Syms.Zerobase, s.sb)
+ }
+ return s.rtcall(ir.Syms.Newobject, true, []*types.Type{types.NewPtr(typ)}, s.reflectType(typ))[0]
+}
+
+// reflectType returns an SSA value representing a pointer to typ's
+// reflection type descriptor.
+func (s *state) reflectType(typ *types.Type) *ssa.Value {
+ lsym := reflectdata.TypeLinksym(typ)
+ return s.entryNewValue1A(ssa.OpAddr, types.NewPtr(types.Types[types.TUINT8]), lsym, s.sb)
+}
+
func dumpSourcesColumn(writer *ssa.HTMLWriter, fn *ir.Func) {
// Read sources of target function fn.
fname := base.Ctxt.PosTable.Pos(fn.Pos()).Filename()
@@ -675,7 +776,7 @@ type state struct {
// all defined variables at the end of each block. Indexed by block ID.
defvars []map[ir.Node]*ssa.Value
- // addresses of PPARAM and PPARAMOUT variables.
+ // addresses of PPARAM and PPARAMOUT variables on the stack.
decladdrs map[*ir.Name]*ssa.Value
// starting values. Memory, stack pointer, and globals pointer
@@ -695,9 +796,6 @@ type state struct {
// Used to deduplicate panic calls.
panics map[funcLine]*ssa.Block
- // list of PPARAMOUT (return) variables.
- returns []*ir.Name
-
cgoUnsafeArgs bool
hasdefer bool // whether the function contains a defer statement
softFloat bool
@@ -1283,8 +1381,8 @@ func (s *state) stmt(n ir.Node) {
case ir.ODCL:
n := n.(*ir.Decl)
- if n.X.Class == ir.PAUTOHEAP {
- s.Fatalf("DCL %v", n)
+ if v := n.X; v.Esc() == ir.EscHeap {
+ s.newHeapaddr(v)
}
case ir.OLABEL:
@@ -1414,10 +1512,10 @@ func (s *state) stmt(n ir.Node) {
// Currently doesn't really work because (*p)[:len(*p)] appears here as:
// tmp = len(*p)
// (*p)[:tmp]
- //if j != nil && (j.Op == OLEN && samesafeexpr(j.Left, n.Left)) {
+ //if j != nil && (j.Op == OLEN && SameSafeExpr(j.Left, n.Left)) {
// j = nil
//}
- //if k != nil && (k.Op == OCAP && samesafeexpr(k.Left, n.Left)) {
+ //if k != nil && (k.Op == OCAP && SameSafeExpr(k.Left, n.Left)) {
// k = nil
//}
if i == nil {
@@ -1486,11 +1584,11 @@ func (s *state) stmt(n ir.Node) {
b := s.exit()
b.Pos = s.lastPos.WithIsStmt()
- case ir.ORETJMP:
- n := n.(*ir.BranchStmt)
+ case ir.OTAILCALL:
+ n := n.(*ir.TailCallStmt)
b := s.exit()
b.Kind = ssa.BlockRetJmp // override BlockRet
- b.Aux = callTargetLSym(n.Label, s.curfn.LSym)
+ b.Aux = callTargetLSym(n.Target, s.curfn.LSym)
case ir.OCONTINUE, ir.OBREAK:
n := n.(*ir.BranchStmt)
@@ -1704,6 +1802,7 @@ const shareDeferExits = false
// It returns a BlockRet block that ends the control flow. Its control value
// will be set to the final memory state.
func (s *state) exit() *ssa.Block {
+ lateResultLowering := s.f.DebugTest && ssa.LateCallExpansionEnabledWithin(s.f)
if s.hasdefer {
if s.hasOpenDefers {
if shareDeferExits && s.lastDeferExit != nil && len(s.openDefers) == s.lastDeferCount {
@@ -1720,24 +1819,61 @@ func (s *state) exit() *ssa.Block {
}
}
- // Run exit code. Typically, this code copies heap-allocated PPARAMOUT
- // variables back to the stack.
- s.stmtList(s.curfn.Exit)
+ var b *ssa.Block
+ var m *ssa.Value
+ // Do actual return.
+ // These currently turn into self-copies (in many cases).
+ if lateResultLowering {
+ resultFields := s.curfn.Type().Results().FieldSlice()
+ results := make([]*ssa.Value, len(resultFields)+1, len(resultFields)+1)
+ m = s.newValue0(ssa.OpMakeResult, s.f.OwnAux.LateExpansionResultType())
+ // Store SSAable and heap-escaped PPARAMOUT variables back to stack locations.
+ for i, f := range resultFields {
+ n := f.Nname.(*ir.Name)
+ s.vars[memVar] = s.newValue1A(ssa.OpVarDef, types.TypeMem, n, s.mem())
+ if s.canSSA(n) { // result is in some SSA variable
+ results[i] = s.variable(n, n.Type())
+ } else if !n.OnStack() { // result is actually heap allocated
+ ha := s.expr(n.Heapaddr)
+ s.instrumentFields(n.Type(), ha, instrumentRead)
+ results[i] = s.newValue2(ssa.OpDereference, n.Type(), ha, s.mem())
+ } else { // result is not SSA-able; not escaped, so not on heap, but too large for SSA.
+ // Before register ABI this ought to be a self-move, home=dest,
+ // With register ABI, it's still a self-move if parameter is on stack (i.e., too big or overflowed)
+ results[i] = s.newValue2(ssa.OpDereference, n.Type(), s.addr(n), s.mem())
+ }
+ }
- // Store SSAable PPARAMOUT variables back to stack locations.
- for _, n := range s.returns {
- addr := s.decladdrs[n]
- val := s.variable(n, n.Type())
- s.vars[memVar] = s.newValue1A(ssa.OpVarDef, types.TypeMem, n, s.mem())
- s.store(n.Type(), addr, val)
- // TODO: if val is ever spilled, we'd like to use the
- // PPARAMOUT slot for spilling it. That won't happen
- // currently.
- }
+ // Run exit code. Today, this is just racefuncexit, in -race mode.
+ // TODO this seems risky here with a register-ABI, but not clear it is right to do it earlier either.
+ // Spills in register allocation might just fix it.
+ s.stmtList(s.curfn.Exit)
- // Do actual return.
- m := s.mem()
- b := s.endBlock()
+ results[len(results)-1] = s.mem()
+ m.AddArgs(results...)
+ } else {
+ // Store SSAable and heap-escaped PPARAMOUT variables back to stack locations.
+ for _, f := range s.curfn.Type().Results().FieldSlice() {
+ n := f.Nname.(*ir.Name)
+ if s.canSSA(n) {
+ val := s.variable(n, n.Type())
+ s.vars[memVar] = s.newValue1A(ssa.OpVarDef, types.TypeMem, n, s.mem())
+ s.store(n.Type(), s.decladdrs[n], val)
+ } else if !n.OnStack() {
+ s.vars[memVar] = s.newValue1A(ssa.OpVarDef, types.TypeMem, n, s.mem())
+ s.move(n.Type(), s.decladdrs[n], s.expr(n.Heapaddr))
+ } // else, on stack but too large to SSA, the result is already in its destination by construction, so no store needed.
+
+ // TODO: if (SSA) val is ever spilled, we'd like to use the PPARAMOUT slot for spilling it. That won't happen currently.
+ }
+
+ // Run exit code. Today, this is just racefuncexit, in -race mode.
+ s.stmtList(s.curfn.Exit)
+
+ // Do actual return.
+ m = s.mem()
+ }
+ b = s.endBlock()
b.Kind = ssa.BlockRet
b.SetControl(m)
if s.hasdefer && s.hasOpenDefers {
@@ -2159,15 +2295,10 @@ func (s *state) expr(n ir.Node) *ssa.Value {
if s.canSSA(n) {
return s.variable(n, n.Type())
}
- addr := s.addr(n)
- return s.load(n.Type(), addr)
- case ir.ONAMEOFFSET:
- n := n.(*ir.NameOffsetExpr)
- if s.canSSAName(n.Name_) && TypeOK(n.Type()) {
- return s.variable(n, n.Type())
- }
- addr := s.addr(n)
- return s.load(n.Type(), addr)
+ return s.load(n.Type(), s.addr(n))
+ case ir.OLINKSYMOFFSET:
+ n := n.(*ir.LinksymOffsetExpr)
+ return s.load(n.Type(), s.addr(n))
case ir.ONIL:
n := n.(*ir.NilExpr)
t := n.Type()
@@ -2936,14 +3067,9 @@ func (s *state) expr(n ir.Node) *ssa.Value {
}
return s.zeroVal(n.Type())
- case ir.ONEWOBJ:
+ case ir.ONEW:
n := n.(*ir.UnaryExpr)
- if n.Type().Elem().Size() == 0 {
- return s.newValue1A(ssa.OpAddr, n.Type(), ir.Syms.Zerobase, s.sb)
- }
- typ := s.expr(n.X)
- vv := s.rtcall(ir.Syms.Newobject, true, []*types.Type{n.Type()}, typ)
- return vv[0]
+ return s.newObject(n.Type().Elem())
default:
s.Fatalf("unhandled expr %v", n.Op())
@@ -3260,7 +3386,7 @@ func (s *state) assign(left ir.Node, right *ssa.Value, deref bool, skip skipMask
// If this assignment clobbers an entire local variable, then emit
// OpVarDef so liveness analysis knows the variable is redefined.
- if base, ok := clobberBase(left).(*ir.Name); ok && base.Op() == ir.ONAME && base.Class != ir.PEXTERN && base.Class != ir.PAUTOHEAP && skip == 0 {
+ if base, ok := clobberBase(left).(*ir.Name); ok && base.OnStack() && skip == 0 {
s.vars[memVar] = s.newValue1Apos(ssa.OpVarDef, types.TypeMem, base, s.mem(), !ir.IsAutoTmp(base))
}
@@ -4366,30 +4492,8 @@ func (s *state) intrinsicCall(n *ir.CallExpr) *ssa.Value {
// intrinsicArgs extracts args from n, evaluates them to SSA values, and returns them.
func (s *state) intrinsicArgs(n *ir.CallExpr) []*ssa.Value {
- // Construct map of temps; see comments in s.call about the structure of n.
- temps := map[ir.Node]*ssa.Value{}
- for _, a := range n.Args {
- if a.Op() != ir.OAS {
- s.Fatalf("non-assignment as a temp function argument %v", a.Op())
- }
- a := a.(*ir.AssignStmt)
- l, r := a.X, a.Y
- if l.Op() != ir.ONAME {
- s.Fatalf("non-ONAME temp function argument %v", a.Op())
- }
- // Evaluate and store to "temporary".
- // Walk ensures these temporaries are dead outside of n.
- temps[l] = s.expr(r)
- }
- args := make([]*ssa.Value, len(n.Rargs))
- for i, n := range n.Rargs {
- // Store a value to an argument slot.
- if x, ok := temps[n]; ok {
- // This is a previously computed temporary.
- args[i] = x
- continue
- }
- // This is an explicit value; evaluate it.
+ args := make([]*ssa.Value, len(n.Args))
+ for i, n := range n.Args {
args[i] = s.expr(n)
}
return args
@@ -4402,13 +4506,6 @@ func (s *state) intrinsicArgs(n *ir.CallExpr) []*ssa.Value {
// (as well as the deferBits variable), and this will enable us to run the proper
// defer calls during panics.
func (s *state) openDeferRecord(n *ir.CallExpr) {
- // Do any needed expression evaluation for the args (including the
- // receiver, if any). This may be evaluating something like 'autotmp_3 =
- // once.mutex'. Such a statement will create a mapping in s.vars[] from
- // the autotmp name to the evaluated SSA arg value, but won't do any
- // stores to the stack.
- s.stmtList(n.Args)
-
var args []*ssa.Value
var argNodes []*ir.Name
@@ -4441,7 +4538,7 @@ func (s *state) openDeferRecord(n *ir.CallExpr) {
opendefer.closureNode = opendefer.closure.Aux.(*ir.Name)
opendefer.rcvrNode = opendefer.rcvr.Aux.(*ir.Name)
}
- for _, argn := range n.Rargs {
+ for _, argn := range n.Args {
var v *ssa.Value
if TypeOK(argn.Type()) {
v = s.openDeferSave(nil, argn.Type(), s.expr(argn))
@@ -4667,7 +4764,7 @@ func (s *state) callAddr(n *ir.CallExpr, k callKind) *ssa.Value {
// Returns the address of the return value (or nil if none).
func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Value {
s.prevCall = nil
- var sym *types.Sym // target symbol (if static)
+ var callee *ir.Name // target function (if static)
var closure *ssa.Value // ptr to closure to run (if dynamic)
var codeptr *ssa.Value // ptr to target code (if dynamic)
var rcvr *ssa.Value // receiver to set
@@ -4685,13 +4782,21 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
}
testLateExpansion := false
+ inRegisters := false
switch n.Op() {
case ir.OCALLFUNC:
testLateExpansion = k != callDeferStack && ssa.LateCallExpansionEnabledWithin(s.f)
if k == callNormal && fn.Op() == ir.ONAME && fn.(*ir.Name).Class == ir.PFUNC {
fn := fn.(*ir.Name)
- sym = fn.Sym()
+ callee = fn
+ // TODO remove after register abi is working
+ inRegistersImported := fn.Pragma()&ir.RegisterParams != 0
+ inRegistersSamePackage := fn.Func != nil && fn.Func.Pragma&ir.RegisterParams != 0
+ inRegisters = inRegistersImported || inRegistersSamePackage
+ if inRegisters {
+ s.f.Warnl(n.Pos(), "called function %v has register params", callee)
+ }
break
}
closure = s.expr(fn)
@@ -4719,11 +4824,6 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
types.CalcSize(fn.Type())
stksize := fn.Type().ArgWidth() // includes receiver, args, and results
- // Run all assignments of temps.
- // The temps are introduced to avoid overwriting argument
- // slots when arguments themselves require function calls.
- s.stmtList(n.Args)
-
var call *ssa.Value
if k == callDeferStack {
testLateExpansion = ssa.LateCallExpansionEnabledWithin(s.f)
@@ -4757,7 +4857,7 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
// Then, store all the arguments of the defer call.
ft := fn.Type()
off := t.FieldOff(12)
- args := n.Rargs
+ args := n.Args
// Set receiver (for interface calls). Always a pointer.
if rcvr != nil {
@@ -4832,7 +4932,7 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
// Write args.
t := n.X.Type()
- args := n.Rargs
+ args := n.Args
if n.Op() == ir.OCALLMETH {
base.Fatalf("OCALLMETH missed by walkCall")
}
@@ -4885,13 +4985,13 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
} else {
call = s.newValue2A(ssa.OpInterCall, types.TypeMem, ssa.InterfaceAuxCall(ACArgs, ACResults), codeptr, s.mem())
}
- case sym != nil:
+ case callee != nil:
if testLateExpansion {
- aux := ssa.StaticAuxCall(callTargetLSym(sym, s.curfn.LSym), ACArgs, ACResults)
+ aux := ssa.StaticAuxCall(callTargetLSym(callee, s.curfn.LSym), ACArgs, ACResults)
call = s.newValue0A(ssa.OpStaticLECall, aux.LateExpansionResultType(), aux)
call.AddArgs(callArgs...)
} else {
- call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, ssa.StaticAuxCall(callTargetLSym(sym, s.curfn.LSym), ACArgs, ACResults), s.mem())
+ call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, ssa.StaticAuxCall(callTargetLSym(callee, s.curfn.LSym), ACArgs, ACResults), s.mem())
}
default:
s.Fatalf("bad call type %v %v", n.Op(), n)
@@ -4987,24 +5087,27 @@ func (s *state) addr(n ir.Node) *ssa.Value {
}
t := types.NewPtr(n.Type())
- var offset int64
+ linksymOffset := func(lsym *obj.LSym, offset int64) *ssa.Value {
+ v := s.entryNewValue1A(ssa.OpAddr, t, lsym, s.sb)
+ // TODO: Make OpAddr use AuxInt as well as Aux.
+ if offset != 0 {
+ v = s.entryNewValue1I(ssa.OpOffPtr, v.Type, offset, v)
+ }
+ return v
+ }
switch n.Op() {
- case ir.ONAMEOFFSET:
- no := n.(*ir.NameOffsetExpr)
- offset = no.Offset_
- n = no.Name_
- fallthrough
+ case ir.OLINKSYMOFFSET:
+ no := n.(*ir.LinksymOffsetExpr)
+ return linksymOffset(no.Linksym, no.Offset_)
case ir.ONAME:
n := n.(*ir.Name)
+ if n.Heapaddr != nil {
+ return s.expr(n.Heapaddr)
+ }
switch n.Class {
case ir.PEXTERN:
// global variable
- v := s.entryNewValue1A(ssa.OpAddr, t, n.Linksym(), s.sb)
- // TODO: Make OpAddr use AuxInt as well as Aux.
- if offset != 0 {
- v = s.entryNewValue1I(ssa.OpOffPtr, v.Type, offset, v)
- }
- return v
+ return linksymOffset(n.Linksym(), 0)
case ir.PPARAM:
// parameter slot
v := s.decladdrs[n]
@@ -5024,8 +5127,6 @@ func (s *state) addr(n ir.Node) *ssa.Value {
// ensure that we reuse symbols for out parameters so
// that cse works on their addresses
return s.newValue2Apos(ssa.OpLocalAddr, t, n, s.sp, s.mem(), true)
- case ir.PAUTOHEAP:
- return s.expr(n.Heapaddr)
default:
s.Fatalf("variable address class %v not implemented", n.Class)
return nil
@@ -5126,15 +5227,10 @@ func (s *state) canSSA(n ir.Node) bool {
}
func (s *state) canSSAName(name *ir.Name) bool {
- if name.Addrtaken() {
- return false
- }
- if ir.IsParamHeapCopy(name) {
+ if name.Addrtaken() || !name.OnStack() {
return false
}
switch name.Class {
- case ir.PEXTERN, ir.PAUTOHEAP:
- return false
case ir.PPARAMOUT:
if s.hasdefer {
// TODO: handle this case? Named return values must be
@@ -5160,7 +5256,7 @@ func (s *state) canSSAName(name *ir.Name) bool {
// TODO: try to make more variables SSAable?
}
-// canSSA reports whether variables of type t are SSA-able.
+// TypeOK reports whether variables of type t are SSA-able.
func TypeOK(t *types.Type) bool {
types.CalcSize(t)
if t.Width > int64(4*types.PtrSize) {
@@ -6013,8 +6109,8 @@ func (s *state) floatToUint(cvttab *f2uCvtTab, n ir.Node, x *ssa.Value, ft, tt *
// commaok indicates whether to panic or return a bool.
// If commaok is false, resok will be nil.
func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Value) {
- iface := s.expr(n.X) // input interface
- target := s.expr(n.DstType) // target type
+ iface := s.expr(n.X) // input interface
+ target := s.reflectType(n.Type()) // target type
byteptr := s.f.Config.Types.BytePtr
if n.Type().IsInterface() {
@@ -6148,7 +6244,7 @@ func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Val
if !commaok {
// on failure, panic by calling panicdottype
s.startBlock(bFail)
- taddr := s.expr(n.SrcType)
+ taddr := s.reflectType(n.X.Type())
if n.X.Type().IsEmptyInterface() {
s.rtcall(ir.Syms.PanicdottypeE, false, nil, itab, target, taddr)
} else {
@@ -6365,7 +6461,7 @@ func (s *State) DebugFriendlySetPosFrom(v *ssa.Value) {
// in the generated code.
if p.IsStmt() != src.PosIsStmt {
p = p.WithNotStmt()
- // Calls use the pos attached to v, but copy the statement mark from SSAGenState
+ // Calls use the pos attached to v, but copy the statement mark from State
}
s.SetPos(p)
} else {
@@ -6374,57 +6470,6 @@ func (s *State) DebugFriendlySetPosFrom(v *ssa.Value) {
}
}
-// byXoffset implements sort.Interface for []*ir.Name using Xoffset as the ordering.
-type byXoffset []*ir.Name
-
-func (s byXoffset) Len() int { return len(s) }
-func (s byXoffset) Less(i, j int) bool { return s[i].FrameOffset() < s[j].FrameOffset() }
-func (s byXoffset) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-
-func emitStackObjects(e *ssafn, pp *objw.Progs) {
- var vars []*ir.Name
- for _, n := range e.curfn.Dcl {
- if liveness.ShouldTrack(n) && n.Addrtaken() {
- vars = append(vars, n)
- }
- }
- if len(vars) == 0 {
- return
- }
-
- // Sort variables from lowest to highest address.
- sort.Sort(byXoffset(vars))
-
- // Populate the stack object data.
- // Format must match runtime/stack.go:stackObjectRecord.
- x := e.curfn.LSym.Func().StackObjects
- off := 0
- off = objw.Uintptr(x, off, uint64(len(vars)))
- for _, v := range vars {
- // Note: arguments and return values have non-negative Xoffset,
- // in which case the offset is relative to argp.
- // Locals have a negative Xoffset, in which case the offset is relative to varp.
- off = objw.Uintptr(x, off, uint64(v.FrameOffset()))
- if !types.TypeSym(v.Type()).Siggen() {
- e.Fatalf(v.Pos(), "stack object's type symbol not generated for type %s", v.Type())
- }
- off = objw.SymPtr(x, off, reflectdata.WriteType(v.Type()), 0)
- }
-
- // Emit a funcdata pointing at the stack object data.
- p := pp.Prog(obj.AFUNCDATA)
- p.From.SetConst(objabi.FUNCDATA_StackObjects)
- p.To.Type = obj.TYPE_MEM
- p.To.Name = obj.NAME_EXTERN
- p.To.Sym = x
-
- if base.Flag.Live != 0 {
- for _, v := range vars {
- base.WarnfAt(v.Pos(), "stack object %v %s", v, v.Type().String())
- }
- }
-}
-
// genssa appends entries to pp for each instruction in f.
func genssa(f *ssa.Func, pp *objw.Progs) {
var s State
@@ -6432,7 +6477,6 @@ func genssa(f *ssa.Func, pp *objw.Progs) {
e := f.Frontend().(*ssafn)
s.livenessMap = liveness.Compute(e.curfn, f, e.stkptrsize, pp)
- emitStackObjects(e, pp)
openDeferInfo := e.curfn.LSym.Func().OpenCodedDeferInfo
if openDeferInfo != nil {
@@ -7165,7 +7209,7 @@ func (e *ssafn) SplitInterface(name ssa.LocalSlot) (ssa.LocalSlot, ssa.LocalSlot
if n.Type().IsEmptyInterface() {
f = ".type"
}
- c := e.SplitSlot(&name, f, 0, u) // see comment in plive.go:onebitwalktype1.
+ c := e.SplitSlot(&name, f, 0, u) // see comment in typebits.Set
d := e.SplitSlot(&name, ".data", u.Size(), t)
return c, d
}
@@ -7345,31 +7389,26 @@ func clobberBase(n ir.Node) ir.Node {
//
// 3. in all other cases, want the regular ABIInternal linksym
//
-func callTargetLSym(callee *types.Sym, callerLSym *obj.LSym) *obj.LSym {
+func callTargetLSym(callee *ir.Name, callerLSym *obj.LSym) *obj.LSym {
lsym := callee.Linksym()
if !base.Flag.ABIWrap {
return lsym
}
- if ir.AsNode(callee.Def) == nil {
- return lsym
- }
- defn := ir.AsNode(callee.Def).Name().Defn
- if defn == nil {
+ fn := callee.Func
+ if fn == nil {
return lsym
}
- ndclfunc := defn.(*ir.Func)
// check for case 1 above
if callerLSym.ABIWrapper() {
- if nlsym := ndclfunc.LSym; nlsym != nil {
+ if nlsym := fn.LSym; nlsym != nil {
lsym = nlsym
}
} else {
// check for case 2 above
- nam := ndclfunc.Nname
- defABI, hasDefABI := symabiDefs[nam.Sym().LinksymName()]
+ defABI, hasDefABI := symabiDefs[lsym.Name]
if hasDefABI && defABI == obj.ABI0 {
- lsym = nam.Sym().LinksymABI0()
+ lsym = callee.LinksymABI(obj.ABI0)
}
}
return lsym
diff --git a/src/cmd/compile/internal/staticdata/data.go b/src/cmd/compile/internal/staticdata/data.go
index 4b12590fde..b06fd7aa4b 100644
--- a/src/cmd/compile/internal/staticdata/data.go
+++ b/src/cmd/compile/internal/staticdata/data.go
@@ -25,55 +25,38 @@ import (
"cmd/internal/src"
)
-// InitAddr writes the static address of a to n. a must be an ONAME.
-// Neither n nor a is modified.
-func InitAddr(n *ir.Name, noff int64, a *ir.Name, aoff int64) {
+// InitAddrOffset writes the static name symbol lsym to n, it does not modify n.
+// It's the caller responsibility to make sure lsym is from ONAME/PEXTERN node.
+func InitAddrOffset(n *ir.Name, noff int64, lsym *obj.LSym, off int64) {
if n.Op() != ir.ONAME {
- base.Fatalf("addrsym n op %v", n.Op())
+ base.Fatalf("InitAddr n op %v", n.Op())
}
if n.Sym() == nil {
- base.Fatalf("addrsym nil n sym")
- }
- if a.Op() != ir.ONAME {
- base.Fatalf("addrsym a op %v", a.Op())
+ base.Fatalf("InitAddr nil n sym")
}
s := n.Linksym()
- s.WriteAddr(base.Ctxt, noff, types.PtrSize, a.Linksym(), aoff)
+ s.WriteAddr(base.Ctxt, noff, types.PtrSize, lsym, off)
}
-// InitFunc writes the static address of f to n. f must be a global function.
-// Neither n nor f is modified.
-func InitFunc(n *ir.Name, noff int64, f *ir.Name) {
- if n.Op() != ir.ONAME {
- base.Fatalf("pfuncsym n op %v", n.Op())
- }
- if n.Sym() == nil {
- base.Fatalf("pfuncsym nil n sym")
- }
- if f.Class != ir.PFUNC {
- base.Fatalf("pfuncsym class not PFUNC %d", f.Class)
- }
- s := n.Linksym()
- s.WriteAddr(base.Ctxt, noff, types.PtrSize, FuncLinksym(f), 0)
+// InitAddr is InitAddrOffset, with offset fixed to 0.
+func InitAddr(n *ir.Name, noff int64, lsym *obj.LSym) {
+ InitAddrOffset(n, noff, lsym, 0)
}
-// InitSlice writes a static slice symbol {&arr, lencap, lencap} to n+noff.
-// InitSlice does not modify n.
-func InitSlice(n *ir.Name, noff int64, arr *ir.Name, lencap int64) {
+// InitSlice writes a static slice symbol {lsym, lencap, lencap} to n+noff, it does not modify n.
+// It's the caller responsibility to make sure lsym is from ONAME node.
+func InitSlice(n *ir.Name, noff int64, lsym *obj.LSym, lencap int64) {
s := n.Linksym()
- if arr.Op() != ir.ONAME {
- base.Fatalf("slicesym non-name arr %v", arr)
- }
- s.WriteAddr(base.Ctxt, noff, types.PtrSize, arr.Linksym(), 0)
+ s.WriteAddr(base.Ctxt, noff, types.PtrSize, lsym, 0)
s.WriteInt(base.Ctxt, noff+types.SliceLenOffset, types.PtrSize, lencap)
s.WriteInt(base.Ctxt, noff+types.SliceCapOffset, types.PtrSize, lencap)
}
func InitSliceBytes(nam *ir.Name, off int64, s string) {
if nam.Op() != ir.ONAME {
- base.Fatalf("slicebytes %v", nam)
+ base.Fatalf("InitSliceBytes %v", nam)
}
- InitSlice(nam, off, slicedata(nam.Pos(), s), int64(len(s)))
+ InitSlice(nam, off, slicedata(nam.Pos(), s).Linksym(), int64(len(s)))
}
const (
@@ -243,14 +226,14 @@ func FuncSym(s *types.Sym) *types.Sym {
// except for the types package, which is protected separately.
// Reusing funcsymsmu to also cover this package lookup
// avoids a general, broader, expensive package lookup mutex.
- // Note makefuncsym also does package look-up of func sym names,
+ // Note NeedFuncSym also does package look-up of func sym names,
// but that it is only called serially, from the front end.
funcsymsmu.Lock()
sf, existed := s.Pkg.LookupOK(ir.FuncSymName(s))
// Don't export s·f when compiling for dynamic linking.
// When dynamically linking, the necessary function
- // symbols will be created explicitly with makefuncsym.
- // See the makefuncsym comment for details.
+ // symbols will be created explicitly with NeedFuncSym.
+ // See the NeedFuncSym comment for details.
if !base.Ctxt.Flag_dynlink && !existed {
funcsyms = append(funcsyms, s)
}
@@ -265,6 +248,13 @@ func FuncLinksym(n *ir.Name) *obj.LSym {
return FuncSym(n.Sym()).Linksym()
}
+func GlobalLinksym(n *ir.Name) *obj.LSym {
+ if n.Op() != ir.ONAME || n.Class != ir.PEXTERN {
+ base.Fatalf("expected global variable: %v", n)
+ }
+ return n.Linksym()
+}
+
// NeedFuncSym ensures that s·f is exported, if needed.
// It is only used with -dynlink.
// When not compiling for dynamic linking,
@@ -297,7 +287,7 @@ func NeedFuncSym(s *types.Sym) {
func WriteFuncSyms() {
sort.Slice(funcsyms, func(i, j int) bool {
- return funcsyms[i].LinksymName() < funcsyms[j].LinksymName()
+ return funcsyms[i].Linksym().Name < funcsyms[j].Linksym().Name
})
for _, s := range funcsyms {
sf := s.Pkg.Lookup(ir.FuncSymName(s)).Linksym()
@@ -310,16 +300,16 @@ func WriteFuncSyms() {
// Neither n nor c is modified.
func InitConst(n *ir.Name, noff int64, c ir.Node, wid int) {
if n.Op() != ir.ONAME {
- base.Fatalf("litsym n op %v", n.Op())
+ base.Fatalf("InitConst n op %v", n.Op())
}
if n.Sym() == nil {
- base.Fatalf("litsym nil n sym")
+ base.Fatalf("InitConst nil n sym")
}
if c.Op() == ir.ONIL {
return
}
if c.Op() != ir.OLITERAL {
- base.Fatalf("litsym c op %v", c.Op())
+ base.Fatalf("InitConst c op %v", c.Op())
}
s := n.Linksym()
switch u := c.Val(); u.Kind() {
@@ -358,6 +348,6 @@ func InitConst(n *ir.Name, noff int64, c ir.Node, wid int) {
s.WriteInt(base.Ctxt, noff+int64(types.PtrSize), types.PtrSize, int64(len(i)))
default:
- base.Fatalf("litsym unhandled OLITERAL %v", c)
+ base.Fatalf("InitConst unhandled OLITERAL %v", c)
}
}
diff --git a/src/cmd/compile/internal/staticdata/embed.go b/src/cmd/compile/internal/staticdata/embed.go
index 2e551f0b2c..8936c4f5b4 100644
--- a/src/cmd/compile/internal/staticdata/embed.go
+++ b/src/cmd/compile/internal/staticdata/embed.go
@@ -23,13 +23,7 @@ const (
embedFiles
)
-func embedFileList(v *ir.Name) []string {
- kind := embedKind(v.Type())
- if kind == embedUnknown {
- base.ErrorfAt(v.Pos(), "go:embed cannot apply to var of type %v", v.Type())
- return nil
- }
-
+func embedFileList(v *ir.Name, kind int) []string {
// Build list of files to store.
have := make(map[string]bool)
var list []string
@@ -71,38 +65,15 @@ func embedFileList(v *ir.Name) []string {
return list
}
-// embedKindApprox determines the kind of embedding variable, approximately.
-// The match is approximate because we haven't done scope resolution yet and
-// can't tell whether "string" and "byte" really mean "string" and "byte".
-// The result must be confirmed later, after type checking, using embedKind.
-func embedKindApprox(typ ir.Node) int {
- if typ.Sym() != nil && typ.Sym().Name == "FS" && (typ.Sym().Pkg.Path == "embed" || (typ.Sym().Pkg == types.LocalPkg && base.Ctxt.Pkgpath == "embed")) {
- return embedFiles
- }
- // These are not guaranteed to match only string and []byte -
- // maybe the local package has redefined one of those words.
- // But it's the best we can do now during the noder.
- // The stricter check happens later, in initEmbed calling embedKind.
- if typ.Sym() != nil && typ.Sym().Name == "string" && typ.Sym().Pkg == types.LocalPkg {
- return embedString
- }
- if typ, ok := typ.(*ir.SliceType); ok {
- if sym := typ.Elem.Sym(); sym != nil && sym.Name == "byte" && sym.Pkg == types.LocalPkg {
- return embedBytes
- }
- }
- return embedUnknown
-}
-
// embedKind determines the kind of embedding variable.
func embedKind(typ *types.Type) int {
if typ.Sym() != nil && typ.Sym().Name == "FS" && (typ.Sym().Pkg.Path == "embed" || (typ.Sym().Pkg == types.LocalPkg && base.Ctxt.Pkgpath == "embed")) {
return embedFiles
}
- if typ == types.Types[types.TSTRING] {
+ if typ.Kind() == types.TSTRING {
return embedString
}
- if typ.Sym() == nil && typ.IsSlice() && typ.Elem() == types.ByteType {
+ if typ.Sym() == nil && typ.IsSlice() && typ.Elem().Kind() == types.TUINT8 {
return embedBytes
}
return embedUnknown
@@ -134,11 +105,28 @@ func embedFileLess(x, y string) bool {
// WriteEmbed emits the init data for a //go:embed variable,
// which is either a string, a []byte, or an embed.FS.
func WriteEmbed(v *ir.Name) {
- files := embedFileList(v)
- switch kind := embedKind(v.Type()); kind {
- case embedUnknown:
+ // TODO(mdempsky): User errors should be reported by the frontend.
+
+ commentPos := (*v.Embed)[0].Pos
+ if !types.AllowsGoVersion(types.LocalPkg, 1, 16) {
+ prevPos := base.Pos
+ base.Pos = commentPos
+ base.ErrorfVers("go1.16", "go:embed")
+ base.Pos = prevPos
+ return
+ }
+ if base.Flag.Cfg.Embed.Patterns == nil {
+ base.ErrorfAt(commentPos, "invalid go:embed: build system did not supply embed configuration")
+ return
+ }
+ kind := embedKind(v.Type())
+ if kind == embedUnknown {
base.ErrorfAt(v.Pos(), "go:embed cannot apply to var of type %v", v.Type())
+ return
+ }
+ files := embedFileList(v, kind)
+ switch kind {
case embedString, embedBytes:
file := files[0]
fsym, size, err := fileStringSym(v.Pos(), base.Flag.Cfg.Embed.Files[file], kind == embedString, nil)
diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go
index ac0b6cd87e..f3ad82e7b6 100644
--- a/src/cmd/compile/internal/staticinit/sched.go
+++ b/src/cmd/compile/internal/staticinit/sched.go
@@ -15,6 +15,7 @@ import (
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/obj"
+ "cmd/internal/src"
)
type Entry struct {
@@ -80,7 +81,7 @@ func (s *Schedule) tryStaticInit(nn ir.Node) bool {
func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Type) bool {
if rn.Class == ir.PFUNC {
// TODO if roff != 0 { panic }
- staticdata.InitFunc(l, loff, rn)
+ staticdata.InitAddr(l, loff, staticdata.FuncLinksym(rn))
return true
}
if rn.Class != ir.PEXTERN || rn.Sym().Pkg != types.LocalPkg {
@@ -137,9 +138,8 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
case ir.OADDR:
r := r.(*ir.AddrExpr)
- if a := r.X; a.Op() == ir.ONAME {
- a := a.(*ir.Name)
- staticdata.InitAddr(l, loff, a, 0)
+ if a, ok := r.X.(*ir.Name); ok && a.Op() == ir.ONAME {
+ staticdata.InitAddr(l, loff, staticdata.GlobalLinksym(a))
return true
}
@@ -148,14 +148,14 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
switch r.X.Op() {
case ir.OARRAYLIT, ir.OSLICELIT, ir.OSTRUCTLIT, ir.OMAPLIT:
// copy pointer
- staticdata.InitAddr(l, loff, s.Temps[r], 0)
+ staticdata.InitAddr(l, loff, staticdata.GlobalLinksym(s.Temps[r]))
return true
}
case ir.OSLICELIT:
r := r.(*ir.CompLitExpr)
// copy slice
- staticdata.InitSlice(l, loff, s.Temps[r], r.Len)
+ staticdata.InitSlice(l, loff, staticdata.GlobalLinksym(s.Temps[r]), r.Len)
return true
case ir.OARRAYLIT, ir.OSTRUCTLIT:
@@ -199,6 +199,20 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
r = r.(*ir.ConvExpr).X
}
+ assign := func(pos src.XPos, a *ir.Name, aoff int64, v ir.Node) {
+ if s.StaticAssign(a, aoff, v, v.Type()) {
+ return
+ }
+ var lhs ir.Node
+ if ir.IsBlank(a) {
+ // Don't use NameOffsetExpr with blank (#43677).
+ lhs = ir.BlankNode
+ } else {
+ lhs = ir.NewNameOffsetExpr(pos, a, aoff, v.Type())
+ }
+ s.append(ir.NewAssignStmt(pos, lhs, v))
+ }
+
switch r.Op() {
case ir.ONAME:
r := r.(*ir.Name)
@@ -220,8 +234,8 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
case ir.OADDR:
r := r.(*ir.AddrExpr)
- if name, offset, ok := StaticLoc(r.X); ok {
- staticdata.InitAddr(l, loff, name, offset)
+ if name, offset, ok := StaticLoc(r.X); ok && name.Class == ir.PEXTERN {
+ staticdata.InitAddrOffset(l, loff, name.Linksym(), offset)
return true
}
fallthrough
@@ -234,12 +248,10 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
a := StaticName(r.X.Type())
s.Temps[r] = a
- staticdata.InitAddr(l, loff, a, 0)
+ staticdata.InitAddr(l, loff, a.Linksym())
// Init underlying literal.
- if !s.StaticAssign(a, 0, r.X, a.Type()) {
- s.append(ir.NewAssignStmt(base.Pos, a, r.X))
- }
+ assign(base.Pos, a, 0, r.X)
return true
}
//dump("not static ptrlit", r);
@@ -260,7 +272,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
ta.SetNoalg(true)
a := StaticName(ta)
s.Temps[r] = a
- staticdata.InitSlice(l, loff, a, r.Len)
+ staticdata.InitSlice(l, loff, a.Linksym(), r.Len)
// Fall through to init underlying array.
l = a
loff = 0
@@ -278,10 +290,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
continue
}
ir.SetPos(e.Expr)
- if !s.StaticAssign(l, loff+e.Xoffset, e.Expr, e.Expr.Type()) {
- a := ir.NewNameOffsetExpr(base.Pos, l, loff+e.Xoffset, e.Expr.Type())
- s.append(ir.NewAssignStmt(base.Pos, a, e.Expr))
- }
+ assign(base.Pos, l, loff+e.Xoffset, e.Expr)
}
return true
@@ -298,7 +307,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
// Closures with no captured variables are globals,
// so the assignment can be done at link time.
// TODO if roff != 0 { panic }
- staticdata.InitFunc(l, loff, r.Func.Nname)
+ staticdata.InitAddr(l, loff, staticdata.FuncLinksym(r.Func.Nname))
return true
}
ir.ClosureDebugRuntimeCheck(r)
@@ -335,7 +344,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
// Create a copy of l to modify while we emit data.
// Emit itab, advance offset.
- staticdata.InitAddr(l, loff, itab.X.(*ir.Name), 0)
+ staticdata.InitAddr(l, loff, itab.X.(*ir.LinksymOffsetExpr).Linksym)
// Emit data.
if types.IsDirectIface(val.Type()) {
@@ -345,18 +354,13 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
}
// Copy val directly into n.
ir.SetPos(val)
- if !s.StaticAssign(l, loff+int64(types.PtrSize), val, val.Type()) {
- a := ir.NewNameOffsetExpr(base.Pos, l, loff+int64(types.PtrSize), val.Type())
- s.append(ir.NewAssignStmt(base.Pos, a, val))
- }
+ assign(base.Pos, l, loff+int64(types.PtrSize), val)
} else {
// Construct temp to hold val, write pointer to temp into n.
a := StaticName(val.Type())
s.Temps[val] = a
- if !s.StaticAssign(a, 0, val, val.Type()) {
- s.append(ir.NewAssignStmt(base.Pos, a, val))
- }
- staticdata.InitAddr(l, loff+int64(types.PtrSize), a, 0)
+ assign(base.Pos, a, 0, val)
+ staticdata.InitAddr(l, loff+int64(types.PtrSize), a.Linksym())
}
return true
@@ -450,7 +454,7 @@ var statuniqgen int // name generator for static temps
// StaticName returns a name backed by a (writable) static data symbol.
// Use readonlystaticname for read-only node.
func StaticName(t *types.Type) *ir.Name {
- // Don't use lookupN; it interns the resulting string, but these are all unique.
+ // Don't use LookupNum; it interns the resulting string, but these are all unique.
n := typecheck.NewName(typecheck.Lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen)))
statuniqgen++
typecheck.Declare(n, ir.PEXTERN)
diff --git a/src/cmd/compile/internal/gc/abiutils_test.go b/src/cmd/compile/internal/test/abiutils_test.go
index 6fd0af1b1f..ae7d484062 100644
--- a/src/cmd/compile/internal/gc/abiutils_test.go
+++ b/src/cmd/compile/internal/test/abiutils_test.go
@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package gc
+package test
import (
"bufio"
+ "cmd/compile/internal/abi"
"cmd/compile/internal/base"
"cmd/compile/internal/ssagen"
"cmd/compile/internal/typecheck"
@@ -20,12 +21,7 @@ import (
// AMD64 registers available:
// - integer: RAX, RBX, RCX, RDI, RSI, R8, R9, r10, R11
// - floating point: X0 - X14
-var configAMD64 = ABIConfig{
- regAmounts: RegAmounts{
- intRegs: 9,
- floatRegs: 15,
- },
-}
+var configAMD64 = abi.NewABIConfig(9,15)
func TestMain(m *testing.M) {
ssagen.Arch.LinkArch = &x86.Linkamd64
diff --git a/src/cmd/compile/internal/gc/abiutilsaux_test.go b/src/cmd/compile/internal/test/abiutilsaux_test.go
index 9386b554b0..10fb668745 100644
--- a/src/cmd/compile/internal/gc/abiutilsaux_test.go
+++ b/src/cmd/compile/internal/test/abiutilsaux_test.go
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package gc
+package test
// This file contains utility routines and harness infrastructure used
// by the ABI tests in "abiutils_test.go".
import (
+ "cmd/compile/internal/abi"
"cmd/compile/internal/ir"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
@@ -75,7 +76,7 @@ func tokenize(src string) []string {
return res
}
-func verifyParamResultOffset(t *testing.T, f *types.Field, r ABIParamAssignment, which string, idx int) int {
+func verifyParamResultOffset(t *testing.T, f *types.Field, r abi.ABIParamAssignment, which string, idx int) int {
n := ir.AsNode(f.Nname).(*ir.Name)
if n.FrameOffset() != int64(r.Offset) {
t.Errorf("%s %d: got offset %d wanted %d t=%v",
@@ -110,7 +111,7 @@ func abitest(t *testing.T, ft *types.Type, exp expectedDump) {
types.CalcSize(ft)
// Analyze with full set of registers.
- regRes := ABIAnalyze(ft, configAMD64)
+ regRes := abi.ABIAnalyze(ft, configAMD64)
regResString := strings.TrimSpace(regRes.String())
// Check results.
@@ -121,12 +122,12 @@ func abitest(t *testing.T, ft *types.Type, exp expectedDump) {
}
// Analyze again with empty register set.
- empty := ABIConfig{}
- emptyRes := ABIAnalyze(ft, empty)
+ empty := &abi.ABIConfig{}
+ emptyRes := abi.ABIAnalyze(ft, empty)
emptyResString := emptyRes.String()
// Walk the results and make sure the offsets assigned match
- // up with those assiged by dowidth. This checks to make sure that
+ // up with those assiged by CalcSize. This checks to make sure that
// when we have no available registers the ABI assignment degenerates
// back to the original ABI0.
@@ -135,18 +136,18 @@ func abitest(t *testing.T, ft *types.Type, exp expectedDump) {
rfsl := ft.Recvs().Fields().Slice()
poff := 0
if len(rfsl) != 0 {
- failed |= verifyParamResultOffset(t, rfsl[0], emptyRes.inparams[0], "receiver", 0)
+ failed |= verifyParamResultOffset(t, rfsl[0], emptyRes.InParams()[0], "receiver", 0)
poff = 1
}
// params
pfsl := ft.Params().Fields().Slice()
for k, f := range pfsl {
- verifyParamResultOffset(t, f, emptyRes.inparams[k+poff], "param", k)
+ verifyParamResultOffset(t, f, emptyRes.InParams()[k+poff], "param", k)
}
// results
ofsl := ft.Results().Fields().Slice()
for k, f := range ofsl {
- failed |= verifyParamResultOffset(t, f, emptyRes.outparams[k], "result", k)
+ failed |= verifyParamResultOffset(t, f, emptyRes.OutParams()[k], "result", k)
}
if failed != 0 {
diff --git a/src/cmd/compile/internal/test/testdata/reproducible/issue38068.go b/src/cmd/compile/internal/test/testdata/reproducible/issue38068.go
index db5ca7dcbe..b87daed8e9 100644
--- a/src/cmd/compile/internal/test/testdata/reproducible/issue38068.go
+++ b/src/cmd/compile/internal/test/testdata/reproducible/issue38068.go
@@ -53,7 +53,7 @@ func G(x *A, n int) {
return
}
// Address-taken local of type A, which will insure that the
- // compiler's dtypesym() routine will create a method wrapper.
+ // compiler's writeType() routine will create a method wrapper.
var a, b A
a.next = x
a.prev = &b
diff --git a/src/cmd/compile/internal/typebits/typebits.go b/src/cmd/compile/internal/typebits/typebits.go
index 63a2bb3ffa..1c1b077423 100644
--- a/src/cmd/compile/internal/typebits/typebits.go
+++ b/src/cmd/compile/internal/typebits/typebits.go
@@ -15,7 +15,7 @@ import (
// on future calls with the same type t.
func Set(t *types.Type, off int64, bv bitvec.BitVec) {
if t.Align > 0 && off&int64(t.Align-1) != 0 {
- base.Fatalf("onebitwalktype1: invalid initial alignment: type %v has alignment %d, but offset is %v", t, t.Align, off)
+ base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, t.Align, off)
}
if !t.HasPointers() {
// Note: this case ensures that pointers to go:notinheap types
@@ -26,14 +26,14 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
switch t.Kind() {
case types.TPTR, types.TUNSAFEPTR, types.TFUNC, types.TCHAN, types.TMAP:
if off&int64(types.PtrSize-1) != 0 {
- base.Fatalf("onebitwalktype1: invalid alignment, %v", t)
+ base.Fatalf("typebits.Set: invalid alignment, %v", t)
}
bv.Set(int32(off / int64(types.PtrSize))) // pointer
case types.TSTRING:
// struct { byte *str; intgo len; }
if off&int64(types.PtrSize-1) != 0 {
- base.Fatalf("onebitwalktype1: invalid alignment, %v", t)
+ base.Fatalf("typebits.Set: invalid alignment, %v", t)
}
bv.Set(int32(off / int64(types.PtrSize))) //pointer in first slot
@@ -42,7 +42,7 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
// or, when isnilinter(t)==true:
// struct { Type *type; void *data; }
if off&int64(types.PtrSize-1) != 0 {
- base.Fatalf("onebitwalktype1: invalid alignment, %v", t)
+ base.Fatalf("typebits.Set: invalid alignment, %v", t)
}
// The first word of an interface is a pointer, but we don't
// treat it as such.
@@ -61,7 +61,7 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
case types.TSLICE:
// struct { byte *array; uintgo len; uintgo cap; }
if off&int64(types.PtrSize-1) != 0 {
- base.Fatalf("onebitwalktype1: invalid TARRAY alignment, %v", t)
+ base.Fatalf("typebits.Set: invalid TARRAY alignment, %v", t)
}
bv.Set(int32(off / int64(types.PtrSize))) // pointer in first slot (BitsPointer)
@@ -82,6 +82,6 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
}
default:
- base.Fatalf("onebitwalktype1: unexpected type, %v", t)
+ base.Fatalf("typebits.Set: unexpected type, %v", t)
}
}
diff --git a/src/cmd/compile/internal/typecheck/const.go b/src/cmd/compile/internal/typecheck/const.go
index d6bf101974..1a8e58383a 100644
--- a/src/cmd/compile/internal/typecheck/const.go
+++ b/src/cmd/compile/internal/typecheck/const.go
@@ -623,7 +623,7 @@ func OrigInt(n ir.Node, v int64) ir.Node {
return OrigConst(n, constant.MakeInt64(v))
}
-// defaultlit on both nodes simultaneously;
+// DefaultLit on both nodes simultaneously;
// if they're both ideal going in they better
// get the same type going out.
// force means must assign concrete (non-ideal) type.
diff --git a/src/cmd/compile/internal/typecheck/dcl.go b/src/cmd/compile/internal/typecheck/dcl.go
index bd54919c93..eab0bb09b2 100644
--- a/src/cmd/compile/internal/typecheck/dcl.go
+++ b/src/cmd/compile/internal/typecheck/dcl.go
@@ -41,7 +41,7 @@ func Declare(n *ir.Name, ctxt ir.Class) {
s := n.Sym()
- // kludgy: typecheckok means we're past parsing. Eg genwrapper may declare out of package names later.
+ // kludgy: TypecheckAllowed means we're past parsing. Eg reflectdata.methodWrapper may declare out of package names later.
if !inimport && !TypecheckAllowed && s.Pkg != types.LocalPkg {
base.ErrorfAt(n.Pos(), "cannot declare name %v", s)
}
@@ -311,7 +311,7 @@ func FakeRecv() *types.Field {
var fakeRecvField = FakeRecv
-var funcStack []funcStackEnt // stack of previous values of Curfn/dclcontext
+var funcStack []funcStackEnt // stack of previous values of ir.CurFunc/DeclContext
type funcStackEnt struct {
curfn *ir.Func
@@ -401,14 +401,14 @@ func Temp(t *types.Type) *ir.Name {
// make a new Node off the books
func TempAt(pos src.XPos, curfn *ir.Func, t *types.Type) *ir.Name {
if curfn == nil {
- base.Fatalf("no curfn for tempAt")
+ base.Fatalf("no curfn for TempAt")
}
if curfn.Op() == ir.OCLOSURE {
- ir.Dump("tempAt", curfn)
- base.Fatalf("adding tempAt to wrong closure function")
+ ir.Dump("TempAt", curfn)
+ base.Fatalf("adding TempAt to wrong closure function")
}
if t == nil {
- base.Fatalf("tempAt called with nil type")
+ base.Fatalf("TempAt called with nil type")
}
if t.Kind() == types.TFUNC && t.Recv() != nil {
base.Fatalf("misuse of method type: %v", t)
diff --git a/src/cmd/compile/internal/typecheck/expr.go b/src/cmd/compile/internal/typecheck/expr.go
index 12bfae67a8..339fb00aa4 100644
--- a/src/cmd/compile/internal/typecheck/expr.go
+++ b/src/cmd/compile/internal/typecheck/expr.go
@@ -68,7 +68,7 @@ func tcShift(n, l, r ir.Node) (ir.Node, ir.Node, *types.Type) {
return l, r, nil
}
- // no defaultlit for left
+ // no DefaultLit for left
// the outer context gives the type
t = l.Type()
if (l.Type() == types.UntypedFloat || l.Type() == types.UntypedComplex) && r.Op() == ir.OLITERAL {
@@ -201,7 +201,7 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
// n.Left = tcCompLit(n.Left)
func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
if base.EnableTrace && base.Flag.LowerT {
- defer tracePrint("typecheckcomplit", n)(&res)
+ defer tracePrint("tcCompLit", n)(&res)
}
lno := base.Pos
@@ -838,7 +838,7 @@ func tcStar(n *ir.StarExpr, top int) ir.Node {
}
if l.Op() == ir.OTYPE {
n.SetOTYPE(types.NewPtr(l.Type()))
- // Ensure l.Type gets dowidth'd for the backend. Issue 20174.
+ // Ensure l.Type gets CalcSize'd for the backend. Issue 20174.
types.CheckSize(l.Type())
return n
}
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go
index 766eb8bae9..7ab5f68ce3 100644
--- a/src/cmd/compile/internal/typecheck/func.go
+++ b/src/cmd/compile/internal/typecheck/func.go
@@ -100,7 +100,7 @@ func PartialCallType(n *ir.SelectorExpr) *types.Type {
return t
}
-// Lazy typechecking of imported bodies. For local functions, caninl will set ->typecheck
+// Lazy typechecking of imported bodies. For local functions, CanInline will set ->typecheck
// because they're a copy of an already checked body.
func ImportedBody(fn *ir.Func) {
lno := ir.SetPos(fn.Nname)
@@ -122,14 +122,14 @@ func ImportedBody(fn *ir.Func) {
ImportBody(fn)
- // typecheckinl is only for imported functions;
+ // Stmts(fn.Inl.Body) below is only for imported functions;
// their bodies may refer to unsafe as long as the package
// was marked safe during import (which was checked then).
- // the ->inl of a local function has been typechecked before caninl copied it.
+ // the ->inl of a local function has been typechecked before CanInline copied it.
pkg := fnpkg(fn.Nname)
if pkg == types.LocalPkg || pkg == nil {
- return // typecheckinl on local function
+ return // ImportedBody on local function
}
if base.Flag.LowerM > 2 || base.Debug.Export != 0 {
@@ -141,11 +141,11 @@ func ImportedBody(fn *ir.Func) {
Stmts(fn.Inl.Body)
ir.CurFunc = savefn
- // During expandInline (which imports fn.Func.Inl.Body),
- // declarations are added to fn.Func.Dcl by funcHdr(). Move them
+ // During ImportBody (which imports fn.Func.Inl.Body),
+ // declarations are added to fn.Func.Dcl by funcBody(). Move them
// to fn.Func.Inl.Dcl for consistency with how local functions
- // behave. (Append because typecheckinl may be called multiple
- // times.)
+ // behave. (Append because ImportedBody may be called multiple
+ // times on same fn.)
fn.Inl.Dcl = append(fn.Inl.Dcl, fn.Dcl...)
fn.Dcl = nil
@@ -296,15 +296,22 @@ func tcClosure(clo *ir.ClosureExpr, top int) {
fn.SetClosureCalled(top&ctxCallee != 0)
// Do not typecheck fn twice, otherwise, we will end up pushing
- // fn to Target.Decls multiple times, causing initLSym called twice.
+ // fn to Target.Decls multiple times, causing InitLSym called twice.
// See #30709
if fn.Typecheck() == 1 {
clo.SetType(fn.Type())
return
}
- fn.Nname.SetSym(ClosureName(ir.CurFunc))
- ir.MarkFunc(fn.Nname)
+ // Don't give a name and add to xtop if we are typechecking an inlined
+ // body in ImportedBody(), since we only want to create the named function
+ // when the closure is actually inlined (and then we force a typecheck
+ // explicitly in (*inlsubst).node()).
+ inTypeCheckInl := ir.CurFunc != nil && ir.CurFunc.Body == nil
+ if !inTypeCheckInl {
+ fn.Nname.SetSym(ClosureName(ir.CurFunc))
+ ir.MarkFunc(fn.Nname)
+ }
Func(fn)
clo.SetType(fn.Type())
@@ -338,15 +345,22 @@ func tcClosure(clo *ir.ClosureExpr, top int) {
}
fn.ClosureVars = fn.ClosureVars[:out]
- Target.Decls = append(Target.Decls, fn)
+ if base.Flag.W > 1 {
+ s := fmt.Sprintf("New closure func: %s", ir.FuncName(fn))
+ ir.Dump(s, fn)
+ }
+ if !inTypeCheckInl {
+ // Add function to xtop once only when we give it a name
+ Target.Decls = append(Target.Decls, fn)
+ }
}
// type check function definition
// To be called by typecheck, not directly.
-// (Call typecheckFunc instead.)
+// (Call typecheck.Func instead.)
func tcFunc(n *ir.Func) {
if base.EnableTrace && base.Flag.LowerT {
- defer tracePrint("typecheckfunc", n)(nil)
+ defer tracePrint("tcFunc", n)(nil)
}
n.Nname = AssignExpr(n.Nname).(*ir.Name)
@@ -896,7 +910,7 @@ func tcNew(n *ir.UnaryExpr) ir.Node {
// tcPanic typechecks an OPANIC node.
func tcPanic(n *ir.UnaryExpr) ir.Node {
n.X = Expr(n.X)
- n.X = DefaultLit(n.X, types.Types[types.TINTER])
+ n.X = AssignConv(n.X, types.Types[types.TINTER], "argument to panic")
if n.X.Type() == nil {
n.SetType(nil)
return n
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go
index 4d48b80346..be4a689836 100644
--- a/src/cmd/compile/internal/typecheck/iexport.go
+++ b/src/cmd/compile/internal/typecheck/iexport.go
@@ -423,9 +423,13 @@ type exportWriter struct {
prevLine int64
prevColumn int64
- // dclIndex maps function-scoped declarations to their index
- // within their respective Func's Dcl list.
- dclIndex map[*ir.Name]int
+ // dclIndex maps function-scoped declarations to an int used to refer to
+ // them later in the function. For local variables/params, the int is
+ // non-negative and in order of the appearance in the Func's Dcl list. For
+ // closure variables, the index is negative starting at -2.
+ dclIndex map[*ir.Name]int
+ maxDclIndex int
+ maxClosureVarIndex int
}
func (p *iexporter) doDecl(n *ir.Name) {
@@ -976,6 +980,9 @@ func (w *exportWriter) funcExt(n *ir.Name) {
w.linkname(n.Sym())
w.symIdx(n.Sym())
+ // TODO remove after register abi is working.
+ w.uint64(uint64(n.Func.Pragma))
+
// Escape analysis.
for _, fs := range &types.RecvsParams {
for _, f := range fs(n.Type()).FieldSlice() {
@@ -1035,14 +1042,19 @@ func (w *exportWriter) typeExt(t *types.Type) {
// Inline bodies.
-func (w *exportWriter) funcBody(fn *ir.Func) {
- w.int64(int64(len(fn.Inl.Dcl)))
- for i, n := range fn.Inl.Dcl {
+func (w *exportWriter) writeNames(dcl []*ir.Name) {
+ w.int64(int64(len(dcl)))
+ for i, n := range dcl {
w.pos(n.Pos())
w.localIdent(n.Sym())
w.typ(n.Type())
- w.dclIndex[n] = i
+ w.dclIndex[n] = w.maxDclIndex + i
}
+ w.maxDclIndex += len(dcl)
+}
+
+func (w *exportWriter) funcBody(fn *ir.Func) {
+ w.writeNames(fn.Inl.Dcl)
w.stmtList(fn.Inl.Body)
}
@@ -1312,8 +1324,30 @@ func (w *exportWriter) expr(n ir.Node) {
// case OTARRAY, OTMAP, OTCHAN, OTSTRUCT, OTINTER, OTFUNC:
// should have been resolved by typechecking - handled by default case
- // case OCLOSURE:
- // unimplemented - handled by default case
+ case ir.OCLOSURE:
+ n := n.(*ir.ClosureExpr)
+ w.op(ir.OCLOSURE)
+ w.pos(n.Pos())
+ w.signature(n.Type())
+
+ // Write out id for the Outer of each conditional variable. The
+ // conditional variable itself for this closure will be re-created
+ // during import.
+ w.int64(int64(len(n.Func.ClosureVars)))
+ for i, cv := range n.Func.ClosureVars {
+ w.pos(cv.Pos())
+ w.localName(cv.Outer)
+ // Closure variable (which will be re-created during
+ // import) is given via a negative id, starting at -2,
+ // which is used to refer to it later in the function
+ // during export. -1 represents blanks.
+ w.dclIndex[cv] = -(i + 2) - w.maxClosureVarIndex
+ }
+ w.maxClosureVarIndex += len(n.Func.ClosureVars)
+
+ // like w.funcBody(n.Func), but not for .Inl
+ w.writeNames(n.Func.Dcl)
+ w.stmtList(n.Func.Body)
// case OCOMPLIT:
// should have been resolved by typechecking - handled by default case
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index c9effabce0..f2682257f3 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -37,7 +37,7 @@ var (
// and offset where that identifier's declaration can be read.
DeclImporter = map[*types.Sym]iimporterAndOffset{}
- // inlineImporter is like declImporter, but for inline bodies
+ // inlineImporter is like DeclImporter, but for inline bodies
// for function and method symbols.
inlineImporter = map[*types.Sym]iimporterAndOffset{}
)
@@ -265,6 +265,9 @@ type importReader struct {
// curfn is the current function we're importing into.
curfn *ir.Func
+ // Slice of all dcls for function, including any interior closures
+ allDcls []*ir.Name
+ allClosureVars []*ir.Name
}
func (p *iimporter) newReader(off uint64, pkg *types.Pkg) *importReader {
@@ -334,7 +337,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
recv := r.param()
mtyp := r.signature(recv)
- // methodSym already marked m.Sym as a function.
+ // MethodSym already marked m.Sym as a function.
m := ir.NewNameAt(mpos, ir.MethodSym(recv.Type, msym))
m.Class = ir.PFUNC
m.SetType(mtyp)
@@ -647,6 +650,9 @@ func (r *importReader) funcExt(n *ir.Name) {
r.linkname(n.Sym())
r.symIdx(n.Sym())
+ // TODO remove after register abi is working
+ n.SetPragma(ir.PragmaFlag(r.uint64()))
+
// Escape analysis.
for _, fs := range &types.RecvsParams {
for _, f := range fs(n.Type()).FieldSlice() {
@@ -718,6 +724,7 @@ func (r *importReader) doInline(fn *ir.Func) {
base.Fatalf("%v already has inline body", fn)
}
+ //fmt.Printf("Importing %v\n", n)
r.funcBody(fn)
importlist = append(importlist, fn)
@@ -751,6 +758,24 @@ func (r *importReader) funcBody(fn *ir.Func) {
r.curfn = fn
// Import local declarations.
+ fn.Inl.Dcl = r.readFuncDcls(fn)
+
+ // Import function body.
+ body := r.stmtList()
+ if body == nil {
+ // Make sure empty body is not interpreted as
+ // no inlineable body (see also parser.fnbody)
+ // (not doing so can cause significant performance
+ // degradation due to unnecessary calls to empty
+ // functions).
+ body = []ir.Node{}
+ }
+ fn.Inl.Body = body
+
+ r.curfn = outerfn
+}
+
+func (r *importReader) readNames(fn *ir.Func) []*ir.Name {
dcls := make([]*ir.Name, r.int64())
for i := range dcls {
n := ir.NewDeclNameAt(r.pos(), ir.ONAME, r.localIdent())
@@ -759,7 +784,12 @@ func (r *importReader) funcBody(fn *ir.Func) {
n.SetType(r.typ())
dcls[i] = n
}
- fn.Inl.Dcl = dcls
+ r.allDcls = append(r.allDcls, dcls...)
+ return dcls
+}
+
+func (r *importReader) readFuncDcls(fn *ir.Func) []*ir.Name {
+ dcls := r.readNames(fn)
// Fixup parameter classes and associate with their
// signature's type fields.
@@ -784,28 +814,18 @@ func (r *importReader) funcBody(fn *ir.Func) {
for _, f := range typ.Results().FieldSlice() {
fix(f, ir.PPARAMOUT)
}
-
- // Import function body.
- body := r.stmtList()
- if body == nil {
- // Make sure empty body is not interpreted as
- // no inlineable body (see also parser.fnbody)
- // (not doing so can cause significant performance
- // degradation due to unnecessary calls to empty
- // functions).
- body = []ir.Node{}
- }
- fn.Inl.Body = body
-
- r.curfn = outerfn
+ return dcls
}
func (r *importReader) localName() *ir.Name {
i := r.int64()
- if i < 0 {
+ if i == -1 {
return ir.BlankNode.(*ir.Name)
}
- return r.curfn.Inl.Dcl[i]
+ if i < 0 {
+ return r.allClosureVars[-i-2]
+ }
+ return r.allDcls[i]
}
func (r *importReader) stmtList() []ir.Node {
@@ -921,8 +941,38 @@ func (r *importReader) node() ir.Node {
// case OTARRAY, OTMAP, OTCHAN, OTSTRUCT, OTINTER, OTFUNC:
// unreachable - should have been resolved by typechecking
- // case OCLOSURE:
- // unimplemented
+ case ir.OCLOSURE:
+ //println("Importing CLOSURE")
+ pos := r.pos()
+ typ := r.signature(nil)
+
+ // All the remaining code below is similar to (*noder).funcLit(), but
+ // with Dcls and ClosureVars lists already set up
+ fn := ir.NewFunc(pos)
+ fn.SetIsHiddenClosure(true)
+ fn.Nname = ir.NewNameAt(pos, ir.BlankNode.Sym())
+ fn.Nname.Func = fn
+ fn.Nname.Ntype = ir.TypeNode(typ)
+ fn.Nname.Defn = fn
+ fn.Nname.SetType(typ)
+
+ cvars := make([]*ir.Name, r.int64())
+ for i := range cvars {
+ cvars[i] = ir.CaptureName(r.pos(), fn, r.localName().Canonical())
+ }
+ fn.ClosureVars = cvars
+ r.allClosureVars = append(r.allClosureVars, cvars...)
+
+ fn.Dcl = r.readFuncDcls(fn)
+ body := r.stmtList()
+ ir.FinishCaptureNames(pos, r.curfn, fn)
+
+ clo := ir.NewClosureExpr(pos, fn)
+ fn.OClosure = clo
+
+ fn.Body = body
+
+ return clo
// case OPTRLIT:
// unreachable - mapped to case OADDR below by exporter
diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go
index 8baa5dda78..14ed175be9 100644
--- a/src/cmd/compile/internal/typecheck/stmt.go
+++ b/src/cmd/compile/internal/typecheck/stmt.go
@@ -25,7 +25,7 @@ func typecheckrangeExpr(n *ir.RangeStmt) {
}
t := RangeExprType(n.X.Type())
- // delicate little dance. see typecheckas2
+ // delicate little dance. see tcAssignList
if n.Key != nil && !ir.DeclaredBy(n.Key, n) {
n.Key = AssignExpr(n.Key)
}
@@ -90,7 +90,7 @@ func typecheckrangeExpr(n *ir.RangeStmt) {
// fill in the var's type.
func tcAssign(n *ir.AssignStmt) {
if base.EnableTrace && base.Flag.LowerT {
- defer tracePrint("typecheckas", n)(nil)
+ defer tracePrint("tcAssign", n)(nil)
}
if n.Y == nil {
@@ -110,7 +110,7 @@ func tcAssign(n *ir.AssignStmt) {
func tcAssignList(n *ir.AssignListStmt) {
if base.EnableTrace && base.Flag.LowerT {
- defer tracePrint("typecheckas2", n)(nil)
+ defer tracePrint("tcAssignList", n)(nil)
}
assign(n, n.Lhs, n.Rhs)
@@ -119,7 +119,7 @@ func tcAssignList(n *ir.AssignListStmt) {
func assign(stmt ir.Node, lhs, rhs []ir.Node) {
// delicate little dance.
// the definition of lhs may refer to this assignment
- // as its definition, in which case it will call typecheckas.
+ // as its definition, in which case it will call tcAssign.
// in that case, do not call typecheck back, or it will cycle.
// if the variable has a type (ntype) then typechecking
// will not look at defn, so it is okay (and desirable,
diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go
index a640d105d1..b88a9f2283 100644
--- a/src/cmd/compile/internal/typecheck/subr.go
+++ b/src/cmd/compile/internal/typecheck/subr.go
@@ -81,7 +81,7 @@ func markAddrOf(n ir.Node) ir.Node {
// main typecheck has completed.
// The argument to OADDR needs to be typechecked because &x[i] takes
// the address of x if x is an array, but not if x is a slice.
- // Note: outervalue doesn't work correctly until n is typechecked.
+ // Note: OuterValue doesn't work correctly until n is typechecked.
n = typecheck(n, ctxExpr)
if x := ir.OuterValue(n); x.Op() == ir.ONAME {
x.Name().SetAddrtaken(true)
@@ -367,10 +367,10 @@ func assignop(src, dst *types.Type) (ir.Op, string) {
var missing, have *types.Field
var ptr int
if implements(src, dst, &missing, &have, &ptr) {
- // Call itabname so that (src, dst)
+ // Call NeedITab/ITabAddr so that (src, dst)
// gets added to itabs early, which allows
// us to de-virtualize calls through this
- // type/interface pair later. See peekitabs in reflect.go
+ // type/interface pair later. See CompileITabs in reflect.go
if types.IsDirectIface(src) && !dst.IsEmptyInterface() {
NeedITab(src, dst)
}
@@ -440,7 +440,7 @@ func assignop(src, dst *types.Type) (ir.Op, string) {
}
}
- // 6. rule about untyped constants - already converted by defaultlit.
+ // 6. rule about untyped constants - already converted by DefaultLit.
// 7. Any typed value can be assigned to the blank identifier.
if dst.Kind() == types.TBLANK {
@@ -834,7 +834,7 @@ func lookdot0(s *types.Sym, t *types.Type, save **types.Field, ignorecase bool)
var slist []symlink
// Code to help generate trampoline functions for methods on embedded
-// types. These are approx the same as the corresponding adddot
+// types. These are approx the same as the corresponding AddImplicitDots
// routines except that they expect to be called with unique tasks and
// they return the actual methods.
diff --git a/src/cmd/compile/internal/typecheck/syms.go b/src/cmd/compile/internal/typecheck/syms.go
index 28db40db91..202a932e6c 100644
--- a/src/cmd/compile/internal/typecheck/syms.go
+++ b/src/cmd/compile/internal/typecheck/syms.go
@@ -15,7 +15,7 @@ import (
func LookupRuntime(name string) *ir.Name {
s := ir.Pkgs.Runtime.Lookup(name)
if s == nil || s.Def == nil {
- base.Fatalf("syslook: can't find runtime.%s", name)
+ base.Fatalf("LookupRuntime: can't find runtime.%s", name)
}
return ir.AsNode(s.Def).(*ir.Name)
}
@@ -33,7 +33,7 @@ func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
n.Class = old.Class
n.SetType(types.SubstAny(old.Type(), &types_))
if len(types_) > 0 {
- base.Fatalf("substArgTypes: too many argument types")
+ base.Fatalf("SubstArgTypes: too many argument types")
}
return n
}
@@ -86,14 +86,17 @@ func InitRuntime() {
// LookupRuntimeFunc looks up Go function name in package runtime. This function
// must follow the internal calling convention.
func LookupRuntimeFunc(name string) *obj.LSym {
- s := ir.Pkgs.Runtime.Lookup(name)
- s.SetFunc(true)
- return s.Linksym()
+ return LookupRuntimeABI(name, obj.ABIInternal)
}
// LookupRuntimeVar looks up a variable (or assembly function) name in package
// runtime. If this is a function, it may have a special calling
// convention.
func LookupRuntimeVar(name string) *obj.LSym {
- return ir.Pkgs.Runtime.Lookup(name).Linksym()
+ return LookupRuntimeABI(name, obj.ABI0)
+}
+
+// LookupRuntimeABI looks up a name in package runtime using the given ABI.
+func LookupRuntimeABI(name string, abi obj.ABI) *obj.LSym {
+ return base.PkgLinksym("runtime", name, abi)
}
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index d5100021a2..cb434578dd 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -456,7 +456,7 @@ func typecheck(n ir.Node, top int) (res ir.Node) {
}
// indexlit implements typechecking of untyped values as
-// array/slice indexes. It is almost equivalent to defaultlit
+// array/slice indexes. It is almost equivalent to DefaultLit
// but also accepts untyped numeric values representable as
// value of type int (see also checkmake for comparison).
// The result of indexlit MUST be assigned back to n, e.g.
@@ -521,7 +521,7 @@ func typecheck1(n ir.Node, top int) ir.Node {
}
return n
- case ir.ONAMEOFFSET:
+ case ir.OLINKSYMOFFSET:
// type already set
return n
@@ -857,8 +857,8 @@ func typecheck1(n ir.Node, top int) ir.Node {
n := n.(*ir.ReturnStmt)
return tcReturn(n)
- case ir.ORETJMP:
- n := n.(*ir.BranchStmt)
+ case ir.OTAILCALL:
+ n := n.(*ir.TailCallStmt)
return n
case ir.OSELECT:
@@ -938,7 +938,7 @@ func typecheckargs(n ir.InitNode) {
// If we're outside of function context, then this call will
// be executed during the generated init function. However,
// init.go hasn't yet created it. Instead, associate the
- // temporary variables with initTodo for now, and init.go
+ // temporary variables with InitTodoFunc for now, and init.go
// will reassociate them later when it's appropriate.
static := ir.CurFunc == nil
if static {
@@ -1890,7 +1890,7 @@ func checkmake(t *types.Type, arg string, np *ir.Node) bool {
return false
}
- // Do range checks for constants before defaultlit
+ // Do range checks for constants before DefaultLit
// to avoid redundant "constant NNN overflows int" errors.
if n.Op() == ir.OLITERAL {
v := toint(n.Val())
@@ -1904,7 +1904,7 @@ func checkmake(t *types.Type, arg string, np *ir.Node) bool {
}
}
- // defaultlit is necessary for non-constants too: n might be 1.1<<k.
+ // DefaultLit is necessary for non-constants too: n might be 1.1<<k.
// TODO(gri) The length argument requirements for (array/slice) make
// are the same as for index expressions. Factor the code better;
// for instance, indexlit might be called here and incorporate some
@@ -2023,7 +2023,7 @@ func isTermNode(n ir.Node) bool {
n := n.(*ir.BlockStmt)
return isTermNodes(n.List)
- case ir.OGOTO, ir.ORETURN, ir.ORETJMP, ir.OPANIC, ir.OFALL:
+ case ir.OGOTO, ir.ORETURN, ir.OTAILCALL, ir.OPANIC, ir.OFALL:
return true
case ir.OFOR, ir.OFORUNTIL:
diff --git a/src/cmd/compile/internal/types/alg.go b/src/cmd/compile/internal/types/alg.go
index 6091ee249c..2c2700f345 100644
--- a/src/cmd/compile/internal/types/alg.go
+++ b/src/cmd/compile/internal/types/alg.go
@@ -132,7 +132,7 @@ func AlgType(t *Type) (AlgKind, *Type) {
return ret, nil
}
- base.Fatalf("algtype: unexpected type %v", t)
+ base.Fatalf("AlgType: unexpected type %v", t)
return 0, nil
}
@@ -163,7 +163,7 @@ func IncomparableField(t *Type) *Field {
// by padding.
func IsPaddedField(t *Type, i int) bool {
if !t.IsStruct() {
- base.Fatalf("ispaddedfield called non-struct %v", t)
+ base.Fatalf("IsPaddedField called non-struct %v", t)
}
end := t.Width
if i+1 < t.NumFields() {
diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go
index cd0679f6b9..da224d4019 100644
--- a/src/cmd/compile/internal/types/fmt.go
+++ b/src/cmd/compile/internal/types/fmt.go
@@ -44,7 +44,7 @@ func OrigSym(s *Sym) *Sym {
}
if strings.HasPrefix(s.Name, ".anon") {
- // originally an unnamed or _ name (see subr.go: structargs)
+ // originally an unnamed or _ name (see subr.go: NewFuncParams)
return nil
}
diff --git a/src/cmd/compile/internal/types/size.go b/src/cmd/compile/internal/types/size.go
index a54c086ded..98540eefb6 100644
--- a/src/cmd/compile/internal/types/size.go
+++ b/src/cmd/compile/internal/types/size.go
@@ -58,7 +58,7 @@ func typePos(t *Type) src.XPos {
var MaxWidth int64
// CalcSizeDisabled indicates whether it is safe
-// to calculate Types' widths and alignments. See dowidth.
+// to calculate Types' widths and alignments. See CalcSize.
var CalcSizeDisabled bool
// machine size and rounding alignment is dictated around
@@ -135,7 +135,7 @@ func expandiface(t *Type) {
m.Offset = int64(i) * int64(PtrSize)
}
- // Access fields directly to avoid recursively calling dowidth
+ // Access fields directly to avoid recursively calling CalcSize
// within Type.Fields().
t.Extra.(*Interface).Fields.Set(methods)
}
@@ -164,7 +164,7 @@ func calcStructOffset(errtype *Type, t *Type, o int64, flag int) int64 {
f.Offset = o
if f.Nname != nil {
// addrescapes has similar code to update these offsets.
- // Usually addrescapes runs after widstruct,
+ // Usually addrescapes runs after calcStructOffset,
// in which case we could drop this,
// but function closure functions are the exception.
// NOTE(rsc): This comment may be stale.
@@ -306,17 +306,16 @@ func reportTypeLoop(t *Type) {
}
// CalcSize calculates and stores the size and alignment for t.
-// If sizeCalculationDisabled is set, and the size/alignment
+// If CalcSizeDisabled is set, and the size/alignment
// have not already been calculated, it calls Fatal.
// This is used to prevent data races in the back end.
func CalcSize(t *Type) {
- // Calling dowidth when typecheck tracing enabled is not safe.
+ // Calling CalcSize when typecheck tracing enabled is not safe.
// See issue #33658.
if base.EnableTrace && SkipSizeForTracing {
return
}
if PtrSize == 0 {
-
// Assume this is a test.
return
}
@@ -351,7 +350,7 @@ func CalcSize(t *Type) {
return
}
- // defer checkwidth calls until after we're done
+ // defer CheckSize calls until after we're done
DeferCheckSize()
lno := base.Pos
@@ -367,7 +366,7 @@ func CalcSize(t *Type) {
case TFUNC, TCHAN, TMAP, TSTRING:
break
- // simtype == 0 during bootstrap
+ // SimType == 0 during bootstrap
default:
if SimType[t.Kind()] != 0 {
et = SimType[t.Kind()]
@@ -377,7 +376,7 @@ func CalcSize(t *Type) {
var w int64
switch et {
default:
- base.Fatalf("dowidth: unknown type: %v", t)
+ base.Fatalf("CalcSize: unknown type: %v", t)
// compiler-specific stuff
case TINT8, TUINT8, TBOOL:
@@ -443,11 +442,11 @@ func CalcSize(t *Type) {
case TANY:
// not a real type; should be replaced before use.
- base.Fatalf("dowidth any")
+ base.Fatalf("CalcSize any")
case TSTRING:
if StringSize == 0 {
- base.Fatalf("early dowidth string")
+ base.Fatalf("early CalcSize string")
}
w = StringSize
t.Align = uint8(PtrSize)
@@ -477,7 +476,7 @@ func CalcSize(t *Type) {
case TSTRUCT:
if t.IsFuncArgStruct() {
- base.Fatalf("dowidth fn struct %v", t)
+ base.Fatalf("CalcSize fn struct %v", t)
}
w = calcStructOffset(t, t, 0, 1)
@@ -526,7 +525,7 @@ func CalcStructSize(s *Type) {
s.Width = calcStructOffset(s, s, 0, 1) // sets align
}
-// when a type's width should be known, we call checkwidth
+// when a type's width should be known, we call CheckSize
// to compute it. during a declaration like
//
// type T *struct { next T }
@@ -535,11 +534,11 @@ func CalcStructSize(s *Type) {
// until after T has been initialized to be a pointer to that struct.
// similarly, during import processing structs may be used
// before their definition. in those situations, calling
-// defercheckwidth() stops width calculations until
-// resumecheckwidth() is called, at which point all the
-// checkwidths that were deferred are executed.
-// dowidth should only be called when the type's size
-// is needed immediately. checkwidth makes sure the
+// DeferCheckSize() stops width calculations until
+// ResumeCheckSize() is called, at which point all the
+// CalcSizes that were deferred are executed.
+// CalcSize should only be called when the type's size
+// is needed immediately. CheckSize makes sure the
// size is evaluated eventually.
var deferredTypeStack []*Type
@@ -552,7 +551,7 @@ func CheckSize(t *Type) {
// function arg structs should not be checked
// outside of the enclosing function.
if t.IsFuncArgStruct() {
- base.Fatalf("checkwidth %v", t)
+ base.Fatalf("CheckSize %v", t)
}
if defercalc == 0 {
@@ -606,7 +605,7 @@ func PtrDataSize(t *Type) int64 {
case TINTER:
// struct { Itab *tab; void *data; } or
// struct { Type *type; void *data; }
- // Note: see comment in plive.go:onebitwalktype1.
+ // Note: see comment in typebits.Set
return 2 * int64(PtrSize)
case TSLICE:
@@ -628,7 +627,7 @@ func PtrDataSize(t *Type) int64 {
return lastPtrField.Offset + PtrDataSize(lastPtrField.Type)
default:
- base.Fatalf("typeptrdata: unexpected type, %v", t)
+ base.Fatalf("PtrDataSize: unexpected type, %v", t)
return 0
}
}
diff --git a/src/cmd/compile/internal/types/sym.go b/src/cmd/compile/internal/types/sym.go
index 2914e2ed3f..0e66ed348b 100644
--- a/src/cmd/compile/internal/types/sym.go
+++ b/src/cmd/compile/internal/types/sym.go
@@ -64,53 +64,30 @@ func (sym *Sym) IsBlank() bool {
return sym != nil && sym.Name == "_"
}
-func (sym *Sym) LinksymName() string {
- if sym.IsBlank() {
- return "_"
- }
- if sym.Linkname != "" {
- return sym.Linkname
- }
- return sym.Pkg.Prefix + "." + sym.Name
-}
-
// Deprecated: This method should not be used directly. Instead, use a
// higher-level abstraction that directly returns the linker symbol
// for a named object. For example, reflectdata.TypeLinksym(t) instead
// of reflectdata.TypeSym(t).Linksym().
func (sym *Sym) Linksym() *obj.LSym {
- if sym == nil {
- return nil
- }
- initPkg := func(r *obj.LSym) {
- if sym.Linkname != "" {
- r.Pkg = "_"
- } else {
- r.Pkg = sym.Pkg.Prefix
- }
- }
+ abi := obj.ABI0
if sym.Func() {
- // This is a function symbol. Mark it as "internal ABI".
- return base.Ctxt.LookupABIInit(sym.LinksymName(), obj.ABIInternal, initPkg)
+ abi = obj.ABIInternal
}
- return base.Ctxt.LookupInit(sym.LinksymName(), initPkg)
+ return sym.LinksymABI(abi)
}
-// LinksymABI0 looks up or creates an ABI0 linker symbol for "sym",
-// in cases where we want to specifically select the ABI0 version of
-// a symbol (typically used only for ABI wrappers).
-func (sym *Sym) LinksymABI0() *obj.LSym {
+// Deprecated: This method should not be used directly. Instead, use a
+// higher-level abstraction that directly returns the linker symbol
+// for a named object. For example, (*ir.Name).LinksymABI(abi) instead
+// of (*ir.Name).Sym().LinksymABI(abi).
+func (sym *Sym) LinksymABI(abi obj.ABI) *obj.LSym {
if sym == nil {
- return nil
+ base.Fatalf("nil symbol")
}
- initPkg := func(r *obj.LSym) {
- if sym.Linkname != "" {
- r.Pkg = "_"
- } else {
- r.Pkg = sym.Pkg.Prefix
- }
+ if sym.Linkname != "" {
+ return base.Linkname(sym.Linkname, abi)
}
- return base.Ctxt.LookupABIInit(sym.LinksymName(), obj.ABI0, initPkg)
+ return base.PkgLinksym(sym.Pkg.Prefix, sym.Name, abi)
}
// Less reports whether symbol a is ordered before symbol b.
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 5176b96c02..0dfbef8af1 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -107,7 +107,7 @@ const (
// Types stores pointers to predeclared named types.
//
// It also stores pointers to several special types:
-// - Types[TANY] is the placeholder "any" type recognized by substArgTypes.
+// - Types[TANY] is the placeholder "any" type recognized by SubstArgTypes.
// - Types[TBLANK] represents the blank variable's type.
// - Types[TNIL] represents the predeclared "nil" value's type.
// - Types[TUNSAFEPTR] is package unsafe's Pointer type.
@@ -643,7 +643,7 @@ func SubstAny(t *Type, types *[]*Type) *Type {
case TANY:
if len(*types) == 0 {
- base.Fatalf("substArgTypes: not enough argument types")
+ base.Fatalf("SubstArgTypes: not enough argument types")
}
t = (*types)[0]
*types = (*types)[1:]
diff --git a/src/cmd/compile/internal/types2/stdlib_test.go b/src/cmd/compile/internal/types2/stdlib_test.go
index ae573a4ec8..ffd423be27 100644
--- a/src/cmd/compile/internal/types2/stdlib_test.go
+++ b/src/cmd/compile/internal/types2/stdlib_test.go
@@ -162,6 +162,8 @@ func TestStdTest(t *testing.T) {
testTestDir(t, filepath.Join(runtime.GOROOT(), "test"),
"cmplxdivide.go", // also needs file cmplxdivide1.go - ignore
"directive.go", // tests compiler rejection of bad directive placement - ignore
+ "embedfunc.go", // tests //go:embed
+ "embedvers.go", // tests //go:embed
"linkname2.go", // types2 doesn't check validity of //go:xxx directives
)
}
diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go
index 3fe810ac4e..6e8075a35f 100644
--- a/src/cmd/compile/internal/walk/assign.go
+++ b/src/cmd/compile/internal/walk/assign.go
@@ -248,18 +248,6 @@ func walkReturn(n *ir.ReturnStmt) ir.Node {
return n
}
-// fncall reports whether assigning an rvalue of type rt to an lvalue l might involve a function call.
-func fncall(l ir.Node, rt *types.Type) bool {
- if l.HasCall() || l.Op() == ir.OINDEXMAP {
- return true
- }
- if types.Identical(l.Type(), rt) {
- return false
- }
- // There might be a conversion required, which might involve a runtime call.
- return true
-}
-
// check assign type list to
// an expression list. called in
// expr-list = func()
@@ -268,21 +256,17 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node {
base.Fatalf("ascompatet: assignment count mismatch: %d = %d", len(nl), nr.NumFields())
}
- var nn, mm ir.Nodes
+ var nn ir.Nodes
for i, l := range nl {
if ir.IsBlank(l) {
continue
}
r := nr.Field(i)
- // Any assignment to an lvalue that might cause a function call must be
- // deferred until all the returned values have been read.
- if fncall(l, r.Type) {
- tmp := ir.Node(typecheck.Temp(r.Type))
- tmp = typecheck.Expr(tmp)
- a := convas(ir.NewAssignStmt(base.Pos, l, tmp), &mm)
- mm.Append(a)
- l = tmp
+ // Order should have created autotemps of the appropriate type for
+ // us to store results into.
+ if tmp, ok := l.(*ir.Name); !ok || !tmp.AutoTemp() || !types.Identical(tmp.Type(), r.Type) {
+ base.FatalfAt(l.Pos(), "assigning %v to %+v", r.Type, l)
}
res := ir.NewResultExpr(base.Pos, nil, types.BADWIDTH)
@@ -290,16 +274,9 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node {
res.SetType(r.Type)
res.SetTypecheck(1)
- a := convas(ir.NewAssignStmt(base.Pos, l, res), &nn)
- updateHasCall(a)
- if a.HasCall() {
- ir.Dump("ascompatet ucount", a)
- base.Fatalf("ascompatet: too many function calls evaluating parameters")
- }
-
- nn.Append(a)
+ nn.Append(ir.NewAssignStmt(base.Pos, l, res))
}
- return append(nn, mm...)
+ return nn
}
// check assign expression list to
@@ -392,11 +369,7 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
appendWalkStmt(&late, convas(ir.NewAssignStmt(base.Pos, lorig, r), &late))
- if name == nil || name.Addrtaken() || name.Class == ir.PEXTERN || name.Class == ir.PAUTOHEAP {
- memWrite = true
- continue
- }
- if ir.IsBlank(name) {
+ if name != nil && ir.IsBlank(name) {
// We can ignore assignments to blank.
continue
}
@@ -405,7 +378,12 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
// parameters. These can't appear in expressions anyway.
continue
}
- assigned.Add(name)
+
+ if name != nil && name.OnStack() && !name.Addrtaken() {
+ assigned.Add(name)
+ } else {
+ memWrite = true
+ }
}
early.Append(late.Take()...)
@@ -418,7 +396,10 @@ func readsMemory(n ir.Node) bool {
switch n.Op() {
case ir.ONAME:
n := n.(*ir.Name)
- return n.Class == ir.PEXTERN || n.Class == ir.PAUTOHEAP || n.Addrtaken()
+ if n.Class == ir.PFUNC {
+ return false
+ }
+ return n.Addrtaken() || !n.OnStack()
case ir.OADD,
ir.OAND,
diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go
index a061181e2f..97f9de9c1d 100644
--- a/src/cmd/compile/internal/walk/builtin.go
+++ b/src/cmd/compile/internal/walk/builtin.go
@@ -48,10 +48,10 @@ func walkAppend(n *ir.CallExpr, init *ir.Nodes, dst ir.Node) ir.Node {
nsrc := n.Args[0]
- // walkexprlistsafe will leave OINDEX (s[n]) alone if both s
+ // walkExprListSafe will leave OINDEX (s[n]) alone if both s
// and n are name or literal, but those may index the slice we're
// modifying here. Fix explicitly.
- // Using cheapexpr also makes sure that the evaluation
+ // Using cheapExpr also makes sure that the evaluation
// of all arguments (and especially any panics) happen
// before we begin to modify the slice in a visible way.
ls := n.Args[1:]
@@ -277,10 +277,8 @@ func walkMakeMap(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
// Allocate hmap on stack.
// var hv hmap
- hv := typecheck.Temp(hmapType)
- init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, hv, nil)))
// h = &hv
- h = typecheck.NodAddr(hv)
+ h = stackTempAddr(init, hmapType)
// Allocate one bucket pointed to by hmap.buckets on stack if hint
// is not larger than BUCKETSIZE. In case hint is larger than
@@ -303,11 +301,8 @@ func walkMakeMap(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
nif.Likely = true
// var bv bmap
- bv := typecheck.Temp(reflectdata.MapBucketType(t))
- nif.Body.Append(ir.NewAssignStmt(base.Pos, bv, nil))
-
// b = &bv
- b := typecheck.NodAddr(bv)
+ b := stackTempAddr(&nif.Body, reflectdata.MapBucketType(t))
// h.buckets = b
bsym := hmapType.Field(5).Sym // hmap.buckets see reflect.go:hmap
@@ -388,7 +383,7 @@ func walkMakeSlice(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
// n = arr[:l]
i := typecheck.IndexConst(r)
if i < 0 {
- base.Fatalf("walkexpr: invalid index %v", r)
+ base.Fatalf("walkExpr: invalid index %v", r)
}
// cap is constrained to [0,2^31) or [0,2^63) depending on whether
@@ -501,18 +496,19 @@ func walkMakeSliceCopy(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
// walkNew walks an ONEW node.
func walkNew(n *ir.UnaryExpr, init *ir.Nodes) ir.Node {
- if n.Type().Elem().NotInHeap() {
+ t := n.Type().Elem()
+ if t.NotInHeap() {
base.Errorf("%v can't be allocated in Go; it is incomplete (or unallocatable)", n.Type().Elem())
}
if n.Esc() == ir.EscNone {
- if n.Type().Elem().Width >= ir.MaxImplicitStackVarSize {
+ if t.Size() >= ir.MaxImplicitStackVarSize {
base.Fatalf("large ONEW with EscNone: %v", n)
}
- r := typecheck.Temp(n.Type().Elem())
- init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, r, nil))) // zero temp
- return typecheck.Expr(typecheck.NodAddr(r))
+ return stackTempAddr(init, t)
}
- return callnew(n.Type().Elem())
+ types.CalcSize(t)
+ n.MarkNonNil()
+ return n
}
// generate code for print
@@ -678,15 +674,6 @@ func badtype(op ir.Op, tl, tr *types.Type) {
base.Errorf("illegal types for operand: %v%s", op, s)
}
-func callnew(t *types.Type) ir.Node {
- types.CalcSize(t)
- n := ir.NewUnaryExpr(base.Pos, ir.ONEWOBJ, reflectdata.TypePtr(t))
- n.SetType(types.NewPtr(t))
- n.SetTypecheck(1)
- n.MarkNonNil()
- return n
-}
-
func writebarrierfn(name string, l *types.Type, r *types.Type) ir.Node {
fn := typecheck.LookupRuntime(name)
fn = typecheck.SubstArgTypes(fn, l, r)
diff --git a/src/cmd/compile/internal/walk/closure.go b/src/cmd/compile/internal/walk/closure.go
index 694aa99940..1d1cbc2054 100644
--- a/src/cmd/compile/internal/walk/closure.go
+++ b/src/cmd/compile/internal/walk/closure.go
@@ -159,7 +159,7 @@ func walkCallPart(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
//
// clos = &struct{F uintptr; R T}{T.M·f, x}
//
- // Like walkclosure above.
+ // Like walkClosure above.
if n.X.Type().IsInterface() {
// Trigger panic for method on nil interface now.
diff --git a/src/cmd/compile/internal/walk/compare.go b/src/cmd/compile/internal/walk/compare.go
index a4ea31bf55..7c385c0e0d 100644
--- a/src/cmd/compile/internal/walk/compare.go
+++ b/src/cmd/compile/internal/walk/compare.go
@@ -418,7 +418,7 @@ func eqFor(t *types.Type) (n ir.Node, needsize bool) {
// Should only arrive here with large memory or
// a struct/array containing a non-memory field/element.
// Small memory is handled inline, and single non-memory
- // is handled by walkcompare.
+ // is handled by walkCompare.
switch a, _ := types.AlgType(t); a {
case types.AMEM:
n := typecheck.LookupRuntime("memequal")
@@ -436,7 +436,7 @@ func eqFor(t *types.Type) (n ir.Node, needsize bool) {
}))
return n, false
}
- base.Fatalf("eqfor %v", t)
+ base.Fatalf("eqFor %v", t)
return nil, false
}
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go
index 8a77bba2ad..73442dc404 100644
--- a/src/cmd/compile/internal/walk/complit.go
+++ b/src/cmd/compile/internal/walk/complit.go
@@ -64,11 +64,11 @@ func readonlystaticname(t *types.Type) *ir.Name {
}
func isSimpleName(nn ir.Node) bool {
- if nn.Op() != ir.ONAME {
+ if nn.Op() != ir.ONAME || ir.IsBlank(nn) {
return false
}
n := nn.(*ir.Name)
- return n.Class != ir.PAUTOHEAP && n.Class != ir.PEXTERN
+ return n.OnStack()
}
func litas(l ir.Node, r ir.Node, init *ir.Nodes) {
@@ -297,7 +297,7 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes)
if !ok || name.Class != ir.PEXTERN {
base.Fatalf("slicelit: %v", var_)
}
- staticdata.InitSlice(name, offset, vstat, t.NumElem())
+ staticdata.InitSlice(name, offset, vstat.Linksym(), t.NumElem())
return
}
@@ -344,37 +344,18 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes)
if !types.Identical(t, x.Type()) {
panic("dotdotdot base type does not match order's assigned type")
}
-
- if vstat == nil {
- a = ir.NewAssignStmt(base.Pos, x, nil)
- a = typecheck.Stmt(a)
- init.Append(a) // zero new temp
- } else {
- // Declare that we're about to initialize all of x.
- // (Which happens at the *vauto = vstat below.)
- init.Append(ir.NewUnaryExpr(base.Pos, ir.OVARDEF, x))
- }
-
- a = typecheck.NodAddr(x)
+ a = initStackTemp(init, x, vstat)
} else if n.Esc() == ir.EscNone {
- a = typecheck.Temp(t)
- if vstat == nil {
- a = ir.NewAssignStmt(base.Pos, typecheck.Temp(t), nil)
- a = typecheck.Stmt(a)
- init.Append(a) // zero new temp
- a = a.(*ir.AssignStmt).X
- } else {
- init.Append(ir.NewUnaryExpr(base.Pos, ir.OVARDEF, a))
- }
-
- a = typecheck.NodAddr(a)
+ a = initStackTemp(init, typecheck.Temp(t), vstat)
} else {
a = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(t))
}
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, vauto, a))
- if vstat != nil {
- // copy static to heap (4)
+ if vstat != nil && n.Prealloc == nil && n.Esc() != ir.EscNone {
+ // If we allocated on the heap with ONEW, copy the static to the
+ // heap (4). We skip this for stack temporaries, because
+ // initStackTemp already handled the copy.
a = ir.NewStarExpr(base.Pos, vauto)
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, a, vstat))
}
@@ -550,9 +531,8 @@ func anylit(n ir.Node, var_ ir.Node, init *ir.Nodes) {
var r ir.Node
if n.Prealloc != nil {
- // n.Right is stack temporary used as backing store.
- appendWalkStmt(init, ir.NewAssignStmt(base.Pos, n.Prealloc, nil)) // zero backing store, just in case (#18410)
- r = typecheck.NodAddr(n.Prealloc)
+ // n.Prealloc is stack temporary used as backing store.
+ r = initStackTemp(init, n.Prealloc, nil)
} else {
r = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(n.X.Type()))
r.SetEsc(n.Esc())
@@ -667,7 +647,7 @@ func genAsStatic(as *ir.AssignStmt) {
return
case ir.OMETHEXPR:
r := r.(*ir.SelectorExpr)
- staticdata.InitFunc(name, offset, r.FuncName())
+ staticdata.InitAddr(name, offset, staticdata.FuncLinksym(r.FuncName()))
return
case ir.ONAME:
r := r.(*ir.Name)
@@ -675,7 +655,7 @@ func genAsStatic(as *ir.AssignStmt) {
base.Fatalf("genAsStatic %+v", as)
}
if r.Class == ir.PFUNC {
- staticdata.InitFunc(name, offset, r)
+ staticdata.InitAddr(name, offset, staticdata.FuncLinksym(r))
return
}
}
diff --git a/src/cmd/compile/internal/walk/convert.go b/src/cmd/compile/internal/walk/convert.go
index 85459fd92f..fa8e2c0bb8 100644
--- a/src/cmd/compile/internal/walk/convert.go
+++ b/src/cmd/compile/internal/walk/convert.go
@@ -66,17 +66,6 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
return l
}
- if ir.Names.Staticuint64s == nil {
- ir.Names.Staticuint64s = typecheck.NewName(ir.Pkgs.Runtime.Lookup("staticuint64s"))
- ir.Names.Staticuint64s.Class = ir.PEXTERN
- // The actual type is [256]uint64, but we use [256*8]uint8 so we can address
- // individual bytes.
- ir.Names.Staticuint64s.SetType(types.NewArray(types.Types[types.TUINT8], 256*8))
- ir.Names.Zerobase = typecheck.NewName(ir.Pkgs.Runtime.Lookup("zerobase"))
- ir.Names.Zerobase.Class = ir.PEXTERN
- ir.Names.Zerobase.SetType(types.Types[types.TUINTPTR])
- }
-
// Optimize convT2{E,I} for many cases in which T is not pointer-shaped,
// by using an existing addressable value identical to n.Left
// or creating one on the stack.
@@ -85,7 +74,7 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
case fromType.Size() == 0:
// n.Left is zero-sized. Use zerobase.
cheapExpr(n.X, init) // Evaluate n.Left for side-effects. See issue 19246.
- value = ir.Names.Zerobase
+ value = ir.NewLinksymExpr(base.Pos, ir.Syms.Zerobase, types.Types[types.TUINTPTR])
case fromType.IsBoolean() || (fromType.Size() == 1 && fromType.IsInteger()):
// n.Left is a bool/byte. Use staticuint64s[n.Left * 8] on little-endian
// and staticuint64s[n.Left * 8 + 7] on big-endian.
@@ -95,7 +84,10 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
if ssagen.Arch.LinkArch.ByteOrder == binary.BigEndian {
index = ir.NewBinaryExpr(base.Pos, ir.OADD, index, ir.NewInt(7))
}
- xe := ir.NewIndexExpr(base.Pos, ir.Names.Staticuint64s, index)
+ // The actual type is [256]uint64, but we use [256*8]uint8 so we can address
+ // individual bytes.
+ staticuint64s := ir.NewLinksymExpr(base.Pos, ir.Syms.Staticuint64s, types.NewArray(types.Types[types.TUINT8], 256*8))
+ xe := ir.NewIndexExpr(base.Pos, staticuint64s, index)
xe.SetBounded(true)
value = xe
case n.X.Op() == ir.ONAME && n.X.(*ir.Name).Class == ir.PEXTERN && n.X.(*ir.Name).Readonly():
@@ -198,8 +190,7 @@ func walkBytesRunesToString(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
a := typecheck.NodNil()
if n.Esc() == ir.EscNone {
// Create temporary buffer for string on stack.
- t := types.NewArray(types.Types[types.TUINT8], tmpstringbufsize)
- a = typecheck.NodAddr(typecheck.Temp(t))
+ a = stackBufAddr(tmpstringbufsize, types.Types[types.TUINT8])
}
if n.Op() == ir.ORUNES2STR {
// slicerunetostring(*[32]byte, []rune) string
@@ -229,8 +220,7 @@ func walkBytesToStringTemp(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
func walkRuneToString(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
a := typecheck.NodNil()
if n.Esc() == ir.EscNone {
- t := types.NewArray(types.Types[types.TUINT8], 4)
- a = typecheck.NodAddr(typecheck.Temp(t))
+ a = stackBufAddr(4, types.Types[types.TUINT8])
}
// intstring(*[4]byte, rune)
return mkcall("intstring", n.Type(), init, a, typecheck.Conv(n.X, types.Types[types.TINT64]))
@@ -246,9 +236,13 @@ func walkStringToBytes(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
t := types.NewArray(types.Types[types.TUINT8], int64(len(sc)))
var a ir.Node
if n.Esc() == ir.EscNone && len(sc) <= int(ir.MaxImplicitStackVarSize) {
- a = typecheck.NodAddr(typecheck.Temp(t))
+ a = stackBufAddr(t.NumElem(), t.Elem())
} else {
- a = callnew(t)
+ types.CalcSize(t)
+ a = ir.NewUnaryExpr(base.Pos, ir.ONEW, nil)
+ a.SetType(types.NewPtr(t))
+ a.SetTypecheck(1)
+ a.MarkNonNil()
}
p := typecheck.Temp(t.PtrTo()) // *[n]byte
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, p, a)))
@@ -269,8 +263,7 @@ func walkStringToBytes(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
a := typecheck.NodNil()
if n.Esc() == ir.EscNone {
// Create temporary buffer for slice on stack.
- t := types.NewArray(types.Types[types.TUINT8], tmpstringbufsize)
- a = typecheck.NodAddr(typecheck.Temp(t))
+ a = stackBufAddr(tmpstringbufsize, types.Types[types.TUINT8])
}
// stringtoslicebyte(*32[byte], string) []byte
return mkcall("stringtoslicebyte", n.Type(), init, a, typecheck.Conv(s, types.Types[types.TSTRING]))
@@ -294,8 +287,7 @@ func walkStringToRunes(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
a := typecheck.NodNil()
if n.Esc() == ir.EscNone {
// Create temporary buffer for slice on stack.
- t := types.NewArray(types.Types[types.TINT32], tmpstringbufsize)
- a = typecheck.NodAddr(typecheck.Temp(t))
+ a = stackBufAddr(tmpstringbufsize, types.Types[types.TINT32])
}
// stringtoslicerune(*[32]rune, string) []rune
return mkcall("stringtoslicerune", n.Type(), init, a, typecheck.Conv(n.X, types.Types[types.TSTRING]))
@@ -438,8 +430,8 @@ func walkCheckPtrAlignment(n *ir.ConvExpr, init *ir.Nodes, count ir.Node) ir.Nod
}
func walkCheckPtrArithmetic(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
- // Calling cheapexpr(n, init) below leads to a recursive call to
- // walkexpr, which leads us back here again. Use n.Checkptr to
+ // Calling cheapExpr(n, init) below leads to a recursive call to
+ // walkExpr, which leads us back here again. Use n.Checkptr to
// prevent infinite loops.
if n.CheckPtr() {
return n
diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go
index 893a95f403..d7a20206c8 100644
--- a/src/cmd/compile/internal/walk/expr.go
+++ b/src/cmd/compile/internal/walk/expr.go
@@ -30,7 +30,7 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node {
// not okay to use n->ninit when walking n,
// because we might replace n with some other node
// and would lose the init list.
- base.Fatalf("walkexpr init == &n->ninit")
+ base.Fatalf("walkExpr init == &n->ninit")
}
if len(n.Init()) != 0 {
@@ -67,8 +67,6 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node {
_ = staticdata.StringSym(n.Pos(), constant.StringVal(n.Val()))
}
- updateHasCall(n)
-
if base.Flag.LowerW != 0 && n != nil {
ir.Dump("after walk expr", n)
}
@@ -81,17 +79,17 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node {
switch n.Op() {
default:
ir.Dump("walk", n)
- base.Fatalf("walkexpr: switch 1 unknown op %+v", n.Op())
+ base.Fatalf("walkExpr: switch 1 unknown op %+v", n.Op())
panic("unreachable")
- case ir.ONONAME, ir.OGETG, ir.ONEWOBJ:
+ case ir.ONONAME, ir.OGETG:
return n
- case ir.OTYPE, ir.ONAME, ir.OLITERAL, ir.ONIL, ir.ONAMEOFFSET:
+ case ir.OTYPE, ir.ONAME, ir.OLITERAL, ir.ONIL, ir.OLINKSYMOFFSET:
// TODO(mdempsky): Just return n; see discussion on CL 38655.
// Perhaps refactor to use Node.mayBeShared for these instead.
// If these return early, make sure to still call
- // stringsym for constant strings.
+ // StringSym for constant strings.
return n
case ir.OMETHEXPR:
@@ -221,7 +219,7 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node {
return walkIndexMap(n, init)
case ir.ORECV:
- base.Fatalf("walkexpr ORECV") // should see inside OAS only
+ base.Fatalf("walkExpr ORECV") // should see inside OAS only
panic("unreachable")
case ir.OSLICEHEADER:
@@ -359,7 +357,7 @@ func safeExpr(n ir.Node, init *ir.Nodes) ir.Node {
}
switch n.Op() {
- case ir.ONAME, ir.OLITERAL, ir.ONIL, ir.ONAMEOFFSET:
+ case ir.ONAME, ir.OLITERAL, ir.ONIL, ir.OLINKSYMOFFSET:
return n
case ir.OLEN, ir.OCAP:
@@ -413,7 +411,7 @@ func safeExpr(n ir.Node, init *ir.Nodes) ir.Node {
// make a copy; must not be used as an lvalue
if ir.IsAddressable(n) {
- base.Fatalf("missing lvalue case in safeexpr: %v", n)
+ base.Fatalf("missing lvalue case in safeExpr: %v", n)
}
return cheapExpr(n, init)
}
@@ -428,7 +426,7 @@ func walkAddString(n *ir.AddStringExpr, init *ir.Nodes) ir.Node {
c := len(n.List)
if c < 2 {
- base.Fatalf("addstr count %d too small", c)
+ base.Fatalf("walkAddString count %d too small", c)
}
buf := typecheck.NodNil()
@@ -443,8 +441,7 @@ func walkAddString(n *ir.AddStringExpr, init *ir.Nodes) ir.Node {
// Don't allocate the buffer if the result won't fit.
if sz < tmpstringbufsize {
// Create temporary buffer for result string on stack.
- t := types.NewArray(types.Types[types.TUINT8], tmpstringbufsize)
- buf = typecheck.NodAddr(typecheck.Temp(t))
+ buf = stackBufAddr(tmpstringbufsize, types.Types[types.TUINT8])
}
}
@@ -497,9 +494,10 @@ func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
}
func walkCall1(n *ir.CallExpr, init *ir.Nodes) {
- if len(n.Rargs) != 0 {
+ if n.Walked() {
return // already walked
}
+ n.SetWalked(true)
// If this is a method call t.M(...),
// rewrite into a function call T.M(t, ...).
@@ -523,27 +521,26 @@ func walkCall1(n *ir.CallExpr, init *ir.Nodes) {
n.X = walkExpr(n.X, init)
walkExprList(args, init)
- // For any argument whose evaluation might require a function call,
- // store that argument into a temporary variable,
- // to prevent that calls from clobbering arguments already on the stack.
- // When instrumenting, all arguments might require function calls.
- var tempAssigns []ir.Node
for i, arg := range args {
- updateHasCall(arg)
- // Determine param type.
- t := params.Field(i).Type
- if base.Flag.Cfg.Instrumenting || fncall(arg, t) {
- // make assignment of fncall to tempAt
- tmp := typecheck.Temp(t)
- a := convas(ir.NewAssignStmt(base.Pos, tmp, arg), init)
- tempAssigns = append(tempAssigns, a)
+ // Validate argument and parameter types match.
+ param := params.Field(i)
+ if !types.Identical(arg.Type(), param.Type) {
+ base.FatalfAt(n.Pos(), "assigning %L to parameter %v (type %v)", arg, param.Sym, param.Type)
+ }
+
+ // For any argument whose evaluation might require a function call,
+ // store that argument into a temporary variable,
+ // to prevent that calls from clobbering arguments already on the stack.
+ if mayCall(arg) {
+ // assignment of arg to Temp
+ tmp := typecheck.Temp(param.Type)
+ init.Append(convas(typecheck.Stmt(ir.NewAssignStmt(base.Pos, tmp, arg)).(*ir.AssignStmt), init))
// replace arg with temp
args[i] = tmp
}
}
- n.Args = tempAssigns
- n.Rargs = args
+ n.Args = args
}
// walkDivMod walks an ODIV or OMOD node.
@@ -618,11 +615,6 @@ func walkDot(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
func walkDotType(n *ir.TypeAssertExpr, init *ir.Nodes) ir.Node {
n.X = walkExpr(n.X, init)
// Set up interface type addresses for back end.
-
- n.DstType = reflectdata.TypePtr(n.Type())
- if n.Op() == ir.ODOTTYPE {
- n.SrcType = reflectdata.TypePtr(n.X.Type())
- }
if !n.Type().IsInterface() && !n.X.Type().IsEmptyInterface() {
n.Itab = reflectdata.ITabAddr(n.Type(), n.X.Type())
}
diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go
index 38a9bec6e3..fe0b6a0eff 100644
--- a/src/cmd/compile/internal/walk/order.go
+++ b/src/cmd/compile/internal/walk/order.go
@@ -555,10 +555,6 @@ func (o *orderState) mapAssign(n ir.Node) {
n.Y = o.safeMapRHS(n.Y)
}
o.out = append(o.out, n)
-
- case ir.OAS2, ir.OAS2DOTTYPE, ir.OAS2MAPR, ir.OAS2FUNC:
- n := n.(*ir.AssignListStmt)
- o.out = append(o.out, n)
}
}
@@ -637,7 +633,7 @@ func (o *orderState) stmt(n ir.Node) {
t := o.markTemp()
o.exprList(n.Lhs)
o.exprList(n.Rhs)
- o.mapAssign(n)
+ o.out = append(o.out, n)
o.cleanTemp(t)
// Special: avoid copy of func call n.Right
@@ -647,7 +643,7 @@ func (o *orderState) stmt(n ir.Node) {
o.exprList(n.Lhs)
o.init(n.Rhs[0])
o.call(n.Rhs[0])
- o.as2(n)
+ o.as2func(n)
o.cleanTemp(t)
// Special: use temporary variables to hold result,
@@ -679,7 +675,7 @@ func (o *orderState) stmt(n ir.Node) {
base.Fatalf("order.stmt: %v", r.Op())
}
- o.okAs2(n)
+ o.as2ok(n)
o.cleanTemp(t)
// Special: does not save n onto out.
@@ -696,7 +692,7 @@ func (o *orderState) stmt(n ir.Node) {
ir.OFALL,
ir.OGOTO,
ir.OLABEL,
- ir.ORETJMP:
+ ir.OTAILCALL:
o.out = append(o.out, n)
// Special: handle call arguments.
@@ -772,14 +768,12 @@ func (o *orderState) stmt(n ir.Node) {
orderBlock(&n.Else, o.free)
o.out = append(o.out, n)
- // Special: argument will be converted to interface using convT2E
- // so make sure it is an addressable temporary.
case ir.OPANIC:
n := n.(*ir.UnaryExpr)
t := o.markTemp()
n.X = o.expr(n.X, nil)
- if !n.X.Type().IsInterface() {
- n.X = o.addrTemp(n.X)
+ if !n.X.Type().IsEmptyInterface() {
+ base.FatalfAt(n.Pos(), "bad argument to panic: %L", n.X)
}
o.out = append(o.out, n)
o.cleanTemp(t)
@@ -849,7 +843,7 @@ func (o *orderState) stmt(n ir.Node) {
n.X = o.copyExpr(r)
// n.Prealloc is the temp for the iterator.
- // hiter contains pointers and needs to be zeroed.
+ // MapIterType contains pointers and needs to be zeroed.
n.Prealloc = o.newTemp(reflectdata.MapIterType(xt), true)
}
n.Key = o.exprInPlace(n.Key)
@@ -962,7 +956,7 @@ func (o *orderState) stmt(n ir.Node) {
cas.Body.Prepend(o.cleanTempNoPop(t)...)
// TODO(mdempsky): Is this actually necessary?
- // walkselect appears to walk Ninit.
+ // walkSelect appears to walk Ninit.
cas.Body.Prepend(ir.TakeInit(cas)...)
}
@@ -986,7 +980,7 @@ func (o *orderState) stmt(n ir.Node) {
o.cleanTemp(t)
// TODO(rsc): Clean temporaries more aggressively.
- // Note that because walkswitch will rewrite some of the
+ // Note that because walkSwitch will rewrite some of the
// switch into a binary search, this is not as easy as it looks.
// (If we ran that code here we could invoke order.stmt on
// the if-else chain instead.)
@@ -1390,57 +1384,54 @@ func (o *orderState) expr1(n, lhs ir.Node) ir.Node {
// No return - type-assertions above. Each case must return for itself.
}
-// as2 orders OAS2XXXX nodes. It creates temporaries to ensure left-to-right assignment.
-// The caller should order the right-hand side of the assignment before calling order.as2.
+// as2func orders OAS2FUNC nodes. It creates temporaries to ensure left-to-right assignment.
+// The caller should order the right-hand side of the assignment before calling order.as2func.
// It rewrites,
-// a, b, a = ...
+// a, b, a = ...
// as
// tmp1, tmp2, tmp3 = ...
-// a, b, a = tmp1, tmp2, tmp3
+// a, b, a = tmp1, tmp2, tmp3
// This is necessary to ensure left to right assignment order.
-func (o *orderState) as2(n *ir.AssignListStmt) {
- tmplist := []ir.Node{}
- left := []ir.Node{}
- for ni, l := range n.Lhs {
- if !ir.IsBlank(l) {
- tmp := o.newTemp(l.Type(), l.Type().HasPointers())
- n.Lhs[ni] = tmp
- tmplist = append(tmplist, tmp)
- left = append(left, l)
+func (o *orderState) as2func(n *ir.AssignListStmt) {
+ results := n.Rhs[0].Type()
+ as := ir.NewAssignListStmt(n.Pos(), ir.OAS2, nil, nil)
+ for i, nl := range n.Lhs {
+ if !ir.IsBlank(nl) {
+ typ := results.Field(i).Type
+ tmp := o.newTemp(typ, typ.HasPointers())
+ n.Lhs[i] = tmp
+ as.Lhs = append(as.Lhs, nl)
+ as.Rhs = append(as.Rhs, tmp)
}
}
o.out = append(o.out, n)
-
- as := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
- as.Lhs = left
- as.Rhs = tmplist
o.stmt(typecheck.Stmt(as))
}
-// okAs2 orders OAS2XXX with ok.
-// Just like as2, this also adds temporaries to ensure left-to-right assignment.
-func (o *orderState) okAs2(n *ir.AssignListStmt) {
- var tmp1, tmp2 ir.Node
- if !ir.IsBlank(n.Lhs[0]) {
- typ := n.Rhs[0].Type()
- tmp1 = o.newTemp(typ, typ.HasPointers())
+// as2ok orders OAS2XXX with ok.
+// Just like as2func, this also adds temporaries to ensure left-to-right assignment.
+func (o *orderState) as2ok(n *ir.AssignListStmt) {
+ as := ir.NewAssignListStmt(n.Pos(), ir.OAS2, nil, nil)
+
+ do := func(i int, typ *types.Type) {
+ if nl := n.Lhs[i]; !ir.IsBlank(nl) {
+ var tmp ir.Node = o.newTemp(typ, typ.HasPointers())
+ n.Lhs[i] = tmp
+ as.Lhs = append(as.Lhs, nl)
+ if i == 1 {
+ // The "ok" result is an untyped boolean according to the Go
+ // spec. We need to explicitly convert it to the LHS type in
+ // case the latter is a defined boolean type (#8475).
+ tmp = typecheck.Conv(tmp, nl.Type())
+ }
+ as.Rhs = append(as.Rhs, tmp)
+ }
}
- if !ir.IsBlank(n.Lhs[1]) {
- tmp2 = o.newTemp(types.Types[types.TBOOL], false)
- }
+ do(0, n.Rhs[0].Type())
+ do(1, types.Types[types.TBOOL])
o.out = append(o.out, n)
-
- if tmp1 != nil {
- r := ir.NewAssignStmt(base.Pos, n.Lhs[0], tmp1)
- o.mapAssign(typecheck.Stmt(r))
- n.Lhs[0] = tmp1
- }
- if tmp2 != nil {
- r := ir.NewAssignStmt(base.Pos, n.Lhs[1], typecheck.Conv(tmp2, n.Lhs[1].Type()))
- o.mapAssign(typecheck.Stmt(r))
- n.Lhs[1] = tmp2
- }
+ o.stmt(typecheck.Stmt(as))
}
diff --git a/src/cmd/compile/internal/walk/race.go b/src/cmd/compile/internal/walk/race.go
index 77cabe50c6..47cd2fdc22 100644
--- a/src/cmd/compile/internal/walk/race.go
+++ b/src/cmd/compile/internal/walk/race.go
@@ -26,10 +26,9 @@ func instrument(fn *ir.Func) {
if base.Flag.Race {
lno := base.Pos
base.Pos = src.NoXPos
-
if ssagen.Arch.LinkArch.Arch.Family != sys.AMD64 {
- fn.Enter.Prepend(mkcall("racefuncenterfp", nil, nil))
- fn.Exit.Append(mkcall("racefuncexit", nil, nil))
+ fn.Enter.Prepend(mkcallstmt("racefuncenterfp"))
+ fn.Exit.Append(mkcallstmt("racefuncexit"))
} else {
// nodpc is the PC of the caller as extracted by
@@ -44,8 +43,8 @@ func instrument(fn *ir.Func) {
nodpc.SetType(types.Types[types.TUINTPTR])
nodpc.SetFrameOffset(int64(-types.PtrSize))
fn.Dcl = append(fn.Dcl, nodpc)
- fn.Enter.Prepend(mkcall("racefuncenter", nil, nil, nodpc))
- fn.Exit.Append(mkcall("racefuncexit", nil, nil))
+ fn.Enter.Prepend(mkcallstmt("racefuncenter", nodpc))
+ fn.Exit.Append(mkcallstmt("racefuncexit"))
}
base.Pos = lno
}
diff --git a/src/cmd/compile/internal/walk/range.go b/src/cmd/compile/internal/walk/range.go
index 9225c429f0..5ab24b2188 100644
--- a/src/cmd/compile/internal/walk/range.go
+++ b/src/cmd/compile/internal/walk/range.go
@@ -71,7 +71,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
}
if v1 == nil && v2 != nil {
- base.Fatalf("walkrange: v2 != nil while v1 == nil")
+ base.Fatalf("walkRange: v2 != nil while v1 == nil")
}
var ifGuard *ir.IfStmt
@@ -80,7 +80,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
var init []ir.Node
switch t.Kind() {
default:
- base.Fatalf("walkrange")
+ base.Fatalf("walkRange")
case types.TARRAY, types.TSLICE:
if nn := arrayClear(nrange, v1, v2, a); nn != nil {
@@ -168,18 +168,18 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
hit := nrange.Prealloc
th := hit.Type()
- keysym := th.Field(0).Sym // depends on layout of iterator struct. See reflect.go:hiter
+ keysym := th.Field(0).Sym // depends on layout of iterator struct. See reflect.go:MapIterType
elemsym := th.Field(1).Sym // ditto
fn := typecheck.LookupRuntime("mapiterinit")
fn = typecheck.SubstArgTypes(fn, t.Key(), t.Elem(), th)
- init = append(init, mkcall1(fn, nil, nil, reflectdata.TypePtr(t), ha, typecheck.NodAddr(hit)))
+ init = append(init, mkcallstmt1(fn, reflectdata.TypePtr(t), ha, typecheck.NodAddr(hit)))
nfor.Cond = ir.NewBinaryExpr(base.Pos, ir.ONE, ir.NewSelectorExpr(base.Pos, ir.ODOT, hit, keysym), typecheck.NodNil())
fn = typecheck.LookupRuntime("mapiternext")
fn = typecheck.SubstArgTypes(fn, th)
- nfor.Post = mkcall1(fn, nil, nil, typecheck.NodAddr(hit))
+ nfor.Post = mkcallstmt1(fn, typecheck.NodAddr(hit))
key := ir.NewStarExpr(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, hit, keysym))
if v1 == nil {
@@ -269,12 +269,14 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
// } else {
eif := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
- nif.Else = []ir.Node{eif}
// hv2, hv1 = decoderune(ha, hv1)
eif.Lhs = []ir.Node{hv2, hv1}
fn := typecheck.LookupRuntime("decoderune")
- eif.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), nil, ha, hv1)}
+ var fnInit ir.Nodes
+ eif.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), &fnInit, ha, hv1)}
+ fnInit.Append(eif)
+ nif.Else = fnInit
body = append(body, nif)
@@ -374,7 +376,7 @@ func mapClear(m ir.Node) ir.Node {
// instantiate mapclear(typ *type, hmap map[any]any)
fn := typecheck.LookupRuntime("mapclear")
fn = typecheck.SubstArgTypes(fn, t.Key(), t.Elem())
- n := mkcall1(fn, nil, nil, reflectdata.TypePtr(t), m)
+ n := mkcallstmt1(fn, reflectdata.TypePtr(t), m)
return walkStmt(typecheck.Stmt(n))
}
@@ -388,7 +390,7 @@ func mapClear(m ir.Node) ir.Node {
//
// in which the evaluation of a is side-effect-free.
//
-// Parameters are as in walkrange: "for v1, v2 = range a".
+// Parameters are as in walkRange: "for v1, v2 = range a".
func arrayClear(loop *ir.RangeStmt, v1, v2, a ir.Node) ir.Node {
if base.Flag.N != 0 || base.Flag.Cfg.Instrumenting {
return nil
@@ -449,10 +451,10 @@ func arrayClear(loop *ir.RangeStmt, v1, v2, a ir.Node) ir.Node {
if a.Type().Elem().HasPointers() {
// memclrHasPointers(hp, hn)
ir.CurFunc.SetWBPos(stmt.Pos())
- fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
+ fn = mkcallstmt("memclrHasPointers", hp, hn)
} else {
// memclrNoHeapPointers(hp, hn)
- fn = mkcall("memclrNoHeapPointers", nil, nil, hp, hn)
+ fn = mkcallstmt("memclrNoHeapPointers", hp, hn)
}
n.Body.Append(fn)
diff --git a/src/cmd/compile/internal/walk/select.go b/src/cmd/compile/internal/walk/select.go
index 776b020155..873be289dc 100644
--- a/src/cmd/compile/internal/walk/select.go
+++ b/src/cmd/compile/internal/walk/select.go
@@ -13,9 +13,10 @@ import (
func walkSelect(sel *ir.SelectStmt) {
lno := ir.SetPos(sel)
- if len(sel.Compiled) != 0 {
- base.Fatalf("double walkselect")
+ if sel.Walked() {
+ base.Fatalf("double walkSelect")
}
+ sel.SetWalked(true)
init := ir.TakeInit(sel)
@@ -34,7 +35,7 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node {
// optimization: zero-case select
if ncas == 0 {
- return []ir.Node{mkcall("block", nil, nil)}
+ return []ir.Node{mkcallstmt("block")}
}
// optimization: one-case select: single op.
@@ -213,12 +214,12 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node {
// TODO(mdempsky): There should be a cleaner way to
// handle this.
if base.Flag.Race {
- r := mkcall("selectsetpc", nil, nil, typecheck.NodAddr(ir.NewIndexExpr(base.Pos, pcs, ir.NewInt(int64(i)))))
+ r := mkcallstmt("selectsetpc", typecheck.NodAddr(ir.NewIndexExpr(base.Pos, pcs, ir.NewInt(int64(i)))))
init = append(init, r)
}
}
if nsends+nrecvs != ncas {
- base.Fatalf("walkselectcases: miscount: %v + %v != %v", nsends, nrecvs, ncas)
+ base.Fatalf("walkSelectCases: miscount: %v + %v != %v", nsends, nrecvs, ncas)
}
// run the select
@@ -228,7 +229,9 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node {
r := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
r.Lhs = []ir.Node{chosen, recvOK}
fn := typecheck.LookupRuntime("selectgo")
- r.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), nil, bytePtrToIndex(selv, 0), bytePtrToIndex(order, 0), pc0, ir.NewInt(int64(nsends)), ir.NewInt(int64(nrecvs)), ir.NewBool(dflt == nil))}
+ var fnInit ir.Nodes
+ r.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), &fnInit, bytePtrToIndex(selv, 0), bytePtrToIndex(order, 0), pc0, ir.NewInt(int64(nsends)), ir.NewInt(int64(nrecvs)), ir.NewBool(dflt == nil))}
+ init = append(init, fnInit...)
init = append(init, typecheck.Stmt(r))
// selv and order are no longer alive after selectgo.
diff --git a/src/cmd/compile/internal/walk/stmt.go b/src/cmd/compile/internal/walk/stmt.go
index 1df491bd4e..46a621c2ba 100644
--- a/src/cmd/compile/internal/walk/stmt.go
+++ b/src/cmd/compile/internal/walk/stmt.go
@@ -86,6 +86,7 @@ func walkStmt(n ir.Node) ir.Node {
ir.OFALL,
ir.OGOTO,
ir.OLABEL,
+ ir.ODCL,
ir.ODCLCONST,
ir.ODCLTYPE,
ir.OCHECKNIL,
@@ -94,10 +95,6 @@ func walkStmt(n ir.Node) ir.Node {
ir.OVARLIVE:
return n
- case ir.ODCL:
- n := n.(*ir.Decl)
- return walkDecl(n)
-
case ir.OBLOCK:
n := n.(*ir.BlockStmt)
walkStmtList(n.List)
@@ -139,8 +136,8 @@ func walkStmt(n ir.Node) ir.Node {
n := n.(*ir.ReturnStmt)
return walkReturn(n)
- case ir.ORETJMP:
- n := n.(*ir.BranchStmt)
+ case ir.OTAILCALL:
+ n := n.(*ir.TailCallStmt)
return n
case ir.OINLMARK:
@@ -173,20 +170,6 @@ func walkStmtList(s []ir.Node) {
}
}
-// walkDecl walks an ODCL node.
-func walkDecl(n *ir.Decl) ir.Node {
- v := n.X
- if v.Class == ir.PAUTOHEAP {
- if base.Flag.CompilingRuntime {
- base.Errorf("%v escapes to heap, not allowed in runtime", v)
- }
- nn := ir.NewAssignStmt(base.Pos, v.Heapaddr, callnew(v.Type()))
- nn.Def = true
- return walkStmt(typecheck.Stmt(nn))
- }
- return n
-}
-
// walkFor walks an OFOR or OFORUNTIL node.
func walkFor(n *ir.ForStmt) ir.Node {
if n.Cond != nil {
diff --git a/src/cmd/compile/internal/walk/switch.go b/src/cmd/compile/internal/walk/switch.go
index 59446ef3db..162de018f6 100644
--- a/src/cmd/compile/internal/walk/switch.go
+++ b/src/cmd/compile/internal/walk/switch.go
@@ -19,9 +19,10 @@ import (
// walkSwitch walks a switch statement.
func walkSwitch(sw *ir.SwitchStmt) {
// Guard against double walk, see #25776.
- if len(sw.Cases) == 0 && len(sw.Compiled) > 0 {
+ if sw.Walked() {
return // Was fatal, but eliminating every possible source of double-walking is hard
}
+ sw.SetWalked(true)
if sw.Tag != nil && sw.Tag.Op() == ir.OTYPESW {
walkSwitchType(sw)
@@ -48,8 +49,8 @@ func walkSwitchExpr(sw *ir.SwitchStmt) {
// Given "switch string(byteslice)",
// with all cases being side-effect free,
// use a zero-cost alias of the byte slice.
- // Do this before calling walkexpr on cond,
- // because walkexpr will lower the string
+ // Do this before calling walkExpr on cond,
+ // because walkExpr will lower the string
// conversion into a runtime call.
// See issue 24937 for more discussion.
if cond.Op() == ir.OBYTES2STR && allCaseExprsAreSideEffectFree(sw) {
diff --git a/src/cmd/compile/internal/walk/temp.go b/src/cmd/compile/internal/walk/temp.go
new file mode 100644
index 0000000000..9879a6c69d
--- /dev/null
+++ b/src/cmd/compile/internal/walk/temp.go
@@ -0,0 +1,40 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package walk
+
+import (
+ "cmd/compile/internal/base"
+ "cmd/compile/internal/ir"
+ "cmd/compile/internal/typecheck"
+ "cmd/compile/internal/types"
+)
+
+// initStackTemp appends statements to init to initialize the given
+// temporary variable to val, and then returns the expression &tmp.
+func initStackTemp(init *ir.Nodes, tmp *ir.Name, val ir.Node) *ir.AddrExpr {
+ if val != nil && !types.Identical(tmp.Type(), val.Type()) {
+ base.Fatalf("bad initial value for %L: %L", tmp, val)
+ }
+ appendWalkStmt(init, ir.NewAssignStmt(base.Pos, tmp, val))
+ return typecheck.Expr(typecheck.NodAddr(tmp)).(*ir.AddrExpr)
+}
+
+// stackTempAddr returns the expression &tmp, where tmp is a newly
+// allocated temporary variable of the given type. Statements to
+// zero-initialize tmp are appended to init.
+func stackTempAddr(init *ir.Nodes, typ *types.Type) *ir.AddrExpr {
+ return initStackTemp(init, typecheck.Temp(typ), nil)
+}
+
+// stackBufAddr returns thte expression &tmp, where tmp is a newly
+// allocated temporary variable of type [len]elem. This variable is
+// initialized, and elem must not contain pointers.
+func stackBufAddr(len int64, elem *types.Type) *ir.AddrExpr {
+ if elem.HasPointers() {
+ base.FatalfAt(base.Pos, "%v has pointers", elem)
+ }
+ tmp := typecheck.Temp(types.NewArray(elem, len))
+ return typecheck.Expr(typecheck.NodAddr(tmp)).(*ir.AddrExpr)
+}
diff --git a/src/cmd/compile/internal/walk/walk.go b/src/cmd/compile/internal/walk/walk.go
index 4271772fb7..b47d96dc4c 100644
--- a/src/cmd/compile/internal/walk/walk.go
+++ b/src/cmd/compile/internal/walk/walk.go
@@ -7,7 +7,6 @@ package walk
import (
"errors"
"fmt"
- "strings"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
@@ -47,13 +46,6 @@ func Walk(fn *ir.Func) {
ir.DumpList(s, ir.CurFunc.Body)
}
- zeroResults()
- heapmoves()
- if base.Flag.W != 0 && len(ir.CurFunc.Enter) > 0 {
- s := fmt.Sprintf("enter %v", ir.CurFunc.Sym())
- ir.DumpList(s, ir.CurFunc.Enter)
- }
-
if base.Flag.Cfg.Instrumenting {
instrument(fn)
}
@@ -64,23 +56,6 @@ func Walk(fn *ir.Func) {
}
}
-func paramoutheap(fn *ir.Func) bool {
- for _, ln := range fn.Dcl {
- switch ln.Class {
- case ir.PPARAMOUT:
- if ir.IsParamStackCopy(ln) || ln.Addrtaken() {
- return true
- }
-
- case ir.PAUTO:
- // stop early - parameters are over
- return false
- }
- }
-
- return false
-}
-
// walkRecv walks an ORECV node.
func walkRecv(n *ir.UnaryExpr) ir.Node {
if n.Typecheck() == 0 {
@@ -97,8 +72,6 @@ func convas(n *ir.AssignStmt, init *ir.Nodes) *ir.AssignStmt {
if n.Op() != ir.OAS {
base.Fatalf("convas: not OAS %v", n.Op())
}
- defer updateHasCall(n)
-
n.SetTypecheck(1)
if n.X == nil || n.Y == nil {
@@ -127,93 +100,10 @@ func convas(n *ir.AssignStmt, init *ir.Nodes) *ir.AssignStmt {
var stop = errors.New("stop")
-// paramstoheap returns code to allocate memory for heap-escaped parameters
-// and to copy non-result parameters' values from the stack.
-func paramstoheap(params *types.Type) []ir.Node {
- var nn []ir.Node
- for _, t := range params.Fields().Slice() {
- v := ir.AsNode(t.Nname)
- if v != nil && v.Sym() != nil && strings.HasPrefix(v.Sym().Name, "~r") { // unnamed result
- v = nil
- }
- if v == nil {
- continue
- }
-
- if stackcopy := v.Name().Stackcopy; stackcopy != nil {
- nn = append(nn, walkStmt(ir.NewDecl(base.Pos, ir.ODCL, v.(*ir.Name))))
- if stackcopy.Class == ir.PPARAM {
- nn = append(nn, walkStmt(typecheck.Stmt(ir.NewAssignStmt(base.Pos, v, stackcopy))))
- }
- }
- }
-
- return nn
-}
-
-// zeroResults zeros the return values at the start of the function.
-// We need to do this very early in the function. Defer might stop a
-// panic and show the return values as they exist at the time of
-// panic. For precise stacks, the garbage collector assumes results
-// are always live, so we need to zero them before any allocations,
-// even allocations to move params/results to the heap.
-// The generated code is added to Curfn's Enter list.
-func zeroResults() {
- for _, f := range ir.CurFunc.Type().Results().Fields().Slice() {
- v := ir.AsNode(f.Nname)
- if v != nil && v.Name().Heapaddr != nil {
- // The local which points to the return value is the
- // thing that needs zeroing. This is already handled
- // by a Needzero annotation in plive.go:livenessepilogue.
- continue
- }
- if ir.IsParamHeapCopy(v) {
- // TODO(josharian/khr): Investigate whether we can switch to "continue" here,
- // and document more in either case.
- // In the review of CL 114797, Keith wrote (roughly):
- // I don't think the zeroing below matters.
- // The stack return value will never be marked as live anywhere in the function.
- // It is not written to until deferreturn returns.
- v = v.Name().Stackcopy
- }
- // Zero the stack location containing f.
- ir.CurFunc.Enter.Append(ir.NewAssignStmt(ir.CurFunc.Pos(), v, nil))
- }
-}
-
-// returnsfromheap returns code to copy values for heap-escaped parameters
-// back to the stack.
-func returnsfromheap(params *types.Type) []ir.Node {
- var nn []ir.Node
- for _, t := range params.Fields().Slice() {
- v := ir.AsNode(t.Nname)
- if v == nil {
- continue
- }
- if stackcopy := v.Name().Stackcopy; stackcopy != nil && stackcopy.Class == ir.PPARAMOUT {
- nn = append(nn, walkStmt(typecheck.Stmt(ir.NewAssignStmt(base.Pos, stackcopy, v))))
- }
- }
-
- return nn
-}
-
-// heapmoves generates code to handle migrating heap-escaped parameters
-// between the stack and the heap. The generated code is added to Curfn's
-// Enter and Exit lists.
-func heapmoves() {
- lno := base.Pos
- base.Pos = ir.CurFunc.Pos()
- nn := paramstoheap(ir.CurFunc.Type().Recvs())
- nn = append(nn, paramstoheap(ir.CurFunc.Type().Params())...)
- nn = append(nn, paramstoheap(ir.CurFunc.Type().Results())...)
- ir.CurFunc.Enter.Append(nn...)
- base.Pos = ir.CurFunc.Endlineno
- ir.CurFunc.Exit.Append(returnsfromheap(ir.CurFunc.Type().Results())...)
- base.Pos = lno
-}
-
func vmkcall(fn ir.Node, t *types.Type, init *ir.Nodes, va []ir.Node) *ir.CallExpr {
+ if init == nil {
+ base.Fatalf("mkcall with nil init: %v", fn)
+ }
if fn.Type() == nil || fn.Type().Kind() != types.TFUNC {
base.Fatalf("mkcall %v %v", fn, fn.Type())
}
@@ -233,10 +123,24 @@ func mkcall(name string, t *types.Type, init *ir.Nodes, args ...ir.Node) *ir.Cal
return vmkcall(typecheck.LookupRuntime(name), t, init, args)
}
+func mkcallstmt(name string, args ...ir.Node) ir.Node {
+ return mkcallstmt1(typecheck.LookupRuntime(name), args...)
+}
+
func mkcall1(fn ir.Node, t *types.Type, init *ir.Nodes, args ...ir.Node) *ir.CallExpr {
return vmkcall(fn, t, init, args)
}
+func mkcallstmt1(fn ir.Node, args ...ir.Node) ir.Node {
+ var init ir.Nodes
+ n := vmkcall(fn, nil, &init, args)
+ if len(init) == 0 {
+ return n
+ }
+ init.Append(n)
+ return ir.NewBlockStmt(n.Pos(), init)
+}
+
func chanfn(name string, n int, t *types.Type) ir.Node {
if !t.IsChan() {
base.Fatalf("chanfn %v", t)
@@ -324,7 +228,7 @@ func mapfast(t *types.Type) int {
func walkAppendArgs(n *ir.CallExpr, init *ir.Nodes) {
walkExprListSafe(n.Args, init)
- // walkexprlistsafe will leave OINDEX (s[n]) alone if both s
+ // walkExprListSafe will leave OINDEX (s[n]) alone if both s
// and n are name or literal, but those may index the slice we're
// modifying here. Fix explicitly.
ls := n.Args
@@ -356,8 +260,8 @@ func appendWalkStmt(init *ir.Nodes, stmt ir.Node) {
op := stmt.Op()
n := typecheck.Stmt(stmt)
if op == ir.OAS || op == ir.OAS2 {
- // If the assignment has side effects, walkexpr will append them
- // directly to init for us, while walkstmt will wrap it in an OBLOCK.
+ // If the assignment has side effects, walkExpr will append them
+ // directly to init for us, while walkStmt will wrap it in an OBLOCK.
// We need to append them directly.
// TODO(rsc): Clean this up.
n = walkExpr(n, init)
@@ -372,7 +276,7 @@ func appendWalkStmt(init *ir.Nodes, stmt ir.Node) {
const maxOpenDefers = 8
// backingArrayPtrLen extracts the pointer and length from a slice or string.
-// This constructs two nodes referring to n, so n must be a cheapexpr.
+// This constructs two nodes referring to n, so n must be a cheapExpr.
func backingArrayPtrLen(n ir.Node) (ptr, length ir.Node) {
var init ir.Nodes
c := cheapExpr(n, &init)
@@ -390,123 +294,71 @@ func backingArrayPtrLen(n ir.Node) (ptr, length ir.Node) {
return ptr, length
}
-// updateHasCall checks whether expression n contains any function
-// calls and sets the n.HasCall flag if so.
-func updateHasCall(n ir.Node) {
- if n == nil {
- return
- }
- n.SetHasCall(calcHasCall(n))
-}
-
-func calcHasCall(n ir.Node) bool {
- if len(n.Init()) != 0 {
- // TODO(mdempsky): This seems overly conservative.
+// mayCall reports whether evaluating expression n may require
+// function calls, which could clobber function call arguments/results
+// currently on the stack.
+func mayCall(n ir.Node) bool {
+ // When instrumenting, any expression might require function calls.
+ if base.Flag.Cfg.Instrumenting {
return true
}
- switch n.Op() {
- default:
- base.Fatalf("calcHasCall %+v", n)
- panic("unreachable")
+ isSoftFloat := func(typ *types.Type) bool {
+ return types.IsFloat[typ.Kind()] || types.IsComplex[typ.Kind()]
+ }
- case ir.OLITERAL, ir.ONIL, ir.ONAME, ir.OTYPE, ir.ONAMEOFFSET:
- if n.HasCall() {
- base.Fatalf("OLITERAL/ONAME/OTYPE should never have calls: %+v", n)
- }
- return false
- case ir.OCALL, ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER:
- return true
- case ir.OANDAND, ir.OOROR:
- // hard with instrumented code
- n := n.(*ir.LogicalExpr)
- if base.Flag.Cfg.Instrumenting {
- return true
+ return ir.Any(n, func(n ir.Node) bool {
+ // walk should have already moved any Init blocks off of
+ // expressions.
+ if len(n.Init()) != 0 {
+ base.FatalfAt(n.Pos(), "mayCall %+v", n)
}
- return n.X.HasCall() || n.Y.HasCall()
- case ir.OINDEX, ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR, ir.OSLICESTR,
- ir.ODEREF, ir.ODOTPTR, ir.ODOTTYPE, ir.ODIV, ir.OMOD:
- // These ops might panic, make sure they are done
- // before we start marshaling args for a call. See issue 16760.
- return true
- // When using soft-float, these ops might be rewritten to function calls
- // so we ensure they are evaluated first.
- case ir.OADD, ir.OSUB, ir.OMUL:
- n := n.(*ir.BinaryExpr)
- if ssagen.Arch.SoftFloat && (types.IsFloat[n.Type().Kind()] || types.IsComplex[n.Type().Kind()]) {
- return true
- }
- return n.X.HasCall() || n.Y.HasCall()
- case ir.ONEG:
- n := n.(*ir.UnaryExpr)
- if ssagen.Arch.SoftFloat && (types.IsFloat[n.Type().Kind()] || types.IsComplex[n.Type().Kind()]) {
- return true
- }
- return n.X.HasCall()
- case ir.OLT, ir.OEQ, ir.ONE, ir.OLE, ir.OGE, ir.OGT:
- n := n.(*ir.BinaryExpr)
- if ssagen.Arch.SoftFloat && (types.IsFloat[n.X.Type().Kind()] || types.IsComplex[n.X.Type().Kind()]) {
+ switch n.Op() {
+ default:
+ base.FatalfAt(n.Pos(), "mayCall %+v", n)
+
+ case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER:
return true
- }
- return n.X.HasCall() || n.Y.HasCall()
- case ir.OCONV:
- n := n.(*ir.ConvExpr)
- if ssagen.Arch.SoftFloat && ((types.IsFloat[n.Type().Kind()] || types.IsComplex[n.Type().Kind()]) || (types.IsFloat[n.X.Type().Kind()] || types.IsComplex[n.X.Type().Kind()])) {
+
+ case ir.OINDEX, ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR, ir.OSLICESTR,
+ ir.ODEREF, ir.ODOTPTR, ir.ODOTTYPE, ir.ODIV, ir.OMOD:
+ // These ops might panic, make sure they are done
+ // before we start marshaling args for a call. See issue 16760.
return true
+
+ case ir.OANDAND, ir.OOROR:
+ n := n.(*ir.LogicalExpr)
+ // The RHS expression may have init statements that
+ // should only execute conditionally, and so cannot be
+ // pulled out to the top-level init list. We could try
+ // to be more precise here.
+ return len(n.Y.Init()) != 0
+
+ // When using soft-float, these ops might be rewritten to function calls
+ // so we ensure they are evaluated first.
+ case ir.OADD, ir.OSUB, ir.OMUL, ir.ONEG:
+ return ssagen.Arch.SoftFloat && isSoftFloat(n.Type())
+ case ir.OLT, ir.OEQ, ir.ONE, ir.OLE, ir.OGE, ir.OGT:
+ n := n.(*ir.BinaryExpr)
+ return ssagen.Arch.SoftFloat && isSoftFloat(n.X.Type())
+ case ir.OCONV:
+ n := n.(*ir.ConvExpr)
+ return ssagen.Arch.SoftFloat && (isSoftFloat(n.Type()) || isSoftFloat(n.X.Type()))
+
+ case ir.OLITERAL, ir.ONIL, ir.ONAME, ir.OLINKSYMOFFSET, ir.OMETHEXPR,
+ ir.OAND, ir.OANDNOT, ir.OLSH, ir.OOR, ir.ORSH, ir.OXOR, ir.OCOMPLEX, ir.OEFACE,
+ ir.OADDR, ir.OBITNOT, ir.ONOT, ir.OPLUS,
+ ir.OCAP, ir.OIMAG, ir.OLEN, ir.OREAL,
+ ir.OCONVNOP, ir.ODOT,
+ ir.OCFUNC, ir.OIDATA, ir.OITAB, ir.OSPTR,
+ ir.OBYTES2STRTMP, ir.OGETG, ir.OSLICEHEADER:
+ // ok: operations that don't require function calls.
+ // Expand as needed.
}
- return n.X.HasCall()
-
- case ir.OAND, ir.OANDNOT, ir.OLSH, ir.OOR, ir.ORSH, ir.OXOR, ir.OCOPY, ir.OCOMPLEX, ir.OEFACE:
- n := n.(*ir.BinaryExpr)
- return n.X.HasCall() || n.Y.HasCall()
-
- case ir.OAS:
- n := n.(*ir.AssignStmt)
- return n.X.HasCall() || n.Y != nil && n.Y.HasCall()
-
- case ir.OADDR:
- n := n.(*ir.AddrExpr)
- return n.X.HasCall()
- case ir.OPAREN:
- n := n.(*ir.ParenExpr)
- return n.X.HasCall()
- case ir.OBITNOT, ir.ONOT, ir.OPLUS, ir.ORECV,
- ir.OALIGNOF, ir.OCAP, ir.OCLOSE, ir.OIMAG, ir.OLEN, ir.ONEW,
- ir.OOFFSETOF, ir.OPANIC, ir.OREAL, ir.OSIZEOF,
- ir.OCHECKNIL, ir.OCFUNC, ir.OIDATA, ir.OITAB, ir.ONEWOBJ, ir.OSPTR, ir.OVARDEF, ir.OVARKILL, ir.OVARLIVE:
- n := n.(*ir.UnaryExpr)
- return n.X.HasCall()
- case ir.ODOT, ir.ODOTMETH, ir.ODOTINTER:
- n := n.(*ir.SelectorExpr)
- return n.X.HasCall()
-
- case ir.OGETG, ir.OMETHEXPR:
- return false
- // TODO(rsc): These look wrong in various ways but are what calcHasCall has always done.
- case ir.OADDSTR:
- // TODO(rsc): This used to check left and right, which are not part of OADDSTR.
- return false
- case ir.OBLOCK:
- // TODO(rsc): Surely the block's statements matter.
return false
- case ir.OCONVIFACE, ir.OCONVNOP, ir.OBYTES2STR, ir.OBYTES2STRTMP, ir.ORUNES2STR, ir.OSTR2BYTES, ir.OSTR2BYTESTMP, ir.OSTR2RUNES, ir.ORUNESTR:
- // TODO(rsc): Some conversions are themselves calls, no?
- n := n.(*ir.ConvExpr)
- return n.X.HasCall()
- case ir.ODOTTYPE2:
- // TODO(rsc): Shouldn't this be up with ODOTTYPE above?
- n := n.(*ir.TypeAssertExpr)
- return n.X.HasCall()
- case ir.OSLICEHEADER:
- // TODO(rsc): What about len and cap?
- n := n.(*ir.SliceHeaderExpr)
- return n.Ptr.HasCall()
- case ir.OAS2DOTTYPE, ir.OAS2FUNC:
- // TODO(rsc): Surely we need to check List and Rlist.
- return false
- }
+ })
}
// itabType loads the _type field from a runtime.itab struct.
@@ -539,7 +391,7 @@ func runtimeField(name string, offset int64, typ *types.Type) *types.Field {
// ifaceData loads the data field from an interface.
// The concrete type must be known to have type t.
-// It follows the pointer if !isdirectiface(t).
+// It follows the pointer if !IsDirectIface(t).
func ifaceData(pos src.XPos, n ir.Node, t *types.Type) ir.Node {
if t.IsInterface() {
base.Fatalf("ifaceData interface: %v", t)
diff --git a/src/cmd/cover/func.go b/src/cmd/cover/func.go
index 988c4caebf..ce7c771ac9 100644
--- a/src/cmd/cover/func.go
+++ b/src/cmd/cover/func.go
@@ -15,9 +15,9 @@ import (
"go/ast"
"go/parser"
"go/token"
+ exec "internal/execabs"
"io"
"os"
- "os/exec"
"path"
"path/filepath"
"runtime"
diff --git a/src/cmd/cover/testdata/toolexec.go b/src/cmd/cover/testdata/toolexec.go
index 1769efedbe..386de79038 100644
--- a/src/cmd/cover/testdata/toolexec.go
+++ b/src/cmd/cover/testdata/toolexec.go
@@ -16,7 +16,7 @@ package main
import (
"os"
- "os/exec"
+ exec "internal/execabs"
"strings"
)
diff --git a/src/cmd/dist/buildtool.go b/src/cmd/dist/buildtool.go
index eb8729149c..7520b0ef18 100644
--- a/src/cmd/dist/buildtool.go
+++ b/src/cmd/dist/buildtool.go
@@ -285,8 +285,10 @@ func bootstrapFixImports(srcFile string) string {
continue
}
if strings.HasPrefix(line, `import "`) || strings.HasPrefix(line, `import . "`) ||
- inBlock && (strings.HasPrefix(line, "\t\"") || strings.HasPrefix(line, "\t. \"")) {
+ inBlock && (strings.HasPrefix(line, "\t\"") || strings.HasPrefix(line, "\t. \"") || strings.HasPrefix(line, "\texec \"")) {
line = strings.Replace(line, `"cmd/`, `"bootstrap/cmd/`, -1)
+ // During bootstrap, must use plain os/exec.
+ line = strings.Replace(line, `exec "internal/execabs"`, `"os/exec"`, -1)
for _, dir := range bootstrapDirs {
if strings.HasPrefix(dir, "cmd/") {
continue
diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go
index 38cbe7fa02..661624cfe4 100644
--- a/src/cmd/doc/dirs.go
+++ b/src/cmd/doc/dirs.go
@@ -7,9 +7,9 @@ package main
import (
"bytes"
"fmt"
+ exec "internal/execabs"
"log"
"os"
- "os/exec"
"path/filepath"
"regexp"
"strings"
diff --git a/src/cmd/fix/typecheck.go b/src/cmd/fix/typecheck.go
index 40b2287f26..39a53785b7 100644
--- a/src/cmd/fix/typecheck.go
+++ b/src/cmd/fix/typecheck.go
@@ -9,8 +9,8 @@ import (
"go/ast"
"go/parser"
"go/token"
+ exec "internal/execabs"
"os"
- "os/exec"
"path/filepath"
"reflect"
"runtime"
diff --git a/src/cmd/go.mod b/src/cmd/go.mod
index 031b8d4ab7..235e28f64f 100644
--- a/src/cmd/go.mod
+++ b/src/cmd/go.mod
@@ -6,7 +6,7 @@ require (
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
- golang.org/x/mod v0.4.0
+ golang.org/x/mod v0.4.1
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
- golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11
+ golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff
)
diff --git a/src/cmd/go.sum b/src/cmd/go.sum
index 2fde9445f6..70aae0b4cc 100644
--- a/src/cmd/go.sum
+++ b/src/cmd/go.sum
@@ -14,8 +14,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
-golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
+golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
@@ -31,8 +31,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11 h1:9j/upNXDRpADUw2RpUfJ7E7GHtfhDih62kX6JM8vs2c=
-golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff h1:6EkB024TP1fu6cmQqeCNw685zYDVt5g8N1BXh755SQM=
+golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 78f114f6af..49d390297c 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -153,7 +153,10 @@
// created with -buildmode=shared.
// -mod mode
// module download mode to use: readonly, vendor, or mod.
-// See 'go help modules' for more.
+// By default, if a vendor directory is present and the go version in go.mod
+// is 1.14 or higher, the go command acts as if -mod=vendor were set.
+// Otherwise, the go command acts as if -mod=readonly were set.
+// See https://golang.org/ref/mod#build-commands for details.
// -modcacherw
// leave newly-created directories in the module cache read-write
// instead of making them read-only.
@@ -492,15 +495,6 @@
// (gofmt), a fully qualified path (/usr/you/bin/mytool), or a
// command alias, described below.
//
-// To convey to humans and machine tools that code is generated,
-// generated source should have a line that matches the following
-// regular expression (in Go syntax):
-//
-// ^// Code generated .* DO NOT EDIT\.$
-//
-// The line may appear anywhere in the file, but is typically
-// placed near the beginning so it is easy to find.
-//
// Note that go generate does not parse the file, so lines that look
// like directives in comments or multiline strings will be treated
// as directives.
@@ -512,6 +506,15 @@
// Quoted strings use Go syntax and are evaluated before execution; a
// quoted string appears as a single argument to the generator.
//
+// To convey to humans and machine tools that code is generated,
+// generated source should have a line that matches the following
+// regular expression (in Go syntax):
+//
+// ^// Code generated .* DO NOT EDIT\.$
+//
+// This line must appear before the first non-comment, non-blank
+// text in the file.
+//
// Go generate sets several variables when it runs the generator:
//
// $GOARCH
@@ -595,85 +598,49 @@
//
// go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
//
-// Get resolves and adds dependencies to the current development module
-// and then builds and installs them.
-//
-// The first step is to resolve which dependencies to add.
-//
-// For each named package or package pattern, get must decide which version of
-// the corresponding module to use. By default, get looks up the latest tagged
-// release version, such as v0.4.5 or v1.2.3. If there are no tagged release
-// versions, get looks up the latest tagged pre-release version, such as
-// v0.0.1-pre1. If there are no tagged versions at all, get looks up the latest
-// known commit. If the module is not already required at a later version
-// (for example, a pre-release newer than the latest release), get will use
-// the version it looked up. Otherwise, get will use the currently
-// required version.
-//
-// This default version selection can be overridden by adding an @version
-// suffix to the package argument, as in 'go get golang.org/x/text@v0.3.0'.
-// The version may be a prefix: @v1 denotes the latest available version starting
-// with v1. See 'go help modules' under the heading 'Module queries' for the
-// full query syntax.
-//
-// For modules stored in source control repositories, the version suffix can
-// also be a commit hash, branch identifier, or other syntax known to the
-// source control system, as in 'go get golang.org/x/text@master'. Note that
-// branches with names that overlap with other module query syntax cannot be
-// selected explicitly. For example, the suffix @v2 means the latest version
-// starting with v2, not the branch named v2.
-//
-// If a module under consideration is already a dependency of the current
-// development module, then get will update the required version.
-// Specifying a version earlier than the current required version is valid and
-// downgrades the dependency. The version suffix @none indicates that the
-// dependency should be removed entirely, downgrading or removing modules
-// depending on it as needed.
-//
-// The version suffix @latest explicitly requests the latest minor release of
-// the module named by the given path. The suffix @upgrade is like @latest but
-// will not downgrade a module if it is already required at a revision or
-// pre-release version newer than the latest released version. The suffix
-// @patch requests the latest patch release: the latest released version
-// with the same major and minor version numbers as the currently required
-// version. Like @upgrade, @patch will not downgrade a module already required
-// at a newer version. If the path is not already required, @upgrade is
-// equivalent to @latest, and @patch is disallowed.
-//
-// Although get defaults to using the latest version of the module containing
-// a named package, it does not use the latest version of that module's
-// dependencies. Instead it prefers to use the specific dependency versions
-// requested by that module. For example, if the latest A requires module
-// B v1.2.3, while B v1.2.4 and v1.3.1 are also available, then 'go get A'
-// will use the latest A but then use B v1.2.3, as requested by A. (If there
-// are competing requirements for a particular module, then 'go get' resolves
-// those requirements by taking the maximum requested version.)
+// Get resolves its command-line arguments to packages at specific module versions,
+// updates go.mod to require those versions, downloads source code into the
+// module cache, then builds and installs the named packages.
+//
+// To add a dependency for a package or upgrade it to its latest version:
+//
+// go get example.com/pkg
+//
+// To upgrade or downgrade a package to a specific version:
+//
+// go get example.com/pkg@v1.2.3
+//
+// To remove a dependency on a module and downgrade modules that require it:
+//
+// go get example.com/mod@none
+//
+// See https://golang.org/ref/mod#go-get for details.
+//
+// The 'go install' command may be used to build and install packages. When a
+// version is specified, 'go install' runs in module-aware mode and ignores
+// the go.mod file in the current directory. For example:
+//
+// go install example.com/pkg@v1.2.3
+// go install example.com/pkg@latest
+//
+// See 'go help install' or https://golang.org/ref/mod#go-install for details.
+//
+// In addition to build flags (listed in 'go help build') 'go get' accepts the
+// following flags.
//
// The -t flag instructs get to consider modules needed to build tests of
// packages specified on the command line.
//
// The -u flag instructs get to update modules providing dependencies
// of packages named on the command line to use newer minor or patch
-// releases when available. Continuing the previous example, 'go get -u A'
-// will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C,
-// but C does not provide any packages needed to build packages in A
-// (not including tests), then C will not be updated.
+// releases when available.
//
// The -u=patch flag (not -u patch) also instructs get to update dependencies,
// but changes the default to select patch releases.
-// Continuing the previous example,
-// 'go get -u=patch A@latest' will use the latest A with B v1.2.4 (not B v1.2.3),
-// while 'go get -u=patch A' will use a patch release of A instead.
//
// When the -t and -u flags are used together, get will update
// test dependencies as well.
//
-// In general, adding a new dependency may require upgrading
-// existing dependencies to keep a working build, and 'go get' does
-// this automatically. Similarly, downgrading one dependency may
-// require downgrading other dependencies, and 'go get' does
-// this automatically as well.
-//
// The -insecure flag permits fetching from repositories and resolving
// custom domains using insecure schemes such as HTTP, and also bypassess
// module sum validation using the checksum database. Use with caution.
@@ -682,12 +649,8 @@
// variable instead. To bypass module sum validation, use GOPRIVATE or
// GONOSUMDB. See 'go help environment' for details.
//
-// The second step is to download (if needed), build, and install
-// the named packages.
-//
-// The -d flag instructs get to skip this step, downloading source code
-// needed to build the named packages and their dependencies, but not
-// building or installing.
+// The -d flag instructs get not to build or install packages. get will only
+// update go.mod and download source code needed to build packages.
//
// Building and installing packages with get is deprecated. In a future release,
// the -d flag will be enabled by default, and 'go get' will be only be used to
@@ -696,31 +659,14 @@
// ignoring the current module, use 'go install' with an @version suffix like
// "@latest" after each argument.
//
-// If an argument names a module but not a package (because there is no
-// Go source code in the module's root directory), then the install step
-// is skipped for that argument, instead of causing a build failure.
-// For example 'go get golang.org/x/perf' succeeds even though there
-// is no code corresponding to that import path.
-//
-// Note that package patterns are allowed and are expanded after resolving
-// the module versions. For example, 'go get golang.org/x/perf/cmd/...'
-// adds the latest golang.org/x/perf and then installs the commands in that
-// latest version.
-//
-// With no package arguments, 'go get' applies to Go package in the
-// current directory, if any. In particular, 'go get -u' and
-// 'go get -u=patch' update all the dependencies of that package.
-// With no package arguments and also without -u, 'go get' is not much more
-// than 'go install', and 'go get -d' not much more than 'go list'.
-//
-// For more about modules, see 'go help modules'.
+// For more about modules, see https://golang.org/ref/mod.
//
// For more about specifying packages, see 'go help packages'.
//
// This text describes the behavior of get using modules to manage source
// code and dependencies. If instead the go command is running in GOPATH
// mode, the details of get's flags and effects change, as does 'go help get'.
-// See 'go help modules' and 'go help gopath-get'.
+// See 'go help gopath-get'.
//
// See also: go build, go install, go clean, go mod.
//
@@ -840,6 +786,14 @@
// TestGoFiles []string // _test.go files in package
// XTestGoFiles []string // _test.go files outside package
//
+// // Embedded files
+// EmbedPatterns []string // //go:embed patterns
+// EmbedFiles []string // files matched by EmbedPatterns
+// TestEmbedPatterns []string // //go:embed patterns in TestGoFiles
+// TestEmbedFiles []string // files matched by TestEmbedPatterns
+// XTestEmbedPatterns []string // //go:embed patterns in XTestGoFiles
+// XTestEmbedFiles []string // files matched by XTestEmbedPatterns
+//
// // Cgo directives
// CgoCFLAGS []string // cgo: flags for C compiler
// CgoCPPFLAGS []string // cgo: flags for C preprocessor
@@ -1051,7 +1005,7 @@
//
// For more about specifying packages, see 'go help packages'.
//
-// For more about modules, see 'go help modules'.
+// For more about modules, see https://golang.org/ref/mod.
//
//
// Module maintenance
@@ -1116,7 +1070,9 @@
//
// The -x flag causes download to print the commands download executes.
//
-// See 'go help modules' for more about module queries.
+// See https://golang.org/ref/mod#go-mod-download for more about 'go mod download'.
+//
+// See https://golang.org/ref/mod#version-queries for more about version queries.
//
//
// Edit go.mod from tools or scripts
@@ -1219,9 +1175,7 @@
// referred to indirectly. For the full set of modules available to a build,
// use 'go list -m -json all'.
//
-// For example, a tool can obtain the go.mod as a data structure by
-// parsing the output of 'go mod edit -json' and can then make changes
-// by invoking 'go mod edit' with -require, -exclude, and so on.
+// See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
//
//
// Print module requirement graph
@@ -1235,6 +1189,8 @@
// and one of its requirements. Each module is identified as a string of the form
// path@version, except for the main module, which has no @version suffix.
//
+// See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
+//
//
// Initialize new module in current directory
//
@@ -1254,6 +1210,8 @@
// If a configuration file for a vendoring tool is present, init will attempt to
// import module requirements from it.
//
+// See https://golang.org/ref/mod#go-mod-init for more about 'go mod init'.
+//
//
// Add missing and remove unused modules
//
@@ -1273,6 +1231,8 @@
// The -e flag causes tidy to attempt to proceed despite errors
// encountered while loading packages.
//
+// See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'.
+//
//
// Make vendored copy of dependencies
//
@@ -1290,6 +1250,8 @@
// The -e flag causes vendor to attempt to proceed despite errors
// encountered while loading packages.
//
+// See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
+//
//
// Verify dependencies have expected content
//
@@ -1304,6 +1266,8 @@
// modules have been changed and causes 'go mod' to exit with a
// non-zero status.
//
+// See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
+//
//
// Explain why packages or modules are needed
//
@@ -1340,6 +1304,8 @@
// (main module does not need package golang.org/x/text/encoding)
// $
//
+// See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
+//
//
// Compile and run Go program
//
@@ -1784,6 +1750,10 @@
//
// General-purpose environment variables:
//
+// GO111MODULE
+// Controls whether the go command runs in module-aware mode or GOPATH mode.
+// May be "off", "on", or "auto".
+// See https://golang.org/ref/mod#mod-commands.
// GCCGO
// The gccgo command to run for 'go build -compiler=gccgo'.
// GOARCH
@@ -1822,20 +1792,24 @@
// GOPATH
// For more details see: 'go help gopath'.
// GOPROXY
-// URL of Go module proxy. See 'go help modules'.
+// URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
+// and https://golang.org/ref/mod#module-proxy for details.
// GOPRIVATE, GONOPROXY, GONOSUMDB
// Comma-separated list of glob patterns (in the syntax of Go's path.Match)
// of module path prefixes that should always be fetched directly
// or that should not be compared against the checksum database.
-// See 'go help private'.
+// See https://golang.org/ref/mod#private-modules.
// GOROOT
// The root of the go tree.
// GOSUMDB
// The name of checksum database to use and optionally its public key and
-// URL. See 'go help module-auth'.
+// URL. See https://golang.org/ref/mod#authenticating.
// GOTMPDIR
// The directory where the go command will write
// temporary source files, packages, and binaries.
+// GOVCS
+// Lists version control commands that may be used with matching servers.
+// See 'go help vcs'.
//
// Environment variables for use with cgo:
//
@@ -1980,88 +1954,23 @@
// directory and then successive parent directories to find the go.mod
// marking the root of the main (current) module.
//
-// The go.mod file itself is line-oriented, with // comments but
-// no /* */ comments. Each line holds a single directive, made up of a
-// verb followed by arguments. For example:
-//
-// module my/thing
-// go 1.12
-// require other/thing v1.0.2
-// require new/thing/v2 v2.3.4
-// exclude old/thing v1.2.3
-// replace bad/thing v1.4.5 => good/thing v1.4.5
-// retract v1.5.6
-//
-// The verbs are
-// module, to define the module path;
-// go, to set the expected language version;
-// require, to require a particular module at a given version or later;
-// exclude, to exclude a particular module version from use;
-// replace, to replace a module version with a different module version; and
-// retract, to indicate a previously released version should not be used.
-// Exclude and replace apply only in the main module's go.mod and are ignored
-// in dependencies. See https://golang.org/ref/mod for details.
-//
-// The leading verb can be factored out of adjacent lines to create a block,
-// like in Go imports:
-//
-// require (
-// new/thing/v2 v2.3.4
-// old/thing v1.2.3
-// )
-//
-// The go.mod file is designed both to be edited directly and to be
-// easily updated by tools. The 'go mod edit' command can be used to
-// parse and edit the go.mod file from programs and tools.
-// See 'go help mod edit'.
-//
-// The go command automatically updates go.mod each time it uses the
-// module graph, to make sure go.mod always accurately reflects reality
-// and is properly formatted. For example, consider this go.mod file:
-//
-// module M
-//
-// require (
-// A v1
-// B v1.0.0
-// C v1.0.0
-// D v1.2.3
-// E dev
-// )
-//
-// exclude D v1.2.3
-//
-// The update rewrites non-canonical version identifiers to semver form,
-// so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the
-// latest commit on the dev branch, perhaps v0.0.0-20180523231146-b3f5c0f6e5f1.
-//
-// The update modifies requirements to respect exclusions, so the
-// requirement on the excluded D v1.2.3 is updated to use the next
-// available version of D, perhaps D v1.2.4 or D v1.3.0.
-//
-// The update removes redundant or misleading requirements.
-// For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0,
-// then go.mod's requirement of B v1.0.0 is misleading (superseded by
-// A's need for v1.2.0), and its requirement of C v1.0.0 is redundant
-// (implied by A's need for the same version), so both will be removed.
-// If module M contains packages that directly import packages from B or
-// C, then the requirements will be kept but updated to the actual
-// versions being used.
-//
-// Finally, the update reformats the go.mod in a canonical formatting, so
-// that future mechanical changes will result in minimal diffs.
-//
-// Because the module graph defines the meaning of import statements, any
-// commands that load packages also use and therefore update go.mod,
-// including go build, go get, go install, go list, go test, go mod graph,
-// go mod tidy, and go mod why.
-//
-// The expected language version, set by the go directive, determines
-// which language features are available when compiling the module.
-// Language features available in that version will be available for use.
-// Language features removed in earlier versions, or added in later versions,
-// will not be available. Note that the language version does not affect
-// build tags, which are determined by the Go release being used.
+// The go.mod file format is described in detail at
+// https://golang.org/ref/mod#go-mod-file.
+//
+// To create a new go.mod file, use 'go help init'. For details see
+// 'go help mod init' or https://golang.org/ref/mod#go-mod-init.
+//
+// To add missing module requirements or remove unneeded requirements,
+// use 'go mod tidy'. For details, see 'go help mod tidy' or
+// https://golang.org/ref/mod#go-mod-tidy.
+//
+// To add, upgrade, downgrade, or remove a specific module requirement, use
+// 'go get'. For details, see 'go help module-get' or
+// https://golang.org/ref/mod#go-get.
+//
+// To make other changes or to parse go.mod as JSON for use by other tools,
+// use 'go mod edit'. See 'go help mod edit' or
+// https://golang.org/ref/mod#go-mod-edit.
//
//
// GOPATH environment variable
@@ -2296,65 +2205,8 @@
// a site serving from a fixed file system (including a file:/// URL)
// can be a module proxy.
//
-// The GET requests sent to a Go module proxy are:
-//
-// GET $GOPROXY/<module>/@v/list returns a list of known versions of the given
-// module, one per line.
-//
-// GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata
-// about that version of the given module.
-//
-// GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file
-// for that version of the given module.
-//
-// GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive
-// for that version of the given module.
-//
-// GET $GOPROXY/<module>/@latest returns JSON-formatted metadata about the
-// latest known version of the given module in the same format as
-// <module>/@v/<version>.info. The latest version should be the version of
-// the module the go command may use if <module>/@v/list is empty or no
-// listed version is suitable. <module>/@latest is optional and may not
-// be implemented by a module proxy.
-//
-// When resolving the latest version of a module, the go command will request
-// <module>/@v/list, then, if no suitable versions are found, <module>/@latest.
-// The go command prefers, in order: the semantically highest release version,
-// the semantically highest pre-release version, and the chronologically
-// most recent pseudo-version. In Go 1.12 and earlier, the go command considered
-// pseudo-versions in <module>/@v/list to be pre-release versions, but this is
-// no longer true since Go 1.13.
-//
-// To avoid problems when serving from case-sensitive file systems,
-// the <module> and <version> elements are case-encoded, replacing every
-// uppercase letter with an exclamation mark followed by the corresponding
-// lower-case letter: github.com/Azure encodes as github.com/!azure.
-//
-// The JSON-formatted metadata about a given module corresponds to
-// this Go data structure, which may be expanded in the future:
-//
-// type Info struct {
-// Version string // version string
-// Time time.Time // commit time
-// }
-//
-// The zip archive for a specific version of a given module is a
-// standard zip file that contains the file tree corresponding
-// to the module's source code and related files. The archive uses
-// slash-separated paths, and every file path in the archive must
-// begin with <module>@<version>/, where the module and version are
-// substituted directly, not case-encoded. The root of the module
-// file tree corresponds to the <module>@<version>/ prefix in the
-// archive.
-//
-// Even when downloading directly from version control systems,
-// the go command synthesizes explicit info, mod, and zip files
-// and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
-// the same as if it had downloaded them directly from a proxy.
-// The cache layout is the same as the proxy URL space, so
-// serving $GOPATH/pkg/mod/cache/download at (or copying it to)
-// https://example.com/proxy would let other users access those
-// cached module versions with GOPROXY=https://example.com/proxy.
+// For details on the GOPROXY protocol, see
+// https://golang.org/ref/mod#goproxy-protocol.
//
//
// Import path syntax
@@ -2505,7 +2357,7 @@
// (See 'go help gopath-get' and 'go help gopath'.)
//
// When using modules, downloaded packages are stored in the module cache.
-// (See 'go help module-get' and 'go help goproxy'.)
+// See https://golang.org/ref/mod#module-cache.
//
// When using modules, an additional variant of the go-import meta tag is
// recognized and is preferred over those listing version control systems.
@@ -2515,7 +2367,8 @@
//
// This tag means to fetch modules with paths beginning with example.org
// from the module proxy available at the URL https://code.org/moduleproxy.
-// See 'go help goproxy' for details about the proxy protocol.
+// See https://golang.org/ref/mod#goproxy-protocol for details about the
+// proxy protocol.
//
// Import path checking
//
@@ -2546,483 +2399,28 @@
//
// Modules, module versions, and more
//
-// A module is a collection of related Go packages.
-// Modules are the unit of source code interchange and versioning.
-// The go command has direct support for working with modules,
-// including recording and resolving dependencies on other modules.
-// Modules replace the old GOPATH-based approach to specifying
-// which source files are used in a given build.
-//
-// Module support
-//
-// The go command includes support for Go modules. Module-aware mode is active
-// by default whenever a go.mod file is found in the current directory or in
-// any parent directory.
-//
-// The quickest way to take advantage of module support is to check out your
-// repository, create a go.mod file (described in the next section) there, and run
-// go commands from within that file tree.
-//
-// For more fine-grained control, the go command continues to respect
-// a temporary environment variable, GO111MODULE, which can be set to one
-// of three string values: off, on, or auto (the default).
-// If GO111MODULE=on, then the go command requires the use of modules,
-// never consulting GOPATH. We refer to this as the command
-// being module-aware or running in "module-aware mode".
-// If GO111MODULE=off, then the go command never uses
-// module support. Instead it looks in vendor directories and GOPATH
-// to find dependencies; we now refer to this as "GOPATH mode."
-// If GO111MODULE=auto or is unset, then the go command enables or disables
-// module support based on the current directory.
-// Module support is enabled only when the current directory contains a
-// go.mod file or is below a directory containing a go.mod file.
-//
-// In module-aware mode, GOPATH no longer defines the meaning of imports
-// during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
-// and installed commands (in GOPATH/bin, unless GOBIN is set).
-//
-// Defining a module
-//
-// A module is defined by a tree of Go source files with a go.mod file
-// in the tree's root directory. The directory containing the go.mod file
-// is called the module root. Typically the module root will also correspond
-// to a source code repository root (but in general it need not).
-// The module is the set of all Go packages in the module root and its
-// subdirectories, but excluding subtrees with their own go.mod files.
-//
-// The "module path" is the import path prefix corresponding to the module root.
-// The go.mod file defines the module path and lists the specific versions
-// of other modules that should be used when resolving imports during a build,
-// by giving their module paths and versions.
-//
-// For example, this go.mod declares that the directory containing it is the root
-// of the module with path example.com/m, and it also declares that the module
-// depends on specific versions of golang.org/x/text and gopkg.in/yaml.v2:
-//
-// module example.com/m
-//
-// require (
-// golang.org/x/text v0.3.0
-// gopkg.in/yaml.v2 v2.1.0
-// )
-//
-// The go.mod file can also specify replacements and excluded versions
-// that only apply when building the module directly; they are ignored
-// when the module is incorporated into a larger build.
-// For more about the go.mod file, see 'go help go.mod'.
-//
-// To start a new module, simply create a go.mod file in the root of the
-// module's directory tree, containing only a module statement.
-// The 'go mod init' command can be used to do this:
-//
-// go mod init example.com/m
-//
-// In a project already using an existing dependency management tool like
-// godep, glide, or dep, 'go mod init' will also add require statements
-// matching the existing configuration.
-//
-// Once the go.mod file exists, no additional steps are required:
-// go commands like 'go build', 'go test', or even 'go list' will automatically
-// add new dependencies as needed to satisfy imports.
-//
-// The main module and the build list
-//
-// The "main module" is the module containing the directory where the go command
-// is run. The go command finds the module root by looking for a go.mod in the
-// current directory, or else the current directory's parent directory,
-// or else the parent's parent directory, and so on.
-//
-// The main module's go.mod file defines the precise set of packages available
-// for use by the go command, through require, replace, and exclude statements.
-// Dependency modules, found by following require statements, also contribute
-// to the definition of that set of packages, but only through their go.mod
-// files' require statements: any replace and exclude statements in dependency
-// modules are ignored. The replace and exclude statements therefore allow the
-// main module complete control over its own build, without also being subject
-// to complete control by dependencies.
-//
-// The set of modules providing packages to builds is called the "build list".
-// The build list initially contains only the main module. Then the go command
-// adds to the list the exact module versions required by modules already
-// on the list, recursively, until there is nothing left to add to the list.
-// If multiple versions of a particular module are added to the list,
-// then at the end only the latest version (according to semantic version
-// ordering) is kept for use in the build.
-//
-// The 'go list' command provides information about the main module
-// and the build list. For example:
-//
-// go list -m # print path of main module
-// go list -m -f={{.Dir}} # print root directory of main module
-// go list -m all # print build list
-//
-// Maintaining module requirements
-//
-// The go.mod file is meant to be readable and editable by both programmers and
-// tools. Most updates to dependencies can be performed using "go get" and
-// "go mod tidy". Other module-aware build commands may be invoked using the
-// -mod=mod flag to automatically add missing requirements and fix inconsistencies.
-//
-// The "go get" command updates go.mod to change the module versions used in a
-// build. An upgrade of one module may imply upgrading others, and similarly a
-// downgrade of one module may imply downgrading others. The "go get" command
-// makes these implied changes as well. See "go help module-get".
-//
-// The "go mod" command provides other functionality for use in maintaining
-// and understanding modules and go.mod files. See "go help mod", particularly
-// "go help mod tidy" and "go help mod edit".
-//
-// As part of maintaining the require statements in go.mod, the go command
-// tracks which ones provide packages imported directly by the current module
-// and which ones provide packages only used indirectly by other module
-// dependencies. Requirements needed only for indirect uses are marked with a
-// "// indirect" comment in the go.mod file. Indirect requirements may be
-// automatically removed from the go.mod file once they are implied by other
-// direct requirements. Indirect requirements only arise when using modules
-// that fail to state some of their own dependencies or when explicitly
-// upgrading a module's dependencies ahead of its own stated requirements.
-//
-// The -mod build flag provides additional control over the updating and use of
-// go.mod for commands that build packages like "go build" and "go test".
-//
-// If invoked with -mod=readonly (the default in most situations), the go command
-// reports an error if a package named on the command line or an imported package
-// is not provided by any module in the build list computed from the main module's
-// requirements. The go command also reports an error if a module's checksum is
-// missing from go.sum (see Module downloading and verification). Either go.mod or
-// go.sum must be updated in these situations.
-//
-// If invoked with -mod=mod, the go command automatically updates go.mod and
-// go.sum, fixing inconsistencies and adding missing requirements and checksums
-// as needed. If the go command finds an unfamiliar import, it looks up the
-// module containing that import and adds a requirement for the latest version
-// of that module to go.mod. In most cases, therefore, one may add an import to
-// source code and run "go build", "go test", or even "go list" with -mod=mod:
-// as part of analyzing the package, the go command will resolve the import and
-// update the go.mod file.
-//
-// If invoked with -mod=vendor, the go command loads packages from the main
-// module's vendor directory instead of downloading modules to and loading packages
-// from the module cache. The go command assumes the vendor directory holds
-// correct copies of dependencies, and it does not compute the set of required
-// module versions from go.mod files. However, the go command does check that
-// vendor/modules.txt (generated by "go mod vendor") contains metadata consistent
-// with go.mod.
-//
-// If the go command is not invoked with a -mod flag, and the vendor directory
-// is present, and the "go" version in go.mod is 1.14 or higher, the go command
-// will act as if it were invoked with -mod=vendor. Otherwise, the -mod flag
-// defaults to -mod=readonly.
-//
-// Note that neither "go get" nor the "go mod" subcommands accept the -mod flag.
-//
-// Pseudo-versions
-//
-// The go.mod file and the go command more generally use semantic versions as
-// the standard form for describing module versions, so that versions can be
-// compared to determine which should be considered earlier or later than another.
-// A module version like v1.2.3 is introduced by tagging a revision in the
-// underlying source repository. Untagged revisions can be referred to
-// using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef,
-// where the time is the commit time in UTC and the final suffix is the prefix
-// of the commit hash. The time portion ensures that two pseudo-versions can
-// be compared to determine which happened later, the commit hash identifes
-// the underlying commit, and the prefix (v0.0.0- in this example) is derived from
-// the most recent tagged version in the commit graph before this commit.
-//
-// There are three pseudo-version forms:
-//
-// vX.0.0-yyyymmddhhmmss-abcdefabcdef is used when there is no earlier
-// versioned commit with an appropriate major version before the target commit.
-// (This was originally the only form, so some older go.mod files use this form
-// even for commits that do follow tags.)
-//
-// vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef is used when the most
-// recent versioned commit before the target commit is vX.Y.Z-pre.
-//
-// vX.Y.(Z+1)-0.yyyymmddhhmmss-abcdefabcdef is used when the most
-// recent versioned commit before the target commit is vX.Y.Z.
-//
-// Pseudo-versions never need to be typed by hand: the go command will accept
-// the plain commit hash and translate it into a pseudo-version (or a tagged
-// version if available) automatically. This conversion is an example of a
-// module query.
-//
-// Module queries
-//
-// The go command accepts a "module query" in place of a module version
-// both on the command line and in the main module's go.mod file.
-// (After evaluating a query found in the main module's go.mod file,
-// the go command updates the file to replace the query with its result.)
-//
-// A fully-specified semantic version, such as "v1.2.3",
-// evaluates to that specific version.
-//
-// A semantic version prefix, such as "v1" or "v1.2",
-// evaluates to the latest available tagged version with that prefix.
-//
-// A semantic version comparison, such as "<v1.2.3" or ">=v1.5.6",
-// evaluates to the available tagged version nearest to the comparison target
-// (the latest version for < and <=, the earliest version for > and >=).
-//
-// The string "latest" matches the latest available tagged version,
-// or else the underlying source repository's latest untagged revision.
-//
-// The string "upgrade" is like "latest", but if the module is
-// currently required at a later version than the version "latest"
-// would select (for example, a newer pre-release version), "upgrade"
-// will select the later version instead.
-//
-// The string "patch" matches the latest available tagged version
-// of a module with the same major and minor version numbers as the
-// currently required version. If no version is currently required,
-// "patch" is equivalent to "latest".
-//
-// A revision identifier for the underlying source repository, such as
-// a commit hash prefix, revision tag, or branch name, selects that
-// specific code revision. If the revision is also tagged with a
-// semantic version, the query evaluates to that semantic version.
-// Otherwise the query evaluates to a pseudo-version for the commit.
-// Note that branches and tags with names that are matched by other
-// query syntax cannot be selected this way. For example, the query
-// "v2" means the latest version starting with "v2", not the branch
-// named "v2".
-//
-// All queries prefer release versions to pre-release versions.
-// For example, "<v1.2.3" will prefer to return "v1.2.2"
-// instead of "v1.2.3-pre1", even though "v1.2.3-pre1" is nearer
-// to the comparison target.
-//
-// Module versions disallowed by exclude statements in the
-// main module's go.mod are considered unavailable and cannot
-// be returned by queries.
-//
-// For example, these commands are all valid:
-//
-// go get github.com/gorilla/mux@latest # same (@latest is default for 'go get')
-// go get github.com/gorilla/mux@v1.6.2 # records v1.6.2
-// go get github.com/gorilla/mux@e3702bed2 # records v1.6.2
-// go get github.com/gorilla/mux@c856192 # records v0.0.0-20180517173623-c85619274f5d
-// go get github.com/gorilla/mux@master # records current meaning of master
-//
-// Module compatibility and semantic versioning
-//
-// The go command requires that modules use semantic versions and expects that
-// the versions accurately describe compatibility: it assumes that v1.5.4 is a
-// backwards-compatible replacement for v1.5.3, v1.4.0, and even v1.0.0.
-// More generally the go command expects that packages follow the
-// "import compatibility rule", which says:
-//
-// "If an old package and a new package have the same import path,
-// the new package must be backwards compatible with the old package."
-//
-// Because the go command assumes the import compatibility rule,
-// a module definition can only set the minimum required version of one
-// of its dependencies: it cannot set a maximum or exclude selected versions.
-// Still, the import compatibility rule is not a guarantee: it may be that
-// v1.5.4 is buggy and not a backwards-compatible replacement for v1.5.3.
-// Because of this, the go command never updates from an older version
-// to a newer version of a module unasked.
-//
-// In semantic versioning, changing the major version number indicates a lack
-// of backwards compatibility with earlier versions. To preserve import
-// compatibility, the go command requires that modules with major version v2
-// or later use a module path with that major version as the final element.
-// For example, version v2.0.0 of example.com/m must instead use module path
-// example.com/m/v2, and packages in that module would use that path as
-// their import path prefix, as in example.com/m/v2/sub/pkg. Including the
-// major version number in the module path and import paths in this way is
-// called "semantic import versioning". Pseudo-versions for modules with major
-// version v2 and later begin with that major version instead of v0, as in
-// v2.0.0-20180326061214-4fc5987536ef.
-//
-// As a special case, module paths beginning with gopkg.in/ continue to use the
-// conventions established on that system: the major version is always present,
-// and it is preceded by a dot instead of a slash: gopkg.in/yaml.v1
-// and gopkg.in/yaml.v2, not gopkg.in/yaml and gopkg.in/yaml/v2.
-//
-// The go command treats modules with different module paths as unrelated:
-// it makes no connection between example.com/m and example.com/m/v2.
-// Modules with different major versions can be used together in a build
-// and are kept separate by the fact that their packages use different
-// import paths.
-//
-// In semantic versioning, major version v0 is for initial development,
-// indicating no expectations of stability or backwards compatibility.
-// Major version v0 does not appear in the module path, because those
-// versions are preparation for v1.0.0, and v1 does not appear in the
-// module path either.
-//
-// Code written before the semantic import versioning convention
-// was introduced may use major versions v2 and later to describe
-// the same set of unversioned import paths as used in v0 and v1.
-// To accommodate such code, if a source code repository has a
-// v2.0.0 or later tag for a file tree with no go.mod, the version is
-// considered to be part of the v1 module's available versions
-// and is given an +incompatible suffix when converted to a module
-// version, as in v2.0.0+incompatible. The +incompatible tag is also
-// applied to pseudo-versions derived from such versions, as in
-// v2.0.1-0.yyyymmddhhmmss-abcdefabcdef+incompatible.
-//
-// In general, having a dependency in the build list (as reported by 'go list -m all')
-// on a v0 version, pre-release version, pseudo-version, or +incompatible version
-// is an indication that problems are more likely when upgrading that
-// dependency, since there is no expectation of compatibility for those.
-//
-// See https://research.swtch.com/vgo-import for more information about
-// semantic import versioning, and see https://semver.org/ for more about
-// semantic versioning.
-//
-// Module code layout
-//
-// For now, see https://research.swtch.com/vgo-module for information
-// about how source code in version control systems is mapped to
-// module file trees.
-//
-// Module downloading and verification
-//
-// The go command can fetch modules from a proxy or connect to source control
-// servers directly, according to the setting of the GOPROXY environment
-// variable (see 'go help env'). The default setting for GOPROXY is
-// "https://proxy.golang.org,direct", which means to try the
-// Go module mirror run by Google and fall back to a direct connection
-// if the proxy reports that it does not have the module (HTTP error 404 or 410).
-// See https://proxy.golang.org/privacy for the service's privacy policy.
-//
-// If GOPROXY is set to the string "direct", downloads use a direct connection to
-// source control servers. Setting GOPROXY to "off" disallows downloading modules
-// from any source. Otherwise, GOPROXY is expected to be list of module proxy URLs
-// separated by either comma (,) or pipe (|) characters, which control error
-// fallback behavior. For each request, the go command tries each proxy in
-// sequence. If there is an error, the go command will try the next proxy in the
-// list if the error is a 404 or 410 HTTP response or if the current proxy is
-// followed by a pipe character, indicating it is safe to fall back on any error.
-//
-// The GOPRIVATE and GONOPROXY environment variables allow bypassing
-// the proxy for selected modules. See 'go help private' for details.
-//
-// No matter the source of the modules, the go command checks downloads against
-// known checksums, to detect unexpected changes in the content of any specific
-// module version from one day to the next. This check first consults the current
-// module's go.sum file but falls back to the Go checksum database, controlled by
-// the GOSUMDB and GONOSUMDB environment variables. See 'go help module-auth'
-// for details.
-//
-// See 'go help goproxy' for details about the proxy protocol and also
-// the format of the cached downloaded packages.
-//
-// Modules and vendoring
-//
-// When using modules, the go command typically satisfies dependencies by
-// downloading modules from their sources and using those downloaded copies
-// (after verification, as described in the previous section). Vendoring may
-// be used to allow interoperation with older versions of Go, or to ensure
-// that all files used for a build are stored together in a single file tree.
-//
-// The command 'go mod vendor' constructs a directory named vendor in the main
-// module's root directory that contains copies of all packages needed to support
-// builds and tests of packages in the main module. 'go mod vendor' also
-// creates the file vendor/modules.txt that contains metadata about vendored
-// packages and module versions. This file should be kept consistent with go.mod:
-// when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
-//
-// If the vendor directory is present in the main module's root directory, it will
-// be used automatically if the "go" version in the main module's go.mod file is
-// 1.14 or higher. Build commands like 'go build' and 'go test' will load packages
-// from the vendor directory instead of accessing the network or the local module
-// cache. To explicitly enable vendoring, invoke the go command with the flag
-// -mod=vendor. To disable vendoring, use the flag -mod=mod.
-//
-// Unlike vendoring in GOPATH, the go command ignores vendor directories in
-// locations other than the main module's root directory.
+// Modules are how Go manages dependencies.
+//
+// A module is a collection of packages that are released, versioned, and
+// distributed together. Modules may be downloaded directly from version control
+// repositories or from module proxy servers.
+//
+// For a series of tutorials on modules, see
+// https://golang.org/doc/tutorial/create-module.
+//
+// For a detailed reference on modules, see https://golang.org/ref/mod.
//
//
// Module authentication using go.sum
//
-// The go command tries to authenticate every downloaded module,
-// checking that the bits downloaded for a specific module version today
-// match bits downloaded yesterday. This ensures repeatable builds
-// and detects introduction of unexpected changes, malicious or not.
-//
-// In each module's root, alongside go.mod, the go command maintains
-// a file named go.sum containing the cryptographic checksums of the
-// module's dependencies.
-//
-// The form of each line in go.sum is three fields:
-//
-// <module> <version>[/go.mod] <hash>
-//
-// Each known module version results in two lines in the go.sum file.
-// The first line gives the hash of the module version's file tree.
-// The second line appends "/go.mod" to the version and gives the hash
-// of only the module version's (possibly synthesized) go.mod file.
-// The go.mod-only hash allows downloading and authenticating a
-// module version's go.mod file, which is needed to compute the
-// dependency graph, without also downloading all the module's source code.
-//
-// The hash begins with an algorithm prefix of the form "h<N>:".
-// The only defined algorithm prefix is "h1:", which uses SHA-256.
-//
-// Module authentication failures
-//
-// The go command maintains a cache of downloaded packages and computes
-// and records the cryptographic checksum of each package at download time.
-// In normal operation, the go command checks the main module's go.sum file
-// against these precomputed checksums instead of recomputing them on
-// each command invocation. The 'go mod verify' command checks that
-// the cached copies of module downloads still match both their recorded
-// checksums and the entries in go.sum.
-//
-// In day-to-day development, the checksum of a given module version
-// should never change. Each time a dependency is used by a given main
-// module, the go command checks its local cached copy, freshly
-// downloaded or not, against the main module's go.sum. If the checksums
-// don't match, the go command reports the mismatch as a security error
-// and refuses to run the build. When this happens, proceed with caution:
-// code changing unexpectedly means today's build will not match
-// yesterday's, and the unexpected change may not be beneficial.
-//
-// If the go command reports a mismatch in go.sum, the downloaded code
-// for the reported module version does not match the one used in a
-// previous build of the main module. It is important at that point
-// to find out what the right checksum should be, to decide whether
-// go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
-// you want to use the same code you used yesterday.
-//
-// If a downloaded module is not yet included in go.sum and it is a publicly
-// available module, the go command consults the Go checksum database to fetch
-// the expected go.sum lines. If the downloaded code does not match those
-// lines, the go command reports the mismatch and exits. Note that the
-// database is not consulted for module versions already listed in go.sum.
-//
-// If a go.sum mismatch is reported, it is always worth investigating why
-// the code downloaded today differs from what was downloaded yesterday.
-//
-// The GOSUMDB environment variable identifies the name of checksum database
-// to use and optionally its public key and URL, as in:
-//
-// GOSUMDB="sum.golang.org"
-// GOSUMDB="sum.golang.org+<publickey>"
-// GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
-//
-// The go command knows the public key of sum.golang.org, and also that the name
-// sum.golang.google.cn (available inside mainland China) connects to the
-// sum.golang.org checksum database; use of any other database requires giving
-// the public key explicitly.
-// The URL defaults to "https://" followed by the database name.
-//
-// GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
-// See https://sum.golang.org/privacy for the service's privacy policy.
-//
-// If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
-// the checksum database is not consulted, and all unrecognized modules are
-// accepted, at the cost of giving up the security guarantee of verified repeatable
-// downloads for all modules. A better way to bypass the checksum database
-// for specific modules is to use the GOPRIVATE or GONOSUMDB environment
-// variables. See 'go help private' for details.
+// When the go command downloads a module zip file or go.mod file into the
+// module cache, it computes a cryptographic hash and compares it with a known
+// value to verify the file hasn't changed since it was first downloaded. Known
+// hashes are stored in a file in the module root directory named go.sum. Hashes
+// may also be downloaded from the checksum database depending on the values of
+// GOSUMDB, GOPRIVATE, and GONOSUMDB.
//
-// The 'go env -w' command (see 'go help env') can be used to set these variables
-// for future go command invocations.
+// For details, see https://golang.org/ref/mod#authenticating.
//
//
// Package lists and patterns
@@ -3117,8 +2515,8 @@
// These defaults work well for publicly available source code.
//
// The GOPRIVATE environment variable controls which modules the go command
-// considers to be private (not available publicly) and should therefore not use the
-// proxy or checksum database. The variable is a comma-separated list of
+// considers to be private (not available publicly) and should therefore not use
+// the proxy or checksum database. The variable is a comma-separated list of
// glob patterns (in the syntax of Go's path.Match) of module path prefixes.
// For example,
//
@@ -3128,10 +2526,6 @@
// matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
// and rsc.io/private/quux.
//
-// The GOPRIVATE environment variable may be used by other tools as well to
-// identify non-public modules. For example, an editor could use GOPRIVATE
-// to decide whether to hyperlink a package import to a godoc.org page.
-//
// For fine-grained control over module download and validation, the GONOPROXY
// and GONOSUMDB environment variables accept the same kind of glob list
// and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -3144,12 +2538,6 @@
// GOPROXY=proxy.example.com
// GONOPROXY=none
//
-// This would tell the go command and other tools that modules beginning with
-// a corp.example.com subdomain are private but that the company proxy should
-// be used for downloading both public and private modules, because
-// GONOPROXY has been set to a pattern that won't match any modules,
-// overriding GOPRIVATE.
-//
// The GOPRIVATE variable is also used to define the "public" and "private"
// patterns for the GOVCS variable; see 'go help vcs'. For that usage,
// GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
@@ -3158,6 +2546,8 @@
// The 'go env -w' command (see 'go help env') can be used to set these variables
// for future go command invocations.
//
+// For more details, see https://golang.org/ref/mod#private-modules.
+//
//
// Testing flags
//
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index c472620db2..3ce32388d0 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -216,6 +216,7 @@ func TestMain(m *testing.M) {
}
// Don't let these environment variables confuse the test.
os.Setenv("GOENV", "off")
+ os.Unsetenv("GOFLAGS")
os.Unsetenv("GOBIN")
os.Unsetenv("GOPATH")
os.Unsetenv("GIT_ALLOW_PROTOCOL")
@@ -2655,12 +2656,12 @@ func TestBadCommandLines(t *testing.T) {
tg.tempFile("src/@x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
tg.runFail("build", "@x")
- tg.grepStderr("invalid input directory name \"@x\"|cannot use path@version syntax", "did not reject @x directory")
+ tg.grepStderr("invalid input directory name \"@x\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x directory")
tg.tempFile("src/@x/y/y.go", "package y\n")
tg.setenv("GOPATH", tg.path("."))
tg.runFail("build", "@x/y")
- tg.grepStderr("invalid import path \"@x/y\"|cannot use path@version syntax", "did not reject @x/y import path")
+ tg.grepStderr("invalid import path \"@x/y\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x/y import path")
tg.tempFile("src/-x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
diff --git a/src/cmd/go/internal/base/base.go b/src/cmd/go/internal/base/base.go
index 004588c732..954ce47a98 100644
--- a/src/cmd/go/internal/base/base.go
+++ b/src/cmd/go/internal/base/base.go
@@ -10,9 +10,9 @@ import (
"context"
"flag"
"fmt"
+ exec "internal/execabs"
"log"
"os"
- "os/exec"
"strings"
"sync"
diff --git a/src/cmd/go/internal/bug/bug.go b/src/cmd/go/internal/bug/bug.go
index 1085feaaee..4aa08b4ff6 100644
--- a/src/cmd/go/internal/bug/bug.go
+++ b/src/cmd/go/internal/bug/bug.go
@@ -9,10 +9,10 @@ import (
"bytes"
"context"
"fmt"
+ exec "internal/execabs"
"io"
urlpkg "net/url"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
diff --git a/src/cmd/go/internal/fmtcmd/fmt.go b/src/cmd/go/internal/fmtcmd/fmt.go
index b0c1c59b40..6b98f0ccd3 100644
--- a/src/cmd/go/internal/fmtcmd/fmt.go
+++ b/src/cmd/go/internal/fmtcmd/fmt.go
@@ -75,7 +75,8 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
}
if pkg.Error != nil {
var nogo *load.NoGoError
- if errors.As(pkg.Error, &nogo) && len(pkg.InternalAllGoFiles()) > 0 {
+ var embed *load.EmbedError
+ if (errors.As(pkg.Error, &nogo) || errors.As(pkg.Error, &embed)) && len(pkg.InternalAllGoFiles()) > 0 {
// Skip this error, as we will format
// all files regardless.
} else {
diff --git a/src/cmd/go/internal/generate/generate.go b/src/cmd/go/internal/generate/generate.go
index c7401948b8..a48311d51b 100644
--- a/src/cmd/go/internal/generate/generate.go
+++ b/src/cmd/go/internal/generate/generate.go
@@ -12,10 +12,10 @@ import (
"fmt"
"go/parser"
"go/token"
+ exec "internal/execabs"
"io"
"log"
"os"
- "os/exec"
"path/filepath"
"regexp"
"strconv"
@@ -52,15 +52,6 @@ that can be run locally. It must either be in the shell path
(gofmt), a fully qualified path (/usr/you/bin/mytool), or a
command alias, described below.
-To convey to humans and machine tools that code is generated,
-generated source should have a line that matches the following
-regular expression (in Go syntax):
-
- ^// Code generated .* DO NOT EDIT\.$
-
-The line may appear anywhere in the file, but is typically
-placed near the beginning so it is easy to find.
-
Note that go generate does not parse the file, so lines that look
like directives in comments or multiline strings will be treated
as directives.
@@ -72,6 +63,15 @@ arguments when it is run.
Quoted strings use Go syntax and are evaluated before execution; a
quoted string appears as a single argument to the generator.
+To convey to humans and machine tools that code is generated,
+generated source should have a line that matches the following
+regular expression (in Go syntax):
+
+ ^// Code generated .* DO NOT EDIT\.$
+
+This line must appear before the first non-comment, non-blank
+text in the file.
+
Go generate sets several variables when it runs the generator:
$GOARCH
diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go
index 94a42c4f73..38ff3823f2 100644
--- a/src/cmd/go/internal/get/get.go
+++ b/src/cmd/go/internal/get/get.go
@@ -202,7 +202,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
func downloadPaths(patterns []string) []string {
for _, arg := range patterns {
if strings.Contains(arg, "@") {
- base.Fatalf("go: cannot use path@version syntax in GOPATH mode")
+ base.Fatalf("go: can only use path@version syntax with 'go get' and 'go install' in module-aware mode")
continue
}
diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go
index 98f58441b4..e07ad0e1db 100644
--- a/src/cmd/go/internal/help/helpdoc.go
+++ b/src/cmd/go/internal/help/helpdoc.go
@@ -266,7 +266,7 @@ listed in the GOPATH environment variable.
(See 'go help gopath-get' and 'go help gopath'.)
When using modules, downloaded packages are stored in the module cache.
-(See 'go help module-get' and 'go help goproxy'.)
+See https://golang.org/ref/mod#module-cache.
When using modules, an additional variant of the go-import meta tag is
recognized and is preferred over those listing version control systems.
@@ -276,7 +276,8 @@ That variant uses "mod" as the vcs in the content value, as in:
This tag means to fetch modules with paths beginning with example.org
from the module proxy available at the URL https://code.org/moduleproxy.
-See 'go help goproxy' for details about the proxy protocol.
+See https://golang.org/ref/mod#goproxy-protocol for details about the
+proxy protocol.
Import path checking
@@ -483,6 +484,10 @@ See 'go help env' for details.
General-purpose environment variables:
+ GO111MODULE
+ Controls whether the go command runs in module-aware mode or GOPATH mode.
+ May be "off", "on", or "auto".
+ See https://golang.org/ref/mod#mod-commands.
GCCGO
The gccgo command to run for 'go build -compiler=gccgo'.
GOARCH
@@ -521,20 +526,24 @@ General-purpose environment variables:
GOPATH
For more details see: 'go help gopath'.
GOPROXY
- URL of Go module proxy. See 'go help modules'.
+ URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
+ and https://golang.org/ref/mod#module-proxy for details.
GOPRIVATE, GONOPROXY, GONOSUMDB
Comma-separated list of glob patterns (in the syntax of Go's path.Match)
of module path prefixes that should always be fetched directly
or that should not be compared against the checksum database.
- See 'go help private'.
+ See https://golang.org/ref/mod#private-modules.
GOROOT
The root of the go tree.
GOSUMDB
The name of checksum database to use and optionally its public key and
- URL. See 'go help module-auth'.
+ URL. See https://golang.org/ref/mod#authenticating.
GOTMPDIR
The directory where the go command will write
temporary source files, packages, and binaries.
+ GOVCS
+ Lists version control commands that may be used with matching servers.
+ See 'go help vcs'.
Environment variables for use with cgo:
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index ce6f579c05..b4d82d9f8c 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -89,6 +89,14 @@ to -f '{{.ImportPath}}'. The struct being passed to the template is:
TestGoFiles []string // _test.go files in package
XTestGoFiles []string // _test.go files outside package
+ // Embedded files
+ EmbedPatterns []string // //go:embed patterns
+ EmbedFiles []string // files matched by EmbedPatterns
+ TestEmbedPatterns []string // //go:embed patterns in TestGoFiles
+ TestEmbedFiles []string // files matched by TestEmbedPatterns
+ XTestEmbedPatterns []string // //go:embed patterns in XTestGoFiles
+ XTestEmbedFiles []string // files matched by XTestEmbedPatterns
+
// Cgo directives
CgoCFLAGS []string // cgo: flags for C compiler
CgoCPPFLAGS []string // cgo: flags for C preprocessor
@@ -300,7 +308,7 @@ For more about build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
-For more about modules, see 'go help modules'.
+For more about modules, see https://golang.org/ref/mod.
`,
}
@@ -577,8 +585,6 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
// Show vendor-expanded paths in listing
p.TestImports = p.Resolve(p.TestImports)
p.XTestImports = p.Resolve(p.XTestImports)
- p.TestEmbedFiles = p.ResolveEmbed(p.TestEmbedPatterns)
- p.XTestEmbedFiles = p.ResolveEmbed(p.XTestEmbedPatterns)
p.DepOnly = !cmdline[p]
if *listCompiled {
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 855f9698a2..3a274a3ad1 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -96,7 +96,7 @@ type PackagePublic struct {
// Embedded files
EmbedPatterns []string `json:",omitempty"` // //go:embed patterns
- EmbedFiles []string `json:",omitempty"` // files and directories matched by EmbedPatterns
+ EmbedFiles []string `json:",omitempty"` // files matched by EmbedPatterns
// Cgo directives
CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler
@@ -122,11 +122,11 @@ type PackagePublic struct {
TestGoFiles []string `json:",omitempty"` // _test.go files in package
TestImports []string `json:",omitempty"` // imports from TestGoFiles
TestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns
- TestEmbedFiles []string `json:",omitempty"` // //files matched by EmbedPatterns
+ TestEmbedFiles []string `json:",omitempty"` // files matched by TestEmbedPatterns
XTestGoFiles []string `json:",omitempty"` // _test.go files outside package
XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
XTestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns
- XTestEmbedFiles []string `json:",omitempty"` // //files matched by EmbedPatterns
+ XTestEmbedFiles []string `json:",omitempty"` // files matched by XTestEmbedPatterns
}
// AllFiles returns the names of all the files considered for the package.
@@ -304,7 +304,7 @@ func (p *Package) setLoadPackageDataError(err error, path string, stk *ImportSta
}
if path != stk.Top() {
- p = setErrorPos(p, importPos)
+ p.Error.setPos(importPos)
}
}
@@ -412,6 +412,9 @@ type PackageError struct {
}
func (p *PackageError) Error() string {
+ // TODO(#43696): decide when to print the stack or the position based on
+ // the error type and whether the package is in the main module.
+ // Document the rationale.
if p.Pos != "" && (len(p.ImportStack) == 0 || !p.alwaysPrintStack) {
// Omit import stack. The full path to the file where the error
// is the most important thing.
@@ -447,6 +450,15 @@ func (p *PackageError) MarshalJSON() ([]byte, error) {
return json.Marshal(perr)
}
+func (p *PackageError) setPos(posList []token.Position) {
+ if len(posList) == 0 {
+ return
+ }
+ pos := posList[0]
+ pos.Filename = base.ShortPath(pos.Filename)
+ p.Pos = pos.String()
+}
+
// ImportPathError is a type of error that prevents a package from being loaded
// for a given import path. When such a package is loaded, a *Package is
// returned with Err wrapping an ImportPathError: the error is attached to
@@ -695,17 +707,19 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
Err: ImportErrorf(path, "non-canonical import path %q: should be %q", path, pathpkg.Clean(path)),
}
p.Incomplete = true
- setErrorPos(p, importPos)
+ p.Error.setPos(importPos)
}
}
// Checked on every import because the rules depend on the code doing the importing.
if perr := disallowInternal(srcDir, parent, parentPath, p, stk); perr != p {
- return setErrorPos(perr, importPos)
+ perr.Error.setPos(importPos)
+ return perr
}
if mode&ResolveImport != 0 {
if perr := disallowVendor(srcDir, path, parentPath, p, stk); perr != p {
- return setErrorPos(perr, importPos)
+ perr.Error.setPos(importPos)
+ return perr
}
}
@@ -715,7 +729,8 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
ImportStack: stk.Copy(),
Err: ImportErrorf(path, "import %q is a program, not an importable package", path),
}
- return setErrorPos(&perr, importPos)
+ perr.Error.setPos(importPos)
+ return &perr
}
if p.Internal.Local && parent != nil && !parent.Internal.Local {
@@ -730,21 +745,13 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
ImportStack: stk.Copy(),
Err: err,
}
- return setErrorPos(&perr, importPos)
+ perr.Error.setPos(importPos)
+ return &perr
}
return p
}
-func setErrorPos(p *Package, importPos []token.Position) *Package {
- if len(importPos) > 0 {
- pos := importPos[0]
- pos.Filename = base.ShortPath(pos.Filename)
- p.Error.Pos = pos.String()
- }
- return p
-}
-
// loadPackageData loads information needed to construct a *Package. The result
// is cached, and later calls to loadPackageData for the same package will return
// the same data.
@@ -769,11 +776,7 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
}
if strings.Contains(path, "@") {
- if cfg.ModulesEnabled {
- return nil, false, errors.New("can only use path@version syntax with 'go get'")
- } else {
- return nil, false, errors.New("cannot use path@version syntax in GOPATH mode")
- }
+ return nil, false, errors.New("can only use path@version syntax with 'go get' and 'go install' in module-aware mode")
}
// Determine canonical package path and directory.
@@ -1653,7 +1656,7 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
// must be either in an explicit command-line argument,
// or on the importer side (indicated by a non-empty importPos).
if path != stk.Top() && len(importPos) > 0 {
- p = setErrorPos(p, importPos)
+ p.Error.setPos(importPos)
}
}
}
@@ -1663,11 +1666,6 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
p.setLoadPackageDataError(err, path, stk, importPos)
}
- p.EmbedFiles, p.Internal.Embed, err = p.resolveEmbed(p.EmbedPatterns)
- if err != nil {
- setError(err)
- }
-
useBindir := p.Name == "main"
if !p.Standard {
switch cfg.BuildBuildmode {
@@ -1803,9 +1801,20 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
return
}
+ // Errors after this point are caused by this package, not the importing
+ // package. Pushing the path here prevents us from reporting the error
+ // with the position of the import declaration.
stk.Push(path)
defer stk.Pop()
+ p.EmbedFiles, p.Internal.Embed, err = resolveEmbed(p.Dir, p.EmbedPatterns)
+ if err != nil {
+ p.Incomplete = true
+ setError(err)
+ embedErr := err.(*EmbedError)
+ p.Error.setPos(p.Internal.Build.EmbedPatternPos[embedErr.Pattern])
+ }
+
// Check for case-insensitive collision of input files.
// To avoid problems on case-insensitive files, we reject any package
// where two different input files have equal names under a case-insensitive
@@ -1909,35 +1918,62 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
}
}
+// An EmbedError indicates a problem with a go:embed directive.
+type EmbedError struct {
+ Pattern string
+ Err error
+}
+
+func (e *EmbedError) Error() string {
+ return fmt.Sprintf("pattern %s: %v", e.Pattern, e.Err)
+}
+
+func (e *EmbedError) Unwrap() error {
+ return e.Err
+}
+
// ResolveEmbed resolves //go:embed patterns and returns only the file list.
-// For use by go list to compute p.TestEmbedFiles and p.XTestEmbedFiles.
-func (p *Package) ResolveEmbed(patterns []string) []string {
- files, _, _ := p.resolveEmbed(patterns)
- return files
+// For use by go mod vendor to find embedded files it should copy into the
+// vendor directory.
+// TODO(#42504): Once go mod vendor uses load.PackagesAndErrors, just
+// call (*Package).ResolveEmbed
+func ResolveEmbed(dir string, patterns []string) ([]string, error) {
+ files, _, err := resolveEmbed(dir, patterns)
+ return files, err
}
// resolveEmbed resolves //go:embed patterns to precise file lists.
// It sets files to the list of unique files matched (for go list),
// and it sets pmap to the more precise mapping from
// patterns to files.
-// TODO(rsc): All these messages need position information for better error reports.
-func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[string][]string, err error) {
+func resolveEmbed(pkgdir string, patterns []string) (files []string, pmap map[string][]string, err error) {
+ var pattern string
+ defer func() {
+ if err != nil {
+ err = &EmbedError{
+ Pattern: pattern,
+ Err: err,
+ }
+ }
+ }()
+
+ // TODO(rsc): All these messages need position information for better error reports.
pmap = make(map[string][]string)
have := make(map[string]int)
dirOK := make(map[string]bool)
pid := 0 // pattern ID, to allow reuse of have map
- for _, pattern := range patterns {
+ for _, pattern = range patterns {
pid++
// Check pattern is valid for //go:embed.
if _, err := path.Match(pattern, ""); err != nil || !validEmbedPattern(pattern) {
- return nil, nil, fmt.Errorf("pattern %s: invalid pattern syntax", pattern)
+ return nil, nil, fmt.Errorf("invalid pattern syntax")
}
// Glob to find matches.
- match, err := fsys.Glob(p.Dir + string(filepath.Separator) + filepath.FromSlash(pattern))
+ match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(pattern))
if err != nil {
- return nil, nil, fmt.Errorf("pattern %s: %v", pattern, err)
+ return nil, nil, err
}
// Filter list of matches down to the ones that will still exist when
@@ -1946,7 +1982,7 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
// then there may be other things lying around, like symbolic links or .git directories.)
var list []string
for _, file := range match {
- rel := filepath.ToSlash(file[len(p.Dir)+1:]) // file, relative to p.Dir
+ rel := filepath.ToSlash(file[len(pkgdir)+1:]) // file, relative to p.Dir
what := "file"
info, err := fsys.Lstat(file)
@@ -1959,28 +1995,28 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
// Check that directories along path do not begin a new module
// (do not contain a go.mod).
- for dir := file; len(dir) > len(p.Dir)+1 && !dirOK[dir]; dir = filepath.Dir(dir) {
+ for dir := file; len(dir) > len(pkgdir)+1 && !dirOK[dir]; dir = filepath.Dir(dir) {
if _, err := fsys.Stat(filepath.Join(dir, "go.mod")); err == nil {
- return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in different module", pattern, what, rel)
+ return nil, nil, fmt.Errorf("cannot embed %s %s: in different module", what, rel)
}
if dir != file {
if info, err := fsys.Lstat(dir); err == nil && !info.IsDir() {
- return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in non-directory %s", pattern, what, rel, dir[len(p.Dir)+1:])
+ return nil, nil, fmt.Errorf("cannot embed %s %s: in non-directory %s", what, rel, dir[len(pkgdir)+1:])
}
}
dirOK[dir] = true
if elem := filepath.Base(dir); isBadEmbedName(elem) {
if dir == file {
- return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: invalid name %s", pattern, what, rel, elem)
+ return nil, nil, fmt.Errorf("cannot embed %s %s: invalid name %s", what, rel, elem)
} else {
- return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in invalid directory %s", pattern, what, rel, elem)
+ return nil, nil, fmt.Errorf("cannot embed %s %s: in invalid directory %s", what, rel, elem)
}
}
}
switch {
default:
- return nil, nil, fmt.Errorf("pattern %s: cannot embed irregular file %s", pattern, rel)
+ return nil, nil, fmt.Errorf("cannot embed irregular file %s", rel)
case info.Mode().IsRegular():
if have[rel] != pid {
@@ -1996,7 +2032,7 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
if err != nil {
return err
}
- rel := filepath.ToSlash(path[len(p.Dir)+1:])
+ rel := filepath.ToSlash(path[len(pkgdir)+1:])
name := info.Name()
if path != file && (isBadEmbedName(name) || name[0] == '.' || name[0] == '_') {
// Ignore bad names, assuming they won't go into modules.
@@ -2027,13 +2063,13 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
return nil, nil, err
}
if count == 0 {
- return nil, nil, fmt.Errorf("pattern %s: cannot embed directory %s: contains no embeddable files", pattern, rel)
+ return nil, nil, fmt.Errorf("cannot embed directory %s: contains no embeddable files", rel)
}
}
}
if len(list) == 0 {
- return nil, nil, fmt.Errorf("pattern %s: no matching files found", pattern)
+ return nil, nil, fmt.Errorf("no matching files found")
}
sort.Strings(list)
pmap[pattern] = list
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go
index d884361aaa..eb8aef3ee2 100644
--- a/src/cmd/go/internal/load/test.go
+++ b/src/cmd/go/internal/load/test.go
@@ -124,12 +124,14 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
imports = append(imports, p1)
}
var err error
- p.TestEmbedFiles, testEmbed, err = p.resolveEmbed(p.TestEmbedPatterns)
+ p.TestEmbedFiles, testEmbed, err = resolveEmbed(p.Dir, p.TestEmbedPatterns)
if err != nil && ptestErr == nil {
ptestErr = &PackageError{
ImportStack: stk.Copy(),
Err: err,
}
+ embedErr := err.(*EmbedError)
+ ptestErr.setPos(p.Internal.Build.TestEmbedPatternPos[embedErr.Pattern])
}
stk.Pop()
@@ -145,12 +147,14 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
}
p.XTestImports[i] = p1.ImportPath
}
- p.XTestEmbedFiles, xtestEmbed, err = p.resolveEmbed(p.XTestEmbedPatterns)
+ p.XTestEmbedFiles, xtestEmbed, err = resolveEmbed(p.Dir, p.XTestEmbedPatterns)
if err != nil && pxtestErr == nil {
pxtestErr = &PackageError{
ImportStack: stk.Copy(),
Err: err,
}
+ embedErr := err.(*EmbedError)
+ pxtestErr.setPos(p.Internal.Build.XTestEmbedPatternPos[embedErr.Pattern])
}
stk.Pop()
diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go
index ef1ad780c8..e7d3d869cb 100644
--- a/src/cmd/go/internal/modcmd/download.go
+++ b/src/cmd/go/internal/modcmd/download.go
@@ -52,7 +52,9 @@ corresponding to this Go struct:
The -x flag causes download to print the commands download executes.
-See 'go help modules' for more about module queries.
+See https://golang.org/ref/mod#go-mod-download for more about 'go mod download'.
+
+See https://golang.org/ref/mod#version-queries for more about version queries.
`,
}
diff --git a/src/cmd/go/internal/modcmd/edit.go b/src/cmd/go/internal/modcmd/edit.go
index 3a406b91fa..1df104eb1d 100644
--- a/src/cmd/go/internal/modcmd/edit.go
+++ b/src/cmd/go/internal/modcmd/edit.go
@@ -122,9 +122,7 @@ Note that this only describes the go.mod file itself, not other modules
referred to indirectly. For the full set of modules available to a build,
use 'go list -m -json all'.
-For example, a tool can obtain the go.mod as a data structure by
-parsing the output of 'go mod edit -json' and can then make changes
-by invoking 'go mod edit' with -require, -exclude, and so on.
+See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
`,
}
diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go
index 3277548c23..a88e9ef455 100644
--- a/src/cmd/go/internal/modcmd/graph.go
+++ b/src/cmd/go/internal/modcmd/graph.go
@@ -26,6 +26,8 @@ Graph prints the module requirement graph (with replacements applied)
in text form. Each line in the output has two space-separated fields: a module
and one of its requirements. Each module is identified as a string of the form
path@version, except for the main module, which has no @version suffix.
+
+See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
`,
Run: runGraph,
}
diff --git a/src/cmd/go/internal/modcmd/init.go b/src/cmd/go/internal/modcmd/init.go
index c081bb547d..73cc282d81 100644
--- a/src/cmd/go/internal/modcmd/init.go
+++ b/src/cmd/go/internal/modcmd/init.go
@@ -27,6 +27,8 @@ Gopkg.lock), and the current directory (if in GOPATH).
If a configuration file for a vendoring tool is present, init will attempt to
import module requirements from it.
+
+See https://golang.org/ref/mod#go-mod-init for more about 'go mod init'.
`,
Run: runInit,
}
diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go
index fb43e33ec5..3b83d87a8e 100644
--- a/src/cmd/go/internal/modcmd/tidy.go
+++ b/src/cmd/go/internal/modcmd/tidy.go
@@ -29,6 +29,8 @@ to standard error.
The -e flag causes tidy to attempt to proceed despite errors
encountered while loading packages.
+
+See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'.
`,
Run: runTidy,
}
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 1bbb57d353..d3ed9e00e2 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -7,7 +7,9 @@ package modcmd
import (
"bytes"
"context"
+ "errors"
"fmt"
+ "go/build"
"io"
"io/fs"
"os"
@@ -19,7 +21,9 @@ import (
"cmd/go/internal/cfg"
"cmd/go/internal/fsys"
"cmd/go/internal/imports"
+ "cmd/go/internal/load"
"cmd/go/internal/modload"
+ "cmd/go/internal/str"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
@@ -38,6 +42,8 @@ modules and packages to standard error.
The -e flag causes vendor to attempt to proceed despite errors
encountered while loading packages.
+
+See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
`,
Run: runVendor,
}
@@ -180,19 +186,76 @@ func moduleLine(m, r module.Version) string {
}
func vendorPkg(vdir, pkg string) {
+ // TODO(#42504): Instead of calling modload.ImportMap then build.ImportDir,
+ // just call load.PackagesAndErrors. To do that, we need to add a good way
+ // to ignore build constraints.
realPath := modload.ImportMap(pkg)
if realPath != pkg && modload.ImportMap(realPath) != "" {
fmt.Fprintf(os.Stderr, "warning: %s imported as both %s and %s; making two copies.\n", realPath, realPath, pkg)
}
+ copiedFiles := make(map[string]bool)
dst := filepath.Join(vdir, pkg)
src := modload.PackageDir(realPath)
if src == "" {
fmt.Fprintf(os.Stderr, "internal error: no pkg for %s -> %s\n", pkg, realPath)
}
- copyDir(dst, src, matchPotentialSourceFile)
+ copyDir(dst, src, matchPotentialSourceFile, copiedFiles)
if m := modload.PackageModule(realPath); m.Path != "" {
- copyMetadata(m.Path, realPath, dst, src)
+ copyMetadata(m.Path, realPath, dst, src, copiedFiles)
+ }
+
+ ctx := build.Default
+ ctx.UseAllFiles = true
+ bp, err := ctx.ImportDir(src, build.IgnoreVendor)
+ // Because UseAllFiles is set on the build.Context, it's possible ta get
+ // a MultiplePackageError on an otherwise valid package: the package could
+ // have different names for GOOS=windows and GOOS=mac for example. On the
+ // other hand if there's a NoGoError, the package might have source files
+ // specifying "// +build ignore" those packages should be skipped because
+ // embeds from ignored files can't be used.
+ // TODO(#42504): Find a better way to avoid errors from ImportDir. We'll
+ // need to figure this out when we switch to PackagesAndErrors as per the
+ // TODO above.
+ var multiplePackageError *build.MultiplePackageError
+ var noGoError *build.NoGoError
+ if err != nil {
+ if errors.As(err, &noGoError) {
+ return // No source files in this package are built. Skip embeds in ignored files.
+ } else if !errors.As(err, &multiplePackageError) { // multiplePackgeErrors are okay, but others are not.
+ base.Fatalf("internal error: failed to find embedded files of %s: %v\n", pkg, err)
+ }
+ }
+ embedPatterns := str.StringList(bp.EmbedPatterns, bp.TestEmbedPatterns, bp.XTestEmbedPatterns)
+ embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns)
+ if err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
+ for _, embed := range embeds {
+ embedDst := filepath.Join(dst, embed)
+ if copiedFiles[embedDst] {
+ continue
+ }
+
+ // Copy the file as is done by copyDir below.
+ r, err := os.Open(filepath.Join(src, embed))
+ if err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
+ if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
+ w, err := os.Create(embedDst)
+ if err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
+ if _, err := io.Copy(w, r); err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
+ r.Close()
+ if err := w.Close(); err != nil {
+ base.Fatalf("go mod vendor: %v", err)
+ }
}
}
@@ -205,14 +268,14 @@ var copiedMetadata = make(map[metakey]bool)
// copyMetadata copies metadata files from parents of src to parents of dst,
// stopping after processing the src parent for modPath.
-func copyMetadata(modPath, pkg, dst, src string) {
+func copyMetadata(modPath, pkg, dst, src string, copiedFiles map[string]bool) {
for parent := 0; ; parent++ {
if copiedMetadata[metakey{modPath, dst}] {
break
}
copiedMetadata[metakey{modPath, dst}] = true
if parent > 0 {
- copyDir(dst, src, matchMetadata)
+ copyDir(dst, src, matchMetadata, copiedFiles)
}
if modPath == pkg {
break
@@ -280,7 +343,7 @@ func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
}
// copyDir copies all regular files satisfying match(info) from src to dst.
-func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool) {
+func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool, copiedFiles map[string]bool) {
files, err := os.ReadDir(src)
if err != nil {
base.Fatalf("go mod vendor: %v", err)
@@ -292,11 +355,14 @@ func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool) {
if file.IsDir() || !file.Type().IsRegular() || !match(src, file) {
continue
}
+ copiedFiles[file.Name()] = true
r, err := os.Open(filepath.Join(src, file.Name()))
if err != nil {
base.Fatalf("go mod vendor: %v", err)
}
- w, err := os.Create(filepath.Join(dst, file.Name()))
+ dstPath := filepath.Join(dst, file.Name())
+ copiedFiles[dstPath] = true
+ w, err := os.Create(dstPath)
if err != nil {
base.Fatalf("go mod vendor: %v", err)
}
diff --git a/src/cmd/go/internal/modcmd/verify.go b/src/cmd/go/internal/modcmd/verify.go
index c83e70076a..8321429131 100644
--- a/src/cmd/go/internal/modcmd/verify.go
+++ b/src/cmd/go/internal/modcmd/verify.go
@@ -31,6 +31,8 @@ modified since being downloaded. If all the modules are unmodified,
verify prints "all modules verified." Otherwise it reports which
modules have been changed and causes 'go mod' to exit with a
non-zero status.
+
+See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
`,
Run: runVerify,
}
diff --git a/src/cmd/go/internal/modcmd/why.go b/src/cmd/go/internal/modcmd/why.go
index e287c88060..a5f3e8afcb 100644
--- a/src/cmd/go/internal/modcmd/why.go
+++ b/src/cmd/go/internal/modcmd/why.go
@@ -48,6 +48,8 @@ For example:
# golang.org/x/text/encoding
(main module does not need package golang.org/x/text/encoding)
$
+
+See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
`,
}
diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go
index 86c1c14d4a..378fbae34f 100644
--- a/src/cmd/go/internal/modfetch/codehost/codehost.go
+++ b/src/cmd/go/internal/modfetch/codehost/codehost.go
@@ -10,10 +10,10 @@ import (
"bytes"
"crypto/sha256"
"fmt"
+ exec "internal/execabs"
"io"
"io/fs"
"os"
- "os/exec"
"path/filepath"
"strings"
"sync"
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index 8abc039e7f..72005e27d5 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -8,11 +8,11 @@ import (
"bytes"
"errors"
"fmt"
+ exec "internal/execabs"
"io"
"io/fs"
"net/url"
"os"
- "os/exec"
"path/filepath"
"sort"
"strconv"
diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go
index debeb3f319..c55c3cf253 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -768,90 +768,14 @@ var HelpModuleAuth = &base.Command{
UsageLine: "module-auth",
Short: "module authentication using go.sum",
Long: `
-The go command tries to authenticate every downloaded module,
-checking that the bits downloaded for a specific module version today
-match bits downloaded yesterday. This ensures repeatable builds
-and detects introduction of unexpected changes, malicious or not.
-
-In each module's root, alongside go.mod, the go command maintains
-a file named go.sum containing the cryptographic checksums of the
-module's dependencies.
-
-The form of each line in go.sum is three fields:
-
- <module> <version>[/go.mod] <hash>
-
-Each known module version results in two lines in the go.sum file.
-The first line gives the hash of the module version's file tree.
-The second line appends "/go.mod" to the version and gives the hash
-of only the module version's (possibly synthesized) go.mod file.
-The go.mod-only hash allows downloading and authenticating a
-module version's go.mod file, which is needed to compute the
-dependency graph, without also downloading all the module's source code.
-
-The hash begins with an algorithm prefix of the form "h<N>:".
-The only defined algorithm prefix is "h1:", which uses SHA-256.
-
-Module authentication failures
-
-The go command maintains a cache of downloaded packages and computes
-and records the cryptographic checksum of each package at download time.
-In normal operation, the go command checks the main module's go.sum file
-against these precomputed checksums instead of recomputing them on
-each command invocation. The 'go mod verify' command checks that
-the cached copies of module downloads still match both their recorded
-checksums and the entries in go.sum.
-
-In day-to-day development, the checksum of a given module version
-should never change. Each time a dependency is used by a given main
-module, the go command checks its local cached copy, freshly
-downloaded or not, against the main module's go.sum. If the checksums
-don't match, the go command reports the mismatch as a security error
-and refuses to run the build. When this happens, proceed with caution:
-code changing unexpectedly means today's build will not match
-yesterday's, and the unexpected change may not be beneficial.
-
-If the go command reports a mismatch in go.sum, the downloaded code
-for the reported module version does not match the one used in a
-previous build of the main module. It is important at that point
-to find out what the right checksum should be, to decide whether
-go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
-you want to use the same code you used yesterday.
-
-If a downloaded module is not yet included in go.sum and it is a publicly
-available module, the go command consults the Go checksum database to fetch
-the expected go.sum lines. If the downloaded code does not match those
-lines, the go command reports the mismatch and exits. Note that the
-database is not consulted for module versions already listed in go.sum.
-
-If a go.sum mismatch is reported, it is always worth investigating why
-the code downloaded today differs from what was downloaded yesterday.
-
-The GOSUMDB environment variable identifies the name of checksum database
-to use and optionally its public key and URL, as in:
-
- GOSUMDB="sum.golang.org"
- GOSUMDB="sum.golang.org+<publickey>"
- GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
-
-The go command knows the public key of sum.golang.org, and also that the name
-sum.golang.google.cn (available inside mainland China) connects to the
-sum.golang.org checksum database; use of any other database requires giving
-the public key explicitly.
-The URL defaults to "https://" followed by the database name.
-
-GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
-See https://sum.golang.org/privacy for the service's privacy policy.
-
-If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
-the checksum database is not consulted, and all unrecognized modules are
-accepted, at the cost of giving up the security guarantee of verified repeatable
-downloads for all modules. A better way to bypass the checksum database
-for specific modules is to use the GOPRIVATE or GONOSUMDB environment
-variables. See 'go help private' for details.
-
-The 'go env -w' command (see 'go help env') can be used to set these variables
-for future go command invocations.
+When the go command downloads a module zip file or go.mod file into the
+module cache, it computes a cryptographic hash and compares it with a known
+value to verify the file hasn't changed since it was first downloaded. Known
+hashes are stored in a file in the module root directory named go.sum. Hashes
+may also be downloaded from the checksum database depending on the values of
+GOSUMDB, GOPRIVATE, and GONOSUMDB.
+
+For details, see https://golang.org/ref/mod#authenticating.
`,
}
@@ -865,8 +789,8 @@ regardless of source, against the public Go checksum database at sum.golang.org.
These defaults work well for publicly available source code.
The GOPRIVATE environment variable controls which modules the go command
-considers to be private (not available publicly) and should therefore not use the
-proxy or checksum database. The variable is a comma-separated list of
+considers to be private (not available publicly) and should therefore not use
+the proxy or checksum database. The variable is a comma-separated list of
glob patterns (in the syntax of Go's path.Match) of module path prefixes.
For example,
@@ -876,10 +800,6 @@ causes the go command to treat as private any module with a path prefix
matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
and rsc.io/private/quux.
-The GOPRIVATE environment variable may be used by other tools as well to
-identify non-public modules. For example, an editor could use GOPRIVATE
-to decide whether to hyperlink a package import to a godoc.org page.
-
For fine-grained control over module download and validation, the GONOPROXY
and GONOSUMDB environment variables accept the same kind of glob list
and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -892,12 +812,6 @@ users would configure go using:
GOPROXY=proxy.example.com
GONOPROXY=none
-This would tell the go command and other tools that modules beginning with
-a corp.example.com subdomain are private but that the company proxy should
-be used for downloading both public and private modules, because
-GONOPROXY has been set to a pattern that won't match any modules,
-overriding GOPRIVATE.
-
The GOPRIVATE variable is also used to define the "public" and "private"
patterns for the GOVCS variable; see 'go help vcs'. For that usage,
GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
@@ -905,5 +819,7 @@ instead of module paths.
The 'go env -w' command (see 'go help env') can be used to set these variables
for future go command invocations.
+
+For more details, see https://golang.org/ref/mod#private-modules.
`,
}
diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go
index d75b4da521..6c86d8d786 100644
--- a/src/cmd/go/internal/modfetch/proxy.go
+++ b/src/cmd/go/internal/modfetch/proxy.go
@@ -36,65 +36,8 @@ URLs of a specified form. The requests have no query parameters, so even
a site serving from a fixed file system (including a file:/// URL)
can be a module proxy.
-The GET requests sent to a Go module proxy are:
-
-GET $GOPROXY/<module>/@v/list returns a list of known versions of the given
-module, one per line.
-
-GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata
-about that version of the given module.
-
-GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file
-for that version of the given module.
-
-GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive
-for that version of the given module.
-
-GET $GOPROXY/<module>/@latest returns JSON-formatted metadata about the
-latest known version of the given module in the same format as
-<module>/@v/<version>.info. The latest version should be the version of
-the module the go command may use if <module>/@v/list is empty or no
-listed version is suitable. <module>/@latest is optional and may not
-be implemented by a module proxy.
-
-When resolving the latest version of a module, the go command will request
-<module>/@v/list, then, if no suitable versions are found, <module>/@latest.
-The go command prefers, in order: the semantically highest release version,
-the semantically highest pre-release version, and the chronologically
-most recent pseudo-version. In Go 1.12 and earlier, the go command considered
-pseudo-versions in <module>/@v/list to be pre-release versions, but this is
-no longer true since Go 1.13.
-
-To avoid problems when serving from case-sensitive file systems,
-the <module> and <version> elements are case-encoded, replacing every
-uppercase letter with an exclamation mark followed by the corresponding
-lower-case letter: github.com/Azure encodes as github.com/!azure.
-
-The JSON-formatted metadata about a given module corresponds to
-this Go data structure, which may be expanded in the future:
-
- type Info struct {
- Version string // version string
- Time time.Time // commit time
- }
-
-The zip archive for a specific version of a given module is a
-standard zip file that contains the file tree corresponding
-to the module's source code and related files. The archive uses
-slash-separated paths, and every file path in the archive must
-begin with <module>@<version>/, where the module and version are
-substituted directly, not case-encoded. The root of the module
-file tree corresponds to the <module>@<version>/ prefix in the
-archive.
-
-Even when downloading directly from version control systems,
-the go command synthesizes explicit info, mod, and zip files
-and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
-the same as if it had downloaded them directly from a proxy.
-The cache layout is the same as the proxy URL space, so
-serving $GOPATH/pkg/mod/cache/download at (or copying it to)
-https://example.com/proxy would let other users access those
-cached module versions with GOPROXY=https://example.com/proxy.
+For details on the GOPROXY protocol, see
+https://golang.org/ref/mod#goproxy-protocol.
`,
}
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go
index 8463ec4e9c..574f3e194d 100644
--- a/src/cmd/go/internal/modget/get.go
+++ b/src/cmd/go/internal/modget/get.go
@@ -56,85 +56,49 @@ var CmdGet = &base.Command{
UsageLine: "go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]",
Short: "add dependencies to current module and install them",
Long: `
-Get resolves and adds dependencies to the current development module
-and then builds and installs them.
-
-The first step is to resolve which dependencies to add.
-
-For each named package or package pattern, get must decide which version of
-the corresponding module to use. By default, get looks up the latest tagged
-release version, such as v0.4.5 or v1.2.3. If there are no tagged release
-versions, get looks up the latest tagged pre-release version, such as
-v0.0.1-pre1. If there are no tagged versions at all, get looks up the latest
-known commit. If the module is not already required at a later version
-(for example, a pre-release newer than the latest release), get will use
-the version it looked up. Otherwise, get will use the currently
-required version.
-
-This default version selection can be overridden by adding an @version
-suffix to the package argument, as in 'go get golang.org/x/text@v0.3.0'.
-The version may be a prefix: @v1 denotes the latest available version starting
-with v1. See 'go help modules' under the heading 'Module queries' for the
-full query syntax.
-
-For modules stored in source control repositories, the version suffix can
-also be a commit hash, branch identifier, or other syntax known to the
-source control system, as in 'go get golang.org/x/text@master'. Note that
-branches with names that overlap with other module query syntax cannot be
-selected explicitly. For example, the suffix @v2 means the latest version
-starting with v2, not the branch named v2.
-
-If a module under consideration is already a dependency of the current
-development module, then get will update the required version.
-Specifying a version earlier than the current required version is valid and
-downgrades the dependency. The version suffix @none indicates that the
-dependency should be removed entirely, downgrading or removing modules
-depending on it as needed.
-
-The version suffix @latest explicitly requests the latest minor release of
-the module named by the given path. The suffix @upgrade is like @latest but
-will not downgrade a module if it is already required at a revision or
-pre-release version newer than the latest released version. The suffix
-@patch requests the latest patch release: the latest released version
-with the same major and minor version numbers as the currently required
-version. Like @upgrade, @patch will not downgrade a module already required
-at a newer version. If the path is not already required, @upgrade is
-equivalent to @latest, and @patch is disallowed.
-
-Although get defaults to using the latest version of the module containing
-a named package, it does not use the latest version of that module's
-dependencies. Instead it prefers to use the specific dependency versions
-requested by that module. For example, if the latest A requires module
-B v1.2.3, while B v1.2.4 and v1.3.1 are also available, then 'go get A'
-will use the latest A but then use B v1.2.3, as requested by A. (If there
-are competing requirements for a particular module, then 'go get' resolves
-those requirements by taking the maximum requested version.)
+Get resolves its command-line arguments to packages at specific module versions,
+updates go.mod to require those versions, downloads source code into the
+module cache, then builds and installs the named packages.
+
+To add a dependency for a package or upgrade it to its latest version:
+
+ go get example.com/pkg
+
+To upgrade or downgrade a package to a specific version:
+
+ go get example.com/pkg@v1.2.3
+
+To remove a dependency on a module and downgrade modules that require it:
+
+ go get example.com/mod@none
+
+See https://golang.org/ref/mod#go-get for details.
+
+The 'go install' command may be used to build and install packages. When a
+version is specified, 'go install' runs in module-aware mode and ignores
+the go.mod file in the current directory. For example:
+
+ go install example.com/pkg@v1.2.3
+ go install example.com/pkg@latest
+
+See 'go help install' or https://golang.org/ref/mod#go-install for details.
+
+In addition to build flags (listed in 'go help build') 'go get' accepts the
+following flags.
The -t flag instructs get to consider modules needed to build tests of
packages specified on the command line.
The -u flag instructs get to update modules providing dependencies
of packages named on the command line to use newer minor or patch
-releases when available. Continuing the previous example, 'go get -u A'
-will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C,
-but C does not provide any packages needed to build packages in A
-(not including tests), then C will not be updated.
+releases when available.
The -u=patch flag (not -u patch) also instructs get to update dependencies,
but changes the default to select patch releases.
-Continuing the previous example,
-'go get -u=patch A@latest' will use the latest A with B v1.2.4 (not B v1.2.3),
-while 'go get -u=patch A' will use a patch release of A instead.
When the -t and -u flags are used together, get will update
test dependencies as well.
-In general, adding a new dependency may require upgrading
-existing dependencies to keep a working build, and 'go get' does
-this automatically. Similarly, downgrading one dependency may
-require downgrading other dependencies, and 'go get' does
-this automatically as well.
-
The -insecure flag permits fetching from repositories and resolving
custom domains using insecure schemes such as HTTP, and also bypassess
module sum validation using the checksum database. Use with caution.
@@ -143,12 +107,8 @@ To permit the use of insecure schemes, use the GOINSECURE environment
variable instead. To bypass module sum validation, use GOPRIVATE or
GONOSUMDB. See 'go help environment' for details.
-The second step is to download (if needed), build, and install
-the named packages.
-
-The -d flag instructs get to skip this step, downloading source code
-needed to build the named packages and their dependencies, but not
-building or installing.
+The -d flag instructs get not to build or install packages. get will only
+update go.mod and download source code needed to build packages.
Building and installing packages with get is deprecated. In a future release,
the -d flag will be enabled by default, and 'go get' will be only be used to
@@ -157,31 +117,14 @@ dependencies from the current module, use 'go install'. To install a package
ignoring the current module, use 'go install' with an @version suffix like
"@latest" after each argument.
-If an argument names a module but not a package (because there is no
-Go source code in the module's root directory), then the install step
-is skipped for that argument, instead of causing a build failure.
-For example 'go get golang.org/x/perf' succeeds even though there
-is no code corresponding to that import path.
-
-Note that package patterns are allowed and are expanded after resolving
-the module versions. For example, 'go get golang.org/x/perf/cmd/...'
-adds the latest golang.org/x/perf and then installs the commands in that
-latest version.
-
-With no package arguments, 'go get' applies to Go package in the
-current directory, if any. In particular, 'go get -u' and
-'go get -u=patch' update all the dependencies of that package.
-With no package arguments and also without -u, 'go get' is not much more
-than 'go install', and 'go get -d' not much more than 'go list'.
-
-For more about modules, see 'go help modules'.
+For more about modules, see https://golang.org/ref/mod.
For more about specifying packages, see 'go help packages'.
This text describes the behavior of get using modules to manage source
code and dependencies. If instead the go command is running in GOPATH
mode, the details of get's flags and effects change, as does 'go help get'.
-See 'go help modules' and 'go help gopath-get'.
+See 'go help gopath-get'.
See also: go build, go install, go clean, go mod.
`,
@@ -1558,7 +1501,7 @@ func (r *resolver) checkPackagesAndRetractions(ctx context.Context, pkgPatterns
}
}
if retractPath != "" {
- fmt.Fprintf(os.Stderr, "go: run 'go get %s@latest' to switch to the latest unretracted version\n", retractPath)
+ fmt.Fprintf(os.Stderr, "go: to switch to the latest unretracted version, run:\n\tgo get %s@latest", retractPath)
}
}
diff --git a/src/cmd/go/internal/modget/query.go b/src/cmd/go/internal/modget/query.go
index 20eb0b6364..d8364c8c0d 100644
--- a/src/cmd/go/internal/modget/query.go
+++ b/src/cmd/go/internal/modget/query.go
@@ -281,14 +281,14 @@ func reportError(q *query, err error) {
// TODO(bcmills): Use errors.As to unpack these errors instead of parsing
// strings with regular expressions.
- patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:)\"`]|$)")
+ patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:;)\"`]|$)")
if patternRE.MatchString(errStr) {
if q.rawVersion == "" {
base.Errorf("go get: %s", errStr)
return
}
- versionRE := regexp.MustCompile("(?m)(?:[ @(\"`]|^)" + regexp.QuoteMeta(q.version) + "(?:[ :)\"`]|$)")
+ versionRE := regexp.MustCompile("(?m)(?:[ @(\"`]|^)" + regexp.QuoteMeta(q.version) + "(?:[ :;)\"`]|$)")
if versionRE.MatchString(errStr) {
base.Errorf("go get: %s", errStr)
return
diff --git a/src/cmd/go/internal/modload/help.go b/src/cmd/go/internal/modload/help.go
index d81dfd56fb..1cb58961be 100644
--- a/src/cmd/go/internal/modload/help.go
+++ b/src/cmd/go/internal/modload/help.go
@@ -12,395 +12,16 @@ var HelpModules = &base.Command{
UsageLine: "modules",
Short: "modules, module versions, and more",
Long: `
-A module is a collection of related Go packages.
-Modules are the unit of source code interchange and versioning.
-The go command has direct support for working with modules,
-including recording and resolving dependencies on other modules.
-Modules replace the old GOPATH-based approach to specifying
-which source files are used in a given build.
+Modules are how Go manages dependencies.
-Module support
+A module is a collection of packages that are released, versioned, and
+distributed together. Modules may be downloaded directly from version control
+repositories or from module proxy servers.
-The go command includes support for Go modules. Module-aware mode is active
-by default whenever a go.mod file is found in the current directory or in
-any parent directory.
+For a series of tutorials on modules, see
+https://golang.org/doc/tutorial/create-module.
-The quickest way to take advantage of module support is to check out your
-repository, create a go.mod file (described in the next section) there, and run
-go commands from within that file tree.
-
-For more fine-grained control, the go command continues to respect
-a temporary environment variable, GO111MODULE, which can be set to one
-of three string values: off, on, or auto (the default).
-If GO111MODULE=on, then the go command requires the use of modules,
-never consulting GOPATH. We refer to this as the command
-being module-aware or running in "module-aware mode".
-If GO111MODULE=off, then the go command never uses
-module support. Instead it looks in vendor directories and GOPATH
-to find dependencies; we now refer to this as "GOPATH mode."
-If GO111MODULE=auto or is unset, then the go command enables or disables
-module support based on the current directory.
-Module support is enabled only when the current directory contains a
-go.mod file or is below a directory containing a go.mod file.
-
-In module-aware mode, GOPATH no longer defines the meaning of imports
-during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
-and installed commands (in GOPATH/bin, unless GOBIN is set).
-
-Defining a module
-
-A module is defined by a tree of Go source files with a go.mod file
-in the tree's root directory. The directory containing the go.mod file
-is called the module root. Typically the module root will also correspond
-to a source code repository root (but in general it need not).
-The module is the set of all Go packages in the module root and its
-subdirectories, but excluding subtrees with their own go.mod files.
-
-The "module path" is the import path prefix corresponding to the module root.
-The go.mod file defines the module path and lists the specific versions
-of other modules that should be used when resolving imports during a build,
-by giving their module paths and versions.
-
-For example, this go.mod declares that the directory containing it is the root
-of the module with path example.com/m, and it also declares that the module
-depends on specific versions of golang.org/x/text and gopkg.in/yaml.v2:
-
- module example.com/m
-
- require (
- golang.org/x/text v0.3.0
- gopkg.in/yaml.v2 v2.1.0
- )
-
-The go.mod file can also specify replacements and excluded versions
-that only apply when building the module directly; they are ignored
-when the module is incorporated into a larger build.
-For more about the go.mod file, see 'go help go.mod'.
-
-To start a new module, simply create a go.mod file in the root of the
-module's directory tree, containing only a module statement.
-The 'go mod init' command can be used to do this:
-
- go mod init example.com/m
-
-In a project already using an existing dependency management tool like
-godep, glide, or dep, 'go mod init' will also add require statements
-matching the existing configuration.
-
-Once the go.mod file exists, no additional steps are required:
-go commands like 'go build', 'go test', or even 'go list' will automatically
-add new dependencies as needed to satisfy imports.
-
-The main module and the build list
-
-The "main module" is the module containing the directory where the go command
-is run. The go command finds the module root by looking for a go.mod in the
-current directory, or else the current directory's parent directory,
-or else the parent's parent directory, and so on.
-
-The main module's go.mod file defines the precise set of packages available
-for use by the go command, through require, replace, and exclude statements.
-Dependency modules, found by following require statements, also contribute
-to the definition of that set of packages, but only through their go.mod
-files' require statements: any replace and exclude statements in dependency
-modules are ignored. The replace and exclude statements therefore allow the
-main module complete control over its own build, without also being subject
-to complete control by dependencies.
-
-The set of modules providing packages to builds is called the "build list".
-The build list initially contains only the main module. Then the go command
-adds to the list the exact module versions required by modules already
-on the list, recursively, until there is nothing left to add to the list.
-If multiple versions of a particular module are added to the list,
-then at the end only the latest version (according to semantic version
-ordering) is kept for use in the build.
-
-The 'go list' command provides information about the main module
-and the build list. For example:
-
- go list -m # print path of main module
- go list -m -f={{.Dir}} # print root directory of main module
- go list -m all # print build list
-
-Maintaining module requirements
-
-The go.mod file is meant to be readable and editable by both programmers and
-tools. Most updates to dependencies can be performed using "go get" and
-"go mod tidy". Other module-aware build commands may be invoked using the
--mod=mod flag to automatically add missing requirements and fix inconsistencies.
-
-The "go get" command updates go.mod to change the module versions used in a
-build. An upgrade of one module may imply upgrading others, and similarly a
-downgrade of one module may imply downgrading others. The "go get" command
-makes these implied changes as well. See "go help module-get".
-
-The "go mod" command provides other functionality for use in maintaining
-and understanding modules and go.mod files. See "go help mod", particularly
-"go help mod tidy" and "go help mod edit".
-
-As part of maintaining the require statements in go.mod, the go command
-tracks which ones provide packages imported directly by the current module
-and which ones provide packages only used indirectly by other module
-dependencies. Requirements needed only for indirect uses are marked with a
-"// indirect" comment in the go.mod file. Indirect requirements may be
-automatically removed from the go.mod file once they are implied by other
-direct requirements. Indirect requirements only arise when using modules
-that fail to state some of their own dependencies or when explicitly
-upgrading a module's dependencies ahead of its own stated requirements.
-
-The -mod build flag provides additional control over the updating and use of
-go.mod for commands that build packages like "go build" and "go test".
-
-If invoked with -mod=readonly (the default in most situations), the go command
-reports an error if a package named on the command line or an imported package
-is not provided by any module in the build list computed from the main module's
-requirements. The go command also reports an error if a module's checksum is
-missing from go.sum (see Module downloading and verification). Either go.mod or
-go.sum must be updated in these situations.
-
-If invoked with -mod=mod, the go command automatically updates go.mod and
-go.sum, fixing inconsistencies and adding missing requirements and checksums
-as needed. If the go command finds an unfamiliar import, it looks up the
-module containing that import and adds a requirement for the latest version
-of that module to go.mod. In most cases, therefore, one may add an import to
-source code and run "go build", "go test", or even "go list" with -mod=mod:
-as part of analyzing the package, the go command will resolve the import and
-update the go.mod file.
-
-If invoked with -mod=vendor, the go command loads packages from the main
-module's vendor directory instead of downloading modules to and loading packages
-from the module cache. The go command assumes the vendor directory holds
-correct copies of dependencies, and it does not compute the set of required
-module versions from go.mod files. However, the go command does check that
-vendor/modules.txt (generated by "go mod vendor") contains metadata consistent
-with go.mod.
-
-If the go command is not invoked with a -mod flag, and the vendor directory
-is present, and the "go" version in go.mod is 1.14 or higher, the go command
-will act as if it were invoked with -mod=vendor. Otherwise, the -mod flag
-defaults to -mod=readonly.
-
-Note that neither "go get" nor the "go mod" subcommands accept the -mod flag.
-
-Pseudo-versions
-
-The go.mod file and the go command more generally use semantic versions as
-the standard form for describing module versions, so that versions can be
-compared to determine which should be considered earlier or later than another.
-A module version like v1.2.3 is introduced by tagging a revision in the
-underlying source repository. Untagged revisions can be referred to
-using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef,
-where the time is the commit time in UTC and the final suffix is the prefix
-of the commit hash. The time portion ensures that two pseudo-versions can
-be compared to determine which happened later, the commit hash identifes
-the underlying commit, and the prefix (v0.0.0- in this example) is derived from
-the most recent tagged version in the commit graph before this commit.
-
-There are three pseudo-version forms:
-
-vX.0.0-yyyymmddhhmmss-abcdefabcdef is used when there is no earlier
-versioned commit with an appropriate major version before the target commit.
-(This was originally the only form, so some older go.mod files use this form
-even for commits that do follow tags.)
-
-vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef is used when the most
-recent versioned commit before the target commit is vX.Y.Z-pre.
-
-vX.Y.(Z+1)-0.yyyymmddhhmmss-abcdefabcdef is used when the most
-recent versioned commit before the target commit is vX.Y.Z.
-
-Pseudo-versions never need to be typed by hand: the go command will accept
-the plain commit hash and translate it into a pseudo-version (or a tagged
-version if available) automatically. This conversion is an example of a
-module query.
-
-Module queries
-
-The go command accepts a "module query" in place of a module version
-both on the command line and in the main module's go.mod file.
-(After evaluating a query found in the main module's go.mod file,
-the go command updates the file to replace the query with its result.)
-
-A fully-specified semantic version, such as "v1.2.3",
-evaluates to that specific version.
-
-A semantic version prefix, such as "v1" or "v1.2",
-evaluates to the latest available tagged version with that prefix.
-
-A semantic version comparison, such as "<v1.2.3" or ">=v1.5.6",
-evaluates to the available tagged version nearest to the comparison target
-(the latest version for < and <=, the earliest version for > and >=).
-
-The string "latest" matches the latest available tagged version,
-or else the underlying source repository's latest untagged revision.
-
-The string "upgrade" is like "latest", but if the module is
-currently required at a later version than the version "latest"
-would select (for example, a newer pre-release version), "upgrade"
-will select the later version instead.
-
-The string "patch" matches the latest available tagged version
-of a module with the same major and minor version numbers as the
-currently required version. If no version is currently required,
-"patch" is equivalent to "latest".
-
-A revision identifier for the underlying source repository, such as
-a commit hash prefix, revision tag, or branch name, selects that
-specific code revision. If the revision is also tagged with a
-semantic version, the query evaluates to that semantic version.
-Otherwise the query evaluates to a pseudo-version for the commit.
-Note that branches and tags with names that are matched by other
-query syntax cannot be selected this way. For example, the query
-"v2" means the latest version starting with "v2", not the branch
-named "v2".
-
-All queries prefer release versions to pre-release versions.
-For example, "<v1.2.3" will prefer to return "v1.2.2"
-instead of "v1.2.3-pre1", even though "v1.2.3-pre1" is nearer
-to the comparison target.
-
-Module versions disallowed by exclude statements in the
-main module's go.mod are considered unavailable and cannot
-be returned by queries.
-
-For example, these commands are all valid:
-
- go get github.com/gorilla/mux@latest # same (@latest is default for 'go get')
- go get github.com/gorilla/mux@v1.6.2 # records v1.6.2
- go get github.com/gorilla/mux@e3702bed2 # records v1.6.2
- go get github.com/gorilla/mux@c856192 # records v0.0.0-20180517173623-c85619274f5d
- go get github.com/gorilla/mux@master # records current meaning of master
-
-Module compatibility and semantic versioning
-
-The go command requires that modules use semantic versions and expects that
-the versions accurately describe compatibility: it assumes that v1.5.4 is a
-backwards-compatible replacement for v1.5.3, v1.4.0, and even v1.0.0.
-More generally the go command expects that packages follow the
-"import compatibility rule", which says:
-
-"If an old package and a new package have the same import path,
-the new package must be backwards compatible with the old package."
-
-Because the go command assumes the import compatibility rule,
-a module definition can only set the minimum required version of one
-of its dependencies: it cannot set a maximum or exclude selected versions.
-Still, the import compatibility rule is not a guarantee: it may be that
-v1.5.4 is buggy and not a backwards-compatible replacement for v1.5.3.
-Because of this, the go command never updates from an older version
-to a newer version of a module unasked.
-
-In semantic versioning, changing the major version number indicates a lack
-of backwards compatibility with earlier versions. To preserve import
-compatibility, the go command requires that modules with major version v2
-or later use a module path with that major version as the final element.
-For example, version v2.0.0 of example.com/m must instead use module path
-example.com/m/v2, and packages in that module would use that path as
-their import path prefix, as in example.com/m/v2/sub/pkg. Including the
-major version number in the module path and import paths in this way is
-called "semantic import versioning". Pseudo-versions for modules with major
-version v2 and later begin with that major version instead of v0, as in
-v2.0.0-20180326061214-4fc5987536ef.
-
-As a special case, module paths beginning with gopkg.in/ continue to use the
-conventions established on that system: the major version is always present,
-and it is preceded by a dot instead of a slash: gopkg.in/yaml.v1
-and gopkg.in/yaml.v2, not gopkg.in/yaml and gopkg.in/yaml/v2.
-
-The go command treats modules with different module paths as unrelated:
-it makes no connection between example.com/m and example.com/m/v2.
-Modules with different major versions can be used together in a build
-and are kept separate by the fact that their packages use different
-import paths.
-
-In semantic versioning, major version v0 is for initial development,
-indicating no expectations of stability or backwards compatibility.
-Major version v0 does not appear in the module path, because those
-versions are preparation for v1.0.0, and v1 does not appear in the
-module path either.
-
-Code written before the semantic import versioning convention
-was introduced may use major versions v2 and later to describe
-the same set of unversioned import paths as used in v0 and v1.
-To accommodate such code, if a source code repository has a
-v2.0.0 or later tag for a file tree with no go.mod, the version is
-considered to be part of the v1 module's available versions
-and is given an +incompatible suffix when converted to a module
-version, as in v2.0.0+incompatible. The +incompatible tag is also
-applied to pseudo-versions derived from such versions, as in
-v2.0.1-0.yyyymmddhhmmss-abcdefabcdef+incompatible.
-
-In general, having a dependency in the build list (as reported by 'go list -m all')
-on a v0 version, pre-release version, pseudo-version, or +incompatible version
-is an indication that problems are more likely when upgrading that
-dependency, since there is no expectation of compatibility for those.
-
-See https://research.swtch.com/vgo-import for more information about
-semantic import versioning, and see https://semver.org/ for more about
-semantic versioning.
-
-Module code layout
-
-For now, see https://research.swtch.com/vgo-module for information
-about how source code in version control systems is mapped to
-module file trees.
-
-Module downloading and verification
-
-The go command can fetch modules from a proxy or connect to source control
-servers directly, according to the setting of the GOPROXY environment
-variable (see 'go help env'). The default setting for GOPROXY is
-"https://proxy.golang.org,direct", which means to try the
-Go module mirror run by Google and fall back to a direct connection
-if the proxy reports that it does not have the module (HTTP error 404 or 410).
-See https://proxy.golang.org/privacy for the service's privacy policy.
-
-If GOPROXY is set to the string "direct", downloads use a direct connection to
-source control servers. Setting GOPROXY to "off" disallows downloading modules
-from any source. Otherwise, GOPROXY is expected to be list of module proxy URLs
-separated by either comma (,) or pipe (|) characters, which control error
-fallback behavior. For each request, the go command tries each proxy in
-sequence. If there is an error, the go command will try the next proxy in the
-list if the error is a 404 or 410 HTTP response or if the current proxy is
-followed by a pipe character, indicating it is safe to fall back on any error.
-
-The GOPRIVATE and GONOPROXY environment variables allow bypassing
-the proxy for selected modules. See 'go help private' for details.
-
-No matter the source of the modules, the go command checks downloads against
-known checksums, to detect unexpected changes in the content of any specific
-module version from one day to the next. This check first consults the current
-module's go.sum file but falls back to the Go checksum database, controlled by
-the GOSUMDB and GONOSUMDB environment variables. See 'go help module-auth'
-for details.
-
-See 'go help goproxy' for details about the proxy protocol and also
-the format of the cached downloaded packages.
-
-Modules and vendoring
-
-When using modules, the go command typically satisfies dependencies by
-downloading modules from their sources and using those downloaded copies
-(after verification, as described in the previous section). Vendoring may
-be used to allow interoperation with older versions of Go, or to ensure
-that all files used for a build are stored together in a single file tree.
-
-The command 'go mod vendor' constructs a directory named vendor in the main
-module's root directory that contains copies of all packages needed to support
-builds and tests of packages in the main module. 'go mod vendor' also
-creates the file vendor/modules.txt that contains metadata about vendored
-packages and module versions. This file should be kept consistent with go.mod:
-when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
-
-If the vendor directory is present in the main module's root directory, it will
-be used automatically if the "go" version in the main module's go.mod file is
-1.14 or higher. Build commands like 'go build' and 'go test' will load packages
-from the vendor directory instead of accessing the network or the local module
-cache. To explicitly enable vendoring, invoke the go command with the flag
--mod=vendor. To disable vendoring, use the flag -mod=mod.
-
-Unlike vendoring in GOPATH, the go command ignores vendor directories in
-locations other than the main module's root directory.
+For a detailed reference on modules, see https://golang.org/ref/mod.
`,
}
@@ -413,87 +34,22 @@ file in its root. When the go command is run, it looks in the current
directory and then successive parent directories to find the go.mod
marking the root of the main (current) module.
-The go.mod file itself is line-oriented, with // comments but
-no /* */ comments. Each line holds a single directive, made up of a
-verb followed by arguments. For example:
-
- module my/thing
- go 1.12
- require other/thing v1.0.2
- require new/thing/v2 v2.3.4
- exclude old/thing v1.2.3
- replace bad/thing v1.4.5 => good/thing v1.4.5
- retract v1.5.6
-
-The verbs are
- module, to define the module path;
- go, to set the expected language version;
- require, to require a particular module at a given version or later;
- exclude, to exclude a particular module version from use;
- replace, to replace a module version with a different module version; and
- retract, to indicate a previously released version should not be used.
-Exclude and replace apply only in the main module's go.mod and are ignored
-in dependencies. See https://golang.org/ref/mod for details.
-
-The leading verb can be factored out of adjacent lines to create a block,
-like in Go imports:
-
- require (
- new/thing/v2 v2.3.4
- old/thing v1.2.3
- )
-
-The go.mod file is designed both to be edited directly and to be
-easily updated by tools. The 'go mod edit' command can be used to
-parse and edit the go.mod file from programs and tools.
-See 'go help mod edit'.
-
-The go command automatically updates go.mod each time it uses the
-module graph, to make sure go.mod always accurately reflects reality
-and is properly formatted. For example, consider this go.mod file:
-
- module M
-
- require (
- A v1
- B v1.0.0
- C v1.0.0
- D v1.2.3
- E dev
- )
-
- exclude D v1.2.3
-
-The update rewrites non-canonical version identifiers to semver form,
-so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the
-latest commit on the dev branch, perhaps v0.0.0-20180523231146-b3f5c0f6e5f1.
-
-The update modifies requirements to respect exclusions, so the
-requirement on the excluded D v1.2.3 is updated to use the next
-available version of D, perhaps D v1.2.4 or D v1.3.0.
+The go.mod file format is described in detail at
+https://golang.org/ref/mod#go-mod-file.
-The update removes redundant or misleading requirements.
-For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0,
-then go.mod's requirement of B v1.0.0 is misleading (superseded by
-A's need for v1.2.0), and its requirement of C v1.0.0 is redundant
-(implied by A's need for the same version), so both will be removed.
-If module M contains packages that directly import packages from B or
-C, then the requirements will be kept but updated to the actual
-versions being used.
+To create a new go.mod file, use 'go help init'. For details see
+'go help mod init' or https://golang.org/ref/mod#go-mod-init.
-Finally, the update reformats the go.mod in a canonical formatting, so
-that future mechanical changes will result in minimal diffs.
+To add missing module requirements or remove unneeded requirements,
+use 'go mod tidy'. For details, see 'go help mod tidy' or
+https://golang.org/ref/mod#go-mod-tidy.
-Because the module graph defines the meaning of import statements, any
-commands that load packages also use and therefore update go.mod,
-including go build, go get, go install, go list, go test, go mod graph,
-go mod tidy, and go mod why.
+To add, upgrade, downgrade, or remove a specific module requirement, use
+'go get'. For details, see 'go help module-get' or
+https://golang.org/ref/mod#go-get.
-The expected language version, set by the go directive, determines
-which language features are available when compiling the module.
-Language features available in that version will be available for use.
-Language features removed in earlier versions, or added in later versions,
-will not be available. Note that the language version does not affect
-build tags, which are determined by the Go release being used.
+To make other changes or to parse go.mod as JSON for use by other tools,
+use 'go mod edit'. See 'go help mod edit' or
+https://golang.org/ref/mod#go-mod-edit.
`,
}
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index ce5671728e..182429aee4 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -31,10 +31,6 @@ type ImportMissingError struct {
Module module.Version
QueryErr error
- // inAll indicates whether Path is in the "all" package pattern,
- // and thus would be added by 'go mod tidy'.
- inAll bool
-
// isStd indicates whether we would expect to find the package in the standard
// library. This is normally true for all dotless import paths, but replace
// directives can cause us to treat the replaced paths as also being in
@@ -58,7 +54,7 @@ func (e *ImportMissingError) Error() string {
if e.QueryErr != nil {
return fmt.Sprintf("cannot find module providing package %s: %v", e.Path, e.QueryErr)
}
- if cfg.BuildMod == "mod" {
+ if cfg.BuildMod == "mod" || (cfg.BuildMod == "readonly" && allowMissingModuleImports) {
return "cannot find module providing package " + e.Path
}
@@ -67,16 +63,14 @@ func (e *ImportMissingError) Error() string {
if !modfetch.IsZeroPseudoVersion(e.replaced.Version) {
suggestArg = e.replaced.String()
}
- return fmt.Sprintf("module %s provides package %s and is replaced but not required; try 'go get -d %s' to add it", e.replaced.Path, e.Path, suggestArg)
+ return fmt.Sprintf("module %s provides package %s and is replaced but not required; to add it:\n\tgo get %s", e.replaced.Path, e.Path, suggestArg)
}
suggestion := ""
if !HasModRoot() {
suggestion = ": working directory is not part of a module"
- } else if e.inAll {
- suggestion = "; try 'go mod tidy' to add it"
} else {
- suggestion = fmt.Sprintf("; try 'go get -d %s' to add it", e.Path)
+ suggestion = fmt.Sprintf("; to add it:\n\tgo get %s", e.Path)
}
return fmt.Sprintf("no required module provides package %s%s", e.Path, suggestion)
}
@@ -136,24 +130,57 @@ func (e *AmbiguousImportError) Error() string {
}
// ImportMissingSumError is reported in readonly mode when we need to check
-// if a module in the build list contains a package, but we don't have a sum
-// for its .zip file.
+// if a module contains a package, but we don't have a sum for its .zip file.
+// We might need sums for multiple modules to verify the package is unique.
+//
+// TODO(#43653): consolidate multiple errors of this type into a single error
+// that suggests a 'go get' command for root packages that transtively import
+// packages from modules with missing sums. load.CheckPackageErrors would be
+// a good place to consolidate errors, but we'll need to attach the import
+// stack here.
type ImportMissingSumError struct {
- importPath string
- found, inAll bool
+ importPath string
+ found bool
+ mods []module.Version
+ importer, importerVersion string // optional, but used for additional context
+ importerIsTest bool
}
func (e *ImportMissingSumError) Error() string {
+ var importParen string
+ if e.importer != "" {
+ importParen = fmt.Sprintf(" (imported by %s)", e.importer)
+ }
var message string
if e.found {
- message = fmt.Sprintf("missing go.sum entry needed to verify package %s is provided by exactly one module", e.importPath)
+ message = fmt.Sprintf("missing go.sum entry needed to verify package %s%s is provided by exactly one module", e.importPath, importParen)
} else {
- message = fmt.Sprintf("missing go.sum entry for module providing package %s", e.importPath)
+ message = fmt.Sprintf("missing go.sum entry for module providing package %s%s", e.importPath, importParen)
}
- if e.inAll {
- return message + "; try 'go mod tidy' to add it"
+ var hint string
+ if e.importer == "" {
+ // Importing package is unknown, or the missing package was named on the
+ // command line. Recommend 'go mod download' for the modules that could
+ // provide the package, since that shouldn't change go.mod.
+ args := make([]string, len(e.mods))
+ for i, mod := range e.mods {
+ args[i] = mod.Path
+ }
+ hint = fmt.Sprintf("; to add:\n\tgo mod download %s", strings.Join(args, " "))
+ } else {
+ // Importing package is known (common case). Recommend 'go get' on the
+ // current version of the importing package.
+ tFlag := ""
+ if e.importerIsTest {
+ tFlag = " -t"
+ }
+ version := ""
+ if e.importerVersion != "" {
+ version = "@" + e.importerVersion
+ }
+ hint = fmt.Sprintf("; to add:\n\tgo get%s %s%s", tFlag, e.importer, version)
}
- return message
+ return message + hint
}
func (e *ImportMissingSumError) ImportPath() string {
@@ -244,7 +271,7 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve
// Check each module on the build list.
var dirs []string
var mods []module.Version
- haveSumErr := false
+ var sumErrMods []module.Version
for _, m := range buildList {
if !maybeInModule(path, m.Path) {
// Avoid possibly downloading irrelevant modules.
@@ -257,8 +284,9 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve
// We are missing a sum needed to fetch a module in the build list.
// We can't verify that the package is unique, and we may not find
// the package at all. Keep checking other modules to decide which
- // error to report.
- haveSumErr = true
+ // error to report. Multiple sums may be missing if we need to look in
+ // multiple nested modules to resolve the import.
+ sumErrMods = append(sumErrMods, m)
continue
}
// Report fetch error.
@@ -279,8 +307,12 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve
if len(mods) > 1 {
return module.Version{}, "", &AmbiguousImportError{importPath: path, Dirs: dirs, Modules: mods}
}
- if haveSumErr {
- return module.Version{}, "", &ImportMissingSumError{importPath: path, found: len(mods) > 0}
+ if len(sumErrMods) > 0 {
+ return module.Version{}, "", &ImportMissingSumError{
+ importPath: path,
+ mods: sumErrMods,
+ found: len(mods) > 0,
+ }
}
if len(mods) == 1 {
return mods[0], dirs[0], nil
@@ -365,7 +397,7 @@ func queryImport(ctx context.Context, path string) (module.Version, error) {
return module.Version{}, &ImportMissingError{Path: path, isStd: true}
}
- if cfg.BuildMod == "readonly" {
+ if cfg.BuildMod == "readonly" && !allowMissingModuleImports {
// In readonly mode, we can't write go.mod, so we shouldn't try to look up
// the module. If readonly mode was enabled explicitly, include that in
// the error message.
@@ -547,7 +579,7 @@ func fetch(ctx context.Context, mod module.Version, needSum bool) (dir string, i
mod = r
}
- if cfg.BuildMod == "readonly" && needSum && !modfetch.HaveSum(mod) {
+ if HasModRoot() && cfg.BuildMod == "readonly" && needSum && !modfetch.HaveSum(mod) {
return "", false, module.VersionError(mod, &sumMissingError{})
}
diff --git a/src/cmd/go/internal/modload/import_test.go b/src/cmd/go/internal/modload/import_test.go
index 22d5b82e21..9420dc5646 100644
--- a/src/cmd/go/internal/modload/import_test.go
+++ b/src/cmd/go/internal/modload/import_test.go
@@ -58,10 +58,15 @@ var importTests = []struct {
func TestQueryImport(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
testenv.MustHaveExecPath(t, "git")
- defer func(old bool) {
- allowMissingModuleImports = old
- }(allowMissingModuleImports)
- AllowMissingModuleImports()
+
+ oldAllowMissingModuleImports := allowMissingModuleImports
+ oldRootMode := RootMode
+ defer func() {
+ allowMissingModuleImports = oldAllowMissingModuleImports
+ RootMode = oldRootMode
+ }()
+ allowMissingModuleImports = true
+ RootMode = NoRoot
ctx := context.Background()
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 445ebb262f..bc8d17e0a5 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -202,6 +202,8 @@ func Init() {
}
// We're in module mode. Set any global variables that need to be set.
+ cfg.ModulesEnabled = true
+ setDefaultBuildMod()
list := filepath.SplitList(cfg.BuildContext.GOPATH)
if len(list) == 0 || list[0] == "" {
base.Fatalf("missing $GOPATH")
@@ -211,8 +213,6 @@ func Init() {
base.Fatalf("$GOPATH/go.mod exists but should not")
}
- cfg.ModulesEnabled = true
-
if modRoot == "" {
// We're in module mode, but not inside a module.
//
@@ -348,8 +348,8 @@ func die() {
// ensuring requirements are consistent. WriteGoMod should be called later to
// write changes out to disk or report errors in readonly mode.
//
-// As a side-effect, LoadModFile sets a default for cfg.BuildMod if it does not
-// already have an explicit value.
+// As a side-effect, LoadModFile may change cfg.BuildMod to "vendor" if
+// -mod wasn't set explicitly and automatic vendoring should be enabled.
func LoadModFile(ctx context.Context) {
if len(buildList) > 0 {
return
@@ -380,14 +380,14 @@ func LoadModFile(ctx context.Context) {
if f.Module == nil {
// No module declaration. Must add module path.
- base.Fatalf("go: no module declaration in go.mod.\n\tRun 'go mod edit -module=example.com/mod' to specify the module path.")
+ base.Fatalf("go: no module declaration in go.mod. To specify the module path:\n\tgo mod edit -module=example.com/mod")
}
if err := checkModulePathLax(f.Module.Mod.Path); err != nil {
base.Fatalf("go: %v", err)
}
- setDefaultBuildMod()
+ setDefaultBuildMod() // possibly enable automatic vendoring
modFileToBuildList()
if cfg.BuildMod == "vendor" {
readVendorList()
@@ -458,7 +458,7 @@ func CreateModFile(ctx context.Context, modPath string) {
}
}
if !empty {
- fmt.Fprintf(os.Stderr, "go: run 'go mod tidy' to add module requirements and sums\n")
+ fmt.Fprintf(os.Stderr, "go: to add module requirements and sums:\n\tgo mod tidy\n")
}
}
@@ -586,8 +586,8 @@ func modFileToBuildList() {
buildList = list
}
-// setDefaultBuildMod sets a default value for cfg.BuildMod
-// if it is currently empty.
+// setDefaultBuildMod sets a default value for cfg.BuildMod if the -mod flag
+// wasn't provided. setDefaultBuildMod may be called multiple times.
func setDefaultBuildMod() {
if cfg.BuildModExplicit {
// Don't override an explicit '-mod=' argument.
@@ -608,7 +608,7 @@ func setDefaultBuildMod() {
if fi, err := fsys.Stat(filepath.Join(modRoot, "vendor")); err == nil && fi.IsDir() {
modGo := "unspecified"
- if index.goVersionV != "" {
+ if index != nil && index.goVersionV != "" {
if semver.Compare(index.goVersionV, "v1.14") >= 0 {
// The Go version is at least 1.14, and a vendor directory exists.
// Set -mod=vendor by default.
@@ -907,7 +907,7 @@ func WriteGoMod() {
} else if cfg.BuildModReason != "" {
base.Fatalf("go: updates to go.mod needed, disabled by -mod=readonly\n\t(%s)", cfg.BuildModReason)
} else {
- base.Fatalf("go: updates to go.mod needed; try 'go mod tidy' first")
+ base.Fatalf("go: updates to go.mod needed; to update it:\n\tgo mod tidy")
}
}
@@ -976,9 +976,12 @@ func WriteGoMod() {
// It also contains entries for go.mod files needed for MVS (the version
// of these entries ends with "/go.mod").
//
-// If addDirect is true, the set also includes sums for modules directly
-// required by go.mod, as represented by the index, with replacements applied.
-func keepSums(addDirect bool) map[module.Version]bool {
+// If keepBuildListZips is true, the set also includes sums for zip files for
+// all modules in the build list with replacements applied. 'go get' and
+// 'go mod download' may add sums to this set when adding a requirement on a
+// module without a root package or when downloading a direct or indirect
+// dependency.
+func keepSums(keepBuildListZips bool) map[module.Version]bool {
// Re-derive the build list using the current list of direct requirements.
// Keep the sum for the go.mod of each visited module version (or its
// replacement).
@@ -1007,19 +1010,20 @@ func keepSums(addDirect bool) map[module.Version]bool {
panic(fmt.Sprintf("unexpected error reloading build list: %v", err))
}
+ actualMods := make(map[string]module.Version)
+ for _, m := range buildList[1:] {
+ if r := Replacement(m); r.Path != "" {
+ actualMods[m.Path] = r
+ } else {
+ actualMods[m.Path] = m
+ }
+ }
+
// Add entries for modules in the build list with paths that are prefixes of
// paths of loaded packages. We need to retain sums for modules needed to
// report ambiguous import errors. We use our re-derived build list,
// since the global build list may have been tidied.
if loaded != nil {
- actualMods := make(map[string]module.Version)
- for _, m := range buildList[1:] {
- if r := Replacement(m); r.Path != "" {
- actualMods[m.Path] = r
- } else {
- actualMods[m.Path] = m
- }
- }
for _, pkg := range loaded.pkgs {
if pkg.testOf != nil || pkg.inStd || module.CheckImportPath(pkg.path) != nil {
continue
@@ -1032,17 +1036,13 @@ func keepSums(addDirect bool) map[module.Version]bool {
}
}
- // Add entries for modules directly required by go.mod.
- if addDirect {
- for m := range index.require {
- var kept module.Version
- if r := Replacement(m); r.Path != "" {
- kept = r
- } else {
- kept = m
- }
- keep[kept] = true
- keep[module.Version{Path: kept.Path, Version: kept.Version + "/go.mod"}] = true
+ // Add entries for the zip of each module in the build list.
+ // We might not need all of these (tidy does not add them), but they may be
+ // added by a specific 'go get' or 'go mod download' command to resolve
+ // missing import sum errors.
+ if keepBuildListZips {
+ for _, m := range actualMods {
+ keep[m] = true
}
}
@@ -1062,9 +1062,8 @@ func (r *keepSumReqs) Required(m module.Version) ([]module.Version, error) {
}
func TrimGoSum() {
- // Don't retain sums for direct requirements in go.mod. When TrimGoSum is
- // called, go.mod has not been updated, and it may contain requirements on
- // modules deleted from the build list.
- addDirect := false
- modfetch.TrimGoSum(keepSums(addDirect))
+ // Don't retain sums for the zip file of every module in the build list.
+ // We may not need them all to build the main module's packages.
+ keepBuildListZips := false
+ modfetch.TrimGoSum(keepSums(keepBuildListZips))
}
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 27f47fad4d..6d87acc6d3 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -280,11 +280,11 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
checkMultiplePaths()
for _, pkg := range loaded.pkgs {
if pkg.err != nil {
- if pkg.flags.has(pkgInAll) {
- if imErr := (*ImportMissingError)(nil); errors.As(pkg.err, &imErr) {
- imErr.inAll = true
- } else if sumErr := (*ImportMissingSumError)(nil); errors.As(pkg.err, &sumErr) {
- sumErr.inAll = true
+ if sumErr := (*ImportMissingSumError)(nil); errors.As(pkg.err, &sumErr) {
+ if importer := pkg.stack; importer != nil {
+ sumErr.importer = importer.path
+ sumErr.importerVersion = importer.mod.Version
+ sumErr.importerIsTest = importer.testOf != nil
}
}
@@ -870,7 +870,7 @@ func loadFromRoots(params loaderParams) *loader {
// base.Errorf. Ideally, 'go list' should not fail because of this,
// but today, LoadPackages calls WriteGoMod unconditionally, which
// would fail with a less clear message.
- base.Errorf("go: %[1]s: package %[2]s imported from implicitly required module; try 'go get -d %[1]s' to add missing requirements", pkg.path, dep.path)
+ base.Errorf("go: %[1]s: package %[2]s imported from implicitly required module; to add missing requirements, run:\n\tgo get %[2]s@%[3]s", pkg.path, dep.path, dep.mod.Version)
}
ld.direct[dep.mod.Path] = true
}
@@ -1083,14 +1083,21 @@ func (ld *loader) load(pkg *loadPkg) {
}
}
- imports, testImports, err := scanDir(pkg.dir, ld.Tags)
- if err != nil {
- pkg.err = err
- return
- }
-
pkg.inStd = (search.IsStandardImportPath(pkg.path) && search.InDir(pkg.dir, cfg.GOROOTsrc) != "")
+ var imports, testImports []string
+
+ if cfg.BuildContext.Compiler == "gccgo" && pkg.inStd {
+ // We can't scan standard packages for gccgo.
+ } else {
+ var err error
+ imports, testImports, err = scanDir(pkg.dir, ld.Tags)
+ if err != nil {
+ pkg.err = err
+ return
+ }
+ }
+
pkg.imports = make([]*loadPkg, 0, len(imports))
var importFlags loadPkgFlags
if pkg.flags.has(pkgInAll) {
diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go
index eb05e9f9c9..c6667d0bf7 100644
--- a/src/cmd/go/internal/modload/modfile.go
+++ b/src/cmd/go/internal/modload/modfile.go
@@ -446,10 +446,10 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
if actual.Path == "" {
actual = m
}
- if cfg.BuildMod == "readonly" && actual.Version != "" {
+ if HasModRoot() && cfg.BuildMod == "readonly" && actual.Version != "" {
key := module.Version{Path: actual.Path, Version: actual.Version + "/go.mod"}
if !modfetch.HaveSum(key) {
- suggestion := fmt.Sprintf("; try 'go mod download %s' to add it", m.Path)
+ suggestion := fmt.Sprintf("; to add it:\n\tgo mod download %s", m.Path)
return nil, module.VersionError(actual, &sumMissingError{suggestion: suggestion})
}
}
diff --git a/src/cmd/go/internal/modload/mvs.go b/src/cmd/go/internal/modload/mvs.go
index 167d6819b0..31015194f9 100644
--- a/src/cmd/go/internal/modload/mvs.go
+++ b/src/cmd/go/internal/modload/mvs.go
@@ -111,19 +111,3 @@ func (*mvsReqs) Previous(m module.Version) (module.Version, error) {
}
return module.Version{Path: m.Path, Version: "none"}, nil
}
-
-// next returns the next version of m.Path after m.Version.
-// It is only used by the exclusion processing in the Required method,
-// not called directly by MVS.
-func (*mvsReqs) next(m module.Version) (module.Version, error) {
- // TODO(golang.org/issue/38714): thread tracing context through MVS.
- list, err := versions(context.TODO(), m.Path, CheckAllowed)
- if err != nil {
- return module.Version{}, err
- }
- i := sort.Search(len(list), func(i int) bool { return semver.Compare(list[i], m.Version) > 0 })
- if i < len(list) {
- return module.Version{Path: m.Path, Version: list[i]}, nil
- }
- return module.Version{Path: m.Path, Version: "none"}, nil
-}
diff --git a/src/cmd/go/internal/modload/vendor.go b/src/cmd/go/internal/modload/vendor.go
index 80d49053c6..d8fd91f1fe 100644
--- a/src/cmd/go/internal/modload/vendor.go
+++ b/src/cmd/go/internal/modload/vendor.go
@@ -214,6 +214,6 @@ func checkVendorConsistency() {
}
if vendErrors.Len() > 0 {
- base.Fatalf("go: inconsistent vendoring in %s:%s\n\nrun 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory", modRoot, vendErrors)
+ base.Fatalf("go: inconsistent vendoring in %s:%s\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor", modRoot, vendErrors)
}
}
diff --git a/src/cmd/go/internal/test/genflags.go b/src/cmd/go/internal/test/genflags.go
index 5e83d53980..30334b0f30 100644
--- a/src/cmd/go/internal/test/genflags.go
+++ b/src/cmd/go/internal/test/genflags.go
@@ -9,9 +9,9 @@ package main
import (
"bytes"
"flag"
+ exec "internal/execabs"
"log"
"os"
- "os/exec"
"strings"
"testing"
"text/template"
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index 50fe2dbf39..7fc9e8fbdc 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -11,10 +11,10 @@ import (
"errors"
"fmt"
"go/build"
+ exec "internal/execabs"
"io"
"io/fs"
"os"
- "os/exec"
"path"
"path/filepath"
"regexp"
diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index d2671ff5a7..10e6604da5 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -325,7 +325,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
if !testC {
buildFlag = "-i"
}
- fmt.Fprintf(os.Stderr, "flag %s is not a 'go test' flag (unknown flags cannot be used with %s)\n", firstUnknownFlag, buildFlag)
+ fmt.Fprintf(os.Stderr, "go test: unknown flag %s cannot be used with %s\n", firstUnknownFlag, buildFlag)
exitWithUsage()
}
diff --git a/src/cmd/go/internal/tool/tool.go b/src/cmd/go/internal/tool/tool.go
index 7f4dc86802..95c90ea7c8 100644
--- a/src/cmd/go/internal/tool/tool.go
+++ b/src/cmd/go/internal/tool/tool.go
@@ -8,8 +8,9 @@ package tool
import (
"context"
"fmt"
+ exec "internal/execabs"
"os"
- "os/exec"
+ "os/signal"
"sort"
"strings"
@@ -85,7 +86,19 @@ func runTool(ctx context.Context, cmd *base.Command, args []string) {
Stdout: os.Stdout,
Stderr: os.Stderr,
}
- err := toolCmd.Run()
+ err := toolCmd.Start()
+ if err == nil {
+ c := make(chan os.Signal, 100)
+ signal.Notify(c)
+ go func() {
+ for sig := range c {
+ toolCmd.Process.Signal(sig)
+ }
+ }()
+ err = toolCmd.Wait()
+ signal.Stop(c)
+ close(c)
+ }
if err != nil {
// Only print about the exit status if the command
// didn't even run (not an ExitError) or it didn't exit cleanly
diff --git a/src/cmd/go/internal/vcs/vcs.go b/src/cmd/go/internal/vcs/vcs.go
index 4894ecdc35..9feffe0765 100644
--- a/src/cmd/go/internal/vcs/vcs.go
+++ b/src/cmd/go/internal/vcs/vcs.go
@@ -8,13 +8,13 @@ import (
"encoding/json"
"errors"
"fmt"
+ exec "internal/execabs"
"internal/lazyregexp"
"internal/singleflight"
"io/fs"
"log"
urlpkg "net/url"
"os"
- "os/exec"
"path/filepath"
"regexp"
"strings"
@@ -729,7 +729,7 @@ func checkGOVCS(vcs *Cmd, root string) error {
if private {
what = "private"
}
- return fmt.Errorf("GOVCS disallows using %s for %s %s", vcs.Cmd, what, root)
+ return fmt.Errorf("GOVCS disallows using %s for %s %s; see 'go help vcs'", vcs.Cmd, what, root)
}
return nil
diff --git a/src/cmd/go/internal/vet/vetflag.go b/src/cmd/go/internal/vet/vetflag.go
index ef995ef835..5bf5cf4446 100644
--- a/src/cmd/go/internal/vet/vetflag.go
+++ b/src/cmd/go/internal/vet/vetflag.go
@@ -10,9 +10,9 @@ import (
"errors"
"flag"
"fmt"
+ exec "internal/execabs"
"log"
"os"
- "os/exec"
"path/filepath"
"strings"
diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
index 9d141ae233..b071ed1400 100644
--- a/src/cmd/go/internal/work/action.go
+++ b/src/cmd/go/internal/work/action.go
@@ -57,6 +57,9 @@ type Builder struct {
id sync.Mutex
toolIDCache map[string]string // tool name -> tool ID
buildIDCache map[string]string // file name -> build ID
+
+ cgoEnvOnce sync.Once
+ cgoEnvCache []string
}
// NOTE: Much of Action would not need to be exported if not for test.
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 7f2617cf1c..780d639c5d 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -9,9 +9,9 @@ import (
"errors"
"fmt"
"go/build"
+ exec "internal/execabs"
"internal/goroot"
"os"
- "os/exec"
"path"
"path/filepath"
"runtime"
@@ -113,7 +113,10 @@ and test commands:
created with -buildmode=shared.
-mod mode
module download mode to use: readonly, vendor, or mod.
- See 'go help modules' for more.
+ By default, if a vendor directory is present and the go version in go.mod
+ is 1.14 or higher, the go command acts as if -mod=vendor were set.
+ Otherwise, the go command acts as if -mod=readonly were set.
+ See https://golang.org/ref/mod#build-commands for details.
-modcacherw
leave newly-created directories in the module cache read-write
instead of making them read-only.
diff --git a/src/cmd/go/internal/work/buildid.go b/src/cmd/go/internal/work/buildid.go
index d76988145b..c555d4a9f1 100644
--- a/src/cmd/go/internal/work/buildid.go
+++ b/src/cmd/go/internal/work/buildid.go
@@ -7,8 +7,8 @@ package work
import (
"bytes"
"fmt"
+ exec "internal/execabs"
"os"
- "os/exec"
"strings"
"cmd/go/internal/base"
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index feb2299d40..cacb4c05df 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -13,13 +13,13 @@ import (
"encoding/json"
"errors"
"fmt"
+ exec "internal/execabs"
"internal/lazyregexp"
"io"
"io/fs"
"log"
"math/rand"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
@@ -1164,10 +1164,8 @@ func (b *Builder) vet(ctx context.Context, a *Action) error {
return err
}
- env := b.cCompilerEnv()
- if cfg.BuildToolchainName == "gccgo" {
- env = append(env, "GCCGO="+BuildToolchain.compiler())
- }
+ // TODO(rsc): Why do we pass $GCCGO to go vet?
+ env := b.cgoEnv()
p := a.Package
tool := VetTool
@@ -2044,6 +2042,9 @@ func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...interfa
var buf bytes.Buffer
cmd := exec.Command(cmdline[0], cmdline[1:]...)
+ if cmd.Path != "" {
+ cmd.Args[0] = cmd.Path
+ }
cmd.Stdout = &buf
cmd.Stderr = &buf
cleanup := passLongArgsInResponseFiles(cmd)
@@ -2110,6 +2111,24 @@ func (b *Builder) cCompilerEnv() []string {
return []string{"TERM=dumb"}
}
+// cgoEnv returns environment variables to set when running cgo.
+// Some of these pass through to cgo running the C compiler,
+// so it includes cCompilerEnv.
+func (b *Builder) cgoEnv() []string {
+ b.cgoEnvOnce.Do(func() {
+ cc, err := exec.LookPath(b.ccExe()[0])
+ if err != nil || filepath.Base(cc) == cc { // reject relative path
+ cc = "/missing-cc"
+ }
+ gccgo := GccgoBin
+ if filepath.Base(gccgo) == gccgo { // reject relative path
+ gccgo = "/missing-gccgo"
+ }
+ b.cgoEnvCache = append(b.cCompilerEnv(), "CC="+cc, "GCCGO="+gccgo)
+ })
+ return b.cgoEnvCache
+}
+
// mkdir makes the named directory.
func (b *Builder) Mkdir(dir string) error {
// Make Mkdir(a.Objdir) a no-op instead of an error when a.Objdir == "".
@@ -2435,7 +2454,7 @@ func (b *Builder) fcExe() []string {
func (b *Builder) compilerExe(envValue string, def string) []string {
compiler := strings.Fields(envValue)
if len(compiler) == 0 {
- compiler = []string{def}
+ compiler = strings.Fields(def)
}
return compiler
}
@@ -2581,7 +2600,14 @@ func (b *Builder) gccArchArgs() []string {
case "386":
return []string{"-m32"}
case "amd64":
+ if cfg.Goos == "darwin" {
+ return []string{"-arch", "x86_64", "-m64"}
+ }
return []string{"-m64"}
+ case "arm64":
+ if cfg.Goos == "darwin" {
+ return []string{"-arch", "arm64"}
+ }
case "arm":
return []string{"-marm"} // not thumb
case "s390x":
@@ -2703,13 +2729,13 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
// along to the host linker. At this point in the code, cgoLDFLAGS
// consists of the original $CGO_LDFLAGS (unchecked) and all the
// flags put together from source code (checked).
- cgoenv := b.cCompilerEnv()
+ cgoenv := b.cgoEnv()
if len(cgoLDFLAGS) > 0 {
flags := make([]string, len(cgoLDFLAGS))
for i, f := range cgoLDFLAGS {
flags[i] = strconv.Quote(f)
}
- cgoenv = []string{"CGO_LDFLAGS=" + strings.Join(flags, " ")}
+ cgoenv = append(cgoenv, "CGO_LDFLAGS="+strings.Join(flags, " "))
}
if cfg.BuildToolchainName == "gccgo" {
@@ -2940,7 +2966,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
if p.Standard && p.ImportPath == "runtime/cgo" {
cgoflags = []string{"-dynlinker"} // record path to dynamic linker
}
- return b.run(a, base.Cwd, p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
+ return b.run(a, base.Cwd, p.ImportPath, b.cgoEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
}
// Run SWIG on all SWIG input files.
diff --git a/src/cmd/go/internal/work/gccgo.go b/src/cmd/go/internal/work/gccgo.go
index 3ffd01c473..b58c8aa885 100644
--- a/src/cmd/go/internal/work/gccgo.go
+++ b/src/cmd/go/internal/work/gccgo.go
@@ -6,8 +6,8 @@ package work
import (
"fmt"
+ exec "internal/execabs"
"os"
- "os/exec"
"path/filepath"
"strings"
"sync"
@@ -93,6 +93,12 @@ func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg,
args = append(args, "-I", root)
}
}
+ if embedcfg != nil && b.gccSupportsFlag(args[:1], "-fgo-embedcfg=/dev/null") {
+ if err := b.writeFile(objdir+"embedcfg", embedcfg); err != nil {
+ return "", nil, err
+ }
+ args = append(args, "-fgo-embedcfg="+objdir+"embedcfg")
+ }
if b.gccSupportsFlag(args[:1], "-ffile-prefix-map=a=b") {
if cfg.BuildTrimpath {
diff --git a/src/cmd/go/testdata/addmod.go b/src/cmd/go/testdata/addmod.go
index 58376b7ed4..09fc8e713b 100644
--- a/src/cmd/go/testdata/addmod.go
+++ b/src/cmd/go/testdata/addmod.go
@@ -25,7 +25,7 @@ import (
"io/fs"
"log"
"os"
- "os/exec"
+ exec "internal/execabs"
"path/filepath"
"strings"
diff --git a/src/cmd/go/testdata/script/build_darwin_cc_arch.txt b/src/cmd/go/testdata/script/build_darwin_cc_arch.txt
new file mode 100644
index 0000000000..2b81b4cf80
--- /dev/null
+++ b/src/cmd/go/testdata/script/build_darwin_cc_arch.txt
@@ -0,0 +1,24 @@
+# Test that we pass -arch flag to C compiler on Darwin (issue 43692).
+
+[!darwin] skip
+[!cgo] skip
+
+# clear CC, in case user sets it
+env CC=
+
+env CGO_ENABLED=1
+
+env GOARCH=amd64
+go build -n -x c.go
+stderr 'clang.*-arch x86_64'
+
+env GOARCH=arm64
+go build -n -x c.go
+stderr 'clang.*-arch arm64'
+
+-- c.go --
+package main
+
+import "C"
+
+func main() {}
diff --git a/src/cmd/go/testdata/script/cgo_path.txt b/src/cmd/go/testdata/script/cgo_path.txt
new file mode 100644
index 0000000000..0d15998426
--- /dev/null
+++ b/src/cmd/go/testdata/script/cgo_path.txt
@@ -0,0 +1,35 @@
+[!cgo] skip
+
+env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache.
+[!windows] env PATH=.:$PATH
+[!windows] chmod 0777 p/gcc p/clang
+[!windows] exists -exec p/gcc p/clang
+[windows] exists -exec p/gcc.bat p/clang.bat
+! exists p/bug.txt
+go build -x
+! exists p/bug.txt
+
+-- go.mod --
+module m
+
+-- m.go --
+package m
+
+import _ "m/p"
+
+-- p/p.go --
+package p
+
+// #define X 1
+import "C"
+
+-- p/gcc --
+#!/bin/sh
+echo ran gcc >bug.txt
+-- p/clang --
+#!/bin/sh
+echo ran clang >bug.txt
+-- p/gcc.bat --
+echo ran gcc >bug.txt
+-- p/clang.bat --
+echo ran clang >bug.txt
diff --git a/src/cmd/go/testdata/script/embed.txt b/src/cmd/go/testdata/script/embed.txt
index 7e9a548661..6ad42e9cd1 100644
--- a/src/cmd/go/testdata/script/embed.txt
+++ b/src/cmd/go/testdata/script/embed.txt
@@ -3,6 +3,14 @@ go list -f '{{.EmbedPatterns}}'
stdout '\[x\*t\*t\]'
go list -f '{{.EmbedFiles}}'
stdout '\[x.txt\]'
+go list -test -f '{{.TestEmbedPatterns}}'
+stdout '\[y\*t\*t\]'
+go list -test -f '{{.TestEmbedFiles}}'
+stdout '\[y.txt\]'
+go list -test -f '{{.XTestEmbedPatterns}}'
+stdout '\[z\*t\*t\]'
+go list -test -f '{{.XTestEmbedFiles}}'
+stdout '\[z.txt\]'
# build embeds x.txt
go build -x
@@ -20,7 +28,7 @@ cp x.go2 x.go
go build -x
cp x.txt .git
! go build -x
-stderr 'pattern [*]t: cannot embed file [.]git'
+stderr '^x.go:5:12: pattern [*]t: cannot embed file [.]git: invalid name [.]git$'
rm .git
# build rejects symlinks
@@ -32,19 +40,26 @@ rm .git
# build rejects empty directories
mkdir t
! go build -x
-stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
+stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
# build ignores symlinks and invalid names in directories
cp x.txt t/.git
! go build -x
-stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
+stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
+go list -e -f '{{.Incomplete}}'
+stdout 'true'
[symlink] symlink t/x.link -> ../x.txt
[symlink] ! go build -x
-[symlink] stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
+[symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
cp x.txt t/x.txt
go build -x
+# build reports errors with positions in imported packages
+rm t/x.txt
+! go build m/use
+stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
+
-- x.go --
package p
@@ -53,6 +68,22 @@ import "embed"
//go:embed x*t*t
var X embed.FS
+-- x_test.go --
+package p
+
+import "embed"
+
+//go:embed y*t*t
+var Y string
+
+-- x_x_test.go --
+package p_test
+
+import "embed"
+
+//go:embed z*t*t
+var Z string
+
-- x.go2 --
package p
@@ -64,9 +95,15 @@ var X embed.FS
-- x.txt --
hello
+-- y.txt --
+-- z.txt --
-- x.txt2 --
not hello
+-- use/use.go --
+package use
+
+import _ "m"
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/embed_fmt.txt b/src/cmd/go/testdata/script/embed_fmt.txt
new file mode 100644
index 0000000000..8a16afea8a
--- /dev/null
+++ b/src/cmd/go/testdata/script/embed_fmt.txt
@@ -0,0 +1,22 @@
+# go fmt ignores file not found
+go fmt xnofmt.go
+cmp xnofmt.go xfmt.ref
+! go build xnofmt.go
+stderr 'xnofmt.go:5:12: pattern missing.txt: no matching files found'
+
+-- xnofmt.go --
+package p
+
+import "embed"
+
+//go:embed missing.txt
+var X embed.FS
+-- xfmt.ref --
+package p
+
+import "embed"
+
+//go:embed missing.txt
+var X embed.FS
+-- go.mod --
+module m
diff --git a/src/cmd/go/testdata/script/govcs.txt b/src/cmd/go/testdata/script/govcs.txt
index 35f092ee49..4180d7da6a 100644
--- a/src/cmd/go/testdata/script/govcs.txt
+++ b/src/cmd/go/testdata/script/govcs.txt
@@ -5,40 +5,40 @@ env GOPROXY=direct
# GOVCS stops go get
env GOVCS='*:none'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
env GOPRIVATE='github.com/google'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for private github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$'
# public pattern works
env GOPRIVATE='github.com/google'
env GOVCS='public:all,private:none'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for private github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$'
# private pattern works
env GOPRIVATE='hubgit.com/google'
env GOVCS='private:all,public:none'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
# other patterns work (for more patterns, see TestGOVCS)
env GOPRIVATE=
env GOVCS='github.com:svn|hg'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
env GOVCS='github.com/google/go-cmp/inner:git,github.com:svn|hg'
! go get github.com/google/go-cmp
-stderr 'go get: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^go get: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
# bad patterns are reported (for more bad patterns, see TestGOVCSErrors)
env GOVCS='git'
! go get github.com/google/go-cmp
-stderr 'go get github.com/google/go-cmp: malformed entry in GOVCS \(missing colon\): "git"'
+stderr '^go get github.com/google/go-cmp: malformed entry in GOVCS \(missing colon\): "git"$'
env GOVCS=github.com:hg,github.com:git
! go get github.com/google/go-cmp
-stderr 'go get github.com/google/go-cmp: unreachable pattern in GOVCS: "github.com:git" after "github.com:hg"'
+stderr '^go get github.com/google/go-cmp: unreachable pattern in GOVCS: "github.com:git" after "github.com:hg"$'
# bad GOVCS patterns do not stop commands that do not need to check VCS
go list
@@ -50,19 +50,19 @@ env GOPROXY=direct
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.svn/hello
-stderr 'go get rsc.io/nonexist.svn/hello: GOVCS disallows using svn for public rsc.io/nonexist.svn'
+stderr '^go get rsc.io/nonexist.svn/hello: GOVCS disallows using svn for public rsc.io/nonexist.svn; see ''go help vcs''$'
# fossil is disallowed by default
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.fossil/hello
-stderr 'go get rsc.io/nonexist.fossil/hello: GOVCS disallows using fossil for public rsc.io/nonexist.fossil'
+stderr '^go get rsc.io/nonexist.fossil/hello: GOVCS disallows using fossil for public rsc.io/nonexist.fossil; see ''go help vcs''$'
# bzr is disallowed by default
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.bzr/hello
-stderr 'go get rsc.io/nonexist.bzr/hello: GOVCS disallows using bzr for public rsc.io/nonexist.bzr'
+stderr '^go get rsc.io/nonexist.bzr/hello: GOVCS disallows using bzr for public rsc.io/nonexist.bzr; see ''go help vcs''$'
# git is OK by default
env GOVCS=
@@ -77,12 +77,12 @@ env GONOSUMDB='*'
# git can be disallowed
env GOVCS=public:hg
! go get rsc.io/nonexist.git/hello
-stderr 'go get rsc.io/nonexist.git/hello: GOVCS disallows using git for public rsc.io/nonexist.git'
+stderr '^go get rsc.io/nonexist.git/hello: GOVCS disallows using git for public rsc.io/nonexist.git; see ''go help vcs''$'
# hg can be disallowed
env GOVCS=public:git
! go get rsc.io/nonexist.hg/hello
-stderr 'go get rsc.io/nonexist.hg/hello: GOVCS disallows using hg for public rsc.io/nonexist.hg'
+stderr '^go get rsc.io/nonexist.hg/hello: GOVCS disallows using hg for public rsc.io/nonexist.hg; see ''go help vcs''$'
# Repeat in GOPATH mode. Error texts slightly different.
@@ -91,40 +91,40 @@ env GO111MODULE=off
# GOVCS stops go get
env GOVCS='*:none'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
env GOPRIVATE='github.com/google'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for private github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$'
# public pattern works
env GOPRIVATE='github.com/google'
env GOVCS='public:all,private:none'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for private github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$'
# private pattern works
env GOPRIVATE='hubgit.com/google'
env GOVCS='private:all,public:none'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
# other patterns work (for more patterns, see TestGOVCS)
env GOPRIVATE=
env GOVCS='github.com:svn|hg'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
env GOVCS='github.com/google/go-cmp/inner:git,github.com:svn|hg'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp'
+stderr '^package github.com/google/go-cmp: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$'
# bad patterns are reported (for more bad patterns, see TestGOVCSErrors)
env GOVCS='git'
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: malformed entry in GOVCS \(missing colon\): "git"'
+stderr '^package github.com/google/go-cmp: malformed entry in GOVCS \(missing colon\): "git"$'
env GOVCS=github.com:hg,github.com:git
! go get github.com/google/go-cmp
-stderr 'package github.com/google/go-cmp: unreachable pattern in GOVCS: "github.com:git" after "github.com:hg"'
+stderr '^package github.com/google/go-cmp: unreachable pattern in GOVCS: "github.com:git" after "github.com:hg"$'
# bad GOVCS patterns do not stop commands that do not need to check VCS
go list
@@ -133,19 +133,19 @@ go list
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.svn/hello
-stderr 'package rsc.io/nonexist.svn/hello: GOVCS disallows using svn for public rsc.io/nonexist.svn'
+stderr '^package rsc.io/nonexist.svn/hello: GOVCS disallows using svn for public rsc.io/nonexist.svn; see ''go help vcs''$'
# fossil is disallowed by default
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.fossil/hello
-stderr 'package rsc.io/nonexist.fossil/hello: GOVCS disallows using fossil for public rsc.io/nonexist.fossil'
+stderr '^package rsc.io/nonexist.fossil/hello: GOVCS disallows using fossil for public rsc.io/nonexist.fossil; see ''go help vcs''$'
# bzr is disallowed by default
env GOPRIVATE=
env GOVCS=
! go get rsc.io/nonexist.bzr/hello
-stderr 'package rsc.io/nonexist.bzr/hello: GOVCS disallows using bzr for public rsc.io/nonexist.bzr'
+stderr '^package rsc.io/nonexist.bzr/hello: GOVCS disallows using bzr for public rsc.io/nonexist.bzr; see ''go help vcs''$'
# git is OK by default
env GOVCS=
@@ -160,12 +160,12 @@ env GONOSUMDB='*'
# git can be disallowed
env GOVCS=public:hg
! go get rsc.io/nonexist.git/hello
-stderr 'package rsc.io/nonexist.git/hello: GOVCS disallows using git for public rsc.io/nonexist.git'
+stderr '^package rsc.io/nonexist.git/hello: GOVCS disallows using git for public rsc.io/nonexist.git; see ''go help vcs''$'
# hg can be disallowed
env GOVCS=public:git
! go get rsc.io/nonexist.hg/hello
-stderr 'package rsc.io/nonexist.hg/hello: GOVCS disallows using hg for public rsc.io/nonexist.hg'
+stderr '^package rsc.io/nonexist.hg/hello: GOVCS disallows using hg for public rsc.io/nonexist.hg; see ''go help vcs''$'
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_bad_domain.txt b/src/cmd/go/testdata/script/mod_bad_domain.txt
index 20199c1c2c..7a270d0f07 100644
--- a/src/cmd/go/testdata/script/mod_bad_domain.txt
+++ b/src/cmd/go/testdata/script/mod_bad_domain.txt
@@ -19,7 +19,7 @@ stderr 'malformed module path "x/y.z": missing dot in first path element'
! go build ./useappengine
stderr '^useappengine[/\\]x.go:2:8: cannot find package$'
! go build ./usenonexistent
-stderr '^usenonexistent[/\\]x.go:2:8: no required module provides package nonexistent.rsc.io; try ''go mod tidy'' to add it$'
+stderr '^usenonexistent[/\\]x.go:2:8: no required module provides package nonexistent.rsc.io; to add it:\n\tgo get nonexistent.rsc.io$'
# 'get -d' should be similarly definitive
diff --git a/src/cmd/go/testdata/script/mod_edit.txt b/src/cmd/go/testdata/script/mod_edit.txt
index 78485eb86a..d7e681e831 100644
--- a/src/cmd/go/testdata/script/mod_edit.txt
+++ b/src/cmd/go/testdata/script/mod_edit.txt
@@ -21,6 +21,12 @@ cmpenv go.mod $WORK/go.mod.edit1
go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0 -dropretract=v1.0.0 -dropretract=[v1.1.0,v1.2.0]
cmpenv go.mod $WORK/go.mod.edit2
+# -exclude and -retract reject invalid versions.
+! go mod edit -exclude=example.com/m@bad
+stderr '^go mod: -exclude=example.com/m@bad: version "bad" invalid: must be of the form v1.2.3$'
+! go mod edit -retract=bad
+stderr '^go mod: -retract=bad: version "bad" invalid: must be of the form v1.2.3$'
+
# go mod edit -json
go mod edit -json
cmpenv stdout $WORK/go.mod.json
diff --git a/src/cmd/go/testdata/script/mod_get_fallback.txt b/src/cmd/go/testdata/script/mod_get_fallback.txt
index a9834a324e..9733fa366b 100644
--- a/src/cmd/go/testdata/script/mod_get_fallback.txt
+++ b/src/cmd/go/testdata/script/mod_get_fallback.txt
@@ -6,5 +6,5 @@ env GOPROXY=https://proxy.golang.org,direct
env GOSUMDB=off
go get -x -v -d golang.org/x/tools/cmd/goimports
-stderr '# get https://proxy.golang.org/golang.org/x/tools/@latest'
+stderr '# get https://proxy.golang.org/golang.org/x/tools/@v/list'
! stderr '# get https://golang.org'
diff --git a/src/cmd/go/testdata/script/mod_get_promote_implicit.txt b/src/cmd/go/testdata/script/mod_get_promote_implicit.txt
index c64e0c0f70..10ca6594e4 100644
--- a/src/cmd/go/testdata/script/mod_get_promote_implicit.txt
+++ b/src/cmd/go/testdata/script/mod_get_promote_implicit.txt
@@ -6,10 +6,12 @@ cp go.mod.orig go.mod
go list -m indirect-with-pkg
stdout '^indirect-with-pkg v1.0.0 => ./indirect-with-pkg$'
! go list ./use-indirect
-stderr '^go: m/use-indirect: package indirect-with-pkg imported from implicitly required module; try ''go get -d m/use-indirect'' to add missing requirements$'
+stderr '^go: m/use-indirect: package indirect-with-pkg imported from implicitly required module; to add missing requirements, run:\n\tgo get indirect-with-pkg@v1.0.0$'
-# We can promote the implicit requirement by getting the importing package,
-# as hinted.
+# We can promote the implicit requirement by getting the importing package.
+# NOTE: the hint recommends getting the imported package (tested below) since
+# it's more obvious and doesn't require -d. However, that adds an '// indirect'
+# comment on the requirement.
go get -d m/use-indirect
cmp go.mod go.mod.use
cp go.mod.orig go.mod
@@ -17,6 +19,8 @@ cp go.mod.orig go.mod
# We can also promote implicit requirements using 'go get' on them, or their
# packages. This gives us "// indirect" requirements, since 'go get' doesn't
# know they're needed by the main module. See #43131 for the rationale.
+# The hint above recommends this because it's more obvious usage and doesn't
+# require the -d flag.
go get -d indirect-with-pkg indirect-without-pkg
cmp go.mod go.mod.indirect
diff --git a/src/cmd/go/testdata/script/mod_get_replaced.txt b/src/cmd/go/testdata/script/mod_get_replaced.txt
index 76d0793ffe..d97f3f1a40 100644
--- a/src/cmd/go/testdata/script/mod_get_replaced.txt
+++ b/src/cmd/go/testdata/script/mod_get_replaced.txt
@@ -87,7 +87,7 @@ stderr '^go get: malformed module path "example": missing dot in first path elem
go mod edit -replace example@v0.1.0=./example
! go list example
-stderr '^module example provides package example and is replaced but not required; try ''go get -d example@v0.1.0'' to add it$'
+stderr '^module example provides package example and is replaced but not required; to add it:\n\tgo get example@v0.1.0$'
go get -d example
go list -m example
diff --git a/src/cmd/go/testdata/script/mod_get_retract.txt b/src/cmd/go/testdata/script/mod_get_retract.txt
index 6e328eb592..fe0ac88629 100644
--- a/src/cmd/go/testdata/script/mod_get_retract.txt
+++ b/src/cmd/go/testdata/script/mod_get_retract.txt
@@ -11,7 +11,7 @@ cp go.mod.orig go.mod
go mod edit -require example.com/retract/self/prev@v1.9.0
go get -d example.com/retract/self/prev
stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$'
-stderr '^go: run ''go get example.com/retract/self/prev@latest'' to switch to the latest unretracted version$'
+stderr '^go: to switch to the latest unretracted version, run:\n\tgo get example.com/retract/self/prev@latest$'
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.9.0$'
diff --git a/src/cmd/go/testdata/script/mod_gobuild_import.txt b/src/cmd/go/testdata/script/mod_gobuild_import.txt
index 3a133663ec..c13ae844b5 100644
--- a/src/cmd/go/testdata/script/mod_gobuild_import.txt
+++ b/src/cmd/go/testdata/script/mod_gobuild_import.txt
@@ -19,7 +19,7 @@ exec $WORK/testimport$GOEXE other/x/y/z/w .
stdout w2.go
! exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w .
-stderr 'no required module provides package gobuild.example.com/x/y/z/w; try ''go get -d gobuild.example.com/x/y/z/w'' to add it'
+stderr 'no required module provides package gobuild.example.com/x/y/z/w; to add it:\n\tgo get gobuild.example.com/x/y/z/w'
cd z
exec $WORK/testimport$GOEXE other/x/y/z/w .
diff --git a/src/cmd/go/testdata/script/mod_init_tidy.txt b/src/cmd/go/testdata/script/mod_init_tidy.txt
index 6a37edd960..4a525903b2 100644
--- a/src/cmd/go/testdata/script/mod_init_tidy.txt
+++ b/src/cmd/go/testdata/script/mod_init_tidy.txt
@@ -8,14 +8,14 @@ cd ..
# 'go mod init' should recommend 'go mod tidy' if the directory has a .go file.
cd pkginroot
go mod init m
-stderr '^go: run ''go mod tidy'' to add module requirements and sums$'
+stderr '^go: to add module requirements and sums:\n\tgo mod tidy$'
cd ..
# 'go mod init' should recommend 'go mod tidy' if the directory has a
# subdirectory. We don't walk the tree to see if it has .go files.
cd subdir
go mod init m
-stderr '^go: run ''go mod tidy'' to add module requirements and sums$'
+stderr '^go: to add module requirements and sums:\n\tgo mod tidy$'
cd ..
-- empty/empty.txt --
diff --git a/src/cmd/go/testdata/script/mod_install_pkg_version.txt b/src/cmd/go/testdata/script/mod_install_pkg_version.txt
index e4a7668351..e27ebc5cc5 100644
--- a/src/cmd/go/testdata/script/mod_install_pkg_version.txt
+++ b/src/cmd/go/testdata/script/mod_install_pkg_version.txt
@@ -16,7 +16,7 @@ env GO111MODULE=auto
cd m
cp go.mod go.mod.orig
! go list -m all
-stderr '^go: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry; try ''go mod download example.com/cmd'' to add it$'
+stderr '^go: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry; to add it:\n\tgo mod download example.com/cmd$'
go install example.com/cmd/a@latest
cmp go.mod go.mod.orig
exists $GOPATH/bin/a$GOEXE
@@ -67,9 +67,9 @@ cd tmp
go mod init tmp
go mod edit -require=rsc.io/fortune@v1.0.0
! go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
-stderr '^go: rsc.io/fortune@v1.0.0: missing go.sum entry; try ''go mod download rsc.io/fortune'' to add it$'
+stderr '^go: rsc.io/fortune@v1.0.0: missing go.sum entry; to add it:\n\tgo mod download rsc.io/fortune$'
! go install -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0
-stderr '^go: rsc.io/fortune@v1.0.0: missing go.sum entry; try ''go mod download rsc.io/fortune'' to add it$'
+stderr '^go: rsc.io/fortune@v1.0.0: missing go.sum entry; to add it:\n\tgo mod download rsc.io/fortune$'
go get -d rsc.io/fortune@v1.0.0
go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
exists $GOPATH/bin/fortune$GOEXE
@@ -175,6 +175,11 @@ stdout '^\tmod\texample.com/cmd\tv1.0.0\t'
go install example.com/cmd/a@v1.9.0
go version -m $GOPATH/bin/a$GOEXE
stdout '^\tmod\texample.com/cmd\tv1.9.0\t'
+env GO111MODULE=
+
+# 'go install pkg@version' succeeds when -mod=readonly is set explicitly.
+# Verifies #43278.
+go install -mod=readonly example.com/cmd/a@v1.0.0
-- m/go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_invalid_path.txt b/src/cmd/go/testdata/script/mod_invalid_path.txt
index 05a5133571..667828839f 100644
--- a/src/cmd/go/testdata/script/mod_invalid_path.txt
+++ b/src/cmd/go/testdata/script/mod_invalid_path.txt
@@ -3,7 +3,7 @@
# Test that go list fails on a go.mod with no module declaration.
cd $WORK/gopath/src/mod
! go list .
-stderr '^go: no module declaration in go.mod.\n\tRun ''go mod edit -module=example.com/mod'' to specify the module path.$'
+stderr '^go: no module declaration in go.mod. To specify the module path:\n\tgo mod edit -module=example.com/mod$'
# Test that go mod init in GOPATH doesn't add a module declaration
# with a path that can't possibly be a module path, because
diff --git a/src/cmd/go/testdata/script/mod_list_bad_import.txt b/src/cmd/go/testdata/script/mod_list_bad_import.txt
index 3cd50b0de2..b128408a61 100644
--- a/src/cmd/go/testdata/script/mod_list_bad_import.txt
+++ b/src/cmd/go/testdata/script/mod_list_bad_import.txt
@@ -39,7 +39,7 @@ stdout example.com/notfound
# Listing the missing dependency directly should fail outright...
! go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound
-stderr 'no required module provides package example.com/notfound; try ''go get -d example.com/notfound'' to add it'
+stderr 'no required module provides package example.com/notfound; to add it:\n\tgo get example.com/notfound'
! stdout error
! stdout incomplete
diff --git a/src/cmd/go/testdata/script/mod_readonly.txt b/src/cmd/go/testdata/script/mod_readonly.txt
index ca8cd6e068..176be72967 100644
--- a/src/cmd/go/testdata/script/mod_readonly.txt
+++ b/src/cmd/go/testdata/script/mod_readonly.txt
@@ -13,7 +13,7 @@ cmp go.mod go.mod.empty
# -mod=readonly should be set by default.
env GOFLAGS=
! go list all
-stderr '^x.go:2:8: no required module provides package rsc\.io/quote; try ''go mod tidy'' to add it$'
+stderr '^x.go:2:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc\.io/quote$'
cmp go.mod go.mod.empty
env GOFLAGS=-mod=readonly
@@ -51,7 +51,7 @@ cmp go.mod go.mod.inconsistent
# We get a different message when -mod=readonly is used by default.
env GOFLAGS=
! go list
-stderr '^go: updates to go.mod needed; try ''go mod tidy'' first$'
+stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy'
# However, it should not reject files missing a 'go' directive,
# since that was not always required.
@@ -75,15 +75,15 @@ cmp go.mod go.mod.indirect
cp go.mod.untidy go.mod
! go list all
-stderr '^x.go:2:8: no required module provides package rsc.io/quote; try ''go mod tidy'' to add it$'
+stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$'
! go list -deps .
-stderr '^x.go:2:8: no required module provides package rsc.io/quote; try ''go mod tidy'' to add it$'
+stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$'
# However, if we didn't see an import from the main module, we should suggest
# 'go get -d' instead, because we don't know whether 'go mod tidy' would add it.
! go list rsc.io/quote
-stderr '^no required module provides package rsc.io/quote; try ''go get -d rsc.io/quote'' to add it$'
+stderr '^no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$'
-- go.mod --
diff --git a/src/cmd/go/testdata/script/mod_replace_readonly.txt b/src/cmd/go/testdata/script/mod_replace_readonly.txt
index 882c755337..d950d78bd3 100644
--- a/src/cmd/go/testdata/script/mod_replace_readonly.txt
+++ b/src/cmd/go/testdata/script/mod_replace_readonly.txt
@@ -9,7 +9,7 @@ cp go.mod go.mod.orig
# can't in readonly mode, since its go.mod may alter the build list.
go mod edit -replace rsc.io/quote=./quote
! go list rsc.io/quote
-stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; try ''go get -d rsc.io/quote'' to add it$'
+stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote$'
go get -d rsc.io/quote
cmp go.mod go.mod.latest
go list rsc.io/quote
@@ -18,7 +18,7 @@ cp go.mod.orig go.mod
# Same test with a specific version.
go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
! go list rsc.io/quote
-stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; try ''go get -d rsc.io/quote@v1.0.0-doesnotexist'' to add it$'
+stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.0.0-doesnotexist$'
go get -d rsc.io/quote@v1.0.0-doesnotexist
cmp go.mod go.mod.specific
go list rsc.io/quote
@@ -28,7 +28,7 @@ cp go.mod.orig go.mod
go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
go mod edit -replace rsc.io/quote@v1.1.0-doesnotexist=./quote
! go list rsc.io/quote
-stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; try ''go get -d rsc.io/quote@v1.1.0-doesnotexist'' to add it$'
+stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.1.0-doesnotexist$'
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_sum_ambiguous.txt b/src/cmd/go/testdata/script/mod_sum_ambiguous.txt
index 999257c419..07c6659177 100644
--- a/src/cmd/go/testdata/script/mod_sum_ambiguous.txt
+++ b/src/cmd/go/testdata/script/mod_sum_ambiguous.txt
@@ -10,20 +10,34 @@ go mod tidy
grep '^example.com/ambiguous/a v1.0.0 h1:' go.sum
grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum
+# 'go mod download' should also add sums.
+cp go.sum.buildlist-only go.sum
+go mod download example.com/ambiguous/a
+grep '^example.com/ambiguous/a v1.0.0 h1:' go.sum
+! grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum
+go mod download example.com/ambiguous/a/b
+grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum
+
# If two modules could provide a package, and we're missing a sum for one,
# we should see a missing sum error, even if we have a sum for a module that
# provides the package.
cp go.sum.a-only go.sum
! go list example.com/ambiguous/a/b
-stderr '^missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module$'
+stderr '^missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module; to add:\n\tgo mod download example.com/ambiguous/a/b$'
! go list -deps .
-stderr '^use.go:3:8: missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module; try ''go mod tidy'' to add it$'
+stderr '^use.go:3:8: missing go.sum entry needed to verify package example.com/ambiguous/a/b \(imported by m\) is provided by exactly one module; to add:\n\tgo get m$'
cp go.sum.b-only go.sum
! go list example.com/ambiguous/a/b
-stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b$'
+stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b; to add:\n\tgo mod download example.com/ambiguous/a$'
+! go list -deps .
+stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b \(imported by m\); to add:\n\tgo get m$'
+
+cp go.sum.buildlist-only go.sum
+! go list example.com/ambiguous/a/b
+stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b; to add:\n\tgo mod download example.com/ambiguous/a example.com/ambiguous/a/b$'
! go list -deps .
-stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b; try ''go mod tidy'' to add it$'
+stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b \(imported by m\); to add:\n\tgo get m$'
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_sum_readonly.txt b/src/cmd/go/testdata/script/mod_sum_readonly.txt
index 4d6e8aae6a..57c5bbeefd 100644
--- a/src/cmd/go/testdata/script/mod_sum_readonly.txt
+++ b/src/cmd/go/testdata/script/mod_sum_readonly.txt
@@ -4,7 +4,7 @@ env GO111MODULE=on
# When a sum is needed to load the build list, we get an error for the
# specific module. The .mod file is not downloaded, and go.sum is not written.
! go list -m all
-stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry; try ''go mod download rsc.io/quote'' to add it$'
+stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry; to add it:\n\tgo mod download rsc.io/quote$'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
! exists go.sum
@@ -12,7 +12,7 @@ stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry; try ''go mod download rs
# we should see the same error.
cp go.sum.h2only go.sum
! go list -m all
-stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry; try ''go mod download rsc.io/quote'' to add it$'
+stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry; to add it:\n\tgo mod download rsc.io/quote$'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
cmp go.sum go.sum.h2only
rm go.sum
@@ -21,7 +21,7 @@ rm go.sum
cp go.mod go.mod.orig
go mod edit -replace rsc.io/quote@v1.5.2=rsc.io/quote@v1.5.1
! go list -m all
-stderr '^go: rsc.io/quote@v1.5.2 \(replaced by rsc.io/quote@v1.5.1\): missing go.sum entry; try ''go mod download rsc.io/quote'' to add it$'
+stderr '^go: rsc.io/quote@v1.5.2 \(replaced by rsc.io/quote@v1.5.1\): missing go.sum entry; to add it:\n\tgo mod download rsc.io/quote$'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.mod
! exists go.sum
cp go.mod.orig go.mod
@@ -35,19 +35,19 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
# When a sum is needed to load a .mod file for a package outside the build list,
# we get a generic missing import error.
! go list example.com/doesnotexist
-stderr '^no required module provides package example.com/doesnotexist; try ''go get -d example.com/doesnotexist'' to add it$'
+stderr '^no required module provides package example.com/doesnotexist; to add it:\n\tgo get example.com/doesnotexist$'
# When a sum is needed to load a .zip file, we get a more specific error.
# The .zip file is not downloaded.
! go list rsc.io/quote
-stderr '^missing go.sum entry for module providing package rsc.io/quote$'
+stderr '^missing go.sum entry for module providing package rsc.io/quote; to add:\n\tgo mod download rsc.io/quote$'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
# The error is attached to the package from the missing module. We can load
# a package that imports it without that error.
go list -e -deps -f '{{.ImportPath}}{{with .Error}} {{.Err}}{{end}}' .
stdout '^m$'
-stdout '^rsc.io/quote missing go.sum entry for module providing package rsc.io/quote; try ''go mod tidy'' to add it$'
+stdout '^rsc.io/quote missing go.sum entry for module providing package rsc.io/quote \(imported by m\); to add:\n\tgo get m$'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
# go.sum should not have been written.
diff --git a/src/cmd/go/testdata/script/mod_vendor_auto.txt b/src/cmd/go/testdata/script/mod_vendor_auto.txt
index 1b362eda0b..b0ea907206 100644
--- a/src/cmd/go/testdata/script/mod_vendor_auto.txt
+++ b/src/cmd/go/testdata/script/mod_vendor_auto.txt
@@ -66,7 +66,7 @@ stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
-stderr '\n\nrun .go mod vendor. to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory$'
+stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
# Module-specific subcommands should continue to load the full module graph.
go mod graph
@@ -135,7 +135,7 @@ stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
-stderr '\n\nrun .go mod vendor. to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory$'
+stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
# If -mod=vendor is set, limited consistency checks should apply even when
# the go version is 1.13 or earlier.
@@ -151,7 +151,7 @@ cp $WORK/modules-bad-1.13.txt vendor/modules.txt
! go list -mod=vendor -f {{.Dir}} -tags tools all
stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but vendor/modules.txt indicates example.com/printversion@v1.1.0$'
-stderr '\n\nrun .go mod vendor. to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory$'
+stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
# If the go version is still 1.13, 'go mod vendor' should write a
# matching vendor/modules.txt containing the corrected 1.13 data.
diff --git a/src/cmd/go/testdata/script/mod_vendor_embed.txt b/src/cmd/go/testdata/script/mod_vendor_embed.txt
new file mode 100644
index 0000000000..be114159a1
--- /dev/null
+++ b/src/cmd/go/testdata/script/mod_vendor_embed.txt
@@ -0,0 +1,179 @@
+go mod vendor
+cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt
+cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt
+cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt
+cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt
+
+cd broken_no_matching_files
+! go mod vendor
+stderr 'go mod vendor: pattern foo.txt: no matching files found'
+
+cd ../broken_bad_pattern
+! go mod vendor
+stderr 'go mod vendor: pattern ../foo.txt: invalid pattern syntax'
+
+# matchPotentialSourceFile prunes out tests and unbuilt code.
+# Make sure that they are vendored if they are embedded files.
+cd ../embed_unbuilt
+go mod vendor
+cmp vendor/example.com/dep/unbuilt.go dep/unbuilt.go
+cmp vendor/example.com/dep/dep_test.go dep/dep_test.go
+! exists vendor/example.com/dep/not_embedded_unbuilt.go
+! exists vendor/example.com/dep/not_embedded_dep_test.go
+-- go.mod --
+module example.com/foo
+go 1.16
+
+require (
+ example.com/a v0.1.0
+)
+
+replace (
+ example.com/a v0.1.0 => ./a
+)
+-- foo.go --
+package main
+
+import (
+ "fmt"
+
+ "example.com/a"
+)
+
+func main() {
+ fmt.Println(a.Str())
+}
+-- a/go.mod --
+module example.com/a
+-- a/a.go --
+package a
+
+import _ "embed"
+
+//go:embed samedir_embed.txt
+var sameDir string
+
+//go:embed subdir/embed.txt
+var subDir string
+
+func Str() string {
+ return sameDir + subDir
+}
+-- a/a_test.go --
+package a
+
+import _ "embed"
+
+//go:embed subdir/test/embed.txt
+var subderTest string
+-- a/a_x_test.go --
+package a_test
+
+import _ "embed"
+
+//go:embed subdir/test/xtest/embed.txt
+var subdirXtest string
+-- a/samedir_embed.txt --
+embedded file in same directory as package
+-- a/subdir/embed.txt --
+embedded file in subdirectory of package
+-- a/subdir/test/embed.txt --
+embedded file of test in subdirectory of package
+-- a/subdir/test/xtest/embed.txt --
+embedded file of xtest in subdirectory of package
+-- broken_no_matching_files/go.mod --
+module example.com/broken
+go 1.16
+
+require (
+ example.com/brokendep v0.1.0
+)
+
+replace (
+ example.com/brokendep v0.1.0 => ./brokendep
+)
+-- broken_no_matching_files/f.go --
+package broken
+
+import _ "example.com/brokendep"
+
+func F() {}
+-- broken_no_matching_files/brokendep/go.mod --
+module example.com/brokendep
+go 1.16
+-- broken_no_matching_files/brokendep/f.go --
+package brokendep
+
+import _ "embed"
+
+//go:embed foo.txt
+var foo string
+-- broken_bad_pattern/go.mod --
+module example.com/broken
+go 1.16
+
+require (
+ example.com/brokendep v0.1.0
+)
+
+replace (
+ example.com/brokendep v0.1.0 => ./brokendep
+)
+-- broken_bad_pattern/f.go --
+package broken
+
+import _ "example.com/brokendep"
+
+func F() {}
+-- broken_bad_pattern/brokendep/go.mod --
+module example.com/brokendep
+go 1.16
+-- broken_bad_pattern/brokendep/f.go --
+package brokendep
+
+import _ "embed"
+
+//go:embed ../foo.txt
+var foo string
+-- embed_unbuilt/go.mod --
+module example.com/foo
+go 1.16
+
+require (
+ example.com/dep v0.1.0
+)
+
+replace (
+ example.com/dep v0.1.0 => ./dep
+)
+-- embed_unbuilt/foo.go --
+package a
+
+import _ "example.com/dep"
+
+func F() {}
+-- embed_unbuilt/dep/go.mod --
+module example.com/dep
+go 1.16
+-- embed_unbuilt/dep/dep.go --
+package dep
+
+import _ "embed"
+
+//go:embed unbuilt.go
+var unbuilt string
+
+//go:embed dep_test.go
+var depTest string
+-- embed_unbuilt/dep/unbuilt.go --
+// +build ignore
+
+package dep
+-- embed_unbuilt/dep/not_embedded_unbuilt.go --
+// +build ignore
+
+package dep
+-- embed_unbuilt/dep/dep_test.go --
+package dep
+-- embed_unbuilt/dep/not_embedded_dep_test.go --
+package dep
diff --git a/src/cmd/go/testdata/script/mod_versions.txt b/src/cmd/go/testdata/script/mod_versions.txt
index fd5e5c589d..9e6322bae1 100644
--- a/src/cmd/go/testdata/script/mod_versions.txt
+++ b/src/cmd/go/testdata/script/mod_versions.txt
@@ -1,14 +1,14 @@
# Test rejection of pkg@version in GOPATH mode.
env GO111MODULE=off
! go get rsc.io/quote@v1.5.1
-stderr 'cannot use path@version syntax in GOPATH mode'
+stderr '^go: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
! go build rsc.io/quote@v1.5.1
-stderr 'cannot use path@version syntax in GOPATH mode'
+stderr '^package rsc.io/quote@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
env GO111MODULE=on
cd x
! go build rsc.io/quote@v1.5.1
-stderr 'can only use path@version syntax with ''go get'''
+stderr '^package rsc.io/quote@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
-- x/go.mod --
module x
diff --git a/src/cmd/go/testdata/script/test_exit.txt b/src/cmd/go/testdata/script/test_exit.txt
index 23a2429d1e..3703ba53d3 100644
--- a/src/cmd/go/testdata/script/test_exit.txt
+++ b/src/cmd/go/testdata/script/test_exit.txt
@@ -54,6 +54,23 @@ go test -list=. ./main_zero
stdout 'skipping all tests'
! stdout TestNotListed
+# Running the test directly still fails, if we pass the flag.
+go test -c -o ./zero.exe ./zero
+! exec ./zero.exe -test.paniconexit0
+
+# Using -json doesn't affect the exit status.
+! go test -json ./zero
+! stdout '"Output":"ok'
+! stdout 'exit status'
+stdout 'panic'
+stdout '"Output":"FAIL'
+
+# Running the test via test2json also fails.
+! go tool test2json ./zero.exe -test.v -test.paniconexit0
+! stdout '"Output":"ok'
+! stdout 'exit status'
+stdout 'panic'
+
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/test_flag.txt b/src/cmd/go/testdata/script/test_flag.txt
index ec88d38cbe..0142b3f308 100644
--- a/src/cmd/go/testdata/script/test_flag.txt
+++ b/src/cmd/go/testdata/script/test_flag.txt
@@ -9,13 +9,13 @@ go test -count=1 -custom -args -v=7
# However, it should be an error to use custom flags when -i or -c are used,
# since we know for sure that no test binary will run at all.
! go test -i -custom
-stderr '^flag -custom is not a ''go test'' flag \(unknown flags cannot be used with -i\)$'
+stderr '^go test: unknown flag -custom cannot be used with -i$'
! go test -c -custom
-stderr '^flag -custom is not a ''go test'' flag \(unknown flags cannot be used with -c\)$'
+stderr '^go test: unknown flag -custom cannot be used with -c$'
# The same should apply even if -c or -i come after a custom flag.
! go test -custom -c
-stderr '^flag -custom is not a ''go test'' flag \(unknown flags cannot be used with -c\)$'
+stderr '^go test: unknown flag -custom cannot be used with -c$'
-- go.mod --
module m
diff --git a/src/cmd/internal/browser/browser.go b/src/cmd/internal/browser/browser.go
index 6867c85d23..577d31789f 100644
--- a/src/cmd/internal/browser/browser.go
+++ b/src/cmd/internal/browser/browser.go
@@ -6,8 +6,8 @@
package browser
import (
+ exec "internal/execabs"
"os"
- "os/exec"
"runtime"
"time"
)
diff --git a/src/cmd/internal/diff/diff.go b/src/cmd/internal/diff/diff.go
index e9d2c23780..c0ca2f3106 100644
--- a/src/cmd/internal/diff/diff.go
+++ b/src/cmd/internal/diff/diff.go
@@ -7,9 +7,9 @@
package diff
import (
+ exec "internal/execabs"
"io/ioutil"
"os"
- "os/exec"
"runtime"
)
diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go
index e1a70ef853..8de4096f06 100644
--- a/src/cmd/internal/dwarf/dwarf.go
+++ b/src/cmd/internal/dwarf/dwarf.go
@@ -12,7 +12,7 @@ import (
"cmd/internal/objabi"
"errors"
"fmt"
- "os/exec"
+ exec "internal/execabs"
"sort"
"strconv"
"strings"
diff --git a/src/cmd/internal/goobj/mkbuiltin.go b/src/cmd/internal/goobj/mkbuiltin.go
index 07c3406681..22608e7e69 100644
--- a/src/cmd/internal/goobj/mkbuiltin.go
+++ b/src/cmd/internal/goobj/mkbuiltin.go
@@ -118,8 +118,8 @@ func mkbuiltin(w io.Writer) {
// addBasicTypes returns the symbol names for basic types that are
// defined in the runtime and referenced in other packages.
-// Needs to be kept in sync with reflect.go:dumpbasictypes() and
-// reflect.go:dtypesym() in the compiler.
+// Needs to be kept in sync with reflect.go:WriteBasicTypes() and
+// reflect.go:writeType() in the compiler.
func enumerateBasicTypes() []extra {
names := [...]string{
"int8", "uint8", "int16", "uint16",
diff --git a/src/cmd/internal/moddeps/moddeps_test.go b/src/cmd/internal/moddeps/moddeps_test.go
index 9ea21873c5..cba401c896 100644
--- a/src/cmd/internal/moddeps/moddeps_test.go
+++ b/src/cmd/internal/moddeps/moddeps_test.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"internal/testenv"
+ "io"
"io/fs"
"io/ioutil"
"os"
@@ -21,93 +22,34 @@ import (
"golang.org/x/mod/module"
)
-type gorootModule struct {
- Path string
- Dir string
- hasVendor bool
-}
-
-// findGorootModules returns the list of modules found in the GOROOT source tree.
-func findGorootModules(t *testing.T) []gorootModule {
- t.Helper()
- goBin := testenv.GoToolPath(t)
-
- goroot.once.Do(func() {
- goroot.err = filepath.WalkDir(runtime.GOROOT(), func(path string, info fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if info.IsDir() && (info.Name() == "vendor" || info.Name() == "testdata") {
- return filepath.SkipDir
- }
- if path == filepath.Join(runtime.GOROOT(), "pkg") {
- // GOROOT/pkg contains generated artifacts, not source code.
- //
- // In https://golang.org/issue/37929 it was observed to somehow contain
- // a module cache, so it is important to skip. (That helps with the
- // running time of this test anyway.)
- return filepath.SkipDir
- }
- if info.IsDir() || info.Name() != "go.mod" {
- return nil
- }
- dir := filepath.Dir(path)
-
- // Use 'go list' to describe the module contained in this directory (but
- // not its dependencies).
- cmd := exec.Command(goBin, "list", "-json", "-m")
- cmd.Env = append(os.Environ(), "GO111MODULE=on")
- cmd.Dir = dir
- cmd.Stderr = new(strings.Builder)
- out, err := cmd.Output()
- if err != nil {
- return fmt.Errorf("'go list -json -m' in %s: %w\n%s", dir, err, cmd.Stderr)
- }
-
- var m gorootModule
- if err := json.Unmarshal(out, &m); err != nil {
- return fmt.Errorf("decoding 'go list -json -m' in %s: %w", dir, err)
- }
- if m.Path == "" || m.Dir == "" {
- return fmt.Errorf("'go list -json -m' in %s failed to populate Path and/or Dir", dir)
- }
- if _, err := os.Stat(filepath.Join(dir, "vendor")); err == nil {
- m.hasVendor = true
- }
- goroot.modules = append(goroot.modules, m)
- return nil
- })
- })
-
- if goroot.err != nil {
- t.Fatal(goroot.err)
- }
- return goroot.modules
-}
-
-// goroot caches the list of modules found in the GOROOT source tree.
-var goroot struct {
- once sync.Once
- modules []gorootModule
- err error
-}
-
-// TestAllDependenciesVendored ensures that all packages imported within GOROOT
-// are vendored in the corresponding GOROOT module.
+// TestAllDependencies ensures dependencies of all
+// modules in GOROOT are in a consistent state.
//
-// This property allows offline development within the Go project, and ensures
-// that all dependency changes are presented in the usual code review process.
+// In short mode, it does a limited quick check and stops there.
+// In long mode, it also makes a copy of the entire GOROOT tree
+// and requires network access to perform more thorough checks.
+// Keep this distinction in mind when adding new checks.
//
-// This test does NOT ensure that the vendored contents match the unmodified
-// contents of the corresponding dependency versions. Such as test would require
-// network access, and would currently either need to copy the entire GOROOT module
-// or explicitly invoke version control to check for changes.
-// (See golang.org/issue/36852 and golang.org/issue/27348.)
-func TestAllDependenciesVendored(t *testing.T) {
+// See issues 36852, 41409, and 43687.
+// (Also see golang.org/issue/27348.)
+func TestAllDependencies(t *testing.T) {
goBin := testenv.GoToolPath(t)
+ // Ensure that all packages imported within GOROOT
+ // are vendored in the corresponding GOROOT module.
+ //
+ // This property allows offline development within the Go project, and ensures
+ // that all dependency changes are presented in the usual code review process.
+ //
+ // As a quick first-order check, avoid network access and the need to copy the
+ // entire GOROOT tree or explicitly invoke version control to check for changes.
+ // Just check that packages are vendored. (In non-short mode, we go on to also
+ // copy the GOROOT tree and perform more rigorous consistency checks. Jump below
+ // for more details.)
for _, m := range findGorootModules(t) {
- t.Run(m.Path, func(t *testing.T) {
+ // This short test does NOT ensure that the vendored contents match
+ // the unmodified contents of the corresponding dependency versions.
+ t.Run(m.Path+"(quick)", func(t *testing.T) {
if m.hasVendor {
// Load all of the packages in the module to ensure that their
// dependencies are vendored. If any imported package is missing,
@@ -140,6 +82,226 @@ func TestAllDependenciesVendored(t *testing.T) {
}
})
}
+
+ // We now get to the slow, but more thorough part of the test.
+ // Only run it in long test mode.
+ if testing.Short() {
+ return
+ }
+
+ // Ensure that all modules within GOROOT are tidy, vendored, and bundled.
+ // Ensure that the vendored contents match the unmodified contents of the
+ // corresponding dependency versions.
+ //
+ // The non-short section of this test requires network access and the diff
+ // command.
+ //
+ // It makes a temporary copy of the entire GOROOT tree (where it can safely
+ // perform operations that may mutate the tree), executes the same module
+ // maintenance commands that we expect Go developers to run, and then
+ // diffs the potentially modified module copy with the real one in GOROOT.
+ // (We could try to rely on Git to do things differently, but that's not the
+ // path we've chosen at this time. This allows the test to run when the tree
+ // is not checked into Git.)
+
+ testenv.MustHaveExternalNetwork(t)
+ if haveDiff := func() bool {
+ diff, err := exec.Command("diff", "--recursive", "--unified", ".", ".").CombinedOutput()
+ if err != nil || len(diff) != 0 {
+ return false
+ }
+ diff, err = exec.Command("diff", "--recursive", "--unified", ".", "..").CombinedOutput()
+ if err == nil || len(diff) == 0 {
+ return false
+ }
+ return true
+ }(); !haveDiff {
+ // For now, the diff command is a mandatory dependency of this test.
+ // This test will primarily run on longtest builders, since few people
+ // would test the cmd/internal/moddeps package directly, and all.bash
+ // runs tests in short mode. It's fine to skip if diff is unavailable.
+ t.Skip("skipping because a diff command with support for --recursive and --unified flags is unavailable")
+ }
+
+ // Build the bundle binary at the golang.org/x/tools
+ // module version specified in GOROOT/src/cmd/go.mod.
+ bundleDir := t.TempDir()
+ r := runner{Dir: filepath.Join(runtime.GOROOT(), "src/cmd")}
+ r.run(t, goBin, "build", "-mod=readonly", "-o", bundleDir, "golang.org/x/tools/cmd/bundle")
+
+ var gorootCopyDir string
+ for _, m := range findGorootModules(t) {
+ // Create a test-wide GOROOT copy. It can be created once
+ // and reused between subtests whenever they don't fail.
+ //
+ // This is a relatively expensive operation, but it's a pre-requisite to
+ // be able to safely run commands like "go mod tidy", "go mod vendor", and
+ // "go generate" on the GOROOT tree content. Those commands may modify the
+ // tree, and we don't want to happen to the real tree as part of executing
+ // a test.
+ if gorootCopyDir == "" {
+ gorootCopyDir = makeGOROOTCopy(t)
+ }
+
+ t.Run(m.Path+"(thorough)", func(t *testing.T) {
+ defer func() {
+ if t.Failed() {
+ // The test failed, which means it's possible the GOROOT copy
+ // may have been modified. No choice but to reset it for next
+ // module test case. (This is slow, but it happens only during
+ // test failures.)
+ gorootCopyDir = ""
+ }
+ }()
+
+ rel, err := filepath.Rel(runtime.GOROOT(), m.Dir)
+ if err != nil {
+ t.Fatalf("filepath.Rel(%q, %q): %v", runtime.GOROOT(), m.Dir, err)
+ }
+ r := runner{
+ Dir: filepath.Join(gorootCopyDir, rel),
+ Env: append(os.Environ(),
+ // Set GOROOT.
+ "GOROOT="+gorootCopyDir,
+ // Explicitly clear PWD and GOROOT_FINAL so that GOROOT=gorootCopyDir is definitely used.
+ "PWD=",
+ "GOROOT_FINAL=",
+ // Add GOROOTcopy/bin and bundleDir to front of PATH.
+ "PATH="+filepath.Join(gorootCopyDir, "bin")+string(filepath.ListSeparator)+
+ bundleDir+string(filepath.ListSeparator)+os.Getenv("PATH"),
+ ),
+ }
+ goBinCopy := filepath.Join(gorootCopyDir, "bin", "go")
+ r.run(t, goBinCopy, "mod", "tidy") // See issue 43687.
+ r.run(t, goBinCopy, "mod", "verify") // Verify should be a no-op, but test it just in case.
+ r.run(t, goBinCopy, "mod", "vendor") // See issue 36852.
+ pkgs := packagePattern(m.Path)
+ r.run(t, goBinCopy, "generate", `-run=^//go:generate bundle `, pkgs) // See issue 41409.
+ advice := "$ cd " + m.Dir + "\n" +
+ "$ go mod tidy # to remove extraneous dependencies\n" +
+ "$ go mod vendor # to vendor dependecies\n" +
+ "$ go generate -run=bundle " + pkgs + " # to regenerate bundled packages\n"
+ if m.Path == "std" {
+ r.run(t, goBinCopy, "generate", "syscall", "internal/syscall/...") // See issue 43440.
+ advice += "$ go generate syscall internal/syscall/... # to regenerate syscall packages\n"
+ }
+ // TODO(golang.org/issue/43440): Check anything else influenced by dependency versions.
+
+ diff, err := exec.Command("diff", "--recursive", "--unified", r.Dir, m.Dir).CombinedOutput()
+ if err != nil || len(diff) != 0 {
+ t.Errorf(`Module %s in %s is not tidy (-want +got):
+
+%s
+To fix it, run:
+
+%s
+(If module %[1]s is definitely tidy, this could mean
+there's a problem in the go or bundle command.)`, m.Path, m.Dir, diff, advice)
+ }
+ })
+ }
+}
+
+// packagePattern returns a package pattern that matches all packages
+// in the module modulePath, and ideally as few others as possible.
+func packagePattern(modulePath string) string {
+ if modulePath == "std" {
+ return "std"
+ }
+ return modulePath + "/..."
+}
+
+// makeGOROOTCopy makes a temporary copy of the current GOROOT tree.
+// The goal is to allow the calling test t to safely mutate a GOROOT
+// copy without also modifying the original GOROOT.
+//
+// It copies the entire tree as is, with the exception of the GOROOT/.git
+// directory, which is skipped, and the GOROOT/{bin,pkg} directories,
+// which are symlinked. This is done for speed, since a GOROOT tree is
+// functional without being in a Git repository, and bin and pkg are
+// deemed safe to share for the purpose of the TestAllDependencies test.
+func makeGOROOTCopy(t *testing.T) string {
+ t.Helper()
+ gorootCopyDir := t.TempDir()
+ err := filepath.Walk(runtime.GOROOT(), func(src string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+ if src == filepath.Join(runtime.GOROOT(), ".git") {
+ return filepath.SkipDir
+ }
+
+ rel, err := filepath.Rel(runtime.GOROOT(), src)
+ if err != nil {
+ return fmt.Errorf("filepath.Rel(%q, %q): %v", runtime.GOROOT(), src, err)
+ }
+ dst := filepath.Join(gorootCopyDir, rel)
+
+ switch src {
+ case filepath.Join(runtime.GOROOT(), "bin"),
+ filepath.Join(runtime.GOROOT(), "pkg"):
+ // If the OS supports symlinks, use them instead
+ // of copying the bin and pkg directories.
+ if err := os.Symlink(src, dst); err == nil {
+ return filepath.SkipDir
+ }
+ }
+
+ perm := info.Mode() & os.ModePerm
+ if info.Mode()&os.ModeSymlink != 0 {
+ info, err = os.Stat(src)
+ if err != nil {
+ return err
+ }
+ perm = info.Mode() & os.ModePerm
+ }
+
+ // If it's a directory, make a corresponding directory.
+ if info.IsDir() {
+ return os.MkdirAll(dst, perm|0200)
+ }
+
+ // Copy the file bytes.
+ // We can't create a symlink because the file may get modified;
+ // we need to ensure that only the temporary copy is affected.
+ s, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer s.Close()
+ d, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
+ if err != nil {
+ return err
+ }
+ _, err = io.Copy(d, s)
+ if err != nil {
+ d.Close()
+ return err
+ }
+ return d.Close()
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ return gorootCopyDir
+}
+
+type runner struct {
+ Dir string
+ Env []string
+}
+
+// run runs the command and requires that it succeeds.
+func (r runner) run(t *testing.T, args ...string) {
+ t.Helper()
+ cmd := exec.Command(args[0], args[1:]...)
+ cmd.Dir = r.Dir
+ cmd.Env = r.Env
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Logf("> %s\n", strings.Join(args, " "))
+ t.Fatalf("command failed: %s\n%s", err, out)
+ }
}
// TestDependencyVersionsConsistent verifies that each module in GOROOT that
@@ -159,8 +321,7 @@ func TestDependencyVersionsConsistent(t *testing.T) {
seen := map[string]map[requirement][]gorootModule{} // module path → requirement → set of modules with that requirement
for _, m := range findGorootModules(t) {
if !m.hasVendor {
- // TestAllDependenciesVendored will ensure that the module has no
- // dependencies.
+ // TestAllDependencies will ensure that the module has no dependencies.
continue
}
@@ -233,3 +394,74 @@ func TestDependencyVersionsConsistent(t *testing.T) {
}
}
}
+
+type gorootModule struct {
+ Path string
+ Dir string
+ hasVendor bool
+}
+
+// findGorootModules returns the list of modules found in the GOROOT source tree.
+func findGorootModules(t *testing.T) []gorootModule {
+ t.Helper()
+ goBin := testenv.GoToolPath(t)
+
+ goroot.once.Do(func() {
+ goroot.err = filepath.WalkDir(runtime.GOROOT(), func(path string, info fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ if info.IsDir() && (info.Name() == "vendor" || info.Name() == "testdata") {
+ return filepath.SkipDir
+ }
+ if path == filepath.Join(runtime.GOROOT(), "pkg") {
+ // GOROOT/pkg contains generated artifacts, not source code.
+ //
+ // In https://golang.org/issue/37929 it was observed to somehow contain
+ // a module cache, so it is important to skip. (That helps with the
+ // running time of this test anyway.)
+ return filepath.SkipDir
+ }
+ if info.IsDir() || info.Name() != "go.mod" {
+ return nil
+ }
+ dir := filepath.Dir(path)
+
+ // Use 'go list' to describe the module contained in this directory (but
+ // not its dependencies).
+ cmd := exec.Command(goBin, "list", "-json", "-m")
+ cmd.Env = append(os.Environ(), "GO111MODULE=on")
+ cmd.Dir = dir
+ cmd.Stderr = new(strings.Builder)
+ out, err := cmd.Output()
+ if err != nil {
+ return fmt.Errorf("'go list -json -m' in %s: %w\n%s", dir, err, cmd.Stderr)
+ }
+
+ var m gorootModule
+ if err := json.Unmarshal(out, &m); err != nil {
+ return fmt.Errorf("decoding 'go list -json -m' in %s: %w", dir, err)
+ }
+ if m.Path == "" || m.Dir == "" {
+ return fmt.Errorf("'go list -json -m' in %s failed to populate Path and/or Dir", dir)
+ }
+ if _, err := os.Stat(filepath.Join(dir, "vendor")); err == nil {
+ m.hasVendor = true
+ }
+ goroot.modules = append(goroot.modules, m)
+ return nil
+ })
+ })
+
+ if goroot.err != nil {
+ t.Fatal(goroot.err)
+ }
+ return goroot.modules
+}
+
+// goroot caches the list of modules found in the GOROOT source tree.
+var goroot struct {
+ once sync.Once
+ modules []gorootModule
+ err error
+}
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index 977c5c3303..35cb53cbf6 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -766,6 +766,17 @@ type Auto struct {
Gotype *LSym
}
+// RegArg provides spill/fill information for a register-resident argument
+// to a function. These need spilling/filling in the safepoint/stackgrowth case.
+// At the time of fill/spill, the offset must be adjusted by the architecture-dependent
+// adjustment to hardware SP that occurs in a call instruction. E.g., for AMD64,
+// at Offset+8 because the return address was pushed.
+type RegArg struct {
+ Addr Addr
+ Reg int16
+ Spill, Unspill As
+}
+
// Link holds the context for writing object code from a compiler
// to be linker input or for reading that input into the linker.
type Link struct {
@@ -796,6 +807,7 @@ type Link struct {
DebugInfo func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
GenAbstractFunc func(fn *LSym)
Errors int
+ RegArgs []RegArg
InParallel bool // parallel backend phase in effect
UseBASEntries bool // use Base Address Selection Entries in location lists and PC ranges
@@ -844,6 +856,32 @@ func (ctxt *Link) Logf(format string, args ...interface{}) {
ctxt.Bso.Flush()
}
+func (ctxt *Link) SpillRegisterArgs(last *Prog, pa ProgAlloc) *Prog {
+ // Spill register args.
+ for _, ra := range ctxt.RegArgs {
+ spill := Appendp(last, pa)
+ spill.As = ra.Spill
+ spill.From.Type = TYPE_REG
+ spill.From.Reg = ra.Reg
+ spill.To = ra.Addr
+ last = spill
+ }
+ return last
+}
+
+func (ctxt *Link) UnspillRegisterArgs(last *Prog, pa ProgAlloc) *Prog {
+ // Unspill any spilled register args
+ for _, ra := range ctxt.RegArgs {
+ unspill := Appendp(last, pa)
+ unspill.As = ra.Unspill
+ unspill.From = ra.Addr
+ unspill.To.Type = TYPE_REG
+ unspill.To.Reg = ra.Reg
+ last = unspill
+ }
+ return last
+}
+
// The smallest possible offset from the hardware stack pointer to a local
// variable on the stack. Architectures that use a link register save its value
// on the stack in the function prologue and so always have a pointer between
diff --git a/src/cmd/internal/obj/textflag.go b/src/cmd/internal/obj/textflag.go
index fcc4014aa2..2f55793285 100644
--- a/src/cmd/internal/obj/textflag.go
+++ b/src/cmd/internal/obj/textflag.go
@@ -33,7 +33,7 @@ const (
// This function uses its incoming context register.
NEEDCTXT = 64
- // When passed to ggloblsym, causes Local to be set to true on the LSym it creates.
+ // When passed to objw.Global, causes Local to be set to true on the LSym it creates.
LOCAL = 128
// Allocate a word of thread local storage and store the offset from the
diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go
index 839aeb8fe3..1674db626f 100644
--- a/src/cmd/internal/obj/x86/obj6.go
+++ b/src/cmd/internal/obj/x86/obj6.go
@@ -1114,7 +1114,8 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
spfix.Spadj = -framesize
pcdata := ctxt.EmitEntryStackMap(cursym, spfix, newprog)
- pcdata = ctxt.StartUnsafePoint(pcdata, newprog)
+ spill := ctxt.StartUnsafePoint(pcdata, newprog)
+ pcdata = ctxt.SpillRegisterArgs(spill, newprog)
call := obj.Appendp(pcdata, newprog)
call.Pos = cursym.Func().Text.Pos
@@ -1139,7 +1140,8 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
progedit(ctxt, callend.Link, newprog)
}
- pcdata = ctxt.EndUnsafePoint(callend, newprog, -1)
+ pcdata = ctxt.UnspillRegisterArgs(callend, newprog)
+ pcdata = ctxt.EndUnsafePoint(pcdata, newprog, -1)
jmp := obj.Appendp(pcdata, newprog)
jmp.As = obj.AJMP
@@ -1147,9 +1149,9 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
jmp.To.SetTarget(cursym.Func().Text.Link)
jmp.Spadj = +framesize
- jls.To.SetTarget(call)
+ jls.To.SetTarget(spill)
if q1 != nil {
- q1.To.SetTarget(call)
+ q1.To.SetTarget(spill)
}
return end
diff --git a/src/cmd/internal/objfile/xcoff.go b/src/cmd/internal/objfile/xcoff.go
index d438c80226..d6df4db8f0 100644
--- a/src/cmd/internal/objfile/xcoff.go
+++ b/src/cmd/internal/objfile/xcoff.go
@@ -94,9 +94,7 @@ func (f *xcoffFile) pcln() (textStart uint64, symtab, pclntab []byte, err error)
if pclntab, err = loadXCOFFTable(f.xcoff, "runtime.pclntab", "runtime.epclntab"); err != nil {
return 0, nil, nil, err
}
- if symtab, err = loadXCOFFTable(f.xcoff, "runtime.symtab", "runtime.esymtab"); err != nil {
- return 0, nil, nil, err
- }
+ symtab, _ = loadXCOFFTable(f.xcoff, "runtime.symtab", "runtime.esymtab") // ignore error, this symbol is not useful anyway
return textStart, symtab, pclntab, nil
}
diff --git a/src/cmd/internal/pkgpath/pkgpath.go b/src/cmd/internal/pkgpath/pkgpath.go
index 40a040a81a..72e3bdb631 100644
--- a/src/cmd/internal/pkgpath/pkgpath.go
+++ b/src/cmd/internal/pkgpath/pkgpath.go
@@ -10,9 +10,9 @@ import (
"bytes"
"errors"
"fmt"
+ exec "internal/execabs"
"io/ioutil"
"os"
- "os/exec"
"strings"
)
diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go
index d6c25fac41..14a20a17d5 100644
--- a/src/cmd/link/internal/arm64/asm.go
+++ b/src/cmd/link/internal/arm64/asm.go
@@ -1041,7 +1041,7 @@ func gensymlate(ctxt *ld.Link, ldr *loader.Loader) {
}
// machoLabelName returns the name of the "label" symbol used for a
-// relocation targetting s+off. The label symbols is used on darwin
+// relocation targeting s+off. The label symbols is used on darwin
// when external linking, so that the addend fits in a Mach-O relocation.
func machoLabelName(ldr *loader.Loader, s loader.Sym, off int64) string {
return fmt.Sprintf("%s.%d", ldr.SymExtname(s), off/machoRelocLimit)
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index 3c5091e6a0..6013e0ab0a 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -206,8 +206,8 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
}
// We need to be able to reference dynimport symbols when linking against
- // shared libraries, and Solaris, Darwin and AIX need it always
- if !target.IsSolaris() && !target.IsDarwin() && !target.IsAIX() && rs != 0 && rst == sym.SDYNIMPORT && !target.IsDynlinkingGo() && !ldr.AttrSubSymbol(rs) {
+ // shared libraries, and AIX, Darwin, OpenBSD and Solaris always need it.
+ if !target.IsAIX() && !target.IsDarwin() && !target.IsSolaris() && !target.IsOpenbsd() && rs != 0 && rst == sym.SDYNIMPORT && !target.IsDynlinkingGo() && !ldr.AttrSubSymbol(rs) {
if !(target.IsPPC64() && target.IsExternal() && ldr.SymName(rs) == ".TOC.") {
st.err.Errorf(s, "unhandled relocation for %s (type %d (%s) rtype %d (%s))", ldr.SymName(rs), rst, rst, rt, sym.RelocName(target.Arch, rt))
}
diff --git a/src/cmd/link/internal/ld/execarchive.go b/src/cmd/link/internal/ld/execarchive.go
index fe5cc40865..4687c624de 100644
--- a/src/cmd/link/internal/ld/execarchive.go
+++ b/src/cmd/link/internal/ld/execarchive.go
@@ -7,8 +7,8 @@
package ld
import (
+ exec "internal/execabs"
"os"
- "os/exec"
"path/filepath"
"syscall"
)
diff --git a/src/cmd/link/internal/ld/fallocate_test.go b/src/cmd/link/internal/ld/fallocate_test.go
index 51f5fcdd9f..244b70f061 100644
--- a/src/cmd/link/internal/ld/fallocate_test.go
+++ b/src/cmd/link/internal/ld/fallocate_test.go
@@ -57,8 +57,12 @@ func TestFallocate(t *testing.T) {
if got := stat.Size(); got != sz {
t.Errorf("unexpected file size: got %d, want %d", got, sz)
}
- if got, want := stat.Sys().(*syscall.Stat_t).Blocks, (sz+511)/512; got != want {
- t.Errorf("unexpected disk usage: got %d blocks, want %d", got, want)
+ // The number of blocks must be enough for the requested size.
+ // We used to require an exact match, but it appears that
+ // some file systems allocate a few extra blocks in some cases.
+ // See issue #41127.
+ if got, want := stat.Sys().(*syscall.Stat_t).Blocks, (sz+511)/512; got < want {
+ t.Errorf("unexpected disk usage: got %d blocks, want at least %d", got, want)
}
out.munmap()
}
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index bf95745d8d..17d5040827 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -49,11 +49,11 @@ import (
"encoding/base64"
"encoding/binary"
"fmt"
+ exec "internal/execabs"
"io"
"io/ioutil"
"log"
"os"
- "os/exec"
"path/filepath"
"runtime"
"sort"
@@ -1273,6 +1273,7 @@ func (ctxt *Link) hostlink() {
}
case objabi.Hopenbsd:
argv = append(argv, "-Wl,-nopie")
+ argv = append(argv, "-pthread")
case objabi.Hwindows:
if windowsgui {
argv = append(argv, "-mwindows")
@@ -1749,12 +1750,19 @@ func hostlinkArchArgs(arch *sys.Arch) []string {
switch arch.Family {
case sys.I386:
return []string{"-m32"}
- case sys.AMD64, sys.S390X:
+ case sys.AMD64:
+ if objabi.GOOS == "darwin" {
+ return []string{"-arch", "x86_64", "-m64"}
+ }
+ return []string{"-m64"}
+ case sys.S390X:
return []string{"-m64"}
case sys.ARM:
return []string{"-marm"}
case sys.ARM64:
- // nothing needed
+ if objabi.GOOS == "darwin" {
+ return []string{"-arch", "arm64"}
+ }
case sys.MIPS64:
return []string{"-mabi=64"}
case sys.MIPS:
diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go
index 1420030eec..cbd811846b 100644
--- a/src/cmd/link/internal/ld/main.go
+++ b/src/cmd/link/internal/ld/main.go
@@ -95,7 +95,7 @@ var (
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
memprofile = flag.String("memprofile", "", "write memory profile to `file`")
memprofilerate = flag.Int64("memprofilerate", 0, "set runtime.MemProfileRate to `rate`")
- flagAbiWrap = false
+ flagAbiWrap = flag.Bool("abiwrap", objabi.Regabi_enabled != 0, "support ABI wrapper functions")
benchmarkFlag = flag.String("benchmark", "", "set to 'mem' or 'cpu' to enable phase benchmarking")
benchmarkFileFlag = flag.String("benchmarkprofile", "", "emit phase profiles to `base`_phase.{cpu,mem}prof")
)
@@ -134,9 +134,6 @@ func Main(arch *sys.Arch, theArch Arch) {
objabi.Flagfn1("X", "add string value `definition` of the form importpath.name=value", func(s string) { addstrdata1(ctxt, s) })
objabi.Flagcount("v", "print link trace", &ctxt.Debugvlog)
objabi.Flagfn1("importcfg", "read import configuration from `file`", ctxt.readImportCfg)
- if objabi.Regabi_enabled != 0 {
- flag.BoolVar(&flagAbiWrap, "abiwrap", true, "support ABI wrapper functions")
- }
objabi.Flagparse(usage)
@@ -185,6 +182,14 @@ func Main(arch *sys.Arch, theArch Arch) {
interpreter = *flagInterpreter
+ if *flagBuildid == "" && ctxt.Target.IsOpenbsd() {
+ // TODO(jsing): Remove once direct syscalls are no longer in use.
+ // OpenBSD 6.7 onwards will not permit direct syscalls from a
+ // dynamically linked binary unless it identifies the binary
+ // contains a .note.go.buildid ELF note. See issue #36435.
+ *flagBuildid = "go-openbsd"
+ }
+
// enable benchmarking
var bench *benchmark.Metrics
if len(*benchmarkFlag) != 0 {
@@ -332,6 +337,8 @@ func Main(arch *sys.Arch, theArch Arch) {
bench.Start("Asmb")
asmb(ctxt)
+ exitIfErrors()
+
// Generate additional symbols for the native symbol table just prior
// to code generation.
bench.Start("GenSymsLate")
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index 3b709baf75..85a8ff42ad 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -120,7 +120,7 @@ func putelfsym(ctxt *Link, x loader.Sym, typ elf.SymType, curbind elf.SymBind) {
// sym or marker relocation to associate the wrapper with the
// wrapped function.
//
- if flagAbiWrap {
+ if *flagAbiWrap {
if !ldr.IsExternal(x) && ldr.SymType(x) == sym.STEXT {
// First case
if ldr.SymVersion(x) == sym.SymVerABIInternal {
diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go
index 7eeb7ef568..8153c0b31b 100644
--- a/src/cmd/link/link_test.go
+++ b/src/cmd/link/link_test.go
@@ -320,6 +320,7 @@ func TestBuildForTvOS(t *testing.T) {
}
link := exec.Command(CC[0], CC[1:]...)
+ link.Args = append(link.Args, "-o", filepath.Join(tmpDir, "a.out")) // Avoid writing to package directory.
link.Args = append(link.Args, ar, filepath.Join("testdata", "testBuildFortvOS", "main.m"))
if out, err := link.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", link.Args, err, out)
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go
index edaca774f7..1748e13a53 100644
--- a/src/cmd/objdump/objdump_test.go
+++ b/src/cmd/objdump/objdump_test.go
@@ -237,9 +237,6 @@ func testGoAndCgoDisasm(t *testing.T, printCode bool, printGnuAsm bool) {
t.Parallel()
testDisasm(t, "fmthello.go", printCode, printGnuAsm)
if build.Default.CgoEnabled {
- if runtime.GOOS == "aix" {
- return // issue 40972
- }
testDisasm(t, "fmthellocgo.go", printCode, printGnuAsm)
}
}
@@ -261,8 +258,6 @@ func TestDisasmExtld(t *testing.T) {
switch runtime.GOOS {
case "plan9", "windows":
t.Skipf("skipping on %s", runtime.GOOS)
- case "aix":
- t.Skipf("skipping on AIX, see issue 40972")
}
t.Parallel()
testDisasm(t, "fmthello.go", false, false, "-ldflags=-linkmode=external")
diff --git a/src/cmd/test2json/main.go b/src/cmd/test2json/main.go
index 57a874193e..fdf681a8ff 100644
--- a/src/cmd/test2json/main.go
+++ b/src/cmd/test2json/main.go
@@ -6,7 +6,7 @@
//
// Usage:
//
-// go tool test2json [-p pkg] [-t] [./pkg.test -test.v]
+// go tool test2json [-p pkg] [-t] [./pkg.test -test.v [-test.paniconexit0]]
//
// Test2json runs the given test command and converts its output to JSON;
// with no command specified, test2json expects test output on standard input.
@@ -18,6 +18,10 @@
//
// The -t flag requests that time stamps be added to each test event.
//
+// The test must be invoked with -test.v. Additionally passing
+// -test.paniconexit0 will cause test2json to exit with a non-zero
+// status if one of the tests being run calls os.Exit(0).
+//
// Note that test2json is only intended for converting a single test
// binary's output. To convert the output of a "go test" command,
// use "go test -json" instead of invoking test2json directly.
@@ -82,9 +86,9 @@ package main
import (
"flag"
"fmt"
+ exec "internal/execabs"
"io"
"os"
- "os/exec"
"cmd/internal/test2json"
)
diff --git a/src/cmd/trace/pprof.go b/src/cmd/trace/pprof.go
index a73ff5336a..c4d3742820 100644
--- a/src/cmd/trace/pprof.go
+++ b/src/cmd/trace/pprof.go
@@ -9,11 +9,11 @@ package main
import (
"bufio"
"fmt"
+ exec "internal/execabs"
"internal/trace"
"io"
"net/http"
"os"
- "os/exec"
"path/filepath"
"runtime"
"sort"
diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
index 83398dda5d..c6a189dbe0 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
@@ -832,7 +832,16 @@ func (f *File) DropRequire(path string) error {
return nil
}
+// AddExclude adds a exclude statement to the mod file. Errors if the provided
+// version is not a canonical version string
func (f *File) AddExclude(path, vers string) error {
+ if !isCanonicalVersion(vers) {
+ return &module.InvalidVersionError{
+ Version: vers,
+ Err: errors.New("must be of the form v1.2.3"),
+ }
+ }
+
var hint *Line
for _, x := range f.Exclude {
if x.Mod.Path == path && x.Mod.Version == vers {
@@ -904,7 +913,22 @@ func (f *File) DropReplace(oldPath, oldVers string) error {
return nil
}
+// AddRetract adds a retract statement to the mod file. Errors if the provided
+// version interval does not consist of canonical version strings
func (f *File) AddRetract(vi VersionInterval, rationale string) error {
+ if !isCanonicalVersion(vi.High) {
+ return &module.InvalidVersionError{
+ Version: vi.High,
+ Err: errors.New("must be of the form v1.2.3"),
+ }
+ }
+ if !isCanonicalVersion(vi.Low) {
+ return &module.InvalidVersionError{
+ Version: vi.Low,
+ Err: errors.New("must be of the form v1.2.3"),
+ }
+ }
+
r := &Retract{
VersionInterval: vi,
}
@@ -1061,3 +1085,9 @@ func lineRetractLess(li, lj *Line) bool {
}
return semver.Compare(vii.High, vij.High) > 0
}
+
+// isCanonicalVersion tests if the provided version string represents a valid
+// canonical version.
+func isCanonicalVersion(vers string) bool {
+ return vers != "" && semver.Canonical(vers) == vers
+}
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go
index 8c3c2e7ab9..d11505a165 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package analysis
import (
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/diagnostic.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/diagnostic.go
index 57eaf6faa2..cd462a0cb5 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/diagnostic.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/diagnostic.go
@@ -1,3 +1,7 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package analysis
import "go/token"
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go
index 9fa3302dfb..94a3bd5d07 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
/*
Package analysis defines the interface between a modular static
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/help.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/help.go
index c5a70f3b7d..ce92892c81 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/help.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/help.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package analysisflags
import (
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go
index 80c9476fcd..ac37e4784e 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Package analysisutil defines various helper functions
// used by two or more packages beneath go/analysis.
package analysisutil
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go
index bd8a594ef5..6a5fae44f4 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package printf
import (
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
index 02555648a0..f0b15051c5 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
@@ -207,12 +207,12 @@ var (
)
// validateStructTag parses the struct tag and returns an error if it is not
-// in the canonical format, as defined by reflect.StructTag.
+// in the canonical format, which is a space-separated list of key:"value"
+// settings. The value may contain spaces.
func validateStructTag(tag string) error {
// This code is based on the StructTag.Get code in package reflect.
n := 0
- var keys []string
for ; tag != ""; n++ {
if n > 0 && tag != "" && tag[0] != ' ' {
// More restrictive than reflect, but catches likely mistakes
@@ -240,27 +240,14 @@ func validateStructTag(tag string) error {
if i == 0 {
return errTagKeySyntax
}
- if i+1 >= len(tag) || tag[i] < ' ' || tag[i] == 0x7f {
+ if i+1 >= len(tag) || tag[i] != ':' {
return errTagSyntax
}
- key := tag[:i]
- keys = append(keys, key)
- tag = tag[i:]
-
- // If we found a space char here - assume that we have a tag with
- // multiple keys.
- if tag[0] == ' ' {
- continue
- }
-
- // Spaces were filtered above so we assume that here we have
- // only valid tag value started with `:"`.
- if tag[0] != ':' || tag[1] != '"' {
+ if tag[i+1] != '"' {
return errTagValueSyntax
}
-
- // Remove the colon leaving tag at the start of the quoted string.
- tag = tag[1:]
+ key := tag[:i]
+ tag = tag[i+1:]
// Scan quoted string to find value.
i = 1
@@ -276,56 +263,51 @@ func validateStructTag(tag string) error {
qvalue := tag[:i+1]
tag = tag[i+1:]
- wholeValue, err := strconv.Unquote(qvalue)
+ value, err := strconv.Unquote(qvalue)
if err != nil {
return errTagValueSyntax
}
- for _, key := range keys {
- if !checkTagSpaces[key] {
- continue
- }
-
- value := wholeValue
- switch key {
- case "xml":
- // If the first or last character in the XML tag is a space, it is
- // suspicious.
- if strings.Trim(value, " ") != value {
- return errTagValueSpace
- }
+ if !checkTagSpaces[key] {
+ continue
+ }
- // If there are multiple spaces, they are suspicious.
- if strings.Count(value, " ") > 1 {
- return errTagValueSpace
- }
+ switch key {
+ case "xml":
+ // If the first or last character in the XML tag is a space, it is
+ // suspicious.
+ if strings.Trim(value, " ") != value {
+ return errTagValueSpace
+ }
- // If there is no comma, skip the rest of the checks.
- comma := strings.IndexRune(value, ',')
- if comma < 0 {
- continue
- }
+ // If there are multiple spaces, they are suspicious.
+ if strings.Count(value, " ") > 1 {
+ return errTagValueSpace
+ }
- // If the character before a comma is a space, this is suspicious.
- if comma > 0 && value[comma-1] == ' ' {
- return errTagValueSpace
- }
- value = value[comma+1:]
- case "json":
- // JSON allows using spaces in the name, so skip it.
- comma := strings.IndexRune(value, ',')
- if comma < 0 {
- continue
- }
- value = value[comma+1:]
+ // If there is no comma, skip the rest of the checks.
+ comma := strings.IndexRune(value, ',')
+ if comma < 0 {
+ continue
}
- if strings.IndexByte(value, ' ') >= 0 {
+ // If the character before a comma is a space, this is suspicious.
+ if comma > 0 && value[comma-1] == ' ' {
return errTagValueSpace
}
+ value = value[comma+1:]
+ case "json":
+ // JSON allows using spaces in the name, so skip it.
+ comma := strings.IndexRune(value, ',')
+ if comma < 0 {
+ continue
+ }
+ value = value[comma+1:]
}
- keys = keys[:0]
+ if strings.IndexByte(value, ' ') >= 0 {
+ return errTagValueSpace
+ }
}
return nil
}
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go
index 683b7e91d2..9051456e39 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// +build go1.12
package unitchecker
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go
index ad0e7276c9..23e57bf02b 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package analysis
import (
diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go
index 7630629824..919d5305ab 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go
@@ -1,3 +1,7 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package astutil
import "go/ast"
diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go
index d61301b133..b6b00cf2e1 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package inspector
// This file defines func typeOf(ast.Node) uint64.
diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt
index 4e47f41855..e033984956 100644
--- a/src/cmd/vendor/modules.txt
+++ b/src/cmd/vendor/modules.txt
@@ -28,7 +28,7 @@ golang.org/x/arch/x86/x86asm
golang.org/x/crypto/ed25519
golang.org/x/crypto/ed25519/internal/edwards25519
golang.org/x/crypto/ssh/terminal
-# golang.org/x/mod v0.4.0
+# golang.org/x/mod v0.4.1
## explicit
golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile
@@ -44,7 +44,7 @@ golang.org/x/mod/zip
golang.org/x/sys/internal/unsafeheader
golang.org/x/sys/unix
golang.org/x/sys/windows
-# golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11
+# golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff
## explicit
golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/internal/analysisflags