2019-07-25 12:54:03 -07:00
|
|
|
// errorcheck -0 -m -l
|
2015-02-19 16:27:32 +03:00
|
|
|
|
2016-04-10 14:32:26 -07:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-02-19 16:27:32 +03:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test escape analysis for interface conversions.
|
|
|
|
|
|
|
|
package escape
|
|
|
|
|
|
|
|
var sink interface{}
|
|
|
|
|
|
|
|
type M interface {
|
|
|
|
M()
|
|
|
|
}
|
|
|
|
|
|
|
|
func mescapes(m M) { // ERROR "leaking param: m"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = m
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func mdoesnotescape(m M) { // ERROR "m does not escape"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored directly in iface and with value receiver method.
|
|
|
|
type M0 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (M0) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape0() {
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
|
|
|
sink = x
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(M0)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
2015-02-19 16:27:32 +03:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(M0)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = v1
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
2020-10-28 18:49:10 -07:00
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2020-10-28 18:49:10 -07:00
|
|
|
x.M() // ERROR "devirtualizing x.M"
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored indirectly in iface and with value receiver method.
|
|
|
|
type M1 struct {
|
|
|
|
p *int
|
|
|
|
x int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (M1) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape1() {
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-09-09 11:09:01 +07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-09-09 11:09:01 +07:00
|
|
|
var x M = v // ERROR "v escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = x
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-09-09 11:09:01 +07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(M1)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2019-09-12 10:18:03 -07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(M1)
|
|
|
|
sink = v1 // ERROR "v1 escapes to heap"
|
|
|
|
}
|
|
|
|
{
|
2020-10-28 18:49:10 -07:00
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-10-28 18:49:10 -07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
|
|
|
x.M() // ERROR "devirtualizing x.M"
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
2020-09-09 11:09:01 +07:00
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-09-09 11:09:01 +07:00
|
|
|
var x M = v // ERROR "v escapes to heap"
|
2015-02-19 16:27:32 +03:00
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 11:58:33 -07:00
|
|
|
v := M1{&i, 0}
|
2020-09-09 11:09:01 +07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored directly in iface and with pointer receiver method.
|
|
|
|
type M2 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*M2) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape2() {
|
|
|
|
{
|
|
|
|
i := 0
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
|
|
|
sink = x
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(*M2)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} escapes to heap"
|
2015-02-19 16:27:32 +03:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = v1
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1 := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = *v1
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
2015-02-19 16:27:32 +03:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
v1, ok := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = *v1
|
2015-02-19 16:27:32 +03:00
|
|
|
_ = ok
|
|
|
|
}
|
|
|
|
{
|
2020-10-28 18:49:10 -07:00
|
|
|
i := 0
|
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2020-10-28 18:49:10 -07:00
|
|
|
x.M() // ERROR "devirtualizing x.M"
|
2015-02-19 16:27:32 +03:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2020-09-09 11:09:01 +07:00
|
|
|
v := &M2{&i} // ERROR "&M2{...} does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x M = v
|
2015-02-19 16:27:32 +03:00
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 12:31:18 -04:00
|
|
|
|
|
|
|
type T1 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
type T2 struct {
|
|
|
|
T1 T1
|
|
|
|
}
|
|
|
|
|
|
|
|
func dotTypeEscape() *T2 { // #11931
|
|
|
|
var x interface{}
|
2020-09-09 11:09:01 +07:00
|
|
|
x = &T1{p: new(int)} // ERROR "new\(int\) escapes to heap" "&T1{...} does not escape"
|
|
|
|
return &T2{ // ERROR "&T2{...} escapes to heap"
|
2019-09-24 23:56:50 -07:00
|
|
|
T1: *(x.(*T1)),
|
2015-07-30 12:31:18 -04:00
|
|
|
}
|
|
|
|
}
|
2016-02-13 22:39:16 -08:00
|
|
|
|
2016-07-13 12:29:39 -06:00
|
|
|
func dotTypeEscape2() { // #13805, #15796
|
2016-02-13 22:39:16 -08:00
|
|
|
{
|
|
|
|
i := 0
|
2016-07-13 12:29:39 -06:00
|
|
|
j := 0
|
2016-02-13 22:39:16 -08:00
|
|
|
var v int
|
2016-07-13 12:29:39 -06:00
|
|
|
var ok bool
|
cmd/compile/internal/escape: propagate constants to interface conversions to avoid allocs
Currently, the integer value in the following interface conversion gets
heap allocated:
v := 1000
fmt.Println(v)
In contrast, this conversion does not currently cause the integer value
to be heap allocated:
fmt.Println(1000)
The second example is able to avoid heap allocation because of an
optimization in walk (by Josh in #18704 and related issues) that
recognizes a literal is being used. In the first example, that
optimization is currently thwarted by the literal getting assigned
to a local variable prior to use in the interface conversion.
This CL propagates constants to interface conversions like
in the first example to avoid heap allocations, instead using
a read-only global. The net effect is roughly turning the first example
into the second.
One place this comes up in practice currently is with logging or
debug prints. For example, if we have something like:
func conditionalDebugf(format string, args ...interface{}) {
if debugEnabled {
fmt.Fprintf(io.Discard, format, args...)
}
}
Prior to this CL, this integer is heap allocated, even when the
debugEnabled flag is false, and even when the compiler
inlines conditionalDebugf:
v := 1000
conditionalDebugf("hello %d", v)
With this CL, the integer here is no longer heap allocated, even when
the debugEnabled flag is enabled, because the compiler can now see that
it can use a read-only global.
See the writeup in #71359 for more details.
CL 649076 (earlier in our stack) added most of the tests
along with debug diagnostics in convert.go to make it easier
to test this change.
Updates #71359
Updates #62653
Updates #53465
Updates #8618
Change-Id: I19a51e74b36576ebb0b9cf599267cbd2bd847ce4
Reviewed-on: https://go-review.googlesource.com/c/go/+/649079
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-02-12 18:55:04 -05:00
|
|
|
var x interface{} = i // ERROR "0 does not escape"
|
|
|
|
var y interface{} = j // ERROR "0 does not escape"
|
2016-07-13 12:29:39 -06:00
|
|
|
|
2019-04-01 11:58:33 -07:00
|
|
|
*(&v) = x.(int)
|
|
|
|
*(&v), *(&ok) = y.(int)
|
2016-02-13 22:39:16 -08:00
|
|
|
}
|
2023-05-23 10:39:43 +07:00
|
|
|
{ // #13805, #15796
|
|
|
|
i := 0
|
|
|
|
j := 0
|
|
|
|
var ok bool
|
cmd/compile/internal/escape: propagate constants to interface conversions to avoid allocs
Currently, the integer value in the following interface conversion gets
heap allocated:
v := 1000
fmt.Println(v)
In contrast, this conversion does not currently cause the integer value
to be heap allocated:
fmt.Println(1000)
The second example is able to avoid heap allocation because of an
optimization in walk (by Josh in #18704 and related issues) that
recognizes a literal is being used. In the first example, that
optimization is currently thwarted by the literal getting assigned
to a local variable prior to use in the interface conversion.
This CL propagates constants to interface conversions like
in the first example to avoid heap allocations, instead using
a read-only global. The net effect is roughly turning the first example
into the second.
One place this comes up in practice currently is with logging or
debug prints. For example, if we have something like:
func conditionalDebugf(format string, args ...interface{}) {
if debugEnabled {
fmt.Fprintf(io.Discard, format, args...)
}
}
Prior to this CL, this integer is heap allocated, even when the
debugEnabled flag is false, and even when the compiler
inlines conditionalDebugf:
v := 1000
conditionalDebugf("hello %d", v)
With this CL, the integer here is no longer heap allocated, even when
the debugEnabled flag is enabled, because the compiler can now see that
it can use a read-only global.
See the writeup in #71359 for more details.
CL 649076 (earlier in our stack) added most of the tests
along with debug diagnostics in convert.go to make it easier
to test this change.
Updates #71359
Updates #62653
Updates #53465
Updates #8618
Change-Id: I19a51e74b36576ebb0b9cf599267cbd2bd847ce4
Reviewed-on: https://go-review.googlesource.com/c/go/+/649079
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-02-12 18:55:04 -05:00
|
|
|
var x interface{} = i // ERROR "0 does not escape"
|
|
|
|
var y interface{} = j // ERROR "0 does not escape"
|
2023-05-23 10:39:43 +07:00
|
|
|
|
|
|
|
sink = x.(int) // ERROR "x.\(int\) escapes to heap"
|
|
|
|
sink, *(&ok) = y.(int) // ERROR "autotmp_.* escapes to heap"
|
|
|
|
}
|
2016-02-13 22:39:16 -08:00
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2016-07-13 12:29:39 -06:00
|
|
|
j := 0 // ERROR "moved to heap: j"
|
|
|
|
var ok bool
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
var x interface{} = &i
|
|
|
|
var y interface{} = &j
|
2016-07-13 12:29:39 -06:00
|
|
|
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 10:56:30 -07:00
|
|
|
sink = x.(*int)
|
2019-04-01 11:58:33 -07:00
|
|
|
sink, *(&ok) = y.(*int)
|
2016-02-13 22:39:16 -08:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 13:30:54 -07:00
|
|
|
|
|
|
|
func issue42279() {
|
|
|
|
type I interface{ M() }
|
|
|
|
type T struct{ I }
|
|
|
|
|
|
|
|
var i I = T{} // ERROR "T\{\} does not escape"
|
|
|
|
i.M() // ERROR "partially devirtualizing i.M to T"
|
|
|
|
}
|