aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/func.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-09 00:57:55 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-14 02:07:48 +0000
commitef5285fbd0636965d916c81dbf87834731f337b2 (patch)
tree005d62b2e4f8bb7373b93d467fb749696d23ef66 /src/cmd/compile/internal/noder/func.go
parentf065ff221b546c9ac550d947f89eb3b44b11fc2f (diff)
downloadgo-ef5285fbd0636965d916c81dbf87834731f337b2.tar.gz
go-ef5285fbd0636965d916c81dbf87834731f337b2.zip
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2 to guide IR construction. Notably, it completely skips dealing with constant and type expressions (aside from using ir.TypeNode to interoperate with the types1 typechecker), because types2 already handled those. It also omits any syntax checking, trusting that types2 already rejected any errors. It currently still utilizes the types1 typechecker for the desugaring operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting implicit conversions, rewriting f(g()) functions, and so on). However, the IR is constructed in a fully incremental fashion, so it should be easy to now piecemeal replace those dependencies as needed. Nearly all of "go test std cmd" passes with -G=3 enabled by default. The main remaining blocker is the number of test/run.go failures. There also appear to be cases where types2 does not provide us with position information. These will be iterated upon. Portions and ideas from Dan Scales's CL 276653. Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d Reviewed-on: https://go-review.googlesource.com/c/go/+/281932 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/func.go')
-rw-r--r--src/cmd/compile/internal/noder/func.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/noder/func.go b/src/cmd/compile/internal/noder/func.go
new file mode 100644
index 0000000000..702138157c
--- /dev/null
+++ b/src/cmd/compile/internal/noder/func.go
@@ -0,0 +1,74 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package noder
+
+import (
+ "cmd/compile/internal/base"
+ "cmd/compile/internal/ir"
+ "cmd/compile/internal/syntax"
+ "cmd/compile/internal/typecheck"
+ "cmd/compile/internal/types"
+ "cmd/internal/src"
+)
+
+func (g *irgen) funcBody(fn *ir.Func, recv *syntax.Field, sig *syntax.FuncType, block *syntax.BlockStmt) {
+ typecheck.Func(fn)
+
+ // TODO(mdempsky): Remove uses of ir.CurFunc and
+ // typecheck.DeclContext after we stop relying on typecheck
+ // for desugaring.
+ outerfn, outerctxt := ir.CurFunc, typecheck.DeclContext
+ ir.CurFunc = fn
+
+ typ := fn.Type()
+ if param := typ.Recv(); param != nil {
+ g.defParam(param, recv, ir.PPARAM)
+ }
+ for i, param := range typ.Params().FieldSlice() {
+ g.defParam(param, sig.ParamList[i], ir.PPARAM)
+ }
+ for i, result := range typ.Results().FieldSlice() {
+ g.defParam(result, sig.ResultList[i], ir.PPARAMOUT)
+ }
+
+ // We may have type-checked a call to this function already and
+ // calculated its size, including parameter offsets. Now that we've
+ // created the parameter Names, force a recalculation to ensure
+ // their offsets are correct.
+ typ.Align = 0
+ types.CalcSize(typ)
+
+ if block != nil {
+ typecheck.DeclContext = ir.PAUTO
+
+ fn.Body = g.stmts(block.List)
+ if fn.Body == nil {
+ fn.Body = []ir.Node{ir.NewBlockStmt(src.NoXPos, nil)}
+ }
+ fn.Endlineno = g.makeXPos(block.Rbrace)
+
+ if base.Flag.Dwarf {
+ g.recordScopes(fn, sig)
+ }
+ }
+
+ ir.CurFunc, typecheck.DeclContext = outerfn, outerctxt
+}
+
+func (g *irgen) defParam(param *types.Field, decl *syntax.Field, class ir.Class) {
+ typecheck.DeclContext = class
+
+ var name *ir.Name
+ if decl.Name != nil {
+ name, _ = g.def(decl.Name)
+ } else if class == ir.PPARAMOUT {
+ name = g.obj(g.info.Implicits[decl])
+ }
+
+ if name != nil {
+ param.Nname = name
+ param.Sym = name.Sym() // in case it was renamed
+ }
+}