Skip to content
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

Merged
merged 9 commits into from
Jan 25, 2024
Merged

Conversation

gldubc
Copy link
Member

@gldubc gldubc commented Jan 23, 2024

The :atom field of the descr now represents all possible atom types.
It is done with a pair {tag, set} where set 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}

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.
Copy link
Contributor

@sabiwara sabiwara left a 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 💜

@sabiwara
Copy link
Contributor

@gldubc seems you got a bootstrapping error from the CI because the MapSet module can't be compiled.
I think we can just use the :sets module directly (used internally in MapSet actually): :sets.new(version: 2). Also it should have slightly less overhead.

@gldubc
Copy link
Member Author

gldubc commented Jan 24, 2024

I think this PR is complete now. :)

@@ -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])
Copy link
Contributor

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:

Suggested change
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

Copy link
Member Author

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

Copy link
Contributor

@sabiwara sabiwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@josevalim josevalim merged commit 035ff54 into elixir-lang:main Jan 25, 2024
8 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@gldubc gldubc deleted the atom-types branch January 29, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants