Skip to content

Commit

Permalink
Add Vtype-reduction option that enable display of type signatures bef…
Browse files Browse the repository at this point in the history
…ore dealias & normalisations

revise TypeView that won't lose information when extracting qualifier

revise dealias such that it won't lose information

simplify extractArg, removing the unsound part

simplify ImplicitHistory

disable gradle caching

./dev/test.sh now always call make-all.sh

remove an invalid test

simplify & cleanup test cases

Scala 2.13.6 support is dropped, all cross-compiling files are merged into 2.13.7+
  • Loading branch information
tribbloid committed Sep 8, 2023
1 parent ea42916 commit 1854370
Show file tree
Hide file tree
Showing 154 changed files with 786 additions and 1,477 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
max-parallel: 2
fail-fast: false
matrix:
scalaVersion: ["2.13.6", "2.13.7", "2.13.8", "2.13.9", "2.13.10", "2.13.11"]
scalaVersion: ["2.13.7", "2.13.8", "2.13.9", "2.13.10", "2.13.11"]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
max-parallel: 2
fail-fast: false
matrix:
scalaVersion: ["2.13.6", "2.13.7", "2.13.8", "2.13.9", "2.13.10", "2.13.11"]
scalaVersion: ["2.13.7", "2.13.8", "2.13.9", "2.13.10", "2.13.11"]

