From 7b3ee6102d4690c768a7a4b303a89f3f8c811124 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Wed, 14 Apr 2021 09:34:17 -0700 Subject: [dev.typeparams] cmd/compile: move to new export version, keep reading previous version I added constants for the previous export versions, and for the final generics export version. I also added a const for the current export version. We can increment the current export version for unstable changes in dev.typeparams, and eventally set it back to the generics version (2) before release. Added the same constants in typecheck/iexport.go, importer/iimport.go, and gcimporter/iimport.go, must be kept in sync. Put in the needed conditionals to be able to read old versions. Added new export/import test listimp.dir. Change-Id: I166d17d943e07951aa752562e952b067704aeeca Reviewed-on: https://go-review.googlesource.com/c/go/+/319931 Trust: Dan Scales Run-TryBot: Dan Scales TryBot-Result: Go Bot Reviewed-by: Keith Randall --- src/cmd/compile/internal/typecheck/iimport.go | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/cmd/compile/internal/typecheck/iimport.go') diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index b6f227bb00..778ce4be12 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -121,8 +121,14 @@ func ReadImports(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintT ird := &intReader{in, pkg} version := ird.uint64() - if version != iexportVersion { - base.Errorf("import %q: unknown export format version %d", pkg.Path, version) + switch version { + case iexportVersionCurrent, iexportVersionPosCol, iexportVersionGo1_11: + default: + if version > iexportVersionGenerics { + base.Errorf("import %q: unstable export format version %d, just recompile", pkg.Path, version) + } else { + base.Errorf("import %q: unknown export format version %d", pkg.Path, version) + } base.ErrorExit() } @@ -143,7 +149,8 @@ func ReadImports(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintT in.MustSeek(int64(sLen+dLen), os.SEEK_CUR) p := &iimporter{ - ipkg: pkg, + exportVersion: version, + ipkg: pkg, pkgCache: map[uint64]*types.Pkg{}, posBaseCache: map[uint64]*src.PosBase{}, @@ -212,7 +219,8 @@ func ReadImports(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintT } type iimporter struct { - ipkg *types.Pkg + exportVersion uint64 + ipkg *types.Pkg pkgCache map[uint64]*types.Pkg posBaseCache map[uint64]*src.PosBase @@ -314,7 +322,10 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name { return n case 'F': - tparams := r.tparamList() + var tparams []*types.Field + if r.p.exportVersion >= iexportVersionGenerics { + tparams = r.tparamList() + } typ := r.signature(nil, tparams) n := importfunc(r.p.ipkg, pos, sym, typ) @@ -322,7 +333,10 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name { return n case 'T': - rparams := r.typeList() + var rparams []*types.Type + if r.p.exportVersion >= iexportVersionGenerics { + rparams = r.typeList() + } // Types can be recursive. We need to setup a stub // declaration before recursing. @@ -738,6 +752,9 @@ func (r *importReader) typ1() *types.Type { return t case typeParamType: + if r.p.exportVersion < iexportVersionGenerics { + base.Fatalf("unexpected type param type") + } r.setPkg() pos := r.pos() name := r.string() @@ -761,6 +778,9 @@ func (r *importReader) typ1() *types.Type { return t case instType: + if r.p.exportVersion < iexportVersionGenerics { + base.Fatalf("unexpected instantiation type") + } pos := r.pos() len := r.uint64() targs := make([]*types.Type, len) -- cgit v1.2.3-54-g00ecf