mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 10:43:29 +00:00
compiler: implement unsafe.Alignof and unsafe.Sizeof for generic code
For some reason, these aren't lowered when a generic function is instantiated by the SSA package. I've left unsafe.Offsetof to be implemented later, it's a bit difficult to do correctly the way the code is currently structured.
This commit is contained in:
committed by
Ron Evans
parent
70c52ef1b4
commit
7b1e5f6f99
Vendored
+6
@@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type Coord interface {
|
||||
int | float32
|
||||
}
|
||||
@@ -9,6 +11,8 @@ type Point[T Coord] struct {
|
||||
}
|
||||
|
||||
func Add[T Coord](a, b Point[T]) Point[T] {
|
||||
checkSize(unsafe.Alignof(a))
|
||||
checkSize(unsafe.Sizeof(a))
|
||||
return Point[T]{
|
||||
X: a.X + b.X,
|
||||
Y: a.Y + b.Y,
|
||||
@@ -22,3 +26,5 @@ func main() {
|
||||
var ai, bi Point[int]
|
||||
Add(ai, bi)
|
||||
}
|
||||
|
||||
func checkSize(uintptr)
|
||||
|
||||
Reference in New Issue
Block a user