continue-on-error: ${{ contains(needs.vars.outputs.experimentalScalaVersions, matrix.scalaVersion) }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ logs
# gradle
**/.gradle
**/build
**/bin

# sbt
.cache/
Expand Down
13 changes: 8 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version = "2.7.5"
maxColumn=120
version = "3.7.14"
runner.dialect = scala213


maxColumn = 120

# Only format files tracked by git.
project.git=true
project.git = true

align {
preset = some
Expand All @@ -14,12 +17,12 @@ docstrings {
}

newlines {
# topLevelStatements = [before]
# topLevelStatements = [before]
sometimesBeforeColonInMethodReturnType = false
penalizeSingleSelectMultiArgList = false
beforeCurlyLambdaParams = multilineWithCaseOnly
# // afterCurlyLambdaParams = squash
implicitParamListModifierForce = [before,after]
implicitParamListModifierForce = [before, after]
}

rewrite {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ allprojects {
}

val vn = VersionNumber.parse(vs.scalaV)
val supportedPatchVs = listOf(6, 7)
val supportedPatchVs = listOf(7, 8, 9, 10, 11)

for (from in supportedPatchVs) {
if (vn.micro >= from) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
package splain

import scala.collection.concurrent.TrieMap
import scala.collection.mutable
import scala.tools.nsc.typechecker

trait ImplicitsExtension extends typechecker.Implicits {
trait ImplicitsExtension extends TyperCompatViews with typechecker.Implicits {
self: SplainAnalyzer =>

import global._

case class DivergingImplicitErrorView(self: DivergentImplicitTypeError) {
object ImplicitsHistory {

lazy val errMsg: String = {

val formattedPT = showFormatted(formatType(self.pt0, top = false))

s"diverging implicit expansion for type $formattedPT\nstarting with ${self.sym.fullLocationString}"
lazy val currentGlobal: Global = {
val result = Global()
result
}
}

object ImplicitHistory {

@volatile protected var _currentGlobalHistory: GlobalHistory = _

case class GlobalHistory() {
case class Global() {

val byPosition = mutable.HashMap.empty[PositionIndex, LocalHistory]
val localByPosition: TrieMap[PositionIndex, Local] = TrieMap.empty
}

case class LocalHistory() {
case class Local() {

object DivergingImplicitErrors {

val errors = mutable.ArrayBuffer.empty[DivergentImplicitTypeError]
val errors: mutable.ArrayBuffer[DivergentImplicitTypeError] = mutable.ArrayBuffer.empty

def push(v: DivergentImplicitTypeError): Unit = {
errors.addOne(v)
Expand All @@ -54,22 +48,10 @@ trait ImplicitsExtension extends typechecker.Implicits {
result
}

val logs = mutable.ArrayBuffer.empty[String]
val logs: mutable.ArrayBuffer[String] = mutable.ArrayBuffer.empty[String]
// unused messages & comments will be displayed at the end of the implicit error
}
}

case class PositionIndex(
pos: Position
) {}

def currentGlobal: GlobalHistory = Option(_currentGlobalHistory).getOrElse {
ImplicitHistory.synchronized {
val result = GlobalHistory()
_currentGlobalHistory = result
result
}
}
}

override def inferImplicit(
Expand All @@ -82,17 +64,17 @@ trait ImplicitsExtension extends typechecker.Implicits {
pos: Position
): SearchResult = {

import ImplicitHistory._
import ImplicitsHistory._

def getResult = super.inferImplicit(tree, pt, reportAmbiguous, isView, context, saveAmbiguousDivergent, pos)

if (settings.Vimplicits.value && pluginSettings.implicitDiverging) {

val posII = ImplicitHistory.PositionIndex(
val posII = PositionIndex(
tree.pos
)

val local = currentGlobal.byPosition.getOrElseUpdate(posII, LocalHistory())
val local = currentGlobal.localByPosition.getOrElseUpdate(posII, Local())
val previousSimilarErrors = local.DivergingImplicitErrors.errors.filter { ee =>
ee.underlyingTree equalsStructure tree
}
Expand Down Expand Up @@ -133,7 +115,8 @@ trait ImplicitsExtension extends typechecker.Implicits {
result
} else {

getResult
val result: SearchResult = getResult
result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait SplainFormattersExtension extends SplainFormatters {
None
case RefinedType(types, scope) =>
if (scope.isEmpty) {
val subtypes = types.map(_.dealias).flatMap {
val subtypes = types.map(v => dealias(v)).flatMap {
case Refined(types, _) =>
types
case tpe =>
Expand All @@ -64,21 +64,6 @@ trait SplainFormattersExtension extends SplainFormatters {
Simple(sym.toString)
}

override def apply[A](
tpe: Type,
simple: String,
args: List[A],
formattedArgs: => List[Formatted],
top: Boolean
)(rec: (A, Boolean) => Formatted): Option[Formatted] = {
tpe match {
case Refined(parents, decls) =>
Some(RefinedForm(sanitizeParents(parents).map(formatType(_, top)), decls.toList.map(formatDecl)))
case _ =>
None
}
}

val none: Formatted = Simple("<none>")

def separate[A](left: List[A], right: List[A]): (List[A], List[A], List[A]) = {
Expand All @@ -90,7 +75,7 @@ trait SplainFormattersExtension extends SplainFormatters {
(common.toList, uniqueLeft.toList, uniqueRight.toList)
}

def matchTypes(left: List[Type], right: List[Type]): List[Formatted] = {
def compareTypes(left: List[Type], right: List[Type]): List[Formatted] = {
val (common, uniqueLeft, uniqueRight) =
separate(left.map(formatType(_, top = true)), right.map(formatType(_, top = true)))
val diffs = uniqueLeft
Expand All @@ -108,7 +93,7 @@ trait SplainFormattersExtension extends SplainFormatters {
(sym, rhs)
}

def matchDecls(left: List[Symbol], right: List[Symbol]): List[Formatted] = {
def compareDecls(left: List[Symbol], right: List[Symbol]): List[Formatted] = {
val (common, uniqueLeft, uniqueRight) = separate(filterDecls(left), filterDecls(right))
val diffs = uniqueLeft
.map(Some(_))
Expand All @@ -127,12 +112,31 @@ trait SplainFormattersExtension extends SplainFormatters {
} ++ diffs
}

def diff(left: Type, right: Type, top: Boolean): Option[Formatted] =
override def apply[A](
tpe: Type,
simple: String,
args: List[A],
formattedArgs: => List[Formatted],
top: Boolean
)(rec: (A, Boolean) => Formatted): Option[Formatted] = {
tpe match {
case Refined(parents, decls) =>
def elements = sanitizeParents(parents).map(formatType(_, top))

val result = Some(RefinedForm(elements, decls.toList.map(formatDecl)))
result
case _ =>
None
}
}

override def diff(left: Type, right: Type, top: Boolean): Option[Formatted] =
(left, right) match {
case (Refined(leftParents, leftDecls), Refined(rightParents, rightDecls)) =>
val parents = matchTypes(sanitizeParents(leftParents), sanitizeParents(rightParents)).sorted
val decls = matchDecls(leftDecls.toList, rightDecls.toList).sorted
Some(RefinedForm(parents, decls))
val parents = compareTypes(sanitizeParents(leftParents), sanitizeParents(rightParents)).sorted
val decls = compareDecls(leftDecls.toList, rightDecls.toList).sorted
val result = Some(RefinedForm(parents, decls))
result
case _ =>
None
}
Expand Down
Loading

0 comments on commit 1854370

Please sign in to comment.