Skip to content

Rework tuple projection algorithm#15668

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
gldubc:tuple-projection-exact
Jul 25, 2026
Merged

Rework tuple projection algorithm#15668
josevalim merged 1 commit into
elixir-lang:mainfrom
gldubc:tuple-projection-exact

Conversation

@gldubc

@gldubc gldubc commented Jul 24, 2026

Copy link
Copy Markdown
Member

The previous algorithm had a flawed basis, which was creating errors (different representations of the same type gave different results, see issues #15606 and #15491). This addresses both of them.

I added the regressions found in the issues and their respective PRs (#15492 and #15607) into this, thanks a lot @lukaszsamson!

This PR fixes the flaws in the algorithm, along with an explanation of the correct theoretical basis (the inverse image of insertion-- see this pdf that gives a high level math description. This approach will be useful for future similar problems
tuple_delete_at_issue_short.pdf

Other things:

  • reworked some optimizations that were unreachable or useless
  • renamed tuple_split_negative_pairs_index to tuple_project_negative_pairs, since the function is not splitting anything but projecting each negative into a value/remainder pair to eliminate it

A bit of a big thing: now, tuple_take_element does not return optional types. So we can get rid of field types completely in the tuple projection computations and use opt_(union|intersection|difference) instead of the field_* operations.

After I do the same modifications to map projection, it will compound and more uses of field_* should be removed.

Since I added a few comments, this PR removes 7 locs of program code.

@josevalim
josevalim merged commit e303c78 into elixir-lang:main Jul 25, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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