mirror of
https://github.com/golang/go
synced 2024-11-17 13:44:43 -07:00
[dev.unified] cmd/compile: implicit conversions for return statements
This CL inserts implicit conversions for simple N:N return statements. A subsequent CL will handle N:1 return statements. Change-Id: Ia672db3e214025510485e17d3d50d42ff01bc74e Reviewed-on: https://go-review.googlesource.com/c/go/+/413517 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
a3fea7796a
commit
421e9e9db2
@ -134,6 +134,9 @@ type writer struct {
|
|||||||
|
|
||||||
pkgbits.Encoder
|
pkgbits.Encoder
|
||||||
|
|
||||||
|
// sig holds the signature for the current function body, if any.
|
||||||
|
sig *types2.Signature
|
||||||
|
|
||||||
// TODO(mdempsky): We should be able to prune localsIdx whenever a
|
// TODO(mdempsky): We should be able to prune localsIdx whenever a
|
||||||
// scope closes, and then maybe we can just use the same map for
|
// scope closes, and then maybe we can just use the same map for
|
||||||
// storing the TypeParams too (as their TypeName instead).
|
// storing the TypeParams too (as their TypeName instead).
|
||||||
@ -957,6 +960,7 @@ func (w *writer) pragmaFlag(p ir.PragmaFlag) {
|
|||||||
// block), adding it to the export data
|
// block), adding it to the export data
|
||||||
func (pw *pkgWriter) bodyIdx(sig *types2.Signature, block *syntax.BlockStmt, dict *writerDict) (idx pkgbits.Index, closureVars []posVar) {
|
func (pw *pkgWriter) bodyIdx(sig *types2.Signature, block *syntax.BlockStmt, dict *writerDict) (idx pkgbits.Index, closureVars []posVar) {
|
||||||
w := pw.newWriter(pkgbits.RelocBody, pkgbits.SyncFuncBody)
|
w := pw.newWriter(pkgbits.RelocBody, pkgbits.SyncFuncBody)
|
||||||
|
w.sig = sig
|
||||||
w.dict = dict
|
w.dict = dict
|
||||||
|
|
||||||
w.funcargs(sig)
|
w.funcargs(sig)
|
||||||
@ -1132,7 +1136,25 @@ func (w *writer) stmt1(stmt syntax.Stmt) {
|
|||||||
case *syntax.ReturnStmt:
|
case *syntax.ReturnStmt:
|
||||||
w.Code(stmtReturn)
|
w.Code(stmtReturn)
|
||||||
w.pos(stmt)
|
w.pos(stmt)
|
||||||
w.exprList(stmt.Results) // TODO(mdempsky): Implicit conversions to result types.
|
|
||||||
|
// As if w.exprList(stmt.Results), but with implicit conversions to result types.
|
||||||
|
w.Sync(pkgbits.SyncExprList)
|
||||||
|
exprs := unpackListExpr(stmt.Results)
|
||||||
|
w.Sync(pkgbits.SyncExprs)
|
||||||
|
w.Len(len(exprs))
|
||||||
|
|
||||||
|
resultTypes := w.sig.Results()
|
||||||
|
if len(exprs) == resultTypes.Len() {
|
||||||
|
for i, expr := range exprs {
|
||||||
|
w.implicitExpr(stmt, resultTypes.At(i).Type(), expr)
|
||||||
|
}
|
||||||
|
} else if len(exprs) == 0 {
|
||||||
|
// ok: bare "return" with named result parameters
|
||||||
|
} else {
|
||||||
|
// TODO(mdempsky): Implicit conversions for "return g()", where g() is multi-valued.
|
||||||
|
assert(len(exprs) == 1)
|
||||||
|
w.expr(exprs[0])
|
||||||
|
}
|
||||||
|
|
||||||
case *syntax.SelectStmt:
|
case *syntax.SelectStmt:
|
||||||
w.Code(stmtSelect)
|
w.Code(stmtSelect)
|
||||||
|
Loading…
Reference in New Issue
Block a user