summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/transform.go
Commit message (Collapse)AuthorAgeFilesLines
* cmd/compile: remove GOEXPERIMENT=nounified frontendMatthew Dempsky2023-01-261-1085/+0
| | | | | | | | | | | | | | | This CL removes most of the code specific to the nounified frontend. To simplify review, it's a strict remove-only CL. Updates #57410. Change-Id: Ic3196570aa4286618c1d5e7fd0d0e6601a18195b Reviewed-on: https://go-review.googlesource.com/c/go/+/458620 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: add support for unsafe.{String,StringData,SliceData}cuiweixie2022-08-311-3/+3
| | | | | | | | | | | | | | For #53003 Change-Id: I13a761daca8b433b271a1feb711c103d9820772d Reviewed-on: https://go-review.googlesource.com/c/go/+/423774 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: hopehook <hopehook@golangcn.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix some typoscui fliter2022-08-161-1/+1
| | | | | | | | | | | | | Change-Id: I147622770587cff1551a0be189003666463f34e3 GitHub-Last-Rev: 71b5375983820445a331c46481a2a3a44fafb760 GitHub-Pull-Request: golang/go#54472 Reviewed-on: https://go-review.googlesource.com/c/go/+/424154 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* cmd/compile: avoid assignment conversion in append(a, b...)Keith Randall2022-08-081-5/+5
| | | | | | | | | | | | | | | | | | There's no need for a and b to match types. The typechecker already ensured that a and b are both slices with the same base type, or a and b are (possibly named) []byte and string. The optimization to treat append(b, make([], ...)) as a zeroing slice extension doesn't fire when there's a OCONVNOP wrapping the make. Fixes #53888 Change-Id: Ied871ed0bbb8e4a4b35d280c71acbab8103691bc Reviewed-on: https://go-review.googlesource.com/c/go/+/418475 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@golang.org>
* cmd/compile: fix bad order of evaluation for multi-value f()(g()) callsCuong Manh Le2022-05-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The compiler use to compile f()(g()) as: t1, t2 := g() f()(t1, t2) That violates the Go spec, since when "..., all function calls, ... are evaluated in lexical left-to-right order" This PR fixes the bug by compiling f()(g()) as: t0 := f() t1, t2 := g() t0(t1, t2) to make "f()" to be evaluated before "g()". Fixes #50672 Change-Id: I6a766f3dfc7347d10f8fa3a151f6a5ea79bcf818 Reviewed-on: https://go-review.googlesource.com/c/go/+/392834 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
* cmd/compile: change ir.NewCompLitExpr from Ntype to *types.TypeMatthew Dempsky2022-05-051-2/+1
| | | | | | | | | | | | | All callers were already using TypeNode to get an Ntype anyway, so just push the TypeNode constructor down into NewCompLitExpr. Prep refactoring for next CL to remove the Ntype field. Change-Id: I671935afca707aaab11d1c46e39902bd37a485ba Reviewed-on: https://go-review.googlesource.com/c/go/+/403840 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
* cmd/compile: fix transform of OEQ/ONE when one arg is a type paramKeith Randall2022-03-101-1/+1
| | | | | | | | | | | | | | | At this point in stenciling, we have shape types, not raw type parameters. The code was correct in the other part of this function. Update #51522 Change-Id: Ife495160a2be5f6af5400363c3efb68dda518b5f Reviewed-on: https://go-review.googlesource.com/c/go/+/391475 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* cmd/compile/internal/typecheck: remove unused -G=0 codeMatthew Dempsky2022-03-011-6/+0
| | | | | | | | | | | | | | | | | | The typechecking code for dealing with dot imports and redeclaration errors can be removed, as these will now always be caught by types2 instead. Even when running the typecheck on internally constructed IR, we'll never introduce new imports or redeclare identifiers. Also, Func.Shortname (and typecheck.addmethod) was only used by the -G=0 frontend. The new types2-based frontends directly associate methods with their receiver type during IR construction. Change-Id: I6578a448412141c87a0a53a6566639d9c00eeed7 Reviewed-on: https://go-review.googlesource.com/c/go/+/388537 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: add early a CONVIFACE normally created in the order phaseDan Scales2022-01-191-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | Most CONVIFACEs are created in the transform phase (or old typechecker, in -G=0 mode). But if the main result of a multi-value assignment (map, channel, or dot-type) must be converted to an interface during the assignment, that CONVIFACE is not created until (*orderState).as2ok in the order phase (because the AS2* ops and their sub-ops are so tightly intertwined). But we need to create the CONVIFACE during the stenciling/transform phase to enable dictionary lookups. So, in transformAssign(), if we are doing a special multi-value assignment involving a type-param-derived type, assign the results first to temps, so that we can manifest the CONVIFACE during the transform in assigning the first temp to lhs[0]. Added a test for both AS2RECV (channel receives) and AS2MAPR (maps). I don't think we can have a type assertion on a type-param-derived type. Fixes #50642 Change-Id: I4d079fc46c93d8494d7db4ea8234d91522edb02a Reviewed-on: https://go-review.googlesource.com/c/go/+/379054 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: fix conv of slice of user-define byte type to stringDan Scales2022-01-071-0/+25
| | | | | | | | | | | | | | | | | | | | | | | types2 allows the conversion of a slice of a user-defined byte type B (not builtin uint8 or byte) to string. But runtime.slicebytetostring requires a []byte argument, so add in a CONVNOP from []B to []byte if needed. Same for the conversion of a slice of user-defined rune types to string. I made the same change in the transformations of the old typechecker, so as to keep tcConv() and transformConv() in sync. That fixes the bug for -G=0 mode as well. Fixes #23536 Change-Id: Ic79364427f27489187f3f8015bdfbf0769a70d69 Reviewed-on: https://go-review.googlesource.com/c/go/+/376056 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/compile: fix position info for implicit nodes due to genericsDan Scales2021-11-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main fix is that we should call ir.SetPos() at the beginning of (*subster).node.edit function, since that is analogous to the ir.SetPos() at the beginning of typecheck.typecheck(). It ensures that transform functions can use base.Pos() with appropriate results, just like their corresponding tc*() functions do. A small fix is to make sure that the new nodes creates for dictionary references have the correct position based on the location of the function call. Another small fix is to the use of base.Pos when creating a new selector expression (including implicit XDOTs) for a method expression in buildClosure(). Also, I converted the final use of base.Pos in stencil.go to src.NoXPos, since the nodes created by AddImplicitDots will be checked for their type, but won't actually be used. I also needed to add an ir.SetPos() at the beginning of transformCall(), since transformCall() is called in the modify and dict passes, when we base.Pos is not being set for each node. This change fixes all the line numbering problems printed out from Alessandro's program, except for auto-generated functions (which I think are fine). Fixes #49523 Change-Id: I9836a497b7beba25ecafdde653a6c2036a3020d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/363835 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: revert most of CL 349169Keith Randall2021-10-251-14/+1
| | | | | | | | | | | | | | | | | | | | The method of using references to dictionaries to hold methods live during linker deadcode elimination wasn't working very well. I implemented a new scheme in the CL below this, so this CL strips out the old method. The new method has the added benefit of having 0 runtime overhead (unlike the stuff we're ripping out here, which does have a small overhead). Update #48047 Change-Id: I68ac57119792d53c58f1480f407de6ab2bb53211 Reviewed-on: https://go-review.googlesource.com/c/go/+/357836 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>
* cmd/compile: allow delaying of transformCompLit, new transformAddrDan Scales2021-10-081-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | | For this unusual case, where a constraint specifies exactly one type, we can have a COMPLIT expression with a type that is/has typeparams. Therefore, we add code to delay transformCompLit for generic functions. We also need to break out transformAddr (which corresponds to tcAddr), and added code for delaying it as well. Also, we now need to export generic functions containing untransformed OCOMPLIT and OKEY nodes, so added support for that in iexport.go/iimport.go. Untransformed OKEY nodes include an ir.Ident/ONONAME which we can now export. Had to adjust some code/asserts in transformCompLit(), since we may now be transforming an OCOMPLIT from an imported generic function (i.e. from a non-local package). Fixes #48537 Change-Id: I09e1b3bd08b4e013c0b098b8a25d082efa1fef51 Reviewed-on: https://go-review.googlesource.com/c/go/+/354354 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: keep methods on generic types from being deadcode eliminatedKeith Randall2021-09-271-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently make dictionaries contain a relocation pointing to methods that generic code might use, so that those methods are not deadcode eliminated. However, with inlining we can end up not using the dictionary, making the reference from the dictionary to the method no longer keep the method alive. Fix this by keeping the dictionary alive at generic interface call sites. It's a bit of overkill, as we only need to keep the dictionary statically alive. We don't actually need it dynamically alive, which is what KeepAlive does. But it works. It ends up generating a LEAQ + stack spill that aren't necessary, but that's pretty low overhead. To make this work, I needed to stop generating methods on shape types. We should do this anyway, as we shouldn't ever need them. But currently we do use them! issue44688.go has a test that only works because it calls a method on a shape type. I've disabled that test for now, will work on it in a subsequent CL. Fixes #48047 Change-Id: I78968868d6486c1745f51b8b43be0898931432a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/349169 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> Reviewed-by: Than McIntosh <thanm@google.com>
* cmd/compile: add required CONVIFACE nodes when translating OFUNCINST nodekorzhao2021-09-251-0/+6
| | | | | | | | | | | | | | | | | | | In CL 349614. we removed the early transformation code that was needed to create the implicit CONVIFACE nodes. Because the transformCall function is not called when translating OFUNCINST. So we add in needed CONVIFACE nodes via typecheckaste(). Fixes #48598 Change-Id: If9dc7040cdc38ef2e52fdbb08c840095651426f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/351856 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dan Scales <danscales@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
* cmd/compile: delay all transforms for generic funcs/methodsDan Scales2021-09-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | This change cleans up the code, by just delaying all transforms on generic function methods/functions until stenciling time. That way, we don't have extra code to decide whether to delay, or an extra value for the typecheck flag. We are already doing all possible transforms at stencil time anyway, so no changes to the stenciling code. transform.go includes a change for one case where we check for shape rather than tparam, now that we only apply transforms to stenciled functions, not generic functions. This change is to allow CONVIFACE node to be correctly inserted (needed for dictionaries), even with this strange code that doesn't add the CONVIFACE node if the concrete type is NOT huge... Change-Id: I5f1e71fab11b53385902074915b3ad85f8e753fa Reviewed-on: https://go-review.googlesource.com/c/go/+/350736 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
* cmd/compile: fix transform.AssignOp to deal with tricky caseDan Scales2021-09-201-3/+12
| | | | | | | | | | | | | | | | When going to dictionary formats derived from the function instantiations, I had broken out noder.Assignop() to deal specially with shape types, but didn't quite get the tricky case right. We still need to allow conversion between shape types, but if the destination is an interface, we need to use CONVIFACE rather than CONVNOP. Fixes #48453. Change-Id: I8c4b39c2e628172ac34f493f1dd682cbac1e55ae Reviewed-on: https://go-review.googlesource.com/c/go/+/350949 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: fixing writebarrier.go for -G=3wdvxdr2021-09-161-0/+4
| | | | | | | | | | | | | This is caused by some nodes didn't carry the real line number. Noder1 wraps these node with ir.ParenExpr. To fix this issue, wraps this node like what noder1 does. Change-Id: I212cad09b93b8bf1a7adfad416d229d15711918a Reviewed-on: https://go-review.googlesource.com/c/go/+/349769 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org>
* cmd/compile: remove unneeded early transforms, with dictionary changeDan Scales2021-09-151-61/+23
| | | | | | | | | | | | | Now that we are computing the dictionary format on the instantiated functions, we can remove the early transformation code that was needed to create the implicit CONVIFACE nodes in the generic function. Change-Id: I1695484e7d59bccbfb757994f3e40e84288759a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/349614 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: fix case where init info of OAS node is droppedDan Scales2021-09-091-0/+1
| | | | | | | | | | | | | | | | | | | | | When an OAS node is converted to an OSELRECV2 node in tcSelect(), the possible DCL node in the Init field was being dropped, since a completely new node was being created and the Init field was not set. I don't expect n.Init() to be set for the ORECV case, but the code now deals with that too. Fixed bug in both tcSelect() and transformSelect(). Fixes #48289 Change-Id: I09918a70f7cbaa4aa9a17546169f908a8787df15 Reviewed-on: https://go-review.googlesource.com/c/go/+/348569 Trust: Dan Scales <danscales@google.com> 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> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: add CONVIFACE nodes needed in generic code due to assignmentsDan Scales2021-09-071-0/+53
| | | | | | | | | | | | | | Added new function earlyTransformAssign() to add needed CONVIFACE nodes due to assignments in generic functions. Fixes #48049 Change-Id: I7cd9cee6ecf34ed2ef0743d1b17645b9f520fa00 Reviewed-on: https://go-review.googlesource.com/c/go/+/347914 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: fix handling of Defn field during stencilingDan Scales2021-08-311-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the Defn field of a name node is not an ONAME (for a closure variable), then it points to a body node of the same function/closure. Therefore, we should not attempt to substitute it at the time we are substituting the local variables. Instead, we remember a mapping from the Defn node to the nodes that reference it, and update the Defn fields of the copied name nodes at the time that we create the new copy of the Defn node. Added some comments to the Defn field of ir.Name. Moved the Defn (and Outer code, for consistency) from namelist() to localvar(), since Defn needs to updated for all local variables, not just those in a closure. Fixed case where .Defn was not being set properly in noder2 for type switches. Fixed another case where the Defn field had to be updated during transformSelect() because the Defn node was being completely changed to a new node. Fixed some spacing in typeswitch2.go Fixes #47676 Fixes #48016 Change-Id: Iae70dd76575f4a647c1db79e1eba9bbe44bfc226 Reviewed-on: https://go-review.googlesource.com/c/go/+/346290 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* cmd/compile: unexport Type.Width and Type.Align [generated]Matthew Dempsky2021-08-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [git-generate] cd src/cmd/compile/internal : Workaround rf issue with types2 tests. rm types2/*_test.go : Rewrite uses. First a type-safe rewrite, : then a second pass to fix unnecessary conversions. rf ' ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk { import "cmd/compile/internal/types" var t *types.Type t.Width -> t.Size() t.Align -> uint8(t.Alignment()) } ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk { import "cmd/compile/internal/types" var t *types.Type int64(uint8(t.Alignment())) -> t.Alignment() } ' : Rename fields to lower case. ( cd types rf ' mv Type.Width Type.width mv Type.Align Type.align ' ) : Revert types2 changes. git checkout HEAD^ types2 Change-Id: I42091faece104c4ef619d9d4d50514fd48c8f029 Reviewed-on: https://go-review.googlesource.com/c/go/+/345480 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: fixes for non-constant Sizeof/Alignof/OffsetofDan Scales2021-08-231-1/+4
| | | | | | | | | | | | | | | | | | Includes Robert's suggested fix in validate.go to not fail on non-constant alignof/offsetof/sizeof calls. Further changes to wait on transforming these calls until stenciling time, when we can call EvalConst() to evaluate them once all the relevant types are known. Added a bunch of new tests for non-constant Sizeof/Alignof/Offsetof. Fixes #47716 Change-Id: I469af888eb9ce3a853124d919eda753971009b3e Reviewed-on: https://go-review.googlesource.com/c/go/+/344250 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
* cmd/compile: always remove receiver type from instantiated method valuesKeith Randall2021-08-231-5/+1
| | | | | | | | | | | | | | | | | | | If a type T has a method foo, then var t T var i interface{} = t.foo The type of foo is a method type, but the type of t.foo should be a standard function type. Make sure we always do that conversion. Fixes #47775 Change-Id: I464ec792196b050aba1914e070a4ede34bfd0bfa Reviewed-on: https://go-review.googlesource.com/c/go/+/343881 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
* [dev.typeparams] cmd/compile: call transformArgs before early typecheckaste ↵Dan Scales2021-08-091-62/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | in noder In the cases where we do an early call to typecheckaste() in noder to expose CONVIFACE nodes, we need a preceding call to transformArgs(). This is needed to allow typecheckaste() to run correctly, in the case of f(g()), where g has multiple return values. I also cleaned up the code a bit and commented the code in Call(), and we do the call to typecheckaste() in several more cases. In stencil.go:stencil(), I moved the transformCall earlier for the OCALLMETH/ODOTMETH case, just as I did in my previous CL for OCALL/OFUNCINST. By doing this, transformArgs no longer needs to deal with the extra dictionary args. Therefore, I was able to simply transformArgs() to look like typecheckargs() again, and make use of RewriteMultiValue directly. Updates #47514 Change-Id: I49eb82ac05707e50c2e2fb03e39458a70491d406 Reviewed-on: https://go-review.googlesource.com/c/go/+/340531 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* [dev.typeparams] cmd/compile: implement generic type switchesKeith Randall2021-08-091-0/+4
| | | | | | | | | | | | Add a new dynamicType node, which is used as a case entry when the type being switched to is generic. Change-Id: Ice77c6f224b8fdd3ff574fdf4a8ea5f6c7ddbe75 Reviewed-on: https://go-review.googlesource.com/c/go/+/339429 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
* [dev.typeparams] cmd/compile: do transformCall with non-shape type of callDan Scales2021-08-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | Do the transformCall using the original types2-derived type of the call (in particular, the types of the params as non-shapes). Currently, since we were using the param types of the instantiation, we might add in interface conversions to an interface with shapes in the one case of a full-instantiated generic call. So, we do the transformCall() before installing the shaped-based instantiation. transformCall() works correctly even in the case of OCALL/FUNCINST. Fixed two related bugs: - Fixed case where we still were not correctly substituting the types for a function instantiation. - The type substituter needs to copy field flags while substituting in tstruct. Change-Id: I14e960737d6840a75846ede480e6650534ba3af3 Reviewed-on: https://go-review.googlesource.com/c/go/+/340259 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* [dev.typeparams] cmd/compile: handle meth expressions on typeparamsDan Scales2021-07-291-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite a method expression such as 'T.String' (where T is type param and String is part of its type bound Stringer) as: func(rcvr T, other params...) { return Stringer(rcvr).String(other params...) } New function buildClosure2 to create the needed closure. The conversion Stringer(rcvr) uses the dictionary in the outer function. For a method expression like 'Test[T].finish' (where finish is a method of Test[T]), we can already deal with this in buildClosure(). We just need fix transformDot() to allow the method lookup to fail, since shapes have no methods on them. That's fine, since for any instantiated receiver type, we always use the methods on the generic base type. Also removed the OMETHEXPR case in the main switch of node(), which isn't needed any (and removes one more potential unshapify). Also, fixed two small bugs with handling closures that have generic params or generic captured variables. Need to set the instInfo for the closure in the subst struct when descending into a closure during genericSubst() and was missing initializing the startItabConv and gfInfo fields in the closure info. Change-Id: I6dadedd1378477936a27c9c544c014cd2083cfb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/338129 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* [dev.typeparams] transformDot() should set Selection and tc flag for added ODOTsDan Scales2021-07-241-0/+18
| | | | | | | | | | | Fixes -G=3 issue with issue44688.go. Change-Id: Ie98c0cbd48683dedd115332043f14c8f3160f46c Reviewed-on: https://go-review.googlesource.com/c/go/+/337029 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
* [dev.typeparams] Add CONVIFACE nodes in noder2, where possibleDan Scales2021-07-231-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | Changes to add CONVIFACE nodes where possible in noder2, even when the args are typeparams. The transformation to insert a CONVIFACE node can usually happen when there an obvious assignment/conversion to an interface type from a non-interface type. So, we now do this tranformation for: - direct conversions to an interface type - function arguments that are implicitly converted to an interface based on the parameter types. - EQ/NE comparison of an interface and a non-interface With this change, we can remove some special case checks for CONVIFACE nodes after transformation in node(), and instead just have the one check in the CONVIFACE check. Change-Id: I7cf2ef920aebf9e5553210aeaf19f344e128ca62 Reviewed-on: https://go-review.googlesource.com/c/go/+/336992 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* [dev.typeparams] Fix problem with 14.goDan Scales2021-07-221-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | Removed a case in transformCall() where we were setting a type on n, which isn't needed, since noder2 already set the type of n. More importantly, we are losing information, since the type of the results may be a shape type, but the actual type of call is the known type from types2, which may be a concrete type (in this case Zero[MyInt]). That concrete type will then be used correctly if the concrete result is converted to an interface. If we are inlining the call to Zero[MyInt], we need to add an implicit CONVNOP operation, since we are going to use the result variable directly, which has a shape type. So, add an implicit CONVNOP to remember that the known type is the concrete type. Also cleaned up 14.go a bit, so it is more understandable. Renamed type T to AnyInt, since T is used elsewhere as a type parameter. Reformatted Zero function and added a comment. Change-Id: Id917a2e054e0bbae9bd302232853fa8741d49b64 Reviewed-on: https://go-review.googlesource.com/c/go/+/336430 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* [dev.typeparams] cmd/compile: report mismatch between types because of ↵Dan Scales2021-07-091-1/+9
| | | | | | | | | | | | | | | | | | | //go:notinheap types2 currently ignores pragmas, so it does not catch a conversion error when converting a pointer to a type which is NOT marked notinheap to a pointer to a convertible type, but which is marked notinheap. So, we specifically check for this error in transformConv() and report it during noder2. Change-Id: I6e9c9ee29f53fa5e490c1ac8306e2191db59eeb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/333369 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
* [dev.typeparams] cmd/compile: remove ir.CallUseMatthew Dempsky2021-07-031-1/+0
| | | | | | | | | | | | 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>
* [dev.typeparams] cmd/compile: port fix for issue46725 to transform.goDan Scales2021-06-281-1/+13
| | | | | | | | | | | Allow fix for issue46725 to work for -G=3 mode. Change-Id: Id522fbc2278cf878cb3f95b3205a2122c164ae29 Reviewed-on: https://go-review.googlesource.com/c/go/+/331470 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>
* [dev.typeparams] cmd/compile: port CL 330838 for -G=3Cuong Manh Le2021-06-281-1/+1
| | | | | | | | | | | | So next CL can move MethodValueWrapper to walk, since when walk is now the only place which uses this function. Change-Id: Id3be359bfc38efb022451cb7f9e53c2868fe7e12 Reviewed-on: https://go-review.googlesource.com/c/go/+/330840 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>
* [dev.typeparams] cmd/compile: rename OCALLPART to OMETHVALUECuong Manh Le2021-06-271-2/+2
| | | | | | | | | | | | | 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>
* [dev.typeparams] cmd/compile: rewrite method calls during typecheckCuong Manh Le2021-06-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [dev.typeparams] cmd/compile: allow conversions from type parameter to interfaceKeith Randall2021-06-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | When converting from a type param to an interface, allow it if the type bound implements that interface. Query: some conversions go through this path, some use another path? The test does var i interface{foo()int} = x but i := (interface{foo()int})(x) works at tip. Change-Id: I84d497e5228c0e1d1c9d76ffebaedce09dc45e8e Reviewed-on: https://go-review.googlesource.com/c/go/+/325409 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>
* [dev.typeparams] cmd/compile: point StructKeyExpr at the types.FieldMatthew Dempsky2021-06-041-26/+17
| | | | | | | | | | | | | | | | | | | | When constructing struct literals, importers need a way to specify precisely which field to initialize without worrying about visibility or those fields being blank. (A blank field doesn't actually need to be initialized, but the expression needs to be evaluated still, and with the right order-of-operations.) This CL changes StructKeyExpr's Field field to point directly to the corresponding types.Field, rather than merely holding a copy of its Sym and Offset. This is akin to past changes to add SelectorExpr.Selection. Change-Id: I95b72b1788f73206fcebc22b456cf6b1186db6a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/325031 Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* [dev.typeparams] cmd/compile: add dictionary argument to generic functionsKeith Randall2021-06-021-23/+49
| | | | | | | | | | | | | | | | | | | | | | | | | When converting from a generic function to a concrete implementation, add a dictionary argument to the generic function (both an actual argument at each callsite, and a formal argument of each implementation). The dictionary argument comes before all other arguments (including any receiver). The dictionary argument is checked for validity, but is otherwise unused. Subsequent CLs will start using the dictionary for, e.g., converting a value of generic type to interface{}. Import/export required adding support for LINKSYMOFFSET, which is used by the dictionary checking code. Change-Id: I16a7a8d23c7bd6a897e0da87c69f273be9103bd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/323272 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>
* cmd/compile: implement unsafe.Add and unsafe.SliceMatthew Dempsky2021-05-021-2/+2
| | | | | | | | | | | | | 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>
* cmd/compile: break out transformations of tcCompLit into transformCompLitDan Scales2021-04-081-6/+160
| | | | | | | | | | | | | | | | | | | | | | | | Create transformCompLit, which does the transformations done by tcCompLit without the typechecking. This removes the final use of the old typechecker in the noder2 pass. Other changes: - Used the transformCompLit in stringstorunelit(), which creates an OCOMPLIT that needs transformation as well. - Fixed one place in transformIndex where we were still using typecheck.AssignConv, when we should be using its equivalent noder.assignconvfn. The go/test tests always run with -G=3, and I also tested that the "go test" tests continue to run correctly with -G=3. Change-Id: I4a976534ab7311cf2a5f43841026dbf7401e62b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/308529 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: get rid of Fields in types.Interface, use allMethods in ↵Dan Scales2021-04-051-1/+1
| | | | | | | | | | | | | | | | | | types.Type instead Confusingly, the set of all methods of an interface is currently set in Fields field of types.Interface. This is true, even though there is already an allMethods field (and AllMethods method) of types.Type. Change so the set of all methods of an interface are stored in Type.allMethods, and Interface.Fields is removed. Update the comments for Methods and AllMethods. Change-Id: Ibc32bafae86831cba62606b079a855690612c759 Reviewed-on: https://go-review.googlesource.com/c/go/+/307209 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* cmd/compile: deal with call.Use correctly for noder2, allow inlining of ↵Dan Scales2021-03-311-5/+0
| | | | | | | | | | | | | | | | | | | | | | | stenciled functions The setting of n.Use for a call node in transformCall() (and previously in Call()), was not corrrect, since it was trying to use the number of results of the call, rather than whether the call result was actually used. We are already setting n.Use to ir.CallUseStmt if the call node is directly a statement, so we just need to initialize n.Use to ir.CallExprStmt in Call(), which will get changed to ir.CallUseStmt at the statement level if it's used as a statement. Enable inlining of stenciled functions (just disabled for testing, easier debugging). The above n.Use fix was required for the inlining to work for two cases. Change-Id: Ie4ef6cd53fd4b20a4f3be31e629280909a545b7d Reviewed-on: https://go-review.googlesource.com/c/go/+/305913 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: fix various small bugs related to type listsDan Scales2021-03-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix various small bugs related to delaying transformations due to type params. Most of these relate to the need to delay a transformation when an argument of an expression or statement has a type parameter that has a structural constraint. The structural constraint implies the operation should work, but the transformation can't happen until the actual value of the type parameter is known. - delay transformations for send statements and return statements if any args/values have type params. - similarly, delay transformation of a call where the function arg has type parameters. This is mainly important for the case where the function arg is a pure type parameter, but has a structural constraint that requires it to be a function. Move the setting of n.Use to transformCall(), since we may not know how many return values there are until then, if the function arg is a type parameter. - set the type of unary expressions from the type2 type (as we do with most other expressions), since that works better with expressions with type params. - deal with these delayed transformations in subster.node() and convert the CALL checks to a switch statement. - make sure ir.CurFunc is set properly during stenciling, including closures (needed for transforming return statements during stenciling). New test file typelist.go with tests for these cases. Change-Id: I1b82f949d8cec47d906429209e846f4ebc8ec85e Reviewed-on: https://go-review.googlesource.com/c/go/+/305729 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: add transform functions for OXDOT and builtinsDan Scales2021-03-251-3/+290
| | | | | | | | | | | | | | | | | | | | | | | | Pull out the tranformation part of the typechecking functions for: - selector expressions (OXDOT) - calls to builtin functions (which go through the typechecker loop twice, once for the call and once for each different kind of builtin). Some of the transformation functions create new nodes that should have the same type as the original node. For consistency, now each of the transformation functions requires that the node passed in has its type and typecheck flag set. If the transformation function replaces or adds new nodes, it will set the type and typecheck flag for those new nodes. As usual, passes all the gotests, even with -G=3 enabled. Change-Id: Ic48b0ce5f58425f4a358afa78315bfc7c28066c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/304729 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: create/use noder2 transform functions for more node typesDan Scales2021-03-251-0/+523
Pull out the transformation part of the typechecking functions for: - assignment statements - return statements - send statements - select statements - type conversions - normal function/method calls - index operations The transform functions are like the original typechecking functions, but with all code removed related to: - Detecting compile-time errors (already done by types2) - Setting the actual type of existing nodes (already done based on info from types2) - Dealing with untyped constants Moved all the transformation functions to a separate file, transform.go. Continuing with the same pattern, we delay transforming a node if it has any type params in its args, marking it with a typecheck flag of 3, and do the actual transformation during stenciling. Assignment statements are tricky, since their transformation must be delayed if any of the left or right-hands-sides are delayed. Still to do are: - selector expressions (OXDOT) - composite literal expressions (OCOMPLIT) - builtin function calls Change-Id: Ie608cadbbc69b40db0067a5536cf707dd974aacc Reviewed-on: https://go-review.googlesource.com/c/go/+/304049 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>