Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba6dff8

Browse files
dsymeKevinRansom
authored andcommitted
Further protection for GetDeclarations against internal errors (#3386)
* better error protection for language service* protect against ICEs
1 parentaaaa08d commitba6dff8

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

‎src/fsharp/symbols/SymbolHelpers.fs‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ type FSharpErrorInfo(fileName, s:pos, e:pos, severity: FSharpErrorSeverity, mess
8787
[<Sealed>]
8888
typeErrorScope()=
8989
let mutableerrors=[]
90-
staticlet mutablemostRecentError= None
90+
let mutablefirstError= None
9191
letunwindBP= PushThreadBuildPhaseUntilUnwind BuildPhase.TypeCheck
9292
letunwindEL=
9393
PushErrorLoggerPhaseUntilUnwind(fun _oldLogger->
9494
{new ErrorLogger("ErrorScope")with
9595
member x.DiagnosticSink(exn, isError)=
9696
leterr= FSharpErrorInfo.CreateFromException(exn,isError,false,range.Zero)
9797
errors<- err:: errors
98-
if isErrorthen
99-
mostRecentError<- Some err
98+
if isError&& firstError.IsNonethen
99+
firstError<- Some err.Message
100100
member x.ErrorCount= errors.Length})
101101

102102
memberx.Errors= errors|> List.filter(fun error-> error.Severity= FSharpErrorSeverity.Error)
@@ -112,16 +112,33 @@ type ErrorScope() =
112112
unwindEL.Dispose()(* unwind pushes when ErrorScope disposes*)
113113
unwindBP.Dispose()
114114

115-
staticmemberMostRecentError= mostRecentError
115+
memberx.FirstErrorwith get()= firstErrorandset v= firstError<- v
116116

117+
/// Used at entry points to FSharp.Compiler.Service (service.fsi) which manipulate symbols and
118+
/// perform other operations which might expose us to either bona-fide F# error messages such
119+
/// "missing assembly" (for incomplete assembly reference sets), or, if there is a compiler bug,
120+
/// may hit internal compiler failures.
121+
///
122+
/// In some calling cases, we get a chance to report the error as part of user text. For example
123+
/// if there is a "msising assembly" error while formatting the text of the description of an
124+
/// autocomplete, then the error message is shown in replacement of the text (rather than crashing Visual
125+
/// Studio, or swallowing the exception completely)
117126
static memberProtect<'a>(m:range)(f:unit->'a)(err:string->'a):'a=
118127
use errorScope=new ErrorScope()
119128
letres=
120129
try
121130
Some(f())
122-
with e-> errorRecovery e m; None
131+
with e->
132+
// Here we only call errorRecovery to save the error message for later use by TryGetFirstErrorText.
133+
try
134+
errorRecovery e m
135+
with_->
136+
// If error recovery fails, then we have an internal compiler error. In this case, we show the whole stack
137+
// in the extra message, should the extra message be used.
138+
errorScope.FirstError<- Some(e.ToString())
139+
None
123140
match reswith
124-
| Some res->res
141+
| Some res->res
125142
| None->
126143
match errorScope.TryGetFirstErrorText()with
127144
| Some text-> err text

‎src/fsharp/vs/service.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module EnvMisc =
8080
[<RequireQualifiedAccess>]
8181
typeFSharpFindDeclFailureReason=
8282
// generic reason: no particular information about error
83-
| Unknown
83+
| Unknownofmessage:string
8484
// source code file is not available
8585
| NoSourceCode
8686
// trying to find declaration of ProvidedType without TypeProviderDefinitionLocationAttribute
@@ -1102,7 +1102,7 @@ type TypeCheckInfo
11021102
(fun()->
11031103
match GetDeclItemsForNamesAtPosition(ctok, None,Some(names), None, line, lineStr, colAtEndOfNames, ResolveTypeNamesToCtors,ResolveOverloads.Yes,(fun()->[]),fun _->false)with
11041104
| None
1105-
| Some([],_,_,_)-> FSharpFindDeclResult.DeclNotFound FSharpFindDeclFailureReason.Unknown
1105+
| Some([],_,_,_)-> FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.Unknown"")
11061106
| Some(item::_,_,_,_)->
11071107

11081108
// For IL-based entities, switch to a different item. This is because
@@ -1131,7 +1131,7 @@ type TypeCheckInfo
11311131
|_-> FSharpFindDeclResult.DeclNotFound defaultReason
11321132

11331133
match rangeOfItem g preferFlag itemwith
1134-
| None-> fail FSharpFindDeclFailureReason.Unknown
1134+
| None-> fail(FSharpFindDeclFailureReason.Unknown"")
11351135
| Some itemRange->
11361136

11371137
letprojectDir= Filename.directoryName(if projectFileName=""then mainInputFileNameelse projectFileName)
@@ -1143,7 +1143,7 @@ type TypeCheckInfo
11431143
)
11441144
(fun msg->
11451145
Trace.TraceInformation(sprintf"FCS: recovering from error in GetDeclarationLocation: '%s'" msg)
1146-
FSharpFindDeclResult.DeclNotFound FSharpFindDeclFailureReason.Unknown)
1146+
FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.Unknown msg))
11471147

11481148
memberscope.GetSymbolUseAtLocation(ctok,line,lineStr,colAtEndOfNames,names)=
11491149
ErrorScope.Protect Range.range0
@@ -1852,7 +1852,7 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
18521852

18531853
memberinfo.GetDeclarationLocation(line,colAtEndOfNames,lineStr,names,?preferFlag,?userOpName:string)=
18541854
letuserOpName= defaultArg userOpName"Unknown"
1855-
letdflt= FSharpFindDeclResult.DeclNotFound FSharpFindDeclFailureReason.Unknown
1855+
letdflt= FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.Unknown"")
18561856
reactorOp userOpName"GetDeclarationLocation" dflt(fun ctok scope->
18571857
scope.GetDeclarationLocation(ctok, line, lineStr, colAtEndOfNames, names, preferFlag))
18581858

‎src/fsharp/vs/service.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ type FSharpFindDeclFailureReason =
3737
typeinternalFSharpFindDeclFailureReason=
3838
#endif
3939

40-
/// Generic reason: no particular information about error
41-
| Unknown
40+
/// Generic reason: no particular information about error apart from a message
41+
| Unknownofmessage:string
4242

4343
/// Source code file is not available
4444
| NoSourceCode

‎vsintegration/src/FSharp.LanguageService/GotoDefinition.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module internal GotoDefinition =
7373
Trace.Write("LanguageService", sprintf"Goto definition failed: Reason%+A" reason)
7474
lettext=
7575
match reasonwith
76-
| FSharpFindDeclFailureReason.Unknown-> Strings.Errors.GotoDefinitionFailed()
76+
| FSharpFindDeclFailureReason.Unknown_message-> Strings.Errors.GotoDefinitionFailed()
7777
| FSharpFindDeclFailureReason.NoSourceCode-> Strings.Errors.GotoDefinitionFailed_NoSourceCode()
7878
| FSharpFindDeclFailureReason.ProvidedType(typeName)-> Strings.Errors.GotoDefinitionFailed_ProvidedType(typeName)
7979
| FSharpFindDeclFailureReason.ProvidedMember(name)-> Strings.Errors.GotoFailed_ProvidedMember(name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp