提交 668a1a3c 编写于 作者: C CyrusNajmabadi

Store a single checksum for syntax-tree-indices.

上级 d684965b
......@@ -17,7 +17,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols
internal partial class SymbolTreeInfo
{
private const string PrefixMetadataSymbolTreeInfo = "<SymbolTreeInfo>";
private const string SerializationFormat = "16";
private const string SerializationFormat = "17";
/// <summary>
/// Loads the SymbolTreeInfo for a given assembly symbol (metadata or project). If the
......
......@@ -31,7 +31,7 @@ private static void FreeSymbolMap(MultiDictionary<string, ISymbol> symbolMap)
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var stateChecksums = await project.State.GetStateChecksumsAsync(cancellationToken).ConfigureAwait(false);
var checksum = Checksum.Create("SymbolTree",
var checksum = Checksum.Create(nameof(SymbolTreeInfo),
new Checksum[] { stateChecksums.Documents.Checksum, stateChecksums.CompilationOptions, stateChecksums.ParseOptions });
return await LoadOrCreateSourceSymbolTreeInfoAsync(
......
......@@ -17,15 +17,13 @@ internal sealed partial class SyntaxTreeIndex
private readonly DeclarationInfo _declarationInfo;
private SyntaxTreeIndex(
Checksum textChecksum,
Checksum parseOptionsChecksum,
Checksum checksum,
LiteralInfo literalInfo,
IdentifierInfo identifierInfo,
ContextInfo contextInfo,
DeclarationInfo declarationInfo)
{
TextChecksum = textChecksum;
ParseOptionsChecksum = parseOptionsChecksum;
this.Checksum = checksum;
_literalInfo = literalInfo;
_identifierInfo = identifierInfo;
_contextInfo = contextInfo;
......
......@@ -154,11 +154,10 @@ private static async Task<SyntaxTreeIndex> CreateInfoAsync(Document document, Ca
}
}
var checksums = await GetChecksumsAsync(document, cancellationToken).ConfigureAwait(false);
var checksum = await GetChecksumAsync(document, cancellationToken).ConfigureAwait(false);
return new SyntaxTreeIndex(
checksums.textChecksum,
checksums.parseOptionsChecksum,
checksum,
new LiteralInfo(
new BloomFilter(FalsePositiveProbability, stringLiterals, longLiterals)),
new IdentifierInfo(
......
......@@ -13,42 +13,37 @@ namespace Microsoft.CodeAnalysis.FindSymbols
internal sealed partial class SyntaxTreeIndex : IObjectWritable
{
private const string PersistenceName = "<SyntaxTreeIndex>";
private const string SerializationFormat = "7";
private const string SerializationFormat = "8";
public readonly Checksum TextChecksum;
public readonly Checksum ParseOptionsChecksum;
public readonly Checksum Checksum;
private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
private void WriteFormatAndChecksum(ObjectWriter writer, string formatVersion)
{
writer.WriteString(formatVersion);
TextChecksum.WriteTo(writer);
ParseOptionsChecksum.WriteTo(writer);
Checksum.WriteTo(writer);
}
private static bool TryReadFormatAndChecksums(
ObjectReader reader, string formatVersion,
out Checksum textChecksum, out Checksum parseOptionsChecksum)
private static bool TryReadFormatAndChecksum(
ObjectReader reader, string formatVersion, out Checksum checksum)
{
textChecksum = null;
parseOptionsChecksum = null;
checksum = null;
if (reader.ReadString() != formatVersion)
{
return false;
}
textChecksum = Checksum.ReadFrom(reader);
parseOptionsChecksum = Checksum.ReadFrom(reader);
checksum = Checksum.ReadFrom(reader);
return true;
}
private static async Task<SyntaxTreeIndex> LoadAsync(
Document document, string persistenceName, string formatVersion,
Func<ObjectReader, Checksum, Checksum, SyntaxTreeIndex> readFrom, CancellationToken cancellationToken)
Func<ObjectReader, Checksum, SyntaxTreeIndex> readFrom, CancellationToken cancellationToken)
{
var solution = document.Project.Solution;
var persistentStorageService = (IPersistentStorageService2)solution.Workspace.Services.GetService<IPersistentStorageService>();
var (textChecksum, parseOptionsChecksum) = await GetChecksumsAsync(document, cancellationToken).ConfigureAwait(false);
var checksum = await GetChecksumAsync(document, cancellationToken).ConfigureAwait(false);
try
{
......@@ -59,9 +54,9 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
{
if (reader != null)
{
if (DataPreambleMatches(reader, formatVersion, textChecksum, parseOptionsChecksum))
if (DataPreambleMatches(reader, formatVersion, checksum))
{
return readFrom(reader, textChecksum, parseOptionsChecksum);
return readFrom(reader, checksum);
}
}
}
......@@ -75,14 +70,13 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
}
private static bool DataPreambleMatches(
ObjectReader reader, string formatVersion, Checksum textChecksum, Checksum parseOptionsChecksum)
ObjectReader reader, string formatVersion, Checksum checksum)
{
return TryReadFormatAndChecksums(reader, formatVersion, out var persistTextChecksum, out var persistParseOptionsChecksum) &&
persistTextChecksum == textChecksum &&
persistParseOptionsChecksum == parseOptionsChecksum;
return TryReadFormatAndChecksum(reader, formatVersion, out var persistChecksum) &&
persistChecksum == checksum;
}
public static async Task<(Checksum textChecksum, Checksum parseOptionsChecksum)> GetChecksumsAsync(
public static async Task<Checksum> GetChecksumAsync(
Document document, CancellationToken cancellationToken)
{
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
......@@ -94,7 +88,7 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
var parseOptionsChecksum = ChecksumCache.GetOrCreate(
parseOptions, _ => serializer.CreateChecksum(parseOptions, cancellationToken));
return (textChecksum, parseOptionsChecksum);
return Checksum.Create(nameof(SyntaxTreeIndex), new[] { textChecksum, parseOptionsChecksum });
}
private static async Task<bool> SaveAsync(
......@@ -102,7 +96,7 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
{
var solution = document.Project.Solution;
var persistentStorageService = (IPersistentStorageService2)solution.Workspace.Services.GetService<IPersistentStorageService>();
var (textChecksum, parseOptionsChecksum) = await GetChecksumsAsync(document, cancellationToken).ConfigureAwait(false);
var checksum = await GetChecksumAsync(document, cancellationToken).ConfigureAwait(false);
try
{
......@@ -110,7 +104,7 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
data.WriteFormatAndChecksums(writer, formatVersion);
data.WriteFormatAndChecksum(writer, formatVersion);
data.WriteTo(writer);
stream.Position = 0;
......@@ -130,7 +124,7 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
{
var solution = document.Project.Solution;
var persistentStorageService = (IPersistentStorageService2)solution.Workspace.Services.GetService<IPersistentStorageService>();
var (textChecksum, parseOptionsChecksum) = await GetChecksumsAsync(document, cancellationToken).ConfigureAwait(false);
var checksum = await GetChecksumAsync(document, cancellationToken).ConfigureAwait(false);
// check whether we already have info for this document
try
......@@ -141,7 +135,7 @@ private void WriteFormatAndChecksums(ObjectWriter writer, string formatVersion)
{
if (reader != null)
{
return DataPreambleMatches(reader, formatVersion, textChecksum, parseOptionsChecksum);
return DataPreambleMatches(reader, formatVersion, checksum);
}
}
}
......@@ -162,7 +156,7 @@ public void WriteTo(ObjectWriter writer)
}
private static SyntaxTreeIndex ReadFrom(
ObjectReader reader, Checksum textChecksum, Checksum parseOptionsChecksum)
ObjectReader reader, Checksum checksum)
{
var literalInfo = LiteralInfo.TryReadFrom(reader);
var identifierInfo = IdentifierInfo.TryReadFrom(reader);
......@@ -175,7 +169,7 @@ public void WriteTo(ObjectWriter writer)
}
return new SyntaxTreeIndex(
textChecksum, parseOptionsChecksum, literalInfo.Value, identifierInfo.Value, contextInfo.Value, declarationInfo.Value);
checksum, literalInfo.Value, identifierInfo.Value, contextInfo.Value, declarationInfo.Value);
}
private Task<bool> SaveAsync(Document document, CancellationToken cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册