Skip to content

Commit

Permalink
cmd/compile: restore not-in-heap check for map/channel type
Browse files Browse the repository at this point in the history
CL 388538 removed unused -G=0 node types.

However, the code for checking not-in-heap types for map and channel
type was also removed, which is likely not intentional.

This CL restores the check, porting removed code to noder.

Updates golang#54846

Change-Id: I2995836b90e36d2684197fefc9829fddfffe8585
Reviewed-on: https://go-review.googlesource.com/c/go/+/597535
Auto-Submit: Cuong Manh Le <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
cuonglm authored and gopherbot committed Jul 24, 2024
1 parent 864aa86 commit 88833c9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/cmd/compile/internal/noder/irgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info, map[*
}
base.ExitIfErrors()

// Implementation restriction: we don't allow not-in-heap types to
// be used as map keys/values, or channel.
{
for _, file := range files {
syntax.Inspect(file, func(n syntax.Node) bool {
if n, ok := n.(*syntax.TypeDecl); ok {
switch n := n.Type.(type) {
case *syntax.MapType:
typ := n.GetTypeInfo().Type.Underlying().(*types2.Map)
if isNotInHeap(typ.Key()) {
base.ErrorfAt(m.makeXPos(n.Pos()), 0, "incomplete (or unallocatable) map key not allowed")
}
if isNotInHeap(typ.Elem()) {
base.ErrorfAt(m.makeXPos(n.Pos()), 0, "incomplete (or unallocatable) map value not allowed")
}
case *syntax.ChanType:
typ := n.GetTypeInfo().Type.Underlying().(*types2.Chan)
if isNotInHeap(typ.Elem()) {
base.ErrorfAt(m.makeXPos(n.Pos()), 0, "chan of incomplete (or unallocatable) type not allowed")
}
}
}
return true
})
}
}
base.ExitIfErrors()

// Rewrite range over function to explicit function calls
// with the loop bodies converted into new implicit closures.
// We do this now, before serialization to unified IR, so that if the
Expand Down

0 comments on commit 88833c9

Please sign in to comment.