summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-05-05 12:58:13 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-05-05 12:58:13 -0400
commita424e0352aff3490a58d19de5ebf4a164bd03b65 (patch)
tree9cc3661046de89d0263f025bdbf935cce233811d
parentf2ae62f46ac8b9cefc841bd064c7ea8317cc9752 (diff)
-dumpTypesOnError
-rw-r--r--doc/manual.tex2
-rw-r--r--src/elaborate.sig3
-rw-r--r--src/elaborate.sml3
-rw-r--r--src/main.mlton.sml4
4 files changed, 10 insertions, 2 deletions
diff --git a/doc/manual.tex b/doc/manual.tex
index 853febe7..1976199d 100644
--- a/doc/manual.tex
+++ b/doc/manual.tex
@@ -201,7 +201,7 @@ urweb -tc P
\end{verbatim}
It is often worthwhile to run \cd{urweb} in this mode, because later phases of compilation can take significantly longer than type-checking alone, and the type checker catches many errors that would traditionally be found through debugging a running application.
-A related option is \cd{-dumpTypes}, which, as long as parsing succeeds, outputs to stdout a summary of the kinds of all identifiers declared with \cd{con} and the types of all identifiers declared with \cd{val} or \cd{val rec}. This information is dumped even if there are errors during type inference. Compiler error messages go to stderr, not stdout, so it is easy to distinguish the two kinds of output programmatically.
+A related option is \cd{-dumpTypes}, which, as long as parsing succeeds, outputs to stdout a summary of the kinds of all identifiers declared with \cd{con} and the types of all identifiers declared with \cd{val} or \cd{val rec}. This information is dumped even if there are errors during type inference. Compiler error messages go to stderr, not stdout, so it is easy to distinguish the two kinds of output programmatically. A refined version of this option is \cd{-dumpTypesOnError}, which only has an effect when there are compilation errors.
It may be useful to combine another option \cd{-unifyMore} with \cd{-dumpTypes}. Ur/Web type inference proceeds in a series of stages, where the first is standard Hindley-Milner type inference as in ML, and the later phases add more complex aspects. By default, an error detected in one phase cuts off the execution of later phases. However, the later phases might still determine more values of unification variables. These value choices might be ``misguided,'' since earlier phases have not come up with reasonable types at a coarser detail level; but the unification decisions may still be useful for debugging and program understanding. So, if a run with \cd{-dumpTypes} leaves unification variables undetermined in positions where you would like to see best-effort guesses instead, consider \cd{-unifyMore}. Note that \cd{-unifyMore} has no effect when type inference succeeds fully, but it may lead to many more error messages when inference fails.
diff --git a/src/elaborate.sig b/src/elaborate.sig
index b4a4da88..d60cff42 100644
--- a/src/elaborate.sig
+++ b/src/elaborate.sig
@@ -37,6 +37,9 @@ signature ELABORATE = sig
(* After elaboration (successful or failed), should I output a mapping from
* all identifiers to their kinds/types? *)
+ val dumpTypesOnError : bool ref
+ (* Like above, but only used if there are compile errors. *)
+
val unifyMore : bool ref
(* Run all phases of type inference, even if an error is detected by an
* early phase. *)
diff --git a/src/elaborate.sml b/src/elaborate.sml
index fe2e2f12..07a1d976 100644
--- a/src/elaborate.sml
+++ b/src/elaborate.sml
@@ -39,6 +39,7 @@
open ElabErr
val dumpTypes = ref false
+ val dumpTypesOnError = ref false
val unifyMore = ref false
val incremental = ref false
val verbose = ref false
@@ -4747,7 +4748,7 @@ fun elabFile basis basis_tm topStr topSgn top_tm env file =
(*preface ("file", p_file env' file);*)
- if !dumpTypes then
+ if !dumpTypes orelse (!dumpTypesOnError andalso ErrorMsg.anyErrors ()) then
let
open L'
open Print.PD
diff --git a/src/main.mlton.sml b/src/main.mlton.sml
index 4e1f8e2c..6ecb2f92 100644
--- a/src/main.mlton.sml
+++ b/src/main.mlton.sml
@@ -43,6 +43,7 @@ fun oneRun args =
val () = (Compiler.debug := false;
Elaborate.verbose := false;
Elaborate.dumpTypes := false;
+ Elaborate.dumpTypesOnError := false;
Elaborate.unifyMore := false;
Compiler.dumpSource := false;
Compiler.doIflow := false;
@@ -103,6 +104,9 @@ fun oneRun args =
| "-dumpTypes" :: rest =>
(Elaborate.dumpTypes := true;
doArgs rest)
+ | "-dumpTypesOnError" :: rest =>
+ (Elaborate.dumpTypesOnError := true;
+ doArgs rest)
| "-unifyMore" :: rest =>
(Elaborate.unifyMore := true;
doArgs rest)