From 2ba333238fef263cd95437b4b1c650578db364b4 Mon Sep 17 00:00:00 2001 From: Goswin Rothenthal Date: Sun, 18 Dec 2022 23:32:19 +0100 Subject: [PATCH 1/2] add FSI session TryAbort() --- src/Compiler/Interactive/fsi.fs | 2 ++ src/Compiler/Interactive/fsi.fsi | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 0485d4e06e5..4f732c05873 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -3560,6 +3560,8 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i (tcImports :> IDisposable).Dispose() uninstallMagicAssemblyResolution.Dispose() + member _.TryAbort() = controlledExecution.TryAbort() + /// Load the dummy interaction, load the initial files, and, /// if interacting, start the background thread to read the standard input. member _.Interrupt() = fsiInterruptController.Interrupt() diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index 3288c379fe0..d493666c066 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -160,6 +160,13 @@ type FsiEvaluationSession = ?legacyReferenceResolver: LegacyReferenceResolver -> FsiEvaluationSession + /// A host calls this to request an abort of the evaluation thread. + /// This works only on net framework and on net7.0 or later. + /// On net framework it calls thread.Abort(). + /// On net7.0 or higher it cancels an internal cancellation token passed to System.Runtime.ControlledExecution.Run(). + /// On net6.0 or lower it does nothing. + member TryAbort : unit -> unit + /// A host calls this to request an interrupt on the evaluation thread. member Interrupt: unit -> unit From e41563996289eb7e6854c904cfbe5aa5b387f7c3 Mon Sep 17 00:00:00 2001 From: Goswin Rothenthal Date: Sun, 8 Jan 2023 14:47:54 +0100 Subject: [PATCH 2/2] fix tests, more docs --- src/Compiler/Interactive/fsi.fsi | 8 ++++---- ...Sharp.CompilerService.SurfaceArea.netstandard.expected | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index d493666c066..92d11df7f71 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -162,10 +162,10 @@ type FsiEvaluationSession = /// A host calls this to request an abort of the evaluation thread. /// This works only on net framework and on net7.0 or later. - /// On net framework it calls thread.Abort(). - /// On net7.0 or higher it cancels an internal cancellation token passed to System.Runtime.ControlledExecution.Run(). - /// On net6.0 or lower it does nothing. - member TryAbort : unit -> unit + /// On .NET Framework it calls thread.Abort() on the current thread, it also does the required ResetAbort. It reports a OperationCanceledException for the fsi evaluation. + /// On .NET 7 or higher it cancels an internal cancellation token passed to System.Runtime.ControlledExecution.Run(). It reports a OperationCanceledException for the fsi evaluation. + /// On .NET 6 or lower it does nothing. + member TryAbort: unit -> unit /// A host calls this to request an interrupt on the evaluation thread. member Interrupt: unit -> unit diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.expected b/tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.expected index 65f6aa81b24..fe0f5d78251 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.expected +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.expected @@ -4292,6 +4292,7 @@ FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`3[FSharp.Co FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void AddBoundValue(System.String, System.Object) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void EvalInteraction(System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Threading.CancellationToken]) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void EvalScript(System.String) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void TryAbort() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void Interrupt() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void ReportUnhandledException(System.Exception) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void Run()