Skip to content

Fix map union optimization for open maps#15322

Merged
josevalim merged 1 commit intoelixir-lang:mainfrom
gldubc:fix-optimizer-map-union
Apr 29, 2026
Merged

Fix map union optimization for open maps#15322
josevalim merged 1 commit intoelixir-lang:mainfrom
gldubc:fix-optimizer-map-union

Conversation

@gldubc
Copy link
Copy Markdown
Member

@gldubc gldubc commented Apr 28, 2026

An example of the bus is:

closed = closed_map(a: integer(), b: atom())
open = open_map(a: integer(), b: boolean())

union(closed, open)

The optimizer saw that boolean() is a subtype of atom() (and integer() of integer()) and concluded the open map was contained by the closed map. But that is false: the open map also includes maps with extra keys.

The fix is to make the final subtype shortcut reject that tag mismatch, so if the fields suggest “left is subtype of right” but left is :open and right is :closed, return :none. And vice versa. So the generic union is used then.

@josevalim josevalim merged commit 89e0106 into elixir-lang:main Apr 29, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@gldubc gldubc deleted the fix-optimizer-map-union branch April 29, 2026 09:32
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