Skip to content
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

Discover - break overridesRoutes into fixed size chunks #509

Merged
merged 4 commits into from
Dec 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions main/core/src/define/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ object Discover {
}
if overridesRoutes.nonEmpty
} yield {
// by grouping the `overridesRoutes` into a sequence of lambda functions
// containing chunks of 512 elements we kind of work around the problem
// of generating a *huge* macro method body that finally exceeds the
// JVM's maximum allowed method size
val splitSize = 512
val groupedLambdas =
overridesRoutes
.sliding(splitSize, splitSize).toSeq
.map(grp => q"(() => $grp)()")
.reduce((a, b) => q"$a ++ $b")
val lhs = q"classOf[${discoveredModuleType.typeSymbol.asClass}]"
val rhs = q"scala.Seq[(Int, mill.util.Router.EntryPoint[_])](..$overridesRoutes)"
q"$lhs -> $rhs"
q"$lhs -> $groupedLambdas"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to use sliding here; just one big lambda function will do, since that will already group things by the curCls. You may have a lot of curClss, but each one probably won't have enough methods to cause an issue individually

}

c.Expr[Discover[T]](q"mill.define.Discover(scala.collection.immutable.Map(..$mapping))")
Expand Down