Skip to content

Commit

Permalink
Report additional inferred types
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Jan 30, 2024
1 parent 59e3faa commit 336595d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3415,6 +3415,7 @@ let TcSequenceExpressionEntry (cenv: cenv) env (overallTy: OverallTy) tpenv (has
| _ -> ()

if not hasBuilder && not cenv.g.compilingFSharpCore then
CallExprHasTypeSink cenv.tcSink (m, env.NameEnv, overallTy.Commit, env.eAccessRights)
error (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m))

TcSequenceExpression cenv env tpenv comp overallTy m
Expand Down
7 changes: 6 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ let MakeAndPublishSimpleValsForMergedScope (cenv: cenv) env m (names: NameMap<_>
notifyNameResolution (pos, item, itemGroup, itemTyparInst, occurence, nenv, ad, m, replacing)

member _.NotifyExprHasType(_, _, _, _) = assert false // no expr typings in MakeAndPublishSimpleVals
member _.NotifyExprHasTypeSynthetic(_, _, _, _) = assert false // no expr typings in MakeAndPublishSimpleVals

member _.NotifyFormatSpecifierLocation(_, _) = ()

Expand Down Expand Up @@ -5609,7 +5610,8 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE
let pushedExpr = pushUnaryArg synExpr unaryArg
let lambda = SynExpr.Lambda(false, false, SynSimplePats.SimplePats([ svar ],[], svar.Range), pushedExpr, None, m, SynExprLambdaTrivia.Zero)
TcIteratedLambdas cenv true env overallTy Set.empty tpenv lambda
| SynExpr.Lambda _ ->
| SynExpr.Lambda(range = m) ->
CallExprHasTypeSinkSynthetic cenv.tcSink (m, env.NameEnv, overallTy.Commit, env.AccessRights)
TcIteratedLambdas cenv true env overallTy Set.empty tpenv synExpr

| SynExpr.Match (spMatch, synInputExpr, synClauses, _m, _trivia) ->
Expand Down Expand Up @@ -7445,6 +7447,7 @@ and TcAssertExpr cenv overallTy env (m: range) tpenv x =
TcExpr cenv overallTy env tpenv callDiagnosticsExpr

and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, mWholeExpr) =
CallExprHasTypeSink cenv.tcSink (mWholeExpr, env.NameEnv, overallTy, env.eAccessRights)
let g = cenv.g

