On the review with @KevinRansom, we've realized that there's an existing mechanism for proper exit from the compiler - using of exiters (with StopProcessing exceptions probably).
For example:
|
let quitProcessExiter = |
|
{ new Exiter with |
|
member _.Exit(n) = |
|
try |
|
exit n |
|
with _ -> |
|
() |
|
|
|
failwithf "%s" (FSComp.SR.elSysEnvExitDidntExit ()) |
|
} |
|
|
|
// Get the handler for legacy resolution of references via MSBuild. |
|
let legacyReferenceResolver = LegacyMSBuildReferenceResolver.getResolver () |
|
|
|
// Perform the main compilation. |
|
// |
|
// This is the only place where ReduceMemoryFlag.No is set. This is because fsc.exe is not a long-running process and |
|
// thus we can use file-locking memory mapped files. |
|
// |
|
// This is also one of only two places where CopyFSharpCoreFlag.Yes is set. The other is in LegacyHostedCompilerForTesting. |
|
CompileFromCommandLineArguments( |
|
ctok, |
|
argv, |
|
legacyReferenceResolver, |
|
false, |
|
ReduceMemoryFlag.No, |
|
CopyFSharpCoreFlag.Yes, |
|
quitProcessExiter, |
|
ConsoleLoggerProvider(), |
|
None, |
|
None |
|
) |
or:
|
let exiter = |
|
{ new Exiter with |
|
member x.Exit n = raise StopProcessing |
|
} |
|
|
|
try |
|
f exiter |
|
0 |
|
with e -> |
|
stopProcessingRecovery e range0 |
|
1 |
Wondering how easy will it be to plug into the cli options, since it is designed for cases like this and is probably the right way of dealing with it.
Originally posted by @vzarytovskii in #13702 (comment)
On the review with @KevinRansom, we've realized that there's an existing mechanism for proper exit from the compiler - using of exiters (with StopProcessing exceptions probably).
For example:
fsharp/src/fsc/fscmain.fs
Lines 77 to 108 in af0015e
or:
fsharp/src/Compiler/Service/service.fs
Lines 119 to 129 in af0015e
Wondering how easy will it be to plug into the cli options, since it is designed for cases like this and is probably the right way of dealing with it.
Originally posted by @vzarytovskii in #13702 (comment)