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

Optimize :term #13625

Merged
merged 6 commits into from
Jun 2, 2024
Merged

Optimize :term #13625

merged 6 commits into from
Jun 2, 2024

Conversation

josevalim
Copy link
Member

No description provided.

@@ -783,6 +844,10 @@ defmodule Module.Types.Descr do
end)
end)
end)
|> case do
[] -> 0
Copy link
Member Author

Choose a reason for hiding this comment

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

@gldubc you will have to do the same for tuples. We no longer match empty list as empty on intersection/difference. It is either zero or an empty map.

@josevalim josevalim closed this May 31, 2024
@josevalim josevalim reopened this May 31, 2024
Copy link
Member

@gldubc gldubc left a comment

Choose a reason for hiding this comment

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

Looks good to me! 👍🏻

Comment on lines +91 to +99
defguardp is_optional(map)
when is_map(map) and
((is_map_key(map, :bitmap) and (map.bitmap &&& @bit_optional) != 0) or
(is_map_key(map, :dynamic) and is_map(map.dynamic) and
is_map_key(map.dynamic, :bitmap) and
(map.dynamic.bitmap &&& @bit_optional) != 0))

defguardp is_optional_static(map)
when is_map(map) and is_map_key(map, :bitmap) and (map.bitmap &&& @bit_optional) != 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defguardp is_optional(map)
when is_map(map) and
((is_map_key(map, :bitmap) and (map.bitmap &&& @bit_optional) != 0) or
(is_map_key(map, :dynamic) and is_map(map.dynamic) and
is_map_key(map.dynamic, :bitmap) and
(map.dynamic.bitmap &&& @bit_optional) != 0))
defguardp is_optional_static(map)
when is_map(map) and is_map_key(map, :bitmap) and (map.bitmap &&& @bit_optional) != 0
defguardp is_optional_static(map)
when is_map(map) and is_map_key(map, :bitmap) and (map.bitmap &&& @bit_optional) != 0
defguardp is_optional(map)
when is_optional_static(map) or
(is_map(map) and is_map_key(map, :dynamic) and is_optional_static(map.dynamic))

possibly easier to read

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 will check later if the Erlang compiler optimizes the duplicate checks efficiently and merge your proposal. :)

@josevalim josevalim merged commit 11aa0fc into main Jun 2, 2024
18 checks passed
@josevalim josevalim deleted the jv-optimize-term branch June 2, 2024 12:58
@josevalim
Copy link
Member Author

💚 💙 💜 💛 ❤️

josevalim added a commit that referenced this pull request Jun 2, 2024
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