Skip to content

Commit

Permalink
Configurable error depth
Browse files Browse the repository at this point in the history
Summary:
Make subtyping error depth configurable via an environment variable, e.g., `EQWALIZER_ERROR_DEPTH=8 eqwalize module`.

By default, error depth is still set to 4.

Reviewed By: ilya-klyuchnikov

Differential Revision: D47717108

fbshipit-source-id: b7efa3140a35698fd591ec359003c6276a2aad1c
  • Loading branch information
VLanvin authored and facebook-github-bot committed Dec 4, 2023
1 parent ab28269 commit 66e097e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions eqwalizer/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ eqwalizer {
check_redundant_guards = ${?EQWALIZER_CHECK_REDUNDANT_GUARDS}
mode = standalone
mode = ${?EQWALIZER_MODE}
error_depth = 4
error_depth = ${?EQWALIZER_ERROR_DEPTH}
}
2 changes: 2 additions & 0 deletions eqwalizer/src/main/scala/com/whatsapp/eqwalizer/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ package object eqwalizer {
tolerateErrors: Boolean,
checkRedundantGuards: Boolean,
mode: Mode.Mode,
errorDepth: Int,
) {
def useElp(): Boolean = {
mode match {
Expand Down Expand Up @@ -79,6 +80,7 @@ package object eqwalizer {
tolerateErrors = config.getBoolean("tolerate_errors"),
checkRedundantGuards = config.getBoolean("check_redundant_guards"),
mode,
errorDepth = config.getInt("error_depth"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.whatsapp.eqwalizer.ast.Types._
import com.whatsapp.eqwalizer.ast.{RemoteId, Show, TypeVars}

object SubtypeDetail {
private val maxDepth = 4
lazy val nonVerboseRids = builtinTypes.keys.map(RemoteId("erlang", _, 0)).toSet

private case class Detail(t1: Type, t2: Type, reasonPrefix: Option[String], reasonPostfix: Option[String])
Expand Down Expand Up @@ -83,7 +82,7 @@ class SubtypeDetail(pipelineContext: PipelineContext) {
}

private def findSubtypeMismatch(t1: Type, t2: Type): List[Detail] =
findMismatchAux(t1, t2, Nil, Set.empty).reverse.take(maxDepth)
findMismatchAux(t1, t2, Nil, Set.empty).reverse.take(pipelineContext.errorDepth)

// keep this function in sync with subtype.subtype
// Main differences from subtype.subtype's cases:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package object tc {
tolerateErrors: Option[Boolean] = None,
unlimitedRefinement: Option[Boolean] = None,
checkRedundantGuards: Option[Boolean] = None,
errorDepth: Option[Int] = None,
)

val noOptions: Options = Options()
Expand Down Expand Up @@ -65,5 +66,7 @@ package object tc {
options.checkRedundantGuards.getOrElse(config.checkRedundantGuards)
val typeInfo: TypeInfo =
new TypeInfo(this)
val errorDepth: Int =
options.errorDepth.getOrElse(config.errorDepth)
}
}

0 comments on commit 66e097e

Please sign in to comment.