Skip to content

Remove most uses of scala-reflect jar #2062

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

Merged
merged 11 commits into from
Mar 8, 2017

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 7, 2017

The remaining uses of scala-reflect (scala.reflect.io.*, scala.reflect.internal.util.WeakHashSet) cannot be removed until we integrate the backend in the dotty repo.

@smarter smarter requested a review from odersky March 7, 2017 16:23
@smarter smarter force-pushed the fix/scala-reflect-dep branch from e66a146 to 618fe96 Compare March 7, 2017 17:55
@smarter
Copy link
Member Author

smarter commented Mar 7, 2017

Interestingly this revealed a bug in how we set PureInterface which is now fixed by the latest commit.

@smarter
Copy link
Member Author

smarter commented Mar 7, 2017

I think there might be more issues in defKind but this is off-topic, I'll open an issue after this PR is merged.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

case tree: DefDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else NoInits
case tree: DefDef =>
if (tree.unforcedRhs == EmptyTree)
(NoInitsInterface /: tree.vparamss.flatten)((fs, vparam) => fs & defKind(vparam))
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not understand why the change. I assume it has to do with default arguments? But, first, if a parameter has a default value the enclosing trait it's still a NoInits, and second, won't we then see the default method which gives us the right DefKind anyway?

Copy link
Member Author

@smarter smarter Mar 7, 2017

Choose a reason for hiding this comment

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

Yes, it's for default arguments, the corresponding commit message gives more information: 618fe96

if a parameter has a default value the enclosing trait is still a NoInits

Ah indeed, I missed that.

won't we then see the default method which gives us the right DefKind anyway?

No, because defKind is called on each element of the body of the class before they are desugared.

It would be much simpler if defKind was called after desugaring (and would also avoid other issues with default parameters of class constructors for example) but I don't know what that would involve.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. I missed the context before. defKind is called before the trees are desugared. Yes, then we need to do it as you describe except for the NoInits issue. Also since we traverse all methods of a trait here I'd avoid creating too much garbage via flatten. I'd just do a double forall:

if (tree.unforcedRhs == EmptyTree) && tree.vparamss.forall(_.forall(_.rhs.isEmpty)) NoInitsInterface else NoInits

@@ -0,0 +1,39 @@
/* NSC -- new Scala compiler
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this file not duplicate standard collection functionality? Why keep it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine either way, apparently the original motivation for these methods is that they're faster than doing the equivalent using chains of methods from the standard library

Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt it. If we do want to keep these methods, we should also move them to Decorators.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would map2 be decorated on? Anyway, I'll just remove those methods in favor of the standard library, it shouldn't make much of a difference.

package dotc
package util

/** This object provides utility methods to extract elements
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should go in StringDecorator in file Decorators.scala

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

@smarter smarter force-pushed the fix/scala-reflect-dep branch 2 times, most recently from ca2e266 to b4bf2e3 Compare March 8, 2017 09:41
@smarter
Copy link
Member Author

smarter commented Mar 8, 2017

@odersky Comments addressed, thanks! The existing StringDecorators was an instance of PreName so it felt wrong to add random methods to it, instead I renamed it to PreNamedString and added a new StringDecorators implicit class. I updated individual commits in this PR to have a cleaner history but that makes it harder to review the changes, you can see the diff from the previous set of commits at dotty-staging@fa6f988

@smarter
Copy link
Member Author

smarter commented Mar 8, 2017

Interesting, adding the new StringDecorator broke the bootstrap in a weird way:

[error] -- [E008] Member Not Found Error: /home/smarter/opt/dotty/compiler/src/dotty/tools/dotc/core/Comments.scala 
[error] 405 |      defs(sym) ++= defines(raw).map {
[error]     |      ^^^^^^^^^^^^^
[error]     |value `++=` is not a member of scala.collection.immutable.Map[String, String] - did you mean `scala$collection$MapLike$$B.+`?
[error] -- [E008] Member Not Found Error: /home/smarter/opt/dotty/compiler/src/dotty/tools/dotc/typer/Docstrings.scala 
[error] 41 |          tplExp.defineVariables(sym)
[error]    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value `++=` is not a member of scala.collection.immutable.Map[String, String] - did you mean `scala$collection$MapLike$$B.+`?

The errors go away if I unimport StringDecorator, I'll investigate.

smarter added 5 commits March 8, 2017 13:30
The default param will be desugared into a method with a body, so
setting PureInterface would be wrong. The enclosed test previously
failed with a pickling difference, because the unpickler correctly
decided to not set the PureInterface flag since it saw the default param
method.

This fixes the tasty_dotc_util which failed since the last commit
because FreshNameCreator was now incorrectly recognized as a PureInterface.
@smarter smarter force-pushed the fix/scala-reflect-dep branch from b4bf2e3 to a2b3bc1 Compare March 8, 2017 12:30
@smarter
Copy link
Member Author

smarter commented Mar 8, 2017

The issue was due to dotty trying to use the private splitAt in StringDecorator, I've fixed that by hiding splitAt better but I'll open an issue for that.

@smarter smarter merged commit c844809 into scala:master Mar 8, 2017
@allanrenucci allanrenucci deleted the fix/scala-reflect-dep branch December 14, 2017 19:23
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.

2 participants