Skip to content

Commit b0bbfb1

Browse files
timothy-kingGo LUCI
authored and
Go LUCI
committed
cmd/compile/internal/importer: drop support for indexed format
Drop support for the indexed format from the test-only Import function. Adds several TODOs for further tech debt reduction. Change-Id: I45cc5ffce43082a145ccb918face067cdccc5ecd Reviewed-on: https://go-review.googlesource.com/c/go/+/626695 Commit-Queue: Tim King <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 64e7f66 commit b0bbfb1

File tree

5 files changed

+26
-810
lines changed

5 files changed

+26
-810
lines changed

src/cmd/compile/internal/importer/exportdata.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
)
1616

1717
func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
18+
// TODO(taking): replace with src/cmd/internal/archive.ReadHeader.
19+
1820
// See $GOROOT/include/ar.h.
1921
hdr := make([]byte, 16+12+6+6+8+10+2)
2022
_, err = io.ReadFull(r, hdr)
@@ -43,7 +45,12 @@ func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
4345
//
4446
// If size is non-negative, it's the number of bytes of export data
4547
// still available to read from r.
48+
//
49+
// This function should only be used in tests.
4650
func FindExportData(r *bufio.Reader) (hdr string, size int, err error) {
51+
// TODO(taking): Move into a src/internal package then
52+
// dedup with cmd/compile/internal/noder.findExportData and go/internal/gcimporter.FindExportData.
53+
4754
// Read first line to make sure this is an object file.
4855
line, err := r.ReadSlice('\n')
4956
if err != nil {
@@ -71,6 +78,7 @@ func FindExportData(r *bufio.Reader) (hdr string, size int, err error) {
7178
return
7279
}
7380
}
81+
// TODO(taking): The else case is likely dead. Otherwise, size<0. Return an error instead.
7482

7583
// Now at __.PKGDEF in archive or still at beginning of file.
7684
// Either way, line should begin with "go object ".

src/cmd/compile/internal/importer/gcimporter.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// package importer implements Import for gc-generated object files.
5+
// This file contains the FindPkg and Import functions for tests
6+
// to use gc-generated object files.
7+
68
package importer
79

810
import (
@@ -75,7 +77,11 @@ var pkgExts = [...]string{".a", ".o"} // a file from the build cache will have n
7577
// path based on package information provided by build.Import (using
7678
// the build.Default build.Context). A relative srcDir is interpreted
7779
// relative to the current working directory.
80+
//
81+
// This function should only be used in tests.
7882
func FindPkg(path, srcDir string) (filename, id string, err error) {
83+
// TODO(taking): move FindPkg into src/internal and dedup src/go/internal/gcimporter.FindPkg
84+
7985
if path == "" {
8086
return "", "", errors.New("path is empty")
8187
}
@@ -147,6 +153,8 @@ notfound:
147153
// Import imports a gc-generated package given its import path and srcDir, adds
148154
// the corresponding package object to the packages map, and returns the object.
149155
// The packages map must contain all packages already imported.
156+
//
157+
// This function should only be used in tests.
150158
func Import(packages map[string]*types2.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types2.Package, err error) {
151159
var rc io.ReadCloser
152160
var id string
@@ -208,6 +216,7 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
208216
err = fmt.Errorf("import %q: old textual export format no longer supported (recompile library)", path)
209217

210218
case "$$B\n":
219+
// TODO(taking): minimize code delta with src/go/internal/gcimporter.Import.
211220
var data []byte
212221
var r io.Reader = buf
213222
if size >= 0 {
@@ -225,18 +234,18 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
225234
exportFormat := data[0]
226235
s := string(data[1:])
227236

228-
// The indexed export format starts with an 'i'; the older
229-
// binary export format starts with a 'c', 'd', or 'v'
230-
// (from "version"). Select appropriate importer.
237+
// The unified export format starts with a 'u'; the indexed export
238+
// format starts with an 'i'; and the older binary export format
239+
// starts with a 'c', 'd', or 'v' (from "version"). Select
240+
// appropriate importer.
231241
switch exportFormat {
232242
case 'u':
243+
// TODO(taking): Look into whether this should be LastIndex instead of Index.
233244
s = s[:strings.Index(s, "\n$$\n")]
234245
input := pkgbits.NewPkgDecoder(id, s)
235246
pkg = ReadPackage(nil, packages, input)
236-
case 'i':
237-
pkg, err = ImportData(packages, s, id)
238247
default:
239-
err = fmt.Errorf("import %q: old binary export format no longer supported (recompile library)", path)
248+
err = fmt.Errorf("import %q: binary export format %q is no longer supported (recompile package)", path, exportFormat)
240249
}
241250

242251
default:

0 commit comments

Comments
 (0)