Skip to content

Commit 8bbb362

Browse files
committed
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 <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joedian Reid <[email protected]>
1 parent 0ee0bb1 commit 8bbb362

File tree

9 files changed

+7
-54
lines changed

9 files changed

+7
-54
lines changed

src/cmd/compile/internal/ir/node.go

-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,6 @@ const (
454454
Nowritebarrierrec // error on write barrier in this or recursive callees
455455
Yeswritebarrierrec // cancels Nowritebarrierrec in this function and callees
456456

457-
// Runtime and cgo type pragmas
458-
NotInHeap // values of this type must not be heap allocated
459-
460457
// Go command pragmas
461458
GoBuildPragma
462459

src/cmd/compile/internal/noder/decl.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -212,33 +212,9 @@ func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
212212
ntyp.SetVargen()
213213
}
214214

215-
pragmas := g.pragmaFlags(decl.Pragma, typePragmas)
215+
pragmas := g.pragmaFlags(decl.Pragma, 0)
216216
name.SetPragma(pragmas) // TODO(mdempsky): Is this still needed?
217217

218-
if pragmas&ir.NotInHeap != 0 {
219-
ntyp.SetNotInHeap(true)
220-
}
221-
222-
// We need to use g.typeExpr(decl.Type) here to ensure that for
223-
// chained, defined-type declarations like:
224-
//
225-
// type T U
226-
//
227-
// //go:notinheap
228-
// type U struct { … }
229-
//
230-
// we mark both T and U as NotInHeap. If we instead used just
231-
// g.typ(otyp.Underlying()), then we'd instead set T's underlying
232-
// type directly to the struct type (which is not marked NotInHeap)
233-
// and fail to mark T as NotInHeap.
234-
//
235-
// Also, we rely here on Type.SetUnderlying allowing passing a
236-
// defined type and handling forward references like from T to U
237-
// above. Contrast with go/types's Named.SetUnderlying, which
238-
// disallows this.
239-
//
240-
// [mdempsky: Subtleties like these are why I always vehemently
241-
// object to new type pragmas.]
242218
ntyp.SetUnderlying(g.typeExpr(decl.Type))
243219

244220
tparams := otyp.(*types2.Named).TypeParams()

src/cmd/compile/internal/noder/lex.go

-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const (
3636
ir.Nowritebarrier |
3737
ir.Nowritebarrierrec |
3838
ir.Yeswritebarrierrec
39-
40-
typePragmas = ir.NotInHeap
4139
)
4240

4341
func pragmaFlag(verb string) ir.PragmaFlag {
@@ -77,8 +75,6 @@ func pragmaFlag(verb string) ir.PragmaFlag {
7775
return ir.UintptrEscapes | ir.UintptrKeepAlive // implies UintptrKeepAlive
7876
case "go:registerparams": // TODO(register args) remove after register abi is working
7977
return ir.RegisterParams
80-
case "go:notinheap":
81-
return ir.NotInHeap
8278
}
8379
return 0
8480
}

src/cmd/compile/internal/noder/noder.go

-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P
344344
if flag == 0 && !allowedStdPragmas[verb] && base.Flag.Std {
345345
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s is not allowed in the standard library", verb)})
346346
}
347-
if flag == ir.NotInHeap && *base.Flag.LowerP != "runtime/internal/sys" {
348-
p.error(syntax.Error{Pos: pos, Msg: "//go:notinheap only allowed in runtime/internal/sys"})
349-
}
350347
pragma.Flag |= flag
351348
pragma.Pos = append(pragma.Pos, pragmaPos{flag, pos})
352349
}

src/cmd/compile/internal/noder/reader.go

-13
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,6 @@ func (r *reader) typeExt(name *ir.Name) {
10961096
}
10971097

10981098
name.SetPragma(r.pragmaFlag())
1099-
if name.Pragma()&ir.NotInHeap != 0 {
1100-
typ.SetNotInHeap(true)
1101-
}
11021099

