From 8d2b4cb6cc3100f337e08cc7342f42823fa1dc9a Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Mon, 10 May 2021 16:23:35 -0700 Subject: [dev.typeparams] cmd/compile: fixing import of comm clauses/closures in generic functions Improvements: - Fix export/import of the default case of a select statement (was not dealing with nil Comm case) - Set properly the name of closure functions in imported generic functions Added new test exporting/importing a reasonably large channel package, chansimp.go. Change-Id: If2ee12bd749e5df415f48ec4b629a2fa68a79dcb Reviewed-on: https://go-review.googlesource.com/c/go/+/321734 Run-TryBot: Dan Scales TryBot-Result: Go Bot Reviewed-by: Keith Randall Trust: Dan Scales --- src/cmd/compile/internal/typecheck/iexport.go | 7 ++++++- src/cmd/compile/internal/typecheck/iimport.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 802a8c3839..d956ada3c5 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -1523,7 +1523,12 @@ func (w *exportWriter) commList(cases []*ir.CommClause) { w.uint64(uint64(len(cases))) for _, cas := range cases { w.pos(cas.Pos()) - w.node(cas.Comm) + defaultCase := cas.Comm == nil + w.bool(defaultCase) + if !defaultCase { + // Only call w.node for non-default cause (cas.Comm is non-nil) + w.node(cas.Comm) + } w.stmtList(cas.Body) } } diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 39b5ab09da..966e865630 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -1121,7 +1121,13 @@ func (r *importReader) caseList(switchExpr ir.Node) []*ir.CaseClause { func (r *importReader) commList() []*ir.CommClause { cases := make([]*ir.CommClause, r.uint64()) for i := range cases { - cases[i] = ir.NewCommStmt(r.pos(), r.node(), r.stmtList()) + pos := r.pos() + defaultCase := r.bool() + var comm ir.Node + if !defaultCase { + comm = r.node() + } + cases[i] = ir.NewCommStmt(pos, comm, r.stmtList()) } return cases } @@ -1257,6 +1263,12 @@ func (r *importReader) node() ir.Node { if go117ExportTypes { clo.SetType(typ) } + if r.curfn.Type().HasTParam() { + // Generic functions aren't inlined, so give the closure a + // function name now, which is then available for use + // (after appending the type args) for each stenciling. + fn.Nname.SetSym(ClosureName(r.curfn)) + } return clo -- cgit v1.3-5-g9baa