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

[bug#11687] Don't rebuild scala.Seq to drop elems in unapplySeq #8340

Merged
merged 1 commit into from Aug 19, 2019

Conversation

NthPortal
Copy link
Contributor

@NthPortal NthPortal requested a review from smarter August 15, 2019 17:49
@scala-jenkins scala-jenkins added this to the 2.13.1 milestone Aug 15, 2019
@@ -1,3 +1,3 @@
object Test extends App{
LazyList.from(1) match { case LazyList(1, 2, x @_*) => println("It worked!") }
LazyList.from(1) match { case LazyList(1, 2, x @_*) => println(s"It worked! (class: ${x.getClass.getSimpleName})") }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change to prevent DCE

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean that the match expression was not even evaluated because of DCE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, based on @smarter's comment, just the x @_* (which is UnapplySeqWrapper#drop) wasn't evaluated?

Copy link
Member

Choose a reason for hiding this comment

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

patmat never generates the code in the first place if the symbol is unused.

@diesalbla diesalbla added the library:collections PRs involving changes to the standard collection library label Aug 15, 2019
def drop(n: Int): scala.Seq[A] = c.view.drop(n).toSeq
def drop(n: Int): scala.Seq[A] = c match {
case seq: scala.Seq[A] => seq.drop(n)
case _ => c.view.drop(n).toSeq
Copy link
Member

Choose a reason for hiding this comment

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

In which situation is it actually a good idea to go through a view here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

going through a view avoids building an unnecessary intermediate collection (with the same type as c)

Copy link
Member

Choose a reason for hiding this comment

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

Right, but that's only true for types which aren't Seq but use UnapplySeqWrapper. Which types are those exactly? Do we have test cases that exercise this code path ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't. and they will still be forced.

I think saying that it ought to be LazyList.from(c.view.drop(n)) (or LazyList.from(c).drop(n)) to preserve laziness is valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can hear @dwijnand's voice in my head asking if this is really all necessary and the best design

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but that's only true for types which aren't Seq but use UnapplySeqWrapper. Which types are those exactly?

All the mutable.Seq leaves.

Copy link
Member

@szeiger szeiger left a comment

Choose a reason for hiding this comment

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

This is a lot simpler than what I had in mind.

@julienrf
Copy link
Contributor

Thanks @NthPortal 👍

@julienrf julienrf merged commit 7c354fc into scala:2.13.x Aug 19, 2019
@NthPortal NthPortal deleted the topic/bug#11687/PR branch August 19, 2019 20:56
@szeiger szeiger added the release-notes worth highlighting in next release notes label Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:collections PRs involving changes to the standard collection library release-notes worth highlighting in next release notes
Projects
None yet
6 participants