11031100
typecheck.SetBaseTypeIndex(typ, r.Int64(), r.Int64())
11041101
}
@@ -2440,16 +2437,6 @@ func (r *reader) expr() (res ir.Node) {
24402437
// TODO(mdempsky): Stop constructing expressions of untyped type.
24412438
x = typecheck.DefaultLit(x, typ)
24422439

2443-
if op, why := typecheck.Convertop(x.Op() == ir.OLITERAL, x.Type(), typ); op == ir.OXXX {
2444-
// types2 ensured that x is convertable to typ under standard Go
2445-
// semantics, but cmd/compile also disallows some conversions
2446-
// involving //go:notinheap.
2447-
//
2448-
// TODO(mdempsky): This can be removed after #46731 is implemented.
2449-
base.ErrorfAt(pos, "cannot convert %L to type %v%v", x, typ, why)
2450-
base.ErrorExit() // harsh, but prevents constructing invalid IR
2451-
}
2452-
24532440
ce := ir.NewConvExpr(pos, ir.OCONV, typ, x)
24542441
ce.TypeWord, ce.SrcRType = typeWord, srcRType
24552442
if implicit {

src/cmd/compile/internal/noder/writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ func (c *declCollector) Visit(n syntax.Node) syntax.Visitor {
23552355
if n.Alias {
23562356
pw.checkPragmas(n.Pragma, 0, false)
23572357
} else {
2358-
pw.checkPragmas(n.Pragma, typePragmas, false)
2358+
pw.checkPragmas(n.Pragma, 0, false)
23592359

23602360
// Assign a unique ID to function-scoped defined types.
23612361
if c.withinFunc {

src/cmd/compile/internal/typebits/typebits.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Set(t *types.Type, off int64, bv bitvec.BitVec) {
1818
base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, uint8(t.Alignment()), off)
1919
}
2020
if !t.HasPointers() {
21-
// Note: this case ensures that pointers to go:notinheap types
21+
// Note: this case ensures that pointers to not-in-heap types
2222
// are not considered pointers by garbage collection and stack copying.
2323
return
2424
}

src/cmd/compile/internal/typecheck/func.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ func tcUnsafeSlice(n *ir.BinaryExpr) *ir.BinaryExpr {
901901
base.Errorf("first argument to unsafe.Slice must be pointer; have %L", t)
902902
} else if t.Elem().NotInHeap() {
903903
// TODO(mdempsky): This can be relaxed, but should only affect the
904-
// Go runtime itself. End users should only see //go:notinheap
904+
// Go runtime itself. End users should only see not-in-heap
905905
// types due to incomplete C structs in cgo, and those types don't
906906
// have a meaningful size anyway.
907907
base.Errorf("unsafe.Slice of incomplete (or unallocatable) type not allowed")

src/cmd/compile/internal/typecheck/subr.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ func Convertop(srcConstant bool, src, dst *types.Type) (ir.Op, string) {
471471
return ir.OXXX, ""
472472
}
473473

474-
// Conversions from regular to go:notinheap are not allowed
474+
// Conversions from regular to not-in-heap are not allowed
475475
// (unless it's unsafe.Pointer). These are runtime-specific
476476
// rules.
477-
// (a) Disallow (*T) to (*U) where T is go:notinheap but U isn't.
477+
// (a) Disallow (*T) to (*U) where T is not-in-heap but U isn't.
478478
if src.IsPtr() && dst.IsPtr() && dst.Elem().NotInHeap() && !src.Elem().NotInHeap() {
479479
why := fmt.Sprintf(":\n\t%v is incomplete (or unallocatable), but %v is not", dst.Elem(), src.Elem())
480480
return ir.OXXX, why
481481
}
482-
// (b) Disallow string to []T where T is go:notinheap.
482+
// (b) Disallow string to []T where T is not-in-heap.
483483
if src.IsString() && dst.IsSlice() && dst.Elem().NotInHeap() && (dst.Elem().Kind() == types.ByteType.Kind() || dst.Elem().Kind() == types.RuneType.Kind()) {
484484
why := fmt.Sprintf(":\n\t%v is incomplete (or unallocatable)", dst.Elem())
485485
return ir.OXXX, why

0 commit comments

Comments
 (0)