let requiresCtor = (GetCtorShapeCounter env = 1) // Get special expression forms for constructors
Expand Down Expand Up @@ -8060,6 +8063,8 @@ and TcDelayed cenv (overallTy: OverallTy) env tpenv mExpr expr exprTy (atomicFla
// We can now record for posterity the type of this expression and the location of the expression.
if (atomicFlag = ExprAtomicFlag.Atomic) then
CallExprHasTypeSink cenv.tcSink (mExpr, env.NameEnv, exprTy, env.eAccessRights)
else
CallExprHasTypeSinkSynthetic cenv.tcSink (mExpr, env.NameEnv, exprTy, env.eAccessRights)

match delayed with
| []
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ and TcSimplePat optionalArgsOK checkConstraints (cenv: cenv) ty env patEnv p =

| SynSimplePat.Typed (p, cty, m) ->
let ctyR, tpenv = TcTypeAndRecover cenv NewTyparsOK checkConstraints ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv cty
CallExprHasTypeSinkSynthetic cenv.tcSink (p.Range, env.NameEnv, ctyR, env.AccessRights)

match p with
// Optional arguments on members
Expand Down Expand Up @@ -248,6 +249,7 @@ and TcPat warnOnUpper (cenv: cenv) env valReprInfo vFlags (patEnv: TcPatLinearEn
TcConstPat warnOnUpper cenv env vFlags patEnv ty synConst m

| SynPat.Wild m ->
CallExprHasTypeSinkSynthetic cenv.tcSink (m, env.NameEnv, ty, env.AccessRights)
(fun _ -> TPat_wild m), patEnv

| SynPat.IsInst (synTargetTy, m)
Expand Down Expand Up @@ -599,6 +601,7 @@ and TcPatLongIdentUnionCaseOrExnCase warnOnUpper cenv env ad vFlags patEnv ty (m

// Report information about the case occurrence to IDE
CallNameResolutionSink cenv.tcSink (mLongId, env.NameEnv, item, emptyTyparInst, ItemOccurence.Pattern, env.eAccessRights)
CallExprHasTypeSinkSynthetic cenv.tcSink (m, env.NameEnv, ty, env.AccessRights)

let mkf, argTys, argNames = ApplyUnionCaseOrExn m cenv env ty item
let numArgTys = argTys.Length
Expand Down
12 changes: 12 additions & 0 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,8 @@ type ITypecheckResultsSink =

abstract NotifyExprHasType: TType * NameResolutionEnv * AccessorDomain * range -> unit

abstract NotifyExprHasTypeSynthetic: TType * NameResolutionEnv * AccessorDomain * range -> unit

abstract NotifyNameResolution: pos * item: Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit

abstract NotifyMethodGroupNameResolution : pos * item: Item * itemMethodGroup: Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit
Expand Down Expand Up @@ -2203,6 +2205,11 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) =
if allowedRange m then
capturedExprTypings.Add((ty, nenv, ad, m))

member sink.NotifyExprHasTypeSynthetic(ty, nenv, ad, m) =
if allowedRange m then
capturedExprTypings.Add((ty, nenv, ad, m.MakeSynthetic()))


member sink.NotifyNameResolution(endPos, item, tpinst, occurenceType, nenv, ad, m, replace) =
if allowedRange m then
if replace then
Expand Down Expand Up @@ -2278,6 +2285,11 @@ let CallExprHasTypeSink (sink: TcResultsSink) (m: range, nenv, ty, ad) =
| None -> ()
| Some sink -> sink.NotifyExprHasType(ty, nenv, ad, m)

let CallExprHasTypeSinkSynthetic (sink: TcResultsSink) (m: range, nenv, ty, ad) =
match sink.CurrentSink with
| None -> ()
| Some sink -> sink.NotifyExprHasTypeSynthetic(ty, nenv, ad, m)

let CallOpenDeclarationSink (sink: TcResultsSink) (openDeclaration: OpenDeclaration) =
match sink.CurrentSink with
| None -> ()
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ type ITypecheckResultsSink =
/// Record that an expression has a specific type at the given range.
abstract NotifyExprHasType: TType * NameResolutionEnv * AccessorDomain * range -> unit

abstract NotifyExprHasTypeSynthetic: TType * NameResolutionEnv * AccessorDomain * range -> unit

/// Record that a name resolution occurred at a specific location in the source
abstract NotifyNameResolution:
pos * Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * bool -> unit
Expand Down Expand Up @@ -628,6 +630,9 @@ val internal CallNameResolutionSinkReplacing:
/// Report a specific name resolution at a source range
val internal CallExprHasTypeSink: TcResultsSink -> range * NameResolutionEnv * TType * AccessorDomain -> unit

/// Report type at range, but don't use it in features like code completion, only in TryGetExpressionType
val internal CallExprHasTypeSinkSynthetic: TcResultsSink -> range * NameResolutionEnv * TType * AccessorDomain -> unit

/// Report an open declaration
val internal CallOpenDeclarationSink: TcResultsSink -> OpenDeclaration -> unit

Expand Down
6 changes: 4 additions & 2 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ type internal TypeCheckInfo
let quals =
sResolutions.CapturedExpressionTypings
|> Seq.filter (fun (ty, nenv, _, m) ->
not m.IsSynthetic &&

// We only want expression types that end at the particular position in the file we are looking at.
posEq m.End endOfExprPos
&&
Expand Down Expand Up @@ -1702,9 +1704,9 @@ type internal TypeCheckInfo
member scope.IsRelativeNameResolvableFromSymbol(cursorPos: pos, plid: string list, symbol: FSharpSymbol) : bool =
scope.IsRelativeNameResolvable(cursorPos, plid, symbol.Item)

member scope.TryGetExpressionType(range) =
member scope.TryGetExpressionType(range: range) =
sResolutions.CapturedExpressionTypings
|> Seq.tryFindBack (fun (_, _, _, m) -> equals m range)
|> Seq.tryFindBack (fun (_, _, _, m) -> equals (m.MakeSynthetic()) (range.MakeSynthetic()))
|> Option.map (fun (ty, _, _, _) -> FSharpType (cenv, ty))

member scope.GetExpressionDisplayContext(range) =
Expand Down

0 comments on commit 336595d

Please sign in to comment.