-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
This avoids a dependency on the scala-reflect jar
e66a146
to
618fe96
Compare
Interestingly this revealed a bug in how we set |
I think there might be more issues in |
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
ca2e266
to
b4bf2e3
Compare
@odersky Comments addressed, thanks! The existing |
Interesting, adding the new [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 |
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.
b4bf2e3
to
a2b3bc1
Compare
The issue was due to dotty trying to use the private |
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.