Skip to content

AK: Variant the union thing [2/N] - #26916

Open
Hendiadyoin1 wants to merge 4 commits into
SerenityOS:masterfrom
Hendiadyoin1:variant-p2
Open

AK: Variant the union thing [2/N]#26916
Hendiadyoin1 wants to merge 4 commits into
SerenityOS:masterfrom
Hendiadyoin1:variant-p2

Conversation

@Hendiadyoin1

@Hendiadyoin1 Hendiadyoin1 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This does two things:

  1. Deduplicate Variant Member types before they reach variant proper
    This allows stripping some extra logic from the overload resolution and makes the next step easier
    On clang this might also be a bit nicer on the compiler
  2. Make Variant union based and constexpr capable

@github-actions github-actions Bot added the 馃憖 pr-needs-review PR needs review from a maintainer or community member label Aug 1, 2026
@Hendiadyoin1
Hendiadyoin1 marked this pull request as draft August 1, 2026 10:45
@github-actions github-actions Bot removed the 馃憖 pr-needs-review PR needs review from a maintainer or community member label Aug 1, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Aug 23, 2026
@Hendiadyoin1 Hendiadyoin1 added 馃憖 pr-needs-review PR needs review from a maintainer or community member and removed stale labels Aug 23, 2026
@Hendiadyoin1
Hendiadyoin1 requested a review from alimpfard August 23, 2026 12:22
@github-actions github-actions Bot removed the 馃憖 pr-needs-review PR needs review from a maintainer or community member label Aug 23, 2026
@Hendiadyoin1
Hendiadyoin1 marked this pull request as ready for review August 23, 2026 12:23
@github-actions github-actions Bot added the 馃憖 pr-needs-review PR needs review from a maintainer or community member label Aug 23, 2026
@Hendiadyoin1
Hendiadyoin1 force-pushed the variant-p2 branch 9 times, most recently from efb8776 to ede427e Compare August 28, 2026 09:39
This makes the overload resolution logic a lot cleaner.

If we have needs for duplicate types we can rely on `DedupAndApply` to
strip duplicate types before they reach Variant proper.
For constructing the Storage  we use a sentinel value (`VariantIndex`)
to pass along the desired depth/type into the constructor chain.
This is done as we cant easily start the lifetime of the alternatives
after the union was instantiated.
Upcoming c++26 features should fix this
(see trivial unions (P3074R7) and std::start_lifetime (P3726R2))
For move and copy assignment we destroy the active member, and then
replace the whole storage, trivial unions may also make this nicer.

Also Overload resolution now returns the chosen overload wrapper, which
now also holds the index of that overload, which avoids re-walking the
type list to get the index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

馃憖 pr-needs-review PR needs review from a maintainer or community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant