Skip to content

Support Mirror for generic tuples arity > 22 #23363

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eejbyfeldt
Copy link

fixes #15398

@eejbyfeldt eejbyfeldt marked this pull request as ready for review June 14, 2025 04:46

summon[Tuple.Size[Tuple23] =:= 23]
val m = summon[scala.deriving.Mirror.Of[Tuple23]]
summon[m.MirroredLabel =:= "Tuple23"]
Copy link
Member

@bishabosha bishabosha Jun 14, 2025

Choose a reason for hiding this comment

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

I guess this is the main bike-shedding moment - i.e. should it include arity, or just Tuple (or another variant) - i.e. case class can evolve over time to add new fields but its MirroredLabel doesn't change - so I dont think unique label is necessary.

Copy link
Member

Choose a reason for hiding this comment

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

should also update the docs (or create an issue to) for Mirror generation here https://www.scala-lang.org/api/3.7.1/docs/docs/reference/contextual/derivation.html

Copy link
Author

Choose a reason for hiding this comment

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

Created #23475 for the docs because it was not immediately clear to me how to resolve it.

case class can evolve over time to add new fields but its MirroredLabel doesn't change - so I dont think unique label is necessary.

For named tuples it always "NamedTuple". So based on that we should not include the arity, but should we then also drop it for arity < 22 to avoid inconsistency?

I guess this is the main bike-shedding moment - i.e. should it include arity, or just Tuple (or another variant) - i.e.

Is there so good way to make progress on this. Feel like someone just need to make a decision.

Copy link
Member

Choose a reason for hiding this comment

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

Well we should not change existing behaviour so I would just use Tuple as the label for size >=23

Copy link
Author

Choose a reason for hiding this comment

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

Should I read that as you are suggesting changing the PR to have that behavior instead of including the arity? Or it just a comment that we should not break existing behavior.

Copy link
Member

@bishabosha bishabosha Jul 4, 2025

Choose a reason for hiding this comment

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

but should we then also drop it for arity < 22 to avoid inconsistency?

no, because that would change the behavior. Anyway my code suggestions are what i meant :)

@eejbyfeldt eejbyfeldt requested a review from bishabosha July 4, 2025 11:41
else
val elemLabels = (for i <- 1 to arity yield ConstantType(Constant(s"_$i"))).toList
val mirrorRef: Type => Tree = _ => newTupleMirror(arity)
makeProductMirror(tps, elemLabels, s"Tuple$arity".toTermName, mirrorRef)
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
makeProductMirror(tps, elemLabels, s"Tuple$arity".toTermName, mirrorRef)
makeProductMirror(tps, elemLabels, defn.TupleClass.name, mirrorRef)

Copy link
Member

Choose a reason for hiding this comment

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

to use a cached name - another option is define tpnme.Tuple

Copy link
Author

Choose a reason for hiding this comment

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

Added tpnme.Tuple


summon[Tuple.Size[Tuple23] =:= 23]
val m = summon[scala.deriving.Mirror.Of[Tuple23]]
summon[m.MirroredLabel =:= "Tuple23"]
Copy link
Member

@bishabosha bishabosha Jul 4, 2025

Choose a reason for hiding this comment

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

but should we then also drop it for arity < 22 to avoid inconsistency?

no, because that would change the behavior. Anyway my code suggestions are what i meant :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to support Mirrors for Generic Tuples arity +22
2 participants