Skip to content

Commit

Permalink
BestFirstSearch: arg clause an opt-zone for keep
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 27, 2024
1 parent 907c583 commit 830cfe6
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ object BestFirstSearch {
private def hasSlbAfter(state: State)(ft: FormatToken): Boolean = state.policy
.exists(_.appliesUntil(ft)(_.isInstanceOf[PolicyOps.SingleLineBlock]))

private def getNoOptZones(tokens: FormatTokens) = {
private def getNoOptZones(tokens: FormatTokens)(implicit styleMap: StyleMap) = {
val result = Set.newBuilder[Token]
var expire: Token = null
tokens.foreach {
case FormatToken(x, _, _) if expire ne null =>
if (x eq expire) expire = null else result += x
case FormatToken(t: Token.LeftParen, _, m) if (m.leftOwner match {
// TODO(olafur) https://github.com/scalameta/scalameta/issues/345
case lo: Term.ArgClause => !lo.parent.is[Term.ApplyInfix]
case lo: Term.ArgClause => !lo.parent.is[Term.ApplyInfix] &&
!styleMap.at(t).newlines.keep
case _: Term.Apply => true // legacy: when enclosed in parens
case _ => false
}) => expire = tokens.matching(t)
Expand Down
273 changes: 262 additions & 11 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -2239,9 +2239,9 @@ val a = b match {
) ::
JField(
"env",
Extraction.decompose(
i.env
)(DefaultFormats)
Extraction.decompose(i.env)(
DefaultFormats
)
) ::
JField(
"sparkConf",
Expand Down Expand Up @@ -9140,15 +9140,118 @@ trait Infer {
}
}
}
<<< SKIP #4133 very long one-liner with chain of infixes, full method
<<< #4133 very long one-liner with chain of infixes, full method
class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) extends Logging {
def register[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag, A5: TypeTag, A6: TypeTag, A7: TypeTag, A8: TypeTag, A9: TypeTag, A10: TypeTag, A11: TypeTag, A12: TypeTag, A13: TypeTag, A14: TypeTag, A15: TypeTag, A16: TypeTag, A17: TypeTag, A18: TypeTag, A19: TypeTag, A20: TypeTag, A21: TypeTag, A22: TypeTag](name: String, func: Function22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, RT]): UserDefinedFunction = {
val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]()).toOption :: Try(ExpressionEncoder[A2]()).toOption :: Try(ExpressionEncoder[A3]()).toOption :: Try(ExpressionEncoder[A4]()).toOption :: Try(ExpressionEncoder[A5]()).toOption :: Try(ExpressionEncoder[A6]()).toOption :: Try(ExpressionEncoder[A7]()).toOption :: Try(ExpressionEncoder[A8]()).toOption :: Try(ExpressionEncoder[A9]()).toOption :: Try(ExpressionEncoder[A10]()).toOption :: Try(ExpressionEncoder[A11]()).toOption :: Try(ExpressionEncoder[A12]()).toOption :: Try(ExpressionEncoder[A13]()).toOption :: Try(ExpressionEncoder[A14]()).toOption :: Try(ExpressionEncoder[A15]()).toOption :: Try(ExpressionEncoder[A16]()).toOption :: Try(ExpressionEncoder[A17]()).toOption :: Try(ExpressionEncoder[A18]()).toOption :: Try(ExpressionEncoder[A19]()).toOption :: Try(ExpressionEncoder[A20]()).toOption :: Try(ExpressionEncoder[A21]()).toOption :: Try(ExpressionEncoder[A22]()).toOption :: Nil
}
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[276] )∙.: RightParen [952..953) [] Dot [953..954)', line 3: exceeded `runner.maxStateVisits`=150000 [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
<<< SKIP #4133 very long one-liner with chain of infixes
class UDFRegistration private[sql] (
functionRegistry: FunctionRegistry
) extends Logging {
def register[
RT: TypeTag,
A1: TypeTag,
A2: TypeTag,
A3: TypeTag,
A4: TypeTag,
A5: TypeTag,
A6: TypeTag,
A7: TypeTag,
A8: TypeTag,
A9: TypeTag,
A10: TypeTag,
A11: TypeTag,
A12: TypeTag,
A13: TypeTag,
A14: TypeTag,
A15: TypeTag,
A16: TypeTag,
A17: TypeTag,
A18: TypeTag,
A19: TypeTag,
A20: TypeTag,
A21: TypeTag,
A22: TypeTag
](
name: String,
func: Function22[
A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
A10,
A11,
A12,
A13,
A14,
A15,
A16,
A17,
A18,
A19,
A20,
A21,
A22,
RT
]
): UserDefinedFunction = {
val inputEncoders: Seq[
Option[ExpressionEncoder[_]]
] = Try(
ExpressionEncoder[A1]()
).toOption :: Try(
ExpressionEncoder[A2]()
).toOption :: Try(
ExpressionEncoder[A3]()
).toOption :: Try(
ExpressionEncoder[A4]()
).toOption :: Try(
ExpressionEncoder[A5]()
).toOption :: Try(
ExpressionEncoder[A6]()
).toOption :: Try(
ExpressionEncoder[A7]()
).toOption :: Try(
ExpressionEncoder[A8]()
).toOption :: Try(
ExpressionEncoder[A9]()
).toOption :: Try(
ExpressionEncoder[A10]()
).toOption :: Try(
ExpressionEncoder[A11]()
).toOption :: Try(
ExpressionEncoder[A12]()
).toOption :: Try(
ExpressionEncoder[A13]()
).toOption :: Try(
ExpressionEncoder[A14]()
).toOption :: Try(
ExpressionEncoder[A15]()
).toOption :: Try(
ExpressionEncoder[A16]()
).toOption :: Try(
ExpressionEncoder[A17]()
).toOption :: Try(
ExpressionEncoder[A18]()
).toOption :: Try(
ExpressionEncoder[A19]()
).toOption :: Try(
ExpressionEncoder[A20]()
).toOption :: Try(
ExpressionEncoder[A21]()
).toOption :: Try(
ExpressionEncoder[A22]()
).toOption :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes
runner.maxStateVisits = 1000
===
class UDFRegistration {
Expand All @@ -9157,8 +9260,56 @@ class UDFRegistration {
}
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[43] Try∙(: Ident(Try) [277..280) [] LeftParen [280..281)', line 3: exceeded `runner.maxStateVisits`=1000 [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
<<< SKIP #4133 very long one-liner with chain of infixes, with selects
class UDFRegistration {
def foo = {
val inputEncoders
: Seq_Option_ExpressionEncoder_____ =
Try(ExpressionEncoder_A1_) :: Try(
ExpressionEncoder_A2_
) :: Try(
ExpressionEncoder_A3_
) :: Try(
ExpressionEncoder_A4_
) :: Try(
ExpressionEncoder_A5_
) :: Try(
ExpressionEncoder_A6_
) :: Try(
ExpressionEncoder_A7_
) :: Try(
ExpressionEncoder_A8_
) :: Try(
ExpressionEncoder_A9_
) :: Try(
ExpressionEncoder_A10_
) :: Try(
ExpressionEncoder_A11_
) :: Try(
ExpressionEncoder_A12_
) :: Try(
ExpressionEncoder_A13_
) :: Try(
ExpressionEncoder_A14_
) :: Try(
ExpressionEncoder_A15_
) :: Try(
ExpressionEncoder_A16_
) :: Try(
ExpressionEncoder_A17_
) :: Try(
ExpressionEncoder_A18_
) :: Try(
ExpressionEncoder_A19_
) :: Try(
ExpressionEncoder_A20_
) :: Try(
ExpressionEncoder_A21_
) :: Try(
ExpressionEncoder_A22_
) :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes, with selects
runner.maxStateVisits = 5000
===
class UDFRegistration {
Expand All @@ -9167,8 +9318,58 @@ class UDFRegistration {
}
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[77] (∙ExpressionEncoder_A10_: LeftParen [451..452) [] Ident(ExpressionEncoder_A10_) [452..474)', line 3: exceeded `runner.maxStateVisits`=5000 [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
<<< SKIP #4133 very long one-liner with chain of infixes, with select and types
class UDFRegistration {
def foo = {
val inputEncoders
: Seq_Option_ExpressionEncoder_____ =
Try(
ExpressionEncoder_A1_
).toOption :: Try(
ExpressionEncoder_A2_
).toOption :: Try(
ExpressionEncoder_A3_
).toOption :: Try(
ExpressionEncoder_A4_
).toOption :: Try(
ExpressionEncoder_A5_
).toOption :: Try(
ExpressionEncoder_A6_
).toOption :: Try(
ExpressionEncoder_A7_
).toOption :: Try(
ExpressionEncoder_A8_
).toOption :: Try(
ExpressionEncoder_A9_
).toOption :: Try(
ExpressionEncoder_A10_
).toOption :: Try(
ExpressionEncoder_A11_
).toOption :: Try(
ExpressionEncoder_A12_
).toOption :: Try(
ExpressionEncoder_A13_
).toOption :: Try(
ExpressionEncoder_A14_
).toOption :: Try(
ExpressionEncoder_A15_
).toOption :: Try(
ExpressionEncoder_A16_
).toOption :: Try(
ExpressionEncoder_A17_
).toOption :: Try(
ExpressionEncoder_A18_
).toOption :: Try(
ExpressionEncoder_A19_
).toOption :: Try(
ExpressionEncoder_A20_
).toOption :: Try(
ExpressionEncoder_A21_
).toOption :: Try(
ExpressionEncoder_A22_
).toOption :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes, with select and types
runner.maxStateVisits = 100000
===
class UDFRegistration {
Expand All @@ -9177,4 +9378,54 @@ class UDFRegistration {
}
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[121] ::∙Try: Ident(::) [485..487) [ ] Ident(Try) [488..491)', line 3: exceeded `runner.maxStateVisits`=100000 [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
class UDFRegistration {
def foo = {
val inputEncoders: Seq[
Option[ExpressionEncoder[_]]
] = Try(
ExpressionEncoder[A1]
).toOption :: Try(
ExpressionEncoder[A2]
).toOption :: Try(
ExpressionEncoder[A3]
).toOption :: Try(
ExpressionEncoder[A4]
).toOption :: Try(
ExpressionEncoder[A5]
).toOption :: Try(
ExpressionEncoder[A6]
).toOption :: Try(
ExpressionEncoder[A7]
).toOption :: Try(
ExpressionEncoder[A8]
).toOption :: Try(
ExpressionEncoder[A9]
).toOption :: Try(
ExpressionEncoder[A10]
).toOption :: Try(
ExpressionEncoder[A11]
).toOption :: Try(
ExpressionEncoder[A12]
).toOption :: Try(
ExpressionEncoder[A13]
).toOption :: Try(
ExpressionEncoder[A14]
).toOption :: Try(
ExpressionEncoder[A15]
).toOption :: Try(
ExpressionEncoder[A16]
).toOption :: Try(
ExpressionEncoder[A17]
).toOption :: Try(
ExpressionEncoder[A18]
).toOption :: Try(
ExpressionEncoder[A19]
).toOption :: Try(
ExpressionEncoder[A20]
).toOption :: Try(
ExpressionEncoder[A21]
).toOption :: Try(
ExpressionEncoder[A22]
).toOption :: Nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ object a:
>>>
object a:
if reducePattern(caseBindingMap, scrutineeSym.termRef, cdef.pat)(using
gadtCtx)
gadtCtx
)
then {
// c1
}
Expand Down Expand Up @@ -6267,14 +6268,17 @@ object a:
>>>
object a:
rootsForRelease_foreach(root =>
Files.walkingIterator().useScalaFilter(
Files__Is__Directory
).foreach { p =>
val_moduleNamePathElementCount_е_0
if (p_getNameCount_g_root_getNameCount_p_moduleNamePathElementCount) {
val_packageDotted_e_p_subpath_moduleNamePathElementCountFooRoot__p__toString_replace
index_getOrElseUpdate(packageDotted__new_collectionMutableListBuffer)
}
Files.walkingIterator().useScalaFilter(Files__Is__Directory).foreach {
p =>
val_moduleNamePathElementCount_е_0
if (
p_getNameCount_g_root_getNameCount_p_moduleNamePathElementCount
) {
val_packageDotted_e_p_subpath_moduleNamePathElementCountFooRoot__p__toString_replace
index_getOrElseUpdate(
packageDotted__new_collectionMutableListBuffer
)
}
}
)
<<< braces to parens in one-line apply: overflow with braces, fit with parens
Expand Down Expand Up @@ -7028,8 +7032,8 @@ object a {
x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) =>
g.asInstanceOf[Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _] => Any].apply((x1, x2, x3, x4, x5, x6, x7, x8, x9,
x10, x11, x12, x13, x14, x15, x16, x17, x18))).asInstanceOf[
F]
x10, x11, x12, x13, x14, x15, x16, x17,
x18))).asInstanceOf[F]
)
}
<<< #4133 binpack overflow assignment with selects, attributes, !dangling
Expand Down

0 comments on commit 830cfe6

Please sign in to comment.