Compare commits

..

502 Commits

Author SHA1 Message Date
Ian Lance Taylor
55626ee50b [dev.go2go] README: document that this branch is no longer maintained
For golang/go#46346

Change-Id: Iab050557efb96217477072eca42966662485b6b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/322192
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-24 20:10:04 +00:00
Ian Lance Taylor
9cd52cf2a9 [dev.go2go] cmd/go2go: don't pass "run run" to cmd/go
Fixes #45502

Change-Id: I510c47e7780a42ffd0c855da5ce1674d487c1633
Reviewed-on: https://go-review.googlesource.com/c/go/+/309570
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-13 00:32:27 +00:00
Alan D. Cabrera
a4b4db4cde cmd/go2go: add ability to specify build tags in go2go
You can specify build tags, so that imports properly work during translation,
by using the `-tags` option, e.g. `go tool go2go run -tags=appengine x.go2`.
The `-tags` option is available for all the `go2go` sub-commands.

Change-Id: Ib60e7542b10c6a561b61db23d35592b2bc7f63cd
GitHub-Last-Rev: 954cccfae8
GitHub-Pull-Request: golang/go#45147
Reviewed-on: https://go-review.googlesource.com/c/go/+/303275
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-22 22:48:13 +00:00
Rob Findley
8f19f8a9e1 [dev.go2go] all: merge master (12bb256) into dev.go2go
Included in this merge are CL 293010 switching to a new ast.ListExpr for
type argument lists (instead of overloading CallExpr), and CL 295929
partially hiding the new type parameter API.

As a result of those two CLs, the following changes were made to fix the
go2go tool:
 + Update the go2go rewriter for the new syntax.
 + Update test cases to eliminate some remaining '()' syntax for type
   argument lists.
 + Add new files exposing the now-hidden API.

These changes can be reviewed by comparing the latest patchset to
patchset 1.

Merge List:

+ 2021-03-04 12bb256cb3 go/types: use correct recv for parameterized embedded methods
+ 2021-03-03 6db80d7420 cmd/compile/internal/types2: use correct recv for parameterized embedded methods
+ 2021-03-03 d6f6ef6358 cmd/compile: remove races introduced in abiutils field update
+ 2021-03-03 3e524ee65a cmd/compile: make modified Aux type for OpArgXXXX pass ssa/check
+ 2021-03-03 9f33dc3ca1 cmd/compile: handle aggregate OpArg in registers
+ 2021-03-03 c4e3f6c4c7 cmd/compile: remove 8-byte alignment requirement of stack slot on s390x
+ 2021-03-03 85f62b0941 cmd/compile: remove 8-byte alignment requirement of stack slot on mips
+ 2021-03-03 497feff168 cmd/compile: intrinsify runtime/internal/atomic.{And,Or}{8,} on RISCV64
+ 2021-03-03 00cb841b83 syscall: implement rawVforkSyscall for remaining linux platforms
+ 2021-03-03 f2df1e3c34 cmd/compile: retrieve Args from registers
+ 2021-03-03 06c72f3627 A+C: change email address for Baokun Lee
+ 2021-03-03 84ca4949a7 cmd/compile: remove 8-byte alignment requirement of stack slot on mips64
+ 2021-03-03 77973863c3 cmd/compile: use abiutils for all rcvr/in/out frame offsets.
+ 2021-03-03 aea1259a72 cmd/link: disable flaky Darwin "symbols" test
+ 2021-03-02 312fd9937d cmd/go: remove -insecure flag on go get
+ 2021-03-02 2a2f99eefb cmd/go/internal/modload: do not resolve an arbitrary version for 'go list --versions'
+ 2021-03-02 b65091c11d cmd/go: add a test case that reproduces #44296
+ 2021-03-02 e9eed78dc3 cmd/go: resolve std-vendored dependencies as std packages except in 'go get' and 'go mod'
+ 2021-03-02 09f4ef4fa7 cmd/go/internal/mvs: prune spurious dependencies in Downgrade
+ 2021-03-02 c6374f5162 dist: generate stub go.mod in workdir
+ 2021-03-02 97b32a6724 cmd/compile: better version of check frame offsets against abi
+ 2021-03-02 2b50ab2aee cmd/compile: optimize single-precision floating point square root
+ 2021-03-02 ebb92dfed9 internal/poll, runtime: handle netpollopen error in poll_runtime_pollOpen
+ 2021-03-02 4c1a7ab49c cmd/go: reject relative paths in GOMODCACHE environment
+ 2021-03-02 580636a78a all: fix spelling
+ 2021-03-02 a6eeb4add4 go/parser,go/types: hide API changes related to type parameters
+ 2021-03-02 ff5cf4ced3 cmd/link,debug/elf: mips32, add .gnu.attributes and .MIPS.abiflags sections
+ 2021-03-01 700b73975e runtime: use entersyscall in syscall_syscallX on Darwin
+ 2021-03-01 a69c45213d go/types: review of expr.go
+ 2021-03-01 b98ce3b606 cmd/compile:  import empty closure function correctly
+ 2021-03-01 97bdac03ae cmd: upgrade golang.org/x/mod to relax import path check
+ 2021-03-01 f6a74c6568 cmd/compile/internal/ir: fix up stale comment
+ 2021-03-01 87beecd6df cmd/go: add missing newline to retraction warning message
+ 2021-03-01 a400eb3261 Revert "cmd/compile: check frame offsets against abi"
+ 2021-03-01 5fafc0bbd4 cmd/go/internal/modload: don't query when fixing canonical versions
+ 2021-03-01 2a8df4488e os: mark pipes returned by os.Pipe() as inheritable by default
+ 2021-02-27 5ff7ec98b7 cmd/compile: check frame offsets against abi
+ 2021-02-27 a429926159 cmd/compile: fix escape analysis of heap-allocated results
+ 2021-02-27 998fe70b68 cmd/compile: fixed which-result confusion in presence of 0-width types
+ 2021-02-27 d9fd38e68b time: correct unusual extension string cases
+ 2021-02-26 cda8ee095e reflect: fix register ABI spill space calculation
+ 2021-02-26 d8e33d558e cmd/compile: deal with closures in generic functions and instantiated function values
+ 2021-02-26 19f96e73bf syscall: introduce SysProcAttr.ParentProcess on Windows
+ 2021-02-26 3146166baa syscall: introduce SysProcAttr.AdditionalInheritedHandles on Windows
+ 2021-02-26 2d760816ff syscall: restrict inherited handles on Windows
+ 2021-02-26 ba9168bd07 syscall: add support for proc thread attribute lists
+ 2021-02-26 f41460145e cmd/link: recognize ARM64 PE files and relocations
+ 2021-02-26 a655208c9e cmd/link: handle types as converted to interface when dynlink
+ 2021-02-26 23943a6737 cmd/compile: fix mishandling of unsafe-uintptr arguments with call method in go/defer
+ 2021-02-26 e25040d162 cmd/compile: change StaticCall to return a "Results"
+ 2021-02-26 9a555fc24c cmd/compile:  fix missing descend in Addrtaken for closures.
+ 2021-02-25 a61524d103 cmd/internal/obj: add Prog.SetFrom3{Reg,Const}
+ 2021-02-25 5f15af111c syscall: comment on fields omitted from the win32finddata1 struct
+ 2021-02-25 9a7fe196e4 Revert "cmd/compile: fix mishandling of unsafe-uintptr arguments with call method in go/defer"
+ 2021-02-25 b83d073e9e reflect: add Method.IsExported and StructField.IsExported methods
+ 2021-02-25 7fcf9893f7 cmd/internal/obj: fix typo in docs
+ 2021-02-25 6c3bcda866 cmd/compile: declare inlined result params early for empty returns
+ 2021-02-25 526ee96f49 os: avoid allocation in File.WriteString
+ 2021-02-25 194b636f8f database/sql: close driver.Connector if it implements io.Closer
+ 2021-02-25 4ebb6f5110 cmd/compile: automate resultInArg0 register checks
+ 2021-02-25 1a3e968b1f cmd/compile: fix mishandling of unsafe-uintptr arguments with call method in go/defer
+ 2021-02-25 ee2a45e5fb runtime: use pipe2 for nonblockingPipe on dragonfly
+ 2021-02-25 1f7a01459b runtime: batch moving gFree list between local p and global schedt
+ 2021-02-25 bcac57f89c cmd: upgrade golang.org/x/mod to fix go.mod parser
+ 2021-02-25 3137da82fd cmd/go: add a script test corresponding to the downhiddenartifact MVS test
+ 2021-02-25 2c4c189bba cmd/go/internal/mvs: add test cases for downgrade interaction with hidden versions
+ 2021-02-25 9fe8ebf9b4 test: add test case that failed with gccgo
+ 2021-02-25 ad17b65b34 testing/fstest: treat dash specially when building glob
+ 2021-02-25 37ca84a9cd syscall: return error if GetQueuedCompletionStatus truncates key
+ 2021-02-25 76c0003cd5 syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe
+ 2021-02-25 666ad85df4 cmd/compile: fix typo in rewrite_test.go
+ 2021-02-25 d822ffebc5 test: fix inline.go test for linux-amd64-noopt
+ 2021-02-25 ff614b13d9 runtime: subtract one from ip when determining abort
+ 2021-02-24 dbbc5ec7e8 syscall: restore broken GetQueuedCompletionStatus signature but make it not crash
+ 2021-02-24 d0d21b7c4c cmd/compile: plumb abi info into expandCalls
+ 2021-02-24 8027343b63 cmd/compile: disable inlining functions with closures for now
+ 2021-02-24 6c3f8a2f47 cmd/link: use ctxt.Logf instead of package log
+ 2021-02-24 3ee32439b5 cmd/compile: ARM64 optimize []float64 and []float32 access
+ 2021-02-24 80ddc17ae1 cmd/compile/internal-abi: fix ABI0-equivalence for zero-sized values
+ 2021-02-24 3deb528199 cmd/compile/internal-abi: update internal ABI spec for g register
+ 2021-02-24 478277f812 cmd/compile/internal-abi: use x87 mode, not MMX mode
+ 2021-02-24 bf48163e8f cmd/compile: add rule to coalesce writes
+ 2021-02-24 b7f62daa59 cmd/internal/goobj: add test case for object file reader
+ 2021-02-24 c9d9b40b13 context: avoid importing context package twice
+ 2021-02-24 dc4698f52b syscall: do not overflow key memory in GetQueuedCompletionStatus
+ 2021-02-24 7a2f3273c5 cmd/compile: plumb abi info into ssagen/ssa
+ 2021-02-24 adb467ffd2 cmd/compile: reduce inline cost of OCONVOP
+ 2021-02-24 27684ea195 testing: print late arriving log line in panic
+ 2021-02-24 ae1fa08e41 context: reduce contention in cancelCtx.Done
+ 2021-02-24 691ac806d2 cmd/go: fix version validation in 'go mod edit -exclude'
+ 2021-02-24 b97b1456ae cmd/go, cmd/cgo: pass -mfp32 and -mhard/soft-float to MIPS GCC
+ 2021-02-24 07c658316b io/ioutil: forward TempFile and TempDir to os package
+ 2021-02-24 04edf418d2 encoding/json: reduce allocated space in Unmarshal
+ 2021-02-24 e496120891 database: remove race in TestTxContextWait
+ 2021-02-24 26001d109e go/types: review of call.go
+ 2021-02-24 35b80eac7d hash/maphash: remove duplicate from Hash documentation
+ 2021-02-24 eb863240dc runtime: remove unused const stackSystem on dragonfly
+ 2021-02-24 084b07d6f6 spec: improve sentence structure for passing a slice
+ 2021-02-24 6ba4a300d8 docs: fix spelling
+ 2021-02-24 43652dc46f bufio, bytes, strings: handle negative runes in WriteRune
+ 2021-02-24 3780529255 unicode: correctly handle negative runes
+ 2021-02-24 0694fb3d78 image: resolve the TODO of doc comment style
+ 2021-02-23 6cc8aa7ece go/types: minor updates to comments to align with types2
+ 2021-02-23 42b9e3a8df context: fix XTestInterlockedCancels
+ 2021-02-23 aaed6cbced testing/race: fixing intermittent test failure
+ 2021-02-23 fbed561f8a runtime: reset stack poison flag accidentally set
+ 2021-02-23 0458d8c983 go/types, types2: constraints may be parenthesized and that includes "any"
+ 2021-02-23 74903553bc doc: start draft go1.17 release notes, move go1.16 to x/website
+ 2021-02-23 fa40c0232c cmd/go: reproduce issue #44497 in TestScript/mod_edit
+ 2021-02-23 a4dac8bd22 runtime: use BX instead of R15 in race detector
+ 2021-02-23 c49c7a675a runtime: save R15 before checking AVX state
+ 2021-02-23 d2911d7612 cmd/compile: fold MOV*nop and MOV*const
+ 2021-02-23 d434c2338b runtime: clarify GC fractional mode description
+ 2021-02-23 a671e33c6d all: use more precise build tags
+ 2021-02-23 c584f42dcf cmd/compile: change riscv64 Eq32/Neq32 to zero extend before subtraction
+ 2021-02-23 080119799b runtime: fix usleep on windows/arm
+ 2021-02-23 74cac8d479 cmd/compile: add AMD64 parameter register defs, Arg ops, plumb to ssa.Config
+ 2021-02-23 42cd40ee74 cmd/compile: improve bit test code
+ 2021-02-23 f1562c7610 cmd/go: recognize DLL magic from llvm binaries
+ 2021-02-23 bf5fa2d198 cmd/compile: guard special register usage with GOEXPERIMENT=regabi
+ 2021-02-23 c7f596f919 cmd/go: resolve TODO by replacing InDir() function
+ 2021-02-23 5e94fe9316 go/build/constraint: fix splitPlusBuild func doc comment
+ 2021-02-23 55d7dcc3cd runtime: optimize the memory padding in p struct
+ 2021-02-23 ab331c0254 runtime/cgo: use correct lean and mean macro
+ 2021-02-23 91cfbf39e4 cmd/link: set .ctors COFF section to writable and aligned
+ 2021-02-23 811167e2c9 cmd/link: do not pass -Bsymbolic for PE DLLs
+ 2021-02-23 a51daac840 cmd/link: set SizeOfRawData rather than VirtualSize in COFF files for .bss section
+ 2021-02-23 e5159b2a2f cmd/internal/dwarf: minor cleanups
+ 2021-02-23 b3b65f2176 runtime: enable race detector on openbsd/amd64
+ 2021-02-23 a78b0e6721 internal/poll: fix the verbose condition in splice
+ 2021-02-23 08543f0715 ios/fs: mention f.dir in (*subFS).fixErr godoc
+ 2021-02-23 0398a771d2 cmd/internal/obj/riscv: prevent constant loads that do not target registers
+ 2021-02-23 6525abddce cmd/internal/obj/riscv: clean up branch tests
+ 2021-02-23 c4b771348c runtime: fix windows/arm signal handling assembly
+ 2021-02-23 2a18e37c4e cmd/compile: remove backend's "scratch mem" support
+ 2021-02-23 e52149822b cmd/compile: simplify assert{E,I}2I{,2} calling conventions
+ 2021-02-23 86deb459de cmd/compile: remove selectnbrecv2
+ 2021-02-23 4048491234 cmd/compile,runtime: make selectnbrecv return two values
+ 2021-02-23 5e804ba17d cmd/compile: use transitive relations for slice len/cap in poset
+ 2021-02-23 6a40dd05d8 cmd/compile/internal/types2: review of sanitize.go
+ 2021-02-23 975ba6e2b2 cmd/compile: mark OpSB, OpSP as poor statement Op
+ 2021-02-23 a2e150c7cd go/types, cmd/compile/internal/types2: use regular type printing for unsafe.Pointer
+ 2021-02-23 5a0e4fc4e7 cmd/compile/internal/types2: review of conversions.go
+ 2021-02-23 89eb2b55b9 cmd/compile/internal/types2: review of issues_test.go
+ 2021-02-23 378f73e2d5 cmd/compile/internal/types2: enable TestIssue25627
+ 2021-02-23 1901e2647f test: add test for findTypeLoop with symbols from other packages
+ 2021-02-23 5f3dabbb79 cmd/compile: fix import of functions of multiple nested closure
+ 2021-02-23 7af821a661 all: faster midpoint computation in binary search
+ 2021-02-23 f113e9a14f cmd/dist: match goexperiment.regabi tag when GOEXPERIMENT is on
+ 2021-02-22 1126bbb82a go/parser: return ast.BadExpr for missing index operands
+ 2021-02-22 1678829d95 cmd/compile: correctly use X15 to zero frame
+ 2021-02-22 094048b938 cmd/compile/internal: loop opt
+ 2021-02-22 1391d4142c fix typo in issue16760.go
+ 2021-02-22 04903476fe cmd/compile: reject some rare looping CFGs in shortcircuit
+ 2021-02-22 87e984ab29 test: add test for issue 38698
+ 2021-02-22 b2bdadfe88 cmd/internal: cleanup ppc64 optab structure
+ 2021-02-21 0f66fb7b85 go/internal/gccgoimporter: fix up gccgo installation test
+ 2021-02-21 e78e04ce39 cmd/compile: fix panic in DWARF-gen handling obfuscated code
+ 2021-02-20 03d36d8198 syscall: add explicit ios build tag
+ 2021-02-20 40656f3a75 doc/1.16: fix link to fs.FileInfo
+ 2021-02-20 d4b2638234 all: go fmt std cmd (but revert vendor)
+ 2021-02-20 0625460f79 cmd/vet: update buildtag check for //go:build lines
+ 2021-02-20 9fd6cc105d go/printer: canonicalize //go:build and // +build lines while formatting
+ 2021-02-20 5b76343a10 go/build: prefer //go:build over // +build lines
+ 2021-02-20 a8942d2cff runtime/pprof: disable TestMorestack on darwin/arm64
+ 2021-02-20 078f08f0ee spec: every type has a method set (minor clarification)
+ 2021-02-19 26713b5fef go/types: don't write during sanitizeInfo if nothing has changed
+ 2021-02-19 9a99515c8f all: REVERSE MERGE dev.typeparams (7cdfa49) into master
+ 2021-02-19 7cdfa4969a [dev.typeparams] all: merge master (06b86e9) into dev.typeparams
+ 2021-02-19 6521c7b378 [dev.typeparams] cmd/compile/internal/types2: resolve decl cycle the same way as in go/types
+ 2021-02-19 06b86e9803 cmd/compile:  fix check to avoid creating new closure function when typechecking inline body
+ 2021-02-19 9322eec8a2 codereview.cfg: add codereview.cfg for master branch
+ 2021-02-19 02e5a8fdfc runtime: ignore SPWRITE in syscall functions
+ 2021-02-19 fa18f224c3 runtime/pprof: disable TestMorestack on macOS under race detector
+ 2021-02-19 01eb70e3dd os: fix hex exit code print on 32-bit windows
+ 2021-02-19 49add6ad90 runtime: fix spurious stack overflow detection
+ 2021-02-19 fce2a94d84 cmd/compile: fix buglet in inlined info abstract function dwarf-gen
+ 2021-02-19 dfe0ef961b [dev.typeparams] go/types, types2: revert fancy struct printing (fixes x/tools tests)
+ 2021-02-19 7764ee5614 runtime: fix invalid nil g check for for mips64x
+ 2021-02-19 2f37939a21 go/parser: improve error recovery from invalid selector exprs
+ 2021-02-19 8654db4555 [dev.typeparams] go/types: adjust printing of embedded struct fields (fixes x/tools/cmd/guru tests)
+ 2021-02-19 87f425da14 cmd/go/internal/mvs: split Reqs into narrower per-function interfaces
+ 2021-02-19 4da0188c6c cmd/go/internal/modget: split resolveCandidates into two methods
+ 2021-02-19 5f2e24efb3 cmd/internal/diff: skip over Cygwin warning in diff output
+ 2021-02-19 ee7038f6a5 net: disable Windows netsh tests when netsh won't run
+ 2021-02-19 40765ffa95 os/exec: disable failing LookPathTest on windows/arm64
+ 2021-02-19 b445d6ea34 runtime/pprof: expect tests to pass on macOS
+ 2021-02-19 b110a43628 runtime: delete gosave (dead code)
+ 2021-02-19 474d5f4f4d math: remove most 387 implementations
+ 2021-02-19 c7c6c113be runtime: convert windows/arm64 assembly
+ 2021-02-19 3527caa7d6 runtime: initial windows/arm64 implementation files
+ 2021-02-19 427bd7599d runtime: generate windows/arm64 callback asm
+ 2021-02-19 f6c4b4bf96 syscall: add windows/arm64 support
+ 2021-02-19 ac024a0c7b cmd/vendor: get golang.org/x/sys@beda7e5e158
+ 2021-02-19 a3b97e7628 test: disable nilptr on windows/arm64
+ 2021-02-19 985d087782 cmd/link: add windows/arm64 support
+ 2021-02-19 95a44d2409 cmd/internal/objfile: recognize Windows ARM64 executables
+ 2021-02-19 0ca0551f02 debug/pe: recognize arm64 executables
+ 2021-02-19 47e4b0739e Merge "[dev.typeparams] all: merge master (eb98272) into dev.typeparams" into dev.typeparams
+ 2021-02-19 0c633125f2 cmd/dist: add windows/arm64 support
+ 2021-02-19 bb6efb9609 build: set GOPATH consistently in run.bash, run.bat, run.rc
+ 2021-02-19 a1222b7535 cmd/link: add debug print in deadcode
+ 2021-02-19 1c659f2525 cmd/link: clean up windows PE generation
+ 2021-02-19 b6379f190b syscall: clean up windows a bit
+ 2021-02-19 09e059afb1 runtime: enable framepointer on all arm64
+ 2021-02-19 b19e7b518e runtime: clean up windows a bit
+ 2021-02-19 5421c37a1d runtime: fix windows/arm externalthreadhandler
+ 2021-02-19 91cc484ea9 runtime: fix time on windows/arm under WINE
+ 2021-02-19 38672d3dcf runtime: crash earlier on windows for runtime.abort
+ 2021-02-19 a1e9148e3d runtime: print hex numbers with hex prefixes in traceback debug
+ 2021-02-19 75e273fc2c runtime: fix windows/arm CONTEXT_CONTROL
+ 2021-02-19 76ab626bfc runtime: factor common code out of defs_windows_*.go
+ 2021-02-19 ece954d8b8 runtime: find g in Windows profiler using SP
+ 2021-02-19 a54f7fc0fd runtime: do not treat asmcgocall as a topofstack on g0
+ 2021-02-19 776ee4079a runtime: do not treat morestack as a topofstack
+ 2021-02-19 5ecd9e34df runtime: do not treat mcall as a topofstack
+ 2021-02-19 54da3ab385 runtime: use TOPFRAME to identify top-of-frame functions
+ 2021-02-19 fbe74dbf42 runtime: use FuncInfo SPWRITE flag to identify untraceable profile samples
+ 2021-02-19 4dd77bdc91 cmd/asm, cmd/link, runtime: introduce FuncInfo flag bits
+ 2021-02-19 aa0388f2ed runtime: remove unnecessary writes to gp.sched.g
+ 2021-02-19 6fe8981620 cmd/internal/obj/riscv: fix JMP name<>(SB)
+ 2021-02-19 01f05d8ff1 runtime: unify asmcgocall and systemstack traceback setup
+ 2021-02-19 229695a283 runtime: clean up funcID assignment
+ 2021-02-19 c80da0a33a runtime: handle nil gp in cpuprof
+ 2021-02-19 a78879ac67 runtime: move sys.DefaultGoroot to runtime.defaultGOROOT
+ 2021-02-19 8ac23a1f15 runtime: document, clean up internal/sys
+ 2021-02-19 678568a5cf runtime: delete windows setlasterror (unused)
+ 2021-02-19 0d94f989d1 runtime: clean up system calls during cgo callback init
+ 2021-02-19 e7ee3c1fa8 os: report Windows exit status in hex
+ 2021-02-18 a789be7814 [dev.typeparams] cmd/compile: use new converter functions rather than methods (fix build)
+ 2021-02-18 20050a15fe [dev.typeparams] cmd/compile:  support generic types (with stenciling of method calls)
+ 2021-02-18 e7493a9c74 [dev.typeparams] all: merge master (eb98272) into dev.typeparams
+ 2021-02-18 2ff1e05a4c [dev.typeparams] all: update parent repository
+ 2021-02-18 eb982727e3 cmd/go/internal/mvs: fix Downgrade to match Algorithm 4
+ 2021-02-18 3b7277d365 cmd/go: add a script test for artifacts resulting from 'go get -u'
+ 2021-02-18 8960ce7735 [dev.typeparams] cmd/compile/internal/types2: minor adjustments to match go/types more closely
+ 2021-02-18 6f3878b942 [dev.typeparams] cmd/compile/internal/types: review of typestring_test.go
+ 2021-02-18 d6bdd1aeef [dev.typeparams] cmd/compile/internal/types: review of typestring.go
+ 2021-02-18 c2314babb8 [dev.typeparams] cmd/compile/internal/types: review of type.go
+ 2021-02-18 099374b55e [dev.typeparams] cmd/compile/internal/types2: remove Type.Under method in favor of function
+ 2021-02-18 653386a89a [dev.typeparams] cmd/compile/internal/types2: replace Named, TypeParam methods with functions
+ 2021-02-18 5e4da8670b [dev.typeparams] cmd/compile/internal/types2: use converter functions rather than methods
+ 2021-02-18 5ecb9a7887 [dev.typeparams] go/types: use a new ast.ListExpr for multi-type instances
+ 2021-02-18 f3c2208e2c cmd/go: add script tests for potential upgrades due to downgrades
+ 2021-02-18 a5c8a15f64 cmd/go/internal/mvs: clarify and annotate test cases
+ 2021-02-18 a76efea1fe cmd/go/internal/mvs: don't emit duplicates from Req
+ 2021-02-18 609d82b289 cmd/dist: set GOARM=7 for windows/arm
+ 2021-02-18 7b679617f3 [dev.typeparams] go/types: conversions to type parameters are not constant
+ 2021-02-18 f0be3cc547 runtime: unbreak linux/riscv64 following regabi merge
+ 2021-02-18 07ef313525 runtime/cgo: add cast in C code to avoid C compiler warning
+ 2021-02-17 f5d0c653e6 [dev.typeparams] merge master (2f0da6d) into dev.typeparams
+ 2021-02-17 e196cb8258 [dev.typeparams] cmd/dist:  disable -G=3 on the std go tests for now
+ 2021-02-17 2f0da6d9e2 go/types: revert "no 'declared but not used' errors for invalid var decls"
+ 2021-02-17 70c37ee7d0 cmd/compile/internal/test: gofmt abiutils_test.go
+ 2021-02-16 84825599dc all: merge branch dev.regabi (d3cd4830ad) into master
+ 2021-02-16 d3cd4830ad [dev.regabi] test: run abi/regabipragma test with -c=1
+ 2021-02-16 03cea563d1 [dev.regabi] all: merge master (5faf941) into dev.regabi
+ 2021-02-16 b8fb049c7a [dev.regabi] cmd/go: copy internal/abi in TestNewReleaseRebuildsStalePackagesInGOPATH
+ 2021-02-16 5faf941df0 internal/goversion: update Version to 1.17
+ 2021-02-16 ed55da46ab [dev.regabi] go/types: overlapping embedded interfaces requires go1.14
+ 2021-02-16 7696c94334 [dev.regabi] go/types: type alias decl requires go1.9
+ 2021-02-16 c2358a1ae7 [dev.regabi] runtime: stub out spillArgs and unspillArgs
+ 2021-02-16 8cfbf34dd9 internal/abi: set register count constants to zero for regabi experiment
+ 2021-02-16 6f3da9d2f6 README: pull gopher image from website
+ 2021-02-16 d28aae26b0 [dev.regabi] cmd/link: recognize internal/abi as runtime package
+ 2021-02-16 098504c73f cmd/link: generate trampoline for inter-dependent packages
+ 2021-02-16 1004a7cb31 runtime/metrics: update documentation to current interface
+ 2021-02-16 6530f2617f doc/go1.16: remove draft notice
+ 2021-02-16 353e111455 doc/go1.16: fix mismatched id attribute
+ 2021-02-16 e0215315f5 [dev.regabi] reflect: support for register ABI on amd64 for reflect.(Value).Call
+ 2021-02-16 f0d23c9dbb internal/poll: netpollcheckerr before sendfile
+ 2021-02-16 0cb3415154 doc: remove all docs not tied to distribution
+ 2021-02-16 626ef08127 doc: remove install.html and install-source.html
+ 2021-02-16 30641e36aa internal/poll: if copy_file_range returns 0, assume it failed
+ 2021-02-15 33d72fd412 doc/faq: update generics entry to reflect accepted proposal
+ 2021-02-15 852ce7c212 cmd/go: provide a more helpful suggestion for "go vet -?"
+ 2021-02-13 66c27093d0 cmd/link: fix typo in link_test.go
+ 2021-02-13 b81efb7ec4 [dev.regabi] go/types: add support for language version checking
+ 2021-02-13 a7e9b4b948 [dev.regabi] go/types: untyped shift counts must fit into uint
+ 2021-02-13 060fa49bd2 [dev.regabi] go/types: refuse excessively long constants
+ 2021-02-12 a06bd9fecb [dev.typeparams] cmd/compile/internal/types: review of resolver_test.go
+ 2021-02-12 042f88fe30 [dev.typeparams] cmd/compile/internal/types: review of errors_test.go
+ 2021-02-12 0abd7b768b [dev.typeparams] cmd/compile/internal/types: review of universe.go
+ 2021-02-12 1b6f0bf1b2 [dev.typeparams] cmd/compile/internal/types: review of sizes_test.go
+ 2021-02-12 1758780181 [dev.typeparams] cmd/compile/internal/types: review of sizes.go
+ 2021-02-12 3aee461d5c [dev.typeparams] cmd/compile/internal/types: review of return.go
+ 2021-02-12 7428318af6 [dev.typeparams] cmd/compile/internal/types: review of object_test.go
+ 2021-02-12 b20f9e2da1 [dev.typeparams] cmd/compile/internal/types: review of object.go
+ 2021-02-12 20746b2f37 [dev.typeparams] cmd/compile/internal/types: review of labels.go
+ 2021-02-12 bab3461123 [dev.typeparams] cmd/compile/internal/types: review of infer.go
+ 2021-02-12 9168590977 [dev.typeparams] cmd/compile/internal/types: review of builtin_test.go
+ 2021-02-12 f1777cf84c [dev.typeparams] cmd/compile/internal/types: review of builtin.go
+ 2021-02-12 baa6c75dce [dev.regabi] internal/abi: add new internal/abi package for ABI constants
+ 2021-02-12 d1fd9a8863 [dev.regabi] all: merge master (ff0e93e) into dev.regabi
+ 2021-02-12 ff0e93ea31 doc/go1.16: note that package path elements beginning with '.' are disallowed
+ 2021-02-12 0f43973b4b [dev.typeparams] go/types: make predeclared "any" alias for interface{}
+ 2021-02-12 58758e0a21 [dev.typeparams] go/types: better error message for invalid ... use
+ 2021-02-11 c0aa7bd760 [dev.typeparams] cmd/compile: small fixes for stenciling
+ 2021-02-11 249da7ec02 CONTRIBUTORS: update for the Go 1.16 release
+ 2021-02-11 864d4f1c6b cmd/go: multiple small 'go help' fixes
+ 2021-02-11 26ceae85a8 spec: More precise wording in section on function calls.
+ 2021-02-11 930c2c9a68 cmd/go: reject embedded files that can't be packed into modules
+ 2021-02-11 e5b08e6d5c io/fs: allow backslash in ValidPath, reject in os.DirFS.Open
+ 2021-02-10 df23540dde [dev.typeparams] cmd/gofmt: add the -G flag to allow generic code
+ 2021-02-10 ed8079096f cmd/compile: mark concrete call of reflect.(*rtype).Method as REFLECTMETHOD
+ 2021-02-10 ddec18cf82 [dev.typeparams] cmd/compile/internal/types2: overlapping embedded interfaces requires go1.14
+ 2021-02-10 59703d53e2 [dev.regabi] cmd/link: stop using ABI aliases if wrapper is enabled
+ 2021-02-10 fdf3496fcc [dev.typeparams] cmd/compile:  make type conversions by type parameters work
+ 2021-02-10 12e15d430d [dev.typeparams] cmd/compile: handle calling a method on a type param in stenciling
+ 2021-02-09 e9c9683597 cmd/go: suppress errors from 'go get -d' for packages that only conditionally exist
+ 2021-02-09 168d6a49a5 [dev.regabi] go/types: use 512 bits as max. integer precision
+ 2021-02-09 0a62067708 [dev.regabi] go/types: adjust importer to match compiler importer
+ 2021-02-09 1c58fcf7ed [dev.regabi] go/types: handle untyped constant arithmetic overflow
+ 2021-02-09 493363ccff [dev.regabi] go/types: must not import a package called "init"
+ 2021-02-09 e0ac989cf3 archive/tar: detect out of bounds accesses in PAX records resulting from padded lengths
+ 2021-02-09 c48d1503ba [dev.regabi] go/types: report unused packages in source order
+ 2021-02-09 813958f13c [dev.regabi] go/types: factor out sorting of methods
+ 2021-02-09 11d15c171b [dev.regabi] go/types: convert untyped arguments to delete
+ 2021-02-08 ca18c42054 [dev.typeparams] merge dev.regabi (618e3c1) into dev.typeparams
+ 2021-02-09 c9d6f45fec runtime/metrics: fix a couple of documentation typpos
+ 2021-02-09 cea4e21b52 io/fs: backslash is always a glob meta character
+ 2021-02-08 dc725bfb3c doc/go1.16: mention new vet check for asn1.Unmarshal
+ 2021-02-08 618e3c15bd [dev.regabi] go/types: consistently report nil type as "untyped nil"
+ 2021-02-08 a360eeb528 [dev.typeparams] cmd/compile/internal/types2: conversions to type parameters are not constant
+ 2021-02-08 0fbde54ea6 [dev.typeparams] cmd/compile: allow generic funcs to call other generic funcs for stenciling
+ 2021-02-08 50449de66a [dev.regabi] all: merge master (1901853) into dev.regabi
+ 2021-02-08 7b0dfb177f [dev.regabi] runtime: use g register in some assembly functions on AMD64
+ 2021-02-08 2e60c00f56 [dev.regabi] cmd/internal/obj/x86: use g register in stack bounds check
+ 2021-02-08 22f9e1ccbc [dev.regabi] runtime: initialize special registers before sigpanic
+ 2021-02-08 5d7dc53888 [dev.regabi] cmd/compile, runtime: reserve R14 as g registers on AMD64
+ 2021-02-08 1901853098 runtime/metrics: fix panic in readingAllMetric example
+ 2021-02-08 ed3e4afa12 syscall/plan9: remove spooky fd action at a distance
+ 2021-02-08 a21de9ec73 [dev.regabi] cmd/link: resolve symbol ABI in shared linkage
+ 2021-02-05 724d0720b3 doc/go1.16: add missed heading tag in vet section
+ 2021-02-05 b54cd94d47 embed, io/fs: clarify that leading and trailing slashes are disallowed
+ 2021-02-05 4516afebed testing/fstest: avoid symlink-induced failures in tester
+ 2021-02-05 8fa84772ba [dev.regabi] runtime: delete gosave function
+ 2021-02-05 946351d5a2 [dev.regabi] runtime: zero X15 in racecall
+ 2021-02-05 397a46a10a [dev.regabi] cmd/asm: define g register on AMD64
+ 2021-02-05 e79c2fd428 [dev.regabi] runtime: mark racecallbackthunk as ABIInternal
+ 2021-02-05 7cc6de59f2 [dev.regabi] runtime: don't mark rt0_go ABIInternal
+ 2021-02-05 dcb5e0392e [dev.typeparams] cmd/compile: add stenciling of simple generic functions
+ 2021-02-05 63de211014 [dev.regabi] runtime/cgo: call setg_gcc in crosscall_amd64
+ 2021-02-04 f37b0c6c12 [dev.typeparams] cmd/compile/internal/types2: type alias decl requires go1.9
+ 2021-02-04 721488498a [dev.typeparams] cmd/compile: pass -lang flag value to new type checker
+ 2021-02-04 1ff2fdaaf1 [dev.typeparams] cmd/compile/internal/types2: add support for language version checking
+ 2021-02-04 370e9f5843 [dev.typeparams] cmd/compile/internal/types2: use 512 bits as max. integer precision
+ 2021-02-04 120b819f45 [dev.regabi] go/types: report error for invalid main function signature
+ 2021-02-04 52d5cb2822 [dev.regabi] cmd/internal/obj: access Attribute atomically
+ 2021-02-04 bc451b5770 [dev.regabi] go/types: port check_test.go ergonomics from dev.typeparams
+ 2021-02-04 afd67f3334 [dev.regabi] go/types: no "declared but not used" errors for invalid var decls
+ 2021-02-04 ca2f152893 [dev.typeparams] go/types: add missing test from dev.go2go
+ 2021-02-04 8869086d8f runtime: fix typo in histogram.go
+ 2021-02-03 401d7e5a24 [dev.regabi] cmd/compile: reserve X15 as zero register on AMD64
+ 2021-02-03 bfc7418e6d [dev.regabi] runtime, syscall, etc.: mark Darwin syscall wrappers as ABIInternal
+ 2021-02-03 e491c6eea9 math/big: fix comment in divRecursiveStep

Change-Id: Idc1fbc206629b016f7bb24c2066c2be9046a511a
2021-03-04 11:08:34 -05:00
Robert Griesemer
356c1719ec [dev.go2go] all: update/fix codereview.cfg
Change-Id: Icf1a6abc233298ab22fb0e9c3e3792ebd5ff1759
Reviewed-on: https://go-review.googlesource.com/c/go/+/295229
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-02-22 23:59:03 +00:00
Rob Findley
1941f298de [dev.go2go] all: merge dev.typeparams (dc122c7) into dev.go2go
This merge resolved all conflicts by taking the dev.typeparams copy. The
only additional changes were to delete exprstring.go,
exprstring_test.go, methodset.go, and walk.go, which had been deleted
from dev.typeparams but were not present in the merge base.

go/build/deps_test.go was updated to allow go2go dependencies.

Change-Id: I2d6da3c1e44a4da888ee71165d5cb3702fec5f88
2021-02-04 09:12:51 -05:00
Rob Findley
c83a4376c9 [dev.go2go] go/*: merge parser and types changes from dev.typeparams
Merge just the conflicting changes from dev.typeparams (ast, parser,
types, etc.), excluding io/fs changes.

The rest of the dev.typeparams merge will be done in a later CL, once
the compiler changes have stabilized.

Change-Id: Ic24c5902e4cacc85338ab23b100e5a245a5148bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/286774
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-27 17:23:18 +00:00
Rob Findley
673969c453 [dev.go2go] cmd/go2go: update stale documentation for go2go
Update documentation to reflect that -brackets has been removed.

Change-Id: I02efd33ac646a41587a9aaafd2b31a23fb6849f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/286773
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-27 17:21:07 +00:00
Rob Findley
dd089351e9 [dev.go2go] cmd/go2go: remove -brackets from the go2go command
Remove the -brackets flag from the go2go command, as we will no longer
support multiple syntaxes.

Doing this also required removing a test for pointer designation, which
failed without the old syntax. Support for pointer designation will be
removed in the merge from dev.typeparams anyway.

Change-Id: I66f3e604aaa16ce92acc9d8f00e9fce9cd857ec5
Reviewed-on: https://go-review.googlesource.com/c/go/+/286432
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-27 17:21:01 +00:00
Rob Findley
79f7966688 [dev.go2go] go/format: parse type parameters
In order to support generic code, cmd/gofmt was updated to parse type
parameters. However, the playground uses go/format, which was not
updated accordingly. Fix this.

A minor change is also made in go/printer to avoid a data race exposed
by this change.

Fixes #43470

Change-Id: I8a3ac5e3cbc8767e0ca1675130dd27634cb5018f
Reviewed-on: https://go-review.googlesource.com/c/go/+/283134
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-12 16:41:23 +00:00
Rob Findley
aee3904d8f [dev.go2go] import errorcodes.go from the dev.typeparams branch
This is an initial commit to ensure that the automated deployment of
the go2go playground works as expected.

Change-Id: I76952843a5325bccaacca5ee4ed07c0dda9f33aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/283133
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-01-12 00:15:40 +00:00
Rob Findley
abe4d3dce1 [dev.go2go] go/types: remove the aType helper
As of CL 274852, this helper type is no longer necessary.

Change-Id: I47945d5976817cc52b4f092229592d4422a59a67
Reviewed-on: https://go-review.googlesource.com/c/go/+/276193
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-08 17:59:47 +00:00
Rob Findley
a87ed01cf0 [dev.go2go] go/types: revert the Type interface for compatibility
The go2go prototype added converter methods to the Type interface for
convenience, but this change breaks compatibility.

Revert to the previous Type interface, and move the converters to helper
functions. Along the way, enforce some relationships between converters
that simplify the code and avoid switch statements:
 - optype(under(t)) == optype(t)
 - asNamed(expand(t)) == asNamed(t)
 - asTypeParam(under(t)) == asTypeParam(t)
 - as<Other>(optype(t)) == as<Other>(t)

Where possible functions are unexported, with a couple exceptions that
are necessary for the go2go rewriter. These exceptions could probably be
avoided, but it doesn't seem worth the effort.

Eliminating interface methods introduces initialization cycles involving
unaryOpPredicates and binaryOpPredicates, which are avoided using init
functions.

Change-Id: Ia695395431e93b4b5c3484ae07531b561599f437
Reviewed-on: https://go-review.googlesource.com/c/go/+/274852
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-12-04 14:30:20 +00:00
Robert Griesemer
a9402335f2 [dev.go2go] go/types, cmd/compile/internal/types2: a type parameter is a valid type case in a type switch
Likewise for type assertions.

Updates #42758.

Change-Id: Iea727639f348c6997b4d3aaba420ea242e985002
Reviewed-on: https://go-review.googlesource.com/c/go/+/273127
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-25 05:57:40 +00:00
Robert Griesemer
440f144a10 [dev.go2go] go/types, cmd/compile/internal/types2: fix incorrect string(int) conversion (regression)
This is a 1:1 port of the go/types changes in
https://golang.org/cl/272666 (master branch).

Updates #42790.

Change-Id: I633fab83ce9c9895e056592039e1f5e7cb3fe23e
Reviewed-on: https://go-review.googlesource.com/c/go/+/272667
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-24 01:29:01 +00:00
Robert Griesemer
9daca74ad2 [dev.go2go] cmd/compile/internal/types2: port of CL 270657 and CL 270937
- Port of https://golang.org/cl/270657 in go/types to types2.
- Port of https://golang.org/cl/270937 in go/types to types2.

Change-Id: I7d6dadf5bb91c89e51975127bded4279c92510cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/270957
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-18 00:18:01 +00:00
Robert Griesemer
d5beb04d48 [dev.go2go] go/types: backport of https://golang.org/cl/270658
Change-Id: I8f31adff3e0a44767ebdcde3059336bcd549a4b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/270937
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-18 00:17:59 +00:00
Robert Griesemer
bac01b04ab [dev.go2go] go/types: fix indexing of type parameter values constraint by maps
For instance, given a constraint

	interface { type []E, map[K]E }

and a variable x of type parameter type constraint by above constraint,
the index expression x[i] is only permitted if K is an integer type.
Also, &x[i] is not permitted if the type list contains a map type since
map index expressions are not addressable. Finally, if the type list
contains only compatible map types, the index expression x[i] can be
used in a comma-ok assignment.

Fixes #42616.

Change-Id: I6287de47619acee25efbcd73a7b04b835d26a885
Reviewed-on: https://go-review.googlesource.com/c/go/+/270657
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-17 06:11:46 +00:00
Robert Griesemer
2298dab082 [dev.go2go] cmd/compile/internal/types2: backport latest changes from dev.typeparams
With this CL, the types2 packages in the dev.go2go and dev.typeparams
branch are the same again.

Change-Id: If2cd9256a73fd75cc28675e9baac27ef6a289935
Reviewed-on: https://go-review.googlesource.com/c/go/+/264030
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-22 00:19:08 +00:00
Robert Griesemer
8d00158448 [dev.go2go] cmd/compile/internal/syntax: backport changes from dev.typeparams branch
Change-Id: Iaf9bbd80258746fbcaf7b35919c22528a504bcc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/263629
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-20 04:52:06 +00:00
Robert Griesemer
5ab6b82982 [dev.go2go] cmd/compile/internal/types2: implement syntax tree walk, enable all ResolveIdents test
Also: When type-checking struct types, type-check types shared among
multiple fields (such as type T in "a, b, c T") only once rather than
for each field.

Change-Id: I84d6bb0a01863963d214f59e9f58706c29ae5a16
Reviewed-on: https://go-review.googlesource.com/c/go/+/262840
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-16 01:06:25 +00:00
Robert Griesemer
dab75f981e [dev.go2go] cmd/compile/internal/syntax2: comprehensive channel printing tests
This matches the code in dev.typeparams now.

Change-Id: I75de25756d9bdc3de587653ff519f5e7bb5d6369
Reviewed-on: https://go-review.googlesource.com/c/go/+/262839
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-16 01:06:16 +00:00
Robert Griesemer
69b4547432 [dev.go2go] cmd/compile/internal/types2: remove dead code, invalid comment (cleanups)
Change-Id: I8babc2f3a2714d3a184380416bb25fae0997eaac
Reviewed-on: https://go-review.googlesource.com/c/go/+/262838
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-16 01:06:15 +00:00
Robert Griesemer
fef4c5f526 [dev.go2go] cmd/compile/internal/syntax: fix printing of channel types
Change-Id: I79fc051dc9e79638e3c0078ecdcf667bfa50891a
Reviewed-on: https://go-review.googlesource.com/c/go/+/262443
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-15 05:18:32 +00:00
Robert Griesemer
b7ce5f8101 [dev.go2go] cmd/compile/internal/types2: ordinary index expressions can have only one index
With type parameters, an index expression a[i, j] is syntactically possible.
Report an error if it is not a function or type instantiation rather than panic.

Change-Id: I562a56d7fa4febf75432dbe920aec2ff0db76449
Reviewed-on: https://go-review.googlesource.com/c/go/+/262441
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-15 03:52:05 +00:00
Robert Griesemer
5496b9d0bc [dev.go2go] cmd/compile/internal/types2: use Checker.funcInst for function instantiations
Also:
- Simplified code for index expressions that are type instantiations.
- Removed code from Checker.call that was needed for function instantiations.
- Removed handling of *syntax.CallExpr for types (we use *syntax.IndexExpr).
- Added a missing Checker.use call to satisfy a test that would now report an error.
- Adjusted some tests that were still using ()'s rather than []'s.

Change-Id: I559dcac641ab32f1c323481066afb0773e7e95dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/262440
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-15 03:52:04 +00:00
Robert Griesemer
4f077672b7 [dev.go2go] cmd/compile/internal/types2: factor out function instantiation from call check
Change-Id: If933d0f9a58f3f5e6ddb0e94b1d9f3b859b40352
Reviewed-on: https://go-review.googlesource.com/c/go/+/262439
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-15 03:52:02 +00:00
Robert Griesemer
cbfbbc3bed [dev.go2go] cmd/compile/internal/syntax,types2: always use IndexExpr node for type instantiation
Per @mdempsky's suggestion: Instead of representing a type instantiation T[P]
by an IndexExpr node, and a type instantiation with multiple type arguments
T[P1, P2] by a CallExpr node with special Brackets flag, always use an IndexExpr.
Use a ListExpr as index in the (less common) case of multiple type arguments.

This removes the need for the CallExpr.Brackets field and cleans up the parser
(and eventually the type checker) code for type instantiations.

Change-Id: I5ff784800c8235d278b15c69a8a03acfca144b37
Reviewed-on: https://go-review.googlesource.com/c/go/+/262020
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-14 22:27:13 +00:00
Robert Griesemer
32b18b7307 [dev.go2go] go/types, .../types2: fix subtle bug (typo) in receiver type rewriting
Also: Simplify ParenExpr case.
Change-Id: I09cb6988222cb19835617cb6bcc089307b675ab2
Reviewed-on: https://go-review.googlesource.com/c/go/+/262021
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-14 04:08:57 +00:00
Robert Griesemer
c4e9233358 [dev.go2go] cmd/compile/internal/syntax: backport of changes made in dev.typeparams
The changes match the CLs:

https://golang.org/cl/261657
https://golang.org/cl/261658
https://golang.org/cl/261219
https://golang.org/cl/261660

Also: Updated types2 test to match parser changes.

Change-Id: I397980c41234b43a4f12d0ab4ecc3fc23fad278b
Reviewed-on: https://go-review.googlesource.com/c/go/+/261757
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-13 05:32:17 +00:00
Robert Griesemer
10bb7589dd [dev.go2go] cmd/compile: enable parsing of generic code with new -G flag
Providing the -G flag instructs the compiler to accept generic code.
For now, the compiler only parses such files and then exits.

Added a new test directory (test/generic) and initial test case for
generic code.

Change-Id: Ic11e33a9d5f012f8def0bdae205043659562ac73
Reviewed-on: https://go-review.googlesource.com/c/go/+/261659
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-12 23:40:05 +00:00
Robert Griesemer
4ba7c9eef6 [dev.go2go] cmd/compile/internal/syntax: add AllowGenerics mode for enabling/disabling type parameters
Change-Id: I1f6273c2253d1d6e7395b665c6700c6c937b8564
Reviewed-on: https://go-review.googlesource.com/c/go/+/261597
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-12 18:02:18 +00:00
Robert Griesemer
5f39ddea15 [dev.go2go] cmd/compile/internal/types2: enable TestTestdata
All /testdata tests pass now with relaxed column position requirement.

Change-Id: Idabde521f97b042e8f6018f66e037e2494903a3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/261298
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-10 23:39:20 +00:00
Robert Griesemer
99e8b46e6d [dev.go2go] cmd/compile/internal/types2: permit inexact column position for error tests
Change-Id: Ief4067bff20a94aea09a3993c96d2ba9d623b147
Reviewed-on: https://go-review.googlesource.com/c/go/+/261297
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-10 23:39:18 +00:00
Robert Griesemer
f2c8981d40 [dev.go2go] cmd/compile/internal/types2: various fixes towards enabling TestTestdata
- Fix Checker.use (code was nonsensical).
- Fix arity check for const and var decls.
- Fix binary op predicates.
- Fix collection of parameters: make sure each type (incl. ...T types) is only checked once.
- Report an invalid AST error for 3-index slice expressions with missing indices.
- Adjust some tests to match error messages about 3-index slice expressions.
- Fix position for "missing return" error.
- Provide a better error message for incorrect x++/x-- statements.
- Don't report an error for for-loop post declaration statement (the parser does already).
- Adjust some tests for const/var init expressions because we don't get duplicate errors anymore.
- Adjust some tests to match error messages about methods with multiple receivers.
- Adjust some tests for imports because we don't get duplicate errors anymore.
- Disable tests that check interface method type parameters (parser doesn't collect them).
- Adjust some tests for incorrect type instantiations (parser reports the errors).
- Adjust some tests for go/defer statements (parser reports one of the errors).

With these changes, TestTestdata passes now if we ignore exact error column position.
The next CL will enable imprecise error position matching (only line numbers need to
match) and then we can enable the test.

Change-Id: I46fbcb300f065729f4e4660b40edcd2d1e6c78b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/261277
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-10 23:39:17 +00:00
Robert Griesemer
3ae3ea1f0e [dev.go2go] cmd/compile/internal/syntax: provide BadExpr where needed, call correct error handler
- For "if" statements without a condition, provide a BadExpr rather than nil
  so that the type checker doesn't report the same error again.

- For 3-index slice expressions, also provide BadExpr where an index is
  required but missing.

- Declare a parser-local error method to hide the embedded error method
  so we don't use it by mistake.

Change-Id: I19f89668025e17bd6c632cc98c57bd1f5ca099a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/261138
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-10 23:39:16 +00:00
Robert Griesemer
0d5173761c [dev.go2go] cmd/compile/internal/types2: remove another dependency on go/scanner
Instead use syntax.CommentsDo.

Change-Id: I5a12349de81a4e3e96846f2c3c63c8f0fd4294a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/261157
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-10 00:28:53 +00:00
Robert Griesemer
f857dab8dc [dev.go2go] cmd/compile/internal/types2: remove unused token.FileSet from self_test.go
Change-Id: I9e55a96675cc08ef97e84bda0dbaa77e9fece0e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/260058
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-07 05:44:55 +00:00
Robert Griesemer
e595b8c245 [dev.go2go] cmd/compile/internal/syntax2: rewrite checkFiles in terms of syntax.ErrorMap
This eliminates another of the remaining dependencies on the go/* libraries.
The rewrite also enables "approximate" matching where the reported and expected
lines match, but the columns don't.

Change-Id: Ia81c565ee4c9d14e2c224c7f3f7f1b37595d5524
Reviewed-on: https://go-review.googlesource.com/c/go/+/260057
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-07 05:44:45 +00:00
Robert Griesemer
4889382453 [dev.go2go] cmd/compile/internal/syntax: implement ErrorMap
Also: Move CommentsDo into testing.go.

Change-Id: I78a05f2c4486378f05de41152d5739241ba334cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/260019
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-07 05:25:37 +00:00
Robert Griesemer
b81fb4e758 [dev.go2go] cmd/go2go: fix typo in test case
Fixes #41574.

Change-Id: I885f72bd68798b4ccdc539b062afa0d36debce4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/256718
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-24 00:15:54 +00:00
Robert Griesemer
e9e897e0fe [dev.go2go] cmd/compile/internal/types2: rename and move leftPos into pos.go (cleanup)
- renamed leftPos to startPos (matching endPos)
- moved startPos into pos.go
- converted code into (manual) tail-recursive form (matching endPos)

Change-Id: Iaf1f6b9ff15120c383fd12928917d8306401c747
Reviewed-on: https://go-review.googlesource.com/c/go/+/255077
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-15 19:46:15 +00:00
Robert Griesemer
6d0b55d886 [dev.go2go] cmd/compile/internal/types2: enable ScopeLookupParent test
- set missing scope positions for objects
- set various end positions for scopes
- implemented endPos function to determine approx. end positions of nodes

Change-Id: Id908f534725b6becc7d2ccbc4382b1042399c556
Reviewed-on: https://go-review.googlesource.com/c/go/+/254958
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-15 19:34:27 +00:00
Robert Griesemer
e62efddde2 [dev.go2go] cmd/compile/internal/types2: get ScopeLookupParent test to compile again
- Fixed commented out code to compile within syntax-based type checker again.
  Test is still disabled as it doesn't pass yet.

- Added syntax.CommentsDo general file comment/error iterator.

Change-Id: I28425d5c129cab5a085f8f427d8b8476fafa99a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/254957
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-15 04:02:26 +00:00
Robert Griesemer
ff2a0a7ea4 [dev.go2go] cmd/compile/internal/syntax: replace Files.Lines with Files.EOF position
Having the actual end position of a file also provides the number of
lines and is more easily used to determine the (scope) range of a file
as needed by cmd/compile/internal/types2.

Change-Id: Idea736b7caacebbb9e0ebc2094057f4cd54084b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/254897
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-15 00:48:09 +00:00
Robert Griesemer
a47099db29 [dev.go2go] cmd/compile/internal/types2: error handlers now take a poser instead of a Pos
This change makes the recent error handler change type-safe again:
Rather than taking a syntax.Pos (and requiring each caller to call
the Pos method), now an error handler accepts a poser

type poser interface
   Pos() syntax.Pos
}

and then can call Pos directly.

Change-Id: I618db450725b49da873e121e1c1ef603dfc6fe5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/254858
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-14 22:14:42 +00:00
Robert Griesemer
aa0705b3a7 [dev.go2go] cmd/compile/internal/types2: fix error positions for nodes
Nodes of the syntax AST record a position identifying the node's syntactic
feature (e.g., the position of the '.' in a selector expression, or the
position of the '[' in an index expression). But the go/ast reports the
left-most (= start) position of a node, which is what the existing go/types
based test cases expect.

Compute the left-most position of nodes for error reporting. To simplify
error handler calls, pass syntax.Nodes, Objects, or *operands in place of
a syntax.Pos and let the error handler functions decide how to determine
the correct position. This removes > 200 method pos/Pos method calls.

Renamed invalidAST/Arg/Op error handler functions to invalidASTf/Argf/Opf
for consistency.

Fixed several type-checker bugs (incorrectly ported from go/types).

Enabled Fixedbugs tests.

Fixed a bug in go/types/builtins.go.

Change-Id: I05bb749a5374fc3cc2818094bc59a58972443744
Reviewed-on: https://go-review.googlesource.com/c/go/+/254437
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-12 01:25:34 +00:00
Robert Griesemer
ec995dab79 [dev.go2go] cmd/compile/internal/types2: enable Example tests
- correctly collect parser errors
- fix a few small parser and type checker bugs
- don't skip Example tests anymore

Change-Id: Ia3f9a63fd97c410bbe9bbc21efe9dccae4551586
Reviewed-on: https://go-review.googlesource.com/c/go/+/254277
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-11 03:57:18 +00:00
Robert Griesemer
2eecf29c10 [dev.go2go] go/types: minor adjustment to two tests
Brings go/types in sync with the respective tests in types2.

Change-Id: I7d97657c9b8dc8171834739f649907e1767a0feb
Reviewed-on: https://go-review.googlesource.com/c/go/+/253998
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 22:35:49 +00:00
Robert Griesemer
37ac354972 [dev.go2go] cmd/compile/internal/types2: bring over latest go/types changes
Change-Id: I2379f7d84bfe18c4349711555554cce85c103eb1
Reviewed-on: https://go-review.googlesource.com/c/go/+/254197
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 22:28:33 +00:00
Robert Griesemer
e6a1350191 [dev.go2go] cmd/compile/internal/syntax: restore errors for embedded parenthesized fields
When we used ()'s for type parameters, we needed to relax the rules for
embedded struct fields and interface methods: parenthesized embedded
fields and methods were necessary to disambiguate from other constructs.
Now that we use []'s, we can go back to the existing Go rules.

Minor cleanups.

Change-Id: I45399e5b5592c76654a5d504f8bb8b23fff53b85
Reviewed-on: https://go-review.googlesource.com/c/go/+/253997
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 18:36:09 +00:00
Robert Griesemer
c3f85a2312 [dev.go2go] cmd/compile/internal/syntax: use unified parameter syntax
- type and ordinary parameter list follow the same syntax
- type parameters are enclosed in [], ordinary parameters use ()
- type parameter lists cannot be empty
- all type parameters must be named

Adjusted parser to follow new syntax. Lots of related cleanups.
Adjusted testdata/go2/x.go2 tests and removed the xB.go2 tests.
Preliminary adjustments to types2 package to make tests pass.

Change-Id: Ic4e6597180b97f06345f60cafa9bfc7c642a26ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/253040
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 04:49:13 +00:00
Ian Lance Taylor
e6b857770a [dev.go2go] go/go2go: handle inferred arguments for index expressions
Fixes golang/go#41216

Change-Id: Iff109f0a7f047742c5f90d64db201712c04f3259
Reviewed-on: https://go-review.googlesource.com/c/go/+/253818
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-09 21:19:10 +00:00
Robert Griesemer
573d94888f [dev.go2go] go/types: don't crash when a generic function is instantiated with a value
Change-Id: I9fe898c57590e9d80545543bca87676e16c6b728
Reviewed-on: https://go-review.googlesource.com/c/go/+/253379
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-07 21:23:04 +00:00
Robert Griesemer
a2c342556d [dev.go2go] go/types: record constraint type inference when some type params are provided
The existing code didn't record the results of constraint type inference
when it was applied to a partial list of (provided) type parameters.

Changed Info.Inferred map to accept *ast.CallExpr and *ast.IndexExpr
as keys ("call" may be f(x) or f[T]).

Updates #41216.

Change-Id: I5da7467d01643bf74fb78f6c6728209cbd4006c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/253258
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-07 19:09:58 +00:00
Robert Griesemer
9ff2aa4272 [dev.go2go] cmd/gofmt, go/format: set []-mode for type parameters in a few more places
Now that we have mostly settled on the type parameter list syntax we should
probably remove the various modes of parsing and printing. For now just set
the UseBrackets flag explicitly when printing.

Updates #41195.

Change-Id: I56b06b4f930908579a38a140e8221618c8e2fa17
Reviewed-on: https://go-review.googlesource.com/c/go/+/252879
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-02 23:45:03 +00:00
Robert Griesemer
8ea0120a21 [dev.go2go] go/types: interfaces with type lists are only allowed as constraints
Check that such constraint interfaces don't appear in:
- composite types
- type and function instantiations
- assertions
- type switches

Streamlined respective error messages. Added lots of tests.

Fixes #41124.

Change-Id: Ie04a95ab056b40561484f04ed6e843ca371e1d41
Reviewed-on: https://go-review.googlesource.com/c/go/+/251718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-31 05:23:21 +00:00
Robert Griesemer
c4914f19b5 [dev.go2go] go/types: improve error when a type argument doesn't satisfy constraint
If the cause is a method with incorrect signature, report the
expected and presented signature.

Updates #41125.

Change-Id: Ibd0fa23547b77df924ec5421cc8e657d41c5a5a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/251717
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-31 00:10:51 +00:00
Robert Griesemer
ea8318cad7 [dev.go2go] go/parser, go/types: type parameters must always be named
Change-Id: Ia78ec8ebc7bc7432c3ca3c75dbca3ffedc6ab388
Reviewed-on: https://go-review.googlesource.com/c/go/+/251561
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-29 01:02:37 +00:00
Robert Griesemer
4d89d2a7e3 [dev.go2go] go/parser: adjust error message for mixed parameter lists
Error doesn't just apply to ordinary function parameters anymore;
it could be a (type or function) type parameter list.

Change-Id: Ied75d363917079b265140eb1f1a291d98e019229
Reviewed-on: https://go-review.googlesource.com/c/go/+/251558
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:45:43 +00:00
Robert Griesemer
4461513296 [dev.go2go] go/types: add missing instantiation checks for function type arguments
Fixes #40684.

Change-Id: If642edbf321973729a8d5b36b4bf61e3fae7ee3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/251557
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:45:41 +00:00
Robert Griesemer
93e810a5f5 [dev.go2go] go/types: gotype cmd to use new unified type parameter syntax
Change-Id: I76b0d0312e9f7e262139e3b7e4fb8c22989fbca9
Reviewed-on: https://go-review.googlesource.com/c/go/+/251443
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:12:57 +00:00
Ian Lance Taylor
36bab40fc1 [dev.go2go] cmd/gofmt: pass UnifiedParamLists to parser
Fixes #41079

Change-Id: I781c5c681c66712ed2ac0112dd44fa8793845978
Reviewed-on: https://go-review.googlesource.com/c/go/+/251278
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-28 02:28:04 +00:00
Robert Griesemer
5e60d1e8c7 [dev.go2go] go/types: predeclared "any" is only visible as constraint in a type parameter list
Per the restriction in the current design draft.

Change-Id: Ic6ff597849335fa23de22529999d20aacfc205b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/251140
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 23:37:57 +00:00
Robert Griesemer
dd1af75a70 [dev.go2go] go/types: disable implicit instantiation of single type parameter constraints
Per the latest update to the design draft.

Change-Id: I026b52082e739f6806cd37a0f3e88a546a6f2e90
Reviewed-on: https://go-review.googlesource.com/c/go/+/251139
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 23:37:55 +00:00
Robert Griesemer
af1adc5d8c [dev.go2go] go/parser, go/types: make type parameters a syntax error for type aliases
Accept parameterized aliases for robustness but complain.

Change-Id: I86ad945af253b6c483fca0ac331245730fb22a66
Reviewed-on: https://go-review.googlesource.com/c/go/+/251138
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 20:00:05 +00:00
Robert Griesemer
21bc157bc5 [dev.go2go] go/parser: disallow empty type parameter lists and instantiations
When using unified parameter list syntax, an empty type parameter
list in a type declaration is impossible (it means a slice type).
For symmetry, and because it doesn't make sense to support it,
disallow empty type parameter lists in function declarations.
Accept (parse) them but report a syntax error.

Analogously, disallow empty index/slice/instantiation expressions.
Accept (parse) them but report a syntax error.

Adjust go/types and tests as necessary.

Change-Id: Ifc783245a54d276eb22232a7a74be4d47a7d33fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/250718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-27 19:10:21 +00:00
Robert Griesemer
3314879ed2 [dev.go2go] go/printer: don't write "type" keyword in type parameter lists if brackets are used
When the printer mode UseBrackets is set, use the new unified parameter
list syntax: use []'s for type parameters without the "type" keyword.
This will also change gofmt behavior accordingly.

Fixes #41053.

Change-Id: Ibaf490ea9ed178684bea34da5b57afa823a6829f
Reviewed-on: https://go-review.googlesource.com/c/go/+/250998
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 05:16:25 +00:00
Robert Griesemer
27c9d6ef7c [dev.go2go] cmd/go2go: switch to unified parameter syntax
Type and ordinary parameter lists use the same syntax except
for the square brackets or parentheses, respectively.

Change-Id: I6fb93e93bbfc649a2c1ef195d130e0dcee212c79
Reviewed-on: https://go-review.googlesource.com/c/go/+/250717
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-26 16:50:50 +00:00
Robert Griesemer
1964d56295 [dev.go2go] go/types: adjust all tests to use latest syntax
- use square brackets for type parameters
- otherwise, use same syntax as for ordinary parameters:
  all type parameters must have a constraint, can be "any"
- remove (rename) all *B.go2 tests in favor of adjusted *.go2 tests
- remove tests related to pointer notation for type parameters
  (we are going to use constraint type inference instead)
- adjust type string computation accordingly
- minor related adjustments

This change can be reverted if we don't like it.

Change-Id: Ie1034e0996df8f5ca6fbdf9ecaa3c93fcfd7106d
Reviewed-on: https://go-review.googlesource.com/c/go/+/249741
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
2020-08-26 01:59:01 +00:00
Robert Griesemer
7d90fb0025 [dev.go2go] go/parser: add mode for unified type and ordinary parameter list syntax
If UnifiedParamLists is set, type parameter must follow the syntax of ordinary
parameter lists except that they use square brackets rather than parentheses.

Change-Id: Ia17753eab2ab07e9ef62715a7b97d641f7d08cca
Reviewed-on: https://go-review.googlesource.com/c/go/+/249740
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-26 01:57:29 +00:00
Robert Griesemer
12c2128b9e [dev.go2go] go/go2go, go/types: enable constraint type inference
Constraint type inference was not enabled for go/go2go and gotype.

Fixes #40859.

Change-Id: Idcab4d0a2eae6f42f938604fb05aabe4ad94c934
Reviewed-on: https://go-review.googlesource.com/c/go/+/249737
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-21 00:12:31 +00:00
Ian Lance Taylor
ec50ad4981 [dev.go2go] cmd/go2go: in testdata, drop type keyword, always provide constraint
This is a rewrite of the tests to drop the type keyword for parameterized
functions and types, and to instead always provide a constraint.

We can revert if we don't like this approach.

Change-Id: I9cd097b8db2aa3c84a40a7aeaa10246ab3b990dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/248897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17 17:54:56 +00:00
Ian Lance Taylor
bc00f5ba9f [dev.go2go] test: drop type keyword, always provide constraint
This is a rewrite to drop the type keyword for parameterized functions
and types, and to instead always provide a constraint.

We can revert if we don't like this approach.

Change-Id: If4669fb4e2015067e9f955ff8567ed421be639ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/248880
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17 17:54:48 +00:00
Robert Griesemer
af48c2e84b [dev.go2go] go/types: use actual (not underlying) types of type list elements for interface satisfaction
This is a rule change in an attempt to streamline interface satisfaction:
If a (constraint) interface contains a type list, a type argument's type
or underlying type must be included in the type list (and the interface's
methods must be present, of course). Until now, a type argument's under-
lying type had to be one of the underlying types of the types in the type
list.

The effect is subtle: Because an underlying type is never a defined type,
if a type list contains defined types, only those defined types satisfy
the interface. If we want the interface to be more flexible, we can in-
clude non-defined types in its type list. In the common case, type lists
simply contain predeclared types (whose underlying types are themselves),
so this doesn't matter. An observable difference appears only for code
that currently uses defined types in constraint type lists: such code
becomes slightly more restrictive.

The primary benefit of this change is that it opens the door for general
(non-constraint) use of interfaces with type lists: Using the same rules
as for constraint satisfaction, a value may be assigned to a variable of
such an interface if it or its underlying type of the value is included
int the interface's type list. If the type list contains only defined types,
the respective interface acts like a sum type: it can only contain values
of those types (and nil).

This CL only changes the rules for constraints. It does not permit
interfaces with type lists for general (non-constraint) use for now.

Change-Id: I3f25b9d883dd865a74c583efee4be2e22258d493
Reviewed-on: https://go-review.googlesource.com/c/go/+/248265
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 23:21:42 +00:00
Robert Griesemer
722af87f62 [dev.go2go] go/types: determine if type declaration is generic based on use of type parameter
This change makes it possible to declare a generic type with exactly
one type parameter and no constraints without any special syntactic
augmentation: Instead, the parser determines whether a declaration
of the form

	type T[P] type_literal

is an array or generic declaration based on how the type parameter
P is used in type_literal. If P appears only in array lengths (if
at all) in type_literal, T is an array type. Otherwise it is a
generic type.

Change-Id: I6c1d62d61d04f322d73ee16840e0f3ffe299f4c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/248438
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 05:30:01 +00:00
Robert Griesemer
c3a77cc2d3 [dev.go2go] go/types: predeclare type any interface{} (experiment)
For fine-tuning the type parameter list notation. If we
proceed with square brackets rather than parentheses, we
don't need the "type" keyword in type parameter lists in
many cases. However, generic type declarations with one
type parameter and no constraint must somehow disambiguate
from array type declarations:

	type T[P] E

could be a generic type, or an array type declaration

	type T [P]E

There's a variety of choices for disambiguation, such as:

	type T[type P] E         // what we do now
	type T[P interface{}] E  // currently permitted
	type T[P any] E          // permitted with this CL
	type T[P,] E             // currently permitted

If we abandon the "type" keyword (currently optional), we
need an alternative. Writing the constraint seems nicer than
the comma option (in Go, all parameter lists permit a trailing
comma, but an array length specification doesn't allow it).
If we write the constraint, which is often the empty interface,
being able to write "any" would be more convenient.

In the past we have refused to add "any" to the language. There
may be many more situations where we need to specify an empty
constraint (any) so perhaps adding "any" is now justified. It
would also streamline a lot of existing code such as

	Printf(format string, args... any)

Change-Id: I366342ba8d981d344c96b1ceb60f61d963e9175a
Reviewed-on: https://go-review.googlesource.com/c/go/+/248263
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 05:13:41 +00:00
Robert Griesemer
2b748f02a0 [dev.go2go] cmd/compile/internal/types2: fix instantiation crash for generic type parameters
Port of go/types CL https://golang.org/cl/247498.

Updates #40038.

Change-Id: Iab002132627b689e0113c087b3f4d38c6356c3a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/248058
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-12 00:03:11 +00:00
Robert Griesemer
fc29b9010e [dev.go2go] cmd/compile/internal/types2: add special case report for generic map key type
Port of go/types CL https://golang.org/cl/247258. (The typeparamsB.go2
version of typeparams.go2 doesn't exist yet for types2.)

Updates #40551.

Change-Id: If2b329372bd4d160b4def8b66cc87f25ed4823fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/248057
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-12 00:03:09 +00:00
tdakkota
cb2cbbcda2 [dev.go2go] go/types: fix instantiation crash for generic type parame…
…ters

Fixes #40038.

Change-Id: I5b095d01fd1e3703561c179c34ddc3b43d7510f6
GitHub-Last-Rev: 3e5067a780
GitHub-Pull-Request: golang/go#40644
Reviewed-on: https://go-review.googlesource.com/c/go/+/247498
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-11 16:59:21 +00:00
tdakkota
6d33075156 [dev.go2go] go/types: add special case report for generic map key type
Fixes #40551.

Change-Id: Ifc10dbdcdbee6af5bdbfc36ec78e1a4361672acc
GitHub-Last-Rev: 8d373dee63
GitHub-Pull-Request: golang/go#40628
Reviewed-on: https://go-review.googlesource.com/c/go/+/247258
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-11 16:58:03 +00:00
Robert Griesemer
ead7e9b351 [dev.go2go] cmd/compile/internal/syntax: add more parser tests
Updated existing tests to more closely match the go/types
tests; added *B.go2 versions for some tests, using [] for
type parameters.

Change-Id: Ie7cfd9f5515f541d9422a2b2ab8a5d3e02d0499a
Reviewed-on: https://go-review.googlesource.com/c/go/+/246261
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 05:14:38 +00:00
Robert Griesemer
d8b0f3b91f [dev.go2go] go/parser: p.T(P) is a valid instantiated parameter type (fix bug)
The existing code didn't accept an instantiated imported (qualified) type
as type for a regular function parameter.

Also: Simplified logic around use of typeContext flag when []'s
      are used for type parameters.

Change-Id: Ic6c60e943344a976f5b8546c8a378ebd32a82d90
Reviewed-on: https://go-review.googlesource.com/c/go/+/246260
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:24 +00:00
Robert Griesemer
417abfbaf1 [dev.go2go] cmd/compile/internal/syntax: accept [] for type parameter lists
Still missing:
- embedded []-instantiated types in interfaces
- *B.go2 tests which exist for go/types

Change-Id: I3dd115fcd67f725144062c90550a91fcded1cbe2
Reviewed-on: https://go-review.googlesource.com/c/go/+/246259
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:23 +00:00
Robert Griesemer
c77c3236b1 [dev.go2go] cmd/compile/internal/types2: remove most token.Token dependencies
The remaining uses of token.Token are needed for the go/constant API.

Change-Id: I5dc8be1fae16217433da1acb5606fd1d7b8eea54
Reviewed-on: https://go-review.googlesource.com/c/go/+/246257
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:22 +00:00
Robert Griesemer
569c893c93 [dev.go2go] types2: update to include the latest go/types changes
This brings types2 (the syntax-based type-checker) up-to-date
with the latest version of the prototype go/types version. It
does not yet include the *B.go2 tests (using square brackets)
or the relevant syntax parser changes.

Tests that check error positions continue to be disabled since
the synax parser records slightly different positions than the
go/parser (to be fixed).

Manually verified that selected *.go2 tests which don't report
errors pass. Type-checks the std library without errors.

Change-Id: If859b180bba8362db86c211eeb4dc2d46255df36
Reviewed-on: https://go-review.googlesource.com/c/go/+/246137
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-31 06:05:23 +00:00
Robert Griesemer
deb678cebf [dev.go2go] go/types: add testcase for crash 9 of #39634
This test passes type-checking without problems but the
generated code causes a cmd/compile error (filed #40486).

Updates #39634.

Change-Id: If3dd28605f6d8792c6bd5bb032624e9a6140b2c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/245742
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:09 +00:00
Robert Griesemer
15144bdc72 [dev.go2go] go/types: fix isParameterized predicate
When checking if a type is parameterized, we only care about
type parameters bound to the specific type, not "free" type
parameters. The old code simply looked for "any" type parameter.

Change-Id: I6a3fe5ac7e3150c5796d4b7576682ab3d4b8558f
Reviewed-on: https://go-review.googlesource.com/c/go/+/245741
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:01 +00:00
Robert Griesemer
88496095d2 [dev.go2go] go/types: remove incorrect assert and replace with explanatory comment
Addresses crash 26 of #39634.
Also, added test case for crash 25 which was fixed with
https://golang.org/cl/245739.

Updates #39634.

Change-Id: I19793eb79fce63052ba055cde0b1dafdd9476895
Reviewed-on: https://go-review.googlesource.com/c/go/+/245740
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:00:56 +00:00
Robert Griesemer
f0e6640956 [dev.go2go] go/types: generic types in selector expressions must be instantiated
Addresses crash 24 of #39634.

Updates #39634.

Change-Id: If44e834834a07719e7f727d12cc24ac4af0997e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/245739
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:57:09 +00:00
Robert Griesemer
0db4da527f [dev.go2go] go/types: don't crash in assignment due to prior errors
Addresses crash #12 of 39634.

Updates #39634.

Change-Id: Ie67545d21b6a1e80fcdec1b2eb101b69c25e2952
Reviewed-on: https://go-review.googlesource.com/c/go/+/245738
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:27:38 +00:00
Robert Griesemer
d118bf7ce9 [dev.go2go] go/types: don't crash in lookup of incomplete interface
Also, update some comments.

Updates #39634.

Change-Id: I85c63e4b941e2bc04e8b5a59497fc47e5d578b8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/245737
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:10:38 +00:00
Robert Griesemer
df58427917 [dev.go2go] go/types: remove need to enumerate test files, clean up test handling
- Reorganize testdata directory to either contain single-file packages
or (one level of) sub-directories containing multi-file packages.

- Add TestTestdata that runs all the tests in testdata.

- Change TestCheck to only test files explicitly provided via -files.

Providing -v when running these tests now enumerates the packages.
For TestCheck it also prints the type-checking trace.

Change-Id: I66536881789234af030a0a2c9fc096822f593782
Reviewed-on: https://go-review.googlesource.com/c/go/+/244629
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 22:57:29 +00:00
Robert Griesemer
131fbfb416 [dev.go2go] go/types: remove need to enumerate examples and fixedbugs test files
Just traverse the respective directories.

Change-Id: I21432e23550d8331e61d3392e8488c81183ab6f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/244628
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 20:13:27 +00:00
Robert Griesemer
edac449852 [dev.go2go] go/types: clean up test support code and remove global variables
Change-Id: I152d2f4ca95f8217502d796ac49a8c96e5aba60b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 19:40:13 +00:00
Robert Griesemer
d0e6f20899 [dev.go2go] go/parser: make "type" optional in generic type declarations
Experiment: Make "type" keyword optional in generic type declarations when
it is clear that we can't have an array type declaration. This is the case
when we have one the following:

- more than one type parameter
- a type parameter with a constraint
- a trailing comma in the type parameter list

Change-Id: If6c473ba93b993a7c15ff2f7e7302709cc985f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/244623
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 18:10:25 +00:00
Robert Griesemer
fad691cf11 [dev.go2go] go/types: don't crash with unsafe.Alignof/Sizeof on a type parameter value
Report an error instead for now until we have a better idea.
(It's unclear what these operations should do as they are
defined to return a compile-time constant which we can't
know in general.)

Fixes #40301.

Change-Id: I22a991311de117bc00d52b67b4ce862ea09d855a
Reviewed-on: https://go-review.googlesource.com/c/go/+/244622
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 00:25:37 +00:00
Ian Lance Taylor
64148d34c7 [dev.go2go] go/go2go: don't import renamed package twice
We keep an import spec if it uses a local alias. Avoid importing it
again, unless it is required by something else.

Fixes #40318

Change-Id: If90de3bf30412645c9144083372e6b07df3c6a0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-23 23:17:54 +00:00
Robert Griesemer
0030e13efb [dev.go2go] go/types: add a couple more interesting type inference examples
Change-Id: I28b31e013ae28a71adefb07cce0f47b505b57676
Reviewed-on: https://go-review.googlesource.com/c/go/+/244620
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:52:06 +00:00
Robert Griesemer
de8501c203 [dev.go2go] go/parser: change value of UseBrackets constant (fix API check)
Passes all.bash again.

Change-Id: Ie558957b380cef937761faea69458980407bc8db
Reviewed-on: https://go-review.googlesource.com/c/go/+/244619
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:19:31 +00:00
Robert Griesemer
c7314f27b3 [dev.go2go] go/*: remove the need for ast.InstantiatedType
Instead, add the field "Brackets" to ast.CallExpr to identify
the bracket used for the (type) parameters. Adjust dependencies.

Change-Id: I6a73b0517ac518d8055e7fadbfb8662dfff585c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/244618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-23 21:19:13 +00:00
Robert Griesemer
bed4b05106 [dev.go2go] go/types: implement constraint type inference for functions
1) Implement full bidirectional unification for general use.
2) Implement constraint type inference using bidirectional unification.
3) Add flag Config.InferFromConstraints to enable constraint type
   inference (disabled by default).

If we don't have all type arguments (provided or inferred) for a
function call, constraint type inference attempts to infer them
from type parameter constraints that are "structural", i.e., whose
interfaces contain exactly one (non-interface) type in their type
lists. For instance, given

	[type P interface{}, Q interface{type []P}]

the constraint for Q requires that the (underlying) structure of
the type argument for Q must match the underlying type of the type
argument provided for P. If only a type argument for P is given, say
say int, we can infer a type argument for Q, which would be []int.

Change-Id: I8508412ad96a0969d2033e99510c56db0f78177e
Reviewed-on: https://go-review.googlesource.com/c/go/+/244061
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 06:04:12 +00:00
Robert Griesemer
1576a3d981 [dev.go2go] go/parser: recognize f[a, b] as a (potential) function expression (parser bug)
Change-Id: I6b631a0d7efedfedd6c67640c8cbbff81f9e3af8
Reviewed-on: https://go-review.googlesource.com/c/go/+/244457
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-22 23:57:39 +00:00
Rebecca Stambler
f41e3f6173 [dev.go2go] go/ast: add *ast.InstantiatedType case to go/ast.Walk
This is necessary for continued support for the prototype in gopls.

Fixes golang/go#40316

Change-Id: Iafab2e78cfdfd7415d2e2419b8ed1abe6e6216c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/243717
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2020-07-20 22:53:49 +00:00
Ian Lance Taylor
893c5ec17b [dev.go2go] cmd/go2go: rewrite tests to use square bracket syntax
We can roll back this CL if we go back to parentheses.

Change-Id: Ide85330f4c362dad6ae964c6cc1fd0fc6c8a6a60
Reviewed-on: https://go-review.googlesource.com/c/go/+/243162
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:30:46 +00:00
Ian Lance Taylor
486b592393 [dev.go2go] cmd/go2go: add -brackets option
Change-Id: I5c3d36df3d84ad85d2fb70152f5692223cf6cfb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/243161
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:28:54 +00:00
Ian Lance Taylor
78c55f923e [dev.go2go] go/go2go: permit caller to require square brackets
Change-Id: Idcb18ea31edee61931aa253f5f4d95923f6bcf6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/243160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 21:24:39 +00:00
Ian Lance Taylor
ca218546b8 [dev.go2go] test: rewrite generic tests to square bracket syntax
We can roll back this CL if we go back to parentheses.

Change-Id: Ideb7dbe8e3c4499d76518a5c9b6f7931a7c103a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/243158
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:18:10 +00:00
Ian Lance Taylor
6f583c9a5a [dev.go2go] go/go2go: support square bracket generics syntax
Change-Id: If683ad350aaddebcb3ebb691e1235c24c5dc2fe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/243157
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:16:37 +00:00
Robert Griesemer
e8f7e323f3 [dev.go2go] go/parser: UseBrackets mode forces parser to use [] for generics
Not setting the UseBracket mode still permits the parser to switch
to using brackets depending on the first generic type or function
declaration.

Change-Id: I2ee1235cfe58108ce1f5fd4a7fa1ce81f9e0ec0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/242904
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-16 20:02:53 +00:00
Robert Griesemer
a1922594db [dev.go2go] go/parser, go/types: allow both type and func decls to select [] for type params
The first generic type or function declaration encountered in a file chosing
square brackets switches the parser to use square brackets for the remainder of
the file.

Removed the need for extra type declarations in tests solely to switch to [].

Change-Id: Ia8d0c16e69b7e9b0e5397fed7405c5c4afc66451
Reviewed-on: https://go-review.googlesource.com/c/go/+/242899
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-16 00:33:55 +00:00
Robert Griesemer
ee1823718a [dev.go2go] go/parser: optional "type" keyword for generic functions using [] (experiment)
Change-Id: Ib7ebcd97f970e3be09626ee3d58d110e531aecd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/242897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 23:08:25 +00:00
Robert Griesemer
42aea19e55 [dev.go2go] go/printer: initial support for []-enclosed type parameters
Also: Don't strip parentheses around unnamed generic parameter
types when () are used for type instantiations (was bug).

Change-Id: I74edde2be2a01d740d2275e5d8768a5c25fa3302
Reviewed-on: https://go-review.googlesource.com/c/go/+/242717
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-15 05:33:40 +00:00
Robert Griesemer
7e7a795836 [dev.go2go] go/types: adjustments to accept [] or () for type parameters
For each testfile xxx.go2, added a corresponding file xxxB.go2
that is using [] instead of () for type parameters. Removed
extra ()'s that are not needed to disambiguate.

See also https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8

Change-Id: I3d64035b1ca2a22ae50c740ebf4ab8a8f6cab787
Reviewed-on: https://go-review.googlesource.com/c/go/+/242521
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 00:53:18 +00:00
Robert Griesemer
5bf3aa1e25 [dev.go2go] go/parser, go/ast: accept [] or () for type parameters
- The first type declaration using [] for type parameters
  switches the parser to using [] for type parameters and
  type instantiations. Otherwise it uses ().

- Type parameters are now always accepted with any function
  or method declaration. It is up to the consumer of the AST
  to reject them as necessary.

- Type parameters are now never accepted in the receiver
  or result parameter list.

- testdata/xxxB.go2 tests correspond to the testdata/xxx.go2
  tests but use [] instead of ().

- See also https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8

Change-Id: I21b14f9463f7f49deba83b64450a0723b4b1d171
Reviewed-on: https://go-review.googlesource.com/c/go/+/242520
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-15 00:52:51 +00:00
Robert Griesemer
9fe9a324c4 [dev.go2go] go/*: remove vestiges of contracts - they are not coming back
Change-Id: If929860b51b86206d874b49ac00aaa8df09726e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/241657
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-09 00:23:26 +00:00
Ian Lance Taylor
9d9619adc8 [dev.go2go] go/go2go: pass full path when importing Go 1 package
No test case because there is still no test harness for a complex
package heirarchy.

Fixes #40063

Change-Id: Iebe627dd7b2a3e967d437bee61c9d15c7a159fc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/241217
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-07 03:47:15 +00:00
Robert Griesemer
4545287c1b [dev.go2go] go/types: don't panic if receiver type arguments cannot be inferred
This can happen due to earlier errors. This change avoids the panic
but reports a follow-up error. Not ideal, but good enough for now.

Fixes #40056.

Change-Id: I500d4fc2b058cdc70f28883ff8d004df4b43fe4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/241130
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-07 03:13:21 +00:00
Robert Griesemer
17564d8957 [dev.go2go] go/types: do not permit generic types in type switch type lists
Fixes #40057.

Change-Id: Ia1a99378614fda1d0cb3d6b9cf53bbf790fc2953
Reviewed-on: https://go-review.googlesource.com/c/go/+/241126
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-07 00:22:28 +00:00
Ian Lance Taylor
cfb6cac804 [dev.go2go] go/go2go: handle embedded pointers to instantiated types
Change-Id: I47d23dd4a44c644e9ec2f1abbc3cd8cec4a35d04
Reviewed-on: https://go-review.googlesource.com/c/go/+/241125
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-06 23:38:47 +00:00
Ian Lance Taylor
b97f992a7e [dev.go2go] go/go2go: F(type)() is not a parameterized function
Fixes #40015

Change-Id: I4e70398e693a53268d3400e829a179c76ff70e75
Reviewed-on: https://go-review.googlesource.com/c/go/+/241124
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-06 23:18:11 +00:00
Robert Griesemer
c583a5d512 [dev.go2go] go/types: add test for crash 15 from issue 39634
This test case doesn't crash anymore.

Updates #39634.

Change-Id: I29b13762265ef1c16c0298d141fdb6cf2c01f4ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/241123
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 22:08:08 +00:00
Robert Griesemer
a599706090 [dev.go2go] go/types: don't crash instantiating defined types that are not fully set up
Addresses crash #16 of #39634.

Updates #39634.

Change-Id: I33063d6e2176586f097d2d1391f490f1775a2202
Reviewed-on: https://go-review.googlesource.com/c/go/+/241122
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 22:00:41 +00:00
Robert Griesemer
005397e36d [dev.go2go] go/types: don't crash instantiating arrays/slices that are not fully set up
Addresses crash #18 of #39634.

Updates #39634.

Change-Id: I4b1a3d81ce9dc2b59ae9af3146d26f79d8c05973
Reviewed-on: https://go-review.googlesource.com/c/go/+/240904
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-06 21:54:48 +00:00
Pavlo Bashynskyi
0e1fc80d04 [dev.go2go] cmd/go2go: correct URL in README
Change-Id: I947c0181512b7d5dd4219cec92262bd1f443b957
GitHub-Last-Rev: 44ec636b89
GitHub-Pull-Request: golang/go#40054
Reviewed-on: https://go-review.googlesource.com/c/go/+/241039
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-05 19:48:30 +00:00
Robert Griesemer
34f76220c3 [dev.go2go] go/types: make sure arrays, slices always have an element type
Addresses crash #19 of #39634.

Updates #39634.

Change-Id: I42208511a3fc27432891243dcf4799e80432c2c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/240903
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-04 04:55:49 +00:00
Robert Griesemer
6e86f51c54 [dev.go2go] go/types: don't rely on completed interfaces in isParameterized predicate
Also, take type lists into account when computing predicate.
Addresses crash #27 of #39634.

Updates #39634.

Change-Id: Id6e1d0d86ac1cb9d79828a3b5fdfbeba0e6aace0
Reviewed-on: https://go-review.googlesource.com/c/go/+/240902
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-03 22:37:04 +00:00
Robert Griesemer
167909e5f5 [dev.go2go] go/types: don't modify Named.underlying when checking validity
Addresses crash #20 of #39634.
Added test, also for some of the other cases that don't crash
anymore.

Updates #39634.

Change-Id: I999e376985a443ac435f64a7c249f891e7b7a6d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/240901
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-03 22:20:59 +00:00
Ian Lance Taylor
4dde96e380 [dev.go2go] go/go2go: resolve pointers in sameType
Fixes #39982

Change-Id: Ieb33381716662b44464104e0073a52ab5c19b7c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/240899
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-03 19:26:32 +00:00
Robert Griesemer
85ed317eb2 [dev.go2go] go/types: fix computation of type hash
Fixes #39982.

Change-Id: I4e7b52c34bf8df63f2063dc2504a8125ca7585a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/240737
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-02 00:33:43 +00:00
Robert Griesemer
182889ccf5 [dev.go2go] go/types: better error message when converting to a constraint interface
Fixes #39699.

Change-Id: Ib2a756a275c0f96201800d947a72db49d3319a3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/240720
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 22:50:35 +00:00
Robert Griesemer
05f750de93 [dev.go2go] go/types: HasTypeList, IsComparable, IsConstraint predicates for interfaces
HasTypeList existed before but now is also written such that it doesn't
expect an interface to be complete.

Change-Id: I43e8d652c6be755473b201a64bf41d363214881c
Reviewed-on: https://go-review.googlesource.com/c/go/+/240719
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 22:50:26 +00:00
Robert Griesemer
d014fca6d4 [dev.go2go] go/types: fix assertion failure, better error message for inference failure
Fixes #39976.

Change-Id: Idc304a615193847337438e7024e43140472e7bae
Reviewed-on: https://go-review.googlesource.com/c/go/+/240718
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 20:30:10 +00:00
Robert Griesemer
6cf6bf162c [dev.go2go] go/types: report inferred type when a type argument doesn't match
Fixes #39725.

Change-Id: I48248283ae0eb635d489d8661512f32b98700c1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/240523
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-01 00:31:32 +00:00
Ian Lance Taylor
938e96e732 [dev.go2go] go/go2go: instantiate embedded field when needed
If an embedded field is an instantiated type, we need to instantiate
it when instantiating the whole type, in case the type arguments
themselves need instantiation.

Fixes #39953

Change-Id: I80b57456aa4f8e8b2eff82359066c37a9c2a40f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/240522
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-30 23:46:04 +00:00
Robert Griesemer
08b9fd164c [dev.go2go] go/types: better error message when confusing a type parameter with an interface
Fixes #39948.

Change-Id: I868d2264a674a92c39fbe31d89bc002dd74c26fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/240520
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-30 19:00:27 +00:00
Robert Griesemer
1e27b76ebd [dev.go2go] go/types: report "inifinite expansion" cycles across instantiated types
Fixes #39938.

Change-Id: I482b211189cefdc098df5acb4f858f6f1635ce60
Reviewed-on: https://go-review.googlesource.com/c/go/+/240519
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-30 17:48:56 +00:00
Robert Griesemer
236ad5a280 [dev.go2go] go/types: fix broken test case
While at it, simplified test case a bit.

Fixes #39935.
Updates #39754.

Change-Id: Ia3b51f23807d25e62113757c51a660c7e3a9b381
Reviewed-on: https://go-review.googlesource.com/c/go/+/240478
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-30 03:51:21 +00:00
tdakkota
71c7be55eb [dev.go2go] go/types: fix type check skipping for constraints when th…
…ere’s more than one generic constraint.

Check of first constraint was breaking the loop, so other constraints was skipped

Fixes #39754.

Change-Id: I48caa380472371a438c2d2029d1383d03dbf22df
GitHub-Last-Rev: bf418db782
GitHub-Pull-Request: golang/go#39902
Reviewed-on: https://go-review.googlesource.com/c/go/+/240339
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-29 16:07:10 +00:00
Ian Lance Taylor
10ea225e28 [dev.go2go] go/go2go: translate types to AST
We were relying on calling typeString and treating that as an AST ident,
with special handling for instantiated types, but that fails if there is
an instantiated type within a type literal.

Fixes #39881

Change-Id: I793fe359868d8d73e830aa8dc67cf52de99355a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240197
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-26 22:32:53 +00:00
Ian Lance Taylor
93014c51d1 [dev.go2go] go/go2go: avoid crashing on predeclared error type
It has no package, so we need to check for Pkg() == nil.

Fixes #39878

Change-Id: I14a47c5098f97ce42dfa8cc875819f244a2b0201
Reviewed-on: https://go-review.googlesource.com/c/go/+/240013
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-26 18:43:49 +00:00
Ian Lance Taylor
1b08acee45 [dev.go2go] go/go2go: don't add importable name to test file
No test case because we will don't have a general test harness.

Fixes #39851

Change-Id: If7b1262404f390eba80d53c2c1d40724252a5833
Reviewed-on: https://go-review.googlesource.com/c/go/+/240004
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-25 23:22:18 +00:00
Ian Lance Taylor
4dfbf5ab9c [dev.go2go] go/go2go: add package qualifier when needed
Fixes #39842

Change-Id: I5046f1bdd7dbc6d1e17cf3835826933aaadf1581
Reviewed-on: https://go-review.googlesource.com/c/go/+/239711
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-25 02:57:14 +00:00
Ian Lance Taylor
a9f31a8c68 [dev.go2go] cmd/go2go: doc: instantiations can't refer to unexported names
For #39840

Change-Id: Ifc2a95fbd50cbf785251d05042e554872e1e79cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/239709
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 23:56:06 +00:00
Ian Lance Taylor
acd7923802 [dev.go2go] go/go2go: add IDs for test files
No test because the test harness doesn't support test packages.
(But probably we'll need a better test harness.)

Fixes #39839

Change-Id: I4532b1443dbdd081552ffb78477cbe5039183416
Reviewed-on: https://go-review.googlesource.com/c/go/+/239708
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 23:41:00 +00:00
Ian Lance Taylor
2dce748bd8 [dev.go2go] go/go2go: if we have an import path, pass it to go/types
No test because it doesn't really fit into the current test harness.

FIxes #39797

Change-Id: I410217a0e6b3af6808a111d0edbafaa3047b12f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/239707
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 22:35:01 +00:00
Ian Lance Taylor
f04e0ee126 [dev.go2go] go/go2go: include package in instantation of ident
If an instantiated function from a different package uses a plain
identifier to instantiate a generic type or function, include the
package name in the generated identifier.

Fixes #39834

Change-Id: I4c786bac8972475e180cb41178520439343a36ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/239706
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 22:15:29 +00:00
Ian Lance Taylor
5b16464101 [dev.go2go] test: keep translated .go2 files if -k
Change-Id: I8f696c201c00d422b176a65ae72e384cc11e1efb
Reviewed-on: https://go-review.googlesource.com/c/go/+/239704
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:34:54 +00:00
Ian Lance Taylor
af16dac1b0 [dev.go2go] go/go2go: don't import both "./a" and "a"
For #39797

Change-Id: I4063a0138062ce8dc1f35cc7fef7c6773c939362
Reviewed-on: https://go-review.googlesource.com/c/go/+/239703
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:33:55 +00:00
Ian Lance Taylor
fa201df81e [dev.go2go] go/go2go: update name of embedded pointer to instantiation
Fixes #39774

Change-Id: Icb2948ae19e06a3766e7edb01ef40de50e7aca7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/239702
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:01:03 +00:00
DeedleFake
2dc2987ac8 cmd/go2go: standardize help flag with other tools
A very small change because the `--help` flag printing nothing was bugging me.

Change-Id: I221c657ba055e94db7a574c8e8fd044bb135f8b1
GitHub-Last-Rev: 8781a1a29f
GitHub-Pull-Request: golang/go#39788
Reviewed-on: https://go-review.googlesource.com/c/go/+/239537
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-23 23:41:16 +00:00
Ian Lance Taylor
e6e8041d02 [dev.go2go] go/go2go: resolve type alias of parameterized type
Fixes #39792

Change-Id: I9eab19a4f516be5a71e71f04b91c4e46b189fba9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239598
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-23 23:35:25 +00:00
Robert Griesemer
2faeebf4e5 [dev.go2go] go/types: permit alias to generic type
Fixes #39768.

Change-Id: I68c8fbec5adc50e448dabe90b212ef147a384a06
Reviewed-on: https://go-review.googlesource.com/c/go/+/239387
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-23 04:54:48 +00:00
Robert Griesemer
6ca930a00a [dev.go2go] go/types: add internal TODO for future simplification
Change-Id: I8e4e8eebf8c64962ccf5f0e225dd007f691c373a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239384
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-22 23:46:33 +00:00
Ian Lance Taylor
dfb538cec8 [dev.go2go] go/go2go: don't permit underscore as type argument
The go/types package doesn't give us an easy way to get the type,
so just reject it.

Fixes #39743

Change-Id: I5404c10baede0fd2cf67980b06fbebd214a50dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/239382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 23:30:28 +00:00
Ian Lance Taylor
404a12f056 [dev.go2go] go/go2go: use package name, not package path
types.TypeString defaults to using the package path for references to names.
Provide our own types.Qualifier that uses just the package name,
since that is what the translated code has to use.

Fixes #39744

Change-Id: Icde289b2ed0fdd9b0a9aae6aae4557a8951d25a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/239381
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 23:05:26 +00:00
Ian Lance Taylor
a367b7d270 [dev.go2go] go/go2go: check for instantiation with locally defined type
Fixes #39738

Change-Id: I1a3536484a982ec713019572ff7b3c0c36af9784
Reviewed-on: https://go-review.googlesource.com/c/go/+/239380
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 22:19:20 +00:00
Ian Lance Taylor
9b13ca00f8 [dev.go2go] go/go2go: ignore struct tags
Ignore struct tags when generating an instantiated names, and when
comparing types for identity.

Fixes #39737

Change-Id: I53e67fa1d09214dafc4088a59eb00e1a6f18ef3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239379
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 22:07:26 +00:00
Robert Griesemer
da7932368b [dev.go2go] go/types: implement a few more predicates for type list sums
Also: Don't convert an untyped nil to a type parameter when
checking if an untyped value (nil) can be coverted to a target
type.

Fixes #39755.

Change-Id: Ib2645759dc659b9c80c2d0a457180eb9616c7cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239338
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-22 19:06:44 +00:00
Ian Lance Taylor
e643c9792f [dev.go2go] go/go2go: avoid multiple identical instantiations
Move tracking of instantiations from translator to Importer,
so that we can track all instantiations within a package
to avoid duplicates.

Fixes #39749

Change-Id: If6cd5bcdc6e19c2d6481e62a6187ddf7f4fac72a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239337
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 18:38:41 +00:00
Ian Lance Taylor
6500ed4790 [dev.go2go] go/go2go: instantiate local type specs
Fixes #39741

Change-Id: I75e3b98afa5184b87d4a7bbf360761e5cc6c6217
Reviewed-on: https://go-review.googlesource.com/c/go/+/239297
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 17:38:38 +00:00
Robert Griesemer
0a030888da [dev.go2go] go/types: use the underlying type of type list entries
Type lists can contain defined types, make sure we use their
underlying types when computing operational types.

Change-Id: I8b6b11302f6b28977916e495f1486cc7b352e859
Reviewed-on: https://go-review.googlesource.com/c/go/+/239163
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 04:46:40 +00:00
Robert Griesemer
c0c872e8b0 [dev.go2go] go/types: the underlying type of a type parameter is itself
No need to call Under() when we know that we have a type parameter.

While at it: Turn off debug mode.

Change-Id: Ia0b39d88191c8e5ac580e7e84a512061911c40cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/239162
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:57:21 +00:00
Robert Griesemer
cbdb93d5a7 [dev.go2go] go/types: a type constraint must be an interface
In particular, it cannot be a type parameter
with an operational type that is an interface.

Fixes #39723.

Change-Id: Ia6b65eaecd472dd71b1c9f7631ce1872f06e5a6d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239161
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:49:15 +00:00
Ian Lance Taylor
815b29d859 [dev.go2go] go/go2go: get package name from package, not import path
No test because the test framework doesn't easily support
package paths containing a dot.

Fixes #39722

Change-Id: If43dc768b28f521d10bd2ef4288aa789aa4bee01
Reviewed-on: https://go-review.googlesource.com/c/go/+/239160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:45:10 +00:00
Robert Griesemer
7473c4383e [dev.go2go] go/types: check for duplicate types after interfaces were completed
Fixes #39711.

Change-Id: Id0efb854a42bd88a66be8165fa3444e33d1c8f8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239158
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 00:41:07 +00:00
Ian Lance Taylor
ccaf3f5560 [dev.go2go] go/go2go: don't crash on an unnamed receiver
Fixes #39707

Change-Id: I20e5fe2990ceda5429f1a22edf48494d2c6496a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/239159
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:36:20 +00:00
Ian Lance Taylor
cab5f803e8 [dev.go2go] go/go2go: don't drop type arguments in instantiateType
It's not correct to do it here, as we aren't instantiating this
particular type.

Also had a loop check to avoid endless instantiating a recursive type.

Fixes #39688

Change-Id: Ief4c57bb5cea3013501e33ab5bc82a29707af5be
Reviewed-on: https://go-review.googlesource.com/c/go/+/239137
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:01:12 +00:00
Robert Griesemer
6cf535a27b [dev.go2go] go/types: avoid endless recursion when computing operational types
The operational type for a type parameter T constrained by
interface { type T } is the top type, not itself. The latter
can lead to infinite recursions.

Fix suggested by @tdakkota.

Fixes #39680.

Change-Id: I8a6a6c503f09294b9276965f1d9e05c5d22ec912
Reviewed-on: https://go-review.googlesource.com/c/go/+/238863
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 04:37:09 +00:00
Robert Griesemer
b302b5f775 [dev.go2go] go/types: don't panic if an embedded type is not an interface
Fixes #39693.

Change-Id: I7f2a4dd95edac3365a9b41b66afcd0015b5b836c
Reviewed-on: https://go-review.googlesource.com/c/go/+/238858
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 00:09:12 +00:00
Ian Lance Taylor
657803033f [dev.go2go] go/go2go: handle fields promoted through embedded type parameter
Fixes #39678

Change-Id: Ib74d15795ab85ad0b1e58096302a9a88810242c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/238857
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 23:28:46 +00:00
Ian Lance Taylor
20dbf4d49d [dev.go2go] go/go2go: add imports for packages referenced by inferred types
Fixes #39625

Change-Id: Iebae2afbb42092e14c91c52d2046bc287d423844
Reviewed-on: https://go-review.googlesource.com/c/go/+/238817
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 22:00:57 +00:00
Ian Lance Taylor
4af4810e15 [dev.go2go] go/go2go: add type arguments to type instantiation
Previously we instantiated the underlying type, so we didn't need this.
We stopped doing that to get the same type in the generated code,
but now we need to get the right type arguments, rather than just
leaving the type parameters there.

Fixes #39692

Change-Id: I56ba8ff017c37219e7cb9bb6e07a4beb8c50e9dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/238797
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 21:36:57 +00:00
Ian Lance Taylor
7a16d6c119 [dev.go2go] go/go2go: don't crash on functions/methods with no body
Fixes #39672

Change-Id: Ia9fa4e7d5090200d7c2b4f654ac7ee42d7d79732
Reviewed-on: https://go-review.googlesource.com/c/go/+/238761
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 20:51:39 +00:00
Robert Griesemer
5e754162cd [dev.go2go] go/types: fix unification issue when looking up generic methods
If enabled in types.Config, the type checker can handle generic
methods (methods that have their own type parameter list).
This CL fixes an issue with method lookup (missing method test)
that caused some assignments to fail.

Note that this does not affect the go2go tool - we don't have any
plans to support such generic methods. Type-checking them is
fairly straight-forward. Translating them into code is not.

Change-Id: I8b8a6b814417277c728732bd5a9421c99440a47a
Reviewed-on: https://go-review.googlesource.com/c/go/+/238627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 05:58:40 +00:00
Robert Griesemer
2c4c09e4ff [dev.go2go] go/types: don't crash when receiver type doesn't declare type parameters
Fixes #39664.

Change-Id: I0cf585f0c704bdaa163a7ebc9e7c82a734fcd5e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238625
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 00:39:33 +00:00
Ian Lance Taylor
57cec2f259 [dev.go2go] go/go2go: accept slash in an instantiated type name
It shows up when instantiating with types with a package path
containing a slash, as in net/url.Error.

Fixes #39642

Change-Id: Icf40e7bcdf1de7c84f58ebde35ebffadbb071d72
Reviewed-on: https://go-review.googlesource.com/c/go/+/238623
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:45:00 +00:00
Ian Lance Taylor
e531e11b9a [dev.go2go] go/go2go: return quickly from typeWithoutArgs if no args
Avoids crashing when we see a universe scope type in an instantiated type.

Change-Id: Iec3ebee291973180a63cd4cddef7e2f131a30053
Reviewed-on: https://go-review.googlesource.com/c/go/+/238622
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:34:10 +00:00
Ian Lance Taylor
9840dbbef8 [dev.go2go] go/go2go: instantiate embedded type parameters
Turn an embedded type parameter into a regular field with the type
parameter as the name and the type argument as the type.

Fixes #39671

Change-Id: I0050499b90feb5085cac4452d53fa0dc6f614c48
Reviewed-on: https://go-review.googlesource.com/c/go/+/238621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 23:21:31 +00:00
Ahmed W
3f40f78cab README.go2go: add a note about GO2PATH
Adds a little note about `GO2PATH` and that it is required for the `go2go` tool.

Updates #39617

Change-Id: I9e3cea16a7d7539555180dc065957d6a56f390b9
GitHub-Last-Rev: 2aa6815df7
GitHub-Pull-Request: golang/go#39657
Reviewed-on: https://go-review.googlesource.com/c/go/+/238498
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:48:43 +00:00
Ian Lance Taylor
4287a49936 [dev.go2go] cmd/go2go: document that function-local parameterized types don't work
For #39643

Change-Id: Ic3d3e4a4bd46c62705d3ce3473e3e06e1380d834
Reviewed-on: https://go-review.googlesource.com/c/go/+/238620
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:05:55 +00:00
Ian Lance Taylor
143b944192 [dev.go2go] go/go2go: error, not panic, for local parameterized type
Fixes #39643

Change-Id: I45aaaf8818d4d383d1514891b5cc9bc68926ad97
Reviewed-on: https://go-review.googlesource.com/c/go/+/238619
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:03:14 +00:00
Ian Lance Taylor
e0d5d9f770 [dev.go2go] go/go2go: make uses of typeInstantiations consistent
Fixes #39653

Change-Id: I98fd1bd4f0deccb5b4c2ed0d67d508c7f0117839
Reviewed-on: https://go-review.googlesource.com/c/go/+/238618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 21:53:37 +00:00
Ian Lance Taylor
3a25e98917 [dev.go2go] go/go2go: parenthesize type strings
Fixes #39662

Change-Id: Id176ec00474d66a24e95f2db092f3b4245a93cfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/238557
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 19:42:47 +00:00
Ian Lance Taylor
5f01333bf1 [dev.go2go] go/go2go: check for embedded interface with type list
Add an accessor to go/types: HasTypeList for an interface type.

Fixes #39626

Change-Id: I880eabbe6660739cd7febc1df89eaa7f9262c8c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/238360
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 04:20:54 +00:00
Robert Griesemer
0b89d8b52a [dev.go2go] go/types: use correct predicate when checking binary addition
See also https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562
for the analogous problem for another predicate.

Fixes #39623.

Change-Id: I39efcb07c337691eb202de166e2cb8d6b5d5ee18
Reviewed-on: https://go-review.googlesource.com/c/go/+/238359
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-17 03:59:45 +00:00
Ian Lance Taylor
1bcef8724f [dev.go2go] go/go2go: catch more embedded comparable cases
Check for comparable embedded via a different embedded interface.
Check for comparable embedded in a defined interface type.

Change-Id: I8c9c576ad31443dcb77b4be71e29ab2284339cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238357
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 03:29:48 +00:00
Robert Griesemer
c2b328710b [dev.go2go] go/types: prevent comparable interface from being used outside constraints
It was already not possible to implement an interface that was or
embedded the predeclared interface "comparable" in ordinary (non-
constraint) use, but trying to do so would lead to confusing errors
(missing method "==").

Simply disallow the use of such interfaces outside constraints,
as we do for interfaces containing type lists.

Change-Id: I15ccf1b77226a50baf16df46192e90144208f9dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/238300
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-17 02:11:25 +00:00
Ian Lance Taylor
4ba19b0188 [dev.go2go] go/go2go: if an interface embeds comparable, treat it as parameterized
Change-Id: If61c88ae115bc14ae306653e78e3241380ab936a
Reviewed-on: https://go-review.googlesource.com/c/go/+/238301
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 00:44:16 +00:00
Ian Lance Taylor
56a37ac5a4 [dev.go2go] go/go2go: make defaultImporter a field of Importer
It turns out that defaultImporter has modifiable fields, so making it a
package scope variable can cause confusion in the use by test/run.go.

Change-Id: I33b060f2ffd17639312e7aa15a632268a3c14ab1
Reviewed-on: https://go-review.googlesource.com/c/go/+/238299
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 00:36:21 +00:00
Robert Griesemer
45038b7bca [dev.go2go] README.go2go.md: fix typo
Change-Id: Iee71ea7af488a717986d2e5994f16fdeaf8f3dda
Reviewed-on: https://go-review.googlesource.com/c/go/+/238297
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-16 23:13:12 +00:00
Robert Griesemer
ad307489d4 go/types: always use the underlying type of type list entries for operations
Passes all.bash.

Change-Id: Ie31cba04b7147fb1468f90d26450034223745a57
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771577
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-16 05:49:35 +00:00
Robert Griesemer
84cbe4f953 go/types: allow any type in a type list
Since we have to recompute the underlying type of each type in a
type list after instantiation (if any), there is no need to restrict
the types in the type list anymore.

Per the adjustment in the design draft.

Change-Id: I51ced90788e06ed4a9dbd34566e3baca7f3afe20
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771574
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-16 03:41:38 +00:00
Ian Lance Taylor
197db4cd00 go/go2go: use types.RelativeTo rather than doing it by hand
Change-Id: I0891f034ef71311df007bb9aa527132d5b45c672
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771559
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-15 20:51:13 +00:00
Ian Lance Taylor
feeeea1cda README.go2go: add README for branch
Change-Id: I92d9feb0c382a160afbff2428d92487e2275e09f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771427
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-15 20:07:34 +00:00
Robert Griesemer
221a28e338 go/types: always compare against underlying types in type lists
The underlying type of each type list entry must be computed
(again) _after_ the interface was instantiated because its
original typelist may have contained type parameters that were
substituted with defined types.

Passes all.bash.

Change-Id: I65a234fe6b9bc7b36121532410a0ecc29061516e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770445
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-14 06:40:04 +00:00
Robert Griesemer
8d612e39fe go/types: fix a couple of trace output problems (when -v is set)
- fix endless recursion when caused by trace output for self-referential generic types
- print pointer designation of type parameters in type parameter lists

Change-Id: I02d985187ee5e42fdaece2e7420824de8c90a906
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770152
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer
795f776602 go/types: stronger type inference across defined types
If a defined type is passed as an argument for a paramater
of a composite generic but unnamed type (and vice versa),
use the defined type's underlying type for type inference
rather than fail.

Passes all.bash.

Change-Id: I90b33b549c1d0e7569c1520b0f8e45a67152df43
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/770149
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
e7b04c5e2d go/go2go: add check for looping while rewriting
Change-Id: I2dacc606e9aecf8616eff2e9ab9fc09af69b7767
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769752
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer
bbdb05760f go/types: a type parameter acts like a named type; fix predicate and test
Change-Id: Ibe9f074d516200b9b12c26a270e62defc024eeac
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769347
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
bc77b007e5 go/go2go: compare arguments of instantiated types
types.Identical will report that two instantiated types are different
even if they are instantiated with the same type arguments.
Change our comparison so that we treat them as the same.

This lets us drop fully resolving all types, which is good because
that wasn't correct anyhow.

Change-Id: Ibcf2dc08896ecacb11ca302627e5d0c6f0722da7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769080
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer
cf52fda189 go/types: update README
Change-Id: If0031161b0c651d9196ebb7e565dfb8b8c7e664f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768852
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
94ebaa9b4f go/go2go: support instantiating functions with directed channels
Change-Id: I5c7cf605862bc4d34e0eb2b72870c68014d2f58a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768851
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
09a02162ee test: add a couple of pointer method test cases
Change-Id: If91c8a61fcda93eeb5affe51ef8f537736a28bce
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/768839
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Robert Griesemer
d65e7b7b0f go/types: take pointer designation of type parameters into account
There are still a couple of issues with pointer type parameters
that have constraints containing type lists, but at least as far
as method constraints are concerned the code is now matching the
design.

Passes all.bash.

Change-Id: I7b7ad9e03bc6ed159dca2343d3fa6a04fc188659
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765805
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
730419578e go/go2go: handle references to embedded instantiated types
Change-Id: I4f54a7820483e6b79169d319301943063a26ac53
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767868
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:54 -07:00
Ian Lance Taylor
a685620169 test: catch go2go panics in test runner
Change-Id: Ie59118941f732fc9111e77dcf8422d1e1afcd563
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767865
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor
3df5cb5c52 go/go2go: improve handling of self-referential types
Also, resolve types when looking up instantiations.

Change-Id: I8b2e976d9c0d313fe3c1dd9dafce41dcb59b33bf
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/767864
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor
73c4e1f380 test: add AbsDifference test case from design draft
Change-Id: I184ca0949200064947a3c974f8aa9c3738d93e33
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765523
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
7307dda747 go/types: report error if type list contains duplicate entries
Passes all.bash.

Change-Id: I9a795c931100af662c9c62223d4e4ca0103d2af3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765675
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
61c4506052 go/types: permit at most one type list in an interface (excluding embeddings)
Change-Id: Ib5f658341a746d4ac04852b558864bdb1ae3292f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765552
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor
44579f1e8e cmd/go2go: lock map in metrics Count methods
Change-Id: I4a5e74a3b13ce5ac29f6fedc6d6a6da1dabcc33b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/765662
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
468a8d7345 go/types: remove support for contracts
Also: Some additions/corrections to the NOTES file.

Passes all.bash.

Change-Id: I580c7f6f9769b8108e6d8e5a3473b92362eb246d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764658
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
3ec98e186b go/types: implement intersection for embedded type lists
Implement intersection of (sum) type lists so we can correctly
compute a type bound's type list if a type bound embeds other
type bounds (interfaces).

For type bounds A, B we want to preserve the property

   "A embeds B" implies "A satisfies B"

Because type bounds are interfaces this is already true when
considering method sets only. But type bounds also may contain
type lists, and for this property to be true, type lists must
be intersected.

The intersection of two non-empty type lists with different types
may be the empty list (nil), which means that no type satisfies
the type bound. Because we already use nil to indicate the absence
of a type list (i.e., ignoring methods, any type satisfies the type
bound) we need a separate representation. This CL introduces two
new internal types, bottom and top, which stand for "no type" and
"any type" (they represent the bottom and top of the type lattice).
Since nil is already used for what should be the top type, and we
rely on the fact that the zero value for an Interface type is a
valid empty interface, we keep using nil in type lists to indicate
the top type. Eventually we may want to clean this up.

This CL also refines the understanding of type parameters: The
underlying type of a type parameter must be itself (it cannot be
defined by the associated type bound as assumed in a prior CL).
Consider the declaration

	type T(type P) P

which declares a new defined, generic type. The question is, what
is the underlying type of T, i.e., the type which T represents
with a (new) name? (This type is stored in the underlying field
of a Named type.) The only possible answer is P, because otherwise
instantiation of T with any other type Q wouldn't produce that type
Q.

Thus, when checking if an operation is applicable on a value of type
parameter type, we need to explicitly get the type parameter's
"operational type" which is defined by the type parameter's type
bound; specifically the type bounds's type list (which is represented
as a sum type).

Passes all.bash.

Change-Id: Iad7e99884fd8f40a70f75c6470f1817d74994f48
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764158
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
690131b027 go/types: add Config flag to enable method type parameters
The type-checker type-checks method type parameters like
function type parameters without any extra work. But the
current design draft does not permit them and the go2go
translator does not expect them.

Add a flag to enable them for type checker tests, but do
not accept them by default. Instead, type-check but report
an error.

Passes all.bash.

Change-Id: Iec02f4a951a3faccd2409d97d48bc4dd4536a750
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764012
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
d3a2e0e245 go/types: disable type assertions on variables of generic type
This matches the latest design draft. It's unclear what the
correct approach is here, and there is an easy work-around:
just assign to an interface variable first.

Passes all.bash.

Change-Id: Ic1d6ed3de6333505e2044a318ea05fb984b408cf
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/764001
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor
35eefe6b79 test/gen: add some FromStrings test cases
These are from the latest version of the design draft.

There are still a couple of FromStrings test cases that don't yet work.

Change-Id: I057875820d8250012c06faeabda4637f0585b6f8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763941
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Ian Lance Taylor
a6b6ca6dc9 cmd/go2go: use consistent spacing in package doc
Change-Id: Ic3b03820ebfb6c4b0881b18663f46b64227ea93d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763940
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
1bc39b26bf go/types: treat type bound type lists as underlying types of type parameters
If a type parameter's type bound contains a type list, we can view that as
the underlying type(s) of the type parameter. If there is no type list the
underlying type of a type parameter is itself.

This approach resolves several open issues and clarifies the relationship
between type bound type lists and the type parameters. It also provides a
sensible definition for the underlying type of a type parameter (it will
take some more experimentation to see if this view is holding up within
the axiomatic framework of generic Go).

To implement this new view, in this CL we introduce the (implementation-
internal) notion of a sum type. A sum type is a set of two or more
distinct types. With this, we can view an interface with a type list as
an interface that provides a _single_ underlying type, which may be a
sum type.

Defining the underlying type of a type parameter this way enables a lot
of so far failing tests to work. In other instances, we have to implement
type-checking for sum types and can ignore the connection with generic code.
This simplifies the implementation and leads to a better separation of
concerns.

As part of this change:

- Several test cases in testdata/todos.go2 now work as expected
  and move to testdata/issues.go2.

- Fix, clarify, and add various comments.

Passes all.bash.

Change-Id: I25a435b2ccd0c9f9fda5369bc998e52fe120ee0b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/762619
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
cdabf71580 cmd/compile/internal/types2: disallow interfaces with type constraints as variable types
Port of corresponding go/types change:
https://team-review.git.corp.google.com/c/golang/go2-dev/+/760779

Change-Id: Ibdb9b61bb99f34481e2e466b0d024fb14bf1add0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/760899
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
25675854ad go/types: disallow interfaces with type constraints as variable types
Passes all.bash.

Change-Id: I0e080e740f5a70f480859196e34b96d47f914755
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/760779
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
3650c7d512 cmd/compile/internal/types2: fix numeric conversions between type parameter types
This is a simple port of the corresponding go/types change in
https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562.

Also: Added missing newline at end of go/types/testdata/issues.go2.
Change-Id: I8301488d46fa046c0a1f52b47d889864ee094f87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759563
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:53 -07:00
Robert Griesemer
0fa4f81317 go/types: fix numeric conversions between type parameter types
The implementation of conversions T(x) between integers and floating-point
numbers checks that both T and x have either integer or floating-point
type. When the type of T or x is a type parameter, the respective simple
predicate disjunction in the implementation was wrong because if a type list
contains both an integer and a floating-point type, the type parameter is
neither an integer or a floating-point number.

Change-Id: I007aa956007ab1a0228e0ee2fca05804686b404c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
716d51681b go/{ast,parser,types}: remove support for "underlying" in type lists again
Match the latest generics design draft.

Passes all.bash.

Change-Id: I81880a40e3532cd4e28b753472379e3dfed2f362
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/759561
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
fd86e2cab9 cmd/compile/internal/syntax: accept embedded instantiated types in interfaces
Add some smoke tests.

Passes all.bash.

Change-Id: I29ef9a0a8e8b18a6a3c5af151934d38622067857
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/756090
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
cb7d43b2ea cmd/compile/internal/syntax: actually collect type list types (fix bug)
The existing code collected empty fields. Collect the actual
field and added type string test.

(This was not found before because the generic tests are still
disabled in this port because of different position information.)

Change-Id: I959711892aac3c8f7587a4025c4b32f1598f5df3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/756088
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
8355f8a9ee cmd/compile/internal/{syntax, types2}: accept type parameter pointer designation
Accept but (for now) ignore the pointer designation.
This is a port of the relevant changes in go/types:

https://team-review.git.corp.google.com/c/golang/go2-dev/+/750582
https://team-review.git.corp.google.com/c/golang/go2-dev/+/751264

Passes all.bash.

Change-Id: I4767c3addc881691bebf22cb030fa578124b7db0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755797
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
380193353c cmd/compile/internal/types2: make "make" work for generic types
This is a port of the equivalent changes in go/types
(https://team-review.git.corp.google.com/c/golang/go2-dev/+/755783).

Change-Id: I2533a76ea1c5662c93bfd76125946151aa80f660
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755796
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
188ddaf79c go/types: make "make" work for generic types
Passes all.bash.

Change-Id: I524878e0299e12633c633540cc8f76deab81ce48
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755783
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Ian Lance Taylor
7116b1df5f cmd/go2go, go/go2go: use PathListSeparator
Don't assume that path lists use colon separators.

Fixes golang/go#39211

Change-Id: Ibce7295dcc290a7826ee6b25a06aa36b8e40f961
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/755784
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
8df9c7a8fa go/types: make type bound instantiation optional if bound has one type parameter
If a type bound expects one type parameter, permit omitting explicit
instantiation of the type bound in a type parameter list. In that case,
the type bound is instantiated with each respective type parameter
and becomes that type bound for that type parameter.

For example, given:

	type Bound(type T) interface { ... }

the type parameter list:

	(type P, Q Bound)

is syntactic sugar for:

	(type P Bound(P), Q Bound(Q))

This is a generalization of the former change:

https://team-review.git.corp.google.com/c/golang/go2-dev/+/728411

Passes all.bash.

Change-Id: I0191dcf3fbccf6e777f01dfa8ccef5aba0310213
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/751267
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
c64ef0ed90 go/types: recognize (but for now ignore) pointer and "underlying" designations
1) Recognize pointer designation in type parameter lists.
2) Recognize "underlying" type designation in interface type lists.

Adjust a few tests.

Passes all.bash.

Change-Id: Ic33195f2802698f957cbbda1770c78dc4d8a5e2a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/751264
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
1be59591cc go/parser: accept "underlying type" lists in interfaces
A type list may now be preceeded with "underlying" "type":

interface {
    // type list
    underlying type int, int32, int64

    // method
    underlying(int) int32
}

Change-Id: I37ea2ce3ca0e56f1fc35542ae04481dc7665b17c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750491
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
f59b75aff6 go/parser: accept "untyped type" lists in interfaces
A type list may now be preceeded with "untyped" "type":

interface {
	// type list
	untyped type int, int32, int64

	// method
	untyped(int) int32
}

Passes all.bash.

Change-Id: I745c5f05ab5d6013d585da278b27e1eb781c0762
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750483
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Robert Griesemer
774de94abe go/parser: accept pointer type parameter marking
Accept type parameters marked with a '*' as in:

(type A, *B bound)

indicating that the Bound requires pointer methods for B.
The notation is accepted but not yet recorded in the AST.

While at it, clean up some residue in parameter parsing
and disable acceptance of contract notation.

Passes all.bash.

Change-Id: I8d0c4614322bfed885ab26ef2da65a57208a9552
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750582
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:52 -07:00
Ian Lance Taylor
4b7067c133 cmd/go2go: rename testdata contracts to constraints
Change-Id: I52eaf2e87abc53b79b2fbcfcb156f093298341ef
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/750508
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:51 -07:00
Ian Lance Taylor
db04e7cb2e go/go2go, cmd/go2go, test: rewrite example code to not use contracts
Don't emit interfaces that are type bounds in the generated .go file.

Change-Id: I9b0fd2f6041e9464147ad6d82d349fe894ea762d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/735474
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
e83c4715b0 cmd/compile/internal/types2: apply latest go/types changes
After rebasing on top of master, the go/types version of
this branch includes the latest changes of go/types in
the std library. Apply the same changes to types2.

(Created a CL containing the differences between the starting
point for types2 (commit 89463ec, which was a copy of a
prior go/types) and the current go/types, and then cherry-
picked those differences on top of types2.)

Passes all.bash.

Change-Id: I6137a476dc90f5dbd0b90e9fbe144dc7bc13a9e3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/748099
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
75b401bccf cmd/compile/internal/types2: make go vet happy
Also, gofmt a few files.

Change-Id: Ie430556f5c1ae9c8acc24bbc5500a2579275fd39
2020-06-13 12:24:51 -07:00
Robert Griesemer
821d2a635c cmd/compile/internal/types: fix const/var decl handling and enable StdTest
Change-Id: Id06e34bcdfddf6bc0cd990b2eb3d0f1c6ccfdeb3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/747119
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
3f276cd882 cmd/compile/internal/types2: make all tests of TestTypesInfo run
Change-Id: I02069af89e86b2bd5bf3c84e8f8119d84be0aad9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746891
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
e37af78043 cmd/compile: fix Formats test
Change-Id: I0c5b7e330fb77b4d2b87e93a3af149f0b35ed9fa
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746630
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
5887a08520 cmd/compile/internal/gc: report error when compiling generic code
The compiler can parse but not actually compile generic code.

Change-Id: Icfaa61811bdcc80f59d656a25c26db40b6fd7877
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/746626
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
176a871ff3 cmd/compile/internal/types2: make tests depending on imports work
Passes most types2 tests, incl. type-checking of std library.
Passes all.bash.

Change-Id: I5d452ecb3decf1bdfee864c594e3f2a01525e548
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744664
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
c0558e3405 cmd/compile/internal/importer: make importer work with types2
Passes all its tests.

Change-Id: I0ba20a284f08e10531976b6253e3c340bbd84dcd
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744663
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
cdfaff44de cmd/compile/internal/importer: starting point for new importer
Make an exact copy of go/internal/gcimporter in
cmd/compile/internal/importer. Serves as starting
point for a types2-based importer.

Change-Id: Ib676794622bc1cb1614e396df6b391f374757cda
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744662
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
56162a1a5f cmd/compile/internal/types2: make type2 work with syntax package
Snapshot of work in progress.

- Entire package converted to use syntax package.
  (We still need to convert syntax.Operators to token.Tokens
  in some cases so we can use the go/constant package.)
- Some code is commented out and/or unimplemented.
- The functionality provided by eval.go, eval_test.go, gotype.go
  is not needed and was removed.
- Compiles cleanly and many tests run at this point.
- Skips tests that require import to work.

Passes all.bash.

Change-Id: I2f215d97c858c22058779a6a5b1a2065b51bd4af
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741794
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
73270217c8 cmd/compile/internal/types2: starting point for new type checker
Make an exact copy of go/types in cmd/compile/internal/types2.
Serves as starting point for a cmd/compile/internal/syntax-
based type checker, initially using the go/types logic.

Change-Id: Ide782fdaefd591b7757e54be5c16421bb8e935b2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741793
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:51 -07:00
Robert Griesemer
90f286c307 cmd/compile/internal/syntax: record type parameters (don't just parse them)
Also: Distribute type parameter names if necessary.
Change-Id: I59d83c29548b62f21a65b225ee3e743c95287adc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744598
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
5f8feb36c0 cmd/compile/internal/syntax: encode interface type lists more accurately
Encode an interface list element as a Field (like methods) but with
the special name "type" (no method can have that name as it is a
keyword). Types belonging to the same type list share the same name
pointer. This preserves full position information and removes the
need for another list in InterfaceType.

Change-Id: Ib7f02f7272078445546e47b394ed9e112dd5821f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/741894
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
d234c93a9b cmd/compile/internal/syntax: clear pragma at the right place (fix build)
The previous CL changed the parser.list implementation to not consume
the opening token anymore; this was changed so it could be used for
parsing type parameter lists which start with a "(" and a "type".

Consequently, parser.appendGroup was changed to consume the opening
"(" early, before parser.clearPragma was invoked. As a result, a
correctly placed pragma for the next declaration was consumed too
early, leading to an error with test/directive.go. Fixed.

Passes all.bash.

Change-Id: Ief2f71228697e5516ebdecb773fdc30438f1fa9f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/738661
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
70f1138c60 cmd/compile/internal/syntax: accept Go2 syntax
Specifically, this change accepts now:

1) Type parameters in type and function declarations, such as:

	type B(type T) interface {
		m(T) T
	}

	func f(type T B) (list []T) T

2) Type instantiations:

	type T B(int)

3) Embedded instantiated types, with necessary extra parentheses:

	type T struct {
		(B(int))	// ()'s to distinguish from field B of type (int)
	}

	type T interface {
		(B(int))	// ()'s to distinguish from method B with int argument
	}

The compiler simply ignores the new constructs.

Change-Id: Iecb8354d3846d7a5786cbe7d92870d8a2d578133
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/736539
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
bc3ba78503 go/types: implemented AcceptContracts flag to enable/disable contracts
AcceptContracts is a global flag (api.go) to enable/disable contracts.
All go/types tests pass with the flag in either setting, i.e., all
go/types tests involving contracts have been rewritten or disabled.
To ensure the existing go2go code runs, AcceptContracts is set to true
for now.

If contracts are disabled, "comparable" is a predeclared interface
(without type parameters) rather than a predeclared contract (with
one type parameter).

Change-Id: I2ddade9ae38d61d9edca6020f3334d2215b84f1d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/734984
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
4efa3ddb87 go/types: make type bound instantiation optional if there's only one type parameter
This simplifies the use of parameterized interfaces as type bounds.
For example, given:

	type Bound(type T) interface { ... }

we can use this interface as a type bound with or without instantiation
in a type parameter list:

	func _(type T Bound(T))	...  // with explicit instantiation
	func _(type T Bound) ...     // instantiation left away

In the latter example, Bound is syntactic sugar for Bound(T).

In general, in a type parameter list, instantiation of an interface
type bound is optional iff the the type bound applies to exactly one
type parameter and the type bound expects exactly one type argument.

Change-Id: I0e820a0e214427cce6397069c1d5268494096812
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/728411
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
7c99cab23e go/types: better error when accessing non-existent methods of type parameters
Track the contract or type name specifying a type bound
in the corresponding interface and use that information
for more specific error messages.

Change-Id: I8aa3458addd1e8446a3a5766a03fd50e338fc8ed
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/727599
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
e871c64307 go/types: updated README and NOTES
Change-Id: Id80b2a63ab7d358b5818730dfcc75f9e8b6e48a5
2020-06-13 12:24:50 -07:00
Robert Griesemer
4843595d7f go/types: implement specific converter methods for *instance types
This is fixing a known issue (see below) and many unknown issues:
An *instance type may legally represent any kind of type after
instantiation.

Given the declaration:

	type T(type P) P

T(int) is now a valid constant type, and T([]int) is a valid
slice type.

Also, fixed the implementation of isTyped/isUntyped which caused
types to expand prematurely.

Change-Id: Ic71c7252e3b066b0f97c2f1892cf20b2c4c2ef98
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723717
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
37801e2c49 go/types: don't forget *contractType in sanitation code (fix cmd/go2go test)
Change-Id: Ie736a1dba7aa73641d2869bc3a6c36c5400d6c09
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/724470
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
bfe0923cc7 go/types: sanitize Info.Defs/Uses and add tests
Change-Id: I4c7003a88009f142ca674c8ea6b138a444a2bac5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722935
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
975f454e6a go/types: report error for infinite generic types
To make this work for embedded fields, delay checking of
embedded field properties to the end of type checking to
avoid expanding possibly incomplete types.

Change-Id: I0ff7f86398deb05dcd4d0d5b5f94309d63db7a67
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723398
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Ian Lance Taylor
c2d160bafc cmd/go2go: add List example
Change-Id: Id12b3489c2cd17f48d918563b002fe704db6a177
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723255
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
4ba2f1d5fd go/types: fix type substitution
When instantiating a type, cache a new version with a valid (non-nil)
underlying type so that we don't run into a missing underlying type
if instantiation is self-recursive.

Added more tests, also for issues found while debugging.

Change-Id: I520a4f71e60bd9020977276db078582d41a677f1
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/723252
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:50 -07:00
Robert Griesemer
4b95e48766 api: update except.txt to accomodate for bigger types.Type
Fixing API check to make it pass. Adding the extra methods
to types.Type is not backward-compatible, but this is a
prototype, so we don't care too much for now.

Passes all.bash.

Change-Id: I7d1ab5d4eb2d69d10302e2aed2718b4a03ab36cc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722390
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
67da60ed50 go/types: sanitize types.Info maps
Don't export Instance anymore (renamed to instance).

Added sanitizer that expands any *instance type
into an instantiated *Named type as a last pass
of a type checker run.

Note: For now only the Info.Types and Info.Inferred map
      entries are sanitized to make go2go tests pass.

Passes all.bash except for api check.

Change-Id: I2a937b0e7e94c597dfd58af23c314cd20b3f7776
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/722383
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
6300d5adf9 go/types: instantiate generic types lazily
Until now, a generic type instantiation T(P1, P2, ...) was evaluated
eagerly, that is the formal type parameters of T were substituted with
the actual type arguments P1, P2, ... upon encountering that expression.
This caused problems when the type being instantiated wasn't fully set
up yet (i.e., it's declaration wasn't completely processed yet).

With this CL, a type expression of the form T(P1, P2, ...) is
represented via the new "syntactic" Instance type. The instantiation
is not checked eagerly, and no substitution takes place. Only when
needed, is an Instance type "expanded"; this is typically necessary
when operations on the instantiated type need to be performed. The
new exported function Expand(Type) Type takes a type and expands it
(i.e., instantiates it) if the argument was an Instance type. The
type string of an Instance type is prefixed with a '#' as in #T(int),
to distinguish it from the type string of the expanded type T(int).

Operations on types usually require the underlying type, and thus a
new method Type.Under returns the fully expanded underlying type of
a type (incl. following of forwarding chains). Type.Underlying remains
unchanged for backward-compatibility and use by clients expecting the
old behavior.

This CL is also a first step towards more lazy evaluation and checking
of properties that are better deferred to the end, when all types are
fully set up. For instance, when collecting embedded interfaces, we
now just collect the types (they may be Instances of generic interfaces)
and only expand and check if they are indeed interfaces when interfaces
are completed.

This new lazy approach should also permit the (future) introduction of
an Alias type to cleanly track alias types.

Passes go/types tests (but not all.bash).

Change-Id: Id5fb0e2fa497f506c2e938ca6a6606835c8a8b20
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/719901
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
63f4460f70 go/types: implement type conversion methods
Provide easy accessors to a type's underlying type. Instead of

	if t, _ := typ.Underlying().(*XXX); t != nil { ... }

we can now write

	if t := typ.XXX(); t != nil { ... }

where XXX is a type such as Basic, Array, Slice, Pointer, etc.
This removes a type assertion in all cases where typ is not a *Named
type and the code is easier to read.

Also, made Named.Underlying more robust by tracking cycles and nil
underlying types.

The Named.Underlying change is a first step towards making type
checking more lazy which eventually should permit dealing with
cycles that we cannot yet handle properly.

This change briefly breaks some external code (gcimporter, gccgoimporter)
due to the change in semantics of type.Underlying. This will be fixed by
the next change.

Passes go/types tests (but not all.bash).

Change-Id: I493a949e554da6f2a944e7e9b1f1f6f38f597042
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/717606
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
04f9e20db3 go/build: permit go/go2go to depend on internal/goroot
Change-Id: I22ee40f6ea529628bebc4e21ba2ae7789f3f6b60
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/721561
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
39dc66f9c2 go/types: improve contract error messages
If a type or type parameter does not satisfy a contract because the
type or type constraint is not found in the list of type constraints,
change
    T does not satisfy C(T) (T type constraint int not found in interface{type ...})
to
    T does not satisfy C(T) (T type constraint int not found in [type ...])
Also, before this change, if the contract had any required methods,
those were also listed; now we just list the type constraints.

If a defined type does not satisfy a contract because the underlying
type is not found in the list of type constraints, change
    MyUint does not satisfy C(T) (MyUint not found in interface{type ...})
to
    MyUint does not satisfy C(T) (uint not found in [type ...])
That is, when describing the type that is not found, use the underlying type,
not the defined type.

Change-Id: I345836c44921e2e13e7f02041839b5eb4df75c45
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718718
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
7d185f0ba6 go/types: improve contract error messages
If a type parameter that has no type constraints is trying to satisfy
a contract that does have type constraints, change
    T does not satisfy C(T) (missing type int)
to
    T does not satisfy C(T) (T has no type constraints)

If a type parameter that has type constraints is trying to satisfy a
contract that has type constraints, but the parameter has type
constraints that the contract does not permit, change
    T does not satisfy C(T) (missing type int)
to
    T does not satisfy C(T) (T type constraint int not found in interface{type ...}

Change-Id: I3bd4f59b0544b382399d9b9d891a509ce62f56c3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718426
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
67b6f218e9 go/types: fix type bound check
A type argument with an empty type list bound never satisfies
a type parameter with a non-empty type list bound.

Change-Id: Ic4206f74fd4625b4207baa28bdb0de0fc669b37e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/717296
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Jonathan Amsterdam
7a57f4d76e slices: fix Equal contract
slices.Equal only requires comparable, not Ordered.

Change-Id: I0150f1370e478aaa33bbd8788a1f9c9d33b85e06
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716483
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
63d4750592 go/types: avoid crashes when printing/tracing invalid interfaces
Rewrite Interface.Empty to not be dependent on an interface being
complete. Be careful when printing invalid interfaces.

This fixes a couple of crashes when running tests with -v (trace)
mode enabled.

Change-Id: I4be416eac7e3fae83c08608ed74bf3987b2a7457
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716089
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
a89350ee85 go/types: interfaces are comparable (bug fix)
Also: Updated NOTES (unrelated).

Change-Id: I12ce0465e408920d4cd430ab529f346281f4ac64
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716118
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
2b5e8d70c0 go/go2go: parse Go1 packages using go/types
When a Go2 package imports a Go1 package, then if the Go1 package is
in the standard library use the default importer, but otherwise
parse the package ourselves by recursively calling go/types.
This supports a Go2 package importing a Go1 package that imports
a Go2 package.

Change-Id: I8906d8ea5b81e6239652c0e46de79b5c1b59cfcd
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716063
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
c2d8b59433 go/go2go: record types of instantiated AST types
Otherwise we don't know the type of an instantiated type in an
instantiated function.

Change-Id: If7eb75dd920a3c9fc1b6992addcd3b91b6d425a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715718
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
760a3244a7 go/go2go: only copy .go2 files of import to tmpdir
We are only going to translate the .go2 files of an imported package,
so we don't need to copy anything else to the temporary directory.
This fixes the case of an imported package with a subdirectory,
which previously crashed trying to copy the directory.

Change-Id: I54cfb43ad2a3e23a4e0d7201d9e6e2ade02b7469
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715029
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
6df3320d36 test: drop a 0 from gen/err000n.go2
Matches the g cases.

Change-Id: If0c2558b9304cdd73e01d8718303e8fb0fccaf34
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/714999
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
5dac261e8b cmd/go2go: pass GO2PATH as GOPATH to regular go tool
Also when looking for packages specified on the command line,
search GO2PATH before trying to invoke "go list".

Change-Id: I9704ef86fa46b877ee195a40843a034d014c2a3d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/714998
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
dbe1a544f9 go/go2go: run "go install" for Go 1 packages
The default importer looks for installed packages, not sources.

Change-Id: I0c85460fa5792953e78288347fc637e0ee540b15
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/714780
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Ian Lance Taylor
39ba9cff56 cmd/go2go: add basic test for go2go build
Change-Id: I44109a4c0fe81d4c88e13200db1d2e6da576d262
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/714759
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:49 -07:00
Robert Griesemer
fd583fcbae go/types: update README
Change-Id: Ifc694498d0661c02907a1f39f2ea9f1535d8dbdf
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
061f93c871 test: add test for package name in error messages
Also add support for errorcheckdir in Go 2 tests.

Change-Id: Id69577050917d02ca98c91d6184318286d75ac2f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/712204
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
1d379da30b go/go2go: don't expect type arguments after instantiated name
Change-Id: I639adb020890e29b96458db5dffdea31bd1f8ffe
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/712186
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer
faf2cc0cb8 go/types: improve printing of type parameter lists
- leave type bounds away if empty (interface); don't write "any"
- boundle type parameters with the same type type bound
- simpler code for error message cleanup

Change-Id: I8c1b662479de185b2ebae47ed1d16482253dfe03
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710076
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer
f936401d53 go/types: use local and global type cache consistently (cleanup)
- store a *Named type in both caches
- update local cache also when we have a global cache hit

Change-Id: If4ab24a0c24d21f425a76dc51e4ec2ed495b26e4
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710128
Reviewed-by: Robert Griesemer <gri@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer
81022d54ae go/types: remove instantiated type name hacks
Instead of creating a new instantiated type name "name<T1, T2...>"
keep the regular name for the corresponding type object since
these newly created types are never declared. This eliminates
the need to clean up the names (remove the <>'s) before they can
be used.

When printing a named type, simply decide what to print depending
on whether it is instantiated or not.

When looking up an instantiated type, simply create the instantiated
type name string for use in the (local and global) type caches.

Change-Id: I4b20d09ec64d8deefccdd338ffb2f78fdfd2101e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710062
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Robert Griesemer
f25fd9bf57 go/types: remove an empty line (test for code review)
Change-Id: I5595aa5ea2ae808c60dde1566d35bad8ad7761c5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/709260
Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
be37919cd7 go/types: better error message for incomparable type
If a type does not satisfy comparable, don't report "missing method ==".

Change-Id: Idae2477e134f73db9ba5fb94302eec84fefe98ef
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
d3ecc7c57c cmd/go2go: mention some tool restrictions in the doc
Change-Id: I8568fffa6570610d909b0f23fa9bdd3ab6097a78
2020-06-13 12:24:48 -07:00
Robert Griesemer
ab835222b0 go/types: updated README (after rebasing on top of master)
Change-Id: I3d63346aa00b6de8a7ba725081affb155cc828f1
2020-06-13 12:24:48 -07:00
Robert Griesemer
ac135a4bcf go/types: better error messages for type inference
Change-Id: I8a5b07eca76b084901cce6f1bae4f8d107d10701
2020-06-13 12:24:48 -07:00
Robert Griesemer
1ad26bf1a7 go/types: fix some internal comments
Change-Id: I50f9127219321c3f173b28bf42b03e01384d920a
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
0c3eb6800e test: support errorcheck for .go2 files
Change-Id: I90f840c89d4437a8b9fbd4f08582b5cb0d2eec6d
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
fad64b3083 cmd/go2go: add pointer variant to graph package
Change-Id: Ib5cf28be42943ea816c64740f5698a5716d3dec1
2020-06-13 12:24:48 -07:00
Robert Griesemer
07382406ea go/types: fix satisfaction check of argument type against type bound
Per the draft design:

In a generic function body all method calls will be pointer method calls.
If necessary, the function body will insert temporary variables, not seen
by the user, in order to get an addressable variable to use to call the method.

When checking if a concrete type argument satisfies its type bound, assume
that concrete type is the type of an addressable value.

Change-Id: I9d40138755c38330448c010994b95a82f38e60e0
2020-06-13 12:24:48 -07:00
Robert Griesemer
6768c4f513 go/types: first cut at better error messages
- added Error.Full and Error.FullError which provide the full error
  message, possibly containing internal details
- Error.Msg and Error.Error provide a user-friendly error message

Change-Id: Id3044165331af71be31ef423cd2c9b8fe28accbd
2020-06-13 12:24:48 -07:00
Robert Griesemer
62683a7752 go/types: fix lookup of methods of pointers to type parameters
Since the type bound of a type parameter is an interface, no method
is found if the receiver is a pointer to a type parameter (pointers
to interfaces have no methods).

Ignore the indirection in this case.

Change-Id: Ie2af78b4cfb2f70b5d4f1d2afc631716a10ff7d9
2020-06-13 12:24:48 -07:00
Robert Griesemer
f81ad49939 go/types: report an error when seeing pointer designation in contracts
Pointer designations were not recognized nor supported.
Now we recognize them and report an error until type-checking
can handle them.

Change-Id: I0deed536aa03c06c3e9ec60a5c2e186e916b970f
2020-06-13 12:24:48 -07:00
Robert Griesemer
e03920500c go/printer: print pointer designation of type parameters in contracts
Also: Align start or methods and type lists.
Change-Id: Icae3be0ebcbc633d2ed88ff6f620dc078a7c698e
2020-06-13 12:24:48 -07:00
Robert Griesemer
49c8636998 go/parser: accept pointer designation for type parameters in contracts
Change-Id: Ib119b7cd22de7117db82b987a3cd4573cbb6f6c8
2020-06-13 12:24:48 -07:00
Ian Lance Taylor
29365a1738 cmd/go2go: rename graphs_test.go2 to graph_test.go2
Change-Id: I25cfedbf6c115db5545c0c12b96588a581e41a53
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
87059675da go/go2go: support instantiating with an inferred local type
Add a graph example.

Change-Id: Iec533487f2757b9fdc883e4a57715ad993e11254
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
5f4c825cf8 go/go2go: support imports that only defines funcs
That case was breaking when looking for a symbol to import to avoid an
unused package error.

Change-Id: I51ccacf36a95a16eac89071d5fa141608b759014
2020-06-13 12:24:47 -07:00
Robert Griesemer
a31f6ae875 go/*: change representation of type lists in interface types, adjusted dependent code
Until now, types of type lists in interface types were collected in
a single expression list "Types". This made it not possible to gofmt
such interfaces while preserving the original layout of type lists.

This change represents types of type lists as part of an ast.FieldList.
The ast.InterfaceType.Methods field list now represents embedded interfaces,
methods, or type list types through ast.Fields. This preserves all position
information and thus permits accurate gofmt-ing.

The new representation is as follows: For an ast.Field f, if
- len(f.Names) == 0        : f.Type is an embedded interface
- f.Names[0].Name == "type": f.Type is a type of a type list
- otherwise                : f represents a method

Since "type" is a keyword, a Go field name cannot be "type".
Fields of types of type lists that share the same "type" keyword
in the source share the same f.Names[0] identifier (named "type"),
and the position of that identifier is the position of the "type"
keyword in the source.

Related changes:
- Adjusted go/parser to build the new representation.
- Adjusted go/printer and implemented formatting of type lists.
  (This is still not quite correct if there are comments, but
  that is fine-tuning).
- Adjusted go/types to work with the new representation.
- Implemented SplitFieldList and MergeFieldList in go2go
  translator to easily switch between old and new representation.
- Updated documentation.

Change-Id: I016e2ce5949bfe294509d703156c41d42cf7084e
2020-06-13 12:24:47 -07:00
Robert Griesemer
e5e519e893 go/printer: cleanups around contract printing
- added more tests
- documented invariants and status quo

Change-Id: I74d75eee3936e659476fc5b428e8d11d5c5e4098
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
01ab391f82 go/go2go: support instantiating with an instantiated type
Add metrics test case to test GO2PATH.

Change-Id: I48c8a418d743ccd80cdcf36fc043ca0e2dd932f4
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
42884d7524 go/types: support setting the TArgs of a types.Named
Change-Id: I468b77165079ab30844e54b4988717be452cb648
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
10efd1cfc6 go/printer, go/ast: gofmt improvements for generic code
Change-Id: I62f7c0f52ac9d51eacd2392083e1aa7799022559
2020-06-13 12:24:47 -07:00
Robert Griesemer
e39082c80f go/types: remove vestiges of type unification in Checker.identical0
Type unification now happens through the new unifier code.
We can revert the functionality of Checker.identical back
to its original purpose of type comparison. This change
should make identity comparison faster again.

Change-Id: I844515b5f20a890152a0a5436f04c553b3b722e5
2020-06-13 12:24:47 -07:00
Robert Griesemer
5da07bf767 go/types: implemented (bidirectional) unifier and use it for type inference
- Implemented bidirectional unifier as a stand-alone mechanism
  separate from Checker.identical0.
- Use it instead of Checker.identical0 where we need unification.
- Missing: Bidirection functionality not fully implemented because
  we don't use it yet, but the basic outline is present.

Change-Id: I1666c9e4c9094eda749084bb69c700f1b5e879bb
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
42e310c4a6 cmd/go2go: add Append and Copy to slices test
Change-Id: Ie6826d8c66ae33a377dac9e66ff8363439a2be6c
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
4a8a353a22 go/go2go, cmd/go2go: add orderedmap example
Add transitive imports so that imports used by instantiated functions
and types work correctly.

Change-Id: Ie8fe0aaece7ca1bdbf201242870113d741ad3f37
2020-06-13 12:24:47 -07:00
Robert Griesemer
46b40480b6 go/types: updated documentation
Change-Id: Id84fd18dc0e1928c96bb50a1759ced1e56605d51
2020-06-13 12:24:47 -07:00
Robert Griesemer
74bad35110 go/types: updated README
Change-Id: Ib68114593c5c26f05e06e7326c1567d3f253c5a5
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
01b5212797 cmd/go2go: point to testdata/go2path in package docs
Change-Id: I94857bb943503d1107b814e5111ccd6512c4a477
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
0b55a72ba3 cmd/go2go: remove explicit type arguments in chans_test
They are no longer needed as the type checker now ignores channel
direction for type inference.

Change-Id: I06f2ffaf60a140747f1fc5c47135045e9004d551
2020-06-13 12:24:47 -07:00
Robert Griesemer
e490a1bfb5 go/types: ignore channel directions for type inference
Change-Id: Ic7c61dfea7b43bb102bff077bf17d86b26fffba9
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
db2cf1336d go/go2go: instantiate all kinds of types
Change-Id: Iaf17de0e5556171e18d4b0c4ae7e3dd1e9f7c777
2020-06-13 12:24:47 -07:00
Ian Lance Taylor
22a2e4f0c2 cmd/go2go, go/go2go: add chans test case
To make this work, add support for instantiating pointer types.

Change-Id: Ifcecf863ad4194014a242d0a0d01ca3dc0288811
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
8d18d04312 go/go2go: report all type checking errors
Previously we reported just the first one.

Change-Id: Id8fbb50f8c6f8ab56ce76dacda4c388b76ce6c80
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
c165308eb6 go/go2go: fill in missing ast.Expr and Stmt nodes
Change-Id: I151a923c72fb61c8f31dc6d3688bcd338ab472f7
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
c65d33fa3d go/go2go: handle ast.Ellipsis in instantiate and rewrite
Change-Id: I03d316677c2a1cf31fe28d55df1ef21515a0a2ba
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
87d1d10fbe go/go2go: register packages by full import path, not package name
Change-Id: Ie40021111c97c6b30a733912e3106e8a87a0634a
2020-06-13 12:24:46 -07:00
Robert Griesemer
399d59ee46 go/types: make type inference work for self-recursive function calls
Cases such as

	func f(type T)(x T) {
		f(x)
	}

can now be type-checked. For more examples see examples/functions.go2
in the go/types directory.

Change-Id: Id661c84f086cc8ee45ec372ac4af543e68bebe8a
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
67e62d261e cmd/go2go: add sets package to testdata/go2path
Change-Id: Id47ae62192c1c8507689f8a5b1bb347baa5db4ea
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
9482f72042 cmd/go2go: add Map/Reduce/Filter/Max/Min to test cases
Change-Id: I586d4c548d4a982fe15d75128ea4f82be9db2416
2020-06-13 12:24:46 -07:00
Robert Griesemer
54d6b25ee0 go/types: updated README
Change-Id: Ib4a86240ca82722d522f8b1ce67c96695c7c4b13
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
2902418378 cmd/go2go: use embedded comparable in maps test
Change-Id: I9f3a8a377597330daa43d1757ddd8a18560cf5d4
2020-06-13 12:24:46 -07:00
Robert Griesemer
a30aa6c43e go/types: fix contract embedding
Contract embedding is reduced to interface embedding. When embedding
interfaces:
1) use the correct interface to embed; and
2) don't leave type bounds residue on the incoming type arguments
   of the embedded interface/contract as those are also the type
   parameters of the embedding (outer) interface/contract.

Also:
- For now, print "any" instead of "interface{}" (empty interface)
  when printing type parameter lists to reduce clutter. Eventually
  we should not print anything for empty interface bounds, but we
  first must also group type parameters with the same type bounds.
- Print the type parameter subscript in type parameter lists to
  make it clearer which type parameter we are referring to.

Change-Id: Ic83516096387d0f512c4c76a8a8fe849d51e033a
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
2044d8b94b cmd/go2go: use predeclared comparable in maps test
(But embedding comparable doesn't work yet.)

Change-Id: I977ca97597de47c79edb56b385c970392afb87f0
2020-06-13 12:24:46 -07:00
Robert Griesemer
10b59aa539 go/types: implement predeclared contract "comparable"
The comparable contract defines a magic method "==" which
enables comparisons with == and != . Comparable types
automagically implement this method.

TODO: If a type is not comparable but a comparable type is
expected, the error message can be confusing (missing ==
method).

Change-Id: Ie0d89b87c36d83549f7d869c18dd9786151adbae
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
e6f000d2f9 go/go2go: add maps test case
Change-Id: Iad570b218a7a3c2075f846cc86c58ec7e6b0e50c
2020-06-13 12:24:46 -07:00
Robert Griesemer
2bc31ee9f4 go/types: de-parameterize instantiated contracts when embedding them
More precisely, de-parameterize the corresponding interfaces when
embedding them in the corresponding type bounds (interfaces) for
the embedding contract. This prevents the embedded (and already
instantiated) interfaces from being instantiated again when the
outer interface is instantiated and avoids breaking an assertion.

See also the test case in testdata/issues.go2 for more details.

Change-Id: I70c9354849eda0c8a36905d0b80f4d3031542f30
2020-06-13 12:24:46 -07:00
Robert Griesemer
3935b33b31 go/types: avoid follow-on panic after assertion failure in subst
Also: Updated NOTES.

Change-Id: Iabc45e46aa76bacf5c6984dab6f4bcab74392562
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
5a5b14a4b3 go/go2go: support type inference
We can now translate code that use type inference when calling generic
functions. A couple of test cases were adjusted to use it.

Change-Id: I53c2f3dd8f9fcdb44b4a8f592acee1a19ff46f22
2020-06-13 12:24:46 -07:00
Ian Lance Taylor
4172f069ae go/go2go: aggregate types.Info together for all packages
Change-Id: I4c73c417a1e7946422fd2e1035a2ce4406ca1cf3
2020-06-13 12:24:45 -07:00
Robert Griesemer
07a7684507 go/types: record inferred type arguments for parameterized calls
In api.go, introduce a new type `Inferred` which collects type arguments
and signature in one place and which can be extended if need be.

Change-Id: I014dd52641843e85ad408fdaa07eda121cf1c41c
2020-06-13 12:24:45 -07:00
Ian Lance Taylor
2eed31c177 go/go2go, cmd/go2go: build a GOPATH of translated packages
Also start a testsuite for cmd/go2go.

Change-Id: Ib693c79b3a7427ac2f6be3264469274157a39851
2020-06-13 12:24:45 -07:00
Ian Lance Taylor
1bf660ee7c go/go2go: initial support for contracts
Includes a small patch to go/types to correctly check whether type
parameters are comparable.

Change-Id: Icd3443e0cd968eabdbd55f90520b0c6ad485edf8
2020-06-13 12:24:45 -07:00
Robert Griesemer
3370013383 go/types: add support for imported contracts (denoted by qualified identifiers)
Original code by iant@. Slightly streamlined and fixed a bug in the
process (if there is a type error in the contract, we only must "use"
the type arguments if they exist in the first place).

Change-Id: Id404d2cd4fd081b9a8053e194bf643593093e397
2020-06-13 12:24:45 -07:00
Robert Griesemer
73bb221120 go/types: add types.Info.Inferred map recording inferred function signatures
Change-Id: Idc57c1662fe63edbe8f494961cb4dcda6db61e79
2020-06-13 12:24:45 -07:00
Robert Griesemer
1211c65e41 go/types: provide accessor to type arguments for instantiated types
Plus a couple of minor unrelated comment updates.

Change-Id: I38554c9ae9143172ea65da6c270fba10772c194b
2020-06-13 12:24:45 -07:00
Ian Lance Taylor
74ba054b38 go/go2go: start to handle inferred types
Also support for statements and inc/dec statements.

Change-Id: I9af474065d3b433f582422b739fc49ef266d2751
2020-06-13 12:24:45 -07:00
Robert Griesemer
e27cae74ec go/types: assertions/type switches on generic types are strict
Assertions/type switches that are guaranteed to fail on generic
types are not permitted (in contrast to regular type assertions
and type switches).

Change-Id: Iaa5b96f094585cb206fdadaa501445f96f26c166
2020-06-13 12:24:45 -07:00
Robert Griesemer
86b6990e9e go/types: implement type assertions and switches over generic types
Change-Id: I5e8debe3fee832e7829bcf2d451bde9bdc50a600
2020-06-13 12:24:45 -07:00
Ian Lance Taylor
fe586a7418 go/go2go, cmd/go2go: support importing Go2 packages
This support works for the top level test directory, but needs more
testing of "go tool go2go".

Change-Id: I01c4ce4a428535777b0fff1e6f8f39eee9005e04
2020-06-13 12:24:45 -07:00
Robert Griesemer
8578f6bfe6 go/types: address TODO (follow-up on previous commit)
Instead of rewriting the underlying AST for a receiver type in place,
explicitly pass the rewritten AST to Checker.collectParams.
Also, better comments in various places.

Change-Id: If64e80b2c6b4b57477a4a0bf87caaa2f4ea1bf21
2020-06-13 12:24:45 -07:00
Robert Griesemer
f7bc9d382f go/types: support blank identifiers for unused receiver type parameters
Change-Id: I5d7d359d7453f7ed949a7cab7b85419f8f4ee2a9
2020-06-13 12:24:45 -07:00
Robert Griesemer
08e2d11638 go/types: update NOTES
Missed with prior commit.

Change-Id: If111c8c6df6663199a23f8a1d2c147114f34ba6f
2020-06-13 12:24:45 -07:00
Robert Griesemer
86c2daf9e9 go/parser, go/types: permit parentheses around embedded contracts
For symmetry with embedding in structs and interfaces.
Fixed an incorrect error message print in the process.

Change-Id: I295685438a22971edc610e6c51cfefd286eaffba
2020-06-13 12:24:45 -07:00
Ian Lance Taylor
5cc90acd4b go/build: add go/go2go to pkgDeps
Change-Id: I43c131a910c372d849095160e6feb958da906e19
2020-06-13 12:24:45 -07:00
Robert Griesemer
6c083a7972 go/types: use correct package when creating a new instantiated type
Fix provided by iant@.

Change-Id: Iec89f007cfe9b9b50351122a03550e64238f9c44
2020-06-13 12:24:45 -07:00
Robert Griesemer
3d8c442870 go/parser, go/types: accept parameterized embedded struct fields
To be able to distinguish between a named field with a parenthesized
type `foo (T)` and an embedded parameterized type `foo(T)` in structs
we permit the use of parentheses in embedded types. For instance, the
latter example will need to be written as `(foo(T))`.

The parser now accepts any parenthesized embedded type liberally
and assumes that type-checking makes sure only permissible types
are accepted. As a result, parsing of field declarations is now
massively simpler. Also, removed an unused function.

The type-checker now complains about invalid embedded types (as
opposed to an invalid AST); it also now accepts embedded parameterized
types.

Change-Id: Ib8c6cbea9a0b739f66ba266fb5f8b71f91b7b64e
2020-06-13 12:24:45 -07:00
Robert Griesemer
38c2ef660d go/types: implement substMap and use it for substitutions
Instead of passing around a type parameter list and type arguments,
create a substitution map from them and use that map instead.

Change-Id: Ia4a041d95bfaa98888c9c06812d33b3d2a79227d
2020-06-13 12:24:44 -07:00
Robert Griesemer
72d320ec6e go/types: don't compute parameter list twice for regular generic functions (optimization)
Avoid a substitution operation for non-variadic generic functions.

Change-Id: Id40c0078a05be3aa53cd5b8551fa9fe6107bcda8
2020-06-13 12:24:44 -07:00
Robert Griesemer
99c8ae0d28 go/types: cleanup instantiation of function signatures
Make sure that a generic signature is not generic anymore
after instantiation. Update various related comments.

Change-Id: I2ac81037e570dc3a96c138b85529f3d86030776a
2020-06-13 12:24:44 -07:00
Robert Griesemer
3ab56f5ff2 go/types: minor adjustment to an error message and comments
Change-Id: Ie9505d508507c9ed764ec725df1027c92bae0702
2020-06-13 12:24:44 -07:00
Robert Griesemer
e70e49973e go/types: move method collection out of type declaration processing
Simplifies Checker.typeDecl. Also, methods can only be added to
top-level types; no need to try to collect them for local types.

Change-Id: I05b926df7ffa70c32c1dd5faed3c68617be8f270
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
12a7da1eb0 go/go2go: add support for methods of parameterized types
Change-Id: I308eb692612cb8d6e7321c4972e90b102466b4c2
2020-06-13 12:24:44 -07:00
Robert Griesemer
1bcfb0add1 go/types: fix receiver type parameter inference
Make sure receiver type and actual receiver argument
match in "pointer-ness" before attempting to infer
any receiver type parameters.

Change-Id: Ie28004ce42ecef46e348424140b8d0c65e37cdaa
2020-06-13 12:24:44 -07:00
Robert Griesemer
5a2e660efa go/types: improved type strings for instantiated generic types
Better output for now, but the printing code is a hack and needs
a rethink and cleanup.

Change-Id: Ieb1f13a21645b48f9494ceda50f58017b31bbd82
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
b1322d38b6 go/go2go: support parameterized types
Added an accessor function to go/types:

// TParams returns the type parameters of the named type t, or nil.
func (t *Named) TParams() []*TypeName { return t.tparams }

Change-Id: Ife2322c73dd6eaecaed42655a57a37541661d1ed
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
f0d1b476a9 cmd/go2go: support "go2go translate a.go2 b.go2"
For the translate subcommand, support .go2 files as well as package names.
Creates a.go b.go.

Change-Id: Ica09ca447e7312dcec5fabbc68b365bc45d55ad5
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
2687ed5586 go/go2go: simplify error handling in rewrite methods
Just store the error in the translator struct, rather than always
checking for an error and returning it up the stack.

Change-Id: I38ea2a282f61457eea123f852d9daf9337bcf9b8
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
9ceb91ef5f go/go2go: cache type instantiations
Change-Id: Ie239e6ac7cfabf472970cd2aeddf337bcc242043
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
a480c1b795 go/go2go, go/types: support recursive instantiation
Permit a generic function to call a generic function.

Change-Id: Ic41b87eb4effd0d5eb9a6a209c98354b306d5449
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
8238ad0ab5 test, go/go2go: support .go2 files in test directory
Add an initial test.

Change-Id: If1bd6922eebf6881d3ac5d93731078fb9ca7b032
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
a588cbcd8e go/go2go, go/types: preliminary support for rewriting and instantiation
Good enough to run this program:

package main

import "fmt"

func Print(type T)(s []T) {
	for _, v := range s {
		fmt.Println(v)
	}
}

func PrintInts(s []int) {
	Print(int)(s)
}

func main() {
	PrintInts([]int{1, 2})
}

Change-Id: I5ac205138085a63e7075b01ca2779b7eb71f9682
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
10c3db1727 go/go2go: add line comments to rewritten files
Change-Id: I6fe3de668381d89131825ba00cc202f49c7971cf
2020-06-13 12:24:44 -07:00
Ian Lance Taylor
f95754ecff cmd/go2go, go/go2go: new framework for translating generics to Go
Adds a new command go2go, invocable after installation as "go tool go2go".
The go2go command supports build, test, run, and translate subcommands.
These will translate .go2 files to .go files.
No actual translation is done yet; the files are simply rewritten.
So this is a framework that works if the .go2 files are pure Go 1 code.

Change-Id: I8183fd276c4c87577c428794fb87e8dde1fa398d
2020-06-13 12:24:44 -07:00
Robert Griesemer
7ad6dd2e38 go/types: add testdata/todos.go2 for documenting unimplemented features
Also: Updated NOTES file.

Change-Id: I9f760693a486433d5a496d155627cad330630e90
2020-06-13 12:24:43 -07:00
Robert Griesemer
352c86eca2 go/types: better error messages for range clauses over generic values
Change-Id: I7b4ad2734aea5ab508b35ab526f0953b4f99c3f3
2020-06-13 12:02:35 -07:00
Robert Griesemer
2b265905e9 go/types: better comments for range stmt code
Change-Id: Id7ccf3f47b5ba9d8edd023675122d5f975b89905
2020-06-13 12:02:35 -07:00
Robert Griesemer
172f10b1e2 go/types: first cut at supporting range over generic variables
TODO
- some channel errors are not reported for generic variables
- error messages should be better

Change-Id: Ie388d6811b605645ea092481eee3a850c7ceb77b
2020-06-13 12:02:34 -07:00
Robert Griesemer
c8947e760e go/types: update README
Change-Id: I73eec3fa1ce247ae91e6acacfdd238a8314a3969
2020-06-13 12:02:34 -07:00
Robert Griesemer
4150c6a490 go/types: fix various issues with contract instantiation
Contract instantiation (= contracts with explicit type
arguments) should work now but has some implementation
restrictions:

- The type arguments provided to a contract must be
  type parameters from the type parameter list using
  the contract or the type parameter list of the en-
  closing contract (in case of contract embedding).

- Each type argument may be used at most once per
  contract expression.

Change-Id: Ia9f9d81e95d84f11ff3821b9f17b74eadab201f8
2020-06-13 12:02:34 -07:00
Robert Griesemer
203449cf09 go/internal/gccgoimporter: fix test
The typestring for embedded fields in structs was changed
by 8d30bd752d4 (type checking of function type parameters)
but this test was not updated.

Change-Id: I0d9438e3000939de09aa298c33ad1e9604a59fe8
2020-06-13 12:02:34 -07:00
Robert Griesemer
2ebcbd9efd go/printer: add missing test files
Change-Id: If5522bcf0f75a86b7aa36ed853a1349ad4a2a1f4
2020-06-13 12:02:34 -07:00
Robert Griesemer
ee164bc407 go/test: steps toward instantiated contracts (partially working)
See testdata/tmp.go for a test that shouldn't succeed.

Change-Id: Iefa738e0b6df6c3abe74670f8bc1d62a3e8c4e46
2020-06-13 12:02:34 -07:00
Robert Griesemer
5d80216f87 go/types: ensure a TypeParam always has a non-nil type bound
Plus minor cleanups.

Change-Id: I2508a576ad56d55fb188aa78c861afd0d032cf80
2020-06-13 12:02:34 -07:00
Robert Griesemer
3272b2b60b go/types: factor out contract expression handling
Change-Id: I499cce2abd6cf0647ea6c0aa5f93bbd513020518
2020-06-13 12:02:33 -07:00
Robert Griesemer
312a8ea57c go/types: initial code to handle instantiated contract expressions
New code not yet used. Snapshot.

Change-Id: Id3f9172d5ebd198d34b66707eaf429b791374ea1
2020-06-13 12:02:33 -07:00
Robert Griesemer
3c2505cae9 go/types: use Interface.is for generic variable indexing/len/cap (cleanup)
Interface.is already takes care of iterating through all types of
a generic type bound; use it instead of writing custom loops each
time.

Change-Id: Ie0f91b27e5a7b65ea85a8c3847a954db1e9f24fe
2020-06-13 12:02:33 -07:00
Robert Griesemer
1a2a175a8e go/types: implement indexing of generic types
Change-Id: I88a488d9d279b1029dd8086ea1befaa7b5733df6
2020-06-13 12:02:33 -07:00
Robert Griesemer
d2fce6bc64 go/types: implement len/cap for arguments of type paramater type
Change-Id: Ieeaa41573e5ec10df46ab25ec0a3563e3ae5b32b
2020-06-13 12:02:33 -07:00
Robert Griesemer
c49fde5b11 go/types: various comment improvments (cleanup)
Change-Id: I0763f7ef202f9dec11abd4f204ab950b86e0272c
2020-06-13 12:02:33 -07:00
Robert Griesemer
45dd45561e go/parser: better error recovery for (invalid) local contracts
Change-Id: I76b0d2af3767978ca138d899a083a6e399fea0fe
2020-06-13 12:02:33 -07:00
Robert Griesemer
b5ecc31064 go/parser, go/types: minor cleanups around type parameters
Change-Id: Ic2faf89a29193d1d50bb5bdccce0fda2301785ed
2020-06-13 12:02:33 -07:00
Robert Griesemer
2c0e53f518 go/parser, go/types: allow parenthesized embedded interfaces
This enables the distinction between a method M(int) and an
embedded instantiated (parameterized) interface (M(int)).

Change-Id: I150d1b1cd53a2b14ddc0ad6336d84078fcb41ad6
2020-06-13 12:02:33 -07:00
Robert Griesemer
9c75653a79 go/types: generalize/cleanup missingMethod to handle generic methods
This simplifies the use of missingMethod again but moving the lazy
instantiation of methods into missingMethod. Method comparison now
also takes method type paramaters into account.

This change enables the first examples of parameterized methods
to type-check.

Change-Id: I4c629fb7b1f8959184c6ce5196365893d11b197d
2020-06-13 12:02:33 -07:00
Robert Griesemer
3fd481043b go/types: must have at least one type when checking type list properties
Fixes bug with generic min being accepted even though the contract
or interface bound doesn't enumerate any types (or is missing).

Change-Id: Icdfc62fbd2b73ece397d5b5f1ebe27e52ed9b32f
2020-06-13 12:02:33 -07:00
Robert Griesemer
32c4c5a5f8 go/*: move TParams field into ast.FuncType and adjust dependencies
This step further consolidates all parameter types (except for the
receiver) in an ast.FuncType which now matches more closely the
representation of a types.Signature. As a result, fewer parameters
need to passed around because we can just use an *ast.FuncType or
a *types.Signature instead.

As an immediate (and implicit) consequence, parameterized interface
methods now type-check. (But we cannot yet "implement" them with a
matching concrete type.)

Change-Id: I2ea24694ade9838488625ffec48d5e98070d1006
2020-06-13 12:02:32 -07:00
Robert Griesemer
e3a0a7429a go/types: first steps towards parameterized methods
This is a generalization of type parameters to methods.
Being able to type-check them (even if we don't have an
idea how to actually implement such methods) is likely
going to inform the structure the type-checker: If the
code is organized correctly, the generalization should
mostly just work (and consist of the elimination of
extra checks).

So far, this first step only exposed some minor scoping
issues (where does the scope of type parameters start).

Change-Id: I8658ea8d1876a0ce9c62c0e9a7e943301e9cc19d
2020-06-13 12:02:32 -07:00
Robert Griesemer
464fb5c1e7 go/parser: allow method type parameters
Controlled via methodTypeParamsOk (internal flag).

Change-Id: I821a303f897f5a99ac42f667a3f592cbd1e98d0c
2020-06-13 12:02:32 -07:00
Robert Griesemer
a9c105c1d7 go/parser: use named consts rather than bools to control paramater parsing (cleanup)
Change-Id: I5d0638f4a9ad396c0203fc88ea93fcc38945f1b4
2020-06-13 12:02:32 -07:00
Robert Griesemer
bc236133bf go/types: implement interface embedding of interfaces with types
This follows the approach used for methods, but there is no error
reporting yet if a type is (explicitly) declared multiple times in
an interface.

Change-Id: I52428174ae278577a7c538b0817c6fb7af1c369e
2020-06-13 12:02:32 -07:00
Robert Griesemer
d4338964b3 go/types: implement contract embedding
Also:
- updated README
- rebased on master

Change-Id: Ieafcdd94460e02964350abc98651d0348d6521f9
2020-06-13 12:02:32 -07:00
Robert Griesemer
b6a8a0a86f go/types: first steps towards contract embedding
Incomplete but all the major steps are outlined now.

Change-Id: I05c0357072d8b2c9f85154d3dd14984d2134de62
2020-06-13 12:02:32 -07:00
Robert Griesemer
af12458327 go/types: always create a bound for each contract parameter
Also:
- simplify Contract struct
- rename some variables for more consistency

Change-Id: Icd10b47ac97d11870c6d4590c154b7efe158c134
2020-06-13 12:02:32 -07:00
Robert Griesemer
24cbbe5229 go/types: use function body scope for type and ordinary parameters
Change-Id: Iab3cf89125d9e13e1dff86710b313770a520a54a
2020-06-13 12:02:32 -07:00
Robert Griesemer
97251af9c4 go/types: move tparams field out of Func, clean up Signature
Type parameters are now collected as part of signature type
checking, as they are part of the type not the object. This
opens the door to more uniform handling of type parameters,
also for concrete methods and interface methods (future use).

Cleaned up confusion between Signature.mtparams and tparams:
tparams are explicitly declared function type parameters.
mtparams is gone and replaced with rparams which are the
receiver type parameters used in the function.

Various related cleanups.

Change-Id: Id8422b57cc8fbc18ffdca12a69d890aef83c3f80
2020-06-13 12:02:32 -07:00
Robert Griesemer
6e52291881 go/types: factor out type parameter list declaration
Including minor related cleanups.

Change-Id: I9d6f6ce6d2460fed10aa0818baa3f53b6f723b39
2020-06-13 12:02:32 -07:00
Robert Griesemer
2741fd2ea1 go/types: rewrite Checker.collectTypeParams (fix TODO)
Change-Id: Ie504606340d6ce52c1d5241ba13ec02043ba5400
2020-06-13 12:02:32 -07:00
Robert Griesemer
3d4810b5ba go/parser: remove vestiges for [type T] style type parameters
We're not going back to that notation.

Change-Id: Ic3d9b2c931525df60c00ed0ba0e43c20be5f7b43
2020-06-13 12:02:31 -07:00
Robert Griesemer
9090a73d10 go/types: updated NOTES and README files
Change-Id: Iea657febf7bf86f28116d9ac0fdf3c921d436b90
2020-06-13 12:02:31 -07:00
Robert Griesemer
53a8d66b5b go/types: temporary fix for subtle signature instantiation bug
A signature that's instantiated but doesn't have any incoming
or result (value) parameters doesn't get a copy automatically.
This leads to bugs because the instantiated signature doesn't
lose its type parameters when it should.

Make a copy outside for now, this fixes some (but not all cases)
and added test cases.

Also, factored out printing of type parameters in type printing.

Change-Id: I0ec3a4226c7473cddfb16704a2218992dd411593
2020-06-13 12:02:31 -07:00
Robert Griesemer
d45f7ef80d go/types: move tparams field out of TypeName and into Named
Type parameters are a property of the type, not the type name.

Change-Id: I479eafea80f9bfbd638e688ac0747cfa52df5da1
2020-06-13 12:02:31 -07:00
Robert Griesemer
1a93d0a2ca go/types: treat contract decl as declaration, not type
This change completes the prior change by adjusting the go/types
implementation accordingly. As a consequence, contracts may now
not occur in type context anymore and errors are reported if they
do.

With this change, all tests pass again.

Change-Id: Id984b3d24b7cb6ff2fceb74fd3c33fd0af91fdce
2020-06-13 12:02:31 -07:00
Robert Griesemer
3a40a4f856 go/ast, go/parser, go/printer: treat contract decl as declaration, not type (cleanup)
Progress snapshot.

This change makes a contract declaration a proper declaration (as it is
envisioned in the design draft). Specifically, contracts cannot be used
in type position anymore, and a contract declaration is not treated as
a type declaration with the type being a contract.

The change has not been pushed through go/types yet; this change will
temporarily brake go/types.

Change-Id: Ia4034caebab07dac449a02cdd362d6ce5d61c4a3
2020-06-13 12:02:31 -07:00
Robert Griesemer
bf01ee1864 go/types: update README
Change-Id: I9508ad449a82295ec2eb1a31c6932fcf8b42fee3
2020-06-13 12:02:31 -07:00
Robert Griesemer
ac0c4f1846 go/types: fix bug with generic function instantiation
Once a generic function is instantiated, it's not generic anymore.

Also: Added various additional test cases.

Change-Id: Ic2304b6c252cfdf41e526825dda64b8a77023d47
2020-06-13 12:02:31 -07:00
Robert Griesemer
edb963e7e9 go/types: fixed testdata/linalg.go2 example
The new lazy method substitution code seems to work. The bug was
in the test, not in the implementation!

Change-Id: I39794743a01e9725d57f49ccd7c3751376cd01d6
2020-06-13 12:02:31 -07:00
Robert Griesemer
a28b69c5d0 go/types: various attempts at lazy substitution of methods for lookups (snapshot)
When instantiating a type, we should also instantiate its methods (at least their
signatures) so that they have the correct type when being looked up. Unfortunately,
methods may not yet be type-checked; and worse, when we type-check them, typing
their receiver means instantiating that type again which would require updating
(= instantiating) the methods...

Instead, we keep the original list of methods (*Funcs) with each (named) type
and only update the method signatures when looking them up. The problem with this
approach is that we need to know with which values to substitute the method (i.e.,
receiver) type parameters, and this is currently not working.

Change-Id: Ie1835919dc8bfb8161a6a9e3d784c3bbbeb958c4
2020-06-13 12:02:31 -07:00
Robert Griesemer
cef8f5c6a4 go/types: move includeTypes function to a method of Interface (cleanup)
Change-Id: Ic3a4beaa279b6d6349136f5a9ff0447227cabb5a
2020-06-13 12:02:31 -07:00
Robert Griesemer
74d0d556d9 go/types: use named receiver type for contract methods
Change-Id: Ib82a8c41490d75ee80cd96fbf862412fdc5657c2
2020-06-13 12:02:30 -07:00
Robert Griesemer
609756301c go/types: updated NOTES
Change-Id: I65cbbb3aaeb1c364932b7e9ee8bdc7635ac41160
2020-06-13 12:02:30 -07:00
Robert Griesemer
960e15c183 go/types: print implementation type in tracing output of types
Change-Id: I9d48540413addaac4b2a6e2b821e9ef63e97c983
2020-06-13 12:02:30 -07:00
Robert Griesemer
118728b8c2 go/types: steps towards customization of methods in bounds checks (snapshot)
This CL introduces an update mechanism to customize method signatures
with the correct type parameters before comparing them for equality.
The mechanism is not correctly used, yet.

Change-Id: Ib88af88e151578a3fb3a648ed70d3f462a936c9b
2020-06-13 12:02:30 -07:00
Robert Griesemer
e1203396e7 go/types: updated README
This README can now be used as commit message.

Change-Id: I26d1e430d643868bd7e3d71ec585b8518ad47366
2020-06-13 12:02:30 -07:00
Robert Griesemer
29f795f511 go/types: implement conversions to generic types
Change-Id: Ifa878fddea3548a27579b3196921c6816f2d9363
2020-06-13 12:02:30 -07:00
Robert Griesemer
75897ab270 go/types: instantiate contracts when used as type bounds
Change-Id: I1b9ecf6007b485ca53096134fa875a9bf6fcfa73
2020-06-13 12:02:30 -07:00
Robert Griesemer
67b83f1382 go/types: represent type parameter bounds always as interfaces
When type-checking contracts, construct a parameterized named
interface for each of the contract parameters. Use those iterfaces
as type bounds for the type parameters.

This simplifies and cleans up the implementation.

Change-Id: I688e38542fa7fa83dd436439dd9ebe35af2f0458
2020-06-13 12:02:30 -07:00
Robert Griesemer
ed8d54fb3a go/types: added testdata/linalg.go2 to test suite, disabled some code
Context-specific customization of parameterized interface methods of
type parameter bounds is missing; as a result some of linalg.go2 fails.

Change-Id: I3e749ee040d2b3ae8f73ae26680984bc1b4b79ef
2020-06-13 12:02:30 -07:00
Robert Griesemer
2aeeba6836 go/types: set receiver type bounds for methods
Enable a few more tests that now work correctly.

Change-Id: I7efe91660c2896d4d8279b86831aa7de2ae7c0ad
2020-06-13 12:02:30 -07:00
Robert Griesemer
d49c915592 go/types: a type arg type list must be a subset of the type param type list
The original implementation (commit 65377ae6e0) checked the wrong way around.
Added more tests.

Change-Id: I59e1fd6d7e646f2e8e0ff68a0bbcf9ff9def0eff
2020-06-13 12:02:30 -07:00
Robert Griesemer
a30fb05aa2 go/types: substitute type parameters when checking type param. bounds
Change-Id: Ib97d1b3928629bc073b32fde48709369213a4bbb
2020-06-13 12:02:30 -07:00
Robert Griesemer
d941f3db1d go/types: remove satisfyContract - now implemented via instantiate
Change-Id: I1561d57709a996112b39aa8a15826387ea062e29
2020-06-13 12:02:29 -07:00
Robert Griesemer
6e1fbb8a53 go/types: factored writeTypeList, various minor cleanups, added test case
Change-Id: I971633c93099ab69466dc152e23aa9cf3ded50e0
2020-06-13 12:02:29 -07:00
Robert Griesemer
5504084423 go/types: implement type bound checking for type parameter type args
If the type argument is itself a type parameter, we must use that
type parameter's bound to check against the bound of the type
parameter matching the type argument.

Change-Id: If5128115a9fc10af8163c37b1f75645447ead766
2020-06-13 12:02:29 -07:00
Robert Griesemer
0de29c0b76 go/types: more cleanups around type instantiation
- type instantiations checks parameter count
- better positions for error messages
- removed some (now) dead code

Change-Id: Icf70642bbfd4e45a7762b002ea94704dc3d56475
2020-06-13 12:02:29 -07:00
Robert Griesemer
13893bbf9e go/types: type instantiation to verify type bounds
Change-Id: Ia4670a0d6bbabf4a1ac71410c7bfccc99ba61c9d
2020-06-13 12:02:29 -07:00
Robert Griesemer
3458c46de1 go/types: factor out/consolidate instantiate calls
Change-Id: I4973e0ebcd07d543b049f1fcdd8040f2ae214142
2020-06-13 12:02:29 -07:00
Robert Griesemer
be92a40c3f go/types: minor improvements in tracing output, removed some TODOs
Also: added failing test cases to NOTES

Change-Id: Ie7b823b4cc46c64068749676d7a1464082e60264
2020-06-13 12:02:29 -07:00
Robert Griesemer
57c8d7fe0a go/types: do not permit parenthesized uninstantiated generic types
Document the design decision.

Change-Id: Ied5d77bc576653b49edcde4cdb3f6b95623a9045
2020-06-13 12:02:29 -07:00
Robert Griesemer
fefe08cbea go/types: check that generic types are instantiated before use
This (temporarily) disables the use of recursively defined
generic types w/o repeating the type arguments, but such
type definitions need some more (type-checking) love anyway
before all conditions are checked.

Change-Id: I173f5ce2296b1c484ac95a3a887812c0b1f88245
2020-06-13 12:02:29 -07:00
Robert Griesemer
eacaaec439 go/types: add NOTES text file
To be used for better record keeping (design notes, observations,
bugs, TODOs, etc.).

Change-Id: Iaecf091dcd46f53ee55b97236bd0febd7c1d2b3d
2020-06-13 12:02:29 -07:00
Robert Griesemer
edc9611855 go/types: various minor fixes around interface type bounds
- print type bounds when printing function signatures
- store (named) tyep bound rather than underlying type
- first example using parameterized interface type bound working

Change-Id: Ic7110039d1e09838c8f33040e887e6a4f038d75d
2020-06-13 12:02:29 -07:00
Robert Griesemer
704beb3881 go/parser, go/types: parse/type-check interface (literal) type constraints
Accept (parse and type-check) parameterized interfaces with literal
type constraints, as in contracts. For instance, instead of

	contract C(T) {
		T add(T) T
		T int, string
	}

one can write

	type C(type T) interface {
		add(T) T
		type int, string
	}

Their use as type bounds still needs some work, though.

Change-Id: I9d59681dc0ba38054ee5627be141fc6e8a78381b
2020-06-13 12:02:28 -07:00
Robert Griesemer
6db0b6d33a go/parser, go/types: various minor fixes around printing and tracing
- set correct token position for ast.ContractType
- print "best effort" interface position in "complete interface" traces
- don't print trace output for types that are already set up
- print contract "signtature" when printing Contract type

Also: rebased on top of today's master branch

Change-Id: I6a528ce51a4152c25ad5d83ad52e01df8e89d283
2020-06-13 12:02:28 -07:00
Robert Griesemer
234ccd01f3 go/types: print contract type strings
Change-Id: Id698420124d526eb481659856705798bc5648b91
2020-06-13 12:02:28 -07:00
Robert Griesemer
4fa7fd828d go/types: fix type inference and method calls with parameterized receivers
This change expands type inference to parameterized named types
and clarifies handling of type parameters during type inference
(specifically, an inferred type may be a type parameter itself).

The change also implements method selectors with parameterized
receiver types by using type inference to deduce the receiver
type parameters.

Add more tests and enable many disabled tests that now work
correctly.

Change-Id: I8e10f9166fec9a8454f14b8fb089230c70422a1b
2020-06-13 12:02:28 -07:00
Robert Griesemer
1a0bc57392 go/types: removed instantiate call, renamed instantiate2 => instantiate
Also: added a currently failing test case to testdata/tmp.go2

Change-Id: I605bffb457e3b3979b42a642010215630c0544c6
2020-06-13 12:02:28 -07:00
Robert Griesemer
45eb8a74f0 go/types: added another example to examples/types.go2
Also: disabled aggressive rewriting of methods upon type instantiation

(Need to first figure out what we really need to do.)

Change-Id: I6fba78d60963534ebfe130164058ac1fbed7e5a3
2020-06-13 12:02:28 -07:00
Robert Griesemer
47ddbd09af go/types: added example to examples/types.go2
Change-Id: Ib2e5d28c48bc818e1c1a54ae4888bbab916b758a
2020-06-13 12:02:28 -07:00
Robert Griesemer
3e2c9743cb go/types: write TypeParam id's using subscript digits (fun)
Change-Id: I0df6e534774b2616f67c29a1525ddb40dbed9b05
2020-06-13 12:02:28 -07:00
Robert Griesemer
8c7ab48154 go/types: remove Parameterized type and related code
The need for the Parameterized type was eliminated by
the prior commit.

Change-Id: I8a2a2ae19ec5fef9292885fc7d23f8950d917e2f
2020-06-13 12:02:27 -07:00
Robert Griesemer
703974d608 go/types: rewrote instantiation of named types
A parameterized named type is in one of two states: not yet
instantiated, or instantiated. It may be instantiated with
any type, including (outer) type parameters. An instantiated
parameterized type may needs its type parameters substituted
if it is part of an enclosing type (or function) that is
instantiated.

A Named type has an extra field targs which is set to the
type arguments if the type is instantiated.

As a result, we don't need a representation for (partially)
instantiated parameterized types anymore: the Parameterized type
is now unused (but still present in the code).

Added a unique id field to TypeParam types so they can be
printed with a unique name. This permits the creation of a
unique type name for instantiated types which then can be used
for hashing that type name.

Also, made interfaces as type bounds work in more cases.

A handful of places (in testdata/map.go2, map2.go2) are broken
(commented out) and need investigation.

Change-Id: I137d352b419b2520eadde1b07f823375e0273dab
2020-06-13 12:02:27 -07:00
Robert Griesemer
46442bd4a9 go/parser: complain if type parameters are not permitted
Always accept them but complain if they are not permitted.
The analogous parser check was lost in a recent change.

Also: Fix index computation in collectTypeParams.

Change-Id: I7cb89944984df6dadd7f603b56f0c3941d60f7c5
2020-06-13 12:02:27 -07:00
Robert Griesemer
c47bad9a28 go/types: interfaces as type bounds starting to work
With various loose ends.

Change-Id: Idbcb4affc585f5bb14caa2045943a64a78d05d09
2020-06-13 12:02:27 -07:00
Robert Griesemer
51d599efa2 go/parser, go/types: steps towards accepting interfaces as type bounds
Also, rebased branch on top of master.

Change-Id: I758b19ae577a4554687b2206c016277c1ca21a45
2020-06-13 12:02:27 -07:00
Robert Griesemer
34f753b9d1 go/types: add testdata/linalg.go2 (not yet type-checked)
Also, added missing copyright notices in a few places.

Change-Id: Iaa39c10a1821a189cef604d2442e6f7ed7ac68a8
2020-06-13 12:02:27 -07:00
Robert Griesemer
660f7c38d1 go/types: first cut at supporting real/imag/complex with type parameters
Change-Id: Ic0dba1a5e758942a03d114df10cb5536cf432985
2020-06-13 12:02:27 -07:00
Robert Griesemer
e4a39e916f go/types: update README
Change-Id: I81e8304da885f36a2f6a41f6809063e74e87b0ea
2020-06-13 12:02:27 -07:00
Robert Griesemer
1bddb66b7c go/types: more operators supported by contracts
Change-Id: I03493508813d13dd1a16cd675de68170da14b29f
2020-06-13 12:02:27 -07:00
Robert Griesemer
cfbeecaabb go/types: first cut at type-checking type parameters with operators
- implemented for comparisons for now
- can type-check generic min
- also: rebased on top of Go tip

Change-Id: Id35582a59c4cddcb2b4ae9c7d7154ef8e41580ab
2020-06-13 12:02:27 -07:00
Robert Griesemer
dc4f9fb373 go/types: first steps towards collecting/recognizing type constraints
Change-Id: Ic0d70db24ad9fb76a5bb128df654c131f173247e
2020-06-13 12:02:27 -07:00
Robert Griesemer
7b6471a756 go/types: use new Checker.completeInterface when constructing Contracts
Change-Id: I1b54ddb7ac69541fcab1f17e0fe1574288a5b9b9
2020-06-13 12:02:27 -07:00
Robert Griesemer
0ac0b8518c go/types: add testdata/map2.go2, update README
Change-Id: I5a859fe3298998810ba56f3b445fae8e1d177995
2020-06-13 12:02:27 -07:00
Robert Griesemer
5891f8c720 go/types: add cycle detection to IsParameterized
Also: Recognize method expressions with parameterized receivers
and report an error for now (not implemented yet).

Change-Id: I96405b2b739d8e9fff6e9840347d3e78bfe8b6ec
2020-06-13 12:02:27 -07:00
Robert Griesemer
1f06612063 go/types: fix a bug with type instantiation
Change-Id: I977bb5525a40d0e17c27bbc01d7c77426e1bad00
2020-06-13 12:02:26 -07:00
Robert Griesemer
e73de77f33 go/types: some prep work for making import "chans" (testdata/map.go2) work
To make the import work, the import needs to be changed into
`import "./chan"`, the file testdata/chans.go2 needs to be
copies into a new directory testdata/chan and the file must
be renamed to chans.go.

But this exposes some problem with instantiating parameterized
types with other type parameters. Delaying this for now.

Change-Id: I1cd784fb89c2374131f3b1105493492eb0189abc
2020-06-13 12:02:26 -07:00
Robert Griesemer
fbff5cc915 go/types: fix collection of receiver type parameters
... and various related smaller fixes

We can now type-check the slices, chans, and maps
examples from the design doc (with the maps example
prodcing an error because importing chans doesn't
work yet). Progress!

Change-Id: Ifc00359a9a1cdad3bde1659a7de2028ac2544469
2020-06-13 12:02:26 -07:00
Robert Griesemer
3c6943daac go/types: more work on checking contract satisfaction
Change-Id: Ibe54e448603c685d714310ff83d4193150d47ebd
2020-06-13 12:02:26 -07:00
Robert Griesemer
b87cfd9558 go/types: more steps towards contract type checking
- moved type parameter collection out of resolver and into decl phase
- collect (meta-) type information (contracts) for type parameters
- first cut at checking contract satisfaction (methods only for now)

Change-Id: I46707969a172423738171aaea9d5282fb4b25a44
2020-06-13 12:02:26 -07:00
Robert Griesemer
590e4ea3f0 go/types: re-enable initial contract type checking
- collect contract methods in respective interfaces
- basic checking on contract type constraints

Contracts are not yet tested against or used to type check
function bodies.

Change-Id: I13b00c44524e599f92f1ba5b4b5d6734e2bf22e1
2020-06-13 12:02:26 -07:00
Robert Griesemer
628e3a2c6f go/printer: first steps towards printing type parameters and contracts
- type parameters can be printed
- empty contracts can be printed
- contract constraints are missing (only started)

Change-Id: I787898203aeb064b0b2ac49a7b858313cee5f45b
2020-06-13 12:02:26 -07:00
Robert Griesemer
a65d9b58a9 go/types: fix type inference bugs for untyped arguments
Change-Id: Ic98be8b102521090108d288514ee2cf016a7bb46
2020-06-13 12:02:26 -07:00
Robert Griesemer
d03ba9f74c go/types: fix a type instantiation issue, added slices.go2 example
Change-Id: If020572762039adf10973bccd072005084e17e4e
2020-06-13 12:02:26 -07:00
Robert Griesemer
c4a20af9f1 go/types: incorporate last-minute changes added for GopherCon
Change-Id: I8e1ff18f073ca47ef1a5d8ea43c8b6a3bc4d27b8
2020-06-13 12:02:26 -07:00
Robert Griesemer
d4272d0350 go/types: add examples/contracts.go2, extended examples/functions.go2
Change-Id: Icb1c0dfc6e752598a51d8039b5df77cde9a115ca
2020-06-13 12:02:26 -07:00
Robert Griesemer
0f7748af30 go/types: add examples directory
Also: fix substitution for cyclic types

Change-Id: I2d4eca6846c1ac9a2b4d0278246228e1f61aea08
2020-06-13 12:02:25 -07:00
Robert Griesemer
025f8ad924 go/types: add README describing the state of this prototype
Change-Id: I9c994be7600ed969064cf49e8edcbe431f1b7242
2020-06-13 12:02:25 -07:00
Robert Griesemer
e2ccf6356b go/types: initial steps towards customizing method signatures
Needs more work and tests.

Change-Id: Ic54e5798c374254d55b46cb582d7cf87efe125d1
2020-06-13 12:02:25 -07:00
Robert Griesemer
3663c91f3a go/types: unpack parameterized method receivers
Also: Print debug trace when running tests and -v is set.

Change-Id: I741377f82845d4713eebeb26706cb47b55afebd3
2020-06-13 12:02:25 -07:00
Robert Griesemer
be88be6e7a go/types: steps towards type-checking of methods with parameterized receivers
Change-Id: I80b4d4c248cb5e29933366322cca1d76c3ed5e23
2020-06-13 12:02:25 -07:00
Robert Griesemer
0ffe62a473 go/types: more fixes around parameterized types
Change-Id: I81e6e70a2833e7dbb17f5155386ed3c7a75dc2ac
2020-06-13 12:02:25 -07:00
Robert Griesemer
d5d25288d4 go/types: remove typemap again (incomplete and currently not used)
Change-Id: If7483716b2ea7f66ef9fe5311ce000a3b6212524
2020-06-13 12:02:25 -07:00
Robert Griesemer
38fa8c1e9b go/types: fix instantiated type name computation (for now)
This needs more work eventually.

Change-Id: I33fce18c454113620df9bb1db71a60b38b0a1306
2020-06-13 12:02:25 -07:00
Robert Griesemer
de712f2df8 go/types: implemented comparison of parameterized types; minor bug fixes
Also: Added -h flag to test framework; setting -h causes a panic when
an error is reported (for debugging).

Change-Id: Ib45d4ef38769f2ecdd3ce53fa3aed9fd99ef6bc8
2020-06-13 12:02:25 -07:00
Robert Griesemer
06ce58509d go/types: cleaned up parameterized type code a bit; enabled more tests
Change-Id: I579239f30f26e8a483c6f5dc379124d8a9eb4576
2020-06-13 12:02:25 -07:00
Robert Griesemer
2a76603101 go/types: fixed various issues in check.subst
Next known issue:

type List(type E) []E
var _ List(List(List(int))) = [](List(List(int))){}

This won't work because the RHS's composite literal type
is not fully instantiated - it has non-instantiated elements
which are ignored by Checker.instantiatedType. We could just
call Checker.subst w/o any parameters and have it walk the
incoming type and instantiate any element Parameterized types
but that is expensive and also appears to lead to stack over-
flow. Need to investigate.

Change-Id: I80bd09ab5f06e3991f198965424ce3322c7d6402
2020-06-13 12:02:25 -07:00
Robert Griesemer
b8b66e1708 go/types: make tests pass again
Disallow parametrized alias types again. They need a bit more work.

Change-Id: I90fd101a4c61f8693ee850c5dbd6849a60b85bdc
2020-06-13 12:02:24 -07:00
Robert Griesemer
52934f1b1e go/types: significant steps towards complete parametrized type instantiation
testdata/typeinst2.go has some complex examples that pass now.
But code elsewhere seems broken. go test has some issues at the
moment. Committing anyway to not lose the snapshot.

Change-Id: Id8f753a7b098405e2580a45ca1707ef6476c198e
2020-06-13 12:02:24 -07:00
Robert Griesemer
a76283d6e4 go/types: add primitive instantiated type map for canonicalization
Change-Id: I265105d483b6fdcee95f3770b9d6d774c1633638
2020-06-13 12:02:24 -07:00
Robert Griesemer
8142528bfd go/types: correctly substitute types when instantiating parametrized types
- use the right type when instantiating a type
- substitute defined types when underlying types are changing
- improved printing of parametrized types
- improved printing of instantiated types
- more top-level trace output

Change-Id: Ie8a65c9cc51e80925d3f580f54dcc6c0b5abe4c6
2020-06-13 12:02:24 -07:00
Robert Griesemer
fac6c330ac go/types: more steps towards type-checking instantiated types
Change-Id: Iab2dab932faad704fc7141f7afe04eb80597ec57
2020-06-13 12:02:24 -07:00
Robert Griesemer
e6f3c8a0b4 go/types: add missing test file
Change-Id: I36af54691bf757f78612549283e3eea1358dca0e
2020-06-13 12:02:24 -07:00
Robert Griesemer
fa30b485bc go/types: collect function type parameters during resolve phase
- move init and method parameter checks to resolve phase as well
- more consistent error messages
- more tests

Change-Id: I6cb147b35385541ca5d7d7e3f87159df84cced76
2020-06-13 12:02:24 -07:00
Robert Griesemer
db132013f4 go/types: collect type parameters of types and set up corresponding scopes
Change-Id: Ie63ffcdb8e3682b75f9863cea7987561772e6809
2020-06-13 12:02:24 -07:00
Robert Griesemer
aa0fabb90e go/types: prepare resolver for types with type parameters
Change-Id: If4395181b5683750098aefd5292a00921b3a5427
2020-06-13 12:02:24 -07:00
Robert Griesemer
7d54168ae9 go/types: add initial TypeMap implementation
Eventually we need this to avoid repeated instantiation
of generic types.

Change-Id: Idd9625dadfe67398d91121e73ef806576437a2f6
2020-06-13 12:02:24 -07:00
Robert Griesemer
e35f6184bd go/*: accept comma-separated list of types/methods in contracts
Updated go/ast and go/parser. go/types doesn't process the
new data structure yet and is missing a good type representation
of contracts.

Change-Id: I101f7c9e98008840dd1edb55404bb97db5a66ccd
2020-06-13 12:02:23 -07:00
Robert Griesemer
150704f738 go/types: implemented a few TODOs (minor progress) 2020-06-13 12:02:23 -07:00
Robert Griesemer
5ef7be9e7c go/types: more work on type-checking stand-alone contracts
Does not handle contract embedding yet.
2020-06-13 12:02:23 -07:00
Robert Griesemer
48d479685e go/*: added linalg.go2, renamed a couple of Go 2 tests to end in .go2 2020-06-13 12:02:23 -07:00
Robert Griesemer
5541826527 go/types: initial checking of type constraints, factored out contracts code 2020-06-13 12:02:23 -07:00
Robert Griesemer
e21d47f346 go/types: first steps toward type-checking individual contracts 2020-06-13 12:02:23 -07:00
Robert Griesemer
66b509a402 go/*: remove ast.TypeParamList in favor of ast.FieldList 2020-06-13 12:02:23 -07:00
Robert Griesemer
e3b54c8023 go/*: fix parsing of T(P){...} comp. literals and add .go2 tests
Additionally, simplify the syntax for contracts specified in a
type parameter list: It is now not possible to provide explicit
type parameters to a contract in a type parameter list - they
are always implicit. For instance

	func f(type P1, P2 C(P1, P2)) ...

must be written as

	func f(type P1, P2 C) ...

If a different order or different types are desired for C,
a new "intermediate" contract must be declared, as in

	contract C'(A, B) {
		C(B, int)  // here we allow type parameters
	}

	func f(type P1, P2 C')

This simplification will remove confusion if we decide to
allow individual contracts in type parameter lists, such as

	func f(type P C, P1, P2 C') ...

In this case, C accepts one type parameter (and applies to P),
and C' accepts two type parameters and applies to P1 and P2.

The simplification avoids questions such as whether this code
should be permitted:

	func f(type P C(P2), P1, P2 C'(P, P1)) ...

(i.e., can pass P2 to C, or P1 to C', etc.)
2020-06-13 12:02:23 -07:00
Robert Griesemer
6069527287 go/*: switch back to () parentheses, fill in various missing pieces
This change switches parsing back to using () parentheses for
type parameters. The parser now also accepts contracts in
parametrized type declarations, and top-level declared
contracts as defined in the design draft:

contract C(T1, T2) { ... }

(Internally, they are mapped to an ast.ContractType as before.)

Added more tests, incl. map.go2 from the design draft, and removed
some unused parser functions.

Passes parser and types tests.

Known issue: Composite literals with instantiated composite literal
types are not recognized properly: T(P){...} fails to parse.
2020-06-13 12:02:23 -07:00
Robert Griesemer
869c7a4e29 go/*: experiments with () and [] parentheses
This change implements parsing of contracts based on the
most recent design (using a combination of methods and
explicit basic types as well as the short-hand notations
0, 0.0, 0i, ==, and !=). At the moment, a contract is
considered a "type" and declared as such:

type C contract(T1, T2) { ...}

This change also implements parsing of type instantiations
and type parameters for type declarations, using both the
() parentheses and [] brackets (if the flag useBrackets is
set in parser.go).

Not all parsed data structures are set up correctly in the
AST yet. The parser and ast tests pass.

Change-Id: I11ce64ad49e404c5a66ce6623edc8313e803e135
2020-06-13 12:02:23 -07:00
Robert Griesemer
fd16d941dc go/*: type-checking of function type parameters
This change implements parsing and type-checking
of parametrized functions (without contracts).
Type-checking includes checking of generic function
calls using explicit type parameters as well as
implicit type parameters inferred from the actual
arguments.

Change-Id: I03c9c6912aa1e2ac79d9c5125fd5ac72df4e808a
2020-06-13 12:02:22 -07:00
3224 changed files with 89139 additions and 160291 deletions

1
.gitignore vendored
View File

@@ -37,7 +37,6 @@ _testmain.go
/src/cmd/internal/objabi/zbootstrap.go
/src/go/build/zcgo.go
/src/go/doc/headscan
/src/internal/buildcfg/zbootstrap.go
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/test.out

View File

@@ -41,7 +41,7 @@ Aeneas Rekkas (arekkas) <aeneas@ory.am>
Afanasev Stanislav <phpprogger@gmail.com>
Agis Anastasopoulos <agis.anast@gmail.com>
Agniva De Sarker <agnivade@yahoo.co.in>
Ahmed W. Mones <oneofone@gmail.com>
Ahmed Wahed <oneofone@gmail.com>
Ahmet Soormally <ahmet@mangomm.co.uk>
Ahmy Yulrizka <yulrizka@gmail.com>
Aiden Scandella <ai@uber.com>
@@ -145,7 +145,7 @@ Andy Davis <andy@bigandian.com>
Andy Finkenstadt <afinkenstadt@zynga.com>
Andy Lindeman <andy@lindeman.io>
Andy Maloney <asmaloney@gmail.com>
Andy Pan <panjf2000@gmail.com> <panjf2000@golangcn.org> <i@andypan.me>
Andy Pan <panjf2000@gmail.com>
Andy Walker <walkeraj@gmail.com>
Anfernee Yongkun Gui <anfernee.gui@gmail.com>
Angelo Bulfone <mbulfone@gmail.com>
@@ -1425,7 +1425,6 @@ Wèi Cōngruì <crvv.mail@gmail.com>
Wei Fu <fhfuwei@163.com>
Wei Guangjing <vcc.163@gmail.com>
Weichao Tang <tevic.tt@gmail.com>
Weixie Cui <cuiweixie@gmail.com> <523516579@qq.com>
Wembley G. Leach, Jr <wembley.gl@gmail.com>
Will Faught <will.faught@gmail.com>
Will Storey <will@summercat.com>

View File

@@ -33,7 +33,6 @@ Aaron Jacobs <jacobsa@google.com>
Aaron Jensen <jensen.aaro@gmail.com>
Aaron Kemp <kemp.aaron@gmail.com>
Aaron Patterson <tenderlove@ruby-lang.org>
Aaron Sheah <aaronsheah@gmail.com>
Aaron Stein <aaronstein12@gmail.com>
Aaron Torres <tcboox@gmail.com>
Aaron Zinman <aaron@azinman.com>
@@ -48,7 +47,6 @@ Adam Harvey <aharvey@php.net>
Adam Kisala <adam.kisala@gmail.com>
Adam Langley <agl@golang.org>
Adam Medzinski <adam.medzinski@gmail.com>
Adam Mitha <adam.mitha@gmail.com>
Adam Shannon <adamkshannon@gmail.com>
Adam Shelton <aashelt90@gmail.com>
Adam Sindelar <adamsh@google.com>
@@ -56,8 +54,6 @@ Adam Thomason <athomason@gmail.com>
Adam Williams <pwnfactory@gmail.com>
Adam Woodbeck <adam@woodbeck.net>
Adarsh Ravichandran <adarshravichandran91@gmail.com>
Adel Rodríguez <adel.rodriguez@leftfieldlabs.com>
Adin Scannell <ascannell@google.com>
Aditya Harindar <aditya.harindar@gmail.com>
Aditya Mukerjee <dev@chimeracoder.net>
Adrian Hesketh <adrianhesketh@hushmail.com>
@@ -71,8 +67,7 @@ Aeneas Rekkas (arekkas) <aeneas@ory.am>
Afanasev Stanislav <phpprogger@gmail.com>
Agis Anastasopoulos <agis.anast@gmail.com>
Agniva De Sarker <agnivade@yahoo.co.in>
Ahmed W. Mones <oneofone@gmail.com>
Ahmet Aktürk <aakturk000@gmail.com>
Ahmed Wahed <oneofone@gmail.com>
Ahmet Alp Balkan <ahmetb@google.com>
Ahmet Soormally <ahmet@mangomm.co.uk>
Ahmy Yulrizka <yulrizka@gmail.com>
@@ -97,13 +92,11 @@ Alberto Bertogli <albertito@blitiri.com.ar>
Alberto Donizetti <alb.donizetti@gmail.com>
Alberto García Hierro <alberto@garciahierro.com> <alberto.garcia.hierro@gmail.com>
Alec Benzer <alec.benzer@gmail.com>
Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Aleksa Sarai <cyphar@cyphar.com>
Aleksandar Dezelin <dezelin@gmail.com>
Aleksandr Lukinykh <a.lukinykh@xsolla.com>
Aleksandr Razumov <ar@cydev.ru>
Alekseev Artem <a.artem060@gmail.com>
Aleksei Tirman <aleksei.tirman@jetbrains.com>
Alessandro Arzilli <alessandro.arzilli@gmail.com>
Alessandro Baffa <alessandro.baffa@gmail.com>
Alex A Skinner <alex@lx.lc>
@@ -172,7 +165,6 @@ Ali Rizvi-Santiago <arizvisa@gmail.com>
Aliaksandr Valialkin <valyala@gmail.com>
Alice Merrick <amerrick@google.com>
Alif Rachmawadi <subosito@gmail.com>
Allan Guwatudde <guwats10@gmail.com>
Allan Simon <allan.simon@supinfo.com>
Allen Li <ayatane@google.com>
Alok Menghrajani <alok.menghrajani@gmail.com>
@@ -180,7 +172,6 @@ Alwin Doss <alwindoss84@gmail.com>
Aman Gupta <aman@tmm1.net>
Amarjeet Anand <amarjeetanandsingh@gmail.com>
Amir Mohammad Saied <amir@gluegadget.com>
Amit Kumar <mittalmailbox@gmail.com>
Amr Mohammed <merodiro@gmail.com>
Amrut Joshi <amrut.joshi@gmail.com>
An Long <aisk1988@gmail.com>
@@ -194,7 +185,6 @@ André Carvalho <asantostc@gmail.com>
André Martins <aanm90@gmail.com>
Andre Nathan <andrenth@gmail.com>
Andrea Nodari <andrea.nodari91@gmail.com>
Andrea Simonini <andrea.simonini@gmail.com>
Andrea Spadaccini <spadaccio@google.com>
Andreas Auernhammer <aead@mail.de>
Andreas Jellinghaus <andreas@ionisiert.de> <anj@google.com>
@@ -250,11 +240,10 @@ Andy Davis <andy@bigandian.com>
Andy Finkenstadt <afinkenstadt@zynga.com>
Andy Lindeman <andy@lindeman.io>
Andy Maloney <asmaloney@gmail.com>
Andy Pan <panjf2000@gmail.com> <panjf2000@golangcn.org> <i@andypan.me>
Andy Pan <panjf2000@gmail.com>
Andy Walker <walkeraj@gmail.com>
Andy Wang <cbeuw.andy@gmail.com>
Andy Williams <andy@andy.xyz>
Andy Zhao <andyzhao@google.com>
Andzej Maciusovic <andzej.maciusovic@gmail.com>
Anfernee Yongkun Gui <anfernee.gui@gmail.com>
Angelo Bulfone <mbulfone@gmail.com>
@@ -280,7 +269,6 @@ Anton Kuklin <anton.a.kuklin@gmail.com>
Antonin Amand <antonin.amand@gmail.com>
Antonio Antelo <aantelov87@gmail.com>
Antonio Bibiano <antbbn@gmail.com>
Antonio Garcia <garcia.olais@gmail.com>
Antonio Huete Jimenez <tuxillo@quantumachine.net>
Antonio Murdaca <runcom@redhat.com>
Antonio Troina <thoeni@gmail.com>
@@ -304,10 +292,8 @@ Artem Khvastunov <artem.khvastunov@jetbrains.com>
Artem Kolin <artemkaxboy@gmail.com>
Arthur Fabre <arthur@arthurfabre.com>
Arthur Khashaev <arthur@khashaev.ru>
Artur M. Wolff <artur.m.wolff@gmail.com>
Artyom Pervukhin <artyom.pervukhin@gmail.com>
Arvindh Rajesh Tamilmani <art@a-30.net>
Ashish Bhate <ab.listsubs@gmail.com>
Ashish Gandhi <ag@ashishgandhi.org>
Asim Shankar <asimshankar@gmail.com>
Assel Meher <asselmeher@gmail.com>
@@ -339,7 +325,6 @@ Baokun Lee <nototon@gmail.com> <bk@golangcn.org>
Barnaby Keene <accounts@southcla.ws>
Bartosz Grzybowski <melkorm@gmail.com>
Bartosz Oler <brtsz@google.com>
Bassam Ojeil <bojeil@google.com>
Bastian Ike <bastian.ike@gmail.com>
Ben Burkert <ben@benburkert.com>
Ben Cartwright-Cox <Ben@Benjojo.co.uk>
@@ -347,7 +332,6 @@ Ben Eitzen <eitzenb@golang.org>
Ben Fried <ben.fried@gmail.com>
Ben Haines <bhainesva@gmail.com>
Ben Hoyt <benhoyt@gmail.com>
Ben Hutchings <ben.hutchings@essensium.com>
Ben Kraft <benkraft@khanacademy.org>
Ben Laurie <ben@links.org> <benl@google.com>
Ben Lubar <ben.lubar@gmail.com>
@@ -446,7 +430,6 @@ Carl Henrik Lunde <chlunde@ifi.uio.no>
Carl Jackson <carl@stripe.com>
Carl Johnson <me@carlmjohnson.net>
Carl Mastrangelo <notcarl@google.com>
Carl Menezes <carleeto@gmail.com>
Carl Shapiro <cshapiro@google.com> <cshapiro@golang.org>
Carlisia Campos <carlisia@grokkingtech.io>
Carlo Alberto Ferraris <cafxx@strayorange.com>
@@ -460,7 +443,6 @@ Carlos Iriarte <ciriarte@gmail.com>
Carlos Souza <carloshrsouza@gmail.com>
Carolyn Van Slyck <me@carolynvanslyck.com>
Carrie Bynon <cbynon@gmail.com>
Carson Hoffman <c@rsonhoffman.com>
Cary Hull <chull@google.com>
Case Nelson <case.nelson@gmail.com>
Casey Callendrello <squeed@gmail.com>
@@ -480,12 +462,11 @@ Charles Kenney <charlesc.kenney@gmail.com>
Charles L. Dorian <cldorian@gmail.com>
Charles Lee <zombie.fml@gmail.com>
Charles Weill <weill@google.com>
Charlie Moog <moogcharlie@gmail.com>
Charlotte Brandhorst-Satzkorn <catzkorn@gmail.com>
Chauncy Cullitan <chauncyc@google.com>
Chen Zhidong <njutczd@gmail.com>
Chen Zhihan <energiehund@gmail.com>
Cherry Mui <cherryyz@google.com>
Cherry Zhang <cherryyz@google.com>
Chew Choon Keat <choonkeat@gmail.com>
Chiawen Chen <golopot@gmail.com>
Chirag Sukhala <cchirag77@gmail.com>
@@ -535,7 +516,6 @@ Christopher Nelson <nadiasvertex@gmail.com>
Christopher Nielsen <m4dh4tt3r@gmail.com>
Christopher Redden <christopher.redden@gmail.com>
Christopher Swenson <cswenson@google.com>
Christopher Thomas <53317512+chrisssthomas@users.noreply.github.com>
Christopher Wedgwood <cw@f00f.org>
Christos Zoulas <christos@zoulas.com> <zoulasc@gmail.com>
Christy Perez <christy@linux.vnet.ibm.com>
@@ -561,8 +541,6 @@ Cosmos Nicolaou <cnicolaou@google.com>
Costin Chirvasuta <ctin@google.com>
Craig Citro <craigcitro@google.com>
Cristian Staretu <unclejacksons@gmail.com>
Cristo García <cgg.code@gmail.com>
cui fliter <imcusg@gmail.com>
Cuihtlauac ALVARADO <cuihtlauac.alvarado@orange.com>
Cuong Manh Le <cuong@orijtech.com>
Curtis La Graff <curtis@lagraff.me>
@@ -582,7 +560,6 @@ Dan Callahan <dan.callahan@gmail.com>
Dan Harrington <harringtond@google.com>
Dan Jacques <dnj@google.com>
Dan Johnson <computerdruid@google.com>
Dan McArdle <dmcardle@google.com>
Dan Peterson <dpiddy@gmail.com>
Dan Pupius <dan@medium.com>
Dan Scales <danscales@google.com>
@@ -634,7 +611,6 @@ Dave Russell <forfuncsake@gmail.com>
David Anderson <danderson@google.com>
David Barnett <dbarnett@google.com>
David Benjamin <davidben@google.com>
David Black <dblack@atlassian.com>
David Bond <davidsbond93@gmail.com>
David Brophy <dave@brophy.uk>
David Bürgin <676c7473@gmail.com>
@@ -678,7 +654,6 @@ Davor Kapsa <davor.kapsa@gmail.com>
Dean Eigenmann <7621705+decanus@users.noreply.github.com>
Dean Prichard <dean.prichard@gmail.com>
Deepak Jois <deepak.jois@gmail.com>
Deepak S <deepakspavoodath@gmail.com>
Denis Bernard <db047h@gmail.com>
Denis Brandolini <denis.brandolini@gmail.com>
Denis Isaev <idenx@yandex.com>
@@ -701,10 +676,8 @@ Dhiru Kholia <dhiru.kholia@gmail.com>
Dhruvdutt Jadhav <dhruvdutt.jadhav@gmail.com>
Di Xiao <dixiao@google.com>
Didier Spezia <didier.06@gmail.com>
Diego Medina <fmpwizard@gmail.com>
Diego Siqueira <diego9889@gmail.com>
Dieter Plaetinck <dieter@raintank.io>
Dilyn Corner <dilyn.corner@gmail.com>
Dimitri Sokolyuk <sokolyuk@gmail.com>
Dimitri Tcaciuc <dtcaciuc@gmail.com>
Dina Garmash <dgrmsh@gmail.com>
@@ -741,7 +714,6 @@ Doug Fawley <dfawley@google.com>
Douglas Danger Manley <doug.manley@gmail.com>
Drew Flower <drewvanstone@gmail.com>
Drew Hintz <adhintz@google.com>
Drew Richardson <drewrichardson@gmail.com>
Duco van Amstel <duco.vanamstel@gmail.com>
Duncan Holm <mail@frou.org>
Dustin Carlino <dcarlino@google.com>
@@ -763,7 +735,6 @@ Egon Elbre <egonelbre@gmail.com>
Ehren Kret <ehren.kret@gmail.com>
Eitan Adler <lists@eitanadler.com>
Eivind Uggedal <eivind@uggedal.com>
El Mostafa Idrassi <el.mostafa.idrassi@gmail.com>
Elbert Fliek <efliek@gmail.com>
Eldar Rakhimberdin <ibeono@gmail.com>
Elena Grahovac <elena@grahovac.me>
@@ -771,7 +742,6 @@ Eli Bendersky <eliben@google.com>
Elias Naur <mail@eliasnaur.com> <elias.naur@gmail.com>
Elliot Morrison-Reed <elliotmr@gmail.com>
Ellison Leão <ellisonleao@gmail.com>
Elvina Yakubova <elvinayakubova@gmail.com>
Emerson Lin <linyintor@gmail.com>
Emil Bektimirov <lefelys@gmail.com>
Emil Hessman <emil@hessman.se>
@@ -797,7 +767,6 @@ Eric Rescorla <ekr@rtfm.com>
Eric Roshan-Eisner <eric.d.eisner@gmail.com>
Eric Rutherford <erutherford@gmail.com>
Eric Rykwalder <e.rykwalder@gmail.com>
Eric Wang <wangchaogo1990@gmail.com>
Erick Tryzelaar <etryzelaar@google.com>
Erik Aigner <aigner.erik@gmail.com>
Erik Dubbelboer <erik@dubbelboer.com>
@@ -809,7 +778,6 @@ Ernest Chiang <ernest_chiang@htc.com>
Erwin Oegema <blablaechthema@hotmail.com>
Esko Luontola <esko.luontola@gmail.com>
Ethan Burns <eaburns@google.com>
Ethan Hur <ethan0311@gmail.com>
Ethan Miller <eamiller@us.ibm.com>
Euan Kemp <euank@euank.com>
Eugene Formanenko <mo4islona@gmail.com>
@@ -850,7 +818,6 @@ Felix Cornelius <9767036+fcornelius@users.noreply.github.com>
Felix Geisendörfer <haimuiba@gmail.com>
Felix Kollmann <fk@konsorten.de>
Ferenc Szabo <frncmx@gmail.com>
Fernandez Ludovic <lfernandez.dev@gmail.com>
Filip Gruszczyński <gruszczy@gmail.com>
Filip Haglund <drathier@users.noreply.github.com>
Filip Stanis <fstanis@google.com>
@@ -891,7 +858,6 @@ Gabriel Nelle <tehsphinx@web.de>
Gabriel Nicolas Avellaneda <avellaneda.gabriel@gmail.com>
Gabriel Rosenhouse <rosenhouse@gmail.com>
Gabriel Russell <gabriel.russell@gmail.com>
Gabriel Vasile <gabriel.vasile0793@gmail.com>
Gareth Paul Jones <gpj@foursquare.com>
Garret Kelly <gdk@google.com>
Garrick Evans <garrick@google.com>
@@ -925,8 +891,6 @@ Gianguido Sora` <g.sora4@gmail.com>
Gideon Jan-Wessel Redelinghuys <gjredelinghuys@gmail.com>
Giles Lean <giles.lean@pobox.com>
Giovanni Bajo <rasky@develer.com>
GitHub User @180909 (70465953) <734461790@qq.com>
GitHub User @6543 (24977596) <6543@obermui.de>
GitHub User @aca (50316549) <acadx0@gmail.com>
GitHub User @ajnirp (1688456) <ajnirp@users.noreply.github.com>
GitHub User @ajz01 (4744634) <ajzdenek@gmail.com>
@@ -940,12 +904,10 @@ GitHub User @bontequero (2674999) <bontequero@gmail.com>
GitHub User @cch123 (384546) <buaa.cch@gmail.com>
GitHub User @chainhelen (7046329) <chainhelen@gmail.com>
GitHub User @chanxuehong (3416908) <chanxuehong@gmail.com>
GitHub User @Cluas (10056928) <Cluas@live.cn>
GitHub User @cncal (23520240) <flycalvin@qq.com>
GitHub User @DQNEO (188741) <dqneoo@gmail.com>
GitHub User @Dreamacro (8615343) <chuainian@gmail.com>
GitHub User @dupoxy (1143957) <dupoxy@users.noreply.github.com>
GitHub User @EndlessCheng (7086966) <loli.con@qq.com>
GitHub User @erifan (31343225) <eric.fang@arm.com>
GitHub User @esell (9735165) <eujon.sellers@gmail.com>
GitHub User @fatedier (7346661) <fatedier@gmail.com>
@@ -954,15 +916,12 @@ GitHub User @geedchin (11672310) <geedchin@gmail.com>
GitHub User @GrigoriyMikhalkin (3637857) <grigoriymikhalkin@gmail.com>
GitHub User @hengwu0 (41297446) <41297446+hengwu0@users.noreply.github.com>
GitHub User @hitzhangjie (3725760) <hit.zhangjie@gmail.com>
GitHub User @hqpko (13887251) <whaibin01@hotmail.com>
GitHub User @itchyny (375258) <itchyny@hatena.ne.jp>
GitHub User @jinmiaoluo (39730824) <jinmiaoluo@icloud.com>
GitHub User @jopbrown (6345470) <msshane2008@gmail.com>
GitHub User @kazyshr (30496953) <kazyshr0301@gmail.com>
GitHub User @kc1212 (1093806) <kc1212@users.noreply.github.com>
GitHub User @komisan19 (18901496) <komiyama6219@gmail.com>
GitHub User @Kropekk (13366453) <kamilkropiewnicki@gmail.com>
GitHub User @lhl2617 (33488131) <l.h.lee2617@gmail.com>
GitHub User @linguohua (3434367) <lghchinaidea@gmail.com>
GitHub User @LotusFenn (13775899) <fenn.lotus@gmail.com>
GitHub User @ly303550688 (11519839) <yang.liu636@gmail.com>
@@ -977,14 +936,10 @@ GitHub User @OlgaVlPetrova (44112727) <OVPpetrova@gmail.com>
GitHub User @pityonline (438222) <pityonline@gmail.com>
GitHub User @po3rin (29445112) <abctail30@gmail.com>
GitHub User @pokutuna (57545) <popopopopokutuna@gmail.com>
GitHub User @povsister (11040951) <pov@mahou-shoujo.moe>
GitHub User @pytimer (17105586) <lixin20101023@gmail.com>
GitHub User @qcrao (7698088) <qcrao91@gmail.com>
GitHub User @ramenjuniti (32011829) <ramenjuniti@gmail.com>
GitHub User @saitarunreddy (21041941) <saitarunreddypalla@gmail.com>
GitHub User @SataQiu (9354727) <shidaqiu2018@gmail.com>
GitHub User @shogo-ma (9860598) <Choroma194@gmail.com>
GitHub User @sivchari (55221074) <shibuuuu5@gmail.com>
GitHub User @skanehira (7888591) <sho19921005@gmail.com>
GitHub User @soolaugust (10558124) <soolaugust@gmail.com>
GitHub User @surechen (7249331) <surechen17@gmail.com>
@@ -992,12 +947,9 @@ GitHub User @tatsumack (4510569) <tatsu.mack@gmail.com>
GitHub User @tell-k (26263) <ffk2005@gmail.com>
GitHub User @tennashi (10219626) <tennashio@gmail.com>
GitHub User @uhei (2116845) <uhei@users.noreply.github.com>
GitHub User @uji (49834542) <ujiprog@gmail.com>
GitHub User @unbyte (5772358) <i@shangyes.net>
GitHub User @uropek (39370426) <uropek@gmail.com>
GitHub User @utkarsh-extc (53217283) <utkarsh.extc@gmail.com>
GitHub User @witchard (4994659) <witchard@hotmail.co.uk>
GitHub User @wolf1996 (5901874) <ksgiv37@gmail.com>
GitHub User @yah01 (12216890) <kagaminehuan@gmail.com>
GitHub User @yuanhh (1298735) <yuan415030@gmail.com>
GitHub User @zikaeroh (48577114) <zikaeroh@gmail.com>
@@ -1010,7 +962,6 @@ Glenn Brown <glennb@google.com>
Glenn Lewis <gmlewis@google.com>
Gordon Klaus <gordon.klaus@gmail.com>
Gordon Tyler <gordon@doxxx.net>
Grace Han <hgrace503@gmail.com>
Graham King <graham4king@gmail.com>
Graham Miller <graham.miller@gmail.com>
Grant Griffiths <ggp493@gmail.com>
@@ -1026,12 +977,10 @@ Guilherme Caruso <gui.martinscaruso@gmail.com>
Guilherme Garnier <guilherme.garnier@gmail.com>
Guilherme Goncalves <guilhermeaugustosg@gmail.com>
Guilherme Rezende <guilhermebr@gmail.com>
Guilherme Souza <32180229+gqgs@users.noreply.github.com>
Guillaume J. Charmes <guillaume@charmes.net>
Guillaume Sottas <guillaumesottas@gmail.com>
Günther Noack <gnoack@google.com>
Guobiao Mei <meiguobiao@gmail.com>
Guodong Li <guodongli@google.com>
Guoliang Wang <iamwgliang@gmail.com>
Gustav Paul <gustav.paul@gmail.com>
Gustav Westling <gustav@westling.xyz>
@@ -1046,7 +995,6 @@ HAMANO Tsukasa <hamano@osstech.co.jp>
Han-Wen Nienhuys <hanwen@google.com>
Hang Qian <hangqian90@gmail.com>
Hanjun Kim <hallazzang@gmail.com>
Hanlin He <hanling.he@gmail.com>
Hanlin Shi <shihanlin9@gmail.com>
Haoran Luo <haoran.luo@chaitin.com>
Haosdent Huang <haosdent@gmail.com>
@@ -1078,19 +1026,18 @@ Herbie Ong <herbie@google.com>
Heschi Kreinick <heschi@google.com>
Hidetatsu Yaginuma <ygnmhdtt@gmail.com>
Hilko Bengen <bengen@hilluzination.de>
Himanshu Kishna Srivastava <28himanshu@gmail.com>
Hiroaki Nakamura <hnakamur@gmail.com>
Hiromichi Ema <ema.hiro@gmail.com>
Hironao OTSUBO <motemen@gmail.com>
Hiroshi Ioka <hirochachacha@gmail.com>
Hitoshi Mitake <mitake.hitoshi@gmail.com>
Holden Huang <ttyh061@gmail.com>
Songlin Jiang <hollowman@hollowman.ml>
Hong Ruiqi <hongruiqi@gmail.com>
Hongfei Tan <feilengcui008@gmail.com>
Horacio Duran <horacio.duran@gmail.com>
Horst Rutter <hhrutter@gmail.com>
Hossein Sheikh Attar <hattar@google.com>
Hossein Zolfi <hossein.zolfi@gmail.com>
Howard Zhang <howard.zhang@arm.com>
Hsin Tsao <tsao@google.com>
Hsin-Ho Yeh <yhh92u@gmail.com>
@@ -1107,14 +1054,11 @@ Ian Haken <ihaken@netflix.com>
Ian Kent <iankent85@gmail.com>
Ian Lance Taylor <iant@golang.org>
Ian Leue <ian@appboy.com>
Ian Mckay <iann0036@gmail.com>
Ian Tay <iantay@google.com>
Ian Woolf <btw515wolf2@gmail.com>
Ian Zapolsky <ianzapolsky@gmail.com>
Ibrahim AshShohail <ibra.sho@gmail.com>
Icarus Sparry <golang@icarus.freeuk.com>
Iccha Sethi <icchasethi@gmail.com>
Ichinose Shogo <shogo82148@gmail.com>
Idora Shinatose <idora.shinatose@gmail.com>
Ignacio Hagopian <jsign.uy@gmail.com>
Igor Bernstein <igorbernstein@google.com>
@@ -1124,7 +1068,6 @@ Igor Vashyst <ivashyst@gmail.com>
Igor Zhilianin <igor.zhilianin@gmail.com>
Ikko Ashimine <eltociear@gmail.com>
Illya Yalovyy <yalovoy@gmail.com>
Ilya Chukov <56119080+Elias506@users.noreply.github.com>
Ilya Sinelnikov <sidhmangh@gmail.com>
Ilya Tocar <ilya.tocar@intel.com>
INADA Naoki <songofacandy@gmail.com>
@@ -1179,7 +1122,6 @@ James Cowgill <James.Cowgill@imgtec.com>
James Craig Burley <james-github@burleyarch.com>
James David Chalfant <james.chalfant@gmail.com>
James Eady <jmeady@google.com>
James Fennell <jpfennell@google.com>
James Fysh <james.fysh@gmail.com>
James Gray <james@james4k.com>
James Hartig <fastest963@gmail.com>
@@ -1236,7 +1178,6 @@ Jason Wangsadinata <jwangsadinata@gmail.com>
Javier Kohen <jkohen@google.com>
Javier Revillas <jrevillas@massivedynamic.io>
Javier Segura <javism@gmail.com>
Jay Chen <chenjie@chenjie.info>
Jay Conrod <jayconrod@google.com>
Jay Lee <BusyJayLee@gmail.com>
Jay Taylor <outtatime@gmail.com>
@@ -1259,7 +1200,6 @@ Jeff Johnson <jrjohnson@google.com>
Jeff R. Allen <jra@nella.org> <jeff.allen@gmail.com>
Jeff Sickel <jas@corpus-callosum.com>
Jeff Wendling <jeff@spacemonkey.com>
Jeff Widman <jeff@jeffwidman.com>
Jeffrey H <jeffreyh192@gmail.com>
Jelte Fennema <github-tech@jeltef.nl>
Jens Frederich <jfrederich@gmail.com>
@@ -1270,7 +1210,6 @@ Jeremy Faller <jeremy@golang.org>
Jeremy Jackins <jeremyjackins@gmail.com>
Jeremy Jay <jeremy@pbnjay.com>
Jeremy Schlatter <jeremy.schlatter@gmail.com>
Jero Bado <tokidokitalkyou@gmail.com>
Jeroen Bobbeldijk <jerbob92@gmail.com>
Jeroen Simonetti <jeroen@simonetti.nl>
Jérôme Doucet <jerdct@gmail.com>
@@ -1312,8 +1251,6 @@ Joe Richey <joerichey@google.com>
Joe Shaw <joe@joeshaw.org>
Joe Sylve <joe.sylve@gmail.com>
Joe Tsai <joetsai@digital-static.net>
Joel Courtney <euphemize@gmail.com>
Joel Ferrier <joelferrier@google.com>
Joel Sing <joel@sing.id.au> <jsing@google.com>
Joël Stemmer <jstemmer@google.com>
Joel Stemmer <stemmertech@gmail.com>
@@ -1323,9 +1260,7 @@ Johan Euphrosine <proppy@google.com>
Johan Jansson <johan.jansson@iki.fi>
Johan Knutzen <johan@senri.se>
Johan Sageryd <j@1616.se>
Johannes Huning <johannes.huning@gmail.com>
John Asmuth <jasmuth@gmail.com>
John Bampton <jbampton@gmail.com>
John Beisley <huin@google.com>
John C Barstow <jbowtie@amathaine.com>
John DeNero <denero@google.com>
@@ -1334,7 +1269,6 @@ John Gibb <johngibb@gmail.com>
John Gilik <john@jgilik.com>
John Graham-Cumming <jgc@jgc.org> <jgrahamc@gmail.com>
John Howard Palevich <jack.palevich@gmail.com>
John Jago <johnjago@protonmail.com>
John Jeffery <jjeffery@sp.com.au>
John Jenkins <twodopeshaggy@gmail.com>
John Leidegren <john.leidegren@gmail.com>
@@ -1386,7 +1320,6 @@ Josa Gesell <josa@gesell.me>
Jose Luis Vázquez González <josvazg@gmail.com>
Joseph Bonneau <jcb@google.com>
Joseph Holsten <joseph@josephholsten.com>
Joseph Morag <sefim96@gmail.com>
Josh Baum <joshbaum@google.com>
Josh Bleecher Snyder <josharian@gmail.com>
Josh Chorlton <jchorlton@gmail.com>
@@ -1394,14 +1327,12 @@ Josh Deprez <josh.deprez@gmail.com>
Josh Goebel <dreamer3@gmail.com>
Josh Hoak <jhoak@google.com>
Josh Holland <jrh@joshh.co.uk>
Josh Rickmar <jrick@companyzero.com>
Josh Roppo <joshroppo@gmail.com>
Josh Varga <josh.varga@gmail.com>
Joshua Bezaleel Abednego <joshua.bezaleel@gmail.com>
Joshua Boelter <joshua.boelter@intel.com>
Joshua Chase <jcjoshuachase@gmail.com>
Joshua Crowgey <jcrowgey@uw.edu>
Joshua Harshman <joshgreyhat@gmail.com>
Joshua M. Clulow <josh.clulow@joyent.com>
Joshua Rubin <joshua@rubixconsulting.com>
Josselin Costanzi <josselin@costanzi.fr>
@@ -1422,7 +1353,6 @@ Julie Qiu <julie@golang.org>
Julien Kauffmann <julien.kauffmann@freelan.org>
Julien Salleyron <julien.salleyron@gmail.com>
Julien Schmidt <google@julienschmidt.com>
Julien Tant <julien@craftyx.fr>
Julio Montes <julio.montes@intel.com>
Jun Zhang <jim.zoumo@gmail.com>
Junchen Li <junchen.li@arm.com>
@@ -1489,12 +1419,10 @@ Kenta Mori <zoncoen@gmail.com>
Kerollos Magdy <kerolloz@yahoo.com>
Ketan Parmar <ketanbparmar@gmail.com>
Kevan Swanberg <kevswanberg@gmail.com>
Kevin Albertson <kevin.albertson@mongodb.com>
Kevin Ballard <kevin@sb.org>
Kevin Burke <kev@inburke.com>
Kévin Dunglas <dunglas@gmail.com>
Kevin Gillette <extemporalgenome@gmail.com>
Kevin Herro <kevin109104@gmail.com>
Kevin Kirsche <kev.kirsche@gmail.com>
Kevin Klues <klueska@gmail.com> <klueska@google.com>
Kevin Malachowski <chowski@google.com>
@@ -1529,7 +1457,6 @@ Koya IWAMURA <kiwamura0314@gmail.com>
Kris Kwiatkowski <kris@cloudflare.com>
Kris Nova <kris@nivenly.com>
Kris Rousey <krousey@google.com>
Krishna Birla <krishnabirla16@gmail.com>
Kristopher Watts <traetox@gmail.com>
Krzysztof Dąbrowski <krzysdabro@live.com>
Kshitij Saraogi <kshitijsaraogi@gmail.com>
@@ -1553,7 +1480,6 @@ Lajos Papp <lalyos@yahoo.com>
Lakshay Garg <lakshay.garg.1996@gmail.com>
Lann Martin <lannm@google.com>
Lanre Adelowo <yo@lanre.wtf>
Lapo Luchini <lapo@lapo.it>
Larry Clapp <larry@theclapp.org>
Larry Hosken <lahosken@golang.org>
Lars Jeppesen <jeppesen.lars@gmail.com>
@@ -1570,7 +1496,6 @@ Leigh McCulloch <leighmcc@gmail.com>
Leo Antunes <leo@costela.net>
Leo Rudberg <ljr@google.com>
Leon Klingele <git@leonklingele.de>
Leonard Wang <wangdeyu0907@gmail.com>
Leonardo Comelli <leonardo.comelli@gmail.com>
Leonel Quinteros <leonel.quinteros@gmail.com>
Lev Shamardin <shamardin@gmail.com>
@@ -1581,9 +1506,7 @@ Lily Chung <lilithkchung@gmail.com>
Lingchao Xin <douglarek@gmail.com>
Lion Yang <lion@aosc.xyz>
Liz Rice <liz@lizrice.com>
Lize Cai <lizzzcai1@gmail.com>
Lloyd Dewolf <foolswisdom@gmail.com>
Lluís Batlle i Rossell <viric@viric.name>
Lorenz Bauer <lmb@cloudflare.com>
Lorenz Brun <lorenz@brun.one>
Lorenz Nickel <mail@lorenznickel.de>
@@ -1608,7 +1531,6 @@ Lukasz Milewski <lmmilewski@gmail.com>
Luke Champine <luke.champine@gmail.com>
Luke Curley <qpingu@gmail.com>
Luke Granger-Brown <git@lukegb.com>
Luke Shumaker <lukeshu@datawire.io>
Luke Young <bored-engineer@users.noreply.github.com>
Luna Duclos <luna.duclos@palmstonegames.com>
Luuk van Dijk <lvd@golang.org> <lvd@google.com>
@@ -1628,7 +1550,6 @@ Mal Curtis <mal@mal.co.nz>
Manfred Touron <m@42.am>
Manigandan Dharmalingam <manigandan.jeff@gmail.com>
Manish Goregaokar <manishsmail@gmail.com>
Manlio Perillo <manlio.perillo@gmail.com>
Manoj Dayaram <platform-dev@moovweb.com> <manoj.dayaram@moovweb.com>
Mansour Rahimi <rahimi.mnr@gmail.com>
Manu Garg <manugarg@google.com>
@@ -1725,8 +1646,6 @@ Matt Joiner <anacrolix@gmail.com>
Matt Jones <mrjones@google.com>
Matt Juran <thepciet@gmail.com>
Matt Layher <mdlayher@gmail.com>
Matt Masurka <masurka@google.com>
Matt Pearring <broskies@google.com>
Matt Reiferson <mreiferson@gmail.com>
Matt Robenolt <matt@ydekproductions.com>
Matt Strong <mstrong1341@gmail.com>
@@ -1740,12 +1659,9 @@ Matthew Denton <mdenton@skyportsystems.com>
Matthew Holt <Matthew.Holt+git@gmail.com>
Matthew Horsnell <matthew.horsnell@gmail.com>
Matthew Waters <mwwaters@gmail.com>
Matthias Frei <matthias.frei@inf.ethz.ch>
Matthieu Hauglustaine <matt.hauglustaine@gmail.com>
Matthieu Olivier <olivier.matthieu@gmail.com>
Matthijs Kooijman <matthijs@stdin.nl>
Mattias Appelgren <mattias@ppelgren.se>
Mauricio Alvarado <mauricio.alvarado@leftfieldlabs.com>
Max Drosdo.www <g1ran1q@gmail.com>
Max Riveiro <kavu13@gmail.com>
Max Schmitt <max@schmitt.mx>
@@ -1761,11 +1677,9 @@ Máximo Cuadros Ortiz <mcuadros@gmail.com>
Maxwell Krohn <themax@gmail.com>
Maya Rashish <maya@NetBSD.org>
Mayank Kumar <krmayankk@gmail.com>
Mehrad Sadeghi <2012.linkinpark@gmail.com>
Meir Fischer <meirfischer@gmail.com>
Meng Zhuo <mengzhuo1203@gmail.com> <mzh@golangcn.org>
Mhd Sulhan <m.shulhan@gmail.com>
Mia Zhu <CrystalZhu1025getu@gmail.com>
Micah Stetson <micah.stetson@gmail.com>
Michael Anthony Knyszek <mknyszek@google.com>
Michael Brandenburg <mbrandenburg@bolste.com>
@@ -1816,10 +1730,8 @@ Michal Franc <lam.michal.franc@gmail.com>
Michał Łowicki <mlowicki@gmail.com>
Michal Pristas <michal.pristas@gmail.com>
Michal Rostecki <mrostecki@suse.de>
Michal Stokluska <mstoklus@redhat.com>
Michalis Kargakis <michaliskargakis@gmail.com>
Michel Lespinasse <walken@google.com>
Michel Levieux <mlevieux42@gmail.com>
Michele Di Pede <michele.di.pede@gmail.com>
Mickael Kerjean <mickael.kerjean@gmail.com>
Mickey Reiss <mickeyreiss@gmail.com>
@@ -1878,9 +1790,7 @@ Muir Manders <muir@mnd.rs>
Mukesh Sharma <sharma.mukesh439@gmail.com>
Mura Li <mura_li@castech.com.tw>
Mykhailo Lesyk <mikhail@lesyk.org>
Nahum Shalman <nahamu@gmail.com>
Naman Aggarwal <aggarwal.nam@gmail.com>
Naman Gera <namangera15@gmail.com>
Nan Deng <monnand@gmail.com>
Nao Yonashiro <owan.orisano@gmail.com>
Naoki Kanatani <k12naoki@gmail.com>
@@ -1908,7 +1818,6 @@ Neven Sajko <nsajko@gmail.com>
Nevins Bartolomeo <nevins.bartolomeo@gmail.com>
Niall Sheridan <nsheridan@gmail.com>
Nic Day <nic.day@me.com>
Nicholas Asimov <nicholas@asimov.me>
Nicholas Katsaros <nick@nickkatsaros.com>
Nicholas Maniscalco <nicholas@maniscalco.com>
Nicholas Ng <nickng@nickng.io>
@@ -1938,7 +1847,6 @@ Nik Nyby <nnyby@columbia.edu>
Nikhil Benesch <nikhil.benesch@gmail.com>
Nikita Gillmann <nikita@n0.is> <ng0@n0.is>
Nikita Kryuchkov <nkryuchkov10@gmail.com>
Nikita Melekhin <nimelehin@gmail.com>
Nikita Vanyasin <nikita.vanyasin@gmail.com>
Niklas Schnelle <niklas.schnelle@gmail.com>
Niko Dziemba <niko@dziemba.com>
@@ -1950,7 +1858,6 @@ Niranjan Godbole <niranjan8192@gmail.com>
Nishanth Shanmugham <nishanth.gerrard@gmail.com>
Noah Campbell <noahcampbell@gmail.com>
Noah Goldman <noahg34@gmail.com>
Noah Santschi-Cooney <noah@santschi-cooney.ch>
Noble Johnson <noblepoly@gmail.com>
Nodir Turakulov <nodir@google.com>
Noel Georgi <git@frezbo.com>
@@ -1987,7 +1894,6 @@ Pablo Rozas Larraondo <pablo.larraondo@anu.edu.au>
Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
Padraig Kitterick <padraigkitterick@gmail.com>
Pallat Anchaleechamaikorn <yod.pallat@gmail.com>
Pan Chenglong <1004907659@qq.com>
Panos Georgiadis <pgeorgiadis@suse.de>
Pantelis Sampaziotis <psampaz@gmail.com>
Paolo Giarrusso <p.giarrusso@gmail.com>
@@ -2041,7 +1947,6 @@ Paulo Casaretto <pcasaretto@gmail.com>
Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Paulo Gomes <paulo.gomes.uk@gmail.com>
Pavel Paulau <pavel.paulau@gmail.com>
Pavel Watson <watsonpavel@gmail.com>
Pavel Zinovkin <pavel.zinovkin@gmail.com>
Pavlo Sumkin <ymkins@gmail.com>
Pawel Knap <pawelknap88@gmail.com>
@@ -2049,8 +1954,6 @@ Pawel Szczur <filemon@google.com>
Paweł Szulik <pawel.szulik@intel.com>
Pei Xian Chee <luciolas1991@gmail.com>
Pei-Ming Wu <p408865@gmail.com>
Pen Tree <appletree2479@outlook.com>
Peng Gao <peng.gao.dut@gmail.com>
Percy Wegmann <ox.to.a.cart@gmail.com>
Perry Abbott <perry.j.abbott@gmail.com>
Petar Dambovaliev <petar.atanasov.1987@gmail.com>
@@ -2089,7 +1992,6 @@ Philip Brown <phil@bolthole.com>
Philip Hofer <phofer@umich.edu>
Philip K. Warren <pkwarren@gmail.com>
Philip Nelson <me@pnelson.ca>
Philipp Sauter <sauterp@protonmail.com>
Philipp Stephani <phst@google.com>
Phillip Campbell <15082+phillc@users.noreply.github.com>
Pierre Carru <pierre.carru@eshard.com>
@@ -2105,7 +2007,6 @@ Poh Zi How <poh.zihow@gmail.com>
Polina Osadcha <polliosa@google.com>
Pontus Leitzler <leitzler@gmail.com>
Povilas Versockas <p.versockas@gmail.com>
Prajwal Koirala <16564273+Prajwal-Koirala@users.noreply.github.com>
Prasanga Siripala <pj@pjebs.com.au>
Prasanna Swaminathan <prasanna@mediamath.com>
Prashant Agrawal <prashant.a.vjti@gmail.com>
@@ -2126,13 +2027,11 @@ Quim Muntal <quimmuntal@gmail.com>
Quinn Slack <sqs@sourcegraph.com>
Quinten Yearsley <qyearsley@chromium.org>
Quoc-Viet Nguyen <afelion@gmail.com>
Rabin Gaire <rabingaire20@gmail.com>
Radek Simko <radek.simko@gmail.com>
Radek Sohlich <sohlich@gmail.com>
Radu Berinde <radu@cockroachlabs.com>
Rafal Jeczalik <rjeczalik@gmail.com>
Raghavendra Nagaraj <jamdagni86@gmail.com>
Rahul Bajaj <rahulrb0509@gmail.com>
Rahul Chaudhry <rahulchaudhry@chromium.org>
Rahul Wadhwani <rahulwadhwani21@gmail.com>
Raif S. Naffah <go@naffah-raif.name>
@@ -2142,14 +2041,12 @@ Rajender Reddy Kompally <rajenderreddykompally@gmail.com>
Ralph Corderoy <ralph@inputplus.co.uk>
Ramazan AYYILDIZ <rayyildiz@gmail.com>
Ramesh Dharan <dharan@google.com>
Randy Reddig <randy@alta.software>
Raph Levien <raph@google.com>
Raphael Geronimi <raphael.geronimi@gmail.com>
Raul Silvera <rsilvera@google.com>
Ravil Bikbulatov <weeellz12@gmail.com>
RaviTeja Pothana <ravi.tezu@gmail.com>
Ray Tung <rtung@thoughtworks.com>
Ray Wu <ray@liftoff.io>
Raymond Kazlauskas <raima220@gmail.com>
Rebecca Stambler <rstambler@golang.org>
Reilly Watson <reillywatson@gmail.com>
@@ -2169,7 +2066,6 @@ Richard Eric Gavaletz <gavaletz@gmail.com>
Richard Gibson <richard.gibson@gmail.com>
Richard Miller <miller.research@gmail.com>
Richard Musiol <mail@richard-musiol.de> <neelance@gmail.com>
Richard Pickering <richard.pickering@hotmail.co.uk>
Richard Ulmer <codesoap@mailbox.org>
Richard Wilkes <wilkes@me.com>
Rick Arnold <rickarnoldjr@gmail.com>
@@ -2228,7 +2124,6 @@ Rowan Worth <sqweek@gmail.com>
Rudi Kramer <rudi.kramer@gmail.com>
Rui Ueyama <ruiu@google.com>
Ruixin Bao <ruixin.bao@ibm.com>
Ruslan Andreev <ruslan.andreev@huawei.com>
Ruslan Nigmatullin <elessar@dropbox.com>
Russ Cox <rsc@golang.org>
Russell Haering <russellhaering@gmail.com>
@@ -2246,7 +2141,6 @@ Ryan Seys <ryan@ryanseys.com>
Ryan Slade <ryanslade@gmail.com>
Ryan Zhang <ryan.zhang@docker.com>
Ryoichi KATO <ryo1kato@gmail.com>
Ryoya Sekino <ryoyasekino1993@gmail.com>
Ryuji Iwata <qt.luigi@gmail.com>
Ryuma Yoshida <ryuma.y1117@gmail.com>
Ryuzo Yamamoto <ryuzo.yamamoto@gmail.com>
@@ -2282,10 +2176,8 @@ Sardorbek Pulatov <sardorbek.pulatov@outlook.com>
Sascha Brawer <sascha@brawer.ch>
Sasha Lionheart <lionhearts@google.com>
Sasha Sobol <sasha@scaledinference.com>
Satoru Kitaguchi <rule.the.fate.myfirststory@gmail.com>
Scott Barron <scott.barron@github.com>
Scott Bell <scott@sctsm.com>
Scott Cotton <scott@mindowl.com>
Scott Crunkleton <crunk1@gmail.com>
Scott Ferguson <scottwferg@gmail.com>
Scott Lawrence <bytbox@gmail.com>
@@ -2299,7 +2191,6 @@ Sean Chittenden <seanc@joyent.com>
Sean Christopherson <sean.j.christopherson@intel.com>
Sean Dolphin <Sean.Dolphin@kpcompass.com>
Sean Harger <sharger@google.com>
Sean Harrington <sean.harrington@leftfieldlabs.com>
Sean Hildebrand <seanwhildebrand@gmail.com>
Sean Liao <seankhliao@gmail.com>
Sean Rees <sean@erifax.org>
@@ -2321,7 +2212,6 @@ Sergey Dobrodey <sergey.dobrodey@synesis.ru>
Sergey Frolov <sfrolov@google.com>
Sergey Glushchenko <gsserge@gmail.com>
Sergey Ivanov <ser1325@gmail.com>
Sergey Kacheev <S.Kacheev@gmail.com>
Sergey Lukjanov <me@slukjanov.name>
Sergey Mishin <sergeymishine@gmail.com>
Sergey Mudrik <sergey.mudrik@gmail.com>
@@ -2333,7 +2223,6 @@ Serhat Giydiren <serhatgiydiren@gmail.com>
Serhii Aheienko <serhii.aheienko@gmail.com>
Seth Hoenig <seth.a.hoenig@gmail.com>
Seth Vargo <sethvargo@gmail.com>
Shaba Abhiram <shabarivas.abhiram@gmail.com>
Shahar Kohanim <skohanim@gmail.com>
Shailesh Suryawanshi <ss.shailesh28@gmail.com>
Shamil Garatuev <garatuev@gmail.com>
@@ -2361,13 +2250,9 @@ Shivakumar GN <shivakumar.gn@gmail.com>
Shivani Singhal <shivani.singhal2804@gmail.com>
Shivansh Rai <shivansh@freebsd.org>
Shivashis Padhi <shivashispadhi@gmail.com>
Shoshin Nikita <shoshin_nikita@fastmail.com>
Shota Sugiura <s.shota.710.3506@gmail.com>
Shubham Sharma <shubham.sha12@gmail.com>
Shuhei Takahashi <nya@chromium.org>
Shun Fan <sfan@google.com>
Silvan Jegen <s.jegen@gmail.com>
Simão Gomes Viana <simaogmv@gmail.com>
Simarpreet Singh <simar@linux.com>
Simon Drake <simondrake1990@gmail.com>
Simon Ferquel <simon.ferquel@docker.com>
@@ -2382,16 +2267,13 @@ Sina Siadat <siadat@gmail.com>
Sjoerd Siebinga <sjoerd.siebinga@gmail.com>
Sokolov Yura <funny.falcon@gmail.com>
Song Gao <song@gao.io>
Song Lim <songlim327@gmail.com>
Songjiayang <songjiayang1@gmail.com>
Songlin Jiang <hollowman@hollowman.ml>
Soojin Nam <jsunam@gmail.com>
Søren L. Hansen <soren@linux2go.dk>
Sparrow Li <liyuancylx@gmail.com>
Spencer Kocot <spencerkocot@gmail.com>
Spencer Nelson <s@spenczar.com>
Spencer Tung <spencertung@google.com>
Spenser Black <spenserblack01@gmail.com>
Spring Mc <heresy.mc@gmail.com>
Srdjan Petrovic <spetrovic@google.com>
Sridhar Venkatakrishnan <sridhar@laddoo.net>
@@ -2442,7 +2324,6 @@ Suyash <dextrous93@gmail.com>
Suzy Mueller <suzmue@golang.org>
Sven Almgren <sven@tras.se>
Sven Blumenstein <svbl@google.com>
Sven Lee <lee1300394324@gmail.com>
Sven Taute <sven.taute@gmail.com>
Sylvain Zimmer <sylvain@sylvainzimmer.com>
Syohei YOSHIDA <syohex@gmail.com>
@@ -2525,14 +2406,12 @@ Tiwei Bie <tiwei.btw@antgroup.com>
Tobias Assarsson <tobias.assarsson@gmail.com>
Tobias Columbus <tobias.columbus@gmail.com> <tobias.columbus@googlemail.com>
Tobias Klauser <tklauser@distanz.ch>
Tobias Kohlbau <tobias@kohlbau.de>
Toby Burress <kurin@google.com>
Todd Kulesza <tkulesza@google.com>
Todd Neal <todd@tneal.org>
Todd Wang <toddwang@gmail.com>
Tom Anthony <git@tomanthony.co.uk>
Tom Bergan <tombergan@google.com>
Tom Freudenberg <tom.freudenberg@4commerce.de>
Tom Heng <zhm20070928@gmail.com>
Tom Lanyon <tomlanyon@google.com>
Tom Levy <tomlevy93@gmail.com>
@@ -2561,7 +2440,6 @@ Toshiki Shima <hayabusa1419@gmail.com>
Totoro W <tw19881113@gmail.com>
Travis Bischel <travis.bischel@gmail.com>
Travis Cline <travis.cline@gmail.com>
Trevor Dixon <trevordixon@gmail.com>
Trevor Strohman <trevor.strohman@gmail.com>
Trey Lawrence <lawrence.trey@gmail.com>
Trey Roessig <trey.roessig@gmail.com>
@@ -2585,7 +2463,6 @@ Tzach Shabtay <tzachshabtay@gmail.com>
Tzu-Chiao Yeh <su3g4284zo6y7@gmail.com>
Tzu-Jung Lee <roylee17@currant.com>
Udalov Max <re.udalov@gmail.com>
Uddeshya Singh <singhuddeshyaofficial@gmail.com>
Ugorji Nwoke <ugorji@gmail.com>
Ulf Holm Nielsen <doktor@dyregod.dk>
Ulrich Kunitz <uli.kunitz@gmail.com>
@@ -2598,7 +2475,6 @@ Vadim Grek <vadimprog@gmail.com>
Vadim Vygonets <unixdj@gmail.com>
Val Polouchkine <vpolouch@justin.tv>
Valentin Vidic <vvidic@valentin-vidic.from.hr>
Vaughn Iverson <vsivsi@yahoo.com>
Vee Zhang <veezhang@126.com> <vveezhang@gmail.com>
Vega Garcia Luis Alfonso <vegacom@gmail.com>
Venil Noronha <veniln@vmware.com>
@@ -2615,7 +2491,6 @@ Vincent Batts <vbatts@hashbangbash.com> <vbatts@gmail.com>
Vincent Vanackere <vincent.vanackere@gmail.com>
Vinu Rajashekhar <vinutheraj@gmail.com>
Vish Subramanian <vish@google.com>
Vishal Dalwadi <dalwadivishal26@gmail.com>
Vishvananda Ishaya <vishvananda@gmail.com>
Visweswara R <r.visweswara@gmail.com>
Vitaly Zdanevich <zdanevich.vitaly@ya.ru>
@@ -2651,7 +2526,6 @@ Wei Guangjing <vcc.163@gmail.com>
Wei Xiao <wei.xiao@arm.com>
Wei Xikai <xykwei@gmail.com>
Weichao Tang <tevic.tt@gmail.com>
Weixie Cui <cuiweixie@gmail.com> <523516579@qq.com>
Wembley G. Leach, Jr <wembley.gl@gmail.com>
Wenlei (Frank) He <wlhe@google.com>
Wenzel Lowe <lowewenzel@gmail.com>
@@ -2667,7 +2541,6 @@ Willem van der Schyff <willemvds@gmail.com>
William Chan <willchan@chromium.org>
William Chang <mr.williamchang@gmail.com>
William Josephson <wjosephson@gmail.com>
William Langford <wlangfor@gmail.com>
William Orr <will@worrbase.com> <ay1244@gmail.com>
William Poussier <william.poussier@gmail.com>
Wisdom Omuya <deafgoat@gmail.com>
@@ -2676,7 +2549,6 @@ Xi Ruoyao <xry23333@gmail.com>
Xia Bin <snyh@snyh.org>
Xiangdong Ji <xiangdong.ji@arm.com>
Xiaodong Liu <teaofmoli@gmail.com>
Xing Gao <18340825824@163.com>
Xing Xing <mikespook@gmail.com>
Xingqang Bai <bxq2011hust@qq.com>
Xu Fei <badgangkiller@gmail.com>
@@ -2698,7 +2570,6 @@ Yasha Bubnov <girokompass@gmail.com>
Yasser Abdolmaleki <yasser@yasser.ca>
Yasuharu Goto <matope.ono@gmail.com>
Yasuhiro Matsumoto <mattn.jp@gmail.com>
Yasutaka Shinzaki <shinzaki@yasu26.tech>
Yasuyuki Oka <yasuyk@gmail.com>
Yazen Shunnar <yazen.shunnar@gmail.com>
Yestin Sun <ylh@pdx.edu>
@@ -2711,18 +2582,14 @@ Yorman Arias <cixtords@gmail.com>
Yoshiyuki Kanno <nekotaroh@gmail.com> <yoshiyuki.kanno@stoic.co.jp>
Yoshiyuki Mineo <yoshiyuki.mineo@gmail.com>
Yosuke Akatsuka <yosuke.akatsuka@gmail.com>
Youfu Zhang <zhangyoufu@gmail.com>
Yu Heng Zhang <annita.zhang@cn.ibm.com>
Yu Xuan Zhang <zyxsh@cn.ibm.com>
Yu, Li-Yu <afg984@gmail.com>
Yuichi Kishimoto <yk2220s@gmail.com>
Yuichi Nishiwaki <yuichi.nishiwaki@gmail.com>
Yuji Yaginuma <yuuji.yaginuma@gmail.com>
Yuki Ito <mrno110y@gmail.com>
Yuki OKUSHI <huyuumi.dev@gmail.com>
Yuki Yugui Sonoda <yugui@google.com>
Yukihiro Nishinaka <6elpinal@gmail.com>
YunQiang Su <syq@debian.org>
Yury Smolsky <yury@smolsky.by>
Yusuke Kagiwada <block.rxckin.beats@gmail.com>
Yuusei Kuwana <kuwana@kumama.org>
@@ -2731,7 +2598,6 @@ Yves Junqueira <yvesj@google.com> <yves.junqueira@gmail.com>
Zac Bergquist <zbergquist99@gmail.com>
Zach Bintliff <zbintliff@gmail.com>
Zach Gershman <zachgersh@gmail.com>
Zach Hoffman <zrhoffman@apache.org>
Zach Jones <zachj1@gmail.com>
Zachary Amsden <zach@thundertoken.com>
Zachary Gershman <zgershman@pivotal.io>
@@ -2750,7 +2616,6 @@ Zhou Peng <p@ctriple.cn>
Ziad Hatahet <hatahet@gmail.com>
Ziheng Liu <lzhfromustc@gmail.com>
Zorion Arrizabalaga <zorionk@gmail.com>
Zvonimir Pavlinovic <zpavlinovic@google.com>
Zyad A. Ali <zyad.ali.me@gmail.com>
Максадбек Ахмедов <a.maksadbek@gmail.com>
Максим Федосеев <max.faceless.frei@gmail.com>

46
README.go2go.md Normal file
View File

@@ -0,0 +1,46 @@
# dev.go2go branch
This branch provides an experimental go2go tool for testing the use of
the generics design draft.
This branch was published in 2020 and is no longer being maintained.
The [generics
proposal](https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md)
has [been accepted](https://golang.org/issue/43651) and development is
now focused on implementing the proposal in the ordinary Go tools.
## Original README
This branch contains a type checker and a translation tool for
experimentation with generics in Go.
This implements the [generics design draft](https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md).
You can build this branch [as
usual](https://golang.org/doc/install/source).
You can then use the new `go2go` tool.
Write your generic code in a file with the extension `.go2` instead of
`.go`.
Run it using `go tool go2go run x.go2`.
There are some sample packages in `cmd/go2go/testdata/go2path/src`.
You can see the full documentation for the tool by running `go doc
cmd/go2go`.
The `go2go` tool will look for `.go2` files using the environment variable `GO2PATH`.
You can find some useful packages that you might want to experiment with by
setting `GO2PATH=$GOROOT/src/cmd/go2go/testdata/go2path`.
If you find bugs in the updated type checker or in the translation
tool, they should be filed in the [standard Go issue
tracker](https://golang.org/issue).
Please start the issue title with `cmd/go2go`.
Note that the issue tracker should only be used for reporting bugs in
the tools, not for discussion of changes to the language.
Unlike typical dev branches, we do not intend any eventual merge of
this code into the master branch.
We will update it for bug fixes and change to the generic design
draft.
If a generics language proposal is accepted, it will be implemented in
the standard compiler, not via a translation tool.
The necessary changes to the go/* packages (go/ast, go/parser, and so
forth) may re-use code from this prototype but will follow the usual
code review process.

View File

@@ -1,7 +1,4 @@
pkg encoding/json, method (*RawMessage) MarshalJSON() ([]uint8, error)
pkg math, const MaxFloat64 = 1.79769e+308 // 179769313486231570814527423731704356798100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
pkg math, const SmallestNonzeroFloat32 = 1.4013e-45 // 17516230804060213386546619791123951641/12500000000000000000000000000000000000000000000000000000000000000000000000000000000
pkg math, const SmallestNonzeroFloat64 = 4.94066e-324 // 4940656458412465441765687928682213723651/1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
pkg math/big, const MaxBase = 36
pkg math/big, type Word uintptr
pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)

View File

@@ -1,195 +0,0 @@
pkg archive/zip, method (*File) OpenRaw() (io.Reader, error)
pkg archive/zip, method (*Writer) Copy(*File) error
pkg archive/zip, method (*Writer) CreateRaw(*FileHeader) (io.Writer, error)
pkg compress/lzw, method (*Reader) Close() error
pkg compress/lzw, method (*Reader) Read([]uint8) (int, error)
pkg compress/lzw, method (*Reader) Reset(io.Reader, Order, int)
pkg compress/lzw, method (*Writer) Close() error
pkg compress/lzw, method (*Writer) Reset(io.Writer, Order, int)
pkg compress/lzw, method (*Writer) Write([]uint8) (int, error)
pkg compress/lzw, type Reader struct
pkg compress/lzw, type Writer struct
pkg crypto/tls, method (*CertificateRequestInfo) Context() context.Context
pkg crypto/tls, method (*ClientHelloInfo) Context() context.Context
pkg crypto/tls, method (*Conn) HandshakeContext(context.Context) error
pkg database/sql, method (*NullByte) Scan(interface{}) error
pkg database/sql, method (*NullInt16) Scan(interface{}) error
pkg database/sql, method (NullByte) Value() (driver.Value, error)
pkg database/sql, method (NullInt16) Value() (driver.Value, error)
pkg database/sql, type NullByte struct
pkg database/sql, type NullByte struct, Byte uint8
pkg database/sql, type NullByte struct, Valid bool
pkg database/sql, type NullInt16 struct
pkg database/sql, type NullInt16 struct, Int16 int16
pkg database/sql, type NullInt16 struct, Valid bool
pkg debug/elf, const SHT_MIPS_ABIFLAGS = 1879048234
pkg debug/elf, const SHT_MIPS_ABIFLAGS SectionType
pkg encoding/csv, method (*Reader) FieldPos(int) (int, int)
pkg go/build, type Context struct, ToolTags []string
pkg go/parser, const SkipObjectResolution = 64
pkg go/parser, const SkipObjectResolution Mode
pkg image, method (*Alpha) RGBA64At(int, int) color.RGBA64
pkg image, method (*Alpha) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*Alpha16) RGBA64At(int, int) color.RGBA64
pkg image, method (*Alpha16) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*CMYK) RGBA64At(int, int) color.RGBA64
pkg image, method (*CMYK) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*Gray) RGBA64At(int, int) color.RGBA64
pkg image, method (*Gray) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*Gray16) RGBA64At(int, int) color.RGBA64
pkg image, method (*Gray16) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*NRGBA) RGBA64At(int, int) color.RGBA64
pkg image, method (*NRGBA) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*NRGBA64) RGBA64At(int, int) color.RGBA64
pkg image, method (*NRGBA64) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*NYCbCrA) RGBA64At(int, int) color.RGBA64
pkg image, method (*Paletted) RGBA64At(int, int) color.RGBA64
pkg image, method (*Paletted) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*RGBA) RGBA64At(int, int) color.RGBA64
pkg image, method (*RGBA) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*Uniform) RGBA64At(int, int) color.RGBA64
pkg image, method (*YCbCr) RGBA64At(int, int) color.RGBA64
pkg image, method (Rectangle) RGBA64At(int, int) color.RGBA64
pkg image, type RGBA64Image interface { At, Bounds, ColorModel, RGBA64At }
pkg image, type RGBA64Image interface, At(int, int) color.Color
pkg image, type RGBA64Image interface, Bounds() Rectangle
pkg image, type RGBA64Image interface, ColorModel() color.Model
pkg image, type RGBA64Image interface, RGBA64At(int, int) color.RGBA64
pkg image/draw, type RGBA64Image interface { At, Bounds, ColorModel, RGBA64At, Set, SetRGBA64 }
pkg image/draw, type RGBA64Image interface, At(int, int) color.Color
pkg image/draw, type RGBA64Image interface, Bounds() image.Rectangle
pkg image/draw, type RGBA64Image interface, ColorModel() color.Model
pkg image/draw, type RGBA64Image interface, RGBA64At(int, int) color.RGBA64
pkg image/draw, type RGBA64Image interface, Set(int, int, color.Color)
pkg image/draw, type RGBA64Image interface, SetRGBA64(int, int, color.RGBA64)
pkg io/fs, func FileInfoToDirEntry(FileInfo) DirEntry
pkg math, const MaxFloat64 = 1.79769e+308 // 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368
pkg math, const MaxInt = 9223372036854775807
pkg math, const MaxInt ideal-int
pkg math, const MaxUint = 18446744073709551615
pkg math, const MaxUint ideal-int
pkg math, const MinInt = -9223372036854775808
pkg math, const MinInt ideal-int
pkg math, const SmallestNonzeroFloat32 = 1.4013e-45 // 1/713623846352979940529142984724747568191373312
pkg math, const SmallestNonzeroFloat64 = 4.94066e-324 // 1/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784
pkg net, method (*ParseError) Temporary() bool
pkg net, method (*ParseError) Timeout() bool
pkg net, method (IP) IsPrivate() bool
pkg net/http, func AllowQuerySemicolons(Handler) Handler
pkg net/url, method (Values) Has(string) bool
pkg reflect, func VisibleFields(Type) []StructField
pkg reflect, method (Method) IsExported() bool
pkg reflect, method (StructField) IsExported() bool
pkg reflect, method (Value) CanConvert(Type) bool
pkg runtime/cgo (darwin-amd64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (darwin-amd64-cgo), method (Handle) Delete()
pkg runtime/cgo (darwin-amd64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (darwin-amd64-cgo), type Handle uintptr
pkg runtime/cgo (freebsd-386-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (freebsd-386-cgo), method (Handle) Delete()
pkg runtime/cgo (freebsd-386-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (freebsd-386-cgo), type Handle uintptr
pkg runtime/cgo (freebsd-amd64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (freebsd-amd64-cgo), method (Handle) Delete()
pkg runtime/cgo (freebsd-amd64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (freebsd-amd64-cgo), type Handle uintptr
pkg runtime/cgo (freebsd-arm-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (freebsd-arm-cgo), method (Handle) Delete()
pkg runtime/cgo (freebsd-arm-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (freebsd-arm-cgo), type Handle uintptr
pkg runtime/cgo (linux-386-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (linux-386-cgo), method (Handle) Delete()
pkg runtime/cgo (linux-386-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (linux-386-cgo), type Handle uintptr
pkg runtime/cgo (linux-amd64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (linux-amd64-cgo), method (Handle) Delete()
pkg runtime/cgo (linux-amd64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (linux-amd64-cgo), type Handle uintptr
pkg runtime/cgo (linux-arm-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (linux-arm-cgo), method (Handle) Delete()
pkg runtime/cgo (linux-arm-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (linux-arm-cgo), type Handle uintptr
pkg runtime/cgo (netbsd-386-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (netbsd-386-cgo), method (Handle) Delete()
pkg runtime/cgo (netbsd-386-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (netbsd-386-cgo), type Handle uintptr
pkg runtime/cgo (netbsd-amd64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (netbsd-amd64-cgo), method (Handle) Delete()
pkg runtime/cgo (netbsd-amd64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (netbsd-amd64-cgo), type Handle uintptr
pkg runtime/cgo (netbsd-arm-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (netbsd-arm-cgo), method (Handle) Delete()
pkg runtime/cgo (netbsd-arm-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (netbsd-arm-cgo), type Handle uintptr
pkg runtime/cgo (netbsd-arm64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (netbsd-arm64-cgo), method (Handle) Delete()
pkg runtime/cgo (netbsd-arm64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (netbsd-arm64-cgo), type Handle uintptr
pkg runtime/cgo (openbsd-386-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (openbsd-386-cgo), method (Handle) Delete()
pkg runtime/cgo (openbsd-386-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (openbsd-386-cgo), type Handle uintptr
pkg runtime/cgo (openbsd-amd64-cgo), func NewHandle(interface{}) Handle
pkg runtime/cgo (openbsd-amd64-cgo), method (Handle) Delete()
pkg runtime/cgo (openbsd-amd64-cgo), method (Handle) Value() interface{}
pkg runtime/cgo (openbsd-amd64-cgo), type Handle uintptr
pkg strconv, func QuotedPrefix(string) (string, error)
pkg sync/atomic, method (*Value) CompareAndSwap(interface{}, interface{}) bool
pkg sync/atomic, method (*Value) Swap(interface{}) interface{}
pkg syscall (netbsd-386), const SYS_WAIT6 = 481
pkg syscall (netbsd-386), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-386), const WEXITED = 32
pkg syscall (netbsd-386), const WEXITED ideal-int
pkg syscall (netbsd-386-cgo), const SYS_WAIT6 = 481
pkg syscall (netbsd-386-cgo), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-386-cgo), const WEXITED = 32
pkg syscall (netbsd-386-cgo), const WEXITED ideal-int
pkg syscall (netbsd-amd64), const SYS_WAIT6 = 481
pkg syscall (netbsd-amd64), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-amd64), const WEXITED = 32
pkg syscall (netbsd-amd64), const WEXITED ideal-int
pkg syscall (netbsd-amd64-cgo), const SYS_WAIT6 = 481
pkg syscall (netbsd-amd64-cgo), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-amd64-cgo), const WEXITED = 32
pkg syscall (netbsd-amd64-cgo), const WEXITED ideal-int
pkg syscall (netbsd-arm), const SYS_WAIT6 = 481
pkg syscall (netbsd-arm), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-arm), const WEXITED = 32
pkg syscall (netbsd-arm), const WEXITED ideal-int
pkg syscall (netbsd-arm-cgo), const SYS_WAIT6 = 481
pkg syscall (netbsd-arm-cgo), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-arm-cgo), const WEXITED = 32
pkg syscall (netbsd-arm-cgo), const WEXITED ideal-int
pkg syscall (netbsd-arm64), const SYS_WAIT6 = 481
pkg syscall (netbsd-arm64), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-arm64), const WEXITED = 32
pkg syscall (netbsd-arm64), const WEXITED ideal-int
pkg syscall (netbsd-arm64-cgo), const SYS_WAIT6 = 481
pkg syscall (netbsd-arm64-cgo), const SYS_WAIT6 ideal-int
pkg syscall (netbsd-arm64-cgo), const WEXITED = 32
pkg syscall (netbsd-arm64-cgo), const WEXITED ideal-int
pkg syscall (openbsd-386), const MSG_CMSG_CLOEXEC = 2048
pkg syscall (openbsd-386), const MSG_CMSG_CLOEXEC ideal-int
pkg syscall (openbsd-386-cgo), const MSG_CMSG_CLOEXEC = 2048
pkg syscall (openbsd-386-cgo), const MSG_CMSG_CLOEXEC ideal-int
pkg syscall (openbsd-amd64), const MSG_CMSG_CLOEXEC = 2048
pkg syscall (openbsd-amd64), const MSG_CMSG_CLOEXEC ideal-int
pkg syscall (openbsd-amd64-cgo), const MSG_CMSG_CLOEXEC = 2048
pkg syscall (openbsd-amd64-cgo), const MSG_CMSG_CLOEXEC ideal-int
pkg syscall (windows-386), type SysProcAttr struct, AdditionalInheritedHandles []Handle
pkg syscall (windows-386), type SysProcAttr struct, ParentProcess Handle
pkg syscall (windows-amd64), type SysProcAttr struct, AdditionalInheritedHandles []Handle
pkg syscall (windows-amd64), type SysProcAttr struct, ParentProcess Handle
pkg testing, method (*B) Setenv(string, string)
pkg testing, method (*T) Setenv(string, string)
pkg testing, type TB interface, Setenv(string, string)
pkg text/template/parse, const SkipFuncCheck = 2
pkg text/template/parse, const SkipFuncCheck Mode
pkg time, const Layout = "01/02 03:04:05PM '06 -0700"
pkg time, const Layout ideal-string
pkg time, func UnixMicro(int64) Time
pkg time, func UnixMilli(int64) Time
pkg time, method (Time) GoString() string
pkg time, method (Time) IsDST() bool
pkg time, method (Time) UnixMicro() int64
pkg time, method (Time) UnixMilli() int64

View File

@@ -1,2 +1,2 @@
branch: dev.typeparams
parent-branch: master
branch: dev.go2go
parent-branch: master

View File

@@ -166,7 +166,7 @@ jumps and branches.
</li>
<li>
<code>SP</code>: Stack pointer: the highest address within the local stack frame.
<code>SP</code>: Stack pointer: top of stack.
</li>
</ul>
@@ -216,7 +216,7 @@ If a Go prototype does not name its result, the expected assembly name is <code>
The <code>SP</code> pseudo-register is a virtual stack pointer
used to refer to frame-local variables and the arguments being
prepared for function calls.
It points to the highest address within the local stack frame, so references should use negative offsets
It points to the top of the local stack frame, so references should use negative offsets
in the range [framesize, 0):
<code>x-8(SP)</code>, <code>y-4(SP)</code>, and so on.
</p>
@@ -409,7 +409,7 @@ The linker will choose one of the duplicates to use.
(For <code>TEXT</code> items.)
Don't insert the preamble to check if the stack must be split.
The frame for the routine, plus anything it calls, must fit in the
spare space remaining in the current stack segment.
spare space at the top of the stack segment.
Used to protect routines such as the stack splitting code itself.
</li>
<li>
@@ -460,7 +460,7 @@ Only valid on functions that declare a frame size of 0.
<code>TOPFRAME</code> = 2048
<br>
(For <code>TEXT</code> items.)
Function is the outermost frame of the call stack. Traceback should stop at this function.
Function is the top of the call stack. Traceback should stop at this function.
</li>
</ul>
@@ -827,6 +827,10 @@ The other codes are <code>-&gt;</code> (arithmetic right shift),
<h3 id="arm64">ARM64</h3>
<p>
The ARM64 port is in an experimental state.
</p>
<p>
<code>R18</code> is the "platform register", reserved on the Apple platform.
To prevent accidental misuse, the register is named <code>R18_PLATFORM</code>.

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of Jul 26, 2021",
"Subtitle": "Version of Feb 24, 2021",
"Path": "/ref/spec"
}-->
@@ -490,8 +490,8 @@ After a backslash, certain single-character escapes represent special values:
\n U+000A line feed or newline
\r U+000D carriage return
\t U+0009 horizontal tab
\v U+000B vertical tab
\\ U+005C backslash
\v U+000b vertical tab
\\ U+005c backslash
\' U+0027 single quote (valid escape only within rune literals)
\" U+0022 double quote (valid escape only within string literals)
</pre>
@@ -3681,8 +3681,8 @@ The bitwise logical and shift operators apply to integers only.
^ bitwise XOR integers
&amp;^ bit clear (AND NOT) integers
&lt;&lt; left shift integer &lt;&lt; integer &gt;= 0
&gt;&gt; right shift integer &gt;&gt; integer &gt;= 0
&lt;&lt; left shift integer &lt;&lt; unsigned integer
&gt;&gt; right shift integer &gt;&gt; unsigned integer
</pre>
@@ -4164,10 +4164,6 @@ in any of these cases:
<li>
<code>x</code> is a string and <code>T</code> is a slice of bytes or runes.
</li>
<li>
<code>x</code> is a slice, <code>T</code> is a pointer to an array,
and the slice and array types have <a href="#Type_identity">identical</a> element types.
</li>
</ul>
<p>
@@ -4318,28 +4314,6 @@ MyRunes("白鵬翔") // []rune{0x767d, 0x9d6c, 0x7fd4}
</li>
</ol>
<h4 id="Conversions_from_slice_to_array_pointer">Conversions from slice to array pointer</h4>
<p>
Converting a slice to an array pointer yields a pointer to the underlying array of the slice.
If the <a href="#Length_and_capacity">length</a> of the slice is less than the length of the array,
a <a href="#Run_time_panics">run-time panic</a> occurs.
</p>
<pre>
s := make([]byte, 2, 4)
s0 := (*[0]byte)(s) // s0 != nil
s1 := (*[1]byte)(s[1:]) // &amp;s1[0] == &amp;s[1]
s2 := (*[2]byte)(s) // &amp;s2[0] == &amp;s[0]
s4 := (*[4]byte)(s) // panics: len([4]byte) > len(s)
var t []string
t0 := (*[0]string)(t) // t0 == nil
t1 := (*[1]string)(t) // panics: len([1]string) > len(t)
u := make([]byte, 0)
u0 = (*[0]byte)(u) // u0 != nil
</pre>
<h3 id="Constant_expressions">Constant expressions</h3>
@@ -4674,7 +4648,7 @@ The following built-in functions are not permitted in statement context:
<pre>
append cap complex imag len make new real
unsafe.Add unsafe.Alignof unsafe.Offsetof unsafe.Sizeof unsafe.Slice
unsafe.Alignof unsafe.Offsetof unsafe.Sizeof
</pre>
<pre>
@@ -4913,7 +4887,7 @@ if x := f(); x &lt; y {
<p>
"Switch" statements provide multi-way execution.
An expression or type is compared to the "cases"
An expression or type specifier is compared to the "cases"
inside the "switch" to determine which branch
to execute.
</p>
@@ -4957,9 +4931,9 @@ ExprSwitchCase = "case" ExpressionList | "default" .
<p>
If the switch expression evaluates to an untyped constant, it is first implicitly
<a href="#Conversions">converted</a> to its <a href="#Constants">default type</a>.
<a href="#Conversions">converted</a> to its <a href="#Constants">default type</a>;
if it is an untyped boolean value, it is first implicitly converted to type <code>bool</code>.
The predeclared untyped value <code>nil</code> cannot be used as a switch expression.
The switch expression type must be <a href="#Comparison_operators">comparable</a>.
</p>
<p>
@@ -5024,7 +4998,7 @@ floating point, or string constants in case expressions.
A type switch compares types rather than values. It is otherwise similar
to an expression switch. It is marked by a special switch expression that
has the form of a <a href="#Type_assertions">type assertion</a>
using the keyword <code>type</code> rather than an actual type:
using the reserved word <code>type</code> rather than an actual type:
</p>
<pre>
@@ -6715,10 +6689,6 @@ type Pointer *ArbitraryType
func Alignof(variable ArbitraryType) uintptr
func Offsetof(selector ArbitraryType) uintptr
func Sizeof(variable ArbitraryType) uintptr
type IntegerType int // shorthand for an integer type; it is not a real type
func Add(ptr Pointer, len IntegerType) Pointer
func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
</pre>
<p>
@@ -6775,40 +6745,6 @@ Calls to <code>Alignof</code>, <code>Offsetof</code>, and
<code>Sizeof</code> are compile-time constant expressions of type <code>uintptr</code>.
</p>
<p>
The function <code>Add</code> adds <code>len</code> to <code>ptr</code>
and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>.
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
A constant <code>len</code> argument must be <a href="#Representability">representable</a> by a value of type <code>int</code>;
if it is an untyped constant it is given type <code>int</code>.
The rules for <a href="/pkg/unsafe#Pointer">valid uses</a> of <code>Pointer</code> still apply.
</p>
<p>
The function <code>Slice</code> returns a slice whose underlying array starts at <code>ptr</code>
and whose length and capacity are <code>len</code>.
<code>Slice(ptr, len)</code> is equivalent to
</p>
<pre>
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
</pre>
<p>
except that, as a special case, if <code>ptr</code>
is <code>nil</code> and <code>len</code> is zero,
<code>Slice</code> returns <code>nil</code>.
</p>
<p>
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>;
if it is an untyped constant it is given type <code>int</code>.
At run time, if <code>len</code> is negative,
or if <code>ptr</code> is <code>nil</code> and <code>len</code> is not zero,
a <a href="#Run_time_panics">run-time panic</a> occurs.
</p>
<h3 id="Size_and_alignment_guarantees">Size and alignment guarantees</h3>
<p>

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -14,6 +14,7 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -275,7 +276,7 @@ func adbCopyGoroot() error {
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
return err
}
s, err := io.ReadAll(stat)
s, err := ioutil.ReadAll(stat)
if err != nil {
return err
}
@@ -293,7 +294,7 @@ func adbCopyGoroot() error {
goroot := runtime.GOROOT()
// Build go for android.
goCmd := filepath.Join(goroot, "bin", "go")
tmpGo, err := os.CreateTemp("", "go_android_exec-cmd-go-*")
tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*")
if err != nil {
return err
}

View File

@@ -1,134 +0,0 @@
// 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.
// Issue 42580: cmd/cgo: shifting identifier position in ast
package errorstest
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
type ShortPosition struct {
Line int
Column int
Visited bool
}
type IdentPositionInfo map[string][]ShortPosition
type Visitor struct {
identPosInfo IdentPositionInfo
fset *token.FileSet
t *testing.T
}
func (v *Visitor) Visit(node ast.Node) ast.Visitor {
if ident, ok := node.(*ast.Ident); ok {
if expectedPositions, ok := v.identPosInfo[ident.Name]; ok {
gotMatch := false
var errorMessage strings.Builder
for caseIndex, expectedPos := range expectedPositions {
actualPosition := v.fset.PositionFor(ident.Pos(), true)
errorOccured := false
if expectedPos.Line != actualPosition.Line {
fmt.Fprintf(&errorMessage, "wrong line number for ident %s: expected: %d got: %d\n", ident.Name, expectedPos.Line, actualPosition.Line)
errorOccured = true
}
if expectedPos.Column != actualPosition.Column {
fmt.Fprintf(&errorMessage, "wrong column number for ident %s: expected: %d got: %d\n", ident.Name, expectedPos.Column, actualPosition.Column)
errorOccured = true
}
if errorOccured {
continue
}
gotMatch = true
expectedPositions[caseIndex].Visited = true
}
if !gotMatch {
v.t.Errorf(errorMessage.String())
}
}
}
return v
}
func TestArgumentsPositions(t *testing.T) {
testdata, err := filepath.Abs("testdata")
if err != nil {
t.Fatal(err)
}
tmpPath := t.TempDir()
dir := filepath.Join(tmpPath, "src", "testpositions")
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
cmd := exec.Command("go", "tool", "cgo",
"-srcdir", testdata,
"-objdir", dir,
"issue42580.go")
cmd.Stderr = new(bytes.Buffer)
err = cmd.Run()
if err != nil {
t.Fatalf("%s: %v\n%s", cmd, err, cmd.Stderr)
}
mainProcessed, err := ioutil.ReadFile(filepath.Join(dir, "issue42580.cgo1.go"))
if err != nil {
t.Fatal(err)
}
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "", mainProcessed, parser.AllErrors)
if err != nil {
fmt.Println(err)
return
}
expectation := IdentPositionInfo{
"checkedPointer": []ShortPosition{
ShortPosition{
Line: 32,
Column: 56,
},
},
"singleInnerPointerChecked": []ShortPosition{
ShortPosition{
Line: 37,
Column: 91,
},
},
"doublePointerChecked": []ShortPosition{
ShortPosition{
Line: 42,
Column: 91,
},
},
}
for _, decl := range f.Decls {
if fdecl, ok := decl.(*ast.FuncDecl); ok {
ast.Walk(&Visitor{expectation, fset, t}, fdecl.Body)
}
}
for ident, positions := range expectation {
for _, position := range positions {
if !position.Visited {
t.Errorf("Position %d:%d missed for %s ident", position.Line, position.Column, ident)
}
}
}
}

View File

@@ -6,6 +6,7 @@ package errorstest
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -54,7 +55,7 @@ func TestBadSymbol(t *testing.T) {
makeFile := func(mdir, base, source string) string {
ret := filepath.Join(mdir, base)
if err := os.WriteFile(ret, []byte(source), 0644); err != nil {
if err := ioutil.WriteFile(ret, []byte(source), 0644); err != nil {
t.Fatal(err)
}
return ret
@@ -99,7 +100,7 @@ func TestBadSymbol(t *testing.T) {
// _cgo_import.go.
rewrite := func(from, to string) {
obj, err := os.ReadFile(from)
obj, err := ioutil.ReadFile(from)
if err != nil {
t.Fatal(err)
}
@@ -114,7 +115,7 @@ func TestBadSymbol(t *testing.T) {
obj = bytes.ReplaceAll(obj, []byte(magicInput), []byte(magicReplace))
if err := os.WriteFile(to, obj, 0644); err != nil {
if err := ioutil.WriteFile(to, obj, 0644); err != nil {
t.Fatal(err)
}
}

View File

@@ -7,6 +7,7 @@ package errorstest
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -24,7 +25,7 @@ func check(t *testing.T, file string) {
t.Run(file, func(t *testing.T) {
t.Parallel()
contents, err := os.ReadFile(path(file))
contents, err := ioutil.ReadFile(path(file))
if err != nil {
t.Fatal(err)
}
@@ -40,8 +41,7 @@ func check(t *testing.T, file string) {
if len(frags) == 1 {
continue
}
frag := fmt.Sprintf(":%d:.*%s", i+1, frags[1])
re, err := regexp.Compile(frag)
re, err := regexp.Compile(string(frags[1]))
if err != nil {
t.Errorf("Invalid regexp after `ERROR HERE: `: %#q", frags[1])
continue
@@ -56,7 +56,7 @@ func check(t *testing.T, file string) {
}
func expect(t *testing.T, file string, errors []*regexp.Regexp) {
dir, err := os.MkdirTemp("", filepath.Base(t.Name()))
dir, err := ioutil.TempDir("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}

View File

@@ -10,6 +10,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -462,7 +463,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
gopath = *tmp
dir = ""
} else {
d, err := os.MkdirTemp("", filepath.Base(t.Name()))
d, err := ioutil.TempDir("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}
@@ -474,7 +475,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
if err := os.MkdirAll(src, 0777); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
t.Fatal(err)
}
@@ -534,10 +535,10 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
fmt.Fprintf(&cgo1, "}\n\n")
fmt.Fprintf(&cgo1, "%s\n", ptrTestMain)
if err := os.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
t.Fatal(err)
}

View File

@@ -40,15 +40,15 @@ func main() {
C.foop = x // ERROR HERE
// issue 13129: used to output error about C.unsignedshort with CC=clang
var x1 C.ushort
x1 = int(0) // ERROR HERE: C\.ushort
var x C.ushort
x = int(0) // ERROR HERE: C\.ushort
// issue 13423
_ = C.fopen() // ERROR HERE
// issue 13467
var x2 rune = '✈'
var _ rune = C.transform(x2) // ERROR HERE: C\.int
var x rune = '✈'
var _ rune = C.transform(x) // ERROR HERE: C\.int
// issue 13635: used to output error about C.unsignedchar.
// This test tests all such types.
@@ -91,18 +91,10 @@ func main() {
// issue 26745
_ = func(i int) int {
// typecheck reports at column 14 ('+'), but types2 reports at
// column 10 ('C').
// TODO(mdempsky): Investigate why, and see if types2 can be
// updated to match typecheck behavior.
return C.i + 1 // ERROR HERE: \b(10|14)\b
return C.i + 1 // ERROR HERE: :13
}
_ = func(i int) {
// typecheck reports at column 7 ('('), but types2 reports at
// column 8 ('i'). The types2 position is more correct, but
// updating typecheck here is fundamentally challenging because of
// IR limitations.
C.fi(i) // ERROR HERE: \b(7|8)\b
C.fi(i) // ERROR HERE: :6
}
C.fi = C.fi // ERROR HERE

View File

@@ -1,44 +0,0 @@
// 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.
// Issue 42580: cmd/cgo: shifting identifier position in ast
package cgotest
// typedef int (*intFunc) ();
//
// char* strarg = "";
//
// int func_with_char(char* arg, void* dummy)
// {return 5;}
//
// int* get_arr(char* arg, void* dummy)
// {return NULL;}
import "C"
import "unsafe"
// Test variables
var (
checkedPointer = []byte{1}
doublePointerChecked = []byte{1}
singleInnerPointerChecked = []byte{1}
)
// This test checks the positions of variable identifiers.
// Changing the positions of the test variables idents after this point will break the test.
func TestSingleArgumentCast() C.int {
retcode := C.func_with_char((*C.char)(unsafe.Pointer(&checkedPointer[0])), unsafe.Pointer(C.strarg))
return retcode
}
func TestSingleArgumentCastRecFuncAsSimpleArg() C.int {
retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&singleInnerPointerChecked[0])), unsafe.Pointer(C.strarg)))), nil)
return retcode
}
func TestSingleArgumentCastRecFunc() C.int {
retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&doublePointerChecked[0])), unsafe.Pointer(C.strarg)))), unsafe.Pointer(C.strarg))
return retcode
}

View File

@@ -6,6 +6,7 @@ package life_test
import (
"bytes"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -20,7 +21,7 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
GOPATH, err := os.MkdirTemp("", "cgolife")
GOPATH, err := ioutil.TempDir("", "cgolife")
if err != nil {
log.Panic(err)
}
@@ -37,7 +38,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := os.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
log.Panic(err)
}

View File

@@ -6,6 +6,7 @@ package stdio_test
import (
"bytes"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -20,7 +21,7 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
GOPATH, err := os.MkdirTemp("", "cgostdio")
GOPATH, err := ioutil.TempDir("", "cgostdio")
if err != nil {
log.Panic(err)
}
@@ -37,7 +38,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
log.Panic(err)
}

View File

@@ -59,7 +59,6 @@ func Test28896(t *testing.T) { test28896(t) }
func Test30065(t *testing.T) { test30065(t) }
func Test32579(t *testing.T) { test32579(t) }
func Test31891(t *testing.T) { test31891(t) }
func Test45451(t *testing.T) { test45451(t) }
func TestAlign(t *testing.T) { testAlign(t) }
func TestAtol(t *testing.T) { testAtol(t) }
func TestBlocking(t *testing.T) { testBlocking(t) }
@@ -81,7 +80,6 @@ func TestNamedEnum(t *testing.T) { testNamedEnum(t) }
func TestCastToEnum(t *testing.T) { testCastToEnum(t) }
func TestErrno(t *testing.T) { testErrno(t) }
func TestFpVar(t *testing.T) { testFpVar(t) }
func TestHandle(t *testing.T) { testHandle(t) }
func TestHelpers(t *testing.T) { testHelpers(t) }
func TestLibgcc(t *testing.T) { testLibgcc(t) }
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }

View File

@@ -8,8 +8,7 @@ package cgotest
import (
"fmt"
"os"
"sort"
"io/ioutil"
"strings"
"syscall"
"testing"
@@ -65,7 +64,7 @@ import "C"
func compareStatus(filter, expect string) error {
expected := filter + expect
pid := syscall.Getpid()
fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
if err != nil {
return fmt.Errorf("unable to find %d tasks: %v", pid, err)
}
@@ -73,7 +72,7 @@ func compareStatus(filter, expect string) error {
foundAThread := false
for _, f := range fs {
tf := fmt.Sprintf("/proc/%s/status", f.Name())
d, err := os.ReadFile(tf)
d, err := ioutil.ReadFile(tf)
if err != nil {
// There are a surprising number of ways this
// can error out on linux. We've seen all of
@@ -106,23 +105,11 @@ func compareStatus(filter, expect string) error {
// "Pid:\t".
}
if strings.HasPrefix(line, filter) {
if line == expected {
foundAThread = true
break
if line != expected {
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
}
if filter == "Groups:" && strings.HasPrefix(line, "Groups:\t") {
// https://github.com/golang/go/issues/46145
// Containers don't reliably output this line in sorted order so manually sort and compare that.
a := strings.Split(line[8:], " ")
sort.Strings(a)
got := strings.Join(a, " ")
if got == expected[8:] {
foundAThread = true
break
}
}
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
foundAThread = true
break
}
}
}

View File

@@ -5,7 +5,7 @@
// +build !android
// Test that pthread_cancel works as expected
// (NPTL uses SIGRTMIN to implement thread cancellation)
// (NPTL uses SIGRTMIN to implement thread cancelation)
// See https://golang.org/issue/6997
package cgotest
@@ -17,10 +17,8 @@ extern int CancelThread();
*/
import "C"
import (
"testing"
"time"
)
import "testing"
import "time"
func test6997(t *testing.T) {
r := C.StartThread()

View File

@@ -1,11 +0,0 @@
// Copyright 2014 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.
#include "_cgo_export.h"
int get8148(void) {
T t;
t.i = 42;
return issue8148Callback(&t);
}

View File

@@ -10,7 +10,14 @@ package cgotest
/*
typedef struct { int i; } T;
int get8148(void);
int issue8148Callback(T*);
static int get() {
T t;
t.i = 42;
return issue8148Callback(&t);
}
*/
import "C"
@@ -20,5 +27,5 @@ func issue8148Callback(t *C.T) C.int {
}
func Issue8148() int {
return int(C.get8148())
return int(C.get())
}

View File

@@ -5,6 +5,7 @@
package cgotest
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -36,7 +37,7 @@ func TestCrossPackageTests(t *testing.T) {
}
}
GOPATH, err := os.MkdirTemp("", "cgotest")
GOPATH, err := ioutil.TempDir("", "cgotest")
if err != nil {
t.Fatal(err)
}
@@ -46,7 +47,7 @@ func TestCrossPackageTests(t *testing.T) {
if err := overlayDir(modRoot, "testdata"); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
t.Fatal(err)
}

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that setgid does not hang on Linux.
// Test that setgid does not hang on GNU/Linux.
// See https://golang.org/issue/3871 for details.
package cgotest

View File

@@ -899,10 +899,6 @@ static uint16_t issue31093F(uint16_t v) { return v; }
// issue 32579
typedef struct S32579 { unsigned char data[1]; } S32579;
// issue 37033, cgo.Handle
extern void GoFunc37033(uintptr_t handle);
void cFunc37033(uintptr_t handle) { GoFunc37033(handle); }
// issue 38649
// Test that #define'd type aliases work.
#define netbsd_gid unsigned int
@@ -912,9 +908,6 @@ void cFunc37033(uintptr_t handle) { GoFunc37033(handle); }
enum Enum40494 { X_40494 };
union Union40494 { int x; };
void issue40494(enum Enum40494 e, union Union40494* up) {}
// Issue 45451, bad handling of go:notinheap types.
typedef struct issue45451Undefined issue45451;
*/
import "C"
@@ -927,7 +920,6 @@ import (
"os/signal"
"reflect"
"runtime"
"runtime/cgo"
"sync"
"syscall"
"testing"
@@ -2238,23 +2230,6 @@ func test32579(t *testing.T) {
}
}
// issue 37033, check if cgo.Handle works properly
func testHandle(t *testing.T) {
ch := make(chan int)
for i := 0; i < 42; i++ {
h := cgo.NewHandle(ch)
go func() {
C.cFunc37033(C.uintptr_t(h))
}()
if v := <-ch; issue37033 != v {
t.Fatalf("unexpected receiving value: got %d, want %d", v, issue37033)
}
h.Delete()
}
}
// issue 38649
var issue38649 C.netbsd_gid = 42
@@ -2269,19 +2244,3 @@ var issue39877 *C.void = nil
func Issue40494() {
C.issue40494(C.enum_Enum40494(C.X_40494), (*C.union_Union40494)(nil))
}
// Issue 45451.
func test45451(t *testing.T) {
var u *C.issue45451
typ := reflect.ValueOf(u).Type().Elem()
// The type is undefined in C so allocating it should panic.
defer func() {
if r := recover(); r == nil {
t.Error("expected panic")
}
}()
_ = reflect.New(typ)
t.Errorf("reflect.New(%v) should have panicked", typ)
}

View File

@@ -1,24 +0,0 @@
// 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.
#include "_cgo_export.h"
void lockOSThreadC(void) {
lockOSThreadCallback();
}
void issue7978c(uint32_t *sync) {
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 0)
;
__atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 2)
;
issue7978cb();
__atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 6)
;
}
void f7665(void) {
}

View File

@@ -12,7 +12,6 @@ package cgotest
import (
"runtime"
"runtime/cgo"
"runtime/debug"
"strings"
"sync"
@@ -27,6 +26,7 @@ import (
extern void doAdd(int, int);
// issue 1328
extern void BackIntoGo(void);
void IntoC(void);
// issue 1560
@@ -38,7 +38,11 @@ long long mysleep(int seconds);
long long twoSleep(int);
// issue 3775
void lockOSThreadC(void);
void lockOSThreadCallback(void);
inline static void lockOSThreadC(void)
{
lockOSThreadCallback();
}
int usleep(unsigned usec);
// issue 4054 part 2 - part 1 in test.go
@@ -77,9 +81,21 @@ extern void f7665(void);
#include <stdint.h>
void issue7978cb(void);
// use ugly atomic variable sync since that doesn't require calling back into
// Go code or OS dependencies
void issue7978c(uint32_t *sync);
static void issue7978c(uint32_t *sync) {
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 0)
;
__atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 2)
;
issue7978cb();
__atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST);
while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 6)
;
}
// issue 8331 part 2 - part 1 in test.go
// A typedef of an unnamed struct is the same struct when
@@ -412,6 +428,9 @@ func test6907Go(t *testing.T) {
// issue 7665
//export f7665
func f7665() {}
var bad7665 unsafe.Pointer = C.f7665
var good7665 uintptr = uintptr(C.f7665)
@@ -539,17 +558,6 @@ func test31891(t *testing.T) {
C.callIssue31891()
}
// issue 37033, check if cgo.Handle works properly
var issue37033 = 42
//export GoFunc37033
func GoFunc37033(handle C.uintptr_t) {
h := cgo.Handle(handle)
ch := h.Value().(chan int)
ch <- issue37033
}
// issue 38408
// A typedef pointer can be used as the element type.
// No runtime test; just make sure it compiles.

View File

@@ -10,6 +10,7 @@ import (
"debug/elf"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -52,7 +53,7 @@ func testMain(m *testing.M) int {
// We need a writable GOPATH in which to run the tests.
// Construct one in a temporary directory.
var err error
GOPATH, err = os.MkdirTemp("", "carchive_test")
GOPATH, err = ioutil.TempDir("", "carchive_test")
if err != nil {
log.Panic(err)
}
@@ -73,7 +74,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := os.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
if err := ioutil.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
log.Panic(err)
}
@@ -175,7 +176,7 @@ func genHeader(t *testing.T, header, dir string) {
// The 'cgo' command generates a number of additional artifacts,
// but we're only interested in the header.
// Shunt the rest of the outputs to a temporary directory.
objDir, err := os.MkdirTemp(GOPATH, "_obj")
objDir, err := ioutil.TempDir(GOPATH, "_obj")
if err != nil {
t.Fatal(err)
}
@@ -251,7 +252,7 @@ var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)
// the user and make the files change based on details of the location
// of GOPATH.
func checkLineComments(t *testing.T, hdrname string) {
hdr, err := os.ReadFile(hdrname)
hdr, err := ioutil.ReadFile(hdrname)
if err != nil {
if !os.IsNotExist(err) {
t.Error(err)
@@ -617,7 +618,7 @@ func TestExtar(t *testing.T) {
t.Fatal(err)
}
s := strings.Replace(testar, "PWD", dir, 1)
if err := os.WriteFile("testar", []byte(s), 0777); err != nil {
if err := ioutil.WriteFile("testar", []byte(s), 0777); err != nil {
t.Fatal(err)
}
@@ -775,7 +776,7 @@ func TestSIGPROF(t *testing.T) {
// tool with -buildmode=c-archive, it passes -shared to the compiler,
// so we override that. The go tool doesn't work this way, but Bazel
// will likely do it in the future. And it ought to work. This test
// was added because at one time it did not work on PPC Linux.
// was added because at one time it did not work on PPC GNU/Linux.
func TestCompileWithoutShared(t *testing.T) {
// For simplicity, reuse the signal forwarding test.
checkSignalForwardingTest(t)

View File

@@ -5,7 +5,7 @@
package main
import (
"io"
"io/ioutil"
"runtime/pprof"
)
@@ -13,7 +13,7 @@ import "C"
//export go_start_profile
func go_start_profile() {
pprof.StartCPUProfile(io.Discard)
pprof.StartCPUProfile(ioutil.Discard)
}
//export go_stop_profile

View File

@@ -36,7 +36,7 @@ int install_handler() {
return 2;
}
// gccgo does not set SA_ONSTACK for SIGSEGV.
if (getenv("GCCGO") == NULL && (osa.sa_flags&SA_ONSTACK) == 0) {
if (getenv("GCCGO") == "" && (osa.sa_flags&SA_ONSTACK) == 0) {
fprintf(stderr, "Go runtime did not install signal handler\n");
return 2;
}

View File

@@ -11,6 +11,7 @@ import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -124,7 +125,7 @@ func testMain(m *testing.M) int {
// Copy testdata into GOPATH/src/testcshared, along with a go.mod file
// declaring the same path.
GOPATH, err := os.MkdirTemp("", "cshared_test")
GOPATH, err := ioutil.TempDir("", "cshared_test")
if err != nil {
log.Panic(err)
}
@@ -139,7 +140,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := os.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
if err := ioutil.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
log.Panic(err)
}
@@ -259,7 +260,7 @@ func createHeaders() error {
// The 'cgo' command generates a number of additional artifacts,
// but we're only interested in the header.
// Shunt the rest of the outputs to a temporary directory.
objDir, err := os.MkdirTemp("", "testcshared_obj")
objDir, err := ioutil.TempDir("", "testcshared_obj")
if err != nil {
return err
}
@@ -292,60 +293,11 @@ func createHeaders() error {
"-installsuffix", "testcshared",
"-o", libgoname,
filepath.Join(".", "libgo", "libgo.go")}
if GOOS == "windows" && strings.HasSuffix(args[6], ".a") {
args[6] = strings.TrimSuffix(args[6], ".a") + ".dll"
}
cmd = exec.Command(args[0], args[1:]...)
out, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("command failed: %v\n%v\n%s\n", args, err, out)
}
if GOOS == "windows" {
// We can't simply pass -Wl,--out-implib, because this relies on having imports from multiple packages,
// which results in the linkers output implib getting overwritten at each step. So instead build the
// import library the traditional way, using a def file.
err = os.WriteFile("libgo.def",
[]byte("LIBRARY libgo.dll\nEXPORTS\n\tDidInitRun\n\tDidMainRun\n\tDivu\n\tFromPkg\n\t_cgo_dummy_export\n"),
0644)
if err != nil {
return fmt.Errorf("unable to write def file: %v", err)
}
out, err = exec.Command(cc[0], append(cc[1:], "-print-prog-name=dlltool")...).CombinedOutput()
if err != nil {
return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
}
args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
// This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
// we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
dlltoolContents, err := os.ReadFile(args[0])
if err != nil {
return fmt.Errorf("unable to read dlltool: %v\n", err)
}
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
base, name := filepath.Split(args[0])
args[0] = filepath.Join(base, "llvm-dlltool")
var machine string
switch strings.SplitN(name, "-", 2)[0] {
case "i686":
machine = "i386"
case "x86_64":
machine = "i386:x86-64"
case "armv7":
machine = "arm"
case "aarch64":
machine = "arm64"
}
if len(machine) > 0 {
args = append(args, "-m", machine)
}
}
out, err = exec.Command(args[0], args[1:]...).CombinedOutput()
if err != nil {
return fmt.Errorf("unable to run dlltool to create import library: %v\n%s\n", err, out)
}
}
if runtime.GOOS != GOOS && GOOS == "android" {
args = append(adbCmd(), "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname))
@@ -429,7 +381,7 @@ func main() {
srcfile := filepath.Join(tmpdir, "test.go")
objfile := filepath.Join(tmpdir, "test.dll")
if err := os.WriteFile(srcfile, []byte(prog), 0666); err != nil {
if err := ioutil.WriteFile(srcfile, []byte(prog), 0666); err != nil {
t.Fatal(err)
}
argv := []string{"build", "-buildmode=c-shared"}
@@ -449,7 +401,7 @@ func main() {
defer f.Close()
section := f.Section(".edata")
if section == nil {
t.Skip(".edata section is not present")
t.Fatalf(".edata section is not present")
}
// TODO: deduplicate this struct from cmd/link/internal/ld/pe.go
@@ -691,7 +643,7 @@ func TestPIE(t *testing.T) {
// Test that installing a second time recreates the header file.
func TestCachedInstall(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "cshared")
tmpdir, err := ioutil.TempDir("", "cshared")
if err != nil {
t.Fatal(err)
}
@@ -767,14 +719,14 @@ func TestCachedInstall(t *testing.T) {
// copyFile copies src to dst.
func copyFile(t *testing.T, dst, src string) {
t.Helper()
data, err := os.ReadFile(src)
data, err := ioutil.ReadFile(src)
if err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(dst, data, 0666); err != nil {
if err := ioutil.WriteFile(dst, data, 0666); err != nil {
t.Fatal(err)
}
}
@@ -791,19 +743,14 @@ func TestGo2C2Go(t *testing.T) {
t.Parallel()
tmpdir, err := os.MkdirTemp("", "cshared-TestGo2C2Go")
tmpdir, err := ioutil.TempDir("", "cshared-TestGo2C2Go")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
lib := filepath.Join(tmpdir, "libtestgo2c2go."+libSuffix)
var env []string
if GOOS == "windows" && strings.HasSuffix(lib, ".a") {
env = append(env, "CGO_LDFLAGS=-Wl,--out-implib,"+lib, "CGO_LDFLAGS_ALLOW=.*")
lib = strings.TrimSuffix(lib, ".a") + ".dll"
}
run(t, env, "go", "build", "-buildmode=c-shared", "-o", lib, "./go2c2go/go")
run(t, nil, "go", "build", "-buildmode=c-shared", "-o", lib, "./go2c2go/go")
cgoCflags := os.Getenv("CGO_CFLAGS")
if cgoCflags != "" {

View File

@@ -6,6 +6,7 @@ package testgodefs
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -33,7 +34,7 @@ func TestGoDefs(t *testing.T) {
t.Fatal(err)
}
gopath, err := os.MkdirTemp("", "testgodefs-gopath")
gopath, err := ioutil.TempDir("", "testgodefs-gopath")
if err != nil {
t.Fatal(err)
}
@@ -57,20 +58,20 @@ func TestGoDefs(t *testing.T) {
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr)
}
if err := os.WriteFile(filepath.Join(dir, fp+"_defs.go"), out, 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(dir, fp+"_defs.go"), out, 0644); err != nil {
t.Fatal(err)
}
}
main, err := os.ReadFile(filepath.Join("testdata", "main.go"))
main, err := ioutil.ReadFile(filepath.Join("testdata", "main.go"))
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "main.go"), main, 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), main, 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module testgodefs\ngo 1.14\n"), 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(dir, "go.mod"), []byte("module testgodefs\ngo 1.14\n"), 0644); err != nil {
t.Fatal(err)
}

View File

@@ -9,6 +9,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -30,28 +31,15 @@ func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
// tmpDir is used to cleanup logged commands -- s/tmpDir/$TMPDIR/
var tmpDir string
// prettyPrintf prints lines with tmpDir sanitized.
func prettyPrintf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
if tmpDir != "" {
s = strings.ReplaceAll(s, tmpDir, "$TMPDIR")
}
fmt.Print(s)
}
func testMain(m *testing.M) int {
// Copy testdata into GOPATH/src/testplugin, along with a go.mod file
// declaring the same path.
GOPATH, err := os.MkdirTemp("", "plugin_test")
GOPATH, err := ioutil.TempDir("", "plugin_test")
if err != nil {
log.Panic(err)
}
defer os.RemoveAll(GOPATH)
tmpDir = GOPATH
modRoot := filepath.Join(GOPATH, "src", "testplugin")
altRoot := filepath.Join(GOPATH, "alt", "src", "testplugin")
@@ -62,20 +50,14 @@ func testMain(m *testing.M) int {
if err := overlayDir(dstRoot, srcRoot); err != nil {
log.Panic(err)
}
prettyPrintf("mkdir -p %s\n", dstRoot)
prettyPrintf("rsync -a %s/ %s\n", srcRoot, dstRoot)
if err := os.WriteFile(filepath.Join(dstRoot, "go.mod"), []byte("module testplugin\n"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(dstRoot, "go.mod"), []byte("module testplugin\n"), 0666); err != nil {
log.Panic(err)
}
prettyPrintf("echo 'module testplugin' > %s/go.mod\n", dstRoot)
}
os.Setenv("GOPATH", filepath.Join(GOPATH, "alt"))
if err := os.Chdir(altRoot); err != nil {
log.Panic(err)
} else {
prettyPrintf("cd %s\n", altRoot)
}
os.Setenv("PWD", altRoot)
goCmd(nil, "build", "-buildmode=plugin", "-o", filepath.Join(modRoot, "plugin-mismatch.so"), "./plugin-mismatch")
@@ -83,8 +65,6 @@ func testMain(m *testing.M) int {
os.Setenv("GOPATH", GOPATH)
if err := os.Chdir(modRoot); err != nil {
log.Panic(err)
} else {
prettyPrintf("cd %s\n", modRoot)
}
os.Setenv("PWD", modRoot)
@@ -92,14 +72,13 @@ func testMain(m *testing.M) int {
goCmd(nil, "build", "-buildmode=plugin", "./plugin1")
goCmd(nil, "build", "-buildmode=plugin", "./plugin2")
so, err := os.ReadFile("plugin2.so")
so, err := ioutil.ReadFile("plugin2.so")
if err != nil {
log.Panic(err)
}
if err := os.WriteFile("plugin2-dup.so", so, 0444); err != nil {
if err := ioutil.WriteFile("plugin2-dup.so", so, 0444); err != nil {
log.Panic(err)
}
prettyPrintf("cp plugin2.so plugin2-dup.so\n")
goCmd(nil, "build", "-buildmode=plugin", "-o=sub/plugin1.so", "./sub/plugin1")
goCmd(nil, "build", "-buildmode=plugin", "-o=unnamed1.so", "./unnamed1/main.go")
@@ -116,53 +95,8 @@ func goCmd(t *testing.T, op string, args ...string) {
run(t, "go", append([]string{op, "-gcflags", gcflags}, args...)...)
}
// escape converts a string to something suitable for a shell command line.
func escape(s string) string {
s = strings.Replace(s, "\\", "\\\\", -1)
s = strings.Replace(s, "'", "\\'", -1)
// Conservative guess at characters that will force quoting
if s == "" || strings.ContainsAny(s, "\\ ;#*&$~?!|[]()<>{}`") {
s = "'" + s + "'"
}
return s
}
// asCommandLine renders cmd as something that could be copy-and-pasted into a command line
func asCommandLine(cwd string, cmd *exec.Cmd) string {
s := "("
if cmd.Dir != "" && cmd.Dir != cwd {
s += "cd" + escape(cmd.Dir) + ";"
}
for _, e := range cmd.Env {
if !strings.HasPrefix(e, "PATH=") &&
!strings.HasPrefix(e, "HOME=") &&
!strings.HasPrefix(e, "USER=") &&
!strings.HasPrefix(e, "SHELL=") {
s += " "
s += escape(e)
}
}
// These EVs are relevant to this test.
for _, e := range os.Environ() {
if strings.HasPrefix(e, "PWD=") ||
strings.HasPrefix(e, "GOPATH=") ||
strings.HasPrefix(e, "LD_LIBRARY_PATH=") {
s += " "
s += escape(e)
}
}
for _, a := range cmd.Args {
s += " "
s += escape(a)
}
s += " )"
return s
}
func run(t *testing.T, bin string, args ...string) string {
cmd := exec.Command(bin, args...)
cmdLine := asCommandLine(".", cmd)
prettyPrintf("%s\n", cmdLine)
cmd.Stderr = new(strings.Builder)
out, err := cmd.Output()
if err != nil {
@@ -263,17 +197,6 @@ func TestIssue25756(t *testing.T) {
}
}
// Test with main using -buildmode=pie with plugin for issue #43228
func TestIssue25756pie(t *testing.T) {
if os.Getenv("GO_BUILDER_NAME") == "darwin-arm64-11_0-toothrot" {
t.Skip("broken on darwin/arm64 builder in sharded mode; see issue 46239")
}
goCmd(t, "build", "-buildmode=plugin", "-o", "life.so", "./issue25756/plugin")
goCmd(t, "build", "-buildmode=pie", "-o", "issue25756pie.exe", "./issue25756/main.go")
run(t, "./issue25756pie.exe")
}
func TestMethod(t *testing.T) {
// Exported symbol's method must be live.
goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go")
@@ -286,10 +209,3 @@ func TestMethod2(t *testing.T) {
goCmd(t, "build", "-o", "method2.exe", "./method2/main.go")
run(t, "./method2.exe")
}
func TestIssue44956(t *testing.T) {
goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p1.so", "./issue44956/plugin1.go")
goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p2.so", "./issue44956/plugin2.go")
goCmd(t, "build", "-o", "issue44956.exe", "./issue44956/main.go")
run(t, "./issue44956.exe")
}

View File

@@ -1,7 +0,0 @@
// 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
var X = &map[int]int{123: 456}

View File

@@ -1,47 +0,0 @@
// 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.
// Issue 44956: writable static temp is not exported correctly.
// In the test below, package base is
//
// X = &map{...}
//
// which compiles to
//
// X = &stmp // static
// stmp = makemap(...) // in init function
//
// plugin1 and plugin2 both import base. plugin1 doesn't use
// base.X, so that symbol is deadcoded in plugin1.
//
// plugin1 is loaded first. base.init runs at that point, which
// initialize base.stmp.
//
// plugin2 is then loaded. base.init already ran, so it doesn't run
// again. When base.stmp is not exported, plugin2's base.X points to
// its own private base.stmp, which is not initialized, fail.
package main
import "plugin"
func main() {
_, err := plugin.Open("issue44956p1.so")
if err != nil {
panic("FAIL")
}
p2, err := plugin.Open("issue44956p2.so")
if err != nil {
panic("FAIL")
}
f, err := p2.Lookup("F")
if err != nil {
panic("FAIL")
}
x := f.(func() *map[int]int)()
if x == nil || (*x)[123] != 456 {
panic("FAIL")
}
}

View File

@@ -1,9 +0,0 @@
// 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 main
import _ "testplugin/issue44956/base"
func main() {}

View File

@@ -1,11 +0,0 @@
// 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 main
import "testplugin/issue44956/base"
func F() *map[int]int { return base.X }
func main() {}

View File

@@ -15,7 +15,7 @@ import (
var t p.T
type I interface{ M() }
type I interface { M() }
func main() {
pl, err := plugin.Open("method2.so")

View File

@@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -35,7 +36,7 @@ func requireOvercommit(t *testing.T) {
overcommit.Once.Do(func() {
var out []byte
out, overcommit.err = os.ReadFile("/proc/sys/vm/overcommit_memory")
out, overcommit.err = ioutil.ReadFile("/proc/sys/vm/overcommit_memory")
if overcommit.err != nil {
return
}
@@ -312,14 +313,14 @@ int main() {
`)
func (c *config) checkCSanitizer() (skip bool, err error) {
dir, err := os.MkdirTemp("", c.sanitizer)
dir, err := ioutil.TempDir("", c.sanitizer)
if err != nil {
return false, fmt.Errorf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(dir)
src := filepath.Join(dir, "return0.c")
if err := os.WriteFile(src, cMain, 0600); err != nil {
if err := ioutil.WriteFile(src, cMain, 0600); err != nil {
return false, fmt.Errorf("failed to write C source file: %v", err)
}
@@ -417,7 +418,7 @@ func (d *tempDir) Join(name string) string {
func newTempDir(t *testing.T) *tempDir {
t.Helper()
dir, err := os.MkdirTemp("", filepath.Dir(t.Name()))
dir, err := ioutil.TempDir("", filepath.Dir(t.Name()))
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
@@ -439,14 +440,3 @@ func hangProneCmd(name string, arg ...string) *exec.Cmd {
}
return cmd
}
// mSanSupported is a copy of the function cmd/internal/sys.MSanSupported,
// because the internal pacakage can't be used here.
func mSanSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "arm64"
default:
return false
}
}

View File

@@ -6,7 +6,7 @@ package sanitizers_test
import (
"fmt"
"os"
"io/ioutil"
"strings"
"testing"
)
@@ -19,12 +19,6 @@ func TestShared(t *testing.T) {
if err != nil {
t.Fatal(err)
}
GOARCH, err := goEnv("GOARCH")
if err != nil {
t.Fatal(err)
}
libExt := "so"
if GOOS == "darwin" {
libExt = "dylib"
@@ -47,11 +41,6 @@ func TestShared(t *testing.T) {
for _, tc := range cases {
tc := tc
name := strings.TrimSuffix(tc.src, ".go")
//The memory sanitizer tests require support for the -msan option.
if tc.sanitizer == "memory" && !mSanSupported(GOOS, GOARCH) {
t.Logf("skipping %s test on %s/%s; -msan option is not supported.", name, GOOS, GOARCH)
continue
}
t.Run(name, func(t *testing.T) {
t.Parallel()
config := configure(tc.sanitizer)
@@ -64,7 +53,7 @@ func TestShared(t *testing.T) {
mustRun(t, config.goCmd("build", "-buildmode=c-shared", "-o", lib, srcPath(tc.src)))
cSrc := dir.Join("main.c")
if err := os.WriteFile(cSrc, cMain, 0600); err != nil {
if err := ioutil.WriteFile(cSrc, cMain, 0600); err != nil {
t.Fatalf("failed to write C source file: %v", err)
}

View File

@@ -10,19 +10,6 @@ import (
)
func TestMSAN(t *testing.T) {
goos, err := goEnv("GOOS")
if err != nil {
t.Fatal(err)
}
goarch, err := goEnv("GOARCH")
if err != nil {
t.Fatal(err)
}
// The msan tests require support for the -msan option.
if !mSanSupported(goos, goarch) {
t.Skipf("skipping on %s/%s; -msan option is not supported.", goos, goarch)
}
t.Parallel()
requireOvercommit(t)
config := configure("memory")
@@ -42,7 +29,6 @@ func TestMSAN(t *testing.T) {
{src: "msan5.go"},
{src: "msan6.go"},
{src: "msan7.go"},
{src: "msan8.go"},
{src: "msan_fail.go", wantErr: true},
}
for _, tc := range cases {

View File

@@ -1,109 +0,0 @@
// 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 main
/*
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <sanitizer/msan_interface.h>
// cgoTracebackArg is the type of the argument passed to msanGoTraceback.
struct cgoTracebackArg {
uintptr_t context;
uintptr_t sigContext;
uintptr_t* buf;
uintptr_t max;
};
// msanGoTraceback is registered as the cgo traceback function.
// This will be called when a signal occurs.
void msanGoTraceback(void* parg) {
struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg);
arg->buf[0] = 0;
}
// msanGoWait will be called with all registers undefined as far as
// msan is concerned. It just waits for a signal.
// Because the registers are msan-undefined, the signal handler will
// be invoked with all registers msan-undefined.
__attribute__((noinline))
void msanGoWait(unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, unsigned long a6) {
sigset_t mask;
sigemptyset(&mask);
sigsuspend(&mask);
}
// msanGoSignalThread is the thread ID of the msanGoLoop thread.
static pthread_t msanGoSignalThread;
// msanGoSignalThreadSet is used to record that msanGoSignalThread
// has been initialized. This is accessed atomically.
static int32_t msanGoSignalThreadSet;
// uninit is explicitly poisoned, so that we can make all registers
// undefined by calling msanGoWait.
static unsigned long uninit;
// msanGoLoop loops calling msanGoWait, with the arguments passed
// such that msan thinks that they are undefined. msan permits
// undefined values to be used as long as they are not used to
// for conditionals or for memory access.
void msanGoLoop() {
int i;
msanGoSignalThread = pthread_self();
__atomic_store_n(&msanGoSignalThreadSet, 1, __ATOMIC_SEQ_CST);
// Force uninit to be undefined for msan.
__msan_poison(&uninit, sizeof uninit);
for (i = 0; i < 100; i++) {
msanGoWait(uninit, uninit, uninit, uninit, uninit, uninit);
}
}
// msanGoReady returns whether msanGoSignalThread is set.
int msanGoReady() {
return __atomic_load_n(&msanGoSignalThreadSet, __ATOMIC_SEQ_CST) != 0;
}
// msanGoSendSignal sends a signal to the msanGoLoop thread.
void msanGoSendSignal() {
pthread_kill(msanGoSignalThread, SIGWINCH);
}
*/
import "C"
import (
"runtime"
"time"
)
func main() {
runtime.SetCgoTraceback(0, C.msanGoTraceback, nil, nil)
c := make(chan bool)
go func() {
defer func() { c <- true }()
C.msanGoLoop()
}()
for C.msanGoReady() == 0 {
time.Sleep(time.Microsecond)
}
loop:
for {
select {
case <-c:
break loop
default:
C.msanGoSendSignal()
time.Sleep(time.Microsecond)
}
}
}

View File

@@ -44,7 +44,7 @@ void spin() {
import "C"
import (
"io"
"io/ioutil"
"runtime/pprof"
"time"
)
@@ -60,7 +60,7 @@ func goSpin() {
}
func main() {
pprof.StartCPUProfile(io.Discard)
pprof.StartCPUProfile(ioutil.Discard)
go C.spin()
goSpin()
pprof.StopCPUProfile()

View File

@@ -13,6 +13,7 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -89,7 +90,7 @@ func goCmd(t *testing.T, args ...string) string {
// TestMain calls testMain so that the latter can use defer (TestMain exits with os.Exit).
func testMain(m *testing.M) (int, error) {
workDir, err := os.MkdirTemp("", "shared_test")
workDir, err := ioutil.TempDir("", "shared_test")
if err != nil {
return 0, err
}
@@ -176,7 +177,7 @@ func cloneTestdataModule(gopath string) (string, error) {
if err := overlayDir(modRoot, "testdata"); err != nil {
return "", err
}
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module testshared\n"), 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module testshared\n"), 0644); err != nil {
return "", err
}
return modRoot, nil
@@ -317,7 +318,7 @@ func TestShlibnameFiles(t *testing.T) {
}
for _, pkg := range pkgs {
shlibnamefile := filepath.Join(gorootInstallDir, pkg+".shlibname")
contentsb, err := os.ReadFile(shlibnamefile)
contentsb, err := ioutil.ReadFile(shlibnamefile)
if err != nil {
t.Errorf("error reading shlibnamefile for %s: %v", pkg, err)
continue
@@ -790,7 +791,7 @@ func resetFileStamps() {
// It also sets the time of the file, so that we can see if it is rewritten.
func touch(t *testing.T, path string) (cleanup func()) {
t.Helper()
data, err := os.ReadFile(path)
data, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
@@ -836,14 +837,14 @@ func touch(t *testing.T, path string) (cleanup func()) {
// user-writable.
perm := fi.Mode().Perm() | 0200
if err := os.WriteFile(path, data, perm); err != nil {
if err := ioutil.WriteFile(path, data, perm); err != nil {
t.Fatal(err)
}
if err := os.Chtimes(path, nearlyNew, nearlyNew); err != nil {
t.Fatal(err)
}
return func() {
if err := os.WriteFile(path, old, perm); err != nil {
if err := ioutil.WriteFile(path, old, perm); err != nil {
t.Fatal(err)
}
}

View File

@@ -7,6 +7,7 @@
package so_test
import (
"io/ioutil"
"log"
"os"
"os/exec"
@@ -36,7 +37,7 @@ func requireTestSOSupported(t *testing.T) {
func TestSO(t *testing.T) {
requireTestSOSupported(t)
GOPATH, err := os.MkdirTemp("", "cgosotest")
GOPATH, err := ioutil.TempDir("", "cgosotest")
if err != nil {
log.Fatal(err)
}
@@ -46,7 +47,7 @@ func TestSO(t *testing.T) {
if err := overlayDir(modRoot, "testdata"); err != nil {
log.Panic(err)
}
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil {
log.Panic(err)
}
@@ -79,10 +80,6 @@ func TestSO(t *testing.T) {
case "windows":
ext = "dll"
args = append(args, "-DEXPORT_DLL")
// At least in mingw-clang it is not permitted to just name a .dll
// on the command line. You must name the corresponding import
// library instead, even though the dll is used when the executable is run.
args = append(args, "-Wl,-out-implib,libcgosotest.a")
case "aix":
ext = "so.1"
}

View File

@@ -14,7 +14,7 @@ package cgosotest
#cgo solaris LDFLAGS: -L. -lcgosotest
#cgo netbsd LDFLAGS: -L. libcgosotest.so
#cgo darwin LDFLAGS: -L. libcgosotest.dylib
#cgo windows LDFLAGS: -L. libcgosotest.a
#cgo windows LDFLAGS: -L. libcgosotest.dll
#cgo aix LDFLAGS: -L. -l cgosotest
void init(void);

View File

@@ -7,6 +7,7 @@
package so_test
import (
"io/ioutil"
"log"
"os"
"os/exec"
@@ -36,7 +37,7 @@ func requireTestSOSupported(t *testing.T) {
func TestSO(t *testing.T) {
requireTestSOSupported(t)
GOPATH, err := os.MkdirTemp("", "cgosotest")
GOPATH, err := ioutil.TempDir("", "cgosotest")
if err != nil {
log.Fatal(err)
}
@@ -46,7 +47,7 @@ func TestSO(t *testing.T) {
if err := overlayDir(modRoot, "testdata"); err != nil {
log.Panic(err)
}
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil {
log.Panic(err)
}
@@ -79,10 +80,6 @@ func TestSO(t *testing.T) {
case "windows":
ext = "dll"
args = append(args, "-DEXPORT_DLL")
// At least in mingw-clang it is not permitted to just name a .dll
// on the command line. You must name the corresponding import
// library instead, even though the dll is used when the executable is run.
args = append(args, "-Wl,-out-implib,libcgosotest.a")
case "aix":
ext = "so.1"
}

View File

@@ -18,7 +18,7 @@ package cgosotest
#cgo solaris LDFLAGS: -L. -lcgosotest
#cgo netbsd LDFLAGS: -L. libcgosotest.so
#cgo darwin LDFLAGS: -L. libcgosotest.dylib
#cgo windows LDFLAGS: -L. libcgosotest.a
#cgo windows LDFLAGS: -L. libcgosotest.dll
#cgo aix LDFLAGS: -L. -l cgosotest
#include "cgoso_c.h"

View File

@@ -15,7 +15,7 @@
<a href="#" url="https://golang.org/pkg/">pkg</a> id/name:</small>
<form style='margin: 0' id='navform'><nobr><input id="inputbox" size=10 tabindex=1 /><input type="submit" value="go" /></nobr></form>
<small>Also: <a href="#" url="https://build.golang.org">buildbots</a>
<a href="#" url="https://github.com/golang/go">GitHub</a>
<a href="#" url="https://github.com/golang/go">Github</a>
</small>
</body>
</html>

View File

@@ -16,6 +16,7 @@ import (
"bytes"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@@ -37,7 +38,7 @@ func main() {
fmt.Println("# will be overwritten when running Go programs.")
for _, mp := range mps {
fmt.Println()
f, err := os.CreateTemp("", "go_ios_detect_")
f, err := ioutil.TempFile("", "go_ios_detect_")
check(err)
fname := f.Name()
defer os.Remove(fname)

View File

@@ -26,6 +26,7 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"net"
"os"
@@ -78,7 +79,7 @@ func main() {
func runMain() (int, error) {
var err error
tmpdir, err = os.MkdirTemp("", "go_ios_exec_")
tmpdir, err = ioutil.TempDir("", "go_ios_exec_")
if err != nil {
return 1, err
}
@@ -204,13 +205,13 @@ func assembleApp(appdir, bin string) error {
}
entitlementsPath := filepath.Join(tmpdir, "Entitlements.plist")
if err := os.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil {
if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist(pkgpath)), 0744); err != nil {
if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist(pkgpath)), 0744); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil {
if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil {
return err
}
return nil

View File

@@ -11,7 +11,7 @@ import (
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
@@ -144,7 +144,7 @@ func doCrawl(url string) error {
if res.StatusCode != 200 {
return errors.New(res.Status)
}
slurp, err := io.ReadAll(res.Body)
slurp, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatalf("Error reading %s body: %v", url, err)

View File

@@ -13,6 +13,7 @@ package reboot_test
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -22,7 +23,7 @@ import (
func TestExperimentToolID(t *testing.T) {
// Set up GOROOT
goroot, err := os.MkdirTemp("", "experiment-goroot")
goroot, err := ioutil.TempDir("", "experiment-goroot")
if err != nil {
t.Fatal(err)
}
@@ -33,13 +34,13 @@ func TestExperimentToolID(t *testing.T) {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil {
t.Fatal(err)
}
env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
// Use a clean cache.
gocache, err := os.MkdirTemp("", "experiment-gocache")
gocache, err := ioutil.TempDir("", "experiment-gocache")
if err != nil {
t.Fatal(err)
}

View File

@@ -7,6 +7,7 @@
package reboot_test
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -15,7 +16,7 @@ import (
)
func TestRepeatBootstrap(t *testing.T) {
goroot, err := os.MkdirTemp("", "reboot-goroot")
goroot, err := ioutil.TempDir("", "reboot-goroot")
if err != nil {
t.Fatal(err)
}
@@ -26,7 +27,7 @@ func TestRepeatBootstrap(t *testing.T) {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
if err := ioutil.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
t.Fatal(err)
}

View File

@@ -993,13 +993,13 @@
</style>
<div style="padding-right: 200px">
<div style="float:right; border-style: solid; border-width: 1px; padding:20px">
X no feedback<br>
0 uninitialized<br>
. premonomorphic<br>
1 monomorphic<br>
^ recompute handler<br>
P polymorphic<br>
N megamorphic<br>
X no feedback<br/>
0 uninitialized<br/>
. premonomorphic<br/>
1 monomorphic<br/>
^ recompute handler<br/>
P polymorphic<br/>
N megamorphic<br/>
G generic
</div>
</div>
@@ -3596,7 +3596,7 @@
<div id="pipeline_per_frame_container">
<div class="subtitle">Graphics Pipeline and Raster Tasks</div>
<div class="description">
When raster tasks are completed in comparison to the rest of the graphics pipeline.<br>
When raster tasks are completed in comparison to the rest of the graphics pipeline.<br/>
Only pages where raster tasks are completed after beginFrame is issued are included.
</div>
<tr-v-ui-raster-visualization id="rasterVisualization">

View File

@@ -296,8 +296,8 @@
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
},
// func walltime() (sec int64, nsec int32)
"runtime.walltime": (sp) => {
// func walltime1() (sec int64, nsec int32)
"runtime.walltime1": (sp) => {
sp >>>= 0;
const msec = (new Date).getTime();
setInt64(sp + 8, msec / 1000);
@@ -401,7 +401,6 @@
storeValue(sp + 56, result);
this.mem.setUint8(sp + 64, 1);
} catch (err) {
sp = this._inst.exports.getsp() >>> 0; // see comment above
storeValue(sp + 56, err);
this.mem.setUint8(sp + 64, 0);
}
@@ -418,7 +417,6 @@
storeValue(sp + 40, result);
this.mem.setUint8(sp + 48, 1);
} catch (err) {
sp = this._inst.exports.getsp() >>> 0; // see comment above
storeValue(sp + 40, err);
this.mem.setUint8(sp + 48, 0);
}
@@ -435,7 +433,6 @@
storeValue(sp + 40, result);
this.mem.setUint8(sp + 48, 1);
} catch (err) {
sp = this._inst.exports.getsp() >>> 0; // see comment above
storeValue(sp + 40, err);
this.mem.setUint8(sp + 48, 0);
}

2
robots.txt Normal file
View File

@@ -0,0 +1,2 @@
User-agent: *
Disallow: /

View File

@@ -262,11 +262,16 @@ func TestFileInfoHeaderDir(t *testing.T) {
func TestFileInfoHeaderSymlink(t *testing.T) {
testenv.MustHaveSymlink(t)
tmpdir := t.TempDir()
tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
link := filepath.Join(tmpdir, "link")
target := tmpdir
if err := os.Symlink(target, link); err != nil {
err = os.Symlink(target, link)
if err != nil {
t.Fatal(err)
}
fi, err := os.Lstat(link)

View File

@@ -52,9 +52,12 @@ type File struct {
FileHeader
zip *Reader
zipr io.ReaderAt
zipsize int64
headerOffset int64
zip64 bool // zip64 extended information extra field presence
descErr error // error reading the data descriptor during init
}
func (f *File) hasDataDescriptor() bool {
return f.Flags&0x8 != 0
}
// OpenReader will open the Zip file specified by name and return a ReadCloser.
@@ -96,15 +99,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
return err
}
z.r = r
// Since the number of directory records is not validated, it is not
// safe to preallocate z.File without first checking that the specified
// number of files is reasonable, since a malformed archive may
// indicate it contains up to 1 << 128 - 1 files. Since each file has a
// header which will be _at least_ 30 bytes we can safely preallocate
// if (data size / 30) >= end.directoryRecords.
if (uint64(size)-end.directorySize)/30 >= end.directoryRecords {
z.File = make([]*File, 0, end.directoryRecords)
}
z.File = make([]*File, 0, end.directoryRecords)
z.Comment = end.comment
rs := io.NewSectionReader(r, 0, size)
if _, err = rs.Seek(int64(end.directoryOffset), io.SeekStart); err != nil {
@@ -117,7 +112,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
// a bad one, and then only report an ErrFormat or UnexpectedEOF if
// the file count modulo 65536 is incorrect.
for {
f := &File{zip: z, zipr: r}
f := &File{zip: z, zipr: r, zipsize: size}
err = readDirectoryHeader(f, buf)
if err == ErrFormat || err == io.ErrUnexpectedEOF {
break
@@ -125,7 +120,6 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
if err != nil {
return err
}
f.readDataDescriptor()
z.File = append(z.File, f)
}
if uint16(len(z.File)) != uint16(end.directoryRecords) { // only compare 16 bits here
@@ -186,68 +180,26 @@ func (f *File) Open() (io.ReadCloser, error) {
return nil, ErrAlgorithm
}
var rc io.ReadCloser = dcomp(r)
var desr io.Reader
if f.hasDataDescriptor() {
desr = io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, dataDescriptorLen)
}
rc = &checksumReader{
rc: rc,
hash: crc32.NewIEEE(),
f: f,
desr: desr,
}
return rc, nil
}
// OpenRaw returns a Reader that provides access to the File's contents without
// decompression.
func (f *File) OpenRaw() (io.Reader, error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return nil, err
}
r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, int64(f.CompressedSize64))
return r, nil
}
func (f *File) readDataDescriptor() {
if !f.hasDataDescriptor() {
return
}
bodyOffset, err := f.findBodyOffset()
if err != nil {
f.descErr = err
return
}
// In section 4.3.9.2 of the spec: "However ZIP64 format MAY be used
// regardless of the size of a file. When extracting, if the zip64
// extended information extra field is present for the file the
// compressed and uncompressed sizes will be 8 byte values."
//
// Historically, this package has used the compressed and uncompressed
// sizes from the central directory to determine if the package is
// zip64.
//
// For this case we allow either the extra field or sizes to determine
// the data descriptor length.
zip64 := f.zip64 || f.isZip64()
n := int64(dataDescriptorLen)
if zip64 {
n = dataDescriptor64Len
}
size := int64(f.CompressedSize64)
r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, n)
dd, err := readDataDescriptor(r, zip64)
if err != nil {
f.descErr = err
return
}
f.CRC32 = dd.crc32
}
type checksumReader struct {
rc io.ReadCloser
hash hash.Hash32
nread uint64 // number of bytes read so far
f *File
err error // sticky error
desr io.Reader // if non-nil, where to read the data descriptor
err error // sticky error
}
func (r *checksumReader) Stat() (fs.FileInfo, error) {
@@ -268,12 +220,12 @@ func (r *checksumReader) Read(b []byte) (n int, err error) {
if r.nread != r.f.UncompressedSize64 {
return 0, io.ErrUnexpectedEOF
}
if r.f.hasDataDescriptor() {
if r.f.descErr != nil {
if r.f.descErr == io.EOF {
if r.desr != nil {
if err1 := readDataDescriptor(r.desr, r.f); err1 != nil {
if err1 == io.EOF {
err = io.ErrUnexpectedEOF
} else {
err = r.f.descErr
err = err1
}
} else if r.hash.Sum32() != r.f.CRC32 {
err = ErrChecksum
@@ -384,8 +336,6 @@ parseExtras:
switch fieldTag {
case zip64ExtraID:
f.zip64 = true
// update directory values from the zip64 extra block.
// They should only be consulted if the sizes read earlier
// are maxed out.
@@ -485,9 +435,8 @@ parseExtras:
return nil
}
func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
// Create enough space for the largest possible size
var buf [dataDescriptor64Len]byte
func readDataDescriptor(r io.Reader, f *File) error {
var buf [dataDescriptorLen]byte
// The spec says: "Although not originally assigned a
// signature, the value 0x08074b50 has commonly been adopted
@@ -497,9 +446,10 @@ func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
// descriptors and should account for either case when reading
// ZIP files to ensure compatibility."
//
// First read just those 4 bytes to see if the signature exists.
// dataDescriptorLen includes the size of the signature but
// first read just those 4 bytes to see if it exists.
if _, err := io.ReadFull(r, buf[:4]); err != nil {
return nil, err
return err
}
off := 0
maybeSig := readBuf(buf[:4])
@@ -508,28 +458,21 @@ func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
// bytes.
off += 4
}
end := dataDescriptorLen - 4
if zip64 {
end = dataDescriptor64Len - 4
if _, err := io.ReadFull(r, buf[off:12]); err != nil {
return err
}
if _, err := io.ReadFull(r, buf[off:end]); err != nil {
return nil, err
}
b := readBuf(buf[:end])
out := &dataDescriptor{
crc32: b.uint32(),
b := readBuf(buf[:12])
if b.uint32() != f.CRC32 {
return ErrChecksum
}
if zip64 {
out.compressedSize = b.uint64()
out.uncompressedSize = b.uint64()
} else {
out.compressedSize = uint64(b.uint32())
out.uncompressedSize = uint64(b.uint32())
}
return out, nil
// The two sizes that follow here can be either 32 bits or 64 bits
// but the spec is not very clear on this and different
// interpretations has been made causing incompatibilities. We
// already have the sizes from the central directory so we can
// just ignore these.
return nil
}
func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) {
@@ -685,11 +628,10 @@ func (b *readBuf) sub(n int) readBuf {
}
// A fileListEntry is a File and its ename.
// If file == nil, the fileListEntry describes a directory without metadata.
// If file == nil, the fileListEntry describes a directory, without metadata.
type fileListEntry struct {
name string
file *File
isDir bool
name string
file *File // nil for directories
}
type fileInfoDirEntry interface {
@@ -698,26 +640,20 @@ type fileInfoDirEntry interface {
}
func (e *fileListEntry) stat() fileInfoDirEntry {
if !e.isDir {
if e.file != nil {
return headerFileInfo{&e.file.FileHeader}
}
return e
}
// Only used for directories.
func (f *fileListEntry) Name() string { _, elem, _ := split(f.name); return elem }
func (f *fileListEntry) Size() int64 { return 0 }
func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }
func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }
func (f *fileListEntry) IsDir() bool { return true }
func (f *fileListEntry) Sys() interface{} { return nil }
func (f *fileListEntry) ModTime() time.Time {
if f.file == nil {
return time.Time{}
}
return f.file.FileHeader.Modified.UTC()
}
func (f *fileListEntry) Name() string { _, elem, _ := split(f.name); return elem }
func (f *fileListEntry) Size() int64 { return 0 }
func (f *fileListEntry) ModTime() time.Time { return time.Time{} }
func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }
func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }
func (f *fileListEntry) IsDir() bool { return true }
func (f *fileListEntry) Sys() interface{} { return nil }
func (f *fileListEntry) Info() (fs.FileInfo, error) { return f, nil }
@@ -728,7 +664,7 @@ func toValidName(name string) string {
if strings.HasPrefix(p, "/") {
p = p[len("/"):]
}
for strings.HasPrefix(p, "../") {
for strings.HasPrefix(name, "../") {
p = p[len("../"):]
}
return p
@@ -737,32 +673,15 @@ func toValidName(name string) string {
func (r *Reader) initFileList() {
r.fileListOnce.Do(func() {
dirs := make(map[string]bool)
knownDirs := make(map[string]bool)
for _, file := range r.File {
isDir := len(file.Name) > 0 && file.Name[len(file.Name)-1] == '/'
name := toValidName(file.Name)
for dir := path.Dir(name); dir != "."; dir = path.Dir(dir) {
dirs[dir] = true
}
entry := fileListEntry{
name: name,
file: file,
isDir: isDir,
}
r.fileList = append(r.fileList, entry)
if isDir {
knownDirs[name] = true
}
r.fileList = append(r.fileList, fileListEntry{name, file})
}
for dir := range dirs {
if !knownDirs[dir] {
entry := fileListEntry{
name: dir,
file: nil,
isDir: true,
}
r.fileList = append(r.fileList, entry)
}
r.fileList = append(r.fileList, fileListEntry{dir + "/", nil})
}
sort.Slice(r.fileList, func(i, j int) bool { return fileEntryLess(r.fileList[i].name, r.fileList[j].name) })
@@ -786,7 +705,7 @@ func (r *Reader) Open(name string) (fs.File, error) {
if e == nil || !fs.ValidPath(name) {
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
}
if e.isDir {
if e.file == nil || strings.HasSuffix(e.file.Name, "/") {
return &openDir{e, r.openReadDir(name), 0}, nil
}
rc, err := e.file.Open()
@@ -811,7 +730,7 @@ func split(name string) (dir, elem string, isDir bool) {
return name[:i], name[i+1:], isDir
}
var dotFile = &fileListEntry{name: "./", isDir: true}
var dotFile = &fileListEntry{name: "./"}
func (r *Reader) openLookup(name string) *fileListEntry {
if name == "." {

View File

@@ -499,15 +499,9 @@ func TestReader(t *testing.T) {
func readTestZip(t *testing.T, zt ZipTest) {
var z *Reader
var err error
var raw []byte
if zt.Source != nil {
rat, size := zt.Source()
z, err = NewReader(rat, size)
raw = make([]byte, size)
if _, err := rat.ReadAt(raw, 0); err != nil {
t.Errorf("ReadAt error=%v", err)
return
}
} else {
path := filepath.Join("testdata", zt.Name)
if zt.Obscured {
@@ -525,12 +519,6 @@ func readTestZip(t *testing.T, zt ZipTest) {
defer rc.Close()
z = &rc.Reader
}
var err2 error
raw, err2 = os.ReadFile(path)
if err2 != nil {
t.Errorf("ReadFile(%s) error=%v", path, err2)
return
}
}
if err != zt.Error {
t.Errorf("error=%v, want %v", err, zt.Error)
@@ -557,7 +545,7 @@ func readTestZip(t *testing.T, zt ZipTest) {
// test read of each file
for i, ft := range zt.File {
readTestFile(t, zt, ft, z.File[i], raw)
readTestFile(t, zt, ft, z.File[i])
}
if t.Failed() {
return
@@ -569,7 +557,7 @@ func readTestZip(t *testing.T, zt ZipTest) {
for i := 0; i < 5; i++ {
for j, ft := range zt.File {
go func(j int, ft ZipTestFile) {
readTestFile(t, zt, ft, z.File[j], raw)
readTestFile(t, zt, ft, z.File[j])
done <- true
}(j, ft)
n++
@@ -586,7 +574,7 @@ func equalTimeAndZone(t1, t2 time.Time) bool {
return t1.Equal(t2) && name1 == name2 && offset1 == offset2
}
func readTestFile(t *testing.T, zt ZipTest, ft ZipTestFile, f *File, raw []byte) {
func readTestFile(t *testing.T, zt ZipTest, ft ZipTestFile, f *File) {
if f.Name != ft.Name {
t.Errorf("name=%q, want %q", f.Name, ft.Name)
}
@@ -606,31 +594,6 @@ func readTestFile(t *testing.T, zt ZipTest, ft ZipTestFile, f *File, raw []byte)
t.Errorf("%v: UncompressedSize=%#x does not match UncompressedSize64=%#x", f.Name, size, f.UncompressedSize64)
}
// Check that OpenRaw returns the correct byte segment
rw, err := f.OpenRaw()
if err != nil {
t.Errorf("%v: OpenRaw error=%v", f.Name, err)
return
}
start, err := f.DataOffset()
if err != nil {
t.Errorf("%v: DataOffset error=%v", f.Name, err)
return
}
got, err := io.ReadAll(rw)
if err != nil {
t.Errorf("%v: OpenRaw ReadAll error=%v", f.Name, err)
return
}
end := uint64(start) + f.CompressedSize64
want := raw[start:end]
if !bytes.Equal(got, want) {
t.Logf("got %q", got)
t.Logf("want %q", want)
t.Errorf("%v: OpenRaw returned unexpected bytes", f.Name)
return
}
r, err := f.Open()
if err != nil {
t.Errorf("%v", err)
@@ -813,8 +776,8 @@ func returnRecursiveZip() (r io.ReaderAt, size int64) {
// "archive/zip"
// "bytes"
// "io"
// "io/ioutil"
// "log"
// "os"
// )
//
// type zeros struct{}
@@ -1110,277 +1073,11 @@ func TestIssue12449(t *testing.T) {
}
func TestFS(t *testing.T) {
for _, test := range []struct {
file string
want []string
}{
{
"testdata/unix.zip",
[]string{"hello", "dir/bar", "readonly"},
},
{
"testdata/subdir.zip",
[]string{"a/b/c"},
},
} {
t.Run(test.file, func(t *testing.T) {
t.Parallel()
z, err := OpenReader(test.file)
if err != nil {
t.Fatal(err)
}
defer z.Close()
if err := fstest.TestFS(z, test.want...); err != nil {
t.Error(err)
}
})
}
}
func TestFSModTime(t *testing.T) {
t.Parallel()
z, err := OpenReader("testdata/subdir.zip")
z, err := OpenReader("testdata/unix.zip")
if err != nil {
t.Fatal(err)
}
defer z.Close()
for _, test := range []struct {
name string
want time.Time
}{
{
"a",
time.Date(2021, 4, 19, 12, 29, 56, 0, timeZone(-7*time.Hour)).UTC(),
},
{
"a/b/c",
time.Date(2021, 4, 19, 12, 29, 59, 0, timeZone(-7*time.Hour)).UTC(),
},
} {
fi, err := fs.Stat(z, test.name)
if err != nil {
t.Errorf("%s: %v", test.name, err)
continue
}
if got := fi.ModTime(); !got.Equal(test.want) {
t.Errorf("%s: got modtime %v, want %v", test.name, got, test.want)
}
}
}
func TestCVE202127919(t *testing.T) {
// Archive containing only the file "../test.txt"
data := []byte{
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x2e, 0x2e,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78,
0x74, 0x0a, 0xc9, 0xc8, 0x2c, 0x56, 0xc8, 0x2c,
0x56, 0x48, 0x54, 0x28, 0x49, 0x2d, 0x2e, 0x51,
0x28, 0x49, 0xad, 0x28, 0x51, 0x48, 0xcb, 0xcc,
0x49, 0xd5, 0xe3, 0x02, 0x04, 0x00, 0x00, 0xff,
0xff, 0x50, 0x4b, 0x07, 0x08, 0xc0, 0xd7, 0xed,
0xc3, 0x20, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00,
0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14,
0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xd7, 0xed, 0xc3, 0x20, 0x00, 0x00,
0x00, 0x1a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e,
0x2e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
0x78, 0x74, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x39, 0x00,
0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00,
}
r, err := NewReader(bytes.NewReader([]byte(data)), int64(len(data)))
if err != nil {
t.Fatalf("Error reading the archive: %v", err)
}
_, err = r.Open("test.txt")
if err != nil {
t.Errorf("Error reading file: %v", err)
}
}
func TestReadDataDescriptor(t *testing.T) {
tests := []struct {
desc string
in []byte
zip64 bool
want *dataDescriptor
wantErr error
}{{
desc: "valid 32 bit with signature",
in: []byte{
0x50, 0x4b, 0x07, 0x08, // signature
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, // compressed size
0x08, 0x09, 0x0a, 0x0b, // uncompressed size
},
want: &dataDescriptor{
crc32: 0x03020100,
compressedSize: 0x07060504,
uncompressedSize: 0x0b0a0908,
},
}, {
desc: "valid 32 bit without signature",
in: []byte{
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, // compressed size
0x08, 0x09, 0x0a, 0x0b, // uncompressed size
},
want: &dataDescriptor{
crc32: 0x03020100,
compressedSize: 0x07060504,
uncompressedSize: 0x0b0a0908,
},
}, {
desc: "valid 64 bit with signature",
in: []byte{
0x50, 0x4b, 0x07, 0x08, // signature
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, // uncompressed size
},
zip64: true,
want: &dataDescriptor{
crc32: 0x03020100,
compressedSize: 0x0b0a090807060504,
uncompressedSize: 0x131211100f0e0d0c,
},
}, {
desc: "valid 64 bit without signature",
in: []byte{
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, // uncompressed size
},
zip64: true,
want: &dataDescriptor{
crc32: 0x03020100,
compressedSize: 0x0b0a090807060504,
uncompressedSize: 0x131211100f0e0d0c,
},
}, {
desc: "invalid 32 bit with signature",
in: []byte{
0x50, 0x4b, 0x07, 0x08, // signature
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, // unexpected end
},
wantErr: io.ErrUnexpectedEOF,
}, {
desc: "invalid 32 bit without signature",
in: []byte{
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, // unexpected end
},
wantErr: io.ErrUnexpectedEOF,
}, {
desc: "invalid 64 bit with signature",
in: []byte{
0x50, 0x4b, 0x07, 0x08, // signature
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, // unexpected end
},
zip64: true,
wantErr: io.ErrUnexpectedEOF,
}, {
desc: "invalid 64 bit without signature",
in: []byte{
0x00, 0x01, 0x02, 0x03, // crc32
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, // unexpected end
},
zip64: true,
wantErr: io.ErrUnexpectedEOF,
}}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
r := bytes.NewReader(test.in)
desc, err := readDataDescriptor(r, test.zip64)
if err != test.wantErr {
t.Fatalf("got err %v; want nil", err)
}
if test.want == nil {
return
}
if desc == nil {
t.Fatalf("got nil DataDescriptor; want non-nil")
}
if desc.crc32 != test.want.crc32 {
t.Errorf("got CRC32 %#x; want %#x", desc.crc32, test.want.crc32)
}
if desc.compressedSize != test.want.compressedSize {
t.Errorf("got CompressedSize %#x; want %#x", desc.compressedSize, test.want.compressedSize)
}
if desc.uncompressedSize != test.want.uncompressedSize {
t.Errorf("got UncompressedSize %#x; want %#x", desc.uncompressedSize, test.want.uncompressedSize)
}
})
}
}
func TestCVE202133196(t *testing.T) {
// Archive that indicates it has 1 << 128 -1 files,
// this would previously cause a panic due to attempting
// to allocate a slice with 1 << 128 -1 elements.
data := []byte{
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x08,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x02,
0x03, 0x62, 0x61, 0x65, 0x03, 0x04, 0x00, 0x00,
0xff, 0xff, 0x50, 0x4b, 0x07, 0x08, 0xbe, 0x20,
0x5c, 0x6c, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00,
0x14, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0xbe, 0x20, 0x5c, 0x6c, 0x09, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0x03, 0x50, 0x4b, 0x06, 0x06, 0x2c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d,
0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x31, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x50, 0x4b, 0x06, 0x07, 0x00,
0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50,
0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00,
}
_, err := NewReader(bytes.NewReader(data), int64(len(data)))
if err != ErrFormat {
t.Fatalf("unexpected error, got: %v, want: %v", err, ErrFormat)
}
// Also check that an archive containing a handful of empty
// files doesn't cause an issue
b := bytes.NewBuffer(nil)
w := NewWriter(b)
for i := 0; i < 5; i++ {
_, err := w.Create("")
if err != nil {
t.Fatalf("Writer.Create failed: %s", err)
}
}
if err := w.Close(); err != nil {
t.Fatalf("Writer.Close failed: %s", err)
}
r, err := NewReader(bytes.NewReader(b.Bytes()), int64(b.Len()))
if err != nil {
t.Fatalf("NewReader failed: %s", err)
}
if len(r.File) != 5 {
t.Errorf("Archive has unexpected number of files, got %d, want 5", len(r.File))
if err := fstest.TestFS(z, "hello", "dir/bar", "dir/empty", "readonly"); err != nil {
t.Fatal(err)
}
}

View File

@@ -42,7 +42,7 @@ const (
directoryHeaderLen = 46 // + filename + extra + comment
directoryEndLen = 22 // + comment
dataDescriptorLen = 16 // four uint32: descriptor signature, crc32, compressed size, size
dataDescriptor64Len = 24 // two uint32: signature, crc32 | two uint64: compressed size, size
dataDescriptor64Len = 24 // descriptor with 8 byte sizes
directory64LocLen = 20 //
directory64EndLen = 56 // + extra
@@ -315,10 +315,6 @@ func (h *FileHeader) isZip64() bool {
return h.CompressedSize64 >= uint32max || h.UncompressedSize64 >= uint32max
}
func (f *FileHeader) hasDataDescriptor() bool {
return f.Flags&0x8 != 0
}
func msdosModeToFileMode(m uint32) (mode fs.FileMode) {
if m&msdosDir != 0 {
mode = fs.ModeDir | 0777
@@ -345,9 +341,11 @@ func fileModeToUnixMode(mode fs.FileMode) uint32 {
case fs.ModeSocket:
m = s_IFSOCK
case fs.ModeDevice:
m = s_IFBLK
case fs.ModeDevice | fs.ModeCharDevice:
m = s_IFCHR
if mode&fs.ModeCharDevice != 0 {
m = s_IFCHR
} else {
m = s_IFBLK
}
}
if mode&fs.ModeSetuid != 0 {
m |= s_ISUID
@@ -390,11 +388,3 @@ func unixModeToFileMode(m uint32) fs.FileMode {
}
return mode
}
// dataDescriptor holds the data descriptor that optionally follows the file
// contents in the zip file.
type dataDescriptor struct {
crc32 uint32
compressedSize uint64
uncompressedSize uint64
}

Binary file not shown.

View File

@@ -37,7 +37,6 @@ type Writer struct {
type header struct {
*FileHeader
offset uint64
raw bool
}
// NewWriter returns a new Writer writing a zip file to w.
@@ -246,31 +245,22 @@ func detectUTF8(s string) (valid, require bool) {
return true, require
}
// prepare performs the bookkeeping operations required at the start of
// CreateHeader and CreateRaw.
func (w *Writer) prepare(fh *FileHeader) error {
if w.last != nil && !w.last.closed {
if err := w.last.close(); err != nil {
return err
}
}
if len(w.dir) > 0 && w.dir[len(w.dir)-1].FileHeader == fh {
// See https://golang.org/issue/11144 confusion.
return errors.New("archive/zip: invalid duplicate FileHeader")
}
return nil
}
// CreateHeader adds a file to the zip archive using the provided FileHeader
// for the file metadata. Writer takes ownership of fh and may mutate
// its fields. The caller must not modify fh after calling CreateHeader.
//
// This returns a Writer to which the file contents should be written.
// The file's contents must be written to the io.Writer before the next
// call to Create, CreateHeader, CreateRaw, or Close.
// call to Create, CreateHeader, or Close.
func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
if err := w.prepare(fh); err != nil {
return nil, err
if w.last != nil && !w.last.closed {
if err := w.last.close(); err != nil {
return nil, err
}
}
if len(w.dir) > 0 && w.dir[len(w.dir)-1].FileHeader == fh {
// See https://golang.org/issue/11144 confusion.
return nil, errors.New("archive/zip: invalid duplicate FileHeader")
}
// The ZIP format has a sad state of affairs regarding character encoding.
@@ -375,7 +365,7 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
ow = fw
}
w.dir = append(w.dir, h)
if err := writeHeader(w.cw, h); err != nil {
if err := writeHeader(w.cw, fh); err != nil {
return nil, err
}
// If we're creating a directory, fw is nil.
@@ -383,7 +373,7 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
return ow, nil
}
func writeHeader(w io.Writer, h *header) error {
func writeHeader(w io.Writer, h *FileHeader) error {
const maxUint16 = 1<<16 - 1
if len(h.Name) > maxUint16 {
return errLongName
@@ -400,20 +390,9 @@ func writeHeader(w io.Writer, h *header) error {
b.uint16(h.Method)
b.uint16(h.ModifiedTime)
b.uint16(h.ModifiedDate)
// In raw mode (caller does the compression), the values are either
// written here or in the trailing data descriptor based on the header
// flags.
if h.raw && !h.hasDataDescriptor() {
b.uint32(h.CRC32)
b.uint32(uint32(min64(h.CompressedSize64, uint32max)))
b.uint32(uint32(min64(h.UncompressedSize64, uint32max)))
} else {
// When this package handle the compression, these values are
// always written to the trailing data descriptor.
b.uint32(0) // crc32
b.uint32(0) // compressed size
b.uint32(0) // uncompressed size
}
b.uint32(0) // since we are writing a data descriptor crc32,
b.uint32(0) // compressed size,
b.uint32(0) // and uncompressed size should be zero
b.uint16(uint16(len(h.Name)))
b.uint16(uint16(len(h.Extra)))
if _, err := w.Write(buf[:]); err != nil {
@@ -426,65 +405,6 @@ func writeHeader(w io.Writer, h *header) error {
return err
}
func min64(x, y uint64) uint64 {
if x < y {
return x
}
return y
}
// CreateRaw adds a file to the zip archive using the provided FileHeader and
// returns a Writer to which the file contents should be written. The file's
// contents must be written to the io.Writer before the next call to Create,
// CreateHeader, CreateRaw, or Close.
//
// In contrast to CreateHeader, the bytes passed to Writer are not compressed.
func (w *Writer) CreateRaw(fh *FileHeader) (io.Writer, error) {
if err := w.prepare(fh); err != nil {
return nil, err
}
fh.CompressedSize = uint32(min64(fh.CompressedSize64, uint32max))
fh.UncompressedSize = uint32(min64(fh.UncompressedSize64, uint32max))
h := &header{
FileHeader: fh,
offset: uint64(w.cw.count),
raw: true,
}
w.dir = append(w.dir, h)
if err := writeHeader(w.cw, h); err != nil {
return nil, err
}
if strings.HasSuffix(fh.Name, "/") {
w.last = nil
return dirWriter{}, nil
}
fw := &fileWriter{
header: h,
zipw: w.cw,
}
w.last = fw
return fw, nil
}
// Copy copies the file f (obtained from a Reader) into w. It copies the raw
// form directly bypassing decompression, compression, and validation.
func (w *Writer) Copy(f *File) error {
r, err := f.OpenRaw()
if err != nil {
return err
}
fw, err := w.CreateRaw(&f.FileHeader)
if err != nil {
return err
}
_, err = io.Copy(fw, r)
return err
}
// RegisterCompressor registers or overrides a custom compressor for a specific
// method ID. If a compressor for a given method is not found, Writer will
// default to looking up the compressor at the package level.
@@ -526,9 +446,6 @@ func (w *fileWriter) Write(p []byte) (int, error) {
if w.closed {
return 0, errors.New("zip: write to closed file")
}
if w.raw {
return w.zipw.Write(p)
}
w.crc32.Write(p)
return w.rawCount.Write(p)
}
@@ -538,9 +455,6 @@ func (w *fileWriter) close() error {
return errors.New("zip: file closed twice")
}
w.closed = true
if w.raw {
return w.writeDataDescriptor()
}
if err := w.comp.Close(); err != nil {
return err
}
@@ -560,33 +474,26 @@ func (w *fileWriter) close() error {
fh.UncompressedSize = uint32(fh.UncompressedSize64)
}
return w.writeDataDescriptor()
}
func (w *fileWriter) writeDataDescriptor() error {
if !w.hasDataDescriptor() {
return nil
}
// Write data descriptor. This is more complicated than one would
// think, see e.g. comments in zipfile.c:putextended() and
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7073588.
// The approach here is to write 8 byte sizes if needed without
// adding a zip64 extra in the local header (too late anyway).
var buf []byte
if w.isZip64() {
if fh.isZip64() {
buf = make([]byte, dataDescriptor64Len)
} else {
buf = make([]byte, dataDescriptorLen)
}
b := writeBuf(buf)
b.uint32(dataDescriptorSignature) // de-facto standard, required by OS X
b.uint32(w.CRC32)
if w.isZip64() {
b.uint64(w.CompressedSize64)
b.uint64(w.UncompressedSize64)
b.uint32(fh.CRC32)
if fh.isZip64() {
b.uint64(fh.CompressedSize64)
b.uint64(fh.UncompressedSize64)
} else {
b.uint32(w.CompressedSize)
b.uint32(w.UncompressedSize)
b.uint32(fh.CompressedSize)
b.uint32(fh.UncompressedSize)
}
_, err := w.zipw.Write(buf)
return err

View File

@@ -6,10 +6,8 @@ package zip
import (
"bytes"
"compress/flate"
"encoding/binary"
"fmt"
"hash/crc32"
"io"
"io/fs"
"math/rand"
@@ -59,18 +57,6 @@ var writeTests = []WriteTest{
Method: Deflate,
Mode: 0755 | fs.ModeSymlink,
},
{
Name: "device",
Data: []byte("device file"),
Method: Deflate,
Mode: 0755 | fs.ModeDevice,
},
{
Name: "chardevice",
Data: []byte("char device file"),
Method: Deflate,
Mode: 0755 | fs.ModeDevice | fs.ModeCharDevice,
},
}
func TestWriter(t *testing.T) {
@@ -367,171 +353,6 @@ func TestWriterDirAttributes(t *testing.T) {
}
}
func TestWriterCopy(t *testing.T) {
// make a zip file
buf := new(bytes.Buffer)
w := NewWriter(buf)
for _, wt := range writeTests {
testCreate(t, w, &wt)
}
if err := w.Close(); err != nil {
t.Fatal(err)
}
// read it back
src, err := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if err != nil {
t.Fatal(err)
}
for i, wt := range writeTests {
testReadFile(t, src.File[i], &wt)
}
// make a new zip file copying the old compressed data.
buf2 := new(bytes.Buffer)
dst := NewWriter(buf2)
for _, f := range src.File {
if err := dst.Copy(f); err != nil {
t.Fatal(err)
}
}
if err := dst.Close(); err != nil {
t.Fatal(err)
}
// read the new one back
r, err := NewReader(bytes.NewReader(buf2.Bytes()), int64(buf2.Len()))
if err != nil {
t.Fatal(err)
}
for i, wt := range writeTests {
testReadFile(t, r.File[i], &wt)
}
}
func TestWriterCreateRaw(t *testing.T) {
files := []struct {
name string
content []byte
method uint16
flags uint16
crc32 uint32
uncompressedSize uint64
compressedSize uint64
}{
{
name: "small store w desc",
content: []byte("gophers"),
method: Store,
flags: 0x8,
},
{
name: "small deflate wo desc",
content: bytes.Repeat([]byte("abcdefg"), 2048),
method: Deflate,
},
}
// write a zip file
archive := new(bytes.Buffer)
w := NewWriter(archive)
for i := range files {
f := &files[i]
f.crc32 = crc32.ChecksumIEEE(f.content)
size := uint64(len(f.content))
f.uncompressedSize = size
f.compressedSize = size
var compressedContent []byte
if f.method == Deflate {
var buf bytes.Buffer
w, err := flate.NewWriter(&buf, flate.BestSpeed)
if err != nil {
t.Fatalf("flate.NewWriter err = %v", err)
}
_, err = w.Write(f.content)
if err != nil {
t.Fatalf("flate Write err = %v", err)
}
err = w.Close()
if err != nil {
t.Fatalf("flate Writer.Close err = %v", err)
}
compressedContent = buf.Bytes()
f.compressedSize = uint64(len(compressedContent))
}
h := &FileHeader{
Name: f.name,
Method: f.method,
Flags: f.flags,
CRC32: f.crc32,
CompressedSize64: f.compressedSize,
UncompressedSize64: f.uncompressedSize,
}
w, err := w.CreateRaw(h)
if err != nil {
t.Fatal(err)
}
if compressedContent != nil {
_, err = w.Write(compressedContent)
} else {
_, err = w.Write(f.content)
}
if err != nil {
t.Fatalf("%s Write got %v; want nil", f.name, err)
}
}
if err := w.Close(); err != nil {
t.Fatal(err)
}
// read it back
r, err := NewReader(bytes.NewReader(archive.Bytes()), int64(archive.Len()))
if err != nil {
t.Fatal(err)
}
for i, want := range files {
got := r.File[i]
if got.Name != want.name {
t.Errorf("got Name %s; want %s", got.Name, want.name)
}
if got.Method != want.method {
t.Errorf("%s: got Method %#x; want %#x", want.name, got.Method, want.method)
}
if got.Flags != want.flags {
t.Errorf("%s: got Flags %#x; want %#x", want.name, got.Flags, want.flags)
}
if got.CRC32 != want.crc32 {
t.Errorf("%s: got CRC32 %#x; want %#x", want.name, got.CRC32, want.crc32)
}
if got.CompressedSize64 != want.compressedSize {
t.Errorf("%s: got CompressedSize64 %d; want %d", want.name, got.CompressedSize64, want.compressedSize)
}
if got.UncompressedSize64 != want.uncompressedSize {
t.Errorf("%s: got UncompressedSize64 %d; want %d", want.name, got.UncompressedSize64, want.uncompressedSize)
}
r, err := got.Open()
if err != nil {
t.Errorf("%s: Open err = %v", got.Name, err)
continue
}
buf, err := io.ReadAll(r)
if err != nil {
t.Errorf("%s: ReadAll err = %v", got.Name, err)
continue
}
if !bytes.Equal(buf, want.content) {
t.Errorf("%v: ReadAll returned unexpected bytes", got.Name)
}
}
}
func testCreate(t *testing.T, w *Writer, wt *WriteTest) {
header := &FileHeader{
Name: wt.Name,
@@ -557,15 +378,15 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
testFileMode(t, f, wt.Mode)
rc, err := f.Open()
if err != nil {
t.Fatalf("opening %s: %v", f.Name, err)
t.Fatal("opening:", err)
}
b, err := io.ReadAll(rc)
if err != nil {
t.Fatalf("reading %s: %v", f.Name, err)
t.Fatal("reading:", err)
}
err = rc.Close()
if err != nil {
t.Fatalf("closing %s: %v", f.Name, err)
t.Fatal("closing:", err)
}
if !bytes.Equal(b, wt.Data) {
t.Errorf("File contents %q, want %q", b, wt.Data)

View File

@@ -48,8 +48,7 @@ type Scanner struct {
// and the next token to return to the user, if any, plus an error, if any.
//
// Scanning stops if the function returns an error, in which case some of
// the input may be discarded. If that error is ErrFinalToken, scanning
// stops with no error.
// the input may be discarded.
//
// Otherwise, the Scanner advances the input. If the token is not nil,
// the Scanner returns it to the user. If the token is nil, the

View File

@@ -215,7 +215,8 @@ func main() {
}
optional := fileFeatures(*nextFile)
exception := fileFeatures(*exceptFile)
fail = !compareAPI(bw, features, required, optional, exception, *allowNew)
fail = !compareAPI(bw, features, required, optional, exception,
*allowNew && strings.Contains(runtime.Version(), "devel"))
}
// export emits the exported package features.

View File

@@ -10,11 +10,8 @@
package main
import (
"errors"
"fmt"
exec "internal/execabs"
"internal/goversion"
"io/fs"
"log"
"os"
"path/filepath"
@@ -46,7 +43,6 @@ func main() {
apiDir := filepath.Join(goroot, "api")
out, err := exec.Command(goCmd(), "tool", "api",
"-c", findAPIDirFiles(apiDir),
allowNew(apiDir),
"-next", filepath.Join(apiDir, "next.txt"),
"-except", filepath.Join(apiDir, "except.txt")).CombinedOutput()
if err != nil {
@@ -75,35 +71,3 @@ func findAPIDirFiles(apiDir string) string {
}
return strings.Join(apiFiles, ",")
}
// allowNew returns the -allow_new flag to use for the 'go tool api' invocation.
func allowNew(apiDir string) string {
// Verify that the api/go1.n.txt for previous Go version exists.
// It definitely should, otherwise it's a signal that the logic below may be outdated.
if _, err := os.Stat(filepath.Join(apiDir, fmt.Sprintf("go1.%d.txt", goversion.Version-1))); err != nil {
log.Fatalln("Problem with api file for previous release:", err)
}
// See whether the api/go1.n.txt for this Go version has been created.
// (As of April 2021, it gets created during the release of the first Beta.)
_, err := os.Stat(filepath.Join(apiDir, fmt.Sprintf("go1.%d.txt", goversion.Version)))
if errors.Is(err, fs.ErrNotExist) {
// It doesn't exist, so we're in development or before Beta 1.
// At this stage, unmentioned API additions are deemed okay.
// (They will be quietly shown in API check output, but the test won't fail).
return "-allow_new=true"
} else if err == nil {
// The api/go1.n.txt for this Go version has been created,
// so we're definitely past Beta 1 in the release cycle.
//
// From this point, enforce that api/go1.n.txt is an accurate and complete
// representation of what's going into the release by failing API check if
// there are API additions (a month into the freeze, there shouldn't be many).
//
// See golang.org/issue/43956.
return "-allow_new=false"
} else {
log.Fatal(err)
}
panic("unreachable")
}

View File

@@ -147,16 +147,7 @@ func arm64RegisterNumber(name string, n int16) (int16, bool) {
return 0, false
}
// ARM64RegisterShift constructs an ARM64 register with shift operation.
func ARM64RegisterShift(reg, op, count int16) (int64, error) {
// the base register of shift operations must be general register.
if reg > arm64.REG_R31 || reg < arm64.REG_R0 {
return 0, errors.New("invalid register for shift operation")
}
return int64(reg&31)<<16 | int64(op)<<22 | int64(uint16(count)), nil
}
// ARM64RegisterExtension constructs an ARM64 register with extension or arrangement.
// ARM64RegisterExtension parses an ARM64 register with extension or arrangement.
func ARM64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, isIndex bool) error {
Rnum := (reg & 31) + int16(num<<5)
if isAmount {
@@ -164,163 +155,154 @@ func ARM64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, i
return errors.New("index shift amount is out of range")
}
}
if reg <= arm64.REG_R31 && reg >= arm64.REG_R0 {
switch ext {
case "UXTB":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_UXTB + Rnum
case "UXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_UXTH + Rnum
case "UXTW":
if !isAmount {
return errors.New("invalid register extension")
}
// effective address of memory is a base register value and an offset register value.
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_UXTW + Rnum
} else {
a.Reg = arm64.REG_UXTW + Rnum
}
case "UXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_UXTX + Rnum
case "SXTB":
if !isAmount {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_SXTB + Rnum
case "SXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_SXTH + Rnum
case "SXTW":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTW + Rnum
} else {
a.Reg = arm64.REG_SXTW + Rnum
}
case "SXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTX + Rnum
} else {
a.Reg = arm64.REG_SXTX + Rnum
}
case "LSL":
if !isAmount {
return errors.New("invalid register extension")
}
a.Index = arm64.REG_LSL + Rnum
default:
return errors.New("unsupported general register extension type: " + ext)
switch ext {
case "UXTB":
if !isAmount {
return errors.New("invalid register extension")
}
} else if reg <= arm64.REG_V31 && reg >= arm64.REG_V0 {
switch ext {
case "B8":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_8B & 15) << 5)
case "B16":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_16B & 15) << 5)
case "H4":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_4H & 15) << 5)
case "H8":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_8H & 15) << 5)
case "S2":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_2S & 15) << 5)
case "S4":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_4S & 15) << 5)
case "D1":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_1D & 15) << 5)
case "D2":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_2D & 15) << 5)
case "Q1":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_1Q & 15) << 5)
case "B":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_B & 15) << 5)
a.Index = num
case "H":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_H & 15) << 5)
a.Index = num
case "S":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_S & 15) << 5)
a.Index = num
case "D":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_D & 15) << 5)
a.Index = num
default:
return errors.New("unsupported simd register extension type: " + ext)
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
} else {
return errors.New("invalid register and extension combination")
a.Reg = arm64.REG_UXTB + Rnum
case "UXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_UXTH + Rnum
case "UXTW":
if !isAmount {
return errors.New("invalid register extension")
}
// effective address of memory is a base register value and an offset register value.
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_UXTW + Rnum
} else {
a.Reg = arm64.REG_UXTW + Rnum
}
case "UXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_UXTX + Rnum
case "SXTB":
if !isAmount {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_SXTB + Rnum
case "SXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode")
}
a.Reg = arm64.REG_SXTH + Rnum
case "SXTW":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTW + Rnum
} else {
a.Reg = arm64.REG_SXTW + Rnum
}
case "SXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTX + Rnum
} else {
a.Reg = arm64.REG_SXTX + Rnum
}
case "LSL":
if !isAmount {
return errors.New("invalid register extension")
}
a.Index = arm64.REG_LSL + Rnum
case "B8":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_8B & 15) << 5)
case "B16":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_16B & 15) << 5)
case "H4":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_4H & 15) << 5)
case "H8":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_8H & 15) << 5)
case "S2":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_2S & 15) << 5)
case "S4":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_4S & 15) << 5)
case "D1":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_1D & 15) << 5)
case "D2":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_2D & 15) << 5)
case "Q1":
if isIndex {
return errors.New("invalid register extension")
}
a.Reg = arm64.REG_ARNG + (reg & 31) + ((arm64.ARNG_1Q & 15) << 5)
case "B":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_B & 15) << 5)
a.Index = num
case "H":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_H & 15) << 5)
a.Index = num
case "S":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_S & 15) << 5)
a.Index = num
case "D":
if !isIndex {
return nil
}
a.Reg = arm64.REG_ELEM + (reg & 31) + ((arm64.ARNG_D & 15) << 5)
a.Index = num
default:
return errors.New("unsupported register extension type: " + ext)
}
return nil
}
// ARM64RegisterArrangement constructs an ARM64 vector register arrangement.
// ARM64RegisterArrangement parses an ARM64 vector register arrangement.
func ARM64RegisterArrangement(reg int16, name, arng string) (int64, error) {
var curQ, curSize uint16
if name[0] != 'V' {

View File

@@ -134,14 +134,6 @@ func (p *Parser) asmText(operands [][]lex.Token) {
next++
}
// Issue an error if we see a function defined as ABIInternal
// without NOSPLIT. In ABIInternal, obj needs to know the function
// signature in order to construct the morestack path, so this
// currently isn't supported for asm functions.
if nameAddr.Sym.ABI() == obj.ABIInternal && flag&obj.NOSPLIT == 0 {
p.errorf("TEXT %q: ABIInternal requires NOSPLIT", name)
}
// Next operand is the frame and arg size.
// Bizarre syntax: $frameSize-argSize is two words, not subtraction.
// Both frameSize and argSize must be simple integers; only frameSize
@@ -807,11 +799,19 @@ func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
p.errorf("can't handle %s instruction with 4 operands", op)
return
case 5:
if p.arch.Family == sys.PPC64 {
if p.arch.Family == sys.PPC64 && arch.IsPPC64RLD(op) {
// Always reg, reg, con, con, reg. (con, con is a 'mask').
prog.From = a[0]
// Second arg is always a register type on ppc64.
prog.Reg = p.getRegister(prog, op, &a[1])
prog.SetRestArgs([]obj.Addr{a[2], a[3]})
mask1 := p.getConstant(prog, op, &a[2])
mask2 := p.getConstant(prog, op, &a[3])
var mask uint32
if mask1 < mask2 {
mask = (^uint32(0) >> uint(mask1)) & (^uint32(0) << uint(31-mask2))
} else {
mask = (^uint32(0) >> uint(mask2+1)) & (^uint32(0) << uint(31-(mask1-1)))
}
prog.SetFrom3Const(int64(mask))
prog.To = a[4]
break
}

View File

@@ -8,7 +8,6 @@ import (
"bufio"
"bytes"
"fmt"
"internal/buildcfg"
"io/ioutil"
"os"
"path/filepath"
@@ -20,6 +19,7 @@ import (
"cmd/asm/internal/lex"
"cmd/internal/obj"
"cmd/internal/objabi"
)
// An end-to-end test for the assembler: Do we print what we parse?
@@ -270,7 +270,7 @@ var (
errQuotesRE = regexp.MustCompile(`"([^"]*)"`)
)
func testErrors(t *testing.T, goarch, file string, flags ...string) {
func testErrors(t *testing.T, goarch, file string) {
input := filepath.Join("testdata", file+".s")
architecture, ctxt := setArch(goarch)
lexer := lex.NewLexer(input)
@@ -292,14 +292,6 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
}
errBuf.WriteString(s)
}
for _, flag := range flags {
switch flag {
case "dynlink":
ctxt.Flag_dynlink = true
default:
t.Errorf("unknown flag %s", flag)
}
}
pList.Firstpc, ok = parser.Parse()
obj.Flushplist(ctxt, pList, nil, "")
if ok && !failed {
@@ -368,10 +360,10 @@ func Test386EndToEnd(t *testing.T) {
}
func TestARMEndToEnd(t *testing.T) {
defer func(old int) { buildcfg.GOARM = old }(buildcfg.GOARM)
defer func(old int) { objabi.GOARM = old }(objabi.GOARM)
for _, goarm := range []int{5, 6, 7} {
t.Logf("GOARM=%d", goarm)
buildcfg.GOARM = goarm
objabi.GOARM = goarm
testEndToEnd(t, "arm", "arm")
if goarm == 6 {
testEndToEnd(t, "arm", "armv6")
@@ -438,10 +430,6 @@ func TestAMD64Errors(t *testing.T) {
testErrors(t, "amd64", "amd64error")
}
func TestAMD64DynLinkErrors(t *testing.T) {
testErrors(t, "amd64", "amd64dynlinkerror", "dynlink")
}
func TestMIPSEndToEnd(t *testing.T) {
testEndToEnd(t, "mips", "mips")
testEndToEnd(t, "mips64", "mips64")

View File

@@ -5,20 +5,20 @@
package asm
import (
"internal/buildcfg"
"strings"
"testing"
"cmd/asm/internal/arch"
"cmd/asm/internal/lex"
"cmd/internal/obj"
"cmd/internal/objabi"
)
// A simple in-out test: Do we print what we parse?
func setArch(goarch string) (*arch.Arch, *obj.Link) {
buildcfg.GOOS = "linux" // obj can handle this OS for all architectures.
buildcfg.GOARCH = goarch
objabi.GOOS = "linux" // obj can handle this OS for all architectures.
objabi.GOARCH = goarch
architecture := arch.Set(goarch)
if architecture == nil {
panic("asm: unrecognized architecture " + goarch)

View File

@@ -689,11 +689,7 @@ func (p *Parser) registerShift(name string, prefix rune) int64 {
p.errorf("unexpected %s in register shift", tok.String())
}
if p.arch.Family == sys.ARM64 {
off, err := arch.ARM64RegisterShift(r1, op, count)
if err != nil {
p.errorf(err.Error())
}
return off
return int64(r1&31)<<16 | int64(op)<<22 | int64(uint16(count))
} else {
return int64((r1 & 15) | op<<5 | count)
}
@@ -1003,18 +999,15 @@ func (p *Parser) registerIndirect(a *obj.Addr, prefix rune) {
p.errorf("unimplemented two-register form")
}
a.Index = r1
if scale != 0 && scale != 1 && p.arch.Family == sys.ARM64 {
// Support (R1)(R2) (no scaling) and (R1)(R2*1).
p.errorf("arm64 doesn't support scaled register format")
if scale == 0 && p.arch.Family == sys.ARM64 {
// scale is 1 by default for ARM64
a.Scale = 1
} else {
a.Scale = int16(scale)
}
}
p.get(')')
} else if scale != 0 {
if p.arch.Family == sys.ARM64 {
p.errorf("arm64 doesn't support scaled register format")
}
// First (R) was missing, all we have is (R*scale).
a.Reg = 0
a.Index = r1

View File

@@ -25,13 +25,11 @@ func tokenize(s string) [][]lex.Token {
func TestErroneous(t *testing.T) {
type errtest struct {
tests := []struct {
pseudo string
operands string
expected string
}
nonRuntimeTests := []errtest{
}{
{"TEXT", "", "expect two or three operands for TEXT"},
{"TEXT", "%", "expect two or three operands for TEXT"},
{"TEXT", "1, 1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
@@ -60,44 +58,23 @@ func TestErroneous(t *testing.T) {
{"PCDATA", "1", "expect two operands for PCDATA"},
}
runtimeTests := []errtest{
{"TEXT", "foo<ABIInternal>(SB),0", "TEXT \"foo\": ABIInternal requires NOSPLIT"},
}
testcats := []struct {
compilingRuntime bool
tests []errtest
}{
{
compilingRuntime: false,
tests: nonRuntimeTests,
},
{
compilingRuntime: true,
tests: runtimeTests,
},
}
// Note these errors should be independent of the architecture.
// Just run the test with amd64.
parser := newParser("amd64")
var buf bytes.Buffer
parser.errorWriter = &buf
for _, cat := range testcats {
for _, test := range cat.tests {
parser.compilingRuntime = cat.compilingRuntime
parser.errorCount = 0
parser.lineNum++
if !parser.pseudo(test.pseudo, tokenize(test.operands)) {
t.Fatalf("Wrong pseudo-instruction: %s", test.pseudo)
}
errorLine := buf.String()
if test.expected != errorLine {
t.Errorf("Unexpected error %q; expected %q", errorLine, test.expected)
}
buf.Reset()
for _, test := range tests {
parser.errorCount = 0
parser.lineNum++
if !parser.pseudo(test.pseudo, tokenize(test.operands)) {
t.Fatalf("Wrong pseudo-instruction: %s", test.pseudo)
}
errorLine := buf.String()
if test.expected != errorLine {
t.Errorf("Unexpected error %q; expected %q", errorLine, test.expected)
}
buf.Reset()
}
}

View File

@@ -1,68 +0,0 @@
// 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.
// Test to make sure that if we use R15 after it is clobbered by
// a global variable access while dynamic linking, we get an error.
// See issue 43661.
TEXT ·a1(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
MOVL $0, R15
RET
TEXT ·a2(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
MOVQ $0, R15
RET
TEXT ·a3(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
XORL R15, R15
RET
TEXT ·a4(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
XORQ R15, R15
RET
TEXT ·a5(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
XORL R15, R15
RET
TEXT ·a6(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
POPQ R15
PUSHQ R15
RET
TEXT ·a7(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
MOVQ R15, AX // ERROR "when dynamic linking, R15 is clobbered by a global variable access and is used here"
RET
TEXT ·a8(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
ADDQ AX, R15 // ERROR "when dynamic linking, R15 is clobbered by a global variable access and is used here"
RET
TEXT ·a9(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
ORQ R15, R15 // ERROR "when dynamic linking, R15 is clobbered by a global variable access and is used here"
RET
TEXT ·a10(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
JEQ one
ORQ R15, R15 // ERROR "when dynamic linking, R15 is clobbered by a global variable access and is used here"
one:
RET
TEXT ·a11(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
JEQ one
JMP two
one:
ORQ R15, R15 // ERROR "when dynamic linking, R15 is clobbered by a global variable access and is used here"
two:
RET
TEXT ·a12(SB), 0, $0-0
CMPL runtime·writeBarrier(SB), $0
JMP one
two:
ORQ R15, R15
RET
one:
MOVL $0, R15
JMP two

View File

@@ -64,16 +64,6 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
CMN R1.SXTX<<2, R10 // 5fe921ab
CMPW R2.UXTH<<3, R11 // 7f2d226b
CMNW R1.SXTB, R9 // 3f81212b
ADD R1<<1, RSP, R3 // e367218b
ADDW R1<<2, R3, RSP // 7f48210b
SUB R1<<3, RSP // ff6f21cb
SUBS R1<<4, RSP, R3 // e37321eb
ADDS R1<<1, RSP, R4 // e46721ab
CMP R1<<2, RSP // ff6b21eb
CMN R1<<3, RSP // ff6f21ab
ADDS R1<<1, ZR, R4 // e40701ab
ADD R3<<50, ZR, ZR // ffcb038b
CMP R4<<24, ZR // ff6304eb
CMPW $0x60060, R2 // CMPW $393312, R2 // 1b0c8052db00a0725f001b6b
CMPW $40960, R0 // 1f284071
CMPW $27745, R2 // 3b8c8d525f001b6b
@@ -89,7 +79,7 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
CMP R1<<33, R2
CMP R22.SXTX, RSP // ffe336eb
CMP $0x22220000, RSP // CMP $572653568, RSP // 5b44a4d2ff633beb
CMPW $0x22220000, RSP // CMPW $572653568, RSP // 5b44a452ff433b6b
CMPW $0x22220000, RSP // CMPW $572653568, RSP // 5b44a452ff633b6b
CCMN MI, ZR, R1, $4 // e44341ba
// MADD Rn,Rm,Ra,Rd
MADD R1, R2, R3, R4 // 6408019b
@@ -217,18 +207,6 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
VUADDW2 V9.B16, V12.H8, V14.H8 // 8e11296e
VUADDW2 V13.H8, V20.S4, V30.S4 // 9e126d6e
VUADDW2 V21.S4, V24.D2, V29.D2 // 1d13b56e
VUMAX V3.B8, V2.B8, V1.B8 // 4164232e
VUMAX V3.B16, V2.B16, V1.B16 // 4164236e
VUMAX V3.H4, V2.H4, V1.H4 // 4164632e
VUMAX V3.H8, V2.H8, V1.H8 // 4164636e
VUMAX V3.S2, V2.S2, V1.S2 // 4164a32e
VUMAX V3.S4, V2.S4, V1.S4 // 4164a36e
VUMIN V3.B8, V2.B8, V1.B8 // 416c232e
VUMIN V3.B16, V2.B16, V1.B16 // 416c236e
VUMIN V3.H4, V2.H4, V1.H4 // 416c632e
VUMIN V3.H8, V2.H8, V1.H8 // 416c636e
VUMIN V3.S2, V2.S2, V1.S2 // 416ca32e
VUMIN V3.S4, V2.S4, V1.S4 // 416ca36e
FCCMPS LT, F1, F2, $1 // 41b4211e
FMADDS F1, F3, F2, F4 // 440c011f
FMADDD F4, F5, F4, F4 // 8414441f
@@ -374,10 +352,6 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
MOVD $1, ZR
MOVD $1, R1
MOVK $1, R1
MOVD $0x1000100010001000, RSP // MOVD $1152939097061330944, RSP // ff8304b2
MOVW $0x10001000, RSP // MOVW $268439552, RSP // ff830432
ADDW $0x10001000, R1 // ADDW $268439552, R1 // fb83043221001b0b
ADDW $0x22220000, RSP, R3 // ADDW $572653568, RSP, R3 // 5b44a452e3433b0b
// move a large constant to a Vd.
VMOVS $0x80402010, V11 // VMOVS $2151686160, V11
@@ -406,13 +380,13 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
// LD1/ST1
VLD1 (R8), [V1.B16, V2.B16] // 01a1404c
VLD1.P (R3), [V31.H8, V0.H8] // 7fa4df4c
VLD1.P (R8)(R20), [V21.B16, V22.B16] // 15a1d44c
VLD1.P (R8)(R20), [V21.B16, V22.B16] // VLD1.P (R8)(R20*1), [V21.B16,V22.B16] // 15a1d44c
VLD1.P 64(R1), [V5.B16, V6.B16, V7.B16, V8.B16] // 2520df4c
VLD1.P 1(R0), V4.B[15] // 041cdf4d
VLD1.P 2(R0), V4.H[7] // 0458df4d
VLD1.P 4(R0), V4.S[3] // 0490df4d
VLD1.P 8(R0), V4.D[1] // 0484df4d
VLD1.P (R0)(R1), V4.D[1] // 0484c14d
VLD1.P (R0)(R1), V4.D[1] // VLD1.P (R0)(R1*1), V4.D[1] // 0484c14d
VLD1 (R0), V4.D[1] // 0484404d
VST1.P [V4.S4, V5.S4], 32(R1) // 24a89f4c
VST1 [V0.S4, V1.S4], (R0) // 00a8004c
@@ -420,29 +394,29 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
VLD1.P 24(R30), [V3.S2,V4.S2,V5.S2] // c36bdf0c
VLD2 (R29), [V23.H8, V24.H8] // b787404c
VLD2.P 16(R0), [V18.B8, V19.B8] // 1280df0c
VLD2.P (R1)(R2), [V15.S2, V16.S2] // 2f88c20c
VLD2.P (R1)(R2), [V15.S2, V16.S2] // VLD2.P (R1)(R2*1), [V15.S2,V16.S2] // 2f88c20c
VLD3 (R27), [V11.S4, V12.S4, V13.S4] // 6b4b404c
VLD3.P 48(RSP), [V11.S4, V12.S4, V13.S4] // eb4bdf4c
VLD3.P (R30)(R2), [V14.D2, V15.D2, V16.D2] // ce4fc24c
VLD3.P (R30)(R2), [V14.D2, V15.D2, V16.D2] // VLD3.P (R30)(R2*1), [V14.D2,V15.D2,V16.D2] // ce4fc24c
VLD4 (R15), [V10.H4, V11.H4, V12.H4, V13.H4] // ea05400c
VLD4.P 32(R24), [V31.B8, V0.B8, V1.B8, V2.B8] // 1f03df0c
VLD4.P (R13)(R9), [V14.S2, V15.S2, V16.S2, V17.S2] // ae09c90c
VLD4.P (R13)(R9), [V14.S2, V15.S2, V16.S2, V17.S2] // VLD4.P (R13)(R9*1), [V14.S2,V15.S2,V16.S2,V17.S2] // ae09c90c
VLD1R (R1), [V9.B8] // 29c0400d
VLD1R.P (R1), [V9.B8] // 29c0df0d
VLD1R.P 1(R1), [V2.B8] // 22c0df0d
VLD1R.P 2(R1), [V2.H4] // 22c4df0d
VLD1R (R0), [V0.B16] // 00c0404d
VLD1R.P (R0), [V0.B16] // 00c0df4d
VLD1R.P (R15)(R1), [V15.H4] // efc5c10d
VLD1R.P (R15)(R1), [V15.H4] // VLD1R.P (R15)(R1*1), [V15.H4] // efc5c10d
VLD2R (R15), [V15.H4, V16.H4] // efc5600d
VLD2R.P 16(R0), [V0.D2, V1.D2] // 00ccff4d
VLD2R.P (R0)(R5), [V31.D1, V0.D1] // 1fcce50d
VLD2R.P (R0)(R5), [V31.D1, V0.D1] // VLD2R.P (R0)(R5*1), [V31.D1, V0.D1] // 1fcce50d
VLD3R (RSP), [V31.S2, V0.S2, V1.S2] // ffeb400d
VLD3R.P 6(R15), [V15.H4, V16.H4, V17.H4] // efe5df0d
VLD3R.P (R15)(R6), [V15.H8, V16.H8, V17.H8] // efe5c64d
VLD3R.P (R15)(R6), [V15.H8, V16.H8, V17.H8] // VLD3R.P (R15)(R6*1), [V15.H8, V16.H8, V17.H8] // efe5c64d
VLD4R (R0), [V0.B8, V1.B8, V2.B8, V3.B8] // 00e0600d
VLD4R.P 16(RSP), [V31.S4, V0.S4, V1.S4, V2.S4] // ffebff4d
VLD4R.P (R15)(R9), [V15.H4, V16.H4, V17.H4, V18.H4] // efe5e90d
VLD4R.P (R15)(R9), [V15.H4, V16.H4, V17.H4, V18.H4] // VLD4R.P (R15)(R9*1), [V15.H4, V16.H4, V17.H4, V18.H4] // efe5e90d
VST1.P [V24.S2], 8(R2) // 58789f0c
VST1 [V29.S2, V30.S2], (R29) // bdab000c
VST1 [V14.H4, V15.H4, V16.H4], (R27) // 6e67000c
@@ -450,17 +424,17 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
VST1.P V4.H[7], 2(R0) // 04589f4d
VST1.P V4.S[3], 4(R0) // 04909f4d
VST1.P V4.D[1], 8(R0) // 04849f4d
VST1.P V4.D[1], (R0)(R1) // 0484814d
VST1.P V4.D[1], (R0)(R1) // VST1.P V4.D[1], (R0)(R1*1) // 0484814d
VST1 V4.D[1], (R0) // 0484004d
VST2 [V22.H8, V23.H8], (R23) // f686004c
VST2.P [V14.H4, V15.H4], 16(R17) // 2e869f0c
VST2.P [V14.H4, V15.H4], (R3)(R17) // 6e84910c
VST2.P [V14.H4, V15.H4], (R3)(R17) // VST2.P [V14.H4,V15.H4], (R3)(R17*1) // 6e84910c
VST3 [V1.D2, V2.D2, V3.D2], (R11) // 614d004c
VST3.P [V18.S4, V19.S4, V20.S4], 48(R25) // 324b9f4c
VST3.P [V19.B8, V20.B8, V21.B8], (R3)(R7) // 7340870c
VST3.P [V19.B8, V20.B8, V21.B8], (R3)(R7) // VST3.P [V19.B8, V20.B8, V21.B8], (R3)(R7*1) // 7340870c
VST4 [V22.D2, V23.D2, V24.D2, V25.D2], (R3) // 760c004c
VST4.P [V14.D2, V15.D2, V16.D2, V17.D2], 64(R15) // ee0d9f4c
VST4.P [V24.B8, V25.B8, V26.B8, V27.B8], (R3)(R23) // 7800970c
VST4.P [V24.B8, V25.B8, V26.B8, V27.B8], (R3)(R23) // VST4.P [V24.B8, V25.B8, V26.B8, V27.B8], (R3)(R23*1) // 7800970c
// pre/post-indexed
FMOVS.P F20, 4(R0) // 144400bc
@@ -547,30 +521,29 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
// shifted or extended register offset.
MOVD (R2)(R6.SXTW), R4 // 44c866f8
MOVD (R3)(R6), R5 // 656866f8
MOVD (R3)(R6*1), R5 // 656866f8
MOVD (R2)(R6), R4 // 446866f8
MOVD (R3)(R6), R5 // MOVD (R3)(R6*1), R5 // 656866f8
MOVD (R2)(R6), R4 // MOVD (R2)(R6*1), R4 // 446866f8
MOVWU (R19)(R20<<2), R20 // 747a74b8
MOVD (R2)(R6<<3), R4 // 447866f8
MOVD (R3)(R7.SXTX<<3), R8 // 68f867f8
MOVWU (R5)(R4.UXTW), R10 // aa4864b8
MOVBU (R3)(R9.UXTW), R8 // 68486938
MOVBU (R5)(R8), R10 // aa686838
MOVBU (R5)(R8), R10 // MOVBU (R5)(R8*1), R10 // aa686838
MOVHU (R2)(R7.SXTW<<1), R11 // 4bd86778
MOVHU (R1)(R2<<1), R5 // 25786278
MOVB (R9)(R3.UXTW), R6 // 2649a338
MOVB (R10)(R6), R15 // 4f69a638
MOVB (R10)(R6), R15 // MOVB (R10)(R6*1), R15 // 4f69a638
MOVB (R29)(R30<<0), R14 // ae7bbe38
MOVB (R29)(R30), R14 // ae6bbe38
MOVB (R29)(R30), R14 // MOVB (R29)(R30*1), R14 // ae6bbe38
MOVH (R5)(R7.SXTX<<1), R19 // b3f8a778
MOVH (R8)(R4<<1), R10 // 0a79a478
MOVW (R9)(R8.SXTW<<2), R19 // 33d9a8b8
MOVW (R1)(R4.SXTX), R11 // 2be8a4b8
MOVW (R1)(R4.SXTX), ZR // 3fe8a4b8
MOVW (R2)(R5), R12 // 4c68a5b8
FMOVS (R2)(R6), F4 // 446866bc
MOVW (R2)(R5), R12 // MOVW (R2)(R5*1), R12 // 4c68a5b8
FMOVS (R2)(R6), F4 // FMOVS (R2)(R6*1), F4 // 446866bc
FMOVS (R2)(R6<<2), F4 // 447866bc
FMOVD (R2)(R6), F4 // 446866fc
FMOVD (R2)(R6), F4 // FMOVD (R2)(R6*1), F4 // 446866fc
FMOVD (R2)(R6<<3), F4 // 447866fc
MOVD R5, (R2)(R6<<3) // 457826f8
@@ -580,16 +553,15 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
MOVW R7, (R3)(R4.SXTW) // 67c824b8
MOVB R4, (R2)(R6.SXTX) // 44e82638
MOVB R8, (R3)(R9.UXTW) // 68482938
MOVB R10, (R5)(R8) // aa682838
MOVB R10, (R5)(R8*1) // aa682838
MOVB R10, (R5)(R8) // MOVB R10, (R5)(R8*1) // aa682838
MOVH R11, (R2)(R7.SXTW<<1) // 4bd82778
MOVH R5, (R1)(R2<<1) // 25782278
MOVH R7, (R2)(R5.SXTX<<1) // 47f82578
MOVH R8, (R3)(R6.UXTW) // 68482678
MOVB R4, (R2)(R6.SXTX) // 44e82638
FMOVS F4, (R2)(R6) // 446826bc
FMOVS F4, (R2)(R6) // FMOVS F4, (R2)(R6*1) // 446826bc
FMOVS F4, (R2)(R6<<2) // 447826bc
FMOVD F4, (R2)(R6) // 446826fc
FMOVD F4, (R2)(R6) // FMOVD F4, (R2)(R6*1) // 446826fc
FMOVD F4, (R2)(R6<<3) // 447826fc
// vmov
@@ -599,12 +571,9 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
VMOV R20, V1.S[0] // 811e044e
VMOV R20, V1.S[1] // 811e0c4e
VMOV R1, V9.H4 // 290c020e
VDUP R1, V9.H4 // 290c020e
VMOV R22, V11.D2 // cb0e084e
VDUP R22, V11.D2 // cb0e084e
VMOV V2.B16, V4.B16 // 441ca24e
VMOV V20.S[0], V20 // 9406045e
VDUP V20.S[0], V20 // 9406045e
VMOV V12.D[0], V12.D[1] // 8c05186e
VMOV V10.S[0], V12.S[1] // 4c050c6e
VMOV V9.H[0], V12.H[1] // 2c05066e
@@ -1013,54 +982,6 @@ again:
FSTPS (F3, F4), x(SB)
FSTPS (F3, F4), x+8(SB)
// FLDPQ/FSTPQ
FLDPQ -4000(R0), (F1, F2) // 1b803ed1610b40ad
FLDPQ -1024(R0), (F1, F2) // 010860ad
FLDPQ (R0), (F1, F2) // 010840ad
FLDPQ 16(R0), (F1, F2) // 018840ad
FLDPQ -16(R0), (F1, F2) // 01887fad
FLDPQ.W 32(R0), (F1, F2) // 0108c1ad
FLDPQ.P 32(R0), (F1, F2) // 0108c1ac
FLDPQ 11(R0), (F1, F2) // 1b2c0091610b40ad
FLDPQ 1024(R0), (F1, F2) // 1b001091610b40ad
FLDPQ 4104(R0), (F1, F2)
FLDPQ -4000(RSP), (F1, F2) // fb833ed1610b40ad
FLDPQ -1024(RSP), (F1, F2) // e10b60ad
FLDPQ (RSP), (F1, F2) // e10b40ad
FLDPQ 16(RSP), (F1, F2) // e18b40ad
FLDPQ -16(RSP), (F1, F2) // e18b7fad
FLDPQ.W 32(RSP), (F1, F2) // e10bc1ad
FLDPQ.P 32(RSP), (F1, F2) // e10bc1ac
FLDPQ 11(RSP), (F1, F2) // fb2f0091610b40ad
FLDPQ 1024(RSP), (F1, F2) // fb031091610b40ad
FLDPQ 4104(RSP), (F1, F2)
FLDPQ -31(R0), (F1, F2) // 1b7c00d1610b40ad
FLDPQ -4(R0), (F1, F2) // 1b1000d1610b40ad
FLDPQ x(SB), (F1, F2)
FLDPQ x+8(SB), (F1, F2)
FSTPQ (F3, F4), -4000(R5) // bb803ed1631300ad
FSTPQ (F3, F4), -1024(R5) // a31020ad
FSTPQ (F3, F4), (R5) // a31000ad
FSTPQ (F3, F4), 16(R5) // a39000ad
FSTPQ (F3, F4), -16(R5) // a3903fad
FSTPQ.W (F3, F4), 32(R5) // a31081ad
FSTPQ.P (F3, F4), 32(R5) // a31081ac
FSTPQ (F3, F4), 11(R5) // bb2c0091631300ad
FSTPQ (F3, F4), 1024(R5) // bb001091631300ad
FSTPQ (F3, F4), 4104(R5)
FSTPQ (F3, F4), -4000(RSP) // fb833ed1631300ad
FSTPQ (F3, F4), -1024(RSP) // e31320ad
FSTPQ (F3, F4), (RSP) // e31300ad
FSTPQ (F3, F4), 16(RSP) // e39300ad
FSTPQ (F3, F4), -16(RSP) // e3933fad
FSTPQ.W (F3, F4), 32(RSP) // e31381ad
FSTPQ.P (F3, F4), 32(RSP) // e31381ac
FSTPQ (F3, F4), 11(RSP) // fb2f0091631300ad
FSTPQ (F3, F4), 1024(RSP) // fb031091631300ad
FSTPQ (F3, F4), 4104(RSP)
FSTPQ (F3, F4), x(SB)
FSTPQ (F3, F4), x+8(SB)
// System Register
MSR $1, SPSel // bf4100d5
MSR $9, DAIFSet // df4903d5

View File

@@ -188,7 +188,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
MOVBU 2916(R24), R3 // 03936d39
MOVBU (R19)(R14<<0), R23 // 777a6e38
MOVBU (R2)(R8.SXTX), R19 // 53e86838
MOVBU (R27)(R23), R14 // 6e6b7738
MOVBU (R27)(R23), R14 // MOVBU (R27)(R23*1), R14 // 6e6b7738
MOVHU.P 107(R14), R13 // cdb54678
MOVHU.W 192(R3), R2 // 620c4c78
MOVHU 6844(R4), R19 // 93787579
@@ -201,9 +201,9 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
MOVB 997(R9), R23 // 37958f39
//TODO MOVBW (R2<<1)(R21), R15 // af7ae238
//TODO MOVBW (R26)(R0), R21 // 1568fa38
MOVB (R5)(R15), R16 // b068af38
MOVB (R5)(R15), R16 // MOVB (R5)(R15*1), R16 // b068af38
MOVB (R19)(R26.SXTW), R19 // 73caba38
MOVB (R29)(R30), R14 // ae6bbe38
MOVB (R29)(R30), R14 // MOVB (R29)(R30*1), R14 // ae6bbe38
//TODO MOVHW.P 218(R22), R25 // d9a6cd78
MOVH.P 179(R23), R5 // e5368b78
//TODO MOVHW.W 136(R2), R27 // 5b8cc878
@@ -357,12 +357,12 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
MOVD R25, -137(R17) // 397217f8
MOVW R4, (R12)(R22.UXTW<<2) // 845936b8
MOVD R27, (R5)(R15.UXTW<<3) // bb582ff8
MOVB R2, (R10)(R16) // 42693038
MOVB R2, (R29)(R26) // a26b3a38
MOVB R2, (R10)(R16) // MOVB R2, (R10)(R16*1) // 42693038
MOVB R2, (R29)(R26) // MOVB R2, (R29)(R26*1) // a26b3a38
MOVH R11, -80(R23) // eb021b78
MOVH R11, (R27)(R14.SXTW<<1) // 6bdb2e78
MOVB R19, (R0)(R4) // 13682438
MOVB R1, (R6)(R4) // c1682438
MOVB R19, (R0)(R4) // MOVB R19, (R0)(R4*1) // 13682438
MOVB R1, (R6)(R4) // MOVB R1, (R6)(R4*1) // c1682438
MOVH R3, (R11)(R13<<1) // 63792d78
//TODO STTR 55(R4), R29 // 9d7803b8
//TODO STTR 124(R5), R25 // b9c807f8
@@ -669,7 +669,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
VCMEQ V24.S4, V13.S4, V12.S4 // ac8db86e
VCNT V13.B8, V11.B8 // ab59200e
VMOV V31.B[15], V18 // f2071f5e
VDUP V31.B[15], V18 // f2071f5e
VDUP V31.B[13], V20.B16 // f4071b4e
VEOR V4.B8, V18.B8, V7.B8 // 471e242e
VEXT $4, V2.B8, V1.B8, V3.B8 // 2320022e
@@ -680,28 +679,27 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
VLD1 (R24), [V18.D1, V19.D1, V20.D1] // 126f400c
VLD1 (R29), [V14.D1, V15.D1, V16.D1, V17.D1] // ae2f400c
VLD1.P 16(R23), [V1.B16] // e172df4c
VLD1.P (R6)(R11), [V31.D1] // df7ccb0c
VLD1.P (R6)(R11), [V31.D1] // VLD1.P (R6)(R11*1), [V31.D1] // df7ccb0c
VLD1.P 16(R7), [V31.D1, V0.D1] // ffacdf0c
VLD1.P (R19)(R4), [V24.B8, V25.B8] // 78a2c40c
VLD1.P (R20)(R8), [V7.H8, V8.H8, V9.H8] // 8766c84c
VLD1.P (R19)(R4), [V24.B8, V25.B8] // VLD1.P (R19)(R4*1), [V24.B8, V25.B8] // 78a2c40c
VLD1.P (R20)(R8), [V7.H8, V8.H8, V9.H8] // VLD1.P (R20)(R8*1), [V7.H8, V8.H8, V9.H8] // 8766c84c
VLD1.P 32(R30), [V5.B8, V6.B8, V7.B8, V8.B8] // c523df0c
VLD1 (R19), V14.B[15] // 6e1e404d
VLD1 (R29), V0.H[1] // a04b400d
VLD1 (R27), V2.S[0] // 6283400d
VLD1 (R21), V5.D[1] // a586404d
VLD1.P 1(R19), V10.B[14] // 6a1adf4d
VLD1.P (R3)(R14), V16.B[11] // 700cce4d
VLD1.P (R3)(R14), V16.B[11] // VLD1.P (R3)(R14*1), V16.B[11] // 700cce4d
VLD1.P 2(R1), V28.H[2] // 3c50df0d
VLD1.P (R13)(R20), V9.H[2] // a951d40d
VLD1.P (R13)(R20), V9.H[2] // VLD1.P (R13)(R20*1), V9.H[2] // a951d40d
VLD1.P 4(R17), V1.S[3] // 2192df4d
VLD1.P (R14)(R2), V17.S[2] // d181c24d
VLD1.P (R14)(R2), V17.S[2] // VLD1.P (R14)(R2*1), V17.S[2] // d181c24d
VLD1.P 8(R5), V30.D[1] // be84df4d
VLD1.P (R27)(R13), V27.D[0] // 7b87cd0d
VLD1.P (R27)(R13), V27.D[0] // VLD1.P (R27)(R13*1), V27.D[0] // 7b87cd0d
//TODO FMOVS.P -29(RSP), F8 // e8375ebc
//TODO FMOVS.W 71(R29), F28 // bc7f44bc
FMOVS 6160(R4), F23 // 971058bd
VMOV V18.B[10], V27 // 5b06155e
VDUP V18.B[10], V27 // 5b06155e
VMOV V12.B[2], V28.B[12] // 9c15196e
VMOV R30, V4.B[13] // c41f1b4e
VMOV V2.B16, V4.B16 // 441ca24e
@@ -734,25 +732,25 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
VSHL $7, V22.D2, V25.D2 // d956474f
VST1 [V14.H4, V15.H4, V16.H4], (R27) // 6e67000c
VST1 [V2.S4, V3.S4, V4.S4, V5.S4], (R14) // c229004c
VST1.P [V25.S4], (R7)(R29) // f9789d4c
VST1.P [V25.S4], (R7)(R29) // VST1.P [V25.S4], (R7)(R29*1) // f9789d4c
VST1.P [V25.D2, V26.D2], 32(R7) // f9ac9f4c
VST1.P [V14.D1, V15.D1], (R7)(R23) // eeac970c
VST1.P [V14.D1, V15.D1], (R7)(R23) // VST1.P [V14.D1, V15.D1], (R7)(R23*1) // eeac970c
VST1.P [V25.D2, V26.D2, V27.D2], 48(R27) // 796f9f4c
VST1.P [V13.H8, V14.H8, V15.H8], (R3)(R14) // 6d648e4c
VST1.P [V13.H8, V14.H8, V15.H8], (R3)(R14) // VST1.P [V13.H8, V14.H8, V15.H8], (R3)(R14*1) // 6d648e4c
VST1.P [V16.S4, V17.S4, V18.S4, V19.S4], 64(R6) // d0289f4c
VST1.P [V19.H4, V20.H4, V21.H4, V22.H4], (R4)(R16) // 9324900c
VST1.P [V19.H4, V20.H4, V21.H4, V22.H4], (R4)(R16) // VST1.P [V19.H4, V20.H4, V21.H4, V22.H4], (R4)(R16*1) // 9324900c
VST1 V12.B[3], (R1) // 2c0c000d
VST1 V12.B[3], (R1) // 2c0c000d
VST1 V25.S[2], (R20) // 9982004d
VST1 V9.D[1], (RSP) // e987004d
VST1.P V30.B[6], 1(R3) // 7e189f0d
VST1.P V8.B[0], (R3)(R21) // 6800950d
VST1.P V8.B[0], (R3)(R21) // VST1.P V8.B[0], (R3)(R21*1) // 6800950d
VST1.P V15.H[5], 2(R10) // 4f499f4d
VST1.P V1.H[7], (R23)(R11) // e15a8b4d
VST1.P V1.H[7], (R23)(R11) // VST1.P V1.H[7], (R23)(R11*1) // e15a8b4d
VST1.P V26.S[0], 4(R11) // 7a819f0d
VST1.P V9.S[1], (R16)(R21) // 0992950d
VST1.P V9.S[1], (R16)(R21) // VST1.P V9.S[1], (R16)(R21*1) // 0992950d
VST1.P V16.D[0], 8(R9) // 30859f0d
VST1.P V23.D[1], (R21)(R16) // b786904d
VST1.P V23.D[1], (R21)(R16) // VST1.P V23.D[1], (R21)(R16*1) // b786904d
VSUB V1, V12, V23 // 9785e17e
VUADDLV V31.S4, V11 // eb3bb06e
UCVTFWS R11, F19 // 7301231e

View File

@@ -8,60 +8,12 @@ TEXT errors(SB),$0
ADDSW R7->32, R14, R13 // ERROR "shift amount out of range 0 to 31"
ADD R1.UXTB<<5, R2, R3 // ERROR "shift amount out of range 0 to 4"
ADDS R1.UXTX<<7, R2, R3 // ERROR "shift amount out of range 0 to 4"
ADDS R5, R6, RSP // ERROR "illegal destination register"
SUBS R5, R6, RSP // ERROR "illegal destination register"
ADDSW R5, R6, RSP // ERROR "illegal destination register"
SUBSW R5, R6, RSP // ERROR "illegal destination register"
ADDS $0xff, R6, RSP // ERROR "illegal destination register"
ADDS $0xffff0, R6, RSP // ERROR "illegal destination register"
ADDS $0x1000100010001000, R6, RSP // ERROR "illegal destination register"
ADDS $0x10001000100011, R6, RSP // ERROR "illegal destination register"
ADDSW $0xff, R6, RSP // ERROR "illegal destination register"
ADDSW $0xffff0, R6, RSP // ERROR "illegal destination register"
ADDSW $0x1000100010001000, R6, RSP // ERROR "illegal destination register"
ADDSW $0x10001000100011, R6, RSP // ERROR "illegal destination register"
SUBS $0xff, R6, RSP // ERROR "illegal destination register"
SUBS $0xffff0, R6, RSP // ERROR "illegal destination register"
SUBS $0x1000100010001000, R6, RSP // ERROR "illegal destination register"
SUBS $0x10001000100011, R6, RSP // ERROR "illegal destination register"
SUBSW $0xff, R6, RSP // ERROR "illegal destination register"
SUBSW $0xffff0, R6, RSP // ERROR "illegal destination register"
SUBSW $0x1000100010001000, R6, RSP // ERROR "illegal destination register"
SUBSW $0x10001000100011, R6, RSP // ERROR "illegal destination register"
AND $0x22220000, R2, RSP // ERROR "illegal combination"
ANDS $0x22220000, R2, RSP // ERROR "illegal combination"
ADD R1, R2, R3, R4 // ERROR "illegal combination"
BICW R7@>33, R5, R16 // ERROR "shift amount out of range 0 to 31"
NEGW R7<<33, R5 // ERROR "shift amount out of range 0 to 31"
NEGSW R7<<33, R5 // ERROR "shift amount out of range 0 to 31"
ADD R7@>2, R5, R16 // ERROR "unsupported shift operator"
ADDW R7@>2, R5, R16 // ERROR "unsupported shift operator"
ADDS R7@>2, R5, R16 // ERROR "unsupported shift operator"
ADDSW R7@>2, R5, R16 // ERROR "unsupported shift operator"
SUB R7@>2, R5, R16 // ERROR "unsupported shift operator"
SUBW R7@>2, R5, R16 // ERROR "unsupported shift operator"
SUBS R7@>2, R5, R16 // ERROR "unsupported shift operator"
SUBSW R7@>2, R5, R16 // ERROR "unsupported shift operator"
CMP R7@>2, R5 // ERROR "unsupported shift operator"
CMPW R7@>2, R5 // ERROR "unsupported shift operator"
CMN R7@>2, R5 // ERROR "unsupported shift operator"
CMNW R7@>2, R5 // ERROR "unsupported shift operator"
NEG R7@>2, R5 // ERROR "unsupported shift operator"
NEGW R7@>2, R5 // ERROR "unsupported shift operator"
NEGS R7@>2, R5 // ERROR "unsupported shift operator"
NEGSW R7@>2, R5 // ERROR "unsupported shift operator"
CINC CS, R2, R3, R4 // ERROR "illegal combination"
CSEL LT, R1, R2 // ERROR "illegal combination"
CINC AL, R2, R3 // ERROR "invalid condition"
CINC NV, R2, R3 // ERROR "invalid condition"
CINVW AL, R2, R3 // ERROR "invalid condition"
CINV NV, R2, R3 // ERROR "invalid condition"
CNEG AL, R2, R3 // ERROR "invalid condition"
CNEGW NV, R2, R3 // ERROR "invalid condition"
CSET AL, R2 // ERROR "invalid condition"
CSET NV, R2 // ERROR "invalid condition"
CSETMW AL, R2 // ERROR "invalid condition"
CSETM NV, R2 // ERROR "invalid condition"
LDP.P 8(R2), (R2, R3) // ERROR "constrained unpredictable behavior"
LDP.W 8(R3), (R2, R3) // ERROR "constrained unpredictable behavior"
LDP (R1), (R2, R2) // ERROR "constrained unpredictable behavior"
@@ -69,8 +21,8 @@ TEXT errors(SB),$0
LDP (R0), (R3, ZR) // ERROR "invalid register pair"
LDXPW (RSP), (R2, R2) // ERROR "constrained unpredictable behavior"
LDAXPW (R5), (R2, R2) // ERROR "constrained unpredictable behavior"
MOVD.P 300(R2), R3 // ERROR "offset out of range [-256,255]"
MOVD.P R3, 344(R2) // ERROR "offset out of range [-256,255]"
MOVD.P 300(R2), R3 // ERROR "offset out of range [-255,254]"
MOVD.P R3, 344(R2) // ERROR "offset out of range [-255,254]"
MOVD (R3)(R7.SXTX<<2), R8 // ERROR "invalid index shift amount"
MOVWU (R5)(R4.UXTW<<3), R10 // ERROR "invalid index shift amount"
MOVWU (R5)(R4<<1), R10 // ERROR "invalid index shift amount"
@@ -106,13 +58,13 @@ TEXT errors(SB),$0
VMOV V8.H[9], R3 // ERROR "register element index out of range 0 to 7"
VMOV V8.S[4], R3 // ERROR "register element index out of range 0 to 3"
VMOV V8.D[2], R3 // ERROR "register element index out of range 0 to 1"
VDUP V8.B[16], V3.B16 // ERROR "register element index out of range 0 to 15"
VDUP V8.B[17], V3.B8 // ERROR "register element index out of range 0 to 15"
VDUP V8.H[9], V3.H4 // ERROR "register element index out of range 0 to 7"
VDUP V8.H[9], V3.H8 // ERROR "register element index out of range 0 to 7"
VDUP V8.S[4], V3.S2 // ERROR "register element index out of range 0 to 3"
VDUP V8.S[4], V3.S4 // ERROR "register element index out of range 0 to 3"
VDUP V8.D[2], V3.D2 // ERROR "register element index out of range 0 to 1"
VDUP V8.B[16], R3.B16 // ERROR "register element index out of range 0 to 15"
VDUP V8.B[17], R3.B8 // ERROR "register element index out of range 0 to 15"
VDUP V8.H[9], R3.H4 // ERROR "register element index out of range 0 to 7"
VDUP V8.H[9], R3.H8 // ERROR "register element index out of range 0 to 7"
VDUP V8.S[4], R3.S2 // ERROR "register element index out of range 0 to 3"
VDUP V8.S[4], R3.S4 // ERROR "register element index out of range 0 to 3"
VDUP V8.D[2], R3.D2 // ERROR "register element index out of range 0 to 1"
VFMLA V1.D2, V12.D2, V3.S2 // ERROR "operand mismatch"
VFMLA V1.S2, V12.S2, V3.D2 // ERROR "operand mismatch"
VFMLA V1.S4, V12.S2, V3.D2 // ERROR "operand mismatch"
@@ -157,9 +109,6 @@ TEXT errors(SB),$0
VREV16 V1.D1, V2.D1 // ERROR "invalid arrangement"
VREV16 V1.B8, V2.B16 // ERROR "invalid arrangement"
VREV16 V1.H4, V2.H4 // ERROR "invalid arrangement"
FLDPQ (R0), (R1, R2) // ERROR "invalid register pair"
FLDPQ (R1), (F2, F2) // ERROR "constrained unpredictable behavior"
FSTPQ (R1, R2), (R0) // ERROR "invalid register pair"
FLDPD (R0), (R1, R2) // ERROR "invalid register pair"
FLDPD (R1), (F2, F2) // ERROR "constrained unpredictable behavior"
FLDPS (R2), (F3, F3) // ERROR "constrained unpredictable behavior"
@@ -406,17 +355,10 @@ TEXT errors(SB),$0
VBIF V0.D2, V1.D2, V2.D2 // ERROR "invalid arrangement"
VUADDW V9.B8, V12.H8, V14.B8 // ERROR "invalid arrangement"
VUADDW2 V9.B8, V12.S4, V14.S4 // ERROR "operand mismatch"
VUMAX V1.D2, V2.D2, V3.D2 // ERROR "invalid arrangement"
VUMIN V1.D2, V2.D2, V3.D2 // ERROR "invalid arrangement"
VUMAX V1.B8, V2.B8, V3.B16 // ERROR "operand mismatch"
VUMIN V1.H4, V2.S4, V3.H4 // ERROR "operand mismatch"
VSLI $64, V7.D2, V8.D2 // ERROR "shift out of range"
VUSRA $0, V7.D2, V8.D2 // ERROR "shift out of range"
CASPD (R3, R4), (R2), (R8, R9) // ERROR "source register pair must start from even register"
CASPD (R2, R3), (R2), (R9, R10) // ERROR "destination register pair must start from even register"
CASPD (R2, R4), (R2), (R8, R9) // ERROR "source register pair must be contiguous"
CASPD (R2, R3), (R2), (R8, R10) // ERROR "destination register pair must be contiguous"
ADD R1>>2, RSP, R3 // ERROR "illegal combination"
ADDS R2<<3, R3, RSP // ERROR "unexpected SP reference"
CMP R1<<5, RSP // ERROR "the left shift amount out of range 0 to 4"
RET

View File

@@ -407,8 +407,6 @@ label4:
SRLV R27, R6, R17 // 03668816
SRA R11, R19, R20 // 0173a007
SRAV R20, R19, R19 // 02939817
ROTR R19, R18, R20 // 0272a046
ROTRV R9, R13, R16 // 012d8056
// LSHW rreg ',' rreg
// {
@@ -420,8 +418,6 @@ label4:
SRLV R27, R6 // 03663016
SRA R11, R19 // 01739807
SRAV R20, R19 // 02939817
ROTR R20, R19 // 02939846
ROTRV R16, R9 // 02094856
// LSHW imm ',' sreg ',' rreg
// {
@@ -433,8 +429,6 @@ label4:
SRLV $31, R6, R17 // 00068ffa
SRA $8, R8, R19 // 00089a03
SRAV $19, R8, R7 // 00083cfb
ROTR $12, R8, R3 // 00281b02
ROTRV $8, R22, R22 // 0036b23a
// LSHW imm ',' rreg
// {
@@ -446,8 +440,6 @@ label4:
SRLV $31, R17 // 00118ffa
SRA $3, R12 // 000c60c3
SRAV $12, R3 // 00031b3b
ROTR $12, R8 // 00284302
ROTRV $63, R22 // 0036b7fe
// LAND/LXOR/LNOR/LOR rreg ',' rreg

View File

@@ -41,8 +41,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
MOVDBR (R3)(R4), R5 // 7ca41c28
MOVWBR (R3)(R4), R5 // 7ca41c2c
MOVHBR (R3)(R4), R5 // 7ca41e2c
MOVD $foo+4009806848(FP), R5 // 3ca1ef0138a5cc20
MOVD $foo(SB), R5 // 3ca0000038a50000
MOVDU 8(R3), R4 // e8830009
MOVDU (R3)(R4), R5 // 7ca4186a
@@ -79,15 +77,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
MOVBU R4, 1(R3) // 9c830001
MOVBU R5, (R3)(R4) // 7ca419ee
MOVB $0, R4 // 38800000
MOVBZ $0, R4 // 38800000
MOVH $0, R4 // 38800000
MOVHZ $0, R4 // 38800000
MOVW $0, R4 // 38800000
MOVWZ $0, R4 // 38800000
MOVD $0, R4 // 38800000
MOVD $0, R0 // 38000000
ADD $1, R3 // 38630001
ADD $1, R3, R4 // 38830001
ADD $-1, R4 // 3884ffff
@@ -291,17 +280,11 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
ROTLW R3, R4, R5 // 5c85183e
EXTSWSLI $3, R4, R5 // 7c851ef4
RLWMI $7, R3, $65535, R6 // 50663c3e
RLWMI $7, R3, $16, $31, R6 // 50663c3e
RLWMICC $7, R3, $65535, R6 // 50663c3f
RLWMICC $7, R3, $16, $31, R6 // 50663c3f
RLWNM $3, R4, $7, R6 // 54861f7e
RLWNM $3, R4, $29, $31, R6 // 54861f7e
RLWNM R3, R4, $7, R6 // 5c861f7e
RLWNM R3, R4, $29, $31, R6 // 5c861f7e
RLWNMCC $3, R4, $7, R6 // 54861f7f
RLWNMCC $3, R4, $29, $31, R6 // 54861f7f
RLWNMCC R3, R4, $7, R6 // 5c861f7f
RLWNMCC R3, R4, $29, $31, R6 // 5c861f7f
RLDMI $0, R4, $7, R6 // 7886076c
RLDMICC $0, R4, $7, R6 // 7886076d
RLDIMI $0, R4, $7, R6 // 788601cc
@@ -320,8 +303,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
RLDICCC $0, R4, $15, R6 // 788603c9
CLRLSLWI $16, R5, $8, R4 // 54a4422e
CLRLSLDI $24, R4, $2, R3 // 78831588
RLDCR $1, R1, $-16, R1 // 78210ee4
RLDCRCC $1, R1, $-16, R1 // 78210ee5
BEQ 0(PC) // 41820000
BEQ CR1,0(PC) // 41860000

View File

@@ -280,9 +280,6 @@ start:
MOV $2047, X5 // 9b02f07f
MOV $-2048, X5 // 9b020080
// Converted to load of symbol.
MOV $4294967296, X5 // 97020000
MOV (X5), X6 // 03b30200
MOV 4(X5), X6 // 03b34200
MOVB (X5), X6 // 03830200
@@ -328,7 +325,7 @@ start:
// These jumps can get printed as jumps to 2 because they go to the
// second instruction in the function (the first instruction is an
// invisible stack pointer adjustment).
JMP start // JMP 2 // 6ff01fc2
JMP start // JMP 2 // 6ff09fc2
JMP (X5) // 67800200
JMP 4(X5) // 67804200
@@ -341,16 +338,16 @@ start:
JMP asmtest(SB) // 970f0000
// Branch pseudo-instructions
BEQZ X5, start // BEQZ X5, 2 // e38202c0
BGEZ X5, start // BGEZ X5, 2 // e3d002c0
BGT X5, X6, start // BGT X5, X6, 2 // e34e53be
BGTU X5, X6, start // BGTU X5, X6, 2 // e36c53be
BGTZ X5, start // BGTZ X5, 2 // e34a50be
BLE X5, X6, start // BLE X5, X6, 2 // e35853be
BLEU X5, X6, start // BLEU X5, X6, 2 // e37653be
BLEZ X5, start // BLEZ X5, 2 // e35450be
BLTZ X5, start // BLTZ X5, 2 // e3c202be
BNEZ X5, start // BNEZ X5, 2 // e39002be
BEQZ X5, start // BEQZ X5, 2 // e38602c0
BGEZ X5, start // BGEZ X5, 2 // e3d402c0
BGT X5, X6, start // BGT X5, X6, 2 // e34253c0
BGTU X5, X6, start // BGTU X5, X6, 2 // e36053c0
BGTZ X5, start // BGTZ X5, 2 // e34e50be
BLE X5, X6, start // BLE X5, X6, 2 // e35c53be
BLEU X5, X6, start // BLEU X5, X6, 2 // e37a53be
BLEZ X5, start // BLEZ X5, 2 // e35850be
BLTZ X5, start // BLTZ X5, 2 // e3c602be
BNEZ X5, start // BNEZ X5, 2 // e39402be
// Set pseudo-instructions
SEQZ X15, X15 // 93b71700

View File

@@ -6,7 +6,6 @@ package lex
import (
"fmt"
"internal/buildcfg"
"os"
"path/filepath"
"strconv"
@@ -46,21 +45,6 @@ func NewInput(name string) *Input {
// predefine installs the macros set by the -D flag on the command line.
func predefine(defines flags.MultiFlag) map[string]*Macro {
macros := make(map[string]*Macro)
// Set macros for GOEXPERIMENTs so we can easily switch
// runtime assembly code based on them.
if *flags.CompilingRuntime {
for _, exp := range buildcfg.EnabledExperiments() {
// Define macro.
name := "GOEXPERIMENT_" + exp
macros[name] = &Macro{
name: name,
args: nil,
tokens: Tokenize("1"),
}
}
}
for _, name := range defines {
value := "1"
i := strings.IndexRune(name, '=')

View File

@@ -8,7 +8,6 @@ import (
"bufio"
"flag"
"fmt"
"internal/buildcfg"
"log"
"os"
@@ -26,8 +25,7 @@ func main() {
log.SetFlags(0)
log.SetPrefix("asm: ")
buildcfg.Check()
GOARCH := buildcfg.GOARCH
GOARCH := objabi.GOARCH
architecture := arch.Set(GOARCH)
if architecture == nil {
@@ -70,7 +68,7 @@ func main() {
defer buf.Close()
if !*flags.SymABIs {
buf.WriteString(objabi.HeaderString())
fmt.Fprintf(buf, "go object %s %s %s\n", objabi.GOOS, objabi.GOARCH, objabi.Version)
fmt.Fprintf(buf, "!\n")
}

View File

@@ -387,9 +387,6 @@ and of course there is nothing stopping the C code from doing anything
it likes. However, programs that break these rules are likely to fail
in unexpected and unpredictable ways.
The runtime/cgo.Handle type can be used to safely pass Go values
between Go and C. See the runtime/cgo package documentation for details.
Note: the current implementation has a bug. While Go code is permitted
to write nil or a C pointer (but not a Go pointer) to C memory, the
current implementation may sometimes cause a runtime error if the

View File

@@ -909,7 +909,7 @@ func (p *Package) rewriteCall(f *File, call *Call) (string, bool) {
var sbCheck bytes.Buffer
for i, param := range params {
origArg := args[i]
arg, nu := p.mangle(f, &args[i], true)
arg, nu := p.mangle(f, &args[i])
if nu {
needsUnsafe = true
}
@@ -952,7 +952,7 @@ func (p *Package) rewriteCall(f *File, call *Call) (string, bool) {
sb.WriteString("return ")
}
m, nu := p.mangle(f, &call.Call.Fun, false)
m, nu := p.mangle(f, &call.Call.Fun)
if nu {
needsUnsafe = true
}
@@ -1086,8 +1086,7 @@ func (p *Package) hasPointer(f *File, t ast.Expr, top bool) bool {
// rewriting calls when it finds them.
// It removes the corresponding references in f.Ref and f.Calls, so that we
// don't try to do the replacement again in rewriteRef or rewriteCall.
// If addPosition is true, add position info to the idents of C names in arg.
func (p *Package) mangle(f *File, arg *ast.Expr, addPosition bool) (ast.Expr, bool) {
func (p *Package) mangle(f *File, arg *ast.Expr) (ast.Expr, bool) {
needsUnsafe := false
f.walk(arg, ctxExpr, func(f *File, arg interface{}, context astContext) {
px, ok := arg.(*ast.Expr)
@@ -1102,7 +1101,7 @@ func (p *Package) mangle(f *File, arg *ast.Expr, addPosition bool) (ast.Expr, bo
for _, r := range f.Ref {
if r.Expr == px {
*px = p.rewriteName(f, r, addPosition)
*px = p.rewriteName(f, r)
r.Done = true
break
}
@@ -1362,7 +1361,7 @@ func (p *Package) rewriteRef(f *File) {
}
}
expr := p.rewriteName(f, r, false)
expr := p.rewriteName(f, r)
if *godefs {
// Substitute definition for mangled type name.
@@ -1425,23 +1424,8 @@ func (p *Package) rewriteRef(f *File) {
}
// rewriteName returns the expression used to rewrite a reference.
// If addPosition is true, add position info in the ident name.
func (p *Package) rewriteName(f *File, r *Ref, addPosition bool) ast.Expr {
getNewIdent := ast.NewIdent
if addPosition {
getNewIdent = func(newName string) *ast.Ident {
mangledIdent := ast.NewIdent(newName)
if len(newName) == len(r.Name.Go) {
return mangledIdent
}
p := fset.Position((*r.Expr).End())
if p.Column == 0 {
return mangledIdent
}
return ast.NewIdent(fmt.Sprintf("%s /*line :%d:%d*/", newName, p.Line, p.Column))
}
}
var expr ast.Expr = getNewIdent(r.Name.Mangle) // default
func (p *Package) rewriteName(f *File, r *Ref) ast.Expr {
var expr ast.Expr = ast.NewIdent(r.Name.Mangle) // default
switch r.Context {
case ctxCall, ctxCall2:
if r.Name.Kind != "func" {
@@ -1469,7 +1453,7 @@ func (p *Package) rewriteName(f *File, r *Ref, addPosition bool) ast.Expr {
n.Mangle = "_C2func_" + n.Go
f.Name["2"+r.Name.Go] = n
}
expr = getNewIdent(n.Mangle)
expr = ast.NewIdent(n.Mangle)
r.Name = n
break
}
@@ -1500,7 +1484,7 @@ func (p *Package) rewriteName(f *File, r *Ref, addPosition bool) ast.Expr {
// issue 7757.
expr = &ast.CallExpr{
Fun: &ast.Ident{NamePos: (*r.Expr).Pos(), Name: "_Cgo_ptr"},
Args: []ast.Expr{getNewIdent(name.Mangle)},
Args: []ast.Expr{ast.NewIdent(name.Mangle)},
}
case "type":
// Okay - might be new(T)
@@ -1638,8 +1622,6 @@ func (p *Package) gccCmd() []string {
c = append(c, "-maix64")
c = append(c, "-mcmodel=large")
}
// disable LTO so we get an object whose symbols we can read
c = append(c, "-fno-lto")
c = append(c, "-") //read input from standard input
return c
}

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Cgo; see doc.go for an overview.
// Cgo; see gmp.go for an overview.
// TODO(rsc):
// Emit correct line number annotations.
@@ -17,11 +17,9 @@ import (
"go/ast"
"go/printer"
"go/token"
"internal/buildcfg"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
@@ -304,14 +302,6 @@ func main() {
p := newPackage(args[:i])
// We need a C compiler to be available. Check this.
gccName := p.gccBaseCmd()[0]
_, err := exec.LookPath(gccName)
if err != nil {
fatalf("C compiler %q not found: %v", gccName, err)
os.Exit(2)
}
// Record CGO_LDFLAGS from the environment for external linking.
if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
args, err := splitQuoted(ldflags)
@@ -415,9 +405,8 @@ func newPackage(args []string) *Package {
if s := os.Getenv("GOOS"); s != "" {
goos = s
}
buildcfg.Check()
gomips = buildcfg.GOMIPS
gomips64 = buildcfg.GOMIPS64
gomips = objabi.GOMIPS
gomips64 = objabi.GOMIPS64
ptrSize := ptrSizeMap[goarch]
if ptrSize == 0 {
fatalf("unknown ptrSize for $GOARCH %q", goarch)

View File

@@ -168,18 +168,8 @@ func (p *Package) writeDefs() {
if *gccgo {
fmt.Fprintf(fc, "extern byte *%s;\n", n.C)
} else {
// Force a reference to all symbols so that
// the external linker will add DT_NEEDED
// entries as needed on ELF systems.
// Treat function variables differently
// to avoid type confict errors from LTO
// (Link Time Optimization).
if n.Kind == "fpvar" {
fmt.Fprintf(fm, "extern void %s();\n", n.C)
} else {
fmt.Fprintf(fm, "extern char %s[];\n", n.C)
fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
}
fmt.Fprintf(fm, "extern char %s[];\n", n.C)
fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
fmt.Fprintf(fgo2, "//go:linkname __cgo_%s %s\n", n.C, n.C)
fmt.Fprintf(fgo2, "//go:cgo_import_static %s\n", n.C)
fmt.Fprintf(fgo2, "var __cgo_%s byte\n", n.C)
@@ -1031,28 +1021,14 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
}
fmt.Fprintf(fgcc, "}\n")
// In internal linking mode, the Go linker sees both
// the C wrapper written above and the Go wrapper it
// references. Hence, export the C wrapper (e.g., for
// if we're building a shared object). The Go linker
// will resolve the C wrapper's reference to the Go
// wrapper without a separate export.
fmt.Fprintf(fgo2, "//go:cgo_export_dynamic %s\n", exp.ExpName)
// cgo_export_static refers to a symbol by its linker
// name, so set the linker name of the Go wrapper.
fmt.Fprintf(fgo2, "//go:linkname _cgoexp%s_%s _cgoexp%s_%s\n", cPrefix, exp.ExpName, cPrefix, exp.ExpName)
// In external linking mode, the Go linker sees the Go
// wrapper, but not the C wrapper. For this case,
// export the Go wrapper so the host linker can
// resolve the reference from the C wrapper to the Go
// wrapper.
fmt.Fprintf(fgo2, "//go:cgo_export_static _cgoexp%s_%s\n", cPrefix, exp.ExpName)
// Build the wrapper function compiled by cmd/compile.
// This unpacks the argument struct above and calls the Go function.
fmt.Fprintf(fgo2, "//go:cgo_export_dynamic %s\n", exp.ExpName)
fmt.Fprintf(fgo2, "//go:linkname _cgoexp%s_%s _cgoexp%s_%s\n", cPrefix, exp.ExpName, cPrefix, exp.ExpName)
fmt.Fprintf(fgo2, "//go:cgo_export_static _cgoexp%s_%s\n", cPrefix, exp.ExpName)
fmt.Fprintf(fgo2, "func _cgoexp%s_%s(a *%s) {\n", cPrefix, exp.ExpName, gotype)
fmt.Fprintf(fm, "void _cgoexp%s_%s(void* p){}\n", cPrefix, exp.ExpName)
fmt.Fprintf(fm, "int _cgoexp%s_%s;\n", cPrefix, exp.ExpName)
if gccResult != "void" {
// Write results back to frame.
@@ -1741,12 +1717,8 @@ typedef struct __go_open_array {
struct __go_string __go_byte_array_to_string(const void* p, intgo len);
struct __go_open_array __go_string_to_byte_array (struct __go_string str);
extern void runtime_throw(const char *);
const char *_cgoPREFIX_Cfunc_CString(struct __go_string s) {
char *p = malloc(s.__length+1);
if(p == NULL)
runtime_throw("runtime: C malloc failed");
memmove(p, s.__data, s.__length);
p[s.__length] = 0;
return p;
@@ -1754,8 +1726,6 @@ const char *_cgoPREFIX_Cfunc_CString(struct __go_string s) {
void *_cgoPREFIX_Cfunc_CBytes(struct __go_open_array b) {
char *p = malloc(b.__count);
if(p == NULL)
runtime_throw("runtime: C malloc failed");
memmove(p, b.__values, b.__count);
return p;
}
@@ -1774,13 +1744,14 @@ Slice _cgoPREFIX_Cfunc_GoBytes(char *p, int32_t n) {
return __go_string_to_byte_array(s);
}
extern void runtime_throw(const char *);
void *_cgoPREFIX_Cfunc__CMalloc(size_t n) {
void *p = malloc(n);
if(p == NULL && n == 0)
p = malloc(1);
if(p == NULL)
runtime_throw("runtime: C malloc failed");
return p;
void *p = malloc(n);
if(p == NULL && n == 0)
p = malloc(1);
if(p == NULL)
runtime_throw("runtime: C malloc failed");
return p;
}
struct __go_type_descriptor;

View File

@@ -83,8 +83,7 @@ Flags:
Without this flag, the -o output is a combination of both
linker and compiler input.
-m
Print optimization decisions. Higher values or repetition
produce more detail.
Print optimization decisions.
-memprofile file
Write memory profile for the compilation to file.
-memprofilerate rate

View File

@@ -233,7 +233,7 @@ stack frame is laid out in the following sequence:
r1.x uintptr
r1.y [2]uintptr
a1Spill uint8
a3Spill uint8
a2Spill uint8
_ [6]uint8 // alignment padding
In the stack frame, only the `a2` field is initialized on entry; the
@@ -401,16 +401,16 @@ without corrupting arguments or results.
Special-purpose registers are as follows:
| Register | Call meaning | Return meaning | Body meaning |
| --- | --- | --- | --- |
| RSP | Stack pointer | Same | Same |
| RBP | Frame pointer | Same | Same |
| RDX | Closure context pointer | Scratch | Scratch |
| R12 | Scratch | Scratch | Scratch |
| R13 | Scratch | Scratch | Scratch |
| R14 | Current goroutine | Same | Same |
| R15 | GOT reference temporary if dynlink | Same | Same |
| X15 | Zero value | Same | Scratch |
| Register | Call meaning | Body meaning |
| --- | --- | --- |
| RSP | Stack pointer | Fixed |
| RBP | Frame pointer | Fixed |
| RDX | Closure context pointer | Scratch |
| R12 | None | Scratch |
| R13 | None | Scratch |
| R14 | Current goroutine | Scratch |
| R15 | GOT reference temporary | Fixed if dynlink |
| X15 | Zero value | Fixed |
*Rationale*: These register meanings are compatible with Gos
stack-based calling convention except for R14 and X15, which will have
@@ -424,21 +424,10 @@ While this adds one byte to every function prologue, it is hardly ever
accessed outside the function prologue and we expect making more
single-byte registers available to be a net win.
*Rationale*: We could allow R14 (the current goroutine pointer) to be
a scratch register in function bodies because it can always be
restored from TLS on amd64.
However, we designate it as a fixed register for simplicity and for
consistency with other architectures that may not have a copy of the
current goroutine pointer in TLS.
*Rationale*: We designate X15 as a fixed zero register because
functions often have to bulk zero their stack frames, and this is more
efficient with a designated zero register.
*Implementation note*: Registers with fixed meaning at calls but not
in function bodies must be initialized by "injected" calls such as
signal-based panics.
#### Stack layout
The stack pointer, RSP, grows down and is always aligned to 8 bytes.
@@ -505,128 +494,6 @@ control bits specified by the ELF AMD64 ABI.
The x87 floating-point control word is not used by Go on amd64.
### arm64 architecture
The arm64 architecture uses R0 R15 for integer arguments and results.
It uses F0 F15 for floating-point arguments and results.
*Rationale*: 16 integer registers and 16 floating-point registers are
more than enough for passing arguments and results for practically all
functions (see Appendix). While there are more registers available,
using more registers provides little benefit. Additionally, it will add
overhead on code paths where the number of arguments are not statically
known (e.g. reflect call), and will consume more stack space when there
is only limited stack space available to fit in the nosplit limit.
Registers R16 and R17 are permanent scratch registers. They are also
used as scratch registers by the linker (Go linker and external
linker) in trampolines.
Register R18 is reserved and never used. It is reserved for the OS
on some platforms (e.g. macOS).
Registers R19 R25 are permanent scratch registers. In addition,
R27 is a permanent scratch register used by the assembler when
expanding instructions.
Floating-point registers F16 F31 are also permanent scratch
registers.
Special-purpose registers are as follows:
| Register | Call meaning | Return meaning | Body meaning |
| --- | --- | --- | --- |
| RSP | Stack pointer | Same | Same |
| R30 | Link register | Same | Scratch (non-leaf functions) |
| R29 | Frame pointer | Same | Same |
| R28 | Current goroutine | Same | Same |
| R27 | Scratch | Scratch | Scratch |
| R26 | Closure context pointer | Scratch | Scratch |
| R18 | Reserved (not used) | Same | Same |
| ZR | Zero value | Same | Same |
*Rationale*: These register meanings are compatible with Gos
stack-based calling convention.
*Rationale*: The link register, R30, holds the function return
address at the function entry. For functions that have frames
(including most non-leaf functions), R30 is saved to stack in the
function prologue and restored in the epilogue. Within the function
body, R30 can be used as a scratch register.
*Implementation note*: Registers with fixed meaning at calls but not
in function bodies must be initialized by "injected" calls such as
signal-based panics.
#### Stack layout
The stack pointer, RSP, grows down and is always aligned to 16 bytes.
*Rationale*: The arm64 architecture requires the stack pointer to be
16-byte aligned.
A function's stack frame, after the frame is created, is laid out as
follows:
+------------------------------+
| ... locals ... |
| ... outgoing arguments ... |
| return PC | ← RSP points to
| frame pointer on entry |
+------------------------------+ ↓ lower addresses
The "return PC" is loaded to the link register, R30, as part of the
arm64 `CALL` operation.
On entry, a function subtracts from RSP to open its stack frame, and
saves the values of R30 and R29 at the bottom of the frame.
Specifically, R30 is saved at 0(RSP) and R29 is saved at -8(RSP),
after RSP is updated.
A leaf function that does not require any stack space may omit the
saved R30 and R29.
The Go ABI's use of R29 as a frame pointer register is compatible with
arm64 architecture requirement so that Go can inter-operate with platform
debuggers and profilers.
This stack layout is used by both register-based (ABIInternal) and
stack-based (ABI0) calling conventions.
#### Flags
The arithmetic status flags (NZCV) are treated like scratch registers
and not preserved across calls.
All other bits in PSTATE are system flags and are not modified by Go.
The floating-point status register (FPSR) is treated like scratch
registers and not preserved across calls.
At calls, the floating-point control register (FPCR) bits are always
set as follows:
| Flag | Bit | Value | Meaning |
| --- | --- | --- | --- |
| DN | 25 | 0 | Propagate NaN operands |
| FZ | 24 | 0 | Do not flush to zero |
| RC | 23/22 | 0 (RN) | Round to nearest, choose even if tied |
| IDE | 15 | 0 | Denormal operations trap disabled |
| IXE | 12 | 0 | Inexact trap disabled |
| UFE | 11 | 0 | Underflow trap disabled |
| OFE | 10 | 0 | Overflow trap disabled |
| DZE | 9 | 0 | Divide-by-zero trap disabled |
| IOE | 8 | 0 | Invalid operations trap disabled |
| NEP | 2 | 0 | Scalar operations do not affect higher elements in vector registers |
| AH | 1 | 0 | No alternate handling of de-normal inputs |
| FIZ | 0 | 0 | Do not zero de-normals |
*Rationale*: Having a fixed FPCR control configuration allows Go
functions to use floating-point and vector (SIMD) operations without
modifying or saving the FPCR.
Functions are allowed to modify it between calls (as long as they
restore it), but as of this writing Go code never does.
## Future directions
### Spill path improvements

View File

@@ -5,8 +5,6 @@
package abi
import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
"cmd/internal/src"
"fmt"
@@ -70,14 +68,6 @@ func (a *ABIParamResultInfo) SpillAreaSize() int64 {
return a.spillAreaSize
}
// ArgWidth returns the amount of stack needed for all the inputs
// and outputs of a function or method, including ABI-defined parameter
// slots and ABI-defined spill slots for register-resident parameters.
// The name is inherited from (*Type).ArgWidth(), which it replaces.
func (a *ABIParamResultInfo) ArgWidth() int64 {
return a.spillAreaSize + a.offsetToSpillArea - a.config.LocalsOffset()
}
// RegIndex stores the index into the set of machine registers used by
// the ABI on a specific architecture for parameter passing. RegIndex
// values 0 through N-1 (where N is the number of integer registers
@@ -105,147 +95,32 @@ type ABIParamAssignment struct {
// This will panic if "a" describes a register-allocated parameter.
func (a *ABIParamAssignment) Offset() int32 {
if len(a.Registers) > 0 {
base.Fatalf("register allocated parameters have no offset")
panic("Register allocated parameters have no offset")
}
return a.offset
}
// RegisterTypes returns a slice of the types of the registers
// corresponding to a slice of parameters. The returned slice
// has capacity for one more, likely a memory type.
func RegisterTypes(apa []ABIParamAssignment) []*types.Type {
rcount := 0
for _, pa := range apa {
rcount += len(pa.Registers)
// SpillOffset returns the offset *within the spill area* for the parameter that "a" describes.
// Registers will be spilled here; if a memory home is needed (for a pointer method e.g.)
// then that will be the address.
// This will panic if "a" describes a stack-allocated parameter.
func (a *ABIParamAssignment) SpillOffset() int32 {
if len(a.Registers) == 0 {
panic("Stack-allocated parameters have no spill offset")
}
if rcount == 0 {
// Note that this catches top-level struct{} and [0]Foo, which are stack allocated.
return make([]*types.Type, 0, 1)
}
rts := make([]*types.Type, 0, rcount+1)
for _, pa := range apa {
if len(pa.Registers) == 0 {
continue
}
rts = appendParamTypes(rts, pa.Type)
}
return rts
return a.offset
}
func (pa *ABIParamAssignment) RegisterTypesAndOffsets() ([]*types.Type, []int64) {
l := len(pa.Registers)
if l == 0 {
return nil, nil
}
typs := make([]*types.Type, 0, l)
offs := make([]int64, 0, l)
offs, _ = appendParamOffsets(offs, 0, pa.Type)
return appendParamTypes(typs, pa.Type), offs
}
func appendParamTypes(rts []*types.Type, t *types.Type) []*types.Type {
w := t.Width
if w == 0 {
return rts
}
if t.IsScalar() || t.IsPtrShaped() {
if t.IsComplex() {
c := types.FloatForComplex(t)
return append(rts, c, c)
} else {
if int(t.Size()) <= types.RegSize {
return append(rts, t)
}
// assume 64bit int on 32-bit machine
// TODO endianness? Should high-order (sign bits) word come first?
if t.IsSigned() {
rts = append(rts, types.Types[types.TINT32])
} else {
rts = append(rts, types.Types[types.TUINT32])
}
return append(rts, types.Types[types.TUINT32])
}
} else {
typ := t.Kind()
switch typ {
case types.TARRAY:
for i := int64(0); i < t.NumElem(); i++ { // 0 gets no registers, plus future-proofing.
rts = appendParamTypes(rts, t.Elem())
}
case types.TSTRUCT:
for _, f := range t.FieldSlice() {
if f.Type.Size() > 0 { // embedded zero-width types receive no registers
rts = appendParamTypes(rts, f.Type)
}
}
case types.TSLICE:
return appendParamTypes(rts, synthSlice)
case types.TSTRING:
return appendParamTypes(rts, synthString)
case types.TINTER:
return appendParamTypes(rts, synthIface)
}
}
return rts
}
// appendParamOffsets appends the offset(s) of type t, starting from "at",
// to input offsets, and returns the longer slice and the next unused offset.
func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int64) {
at = align(at, t)
w := t.Width
if w == 0 {
return offsets, at
}
if t.IsScalar() || t.IsPtrShaped() {
if t.IsComplex() || int(t.Width) > types.RegSize { // complex and *int64 on 32-bit
s := w / 2
return append(offsets, at, at+s), at + w
} else {
return append(offsets, at), at + w
}
} else {
typ := t.Kind()
switch typ {
case types.TARRAY:
for i := int64(0); i < t.NumElem(); i++ {
offsets, at = appendParamOffsets(offsets, at, t.Elem())
}
case types.TSTRUCT:
for i, f := range t.FieldSlice() {
offsets, at = appendParamOffsets(offsets, at, f.Type)
if f.Type.Width == 0 && i == t.NumFields()-1 {
at++ // last field has zero width
}
}
at = align(at, t) // type size is rounded up to its alignment
case types.TSLICE:
return appendParamOffsets(offsets, at, synthSlice)
case types.TSTRING:
return appendParamOffsets(offsets, at, synthString)
case types.TINTER:
return appendParamOffsets(offsets, at, synthIface)
}
}
return offsets, at
}
// FrameOffset returns the frame-pointer-relative location that a function
// would spill its input or output parameter to, if such a spill slot exists.
// If there is none defined (e.g., register-allocated outputs) it panics.
// For register-allocated inputs that is their spill offset reserved for morestack;
// for stack-allocated inputs and outputs, that is their location on the stack.
// (In a future version of the ABI, register-resident inputs may lose their defined
// spill area to help reduce stack sizes.)
// FrameOffset returns the location that a value would spill to, if any exists.
// For register-allocated inputs, that is their spill offset reserved for morestack
// (might as well use it, it is there); for stack-allocated inputs and outputs,
// that is their location on the stack. For register-allocated outputs, there is
// no defined spill area, so return -1.
func (a *ABIParamAssignment) FrameOffset(i *ABIParamResultInfo) int64 {
if a.offset == -1 {
base.Fatalf("function parameter has no ABI-defined frame-pointer offset")
if len(a.Registers) == 0 || a.offset == -1 {
return int64(a.offset)
}
if len(a.Registers) == 0 { // passed on stack
return int64(a.offset) - i.config.LocalsOffset()
}
// spill area for registers
return int64(a.offset) + i.SpillAreaOffset() - i.config.LocalsOffset()
return int64(a.offset) + i.SpillAreaOffset()
}
// RegAmounts holds a specified number of integer/float registers.
@@ -422,50 +297,48 @@ func (config *ABIConfig) ABIAnalyzeFuncType(ft *types.Func) *ABIParamResultInfo
// ABIAnalyze returns the same result as ABIAnalyzeFuncType, but also
// updates the offsets of all the receiver, input, and output fields.
// If setNname is true, it also sets the FrameOffset of the Nname for
// the field(s); this is for use when compiling a function and figuring out
// spill locations. Doing this for callers can cause races for register
// outputs because their frame location transitions from BOGUS_FUNARG_OFFSET
// to zero to an as-if-AUTO offset that has no use for callers.
func (config *ABIConfig) ABIAnalyze(t *types.Type, setNname bool) *ABIParamResultInfo {
func (config *ABIConfig) ABIAnalyze(t *types.Type) *ABIParamResultInfo {
ft := t.FuncType()
result := config.ABIAnalyzeFuncType(ft)
// Fill in the frame offsets for receiver, inputs, results
k := 0
if t.NumRecvs() != 0 {
config.updateOffset(result, ft.Receiver.FieldSlice()[0], result.inparams[0], false, setNname)
config.updateOffset(result, ft.Receiver.FieldSlice()[0], result.inparams[0], false)
k++
}
for i, f := range ft.Params.FieldSlice() {
config.updateOffset(result, f, result.inparams[k+i], false, setNname)
config.updateOffset(result, f, result.inparams[k+i], false)
}
for i, f := range ft.Results.FieldSlice() {
config.updateOffset(result, f, result.outparams[i], true, setNname)
config.updateOffset(result, f, result.outparams[i], true)
}
return result
}
func (config *ABIConfig) updateOffset(result *ABIParamResultInfo, f *types.Field, a ABIParamAssignment, isReturn, setNname bool) {
// parameterUpdateMu protects the Offset field of function/method parameters (a subset of structure Fields)
var parameterUpdateMu sync.Mutex
// FieldOffsetOf returns a concurency-safe version of f.Offset
func FieldOffsetOf(f *types.Field) int64 {
parameterUpdateMu.Lock()
defer parameterUpdateMu.Unlock()
return f.Offset
}
func (config *ABIConfig) updateOffset(result *ABIParamResultInfo, f *types.Field, a ABIParamAssignment, isReturn bool) {
// Everything except return values in registers has either a frame home (if not in a register) or a frame spill location.
if !isReturn || len(a.Registers) == 0 {
// The type frame offset DOES NOT show effects of minimum frame size.
// Getting this wrong breaks stackmaps, see liveness/plive.go:WriteFuncMap and typebits/typebits.go:Set
off := a.FrameOffset(result)
parameterUpdateMu.Lock()
defer parameterUpdateMu.Unlock()
off := a.FrameOffset(result) - config.LocalsOffset()
fOffset := f.Offset
if fOffset == types.BOGUS_FUNARG_OFFSET {
if setNname && f.Nname != nil {
f.Nname.(*ir.Name).SetFrameOffset(off)
f.Nname.(*ir.Name).SetIsOutputParamInRegisters(false)
}
} else {
base.Fatalf("field offset for %s at %s has been set to %d", f.Sym.Name, base.FmtPos(f.Pos), fOffset)
}
} else {
if setNname && f.Nname != nil {
fname := f.Nname.(*ir.Name)
fname.SetIsOutputParamInRegisters(true)
fname.SetFrameOffset(0)
// Set the Offset the first time. After that, we may recompute it, but it should never change.
f.Offset = off
} else if fOffset != off {
panic(fmt.Errorf("Offset changed from %d to %d", fOffset, off))
}
}
}
@@ -484,9 +357,9 @@ func (c *RegAmounts) regString(r RegIndex) string {
return fmt.Sprintf("<?>%d", r)
}
// ToString method renders an ABIParamAssignment in human-readable
// toString method renders an ABIParamAssignment in human-readable
// form, suitable for debugging or unit testing.
func (ri *ABIParamAssignment) ToString(config *ABIConfig, extra bool) string {
func (ri *ABIParamAssignment) toString(config *ABIConfig) string {
regs := "R{"
offname := "spilloffset" // offset is for spill for register(s)
if len(ri.Registers) == 0 {
@@ -494,25 +367,19 @@ func (ri *ABIParamAssignment) ToString(config *ABIConfig, extra bool) string {
}
for _, r := range ri.Registers {
regs += " " + config.regAmounts.regString(r)
if extra {
regs += fmt.Sprintf("(%d)", r)
}
}
if extra {
regs += fmt.Sprintf(" | #I=%d, #F=%d", config.regAmounts.intRegs, config.regAmounts.floatRegs)
}
return fmt.Sprintf("%s } %s: %d typ: %v", regs, offname, ri.offset, ri.Type)
}
// String method renders an ABIParamResultInfo in human-readable
// toString method renders an ABIParamResultInfo in human-readable
// form, suitable for debugging or unit testing.
func (ri *ABIParamResultInfo) String() string {
res := ""
for k, p := range ri.inparams {
res += fmt.Sprintf("IN %d: %s\n", k, p.ToString(ri.config, false))
res += fmt.Sprintf("IN %d: %s\n", k, p.toString(ri.config))
}
for k, r := range ri.outparams {
res += fmt.Sprintf("OUT %d: %s\n", k, r.ToString(ri.config, false))
res += fmt.Sprintf("OUT %d: %s\n", k, r.toString(ri.config))
}
res += fmt.Sprintf("offsetToSpillArea: %d spillAreaSize: %d",
ri.offsetToSpillArea, ri.spillAreaSize)
@@ -550,55 +417,25 @@ func (state *assignState) stackSlot(t *types.Type) int64 {
return rv
}
// allocateRegs returns an ordered list of register indices for a parameter or result
// allocateRegs returns a set of register indices for a parameter or result
// that we've just determined to be register-assignable. The number of registers
// needed is assumed to be stored in state.pUsed.
func (state *assignState) allocateRegs(regs []RegIndex, t *types.Type) []RegIndex {
if t.Width == 0 {
return regs
func (state *assignState) allocateRegs() []RegIndex {
regs := []RegIndex{}
// integer
for r := state.rUsed.intRegs; r < state.rUsed.intRegs+state.pUsed.intRegs; r++ {
regs = append(regs, RegIndex(r))
}
ri := state.rUsed.intRegs
rf := state.rUsed.floatRegs
if t.IsScalar() || t.IsPtrShaped() {
if t.IsComplex() {
regs = append(regs, RegIndex(rf+state.rTotal.intRegs), RegIndex(rf+1+state.rTotal.intRegs))
rf += 2
} else if t.IsFloat() {
regs = append(regs, RegIndex(rf+state.rTotal.intRegs))
rf += 1
} else {
n := (int(t.Size()) + types.RegSize - 1) / types.RegSize
for i := 0; i < n; i++ { // looking ahead to really big integers
regs = append(regs, RegIndex(ri))
ri += 1
}
}
state.rUsed.intRegs = ri
state.rUsed.floatRegs = rf
return regs
} else {
typ := t.Kind()
switch typ {
case types.TARRAY:
for i := int64(0); i < t.NumElem(); i++ {
regs = state.allocateRegs(regs, t.Elem())
}
return regs
case types.TSTRUCT:
for _, f := range t.FieldSlice() {
regs = state.allocateRegs(regs, f.Type)
}
return regs
case types.TSLICE:
return state.allocateRegs(regs, synthSlice)
case types.TSTRING:
return state.allocateRegs(regs, synthString)
case types.TINTER:
return state.allocateRegs(regs, synthIface)
}
state.rUsed.intRegs += state.pUsed.intRegs
// floating
for r := state.rUsed.floatRegs; r < state.rUsed.floatRegs+state.pUsed.floatRegs; r++ {
regs = append(regs, RegIndex(r+state.rTotal.intRegs))
}
base.Fatalf("was not expecting type %s", t)
panic("unreachable")
state.rUsed.floatRegs += state.pUsed.floatRegs
return regs
}
// regAllocate creates a register ABIParamAssignment object for a param
@@ -614,7 +451,7 @@ func (state *assignState) regAllocate(t *types.Type, name types.Object, isReturn
return ABIParamAssignment{
Type: t,
Name: name,
Registers: state.allocateRegs([]RegIndex{}, t),
Registers: state.allocateRegs(),
offset: int32(spillLoc),
}
}
@@ -753,8 +590,7 @@ func (state *assignState) regassign(pt *types.Type) bool {
case types.TINTER:
return state.regassignStruct(synthIface)
default:
base.Fatalf("not expected")
panic("unreachable")
panic("not expected")
}
}
@@ -765,8 +601,7 @@ func (state *assignState) regassign(pt *types.Type) bool {
func (state *assignState) assignParamOrReturn(pt *types.Type, n types.Object, isReturn bool) ABIParamAssignment {
state.pUsed = RegAmounts{}
if pt.Width == types.BADWIDTH {
base.Fatalf("should never happen")
panic("unreachable")
panic("should never happen")
} else if pt.Width == 0 {
return state.stackAllocate(pt, n)
} else if state.regassign(pt) {
@@ -775,51 +610,3 @@ func (state *assignState) assignParamOrReturn(pt *types.Type, n types.Object, is
return state.stackAllocate(pt, n)
}
}
// ComputePadding returns a list of "post element" padding values in
// the case where we have a structure being passed in registers. Give
// a param assignment corresponding to a struct, it returns a list of
// contaning padding values for each field, e.g. the Kth element in
// the list is the amount of padding between field K and the following
// field. For things that are not struct (or structs without padding)
// it returns a list of zeros. Example:
//
// type small struct {
// x uint16
// y uint8
// z int32
// w int32
// }
//
// For this struct we would return a list [0, 1, 0, 0], meaning that
// we have one byte of padding after the second field, and no bytes of
// padding after any of the other fields. Input parameter "storage"
// is with enough capacity to accommodate padding elements for
// the architected register set in question.
func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 {
nr := len(pa.Registers)
padding := storage[:nr]
for i := 0; i < nr; i++ {
padding[i] = 0
}
if pa.Type.Kind() != types.TSTRUCT || nr == 0 {
return padding
}
types := make([]*types.Type, 0, nr)
types = appendParamTypes(types, pa.Type)
if len(types) != nr {
panic("internal error")
}
off := int64(0)
for idx, t := range types {
ts := t.Size()
off += int64(ts)
if idx < len(types)-1 {
noff := align(off, types[idx+1])
if noff != off {
padding[idx] = uint64(noff - off)
}
}
}
return padding
}

View File

@@ -18,10 +18,9 @@ func Init(arch *ssagen.ArchInfo) {
arch.ZeroRange = zerorange
arch.Ginsnop = ginsnop
arch.Ginsnopdefer = ginsnop
arch.SSAMarkMoves = ssaMarkMoves
arch.SSAGenValue = ssaGenValue
arch.SSAGenBlock = ssaGenBlock
arch.LoadRegResult = loadRegResult
arch.SpillArgReg = spillArgReg
}

View File

@@ -11,11 +11,11 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"internal/buildcfg"
"cmd/internal/objabi"
)
// no floating point in note handlers on Plan 9
var isPlan9 = buildcfg.GOOS == "plan9"
var isPlan9 = objabi.GOOS == "plan9"
// DUFFZERO consists of repeated blocks of 4 MOVUPSs + LEAQ,
// See runtime/mkduff.go.
@@ -56,7 +56,8 @@ func dzDI(b int64) int64 {
func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.Prog {
const (
r13 = 1 << iota // if R13 is already zeroed.
ax = 1 << iota // if AX is already zeroed.
x15 // if X15 is already zeroed. Note: in new ABI, X15 is always zero.
)
if cnt == 0 {
@@ -68,22 +69,27 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
if cnt%int64(types.PtrSize) != 0 {
base.Fatalf("zerorange count not a multiple of widthptr %d", cnt)
}
if *state&r13 == 0 {
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_R13, 0)
*state |= r13
if *state&ax == 0 {
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
*state |= ax
}
p = pp.Append(p, x86.AMOVL, obj.TYPE_REG, x86.REG_R13, 0, obj.TYPE_MEM, x86.REG_SP, off)
p = pp.Append(p, x86.AMOVL, obj.TYPE_REG, x86.REG_AX, 0, obj.TYPE_MEM, x86.REG_SP, off)
off += int64(types.PtrSize)
cnt -= int64(types.PtrSize)
}
if cnt == 8 {
if *state&r13 == 0 {
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_R13, 0)
*state |= r13
if *state&ax == 0 {
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
*state |= ax
}
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R13, 0, obj.TYPE_MEM, x86.REG_SP, off)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_AX, 0, obj.TYPE_MEM, x86.REG_SP, off)
} else if !isPlan9 && cnt <= int64(8*types.RegSize) {
if objabi.Regabi_enabled == 0 && *state&x15 == 0 {
p = pp.Append(p, x86.AXORPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_REG, x86.REG_X15, 0)
*state |= x15
}
for i := int64(0); i < cnt/16; i++ {
p = pp.Append(p, x86.AMOVUPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_MEM, x86.REG_SP, off+i*16)
}
@@ -92,47 +98,27 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
p = pp.Append(p, x86.AMOVUPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_MEM, x86.REG_SP, off+cnt-int64(16))
}
} else if !isPlan9 && (cnt <= int64(128*types.RegSize)) {
// Save DI to r12. With the amd64 Go register abi, DI can contain
// an incoming parameter, whereas R12 is always scratch.
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_DI, 0, obj.TYPE_REG, x86.REG_R12, 0)
// Emit duffzero call
if objabi.Regabi_enabled == 0 && *state&x15 == 0 {
p = pp.Append(p, x86.AXORPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_REG, x86.REG_X15, 0)
*state |= x15
}
p = pp.Append(p, leaptr, obj.TYPE_MEM, x86.REG_SP, off+dzDI(cnt), obj.TYPE_REG, x86.REG_DI, 0)
p = pp.Append(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_ADDR, 0, dzOff(cnt))
p.To.Sym = ir.Syms.Duffzero
if cnt%16 != 0 {
p = pp.Append(p, x86.AMOVUPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_MEM, x86.REG_DI, -int64(8))
}
// Restore DI from r12
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R12, 0, obj.TYPE_REG, x86.REG_DI, 0)
} else {
// When the register ABI is in effect, at this point in the
// prolog we may have live values in all of RAX,RDI,RCX. Save
// them off to registers before the REPSTOSQ below, then
// restore. Note that R12 and R13 are always available as
// scratch regs; here we also use R15 (this is safe to do
// since there won't be any globals accessed in the prolog).
// See rewriteToUseGot() in obj6.go for more on r15 use.
if *state&ax == 0 {
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
*state |= ax
}
// Save rax/rdi/rcx
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_DI, 0, obj.TYPE_REG, x86.REG_R12, 0)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_AX, 0, obj.TYPE_REG, x86.REG_R13, 0)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_CX, 0, obj.TYPE_REG, x86.REG_R15, 0)
// Set up the REPSTOSQ and kick it off.
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, cnt/int64(types.RegSize), obj.TYPE_REG, x86.REG_CX, 0)
p = pp.Append(p, leaptr, obj.TYPE_MEM, x86.REG_SP, off, obj.TYPE_REG, x86.REG_DI, 0)
p = pp.Append(p, x86.AREP, obj.TYPE_NONE, 0, 0, obj.TYPE_NONE, 0, 0)
p = pp.Append(p, x86.ASTOSQ, obj.TYPE_NONE, 0, 0, obj.TYPE_NONE, 0, 0)
// Restore rax/rdi/rcx
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R12, 0, obj.TYPE_REG, x86.REG_DI, 0)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R13, 0, obj.TYPE_REG, x86.REG_AX, 0)
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R15, 0, obj.TYPE_REG, x86.REG_CX, 0)
// Record the fact that r13 is no longer zero.
*state &= ^uint32(r13)
}
return p

View File

@@ -6,18 +6,17 @@ package amd64
import (
"fmt"
"internal/buildcfg"
"math"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/logopt"
"cmd/compile/internal/objw"
"cmd/compile/internal/ssa"
"cmd/compile/internal/ssagen"
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"cmd/internal/objabi"
)
// markMoves marks any MOVXconst ops that need to avoid clobbering flags.
@@ -254,15 +253,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssa.OpAMD64BTRL, ssa.OpAMD64BTRQ:
opregreg(s, v.Op.Asm(), v.Reg(), v.Args[1].Reg())
case ssa.OpAMD64SHRDQ, ssa.OpAMD64SHLDQ:
p := s.Prog(v.Op.Asm())
lo, hi, bits := v.Args[0].Reg(), v.Args[1].Reg(), v.Args[2].Reg()
p.From.Type = obj.TYPE_REG
p.From.Reg = bits
p.To.Type = obj.TYPE_REG
p.To.Reg = lo
p.SetFrom3Reg(hi)
case ssa.OpAMD64DIVQU, ssa.OpAMD64DIVLU, ssa.OpAMD64DIVWU:
// Arg[0] (the dividend) is in AX.
// Arg[1] (the divisor) can be in any other register.
@@ -692,9 +682,9 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p := s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_MEM
p.From.Reg = v.Args[0].Reg()
ssagen.AddAux2(&p.From, v, sc.Off64())
ssagen.AddAux2(&p.From, v, sc.Off())
p.To.Type = obj.TYPE_CONST
p.To.Offset = sc.Val64()
p.To.Offset = sc.Val()
case ssa.OpAMD64CMPQloadidx8, ssa.OpAMD64CMPQloadidx1, ssa.OpAMD64CMPLloadidx4, ssa.OpAMD64CMPLloadidx1, ssa.OpAMD64CMPWloadidx2, ssa.OpAMD64CMPWloadidx1, ssa.OpAMD64CMPBloadidx1:
p := s.Prog(v.Op.Asm())
memIdx(&p.From, v)
@@ -705,9 +695,9 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
sc := v.AuxValAndOff()
p := s.Prog(v.Op.Asm())
memIdx(&p.From, v)
ssagen.AddAux2(&p.From, v, sc.Off64())
ssagen.AddAux2(&p.From, v, sc.Off())
p.To.Type = obj.TYPE_CONST
p.To.Offset = sc.Val64()
p.To.Offset = sc.Val()
case ssa.OpAMD64MOVLconst, ssa.OpAMD64MOVQconst:
x := v.Reg()
@@ -756,6 +746,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore, ssa.OpAMD64MOVOstore,
ssa.OpAMD64BTCQmodify, ssa.OpAMD64BTCLmodify, ssa.OpAMD64BTRQmodify, ssa.OpAMD64BTRLmodify, ssa.OpAMD64BTSQmodify, ssa.OpAMD64BTSLmodify,
ssa.OpAMD64ADDQmodify, ssa.OpAMD64SUBQmodify, ssa.OpAMD64ANDQmodify, ssa.OpAMD64ORQmodify, ssa.OpAMD64XORQmodify,
ssa.OpAMD64ADDLmodify, ssa.OpAMD64SUBLmodify, ssa.OpAMD64ANDLmodify, ssa.OpAMD64ORLmodify, ssa.OpAMD64XORLmodify:
p := s.Prog(v.Op.Asm())
@@ -778,7 +769,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssagen.AddAux(&p.To, v)
case ssa.OpAMD64ADDQconstmodify, ssa.OpAMD64ADDLconstmodify:
sc := v.AuxValAndOff()
off := sc.Off64()
off := sc.Off()
val := sc.Val()
if val == 1 || val == -1 {
var asm obj.As
@@ -803,10 +794,11 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
fallthrough
case ssa.OpAMD64ANDQconstmodify, ssa.OpAMD64ANDLconstmodify, ssa.OpAMD64ORQconstmodify, ssa.OpAMD64ORLconstmodify,
ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify:
ssa.OpAMD64BTCQconstmodify, ssa.OpAMD64BTCLconstmodify, ssa.OpAMD64BTSQconstmodify, ssa.OpAMD64BTSLconstmodify,
ssa.OpAMD64BTRQconstmodify, ssa.OpAMD64BTRLconstmodify, ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify:
sc := v.AuxValAndOff()
off := sc.Off64()
val := sc.Val64()
off := sc.Off()
val := sc.Val()
p := s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_CONST
p.From.Offset = val
@@ -818,13 +810,16 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p := s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_CONST
sc := v.AuxValAndOff()
p.From.Offset = sc.Val64()
p.From.Offset = sc.Val()
p.To.Type = obj.TYPE_MEM
p.To.Reg = v.Args[0].Reg()
ssagen.AddAux2(&p.To, v, sc.Off64())
ssagen.AddAux2(&p.To, v, sc.Off())
case ssa.OpAMD64MOVOstorezero:
if s.ABI != obj.ABIInternal {
// zero X15 manually
v.Fatalf("MOVOstorezero can be only used in ABIInternal functions")
}
if !(objabi.Regabi_enabled == 1 && base.Flag.ABIWrap) {
// zeroing X15 manually if wrappers are not used
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
p := s.Prog(v.Op.Asm())
@@ -841,7 +836,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p := s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_CONST
sc := v.AuxValAndOff()
p.From.Offset = sc.Val64()
p.From.Offset = sc.Val()
switch {
case p.As == x86.AADDQ && p.From.Offset == 1:
p.As = x86.AINCQ
@@ -857,7 +852,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.From.Type = obj.TYPE_NONE
}
memIdx(&p.To, v)
ssagen.AddAux2(&p.To, v, sc.Off64())
ssagen.AddAux2(&p.To, v, sc.Off())
case ssa.OpAMD64MOVLQSX, ssa.OpAMD64MOVWQSX, ssa.OpAMD64MOVBQSX, ssa.OpAMD64MOVLQZX, ssa.OpAMD64MOVWQZX, ssa.OpAMD64MOVBQZX,
ssa.OpAMD64CVTTSS2SL, ssa.OpAMD64CVTTSD2SL, ssa.OpAMD64CVTTSS2SQ, ssa.OpAMD64CVTTSD2SQ,
ssa.OpAMD64CVTSS2SD, ssa.OpAMD64CVTSD2SS:
@@ -915,7 +910,10 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.To.Reg = v.Reg()
case ssa.OpAMD64DUFFZERO:
if s.ABI != obj.ABIInternal {
// zero X15 manually
v.Fatalf("MOVOconst can be only used in ABIInternal functions")
}
if !(objabi.Regabi_enabled == 1 && base.Flag.ABIWrap) {
// zeroing X15 manually if wrappers are not used
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
off := duffStart(v.AuxInt)
@@ -982,41 +980,26 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssagen.AddAux(&p.From, v)
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpArgIntReg, ssa.OpArgFloatReg:
// The assembler needs to wrap the entry safepoint/stack growth code with spill/unspill
// The loop only runs once.
for _, ap := range v.Block.Func.RegArgs {
// Pass the spill/unspill information along to the assembler, offset by size of return PC pushed on stack.
addr := ssagen.SpillSlotAddr(ap, x86.REG_SP, v.Block.Func.Config.PtrSize)
s.FuncInfo().AddSpill(
obj.RegSpill{Reg: ap.Reg, Addr: addr, Unspill: loadByType(ap.Type), Spill: storeByType(ap.Type)})
}
v.Block.Func.RegArgs = nil
ssagen.CheckArgReg(v)
case ssa.OpAMD64LoweredGetClosurePtr:
// Closure pointer is DX.
ssagen.CheckLoweredGetClosurePtr(v)
case ssa.OpAMD64LoweredGetG:
if s.ABI == obj.ABIInternal {
v.Fatalf("LoweredGetG should not appear in ABIInternal")
if objabi.Regabi_enabled == 1 && base.Flag.ABIWrap {
v.Fatalf("LoweredGetG should not appear in new ABI")
}
r := v.Reg()
getgFromTLS(s, r)
case ssa.OpAMD64CALLstatic:
if s.ABI == obj.ABI0 && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABIInternal {
if objabi.Regabi_enabled == 1 && s.ABI == obj.ABI0 && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABIInternal {
// zeroing X15 when entering ABIInternal from ABI0
if buildcfg.GOOS != "plan9" { // do not use SSE on Plan 9
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
getgFromTLS(s, x86.REG_R14)
}
s.Call(v)
if s.ABI == obj.ABIInternal && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABI0 {
if objabi.Regabi_enabled == 1 && s.ABI == obj.ABIInternal && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABI0 {
// zeroing X15 when entering ABIInternal from ABI0
if buildcfg.GOOS != "plan9" { // do not use SSE on Plan 9
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
getgFromTLS(s, x86.REG_R14)
}
@@ -1239,13 +1222,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.To.Reg = x86.REG_SP
ssagen.AddAux(&p.To, v)
p.To.Offset += 4
case ssa.OpClobberReg:
x := uint64(0xdeaddeaddeaddead)
p := s.Prog(x86.AMOVQ)
p.From.Type = obj.TYPE_CONST
p.From.Offset = int64(x)
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
default:
v.Fatalf("genValue not implemented: %s", v.LongString())
}
@@ -1308,11 +1284,9 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
case ssa.BlockRet:
s.Prog(obj.ARET)
case ssa.BlockRetJmp:
if s.ABI == obj.ABI0 && b.Aux.(*obj.LSym).ABI() == obj.ABIInternal {
if objabi.Regabi_enabled == 1 && s.ABI == obj.ABI0 && b.Aux.(*obj.LSym).ABI() == obj.ABIInternal {
// zeroing X15 when entering ABIInternal from ABI0
if buildcfg.GOOS != "plan9" { // do not use SSE on Plan 9
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
getgFromTLS(s, x86.REG_R14)
}
@@ -1353,22 +1327,3 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
b.Fatalf("branch not implemented: %s", b.LongString())
}
}
func loadRegResult(s *ssagen.State, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
p := s.Prog(loadByType(t))
p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_AUTO
p.From.Sym = n.Linksym()
p.From.Offset = n.FrameOffset() + off
p.To.Type = obj.TYPE_REG
p.To.Reg = reg
return p
}
func spillArgReg(pp *objw.Progs, p *obj.Prog, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
p = pp.Append(p, storeByType(t), obj.TYPE_REG, reg, 0, obj.TYPE_MEM, 0, n.FrameOffset()+off)
p.To.Name = obj.NAME_PARAM
p.To.Sym = n.Linksym()
p.Pos = p.Pos.WithNotStmt()
return p
}

View File

@@ -8,16 +8,17 @@ import (
"cmd/compile/internal/ssa"
"cmd/compile/internal/ssagen"
"cmd/internal/obj/arm"
"internal/buildcfg"
"cmd/internal/objabi"
)
func Init(arch *ssagen.ArchInfo) {
arch.LinkArch = &arm.Linkarm
arch.REGSP = arm.REGSP
arch.MAXWIDTH = (1 << 32) - 1
arch.SoftFloat = buildcfg.GOARM == 5
arch.SoftFloat = objabi.GOARM == 5
arch.ZeroRange = zerorange
arch.Ginsnop = ginsnop
arch.Ginsnopdefer = ginsnop
arch.SSAMarkMoves = func(s *ssagen.State, b *ssa.Block) {}
arch.SSAGenValue = ssaGenValue

View File

@@ -6,7 +6,6 @@ package arm
import (
"fmt"
"internal/buildcfg"
"math"
"math/bits"
@@ -18,6 +17,7 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/arm"
"cmd/internal/objabi"
)
// loadByType returns the load instruction of the given type.
@@ -286,7 +286,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
case ssa.OpARMANDconst, ssa.OpARMBICconst:
// try to optimize ANDconst and BICconst to BFC, which saves bytes and ticks
// BFC is only available on ARMv7, and its result and source are in the same register
if buildcfg.GOARM == 7 && v.Reg() == v.Args[0].Reg() {
if objabi.GOARM == 7 && v.Reg() == v.Args[0].Reg() {
var val uint32
if v.Op == ssa.OpARMANDconst {
val = ^uint32(v.AuxInt)
@@ -643,7 +643,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
default:
}
}
if buildcfg.GOARM >= 6 {
if objabi.GOARM >= 6 {
// generate more efficient "MOVB/MOVBU/MOVH/MOVHU Reg@>0, Reg" on ARMv6 & ARMv7
genshift(s, v.Op.Asm(), 0, v.Args[0].Reg(), v.Reg(), arm.SHIFT_RR, 0)
return
@@ -861,7 +861,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
v.Fatalf("FlagConstant op should never make it to codegen %v", v.LongString())
case ssa.OpARMInvertFlags:
v.Fatalf("InvertFlags should never make it to codegen %v", v.LongString())
case ssa.OpClobber, ssa.OpClobberReg:
case ssa.OpClobber:
// TODO: implement for clobberdead experiment. Nop is ok for now.
default:
v.Fatalf("genValue not implemented: %s", v.LongString())

View File

@@ -18,10 +18,9 @@ func Init(arch *ssagen.ArchInfo) {
arch.PadFrame = padframe
arch.ZeroRange = zerorange
arch.Ginsnop = ginsnop
arch.Ginsnopdefer = ginsnop
arch.SSAMarkMoves = func(s *ssagen.State, b *ssa.Block) {}
arch.SSAGenValue = ssaGenValue
arch.SSAGenBlock = ssaGenBlock
arch.LoadRegResult = loadRegResult
arch.SpillArgReg = spillArgReg
}

View File

@@ -10,10 +10,10 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/arm64"
"internal/buildcfg"
"cmd/internal/objabi"
)
var darwin = buildcfg.GOOS == "darwin" || buildcfg.GOOS == "ios"
var darwin = objabi.GOOS == "darwin" || objabi.GOOS == "ios"
func padframe(frame int64) int64 {
// arm64 requires that the frame size (not counting saved FP&LR)

View File

@@ -10,7 +10,6 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/logopt"
"cmd/compile/internal/objw"
"cmd/compile/internal/ssa"
"cmd/compile/internal/ssagen"
"cmd/compile/internal/types"
@@ -162,18 +161,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.From.Type = obj.TYPE_REG
p.From.Reg = v.Args[0].Reg()
ssagen.AddrAuto(&p.To, v)
case ssa.OpArgIntReg, ssa.OpArgFloatReg:
// The assembler needs to wrap the entry safepoint/stack growth code with spill/unspill
// The loop only runs once.
for _, a := range v.Block.Func.RegArgs {
// Pass the spill/unspill information along to the assembler, offset by size of
// the saved LR slot.
addr := ssagen.SpillSlotAddr(a, arm64.REGSP, base.Ctxt.FixedFrameSize())
s.FuncInfo().AddSpill(
obj.RegSpill{Reg: a.Reg, Addr: addr, Unspill: loadByType(a.Type), Spill: storeByType(a.Type)})
}
v.Block.Func.RegArgs = nil
ssagen.CheckArgReg(v)
case ssa.OpARM64ADD,
ssa.OpARM64SUB,
ssa.OpARM64AND,
@@ -928,7 +915,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssa.OpARM64FCVTDS,
ssa.OpARM64REV,
ssa.OpARM64REVW,
ssa.OpARM64REV16,
ssa.OpARM64REV16W,
ssa.OpARM64RBIT,
ssa.OpARM64RBITW,
@@ -970,20 +956,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.SetFrom3Reg(r1)
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpARM64CSINC, ssa.OpARM64CSINV, ssa.OpARM64CSNEG:
p := s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_REG // assembler encodes conditional bits in Reg
p.From.Reg = condBits[ssa.Op(v.AuxInt)]
p.Reg = v.Args[0].Reg()
p.SetFrom3Reg(v.Args[1].Reg())
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpARM64CSETM:
p := s.Prog(arm64.ACSETM)
p.From.Type = obj.TYPE_REG // assembler encodes conditional bits in Reg
p.From.Reg = condBits[ssa.Op(v.AuxInt)]
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpARM64DUFFZERO:
// runtime.duffzero expects start address in R20
p := s.Prog(obj.ADUFFZERO)
@@ -1115,33 +1087,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
case ssa.OpARM64InvertFlags:
v.Fatalf("InvertFlags should never make it to codegen %v", v.LongString())
case ssa.OpClobber:
// MOVW $0xdeaddead, REGTMP
// MOVW REGTMP, (slot)
// MOVW REGTMP, 4(slot)
p := s.Prog(arm64.AMOVW)
p.From.Type = obj.TYPE_CONST
p.From.Offset = 0xdeaddead
p.To.Type = obj.TYPE_REG
p.To.Reg = arm64.REGTMP
p = s.Prog(arm64.AMOVW)
p.From.Type = obj.TYPE_REG
p.From.Reg = arm64.REGTMP
p.To.Type = obj.TYPE_MEM
p.To.Reg = arm64.REGSP
ssagen.AddAux(&p.To, v)
p = s.Prog(arm64.AMOVW)
p.From.Type = obj.TYPE_REG
p.From.Reg = arm64.REGTMP
p.To.Type = obj.TYPE_MEM
p.To.Reg = arm64.REGSP
ssagen.AddAux2(&p.To, v, v.AuxInt+4)
case ssa.OpClobberReg:
x := uint64(0xdeaddeaddeaddead)
p := s.Prog(arm64.AMOVD)
p.From.Type = obj.TYPE_CONST
p.From.Offset = int64(x)
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
// TODO: implement for clobberdead experiment. Nop is ok for now.
default:
v.Fatalf("genValue not implemented: %s", v.LongString())
}
@@ -1305,22 +1251,3 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
b.Fatalf("branch not implemented: %s", b.LongString())
}
}
func loadRegResult(s *ssagen.State, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
p := s.Prog(loadByType(t))
p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_AUTO
p.From.Sym = n.Linksym()
p.From.Offset = n.FrameOffset() + off
p.To.Type = obj.TYPE_REG
p.To.Reg = reg
return p
}
func spillArgReg(pp *objw.Progs, p *obj.Prog, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
p = pp.Append(p, storeByType(t), obj.TYPE_REG, reg, 0, obj.TYPE_MEM, 0, n.FrameOffset()+off)
p.To.Name = obj.NAME_PARAM
p.To.Sym = n.Linksym()
p.Pos = p.Pos.WithNotStmt()
return p
}

Some files were not shown because too many files have changed in this diff Show More