I can't explain exactly because my explanation is likely very flawed, but the logic you are looking for is in https://github.com/golang/go/blob/320ddcf8344beb1c322f3a7f0a251eea5e442a10/src/cmd/compile/internal/gc/inl.go#L186. Basically, labeled loops are not considered "hairy" by the compiler and can be inlined.
On Mon, Aug 29, 2016 at 7:40 AM, Ariel Mashraki <ariel.mashr...@ironsrc.com> wrote: > Hello, > > Running `go build -gcflags -m` on the given code below will produce: > > > main.go:3: can inline f1 > > main.go:24: inlining call to f1 > > > Can someone please explain why doesn't the f2 function get inlined ? > > Thanks > > > > package main > > func f1() int { > > i := 0 > > loop: > > if i > 10 { > > return i > > } > > i++ > > goto loop > > } > > func f2() int { > > i := 0 > > for { > > if i > 10 { > > return i > > } > > i++ > > } > > } > > > func main() { > > f1() > > f2() > > } > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.