Conversation
Co-authored-by: krishkat <krishna.kater@gmail.com>
| <UltraMessagePackTargetFrameworks>$(TargetFrameworks.Replace(';', ','))</UltraMessagePackTargetFrameworks> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <CompilerVisibleProperty Include="UltraMessagePackTargetFrameworks" /> | ||
| </ItemGroup> |
There was a problem hiding this comment.
These won't help users of your analyzer package as they're repo-local.
But you can define these inside your package's buildTransitive folder so that all consumers of your package get them too.
There was a problem hiding this comment.
Yes, of course it will be included when packaging. There are other projects that make things visible this way, so I don't think this itself is a problem.
|
From your PR description and a quick check of the code changes, it looks like you're declaring your
Is that correct? Reactions to this plan (if I'm right on above):
As we have agreed previously, I don't have to be comfortable with the plan. I just wanted you to be aware of the above for your consideration. |
|
Yes, this is a fairly unusual technique, and I completely understand the concern. You are correct on 1, 2, and 4. public static ImmutableArray<TResult> CreateRange<TSource, TArg, TResult>(ImmutableArray<TSource> items, Func<TSource, TArg, TResult> selector, TArg arg)
#if NET
where TArg : allows ref struct
#endifOf course, in this proposal the constraint sits on a public type, so the problems that can arise are different. On your reaction 1, it is safe in the sense that it's safe; whether it counts as expected behavior, hard to say. |
|
The compatibility issue has been resolved. |
This Round covers the target framework settings and the adjustments made for them.
As before, anything outside the items described below is off topic, so please save those discussions for another occasion.
We adopt
netstandard2.0,netstandard2.1, andnet10.0as the target frameworks.net10.0is the main target, andnetstandard2.1is for current Unity(Game Engine).Unity is netstandard2.1 / C# 9. Considering the LTS cycle, it will still be required for at least another two years.
netstandard2.0will mainly be for .NET Framework 4.8..NET 9 is an STS release that will reach End of Life around the time this library ships, so we start from .NET 10.
The library as a whole is built around
allows ref struct, in other words it assumes .NET 9 / C# 13.allows ref structinvolves not only the language but also the runtime, so it does not work on anything below .NET 9.The architectural focus is how to get through the transition period until everything is on .NET 9 / C# 13 or later.
This proposal is based on the premise that providing full compatibility is impossible, and that we make the best effort we can within that constraint.
Ideally, targeting only net10.0 would be the quickest path, but I want to avoid that, and I would ask you to understand that intent first.
For
allows ref structon each Formatter, we branch with#if....For ease of writing, a Source Generator is shipped alongside, and in most cases you can write it like this.
This Source Generator is used both for distribution and internally, referenced by the core library itself.
What needs careful attention is the compatibility problem.
We clarify the behavior when a 3rd party library built against netstandard2.1 is loaded in a net10 environment.
Regarding
IMessagePackFormatterFactory.CreateFormatter,a Generic Virtual Method causes a load-time error due to compatibility issues,
so for netstandard2.0 and 2.1 we define only the non-generic CreateFormatter.
On net10 the generic version is what will mainly be called, but for libraries built against netstandard2.1
we call the non-generic version through a default interface method.
As for formatter types, formatters defined against netstandard2.0 or 2.1
cannot be instantiated on the normal code path of net10.0 (the
ref structIWrite/ReadBuffer).In this case, the Resolver now throws a dedicated exception message saying the formatter does not support net10.0.
This compatibility problem comes from the existence of libraries defined only for netstandard2.0/2.1,
so as a countermeasure we prepared an Analyzer with the rule "if the TFMs include one that does not resolve to net10.0 (such as netstandard), then net10.0 must also be included".
Since v3, MessagePack ships with a Source Generator and Analyzer by default, so we want to make the checking mechanisms solid.
By taking countermeasures including the Analyzer from the start, we prevent net10.0 from being left out.
//
In addition,
IWriteBuffer/IReadBufferand their implementations were adjusted.These implementation types come in pairs, a
ref structversion and astructversion for environments whereallows ref structis not available.For the
structversion, we removed the internal use of Pin and adjusted it to avoid unsafe definitions as much as possible.Also, TWriteBuffer and TReadBuffer must not be copied, but there is no language mechanism to enforce this,
so as an initial defensive measure, the Analyzer detects copies of types that implement
IWriteBuffer / IReadBuffer.In addition, GetSpan/Advance now each independently detect out-of-range access.