Skip to content

Commit

Permalink
cmd/compile/internal/importer: drop support for indexed format
Browse files Browse the repository at this point in the history
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 <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
timothy-king authored and Go LUCI committed Nov 8, 2024
1 parent 64e7f66 commit b0bbfb1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 810 deletions.
8 changes: 8 additions & 0 deletions src/cmd/compile/internal/importer/exportdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
// TODO(taking): replace with src/cmd/internal/archive.ReadHeader.

// See $GOROOT/include/ar.h.
hdr := make([]byte, 16+12+6+6+8+10+2)
_, err = io.ReadFull(r, hdr)
Expand Down Expand Up @@ -43,7 +45,12 @@ func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
//
// If size is non-negative, it's the number of bytes of export data
// still available to read from r.
//
// This function should only be used in tests.
func FindExportData(r *bufio.Reader) (hdr string, size int, err error) {
// TODO(taking): Move into a src/internal package then
// dedup with cmd/compile/internal/noder.findExportData and go/internal/gcimporter.FindExportData.

// Read first line to make sure this is an object file.
line, err := r.ReadSlice('\n')
if err != nil {
Expand Down Expand Up @@ -71,6 +78,7 @@ func FindExportData(r *bufio.Reader) (hdr string, size int, err error) {
return
}
}
// TODO(taking): The else case is likely dead. Otherwise, size<0. Return an error instead.

// Now at __.PKGDEF in archive or still at beginning of file.
// Either way, line should begin with "go object ".
Expand Down
23 changes: 16 additions & 7 deletions src/cmd/compile/internal/importer/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// package importer implements Import for gc-generated object files.
// This file contains the FindPkg and Import functions for tests
// to use gc-generated object files.

package importer

import (
Expand Down Expand Up @@ -75,7 +77,11 @@ var pkgExts = [...]string{".a", ".o"} // a file from the build cache will have n
// path based on package information provided by build.Import (using
// the build.Default build.Context). A relative srcDir is interpreted
// relative to the current working directory.
//
// This function should only be used in tests.
func FindPkg(path, srcDir string) (filename, id string, err error) {
// TODO(taking): move FindPkg into src/internal and dedup src/go/internal/gcimporter.FindPkg

if path == "" {
return "", "", errors.New("path is empty")
}
Expand Down Expand Up @@ -147,6 +153,8 @@ notfound:
// Import imports a gc-generated package given its import path and srcDir, adds
// the corresponding package object to the packages map, and returns the object.
// The packages map must contain all packages already imported.
//
// This function should only be used in tests.
func Import(packages map[string]*types2.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types2.Package, err error) {
var rc io.ReadCloser
var id string
Expand Down Expand Up @@ -208,6 +216,7 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
err = fmt.Errorf("import %q: old textual export format no longer supported (recompile library)", path)

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

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

default:
Expand Down
Loading

0 comments on commit b0bbfb1

Please sign in to comment.