Skip to content

Commit 17f4213

Browse files
committed
Refine timeout config
1 parent 9be3001 commit 17f4213

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

compiler/src/dotty/tools/dotc/Run.scala

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import scala.util.control.NonFatal
3131
/** A compiler run. Exports various methods to compile source files */
3232
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
3333

34+
/** Default timeout to stop looking for further implicit suggestions, in ms.
35+
* This is usually for the first import suggestion; subsequent suggestions
36+
* may get smaller timeouts. @see ImportSuggestions.reduceTimeBudget
37+
*/
38+
var importSuggestionBudget: Int = ictx.settings.XimportSuggestionTimeout.value
39+
3440
/** If this variable is set to `true`, some core typer operations will
3541
* return immediately. Currently these early abort operations are
3642
* `Typer.typed` and `Implicits.typedImplicit`.

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class ScalaSettings extends Settings.SettingGroup {
8787
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
8888
val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.")
8989
val XignoreScala2Macros: Setting[Boolean] = BooleanSetting("-Xignore-scala2-macros", "Ignore errors when compiling code that calls Scala2 macros, these will fail at runtime.")
90+
val XimportSuggestionTimeout: Setting[Int] = IntSetting("-Ximport-suggestion-timeout", "Timeout (in ms) for searching for import suggestions when errors are reported.", 8000)
9091

9192
val XmixinForceForwarders = ChoiceSetting(
9293
name = "-Xmixin-force-forwarders",

compiler/src/dotty/tools/dotc/typer/Implicits.scala

-14
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,6 @@ trait ImplicitRunInfo:
481481

482482
private val EmptyTermRefSet = new TermRefSet(using NoContext)
483483

484-
/** Global timeout to stop looking for further implicit suggestions, in ms.
485-
* This is for the first import suggestion; subsequent suggestions
486-
* get smaller timeouts.
487-
*/
488-
private inline val suggestFirstImplicitsTimeOut = 10000
489-
490-
/** Global default timeout to stop looking for further implicit suggestions, in ms.
491-
* This is usually for the first import suggestion; subsequent suggestions
492-
* may get smaller timeouts. Specifically, the importSuggestions method reduces
493-
* the budget available after it is run by the time it took, but never less
494-
* than to half of the previous budget.
495-
*/
496-
var importSuggestionBudget: Long = 10000
497-
498484
private def isExcluded(sym: Symbol) =
499485
if migrateTo3 then false else sym.is(Package) || sym.isPackageObject
500486

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,16 @@ trait ImportSuggestions:
252252
(Nil, Nil)
253253
finally
254254
timer.cancel()
255-
ctx.run.importSuggestionBudget =
256-
(ctx.run.importSuggestionBudget - (System.currentTimeMillis() - start))
257-
`max` (ctx.run.importSuggestionBudget / 2)
255+
reduceTimeBudget(((System.currentTimeMillis() - start) min Int.MaxValue).toInt)
258256
end importSuggestions
259257

258+
/** Reduce next timeout for import suggestions by the amount of time it took
259+
* for current search, but but never less than to half of the previous budget.
260+
*/
261+
private def reduceTimeBudget(used: Int)(using Context) =
262+
ctx.run.importSuggestionBudget =
263+
(ctx.run.importSuggestionBudget - used) max (ctx.run.importSuggestionBudget / 2)
264+
260265
/** The `ref` parts of this list of pairs, discarding subsequent elements that
261266
* have the same String part. Elements are sorted by their String parts.
262267
*/

0 commit comments

Comments
 (0)