Skip to content

Commit c04b38d

Browse files
committed
Context: set compilerCallback like other context variables
Previously, we could set compilerCallback on non-fresh contexts, but there is no reason that this should be allowed, and this is not done anymore in the code since the last commit.
1 parent f81f730 commit c04b38d

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/dotty/tools/dotc/CompilerCallback.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.io.File
1818
* }
1919
* dotty.tools.dotc.process(args, callback)
2020
* // Or, if you have a custom root context `rootCtx`:
21-
* dotty.tools.dotc.process(args, rootCtx.setCompilerCallback(callback))
21+
* dotty.tools.dotc.process(args, rootCtx.fresh.setCompilerCallback(callback))
2222
* }}}
2323
*/
2424
trait CompilerCallback {

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,16 @@ object Contexts {
7272
def next = { val c = current; current = current.outer; c }
7373
}
7474

75-
/** Set the compiler callback, shared by all contexts with the same `base` */
76-
def setCompilerCallback(callback: CompilerCallback): this.type = {
77-
base.compilerCallback = callback; this
78-
}
79-
8075
/** The outer context */
8176
private[this] var _outer: Context = _
8277
protected def outer_=(outer: Context) = _outer = outer
8378
def outer: Context = _outer
8479

85-
// protected def compilerCallback_=(callback: CompilerCallback) =
86-
// _compilerCallback = callback
87-
// def compilerCallback: CompilerCallback = _compilerCallback
88-
// def setCompilerCallback(callback: CompilerCallback): this.type = {
89-
// this.compilerCallback = callback; this
90-
// }
80+
/** The compiler callback implementation, or null if no callback will be called. */
81+
private[this] var _compilerCallback: CompilerCallback = _
82+
protected def compilerCallback_=(callback: CompilerCallback) =
83+
_compilerCallback = callback
84+
def compilerCallback: CompilerCallback = _compilerCallback
9185

9286
/** The current context */
9387
private[this] var _period: Period = _
@@ -426,6 +420,7 @@ object Contexts {
426420
abstract class FreshContext extends Context {
427421
def setPeriod(period: Period): this.type = { this.period = period; this }
428422
def setMode(mode: Mode): this.type = { this.mode = mode; this }
423+
def setCompilerCallback(callback: CompilerCallback): this.type = { this.compilerCallback = callback; this }
429424
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
430425
def setReporter(reporter: Reporter): this.type = setTyperState(typerState.withReporter(reporter))
431426
def setNewTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true))
@@ -537,10 +532,6 @@ object Contexts {
537532

538533
/** The essential mutable state of a context base, collected into a common class */
539534
class ContextState {
540-
541-
/** The compiler callback implementation, or null if unset */
542-
var compilerCallback: CompilerCallback = _
543-
544535
// Symbols state
545536

546537
/** A counter for unique ids */

0 commit comments

Comments
 (0)