Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3628,38 +3628,52 @@ 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.
let ctok = AssumeCompilationThreadWithoutEvidence()

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.
Expand All @@ -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 "input.fsx" 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
Expand Down
44 changes: 44 additions & 0 deletions src/Compiler/Interactive/fsi.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -188,6 +198,18 @@ type FsiEvaluationSession =
member EvalInteractionNonThrowing:
code: string * ?cancellationToken: CancellationToken -> Choice<FsiValue option, exn> * 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<FsiValue option, exn> * 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.
Expand All @@ -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
Expand All @@ -223,6 +255,18 @@ type FsiEvaluationSession =
/// by input from 'stdin'.
member EvalExpressionNonThrowing: code: string -> Choice<FsiValue option, exn> * 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<FsiValue option, exn> * 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4203,18 +4203,22 @@ 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)
FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assembly[] DynamicAssemblies
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4203,18 +4203,22 @@ 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)
FSharp.Compiler.Interactive.Shell+FsiEvaluationSession: System.Reflection.Assembly[] DynamicAssemblies
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)
Expand Down