On Thu, Jan 14, 2021 at 3:07 PM roger peppe <rogpe...@gmail.com> wrote: > > FWIW I think that one possible approach to allowing methods (and potentially > function values) with type parameters might be to allow instantiating them > only with a limited set of "shapes" of data (for example, only pointer-like > types). Then I think there's the possibility that the method or function > could be compiled once for each allowed shape but still allow instantiation > with an arbitrary number of types, without the necessity to statically > enumerate all the possible types for that function. > >> We need to instantiate p1.S.Identity[int] somewhere, but how? > > > If one did something like the above, I guess you'd look up the implementation > by shape (8 bytes, non pointer) from the type info in the interface value, > then call the compiled function with the appropriate meta information based > on that. Details left as an exercise for the reader :) > > I don't see that reflection per se would need to be involved, any more than > reflection is involved when doing a dynamic type conversion.
I don't think that approach would work for an implementation that re-compiles the generic function for each set of type arguments. There would be no implementation to select. And, of course, the specific GC shape required might be missing. I think that any choice we make here has to always work reliably. Ian -- 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/CAOyqgcVo4LtwJYwFsxhsAODW5Rrcd7aSRtMR-uENFRF%3DBC0wvA%40mail.gmail.com.