Skip to content

Commit

Permalink
Router: extract single stat from rewritten block
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 27, 2024
1 parent 2902568 commit 856b406
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1577,14 +1577,6 @@ class FormatOps(
getNlSplit(if (policy.isEmpty) 0 else 1),
)
def hasStateColumn = spaceIndents.exists(_.hasStateColumn)
@tailrec
def getBlockStat(t: Tree): Tree = t match {
case b: Term.Block => getSingleStatExceptEndMarker(b.stats) match {
case Some(s) if !isEnclosedInMatching(b) => getBlockStat(s)
case _ => t
}
case _ => t
}
val adjustedBody = getBlockStat(body)
val (spaceSplit, nlSplit) = adjustedBody match {
case t: Term.If if isKeep || ifWithoutElse(t) || hasStateColumn =>
Expand Down Expand Up @@ -1756,6 +1748,15 @@ class FormatOps(
): Split = asInfixApp(body)
.fold(withIndent(nlSplit, endFt))(InfixSplits.withNLIndent(nlSplit))

@tailrec
def getBlockStat(t: Tree): Tree = t match {
case b: Term.Block => getSingleStatExceptEndMarker(b.stats) match {
case Some(s) if !isEnclosedInMatching(b) => getBlockStat(s)
case _ => t
}
case _ => t
}

}

def withNLPolicy(endFt: FormatToken)(nlSplit: Split): Split = nlSplit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2611,10 +2611,10 @@ class Router(formatOps: FormatOps) {
if (style.newlines.getBeforeMultiline eq Newlines.classic) classicSplits
else CtrlBodySplits.getWithIndent(body, endFt)(null)(Split(Newline2x(ft), _))

private def getSplitsValEqualsClassic(body: Tree, endFt: FormatToken)(implicit
style: ScalafmtConfig,
ft: FormatToken,
): Seq[Split] = {
private def getSplitsValEqualsClassic(
rawBody: Tree,
endFt: FormatToken,
)(implicit style: ScalafmtConfig, ft: FormatToken): Seq[Split] = {
def wouldDangle = ft.meta.leftOwner.parent
.exists(style.danglingParentheses.atSite(_, false))

Expand Down Expand Up @@ -2648,6 +2648,7 @@ class Router(formatOps: FormatOps) {
PenalizeAllNewlines(expire, Constants.ShouldBeSingleLine),
)
}
val body = CtrlBodySplits.getBlockStat(rawBody)
val spaceSplit = body match {
case _ if ft.hasBreak && ft.meta.leftOwner.is[Defn] => Split.ignored
case _: Term.If => twoBranches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2054,18 +2054,10 @@ hostLocalDirManager = {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
-hostLocalDirManager =
- if (
- (conf.get(config.SHUFFLE_HOST_LOCAL_DISK_READING_ENABLED) &&
- !conf.get(config.SHUFFLE_USE_OLD_FETCH_PROTOCOL)) ||
- Utils.isPushBasedShuffleEnabled(conf, isDriver)
- )
- None
+hostLocalDirManager = if (
+ (conf.get(config.SHUFFLE_HOST_LOCAL_DISK_READING_ENABLED) &&
+ !conf.get(config.SHUFFLE_USE_OLD_FETCH_PROTOCOL)) ||
+ Utils.isPushBasedShuffleEnabled(conf, isDriver)
+)
+ None
hostLocalDirManager =
if (
(conf.get(config.SHUFFLE_HOST_LOCAL_DISK_READING_ENABLED) &&
!conf.get(config.SHUFFLE_USE_OLD_FETCH_PROTOCOL)) ||
Utils.isPushBasedShuffleEnabled(conf, isDriver)
)
None

0 comments on commit 856b406

Please sign in to comment.