-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add atom singleton types to descr #13277
Conversation
The :atom field now contains a representation for all possible atom types. The representation is a pair `{s, bool}` where `s` is a set of atoms. If `bool` is `true` it represents the union of the atoms in `s`. Else, it represents every atom except those in `s`. `boolean()` is defined as the singletons true, false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I commented too early and the implementation might still change.
Really exciting PR 💜
Co-authored-by: Jean Klingler <[email protected]>
Co-authored-by: Jean Klingler <[email protected]>
@gldubc seems you got a bootstrapping error from the CI because the MapSet module can't be compiled. |
I think this PR is complete now. :) |
lib/elixir/lib/module/types/descr.ex
Outdated
@@ -50,6 +51,8 @@ defmodule Module.Types.Descr do | |||
def reference(), do: %{bitmap: @bit_reference} | |||
def tuple(), do: %{bitmap: @bit_tuple} | |||
|
|||
def boolean(), do: atom([true, false]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could reuse your @boolset
here so all calls to this function could return the same structure instead of generating a new one:
def boolean(), do: atom([true, false]) | |
def boolean(), do: {:union, @boolset} |
Here is a quick illustration:
defmodule Foo do
@boolset :sets.new(version: 2)
def bool1, do: {:union, @boolset}
def bool2, do: {:union, :sets.new(version: 2)}
end
iex> Foo.bool1() === Foo.bool2()
true
iex> :erts_debug.same(Foo.bool1(), Foo.bool1())
true
iex> :erts_debug.same(Foo.bool2(), Foo.bool2())
false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see; thanks for the illustration! Pushing that change as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
💚 💙 💜 💛 ❤️ |
The :atom field of the descr now represents all possible atom types.
It is done with a pair
{tag, set}
whereset
is a set of atoms.If
tag = :union
the pair represents the union of the atoms in s.Else, if
tag = :negation
, it represents every atom except those in s.boolean() is defined as the union of the singletons true, false
edit: re-wrote description using tagged pairs instead of
{set, bool}