aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/func.go
AgeCommit message (Collapse)Author
2021-07-07[dev.typeparams] cmd/compile: rename PartialCallType -> MethodValueTypeCuong Manh Le
CL 330837 rename OCALLPART to OMETHVALUE, so do the same thing for PartialCallType for consistency. Change-Id: Id40eb35bbcee7719acfb41fce0e2b968879f9fef Reviewed-on: https://go-review.googlesource.com/c/go/+/332769 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-07-04[dev.typeparams] cmd/compile: set Func.ClosureCalled in escape analysisMatthew Dempsky
The Func.ClosureCalled flag is an optimization used by escape analysis to detect closures that were directly called, so we know we have visibility of the result flows. It's not needed by any other phases of the compiler, so we might as well calculate it within escape analysis too. This saves some trouble during IR construction and trying to maintain the ClosureCalled flag through inlining and copying. Passes toolstash -cmp. Change-Id: Ic53cecb7ac439745c0dfba2cd202b9cc40f1e47c Reviewed-on: https://go-review.googlesource.com/c/go/+/332691 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-07-03[dev.typeparams] cmd/compile: remove ir.CallUseMatthew Dempsky
Unneeded after the previous CL changed inlining to leave OINLCALL nodes in place. Change-Id: I9af09a86a21caa51a1117b3de17d7312dd702600 Reviewed-on: https://go-review.googlesource.com/c/go/+/332650 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Trust: Matthew Dempsky <mdempsky@google.com>
2021-06-30[dev.typeparams] all: merge master (4711bf3) into dev.typeparamsMatthew Dempsky
Conflicts: - src/cmd/compile/internal/walk/builtin.go On dev.typeparams, CL 330194 changed OCHECKNIL to not require manual SetTypecheck(1) anymore; while on master, CL 331070 got rid of the OCHECKNIL altogether by moving the check into the runtime support functions. - src/internal/buildcfg/exp.go On master, CL 331109 refactored the logic for parsing the GOEXPERIMENT string, so that it could be more easily reused by cmd/go; while on dev.typeparams, several CLs tweaked the regabi experiment defaults. Merge List: + 2021-06-30 4711bf30e5 doc/go1.17: linkify "language changes" in the runtime section + 2021-06-30 ed56ea73e8 path/filepath: deflake TestEvalSymlinksAboveRoot on darwin + 2021-06-30 c080d0323b cmd/dist: pass -Wno-unknown-warning-option in swig_callback_lto + 2021-06-30 7d0e9e6e74 image/gif: fix typo in the comment (io.ReadByte -> io.ByteReader) + 2021-06-30 0fa3265fe1 os: change example to avoid deprecated function + 2021-06-30 d19a53338f image: add Uniform.RGBA64At and Rectangle.RGBA64At + 2021-06-30 c45e800e0c crypto/x509: don't fail on optional auth key id fields + 2021-06-29 f9d50953b9 net: fix failure of TestCVE202133195 + 2021-06-29 e294b8a49e doc/go1.17: fix typo "MacOS" -> "macOS" + 2021-06-29 3463852b76 math/big: fix typo of comment (`BytesScanner` to `ByteScanner`) + 2021-06-29 fd4b587da3 cmd/compile: suppress details error for invalid variadic argument type + 2021-06-29 e2e05af6e1 cmd/internal/obj/arm64: fix an encoding error of CMPW instruction + 2021-06-28 4bb0847b08 cmd/compile,runtime: change unsafe.Slice((*T)(nil), 0) to return []T(nil) + 2021-06-28 1519271a93 spec: change unsafe.Slice((*T)(nil), 0) to return []T(nil) + 2021-06-28 5385e2386b runtime/internal/atomic: drop Cas64 pointer indirection in comments + 2021-06-28 956c81bfe6 cmd/go: add GOEXPERIMENT to `go env` output + 2021-06-28 a1d27269d6 cmd/go: prep for 'go env' refactoring + 2021-06-28 901510ed4e cmd/link/internal/ld: skip the windows ASLR test when CGO_ENABLED=0 + 2021-06-28 361159c055 cmd/cgo: fix 'see gmp.go' to 'see doc.go' + 2021-06-27 c95464f0ea internal/buildcfg: refactor GOEXPERIMENT parsing code somewhat + 2021-06-25 ed01ceaf48 runtime/race: use race build tag on syso_test.go + 2021-06-25 d1916e5e84 go/types: in TestCheck/issues.src, import regexp/syntax instead of cmd/compile/internal/syntax + 2021-06-25 5160896c69 go/types: in TestStdlib, import from source instead of export data + 2021-06-25 d01bc571f7 runtime: make ncgocall a global counter Change-Id: I1ce4a3b3ff7c824c67ad66dd27d9d5f1d25c0023
2021-06-28cmd/compile,runtime: change unsafe.Slice((*T)(nil), 0) to return []T(nil)Matthew Dempsky
This CL removes the unconditional OCHECKNIL check added in walkUnsafeSlice by instead passing it as a pointer to runtime.unsafeslice, and hiding the check behind a `len == 0` check. While here, this CL also implements checkptr functionality for unsafe.Slice and disallows use of unsafe.Slice with //go:notinheap types. Updates #46742. Change-Id: I743a445ac124304a4d7322a7fe089c4a21b9a655 Reviewed-on: https://go-review.googlesource.com/c/go/+/331070 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-06-28[dev.typeparams] cmd/compile: move MethodValueWrapper to walkCuong Manh Le
walk is the only pass that use the function, so un-export it, too. Change-Id: I32ec64d1c15fda7bb54bd8efa528ed32c102876d Reviewed-on: https://go-review.googlesource.com/c/go/+/330841 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-27[dev.typeparams] cmd/compile: rename OCALLPART to OMETHVALUECuong Manh Le
Go spec call them "method values", not "partial calls". Note that we use "OMETHVALUE" (as opposed to "OMETHODVALUE") to be consistent with "OMETHEXPR". Change-Id: I1efd985d4b567a1b4b20aeb603eb82db579edbd5 Reviewed-on: https://go-review.googlesource.com/c/go/+/330837 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-26[dev.typeparams] cmd/compile: rewrite method calls during typecheckCuong Manh Le
CL 330671 move rewriting method call to method expression to escape analysis. This CL move the rewriting up further, into typecheck. It helps simplify the code for dowstream passes, as they now only have to deal with OCALLFUNC. There're two notes: - For -G=3, we can't rewrite d.M() where d is an instantiated receiver in transformCall, but let irgen.stencil to rewrite it. - Escape analysis still have to check for rewriting method calls, as the devirtualization pass can still generate OCALLMETH. Does not pass toolstash, since when the export data now contains method expression calls instead of method calls. Change-Id: I77465ef04d50dc4efedddca7eb55b3fc9483db0e Reviewed-on: https://go-review.googlesource.com/c/go/+/330831 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-25[dev.typeparams] cmd/compile: rewrite method call into method expression ↵Cuong Manh Le
during escape analysis CL 330331 extended escape analysis to analyze method expression calls the same as normal method calls. We can now simply desugar method calls into function calls in escape analysis. To do this, two things must be changed: - Folding the rewrite method call to method expression call into an export function in typecheck package, so others can re-use it. - walkCall now have to call usemethod for method expression calls. (It seems to me this is a bug in current tip, because if one write (*rtype).Method(typ, i) in package "reflect", then the function won't be marked with AttrReflectMethod) Passes toolstash -cmp. Change-Id: I4745ab6110b417c7fd32949cc799811a882cd2ec Reviewed-on: https://go-review.googlesource.com/c/go/+/330671 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-23[dev.typeparams] cmd/compile: desugar ORECOVER into ORECOVERFPMatthew Dempsky
Currently ORECOVER is a single operation that both (1) calculates the (logical) caller frame pointer and (2) calls runtime.gorecover. This is normally fine, but it's inconvenient for regabi, which wants to wrap "defer recover()" into "defer func() { recover() }" and needs (1) and (2) to happen at different times. The current solution is to apply walkRecover early to split it into the two steps, but calling it during order is a minor layering violation. It works well today because the order and walk phases are closely related anyway and walkRecover is relatively simple, but it won't work for go/defer wrapping earlier into the frontend. This CL adds a new, lower-level ORECOVERFP primitive, which represents just part (2); and OGETCALLER{PC,SP} primitives, which provide a way to compute (1) in the frontend too. OGETCALLERPC isn't needed/used today, but it seems worth including for completeness. Maybe it will be useful at some point for intrinsifying runtime.getcaller{pc,sp}, like we already do for runtime.getg. Change-Id: Iaa8ae51e09306c45c147b6759a5b7c24dcc317ca Reviewed-on: https://go-review.googlesource.com/c/go/+/330192 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-06-12[dev.typeparams] cmd/compile: refactor closure constructionMatthew Dempsky
typecheck.tcClosure is complicated with many code flows because all of its callers setup the closure funcs in slightly different ways. E.g., it's non-obvious who's responsible for setting the underlying func's Sym or adding it to target.Decls, or how to write new code that constructs a closure without interfering with existing code. This CL refactors everything to use three common functions in package ir: NewClosureFunc (which handle creating the Func, Name, and ClosureExpr and wiring them together), NameClosure (which generates and assigns its unique Sym), and UseClosure (which handles adding the Func to target.Decls). Most IR builders can actually name the closure right away, but the legacy noder+typecheck path may not yet know the name of the enclosing function. In particular, for methods declared with aliased receiver parameters, we need to wait until after typechecking top-level declarations to know the method's true name. So they're left anonymous until typecheck. UseClosure does relatively little work today, but it serves as a useful spot to check that the code setting up closures got it right. It may also eventually serve as an optimization point for early lifting of trivial closures, which may or may not ultimately be beneficial. Change-Id: I7da1e93c70d268f575b12d6aaeb2336eb910a6f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/327051 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-06-07[dev.typeparams] all: merge master (8212707) into dev.typeparamsMatthew Dempsky
Conflicts: - src/go/internal/gcimporter/iimport.go CL 325429 and CL 319931 made unrelated changes to adjacent lines Merge List: + 2021-06-07 8212707871 crypto/elliptic: update P-521 docs to say it's constant-time + 2021-06-07 7406180012 fmt: split package documentation into more sections + 2021-06-07 e3176bbc3e crypto/tls: fix typo in Config.NextProtos docs + 2021-06-05 e1fa26026d spec: improve wording consistency by eliminating "specifier" + 2021-06-05 f490134126 spec: improve wording by choosing an official term "keyword" + 2021-06-05 e3cb381704 go/internal/gcimporter: don't waste CPU copying bytes in `io.ReadAll` + 2021-06-05 9d669ed47a misc/cgo/errors: use expected column numbers + 2021-06-04 95939e8de7 cmd/compile/internal/abi: fix typo in comment + 2021-06-04 831f9376d8 net/http: fix ResponseWriter.ReadFrom with short reads + 2021-06-04 3a9d906edc os: avoid finalizer race in windows process object + 2021-06-04 105c5b50e0 os: terminate windows processes via handle directly + 2021-06-04 79cd407f88 syscall: regenerate zsyscall_windows.go + 2021-06-04 c6b6211229 doc/go1.17: document testing changes for Go 1.17 + 2021-06-04 0214440075 syscall: do not pass console handles to PROC_THREAD_ATTRIBUTE_HANDLE_LIST on Windows 7 + 2021-06-04 962d5c997a cmd/compile,go/types: restrict use of unsafe.{Add,Slice} to go1.17 or newer + 2021-06-04 b29b123e07 cmd/compile: remove spurious ir.Dump + 2021-06-03 6d98301114 cmd/link: use correct alignment in PE DWARF sections + 2021-06-03 e0d029f758 runtime: avoid gp.lockedm race in exitsyscall0 + 2021-06-02 dd7ba3ba2c net: don't rely on system hosts in TestCVE202133195 + 2021-06-02 4f572d7076 io/fs: minor corrections to Sub docs + 2021-06-02 e11d14225c doc/go1.17: remove runtime section + 2021-06-02 6e189afd3e doc/go1.17: mention SYS_WAIT6/WEXITED on NetBSD + 2021-06-02 ff9f5fb859 cmd/link: recognize clang linker error in testCGOLTO + 2021-06-02 1c6a2ea2ea doc/go1.17: document time changes for Go1.17 + 2021-06-02 d743e67e06 doc/go1.17: document flag changes for Go 1.17 + 2021-06-02 dc8f87b749 runtime/internal/sys: generate //go:build lines in gengoos.go + 2021-06-02 84c0e5d47f cmd/link: move issue 43830 tests out of TestScript + 2021-06-02 cae68700cc runtime: fix formatting + 2021-06-01 567ee865f6 cmd/go: add declaration to cgo_lto_issue43830 test + 2021-06-01 24e9707cbf cmd/link, cmd/cgo: support -flto in CFLAGS Change-Id: I9ef88e7de0f8b1841ed9604b613b41672df67e71
2021-06-04[dev.typeparams] cmd/compile: allow inlining in instantiated functionsDan Scales
Change markType to scan generic types and methods, so that inlineable functions inside generic functions/methods will be properly marked for export, which means inlining inside instantiated functions will work correctly. Also, fix handling of closures for instantiated functions. Some code needs to be adjusted, since instantiated functions/methods are compiled as if in the package of the source generic function/type, rather than in the local package. When we create the closure struct, we want to make sure that the .F field has the same package as the other fields for the closure variables. Also, we need to disable a check in tcCompLit() when being done for an instantiated function, since fields of the closure struct will be from the source package, not the local package. Re-enabled part of the orderedmapsimp test that was disabled because of these issues. Change-Id: Ic4dba8917da0a36b17c0bdb69d6d6edfdf14104a Reviewed-on: https://go-review.googlesource.com/c/go/+/324331 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-06-04cmd/compile,go/types: restrict use of unsafe.{Add,Slice} to go1.17 or newerMatthew Dempsky
This CL updates cmd/compile (including types2) and go/types to report errors about using unsafe.Add and unsafe.Slice when language compatibility is set to Go 1.16 or older. Fixes #46525. Change-Id: I1bfe025a672d9f4b929f443064ad1effd38d0363 Reviewed-on: https://go-review.googlesource.com/c/go/+/324369 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
2021-05-26[dev.typeparams] cmd/compile: simplify inlining variadic callsMatthew Dempsky
We already have and use FixVariadicCall to normalize non-dotted calls to variadic functions elsewhere in the compiler to simplify rewriting of function calls. This CL updates inl.go to use it too. A couple tests need to be updated to (correctly) expect diagnostics about "... argument" instead of a slice literal. This is because inl.go previously failed to set Implicit on the slice literal node. Change-Id: I76bd79b95ae1f16e3b26ff7e9e1c468f538fd1f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/323009 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-05-07cmd/compile: improving the documentation of various fields and functionsDan Scales
This is only changes to comments, so should be fine to go into 1.17. Change-Id: I01e28dc76b03fb3ca846d976f8ac84bc2acb2ea2 Reviewed-on: https://go-review.googlesource.com/c/go/+/318009 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-05-02cmd/compile: implement unsafe.Add and unsafe.SliceMatthew Dempsky
Updates #19367. Updates #40481. Change-Id: Iabd2afdd0d520e5d68fd9e6dedd013335a4b3886 Reviewed-on: https://go-review.googlesource.com/c/go/+/312214 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-04-10cmd/compile: include typecheck information in export/importKeith Randall
Include type information on exported function bodies, so that the importer does not have to re-typecheck the body. This involves including type information in the encoded output, as well as avoiding some of the opcode rewriting and other changes that the old exporter did assuming there would be a re-typechecking pass. This CL could be considered a cleanup, but is more important than that because it is an enabling change for generics. Without this CL, we'd have to upgrade the current typechecker to understand generics. With this CL, the current typechecker can mostly go away in favor of the types2 typechecker. For now, inlining of functions that contain closures is turned off. We will hopefully resolve this before freeze. Object files are only 0.07% bigger. Change-Id: I85c9da09f66bfdc910dc3e26abb2613a1831634d Reviewed-on: https://go-review.googlesource.com/c/go/+/301291 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-04-06cmd/compile/internal/typecheck: call tcConv directlycui
Change-Id: I9f71acfa93c47cff620b006918872ecd90bbebe9 GitHub-Last-Rev: 2fed2e23054d75f7a743f9c5a6e5574a545e3080 GitHub-Pull-Request: golang/go#45366 Reviewed-on: https://go-review.googlesource.com/c/go/+/307109 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-15cmd/compile: fix outdated commentEthan Hur
variable xtop has removed and refactored after go 1.16, but there are comments referring xtop. It may mislead new contributors to be confused. Change-Id: Id79c747d8daef14049b29e70a4ecd34054a28a5e GitHub-Last-Rev: 94b55208862fdc9fa0de39aacf2c9ef9987cef56 GitHub-Pull-Request: golang/go#44995 Reviewed-on: https://go-review.googlesource.com/c/go/+/301629 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Keith Randall <khr@golang.org>
2021-03-09cmd/compile: detect duplicate importing earlierKeith Randall
Change-Id: I05ba944e189a884b727e40a9526d212612c3e923 Reviewed-on: https://go-review.googlesource.com/c/go/+/299770 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-02-19cmd/compile: fix check to avoid creating new closure function when ↵Dan Scales
typechecking inline body By default, when typechecking a closure, tcClosure() creates a new closure function. This should really be done separate from typechecking. For now, we explicitly avoid creating a new closure function when typechecking an inline body (in ImportedBody). However, the heuristic for determining when we are typechecking an inline body was not correct for double nested closures in an inline body, since CurFunc will then be the inner closure, which has a body. So, use a simple global variable to indicate when we typechecking an inline body. The global variable is fine (just like ir.CurFunc), since the front-end runs serially. Fixes #44325 Change-Id: If2829fe1ebb195a7b1a240192b57fe6f04d1a36b Reviewed-on: https://go-review.googlesource.com/c/go/+/294211 TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com>
2021-01-25[dev.regabi] cmd/compile: backport changes from dev.typeparams (9456804)Matthew Dempsky
This CL backports a bunch of changes that landed on dev.typeparams, but are not dependent on types2 or generics. By backporting, we reduce the divergence between development branches, hopefully improving test coverage and reducing risk of merge conflicts. Updates #43866. Change-Id: I382510855c9b5fac52b17066e44a00bd07fe86f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/286172 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-01-20[dev.regabi] cmd/compile: exporting, importing, and inlining functions with ↵Dan Scales
OCLOSURE I have exporting, importing, and inlining of functions with closures working in all cases (issue #28727). all.bash runs successfully without errors. Approach: - Write out the Func type, Dcls, ClosureVars, and Body when exporting an OCLOSURE. - When importing an OCLOSURE, read in the type, dcls, closure vars, and body, and then do roughly equivalent code to (*noder).funcLit - During inlining of a closure within inlined function, create new nodes for all params and local variables (including closure variables), so they can have a new Curfn and some other field values. Must substitute not only on the Nbody of the closure, but also the Type, Cvars, and Dcl fields. Fixes #28727 Change-Id: I4da1e2567c3fa31a5121afbe82dc4e5ee32b3170 Reviewed-on: https://go-review.googlesource.com/c/go/+/283112 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com>
2021-01-18[dev.regabi] cmd/compile: convert OPANIC argument to interface{} during ↵Matthew Dempsky
typecheck Currently, typecheck leaves arguments to OPANIC as their original type. This CL changes it to insert implicit OCONVIFACE operations to convert arguments to `interface{}` like how any other function call would be handled. No immediate benefits, other than getting to remove a tiny bit of special-case logic in order.go's handling of OPANICs. Instead, the generic code path for handling OCONVIFACE is used, if necessary. Longer term, this should be marginally helpful for #43753, as it reduces the number of cases where we need values to be addressable for runtime calls. However, this does require adding some hacks to appease existing tests: 1. We need yet another kludge in inline budgeting, to ensure that reflect.flag.mustBe stays inlinable for cmd/compile/internal/test's TestIntendedInlining. 2. Since the OCONVIFACE expressions are now being introduced during typecheck, they're now visible to escape analysis. So expressions like "panic(1)" are now seen as "panic(interface{}(1))", and escape analysis warns that the "interface{}(1)" escapes to the heap. These have always escaped to heap, just now we're accurately reporting about it. (Also, unfortunately fmt.go hides implicit conversions by default in diagnostics messages, so instead of reporting "interface{}(1) escapes to heap", it actually reports "1 escapes to heap", which is confusing. However, this confusing messaging also isn't new.) Change-Id: Icedf60e1d2e464e219441b8d1233a313770272af Reviewed-on: https://go-review.googlesource.com/c/go/+/284412 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Trust: Matthew Dempsky <mdempsky@google.com>
2021-01-16[dev.regabi] cmd/compile, runtime: fix up comments/error messages from ↵Dan Scales
recent renames Went in a semi-automated way through the clearest renames of functions, and updated comments and error messages where it made sense. Change-Id: Ied8e152b562b705da7f52f715991a77dab60da35 Reviewed-on: https://go-review.googlesource.com/c/go/+/284216 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-12[dev.regabi] cmd/compile: remove Func.ClosureTypeMatthew Dempsky
The closure's type always matches the corresponding function's type, so just use one instance rather than carrying around two. Simplifies construction of closures, rewriting them during walk, and shrinks memory usage. Passes toolstash -cmp. Change-Id: I83b8b8f435b02ab25a30fb7aa15d5ec7ad97189d Reviewed-on: https://go-review.googlesource.com/c/go/+/283152 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-01-12[dev.regabi] cmd/compile: call NeedFuncSym in InitLSymMatthew Dempsky
InitLSym is where we're now generating ABI wrappers, so it seems as good a place as any to make sure we're generating the degenerate closure wrappers for declared functions and methods. Change-Id: I097f34bbcee65dee87a97f9ed6f3f38e4cf2e2b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/283312 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-01-10[dev.regabi] cmd/compile: use ClosureVars for method value wrappersMatthew Dempsky
Similar to with regular closures, we can change method value wrappers to use ClosureVars and allow SSA construction to take care of wiring it up appropriately. Change-Id: I05c0b1bcec4e24305324755df35b7bc5b8a6ce7a Reviewed-on: https://go-review.googlesource.com/c/go/+/281353 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-01-05[dev.regabi] cmd/compile: remove CaptureVarsMatthew Dempsky
Capture analysis is now part of escape analysis. Passes toolstash -cmp. Change-Id: Ifcd3ecc342074c590e0db1ff0646dfa1ea2ff57b Reviewed-on: https://go-review.googlesource.com/c/go/+/281543 Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-05[dev.regabi] cmd/compile: add Name.Canonical and move ByvalMatthew Dempsky
There's a bunch of code that wants to map closure variables back to their original name, so add a single Name.Canonical method that they can all use. Also, move the Byval flag from being stored on individual closure variables to being stored on the canonical variable. Passes toolstash -cmp. Change-Id: Ia3ef81af5a15783d09f04b4e274ce33df94518e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/281541 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-05[dev.regabi] cmd/compile: simplify CaptureVarsMatthew Dempsky
CaptureVars is responsible for deciding whether free variables should be captured by value or by reference, but currently it also makes up for some of the short-comings of the frontend symbol resolution / type-checking algorithms. These are really separate responsibilities, so move the latter into type-checking where it fits better. Passes toolstash -cmp. Change-Id: Iffbd53e83846a9ca9dfb54b597450b8543252850 Reviewed-on: https://go-review.googlesource.com/c/go/+/281534 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-04[dev.regabi] cmd/compile: remove Name.Class_ accessorsMatthew Dempsky
These aren't part of the Node interface anymore, so no need to keep them around. Passes toolstash -cmp. [git-generate] cd src/cmd/compile/internal/ir : Fix one off case that causes trouble for rf. sed -i -e 's/n.SetClass(ir.PAUTO)/n.Class_ = ir.PAUTO/' ../ssa/export_test.go pkgs=$(go list . ../...) rf ' ex '"$(echo $pkgs)"' { var n *Name var c Class n.Class() -> n.Class_ n.SetClass(c) -> n.Class_ = c } rm Name.Class rm Name.SetClass mv Name.Class_ Name.Class ' Change-Id: Ifb304bf4691a8c455456aabd8aa77178d4a49500 Reviewed-on: https://go-review.googlesource.com/c/go/+/281294 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-02[dev.regabi] cmd/compile: remove Nodes.Set [generated]Matthew Dempsky
Just "=". It's cleaner. Passes toolstash -cmp. [git-generate] cd src/cmd/compile/internal/ir pkgs=$(go list . ../...) rf ' ex '"$(echo $pkgs)"' { var l Nodes var p *Nodes p.Set(l) -> *p = l } ex '"$(echo $pkgs)"' { var n InitNode var l Nodes *n.PtrInit() = l -> n.SetInit(l) } rm Nodes.Set ' Change-Id: Ic97219792243667146a02776553942ae1189ff7d Reviewed-on: https://go-review.googlesource.com/c/go/+/281002 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-01[dev.regabi] cmd/compile: refactor redundant type conversion [generated]Cuong Manh Le
Passes toolstash -cmp. [git-generate] cd src/cmd/compile rf ' ex . '"$(printf '%s\n' ./internal/* | paste -sd' ')"' { type T interface{} var t T strict t t.(T) -> t } ' cd internal/ir go generate Change-Id: I492d50390e724a7216c3cd8b49d4aaf7d0c335da Reviewed-on: https://go-review.googlesource.com/c/go/+/280716 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-01-01[dev.regabi] cmd/compile: remove Func.ClosureEnterMatthew Dempsky
We can easily compute this on demand. Passes toolstash -cmp. Change-Id: I433d8adb2b1615ae05b2764e69904369a59542c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/280994 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-01-01[dev.regabi] cmd/compile: reshuffle type-checking code [generated]Matthew Dempsky
This commit splits up typecheck.Package and moves the code elsewhere. The type-checking code is moved into noder, so that it can eventually be interleaved with the noding process. The non-type-checking code is moved back into package gc, so that it can be incorporated into appropriate compiler backend phases. While here, deadcode removal is moved into its own package. Passes toolstash -cmp. [git-generate] cd src/cmd/compile/internal/typecheck : Split into two functions. sed -i -e '/Phase 6/i}\n\nfunc postTypecheck() {' typecheck.go rf ' # Export needed identifiers. mv deadcode Deadcode mv loadsys InitRuntime mv declareUniverse DeclareUniverse mv dirtyAddrtaken DirtyAddrtaken mv computeAddrtaken ComputeAddrtaken mv incrementalAddrtaken IncrementalAddrtaken # Move into new package. mv Deadcode deadcodeslice deadcodeexpr deadcode.go mv deadcode.go cmd/compile/internal/deadcode # Move top-level type-checking code into noder. # Move DeclVars there too, now that nothing else uses it. mv DeclVars Package noder.go mv noder.go cmd/compile/internal/noder # Move non-type-checking code back into gc. mv postTypecheck main.go mv main.go cmd/compile/internal/gc ' cd ../deadcode rf ' # Destutter names. mv Deadcode Func mv deadcodeslice stmts mv deadcodeexpr expr ' cd ../noder rf ' # Move functions up, next to their related code. mv noder.go:/func Package/-1,$ \ noder.go:/makeSrcPosBase translates/-1 mv noder.go:/func DeclVars/-3,$ \ noder.go:/constState tracks/-1 ' cd ../gc rf ' # Inline postTypecheck code back into gc.Main. mv main.go:/func postTypecheck/+0,/AllImportedBodies/+1 \ main.go:/Build init task/-1 rm postTypecheck ' Change-Id: Ie5e992ece4a42204cce6aa98dd6eb52112d098c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/280974 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-01[dev.regabi] cmd/compile: remove idempotent Name() calls [generated]Matthew Dempsky
[git-generate] cd src/cmd/compile/internal/ir pkgs=$(grep -l -w Name ../*/*.go | xargs dirname | sort -u | grep -v '/ir$') rf ' ex . '"$(echo $pkgs)"' { var n *Name n.Name() -> n } ' Change-Id: I6bfce6417a6dba833d2f652ae212a32c11bc5ef6 Reviewed-on: https://go-review.googlesource.com/c/go/+/280972 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-29[dev.regabi] cmd/compile: move new addrtaken bit back to the old nameKeith Randall
Change-Id: I2732aefe95a21c23d73a907d5596fcb1626d6dd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/275697 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2020-12-29[dev.regabi] cmd/compile: remove original addrtaken bitKeith Randall
Switch the source of truth to the new addrtaken bit. Remove the old one. Change-Id: Ie53679ab14cfcd34b55e912e7ecb962a22db7db3 Reviewed-on: https://go-review.googlesource.com/c/go/+/275696 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2020-12-29[dev.regabi] cmd/compile: separate out address taken computation from ↵Keith Randall
typechecker This CL computes a second parallel addrtaken bit that we check against the old way of doing it. A subsequent CL will rip out the typechecker code and just use the new way. Change-Id: I62b7342c44f694144844695386f80088bbd40bf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/275695 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2020-12-29[dev.regabi] cmd/compile: simplify ir.Func somewhatMatthew Dempsky
Two simplifications: 1. Statements (including ODCLFUNC) don't have types, and the Func.Nname already has a type. There's no need for a second one. However, there is a lot of code that expects to be able to call Func.Type, so leave a forwarding method, like with Sym and Linksym. 2. Inline and remove ir.NewFuncNameAt. It doesn't really save any code, and it's only used a handful of places. Passes toolstash -cmp. Change-Id: I51acaa341897dae0fcdf2fa576a10174a2ae4d1e Reviewed-on: https://go-review.googlesource.com/c/go/+/280648 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-29[dev.regabi] cmd/compile: use Ntype where possibleMatthew Dempsky
For nodes that are always a type expression, we can use Ntype instead of Node. Passes toolstash -cmp. Change-Id: I28f9fa235015ab48d0da06b78b30c49d74c64e3a Reviewed-on: https://go-review.googlesource.com/c/go/+/280642 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-29[dev.regabi] cmd/compile: merge {Selector,CallPart,Method}ExprMatthew Dempsky
These three expression nodes all represent the same syntax, and so they're represented the same within types2. And also they're not handled that meaningfully differently throughout the rest of the compiler to merit unique representations. Method expressions are somewhat unique today that they're very frequently turned into plain function names. But eventually that can be handled by a post-typecheck desugaring phase that reduces the number of redundant AST forms. Passes toolstash -cmp. Change-Id: I20df91bbd0d885c1f18ec67feb61ae1558670719 Reviewed-on: https://go-review.googlesource.com/c/go/+/280636 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2020-12-28[dev.regabi] cmd/compile: remove Declare in makepartialcallMatthew Dempsky
This is the only remaining late call to Declare. By changing it to use Temp, we'll be able to move the legacy lexical scoping logic by moving it to noder and iimport. Passes toolstash -cmp. Change-Id: Id7cf7a08e3138e50816f515fef3088785a10aaf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/280513 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-28[dev.regabi] cmd/compile: remove unnecessary Name.Sym callMatthew Dempsky
Since the introduction of ir.BasicLit, we no longer create Names without Syms. Passes toolstash -cmp. Change-Id: I82de3fd65455e3756ff56e52febb512c0a2128f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/280512 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-28[dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETHMatthew Dempsky
ODOTMETH is unique among SelectorExpr expressions, in that Sel gets mangled so that it no longer has the original identifier that was selected (e.g., just "Foo"), but instead the qualified symbol name for the selected method (e.g., "pkg.Type.Foo"). This is rarely useful, and instead results in a lot of compiler code needing to worry about undoing this change. This CL changes ODOTMETH to leave the original symbol in place. The handful of code locations where the mangled symbol name is actually wanted are updated to use ir.MethodExprName(n).Sym() or (equivalently) ir.MethodExprName(n).Func.Sym() instead. Historically, the compiler backend has mistakenly used types.Syms where it should have used ir.Name/ir.Funcs. And this change in particular may risk breaking something, as the SelectorExpr.Sel will no longer point at a symbol that uniquely identifies the called method. However, I expect CL 280294 (desugar OCALLMETH into OCALLFUNC) to have substantially reduced this risk, as ODOTMETH expressions are now replaced entirely earlier in the compiler. Passes toolstash -cmp. Change-Id: If3c9c3b7df78ea969f135840574cf89e1d263876 Reviewed-on: https://go-review.googlesource.com/c/go/+/280436 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-23[dev.regabi] cmd/compile: prefer types constructors over typecheckMatthew Dempsky
Similar to the earlier mkbuiltin cleanup, there's a bunch of code that calls typecheck.NewFuncType or typecheck.NewStructType, which can now just call types.NewSignature and types.NewStruct, respectively. Passes toolstash -cmp. Change-Id: Ie6e09f1a7efef84b9a2bb5daa7087a6879979668 Reviewed-on: https://go-review.googlesource.com/c/go/+/279955 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-23[dev.regabi] cmd/compile: split up typecheck1 [generated]Russ Cox
typecheck1 is the largest non-machine-generated function in the compiler. weighing in at 1,747 lines. Since we are destroying the git blame history anyway, now is a good time to split each different case into its own function, making future work on this function more manageable. [git-generate] cd src/cmd/compile/internal/typecheck rf ' # Remove tracing print from typecheck1 - the one in typecheck is fine. # Removing it lets us remove the named result. # That lets all the cut-out functions not have named results. rm typecheck.go:/^func typecheck1/+0,/^func typecheck1/+4 sub typecheck.go:/^func typecheck1/+/\(res ir\.Node\)/ ir.Node mv typecheckselect tcSelect mv typecheckswitch tcSwitch mv typecheckrange tcRange mv typecheckfunc tcFunc mv checkdefergo tcGoDefer mv typecheckclosure tcClosure mv check typecheck mv typecheckcomplit tcCompLit mv typecheckas tcAssign mv typecheckas2 tcAssignList mv typecheckpartialcall tcCallPart mv typecheckExprSwitch tcSwitchExpr mv typecheckTypeSwitch tcSwitchType mv typecheck1:/^\tcase ir.ORETURN:/+2,/^\tcase /-2 tcReturn add typecheck.go:/^func tcReturn/-0 \ // tcReturn typechecks an ORETURN node. mv typecheck1:/^\tcase ir.OIF:/+2,/^\tcase /-2 tcIf add typecheck.go:/^func tcIf/-0 \ // tcIf typechecks an OIF node. mv typecheck1:/^\tcase ir.OFOR,/+2,/^\tcase /-2 tcFor add typecheck.go:/^func tcFor/-0 \ // tcFor typechecks an OFOR node. mv typecheck1:/^\tcase ir.OSPTR:/+2,/^\tcase /-2 tcSPtr add typecheck.go:/^func tcSPtr/-0 \ // tcSPtr typechecks an OSPTR node. mv typecheck1:/^\tcase ir.OITAB:/+2,/^\tcase /-2 tcITab add typecheck.go:/^func tcITab/-0 \ // tcITab typechecks an OITAB node. mv typecheck1:/^\tcase ir.ORECOVER:/+2,/^\tcase /-2 tcRecover add typecheck.go:/^func tcRecover/-0 \ // tcRecover typechecks an ORECOVER node. mv typecheck1:/^\tcase ir.OPANIC:/+2,/^\tcase /-2 tcPanic add typecheck.go:/^func tcPanic/-0 \ // tcPanic typechecks an OPANIC node. mv typecheck1:/^\tcase ir.OPRINT,/+2,/^\tcase /-2 tcPrint add typecheck.go:/^func tcPrint/-0 \ // tcPrint typechecks an OPRINT or OPRINTN node. mv typecheck1:/^\tcase ir.ONEW:/+2,/^\tcase /-2 tcNew add typecheck.go:/^func tcNew/-0 \ // tcNew typechecks an ONEW node. mv typecheck1:/^\tcase ir.OMAKE:/+2,/^\tcase /-2 tcMake add typecheck.go:/^func tcMake/-0 \ // tcMake typechecks an OMAKE node. mv typecheck1:/^\tcase ir.OCONV:/+2,/^\tcase /-2 tcConv add typecheck.go:/^func tcConv/-0 \ // tcConv typechecks an OCONV node. mv typecheck1:/^\tcase ir.OCOPY:/+2,/^\tcase /-2 tcCopy add typecheck.go:/^func tcCopy/-0 \ // tcCopy typechecks an OCOPY node. mv typecheck1:/^\tcase ir.OAPPEND:/+2,/^\tcase /-2 tcAppend add typecheck.go:/^func tcAppend/-0 \ // tcAppend typechecks an OAPPEND node. mv typecheck1:/^\tcase ir.ODELETE:/+2,/^\tcase /-2 tcDelete add typecheck.go:/^func tcDelete/-0 \ // tcDelete typechecks an ODELETE node. mv typecheck1:/^\tcase ir.OCLOSE:/+2,/^\tcase /-2 tcClose add typecheck.go:/^func tcClose/-0 \ // tcClose typechecks an OCLOSE node. mv typecheck1:/^\tcase ir.OCOMPLEX:/+2,/^\tcase /-2 tcComplex add typecheck.go:/^func tcComplex/-0 \ // tcComplex typechecks an OCOMPLEX node. mv typecheck1:/^\tcase ir.OREAL,/+2,/^\tcase /-2 tcRealImag add typecheck.go:/^func tcRealImag/-0 \ // tcRealImag typechecks an OREAL or OIMAG node. mv typecheck1:/^\tcase ir.OCAP,/+2,/^\tcase /-2 tcLenCap add typecheck.go:/^func tcLenCap/-0 \ // tcLenCap typechecks an OLEN or OCAP node. mv typecheck1:/^\tcase ir.OCALL:/+2,/^\tcase /-2 tcCall add typecheck.go:/^func tcCall/-0 \ // tcCall typechecks an OCALL node. mv typecheck1:/^\tcase ir.OSLICE,/+2,/^\tcase /-3 tcSlice add typecheck.go:/^func tcSlice/-0 \ // tcSlice typechecks an OSLICE or OSLICE3 node. # move type assertion above comment mv typecheck1:/^\tcase ir.OMAKESLICECOPY:/+/n := n/-+ typecheck1:/^\tcase ir.OMAKESLICECOPY:/+0 mv typecheck1:/^\tcase ir.OMAKESLICECOPY:/+2,/^\tcase /-2 tcMakeSliceCopy add typecheck.go:/^func tcMakeSliceCopy/-0 \ // tcMakeSliceCopy typechecks an OMAKESLICECOPY node. # move type assertion above comment mv typecheck1:/^\tcase ir.OSLICEHEADER:/+/n := n/-+ typecheck1:/^\tcase ir.OSLICEHEADER:/+0 mv typecheck1:/^\tcase ir.OSLICEHEADER:/+2,/^\tcase /-2 tcSliceHeader add typecheck.go:/^func tcSliceHeader/-0 \ // tcSliceHeader typechecks an OSLICEHEADER node. mv typecheck1:/^\tcase ir.OSEND:/+2,/^\tcase /-2 tcSend add typecheck.go:/^func tcSend/-0 \ // tcSend typechecks an OSEND node. mv typecheck1:/^\tcase ir.ORECV:/+2,/^\tcase /-2 tcRecv add typecheck.go:/^func tcRecv/-0 \ // tcRecv typechecks an ORECV node. mv typecheck1:/^\tcase ir.OINDEX:/+2,/^\tcase /-2 tcIndex add typecheck.go:/^func tcIndex/-0 \ // tcIndex typechecks an OINDEX node. mv typecheck1:/^\tcase ir.ODOTTYPE:/+2,/^\tcase /-2 tcDotType add typecheck.go:/^func tcDotType/-0 \ // tcDotType typechecks an ODOTTYPE node. mv typecheck1:/^\tcase ir.OXDOT,/+2,/^\tcase /-2 tcDot add typecheck.go:/^func tcDot/-0 \ // tcDot typechecks an OXDOT or ODOT node. mv typecheck1:/^\tcase ir.OADDR:/+2,/^\tcase /-2 tcAddr add typecheck.go:/^func tcAddr/-0 \ // tcAddr typechecks an OADDR node. mv typecheck1:/^\tcase ir.OBITNOT,/+2,/^\tcase /-3 tcUnaryArith add typecheck.go:/^func tcUnaryArith/-0 \ // tcUnaryArith typechecks a unary arithmetic expression. mv typecheck1:/^\t\tir.OXOR:/+1,/^\tcase /-2 tcArith add typecheck.go:/^func tcArith/-0 \ // tcArith typechecks a binary arithmetic expression. mv typecheck1:/^\tcase ir.ODEREF:/+2,/^\tcase /-2 tcStar add typecheck.go:/^func tcStar/-0 \ // tcStar typechecks an ODEREF node, which may be an expression or a type. mv typecheck1:/^\tcase ir.OTFUNC:/+2,/^\tcase /-2 tcFuncType add typecheck.go:/^func tcFuncType/-0 \ // tcFuncType typechecks an OTFUNC node. mv typecheck1:/^\tcase ir.OTINTER:/+2,/^\tcase /-2 tcInterfaceType add typecheck.go:/^func tcInterfaceType/-0 \ // tcInterfaceType typechecks an OTINTER node. mv typecheck1:/^\tcase ir.OTSTRUCT:/+2,/^\tcase /-2 tcStructType add typecheck.go:/^func tcStructType/-0 \ // tcStructType typechecks an OTSTRUCT node. mv typecheck1:/^\tcase ir.OTCHAN:/+2,/^\tcase /-2 tcChanType add typecheck.go:/^func tcChanType/-0 \ // tcChanType typechecks an OTCHAN node. mv typecheck1:/^\tcase ir.OTMAP:/+2,/^\tcase /-2 tcMapType add typecheck.go:/^func tcMapType/-0 \ // tcMapType typechecks an OTMAP node. mv typecheck1:/^\tcase ir.OTARRAY:/+2,/^\tcase /-2 tcArrayType add typecheck.go:/^func tcArrayType/-0 \ // tcArrayType typechecks an OTARRAY node. mv typecheck1:/^\tcase ir.OTSLICE:/+2,/^\tcase /-2 tcSliceType add typecheck.go:/^func tcSliceType/-0 \ // tcSliceType typechecks an OTSLICE node. mv \ tcAssign \ tcAssignList \ tcFor \ tcGoDefer \ tcIf \ tcRange \ tcReturn \ tcSelect \ tcSend \ tcSwitch \ tcSwitchExpr \ tcSwitchType \ typeSet \ typeSetEntry \ typeSet.add \ stmt1.go mv stmt1.go stmt.go mv \ tcAddr \ tcArith \ tcArrayType \ tcChanType \ tcClosure \ tcCompLit \ tcConv \ tcDot \ tcDotType \ tcFuncType \ tcITab \ tcIndex \ tcInterfaceType \ tcLenCap \ tcMapType \ tcRecv \ tcSPtr \ tcSlice \ tcSliceHeader \ tcSliceType \ tcStar \ tcStructType \ tcUnaryArith \ expr.go mv \ tcClosure \ tcCallPart \ tcFunc \ tcCall \ tcAppend \ tcClose \ tcComplex \ tcCopy \ tcDelete \ tcMake \ tcMakeSliceCopy \ tcNew \ tcPanic \ tcPrint \ tcRealImag \ tcRecover \ func1.go mv func1.go func.go mv \ tcArrayType \ tcChanType \ tcFuncType \ tcInterfaceType \ tcMapType \ tcSliceType \ tcStructType \ type.go ' Change-Id: I0fb0a3039005bc1783575291daff1e6c306895ff Reviewed-on: https://go-review.googlesource.com/c/go/+/279429 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-23[dev.regabi] cmd/compile: split out package typecheck [generated]Russ Cox
This commit splits the typechecking logic into its own package, the first of a sequence of CLs to break package gc into more manageable units. [git-generate] cd src/cmd/compile/internal/gc rf ' # The binary import/export has to be part of typechecking, # because we load inlined function bodies lazily, but "exporter" # should not be. Move that out of bexport.go. mv exporter exporter.markObject exporter.markType export.go # Use the typechecking helpers, so that the calls left behind # in package gc do not need access to ctxExpr etc. ex { import "cmd/compile/internal/ir" # TODO(rsc): Should not be necessary. avoid TypecheckExpr avoid TypecheckStmt avoid TypecheckExprs avoid TypecheckStmts avoid TypecheckAssignExpr avoid TypecheckCallee var n ir.Node var ns []ir.Node typecheck(n, ctxExpr) -> TypecheckExpr(n) typecheck(n, ctxStmt) -> TypecheckStmt(n) typecheckslice(ns, ctxExpr) -> TypecheckExprs(ns) typecheckslice(ns, ctxStmt) -> TypecheckStmts(ns) typecheck(n, ctxExpr|ctxAssign) -> TypecheckAssignExpr(n) typecheck(n, ctxExpr|ctxCallee) -> TypecheckCallee(n) } # Move some typechecking API to typecheck. mv syslook LookupRuntime mv substArgTypes SubstArgTypes mv LookupRuntime SubstArgTypes syms.go mv conv Conv mv convnop ConvNop mv Conv ConvNop typecheck.go mv colasdefn AssignDefn mv colasname assignableName mv Target target.go mv initname autoexport exportsym dcl.go mv exportsym Export # Export API to be called from outside typecheck. # The ones with "Typecheck" prefixes will be renamed later to drop the prefix. mv adddot AddImplicitDots mv assignconv AssignConv mv expandmeth CalcMethods mv capturevarscomplete CaptureVarsComplete mv checkMapKeys CheckMapKeys mv checkreturn CheckReturn mv dclcontext DeclContext mv dclfunc DeclFunc mv declare Declare mv dotImportRefs DotImportRefs mv declImporter DeclImporter mv variter DeclVars mv defaultlit DefaultLit mv evalConst EvalConst mv expandInline ImportBody mv finishUniverse declareUniverse mv funcbody FinishFuncBody mv funchdr StartFuncBody mv indexconst IndexConst mv initTodo InitTodoFunc mv lookup Lookup mv resolve Resolve mv lookupN LookupNum mv nodAddr NodAddr mv nodAddrAt NodAddrAt mv nodnil NodNil mv origBoolConst OrigBool mv origConst OrigConst mv origIntConst OrigInt mv redeclare Redeclared mv tostruct NewStructType mv functype NewFuncType mv methodfunc NewMethodType mv structargs NewFuncParams mv temp Temp mv tempAt TempAt mv typecheckok TypecheckAllowed mv typecheck _typecheck # make room for typecheck pkg mv typecheckinl TypecheckImportedBody mv typecheckFunc TypecheckFunc mv iimport ReadImports mv iexport WriteExports mv sysfunc LookupRuntimeFunc mv sysvar LookupRuntimeVar # Move function constructors to typecheck. mv mkdotargslice MakeDotArgs mv fixVariadicCall FixVariadicCall mv closureType ClosureType mv partialCallType PartialCallType mv capturevars CaptureVars mv MakeDotArgs FixVariadicCall ClosureType PartialCallType CaptureVars typecheckclosure func.go mv autolabel AutoLabel mv AutoLabel syms.go mv Dlist dlist mv Symlink symlink mv \ AssignDefn assignableName \ AssignConv \ CaptureVarsComplete \ DeclContext \ DeclFunc \ DeclImporter \ DeclVars \ Declare \ DotImportRefs \ Export \ InitTodoFunc \ Lookup \ LookupNum \ LookupRuntimeFunc \ LookupRuntimeVar \ NewFuncParams \ NewName \ NodAddr \ NodAddrAt \ NodNil \ Redeclared \ StartFuncBody \ FinishFuncBody \ TypecheckImportedBody \ AddImplicitDots \ CalcMethods \ CheckFuncStack \ NewFuncType \ NewMethodType \ NewStructType \ TypecheckAllowed \ Temp \ TempAt \ adddot1 \ dotlist \ addmethod \ assignconvfn \ assignop \ autotmpname \ autoexport \ bexport.go \ checkdupfields \ checkembeddedtype \ closurename \ convertop \ declare_typegen \ decldepth \ dlist \ dotpath \ expand0 \ expand1 \ expandDecl \ fakeRecvField \ fnpkg \ funcStack \ funcStackEnt \ funcarg \ funcarg2 \ funcargs \ funcargs2 \ globClosgen \ ifacelookdot \ implements \ importalias \ importconst \ importfunc \ importobj \ importsym \ importtype \ importvar \ inimport \ initname \ isptrto \ loadsys \ lookdot0 \ lookdot1 \ makepartialcall \ okfor \ okforlen \ operandType \ slist \ symlink \ tointerface \ typeSet \ typeSet.add \ typeSetEntry \ typecheckExprSwitch \ typecheckTypeSwitch \ typecheckpartialcall \ typecheckrange \ typecheckrangeExpr \ typecheckselect \ typecheckswitch \ vargen \ builtin.go \ builtin_test.go \ const.go \ func.go \ iexport.go \ iimport.go \ mapfile_mmap.go \ syms.go \ target.go \ typecheck.go \ unsafe.go \ universe.go \ cmd/compile/internal/typecheck ' rm gen.go types.go types_acc.go sed -i '' 's/package gc/package typecheck/' mapfile_read.go mkbuiltin.go mv mapfile_read.go ../typecheck # not part of default build mv mkbuiltin.go ../typecheck # package main helper mv builtin ../typecheck cd ../typecheck mv dcl.go dcl1.go mv typecheck.go typecheck1.go mv universe.go universe1.go rf ' # Sweep some small files into larger ones. # "mv sym... file1.go file.go" (after the mv file1.go file.go above) # lets us insert sym... at the top of file.go. mv okfor okforeq universe1.go universe.go mv DeclContext vargen dcl1.go Temp TempAt autotmpname NewMethodType dcl.go mv InitTodoFunc inimport decldepth TypecheckAllowed typecheck1.go typecheck.go mv inl.go closure.go func.go mv range.go select.go swt.go stmt.go mv Lookup loadsys LookupRuntimeFunc LookupRuntimeVar syms.go mv unsafe.go const.go mv TypecheckAssignExpr AssignExpr mv TypecheckExpr Expr mv TypecheckStmt Stmt mv TypecheckExprs Exprs mv TypecheckStmts Stmts mv TypecheckCall Call mv TypecheckCallee Callee mv _typecheck check mv TypecheckFunc Func mv TypecheckFuncBody FuncBody mv TypecheckImports AllImportedBodies mv TypecheckImportedBody ImportedBody mv TypecheckInit Init mv TypecheckPackage Package ' rm gen.go go.go init.go main.go reflect.go Change-Id: Iea6a7aaf6407d690670ec58aeb36cc0b280f80b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/279236 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>