From c9fad94175b6b1d5686325cb96baaacc6f424257 Mon Sep 17 00:00:00 2001 From: maxim Date: Fri, 1 Apr 2022 19:01:45 +1300 Subject: [PATCH 01/23] Fix for "System.NotImplementedException: byref delegate" in System.Linq.Expressions for AOT compilation. --- .../MessagePack/MessagePackSerializer.NonGeneric.cs | 4 ++++ .../Scripts/MessagePack/MessagePackSerializer.cs | 12 ++++++++++++ .../MessagePack/MessagePackSerializerOptions.cs | 5 +++++ .../MessagePack/Resolvers/DynamicObjectResolver.cs | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs index 281e20f31..18c52d4e4 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs @@ -221,6 +221,7 @@ internal CompiledMethods(Type type) { // public static void Serialize(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options) MethodInfo serialize = GetMethod(nameof(Serialize), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), null, typeof(MessagePackSerializerOptions) }); + MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(Object), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Serialize_MessagePackWriter_T_Options = (ref MessagePackWriter x, object y, MessagePackSerializerOptions z) => ThrowRefStructNotSupported(); #else @@ -237,12 +238,14 @@ internal CompiledMethods(Type type) MessagePackWriterSerialize lambda = Expression.Lambda(body, param1, param2, param3).Compile(PreferInterpretation); this.Serialize_MessagePackWriter_T_Options = lambda; + this.Serialize_MessagePackWriter_T_Options = (MessagePackWriterSerialize)serialize.CreateDelegate(typeof(MessagePackWriterSerialize)); #endif } { // public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) MethodInfo deserialize = GetMethod(nameof(Deserialize), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); + MethodInfo deserialize = GetMethod(nameof(DeserializeSemiGeneric), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Deserialize_MessagePackReader_Options = (ref MessagePackReader reader, MessagePackSerializerOptions options) => { ThrowRefStructNotSupported(); return null; }; #else @@ -252,6 +255,7 @@ internal CompiledMethods(Type type) MessagePackReaderDeserialize lambda = Expression.Lambda(body, param1, param2).Compile(); this.Deserialize_MessagePackReader_Options = lambda; + this.Deserialize_MessagePackReader_Options = (MessagePackReaderDeserialize)deserialize.CreateDelegate(typeof(MessagePackReaderDeserialize)); #endif } diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index 0e0188cff..a4f902f59 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -66,6 +66,13 @@ public static void Serialize(IBufferWriter writer, T value, MessagePack /// The value to serialize. /// The options. Use null to use default options. /// Thrown when any error occurs during serialization. + internal static void SerializeSemiGeneric(ref MessagePackWriter writer, Object valueObject, MessagePackSerializerOptions options = null) + { + T value = (T)valueObject; + + Serialize(ref writer, value, options); + } + public static void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options = null) { options = options ?? DefaultOptions; @@ -220,6 +227,11 @@ public static T Deserialize(in ReadOnlySequence byteSequence, MessagePa /// The deserialized value. /// Thrown when any error occurs during deserialization. public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options = null) + { + return (T)DeserializeSemiGeneric(ref reader, options); + } + + internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) { options = options ?? DefaultOptions; diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs index ebf1ca43b..f31174557 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs @@ -29,6 +29,11 @@ public class MessagePackSerializerOptions }; #if !DYNAMICCODEDUMPER +#if DYNAMICCODEDUMPER + static readonly MessagePackSerializerOptions _standard = new MessagePackSerializerOptions(Resolvers.BuiltinResolver.Instance); + + public static MessagePackSerializerOptions Standard => _standard; +#else /// /// Gets a good default set of options that uses the and no compression. /// diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs index 52b92b0e4..643a6643b 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs @@ -1264,6 +1264,9 @@ void OnNotFound() il.Emit(OpCodes.Br, readNext); } +#if NET_STANDARD_2_0 + throw new NotImplementedException("NET_STANDARD_2_0 directive was used"); +#else if (canOverwrite) { automata.EmitMatch(il, buffer, longKey, OnFoundAssignDirect, OnNotFound); @@ -1272,6 +1275,7 @@ void OnNotFound() { automata.EmitMatch(il, buffer, longKey, OnFoundAssignLocalVariable, OnNotFound); } +#endif il.MarkLabel(readNext); reader.EmitLdarg(); From 7a4a9ef9fbe1d8eb2b9139afa10e6d8f691ff976 Mon Sep 17 00:00:00 2001 From: maxim Date: Tue, 28 Jun 2022 13:02:50 +1200 Subject: [PATCH 02/23] Several lines of code were deleted (which were not deleted in previous commit by some unknown accident). --- .../MessagePackSerializer.NonGeneric.cs | 21 ------------------- .../MessagePackSerializerOptions.cs | 1 - 2 files changed, 22 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs index 18c52d4e4..019eb8e78 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs @@ -220,41 +220,20 @@ internal CompiledMethods(Type type) { // public static void Serialize(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options) - MethodInfo serialize = GetMethod(nameof(Serialize), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), null, typeof(MessagePackSerializerOptions) }); MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(Object), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Serialize_MessagePackWriter_T_Options = (ref MessagePackWriter x, object y, MessagePackSerializerOptions z) => ThrowRefStructNotSupported(); #else - ParameterExpression param1 = Expression.Parameter(typeof(MessagePackWriter).MakeByRefType(), "writer"); - ParameterExpression param2 = Expression.Parameter(typeof(object), "obj"); - ParameterExpression param3 = Expression.Parameter(typeof(MessagePackSerializerOptions), "options"); - - MethodCallExpression body = Expression.Call( - null, - serialize, - param1, - ti.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type), - param3); - MessagePackWriterSerialize lambda = Expression.Lambda(body, param1, param2, param3).Compile(PreferInterpretation); - - this.Serialize_MessagePackWriter_T_Options = lambda; this.Serialize_MessagePackWriter_T_Options = (MessagePackWriterSerialize)serialize.CreateDelegate(typeof(MessagePackWriterSerialize)); #endif } { // public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) - MethodInfo deserialize = GetMethod(nameof(Deserialize), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); MethodInfo deserialize = GetMethod(nameof(DeserializeSemiGeneric), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Deserialize_MessagePackReader_Options = (ref MessagePackReader reader, MessagePackSerializerOptions options) => { ThrowRefStructNotSupported(); return null; }; #else - ParameterExpression param1 = Expression.Parameter(typeof(MessagePackReader).MakeByRefType(), "reader"); - ParameterExpression param2 = Expression.Parameter(typeof(MessagePackSerializerOptions), "options"); - UnaryExpression body = Expression.Convert(Expression.Call(null, deserialize, param1, param2), typeof(object)); - MessagePackReaderDeserialize lambda = Expression.Lambda(body, param1, param2).Compile(); - - this.Deserialize_MessagePackReader_Options = lambda; this.Deserialize_MessagePackReader_Options = (MessagePackReaderDeserialize)deserialize.CreateDelegate(typeof(MessagePackReaderDeserialize)); #endif } diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs index f31174557..bc1557b02 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs @@ -28,7 +28,6 @@ public class MessagePackSerializerOptions "System.Management.IWbemClassObjectFreeThreaded", }; -#if !DYNAMICCODEDUMPER #if DYNAMICCODEDUMPER static readonly MessagePackSerializerOptions _standard = new MessagePackSerializerOptions(Resolvers.BuiltinResolver.Instance); From ebb2040b53747eed245aa8afa133d102b3c14608 Mon Sep 17 00:00:00 2001 From: Gleb Lebedev Date: Wed, 29 Jun 2022 12:34:19 +0100 Subject: [PATCH 03/23] Skip type collection if property has MessagePackFormatterAttribute --- .../CodeAnalysis/TypeCollector.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs b/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs index 935ceb871..eeedbdadc 100644 --- a/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs +++ b/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs @@ -720,7 +720,12 @@ private ObjectSerializationInfo GetObjectInfo(INamedTypeSymbol type) stringMembers.Add(member.StringKey, member); } - this.CollectCore(item.Type); // recursive collect + var messagePackFormatter = item.GetAttributes().FirstOrDefault(x => x.AttributeClass.ApproximatelyEqual(this.typeReferences.MessagePackFormatterAttribute))?.ConstructorArguments[0]; + + if (messagePackFormatter == null) + { + this.CollectCore(item.Type); // recursive collect + } } foreach (IFieldSymbol item in type.GetAllMembers().OfType()) From 3cd55341c145b01fb4087aa4f407995533d732c0 Mon Sep 17 00:00:00 2001 From: maxim Date: Sun, 3 Jul 2022 20:03:26 +1200 Subject: [PATCH 04/23] Changes to fixx issues to pass CI build pipeline. --- .../MessagePack/MessagePackSerializer.cs | 24 +++++++++---------- .../MessagePackSerializerOptions.cs | 6 +---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index f3773f700..4348e4c3d 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -71,13 +71,6 @@ public static void Serialize(IBufferWriter writer, T value, MessagePack fastWriter.Flush(); } - /// - /// Serializes a given value with the specified buffer writer. - /// - /// The buffer writer to serialize with. - /// The value to serialize. - /// The options. Use null to use default options. - /// Thrown when any error occurs during serialization. internal static void SerializeSemiGeneric(ref MessagePackWriter writer, Object valueObject, MessagePackSerializerOptions options = null) { T value = (T)valueObject; @@ -85,6 +78,13 @@ internal static void SerializeSemiGeneric(ref MessagePackWriter writer, Objec Serialize(ref writer, value, options); } + /// + /// Serializes a given value with the specified buffer writer. + /// + /// The buffer writer to serialize with. + /// The value to serialize. + /// The options. Use null to use default options. + /// Thrown when any error occurs during serialization. public static void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options = null) { options = options ?? DefaultOptions; @@ -239,11 +239,6 @@ public static T Deserialize(in ReadOnlySequence byteSequence, MessagePa /// The deserialized value. /// Thrown when any error occurs during deserialization. public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options = null) - { - return (T)DeserializeSemiGeneric(ref reader, options); - } - - internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) { options = options ?? DefaultOptions; @@ -276,6 +271,11 @@ internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, M } } + internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) + { + return DeserializeSemiGeneric(ref reader, options); + } + /// /// Deserializes a value of a given type from a sequence of bytes. /// diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs index de2bb4b8e..a9a9ec515 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs @@ -28,11 +28,7 @@ public class MessagePackSerializerOptions "System.Management.IWbemClassObjectFreeThreaded", }; -#if DYNAMICCODEDUMPER - static readonly MessagePackSerializerOptions _standard = new MessagePackSerializerOptions(Resolvers.BuiltinResolver.Instance); - - public static MessagePackSerializerOptions Standard => _standard; -#else +#if !DYNAMICCODEDUMPER /// /// Gets a good default set of options that uses the and no compression. /// From 287c4f7a7a2d6f93d98bd143cb7578cd9ea204da Mon Sep 17 00:00:00 2001 From: maxim Date: Sun, 3 Jul 2022 20:26:50 +1200 Subject: [PATCH 05/23] Small bug fix --- .../Assets/Scripts/MessagePack/MessagePackSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index 4348e4c3d..9510ea893 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -273,7 +273,7 @@ public static T Deserialize(ref MessagePackReader reader, MessagePackSerializ internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) { - return DeserializeSemiGeneric(ref reader, options); + return Deserialize(ref reader, options); } /// From eb6b93bb63794566ebb4d36e37ea173782851c79 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 23 Jul 2022 08:03:47 -0600 Subject: [PATCH 06/23] Revise the fix slightly --- .../MessagePackSerializer.NonGeneric.cs | 22 ++++++++++++++++--- .../MessagePack/MessagePackSerializer.cs | 12 ---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs index 019eb8e78..bd6f9b431 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs @@ -82,6 +82,22 @@ public static object Deserialize(Type type, ReadOnlySequence bytes, Messag return GetOrAdd(type).Deserialize_ReadOnlySequence_Options_CancellationToken.Invoke(bytes, options, cancellationToken); } + /// + /// Helper method used by reflection. + /// + private static void SerializeSemiGeneric(ref MessagePackWriter writer, object valueObject, MessagePackSerializerOptions options = null) + { + Serialize(ref writer, (T)valueObject, options); + } + + /// + /// Helper method used by reflection. + /// + private static object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) + { + return Deserialize(ref reader, options); + } + private static async ValueTask DeserializeObjectAsync(Stream stream, MessagePackSerializerOptions options, CancellationToken cancellationToken) => await DeserializeAsync(stream, options, cancellationToken).ConfigureAwait(false); private static CompiledMethods GetOrAdd(Type type) @@ -219,8 +235,8 @@ internal CompiledMethods(Type type) } { - // public static void Serialize(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options) - MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(Object), typeof(MessagePackSerializerOptions) }); + // private static void SerializeSemiGeneric(ref MessagePackWriter writer, object obj, MessagePackSerializerOptions options) + MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(object), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Serialize_MessagePackWriter_T_Options = (ref MessagePackWriter x, object y, MessagePackSerializerOptions z) => ThrowRefStructNotSupported(); #else @@ -229,7 +245,7 @@ internal CompiledMethods(Type type) } { - // public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + // private static object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options) MethodInfo deserialize = GetMethod(nameof(DeserializeSemiGeneric), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Deserialize_MessagePackReader_Options = (ref MessagePackReader reader, MessagePackSerializerOptions options) => { ThrowRefStructNotSupported(); return null; }; diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index 9510ea893..8c4a454c6 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -71,13 +71,6 @@ public static void Serialize(IBufferWriter writer, T value, MessagePack fastWriter.Flush(); } - internal static void SerializeSemiGeneric(ref MessagePackWriter writer, Object valueObject, MessagePackSerializerOptions options = null) - { - T value = (T)valueObject; - - Serialize(ref writer, value, options); - } - /// /// Serializes a given value with the specified buffer writer. /// @@ -271,11 +264,6 @@ public static T Deserialize(ref MessagePackReader reader, MessagePackSerializ } } - internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) - { - return Deserialize(ref reader, options); - } - /// /// Deserializes a value of a given type from a sequence of bytes. /// From 1092f85b68ceff6667eadf43081097e02adb77c8 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 2 Aug 2022 07:10:46 -0600 Subject: [PATCH 07/23] Fix PerBenchmarkDotNet project This has evidently been broken since I regressed it in 5c0220eecc34. --- .../MessagePackWriterBenchmark.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sandbox/PerfBenchmarkDotNet/MessagePackWriterBenchmark.cs b/sandbox/PerfBenchmarkDotNet/MessagePackWriterBenchmark.cs index 8afaccc14..64e7c89a3 100644 --- a/sandbox/PerfBenchmarkDotNet/MessagePackWriterBenchmark.cs +++ b/sandbox/PerfBenchmarkDotNet/MessagePackWriterBenchmark.cs @@ -13,7 +13,7 @@ namespace PerfBenchmarkDotNet { [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] - public sealed class MessagePackWriterBenchmark : IDisposable + public class MessagePackWriterBenchmark : IDisposable { private const int RepsOverArray = 300 * 1024; private readonly Sequence sequence = new Sequence(); @@ -152,7 +152,16 @@ public void WriteString() public void Dispose() { - this.sequence.Dispose(); + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + this.sequence.Dispose(); + } } } } From 37e2dbc2420e13f5b70f4d38bdb0457dfc191146 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 2 Aug 2022 08:32:40 -0600 Subject: [PATCH 08/23] Add non-generic serialize/deserialize perf tests --- sandbox/PerfBenchmarkDotNet/DeserializeBenchmark.cs | 8 +++++++- sandbox/PerfBenchmarkDotNet/SerializeBenchmark.cs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sandbox/PerfBenchmarkDotNet/DeserializeBenchmark.cs b/sandbox/PerfBenchmarkDotNet/DeserializeBenchmark.cs index 3c0ef2f29..68af163a9 100644 --- a/sandbox/PerfBenchmarkDotNet/DeserializeBenchmark.cs +++ b/sandbox/PerfBenchmarkDotNet/DeserializeBenchmark.cs @@ -1,4 +1,4 @@ -// Copyright (c) All contributors. All rights reserved. +// Copyright (c) All contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. extern alias newmsgpack; @@ -60,6 +60,12 @@ public IntKeySerializerTarget IntKey() return newmsgpack.MessagePack.MessagePackSerializer.Deserialize(intObj); } + [Benchmark] + public IntKeySerializerTarget IntKey_NonGeneric() + { + return (IntKeySerializerTarget)newmsgpack.MessagePack.MessagePackSerializer.Deserialize(typeof(IntKeySerializerTarget), intObj); + } + [Benchmark] public StringKeySerializerTarget StringKey() { diff --git a/sandbox/PerfBenchmarkDotNet/SerializeBenchmark.cs b/sandbox/PerfBenchmarkDotNet/SerializeBenchmark.cs index 0ed114b06..fc9a3a06d 100644 --- a/sandbox/PerfBenchmarkDotNet/SerializeBenchmark.cs +++ b/sandbox/PerfBenchmarkDotNet/SerializeBenchmark.cs @@ -1,4 +1,4 @@ -// Copyright (c) All contributors. All rights reserved. +// Copyright (c) All contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. extern alias newmsgpack; @@ -35,6 +35,12 @@ public byte[] IntKey() return newmsgpack.MessagePack.MessagePackSerializer.Serialize(intData); } + [Benchmark] + public byte[] IntKey_NonGeneric() + { + return newmsgpack.MessagePack.MessagePackSerializer.Serialize(typeof(IntKeySerializerTarget), intData); + } + [Benchmark] public byte[] StringKey() { From 0eccfe506044da8d1a1ca2ca3d4270d6c8e319d2 Mon Sep 17 00:00:00 2001 From: Oleksii Kharkov Date: Fri, 12 Aug 2022 15:40:34 +0300 Subject: [PATCH 09/23] Bug with long & double is fixed. There was a bug, which produced "System.OverflowException: Arithmetic operation resulted in an overflow". --- .../Assets/Scripts/MessagePack/SafeBitConverter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/SafeBitConverter.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/SafeBitConverter.cs index 7eb77a006..8bbc141a9 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/SafeBitConverter.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/SafeBitConverter.cs @@ -13,15 +13,15 @@ internal static long ToInt64(ReadOnlySpan value) #if UNITY_ANDROID if (BitConverter.IsLittleEndian) { - int i1 = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); - int i2 = value[4] | (value[5] << 8) | (value[6] << 16) | (value[7] << 24); - return (uint)i1 | ((long)i2 << 32); + long i1 = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); + long i2 = value[4] | (value[5] << 8) | (value[6] << 16) | (value[7] << 24); + return i1 | (i2 << 32); } else { - int i1 = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3]; - int i2 = (value[4] << 24) | (value[5] << 16) | (value[6] << 8) | value[7]; - return (uint)i2 | ((long)i1 << 32); + long i1 = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3]; + long i2 = (value[4] << 24) | (value[5] << 16) | (value[6] << 8) | value[7]; + return i2 | (i1 << 32); } #else return MemoryMarshal.Cast(value)[0]; From 615d9494c8795052df21a2b8d1b6cc28ee378f79 Mon Sep 17 00:00:00 2001 From: petris Date: Fri, 19 Aug 2022 23:23:10 +0200 Subject: [PATCH 10/23] Enable SPAN_BUILTIN code for Unity 2021.2+ --- .../Scripts/MessagePack/Formatters/StringInterningFormatter.cs | 2 +- .../Assets/Scripts/MessagePack/StreamPolyfillExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StringInterningFormatter.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StringInterningFormatter.cs index 9e07521b7..6839f5a30 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StringInterningFormatter.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StringInterningFormatter.cs @@ -31,7 +31,7 @@ public string Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt Span chars = stackalloc char[bytes.Length]; int charLength; -#if SPAN_BUILTIN +#if SPAN_BUILTIN || UNITY_2021_2_OR_NEWER charLength = StringEncoding.UTF8.GetChars(bytes, chars); #else unsafe diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/StreamPolyfillExtensions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/StreamPolyfillExtensions.cs index 2b6222c89..83389cec2 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/StreamPolyfillExtensions.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/StreamPolyfillExtensions.cs @@ -13,7 +13,7 @@ namespace MessagePack { -#if !SPAN_BUILTIN +#if !SPAN_BUILTIN && !UNITY_2021_2_OR_NEWER internal static class StreamPolyfillExtensions { /// From 164a2bd266c313dc03f7c794471ce0051217a2d0 Mon Sep 17 00:00:00 2001 From: Iman Navidi Date: Thu, 25 Aug 2022 16:31:38 +0430 Subject: [PATCH 11/23] removing extra double quotation mark --- .../Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs index 38e39985d..877109d6f 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs @@ -432,7 +432,7 @@ private static void ToJsonCore(ref MessagePackReader reader, TextWriter writer, } else { - writer.Write("{\"$type\":\"" + typeNameTokenBuilder.ToString() + "}"); + writer.Write("{\"$type\":" + typeNameTokenBuilder.ToString() + "}"); } } #endif From f42870232c04383ccbc28e885abce2a09e9beff5 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 9 Sep 2022 08:41:14 -0600 Subject: [PATCH 12/23] Improve error messages in exceptions thrown from `PrimitiveObjectFormatter` --- .../Formatters/PrimitiveObjectFormatter.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/PrimitiveObjectFormatter.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/PrimitiveObjectFormatter.cs index 7cf007ea1..298efd0f5 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/PrimitiveObjectFormatter.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/PrimitiveObjectFormatter.cs @@ -4,7 +4,7 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Net.Security; +using System.Globalization; using System.Reflection; namespace MessagePack.Formatters @@ -202,9 +202,7 @@ public void Serialize(ref MessagePackWriter writer, object value, MessagePackSer public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { - MessagePackType type = reader.NextMessagePackType; - IFormatterResolver resolver = options.Resolver; - switch (type) + switch (reader.NextMessagePackType) { case MessagePackType.Integer: var code = reader.NextCode; @@ -249,7 +247,7 @@ public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt return reader.ReadUInt64(); } - throw new MessagePackSerializationException("Invalid primitive bytes."); + throw new MessagePackSerializationException(string.Format(CultureInfo.CurrentCulture, "Unrecognized primitive code 0x{0:x2} for integer type.", code)); case MessagePackType.Boolean: return reader.ReadBoolean(); case MessagePackType.Float: @@ -269,12 +267,12 @@ public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt return reader.ReadBytes()?.ToArray(); case MessagePackType.Extension: ExtensionHeader ext = reader.ReadExtensionFormatHeader(); - if (ext.TypeCode == ReservedMessagePackExtensionTypeCode.DateTime) + switch (ext.TypeCode) { - return reader.ReadDateTime(ext); + case ReservedMessagePackExtensionTypeCode.DateTime: return reader.ReadDateTime(ext); + default: throw new MessagePackSerializationException(string.Format(CultureInfo.CurrentCulture, "Extension type code 0x{0:x2} is not supported by the {1}.", ext.TypeCode, nameof(PrimitiveObjectFormatter))); } - throw new MessagePackSerializationException("Invalid primitive bytes."); case MessagePackType.Array: { var length = reader.ReadArrayHeader(); @@ -283,7 +281,7 @@ public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt return Array.Empty(); } - IMessagePackFormatter objectFormatter = resolver.GetFormatter(); + IMessagePackFormatter objectFormatter = options.Resolver.GetFormatter(); var array = new object[length]; options.Security.DepthStep(ref reader); try @@ -320,7 +318,7 @@ public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt reader.ReadNil(); return null; default: - throw new MessagePackSerializationException("Invalid primitive bytes."); + throw new MessagePackSerializationException(string.Format(CultureInfo.CurrentCulture, "Unrecognized code: 0x{0:X2}.", reader.NextCode)); } } From 02c28ce1702c3ed08cc8808073cd522c1b2f9086 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 20 Sep 2022 08:00:47 -0600 Subject: [PATCH 13/23] Close stale issues as 'not planned' --- .github/workflows/stale.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index e625d1164..1c28881b0 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/stale@v1 + - uses: actions/stale@v5.2.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 90 @@ -21,3 +21,5 @@ jobs: stale-pr-message: 'This pull request is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.' stale-pr-label: 'no-pr-activity' exempt-pr-label: 'awaiting-approval' + close-issue-reason: not_planned + From 164e775a4446075245a74c0d5449ddd3f1c2b870 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 20 Sep 2022 08:02:45 -0600 Subject: [PATCH 14/23] Allow manual triggering of the stale workflow --- .github/workflows/stale.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 1c28881b0..a43ba9ed4 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -3,6 +3,7 @@ name: Mark stale issues and pull requests on: schedule: - cron: "0 0 * * *" + workflow_dispatch: jobs: stale: From 8295c968db3fbc31654e93e25499bdc68da5c8cf Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 20 Sep 2022 08:05:43 -0600 Subject: [PATCH 15/23] Update workflow inputs --- .github/workflows/stale.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index a43ba9ed4..27e7f9cf0 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -18,9 +18,9 @@ jobs: days-before-close: 5 stale-issue-message: 'This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.' stale-issue-label: 'no-issue-activity' - exempt-issue-label: 'awaiting-approval' + exempt-issue-labels: awaiting-approval stale-pr-message: 'This pull request is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.' stale-pr-label: 'no-pr-activity' - exempt-pr-label: 'awaiting-approval' + exempt-pr-labels: awaiting-approval close-issue-reason: not_planned From fec0f19d7254fbd3ff40b32dafd86dbe41805749 Mon Sep 17 00:00:00 2001 From: Vitalii Zabrodin Date: Wed, 5 Oct 2022 23:43:12 +0300 Subject: [PATCH 16/23] Fix ASP.NET Core output formatter to support null ObjectType --- .../MessagePackOutputFormatter.cs | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs b/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs index 409981148..9dd8c0750 100644 --- a/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs +++ b/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs @@ -25,42 +25,40 @@ public MessagePackOutputFormatter(MessagePackSerializerOptions options) public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) { - if (context.ObjectType == typeof(object)) + if (context.Object == null) { - if (context.Object == null) - { #if NETSTANDARD2_0 + context.HttpContext.Response.Body.WriteByte(MessagePackCode.Nil); + return Task.CompletedTask; +#else + var writer = context.HttpContext.Response.BodyWriter; + if (writer == null) + { context.HttpContext.Response.Body.WriteByte(MessagePackCode.Nil); return Task.CompletedTask; -#else - var writer = context.HttpContext.Response.BodyWriter; - if (writer == null) - { - context.HttpContext.Response.Body.WriteByte(MessagePackCode.Nil); - return Task.CompletedTask; - } + } - var span = writer.GetSpan(1); - span[0] = MessagePackCode.Nil; - writer.Advance(1); - return writer.FlushAsync().AsTask(); + var span = writer.GetSpan(1); + span[0] = MessagePackCode.Nil; + writer.Advance(1); + return writer.FlushAsync().AsTask(); #endif - } - else - { + } + + if (context.ObjectType == null || context.ObjectType == typeof(object)) + { #if NETSTANDARD2_0 - return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); + return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); #else - var writer = context.HttpContext.Response.BodyWriter; - if (writer == null) - { - return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); - } + var writer = context.HttpContext.Response.BodyWriter; + if (writer == null) + { + return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); + } - MessagePackSerializer.Serialize(context.Object.GetType(), writer, context.Object, this.options, context.HttpContext.RequestAborted); - return writer.FlushAsync().AsTask(); + MessagePackSerializer.Serialize(context.Object.GetType(), writer, context.Object, this.options, context.HttpContext.RequestAborted); + return writer.FlushAsync().AsTask(); #endif - } } else { From 87fd1d1915844692a2c29d5f40780177d7f3f177 Mon Sep 17 00:00:00 2001 From: Vitalii Zabrodin Date: Wed, 5 Oct 2022 23:44:59 +0300 Subject: [PATCH 17/23] Refactor ASP.NET Core output formatter --- .../MessagePackOutputFormatter.cs | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs b/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs index 9dd8c0750..222422a96 100644 --- a/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs +++ b/src/MessagePack.AspNetCoreMvcFormatter/MessagePackOutputFormatter.cs @@ -44,34 +44,19 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) return writer.FlushAsync().AsTask(); #endif } - - if (context.ObjectType == null || context.ObjectType == typeof(object)) - { -#if NETSTANDARD2_0 - return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); -#else - var writer = context.HttpContext.Response.BodyWriter; - if (writer == null) - { - return MessagePackSerializer.SerializeAsync(context.Object.GetType(), context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); - } - - MessagePackSerializer.Serialize(context.Object.GetType(), writer, context.Object, this.options, context.HttpContext.RequestAborted); - return writer.FlushAsync().AsTask(); -#endif - } else { + var objectType = context.ObjectType == null || context.ObjectType == typeof(object) ? context.Object.GetType() : context.ObjectType; #if NETSTANDARD2_0 - return MessagePackSerializer.SerializeAsync(context.ObjectType, context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); + return MessagePackSerializer.SerializeAsync(objectType, context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); #else var writer = context.HttpContext.Response.BodyWriter; if (writer == null) { - return MessagePackSerializer.SerializeAsync(context.ObjectType, context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); + return MessagePackSerializer.SerializeAsync(objectType, context.HttpContext.Response.Body, context.Object, this.options, context.HttpContext.RequestAborted); } - MessagePackSerializer.Serialize(context.ObjectType, writer, context.Object, this.options, context.HttpContext.RequestAborted); + MessagePackSerializer.Serialize(objectType, writer, context.Object, this.options, context.HttpContext.RequestAborted); return writer.FlushAsync().AsTask(); #endif } From 5b802812e6e0291f76725b990ef18685af0af59e Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 10 Oct 2022 08:34:01 -0600 Subject: [PATCH 18/23] Update Microsoft.NET.StringTools dependency to 17.3.1 --- sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj | 2 +- src/MessagePack/MessagePack.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj b/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj index 0daf9da44..6d0c4cdec 100644 --- a/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj +++ b/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj @@ -144,6 +144,6 @@ - + diff --git a/src/MessagePack/MessagePack.csproj b/src/MessagePack/MessagePack.csproj index 801ab7de1..6dc057b89 100644 --- a/src/MessagePack/MessagePack.csproj +++ b/src/MessagePack/MessagePack.csproj @@ -34,7 +34,7 @@ - + From 5a138c417afdf891358e4885c0f81fca3fa032bd Mon Sep 17 00:00:00 2001 From: Tatsuya Honda Date: Sat, 19 Nov 2022 23:39:37 +0900 Subject: [PATCH 19/23] fix duplicate registration of named tuples (#1464) * fix duplicate registration of named tuples * fix: avoid unnecessary conversion --- .../CodeAnalysis/TypeCollector.cs | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs b/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs index eeedbdadc..da68130aa 100644 --- a/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs +++ b/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs @@ -252,12 +252,15 @@ public class TypeCollector private readonly List collectedGenericInfo = new(); private readonly List collectedUnionInfo = new(); + private readonly Compilation compilation; + public TypeCollector(Compilation compilation, bool disallowInternal, bool isForceUseMap, string[]? ignoreTypeNames, Action logger) { this.typeReferences = new ReferenceSymbols(compilation, logger); this.disallowInternal = disallowInternal; this.isForceUseMap = isForceUseMap; this.externalIgnoreTypeNames = new HashSet(ignoreTypeNames ?? Array.Empty()); + this.compilation = compilation; targetTypes = compilation.GetNamedTypeSymbols() .Where(x => @@ -329,7 +332,7 @@ private void CollectCore(ITypeSymbol typeSymbol) if (typeSymbol is IArrayTypeSymbol arrayTypeSymbol) { - this.CollectArray(arrayTypeSymbol); + this.CollectArray((IArrayTypeSymbol)ToTupleUnderlyingType(arrayTypeSymbol)); return; } @@ -357,13 +360,7 @@ private void CollectCore(ITypeSymbol typeSymbol) if (type.IsGenericType) { - this.CollectGeneric(type); - return; - } - - if (type.TupleUnderlyingType != null) - { - CollectGeneric(type.TupleUnderlyingType); + this.CollectGeneric((INamedTypeSymbol)ToTupleUnderlyingType(type)); return; } @@ -459,6 +456,28 @@ private void CollectArray(IArrayTypeSymbol array) this.collectedGenericInfo.Add(info); } + private ITypeSymbol ToTupleUnderlyingType(ITypeSymbol typeSymbol) + { + if (typeSymbol is IArrayTypeSymbol array) + { + return compilation.CreateArrayTypeSymbol(ToTupleUnderlyingType(array.ElementType), array.Rank); + } + + if (typeSymbol is not INamedTypeSymbol namedType || !namedType.IsGenericType) + { + return typeSymbol; + } + + namedType = namedType.TupleUnderlyingType ?? namedType; + var newTypeArguments = namedType.TypeArguments.Select(ToTupleUnderlyingType).ToArray(); + if (!namedType.TypeArguments.SequenceEqual(newTypeArguments)) + { + return namedType.ConstructedFrom.Construct(newTypeArguments); + } + + return namedType; + } + private void CollectGeneric(INamedTypeSymbol type) { INamedTypeSymbol genericType = type.ConstructUnboundGenericType(); From 93f938d362bebb15bce5aff047d01bf4ea04838b Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 19 Nov 2022 07:49:44 -0700 Subject: [PATCH 20/23] Fix null param check in `StaticCompositeResolver` Fixes #1523 --- .../Scripts/MessagePack/Resolvers/StaticCompositeResolver.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/StaticCompositeResolver.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/StaticCompositeResolver.cs index ba0084c59..8d8037bc2 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/StaticCompositeResolver.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/StaticCompositeResolver.cs @@ -8,7 +8,7 @@ namespace MessagePack.Resolvers { /// - /// Singleton version of CompositeResolver, which be able to register a collection of formatters and resolvers to a single instance. + /// Singleton version of , which can register a collection of formatters and resolvers to a single instance. /// public class StaticCompositeResolver : IFormatterResolver { @@ -40,7 +40,7 @@ public void Register(params IMessagePackFormatter[] formatters) throw new InvalidOperationException("Register must call on startup(before use GetFormatter)."); } - if (this.formatters is null) + if (formatters is null) { throw new ArgumentNullException(nameof(formatters)); } From c972b170d1d8c50c269034d0778a2af4bdcb4cdc Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 19 Nov 2022 08:15:47 -0700 Subject: [PATCH 21/23] Update to 17.4.0 to fix break --- sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj | 2 +- src/MessagePack/MessagePack.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj b/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj index 6d0c4cdec..6f68213f6 100644 --- a/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj +++ b/sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj @@ -144,6 +144,6 @@ - + diff --git a/src/MessagePack/MessagePack.csproj b/src/MessagePack/MessagePack.csproj index 6dc057b89..762888bec 100644 --- a/src/MessagePack/MessagePack.csproj +++ b/src/MessagePack/MessagePack.csproj @@ -34,7 +34,7 @@ - + From 0c41ccb0a0ee52a4c9c02c38221d87172c077798 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 19 Nov 2022 08:36:30 -0700 Subject: [PATCH 22/23] Add incremental build support to MessagePack.MSBuild.Tasks Fixes #1526 --- .../MessagePackGenerator.cs | 7 +------ .../build/MessagePack.MSBuild.Tasks.targets | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs index a3766024a..0e9f3e727 100644 --- a/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs +++ b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs @@ -28,7 +28,7 @@ public class MessagePackGenerator : Microsoft.Build.Utilities.Task, ICancelableT public ITaskItem[] Compile { get; set; } = null!; [Required] - public string IntermediateOutputPath { get; set; } = null!; + public string GeneratedOutputPath { get; set; } = null!; [Required] public ITaskItem[] ReferencePath { get; set; } = null!; @@ -44,9 +44,6 @@ public class MessagePackGenerator : Microsoft.Build.Utilities.Task, ICancelableT public string[]? ExternalIgnoreTypeNames { get; set; } - [Output] - public string? GeneratedOutputPath { get; set; } - internal CancellationToken CancellationToken => this.cts.Token; public void Cancel() => this.cts.Cancel(); @@ -59,8 +56,6 @@ public override bool Execute() return false; } - this.GeneratedOutputPath = Path.Combine(this.IntermediateOutputPath, GeneratedFileName); - try { var compilation = this.CreateCompilation(); diff --git a/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBuild.Tasks.targets b/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBuild.Tasks.targets index 554bc7f42..e95cf9e90 100644 --- a/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBuild.Tasks.targets +++ b/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBuild.Tasks.targets @@ -1,21 +1,28 @@  + + $(IntermediateOutputPath)mpc_generated.cs + + + + + + + DependsOnTargets="ResolveReferences" + Inputs="@(Compile)" + Outputs="$(GeneratedMessagePackFile)"> - - - + /> From d532384bee34649bfda4d98dd8f620c6c1789086 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 19 Nov 2022 13:09:02 -0700 Subject: [PATCH 23/23] Remove dead constant --- src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs index 0e9f3e727..69d8f23e5 100644 --- a/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs +++ b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs @@ -20,8 +20,6 @@ namespace MessagePack.MSBuild.Tasks { public class MessagePackGenerator : Microsoft.Build.Utilities.Task, ICancelableTask { - private const string GeneratedFileName = "mpc_generated.cs"; - private readonly CancellationTokenSource cts = new CancellationTokenSource(); [Required]