-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
First step of the replacement of Roslyn based ahead of time code generator with Mono.Cecil based post compiled time assembly modifier. #846
Conversation
If you want dotnet global tool, you can use MSPack.Processor.CLI. If you want core source code, you can use MSPack.Processor.Core.
I'm against any solution based on IL-rewriting. Across many years of .NET development, I've never seen an IL-rewriting tool that didn't corrupt the .dll in some way in some circumstances and I don't want to get stuck maintaining use of such a tool. I haven't reviewed the diff, @pCYSl5EDgo. Your PR description suggests several benefits and I'm wondering if/why switching to an IL-rewriter is necessary to get some of those benefits, or if we can still get them through mpc. |
The most successful IL-rewriter tool I've ever seen is the Burst Compiler. It forces very strict rules on the programmers in order not to emit invalid assembly. A few important benefits are inavailable without IL-rewriter tool(MSPack).
Other benefits are available by future mpc, Roslyn C# code generation.
|
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.
OK, well it seems interesting and I like how it removes the need to periodically generate source code. I don't like IL rewriting because whenever the compiler comes up with something new, IL rewriters tend to break (or remove the new thing from the rewritten assembly without warning).
But it appears this basically adds documentation and a hook for Unity. It doesn't remove mpc.
@neuecc is the mastermind behind mpc and unity support here, so he needs to approve too.
|
||
- Cannot serialize/deserialize generics types. | ||
- Cannot serialize/deserialize fixed size buffers. | ||
- Cannot serialize/deserialize private/internal members. |
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.
Does Unity even support IgnoresAccessChecksToAttribute
?
I think your mpcc is not meant to replace the mpc, but could be offered as another option. I'm looking forward to the code generation extensions in C# 9.0(?) code generation extensions in C# 9.0(?) and ( dotnet/csharplang#107 ) |
I have no doubt that there is bloated maintenance costs. I close this pull request. Thank you for your reviews and comments. |
Summary
This pull request consists of three commits.
mspc
dotnet global tool.Related Issues
Background
mpc
is Roslyn based ahead of time code generator.mpc analyzes C# source codes and generate a
formatter resolver
andformatter
s.mpc has some limitations and lacks of some features such as private/internal member access.
mspc
is Mono.Cecil based post compile time assembly modifier.mspc analyzes compiled managed assemblies.
mspc modifies
formatter resolver
and generatesformatter
s underformatter resolver
.mspc emits IL and utilize many optimization that cannot be done in C#.
What is changed in src/UnityClient
MSPack Unity editor extension hooks the build process after C# compilation and modifies dlls.
MSPack Unity editor extension is disabled by default. Click the
Window -> MessagePack -> MSPackCodeModifier
to enable MSPack Unity editor extension.MSPack Unity editor extension searches
formatter resolver
in Assembly-CSharp.dll and modifies first found type during building the player.Pros
Allow private/internal field/property serialization/deserialization.
mspc
analyze target input dll whether it has validIgnoresAccessChecksToAttribute
definition.If there is no definition,
mspc
defines it in target assembly.AllowPrivateFormatters can be generated by
mspc
.Decrease memory allocation of String-Key type formatter
Target type code is here.
`mpc` currently generates codes as belows.
`mspc` generates these classes as nested types of `formatter resolver`.
mspc
generated serialize method seems to allocate byte array but actually it does not allocate any new heap memory.Emitted IL shows actual behaviour.
Serialize/Deserialize backing field of auto-property directly
mspc
reads getter and setter method's IL instructions.If they match instruction of auto-property,
mspc
generates formatter which directly serialize/desrialize backing field.Serialize/Deserialize fixed size buffer of unsafe struct
Here is the sample target type.
Here is the disassembled formatter C# code generated by `mspc`.
Generics Support
Here is the sample target type.
mpc
cannot generate appropriate code for this target type.mpc
requiresClosed type
.Here is the disassembled formatter C# code generated by `mspc`.