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

Commitae4e8e2

Browse files
authored
Fixed using on asyncMaybe; Added more ETW logging (#4878)
* Fixed Using for asyncMaybe; added more ETW event logs* Added more logs. Reverted invasive logging code for classification and completion* Reverted Using; Added logs to incrementalBuildersCache in getOrCreateBuilderAndKeepAlive* Added Logger.fs/fsi to Fsc-proto.fsproj
1 parentd4c8243 commitae4e8e2

File tree

12 files changed

+129
-49
lines changed

12 files changed

+129
-49
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5528,8 +5528,11 @@ let TypeCheckMultipleInputsFinish(results, tcState: TcState) =
55285528

55295529
letTypeCheckOneInputAndFinishEventually(checkForErrors,tcConfig:TcConfig,tcImports,tcGlobals,prefixPathOpt,tcSink,tcState,input)=
55305530
eventually{
5531+
Logger.LogBlockStart LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
55315532
let!results,tcState= TypeCheckOneInputEventually(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input)
5532-
return TypeCheckMultipleInputsFinish([results], tcState)
5533+
letresult= TypeCheckMultipleInputsFinish([results], tcState)
5534+
Logger.LogBlockStop LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
5535+
return result
55335536
}
55345537

55355538
letTypeCheckClosedInputSetFinish(declaredImpls:TypedImplFile list,tcState)=

‎src/fsharp/Fsc-proto/Fsc-proto.fsproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<OtherFlags>--module Microsoft.FSharp.Compiler.AbstractIL.Internal.AsciiParser --open Microsoft.FSharp.Compiler.AbstractIL --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing</OtherFlags>
5050
<Link>ilpars.fsy</Link>
5151
</FsYacc>
52+
<CompileInclude="..\Logger.fsi">
53+
<Link>Logger.fsi</Link>
54+
</Compile>
55+
<CompileInclude="..\Logger.fs">
56+
<Link>Logger.fs</Link>
57+
</Compile>
5258
<CompileInclude="..\..\utils\reshapedreflection.fs">
5359
<Link>Reflection\reshapedreflection.fs</Link>
5460
</Compile>

‎src/fsharp/Logger.fs‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ open System.Diagnostics.Tracing
66
openSystem
77

88
typeLogCompilerFunctionId=
9-
| ParseAndCheckFileInProject=1
9+
| Service_ParseAndCheckFileInProject=1
10+
| Service_CheckOneFile=2
11+
| Service_IncrementalBuildersCache_BuildingNewCache=3
12+
| Service_IncrementalBuildersCache_GettingCache=4
13+
| CompileOps_TypeCheckOneInputAndFinishEventually=5
1014

1115
/// This is for ETW tracing across FSharp.Compiler.
1216
[<Sealed;EventSource(Name="FSharpCompiler")>]
@@ -21,34 +25,52 @@ type FSharpCompilerEventSource() =
2125
if this.IsEnabled()then
2226
this.WriteEvent(1, int functionId)
2327

28+
2429
[<Event(2)>]
25-
memberthis.BlockStart(functionId:LogCompilerFunctionId)=
30+
memberthis.LogMessage(message:string,functionId:LogCompilerFunctionId)=
2631
if this.IsEnabled()then
27-
this.WriteEvent(2, int functionId)
32+
this.WriteEvent(2,message,int functionId)
2833

2934
[<Event(3)>]
30-
memberthis.BlockStop(functionId:LogCompilerFunctionId)=
35+
memberthis.BlockStart(functionId:LogCompilerFunctionId)=
3136
if this.IsEnabled()then
3237
this.WriteEvent(3, int functionId)
3338

3439
[<Event(4)>]
35-
memberthis.BlockMessageStart(message:string,functionId:LogCompilerFunctionId)=
40+
memberthis.BlockStop(functionId:LogCompilerFunctionId)=
3641
if this.IsEnabled()then
37-
this.WriteEvent(4,message,int functionId)
42+
this.WriteEvent(4, int functionId)
3843

3944
[<Event(5)>]
40-
memberthis.BlockMessageStop(message:string,functionId:LogCompilerFunctionId)=
45+
memberthis.BlockMessageStart(message:string,functionId:LogCompilerFunctionId)=
4146
if this.IsEnabled()then
4247
this.WriteEvent(5, message, int functionId)
4348

49+
[<Event(6)>]
50+
memberthis.BlockMessageStop(message:string,functionId:LogCompilerFunctionId)=
51+
if this.IsEnabled()then
52+
this.WriteEvent(6, message, int functionId)
53+
4454
[<RequireQualifiedAccess>]
4555
moduleLogger=
4656

47-
letLog(functionId)= FSharpCompilerEventSource.Instance.Log(functionId)
57+
letLog(functionId)=
58+
FSharpCompilerEventSource.Instance.Log(functionId)
59+
60+
letLogMessage message functionId=
61+
FSharpCompilerEventSource.Instance.LogMessage(message, functionId)
4862

49-
letLogBlockStart(functionId)= FSharpCompilerEventSource.Instance.BlockStart(functionId)
63+
letLogBlockStart(functionId)=
64+
FSharpCompilerEventSource.Instance.BlockStart(functionId)
65+
66+
letLogBlockStop(functionId)=
67+
FSharpCompilerEventSource.Instance.BlockStop(functionId)
68+
69+
letLogBlockMessageStart message functionId=
70+
FSharpCompilerEventSource.Instance.BlockMessageStart(message, functionId)
5071

51-
letLogBlockStop(functionId)= FSharpCompilerEventSource.Instance.BlockStop(functionId)
72+
letLogBlockMessageStop message functionId=
73+
FSharpCompilerEventSource.Instance.BlockMessageStop(message, functionId)
5274

5375
letLogBlock(functionId)=
5476
FSharpCompilerEventSource.Instance.BlockStart(functionId)

‎src/fsharp/Logger.fsi‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ open System
77
// FIXME: We cannot make this internal yet until F# gets a compiler switch to make cases public when the type itself is internal.
88
// https://github.com/Microsoft/visualfsharp/issues/4821
99
type(* internal*)LogCompilerFunctionId=
10-
| ParseAndCheckFileInProject=1
10+
| Service_ParseAndCheckFileInProject=1
11+
| Service_CheckOneFile=2
12+
| Service_IncrementalBuildersCache_BuildingNewCache=3
13+
| Service_IncrementalBuildersCache_GettingCache=4
14+
| CompileOps_TypeCheckOneInputAndFinishEventually=5
1115

1216
[<RequireQualifiedAccess>]
1317
moduleinternalLogger=
1418

1519
valLog:LogCompilerFunctionId->unit
1620

21+
valLogMessage:message:string->LogCompilerFunctionId->unit
22+
1723
valLogBlockStart:LogCompilerFunctionId->unit
1824

1925
valLogBlockStop:LogCompilerFunctionId->unit
2026

27+
valLogBlockMessageStart:message:string->LogCompilerFunctionId->unit
28+
29+
valLogBlockMessageStop:message:string->LogCompilerFunctionId->unit
30+
2131
valLogBlock:LogCompilerFunctionId->IDisposable
2232

2333
valLogBlockMessage:message:string->LogCompilerFunctionId->IDisposable

‎src/fsharp/service/service.fs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,8 @@ module internal Parser =
16111611
userOpName:string)=
16121612

