Skip to content

Commit 128a5f9

Browse files
committed
Avoid expensive settings lookup in setDenot
1 parent f925706 commit 128a5f9

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
231231
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
232232
ctx.base.usePhases(phases)
233233

234+
if ctx.settings.YnoDoubleBindings.value then
235+
ctx.base.checkNoDoubleBindings = true
236+
234237
def runPhases(using Context) = {
235238
var lastPrintedTree: PrintedTree = NoPrintedTree
236239
val profiler = ctx.profiler

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ object Config {
8383
*/
8484
inline val failOnInstantiationToNothing = false
8585

86-
/** Enable noDoubleDef checking if option "-YnoDoubleDefs" is set.
87-
* The reason to have an option as well as the present global switch is
88-
* that the noDoubleDef checking is done in a hotspot, and we do not
89-
* want to incur the overhead of checking an option each time.
90-
*/
91-
inline val checkNoDoubleBindings = true
92-
9386
/** Check positions for consistency after parsing */
9487
inline val checkPositions = true
9588

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,11 @@ object Contexts {
986986
/** Flag to suppress inlining, set after overflow */
987987
private[dotc] var stopInlining: Boolean = false
988988

989+
/** Cached -Yno-double-bindings setting. This is accessed from `setDenot`, which
990+
* is fairly hot, so we don't want to lookup the setting each time it is called.
991+
*/
992+
private[dotc] var checkNoDoubleBindings = false
993+
989994
/** A variable that records that some error was reported in a globally committable context.
990995
* The error will not necessarlily be emitted, since it could still be that
991996
* the enclosing context will be aborted. The variable is used as a smoke test

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,9 +2440,8 @@ object Types {
24402440
setDenot(memberDenot(name, allowPrivate = !symbol.exists || symbol.is(Private)))
24412441

24422442
private def setDenot(denot: Denotation)(using Context): Unit = {
2443-
if (Config.checkNoDoubleBindings)
2444-
if (ctx.settings.YnoDoubleBindings.value)
2445-
checkSymAssign(denot.symbol)
2443+
if ctx.base.checkNoDoubleBindings then
2444+
checkSymAssign(denot.symbol)
24462445

24472446
lastDenotation = denot
24482447
lastSymbol = denot.symbol

0 commit comments

Comments
 (0)