Skip to content

Commit 79ae75e

Browse files
committed
Add setting for macro evaluation timeouts
1 parent 708191d commit 79ae75e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class ScalaSettings extends Settings.SettingGroup {
4646
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
4747
val fromTasty = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")
4848

49+
/** Macro settings */
50+
val macroTimeout = IntSetting("-macro-timeout", "Timeout for the evaluation of a macro in ms", 1000, 1 to Int.MaxValue)
51+
4952
/** Decompiler settings */
5053
val printTasty = BooleanSetting("-print-tasty", "Prints the raw tasty when decompiling.")
5154
val printLines = BooleanSetting("-print-lines", "Show source code line numbers.")

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ object Splicer {
7474

7575
private def evaluateLambda(lambda: Seq[Any] => Object, args: Seq[Any], pos: Position)(implicit ctx: Context): Option[scala.quoted.Expr[Nothing]] = {
7676
try {
77-
val res = Sandbox.runInSecuredThread(lambda(args))
77+
val timeout = ctx.settings.macroTimeout.value
78+
val res = Sandbox.runInSecuredThread(timeout)(lambda(args))
7879
Some(res.asInstanceOf[scala.quoted.Expr[Nothing]])
7980
} catch {
8081
case ex: scala.quoted.QuoteError =>

compiler/src/dotty/tools/dotc/util/Sandbox.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import scala.quoted.QuoteError
88

99
object Sandbox {
1010

11-
/** Timeout in milliseconds */
12-
final val timeout = 3000 // TODO add a flag to allow custom timeouts
13-
14-
def runInSecuredThread[T](thunk: => T): T = {
11+
def runInSecuredThread[T](timeout: Int)(thunk: => T): T = {
1512
runWithSandboxSecurityManager { securityManager =>
1613
class SandboxThread extends Thread {
1714
var result: scala.util.Try[T] =

0 commit comments

Comments
 (0)