]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove go:notinheap pragma
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 10 Aug 2022 13:01:48 +0000 (20:01 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 2 Sep 2022 18:24:59 +0000 (18:24 +0000)
Updates #46731

Change-Id: I247fa9c7ca97feb9053665da7ff56e7f5b571f74
Reviewed-on: https://go-review.googlesource.com/c/go/+/422815
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/noder/decl.go
src/cmd/compile/internal/noder/lex.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/writer.go
src/cmd/compile/internal/typebits/typebits.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/subr.go

index 4196622b8a3587a60d95a0b85593880ba3a04993..7a4fb02f25d01a79bd400a91547edebaf7a7b2b5 100644 (file)
@@ -454,9 +454,6 @@ const (
        Nowritebarrierrec  // error on write barrier in this or recursive callees
        Yeswritebarrierrec // cancels Nowritebarrierrec in this function and callees
 
-       // Runtime and cgo type pragmas
-       NotInHeap // values of this type must not be heap allocated
-
        // Go command pragmas
        GoBuildPragma
 
index 91a90d9e090c10b1d936d282366f243d7c4b2a9d..07353cc17eaaf2fa9358ab310f8732a678f265aa 100644 (file)
@@ -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()
index cef0f082ca9e04f9ce74eb1233e885d3dde1d960..c964eca678416c8d440c14af47b3a8b4a9968865 100644 (file)
@@ -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
 }
index b68d7b7702475465bf9baa2bd2c235fbec27f9a8..15b1bf7b9fe51ab21f0eec58168bca99b49019b1 100644 (file)
@@ -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})
        }
index 8270c403fe38404ca7e8ce758a8b726087a16b42..e69d8edc0b7b8fce5fe2ba0f53f0160cabab42a7 100644 (file)
@@ -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 {
index ebec33b6f4d97f61f8971a6769a0ee56d47a2f6a..e7aa5c1c499d58d290f986ec67139ae642c003ae 100644 (file)
@@ -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 {
index fddad6e7e84b8176fd3d2865433d53d0b95236b2..06c1d12a342b83c004bf3d45309d03d1d4f00981 100644 (file)
@@ -18,7 +18,7 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
                base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, uint8(t.Alignment()), off)
        }
        if !t.HasPointers() {
-               // Note: this case ensures that pointers to go:notinheap types
+               // Note: this case ensures that pointers to not-in-heap types
                // are not considered pointers by garbage collection and stack copying.
                return
        }
index 18bc865e2692ca7343efae47c053f16f045d0ac8..d62066f33ce8e121520d731fbf37089318e5dd1e 100644 (file)
@@ -901,7 +901,7 @@ func tcUnsafeSlice(n *ir.BinaryExpr) *ir.BinaryExpr {
                base.Errorf("first argument to unsafe.Slice must be pointer; have %L", t)
        } else if t.Elem().NotInHeap() {
                // TODO(mdempsky): This can be relaxed, but should only affect the
-               // Go runtime itself. End users should only see //go:notinheap
+               // Go runtime itself. End users should only see not-in-heap
                // types due to incomplete C structs in cgo, and those types don't
                // have a meaningful size anyway.
                base.Errorf("unsafe.Slice of incomplete (or unallocatable) type not allowed")
index b932c2c444093fdaa90a603ca457b8605589c9bf..eab71556d3f776f82f630e700ae21900773a0f1e 100644 (file)
@@ -471,15 +471,15 @@ func Convertop(srcConstant bool, src, dst *types.Type) (ir.Op, string) {
                return ir.OXXX, ""
        }
 
-       // Conversions from regular to go:notinheap are not allowed
+       // Conversions from regular to not-in-heap are not allowed
        // (unless it's unsafe.Pointer). These are runtime-specific
        // rules.
-       // (a) Disallow (*T) to (*U) where T is go:notinheap but U isn't.
+       // (a) Disallow (*T) to (*U) where T is not-in-heap but U isn't.
        if src.IsPtr() && dst.IsPtr() && dst.Elem().NotInHeap() && !src.Elem().NotInHeap() {
                why := fmt.Sprintf(":\n\t%v is incomplete (or unallocatable), but %v is not", dst.Elem(), src.Elem())
                return ir.OXXX, why
        }
-       // (b) Disallow string to []T where T is go:notinheap.
+       // (b) Disallow string to []T where T is not-in-heap.
        if src.IsString() && dst.IsSlice() && dst.Elem().NotInHeap() && (dst.Elem().Kind() == types.ByteType.Kind() || dst.Elem().Kind() == types.RuneType.Kind()) {
                why := fmt.Sprintf(":\n\t%v is incomplete (or unallocatable)", dst.Elem())
                return ir.OXXX, why