-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve and document the Driver#process API, fix partest logging #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cf1413b
d6a52ee
f926c8c
73fad44
208f7cd
7827c5a
a33d517
7eba7f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,28 +33,64 @@ abstract class Driver extends DotClass { | |
protected def sourcesRequired = true | ||
|
||
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = { | ||
val summary = CompilerCommand.distill(args)(rootCtx) | ||
// FIXME: We should reuse rootCtx instead of creating newCtx, but this | ||
// makes some tests fail with "denotation module _root_ invalid in run 2." | ||
val newCtx = initCtx.setCompilerCallback(rootCtx.compilerCallback) | ||
implicit val ctx: Context = newCtx.fresh.setSettings(summary.sstate) | ||
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired) | ||
val ctx = rootCtx.fresh | ||
val summary = CompilerCommand.distill(args)(ctx) | ||
ctx.setSettings(summary.sstate) | ||
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) | ||
(fileNames, ctx) | ||
} | ||
|
||
def process(args: Array[String], rootCtx: Context): Reporter = { | ||
val (fileNames, ctx) = setup(args, rootCtx) | ||
doCompile(newCompiler(), fileNames)(ctx) | ||
} | ||
|
||
def process(args: Array[String], callback: CompilerCallback): Reporter = { | ||
process(args, initCtx.setCompilerCallback(callback)) | ||
/** Principal entry point to the compiler. | ||
* Creates a new compiler instance and run it with arguments `args`. | ||
* | ||
* The optional arguments of this method all have `null` as their default | ||
* value, this makes it easier to call this method by reflection or from Java. | ||
* | ||
* @param args Arguments to pass to the compiler. | ||
* @param reporter Used to log errors, warnings, and info messages. | ||
* The default reporter is used if this is `null`. | ||
* @param callback Used to execute custom code during the compilation | ||
* process. No callbacks will be executed if this is `null`. | ||
* @return The `Reporter` used. Use `Reporter#hasErrors` to check | ||
* if compilation succeeded. | ||
*/ | ||
final def process(args: Array[String], reporter: Reporter = null, | ||
callback: CompilerCallback = null): Reporter = { | ||
val ctx = initCtx.fresh | ||
if (reporter != null) | ||
ctx.setReporter(reporter) | ||
if (callback != null) | ||
ctx.setCompilerCallback(callback) | ||
process(args, ctx) | ||
} | ||
|
||
// We overload `process` instead of using a default argument so that we | ||
// can easily call this method using reflection from `RawCompiler` in sbt. | ||
def process(args: Array[String]): Reporter = { | ||
process(args, initCtx) | ||
/** Entry point to the compiler with no optional arguments. | ||
* | ||
* This overload is provided for compatibility reasons: the | ||
* `RawCompiler` of sbt expects this method to exist and calls | ||
* it using reflection. Keeping it means that we can change | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expects |
||
* the other overloads without worrying about breaking compatibility | ||
* with sbt. | ||
*/ | ||
final def process(args: Array[String]): Reporter = | ||
process(args, null, null) | ||
|
||
/** Entry point to the compiler using a custom `Context`. | ||
* | ||
* In most cases, you do not need a custom `Context` and should | ||
* instead use one of the other overloads of `process`. However, | ||
* the other overloads cannot be overriden, instead you | ||
* should override this one which they call internally. | ||
* | ||
* @param args Arguments to pass to the compiler. | ||
* @param rootCtx The root Context to use. | ||
* @return The `Reporter` used. Use `Reporter#hasErrors` to check | ||
* if compilation succeeded. | ||
*/ | ||
def process(args: Array[String], rootCtx: Context): Reporter = { | ||
val (fileNames, ctx) = setup(args, rootCtx) | ||
doCompile(newCompiler(), fileNames)(ctx) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,22 +72,16 @@ object Contexts { | |
def next = { val c = current; current = current.outer; c } | ||
} | ||
|
||
/** Set the compiler callback, shared by all contexts with the same `base` */ | ||
def setCompilerCallback(callback: CompilerCallback): this.type = { | ||
base.compilerCallback = callback; this | ||
} | ||
|
||
/** The outer context */ | ||
private[this] var _outer: Context = _ | ||
protected def outer_=(outer: Context) = _outer = outer | ||
def outer: Context = _outer | ||
|
||
// protected def compilerCallback_=(callback: CompilerCallback) = | ||
// _compilerCallback = callback | ||
// def compilerCallback: CompilerCallback = _compilerCallback | ||
// def setCompilerCallback(callback: CompilerCallback): this.type = { | ||
// this.compilerCallback = callback; this | ||
// } | ||
/** The compiler callback implementation, or null if no callback will be called. */ | ||
private[this] var _compilerCallback: CompilerCallback = _ | ||
protected def compilerCallback_=(callback: CompilerCallback) = | ||
_compilerCallback = callback | ||
def compilerCallback: CompilerCallback = _compilerCallback | ||
|
||
/** The current context */ | ||
private[this] var _period: Period = _ | ||
|
@@ -426,7 +420,9 @@ object Contexts { | |
abstract class FreshContext extends Context { | ||
def setPeriod(period: Period): this.type = { this.period = period; this } | ||
def setMode(mode: Mode): this.type = { this.mode = mode; this } | ||
def setCompilerCallback(callback: CompilerCallback): this.type = { this.compilerCallback = callback; this } | ||
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this } | ||
def setReporter(reporter: Reporter): this.type = setTyperState(typerState.withReporter(reporter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a useful helper method. I think there are several occurrences of |
||
def setNewTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true)) | ||
def setExploreTyperState: this.type = setTyperState(typerState.fresh(isCommittable = false)) | ||
def setPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this } | ||
|
@@ -481,7 +477,7 @@ object Contexts { | |
outer = NoContext | ||
period = InitialPeriod | ||
mode = Mode.None | ||
typerState = new TyperState(new ThrowingReporter(new ConsoleReporter()(this))) | ||
typerState = new TyperState(new ConsoleReporter()) | ||
printerFn = new RefinedPrinter(_) | ||
owner = NoSymbol | ||
sstate = settings.defaultState | ||
|
@@ -536,10 +532,6 @@ object Contexts { | |
|
||
/** The essential mutable state of a context base, collected into a common class */ | ||
class ContextState { | ||
|
||
/** The compiler callback implementation, or null if unset */ | ||
var compilerCallback: CompilerCallback = _ | ||
|
||
// Symbols state | ||
|
||
/** A counter for unique ids */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the default arguments here? Or do the overloaded variants of
process
cover all the use cases already?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yes, I don't want to add even more overloads like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair enough.
On Thu, Feb 4, 2016 at 7:09 PM, Guillaume Martres notifications@github.com
wrote:
Martin Odersky
EPFL