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>
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
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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
- 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>
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>
- 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>
- 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>
- 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>
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>
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>
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>
- 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>
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>
- 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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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
- 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
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
Pointer designations were not recognized nor supported.
Now we recognize them and report an error until type-checking
can handle them.
Change-Id: I0deed536aa03c06c3e9ec60a5c2e186e916b970f
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
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
- 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
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
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
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
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
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
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
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
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
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
For symmetry with embedding in structs and interfaces.
Fixed an incorrect error message print in the process.
Change-Id: I295685438a22971edc610e6c51cfefd286eaffba
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
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
Make sure that a generic signature is not generic anymore
after instantiation. Update various related comments.
Change-Id: I2ac81037e570dc3a96c138b85529f3d86030776a
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
Make sure receiver type and actual receiver argument
match in "pointer-ness" before attempting to infer
any receiver type parameters.
Change-Id: Ie28004ce42ecef46e348424140b8d0c65e37cdaa
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
Just store the error in the translator struct, rather than always
checking for an error and returning it up the stack.
Change-Id: I38ea2a282f61457eea123f852d9daf9337bcf9b8
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
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
TODO
- some channel errors are not reported for generic variables
- error messages should be better
Change-Id: Ie388d6811b605645ea092481eee3a850c7ceb77b
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
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
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
This enables the distinction between a method M(int) and an
embedded instantiated (parameterized) interface (M(int)).
Change-Id: I150d1b1cd53a2b14ddc0ad6336d84078fcb41ad6
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
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
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
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
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
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
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
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
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
Once a generic function is instantiated, it's not generic anymore.
Also: Added various additional test cases.
Change-Id: Ic2304b6c252cfdf41e526825dda64b8a77023d47
The new lazy method substitution code seems to work. The bug was
in the test, not in the implementation!
Change-Id: I39794743a01e9725d57f49ccd7c3751376cd01d6
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
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
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
Context-specific customization of parameterized interface methods of
type parameter bounds is missing; as a result some of linalg.go2 fails.
Change-Id: I3e749ee040d2b3ae8f73ae26680984bc1b4b79ef
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
- type instantiations checks parameter count
- better positions for error messages
- removed some (now) dead code
Change-Id: Icf70642bbfd4e45a7762b002ea94704dc3d56475
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
- 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
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
- 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
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
Also: disabled aggressive rewriting of methods upon type instantiation
(Need to first figure out what we really need to do.)
Change-Id: I6fba78d60963534ebfe130164058ac1fbed7e5a3
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
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
- implemented for comparisons for now
- can type-check generic min
- also: rebased on top of Go tip
Change-Id: Id35582a59c4cddcb2b4ae9c7d7154ef8e41580ab
Also: Recognize method expressions with parameterized receivers
and report an error for now (not implemented yet).
Change-Id: I96405b2b739d8e9fff6e9840347d3e78bfe8b6ec
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
... 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
- 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
- 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
- type parameters can be printed
- empty contracts can be printed
- contract constraints are missing (only started)
Change-Id: I787898203aeb064b0b2ac49a7b858313cee5f45b
Also: Added -h flag to test framework; setting -h causes a panic when
an error is reported (for debugging).
Change-Id: Ib45d4ef38769f2ecdd3ce53fa3aed9fd99ef6bc8
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
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
- 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
- move init and method parameter checks to resolve phase as well
- more consistent error messages
- more tests
Change-Id: I6cb147b35385541ca5d7d7e3f87159df84cced76
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
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.)
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.
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
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
112 changed files with 9560 additions and 18 deletions
// Copyright 2020 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 "./a"
type S[T any] struct {
F T
}
func NewS[T any](v T) S[T] {
return S[T]{F: v}
}
func main() {
v1 := a.NewS(0)
v2 := NewS(0)
if v1.F != v2.F {
panic(v1)
}
}
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.