Skip to content

Commit

Permalink
FormatOps: { of refined type is optimal for defn
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 31, 2024
1 parent a31b8ce commit d4efa00
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ class FormatOps(
case Some(p) => defnSiteOptimalToken(p)
case _ => None
}
case Tree.WithDeclTpe(tpe: Type.Refine) if tpe.body.nonEmpty =>
getHeadOpt(tpe.body)
case Tree.WithDeclTpeOpt(Some(tpe: Type.Refine)) if tpe.body.nonEmpty =>
getHeadOpt(tpe.body)
// macro body comes after KwMacro, not directly after Equals
case t: Defn.Macro => tokenBeforeOpt(t.body).map(prevNonCommentBefore)
case t: Tree.WithBody => tokenBeforeOpt(t.body)
case t: Stat.WithTemplate => tokenBeforeOpt(t.templ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunityScala2Suite(name: String)

class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

override protected def totalStatesVisited: Option[Int] = Some(42514702)
override protected def totalStatesVisited: Option[Int] = Some(42512477)

override protected def builds =
Seq(getBuild("v2.12.20", dialects.Scala212, 1277))
Expand All @@ -18,7 +18,7 @@ class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

class CommunityScala2_13Suite extends CommunityScala2Suite("scala-2.13") {

override protected def totalStatesVisited: Option[Int] = Some(52982463)
override protected def totalStatesVisited: Option[Int] = Some(52980238)

override protected def builds =
Seq(getBuild("v2.13.14", dialects.Scala213, 1287))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ abstract class CommunityScala3Suite(name: String)

class CommunityScala3_2Suite extends CommunityScala3Suite("scala-3.2") {

override protected def totalStatesVisited: Option[Int] = Some(39189546)
override protected def totalStatesVisited: Option[Int] = Some(39189350)

override protected def builds = Seq(getBuild("3.2.2", dialects.Scala32, 791))

}

class CommunityScala3_3Suite extends CommunityScala3Suite("scala-3.3") {

override protected def totalStatesVisited: Option[Int] = Some(42296092)
override protected def totalStatesVisited: Option[Int] = Some(42295896)

override protected def builds = Seq(getBuild("3.3.3", dialects.Scala33, 861))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11623,9 +11623,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
}
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11645,9 +11643,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11667,9 +11663,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand Down
36 changes: 18 additions & 18 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -10848,12 +10848,12 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] }
implicit def toAllConsKOps[F[_], A](target: F[A])(
implicit_tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] }
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
}
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
}
}
<<< #4704 Defn.Def with refined decltpe
maxColumn = 90
Expand All @@ -10868,12 +10868,12 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] } = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(
implicit_tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] } = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = foo
}
<<< #4704 Defn.DefMacro with refined decltpe
maxColumn = 90
Expand All @@ -10888,10 +10888,10 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] } = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(
implicit_tc: ConsK[F]
): AllOps[F, A] { type TypeClassType = ConsK[F] } = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = macro foo
}
Original file line number Diff line number Diff line change
Expand Up @@ -11384,9 +11384,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
}
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11406,9 +11404,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11428,9 +11424,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11827,9 +11827,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
}
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11849,9 +11847,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand All @@ -11871,9 +11867,7 @@ object ops {
}
>>>
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit
tc: ConsK[F]
): AllOps[F, A] {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = macro foo
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit_tc: ConsK[F]): AllOps[F, A] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1246977, "total explored")
assertEquals(explored, 1244442, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit d4efa00

Please sign in to comment.