提交 f6adbb43 编写于 作者: D David Poeschl 提交者: Manish Vasani

Revert "Merge pull request #14671 from mattwar/Streamer" (#15068)

This reverts commit 7dd78ae8, reversing
changes made to 449f5586.
上级 290a52e0
......@@ -26,7 +26,7 @@ internal XmlSyntaxDiagnosticInfo(int offset, int width, XmlParseErrorCode code,
protected override void WriteTo(ObjectWriter writer)
{
base.WriteTo(writer);
writer.WriteUInt32((uint)_xmlErrorCode);
writer.WriteCompressedUInt((uint)_xmlErrorCode);
}
protected override Func<ObjectReader, object> GetReader()
......@@ -37,7 +37,7 @@ protected override void WriteTo(ObjectWriter writer)
private XmlSyntaxDiagnosticInfo(ObjectReader reader)
: base(reader)
{
_xmlErrorCode = (XmlParseErrorCode)reader.ReadUInt32();
_xmlErrorCode = (XmlParseErrorCode)reader.ReadCompressedUInt();
}
#endregion
......
......@@ -204,25 +204,44 @@ public static SyntaxNode DeserializeFrom(Stream stream, CancellationToken cancel
throw new InvalidOperationException(CodeAnalysisResources.TheStreamCannotBeReadFrom);
}
using (var reader = new StreamObjectReader(stream, knownObjects: GetDeserializationObjectData(), binder: s_defaultBinder, cancellationToken: cancellationToken))
using (var reader = new ObjectReader(stream, defaultData: GetDefaultObjectReaderData(), binder: s_defaultBinder))
{
var root = (Syntax.InternalSyntax.CSharpSyntaxNode)reader.ReadValue();
return root.CreateRed();
}
}
internal override ObjectData GetSerializationObjectData()
private static ObjectWriterData s_defaultObjectWriterData;
internal override ObjectWriterData GetDefaultObjectWriterData()
{
return GetDeserializationObjectData();
if (s_defaultObjectWriterData == null)
{
var data = new ObjectWriterData(GetSerializationData());
Interlocked.CompareExchange(ref s_defaultObjectWriterData, data, null);
}
return s_defaultObjectWriterData;
}
private static ObjectReaderData s_defaultObjectReaderData;
private static ObjectReaderData GetDefaultObjectReaderData()
{
if (s_defaultObjectReaderData == null)
{
var data = new ObjectReaderData(GetSerializationData());
Interlocked.CompareExchange(ref s_defaultObjectReaderData, data, null);
}
return s_defaultObjectReaderData;
}
private static ObjectData s_serializationObjectData;
private static IEnumerable<object> s_serializationData;
private static ObjectData GetDeserializationObjectData()
private static IEnumerable<object> GetSerializationData()
{
if (s_serializationObjectData == null)
if (s_serializationData == null)
{
var data = new ObjectData(
var data =
// known assemblies names and types (not in generated list)
new object[] {
typeof(object).GetTypeInfo().Assembly.FullName, // mscorlib
......@@ -268,12 +287,12 @@ private static ObjectData GetDeserializationObjectData()
"offset",
"width",
})
.ToImmutableArray());
.ToImmutableArray();
System.Threading.Interlocked.CompareExchange(ref s_serializationObjectData, data, null);
System.Threading.Interlocked.CompareExchange(ref s_serializationData, data, null);
}
return s_serializationObjectData;
return s_serializationData;
}
#endregion
......
......@@ -42,11 +42,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Compile Include="Serialization\FixedObjectBinder.cs" />
<Compile Include="Serialization\ObjectData.cs" />
<Compile Include="Serialization\StreamObjectReader.cs" />
<Compile Include="Serialization\StreamObjectWriter.cs" />
<Compile Include="Serialization\TypeKey.cs" />
<Compile Include="InternalUtilities\CommandLineUtilities.cs" />
<Compile Include="InternalUtilities\OrderedMultiDictionary.cs" />
<Compile Include="Syntax\InternalSyntax\GreenNodeExtensions.cs" />
......@@ -552,12 +547,18 @@
<Compile Include="ReferenceManager\UnifiedAssembly.cs" />
<Compile Include="ResourceDescription.cs" />
<Compile Include="ResourceException.cs" />
<Compile Include="Serialization\RecordingObjectBinder.cs" />
<Compile Include="Serialization\ConcurrentRecordingObjectBinder.cs" />
<Compile Include="Serialization\FixedObjectBinder.cs" />
<Compile Include="Serialization\IObjectReadable.cs" />
<Compile Include="Serialization\IObjectWritable.cs" />
<Compile Include="Serialization\ObjectBinder.cs" />
<Compile Include="Serialization\ObjectReader.cs" />
<Compile Include="Serialization\ObjectReaderData.cs" />
<Compile Include="Serialization\ObjectReaderWriterBase.cs" />
<Compile Include="Serialization\ObjectWriter.cs" />
<Compile Include="Serialization\ObjectWriterData.cs" />
<Compile Include="Serialization\RecordingObjectBinder.cs" />
<Compile Include="Serialization\SimpleRecordingObjectBinder.cs" />
<Compile Include="SignatureComparer.cs" />
<Compile Include="SourceCodeKind.cs" />
<Compile Include="SpecialMember.cs" />
......
......@@ -164,9 +164,9 @@ internal class CodeAnalysisResources {
/// <summary>
/// Looks up a localized string similar to Arrays with more than one dimension cannot be serialized..
/// </summary>
internal static string Arrays_with_more_than_one_dimension_cannot_be_serialized {
internal static string ArraysWithMoreThanOneDimensionCannotBeSerialized {
get {
return ResourceManager.GetString("Arrays_with_more_than_one_dimension_cannot_be_serialized", resourceCulture);
return ResourceManager.GetString("ArraysWithMoreThanOneDimensionCannotBeSerialized", resourceCulture);
}
}
......@@ -215,24 +215,6 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot deserialize type &apos;{0}&apos;..
/// </summary>
internal static string Cannot_deserialize_type_0 {
get {
return ResourceManager.GetString("Cannot_deserialize_type_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot serialize type &apos;{0}&apos;..
/// </summary>
internal static string Cannot_serialize_type_0 {
get {
return ResourceManager.GetString("Cannot_serialize_type_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Can&apos;t alias a module..
/// </summary>
......@@ -414,15 +396,6 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Deserialization reader for &apos;{0}&apos; read incorrect number of values..
/// </summary>
internal static string Deserialization_reader_for_0_read_incorrect_number_of_values {
get {
return ResourceManager.GetString("Deserialization_reader_for_0_read_incorrect_number_of_values", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A DiagnosticDescriptor must have an Id that is neither null nor an empty string nor a string that only contains white space..
/// </summary>
......@@ -955,6 +928,15 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot deserialize type &apos;{0}&apos;, no binder supplied..
/// </summary>
internal static string NoBinderException {
get {
return ResourceManager.GetString("NoBinderException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A node or token is out of sequence..
/// </summary>
......@@ -964,6 +946,24 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot deserialize type &apos;{0}&apos;, it has no deserialization reader..
/// </summary>
internal static string NoReaderException {
get {
return ResourceManager.GetString("NoReaderException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The type &apos;{0}&apos; cannot be written, it does not implement IObjectWritable.
/// </summary>
internal static string NotWritableException {
get {
return ResourceManager.GetString("NotWritableException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A value in the pathMap is null..
/// </summary>
......@@ -1288,15 +1288,6 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to The type &apos;{0}&apos; is not understood by the serialization binder..
/// </summary>
internal static string The_type_0_is_not_understood_by_the_serialization_binder {
get {
return ResourceManager.GetString("The_type_0_is_not_understood_by_the_serialization_binder", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The stream cannot be read from..
/// </summary>
......@@ -1435,9 +1426,9 @@ internal class CodeAnalysisResources {
/// <summary>
/// Looks up a localized string similar to Value too large to be represented as a 30 bit unsigned integer..
/// </summary>
internal static string Value_too_large_to_be_represented_as_a_30_bit_unsigned_integer {
internal static string ValueTooLargeToBeRepresented {
get {
return ResourceManager.GetString("Value_too_large_to_be_represented_as_a_30_bit_unsigned_integer", resourceCulture);
return ResourceManager.GetString("ValueTooLargeToBeRepresented", resourceCulture);
}
}
......
......@@ -207,10 +207,10 @@
<data name="GetMetadataMustReturnInstance" xml:space="preserve">
<value>{0}.GetMetadata() must return an instance of {1}.</value>
</data>
<data name="Value_too_large_to_be_represented_as_a_30_bit_unsigned_integer" xml:space="preserve">
<data name="ValueTooLargeToBeRepresented" xml:space="preserve">
<value>Value too large to be represented as a 30 bit unsigned integer.</value>
</data>
<data name="Arrays_with_more_than_one_dimension_cannot_be_serialized" xml:space="preserve">
<data name="ArraysWithMoreThanOneDimensionCannotBeSerialized" xml:space="preserve">
<value>Arrays with more than one dimension cannot be serialized.</value>
</data>
<data name="InvalidAssemblyName" xml:space="preserve">
......@@ -431,14 +431,14 @@
<data name="InvalidDiagnosticLocationReported" xml:space="preserve">
<value>Reported diagnostic '{0}' has a source location in file '{1}', which is not part of the compilation being analyzed.</value>
</data>
<data name="The_type_0_is_not_understood_by_the_serialization_binder" xml:space="preserve">
<value>The type '{0}' is not understood by the serialization binder.</value>
<data name="NoBinderException" xml:space="preserve">
<value>Cannot deserialize type '{0}', no binder supplied.</value>
</data>
<data name="Cannot_deserialize_type_0" xml:space="preserve">
<value>Cannot deserialize type '{0}'.</value>
<data name="NoReaderException" xml:space="preserve">
<value>Cannot deserialize type '{0}', it has no deserialization reader.</value>
</data>
<data name="Cannot_serialize_type_0" xml:space="preserve">
<value>Cannot serialize type '{0}'.</value>
<data name="NotWritableException" xml:space="preserve">
<value>The type '{0}' cannot be written, it does not implement IObjectWritable</value>
</data>
<data name="InvalidNodeToTrack" xml:space="preserve">
<value>Node to track is not a descendant of the root.</value>
......@@ -579,9 +579,6 @@
<data name="SeparatorIsExpected" xml:space="preserve">
<value>separator is expected</value>
</data>
<data name="Deserialization_reader_for_0_read_incorrect_number_of_values" xml:space="preserve">
<value>Deserialization reader for '{0}' read incorrect number of values.</value>
</data>
<data name="TheStreamCannotBeReadFrom" xml:space="preserve">
<value>The stream cannot be read from.</value>
</data>
......
......@@ -141,12 +141,12 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
protected virtual void WriteTo(ObjectWriter writer)
{
writer.WriteValue(_messageProvider);
writer.WriteInt32(_errorCode);
writer.WriteCompressedUInt((uint)_errorCode);
writer.WriteInt32((int)_effectiveSeverity);
writer.WriteInt32((int)_defaultSeverity);
int count = _arguments?.Length ?? 0;
writer.WriteInt32(count);
writer.WriteCompressedUInt((uint)count);
if (count > 0)
{
......@@ -170,11 +170,11 @@ protected virtual void WriteTo(ObjectWriter writer)
protected DiagnosticInfo(ObjectReader reader)
{
_messageProvider = (CommonMessageProvider)reader.ReadValue();
_errorCode = reader.ReadInt32();
_errorCode = (int)reader.ReadCompressedUInt();
_effectiveSeverity = (DiagnosticSeverity)reader.ReadInt32();
_defaultSeverity = (DiagnosticSeverity)reader.ReadInt32();
var count = reader.ReadInt32();
var count = (int)reader.ReadCompressedUInt();
if (count == 0)
{
_arguments = Array.Empty<object>();
......
......@@ -72,7 +72,7 @@ private LocalizableResourceString(ObjectReader reader)
_nameOfLocalizableResource = reader.ReadString();
_resourceManager = new ResourceManager(_resourceSource);
var length = reader.ReadInt32();
var length = (int)reader.ReadCompressedUInt();
if (length == 0)
{
_formatArguments = Array.Empty<string>();
......@@ -98,8 +98,8 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
{
writer.WriteValue(_resourceSource);
writer.WriteString(_nameOfLocalizableResource);
var length = _formatArguments.Length;
writer.WriteInt32(length);
var length = (uint)_formatArguments.Length;
writer.WriteCompressedUInt(length);
for (int i = 0; i < length; i++)
{
writer.WriteString(_formatArguments[i]);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
namespace Roslyn.Utilities
{
/// <summary>
/// A binder that gathers type/reader mappings during object writing
/// </summary>
internal sealed class ConcurrentRecordingObjectBinder : RecordingObjectBinder
{
private readonly ConcurrentDictionary<TypeKey, Type> _typeMap =
new ConcurrentDictionary<TypeKey, Type>();
private readonly ConcurrentDictionary<Type, Func<ObjectReader, object>> _readerMap =
new ConcurrentDictionary<Type, Func<ObjectReader, object>>();
public override Type GetType(string assemblyName, string typeName)
{
Type type;
if (!_typeMap.TryGetValue(new TypeKey(assemblyName, typeName), out type))
{
Debug.Assert(false, assemblyName + "/" + typeName + " don't exist");
}
return type;
}
public override Func<ObjectReader, object> GetReader(Type type)
{
Func<ObjectReader, object> reader;
if (!_readerMap.TryGetValue(type, out reader))
{
Debug.Assert(false, type.ToString() + " reader doesn't exist");
}
return reader;
}
private bool HasConstructor(Type type)
{
return _readerMap.ContainsKey(type);
}
public override void Record(Type type)
{
if (type != null)
{
var key = new TypeKey(type.GetTypeInfo().Assembly.FullName, type.FullName);
_typeMap.TryAdd(key, type);
}
}
public override void Record(object instance)
{
if (instance != null)
{
var type = instance.GetType();
var readable = instance as IObjectReadable;
if (readable != null)
{
if (HasConstructor(type))
{
return;
}
_readerMap.TryAdd(type, readable.GetReader());
}
Record(type);
}
}
}
}
......@@ -2,47 +2,36 @@
using System;
using System.Collections.Immutable;
using System.Reflection;
namespace Roslyn.Utilities
{
/// <summary>
/// An <see cref="ObjectBinder"/> with a fixed set of type and reader mappings.
/// A binder that used a predetermine list of types and reader functions.
/// </summary>
internal class FixedObjectBinder : ObjectBinder
{
private readonly ImmutableDictionary<TypeKey, Type> _typeMap;
private readonly ImmutableDictionary<Type, Func<ObjectReader, object>> _readerMap;
public FixedObjectBinder(
ImmutableDictionary<TypeKey, Type> typeMap,
ImmutableDictionary<Type, Func<ObjectReader, object>> readerMap)
public FixedObjectBinder(ImmutableDictionary<Type, Func<ObjectReader, object>> readerMap)
{
_typeMap = typeMap ?? ImmutableDictionary<TypeKey, Type>.Empty;
_readerMap = readerMap ?? ImmutableDictionary<Type, Func<ObjectReader, object>>.Empty;
_readerMap = readerMap;
_typeMap = readerMap.Keys.ToImmutableDictionary(t => new TypeKey(t.GetTypeInfo().Assembly.FullName, t.FullName));
}
public static readonly FixedObjectBinder Empty = new FixedObjectBinder(null, null);
public override bool TryGetType(TypeKey key, out Type type)
{
return _typeMap.TryGetValue(key, out type);
}
public override bool TryGetTypeKey(Type type, out TypeKey key)
{
// do not let types have keys that cannot be reverse mapped.
return base.TryGetTypeKey(type, out key) && _typeMap.ContainsKey(key);
}
public override bool TryGetWriter(Object instance, out Action<ObjectWriter, Object> writer)
public override Type GetType(string assemblyName, string typeName)
{
// don't let objects be written that do not have known readers.
return base.TryGetWriter(instance, out writer) && _readerMap.ContainsKey(instance.GetType());
Type type;
_typeMap.TryGetValue(new TypeKey(assemblyName, typeName), out type);
return type;
}
public override bool TryGetReader(Type type, out Func<ObjectReader, object> reader)
public override Func<ObjectReader, object> GetReader(Type type)
{
return _readerMap.TryGetValue(type, out reader);
Func<ObjectReader, object> reader;
_readerMap.TryGetValue(type, out reader);
return reader;
}
}
}
......@@ -4,15 +4,6 @@
namespace Roslyn.Utilities
{
/// <summary>
/// Objects that implement this interface know how to provide a way to read and construct instances of the same type
/// from an <see cref="ObjectReader"/>.
/// </summary>
/// <remarks>
/// This is typically used by a <see cref="ObjectBinder"/> that records how to
/// read back objects that were previously written using the same <see cref="ObjectBinder"/> instance, as a way to avoid needing
/// to describe all deserialization readers up front, and/or avoid using reflection to discover them.
/// </remarks>
internal interface IObjectReadable
{
Func<ObjectReader, object> GetReader();
......
......@@ -2,10 +2,6 @@
namespace Roslyn.Utilities
{
/// <summary>
/// Objects that implement this interface know how to write their contents to an <see cref="ObjectWriter"/>,
/// so they can be reconstructed later by an <see cref="ObjectReader"/>.
/// </summary>
internal interface IObjectWritable
{
void WriteTo(ObjectWriter writer);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Reflection;
namespace Roslyn.Utilities
{
/// <summary>
/// A type that provides object and type encoding/decoding.
/// </summary>
internal abstract class ObjectBinder
{
/// <summary>
/// Gets the <see cref="Type"/> corresponding to the specified <see cref="TypeKey"/>.
/// Returns false if no type corresponds to the key.
/// </summary>
public abstract bool TryGetType(TypeKey key, out Type type);
public abstract Type GetType(string assemblyName, string typeName);
public abstract Func<ObjectReader, object> GetReader(Type type);
/// <summary>
/// Gets the <see cref="TypeKey"/> for the specified <see cref="Type"/>.
/// Returns false if the type cannot be serialized.
/// </summary>
public virtual bool TryGetTypeKey(Type type, out TypeKey key)
internal struct TypeKey : IEquatable<TypeKey>
{
key = new TypeKey(type.GetTypeInfo().Assembly.FullName, type.FullName);
return true;
}
internal readonly string AssemblyName;
internal readonly string TypeName;
/// <summary>
/// Gets a function that reads an type's members from an <see cref="ObjectReader"/> and constructs an instance with those members.
/// Returns false if the type cannot be deserialized.
/// </summary>
public abstract bool TryGetReader(Type type, out Func<ObjectReader, object> reader);
public TypeKey(string assemblyName, string typeName)
{
this.AssemblyName = assemblyName;
this.TypeName = typeName;
}
/// <summary>
/// Gets a function that writes an object's members to a <see cref="ObjectWriter"/>.
/// Returns false if the type cannot be serialized.
/// </summary>
public virtual bool TryGetWriter(object instance, out Action<ObjectWriter, object> writer)
{
if (instance is IObjectWritable)
public bool Equals(TypeKey other)
{
writer = (w, i) => ((IObjectWritable)i).WriteTo(w); // static delegate should be cached
return true;
return this.AssemblyName == other.AssemblyName
&& this.TypeName == other.TypeName;
}
else
public override bool Equals(object obj)
{
return obj is TypeKey && this.Equals((TypeKey)obj);
}
public override int GetHashCode()
{
writer = null;
return false;
return Hash.Combine(this.AssemblyName.GetHashCode(), this.TypeName.GetHashCode());
}
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
namespace Roslyn.Utilities
{
/// <summary>
/// Represents a fixed array of objects that do not need to be serialized because they are well known on both ends.
/// </summary>
/// <remarks>
/// This class is just a sneaky way to get a reference to an ImmutableArray,
/// due to <see cref="StreamObjectWriter"/> needing to be able to use it as a key for a ConditionalWeakTable.
/// </remarks>
internal class ObjectData
{
public ImmutableArray<object> Objects { get; }
public ObjectData(ImmutableArray<object> objects)
{
this.Objects = objects.NullToEmpty();
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Roslyn.Utilities
{
internal class ObjectReaderData : IDisposable
{
internal static readonly ObjectPool<List<object>> ListPool =
new ObjectPool<List<object>>(() => new List<object>(128), 2);
private readonly ObjectReaderData _baseData;
private readonly List<object> _values = ListPool.Allocate();
private readonly int _baseDataCount;
internal ObjectReaderData(params object[] items)
: this((IEnumerable<object>)items)
{
}
internal ObjectReaderData(IEnumerable<object> items)
{
if (items != null)
{
foreach (var value in items)
{
_values.Add(value);
}
}
}
internal ObjectReaderData(ObjectReaderData baseData)
{
Debug.Assert(baseData?._baseData == null, "Should be <= 1 level deep");
_baseData = baseData;
_baseDataCount = baseData?._values.Count ?? 0;
}
public void Dispose()
{
_values.Clear();
ListPool.Free(_values);
}
public int GetNextId()
{
_values.Add(null);
return _baseDataCount + _values.Count - 1;
}
public void AddValue(int id, object value)
{
_values[id - _baseDataCount] = value;
}
public object GetValue(int id)
{
if (_baseData != null)
{
if (id < _baseDataCount)
{
return _baseData.GetValue(id);
}
else
{
return _values[id - _baseDataCount];
}
}
else
{
return _values[id];
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Roslyn.Utilities
{
internal class ObjectReaderWriterBase
{
// we have s_typeMap and s_reversedTypeMap since there is no bidirectional map in compiler
protected static readonly ImmutableDictionary<Type, DataKind> s_typeMap = ImmutableDictionary.CreateRange<Type, DataKind>(
new KeyValuePair<Type, DataKind>[]
{
KeyValuePair.Create(typeof(bool), DataKind.BooleanType),
KeyValuePair.Create(typeof(char), DataKind.Char),
KeyValuePair.Create(typeof(string), DataKind.StringType),
KeyValuePair.Create(typeof(sbyte), DataKind.Int8),
KeyValuePair.Create(typeof(short), DataKind.Int16),
KeyValuePair.Create(typeof(int), DataKind.Int32),
KeyValuePair.Create(typeof(long), DataKind.Int64),
KeyValuePair.Create(typeof(byte), DataKind.UInt8),
KeyValuePair.Create(typeof(ushort), DataKind.UInt16),
KeyValuePair.Create(typeof(uint), DataKind.UInt32),
KeyValuePair.Create(typeof(ulong), DataKind.UInt64),
KeyValuePair.Create(typeof(float), DataKind.Float4),
KeyValuePair.Create(typeof(double), DataKind.Float8),
KeyValuePair.Create(typeof(decimal), DataKind.Decimal),
});
protected static readonly ImmutableDictionary<DataKind, Type> s_reverseTypeMap = s_typeMap.ToImmutableDictionary(kv => kv.Value, kv => kv.Key);
internal enum DataKind : byte
{
Null,
Type,
TypeRef, // type ref id as 4 bytes
TypeRef_B, // type ref id as 1 byte
TypeRef_S, // type ref id as 2 bytes
Object_W, // IObjectWritable
ObjectRef, // object ref id as 4 bytes
ObjectRef_B, // object ref id as 1 byte
ObjectRef_S, // object ref id as 2 bytes
StringUtf8, // string in UTF8 encoding
StringUtf16, // string in UTF16 encoding
StringRef, // string ref id as 4-bytes
StringRef_B, // string ref id as 1-byte
StringRef_S, // string ref id as 2-bytes
Boolean_T, // boolean true
Boolean_F, // boolean false
Char,
Int8,
Int16,
Int32, // int32 encoded as 4 bytes
Int32_B, // int32 encoded as 1 byte
Int32_S, // int32 encoded as 2 bytes
Int32_Z, // int32 zero
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
Float4,
Float8,
Decimal,
DateTime,
Enum,
Array, // array with # elements encoded as compressed int
Array_0, // array with zero elements
Array_1, // array with one element
Array_2, // array with two elements
Array_3, // array with three elements
BooleanType, // boolean type marker
StringType // string type marker
}
internal static readonly byte ByteMarkerMask = 3 << 6;
internal static readonly byte Byte1Marker = 0;
internal static readonly byte Byte2Marker = 1 << 6;
internal static readonly byte Byte4Marker = 2 << 6;
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Roslyn.Utilities
{
internal class ObjectWriterData : IDisposable
{
internal static readonly ObjectPool<Dictionary<object, int>> DictionaryPool =
new ObjectPool<Dictionary<object, int>>(() => new Dictionary<object, int>(128), 2);
private readonly ObjectWriterData _baseData;
private readonly Dictionary<object, int> _valueToIdMap = DictionaryPool.Allocate();
private int _nextId;
internal ObjectWriterData(params object[] items)
: this((IEnumerable<object>)items)
{
}
internal ObjectWriterData(IEnumerable<object> items)
{
if (items != null)
{
foreach (var value in items)
{
_valueToIdMap.Add(value, _valueToIdMap.Count);
}
}
_nextId = _valueToIdMap.Count;
}
internal ObjectWriterData(ObjectWriterData baseData)
{
_baseData = baseData;
_nextId = baseData?._nextId ?? 0;
}
public void Dispose()
{
// If the map grew too big, don't return it to the pool.
// When testing with the Roslyn solution, this dropped only 2.5% of requests.
if (_valueToIdMap.Count > 1024)
{
DictionaryPool.ForgetTrackedObject(_valueToIdMap);
return;
}
_valueToIdMap.Clear();
DictionaryPool.Free(_valueToIdMap);
}
public bool TryGetId(object value, out int id)
{
if (_baseData != null && _baseData.TryGetId(value, out id))
{
return true;
}
return _valueToIdMap.TryGetValue(value, out id);
}
private int GetNextId()
{
var id = _nextId;
_nextId++;
return id;
}
public int Add(object value)
{
var id = this.GetNextId();
_valueToIdMap.Add(value, id);
return id;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
namespace Roslyn.Utilities
{
/// <summary>
/// A <see cref="ObjectBinder"/> that records runtime types and object readers during object writing so they
/// can be used to read back objects later.
/// A binder that gathers type/reader mappings during object writing
/// </summary>
/// <remarks>
/// This binder records runtime types an object readers as a way to avoid needing to describe all serialization types up front
/// or using reflection to determine them on demand.
/// </remarks>
internal sealed class RecordingObjectBinder : ObjectBinder
internal abstract class RecordingObjectBinder : ObjectBinder
{
private readonly ConcurrentDictionary<TypeKey, Type> _typeMap =
new ConcurrentDictionary<TypeKey, Type>();
private readonly ConcurrentDictionary<Type, Func<ObjectReader, object>> _readerMap =
new ConcurrentDictionary<Type, Func<ObjectReader, object>>();
public override bool TryGetType(TypeKey key, out Type type)
{
return _typeMap.TryGetValue(key, out type);
}
public override bool TryGetTypeKey(Type type, out TypeKey key)
{
if (base.TryGetTypeKey(type, out key))
{
RecordType(type, key);
return true;
}
else
{
return false;
}
}
public override bool TryGetReader(Type type, out Func<ObjectReader, object> reader)
{
return _readerMap.TryGetValue(type, out reader);
}
public override bool TryGetWriter(Object instance, out Action<ObjectWriter, Object> writer)
{
RecordReader(instance);
return base.TryGetWriter(instance, out writer);
}
private void RecordType(Type type, TypeKey key)
{
if (type != null)
{
_typeMap.TryAdd(key, type);
}
}
private void RecordReader(object instance)
{
if (instance != null)
{
var type = instance.GetType();
TypeKey key;
if (TryGetTypeKey(type, out key)) // records type as side-effect
{
var readable = instance as IObjectReadable;
if (readable != null)
{
if (_readerMap.ContainsKey(type))
{
Debug.Assert(_typeMap.ContainsKey(key));
}
else
{
_readerMap.TryAdd(type, readable.GetReader());
}
}
}
}
}
public abstract void Record(Type type);
public abstract void Record(object instance);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
namespace Roslyn.Utilities
{
/// <summary>
/// A binder that gathers type/reader mappings during object writing
/// </summary>
internal sealed class SimpleRecordingObjectBinder : RecordingObjectBinder
{
private readonly Dictionary<TypeKey, Type> _typeMap =
new Dictionary<TypeKey, Type>();
private readonly Dictionary<Type, Func<ObjectReader, object>> _readerMap =
new Dictionary<Type, Func<ObjectReader, object>>();
public override Type GetType(string assemblyName, string typeName)
{
Type type;
if (!_typeMap.TryGetValue(new TypeKey(assemblyName, typeName), out type))
{
Debug.Assert(false, assemblyName + "/" + typeName + " don't exist");
}
return type;
}
public override Func<ObjectReader, object> GetReader(Type type)
{
Func<ObjectReader, object> reader;
if (!_readerMap.TryGetValue(type, out reader))
{
Debug.Assert(false, type.ToString() + " reader doesn't exist");
}
return reader;
}
private bool HasConstructor(Type type)
{
return _readerMap.ContainsKey(type);
}
public override void Record(Type type)
{
if (type != null)
{
var key = new TypeKey(type.GetTypeInfo().Assembly.FullName, type.FullName);
if (!_typeMap.ContainsKey(key))
{
_typeMap.Add(key, type);
}
}
}
public override void Record(object instance)
{
if (instance != null)
{
var type = instance.GetType();
var readable = instance as IObjectReadable;
if (readable != null)
{
if (HasConstructor(type))
{
Debug.Assert(_typeMap.ContainsKey(new TypeKey(type.GetTypeInfo().Assembly.FullName, type.FullName)));
return;
}
if (!_readerMap.ContainsKey(type))
{
_readerMap.Add(type, readable.GetReader());
}
}
Record(type);
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Roslyn.Utilities
{
/// <summary>
/// The name parts of a type that can be used to uniquely identity that type.
/// </summary>
internal struct TypeKey : IEquatable<TypeKey>
{
public readonly string AssemblyName;
public readonly string TypeName;
public TypeKey(string assemblyName, string typeName)
{
this.AssemblyName = assemblyName;
this.TypeName = typeName;
}
public bool Equals(TypeKey other)
{
return this.AssemblyName == other.AssemblyName
&& this.TypeName == other.TypeName;
}
public override bool Equals(object obj)
{
return obj is TypeKey && this.Equals((TypeKey)obj);
}
public override int GetHashCode()
{
return Hash.Combine(this.AssemblyName.GetHashCode(), this.TypeName.GetHashCode());
}
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ public override string Language
protected override SyntaxTree SyntaxTreeCore => this.Parent.SyntaxTree;
internal override ObjectData GetSerializationObjectData()
internal override ObjectWriterData GetDefaultObjectWriterData()
{
throw ExceptionUtilities.Unreachable;
}
......
......@@ -1234,7 +1234,7 @@ public bool IsEquivalentTo(SyntaxNode node, bool topLevel = false)
return IsEquivalentToCore(node, topLevel);
}
internal static readonly ObjectBinder s_defaultBinder = new RecordingObjectBinder();
internal static readonly RecordingObjectBinder s_defaultBinder = new ConcurrentRecordingObjectBinder();
public virtual void SerializeTo(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
{
......@@ -1248,13 +1248,13 @@ public virtual void SerializeTo(Stream stream, CancellationToken cancellationTok
throw new InvalidOperationException(CodeAnalysisResources.TheStreamCannotBeWrittenTo);
}
using (var writer = new StreamObjectWriter(stream, GetSerializationObjectData(), binder: s_defaultBinder, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, GetDefaultObjectWriterData(), binder: s_defaultBinder, cancellationToken: cancellationToken))
{
writer.WriteValue(this.Green);
}
}
internal abstract ObjectData GetSerializationObjectData();
internal abstract ObjectWriterData GetDefaultObjectWriterData();
#region Core Methods
......
......@@ -253,17 +253,7 @@ public static SyntaxTree Parse(string text, string filename = "", CSharpParseOpt
}
var stringText = StringText.From(text, Encoding.UTF8);
return CheckSerializable(SyntaxFactory.ParseSyntaxTree(stringText, options, filename));
}
private static SyntaxTree CheckSerializable(SyntaxTree tree)
{
var stream = new MemoryStream();
var root = tree.GetRoot();
root.SerializeTo(stream);
stream.Position = 0;
var deserializedRoot = CSharpSyntaxNode.DeserializeFrom(stream);
return tree;
return SyntaxFactory.ParseSyntaxTree(stringText, options, filename);
}
public static SyntaxTree[] Parse(IEnumerable<string> sources, CSharpParseOptions options = null)
......
......@@ -132,52 +132,63 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' Deserialize a syntax node from a byte stream.
''' </summary>
Public Shared Function DeserializeFrom(stream As IO.Stream, Optional cancellationToken As CancellationToken = Nothing) As SyntaxNode
Using reader = New StreamObjectReader(stream, knownObjects:=GetDeserializationObjectData(), binder:=s_defaultBinder, cancellationToken:=cancellationToken)
Using reader = New ObjectReader(stream, defaultData:=GetDefaultObjectReaderData(), binder:=s_defaultBinder)
Return DirectCast(reader.ReadValue(), InternalSyntax.VisualBasicSyntaxNode).CreateRed(Nothing, 0)
End Using
End Function
Friend Overrides Function GetSerializationObjectData() As ObjectData
Return GetDeserializationObjectData()
End Function
Private Shared ReadOnly s_serializationObjectData As ObjectData
Private Shared Function GetDeserializationObjectData() As ObjectData
If s_serializationObjectData Is Nothing Then
Dim data = New ObjectData(
New Object() {
GetType(Object).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.DiagnosticInfo).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxNode).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.SyntaxToken.TriviaInfo),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.SimpleIdentifierSyntax),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.ComplexIdentifierSyntax),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithTwoChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithThreeChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithManyChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithLotsOfChildren),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int32)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int16)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int64)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt32)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt16)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt64)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Byte)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of SByte)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.FloatingLiteralTokenSyntax(Of Single)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.FloatingLiteralTokenSyntax(Of Double)),
GetType(Microsoft.CodeAnalysis.DiagnosticInfo),
GetType(Microsoft.CodeAnalysis.SyntaxAnnotation)
} _
.Concat(InternalSyntax.SyntaxFactory.GetNodeTypes()) _
.Concat(InternalSyntax.SyntaxFactory.GetWellKnownTrivia()) _
.ToImmutableArray())
Interlocked.CompareExchange(s_serializationObjectData, data, Nothing)
Private Shared s_defaultObjectReaderData As ObjectReaderData
Private Shared Function GetDefaultObjectReaderData() As ObjectReaderData
If s_defaultObjectReaderData Is Nothing Then
Interlocked.CompareExchange(s_defaultObjectReaderData, New ObjectReaderData(GetSerializationData()), Nothing)
End If
Return s_defaultObjectReaderData
End Function
Private Shared s_defaultObjectWriterData As ObjectWriterData
Friend Overrides Function GetDefaultObjectWriterData() As ObjectWriterData
If s_defaultObjectWriterData Is Nothing Then
Interlocked.CompareExchange(s_defaultObjectWriterData, New ObjectWriterData(GetSerializationData()), Nothing)
End If
Return s_defaultObjectWriterData
End Function
Private Shared ReadOnly s_serializationData As IEnumerable(Of Object)
Private Shared Function GetSerializationData() As IEnumerable(Of Object)
If s_serializationData Is Nothing Then
Dim data = New Object() {
GetType(Object).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.DiagnosticInfo).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxNode).GetTypeInfo().Assembly.FullName,
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.SyntaxToken.TriviaInfo),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.SimpleIdentifierSyntax),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.ComplexIdentifierSyntax),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithTwoChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithThreeChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithManyChildren),
GetType(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithLotsOfChildren),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int32)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int16)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Int64)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt32)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt16)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of UInt64)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of Byte)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.IntegerLiteralTokenSyntax(Of SByte)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.FloatingLiteralTokenSyntax(Of Single)),
GetType(Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.FloatingLiteralTokenSyntax(Of Double)),
GetType(Microsoft.CodeAnalysis.DiagnosticInfo),
GetType(Microsoft.CodeAnalysis.SyntaxAnnotation)
} _
.Concat(InternalSyntax.SyntaxFactory.GetNodeTypes()) _
.Concat(InternalSyntax.SyntaxFactory.GetWellKnownTrivia()) _
.ToImmutableArray()
Interlocked.CompareExchange(s_serializationData, data, Nothing)
End If
Return s_serializationObjectData
Return s_serializationData
End Function
#End Region
......
......@@ -37,16 +37,6 @@ End Class
</Foo>.Value)
End Sub
<Fact>
Public Sub TestRoundTripDateTimeLiteral()
Dim x As DateTime = #10/5/2015#
RoundTrip(<Foo>
Public Class C
Private _x As DateTime = #10/5/2015#
End Class
</Foo>.Value)
End Sub
<Fact>
Public Sub TestRoundTripSyntaxNodeWithDiagnostics()
Dim text = <Foo>
......
......@@ -35,7 +35,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
var list = SharedPools.Default<List<TodoItem>>().AllocateAndClear();
try
{
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
var format = reader.ReadString();
if (!string.Equals(format, FormatVersion))
......@@ -63,7 +63,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
protected override void WriteTo(Stream stream, Data data, CancellationToken cancellationToken)
{
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(FormatVersion);
data.TextVersion.WriteTo(writer);
......
......@@ -115,14 +115,14 @@ public void TestSerialization()
var stream = new MemoryStream();
var bloomFilter = new BloomFilter(0.001, false, new[] { "Hello, World" });
using (var writer = new StreamObjectWriter(stream))
using (var writer = new ObjectWriter(stream))
{
bloomFilter.WriteTo(writer);
}
stream.Position = 0;
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
var rehydratedFilter = BloomFilter.ReadFrom(reader);
Assert.True(bloomFilter.IsEquivalent(rehydratedFilter));
......
......@@ -33,7 +33,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
{
try
{
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
var format = reader.ReadString();
if (!string.Equals(format, FormatVersion, StringComparison.InvariantCulture))
......@@ -56,7 +56,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
protected override void WriteTo(Stream stream, Data data, CancellationToken cancellationToken)
{
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(FormatVersion);
data.TextVersion.WriteTo(writer);
......
......@@ -140,7 +140,7 @@ private CompilationWithAnalyzers CreateAnalyzerDriver(CompilationWithAnalyzers a
// handling of cancellation and exception
var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
return DiagnosticResultSerializer.Deserialize(reader, analyzerMap, project, version, cancellationToken);
}
......
......@@ -134,7 +134,7 @@ private static bool TryReadFrom(Project project, string keyName, out Versions ve
try
{
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
var formatVersion = reader.ReadInt32();
if (formatVersion != SerializationFormat)
......@@ -207,7 +207,7 @@ private static async Task WriteToDependentSemanticVersionAsync(IPersistentStorag
IPersistentStorage storage, string keyName, VersionStamp projectVersion, VersionStamp semanticVersion, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteInt32(SerializationFormat);
projectVersion.WriteTo(writer);
......
......@@ -153,7 +153,7 @@ public async Task RequestAssetAsync(int sessionId, byte[][] checksums, string st
using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, _source.Token))
using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
{
using (var writer = new StreamObjectWriter(stream))
using (var writer = new ObjectWriter(stream))
{
writer.WriteInt32(sessionId);
......
......@@ -84,7 +84,7 @@ private VersionStamp GetIdentifierSetVersion(EsentStorage.Key key, int identifie
return VersionStamp.Default;
}
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
return VersionStamp.ReadFrom(reader);
}
......@@ -145,7 +145,7 @@ private bool ReadIdentifierPositions(EsentStorage.Key key, int identifierId, Lis
return true;
}
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
var formatVersion = reader.ReadString();
if (formatVersion != IdentifierSetSerializationVersion)
......@@ -235,7 +235,7 @@ private bool WriteIdentifierLocations(EsentStorage.Key key, Document document, V
identifierId = identifierMap[identifier];
using (var stream = accessor.GetWriteStream(key, identifierId))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(IdentifierSetSerializationVersion);
WriteList(writer, positions);
......@@ -292,7 +292,7 @@ private void Free(Dictionary<string, List<int>> map)
accessor.PrepareBatchOneInsert();
using (var stream = accessor.GetWriteStream(key, identifierId))
using (var writer = new StreamObjectWriter(stream))
using (var writer = new ObjectWriter(stream))
{
version.WriteTo(writer);
}
......
......@@ -39,7 +39,7 @@ public DiagnosticDataSerializer(VersionStamp analyzerVersion, VersionStamp versi
public async Task<bool> SerializeAsync(object documentOrProject, string key, ImmutableArray<DiagnosticData> items, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
WriteTo(writer, items, cancellationToken);
......@@ -68,7 +68,7 @@ public async Task<StrongBox<ImmutableArray<DiagnosticData>>> DeserializeAsync(ob
return null;
}
using (var reader = new StreamObjectReader(stream))
using (var reader = new ObjectReader(stream))
{
// we return StrongBox rather than ImmutableArray due to task lib's issue with allocations
// when returning default(value type)
......
......@@ -47,7 +47,7 @@ public Checksum CreateChecksum(MetadataReference reference, CancellationToken ca
public Checksum CreateChecksum(AnalyzerReference reference, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
WriteTo(reference, writer, cancellationToken);
......@@ -180,7 +180,7 @@ private void WritePortableExecutableReferencePropertiesTo(PortableExecutableRefe
private Checksum CreatePortableExecutableReferenceChecksum(PortableExecutableReference reference, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
{
WritePortableExecutableReferencePropertiesTo(reference, writer, cancellationToken);
WriteMvidsTo(TryGetMetadata(reference), writer, cancellationToken);
......
......@@ -71,7 +71,7 @@ private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticA
using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_SerializeDiagnosticResultAsync, GetResultLogInfo, result, CancellationToken))
using (var stream = await DirectStream.GetAsync(streamName, CancellationToken).ConfigureAwait(false))
{
using (var writer = new StreamObjectWriter(stream))
using (var writer = new ObjectWriter(stream))
{
DiagnosticResultSerializer.Serialize(writer, result, CancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册