aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-06-16 10:29:21 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-06-16 06:10:32 +0000
commitee0420d3b56982cb1600dc141dfd4be155adddfe (patch)
treec550e420440b13a2d3358b4573a54a508d98162f /src
parentcf1ae5fc364eb7f2ee5203e4c5e30411c3cfe01f (diff)
downloadgo-ee0420d3b56982cb1600dc141dfd4be155adddfe.tar.gz
go-ee0420d3b56982cb1600dc141dfd4be155adddfe.zip
[dev.typeparams] cmd/compile: factor out implicit/explicit handling
The logic for handling them must keep in sync between reader/writer, so factoring them out from addBody make it's easier to refer later. Change-Id: I26447065867d79f4f47cc678a398b9e7bf5d2403 Reviewed-on: https://go-review.googlesource.com/c/go/+/328051 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/noder/reader.go15
-rw-r--r--src/cmd/compile/internal/noder/sync.go1
-rw-r--r--src/cmd/compile/internal/noder/writer.go11
3 files changed, 21 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index 18ecbff3cc..803acaa88d 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -789,18 +789,25 @@ var bodyReader = map[*ir.Func]pkgReaderIndex{}
// constructed.
var todoBodies []*ir.Func
-func (r *reader) addBody(fn *ir.Func) {
- r.sync(syncAddBody)
+// Keep in sync with writer.implicitTypes
+// Also see comment there for why r.implicits and r.explicits should
+// never both be non-empty.
+func (r *reader) implicitTypes() []*types.Type {
+ r.sync(syncImplicitTypes)
- // See commont in writer.addBody for why r.implicits and r.explicits
- // should never both be non-empty.
implicits := r.implicits
if len(implicits) == 0 {
implicits = r.explicits
} else {
assert(len(r.explicits) == 0)
}
+ return implicits
+}
+
+func (r *reader) addBody(fn *ir.Func) {
+ r.sync(syncAddBody)
+ implicits := r.implicitTypes()
pri := pkgReaderIndex{r.p, r.reloc(relocBody), implicits}
bodyReader[fn] = pri
diff --git a/src/cmd/compile/internal/noder/sync.go b/src/cmd/compile/internal/noder/sync.go
index d77a784479..7326a6edbe 100644
--- a/src/cmd/compile/internal/noder/sync.go
+++ b/src/cmd/compile/internal/noder/sync.go
@@ -151,4 +151,5 @@ const (
syncLocalIdent
syncTypeParamNames
syncTypeParamBounds
+ syncImplicitTypes
)
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index b39dd8651b..1475540d84 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -665,7 +665,9 @@ func (w *writer) pragmaFlag(p ir.PragmaFlag) {
// @@@ Function bodies
-func (w *writer) addBody(sig *types2.Signature, block *syntax.BlockStmt, localsIdx map[types2.Object]int) {
+func (w *writer) implicitTypes() map[*types2.TypeParam]int {
+ w.sync(syncImplicitTypes)
+
// TODO(mdempsky): Theoretically, I think at this point we want to
// extend the implicit type parameters list with any new explicit
// type parameters.
@@ -684,9 +686,14 @@ func (w *writer) addBody(sig *types2.Signature, block *syntax.BlockStmt, localsI
} else {
assert(len(w.explicitIdx) == 0)
}
+ return implicitIdx
+}
+func (w *writer) addBody(sig *types2.Signature, block *syntax.BlockStmt, localsIdx map[types2.Object]int) {
w.sync(syncAddBody)
- w.reloc(relocBody, w.p.bodyIdx(w.p.curpkg, sig, block, implicitIdx, localsIdx))
+
+ implicits := w.implicitTypes()
+ w.reloc(relocBody, w.p.bodyIdx(w.p.curpkg, sig, block, implicits, localsIdx))
}
func (pw *pkgWriter) bodyIdx(pkg *types2.Package, sig *types2.Signature, block *syntax.BlockStmt, implicitIdx map[*types2.TypeParam]int, localsIdx map[types2.Object]int) int {