From 8bbb362f4c954da7c521bf2dd34b22fa3e5ab3c5 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 10 Aug 2022 20:01:48 +0700 Subject: cmd/compile: remove go:notinheap pragma Updates #46731 Change-Id: I247fa9c7ca97feb9053665da7ff56e7f5b571f74 Reviewed-on: https://go-review.googlesource.com/c/go/+/422815 Reviewed-by: Keith Randall Run-TryBot: Cuong Manh Le Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: Joedian Reid --- src/cmd/compile/internal/noder/decl.go | 26 +------------------------- src/cmd/compile/internal/noder/lex.go | 4 ---- src/cmd/compile/internal/noder/noder.go | 3 --- src/cmd/compile/internal/noder/reader.go | 13 ------------- src/cmd/compile/internal/noder/writer.go | 2 +- 5 files changed, 2 insertions(+), 46 deletions(-) (limited to 'src/cmd/compile/internal/noder') diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go index 91a90d9e09..07353cc17e 100644 --- a/src/cmd/compile/internal/noder/decl.go +++ b/src/cmd/compile/internal/noder/decl.go @@ -212,33 +212,9 @@ func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) { ntyp.SetVargen() } - pragmas := g.pragmaFlags(decl.Pragma, typePragmas) + pragmas := g.pragmaFlags(decl.Pragma, 0) name.SetPragma(pragmas) // TODO(mdempsky): Is this still needed? - if pragmas&ir.NotInHeap != 0 { - ntyp.SetNotInHeap(true) - } - - // We need to use g.typeExpr(decl.Type) here to ensure that for - // chained, defined-type declarations like: - // - // type T U - // - // //go:notinheap - // type U struct { … } - // - // we mark both T and U as NotInHeap. If we instead used just - // g.typ(otyp.Underlying()), then we'd instead set T's underlying - // type directly to the struct type (which is not marked NotInHeap) - // and fail to mark T as NotInHeap. - // - // Also, we rely here on Type.SetUnderlying allowing passing a - // defined type and handling forward references like from T to U - // above. Contrast with go/types's Named.SetUnderlying, which - // disallows this. - // - // [mdempsky: Subtleties like these are why I always vehemently - // object to new type pragmas.] ntyp.SetUnderlying(g.typeExpr(decl.Type)) tparams := otyp.(*types2.Named).TypeParams() diff --git a/src/cmd/compile/internal/noder/lex.go b/src/cmd/compile/internal/noder/lex.go index cef0f082ca..c964eca678 100644 --- a/src/cmd/compile/internal/noder/lex.go +++ b/src/cmd/compile/internal/noder/lex.go @@ -36,8 +36,6 @@ const ( ir.Nowritebarrier | ir.Nowritebarrierrec | ir.Yeswritebarrierrec - - typePragmas = ir.NotInHeap ) func pragmaFlag(verb string) ir.PragmaFlag { @@ -77,8 +75,6 @@ func pragmaFlag(verb string) ir.PragmaFlag { return ir.UintptrEscapes | ir.UintptrKeepAlive // implies UintptrKeepAlive case "go:registerparams": // TODO(register args) remove after register abi is working return ir.RegisterParams - case "go:notinheap": - return ir.NotInHeap } return 0 } diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index b68d7b7702..15b1bf7b9f 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -344,9 +344,6 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P if flag == 0 && !allowedStdPragmas[verb] && base.Flag.Std { p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s is not allowed in the standard library", verb)}) } - if flag == ir.NotInHeap && *base.Flag.LowerP != "runtime/internal/sys" { - p.error(syntax.Error{Pos: pos, Msg: "//go:notinheap only allowed in runtime/internal/sys"}) - } pragma.Flag |= flag pragma.Pos = append(pragma.Pos, pragmaPos{flag, pos}) } diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 8270c403fe..e69d8edc0b 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1096,9 +1096,6 @@ func (r *reader) typeExt(name *ir.Name) { } name.SetPragma(r.pragmaFlag()) - if name.Pragma()&ir.NotInHeap != 0 { - typ.SetNotInHeap(true) - } typecheck.SetBaseTypeIndex(typ, r.Int64(), r.Int64()) } @@ -2440,16 +2437,6 @@ func (r *reader) expr() (res ir.Node) { // TODO(mdempsky): Stop constructing expressions of untyped type. x = typecheck.DefaultLit(x, typ) - if op, why := typecheck.Convertop(x.Op() == ir.OLITERAL, x.Type(), typ); op == ir.OXXX { - // types2 ensured that x is convertable to typ under standard Go - // semantics, but cmd/compile also disallows some conversions - // involving //go:notinheap. - // - // TODO(mdempsky): This can be removed after #46731 is implemented. - base.ErrorfAt(pos, "cannot convert %L to type %v%v", x, typ, why) - base.ErrorExit() // harsh, but prevents constructing invalid IR - } - ce := ir.NewConvExpr(pos, ir.OCONV, typ, x) ce.TypeWord, ce.SrcRType = typeWord, srcRType if implicit { diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index ebec33b6f4..e7aa5c1c49 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -2355,7 +2355,7 @@ func (c *declCollector) Visit(n syntax.Node) syntax.Visitor { if n.Alias { pw.checkPragmas(n.Pragma, 0, false) } else { - pw.checkPragmas(n.Pragma, typePragmas, false) + pw.checkPragmas(n.Pragma, 0, false) // Assign a unique ID to function-scoped defined types. if c.withinFunc { -- cgit v1.3-5-g9baa