]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: make interface conversion function selection ABI insensitive
authorCherry Zhang <cherryyz@google.com>
Fri, 9 Apr 2021 18:40:28 +0000 (14:40 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 12 Apr 2021 22:50:31 +0000 (22:50 +0000)
commit49e933fc57c2f858e19c26f4a2e56ba94fc54989
tree1b5d3810f94d9dbbd154ca88553b938d975430d7
parent841bc142160aacde729a983243a0231c8612903d
cmd/compile: make interface conversion function selection ABI insensitive

Before register ABI, we always pass argument in memory, and the
compiler chooses interface conversion functions solely based on
the memory layout. As long as the two types have identical memory
layout, it is fine to mix and match, e.g. convT64 takes a uint64
argument, but it can be used for things like float64 or
struct { x [4]struct{}; y int64 }.

With register ABI, those types may be passed differently, e.g.
uint64 is passed in an integer register, float64 is passed in a
floating point register, the struct above is passed in memory.
I made a few attempts in the previous CLs to try to choose the
right function based on the argument type, but none of them is
really correct.

Instead, this CL changes it to always pass the argument in the
same type the runtime expects, and do conversion before the call
in the compiler. The conversion can be no-op (e.g. a named type
to its underlying type), direct (e.g. int64 to uint64), or
through memory (e.g. *(*uint64)(unsafe.Pointer(&arg))). This way,
the front end does not need to know the ABI. (It only needs to
know how to convert types, and it already does.)

TODO: do something similar for map functions.

Change-Id: I33fc780a47c3f332b765e09b5e527f52ea1d6b5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/309029
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/typecheck/builtin.go
src/cmd/compile/internal/typecheck/builtin/runtime.go
src/cmd/compile/internal/walk/convert.go
src/cmd/compile/internal/walk/order.go
src/runtime/iface.go