Skip to content

Optimize subtype? by aborting early #14561

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

Merged
merged 1 commit into from
Jun 7, 2025
Merged

Optimize subtype? by aborting early #14561

merged 1 commit into from
Jun 7, 2025

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

💚 💙 💜 💛 ❤️

@@ -464,6 +464,26 @@ defmodule Module.Types.Descr do

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.

2 participants