# HG changeset patch # User Adam Chlipala # Date 1336237093 14400 # Node ID 518e0b23c4ef7500130fb80cdd1fdf6c99f12c1e # Parent 6fcce0592178759dfe1b2e2e6a91c4862a68eff3 -dumpTypesOnError diff -r 6fcce0592178 -r 518e0b23c4ef doc/manual.tex --- a/doc/manual.tex Sat May 05 12:45:35 2012 -0400 +++ b/doc/manual.tex Sat May 05 12:58:13 2012 -0400 @@ -201,7 +201,7 @@ \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 -r 6fcce0592178 -r 518e0b23c4ef src/elaborate.sig --- a/src/elaborate.sig Sat May 05 12:45:35 2012 -0400 +++ b/src/elaborate.sig Sat May 05 12:58:13 2012 -0400 @@ -37,6 +37,9 @@ (* 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 -r 6fcce0592178 -r 518e0b23c4ef src/elaborate.sml --- a/src/elaborate.sml Sat May 05 12:45:35 2012 -0400 +++ b/src/elaborate.sml Sat May 05 12:58:13 2012 -0400 @@ -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 @@ (*preface ("file", p_file env' file);*) - if !dumpTypes then + if !dumpTypes orelse (!dumpTypesOnError andalso ErrorMsg.anyErrors ()) then let open L' open Print.PD diff -r 6fcce0592178 -r 518e0b23c4ef src/main.mlton.sml --- a/src/main.mlton.sml Sat May 05 12:45:35 2012 -0400 +++ b/src/main.mlton.sml Sat May 05 12:58:13 2012 -0400 @@ -43,6 +43,7 @@ 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 @@ | "-dumpTypes" :: rest => (Elaborate.dumpTypes := true; doArgs rest) + | "-dumpTypesOnError" :: rest => + (Elaborate.dumpTypesOnError := true; + doArgs rest) | "-unifyMore" :: rest => (Elaborate.unifyMore := true; doArgs rest)