16131613
async{
1614+
use _logBlock= Logger.LogBlockMessage(Guid.NewGuid().ToString()) LogCompilerFunctionId.Service_CheckOneFile
1615+
16141616
match parseResults.ParseTreewith
16151617
// When processing the following cases, we don't need to type-check
16161618
| None->return[||], TypeCheckAborted.Yes
@@ -2396,9 +2398,11 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
23962398
RequireCompilationThread ctok
23972399
match incrementalBuildersCache.TryGet(ctok, options)with
23982400
| Some(builderOpt,creationErrors,_)->
2401+
Logger.Log LogCompilerFunctionId.Service_IncrementalBuildersCache_BuildingNewCache
23992402
letdecrement= IncrementalBuilder.KeepBuilderAlive builderOpt
24002403
return builderOpt,creationErrors, decrement
24012404
| None->
2405+
Logger.Log LogCompilerFunctionId.Service_IncrementalBuildersCache_GettingCache
24022406
let!(builderOpt,creationErrors,_)as info= CreateOneIncrementalBuilder(ctok, options, userOpName)
24032407
incrementalBuildersCache.Set(ctok, options, info)
24042408
letdecrement= IncrementalBuilder.KeepBuilderAlive builderOpt
@@ -2656,24 +2660,31 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
26562660
letexecWithReactorAsync action= reactor.EnqueueAndAwaitOpAsync(userOpName,"ParseAndCheckFileInProject", filename, action)
26572661
async{
26582662
try
2659-
use _logBlock= Logger.LogBlockMessage filename LogCompilerFunctionId.ParseAndCheckFileInProject
2663+
letstrGuid="_"+ Guid.NewGuid().ToString()
2664+
Logger.LogBlockMessageStart(filename+ strGuid) LogCompilerFunctionId.Service_ParseAndCheckFileInProject
26602665

26612666
if implicitlyStartBackgroundWorkthen
2667+
Logger.LogMessage(filename+ strGuid+"-Cancelling background work") LogCompilerFunctionId.Service_ParseAndCheckFileInProject
26622668
reactor.CancelBackgroundOp()// cancel the background work, since we will start new work after we're done
2669+
26632670
let!builderOpt,creationErrors,decrement= execWithReactorAsync(fun ctok-> getOrCreateBuilderAndKeepAlive(ctok, options, userOpName))
26642671
use _unwind= decrement
26652672
match builderOptwith
26662673
| None->
2674+
Logger.LogBlockMessageStop(filename+ strGuid+"-Failed_Aborted") LogCompilerFunctionId.Service_ParseAndCheckFileInProject
2675+
26672676
letparseResults= FSharpParseFileResults(creationErrors, None,true,[||])
26682677
return(parseResults, FSharpCheckFileAnswer.Aborted)
26692678

26702679
| Some builder->
26712680
letcachedResults= bc.GetCachedCheckFileResult(builder, filename, source, options)
26722681

26732682
match cachedResultswith
2674-
| Some(parseResults, checkResults)->return parseResults, FSharpCheckFileAnswer.Succeeded checkResults
2683+
| Some(parseResults, checkResults)->
2684+
Logger.LogBlockMessageStop(filename+ strGuid+"-Successful_Cached") LogCompilerFunctionId.Service_ParseAndCheckFileInProject
2685+
2686+
return parseResults, FSharpCheckFileAnswer.Succeeded checkResults
26752687
|_->
2676-
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName,"ParseAndCheckFileInProject.CacheMiss", filename)
26772688
// todo this blocks the Reactor queue until all files up to the current are type checked. It's OK while editing the file,
26782689
// but results with non cooperative blocking when a firts file from a project opened.
26792690
let!tcPrior= execWithReactorAsync<|fun ctok-> builder.GetCheckResultsBeforeFileInProject(ctok, filename)
@@ -2684,6 +2695,9 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
26842695
letparseTreeOpt= parseTreeOpt|> Option.map builder.DeduplicateParsedInputModuleNameInProject
26852696
letparseResults= FSharpParseFileResults(parseErrors, parseTreeOpt, anyErrors, builder.AllDependenciesDeprecated)
26862697
let!checkResults= bc.CheckOneFileImpl(parseResults, source, filename, options, textSnapshotInfo, fileVersion, builder, tcPrior, creationErrors, userOpName)
2698+
2699+
Logger.LogBlockMessageStop(filename+ strGuid+"-Successful") LogCompilerFunctionId.Service_ParseAndCheckFileInProject
2700+
26872701
return parseResults, checkResults
26882702
finally
26892703
bc.ImplicitlyStartCheckProjectInBackground(options, userOpName)

‎vsintegration/src/FSharp.Editor/Classification/ClassificationService.fs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type internal FSharpClassificationService
3434

3535
member__.AddSyntacticClassificationsAsync(document:Document,textSpan:TextSpan,result:List<ClassifiedSpan>,cancellationToken:CancellationToken)=
3636
async{
37-
use _logBlock= Logger.LogBlock(LogEditorFunctionId.SyntacticClassification)
37+
use _logBlock= Logger.LogBlock(LogEditorFunctionId.Classification_Syntactic)
3838

3939
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
4040
let!sourceText= document.GetTextAsync(cancellationToken)|> Async.AwaitTask
@@ -43,9 +43,8 @@ type internal FSharpClassificationService
4343

4444
member__.AddSemanticClassificationsAsync(document:Document,textSpan:TextSpan,result:List<ClassifiedSpan>,cancellationToken:CancellationToken)=
4545
asyncMaybe{
46-
use _logBlock= Logger.LogBlock(LogEditorFunctionId.SemanticClassification)
46+
use _logBlock= Logger.LogBlock(LogEditorFunctionId.Classification_Semantic)
4747

48-
do! Async.Sleep DefaultTuning.SemanticClassificationInitialDelay|> liftAsync// be less intrusive, give other work priority most of the time
4948
let!_,_,projectOptions= projectInfoManager.TryGetOptionsForDocumentOrProject(document)
5049
let!sourceText= document.GetTextAsync(cancellationToken)
5150
let!_,_,checkResults= checkerProvider.Checker.ParseAndCheckDocument(document, projectOptions, sourceText= sourceText, allowStaleResults=false, userOpName=userOpName)
@@ -66,4 +65,3 @@ type internal FSharpClassificationService
6665
member__.AdjustStaleClassification(_:SourceText,classifiedSpan:ClassifiedSpan):ClassifiedSpan= classifiedSpan
6766

6867

69-

‎vsintegration/src/FSharp.Editor/Common/Logger.fs‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ open System
66
openSystem.Diagnostics.Tracing
77

88
typeLogEditorFunctionId=
9-
| SemanticClassification=1
10-
| SyntacticClassification=2
11-
| HandleCommandLineArgs=3
12-
| Completion_ShouldTrigger=4
13-
| Completion_ProvideCompletionsAsync=5
14-
| Completion_GetDescriptionAsync=6
15-
| Completion_GetChangeAsync=7
9+
| Classification_Semantic=1
10+
| Classification_Syntactic=2
11+
| LanguageService_HandleCommandLineArgs=3
12+
| LanguageService_UpdateProjectInfo=4
13+
| Completion_ShouldTrigger=5
14+
| Completion_ProvideCompletionsAsync=6
15+
| Completion_GetDescriptionAsync=7
16+
| Completion_GetChangeAsync=9
1617

1718
/// This is for ETW tracing across FSharp.Editor.
1819
[<Sealed;EventSource(Name="FSharpEditor")>]
@@ -28,33 +29,50 @@ type FSharpEditorEventSource() =
2829
this.WriteEvent(1, int functionId)
2930

3031
[<Event(2)>]
31-
memberthis.BlockStart(functionId:LogEditorFunctionId)=
32+
memberthis.LogMessage(message:string,functionId:LogEditorFunctionId)=
3233
if this.IsEnabled()then
33-
this.WriteEvent(2, int functionId)
34+
this.WriteEvent(2,message,int functionId)
3435

3536
[<Event(3)>]
36-
memberthis.BlockStop(functionId:LogEditorFunctionId)=
37+
memberthis.BlockStart(functionId:LogEditorFunctionId)=
3738
if this.IsEnabled()then
3839
this.WriteEvent(3, int functionId)
3940

4041
[<Event(4)>]
41-
memberthis.BlockMessageStart(message:string,functionId:LogEditorFunctionId)=
42+
memberthis.BlockStop(functionId:LogEditorFunctionId)=
4243
if this.IsEnabled()then
43-
this.WriteEvent(4,message,int functionId)
44+
this.WriteEvent(4, int functionId)
4445

4546
[<Event(5)>]
46-
memberthis.BlockMessageStop(message:string,functionId:LogEditorFunctionId)=
47+
memberthis.BlockMessageStart(message:string,functionId:LogEditorFunctionId)=
4748
if this.IsEnabled()then
4849
this.WriteEvent(5, message, int functionId)
4950

51+
[<Event(6)>]
52+
memberthis.BlockMessageStop(message:string,functionId:LogEditorFunctionId)=
53+
if this.IsEnabled()then
54+
this.WriteEvent(6, message, int functionId)
55+
5056
[<RequireQualifiedAccess>]
5157
moduleLogger=
5258

53-
letLog(functionId)= FSharpEditorEventSource.Instance.Log(functionId)
59+
letLog(functionId)=
60+
FSharpEditorEventSource.Instance.Log(functionId)
5461

55-
letLogBlockStart(functionId)= FSharpEditorEventSource.Instance.BlockStart(functionId)
62+
letLogMessage message functionId=
63+
FSharpEditorEventSource.Instance.LogMessage(message, functionId)
64+
65+
letLogBlockStart(functionId)=
66+
FSharpEditorEventSource.Instance.BlockStart(functionId)
67+
68+
letLogBlockStop(functionId)=
69+
FSharpEditorEventSource.Instance.BlockStop(functionId)
70+
71+
letLogBlockMessageStart message functionId=
72+
FSharpEditorEventSource.Instance.BlockMessageStart(message, functionId)
5673

57-
letLogBlockStop(functionId)= FSharpEditorEventSource.Instance.BlockStop(functionId)
74+
letLogBlockMessageStop message functionId=
75+
FSharpEditorEventSource.Instance.BlockMessageStop(message, functionId)
5876

5977
letLogBlock(functionId)=
6078
FSharpEditorEventSource.Instance.BlockStart(functionId)

‎vsintegration/src/FSharp.Editor/Common/Logger.fsi‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@ open System
77
// FIXME: We cannot make this internal yet until F# gets a compiler switch to make cases public when the type itself is internal.
88
// https://github.com/Microsoft/visualfsharp/issues/4821
99
type(* internal*)LogEditorFunctionId=
10-
| SemanticClassification=1
11-
| SyntacticClassification=2
12-
| HandleCommandLineArgs=3
13-
| Completion_ShouldTrigger=4
14-
| Completion_ProvideCompletionsAsync=5
15-
| Completion_GetDescriptionAsync=6
16-
| Completion_GetChangeAsync=7
10+
| Classification_Semantic=1
11+
| Classification_Syntactic=2
12+
| LanguageService_HandleCommandLineArgs=3
13+
| LanguageService_UpdateProjectInfo=4
14+
| Completion_ShouldTrigger=5
15+
| Completion_ProvideCompletionsAsync=6
16+
| Completion_GetDescriptionAsync=7
17+
| Completion_GetChangeAsync=9
1718

1819
[<RequireQualifiedAccess>]
1920
moduleinternalLogger=
2021

2122
valLog:LogEditorFunctionId->unit
2223

24+
valLogMessage:message:string->LogEditorFunctionId->unit
25+
2326
valLogBlockStart:LogEditorFunctionId->unit
2427

2528
valLogBlockStop:LogEditorFunctionId->unit
2629

30+
valLogBlockMessageStart:message:string->LogEditorFunctionId->unit
31+
32+
valLogBlockMessageStop:message:string->LogEditorFunctionId->unit
33+
2734
valLogBlock:LogEditorFunctionId->IDisposable
2835

2936
valLogBlockMessage:message:string->LogEditorFunctionId->IDisposable

‎vsintegration/src/FSharp.Editor/Common/Pervasive.fs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ type AsyncMaybeBuilder () =
143143
}
144144

145145
[<DebuggerStepThrough>]
146-
member__.Using(resource:('T:> IDisposable),body:_->Async<_option>):Async<_option>=
147-
try body resource
148-
finallyifnot(isNull resource)then resource.Dispose()
146+
member__.Using(resource:('T:> IDisposable),body:'T->Async<'Uoption>):Async<'Uoption>=
147+
async{
148+
use resource= resource
149+
return! body resource
150+
}
149151

150152
[<DebuggerStepThrough>]
151153
memberx.While(guard,body:Async<_option>):Async<_option>=
@@ -155,7 +157,7 @@ type AsyncMaybeBuilder () =
155157
x.Zero()
156158

157159
[<DebuggerStepThrough>]
158-
memberx.For(sequence:seq<_>,body:'T->Async<unitoption>):Async<_option>=
160+
memberx.For(sequence:seq<_>,body:'T->Async<unitoption>):Async<unitoption>=
159161
x.Using(sequence.GetEnumerator(),fun enum->
160162
x.While(enum.MoveNext, x.Delay(fun()-> bodyenum.Current)))
161163

‎vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,4 @@ type internal FSharpCompletionProvider
305305
}
306306
|> Async.map(Option.defaultValue(CompletionChange.Create(TextChange(item.Span, nameInCode))))
307307

308-
}|> RoslynHelpers.StartAsyncAsTask cancellationToken
308+
}|> RoslynHelpers.StartAsyncAsTask cancellationToken

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp