Skip to content

Commit

Permalink
BestFirstSearch: allow block close go past range
Browse files Browse the repository at this point in the history
In reality, that's what has been happening so far since we used an exact
comparison on `stop`. Marginally improves scala3 performance.
  • Loading branch information
kitbellew committed Nov 13, 2024
1 parent 7e46a26 commit 1ea14fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ private class BestFirstSearch private (range: Set[Range])(implicit

var stats = new StateStats(tokens, initStyle.runner)

private def getBlockCloseToRecurse(ft: FT, stop: T)(implicit
private def getBlockCloseToRecurse(ft: FT)(implicit
style: ScalafmtConfig,
): Option[T] = getEndOfBlock(ft, parensToo = true).collect {
case close if close.left != stop && {
// Block must span at least 3 lines to be worth recursing.
tokens.width(ft, close) > style.maxColumn * 3
} => close.left
// Block must span at least 3 lines to be worth recursing.
case close if tokens.width(ft, close) > style.maxColumn * 3 => close.left
}

private val memo = mutable.Map.empty[Long, Option[State]]
Expand Down Expand Up @@ -111,7 +109,7 @@ private class BestFirstSearch private (range: Set[Range])(implicit
noOptZoneOrBlock.isEmpty || !optimizer.recurseOnBlocks
val blockCloseState =
if (noBlockClose) None
else getBlockCloseToRecurse(splitToken, stop)
else getBlockCloseToRecurse(splitToken)
.flatMap(shortestPathMemo(curr, _, depth + 1, isOpt))
if (blockCloseState.nonEmpty) blockCloseState
.foreach(_.foreach(Q.enqueue))
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(40783820)
override protected def totalStatesVisited: Option[Int] = Some(40783579)

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

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

Expand Down

0 comments on commit 1ea14fc

Please sign in to comment.