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

Exclude universal members (getClass, toString, etc) from root module import #8541

Merged
merged 1 commit into from Nov 18, 2019

Conversation

som-snytt
Copy link
Contributor

definitions.isImportable makes the faulty assertion that universal members are not importable.

In fact, they are imported by default from Predef. This is observable in scala 2 imports and in scala 3 top level definitions.

Fixes scala/bug#5389

@scala-jenkins scala-jenkins added this to the 2.13.2 milestone Nov 15, 2019
Copy link
Member

@hrhino hrhino left a comment

Choose a reason for hiding this comment

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

Thanks. I hate to give the impression that I'm an easier reviewer than all the rest, but lgtm.

This can't have been strange enough to be a puzzler, right? I'm always concerned that we give thought to breaking our users but very little to the puzzlers guy. Should we add it to the community build?

@@ -0,0 +1,4 @@

import ne.scala
Copy link
Member

Choose a reason for hiding this comment

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

So @jducoeur's paying you under the table after all, hmm.

Choose a reason for hiding this comment

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

I've owned the domain for less than 24 hours, and I'm already a world power!


c.initRootContext(throwing, checking)
c
contextWithXML.make(tree, unit = unit).tap(_.initRootContext(throwing, checking))
Copy link
Member

Choose a reason for hiding this comment

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

Fancy!

@lrytz lrytz merged commit 6766e23 into scala:2.13.x Nov 18, 2019
@som-snytt
Copy link
Contributor Author

The improvement would be to construct the masking selectors for universal members only once.

@som-snytt som-snytt deleted the issue/5389 branch November 18, 2019 16:24
val sels = universals.iterator
.map(ImportSelector.mask).toList
.appended(ImportSelector.wild)
c.make(gen.mkImportFromSelector(sym, sels), unit = unit)
Copy link
Member

@retronym retronym Nov 20, 2019

Choose a reason for hiding this comment

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

This hurts compiler performance markedly. I haven't investigated profiles, so I'm not sure whether the cost is creating this Import or the overhead of subsequent symbol lookups using it rather than the simple wildcard.

Could we instead make ImportInfo.importedSymbol exclude these, perhaps conditionally on isRootImport?

It already filters its results through isUnimportable which excludes constructors and private[this]. There is also logic in there that purports to stop all imports of members of AnyRef, but was disabled fully, maybe unintentionally, in 2b4cd6c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely for minor values of major.

Copy link
Member

Choose a reason for hiding this comment

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

I was more worried about compiler performance when merging this one: https://github.com/scala/scala/pull/8538/files#diff-62ccdfe29e58b8e9f06ed66d4cfc88a5R590-R593

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically Any is not your friend. And how could it be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JZ's improvement in the linked PR. I'll follow up by running benchmarks and then by putting LR's mind at ease, if I am able.

@SethTisue
Copy link
Member

I've added the "release notes" since two projects in the community build were affected: akka/akka#28355, lagom/lagom#2579

@som-snytt
Copy link
Contributor Author

See hrhino's prescient approval comment above:

Should we add it to the community build?

This can't have been strange enough to be a puzzler, right?

Also the part where he cops to being an easy review.

It's been said many times on this project that there is no bug so outré that no code in the wild relies on it.

This behavior was actually as specified and not a bug; it could have been a lint. In fact, I am inclined to demote it to lint. WDYT @SethTisue @hrhino ? Or leave it as it is, because it's always a bug? In that case, we can make it a non-lint warning without irking anyone; a behavior change can be irksome; if only we could specify what java.lang and scala.Predef export!

@SethTisue SethTisue changed the title Exclude universal members from root module import Exclude universal members (getClass, toString, etc) from root module import Feb 11, 2020
@SethTisue
Copy link
Member

SethTisue commented Feb 14, 2020

I think I would have also signed off on a PR that made it a lint. mainly, I am happy we now have one or the other, rather than neither.

@hrhino
Copy link
Member

hrhino commented Feb 14, 2020

Thanks for the reminder to get my NEScala tickets.

@som-snytt
Copy link
Contributor Author

So long as you both are happy.

I don't like that it's a bit of a special case, but there's nothing which says the spec can't specify that root contexts work like the first implementation, masking Any-defined members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
7 participants