summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/closure.go
Commit message (Collapse)AuthorAgeFilesLines
* [dev.regabi] cmd/compile: split out package walk [generated]Russ Cox2020-12-231-218/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [git-generate] cd src/cmd/compile/internal/gc rf ' # Late addition to package ir. mv closuredebugruntimecheck ClosureDebugRuntimeCheck mv hasemptycvars IsTrivialClosure mv ClosureDebugRuntimeCheck IsTrivialClosure func.go mv func.go cmd/compile/internal/ir # Late addition to package reflectdata. mv markTypeUsedInInterface MarkTypeUsedInInterface mv markUsedIfaceMethod MarkUsedIfaceMethod mv MarkTypeUsedInInterface MarkUsedIfaceMethod reflect.go mv reflect.go cmd/compile/internal/reflectdata # Late addition to package staticdata. mv litsym InitConst mv InitConst data.go mv data.go cmd/compile/internal/staticdata # Extract staticinit out of walk into its own package. mv InitEntry InitPlan InitSchedule InitSchedule.append InitSchedule.staticInit \ InitSchedule.tryStaticInit InitSchedule.staticcopy \ InitSchedule.staticassign InitSchedule.initplan InitSchedule.addvalue \ statuniqgen staticname stataddr anySideEffects getlit isvaluelit \ sched.go mv InitSchedule.initplans InitSchedule.Plans mv InitSchedule.inittemps InitSchedule.Temps mv InitSchedule.out InitSchedule.Out mv InitSchedule.staticInit InitSchedule.StaticInit mv InitSchedule.staticassign InitSchedule.StaticAssign mv InitSchedule Schedule mv InitPlan Plan mv InitEntry Entry mv anySideEffects AnySideEffects mv staticname StaticName mv stataddr StaticLoc mv sched.go cmd/compile/internal/staticinit # Export API and unexport non-API. mv transformclosure Closure mv walk Walk mv Order orderState mv swt.go switch.go mv racewalk.go race.go mv closure.go order.go range.go select.go switch.go race.go \ sinit.go subr.go walk.go \ cmd/compile/internal/walk ' : # Update format test. cd ../../ go install cmd/compile/... cmd/internal/archive go test -u || go test -u rm -rf ../../../pkg/darwin_amd64/cmd Change-Id: I11c7a45f74d4a9e963da15c080e1018caaa99c05 Reviewed-on: https://go-review.googlesource.com/c/go/+/279478 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: split out package noder [generated]Russ Cox2020-12-231-60/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [git-generate] cd src/cmd/compile/internal/gc rf ' mv ArhdrSize HeaderSize mv arsize ReadHeader mv formathdr FormatHeader mv HeaderSize ReadHeader FormatHeader archive.go mv archive.go cmd/internal/archive mv makePos main.go mv checkDotImports CheckDotImports mv parseFiles ParseFiles mv Pragma pragmas mv PragmaEmbed pragmaEmbed mv PragmaPos pragmaPos mv FuncPragmas funcPragmas mv TypePragmas typePragmas mv fakeRecv noder.funcLit renameinitgen renameinit oldname varEmbed noder.go mv isDriveLetter islocalname findpkg myheight importfile \ reservedimports isbadimport \ pkgnotused \ mkpackage clearImports \ CheckDotImports dotImports importDot \ importName \ import.go mv noder _noder mv import.go lex.go lex_test.go noder.go cmd/compile/internal/noder ' cd ../noder rf ' mv _noder noder ' Change-Id: Iac2b856f7b86143c666d818e4b7c5b261cf387d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/279473 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: split out package typecheck [generated]Russ Cox2020-12-231-298/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [dev.regabi] cmd/compile: move type size calculations into package types ↵Russ Cox2020-12-231-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [generated] To break up package gc, we need to put these calculations somewhere lower in the import graph, either an existing or new package. Package types already needs this code and is using hacks to get it without an import cycle. We can remove the hacks and set up for the new package gc by moving the code into package types itself. [git-generate] cd src/cmd/compile/internal/gc rf ' # Remove old import cycle hacks in gc. rm TypecheckInit:/types.Widthptr =/-0,/types.Dowidth =/+0 \ ../ssa/export_test.go:/types.Dowidth =/-+ ex { import "cmd/compile/internal/types" types.Widthptr -> Widthptr types.Dowidth -> dowidth } # Disable CalcSize in tests instead of base.Fatalf sub dowidth:/base.Fatalf\("dowidth without betypeinit"\)/ \ // Assume this is a test. \ return # Move size calculation into cmd/compile/internal/types mv Widthptr PtrSize mv Widthreg RegSize mv slicePtrOffset SlicePtrOffset mv sliceLenOffset SliceLenOffset mv sliceCapOffset SliceCapOffset mv sizeofSlice SliceSize mv sizeofString StringSize mv skipDowidthForTracing SkipSizeForTracing mv dowidth CalcSize mv checkwidth CheckSize mv widstruct calcStructOffset mv sizeCalculationDisabled CalcSizeDisabled mv defercheckwidth DeferCheckSize mv resumecheckwidth ResumeCheckSize mv typeptrdata PtrDataSize mv \ PtrSize RegSize SlicePtrOffset SkipSizeForTracing typePos align.go PtrDataSize \ size.go mv size.go cmd/compile/internal/types ' : # Remove old import cycle hacks in types. cd ../types rf ' ex { Widthptr -> PtrSize Dowidth -> CalcSize } rm Widthptr Dowidth ' Change-Id: Ib96cdc6bda2617235480c29392ea5cfb20f60cd8 Reviewed-on: https://go-review.googlesource.com/c/go/+/279234 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>
* [dev.regabi] cmd/compile: move helpers into package ir [generated]Russ Cox2020-12-231-26/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [git-generate] cd src/cmd/compile/internal/gc sed -i '' 's/TestBuiltin.*/& t.Skip("mkbuiltin needs fixing")/' builtin_test.go gofmt -w builtin_test.go rf ' # Inline a few little-used constructors to avoid bringing them. ex { import "cmd/compile/internal/base" import "cmd/compile/internal/ir" import "cmd/compile/internal/types" import "cmd/internal/src" var typ *types.Type var sym *types.Sym var str string symfield(sym, typ) -> ir.NewField(base.Pos, sym, nil, typ) anonfield(typ) -> ir.NewField(base.Pos, nil, nil, typ) namedfield(str, typ) -> ir.NewField(base.Pos, lookup(str), nil, typ) var cp *ir.CallPartExpr callpartMethod(cp) -> cp.Method var n ir.Node callpartMethod(n) -> n.(*ir.CallPartExpr).Method var ns []ir.Node liststmt(ns) -> ir.NewBlockStmt(src.NoXPos, ns) } rm symfield anonfield namedfield liststmt callpartMethod mv maxStackVarSize MaxStackVarSize mv maxImplicitStackVarSize MaxImplicitStackVarSize mv smallArrayBytes MaxSmallArraySize mv MaxStackVarSize cfg.go mv nodbool NewBool mv nodintconst NewInt mv nodstr NewString mv NewBool NewInt NewString const.go mv Mpprec ConstPrec mv bigFloatVal BigFloat mv doesoverflow ConstOverflow mv isGoConst IsConstNode mv smallintconst IsSmallIntConst mv isZero IsZero mv islvalue IsAssignable mv staticValue StaticValue mv samesafeexpr SameSafeExpr mv checkPtr ShouldCheckPtr mv isReflectHeaderDataField IsReflectHeaderDataField mv paramNnames ParamNames mv methodSym MethodSym mv methodSymSuffix MethodSymSuffix mv methodExprFunc MethodExprFunc mv methodExprName MethodExprName mv IsZero IsAssignable StaticValue staticValue1 reassigned \ IsIntrinsicCall \ SameSafeExpr ShouldCheckPtr IsReflectHeaderDataField \ ParamNames MethodSym MethodSymSuffix \ MethodExprName MethodExprFunc \ expr.go mv Curfn CurFunc mv funcsymname FuncSymName mv newFuncNameAt NewFuncNameAt mv setNodeNameFunc MarkFunc mv CurFunc FuncSymName NewFuncNameAt MarkFunc func.go mv isParamStackCopy IsParamStackCopy mv isParamHeapCopy IsParamHeapCopy mv nodfp RegFP mv IsParamStackCopy IsParamHeapCopy RegFP name.go mv hasUniquePos HasUniquePos mv setlineno SetPos mv initExpr InitExpr mv hasNamedResults HasNamedResults mv outervalue OuterValue mv HasNamedResults HasUniquePos SetPos InitExpr OuterValue EscNever node.go mv visitBottomUp VisitFuncsBottomUp # scc.go mv cfg.go \ NewBool NewInt NewString \ # parts of const.go ConstPrec BigFloat ConstOverflow IsConstNode IsSmallIntConst \ expr.go func.go name.go node.go scc.go \ cmd/compile/internal/ir ' Change-Id: I13402c5a2cedbf78d993a1eae2940718f23ac166 Reviewed-on: https://go-review.googlesource.com/c/go/+/279421 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>
* [dev.regabi] cmd/compile: simplify Nodes usage [generated]Russ Cox2020-12-231-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that Nodes is a slice, most of the methods can be removed in favor of direct slice operations, reducing the new API that must be understood to: Copy Take Append Prepend Format Passes buildall w/ toolstash -cmp. [git-generate] cd src/cmd/compile/internal/ir rf ' ex . ../gc { var ns Nodes var pns *Nodes var n, n2, n3 Node var i int var slice []Node ns.Len() -> len(ns) ns.Slice() -> ns ns.First() -> ns[0] ns.Second() -> ns[1] ns.Index(i) -> ns[i] ns.Addr(i) -> &ns[i] ns.SetIndex(i, n) -> ns[i] = n ns.SetFirst(n) -> ns[0] = n ns.SetSecond(n) -> ns[1] = n ns.Set1(n) -> ns = []Node{n} ns.Set2(n, n2) -> ns = []Node{n, n2} ns.Set3(n, n2, n3) -> ns = []Node{n, n2, n3} ns.Set1(n) -> ns = []Node{n} ns.Set2(n, n2) -> ns = []Node{n, n2} ns.Set3(n, n2, n3) -> ns = []Node{n, n2, n3} AsNodes(slice) -> Nodes(slice) ns.AppendNodes(pns) -> ns.Append(pns.Take()...) ns.MoveNodes(pns) -> ns = pns.Take() } rm \ Nodes.Len Nodes.Slice \ Nodes.First Nodes.Second Nodes.Index Nodes.Addr \ Nodes.SetIndex Nodes.SetFirst Nodes.SetSecond \ Nodes.Set1 Nodes.Set2 Nodes.Set3 \ AsNodes \ Nodes.AppendNodes Nodes.MoveNodes ' Change-Id: Iee86434ced52e67861c3fa71bdd6d994a8cba735 Reviewed-on: https://go-review.googlesource.com/c/go/+/277936 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>
* [dev.regabi] cmd/compile: remove Left, Right etc methods [generated]Russ Cox2020-12-231-28/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that the generic graph structure methods - Left, Right, and so on - have been removed from the Node interface, each implementation's uses can be replaced with direct field access, using more specific names, and the methods themselves can be deleted. Passes buildall w/ toolstash -cmp. [git-generate] cd src/cmd/compile/internal/ir rf ' mv Func.iota Func.Iota_ mv Name.fn Name.Func_ ' cd ../gc rf ' ex . ../ir { import "cmd/compile/internal/ir" import "cmd/compile/internal/types" var ns ir.Nodes var b bool var i64 int64 var n ir.Node var op ir.Op var sym *types.Sym var class ir.Class var decl *ir.Decl decl.Left() -> decl.X decl.SetLeft(n) -> decl.X = n var asl *ir.AssignListStmt asl.List() -> asl.Lhs asl.PtrList() -> &asl.Lhs asl.SetList(ns) -> asl.Lhs = ns asl.Rlist() -> asl.Rhs asl.PtrRlist() -> &asl.Rhs asl.SetRlist(ns) -> asl.Rhs = ns asl.Colas() -> asl.Def asl.SetColas(b) -> asl.Def = b var as *ir.AssignStmt as.Left() -> as.X as.SetLeft(n) -> as.X = n as.Right() -> as.Y as.SetRight(n) -> as.Y = n as.Colas() -> as.Def as.SetColas(b) -> as.Def = b var ao *ir.AssignOpStmt ao.Left() -> ao.X ao.SetLeft(n) -> ao.X = n ao.Right() -> ao.Y ao.SetRight(n) -> ao.Y = n ao.SubOp() -> ao.AsOp ao.SetSubOp(op) -> ao.AsOp = op ao.Implicit() -> ao.IncDec ao.SetImplicit(b) -> ao.IncDec = b var bl *ir.BlockStmt bl.List() -> bl.List_ bl.PtrList() -> &bl.List_ bl.SetList(ns) -> bl.List_ = ns var br *ir.BranchStmt br.Sym() -> br.Label br.SetSym(sym) -> br.Label = sym var cas *ir.CaseStmt cas.List() -> cas.List_ cas.PtrList() -> &cas.List_ cas.SetList(ns) -> cas.List_ = ns cas.Body() -> cas.Body_ cas.PtrBody() -> &cas.Body_ cas.SetBody(ns) -> cas.Body_ = ns cas.Rlist() -> cas.Vars cas.PtrRlist() -> &cas.Vars cas.SetRlist(ns) -> cas.Vars = ns cas.Left() -> cas.Comm cas.SetLeft(n) -> cas.Comm = n var fr *ir.ForStmt fr.Sym() -> fr.Label fr.SetSym(sym) -> fr.Label = sym fr.Left() -> fr.Cond fr.SetLeft(n) -> fr.Cond = n fr.Right() -> fr.Post fr.SetRight(n) -> fr.Post = n fr.Body() -> fr.Body_ fr.PtrBody() -> &fr.Body_ fr.SetBody(ns) -> fr.Body_ = ns fr.List() -> fr.Late fr.PtrList() -> &fr.Late fr.SetList(ns) -> fr.Late = ns fr.HasBreak() -> fr.HasBreak_ fr.SetHasBreak(b) -> fr.HasBreak_ = b var gs *ir.GoDeferStmt gs.Left() -> gs.Call gs.SetLeft(n) -> gs.Call = n var ifs *ir.IfStmt ifs.Left() -> ifs.Cond ifs.SetLeft(n) -> ifs.Cond = n ifs.Body() -> ifs.Body_ ifs.PtrBody() -> &ifs.Body_ ifs.SetBody(ns) -> ifs.Body_ = ns ifs.Rlist() -> ifs.Else ifs.PtrRlist() -> &ifs.Else ifs.SetRlist(ns) -> ifs.Else = ns ifs.Likely() -> ifs.Likely_ ifs.SetLikely(b) -> ifs.Likely_ = b var im *ir.InlineMarkStmt im.Offset() -> im.Index im.SetOffset(i64) -> im.Index = i64 var lab *ir.LabelStmt lab.Sym() -> lab.Label lab.SetSym(sym) -> lab.Label = sym var rng *ir.RangeStmt rng.Sym() -> rng.Label rng.SetSym(sym) -> rng.Label = sym rng.Right() -> rng.X rng.SetRight(n) -> rng.X = n rng.Body() -> rng.Body_ rng.PtrBody() -> &rng.Body_ rng.SetBody(ns) -> rng.Body_ = ns rng.List() -> rng.Vars rng.PtrList() -> &rng.Vars rng.SetList(ns) -> rng.Vars = ns rng.HasBreak() -> rng.HasBreak_ rng.SetHasBreak(b) -> rng.HasBreak_ = b rng.Colas() -> rng.Def rng.SetColas(b) -> rng.Def = b var ret *ir.ReturnStmt ret.List() -> ret.Results ret.PtrList() -> &ret.Results ret.SetList(ns) -> ret.Results = ns var sel *ir.SelectStmt sel.List() -> sel.Cases sel.PtrList() -> &sel.Cases sel.SetList(ns) -> sel.Cases = ns sel.Sym() -> sel.Label sel.SetSym(sym) -> sel.Label = sym sel.HasBreak() -> sel.HasBreak_ sel.SetHasBreak(b) -> sel.HasBreak_ = b sel.Body() -> sel.Compiled sel.PtrBody() -> &sel.Compiled sel.SetBody(ns) -> sel.Compiled = ns var send *ir.SendStmt send.Left() -> send.Chan send.SetLeft(n) -> send.Chan = n send.Right() -> send.Value send.SetRight(n) -> send.Value = n var sw *ir.SwitchStmt sw.Left() -> sw.Tag sw.SetLeft(n) -> sw.Tag = n sw.List() -> sw.Cases sw.PtrList() -> &sw.Cases sw.SetList(ns) -> sw.Cases = ns sw.Body() -> sw.Compiled sw.PtrBody() -> &sw.Compiled sw.SetBody(ns) -> sw.Compiled = ns sw.Sym() -> sw.Label sw.SetSym(sym) -> sw.Label = sym sw.HasBreak() -> sw.HasBreak_ sw.SetHasBreak(b) -> sw.HasBreak_ = b var tg *ir.TypeSwitchGuard tg.Left() -> tg.Tag tg.SetLeft(nil) -> tg.Tag = nil tg.SetLeft(n) -> tg.Tag = n.(*ir.Ident) tg.Right() -> tg.X tg.SetRight(n) -> tg.X = n var adds *ir.AddStringExpr adds.List() -> adds.List_ adds.PtrList() -> &adds.List_ adds.SetList(ns) -> adds.List_ = ns var addr *ir.AddrExpr addr.Left() -> addr.X addr.SetLeft(n) -> addr.X = n addr.Right() -> addr.Alloc addr.SetRight(n) -> addr.Alloc = n var bin *ir.BinaryExpr bin.Left() -> bin.X bin.SetLeft(n) -> bin.X = n bin.Right() -> bin.Y bin.SetRight(n) -> bin.Y = n var log *ir.LogicalExpr log.Left() -> log.X log.SetLeft(n) -> log.X = n log.Right() -> log.Y log.SetRight(n) -> log.Y = n var call *ir.CallExpr call.Left() -> call.X call.SetLeft(n) -> call.X = n call.List() -> call.Args call.PtrList() -> &call.Args call.SetList(ns) -> call.Args = ns call.Rlist() -> call.Rargs call.PtrRlist() -> &call.Rargs call.SetRlist(ns) -> call.Rargs = ns call.IsDDD() -> call.DDD call.SetIsDDD(b) -> call.DDD = b call.NoInline() -> call.NoInline_ call.SetNoInline(b) -> call.NoInline_ = b call.Body() -> call.Body_ call.PtrBody() -> &call.Body_ call.SetBody(ns) -> call.Body_ = ns var cp *ir.CallPartExpr cp.Func() -> cp.Func_ cp.Left() -> cp.X cp.SetLeft(n) -> cp.X = n cp.Sym() -> cp.Method.Sym var clo *ir.ClosureExpr clo.Func() -> clo.Func_ var cr *ir.ClosureReadExpr cr.Offset() -> cr.Offset_ var cl *ir.CompLitExpr cl.Right() -> cl.Ntype cl.SetRight(nil) -> cl.Ntype = nil cl.SetRight(n) -> cl.Ntype = ir.Node(n).(ir.Ntype) cl.List() -> cl.List_ cl.PtrList() -> &cl.List_ cl.SetList(ns) -> cl.List_ = ns var conv *ir.ConvExpr conv.Left() -> conv.X conv.SetLeft(n) -> conv.X = n var ix *ir.IndexExpr ix.Left() -> ix.X ix.SetLeft(n) -> ix.X = n ix.Right() -> ix.Index ix.SetRight(n) -> ix.Index = n ix.IndexMapLValue() -> ix.Assigned ix.SetIndexMapLValue(b) -> ix.Assigned = b var kv *ir.KeyExpr kv.Left() -> kv.Key kv.SetLeft(n) -> kv.Key = n kv.Right() -> kv.Value kv.SetRight(n) -> kv.Value = n var sk *ir.StructKeyExpr sk.Sym() -> sk.Field sk.SetSym(sym) -> sk.Field = sym sk.Left() -> sk.Value sk.SetLeft(n) -> sk.Value = n sk.Offset() -> sk.Offset_ sk.SetOffset(i64) -> sk.Offset_ = i64 var ic *ir.InlinedCallExpr ic.Body() -> ic.Body_ ic.PtrBody() -> &ic.Body_ ic.SetBody(ns) -> ic.Body_ = ns ic.Rlist() -> ic.ReturnVars ic.PtrRlist() -> &ic.ReturnVars ic.SetRlist(ns) -> ic.ReturnVars = ns var mak *ir.MakeExpr mak.Left() -> mak.Len mak.SetLeft(n) -> mak.Len = n mak.Right() -> mak.Cap mak.SetRight(n) -> mak.Cap = n var par *ir.ParenExpr par.Left() -> par.X par.SetLeft(n) -> par.X = n var res *ir.ResultExpr res.Offset() -> res.Offset_ res.SetOffset(i64) -> res.Offset_ = i64 var dot *ir.SelectorExpr dot.Left() -> dot.X dot.SetLeft(n) -> dot.X = n dot.Sym() -> dot.Sel dot.SetSym(sym) -> dot.Sel = sym dot.Offset() -> dot.Offset_ dot.SetOffset(i64) -> dot.Offset_ = i64 var sl *ir.SliceExpr sl.Left() -> sl.X sl.SetLeft(n) -> sl.X = n sl.List() -> sl.List_ sl.PtrList() -> &sl.List_ sl.SetList(ns) -> sl.List_ = ns var sh *ir.SliceHeaderExpr sh.Left() -> sh.Ptr sh.SetLeft(n) -> sh.Ptr = n sh.List() -> sh.LenCap_ sh.PtrList() -> &sh.LenCap_ sh.SetList(ns) -> sh.LenCap_ = ns var st *ir.StarExpr st.Left() -> st.X st.SetLeft(n) -> st.X = n var ta *ir.TypeAssertExpr ta.Left() -> ta.X ta.SetLeft(n) -> ta.X = n ta.Right() -> ta.Ntype ta.SetRight(n) -> ta.Ntype = n ta.List() -> ta.Itab ta.PtrList() -> &ta.Itab ta.SetList(ns) -> ta.Itab = ns var u *ir.UnaryExpr u.Left() -> u.X u.SetLeft(n) -> u.X = n var fn *ir.Func fn.Body() -> fn.Body_ fn.PtrBody() -> &fn.Body_ fn.SetBody(ns) -> fn.Body_ = ns fn.Iota() -> fn.Iota_ fn.SetIota(i64) -> fn.Iota_ = i64 fn.Func() -> fn var nam *ir.Name nam.SubOp() -> nam.BuiltinOp nam.SetSubOp(op) -> nam.BuiltinOp = op nam.Class() -> nam.Class_ nam.SetClass(class) -> nam.Class_ = class nam.Func() -> nam.Func_ nam.Offset() -> nam.Offset_ nam.SetOffset(i64) -> nam.Offset_ = i64 } ex . ../ir { import "cmd/compile/internal/ir" var n ir.Nodes (&n).Append -> n.Append (&n).AppendNodes -> n.AppendNodes (&n).MoveNodes -> n.MoveNodes (&n).Prepend -> n.Prepend (&n).Set -> n.Set (&n).Set1 -> n.Set1 (&n).Set2 -> n.Set2 (&n).Set3 -> n.Set3 var ntype ir.Ntype ir.Node(ntype).(ir.Ntype) -> ntype } ' cd ../ir rf ' rm \ Decl.Left Decl.SetLeft \ AssignListStmt.List AssignListStmt.PtrList AssignListStmt.SetList \ AssignListStmt.Rlist AssignListStmt.PtrRlist AssignListStmt.SetRlist \ AssignListStmt.Colas AssignListStmt.SetColas \ AssignStmt.Left AssignStmt.SetLeft \ AssignStmt.Right AssignStmt.SetRight \ AssignStmt.Colas AssignStmt.SetColas \ AssignOpStmt.Left AssignOpStmt.SetLeft \ AssignOpStmt.Right AssignOpStmt.SetRight \ AssignOpStmt.SubOp AssignOpStmt.SetSubOp \ AssignOpStmt.Implicit AssignOpStmt.SetImplicit \ BlockStmt.List BlockStmt.PtrList BlockStmt.SetList \ BranchStmt.SetSym \ CaseStmt.List CaseStmt.PtrList CaseStmt.SetList \ CaseStmt.Body CaseStmt.PtrBody CaseStmt.SetBody \ CaseStmt.Rlist CaseStmt.PtrRlist CaseStmt.SetRlist \ CaseStmt.Left CaseStmt.SetLeft \ ForStmt.Left ForStmt.SetLeft \ ForStmt.Right ForStmt.SetRight \ ForStmt.Body ForStmt.PtrBody ForStmt.SetBody \ ForStmt.List ForStmt.PtrList ForStmt.SetList \ ForStmt.HasBreak ForStmt.SetHasBreak \ ForStmt.Sym ForStmt.SetSym \ GoDeferStmt.Left GoDeferStmt.SetLeft \ IfStmt.Left IfStmt.SetLeft \ IfStmt.Body IfStmt.PtrBody IfStmt.SetBody \ IfStmt.Rlist IfStmt.PtrRlist IfStmt.SetRlist \ IfStmt.Likely IfStmt.SetLikely \ LabelStmt.SetSym \ RangeStmt.Right RangeStmt.SetRight \ RangeStmt.Body RangeStmt.PtrBody RangeStmt.SetBody \ RangeStmt.List RangeStmt.PtrList RangeStmt.SetList \ RangeStmt.HasBreak RangeStmt.SetHasBreak \ RangeStmt.Colas RangeStmt.SetColas \ RangeStmt.Sym RangeStmt.SetSym \ ReturnStmt.List ReturnStmt.PtrList ReturnStmt.SetList \ SelectStmt.List SelectStmt.PtrList SelectStmt.SetList \ SelectStmt.HasBreak SelectStmt.SetHasBreak \ SelectStmt.Body SelectStmt.PtrBody SelectStmt.SetBody \ SelectStmt.Sym SelectStmt.SetSym \ SendStmt.Left SendStmt.SetLeft \ SendStmt.Right SendStmt.SetRight \ SwitchStmt.Left SwitchStmt.SetLeft \ SwitchStmt.List SwitchStmt.PtrList SwitchStmt.SetList \ SwitchStmt.Body SwitchStmt.PtrBody SwitchStmt.SetBody \ SwitchStmt.HasBreak SwitchStmt.SetHasBreak \ SwitchStmt.Sym SwitchStmt.SetSym \ TypeSwitchGuard.Left TypeSwitchGuard.SetLeft \ TypeSwitchGuard.Right TypeSwitchGuard.SetRight \ AddStringExpr.List AddStringExpr.PtrList AddStringExpr.SetList \ AddrExpr.Left AddrExpr.SetLeft \ AddrExpr.Right AddrExpr.SetRight \ BinaryExpr.Left BinaryExpr.SetLeft \ BinaryExpr.Right BinaryExpr.SetRight \ LogicalExpr.Left LogicalExpr.SetLeft \ LogicalExpr.Right LogicalExpr.SetRight \ CallExpr.Left CallExpr.SetLeft \ CallExpr.List CallExpr.PtrList CallExpr.SetList \ CallExpr.Rlist CallExpr.PtrRlist CallExpr.SetRlist \ CallExpr.NoInline CallExpr.SetNoInline \ CallExpr.Body CallExpr.PtrBody CallExpr.SetBody \ CallExpr.IsDDD CallExpr.SetIsDDD \ CallPartExpr.Left CallPartExpr.SetLeft \ ClosureReadExpr.Offset \ ClosureReadExpr.Type \ # provided by miniExpr already CompLitExpr.Right CompLitExpr.SetRight \ CompLitExpr.List CompLitExpr.PtrList CompLitExpr.SetList \ ConvExpr.Left ConvExpr.SetLeft \ IndexExpr.Left IndexExpr.SetLeft \ IndexExpr.Right IndexExpr.SetRight \ IndexExpr.IndexMapLValue IndexExpr.SetIndexMapLValue \ KeyExpr.Left KeyExpr.SetLeft \ KeyExpr.Right KeyExpr.SetRight \ StructKeyExpr.Left StructKeyExpr.SetLeft \ StructKeyExpr.Offset StructKeyExpr.SetOffset \ StructKeyExpr.SetSym \ InlinedCallExpr.Body InlinedCallExpr.PtrBody InlinedCallExpr.SetBody \ InlinedCallExpr.Rlist InlinedCallExpr.PtrRlist InlinedCallExpr.SetRlist \ MakeExpr.Left MakeExpr.SetLeft \ MakeExpr.Right MakeExpr.SetRight \ MethodExpr.Left MethodExpr.SetLeft \ MethodExpr.Right MethodExpr.SetRight \ MethodExpr.Offset MethodExpr.SetOffset \ MethodExpr.Class MethodExpr.SetClass \ ParenExpr.Left ParenExpr.SetLeft \ ResultExpr.Offset ResultExpr.SetOffset \ ReturnStmt.IsDDD \ SelectorExpr.Left SelectorExpr.SetLeft \ SelectorExpr.Offset SelectorExpr.SetOffset \ SelectorExpr.SetSym \ SliceExpr.Left SliceExpr.SetLeft \ SliceExpr.List SliceExpr.PtrList SliceExpr.SetList \ SliceHeaderExpr.Left SliceHeaderExpr.SetLeft \ SliceHeaderExpr.List SliceHeaderExpr.PtrList SliceHeaderExpr.SetList \ StarExpr.Left StarExpr.SetLeft \ TypeAssertExpr.Left TypeAssertExpr.SetLeft \ TypeAssertExpr.Right TypeAssertExpr.SetRight \ TypeAssertExpr.List TypeAssertExpr.PtrList TypeAssertExpr.SetList \ UnaryExpr.Left UnaryExpr.SetLeft \ Func.Body Func.PtrBody Func.SetBody \ Func.Iota Func.SetIota \ CallPartExpr.Func ClosureExpr.Func Func.Func Name.Func \ mv BlockStmt.List_ BlockStmt.List mv CaseStmt.List_ CaseStmt.List mv CaseStmt.Body_ CaseStmt.Body mv ForStmt.Body_ ForStmt.Body mv ForStmt.HasBreak_ ForStmt.HasBreak mv Func.Iota_ Func.Iota mv IfStmt.Body_ IfStmt.Body mv IfStmt.Likely_ IfStmt.Likely mv RangeStmt.Body_ RangeStmt.Body mv RangeStmt.HasBreak_ RangeStmt.HasBreak mv SelectStmt.HasBreak_ SelectStmt.HasBreak mv SwitchStmt.HasBreak_ SwitchStmt.HasBreak mv AddStringExpr.List_ AddStringExpr.List mv CallExpr.NoInline_ CallExpr.NoInline mv CallExpr.Body_ CallExpr.Body # TODO what is this? mv CallExpr.DDD CallExpr.IsDDD mv ClosureReadExpr.Offset_ ClosureReadExpr.Offset mv CompLitExpr.List_ CompLitExpr.List mv StructKeyExpr.Offset_ StructKeyExpr.Offset mv InlinedCallExpr.Body_ InlinedCallExpr.Body mv ResultExpr.Offset_ ResultExpr.Offset mv SelectorExpr.Offset_ SelectorExpr.Offset mv SliceExpr.List_ SliceExpr.List mv SliceHeaderExpr.LenCap_ SliceHeaderExpr.LenCap mv Func.Body_ Func.Body mv CallPartExpr.Func_ CallPartExpr.Func mv ClosureExpr.Func_ ClosureExpr.Func mv Name.Func_ Name.Func ' Change-Id: Ia2ee59649674f83eb123e63fda7a7781cf91cc56 Reviewed-on: https://go-review.googlesource.com/c/go/+/277935 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>
* [dev.regabi] cmd/compile: remove ir.Nod [generated]Russ Cox2020-12-231-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite all uses of ir.Nod and friends to call the IR constructors directly. This gives the results a more specific type and will play nicely with introduction of more specific types throughout the code in a followup CL. Passes buildall w/ toolstash -cmp. [git-generate] cd src/cmd/compile/internal/gc rf ' ex . ../ir { import "cmd/compile/internal/ir" import "cmd/compile/internal/types" import "cmd/compile/internal/syntax" import "cmd/internal/src" var p *noder var orig syntax.Node var op ir.Op var l, r ir.Node var sym *types.Sym p.nod(orig, op, l, r) -> ir.NodAt(p.pos(orig), op, l, r) p.nodSym(orig, op, l, sym) -> nodlSym(p.pos(orig), op, l, sym) var xpos src.XPos var ns ir.Nodes npos(xpos, nodSym(op, l, sym)) -> nodlSym(xpos, op, l, sym) npos(xpos, liststmt(ns)) -> ir.NewBlockStmt(xpos, ns) } ex . ../ir { import "cmd/compile/internal/base" import "cmd/compile/internal/ir" import "cmd/compile/internal/types" var op ir.Op var l, r ir.Node ir.Nod(op, l, r) -> ir.NodAt(base.Pos, op, l, r) var sym *types.Sym nodSym(op, l, sym) -> nodlSym(base.Pos, op, l, sym) } ex . ../ir { import "cmd/compile/internal/ir" import "cmd/internal/src" # rf overlapping match handling is not quite good enough # for certain nested rewrites, so handle these two - which often contain other ir.NodAt calls - early. var l, r ir.Node var xpos src.XPos ir.NodAt(xpos, ir.OAS, l, r) -> ir.NewAssignStmt(xpos, l, r) ir.NodAt(xpos, ir.OIF, l, nil) -> ir.NewIfStmt(xpos, l, nil, nil) } ex . ../ir { import "cmd/compile/internal/ir" import "cmd/compile/internal/types" import "cmd/internal/src" var l, r ir.Node var sym *types.Sym var xpos src.XPos nodlSym(xpos, ir.ODOT, l, sym) -> ir.NewSelectorExpr(xpos, ir.ODOT, l, sym) nodlSym(xpos, ir.OXDOT, l, sym) -> ir.NewSelectorExpr(xpos, ir.OXDOT, l, sym) nodlSym(xpos, ir.ODOTPTR, l, sym) -> ir.NewSelectorExpr(xpos, ir.ODOTPTR, l, sym) nodlSym(xpos, ir.OGOTO, nil, sym) -> ir.NewBranchStmt(xpos, ir.OGOTO, sym) nodlSym(xpos, ir.ORETJMP, nil, sym) -> ir.NewBranchStmt(xpos, ir.ORETJMP, sym) nodlSym(xpos, ir.OLABEL, nil, sym) -> ir.NewLabelStmt(xpos, sym) nodlSym(xpos, ir.OSTRUCTKEY, l, sym) -> ir.NewStructKeyExpr(xpos, sym, l) ir.NodAt(xpos, ir.OADD, l, r) -> ir.NewBinaryExpr(xpos, ir.OADD, l, r) ir.NodAt(xpos, ir.OAND, l, r) -> ir.NewBinaryExpr(xpos, ir.OAND, l, r) ir.NodAt(xpos, ir.OANDNOT, l, r) -> ir.NewBinaryExpr(xpos, ir.OANDNOT, l, r) ir.NodAt(xpos, ir.ODIV, l, r) -> ir.NewBinaryExpr(xpos, ir.ODIV, l, r) ir.NodAt(xpos, ir.OEQ, l, r) -> ir.NewBinaryExpr(xpos, ir.OEQ, l, r) ir.NodAt(xpos, ir.OGE, l, r) -> ir.NewBinaryExpr(xpos, ir.OGE, l, r) ir.NodAt(xpos, ir.OGT, l, r) -> ir.NewBinaryExpr(xpos, ir.OGT, l, r) ir.NodAt(xpos, ir.OLE, l, r) -> ir.NewBinaryExpr(xpos, ir.OLE, l, r) ir.NodAt(xpos, ir.OLSH, l, r) -> ir.NewBinaryExpr(xpos, ir.OLSH, l, r) ir.NodAt(xpos, ir.OLT, l, r) -> ir.NewBinaryExpr(xpos, ir.OLT, l, r) ir.NodAt(xpos, ir.OMOD, l, r) -> ir.NewBinaryExpr(xpos, ir.OMOD, l, r) ir.NodAt(xpos, ir.OMUL, l, r) -> ir.NewBinaryExpr(xpos, ir.OMUL, l, r) ir.NodAt(xpos, ir.ONE, l, r) -> ir.NewBinaryExpr(xpos, ir.ONE, l, r) ir.NodAt(xpos, ir.OOR, l, r) -> ir.NewBinaryExpr(xpos, ir.OOR, l, r) ir.NodAt(xpos, ir.ORSH, l, r) -> ir.NewBinaryExpr(xpos, ir.ORSH, l, r) ir.NodAt(xpos, ir.OSUB, l, r) -> ir.NewBinaryExpr(xpos, ir.OSUB, l, r) ir.NodAt(xpos, ir.OXOR, l, r) -> ir.NewBinaryExpr(xpos, ir.OXOR, l, r) ir.NodAt(xpos, ir.OCOPY, l, r) -> ir.NewBinaryExpr(xpos, ir.OCOPY, l, r) ir.NodAt(xpos, ir.OCOMPLEX, l, r) -> ir.NewBinaryExpr(xpos, ir.OCOMPLEX, l, r) ir.NodAt(xpos, ir.OEFACE, l, r) -> ir.NewBinaryExpr(xpos, ir.OEFACE, l, r) ir.NodAt(xpos, ir.OADDR, l, nil) -> ir.NewAddrExpr(xpos, l) ir.NodAt(xpos, ir.OADDSTR, nil, nil) -> ir.NewAddStringExpr(xpos, nil) ir.NodAt(xpos, ir.OANDAND, l, r) -> ir.NewLogicalExpr(xpos, ir.OANDAND, l, r) ir.NodAt(xpos, ir.OOROR, l, r) -> ir.NewLogicalExpr(xpos, ir.OOROR, l, r) ir.NodAt(xpos, ir.OARRAYLIT, nil, nil) -> ir.NewCompLitExpr(xpos, ir.OARRAYLIT, nil, nil) ir.NodAt(xpos, ir.OCOMPLIT, nil, nil) -> ir.NewCompLitExpr(xpos, ir.OCOMPLIT, nil, nil) ir.NodAt(xpos, ir.OMAPLIT, nil, nil) -> ir.NewCompLitExpr(xpos, ir.OMAPLIT, nil, nil) ir.NodAt(xpos, ir.OSTRUCTLIT, nil, nil) -> ir.NewCompLitExpr(xpos, ir.OSTRUCTLIT, nil, nil) ir.NodAt(xpos, ir.OSLICELIT, nil, nil) -> ir.NewCompLitExpr(xpos, ir.OSLICELIT, nil, nil) ir.NodAt(xpos, ir.OARRAYLIT, nil, r) -> ir.NewCompLitExpr(xpos, ir.OARRAYLIT, r.(ir.Ntype), nil) ir.NodAt(xpos, ir.OCOMPLIT, nil, r) -> ir.NewCompLitExpr(xpos, ir.OCOMPLIT, r.(ir.Ntype), nil) ir.NodAt(xpos, ir.OMAPLIT, nil, r) -> ir.NewCompLitExpr(xpos, ir.OMAPLIT, r.(ir.Ntype), nil) ir.NodAt(xpos, ir.OSTRUCTLIT, nil, r) -> ir.NewCompLitExpr(xpos, ir.OSTRUCTLIT, r.(ir.Ntype), nil) ir.NodAt(xpos, ir.OSLICELIT, nil, r) -> ir.NewCompLitExpr(xpos, ir.OSLICELIT, r.(ir.Ntype), nil) ir.NodAt(xpos, ir.OAS2, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OAS2, nil, nil) ir.NodAt(xpos, ir.OAS2DOTTYPE, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OAS2DOTTYPE, nil, nil) ir.NodAt(xpos, ir.OAS2FUNC, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OAS2FUNC, nil, nil) ir.NodAt(xpos, ir.OAS2MAPR, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OAS2MAPR, nil, nil) ir.NodAt(xpos, ir.OAS2RECV, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OAS2RECV, nil, nil) ir.NodAt(xpos, ir.OSELRECV2, nil, nil) -> ir.NewAssignListStmt(xpos, ir.OSELRECV2, nil, nil) ir.NodAt(xpos, ir.OASOP, l, r) -> ir.NewAssignOpStmt(xpos, ir.OXXX, l, r) ir.NodAt(xpos, ir.OBITNOT, l, nil) -> ir.NewUnaryExpr(xpos, ir.OBITNOT, l) ir.NodAt(xpos, ir.ONEG, l, nil) -> ir.NewUnaryExpr(xpos, ir.ONEG, l) ir.NodAt(xpos, ir.ONOT, l, nil) -> ir.NewUnaryExpr(xpos, ir.ONOT, l) ir.NodAt(xpos, ir.OPLUS, l, nil) -> ir.NewUnaryExpr(xpos, ir.OPLUS, l) ir.NodAt(xpos, ir.ORECV, l, nil) -> ir.NewUnaryExpr(xpos, ir.ORECV, l) ir.NodAt(xpos, ir.OALIGNOF, l, nil) -> ir.NewUnaryExpr(xpos, ir.OALIGNOF, l) ir.NodAt(xpos, ir.OCAP, l, nil) -> ir.NewUnaryExpr(xpos, ir.OCAP, l) ir.NodAt(xpos, ir.OCLOSE, l, nil) -> ir.NewUnaryExpr(xpos, ir.OCLOSE, l) ir.NodAt(xpos, ir.OIMAG, l, nil) -> ir.NewUnaryExpr(xpos, ir.OIMAG, l) ir.NodAt(xpos, ir.OLEN, l, nil) -> ir.NewUnaryExpr(xpos, ir.OLEN, l) ir.NodAt(xpos, ir.ONEW, l, nil) -> ir.NewUnaryExpr(xpos, ir.ONEW, l) ir.NodAt(xpos, ir.ONEWOBJ, l, nil) -> ir.NewUnaryExpr(xpos, ir.ONEWOBJ, l) ir.NodAt(xpos, ir.OOFFSETOF, l, nil) -> ir.NewUnaryExpr(xpos, ir.OOFFSETOF, l) ir.NodAt(xpos, ir.OPANIC, l, nil) -> ir.NewUnaryExpr(xpos, ir.OPANIC, l) ir.NodAt(xpos, ir.OREAL, l, nil) -> ir.NewUnaryExpr(xpos, ir.OREAL, l) ir.NodAt(xpos, ir.OSIZEOF, l, nil) -> ir.NewUnaryExpr(xpos, ir.OSIZEOF, l) ir.NodAt(xpos, ir.OCHECKNIL, l, nil) -> ir.NewUnaryExpr(xpos, ir.OCHECKNIL, l) ir.NodAt(xpos, ir.OCFUNC, l, nil) -> ir.NewUnaryExpr(xpos, ir.OCFUNC, l) ir.NodAt(xpos, ir.OIDATA, l, nil) -> ir.NewUnaryExpr(xpos, ir.OIDATA, l) ir.NodAt(xpos, ir.OITAB, l, nil) -> ir.NewUnaryExpr(xpos, ir.OITAB, l) ir.NodAt(xpos, ir.OSPTR, l, nil) -> ir.NewUnaryExpr(xpos, ir.OSPTR, l) ir.NodAt(xpos, ir.OVARDEF, l, nil) -> ir.NewUnaryExpr(xpos, ir.OVARDEF, l) ir.NodAt(xpos, ir.OVARKILL, l, nil) -> ir.NewUnaryExpr(xpos, ir.OVARKILL, l) ir.NodAt(xpos, ir.OVARLIVE, l, nil) -> ir.NewUnaryExpr(xpos, ir.OVARLIVE, l) ir.NodAt(xpos, ir.OBLOCK, nil, nil) -> ir.NewBlockStmt(xpos, nil) ir.NodAt(xpos, ir.OBREAK, nil, nil) -> ir.NewBranchStmt(xpos, ir.OBREAK, nil) ir.NodAt(xpos, ir.OCONTINUE, nil, nil) -> ir.NewBranchStmt(xpos, ir.OCONTINUE, nil) ir.NodAt(xpos, ir.OFALL, nil, nil) -> ir.NewBranchStmt(xpos, ir.OFALL, nil) ir.NodAt(xpos, ir.OGOTO, nil, nil) -> ir.NewBranchStmt(xpos, ir.OGOTO, nil) ir.NodAt(xpos, ir.ORETJMP, nil, nil) -> ir.NewBranchStmt(xpos, ir.ORETJMP, nil) ir.NodAt(xpos, ir.OCALL, l, nil) -> ir.NewCallExpr(xpos, ir.OCALL, l, nil) ir.NodAt(xpos, ir.OCALLFUNC, l, nil) -> ir.NewCallExpr(xpos, ir.OCALLFUNC, l, nil) ir.NodAt(xpos, ir.OCALLINTER, l, nil) -> ir.NewCallExpr(xpos, ir.OCALLINTER, l, nil) ir.NodAt(xpos, ir.OCALLMETH, l, nil) -> ir.NewCallExpr(xpos, ir.OCALLMETH, l, nil) ir.NodAt(xpos, ir.OAPPEND, l, nil) -> ir.NewCallExpr(xpos, ir.OAPPEND, l, nil) ir.NodAt(xpos, ir.ODELETE, l, nil) -> ir.NewCallExpr(xpos, ir.ODELETE, l, nil) ir.NodAt(xpos, ir.OGETG, l, nil) -> ir.NewCallExpr(xpos, ir.OGETG, l, nil) ir.NodAt(xpos, ir.OMAKE, l, nil) -> ir.NewCallExpr(xpos, ir.OMAKE, l, nil) ir.NodAt(xpos, ir.OPRINT, l, nil) -> ir.NewCallExpr(xpos, ir.OPRINT, l, nil) ir.NodAt(xpos, ir.OPRINTN, l, nil) -> ir.NewCallExpr(xpos, ir.OPRINTN, l, nil) ir.NodAt(xpos, ir.ORECOVER, l, nil) -> ir.NewCallExpr(xpos, ir.ORECOVER, l, nil) ir.NodAt(xpos, ir.OCASE, nil, nil) -> ir.NewCaseStmt(xpos, nil, nil) ir.NodAt(xpos, ir.OCONV, l, nil) -> ir.NewConvExpr(xpos, ir.OCONV, nil, l) ir.NodAt(xpos, ir.OCONVIFACE, l, nil) -> ir.NewConvExpr(xpos, ir.OCONVIFACE, nil, l) ir.NodAt(xpos, ir.OCONVNOP, l, nil) -> ir.NewConvExpr(xpos, ir.OCONVNOP, nil, l) ir.NodAt(xpos, ir.ORUNESTR, l, nil) -> ir.NewConvExpr(xpos, ir.ORUNESTR, nil, l) ir.NodAt(xpos, ir.ODCL, l, nil) -> ir.NewDecl(xpos, ir.ODCL, l) ir.NodAt(xpos, ir.ODCLCONST, l, nil) -> ir.NewDecl(xpos, ir.ODCLCONST, l) ir.NodAt(xpos, ir.ODCLTYPE, l, nil) -> ir.NewDecl(xpos, ir.ODCLTYPE, l) ir.NodAt(xpos, ir.ODCLFUNC, nil, nil) -> ir.NewFunc(xpos) ir.NodAt(xpos, ir.ODEFER, l, nil) -> ir.NewGoDeferStmt(xpos, ir.ODEFER, l) ir.NodAt(xpos, ir.OGO, l, nil) -> ir.NewGoDeferStmt(xpos, ir.OGO, l) ir.NodAt(xpos, ir.ODEREF, l, nil) -> ir.NewStarExpr(xpos, l) ir.NodAt(xpos, ir.ODOT, l, nil) -> ir.NewSelectorExpr(xpos, ir.ODOT, l, nil) ir.NodAt(xpos, ir.ODOTPTR, l, nil) -> ir.NewSelectorExpr(xpos, ir.ODOTPTR, l, nil) ir.NodAt(xpos, ir.ODOTMETH, l, nil) -> ir.NewSelectorExpr(xpos, ir.ODOTMETH, l, nil) ir.NodAt(xpos, ir.ODOTINTER, l, nil) -> ir.NewSelectorExpr(xpos, ir.ODOTINTER, l, nil) ir.NodAt(xpos, ir.OXDOT, l, nil) -> ir.NewSelectorExpr(xpos, ir.OXDOT, l, nil) ir.NodAt(xpos, ir.ODOTTYPE, l, nil) -> ir.NewTypeAssertExpr(xpos, l, nil) ir.NodAt(xpos, ir.ODOTTYPE, l, r) -> ir.NewTypeAssertExpr(xpos, l, r.(ir.Ntype)) ir.NodAt(xpos, ir.OFOR, l, r) -> ir.NewForStmt(xpos, nil, l, r, nil) ir.NodAt(xpos, ir.OINDEX, l, r) -> ir.NewIndexExpr(xpos, l, r) ir.NodAt(xpos, ir.OINLMARK, nil, nil) -> ir.NewInlineMarkStmt(xpos, types.BADWIDTH) ir.NodAt(xpos, ir.OKEY, l, r) -> ir.NewKeyExpr(xpos, l, r) ir.NodAt(xpos, ir.OLABEL, nil, nil) -> ir.NewLabelStmt(xpos, nil) ir.NodAt(xpos, ir.OMAKECHAN, l, r) -> ir.NewMakeExpr(xpos, ir.OMAKECHAN, l, r) ir.NodAt(xpos, ir.OMAKEMAP, l, r) -> ir.NewMakeExpr(xpos, ir.OMAKEMAP, l, r) ir.NodAt(xpos, ir.OMAKESLICE, l, r) -> ir.NewMakeExpr(xpos, ir.OMAKESLICE, l, r) ir.NodAt(xpos, ir.OMAKESLICECOPY, l, r) -> ir.NewMakeExpr(xpos, ir.OMAKESLICECOPY, l, r) ir.NodAt(xpos, ir.ONIL, nil, nil) -> ir.NewNilExpr(xpos) ir.NodAt(xpos, ir.OPACK, nil, nil) -> ir.NewPkgName(xpos, nil, nil) ir.NodAt(xpos, ir.OPAREN, l, nil) -> ir.NewParenExpr(xpos, l) ir.NodAt(xpos, ir.ORANGE, nil, r) -> ir.NewRangeStmt(xpos, nil, r, nil) ir.NodAt(xpos, ir.ORESULT, nil, nil) -> ir.NewResultExpr(xpos, nil, types.BADWIDTH) ir.NodAt(xpos, ir.ORETURN, nil, nil) -> ir.NewReturnStmt(xpos, nil) ir.NodAt(xpos, ir.OSELECT, nil, nil) -> ir.NewSelectStmt(xpos, nil) ir.NodAt(xpos, ir.OSEND, l, r) -> ir.NewSendStmt(xpos, l, r) ir.NodAt(xpos, ir.OSLICE, l, nil) -> ir.NewSliceExpr(xpos, ir.OSLICE, l) ir.NodAt(xpos, ir.OSLICEARR, l, nil) -> ir.NewSliceExpr(xpos, ir.OSLICEARR, l) ir.NodAt(xpos, ir.OSLICESTR, l, nil) -> ir.NewSliceExpr(xpos, ir.OSLICESTR, l) ir.NodAt(xpos, ir.OSLICE3, l, nil) -> ir.NewSliceExpr(xpos, ir.OSLICE3, l) ir.NodAt(xpos, ir.OSLICE3ARR, l, nil) -> ir.NewSliceExpr(xpos, ir.OSLICE3ARR, l) ir.NodAt(xpos, ir.OSLICEHEADER, l, nil) -> ir.NewSliceHeaderExpr(xpos, nil, l, nil, nil) ir.NodAt(xpos, ir.OSWITCH, l, nil) -> ir.NewSwitchStmt(xpos, l, nil) ir.NodAt(xpos, ir.OINLCALL, nil, nil) -> ir.NewInlinedCallExpr(xpos, nil, nil) } rm noder.nod noder.nodSym nodSym nodlSym ir.NodAt ir.Nod ' Change-Id: Ibf1eb708de8463ae74ccc47d7966cc263a18295e Reviewed-on: https://go-review.googlesource.com/c/go/+/277933 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>
* [dev.regabi] cmd/compile: only access Func method on concrete typesRuss Cox2020-12-221-4/+4
| | | | | | | | | | | | | | Sets up for removing Func from Node interface. That means that once the Name reorg is done, which will let us remove Name, Sym, and Val, Node will be basically a minimal interface. Passes buildall w/ toolstash -cmp. Change-Id: I6e87897572debd7f8e29b4f5167763dc2792b408 Reviewed-on: https://go-review.googlesource.com/c/go/+/279484 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: collect global compilation stateRuss Cox2020-12-211-4/+4
| | | | | | | | | | | | | | | There are various global variables tracking the state of the compilation. Collect them in a single global struct instead. The struct definition is in package ir, but the struct itself is still in package gc. It may eventually be threaded through the code, but in the short term will end up in package typecheck. Change-Id: I019db07aaedaed2c9b67dd45a4e138dc6028e54c Reviewed-on: https://go-review.googlesource.com/c/go/+/279297 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>
* [dev.regabi] cmd/compile: remove prealloc mapRuss Cox2020-12-181-5/+5
| | | | | | | | | | | | | | | | | | | | | | The prealloc map seems to exist to avoid adding a field to all nodes. Now we can add a field to just the nodes that need the field, so let's do that and avoid having a magic global with extra node state that isn't preserved by operations like Copy nor printed by Dump. This also makes clear which nodes can be prealloc'ed. In particular, the code in walkstmt looked up an entry in prealloc using an ONAME node, but there's no code that ever stores such an entry, so the lookup never succeeded. Having fields makes that kind of thing easier to see and fix. Passes buildall w/ toolstash -cmp. Change-Id: I418ad0e2847615c08868120c13ee719dc0b2eacb Reviewed-on: https://go-review.googlesource.com/c/go/+/278915 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>
* [dev.regabi] cmd/compile: cleanup for concrete types - mop-upRuss Cox2020-12-171-6/+7
| | | | | | | | | | | | | | | | | | | | | | An automated rewrite will add concrete type assertions after a test of n.Op(), when n can be safely type-asserted (meaning, n is not reassigned a different type, n is not reassigned and then used outside the scope of the type assertion, and so on). This sequence of CLs handles the code that the automated rewrite does not: adding specific types to function arguments, adjusting code not to call n.Left() etc when n may have multiple representations, and so on. This CL handles all the little files that are left. Passes buildall w/ toolstash -cmp. Change-Id: I6588c92dbbdd37342a77b365d70e02134a033d2a Reviewed-on: https://go-review.googlesource.com/c/go/+/277932 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: cleanup preparing for concrete types, 2Russ Cox2020-12-171-16/+16
| | | | | | | | | | | | | | | Avoid using the same variable for two different concrete Node types in other files (beyond walk). This will smooth the introduction of specific constructors, replacing ir.Nod and friends. Passes buildall w/ toolstash -cmp. Replay of CL 275885, lost to the bad-merge history rewrite. Change-Id: I0da89502a0bd636b8766f01b6f843c7821b3e9ab Reviewed-on: https://go-review.googlesource.com/c/go/+/277955 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: intercept the making of OADDR nodesKeith Randall2020-12-141-5/+5
| | | | | | | | | | | | | | This is a mechanical change to intercept the construction of all OADDR nodes. We will use the new nodAddr and nodAddrAt functions to compute the Addrtaken bit. Change-Id: I90ee3acb8e32540a198a9999284573418729f422 Reviewed-on: https://go-review.googlesource.com/c/go/+/275694 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com>
* [dev.regabi] cmd/compile: rewrite stale format stringsRuss Cox2020-12-071-1/+1
| | | | | | | | | | | | | | | | | | | | | On ir.Node, ir.Nodes, and ir.Op, # is ignored, so %#v is %v. On ir.Node, %S is the same as %v. On types.Type, # is ignored, so %#L is %L, %#v is %v. On types.Type, 0 is ignored, so %0S is %S. Rewrite all these using go test cmd/compile -r, plus a few multiline formats mentioning %0S on types updated by hand. Now the formats used in the compiler match the documentation for the format methods, a minor miracle. Passes buildall w/ toolstash -cmp. Change-Id: I3d4a3fae543145a68da13eede91166632c5b1ceb Reviewed-on: https://go-review.googlesource.com/c/go/+/275782 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: store types.Field on {Selector,CallPart}ExprMatthew Dempsky2020-12-031-13/+2
| | | | | | | | | | | | | | | | | | | | It's useful to have quick access to the types.Field that a given selector or method value expression refer to. Previously we abused Opt for this, but couldn't do that for OCALLPART because escape analysis uses Opt. Now that we have more flexibility, we can simply add additional pointer fields for this. This also allows getting rid of an unneeded ONAME node for OCALLPART. Passes buildall w/ toolstash -cmp. Change-Id: I980d7bdb19abfd0b6f58a232876861b88dee1e47 Reviewed-on: https://go-review.googlesource.com/c/go/+/275034 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: add Pkg parameter to type constructorsMatthew Dempsky2020-12-021-2/+0
| | | | | | | | | | | | Allows getting rid of the SetPkg method and also addresses a long-standing TODO in the exporter. Suggested by rsc@. Passes buildall w/ toolstash -cmp. Change-Id: Ib294f75f1350572efb2e0d993d49efef884de3d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/274440 Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
* [dev.regabi] cmd/compile: cleanup some leftover cruftMatthew Dempsky2020-12-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Just clearing away some scaffolding artifacts from previous refactorings. [git-generate] cd src/cmd/compile/internal/gc rf ' ex { import "cmd/compile/internal/ir" import "cmd/compile/internal/types" var n *ir.Name; n.Name() -> n var f *ir.Func; f.Func() -> f var o types.Object ir.AsNode(o).Sym() -> o.Sym() ir.AsNode(o).Type() -> o.Type() ir.AsNode(o).(*ir.Name) -> o.(*ir.Name) ir.AsNode(o).(*ir.Func) -> o.(*ir.Func) var x ir.Node ir.AsNode(o) != x -> o != x } ' Change-Id: I946ec344bd7ee274900a392da53b95308ceaade4 Reviewed-on: https://go-review.googlesource.com/c/go/+/274592 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* [dev.regabi] cmd/compile: add custom type syntax Node implementationsRuss Cox2020-11-301-5/+5
| | | | | | | | | | | | | | | | | The type syntax is reused to stand in for the actual type once typechecked, to avoid updating all the possible references to the original type syntax. So all these implementations allow changing their Op from the raw syntax like OTMAP to the finished form OTYPE, even though obviously the representation does not change. Passes buildall w/ toolstash -cmp. Change-Id: I4acca1a5b35fa2f48ee08e8f1e5a330a004c284b Reviewed-on: https://go-review.googlesource.com/c/go/+/274103 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* [dev.regabi] cmd/compile: move typenod, typenodl to ir.TypeNode, ↵Russ Cox2020-11-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | ir.TypeNodeAt [generated] [git-generate] cd src/cmd/compile/internal/gc rf ' mv typenod TypeNode mv typenodl TypeNodeAt mv TypeNode TypeNodeAt type.go mv type.go cmd/compile/internal/ir ' Passes buildall w/ toolstash -cmp. Change-Id: Id546a8cfae93074ebb1496490da7635800807faf Reviewed-on: https://go-review.googlesource.com/c/go/+/274100 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>
* [dev.regabi] cmd/compile: add ir.CallPartExprRuss Cox2020-11-301-7/+3
| | | | | | | | | | | | | | | | Now there are no longer any generic nodes with a non-nil associated Func, so node.fn can be deleted. Also all manipulation of func fields is done with concrete types, so Node.SetFunc can be deleted, along with generic implementations. Passes buildall w/ toolstash -cmp. Change-Id: I4fee99870951ec9dc224f146d87b22e2bfe16889 Reviewed-on: https://go-review.googlesource.com/c/go/+/274099 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>
* [dev.regabi] cmd/compile: add ir.Closure, ir.ClosureReadRuss Cox2020-11-301-19/+13
| | | | | | | | | | | | | | | | | Closures are another reference to Funcs, and it cleans up the code quite a bit to be clear about types. OCLOSUREVAR is renamed to OCLOSUREREAD to make clearer that it is unrelated to the list Func.ClosureVars. Passes buildall w/ toolstash -cmp. Change-Id: Id0d28df2d4d6e9954e34df7a39ea226995eee937 Reviewed-on: https://go-review.googlesource.com/c/go/+/274098 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>
* [dev.regabi] cmd/compile: clean up Name and Func usesRuss Cox2020-11-301-73/+69
| | | | | | | | | | | | | | | | | | | | Now that we have specific types for ONAME and ODCLFUNC nodes (*Name and *Func), use them throughout the compiler to be more precise about what data is being operated on. This is a somewhat large CL, but once you start applying the types in a few places, you end up needing to apply them to many other places to keep everything type-checking. A lot of code also melts away as types are added. Passes buildall w/ toolstash -cmp. Change-Id: I21dd9b945d701c470332bac5394fca744a5b232d Reviewed-on: https://go-review.googlesource.com/c/go/+/274097 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>
* [dev.regabi] cmd/compile: make ir.Name the ONAME Node implementationRuss Cox2020-11-301-6/+7
| | | | | | | | | | | | | | | | | | | | | | Before this CL, an ONAME Node was represented by three structs linked together: a node, a Name, and a Param. Previous CLs removed OLABEL and OPACK from the set of nodes that knew about Name. Now Name can be repurposed to *be* the ONAME Node implementation, replacing three linked structs totaling 152+64+88 = 304 bytes (64-bit) with a single 232-byte struct. Many expressions in the code become simpler as well, without having to use .Param. and sometimes even .Name(). (For a node n where n.Name() != nil, n.Name() == n.(*Name) now.) Passes buildall w/ toolstash -cmp. Change-Id: Ie719f1285c05623b9fd2faaa059e5b360a64b3be Reviewed-on: https://go-review.googlesource.com/c/go/+/274094 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>
* [dev.regabi] cmd/compile: replace *Node type with an interface Node [generated]Russ Cox2020-11-251-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The plan is to introduce a Node interface that replaces the old *Node pointer-to-struct. The previous CL defined an interface INode modeling a *Node. This CL: - Changes all references outside internal/ir to use INode, along with many references inside internal/ir as well. - Renames Node to node. - Renames INode to Node So now ir.Node is an interface implemented by *ir.node, which is otherwise inaccessible, and the code outside package ir is now (clearly) using only the interface. The usual rule is never to redefine an existing name with a new meaning, so that old code that hasn't been updated gets a "unknown name" error instead of more mysterious errors or silent misbehavior. That rule would caution against replacing Node-the-struct with Node-the-interface, as in this CL, because code that says *Node would now be using a pointer to an interface. But this CL is being landed at the same time as another that moves Node from gc to ir. So the net effect is to replace *gc.Node with ir.Node, which does follow the rule: any lingering references to gc.Node will be told it's gone, not silently start using pointers to interfaces. So the rule is followed by the CL sequence, just not this specific CL. Overall, the loss of inlining caused by using interfaces cuts the compiler speed by about 6%, a not insignificant amount. However, as we convert the representation to concrete structs that are not the giant Node over the next weeks, that speed should come back as more of the compiler starts operating directly on concrete types and the memory taken up by the graph of Nodes drops due to the more precise structs. Honestly, I was expecting worse. % benchstat bench.old bench.new name old time/op new time/op delta Template 168ms ± 4% 182ms ± 2% +8.34% (p=0.000 n=9+9) Unicode 72.2ms ±10% 82.5ms ± 6% +14.38% (p=0.000 n=9+9) GoTypes 563ms ± 8% 598ms ± 2% +6.14% (p=0.006 n=9+9) Compiler 2.89s ± 4% 3.04s ± 2% +5.37% (p=0.000 n=10+9) SSA 6.45s ± 4% 7.25s ± 5% +12.41% (p=0.000 n=9+10) Flate 105ms ± 2% 115ms ± 1% +9.66% (p=0.000 n=10+8) GoParser 144ms ±10% 152ms ± 2% +5.79% (p=0.011 n=9+8) Reflect 345ms ± 9% 370ms ± 4% +7.28% (p=0.001 n=10+9) Tar 149ms ± 9% 161ms ± 5% +8.05% (p=0.001 n=10+9) XML 190ms ± 3% 209ms ± 2% +9.54% (p=0.000 n=9+8) LinkCompiler 327ms ± 2% 325ms ± 2% ~ (p=0.382 n=8+8) ExternalLinkCompiler 1.77s ± 4% 1.73s ± 6% ~ (p=0.113 n=9+10) LinkWithoutDebugCompiler 214ms ± 4% 211ms ± 2% ~ (p=0.360 n=10+8) StdCmd 14.8s ± 3% 15.9s ± 1% +6.98% (p=0.000 n=10+9) [Geo mean] 480ms 510ms +6.31% name old user-time/op new user-time/op delta Template 223ms ± 3% 237ms ± 3% +6.16% (p=0.000 n=9+10) Unicode 103ms ± 6% 113ms ± 3% +9.53% (p=0.000 n=9+9) GoTypes 758ms ± 8% 800ms ± 2% +5.55% (p=0.003 n=10+9) Compiler 3.95s ± 2% 4.12s ± 2% +4.34% (p=0.000 n=10+9) SSA 9.43s ± 1% 9.74s ± 4% +3.25% (p=0.000 n=8+10) Flate 132ms ± 2% 141ms ± 2% +6.89% (p=0.000 n=9+9) GoParser 177ms ± 9% 183ms ± 4% ~ (p=0.050 n=9+9) Reflect 467ms ±10% 495ms ± 7% +6.17% (p=0.029 n=10+10) Tar 183ms ± 9% 197ms ± 5% +7.92% (p=0.001 n=10+10) XML 249ms ± 5% 268ms ± 4% +7.82% (p=0.000 n=10+9) LinkCompiler 544ms ± 5% 544ms ± 6% ~ (p=0.863 n=9+9) ExternalLinkCompiler 1.79s ± 4% 1.75s ± 6% ~ (p=0.075 n=10+10) LinkWithoutDebugCompiler 248ms ± 6% 246ms ± 2% ~ (p=0.965 n=10+8) [Geo mean] 483ms 504ms +4.41% [git-generate] cd src/cmd/compile/internal/ir : # We need to do the conversion in multiple steps, so we introduce : # a temporary type alias that will start out meaning the pointer-to-struct : # and then change to mean the interface. rf ' mv Node OldNode add node.go \ type Node = *OldNode ' : # It should work to do this ex in ir, but it misses test files, due to a bug in rf. : # Run the command in gc to handle gc's tests, and then again in ssa for ssa's tests. cd ../gc rf ' ex . ../arm ../riscv64 ../arm64 ../mips64 ../ppc64 ../mips ../wasm { import "cmd/compile/internal/ir" *ir.OldNode -> ir.Node } ' cd ../ssa rf ' ex { import "cmd/compile/internal/ir" *ir.OldNode -> ir.Node } ' : # Back in ir, finish conversion clumsily with sed, : # because type checking and circular aliases do not mix. cd ../ir sed -i '' ' /type Node = \*OldNode/d s/\*OldNode/Node/g s/^func (n Node)/func (n *OldNode)/ s/OldNode/node/g s/type INode interface/type Node interface/ s/var _ INode = (Node)(nil)/var _ Node = (*node)(nil)/ ' *.go gofmt -w *.go sed -i '' ' s/{Func{}, 136, 248}/{Func{}, 152, 280}/ s/{Name{}, 32, 56}/{Name{}, 44, 80}/ s/{Param{}, 24, 48}/{Param{}, 44, 88}/ s/{node{}, 76, 128}/{node{}, 88, 152}/ ' sizeof_test.go cd ../ssa sed -i '' ' s/{LocalSlot{}, 28, 40}/{LocalSlot{}, 32, 48}/ ' sizeof_test.go cd ../gc sed -i '' 's/\*ir.Node/ir.Node/' mkbuiltin.go cd ../../../.. go install std cmd cd cmd/compile go test -u || go test -u Change-Id: I196bbe3b648e4701662e4a2bada40bf155e2a553 Reviewed-on: https://go-review.googlesource.com/c/go/+/272935 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>
* [dev.regabi] cmd/compile: convert types.Node (a pointer) to types.IRNode (an ↵Russ Cox2020-11-251-2/+2
| | | | | | | | | | | | | | | | | | | interface) The pointer hack was nice and saved a word, but it's untenable in a world where nodes are themselves interfaces with different underlying types. Bite the bullet and use an interface to hold the Node when in types.Sym and types.Type. This has the nice benefit of removing AsTypesNode entirely. AsNode is still useful because of its nil handling. Change-Id: I298cba9ff788b956ee287283bec78010e8b601e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/272933 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>
* [dev.regabi] cmd/compile: use Node getters and setters [generated]Russ Cox2020-11-251-111/+111
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that we have all the getters and setters defined, use them and unexport all the actual Node fields. This is the next step toward replacing Node with an interface. [git-generate] cd src/cmd/compile/internal/gc rf ' ex . ../ir ../ssa { import "cmd/compile/internal/ir" import "cmd/compile/internal/types" import "cmd/internal/src" var n, x *ir.Node var op ir.Op var t *types.Type var f *ir.Func var m *ir.Name var s *types.Sym var p src.XPos var i int64 var e uint16 var nodes ir.Nodes n.Op = op -> n.SetOp(op) n.Left = x -> n.SetLeft(x) n.Right = x -> n.SetRight(x) n.Orig = x -> n.SetOrig(x) n.Type = t -> n.SetType(t) n.Func = f -> n.SetFunc(f) n.Name = m -> n.SetName(m) n.Sym = s -> n.SetSym(s) n.Pos = p -> n.SetPos(p) n.Xoffset = i -> n.SetXoffset(i) n.Esc = e -> n.SetEsc(e) n.Ninit.Append -> n.PtrNinit().Append n.Ninit.AppendNodes -> n.PtrNinit().AppendNodes n.Ninit.MoveNodes -> n.PtrNinit().MoveNodes n.Ninit.Prepend -> n.PtrNinit().Prepend n.Ninit.Set -> n.PtrNinit().Set n.Ninit.Set1 -> n.PtrNinit().Set1 n.Ninit.Set2 -> n.PtrNinit().Set2 n.Ninit.Set3 -> n.PtrNinit().Set3 &n.Ninit -> n.PtrNinit() n.Ninit = nodes -> n.SetNinit(nodes) n.Nbody.Append -> n.PtrNbody().Append n.Nbody.AppendNodes -> n.PtrNbody().AppendNodes n.Nbody.MoveNodes -> n.PtrNbody().MoveNodes n.Nbody.Prepend -> n.PtrNbody().Prepend n.Nbody.Set -> n.PtrNbody().Set n.Nbody.Set1 -> n.PtrNbody().Set1 n.Nbody.Set2 -> n.PtrNbody().Set2 n.Nbody.Set3 -> n.PtrNbody().Set3 &n.Nbody -> n.PtrNbody() n.Nbody = nodes -> n.SetNbody(nodes) n.List.Append -> n.PtrList().Append n.List.AppendNodes -> n.PtrList().AppendNodes n.List.MoveNodes -> n.PtrList().MoveNodes n.List.Prepend -> n.PtrList().Prepend n.List.Set -> n.PtrList().Set n.List.Set1 -> n.PtrList().Set1 n.List.Set2 -> n.PtrList().Set2 n.List.Set3 -> n.PtrList().Set3 &n.List -> n.PtrList() n.List = nodes -> n.SetList(nodes) n.Rlist.Append -> n.PtrRlist().Append n.Rlist.AppendNodes -> n.PtrRlist().AppendNodes n.Rlist.MoveNodes -> n.PtrRlist().MoveNodes n.Rlist.Prepend -> n.PtrRlist().Prepend n.Rlist.Set -> n.PtrRlist().Set n.Rlist.Set1 -> n.PtrRlist().Set1 n.Rlist.Set2 -> n.PtrRlist().Set2 n.Rlist.Set3 -> n.PtrRlist().Set3 &n.Rlist -> n.PtrRlist() n.Rlist = nodes -> n.SetRlist(nodes) } ex . ../ir ../ssa { import "cmd/compile/internal/ir" var n *ir.Node n.Op -> n.GetOp() n.Left -> n.GetLeft() n.Right -> n.GetRight() n.Orig -> n.GetOrig() n.Type -> n.GetType() n.Func -> n.GetFunc() n.Name -> n.GetName() n.Sym -> n.GetSym() n.Pos -> n.GetPos() n.Xoffset -> n.GetXoffset() n.Esc -> n.GetEsc() avoid (*ir.Node).PtrNinit avoid (*ir.Node).PtrNbody avoid (*ir.Node).PtrList avoid (*ir.Node).PtrRlist n.Ninit -> n.GetNinit() n.Nbody -> n.GetNbody() n.List -> n.GetList() n.Rlist -> n.GetRlist() } ' cd ../ir rf ' mv Node.Op Node.op mv Node.GetOp Node.Op mv Node.Left Node.left mv Node.GetLeft Node.Left mv Node.Right Node.right mv Node.GetRight Node.Right mv Node.Orig Node.orig mv Node.GetOrig Node.Orig mv Node.Type Node.typ mv Node.GetType Node.Type mv Node.Func Node.fn mv Node.GetFunc Node.Func mv Node.Name Node.name mv Node.GetName Node.Name # All uses are in other Node methods already. mv Node.E Node.e mv Node.Sym Node.sym mv Node.GetSym Node.Sym mv Node.Pos Node.pos mv Node.GetPos Node.Pos mv Node.Esc Node.esc mv Node.GetEsc Node.Esc # While we are here, rename Xoffset to more idiomatic Offset. mv Node.Xoffset Node.offset mv Node.GetXoffset Node.Offset mv Node.SetXoffset Node.SetOffset # While we are here, rename Ninit, Nbody to more idiomatic Init, Body. mv Node.Ninit Node.init mv Node.GetNinit Node.Init mv Node.PtrNinit Node.PtrInit mv Node.SetNinit Node.SetInit mv Node.Nbody Node.body mv Node.GetNbody Node.Body mv Node.PtrNbody Node.PtrBody mv Node.SetNbody Node.SetBody mv Node.List Node.list mv Node.GetList Node.List mv Node.Rlist Node.rlist mv Node.GetRlist Node.Rlist # Unexport these mv Node.SetHasOpt Node.setHasOpt mv Node.SetHasVal Node.setHasVal ' Change-Id: I9894f633375c5237a29b6d6d7b89ba181b56ca3a Reviewed-on: https://go-review.googlesource.com/c/go/+/273009 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: introduce cmd/compile/internal/ir [generated]Russ Cox2020-11-251-60/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we want to break up package gc at all, we will need to move the compiler IR it defines into a separate package that can be imported by packages that gc itself imports. This CL does that. It also removes the TINT8 etc aliases so that all code is clear about which package things are coming from. This CL is automatically generated by the script below. See the comments in the script for details about the changes. [git-generate] cd src/cmd/compile/internal/gc rf ' # These names were never fully qualified # when the types package was added. # Do it now, to avoid confusion about where they live. inline -rm \ Txxx \ TINT8 \ TUINT8 \ TINT16 \ TUINT16 \ TINT32 \ TUINT32 \ TINT64 \ TUINT64 \ TINT \ TUINT \ TUINTPTR \ TCOMPLEX64 \ TCOMPLEX128 \ TFLOAT32 \ TFLOAT64 \ TBOOL \ TPTR \ TFUNC \ TSLICE \ TARRAY \ TSTRUCT \ TCHAN \ TMAP \ TINTER \ TFORW \ TANY \ TSTRING \ TUNSAFEPTR \ TIDEAL \ TNIL \ TBLANK \ TFUNCARGS \ TCHANARGS \ NTYPE \ BADWIDTH # esc.go and escape.go do not need to be split. # Append esc.go onto the end of escape.go. mv esc.go escape.go # Pull out the type format installation from func Main, # so it can be carried into package ir. mv Main:/Sconv.=/-0,/TypeLinkSym/-1 InstallTypeFormats # Names that need to be exported for use by code left in gc. mv Isconst IsConst mv asNode AsNode mv asNodes AsNodes mv asTypesNode AsTypesNode mv basicnames BasicTypeNames mv builtinpkg BuiltinPkg mv consttype ConstType mv dumplist DumpList mv fdumplist FDumpList mv fmtMode FmtMode mv goopnames OpNames mv inspect Inspect mv inspectList InspectList mv localpkg LocalPkg mv nblank BlankNode mv numImport NumImport mv opprec OpPrec mv origSym OrigSym mv stmtwithinit StmtWithInit mv dump DumpAny mv fdump FDumpAny mv nod Nod mv nodl NodAt mv newname NewName mv newnamel NewNameAt mv assertRepresents AssertValidTypeForConst mv represents ValidTypeForConst mv nodlit NewLiteral # Types and fields that need to be exported for use by gc. mv nowritebarrierrecCallSym SymAndPos mv SymAndPos.lineno SymAndPos.Pos mv SymAndPos.target SymAndPos.Sym mv Func.lsym Func.LSym mv Func.setWBPos Func.SetWBPos mv Func.numReturns Func.NumReturns mv Func.numDefers Func.NumDefers mv Func.nwbrCalls Func.NWBRCalls # initLSym is an algorithm left behind in gc, # not an operation on Func itself. mv Func.initLSym initLSym mv nodeQueue NodeQueue mv NodeQueue.empty NodeQueue.Empty mv NodeQueue.popLeft NodeQueue.PopLeft mv NodeQueue.pushRight NodeQueue.PushRight # Many methods on Node are actually algorithms that # would apply to any node implementation. # Those become plain functions. mv Node.funcname FuncName mv Node.isBlank IsBlank mv Node.isGoConst isGoConst mv Node.isNil IsNil mv Node.isParamHeapCopy isParamHeapCopy mv Node.isParamStackCopy isParamStackCopy mv Node.isSimpleName isSimpleName mv Node.mayBeShared MayBeShared mv Node.pkgFuncName PkgFuncName mv Node.backingArrayPtrLen backingArrayPtrLen mv Node.isterminating isTermNode mv Node.labeledControl labeledControl mv Nodes.isterminating isTermNodes mv Nodes.sigerr fmtSignature mv Node.MethodName methodExprName mv Node.MethodFunc methodExprFunc mv Node.IsMethod IsMethod # Every node will need to implement RawCopy; # Copy and SepCopy algorithms will use it. mv Node.rawcopy Node.RawCopy mv Node.copy Copy mv Node.sepcopy SepCopy # Extract Node.Format method body into func FmtNode, # but leave method wrapper behind. mv Node.Format:0,$ FmtNode # Formatting helpers that will apply to all node implementations. mv Node.Line Line mv Node.exprfmt exprFmt mv Node.jconv jconvFmt mv Node.modeString modeString mv Node.nconv nconvFmt mv Node.nodedump nodeDumpFmt mv Node.nodefmt nodeFmt mv Node.stmtfmt stmtFmt # Constant support needed for code moving to ir. mv okforconst OKForConst mv vconv FmtConst mv int64Val Int64Val mv float64Val Float64Val mv Node.ValueInterface ConstValue # Organize code into files. mv LocalPkg BuiltinPkg ir.go mv NumImport InstallTypeFormats Line fmt.go mv syntax.go Nod NodAt NewNameAt Class Pxxx PragmaFlag Nointerface SymAndPos \ AsNode AsTypesNode BlankNode OrigSym \ Node.SliceBounds Node.SetSliceBounds Op.IsSlice3 \ IsConst Node.Int64Val Node.CanInt64 Node.Uint64Val Node.BoolVal Node.StringVal \ Node.RawCopy SepCopy Copy \ IsNil IsBlank IsMethod \ Node.Typ Node.StorageClass node.go mv ConstType ConstValue Int64Val Float64Val AssertValidTypeForConst ValidTypeForConst NewLiteral idealType OKForConst val.go # Move files to new ir package. mv bitset.go class_string.go dump.go fmt.go \ ir.go node.go op_string.go val.go \ sizeof_test.go cmd/compile/internal/ir ' : # fix mkbuiltin.go to generate the changes made to builtin.go during rf sed -i '' ' s/\[T/[types.T/g s/\*Node/*ir.Node/g /internal\/types/c \ fmt.Fprintln(&b, `import (`) \ fmt.Fprintln(&b, ` "cmd/compile/internal/ir"`) \ fmt.Fprintln(&b, ` "cmd/compile/internal/types"`) \ fmt.Fprintln(&b, `)`) ' mkbuiltin.go gofmt -w mkbuiltin.go : # update cmd/dist to add internal/ir cd ../../../dist sed -i '' '/compile.internal.gc/a\ "cmd/compile/internal/ir", ' buildtool.go gofmt -w buildtool.go : # update cmd/compile TestFormats cd ../.. go install std cmd cd cmd/compile go test -u || go test # first one updates but fails; second passes Change-Id: I5f7caf6b20629b51970279e81231a3574d5b51db Reviewed-on: https://go-review.googlesource.com/c/go/+/273008 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: introduce cmd/compile/internal/base [generated]Russ Cox2020-11-251-22/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move Flag, Debug, Ctxt, Exit, and error messages to new package cmd/compile/internal/base. These are the core functionality that everything in gc uses and which otherwise prevent splitting any other code out of gc into different packages. A minor milestone: the compiler source code no longer contains the string "yy". [git-generate] cd src/cmd/compile/internal/gc rf ' mv atExit AtExit mv Ctxt atExitFuncs AtExit Exit base.go mv lineno Pos mv linestr FmtPos mv flusherrors FlushErrors mv yyerror Errorf mv yyerrorl ErrorfAt mv yyerrorv ErrorfVers mv noder.yyerrorpos noder.errorAt mv Warnl WarnfAt mv errorexit ErrorExit mv base.go debug.go flag.go print.go cmd/compile/internal/base ' : # update comments sed -i '' 's/yyerrorl/ErrorfAt/g; s/yyerror/Errorf/g' *.go : # bootstrap.go is not built by default so invisible to rf sed -i '' 's/Fatalf/base.Fatalf/' bootstrap.go goimports -w bootstrap.go : # update cmd/dist to add internal/base cd ../../../dist sed -i '' '/internal.amd64/a\ "cmd/compile/internal/base", ' buildtool.go gofmt -w buildtool.go Change-Id: I59903c7084222d6eaee38823fd222159ba24a31a Reviewed-on: https://go-review.googlesource.com/c/go/+/272250 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: clean up debug flag (-d) handling [generated]Russ Cox2020-11-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The debug table is not as haphazard as flags, but there are still a few mismatches between command-line names and variable names. This CL moves them all into a consistent home (var Debug, like var Flag). Code updated automatically using the rf command below. A followup CL will make a few manual cleanups, leaving this CL completely automated and easier to regenerate during merge conflicts. [git-generate] cd src/cmd/compile/internal/gc rf ' add main.go var Debug struct{} mv Debug_append Debug.Append mv Debug_checkptr Debug.Checkptr mv Debug_closure Debug.Closure mv Debug_compilelater Debug.CompileLater mv disable_checknil Debug.DisableNil mv debug_dclstack Debug.DclStack mv Debug_gcprog Debug.GCProg mv Debug_libfuzzer Debug.Libfuzzer mv Debug_checknil Debug.Nil mv Debug_panic Debug.Panic mv Debug_slice Debug.Slice mv Debug_typeassert Debug.TypeAssert mv Debug_wb Debug.WB mv Debug_export Debug.Export mv Debug_pctab Debug.PCTab mv Debug_locationlist Debug.LocationLists mv Debug_typecheckinl Debug.TypecheckInl mv Debug_gendwarfinl Debug.DwarfInl mv Debug_softfloat Debug.SoftFloat mv Debug_defer Debug.Defer mv Debug_dumpptrs Debug.DumpPtrs mv flag.go:/parse.-d/-1,/unknown.debug/+2 parseDebug mv debugtab Debug parseDebug \ debugHelpHeader debugHelpFooter \ debug.go # Remove //go:generate line copied from main.go rm debug.go:/go:generate/-+ ' Change-Id: I625761ca5659be4052f7161a83baa00df75cca91 Reviewed-on: https://go-review.googlesource.com/c/go/+/272246 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: clean up flag handling [generated]Russ Cox2020-11-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The flag values have grown fairly haphazard, with no organization or even common naming convention. This CL moves all flag values into the Flag struct (formerly misnamed Debug), except for a few that live in Ctxt fields instead. This CL is entirely automated changes. A followup CL will make a few manual cleanups, leaving this CL completely automated and easier to regenerate during merge conflicts. Cleaning up flags is necessary because the printing routines look at some of them, and the printing routines need to move out of package gc to a new package shared by gc and any other packages that split out of gc. [git-generate] cd src/cmd/compile/internal/gc rf ' mv Debug Flag mv DebugFlags Flags mv Flags.e Flags.LowerE mv Flags.h Flags.LowerH mv Flags.j Flags.LowerJ mv Flags.l Flags.LowerL mv Flags.m Flags.LowerM mv Flags.r Flags.LowerR mv Flags.w Flags.LowerW mv Flags.P Flags.Percent mv compiling_runtime Flag.CompilingRuntime mv compiling_std Flag.Std mv localimport Flag.D mv asmhdr Flag.AsmHdr mv buildid Flag.BuildID mv nBackendWorkers Flag.LowerC mv pure_go Flag.Complete mv debugstr Flag.LowerD mv flagDWARF Flag.Dwarf mv genDwarfInline Flag.GenDwarfInl mv flag_installsuffix Flag.InstallSuffix mv flag_lang Flag.Lang mv linkobj Flag.LinkObj mv debuglive Flag.Live mv flag_msan Flag.MSan mv nolocalimports Flag.NoLocalImports mv outfile Flag.LowerO mv myimportpath Ctxt.Pkgpath mv writearchive Flag.Pack mv flag_race Flag.Race mv spectre Flag.Spectre mv trace Flag.LowerT mv pathPrefix Flag.TrimPath mv Debug_vlog Ctxt.Debugvlog mv use_writebarrier Flag.WB mv Main.flag_shared Flag.Shared mv Main.flag_dynlink Flag.Dynlink mv Main.goversion Flag.GoVersion mv Main.symabisPath Flag.SymABIs mv cpuprofile Flag.CPUProfile mv memprofile Flag.MemProfile mv traceprofile Flag.TraceProfile mv blockprofile Flag.BlockProfile mv mutexprofile Flag.MutexProfile mv benchfile Flag.Bench mv Main.smallFrames Flag.SmallFrames mv Main.jsonLogOpt Flag.JSON add Flag:$ \ Cfg struct{} mv embedCfg Flag.Cfg.Embed mv idirs Flag.Cfg.ImportDirs mv importMap Flag.Cfg.ImportMap mv packageFile Flag.Cfg.PackageFile mv spectreIndex Flag.Cfg.SpectreIndex mv addidir addImportDir mv main.go:/Wasm/-0,/ssaDump/-3 ParseFlags mv usage Flag Flags ParseFlags \ concurrentFlagOk concurrentBackendAllowed \ addImportDir addImportMap \ readImportCfg readEmbedCfg \ flag.go # Remove //go:generate line copied from main.go # along with two self-assignments from the merge. rm flag.go:/go:generate/-+ \ flag.go:/Ctxt.Pkgpath = Ctxt.Pkgpath/-+ \ flag.go:/Ctxt.Debugvlog = Ctxt.Debugvlog/-+ ' Change-Id: I10431c15fe7d9f48024d53141d4224d957dbf334 Reviewed-on: https://go-review.googlesource.com/c/go/+/271667 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.regabi] cmd/compile: clean up Node.FuncRuss Cox2020-11-241-78/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original meaning of type Func was "extra fields factored out of a few cases of type Node having to do with functions", but those specific cases didn't necessarily have any relation. A typical declared function is represented by an ODCLFUNC Node at its declaration and an ONAME node at its uses, and both those have a .Func field, but they are *different* Funcs. Similarly, a closure is represented both by an OCLOSURE Node for the value itself and an ODCLFUNC Node for the underlying function implementing the closure. Those too have *different* Funcs, and the Func.Closure field in one points to the other and vice versa. This has led to no end of confusion over the years. This CL elevates type Func to be the canonical identifier for a given Go function. This looks like a trivial CL but in fact is the result of a lot of scaffolding and rewriting, discarded once the result was achieved, to separate out the three different kinds of Func nodes into three separate fields, limited in use to each specific Node type, to understand which Func fields are used by which Node types and what the possible overlaps are. There were a few overlaps, most notably around closures, which led to more fields being added to type Func to keep them separate even though there is now a single Func instead of two different ones for each function. A future CL can and should change Curfn to be a *Func instead of a *Node, finally eliminating the confusion about whether Curfn is an ODCLFUNC node (as it is most of the time) or an ONAME node (as it is when type-checking an inlined function body). Although sizeof_test.go makes it look like Func is growing by two words, there are now half as many Funcs in a running compilation, so the memory footprint has actually been reduced substantially. Change-Id: I598bd96c95728093dc769a835d48f2154a406a61 Reviewed-on: https://go-review.googlesource.com/c/go/+/272253 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>
* [dev.regabi] cmd/compile/internal/gc: add MethodName for getting referenced ↵Matthew Dempsky2020-11-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | method A common operation throughout the front end is getting the ONAME for a method used in a method selector, method expression, or method value. This CL adds MethodName as a uniform API for doing this for all of these kinds of nodes. For method selectors (ODOTMETH) and method expressions (ONAMEs where isMethodExpression reports true), we take advantage of the Node.Opt field to save the types.Field. This is the approach we already started taking in golang.org/cl/271217 (caching types.Field in Node.Opt for ODOT). For method values (OCALLPART), we continue using the existing callpartMethod helper function. Escape analysis already uses Node.Opt for tracking the method value's closure's data flow. A subsequent, automated refactoring CL will make more use of this method. For now, we just address a few cases in inl.go that aren't easily automated. Passes toolstash-check. Change-Id: Ic92b288b2d8b2fa7e18e3b68634326b8ef0d869b Reviewed-on: https://go-review.googlesource.com/c/go/+/272387 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>
* [dev.regabi] cmd/compile/internal/types: add pos/sym/typ params to NewFieldMatthew Dempsky2020-11-241-3/+2
| | | | | | | | | | | | | | | These are almost always set, so might as well expect callers to provide them. They're also all required by go/types's corresponding New{Field,Func,Param,Var} functions, so this eases API compatibility. Passes toolstash-check. Change-Id: Ib3fa355d4961243cd285b41915e87652ae2c22f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/272386 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: update comments only for Node types and some functionsDan Scales2020-11-131-0/+4
| | | | | | | | | | Improve the comments in syntax.go on Node structs and constants. Also, updated a few function header comments. Change-Id: I3e6e4a3c5678fc0b4e18844507b3460303ce1240 Reviewed-on: https://go-review.googlesource.com/c/go/+/269538 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com>
* cmd/compile: make gc debug flags collector a structAlberto Donizetti2020-10-221-1/+1
| | | | | | | | | | | | | | | | | | gc debug flags are currently stored in a 256-long array, that is then addressed using the ASCII numeric value of the flag itself (a quirk inherited from the old C compiler). It is also a little wasteful, since we only define 16 flags, and the other 240 array elements are always empty. This change makes Debug a struct, which also provides static checking that we're not referencing flags that does not exist. Change-Id: I2f0dfef2529325514b3398cf78635543cdf48fe0 Reviewed-on: https://go-review.googlesource.com/c/go/+/263539 Trust: Alberto Donizetti <alb.donizetti@gmail.com> Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* cmd/compile: allowing inlining of functions with OCALLPARTDan Scales2020-10-201-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | OCALLPART is exported in its original form, which is as an OXDOT. The body of the method value wrapper created in makepartialcall() was not being typechecked, and that was causing a problem during escape analysis, so I added code to typecheck the body. The go executable got slightly bigger with this change (13598111 -> 13598905), because of extra exported methods with OCALLPART (I believe), while the text size got slightly smaller (9686964 -> 9686643). This is mainly part of the work to make sure all function bodies can be exported (for purposes of generics), but might as well fix the OCALLPART inlining bug as well. Fixes #18493 Change-Id: If7aa055ff78ed7a6330c6a1e22f836ec567d04fd Reviewed-on: https://go-review.googlesource.com/c/go/+/263620 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>
* cmd/compile: do not declare func nodesCuong Manh Le2020-09-031-13/+1
| | | | | | | | | | | | | | The primary responsibility of declare() to associate a symbol (Sym) with a declaration (Node), so "oldname" will work. Function literals are anonymous, so their symbols does not need to be declared. Passes toolstash-check. Change-Id: I739b1054e3953e85fbd74a99148b9cfd7e5a57eb Reviewed-on: https://go-review.googlesource.com/c/go/+/249078 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* cmd/compile: don't bother to declare closure inside redeclared funcCuong Manh Le2020-08-191-1/+11
| | | | | | | | | | Fixes #17758 Change-Id: I75f5dc5be85fd8a6791ac89dfc0681be759cca36 Reviewed-on: https://go-review.googlesource.com/c/go/+/248517 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/compile: handle OCLOSURE/OCALLPART in mustHeapAlloc checkCuong Manh Le2020-08-151-1/+1
| | | | | | | | | | | | | | Currently, generated struct wrapper for closure is not handled in mustHeapAlloc. That causes compiler crashes when the wrapper struct is too large for stack, and must be heap allocated instead. Fixes #39292 Change-Id: I14c1e591681d9d92317bb2396d6cf5207aa93e08 Reviewed-on: https://go-review.googlesource.com/c/go/+/244917 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* [dev.link] move FuncID creation into the compiler/assemblerJeremy Faller2020-08-031-0/+1
| | | | | | | | | | | | | | | Leaving creation of the funcID till the linker requires the linker to load the function and file names into memory. Moving these into the compiler/assembler prevents this. This work is a step towards moving all func metadata into the compiler. Change-Id: Iebffdc5a909adbd03ac263fde3f4c3d492fb1eac Reviewed-on: https://go-review.googlesource.com/c/go/+/244024 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Austin Clements <austin@google.com>
* cmd/compile: more precise analysis of method valuesMatthew Dempsky2020-04-211-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously for a method value "x.M", we always flowed x directly to the heap, which led to the receiver argument generally needing to be heap allocated. This CL changes it to flow x to the closure and M's receiver parameter. This allows receiver arguments to be stack allocated as long as (1) the closure never escapes, *and* (2) method doesn't leak its receiver parameter. Within the standard library, this allows a handful of objects to be stack allocated instead. Listed here are diagnostics that were previously emitted by "go build -gcflags=-m std cmd" that are no longer emitted: archive/tar/writer.go:118:6: moved to heap: f archive/tar/writer.go:208:6: moved to heap: f archive/tar/writer.go:248:6: moved to heap: f cmd/compile/internal/gc/initorder.go:252:2: moved to heap: d cmd/compile/internal/gc/initorder.go:75:2: moved to heap: s cmd/go/internal/generate/generate.go:206:7: &Generator literal escapes to heap cmd/internal/obj/arm64/asm7.go:910:2: moved to heap: c cmd/internal/obj/mips/asm0.go:415:2: moved to heap: c cmd/internal/obj/pcln.go:294:22: new(pcinlineState) escapes to heap cmd/internal/obj/s390x/asmz.go:459:2: moved to heap: c crypto/tls/handshake_server.go:56:2: moved to heap: hs Thanks to Cuong Manh Le for help coming up with this solution. Fixes #27557. Change-Id: I8c85d671d07fb9b53e11d2dd05949a34dbbd7e17 Reviewed-on: https://go-review.googlesource.com/c/go/+/228263 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/compile: remove period from "not allowed in runtime" errorsMatthew Dempsky2019-10-141-1/+1
| | | | | | | | We don't punctuate compiler diagnostics. Change-Id: I19e1f30fbf04f0d1bfe6648fae26beaf3a06ee92 Reviewed-on: https://go-review.googlesource.com/c/go/+/201077 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* cmd/compile: move some ONAME-specific flags from Node to NameMatthew Dempsky2019-10-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The IsClosureVar, IsOutputParamHeapAddr, Assigned, Addrtaken, InlFormal, and InlLocal flags are only interesting for ONAME nodes, so it's better to set these flags on Name.flags instead of Node.flags. Two caveats though: 1. Previously, we would set Assigned and Addrtaken on the entire expression tree involved in an assignment or addressing operation. However, the rest of the compiler only actually cares about knowing whether the underlying ONAME (if any) was assigned/addressed. 2. This actually requires bumping Name.flags from bitset8 to bitset16, whereas it doesn't allow shrinking Node.flags any. However, Name has some trailing padding bytes, so expanding Name.flags doesn't cost any memory. Passes toolstash-check. Change-Id: I7775d713566a38d5b9723360b1659b79391744c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/200898 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* cmd/compile: simplify OPTRLIT handlingMatthew Dempsky2019-09-261-12/+8
| | | | | | | | | | | | | | | | | | | | | Previously, we would recognize &(T{...}) expressions during type checking, rewrite them into (*T){...}, and then do a lot of extra work to make sure the user doesn't write (*T){...} themselves and resynthesizing the OPTRLIT later on. This CL simply handles &T{...} directly in the straight forward manner, by changing OADDR directly to OPTRLIT when appropriate. While here, match go/types's invalid composite literal type error message. Passes toolstash-check. Change-Id: I902b14c7e2cd9fa93e6915dd58272d2352ba38f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/197120 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* cmd/compile: allow iota inside function in a ConstSpecCuong Manh Le2019-09-121-0/+6
| | | | | | | | | | Fixes #22344 Change-Id: I7c400d9d4ebcab279d08a8c190508d82cbd20899 Reviewed-on: https://go-review.googlesource.com/c/go/+/194717 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* cmd/compile: rename Etype to ctxTypeMatthew Dempsky2019-09-061-1/+1
| | | | | | | | | | | | | golang.org/cl/150140 renamed the other Efoo constants to ctxFoo, but forgot about Etype. gorename -from '"cmd/compile/internal/gc".Etype -to ctxType Change-Id: I142dd42ca84a398f8d2316d75ead3331c023b820 Reviewed-on: https://go-review.googlesource.com/c/go/+/193958 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
* cmd/compile: fix capture-by-reference of return parametersMatthew Dempsky2019-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | As an optimization, function literals capture variables by value when they're not assigned and their address has not been taken. Because result parameters are implicitly assigned through return statements (which do not otherwise set the "assigned" flag), result parameters are explicitly handled to always capture by reference. However, the logic was slightly mistaken because it was only checking if the variable in the immediately enclosing context was a return parameter, whereas in a multiply-nested function literal it would itself be another closure variable (PAUTOHEAP) rather than a return parameter (PPARAMOUT). The fix is to simply test the outermost variable, like the rest of the if statement's tests were already doing. Fixes #32175. Change-Id: Ibadde033ff89a1b47584b3f56c0014d8e5a74512 Reviewed-on: https://go-review.googlesource.com/c/go/+/178541 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/compile: fix const declaration group broken with closureLE Manh Cuong2019-04-161-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | In typecheckclosure, a xfunc node will be put to xtop. But that node can be shared between multiple closures, like in a const declaration group: const ( x = unsafe.Sizeof(func() {}) y ) It makes a xfunc node appears multiple times in xtop, causing duplicate initLSym run. To fix this issue, we only do typecheck for xfunc one time, and setup closure node earlier in typecheckclosure process. Fixes #30709 Change-Id: Ic924a157ee9f3e5d776214bef5390849ddc8aab9 Reviewed-on: https://go-review.googlesource.com/c/go/+/172298 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/compile: inline checknilJosh Bleecher Snyder2019-02-261-1/+7
| | | | | | | | | | | | Now that checknil has only a single caller, inline it. Passes toolstash-check. Change-Id: I5b13596bef84dd9a3e7f4bff8560903f1e54acfb Reviewed-on: https://go-review.googlesource.com/c/148829 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>