提交 bd7bc6f7 编写于 作者: T TomasMatousek

Add more filters to async methods, for better crash dump diagnostics. (changeset 1276034)

上级 7e5edcb7
......@@ -313,40 +313,47 @@ public bool TryGetSemanticModel(out SemanticModel semanticModel)
/// </summary>
public async Task<SemanticModel> GetSemanticModelAsync(CancellationToken cancellationToken = default(CancellationToken))
{
if (!this.SupportsSemanticModel)
try
{
return null;
}
if (!this.SupportsSemanticModel)
{
return null;
}
SemanticModel semanticModel;
if (this.TryGetSemanticModel(out semanticModel))
{
return semanticModel;
}
SemanticModel semanticModel;
if (this.TryGetSemanticModel(out semanticModel))
{
return semanticModel;
}
var syntaxTree = await this.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var compilation = await this.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var syntaxTree = await this.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var compilation = await this.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var result = compilation.GetSemanticModel(syntaxTree);
var result = compilation.GetSemanticModel(syntaxTree);
// first try set the cache if it has not been set
var original = Interlocked.CompareExchange(ref this.model, new WeakReference<SemanticModel>(result), null);
// first try set the cache if it has not been set
var original = Interlocked.CompareExchange(ref this.model, new WeakReference<SemanticModel>(result), null);
// okay, it is first time.
if (original == null)
{
// okay, it is first time.
if (original == null)
{
return result;
}
// it looks like someone has set it. try to reuse same semantic model
if (original.TryGetTarget(out semanticModel))
{
return semanticModel;
}
// it looks like cache is gone. reset the cache.
original.SetTarget(result);
return result;
}
// it looks like someone has set it. try to reuse same semantic model
if (original.TryGetTarget(out semanticModel))
catch (Exception e) if (ExceptionHelpers.CrashUnlessCanceled(e))
{
return semanticModel;
throw ExceptionUtilities.Unreachable;
}
// it looks like cache is gone. reset the cache.
original.SetTarget(result);
return result;
}
/// <summary>
......
......@@ -1719,17 +1719,24 @@ internal ProjectId GetProjectId(MetadataReference reference)
/// </summary>
internal async Task<MetadataReference> GetMetadataReferenceAsync(ProjectReference projectReference, ProjectState fromProject, CancellationToken cancellationToken)
{
// Get the compilation state for this project. If it's not already created, then this
// will create it. Then force that state to completion and get a metadata reference to it.
var tracker = this.GetCompilationTracker(projectReference.ProjectId);
var mdref = await tracker.GetMetadataReferenceAsync(this, fromProject, projectReference, cancellationToken).ConfigureAwait(false);
try
{
// Get the compilation state for this project. If it's not already created, then this
// will create it. Then force that state to completion and get a metadata reference to it.
var tracker = this.GetCompilationTracker(projectReference.ProjectId);
var mdref = await tracker.GetMetadataReferenceAsync(this, fromProject, projectReference, cancellationToken).ConfigureAwait(false);
if (mdref != null)
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
catch (Exception e) if (ExceptionHelpers.CrashUnlessCanceled(e))
{
RecordReferencedProject(mdref, projectReference.ProjectId);
throw ExceptionUtilities.Unreachable;
}
return mdref;
}
/// <summary>
......
......@@ -868,7 +868,9 @@
<Compile Include="Workspace\Solution\ProjectState.cs" />
<Compile Include="Workspace\Solution\RecoverableTextAndVersion.cs" />
<Compile Include="Workspace\Solution\SemanticDocument.cs" />
<Compile Include="Workspace\Solution\Solution.CompilationTracker.cs" />
<Compile Include="Workspace\Solution\Solution.CompilationTracker.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Workspace\Solution\Solution.CompilationTracker.State.cs" />
<Compile Include="Workspace\Solution\Solution.CompilationTranslationAction.Actions.cs" />
<Compile Include="Workspace\Solution\Solution.CompilationTranslationAction.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册