-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Remove syntax serialization logic. #70277
Changes from 26 commits
cb0102b
6fb6240
8839f7f
06a1674
bbbb772
377e4cf
8c3fe33
ab73f4d
265799a
77df906
9dcb386
7f9c2b9
8375ba6
b76ae85
66bb7ea
8af6459
26a3886
df13aa3
928db0d
cc33b1d
256e4d4
e095de0
a325c49
05638e1
3aea819
9f05fa7
a7af896
71e36d1
fb5acb1
137d60d
59dd654
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 |
---|---|---|
|
@@ -276,14 +276,11 @@ public static Diagnostic CreateWithMessage( | |
return $"https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/{id.ToLowerInvariant()}"; | ||
} | ||
|
||
public sealed class LocalizableStringWithArguments : LocalizableString, IObjectWritable | ||
public sealed class LocalizableStringWithArguments : LocalizableString | ||
{ | ||
private readonly LocalizableString _messageFormat; | ||
private readonly string[] _formatArguments; | ||
|
||
static LocalizableStringWithArguments() | ||
=> ObjectBinder.RegisterTypeReader(typeof(LocalizableStringWithArguments), reader => new LocalizableStringWithArguments(reader)); | ||
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. ObjectBinder.RegisterTypeReader was how types specified how they could be deseriealized. But it worked by registering a callback function at an index in an array, then emitting that array index into the serialized stream of bytes. this, of course, coudl not work across processes or across sessions as that index woudl never be the same. this is why this functionality is so practically useless. |
||
|
||
public LocalizableStringWithArguments(LocalizableString messageFormat, params object[] formatArguments) | ||
{ | ||
if (messageFormat == null) | ||
|
@@ -304,40 +301,6 @@ public LocalizableStringWithArguments(LocalizableString messageFormat, params ob | |
} | ||
} | ||
|
||
private LocalizableStringWithArguments(ObjectReader reader) | ||
{ | ||
_messageFormat = (LocalizableString)reader.ReadValue(); | ||
|
||
var length = reader.ReadInt32(); | ||
if (length == 0) | ||
{ | ||
_formatArguments = Array.Empty<string>(); | ||
} | ||
else | ||
{ | ||
using var _ = ArrayBuilder<string>.GetInstance(length, out var argumentsBuilder); | ||
for (var i = 0; i < length; i++) | ||
{ | ||
argumentsBuilder.Add(reader.ReadString()); | ||
} | ||
|
||
_formatArguments = argumentsBuilder.ToArray(); | ||
} | ||
} | ||
|
||
bool IObjectWritable.ShouldReuseInSerialization => false; | ||
|
||
void IObjectWritable.WriteTo(ObjectWriter writer) | ||
{ | ||
writer.WriteValue(_messageFormat); | ||
var length = _formatArguments.Length; | ||
writer.WriteInt32(length); | ||
for (var i = 0; i < length; i++) | ||
{ | ||
writer.WriteString(_formatArguments[i]); | ||
} | ||
} | ||
|
||
protected override string GetText(IFormatProvider? formatProvider) | ||
{ | ||
var messageFormat = _messageFormat.ToString(formatProvider); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,26 +14,14 @@ | |
|
||
namespace Microsoft.CodeAnalysis.CSharp | ||
{ | ||
internal sealed class MessageProvider : CommonMessageProvider, IObjectWritable | ||
internal sealed class MessageProvider : CommonMessageProvider | ||
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. MessageProvider is part of loc strings. Also doesn't need serialization now. |
||
{ | ||
public static readonly MessageProvider Instance = new MessageProvider(); | ||
|
||
static MessageProvider() | ||
{ | ||
ObjectBinder.RegisterTypeReader(typeof(MessageProvider), r => Instance); | ||
} | ||
|
||
private MessageProvider() | ||
{ | ||
} | ||
|
||
bool IObjectWritable.ShouldReuseInSerialization => true; | ||
|
||
void IObjectWritable.WriteTo(ObjectWriter writer) | ||
{ | ||
// write nothing, always read/deserialized as global Instance | ||
} | ||
|
||
public override DiagnosticSeverity GetSeverity(int code) | ||
{ | ||
return ErrorFacts.GetSeverity((ErrorCode)code); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,6 @@ namespace Microsoft.CodeAnalysis.CSharp | |
{ | ||
internal class SyntaxDiagnosticInfo : DiagnosticInfo | ||
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. diagnostic-infos are part of diagnostics. which no longer need to be serialized now. |
||
{ | ||
static SyntaxDiagnosticInfo() | ||
{ | ||
ObjectBinder.RegisterTypeReader(typeof(SyntaxDiagnosticInfo), r => new SyntaxDiagnosticInfo(r)); | ||
} | ||
|
||
internal readonly int Offset; | ||
internal readonly int Width; | ||
|
||
|
@@ -56,23 +51,5 @@ protected override DiagnosticInfo GetInstanceWithSeverityCore(DiagnosticSeverity | |
{ | ||
return new SyntaxDiagnosticInfo(this, severity); | ||
} | ||
|
||
#region Serialization | ||
|
||
protected override void WriteTo(ObjectWriter writer) | ||
{ | ||
base.WriteTo(writer); | ||
writer.WriteInt32(this.Offset); | ||
writer.WriteInt32(this.Width); | ||
} | ||
|
||
protected SyntaxDiagnosticInfo(ObjectReader reader) | ||
: base(reader) | ||
{ | ||
this.Offset = reader.ReadInt32(); | ||
this.Width = reader.ReadInt32(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,6 @@ namespace Microsoft.CodeAnalysis.CSharp | |
{ | ||
internal sealed class XmlSyntaxDiagnosticInfo : SyntaxDiagnosticInfo | ||
{ | ||
static XmlSyntaxDiagnosticInfo() | ||
{ | ||
ObjectBinder.RegisterTypeReader(typeof(XmlSyntaxDiagnosticInfo), r => new XmlSyntaxDiagnosticInfo(r)); | ||
} | ||
|
||
private readonly XmlParseErrorCode _xmlErrorCode; | ||
|
||
internal XmlSyntaxDiagnosticInfo(XmlParseErrorCode code, params object[] args) | ||
|
@@ -38,22 +33,6 @@ protected override DiagnosticInfo GetInstanceWithSeverityCore(DiagnosticSeverity | |
return new XmlSyntaxDiagnosticInfo(this, severity); | ||
} | ||
|
||
#region Serialization | ||
|
||
protected override void WriteTo(ObjectWriter writer) | ||
{ | ||
base.WriteTo(writer); | ||
writer.WriteUInt32((uint)_xmlErrorCode); | ||
} | ||
|
||
private XmlSyntaxDiagnosticInfo(ObjectReader reader) | ||
: base(reader) | ||
{ | ||
_xmlErrorCode = (XmlParseErrorCode)reader.ReadUInt32(); | ||
} | ||
|
||
#endregion | ||
|
||
public override string GetMessage(IFormatProvider? formatProvider = null) | ||
{ | ||
var culture = formatProvider as CultureInfo; | ||
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. writing this comment here above the generated file. THe generated file is where the buld of the deletion comes from as we no longer need to emit all that goop for syntax serialization. |
||
|
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.
IObjectWritable as a concept goes away. Instead of the serialization system taking in arbitrary objects, querying for that, and having that object then decide what to do, serialization is owned entirely on the outside by the objects, who just use our serialization system as a dumb stream wrapper to do things like write ints, bools, and strings to. Only basic constructs are supported (like primitive types, and arrays of types). Arbitrary object graphs are now handled by the caller (note: we have no such cases in roslyn anyways. it was only 'syntax' with its heterogenous graph structure).
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.
LocalizableStirng used to have to be serializable, because it was stored in diagnostics as the messages, and diagnostics were stored inside a tree for syntax errors, and as such needed to be serializable if we serialized the tree. Now that we no longer serialize trees, neither diagnostics nor locstrings need this functionality.