-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/gcimporter: remove bug report on objectpath failure
As reported in golang/go#61674, there are certain cases involving instantiated fields that simply can't be encoded using objectpaths. Therefore, the workaround is fundamentally insufficient, and should probably be removed or made irrelevant (golang/go#61674). In the meantime, update commentary and remove the bug report. Update the gopls regression test for this behavior to exercise the objectpath failure. While at it, ensure that the marker regtests panic on bugs, like all other regtests. This ran into an existing imprecise bug report, which is amended. Updates golang/go#61674 Change-Id: I0eaea00d46cec88ac4c20cebdde805a7db3a33ad Reviewed-on: https://go-review.googlesource.com/c/tools/+/514575 gopls-CI: kokoro <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
- Loading branch information
Showing
5 changed files
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ func IExportShallow(fset *token.FileSet, pkg *types.Package, reportf ReportFunc) | |
// TODO(adonovan): use byte slices throughout, avoiding copying. | ||
const bundle, shallow = false, true | ||
var out bytes.Buffer | ||
err := iexportCommon(&out, fset, bundle, shallow, iexportVersion, []*types.Package{pkg}, reportf) | ||
err := iexportCommon(&out, fset, bundle, shallow, iexportVersion, []*types.Package{pkg}) | ||
return out.Bytes(), err | ||
} | ||
|
||
|
@@ -86,16 +86,16 @@ const bundleVersion = 0 | |
// so that calls to IImportData can override with a provided package path. | ||
func IExportData(out io.Writer, fset *token.FileSet, pkg *types.Package) error { | ||
const bundle, shallow = false, false | ||
return iexportCommon(out, fset, bundle, shallow, iexportVersion, []*types.Package{pkg}, nil) | ||
return iexportCommon(out, fset, bundle, shallow, iexportVersion, []*types.Package{pkg}) | ||
} | ||
|
||
// IExportBundle writes an indexed export bundle for pkgs to out. | ||
func IExportBundle(out io.Writer, fset *token.FileSet, pkgs []*types.Package) error { | ||
const bundle, shallow = true, false | ||
return iexportCommon(out, fset, bundle, shallow, iexportVersion, pkgs, nil) | ||
return iexportCommon(out, fset, bundle, shallow, iexportVersion, pkgs) | ||
} | ||
|
||
func iexportCommon(out io.Writer, fset *token.FileSet, bundle, shallow bool, version int, pkgs []*types.Package, reportf ReportFunc) (err error) { | ||
func iexportCommon(out io.Writer, fset *token.FileSet, bundle, shallow bool, version int, pkgs []*types.Package) (err error) { | ||
if !debug { | ||
defer func() { | ||
if e := recover(); e != nil { | ||
|
@@ -113,7 +113,6 @@ func iexportCommon(out io.Writer, fset *token.FileSet, bundle, shallow bool, ver | |
fset: fset, | ||
version: version, | ||
shallow: shallow, | ||
reportf: reportf, | ||
allPkgs: map[*types.Package]bool{}, | ||
stringIndex: map[string]uint64{}, | ||
declIndex: map[types.Object]uint64{}, | ||
|
@@ -330,7 +329,6 @@ type iexporter struct { | |
|
||
shallow bool // don't put types from other packages in the index | ||
objEncoder *objectpath.Encoder // encodes objects from other packages in shallow mode; lazily allocated | ||
reportf ReportFunc // if non-nil, used to report bugs | ||
localpkg *types.Package // (nil in bundle mode) | ||
|
||
// allPkgs tracks all packages that have been referenced by | ||
|
@@ -917,22 +915,25 @@ func (w *exportWriter) objectPath(obj types.Object) { | |
objectPath, err := w.p.objectpathEncoder().For(obj) | ||
if err != nil { | ||
// Fall back to the empty string, which will cause the importer to create a | ||
// new object. | ||
// new object, which matches earlier behavior. Creating a new object is | ||
// sufficient for many purposes (such as type checking), but causes certain | ||
// references algorithms to fail (golang/go#60819). However, we didn't | ||
// notice this problem during months of [email protected] testing. | ||
// | ||
// This is incorrect in shallow mode (golang/go#60819), but matches | ||
// the previous behavior. This code is defensive, as it is hard to | ||
// prove that the objectpath algorithm will succeed in all cases, and | ||
// creating a new object sort of works. | ||
// (we didn't notice the bug during months of [email protected] testing) | ||
// TODO(golang/go#61674): this workaround is insufficient, as in the case | ||
// where the field forwarded from an instantiated type that may not appear | ||
// in the export data of the original package: | ||
// | ||
// However, report a bug so that we can eventually have confidence | ||
// that export/import is producing a correct package. | ||
// // package a | ||
// type A[P any] struct{ F P } | ||
// | ||
// TODO: remove reportf once we have such confidence. | ||
// // package b | ||
// type B a.A[int] | ||
// | ||
// We need to update references algorithms not to depend on this | ||
// de-duplication, at which point we may want to simply remove the | ||
// workaround here. | ||
w.string("") | ||
if w.p.reportf != nil { | ||
w.p.reportf("unable to encode object %q in package %q: %v", obj.Name(), obj.Pkg().Path(), err) | ||
} | ||
return | ||
} | ||
w.string(string(objectPath)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters