Skip to content

Commit

Permalink
Router: remove { nlPenalty computation
Browse files Browse the repository at this point in the history
Simplify the code a little bit, this penalty was completely superseded
by the lambda penalty execution path.
  • Loading branch information
kitbellew committed Nov 27, 2024
1 parent 8f5626e commit 7b35b4f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,12 @@ class Router(formatOps: FormatOps) {
}
case _ => NoPolicy
}
val nlPenalty = leftOwner match {
case _ if !style.newlines.fold => 0
case t: Term.ArgClause if (t.values match {
case x :: Nil if !x.is[Term.FunctionTerm] => true
case _ => false
}) => 1
case t @ Tree.Block(x :: Nil)
if !x.is[Term.FunctionTerm] && t.parent.is[Term.ArgClause] => 1
case _ => 0
}
val (nlCost, nlArrowPenalty) =
if (!nl.isNL) (0, 0)
else if (slbMod eq noSplitMod) (1 + nlPenalty, nlPenalty)
else getLambdaPenaltiesOnLeftBraceOnLeft(ft)
.fold((1, nlPenalty)) { case (sharedPenalty, herePenalty) =>
(sharedPenalty + herePenalty, sharedPenalty)
}
else {
if (slbMod eq noSplitMod) None
else getLambdaPenaltiesOnLeftBraceOnLeft(ft)
}.fold((1, 0)) { case (shared, here) => (shared + here, shared) }
val newlineBeforeClosingCurly = decideNewlinesOnlyBeforeClose(close)
val nlPolicy = lambdaNLPolicy ==> newlineBeforeClosingCurly
val nlSplit = Split(nl, nlCost, policy = nlPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class CommunityIntellijScalaSuite(name: String)
class CommunityIntellijScala_2024_2_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.2") {

override protected def totalStatesVisited: Option[Int] = Some(59338266)
override protected def totalStatesVisited: Option[Int] = Some(59317488)

override protected def builds = Seq(getBuild(
"2024.2.28",
Expand Down Expand Up @@ -51,7 +51,7 @@ class CommunityIntellijScala_2024_2_Suite
class CommunityIntellijScala_2024_3_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.3") {

override protected def totalStatesVisited: Option[Int] = Some(59554927)
override protected def totalStatesVisited: Option[Int] = Some(59533781)

override protected def builds = Seq(getBuild(
"2024.3.4",
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(42554853)
override protected def totalStatesVisited: Option[Int] = Some(42542831)

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(53041386)
override protected def totalStatesVisited: Option[Int] = Some(53024660)

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(39228800)
override protected def totalStatesVisited: Option[Int] = Some(39220760)

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(42414545)
override protected def totalStatesVisited: Option[Int] = Some(42405381)

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 @@ -9,7 +9,7 @@ abstract class CommunitySparkSuite(name: String)

class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

override protected def totalStatesVisited: Option[Int] = Some(86438662)
override protected def totalStatesVisited: Option[Int] = Some(86363674)

override protected def builds =
Seq(getBuild("v3.4.1", dialects.Scala213, 2585))
Expand All @@ -18,7 +18,7 @@ class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

class CommunitySpark3_5Suite extends CommunitySparkSuite("spark-3.5") {

override protected def totalStatesVisited: Option[Int] = Some(91444980)
override protected def totalStatesVisited: Option[Int] = Some(91365411)

override protected def builds =
Seq(getBuild("v3.5.3", dialects.Scala213, 2756))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9440,7 +9440,7 @@ object a {
}
}
}
>>> { stateVisits = 2250, stateVisits2 = 2250 }
>>> { stateVisits = 2229, stateVisits2 = 2229 }
object a {
private object MemoMap {
def make(implicit trace: Trace): UIO[MemoMap] = Ref.Synchronized
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, 1183838, "total explored")
assertEquals(explored, 1183640, "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 7b35b4f

Please sign in to comment.