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

Upgrade to Scalameta v4.0.0-M4 #756

Merged
merged 20 commits into from
Jun 23, 2018
Merged

Upgrade to Scalameta v4.0.0-M4 #756

merged 20 commits into from
Jun 23, 2018

Conversation

olafurpg
Copy link
Contributor

@olafurpg olafurpg commented Jun 22, 2018

Fixes #749
Fixes #757

  • move scala.meta.{Symbol,Signature} to scalafix.v0 package
  • improve code quality in the type printer:
    • much cleaner pattern matching thanks to new sealed oneof encoding
    • existential types and universal types no longer require hacks because of Scope, thanks @xeno-by ❤️
  • sbt-scalafix is removed in this PR because it will be moved into a separate repo and I prefer to handle the upgrade after the split.

"-Xplugin-require:semanticdb"
"-Xplugin-require:semanticdb",
"-P:semanticdb:synthetics:on",
"-P:semanticdb:text:on"
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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",
Copy link
Contributor

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?

Copy link
Contributor Author

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)
}
}
Copy link
Contributor

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?

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 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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"))
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

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 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
Copy link
Contributor

Choose a reason for hiding this comment

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

FIXME with a ticket?

Copy link
Contributor Author

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) { () =>
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment accidental?

Copy link
Contributor Author

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
Copy link
Contributor Author

@olafurpg olafurpg left a 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.

@@ -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",
Copy link
Contributor Author

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.

"-Xplugin-require:semanticdb"
"-Xplugin-require:semanticdb",
"-P:semanticdb:synthetics:on",
"-P:semanticdb:text:on"
Copy link
Contributor Author

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
Copy link
Contributor Author

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)
}
}
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 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
Copy link
Contributor Author

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
}
Copy link
Contributor Author

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")
})
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'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)
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 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
Copy link
Contributor Author

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) { () =>
Copy link
Contributor Author

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;
```
@olafurpg
Copy link
Contributor Author

I am working on #757 right now, the recent refactorings of the cli made it easier than I expected. Let's wait merging this until #757 is fixed.

@xeno-by
Copy link
Contributor

xeno-by commented Jun 22, 2018

LGTM.

@olafurpg olafurpg merged commit cbadb2b into scalacenter:master Jun 23, 2018
@olafurpg olafurpg deleted the M4 branch June 23, 2018 09:17
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.

Support -P:semanticdb:text:off Upgrade to scalameta 4.0.0-M4
2 participants