From 4172182da96ba3a422e0e673e3f6ac4debc0f571 Mon Sep 17 00:00:00 2001 From: Goswin Rothenthal Date: Sun, 8 Jan 2023 14:56:06 +0100 Subject: [PATCH 1/2] remove input.fsx literal --- src/Compiler/Interactive/fsi.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 30a55989edf..5c7ff2d7558 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -3669,7 +3669,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i let errorOptions = TcConfig.Create(tcConfigB,validate = false).diagnosticsOptions let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat) fsiInteractionProcessor.EvalInteraction(ctok, code, dummyScriptFileName, diagnosticsLogger, cancellationToken) - |> commitResultNonThrowing errorOptions "input.fsx" diagnosticsLogger + |> commitResultNonThrowing errorOptions dummyScriptFileName diagnosticsLogger member _.EvalScript(filePath) : unit = // Explanation: When the user of the FsiInteractiveSession object calls this method, the From f1088fc8af866aa7c9a729793cc06b47ae6f2846 Mon Sep 17 00:00:00 2001 From: Goswin Rothenthal Date: Sat, 14 Jan 2023 14:59:52 +0100 Subject: [PATCH 2/2] add scriptName via overloads --- src/Compiler/Interactive/fsi.fs | 34 +++++++++----- src/Compiler/Interactive/fsi.fsi | 44 +++++++++++++++++++ ...ervice.SurfaceArea.netstandard20.debug.bsl | 4 ++ ...vice.SurfaceArea.netstandard20.release.bsl | 4 ++ 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 5c7ff2d7558..28c9e840c64 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -3628,17 +3628,23 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i member _.FormatValue(reflectionValue:obj, reflectionType) = fsiDynamicCompiler.FormatValue(reflectionValue, reflectionType) - member _.EvalExpression(code) = + member this.EvalExpression(code) = + this.EvalExpression(code, dummyScriptFileName) + + member _.EvalExpression(code, scriptFileName) = // Explanation: When the user of the FsiInteractiveSession object calls this method, the // code is parsed, checked and evaluated on the calling thread. This means EvalExpression // is not safe to call concurrently. let ctok = AssumeCompilationThreadWithoutEvidence() - fsiInteractionProcessor.EvalExpression(ctok, code, dummyScriptFileName, diagnosticsLogger) + fsiInteractionProcessor.EvalExpression(ctok, code, scriptFileName, diagnosticsLogger) |> commitResult - member _.EvalExpressionNonThrowing(code) = + member this.EvalExpressionNonThrowing(code) = + this.EvalExpressionNonThrowing(code, dummyScriptFileName) + + member _.EvalExpressionNonThrowing(code, scriptFileName) = // Explanation: When the user of the FsiInteractiveSession object calls this method, the // code is parsed, checked and evaluated on the calling thread. This means EvalExpression // is not safe to call concurrently. @@ -3646,20 +3652,28 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i let errorOptions = TcConfig.Create(tcConfigB,validate = false).diagnosticsOptions let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat) - fsiInteractionProcessor.EvalExpression(ctok, code, dummyScriptFileName, diagnosticsLogger) - |> commitResultNonThrowing errorOptions dummyScriptFileName diagnosticsLogger + fsiInteractionProcessor.EvalExpression(ctok, code, scriptFileName, diagnosticsLogger) + |> commitResultNonThrowing errorOptions scriptFileName diagnosticsLogger + + member this.EvalInteraction(code, ?cancellationToken) : unit = + let cancellationToken = defaultArg cancellationToken CancellationToken.None + this.EvalInteraction(code, dummyScriptFileName, cancellationToken) - member _.EvalInteraction(code, ?cancellationToken) : unit = + member _.EvalInteraction(code, scriptFileName, ?cancellationToken) : unit = // Explanation: When the user of the FsiInteractiveSession object calls this method, the // code is parsed, checked and evaluated on the calling thread. This means EvalExpression // is not safe to call concurrently. let ctok = AssumeCompilationThreadWithoutEvidence() let cancellationToken = defaultArg cancellationToken CancellationToken.None - fsiInteractionProcessor.EvalInteraction(ctok, code, dummyScriptFileName, diagnosticsLogger, cancellationToken) + fsiInteractionProcessor.EvalInteraction(ctok, code, scriptFileName, diagnosticsLogger, cancellationToken) |> commitResult |> ignore - member _.EvalInteractionNonThrowing(code, ?cancellationToken) = + member this.EvalInteractionNonThrowing(code, ?cancellationToken) = + let cancellationToken = defaultArg cancellationToken CancellationToken.None + this.EvalInteractionNonThrowing(code, dummyScriptFileName, cancellationToken) + + member this.EvalInteractionNonThrowing(code, scriptFileName, ?cancellationToken) = // Explanation: When the user of the FsiInteractiveSession object calls this method, the // code is parsed, checked and evaluated on the calling thread. This means EvalExpression // is not safe to call concurrently. @@ -3668,8 +3682,8 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i let errorOptions = TcConfig.Create(tcConfigB,validate = false).diagnosticsOptions let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat) - fsiInteractionProcessor.EvalInteraction(ctok, code, dummyScriptFileName, diagnosticsLogger, cancellationToken) - |> commitResultNonThrowing errorOptions dummyScriptFileName diagnosticsLogger + fsiInteractionProcessor.EvalInteraction(ctok, code, scriptFileName, diagnosticsLogger, cancellationToken) + |> commitResultNonThrowing errorOptions scriptFileName diagnosticsLogger member _.EvalScript(filePath) : unit = // Explanation: When the user of the FsiInteractiveSession object calls this method, the diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index 3288c379fe0..6c1bed8c418 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -178,6 +178,16 @@ type FsiEvaluationSession = /// by input from 'stdin'. member EvalInteraction: code: string * ?cancellationToken: CancellationToken -> unit + /// Execute the code as if it had been entered as one or more interactions, with an + /// implicit termination at the end of the input. Stop on first error, discarding the rest + /// of the input. Errors are sent to the output writer, a 'true' return value indicates there + /// were no errors overall. Execution is performed on the 'Run()' thread. + /// + /// Due to a current limitation, it is not fully thread-safe to run this operation concurrently with evaluation triggered + /// by input from 'stdin'. + /// The scriptFileName parameter is used to report errors including this file name. + member EvalInteraction: code: string * scriptFileName: string * ?cancellationToken: CancellationToken -> unit + /// Execute the code as if it had been entered as one or more interactions, with an /// implicit termination at the end of the input. Stop on first error, discarding the rest /// of the input. Errors and warnings are collected apart from any exception arising from execution @@ -188,6 +198,18 @@ type FsiEvaluationSession = member EvalInteractionNonThrowing: code: string * ?cancellationToken: CancellationToken -> Choice * FSharpDiagnostic[] + /// Execute the code as if it had been entered as one or more interactions, with an + /// implicit termination at the end of the input. Stop on first error, discarding the rest + /// of the input. Errors and warnings are collected apart from any exception arising from execution + /// which is returned via a Choice. Execution is performed on the 'Run()' thread. + /// + /// Due to a current limitation, it is not fully thread-safe to run this operation concurrently with evaluation triggered + /// by input from 'stdin'. + /// The scriptFileName parameter is used to report errors including this file name. + member EvalInteractionNonThrowing: + code: string * scriptFileName: string * ?cancellationToken: CancellationToken -> + Choice * FSharpDiagnostic[] + /// Execute the given script. Stop on first error, discarding the rest /// of the script. Errors are sent to the output writer, a 'true' return value indicates there /// were no errors overall. Execution is performed on the 'Run()' thread. @@ -213,6 +235,16 @@ type FsiEvaluationSession = /// by input from 'stdin'. member EvalExpression: code: string -> FsiValue option + /// Execute the code as if it had been entered as one or more interactions, with an + /// implicit termination at the end of the input. Stop on first error, discarding the rest + /// of the input. Errors are sent to the output writer. Parsing is performed on the current thread, and execution is performed + /// synchronously on the 'main' thread. + /// + /// Due to a current limitation, it is not fully thread-safe to run this operation concurrently with evaluation triggered + /// by input from 'stdin'. + /// The scriptFileName parameter is used to report errors including this file name. + member EvalExpression: code: string * scriptFileName: string -> FsiValue option + /// Execute the code as if it had been entered as one or more interactions, with an /// implicit termination at the end of the input. Stop on first error, discarding the rest /// of the input. Errors and warnings are collected apart from any exception arising from execution @@ -223,6 +255,18 @@ type FsiEvaluationSession = /// by input from 'stdin'. member EvalExpressionNonThrowing: code: string -> Choice * FSharpDiagnostic[] + /// Execute the code as if it had been entered as one or more interactions, with an + /// implicit termination at the end of the input. Stop on first error, discarding the rest + /// of the input. Errors and warnings are collected apart from any exception arising from execution + /// which is returned via a Choice. Parsing is performed on the current thread, and execution is performed + /// synchronously on the 'main' thread. + /// + /// Due to a current limitation, it is not fully thread-safe to run this operation concurrently with evaluation triggered + /// by input from 'stdin'. + /// The scriptFileName parameter is used to report errors including this file name. + member EvalExpressionNonThrowing: + code: string * scriptFileName: string -> Choice * FSharpDiagnostic[] + /// Format a value to a string using the current PrintDepth, PrintLength etc settings provided by the active fsi configuration object member FormatValue: reflectionValue: obj * reflectionType: Type -> string diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index a0c59428d2d..0acb1c5e189 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -4187,6 +4187,7 @@ FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Control FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[System.Tuple`3[System.Object,System.Type,System.String]],System.Tuple`3[System.Object,System.Type,System.String]] get_ValueBound() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiBoundValue] TryFindBoundValue(System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue] EvalExpression(System.String) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue] EvalExpression(System.String, System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] LCID FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] get_LCID() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Collections.Generic.IEnumerable`1[System.String] GetCompletions(System.String) @@ -4194,11 +4195,14 @@ FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assemb FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assembly[] get_DynamicAssemblies() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.String FormatValue(System.Object, System.Type) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalExpressionNonThrowing(System.String) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalExpressionNonThrowing(System.String, System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalInteractionNonThrowing(System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Threading.CancellationToken]) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalInteractionNonThrowing(System.String, System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Threading.CancellationToken]) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.Unit,System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalScriptNonThrowing(System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`3[FSharp.Compiler.CodeAnalysis.FSharpParseFileResults,FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults,FSharp.Compiler.CodeAnalysis.FSharpCheckProjectResults] ParseAndCheckInteraction(System.String) 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 EvalInteraction(System.String, 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 Interrupt() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void ReportUnhandledException(System.Exception) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 55bf9244652..b40009eacd4 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -4186,6 +4186,7 @@ FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Control FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[System.Tuple`3[System.Object,System.Type,System.String]],System.Tuple`3[System.Object,System.Type,System.String]] get_ValueBound() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiBoundValue] TryFindBoundValue(System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue] EvalExpression(System.String) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue] EvalExpression(System.String, System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] LCID FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] get_LCID() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Collections.Generic.IEnumerable`1[System.String] GetCompletions(System.String) @@ -4193,11 +4194,14 @@ FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assemb FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assembly[] get_DynamicAssemblies() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.String FormatValue(System.Object, System.Type) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalExpressionNonThrowing(System.String) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalExpressionNonThrowing(System.String, System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalInteractionNonThrowing(System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Threading.CancellationToken]) +FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Interactive.Shell+FsiValue],System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalInteractionNonThrowing(System.String, System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Threading.CancellationToken]) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`2[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Core.Unit,System.Exception],FSharp.Compiler.Diagnostics.FSharpDiagnostic[]] EvalScriptNonThrowing(System.String) FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Tuple`3[FSharp.Compiler.CodeAnalysis.FSharpParseFileResults,FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults,FSharp.Compiler.CodeAnalysis.FSharpCheckProjectResults] ParseAndCheckInteraction(System.String) 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 EvalInteraction(System.String, 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 Interrupt() FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: Void ReportUnhandledException(System.Exception)