compiler: avoid bitcast when replacing a method call with a direct call

A bitcast was inserted when the receiver of the call wasn't a *i8. This
is a pretty common case, and did not play well with goroutines.
Avoid this bitcast by changing each call to a direct call, after
unpacking the receiver type from the *i8 parameter. This might also fix
some undefined behavior in the resulting program, as it is technically
not allowed to call a function with a different signature (even if the
signature is compatible).
This commit is contained in:
Ayke van Laethem
2019-04-29 00:12:34 +02:00
committed by Ron Evans
parent 387e1340bf
commit 99da328453
3 changed files with 50 additions and 4 deletions
+16
View File
@@ -21,6 +21,10 @@ func main() {
go nowait()
time.Sleep(time.Millisecond)
println("done with non-blocking goroutine")
var printer Printer
printer = &myPrinter{}
printer.Print()
}
func sub() {
@@ -38,3 +42,15 @@ func wait() {
func nowait() {
println("non-blocking goroutine")
}
type Printer interface {
Print()
}
type myPrinter struct{
}
func (i *myPrinter) Print() {
time.Sleep(time.Millisecond)
println("async interface method call")
}
+1
View File
@@ -9,3 +9,4 @@ wait:
end waiting
non-blocking goroutine
done with non-blocking goroutine
async interface method call