Oh, I actually wanted to add something about this:

Whether or not this will *actually* end up being static or dynamic dispatch
is, AIUI, intentionally left open
<https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md#efficiency>
in the proposal. The current thinking, AIUI, is that generic functions will
probably be compiled generically (requiring dynamic dispatch) whereas
generic types will probably be compiled specialized (getting static
dispatch).

However, note that whatever strategy we use, can also apply to an
interface-based approach. If the compiler can compile a generic function
Foo(type T)(T) specialized to some concrete type C, it could also
devirtualize an interface-argument and pass it concretely to a specialized
version of Foo. Likewise, in cases when the compiler compiles a generic
version of Foo's body, it will have to pass an implicit type-descriptor for
the operations needed on T - a.k.a. an interface.

I may be missing something fundamental here, but it seems to me that
whatever strategy we use to decide whether we want to compile a specialized
or a generic version of a function body could also be used to decide
whether or not to devirtualize an interface. And if we do so, even
non-generic code would benefit from the performance improvement of static
dispatch, where possible.

Just a thought :)

On Sun, Sep 9, 2018 at 9:10 PM Axel Wagner <axel.wagner...@googlemail.com>
wrote:

> True. You can get static dispatch by
> func ShortestPath(type G Graph(Node, Edge), Node, Edge) (g G, from, to
> Node) []Edge
>
> On Sun, Sep 9, 2018 at 8:21 PM Jonathan Amsterdam <jbamster...@gmail.com>
> wrote:
>
>>
>>> FWIW, in my pseudo-interface description
>>> <https://blog.merovius.de/2018/09/05/scrapping_contracts.html>,
>>>
>>
>>  Unrelated to this particular issue, but since you link to your blog
>> post, I just want to mention that in your graph example,
>>
>>   func ShortestPath(type Node, Edge) (g Graph(Node, Edge), from, to
>> Node) []Edge
>>
>>  will have dynamic dispatches in the body (since g is an ordinary
>> interface value). The one in the draft design is completely static.
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to