LF: reduce recursion depth in Archive decoder. (#8827)

We inline the unnecessary decodeExprBody call inside decodeExpr.  This
reduces the recursion depth of decoding expression inside archive,
increasing hence the depth of expression the scala part of the stack
can handle without blowing off the stack.

Before the change the test
//daml-lf/tests:test-scenario-stable-many-fields crashed 25 out of 100
runs.  After the changes the test crashed not once out of 100 runs.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Remy 2021-02-12 10:54:07 +01:00 committed by GitHub
parent c8b82f8e7a
commit f4c7ea3df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -797,14 +797,8 @@ private[archive] class DecodeV1(minor: LV.Minor) extends Decode.OfPackage[PLF.Pa
ImmArray(lfTyConApp.getArgsList.asScala.map(decodeType)),
)
private[lf] def decodeExpr(lfExpr: PLF.Expr, definition: String): Expr =
decodeLocation(lfExpr, definition) match {
case None => decodeExprBody(lfExpr, definition)
case Some(loc) => ELocation(loc, decodeExprBody(lfExpr, definition))
}
private[this] def decodeExprBody(lfExpr: PLF.Expr, definition: String): Expr =
lfExpr.getSumCase match {
private[lf] def decodeExpr(lfExpr: PLF.Expr, definition: String): Expr = {
val expr = lfExpr.getSumCase match {
case PLF.Expr.SumCase.VAR_STR =>
assertUntil(LV.Features.internedStrings, "Expr.var_str")
EVar(toName(lfExpr.getVarStr))
@ -1058,6 +1052,11 @@ private[archive] class DecodeV1(minor: LV.Minor) extends Decode.OfPackage[PLF.Pa
case PLF.Expr.SumCase.SUM_NOT_SET =>
throw ParseError("Expr.SUM_NOT_SET")
}
decodeLocation(lfExpr, definition) match {
case None => expr
case Some(loc) => ELocation(loc, expr)
}
}
private[this] def decodeCaseAlt(lfCaseAlt: PLF.CaseAlt, definition: String): CaseAlt = {
val pat: CasePat = lfCaseAlt.getSumCase match {