-
Notifications
You must be signed in to change notification settings - Fork 185
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
Upgrade to Scalameta v4.0.0-M4 #756
Conversation
The plugin will be moved to a separate repo.
project/ScalafixBuild.scala
Outdated
"-Xplugin-require:semanticdb" | ||
"-Xplugin-require:semanticdb", | ||
"-P:semanticdb:synthetics:on", | ||
"-P:semanticdb:text:on" |
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.
Is -P:semanticdb:text
still required?
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.
Opened #757 to track this. This PR is already a lot, prefer to delegate this to a another PR.
project/ScalafixBuild.scala
Outdated
@@ -74,7 +74,9 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { | |||
lazy val semanticdbSettings = Seq( | |||
scalacOptions ++= List( | |||
"-Yrangepos", | |||
"-Xplugin-require:semanticdb" | |||
"-Xplugin-require:semanticdb", | |||
"-P:semanticdb:synthetics:on", |
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 functionality requires -P:semanticdb:synthetics
?
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.
The NoInfer
rule requires the setting, I've updated the docs to tell users they need this setting for this rule.
case _ => | ||
throw new IllegalArgumentException(info.toProtoString) | ||
} | ||
} |
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 wonder where this comes into play?
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 renamed the method to .valueType
, it's a helper method to get the type of a ValueSignature
or fail.
private implicit class XtensionScopeHardlinks(scope: s.Scope) { | ||
def infos: List[s.SymbolInformation] = | ||
if (scope.hardlinks.isEmpty) scope.symlinks.iterator.map(info).toList | ||
else scope.hardlinks.toList |
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.
Don't we already have a method like that in semanticdb
?
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.
There is a method like this but it requires access to a symbol table to resolve the symlinks.
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.
Ah, I missed the .map(info)
part.
!sym.contains("$anon")) | ||
val typeParameters = classInfo.typeParameters | ||
val parents = classInfo.parents | ||
decls.infos.filter(info => !info.symbol.contains("$anon")) |
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.
Is this filter still necessary after all the fixes that we did around 4.0.0-M2?
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.
Good question. Doesn't seem required anymore, I removed it.
if (shorten.isName) { | ||
name | ||
} else { | ||
toTypeRef(info(symbol)) | ||
} | ||
case _: s.SingleType | _: s.ThisType | _: s.SuperType | | ||
_: s.ConstantType => | ||
Type.Select(toTermRef(prefix), name) |
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.
Can a constant type be a prefix to anything?
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 don't think so, removing it seems to be OK. This was a direct refactoring of the old implementation. Hurray for breaking down SingletonType
🎉
Type.Name(this.info(symbol).name) | ||
) | ||
case s.SuperType(prefix @ _, symbol) => | ||
// TODO: prefix |
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.
FIXME with a ticket?
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.
Done.
case s.ConstantType(_) => | ||
toType(tpe.widen) | ||
case s.ExistentialType(underlying, Some(declarations)) => | ||
withHardlinks(declarations.hardlinks) { () => |
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.
How did you find dealing with hardlinks?
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.
It's been great so far 😊 Removed a lot of ???
/WTFs in the old implementation. I currently keep a mutable scope for hardlink lookups, I could make it immutable but that would require adding a (hardlinks: Map[String, SymbolInformation)
parameter everywhere for questionable benefit.
import scala.meta.internal.semanticdb.Scala._ | ||
import scalafix.internal.util.SymbolOps.Root | ||
|
||
sealed trait Symbol extends Product { |
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.
Oh hey. Long time no see :)
@@ -47,13 +46,13 @@ class PrettyTypeSuite extends BasePrettyTypeSuite { | |||
} | |||
|
|||
// This test is slow, no need to run it on every PR | |||
@Ignore | |||
//@Ignore |
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.
Is this comment accidental?
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.
Removed the comment.
- Fix TODOs: - Print Defn.Object types - Print all s.Accessibility tags - Print Pkg.Object - Add `fatalErrors: Boolean` option to optionally fail on errors. In the fuzz tests we ignore fatal errors like NoSuchElementException because they are bugs that need to be fixed upstream. - Remove irrelevant TODOs - Remove unnecessary guards - Add link to GitHub issue for relevant TODOs - Remove workarounds for bugs that have been fixed upstream - Document when users need to enable -P:semanticdb:synthetics:on
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.
Thank you for the detailed review @xeno-by I've addressed your comments and made several more improvements.
project/ScalafixBuild.scala
Outdated
@@ -74,7 +74,9 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { | |||
lazy val semanticdbSettings = Seq( | |||
scalacOptions ++= List( | |||
"-Yrangepos", | |||
"-Xplugin-require:semanticdb" | |||
"-Xplugin-require:semanticdb", | |||
"-P:semanticdb:synthetics:on", |
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.
The NoInfer
rule requires the setting, I've updated the docs to tell users they need this setting for this rule.
project/ScalafixBuild.scala
Outdated
"-Xplugin-require:semanticdb" | ||
"-Xplugin-require:semanticdb", | ||
"-P:semanticdb:synthetics:on", | ||
"-P:semanticdb:text:on" |
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.
Opened #757 to track this. This PR is already a lot, prefer to delegate this to a another PR.
@@ -47,13 +46,13 @@ class PrettyTypeSuite extends BasePrettyTypeSuite { | |||
} | |||
|
|||
// This test is slow, no need to run it on every PR | |||
@Ignore | |||
//@Ignore |
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.
Removed the comment.
case _ => | ||
throw new IllegalArgumentException(info.toProtoString) | ||
} | ||
} |
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 renamed the method to .valueType
, it's a helper method to get the type of a ValueSignature
or fail.
private implicit class XtensionScopeHardlinks(scope: s.Scope) { | ||
def infos: List[s.SymbolInformation] = | ||
if (scope.hardlinks.isEmpty) scope.symlinks.iterator.map(info).toList | ||
else scope.hardlinks.toList |
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.
There is a method like this but it requires access to a symbol table to resolve the symlinks.
) | ||
case targ => | ||
targ | ||
} |
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.
Yup. RepeatedType
can appear in both Init
position and also for Defn.Def.decltpe
case class A(a: AnyRef*)
currently produces a val a: AnyRef*
method symbol
None | ||
case NonFatal(e) => | ||
e.setStackTrace(e.getStackTrace.filter { e => | ||
e.getClassName.startsWith("scalafix") | ||
}) |
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've replaced this with a fatalErrors: Boolean
option to control if exceptions are caught or not. It's possible to set ExplicitResultTypes.fatalWarnings = true
to control the option. There are still too many NoSuchElementException, for example
if (shorten.isName) { | ||
name | ||
} else { | ||
toTypeRef(info(symbol)) | ||
} | ||
case _: s.SingleType | _: s.ThisType | _: s.SuperType | | ||
_: s.ConstantType => | ||
Type.Select(toTermRef(prefix), name) |
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 don't think so, removing it seems to be OK. This was a direct refactoring of the old implementation. Hurray for breaking down SingletonType
🎉
Type.Name(this.info(symbol).name) | ||
) | ||
case s.SuperType(prefix @ _, symbol) => | ||
// TODO: prefix |
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.
Done.
case s.ConstantType(_) => | ||
toType(tpe.widen) | ||
case s.ExistentialType(underlying, Some(declarations)) => | ||
withHardlinks(declarations.hardlinks) { () => |
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.
It's been great so far 😊 Removed a lot of ???
/WTFs in the old implementation. I currently keep a mutable scope for hardlink lookups, I could make it immutable but that would require adding a (hardlinks: Map[String, SymbolInformation)
parameter everywhere for questionable benefit.
Our build upgraded coursier to 1.1.0-M4 to synchronzie the directories-jvm upgrade with metacp. This problem will go away once we publish scalafix-big with shaded dependencies and move sbt-scalafix to an external repo scalacenter#751 ``` java.lang.NoSuchMethodError: coursier.Cache$.fetch(Ljava/io/File;Lcoursier/CachePolicy;Lscala/collection/Seq;Lscala/Option;Ljava/util/concurrent/ExecutorService;Lscala/Option;)Lscala/Function1; ```
LGTM. |
Fixes #749
Fixes #757
scala.meta.{Symbol,Signature}
toscalafix.v0
packageScope
, thanks @xeno-by ❤️