Why does the min function not get inlined ?
% cat min.go
package main
import "fmt"
func min(a, b int) int {
if a < b {
return a
}
return b
}
func main() {
fmt.Println(min(5, 10))
}
% 8g -l -l min.go
%
Cheers
Dave
from CL 5400043:
"Cross- and intra package inlining of single assignments or return
<expression>."
i don't think if statements are there yet.
func min(a, b int) int {
return b
}
Dave.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Oh this is neat! No idea what or how high the "budget" is in the current implementation, but I trust it is chosen wisely =)
I think that one motivation is that if the go compiler inlines a function, it will never ever affect a stack trace. If an inlined function *did* panic, it might be confusing to figure out the source of the error (since the stack doesn't correspond to the code).
Just curious, can go inline functions defined in a different package?Let's say I implement a vector math package and use in a 3d engine, would the compiler inline calls to the vector math functions?