Skip to content

Commit 9f2f852

Browse files
brettfobaronfel
authored andcommitted
Merge pull request #7702 from KevinRansom/cp_it
Cherry pick fix for eval not returning a value for multi-line submissions.
2 parents c3406e7 + 59c8dc8 commit 9f2f852

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/fsharp/fsi/fsi.fs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,44 +1139,50 @@ type internal FsiDynamicCompiler
11391139
let newState = { istate with tcState = tcState.NextStateAfterIncrementalFragment(tcEnvAtEndOfLastInput) }
11401140

11411141
// Find all new declarations the EvaluationListener
1142+
let mutable itValue = None
11421143
try
11431144
let contents = FSharpAssemblyContents(tcGlobals, tcState.Ccu, Some tcState.CcuSig, tcImports, declaredImpls)
11441145
let contentFile = contents.ImplementationFiles.[0]
1146+
11451147
// Skip the "FSI_NNNN"
1146-
match contentFile.Declarations with
1147-
| [FSharpImplementationFileDeclaration.Entity (_eFakeModule,modDecls) ] ->
1148+
match contentFile.Declarations with
1149+
| [FSharpImplementationFileDeclaration.Entity (_eFakeModule,modDecls) ] ->
11481150
let cenv = SymbolEnv(newState.tcGlobals, newState.tcState.Ccu, Some newState.tcState.CcuSig, newState.tcImports)
1149-
for decl in modDecls do
1150-
match decl with
1151+
for decl in modDecls do
1152+
match decl with
11511153
| FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (v,_,_) ->
11521154
// Report a top-level function or value definition
1153-
if v.IsModuleValueOrMember && not v.IsMember then
1154-
let fsiValueOpt =
1155-
match v.Item with
1156-
| Item.Value vref ->
1157-
let optValue = newState.ilxGenerator.LookupGeneratedValue(valuePrinter.GetEvaluationContext(newState.emEnv), vref.Deref)
1158-
match optValue with
1159-
| Some (res, ty) -> Some(FsiValue(res, ty, FSharpType(cenv, vref.Type)))
1160-
| None -> None
1161-
| _ -> None
1162-
1163-
let symbol = FSharpSymbol.Create(cenv, v.Item)
1164-
let symbolUse = FSharpSymbolUse(tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, v.DeclarationLocation)
1165-
fsi.TriggerEvaluation (fsiValueOpt, symbolUse, decl)
1155+
if v.IsModuleValueOrMember && not v.IsMember then
1156+
let fsiValueOpt =
1157+
match v.Item with
1158+
| Item.Value vref ->
1159+
let optValue = newState.ilxGenerator.LookupGeneratedValue(valuePrinter.GetEvaluationContext(newState.emEnv), vref.Deref)
1160+
match optValue with
1161+
| Some (res, ty) -> Some(FsiValue(res, ty, FSharpType(cenv, vref.Type)))
1162+
| None -> None
1163+
| _ -> None
1164+
1165+
if v.CompiledName = "it" then
1166+
itValue <- fsiValueOpt
1167+
1168+
let symbol = FSharpSymbol.Create(cenv, v.Item)
1169+
let symbolUse = FSharpSymbolUse(tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, v.DeclarationLocation)
1170+
fsi.TriggerEvaluation (fsiValueOpt, symbolUse, decl)
1171+
11661172
| FSharpImplementationFileDeclaration.Entity (e,_) ->
11671173
// Report a top-level module or namespace definition
11681174
let symbol = FSharpSymbol.Create(cenv, e.Item)
11691175
let symbolUse = FSharpSymbolUse(tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, e.DeclarationLocation)
11701176
fsi.TriggerEvaluation (None, symbolUse, decl)
1177+
11711178
| FSharpImplementationFileDeclaration.InitAction _ ->
11721179
// Top level 'do' bindings are not reported as incremental declarations
11731180
()
11741181
| _ -> ()
11751182
with _ -> ()
11761183

1177-
newState
1178-
1179-
1184+
newState, Completed itValue
1185+
11801186
/// Evaluate the given expression and produce a new interactive state.
11811187
member fsiDynamicCompiler.EvalParsedExpression (ctok, errorLogger: ErrorLogger, istate, expr: SynExpr) =
11821188
let tcConfig = TcConfig.Create (tcConfigB, validate=false)
@@ -1186,13 +1192,13 @@ type internal FsiDynamicCompiler
11861192
let defs = fsiDynamicCompiler.BuildItBinding expr
11871193

11881194
// Evaluate the overall definitions.
1189-
let istate = fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, false, true, defs)
1195+
let istate = fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, false, true, defs) |> fst
11901196
// Snarf the type for 'it' via the binding
11911197
match istate.tcState.TcEnvFromImpls.NameEnv.FindUnqualifiedItem itName with
11921198
| NameResolution.Item.Value vref ->
11931199
if not tcConfig.noFeedback then
11941200
valuePrinter.InvokeExprPrinter (istate.tcState.TcEnvFromImpls.DisplayEnv, istate.emEnv, istate.ilxGenerator, vref.Deref)
1195-
1201+
11961202
/// Clear the value held in the previous "it" binding, if any, as long as it has never been referenced.
11971203
match prevIt with
11981204
| Some prevVal when not prevVal.Deref.HasBeenReferenced ->
@@ -1787,7 +1793,7 @@ type internal FsiInteractionProcessor
17871793
| IDefns ([ SynModuleDecl.DoExpr(_,expr,_)],_) ->
17881794
fsiDynamicCompiler.EvalParsedExpression(ctok, errorLogger, istate, expr)
17891795
| IDefns (defs,_) ->
1790-
fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, true, false, defs),Completed None
1796+
fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, true, false, defs)
17911797

17921798
| IHash (ParsedHashDirective("load",sourceFiles,m),_) ->
17931799
fsiDynamicCompiler.EvalSourceFiles (ctok, istate, m, sourceFiles, lexResourceManager, errorLogger),Completed None
@@ -2085,7 +2091,7 @@ type internal FsiInteractionProcessor
20852091
/// Send a dummy interaction through F# Interactive, to ensure all the most common code generation paths are
20862092
/// JIT'ed and ready for use.
20872093
member __.LoadDummyInteraction(ctok, errorLogger) =
2088-
setCurrState (currState |> InteractiveCatch errorLogger (fun istate -> fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, true, false, []), Completed None) |> fst)
2094+
setCurrState (currState |> InteractiveCatch errorLogger (fun istate -> fsiDynamicCompiler.EvalParsedDefinitions (ctok, errorLogger, istate, true, false, []) |> fst, Completed None) |> fst)
20892095

20902096
member __.EvalInteraction(ctok, sourceText, scriptFileName, errorLogger) =
20912097
use _unwind1 = ErrorLogger.PushThreadBuildPhaseUntilUnwind(ErrorLogger.BuildPhase.Interactive)

0 commit comments

Comments
 (0)