cmd/compile: remove go117ExportTypes constant

Now, 1.17 is the least supported version, the compiler always write
type information when exporting function bodies. So we can get rid of
go117ExportTypes constant and all its conditional checking codes.

Change-Id: I9ac616509c30601e94f99426049d814328253395
Reviewed-on: https://go-review.googlesource.com/c/go/+/402974
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2022-04-29 01:08:40 +07:00 committed by Gopher Robot
parent 123e27170a
commit 15381040fa
4 changed files with 155 additions and 355 deletions

View file

@ -934,10 +934,6 @@ func oldInline(call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.InlinedCallExpr
lab := ir.NewLabelStmt(base.Pos, retlabel)
body = append(body, lab)
if !typecheck.Go117ExportTypes {
typecheck.Stmts(body)
}
if base.Flag.GenDwarfInl > 0 {
for _, v := range inlfvars {
v.SetPos(subst.updatedPos(v.Pos()))

View file

@ -187,19 +187,6 @@ func ImportedBody(fn *ir.Func) {
fmt.Printf("typecheck import [%v] %L { %v }\n", fn.Sym(), fn, ir.Nodes(fn.Inl.Body))
}
if !go117ExportTypes {
// If we didn't export & import types, typecheck the code here.
savefn := ir.CurFunc
ir.CurFunc = fn
if inTypeCheckInl {
base.Fatalf("inTypeCheckInl should not be set recursively")
}
inTypeCheckInl = true
Stmts(fn.Inl.Body)
inTypeCheckInl = false
ir.CurFunc = savefn
}
base.Pos = lno
}

View file

@ -1590,11 +1590,7 @@ func (w *exportWriter) stmt(n ir.Node) {
case ir.OAS2, ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV:
n := n.(*ir.AssignListStmt)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OAS2)
}
w.pos(n.Pos())
w.stmtList(n.Init())
w.exprList(n.Lhs)
@ -1759,9 +1755,7 @@ func (w *exportWriter) expr(n ir.Node) {
// Indicate that this is not an OKEY entry.
w.bool(false)
w.qualifiedIdent(n)
if go117ExportTypes {
w.typ(n.Type())
}
break
}
@ -1790,9 +1784,7 @@ func (w *exportWriter) expr(n ir.Node) {
s := n.Sym()
w.string(s.Name)
w.pkg(s.Pkg)
if go117ExportTypes {
w.typ(n.Type())
}
// case OPACK:
// should have been resolved by typechecking - handled by default case
@ -1864,16 +1856,10 @@ func (w *exportWriter) expr(n ir.Node) {
case ir.OPTRLIT:
n := n.(*ir.AddrExpr)
if go117ExportTypes {
w.op(ir.OPTRLIT)
} else {
w.op(ir.OADDR)
}
w.pos(n.Pos())
w.expr(n.X)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OSTRUCTLIT:
n := n.(*ir.CompLitExpr)
@ -1884,15 +1870,11 @@ func (w *exportWriter) expr(n ir.Node) {
case ir.OCOMPLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
n := n.(*ir.CompLitExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OCOMPLIT)
}
w.pos(n.Pos())
w.typ(n.Type())
w.exprList(n.List)
if go117ExportTypes && n.Op() == ir.OSLICELIT {
if n.Op() == ir.OSLICELIT {
w.uint64(uint64(n.Len))
}
case ir.OKEY:
@ -1907,17 +1889,10 @@ func (w *exportWriter) expr(n ir.Node) {
case ir.OXDOT, ir.ODOT, ir.ODOTPTR, ir.ODOTINTER, ir.ODOTMETH, ir.OMETHVALUE, ir.OMETHEXPR:
n := n.(*ir.SelectorExpr)
if go117ExportTypes {
// For go117ExportTypes, we usually see all ops except
// OXDOT, but we can see OXDOT for generic functions.
w.op(n.Op())
} else {
w.op(ir.OXDOT)
}
w.pos(n.Pos())
w.expr(n.X)
w.exoticSelector(n.Sel)
if go117ExportTypes {
w.exoticType(n.Type())
if n.Op() == ir.OXDOT {
// n.Selection for method references will be
@ -1929,15 +1904,10 @@ func (w *exportWriter) expr(n ir.Node) {
// n.Selection is not required for OMETHEXPR, ODOTMETH, and OMETHVALUE. It will
// be reconstructed during import. n.Selection is computed during
// transformDot() for OXDOT.
}
case ir.ODOTTYPE, ir.ODOTTYPE2:
n := n.(*ir.TypeAssertExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.ODOTTYPE)
}
w.pos(n.Pos())
w.expr(n.X)
w.typ(n.Type())
@ -1952,49 +1922,31 @@ func (w *exportWriter) expr(n ir.Node) {
case ir.OINDEX, ir.OINDEXMAP:
n := n.(*ir.IndexExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OINDEX)
}
w.pos(n.Pos())
w.expr(n.X)
w.expr(n.Index)
if go117ExportTypes {
w.exoticType(n.Type())
if n.Op() == ir.OINDEXMAP {
w.bool(n.Assigned)
}
}
case ir.OSLICE, ir.OSLICESTR, ir.OSLICEARR:
n := n.(*ir.SliceExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OSLICE)
}
w.pos(n.Pos())
w.expr(n.X)
w.exprsOrNil(n.Low, n.High)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OSLICE3, ir.OSLICE3ARR:
n := n.(*ir.SliceExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OSLICE3)
}
w.pos(n.Pos())
w.expr(n.X)
w.exprsOrNil(n.Low, n.High)
w.expr(n.Max)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OCOPY, ir.OCOMPLEX, ir.OUNSAFEADD, ir.OUNSAFESLICE:
// treated like other builtin calls (see e.g., OREAL)
@ -2004,19 +1956,11 @@ func (w *exportWriter) expr(n ir.Node) {
w.stmtList(n.Init())
w.expr(n.X)
w.expr(n.Y)
if go117ExportTypes {
w.typ(n.Type())
} else {
w.op(ir.OEND)
}
case ir.OCONV, ir.OCONVIFACE, ir.OCONVIDATA, ir.OCONVNOP, ir.OBYTES2STR, ir.ORUNES2STR, ir.OSTR2BYTES, ir.OSTR2RUNES, ir.ORUNESTR, ir.OSLICE2ARRPTR:
n := n.(*ir.ConvExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OCONV)
}
w.pos(n.Pos())
w.typ(n.Type())
w.expr(n.X)
@ -2026,13 +1970,9 @@ func (w *exportWriter) expr(n ir.Node) {
w.op(n.Op())
w.pos(n.Pos())
w.expr(n.X)
if go117ExportTypes {
if n.Op() != ir.OPANIC {
w.typ(n.Type())
}
} else {
w.op(ir.OEND)
}
case ir.OAPPEND, ir.ODELETE, ir.ORECOVER, ir.OPRINT, ir.OPRINTN:
n := n.(*ir.CallExpr)
@ -2046,27 +1986,19 @@ func (w *exportWriter) expr(n ir.Node) {
} else if n.IsDDD {
base.Fatalf("exporter: unexpected '...' with %v call", n.Op())
}
if go117ExportTypes {
if n.Op() != ir.ODELETE && n.Op() != ir.OPRINT && n.Op() != ir.OPRINTN {
w.typ(n.Type())
}
}
case ir.OCALL, ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER, ir.OGETG:
n := n.(*ir.CallExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OCALL)
}
w.pos(n.Pos())
w.stmtList(n.Init())
w.expr(n.X)
w.exprList(n.Args)
w.bool(n.IsDDD)
if go117ExportTypes {
w.exoticType(n.Type())
}
case ir.OMAKEMAP, ir.OMAKECHAN, ir.OMAKESLICE:
n := n.(*ir.MakeExpr)
@ -2087,7 +2019,7 @@ func (w *exportWriter) expr(n ir.Node) {
// an argument. Don't serialize that argument here.
w.expr(n.Len)
w.op(ir.OEND)
case n.Len != nil && go117ExportTypes:
case n.Len != nil:
w.expr(n.Len)
w.op(ir.OEND)
}
@ -2106,27 +2038,21 @@ func (w *exportWriter) expr(n ir.Node) {
w.op(n.Op())
w.pos(n.Pos())
w.expr(n.X)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OADDR:
n := n.(*ir.AddrExpr)
w.op(n.Op())
w.pos(n.Pos())
w.expr(n.X)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.ODEREF:
n := n.(*ir.StarExpr)
w.op(n.Op())
w.pos(n.Pos())
w.expr(n.X)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OSEND:
n := n.(*ir.SendStmt)
@ -2143,9 +2069,7 @@ func (w *exportWriter) expr(n ir.Node) {
w.pos(n.Pos())
w.expr(n.X)
w.expr(n.Y)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OANDAND, ir.OOROR:
n := n.(*ir.LogicalExpr)
@ -2153,18 +2077,14 @@ func (w *exportWriter) expr(n ir.Node) {
w.pos(n.Pos())
w.expr(n.X)
w.expr(n.Y)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OADDSTR:
n := n.(*ir.AddStringExpr)
w.op(ir.OADDSTR)
w.pos(n.Pos())
w.exprList(n.List)
if go117ExportTypes {
w.typ(n.Type())
}
case ir.ODCLCONST:
// if exporting, DCLCONST should just be removed as its usage
@ -2179,9 +2099,7 @@ func (w *exportWriter) expr(n ir.Node) {
for _, targ := range n.Targs {
w.typ(targ.Type())
}
if go117ExportTypes {
w.typ(n.Type())
}
case ir.OSELRECV2:
n := n.(*ir.AssignListStmt)
@ -2297,15 +2215,5 @@ func (w *intWriter) uint64(x uint64) {
w.Write(buf[:n])
}
// If go117ExportTypes is true, then we write type information when
// exporting function bodies, so those function bodies don't need to
// be re-typechecked on import.
// This flag adds some other info to the serialized stream as well
// which was previously recomputed during typechecking, like
// specializing opcodes (e.g. OXDOT to ODOTPTR) and ancillary
// information (e.g. length field for OSLICELIT).
const go117ExportTypes = true
const Go117ExportTypes = go117ExportTypes
// The name used for dictionary parameters or local variables.
const LocalDictName = ".dict"

View file

@ -1137,11 +1137,9 @@ func (r *importReader) funcBody(fn *ir.Func) {
// functions).
body = []ir.Node{}
}
if go117ExportTypes {
ir.VisitList(body, func(n ir.Node) {
n.SetTypecheck(1)
})
}
fn.Inl.Body = body
r.curfn = outerfn
@ -1319,19 +1317,15 @@ func (r *importReader) node() ir.Node {
case ir.ONONAME:
isKey := r.bool()
n := r.qualifiedIdent()
if go117ExportTypes {
var n2 ir.Node = n
var n ir.Node = r.qualifiedIdent()
// Key ONONAME entries should not be resolved - they should
// stay as identifiers.
if !isKey {
n2 = Resolve(n)
n = Resolve(n)
}
typ := r.typ()
if n2.Type() == nil {
n2.SetType(typ)
}
return n2
if n.Type() == nil {
n.SetType(typ)
}
return n
@ -1386,7 +1380,7 @@ func (r *importReader) node() ir.Node {
cvars := make([]*ir.Name, r.int64())
for i := range cvars {
cvars[i] = ir.CaptureName(r.pos(), fn, r.localName().Canonical())
if go117ExportTypes && cvars[i].Defn == nil {
if cvars[i].Defn == nil {
base.Fatalf("bad import of closure variable")
}
}
@ -1409,21 +1403,16 @@ func (r *importReader) node() ir.Node {
ir.FinishCaptureNames(pos, r.curfn, fn)
clo := fn.OClosure
if go117ExportTypes {
clo.SetType(typ)
}
return clo
case ir.OSTRUCTLIT:
if go117ExportTypes {
pos := r.pos()
typ := r.typ()
list := r.fieldList()
n := ir.NewCompLitExpr(pos, ir.OSTRUCTLIT, nil, list)
n.SetType(typ)
return n
}
return ir.NewCompLitExpr(r.pos(), ir.OCOMPLIT, ir.TypeNode(r.typ()), r.fieldList())
case ir.OCOMPLIT:
pos := r.pos()
@ -1433,10 +1422,6 @@ func (r *importReader) node() ir.Node {
return n
case ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
if !go117ExportTypes {
// unreachable - mapped to OCOMPLIT by exporter
goto error
}
pos := r.pos()
typ := r.typ()
list := r.exprList()
@ -1454,17 +1439,10 @@ func (r *importReader) node() ir.Node {
// unreachable - handled in case OSTRUCTLIT by elemList
case ir.OXDOT, ir.ODOT, ir.ODOTPTR, ir.ODOTINTER, ir.ODOTMETH, ir.OMETHVALUE, ir.OMETHEXPR:
// For !go117ExportTypes, we should only see OXDOT.
// For go117ExportTypes, we usually see all the other ops, but can see
// OXDOT for generic functions.
if op != ir.OXDOT && !go117ExportTypes {
goto error
}
pos := r.pos()
expr := r.expr()
sel := r.exoticSelector()
n := ir.NewSelectorExpr(pos, op, expr, sel)
if go117ExportTypes {
n.SetType(r.exoticType())
switch op {
case ir.OXDOT:
@ -1504,15 +1482,12 @@ func (r *importReader) node() ir.Node {
n.SetType(typ)
}
}
}
return n
case ir.ODOTTYPE, ir.ODOTTYPE2:
n := ir.NewTypeAssertExpr(r.pos(), r.expr(), nil)
n.SetType(r.typ())
if go117ExportTypes {
n.SetOp(op)
}
return n
case ir.ODYNAMICDOTTYPE, ir.ODYNAMICDOTTYPE2:
@ -1522,13 +1497,11 @@ func (r *importReader) node() ir.Node {
case ir.OINDEX, ir.OINDEXMAP:
n := ir.NewIndexExpr(r.pos(), r.expr(), r.expr())
if go117ExportTypes {
n.SetOp(op)
n.SetType(r.exoticType())
if op == ir.OINDEXMAP {
n.Assigned = r.bool()
}
}
return n
case ir.OSLICE, ir.OSLICESTR, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR:
@ -1539,21 +1512,14 @@ func (r *importReader) node() ir.Node {
max = r.expr()
}
n := ir.NewSliceExpr(pos, op, x, low, high, max)
if go117ExportTypes {
n.SetType(r.typ())
}
return n
case ir.OCONV, ir.OCONVIFACE, ir.OCONVIDATA, ir.OCONVNOP, ir.OBYTES2STR, ir.ORUNES2STR, ir.OSTR2BYTES, ir.OSTR2RUNES, ir.ORUNESTR, ir.OSLICE2ARRPTR:
if !go117ExportTypes && op != ir.OCONV {
// unreachable - mapped to OCONV case by exporter
goto error
}
return ir.NewConvExpr(r.pos(), op, r.typ(), r.expr())
case ir.OCOPY, ir.OCOMPLEX, ir.OREAL, ir.OIMAG, ir.OAPPEND, ir.OCAP, ir.OCLOSE, ir.ODELETE, ir.OLEN, ir.OMAKE, ir.ONEW, ir.OPANIC, ir.ORECOVER, ir.OPRINT, ir.OPRINTN, ir.OUNSAFEADD, ir.OUNSAFESLICE:
pos := r.pos()
if go117ExportTypes {
switch op {
case ir.OCOPY, ir.OCOMPLEX, ir.OUNSAFEADD, ir.OUNSAFESLICE:
init := r.stmtList()
@ -1581,37 +1547,18 @@ func (r *importReader) node() ir.Node {
}
// ir.OMAKE
goto error
}
n := builtinCall(pos, op)
switch n.Op() {
case ir.OCOPY, ir.OCOMPLEX, ir.OUNSAFEADD, ir.OUNSAFESLICE:
// treated like other builtin calls
fallthrough
case ir.OAPPEND, ir.ODELETE, ir.ORECOVER, ir.OPRINT, ir.OPRINTN:
n.SetInit(r.stmtList())
}
n.Args = r.exprList()
if op == ir.OAPPEND {
n.IsDDD = r.bool()
}
return n
case ir.OCALL, ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER, ir.OGETG:
pos := r.pos()
init := r.stmtList()
n := ir.NewCallExpr(pos, ir.OCALL, r.expr(), r.exprList())
if go117ExportTypes {
n.SetOp(op)
}
n.SetInit(init)
n.IsDDD = r.bool()
if go117ExportTypes {
n.SetType(r.exoticType())
}
return n
case ir.OMAKEMAP, ir.OMAKECHAN, ir.OMAKESLICE:
if go117ExportTypes {
pos := r.pos()
typ := r.typ()
list := r.exprList()
@ -1625,11 +1572,6 @@ func (r *importReader) node() ir.Node {
n := ir.NewMakeExpr(pos, op, len_, cap_)
n.SetType(typ)
return n
}
n := builtinCall(r.pos(), ir.OMAKE)
n.Args.Append(ir.TypeNode(r.typ()))
n.Args.Append(r.exprList()...)
return n
case ir.OLINKSYMOFFSET:
pos := r.pos()
@ -1641,13 +1583,10 @@ func (r *importReader) node() ir.Node {
// unary expressions
case ir.OPLUS, ir.ONEG, ir.OBITNOT, ir.ONOT, ir.ORECV, ir.OIDATA:
n := ir.NewUnaryExpr(r.pos(), op, r.expr())
if go117ExportTypes {
n.SetType(r.typ())
}
return n
case ir.OADDR, ir.OPTRLIT:
if go117ExportTypes {
pos := r.pos()
expr := r.expr()
expr.SetTypecheck(1) // we do this for all nodes after importing, but do it now so markAddrOf can see it.
@ -1655,31 +1594,22 @@ func (r *importReader) node() ir.Node {
n.SetOp(op)
n.SetType(r.typ())
return n
}
n := NodAddrAt(r.pos(), r.expr())
return n
case ir.ODEREF:
n := ir.NewStarExpr(r.pos(), r.expr())
if go117ExportTypes {
n.SetType(r.typ())
}
return n
// binary expressions
case ir.OADD, ir.OAND, ir.OANDNOT, ir.ODIV, ir.OEQ, ir.OGE, ir.OGT, ir.OLE, ir.OLT,
ir.OLSH, ir.OMOD, ir.OMUL, ir.ONE, ir.OOR, ir.ORSH, ir.OSUB, ir.OXOR, ir.OEFACE:
n := ir.NewBinaryExpr(r.pos(), op, r.expr(), r.expr())
if go117ExportTypes {
n.SetType(r.typ())
}
return n
case ir.OANDAND, ir.OOROR:
n := ir.NewLogicalExpr(r.pos(), op, r.expr(), r.expr())
if go117ExportTypes {
n.SetType(r.typ())
}
return n
case ir.OSEND:
@ -1688,16 +1618,9 @@ func (r *importReader) node() ir.Node {
case ir.OADDSTR:
pos := r.pos()
list := r.exprList()
if go117ExportTypes {
n := ir.NewAddStringExpr(pos, list)
n.SetType(r.typ())
return n
}
x := list[0]
for _, y := range list[1:] {
x = ir.NewBinaryExpr(pos, ir.OADD, x, y)
}
return x
// --------------------------------------------------------------------
// statements
@ -1730,10 +1653,6 @@ func (r *importReader) node() ir.Node {
return n
case ir.OAS2, ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV:
if !go117ExportTypes && op != ir.OAS2 {
// unreachable - mapped to case OAS2 by exporter
goto error
}
pos := r.pos()
init := r.stmtList()
n := ir.NewAssignListStmt(pos, op, r.exprList(), r.exprList())
@ -1820,9 +1739,7 @@ func (r *importReader) node() ir.Node {
}
}
n := ir.NewInstExpr(pos, ir.OFUNCINST, x, targs)
if go117ExportTypes {
n.SetType(r.typ())
}
return n
case ir.OSELRECV2:
@ -1870,14 +1787,6 @@ func (r *importReader) exprsOrNil() (a, b ir.Node) {
return
}
func builtinCall(pos src.XPos, op ir.Op) *ir.CallExpr {
if go117ExportTypes {
// These should all be encoded as direct ops, not OCALL.
base.Fatalf("builtinCall should not be invoked when types are included in import/export")
}
return ir.NewCallExpr(pos, ir.OCALL, ir.NewIdent(base.Pos, types.BuiltinPkg.Lookup(ir.OpNames[op])), nil)
}
// NewIncompleteNamedType returns a TFORW type t with name specified by sym, such
// that t.nod and sym.Def are set correctly. If there are any RParams for the type,
// they should be set soon after creating the TFORW type, before creating the