New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search state exploded for classes with large number of parameters #719

Closed
tgodzik opened this Issue Feb 8, 2017 · 6 comments

Comments

Projects
None yet
3 participants
@tgodzik
Contributor

tgodzik commented Feb 8, 2017

  • Version: 0.5.5
  • Integration: IntelliJ
  • Configuration:
style = default

maxColumn = 120

docstrings = JavaDoc

align.openParenCallSite = false

assumeStandardLibraryStripMargin = true

Scalafmt fails with "SearchStateExploded around line 1" for:

class PropertyInfo18[E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, R: Manifest](name: String, flags: Long, impl: (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) => R) extends DefPropertyInfo[E, (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) => Boolean, (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) => R, R](name, flags)
class PropertyInfo19[E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, R: Manifest](name: String, flags: Long, impl: (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) => R) extends DefPropertyInfo[E, (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) => Boolean, (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) => R, R](name, flags)
@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Feb 8, 2017

Member

Thanks for reporting! If you run that in the tests and then open target/index.html you'll see a report like this

screen shot 2017-02-08 at 11 06 11

What's happening is that each argument in impl doubles the search space. This is because Term.Function is handled specially in router.scala. This should totally be fixable, but I can't promise when I'll look into it. I'm happy to help if you're interested in taking a stab at it yourself.

Member

olafurpg commented Feb 8, 2017

Thanks for reporting! If you run that in the tests and then open target/index.html you'll see a report like this

screen shot 2017-02-08 at 11 06 11

What's happening is that each argument in impl doubles the search space. This is because Term.Function is handled specially in router.scala. This should totally be fixable, but I can't promise when I'll look into it. I'm happy to help if you're interested in taking a stab at it yourself.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Mar 3, 2017

Member

You can use bin packing for defn site to avoid the search state error

// scalafmt: { binPack.defnSite = true }
class PropertyInfo18[
    uE, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16,
    P17, P18, R: Manifest](name: String, flags: Long,
    impl: (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15,
        P16, P17, P18) => R)
    extends DefPropertyInfo[E,
                            (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11,
                                P12, P13, P14, P15, P16, P17, P18) => Boolean,
                            (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11,
                                P12, P13, P14, P15, P16, P17, P18) => R,
                            R](name, flags)
Member

olafurpg commented Mar 3, 2017

You can use bin packing for defn site to avoid the search state error

// scalafmt: { binPack.defnSite = true }
class PropertyInfo18[
    uE, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16,
    P17, P18, R: Manifest](name: String, flags: Long,
    impl: (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15,
        P16, P17, P18) => R)
    extends DefPropertyInfo[E,
                            (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11,
                                P12, P13, P14, P15, P16, P17, P18) => Boolean,
                            (E, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11,
                                P12, P13, P14, P15, P16, P17, P18) => R,
                            R](name, flags)

@olafurpg olafurpg closed this Mar 3, 2017

@mjaghouri

This comment has been minimized.

Show comment
Hide comment
@mjaghouri

mjaghouri Oct 20, 2017

I ran into the same error, but if I try the suggested solution, I get:
StyleMap:44 [e]: Invalid fields: defnSite

Running with this config:

// project/plugins.sbt
libraryDependencies += "com.geirsson" %% "scalafmt-bootstrap" % "0.6.6"
// build.sbt
def latestScalafmt = "1.3.0"
commands += Command.args("scalafmt", "Run scalafmt cli.") {
  case (state, args) =>
    val Right(scalafmt) =
      org.scalafmt.bootstrap.ScalafmtBootstrap.fromVersion(latestScalafmt)
    scalafmt.main("--non-interactive" +: args.toArray)
    state
}

I ran into the same error, but if I try the suggested solution, I get:
StyleMap:44 [e]: Invalid fields: defnSite

Running with this config:

// project/plugins.sbt
libraryDependencies += "com.geirsson" %% "scalafmt-bootstrap" % "0.6.6"
// build.sbt
def latestScalafmt = "1.3.0"
commands += Command.args("scalafmt", "Run scalafmt cli.") {
  case (state, args) =>
    val Right(scalafmt) =
      org.scalafmt.bootstrap.ScalafmtBootstrap.fromVersion(latestScalafmt)
    scalafmt.main("--non-interactive" +: args.toArray)
    state
}
@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Oct 20, 2017

Member

@mjaghouri Please see http://scalameta.org/scalafmt/#Deeplynestedcode for up-to-date recommendations.

Member

olafurpg commented Oct 20, 2017

@mjaghouri Please see http://scalameta.org/scalafmt/#Deeplynestedcode for up-to-date recommendations.

@mjaghouri

This comment has been minimized.

Show comment
Hide comment
@mjaghouri

mjaghouri Oct 20, 2017

Thanks. It fixed most of the errors, but I still get the Search state exploded error in one file in which I have a method with 24 curried parameters (i.e., like def curriedMethod(p1: xxx)(p2: yyy)...(p24: zzz).
Any suggestion?

PS: I used align.openParenCallSite = false. I could of course turn off formatting for that one file, but I hope there is another alternative ;)

mjaghouri commented Oct 20, 2017

Thanks. It fixed most of the errors, but I still get the Search state exploded error in one file in which I have a method with 24 curried parameters (i.e., like def curriedMethod(p1: xxx)(p2: yyy)...(p24: zzz).
Any suggestion?

PS: I used align.openParenCallSite = false. I could of course turn off formatting for that one file, but I hope there is another alternative ;)

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Oct 20, 2017

Member

That curried case probably merits an issue, I have never seen a function with so many curried parameter lists. It may be simple to fix, I'm happy to give pointers if someone is interested in taking a look.

Member

olafurpg commented Oct 20, 2017

That curried case probably merits an issue, I have never seen a function with so many curried parameter lists. It may be simple to fix, I'm happy to give pointers if someone is interested in taking a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment