Skip to content

Commit c4ad09a

Browse files
Removing unreachable code (#15281)
* Removing unreachable code * Automated command ran: fantomas Co-authored-by: T-Gro <[email protected]> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8bed194 commit c4ad09a

File tree

4 files changed

+5
-116
lines changed

4 files changed

+5
-116
lines changed

src/Compiler/Interactive/fsi.fs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,8 +4463,6 @@ type FsiEvaluationSession
44634463
legacyReferenceResolver: LegacyReferenceResolver option
44644464
) =
44654465

4466-
do UnmanagedProcessExecutionOptions.EnableHeapTerminationOnCorruption() (* SDL recommendation *)
4467-
44684466
// Explanation: When FsiEvaluationSession.Create is called we do a bunch of processing. For fsi.exe
44694467
// and fsiAnyCpu.exe there are no other active threads at this point, so we can assume this is the
44704468
// unique compilation thread. For other users of FsiEvaluationSession it is reasonable to assume that
@@ -4625,9 +4623,9 @@ type FsiEvaluationSession
46254623
| Some assembly -> Some(Choice2Of2 assembly)
46264624
| None ->
46274625
#endif
4628-
match tcImports.TryFindExistingFullyQualifiedPathByExactAssemblyRef aref with
4629-
| Some resolvedPath -> Some(Choice1Of2 resolvedPath)
4630-
| None -> None
4626+
match tcImports.TryFindExistingFullyQualifiedPathByExactAssemblyRef aref with
4627+
| Some resolvedPath -> Some(Choice1Of2 resolvedPath)
4628+
| None -> None
46314629

46324630
let fsiDynamicCompiler =
46334631
FsiDynamicCompiler(
@@ -4739,68 +4737,11 @@ type FsiEvaluationSession
47394737
/// A host calls this to report an unhandled exception in a standard way, e.g. an exception on the GUI thread gets printed to stderr
47404738
member x.ReportUnhandledException exn = x.ReportUnhandledExceptionSafe true exn
47414739

4742-
member _.ReportUnhandledExceptionSafe isFromThreadException (exn: exn) =
4740+
member _.ReportUnhandledExceptionSafe _isFromThreadException (exn: exn) =
47434741
fsi.EventLoopInvoke(fun () ->
47444742
fprintfn fsiConsoleOutput.Error "%s" (exn.ToString())
47454743
diagnosticsLogger.SetError()
4746-
4747-
try
4748-
diagnosticsLogger.AbortOnError(fsiConsoleOutput)
4749-
with StopProcessing ->
4750-
// BUG 664864 some window that use System.Windows.Forms.DataVisualization types (possible FSCharts) was created in FSI.
4751-
// at some moment one chart has raised InvalidArgumentException from OnPaint, this exception was intercepted by the code in higher layer and
4752-
// passed to Application.OnThreadException. FSI has already attached its own ThreadException handler, inside it will log the original error
4753-
// and then raise StopProcessing exception to unwind the stack (and possibly shut down current Application) and get to DriveFsiEventLoop.
4754-
// DriveFsiEventLoop handles StopProcessing by suppressing it and restarting event loop from the beginning.
4755-
// This schema works almost always except when FSI is started as 64 bit process (FsiAnyCpu) on Windows 7.
4756-
4757-
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v=vs.85).aspx
4758-
// Remarks:
4759-
// If your application runs on a 32-bit version of Windows operating system, uncaught exceptions from the callback
4760-
// will be passed onto higher-level exception handlers of your application when available.
4761-
// The system then calls the unhandled exception filter to handle the exception prior to terminating the process.
4762-
// If the PCA is enabled, it will offer to fix the problem the next time you run the application.
4763-
// However, if your application runs on a 64-bit version of Windows operating system or WOW64,
4764-
// you should be aware that a 64-bit operating system handles uncaught exceptions differently based on its 64-bit processor architecture,
4765-
// exception architecture, and calling convention.
4766-
// The following table summarizes all possible ways that a 64-bit Windows operating system or WOW64 handles uncaught exceptions.
4767-
// 1. The system suppresses any uncaught exceptions.
4768-
// 2. The system first terminates the process, and then the Program Compatibility Assistant (PCA) offers to fix it the next time
4769-
// you run the application. You can disable the PCA mitigation by adding a Compatibility section to the application manifest.
4770-
// 3. The system calls the exception filters but suppresses any uncaught exceptions when it leaves the callback scope,
4771-
// without invoking the associated handlers.
4772-
// Behavior type 2 only applies to the 64-bit version of the Windows 7 operating system.
4773-
4774-
// NOTE: tests on Win8 box showed that 64 bit version of the Windows 8 always apply type 2 behavior
4775-
4776-
// Effectively this means that when StopProcessing exception is raised from ThreadException callback - it won't be intercepted in DriveFsiEventLoop.
4777-
// Instead it will be interpreted as unhandled exception and crash the whole process.
4778-
4779-
// FIX: detect if current process in 64 bit running on Windows 7 or Windows 8 and if yes - swallow the StopProcessing and ScheduleRestart instead.
4780-
// Visible behavior should not be different, previously exception unwinds the stack and aborts currently running Application.
4781-
// After that it will be intercepted and suppressed in DriveFsiEventLoop.
4782-
// Now we explicitly shut down Application so after execution of callback will be completed the control flow
4783-
// will also go out of WinFormsEventLoop.Run and again get to DriveFsiEventLoop => restart the loop. I'd like the fix to be as conservative as possible
4784-
// so we use special case for problematic case instead of just always scheduling restart.
4785-
4786-
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
4787-
let os = Environment.OSVersion
4788-
// Win7 6.1
4789-
let isWindows7 = os.Version.Major = 6 && os.Version.Minor = 1
4790-
// Win8 6.2
4791-
let isWindows8Plus = os.Version >= Version(6, 2, 0, 0)
4792-
4793-
if
4794-
isFromThreadException
4795-
&& ((isWindows7 && (IntPtr.Size = 8) && isWindows8Plus))
4796-
#if DEBUG
4797-
// for debug purposes
4798-
&& Environment.GetEnvironmentVariable("FSI_SCHEDULE_RESTART_WITH_ERRORS") = null
4799-
#endif
4800-
then
4801-
fsi.EventLoopScheduleRestart()
4802-
else
4803-
reraise ())
4744+
diagnosticsLogger.AbortOnError(fsiConsoleOutput))
48044745

48054746
member _.PartialAssemblySignatureUpdated =
48064747
fsiInteractionProcessor.PartialAssemblySignatureUpdated

src/Compiler/Utilities/lib.fs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ open System
66
open System.Collections.Generic
77
open System.IO
88
open System.Text
9-
open System.Threading
109
open System.Threading.Tasks
11-
open System.Runtime.InteropServices
1210
open Internal.Utilities.Collections
1311
open Internal.Utilities.Library
1412

@@ -381,48 +379,6 @@ type Dumper(x:obj) =
381379
[<DebuggerBrowsable(DebuggerBrowsableState.Collapsed)>]
382380
member self.Dump = sprintf "%A" x
383381
#endif
384-
//---------------------------------------------------------------------------
385-
// EnableHeapTerminationOnCorruption()
386-
//---------------------------------------------------------------------------
387-
388-
// USAGE: call UnmanagedProcessExecutionOptions.EnableHeapTerminationOnCorruption() from "main()".
389-
// Note: This is not SDL required but recommended.
390-
module UnmanagedProcessExecutionOptions =
391-
392-
[<DllImport("kernel32.dll")>]
393-
extern UIntPtr private GetProcessHeap()
394-
395-
[<DllImport("kernel32.dll")>]
396-
extern bool private HeapSetInformation(
397-
UIntPtr _HeapHandle,
398-
UInt32 _HeapInformationClass,
399-
UIntPtr _HeapInformation,
400-
UIntPtr _HeapInformationLength)
401-
402-
[<DllImport("kernel32.dll")>]
403-
extern UInt32 private GetLastError()
404-
405-
// Translation of C# from http://swikb/v1/DisplayOnlineDoc.aspx?entryID=826 and copy in bug://5018
406-
[<System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)>]
407-
let EnableHeapTerminationOnCorruption() =
408-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Major >= 6 && // If OS is Vista or higher
409-
Environment.Version.Major < 3) then // and CLR not 3.0 or higher
410-
// "The flag HeapSetInformation sets is available in Windows XP SP3 and later.
411-
// The data structure used for heap information is available on earlier versions of Windows.
412-
// The call will either return TRUE (found and set the flag) or false (flag not found).
413-
// Not a problem in native code, so the program will merrily continue running.
414-
// In managed code, the call to HeapSetInformation is a p/invoke.
415-
// If HeapSetInformation returns FALSE then an exception will be thrown.
416-
// If we are not running an OS which supports this (XP SP3, Vista, Server 2008, and Win7)
417-
// then the call should not be made." -- see bug://5018.
418-
// See also:
419-
// http://blogs.msdn.com/michael_howard/archive/2008/02/18/faq-about-heapsetinformation-in-windows-vista-and-heap-based-buffer-overruns.aspx
420-
let HeapEnableTerminationOnCorruption = 1u : uint32
421-
if not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero)) then
422-
raise (System.Security.SecurityException(
423-
"Unable to enable unmanaged process execution option TerminationOnCorruption. " +
424-
"HeapSetInformation() returned FALSE; LastError = 0x" +
425-
GetLastError().ToString("X").PadLeft(8, '0') + "."))
426382

427383
[<RequireQualifiedAccess>]
428384
type MaybeLazy<'T> =

src/Compiler/Utilities/lib.fsi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ val inline cacheOptRef: cache: 'a option ref -> f: (unit -> 'a) -> 'a
247247

248248
val inline tryGetCacheValue: cache: cache<'a> -> NonNullSlot<'a> voption
249249

250-
module UnmanagedProcessExecutionOptions =
251-
val EnableHeapTerminationOnCorruption: unit -> unit
252-
253250
[<RequireQualifiedAccess>]
254251
type MaybeLazy<'T> =
255252
| Strict of 'T

src/fsc/fscmain.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ module internal FSharp.Compiler.CommandLineMain
44

55
open System
66
open System.Reflection
7-
open System.Runtime
87
open System.Runtime.CompilerServices
98
open System.Threading
109

1110
open Internal.Utilities.Library
12-
open Internal.Utilities.Library.Extras
1311
open FSharp.Compiler.AbstractIL
1412
open FSharp.Compiler.AbstractIL.ILBinaryReader
1513
open FSharp.Compiler.CompilerConfig
@@ -39,9 +37,6 @@ let main (argv) =
3937
// Set the initial phase to garbage collector to batch mode, which improves overall performance.
4038
use _ = UseBuildPhase BuildPhase.Parameter
4139

42-
// An SDL recommendation
43-
UnmanagedProcessExecutionOptions.EnableHeapTerminationOnCorruption()
44-
4540
try
4641

4742
// We are on a compilation thread

0 commit comments

Comments
 (0)