Skip to content

Use proper process exiting mechanism in FSC #13748

@psfinaki

Description

@psfinaki

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

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)

Metadata

Metadata

Assignees

Labels

Area-FSCEverything related to F# compiler CLI

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions