As far as I know all the implementations of go do monomorphization of 
generic parameters at least by the memory layout of used types. This means 
that while not everything is known about the type at compile-time, at least 
it's size surely is. And we easily can create new types containing generic 
fields like that:
```go
type Foo[T any] struct {
    foo T
}
```
which means Foo size in bytes depends on the size of generic parameter T.
Also since some builtin functions are usable in constant context, we can 
actually create static arrays of size of some particular type resolved in 
compile-time like that:
```go
type Bar struct {
    bar [unsafe.Sizeof(uint64(0))]bytes
}
```
But we cannot define types, which memory layout depends on the generic type 
parameter in more complex ways (but still using only constant functions) 
like that:
```go
type Baz[T any] struct {
    baz [unsafe.Sizeof(*new(T))]byte
}
```
because:
```
array length unsafe.Sizeof(*new(T)) (value of type uintptr) must be constant
```
But isn't it already? Sure it depends on the particular T passed to the 
type, but it will be monomorphized by size anyway and (if compiled) would 
have exactly the same memory layout as Foo[T].

Why exactly isn't it possible in the current (I use go 1.24.5) compiler? Is 
it simply unimplemented, impossible for some unknown to me reason (would 
like to read the actual explaination) or undesirable and forbidden (also, 
why?)?

-- 
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.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/01b8ebdb-c386-460c-ac09-596605bf4f18n%40googlegroups.com.

Reply via email to