You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Being able to parametrize types ([pos_integer()]) is a critical feature of dialyzer. Support for parametrization is extended to some of remote types (:queue.queue(pos_integer())) but unfortunately not to all of them.
One I miss it the most ability to parametrize Enum (Enum.t(pos_integer())).
It won't help with protocols themselves, but it should with things that use them. For example, we could make spec for Enum.map to be @spec map(t(a), (a -> b)) :: t(b). It is my understanding, it would improve analysis in places where Enum.map is used (but not for Enum.map itself - that's perfectly fine).
Reacted by OvermindDL1, Paul Peregud, John Ev., Angelo Moreira, Awlexus, Mathew Bramson, Łukasz Samson, Qqwy / Marten and Artur Plysiuk
@josevalim Do we consolidate the typespecs as well? Otherwise I don't think Dialyzer can make the connection since the type has to be based on term: @type t(inner) :: term.
We know the shape of the types we dispatch on, so we can leverage that and
consolidate it in the same way we consolidate dispatch. However, for things
like parameterized types, the implementation will have to outline that.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
How do we know the shape of the types we dispatch on, do you mean we should assume that ImplModule.t is the type? What if the implementation type has a different number of parameters?
We will need a way to declare that the protocol type is parameterized.
That’s the part that needs to be done, I think.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
Protocol might use a module attribute @typeprotocol (or @type_protocol) or a macro to define the signature of the types; and the implementation might optionally define the types specified in the protocol using the regular @type syntax. During the consolidation process, the types defined in the protocol would be generated by inspecting the typespecs of the different implementations.
@fertapric that's a step in the right direction. The only issue is that @type/@spec/@opaque/@typep are specialish and I wouldn't want to introduce another special module attribute. But we could do it with something like:
Reacted by Michał Muskała, Fernando Tapia Rico, Awlexus, Edenilson Ferreira, Paul Peregud, Kelvin Stinghen, Tomasz Marek Sulima, Dmitrii Novikov, gitneko, Jonatan Männchen and 1 more
Can someone explain why we would need special support for parameterized protocol types?
Given that:
We can @spec private functions.
We can freely add custom @types and @specs to both our defprotocol module and our defimpl modules
-> it should be possible to generate the consolidated protocol module in a way where protocol dispatch calls the particular private function implementation taken from the particular defimpl which will receive any @spec(s) indicated for that particular implementation.
We need to rewrite the protocol types to point only to the possible implementations, instead of today’s term. I.e, we need to make Enumerable.t(integer) point to t/1 of each implementation.
We no longer plan to explore this for now, as there is research on a new type system, which could have first class support for protocols, rather than enabling this on top of Dialyzer.
Reacted by CptBreeza, Andrea Leopardi and Joe Martinez
Activity
[-]feature request: parametrized remote types for typespec[/-][+]Parametrized remote types for protocols[/+]ericmj commentedon Apr 9, 2018
Parameterized types for protocols can be useful for documentation but I don't believe they will help dialyzer analysis.
josevalim commentedon Apr 9, 2018
@ericmj they should help once protocols are consolidated, which are most of the cases now.
michalmuskala commentedon Apr 9, 2018
It won't help with protocols themselves, but it should with things that use them. For example, we could make spec for
Enum.mapto be@spec map(t(a), (a -> b)) :: t(b). It is my understanding, it would improve analysis in places whereEnum.mapis used (but not forEnum.mapitself - that's perfectly fine).ericmj commentedon Apr 9, 2018
@josevalim Do we consolidate the typespecs as well? Otherwise I don't think Dialyzer can make the connection since the type has to be based on
term:@type t(inner) :: term.josevalim commentedon Apr 9, 2018
@ericmj that will be part of the work that needs to be done. :) Yes.
ericmj commentedon Apr 9, 2018
Can you elaborate on how would that work?
josevalim commentedon Apr 9, 2018
ericmj commentedon Apr 9, 2018
How do we know the shape of the types we dispatch on, do you mean we should assume that
ImplModule.tis the type? What if the implementation type has a different number of parameters?josevalim commentedon Apr 9, 2018
fertapric commentedon Dec 13, 2018
Here is an idea.
Protocol might use a module attribute
@typeprotocol(or@type_protocol) or a macro to define the signature of the types; and the implementation might optionally define the types specified in the protocol using the regular@typesyntax. During the consolidation process, the types defined in the protocol would be generated by inspecting the typespecs of the different implementations.Here is an example:
Thoughts?
josevalim commentedon Dec 13, 2018
@fertapric that's a step in the right direction. The only issue is that
@type/@spec/@opaque/@typepare specialish and I wouldn't want to introduce another special module attribute. But we could do it with something like:Or something of sorts.
CptBreeza commentedon Oct 10, 2021
Any further progress on this?
Qqwy commentedon Oct 12, 2021
Can someone explain why we would need special support for parameterized protocol types?
Given that:
@specprivate functions.@types and@specs to both ourdefprotocolmodule and ourdefimplmodules-> it should be possible to generate the consolidated protocol module in a way where protocol dispatch calls the particular private function implementation taken from the particular
defimplwhich will receive any@spec(s) indicated for that particular implementation.Am I missing something?
josevalim commentedon Oct 12, 2021
We need to rewrite the protocol types to point only to the possible implementations, instead of today’s term. I.e, we need to make Enumerable.t(integer) point to t/1 of each implementation.
josevalim commentedon Jul 27, 2022
We no longer plan to explore this for now, as there is research on a new type system, which could have first class support for protocols, rather than enabling this on top of Dialyzer.
Papipo commentedon Mar 10, 2023
@josevalim where can I read about that and what's it status? Thanks! 🙇🏽
josevalim commentedon Mar 10, 2023
The official Elixir blog is where we will post updates. The last one was: https://elixir-lang.org/blog/2022/10/05/my-future-with-elixir-set-theoretic-types/