I got an answer at https://github.com/golang/go/issues/48849 - this happens
because the compiler
uses the same implementation for any type satisfying the constraint.
On Sunday, 3 October 2021 at 17:50:34 UTC+1 Bryan Boreham wrote:
> I observed that the regexp package has a pool of onePassMachine objects,
> which I believe exist to avoid allocation due to heap escape caused by
> calling through the 'inputs' interface.
>
> I expected that, using generics, I can replace that interface with a type
> parameter, and hence do away with the need for the pool.
>
> My trial implementation is here:
> https://github.com/golang/go/compare/master...bboreham:generic-exec
>
> But it does not succeed: the generic parameter escapes to the heap.
> Compiler says:
>
> regexp/exec.go:391:37: parameter i leaks to {heap} with derefs=0:
> regexp/exec.go:391:37: flow: {heap} = i:
> regexp/exec.go:391:37: from unsafe.Pointer(i) (interface-converted) at
> regexp/exec.go:412:14
> regexp/exec.go:391:37: from ().step(pos) (call parameter)
> at regexp/exec.go:412:19
>
> Am I holding it wrong? Why does i get "interface-converted" ?
>
> Thanks,
>
> Bryan
>
--
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 on the web visit
https://groups.google.com/d/msgid/golang-nuts/25e7a016-f6ff-428d-92fb-57cf49d73f40n%40googlegroups.com.