Skip to content

Conversation

@josevalim
Copy link
Member

In the same way we introduced non_disjoint_intersection
to optimize compatibility, we introduce empty_difference
to optimize subtyping.

In the same way we introduced non_disjoint_intersection
to optimize compatibility, we introduce empty_difference
to optimize subtyping.
@josevalim josevalim merged commit 577c803 into main Jun 7, 2025
26 checks passed
@josevalim josevalim deleted the jv-optimize-subtype branch June 7, 2025 13:35
@josevalim
Copy link
Member Author

💚 💙 💜 💛 ❤️


defp iterator_difference_static(:none, map), do: map

defp empty_difference_static?(left, :term), do: not Map.has_key?(left, :optional)
Copy link
Contributor

Choose a reason for hiding this comment

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

@josevalim sorry asking for my understanding, couldn't figure this one out.

What would be an example case that justifies checking for optional?

Currently the following seems to pass all the tests, so it's probably not covered:

-  defp empty_difference_static?(left, :term), do: not Map.has_key?(left, :optional)
+  defp empty_difference_static?(left, :term), do: true

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 don't think there is a practical example, but i am keeping semantic equivalence with the empty? function. empty? check if all fields empty and, if optional is set, it is not considered empty. So I am doing the same here. I have asked @gldubc if empty?(optional(none()) is true or false.

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.

3 participants