diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-04 13:14:32 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-05 23:29:09 +0000 |
commit | a5be3eaee2cc0b8e5da216bdf545b9ca44789892 (patch) | |
tree | 6c22f8db592b5fe5bf27e405485a7263ef82c3d0 /src/cmd/compile/internal/typecheck/iexport.go | |
parent | 4c072c94dc2ffedd29d51d04aba2e1a6f2afd93f (diff) | |
download | go-a5be3eaee2cc0b8e5da216bdf545b9ca44789892.tar.gz go-a5be3eaee2cc0b8e5da216bdf545b9ca44789892.zip |
[dev.typeparams] cmd/compile: refactor export writing
This CL reorganizes export writing in preparation for unified IR:
1. It moves dumpexport into noder as noder.WriteExports so that it can
be extended to include unified IR's export data.
2. Adds an "extensions" flag to typecheck.WriteExports to control
whether the compiler-only extension data (e.g., function bodies and
linker symbol info) is included in the exports.
3. It moves the gc.exporter type into typecheck and renames it to
"crawler". The type originated as the implementation of
the (pre-iexport) binary exporter, but since the removal of bexport
it's been relegated to simply crawling the exported functions/bodies
graph to identify which inline bodies need to be included.
4. It changes inline.Inline_Flood into the method crawler.markInlBody.
Inline_Flood doesn't actually have anything to do with the rest of
inlining; its current name and location are just historical quirks.
Passes toolstash -cmp.
Change-Id: I6445e2de9d3ce500a3aded5a8e20b09f46d23dbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/325212
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iexport.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/iexport.go | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 3bfbea11c0..6987bc9918 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -204,7 +204,6 @@ package typecheck import ( - "bufio" "bytes" "crypto/md5" "encoding/binary" @@ -264,13 +263,22 @@ const ( magic = 0x6742937dc293105 ) -func WriteExports(out *bufio.Writer) { +// WriteExports writes the indexed export format to out. If extensions +// is true, then the compiler-only extensions are included. +func WriteExports(out io.Writer, extensions bool) { + if extensions { + // If we're exporting inline bodies, invoke the crawler to mark + // which bodies to include. + crawlExports(Target.Exports) + } + p := iexporter{ allPkgs: map[*types.Pkg]bool{}, stringIndex: map[string]uint64{}, declIndex: map[*types.Sym]uint64{}, inlineIndex: map[*types.Sym]uint64{}, typIndex: map[*types.Type]uint64{}, + extensions: extensions, } for i, pt := range predeclared() { @@ -397,6 +405,8 @@ type iexporter struct { declIndex map[*types.Sym]uint64 inlineIndex map[*types.Sym]uint64 typIndex map[*types.Type]uint64 + + extensions bool } // stringOff returns the offset of s within the string section. @@ -467,7 +477,9 @@ func (p *iexporter) doDecl(n *ir.Name) { w.tag('V') w.pos(n.Pos()) w.typ(n.Type()) - w.varExt(n) + if w.p.extensions { + w.varExt(n) + } case ir.PFUNC: if ir.IsMethod(n) { @@ -487,7 +499,9 @@ func (p *iexporter) doDecl(n *ir.Name) { w.tparamList(n.Type().TParams().FieldSlice()) } w.signature(n.Type()) - w.funcExt(n) + if w.p.extensions { + w.funcExt(n) + } default: base.Fatalf("unexpected class: %v, %v", n, n.Class) @@ -503,7 +517,9 @@ func (p *iexporter) doDecl(n *ir.Name) { w.tag('C') w.pos(n.Pos()) w.value(n.Type(), n.Val()) - w.constExt(n) + if w.p.extensions { + w.constExt(n) + } case ir.OTYPE: if n.Type().Kind() == types.TTYPEPARAM && n.Type().Underlying() == n.Type() { @@ -551,7 +567,9 @@ func (p *iexporter) doDecl(n *ir.Name) { t := n.Type() if t.IsInterface() { - w.typeExt(t) + if w.p.extensions { + w.typeExt(t) + } break } @@ -567,9 +585,11 @@ func (p *iexporter) doDecl(n *ir.Name) { w.signature(m.Type) } - w.typeExt(t) - for _, m := range methods { - w.methExt(m) + if w.p.extensions { + w.typeExt(t) + for _, m := range methods { + w.methExt(m) + } } default: |