Repository navigation
Generate DkmEvaluationResults asynchronously #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c2c57fd
6bdc906
026a477
43f3d15
4ea94cb
266f657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| using System; | ||
| using System.Collections.ObjectModel; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
| using Microsoft.CodeAnalysis.Collections; | ||
| using Microsoft.CodeAnalysis.ErrorReporting; | ||
| using Microsoft.VisualStudio.Debugger; | ||
|
|
@@ -43,10 +42,15 @@ internal ResultProvider(Formatter formatter) | |
| void IDkmClrResultProvider.GetResult(DkmClrValue value, DkmWorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, ReadOnlyCollection<string> formatSpecifiers, string resultName, string resultFullName, DkmCompletionRoutine<DkmEvaluationAsyncResult> completionRoutine) | ||
| { | ||
| // TODO: Use full name | ||
| GetRootResultAndContinue(value, workList, declaredType, inspectionContext, resultName, | ||
| result => ContinueWithExceptionHandling( | ||
| () => completionRoutine(new DkmEvaluationAsyncResult(result)), | ||
| e => completionRoutine(DkmEvaluationAsyncResult.CreateErrorResult(e)))); | ||
| var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationAsyncResult.CreateErrorResult(e))); | ||
| GetRootResultAndContinue( | ||
| value, | ||
| wl, | ||
| declaredType, | ||
| inspectionContext, | ||
| resultName, | ||
| result => wl.ContinueWith(_ => completionRoutine(new DkmEvaluationAsyncResult(result)))); | ||
| wl.Execute(); | ||
| } | ||
|
|
||
| DkmClrValue IDkmClrResultProvider.GetClrValue(DkmSuccessEvaluationResult evaluationResult) | ||
|
|
@@ -113,7 +117,7 @@ string IDkmClrResultProvider.GetUnderlyingString(DkmEvaluationResult result) | |
| } | ||
| } | ||
|
|
||
| private void CreateEvaluationResultAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| private void CreateEvaluationResultAndContinue(EvalResultDataItem dataItem, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| { | ||
| switch (dataItem.Kind) | ||
| { | ||
|
|
@@ -360,7 +364,7 @@ internal EvalResultDataItem CreateDataItem( | |
| inspectionContext: inspectionContext); | ||
| } | ||
|
|
||
| private void GetRootResultAndContinue(DkmClrValue value, DkmWorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, string resultName, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| private void GetRootResultAndContinue(DkmClrValue value, WorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, string resultName, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| { | ||
| var type = value.Type.GetLmrType(); | ||
| if (type.IsTypeVariables()) | ||
|
|
@@ -440,7 +444,7 @@ private void GetRootResultAndContinue(DkmClrValue value, DkmWorkList workList, D | |
| } | ||
| } | ||
|
|
||
| internal void GetResultAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, EvalResultDataItem parent, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| private void GetResultAndContinue(EvalResultDataItem dataItem, WorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, EvalResultDataItem parent, CompletionRoutine<DkmEvaluationResult> completionRoutine) | ||
| { | ||
| var value = dataItem.Value; // Value may have been replaced (specifically, for Nullable<T>). | ||
| DebuggerDisplayInfo displayInfo; | ||
|
|
@@ -451,13 +455,17 @@ internal void GetResultAndContinue(EvalResultDataItem dataItem, DkmWorkList work | |
| CompletionRoutine<Exception> onException = | ||
| e => completionRoutine(CreateEvaluationResultFromException(e, dataItem, inspectionContext)); | ||
|
|
||
| value.EvaluateDebuggerDisplayStringAndContinue(workList, inspectionContext, targetType, attribute.Name, | ||
| value.EvaluateDebuggerDisplayStringAndContinue(workList.InnerWorkList, inspectionContext, targetType, attribute.Name, | ||
| displayName => ContinueWithExceptionHandling( | ||
| () => value.EvaluateDebuggerDisplayStringAndContinue(workList, inspectionContext, targetType, attribute.Value, | ||
| () => value.EvaluateDebuggerDisplayStringAndContinue(workList.InnerWorkList, inspectionContext, targetType, attribute.Value, | ||
| displayValue => ContinueWithExceptionHandling( | ||
| () => value.EvaluateDebuggerDisplayStringAndContinue(workList, inspectionContext, targetType, attribute.TypeName, | ||
| () => value.EvaluateDebuggerDisplayStringAndContinue(workList.InnerWorkList, inspectionContext, targetType, attribute.TypeName, | ||
| displayType => ContinueWithExceptionHandling( | ||
| () => completionRoutine(GetResult(inspectionContext, dataItem, declaredType, displayName.Result, displayValue.Result, displayType.Result, parent)), | ||
| () => | ||
| { | ||
| completionRoutine(GetResult(inspectionContext, dataItem, declaredType, displayName.Result, displayValue.Result, displayType.Result, parent)); | ||
| workList.Execute(); | ||
| }, | ||
| onException)), | ||
| onException)), | ||
| onException)); | ||
|
|
@@ -536,15 +544,16 @@ private void GetChildrenAndContinue(EvalResultDataItem dataItem, DkmWorkList wor | |
| Debug.Assert(index >= numRows); | ||
| Debug.Assert(initialRequestSize >= numRows); | ||
| var initialChildren = new DkmEvaluationResult[numRows]; | ||
| GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, workList, inspectionContext, stackFrame, | ||
| () => ContinueWithExceptionHandling( | ||
| () => | ||
| { | ||
| var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem)); | ||
| completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext)); | ||
| rows.Free(); | ||
| }, | ||
| e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e)))); | ||
| var wl = new WorkList(workList, e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e))); | ||
| GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, wl, inspectionContext, stackFrame, | ||
| _1 => wl.ContinueWith( | ||
| _2 => | ||
| { | ||
| var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem)); | ||
| completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext)); | ||
| rows.Free(); | ||
| })); | ||
| wl.Execute(); | ||
| } | ||
|
|
||
| private void GetItemsAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, int startIndex, int count, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmEvaluationEnumAsyncResult> completionRoutine) | ||
|
|
@@ -560,35 +569,36 @@ private void GetItemsAndContinue(EvalResultDataItem dataItem, DkmWorkList workLi | |
| var numRows = rows.Count; | ||
| Debug.Assert(count >= numRows); | ||
| var results = new DkmEvaluationResult[numRows]; | ||
| GetEvaluationResultsAndContinue(rows, results, 0, numRows, workList, inspectionContext, value.StackFrame, | ||
| () => ContinueWithExceptionHandling( | ||
| () => | ||
| { | ||
| completionRoutine(new DkmEvaluationEnumAsyncResult(results)); | ||
| rows.Free(); | ||
| }, | ||
| e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e)))); | ||
| var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e))); | ||
| GetEvaluationResultsAndContinue(rows, results, 0, numRows, wl, inspectionContext, value.StackFrame, | ||
| _1 => wl.ContinueWith( | ||
| _2 => | ||
| { | ||
| completionRoutine(new DkmEvaluationEnumAsyncResult(results)); | ||
| rows.Free(); | ||
| })); | ||
| wl.Execute(); | ||
| } | ||
|
|
||
| private void StoreResultAndContinue(DkmEvaluationResult result, ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine completionRoutine) | ||
| private void StoreResultAndContinue(DkmEvaluationResult result, ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine<WorkList> completionRoutine) | ||
| { | ||
| results[index] = result; | ||
| index++; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I think it would be clearer to pass (index + 1) to the next call since no one else will consume the mutated state.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems cleaner. Changed. |
||
| if (index < numRows) | ||
| { | ||
| GetEvaluationResultsAndContinue(rows, results, index, numRows, workList, inspectionContext, stackFrame, completionRoutine); | ||
| workList.ContinueWith(wl => GetEvaluationResultsAndContinue(rows, results, index, numRows, wl, inspectionContext, stackFrame, completionRoutine)); | ||
| } | ||
| else | ||
| { | ||
| completionRoutine(); | ||
| completionRoutine(workList); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this completionRoutine just adds something to the work list, so I don't believe it can throw. If that's the case, then you probably don't need exception handling in the caller.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed try/catch. |
||
| } | ||
|
|
||
| private void GetEvaluationResultsAndContinue(ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine completionRoutine) | ||
| private void GetEvaluationResultsAndContinue(ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine<WorkList> completionRoutine) | ||
| { | ||
| if (index >= numRows) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems strange to use opposite conditions here and in StoreResultAndContinue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this condition can only fail when index == numRows == 0. Maybe we shouldn't call this method in that case. (Rationale: why does our [convoluted] loop have two range checks?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will leave the check as is for now since we're calling this method from GetChildren and GetItems. But StoreResultAndContinue has been merged in and the condition reversed. |
||
| { | ||
| completionRoutine(); | ||
| completionRoutine(workList); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -603,7 +613,7 @@ private void GetEvaluationResultsAndContinue(ArrayBuilder<EvalResultDataItem> ro | |
| // experience is less than ideal (there's no real indication that something went wrong), | ||
| // however, it seems like it's better to enumerate/display some rows than none. We will | ||
| // receive a non-fatal Watson report in this case, so the problem won't go unnoticed. | ||
| completionRoutine(); | ||
| completionRoutine(workList); | ||
| })); | ||
| } | ||
| } | ||
|
|
@@ -668,7 +678,7 @@ private static DkmEvaluationResult CreateEvaluationResultFromException(Exception | |
| DataItem: null); | ||
| } | ||
|
|
||
| internal static void ContinueWithExceptionHandling(CompletionRoutine onCompleted, CompletionRoutine<Exception> onException) | ||
| private static void ContinueWithExceptionHandling(CompletionRoutine onCompleted, CompletionRoutine<Exception> onException) | ||
| { | ||
| try | ||
| { | ||
|
|
@@ -679,5 +689,43 @@ internal static void ContinueWithExceptionHandling(CompletionRoutine onCompleted | |
| onException(e); | ||
| } | ||
| } | ||
|
|
||
| private delegate void WorkListCompletionRoutine(WorkList workList); | ||
|
|
||
| private sealed class WorkList | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense for WorkList to be IDisposable and assert that _completionRoutine is null (or, if not Dispose, then some other sort of validation that Execute always gets called when it needs to)? It worries me a little that we might forget to call Execute on a WorkList that has a continuation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to assert that _completionRoutine is null although it's not clear when we would assert since the place to call Dispose is also a reasonable point to call Execute. |
||
| { | ||
| internal readonly DkmWorkList InnerWorkList; | ||
| private readonly CompletionRoutine<Exception> _onException; | ||
| private WorkListCompletionRoutine _completionRoutine; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, there are three kinds of completion routines floating around, WorkListCompletionRoutine, CompletionRoutine, and DkmCompletionRoutine. However, we seem to call locals of all three types "completionRoutine". I think the code would be much easier to follow if we gave them distinct names.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed WorkListCompletionRoutine. |
||
|
|
||
| internal WorkList(DkmWorkList workList, CompletionRoutine<Exception> onException) | ||
| { | ||
| InnerWorkList = workList; | ||
| _onException = onException; | ||
| } | ||
|
|
||
| internal void ContinueWith(WorkListCompletionRoutine completionRoutine) | ||
| { | ||
| Debug.Assert(_completionRoutine == null); | ||
| _completionRoutine = completionRoutine; | ||
| } | ||
|
|
||
| internal void Execute() | ||
| { | ||
| while (_completionRoutine != null) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we ever expect _completionRoutine to be null when Execute is called (before entering the while)? If not, perhaps Assert?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _completionRoutine will be null if the item in progress has a [DebuggerDisplay] attribute since _completionRoutine will be set asynchronously. |
||
| { | ||
| var completionRoutine = _completionRoutine; | ||
| _completionRoutine = null; | ||
| try | ||
| { | ||
| completionRoutine(this); | ||
| } | ||
| catch (Exception e) when (ExpressionEvaluatorFatalError.ReportNonFatalException(e, DkmComponentManager.ReportCurrentNonFatalException)) | ||
| { | ||
| _onException(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ internal void AddWork(Action item) | |
| _workList.Enqueue(item); | ||
| } | ||
|
|
||
| internal int Length | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this isn't part of the real type, can we add a doc comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using => body for trivial properties. |
||
| { | ||
| get { return _workList.Count; } | ||
| } | ||
|
|
||
| public void Execute() | ||
| { | ||
| while (_workList.Count > 0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: "wl" -> "workList"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the parameter is named 'workList'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah...my bad.