Repository navigation
Fixes for type forwarders. - #2
Conversation
The changes in MarkStep.cs and SweepStep.cs are mostly from https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileMarkStep.cs#L33 and https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileSweepStep.cs#L45 . One additional line Annotations.Mark (assembly.MainModule); was added to MarkStep.Process(). The changes in ResolveFromXmlStep.cs are new and allow type forwarders to be specified in xml descriptors. The change in Mono.Linker.csproj allows opt-out from embedding the default xml descriptors.
|
Hi @erozenfeld, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
|
@marek-safar PTAL |
| if (!Annotations.IsMarked (type)) | ||
| continue; | ||
| Annotations.Mark (exported); | ||
| Annotations.Mark (assembly.MainModule); |
There was a problem hiding this comment.
What is the reasoning for adding this line?
There was a problem hiding this comment.
If a type forwarder needs to be kept, then the module/assembly containing the type forwarder also needs to be kept. In .NET Core we have some assemblies that only have type forwarders and we ran into a case where the assembly was incorrectly deleted.
There was a problem hiding this comment.
Thank you for the explanation. I run into similar issue and wasn't sure about the reasoning/history there.
I noticed it was even there in the original MonoTouchMarkStep.cs (https://github.com/xamarin/monotouch/commit/49fc552e1d43bc1dd39b3e12552d16cb9ac7dc53), but I am not sure why it was removed later (there were many moves of this code so it is not easy to follow)
There was a problem hiding this comment.
Found the commit where it was removed: https://github.com/xamarin/monotouch/commit/7c0e0a1df9276b52be92146ee2c7094167e4e2b4
There was a problem hiding this comment.
I'm getting 404 error trying to open xamarin/monotouch@7c0e0a1 . Is there an explanation in that commit of why the line was removed?
There was a problem hiding this comment.
The commit message is: Only mark the destnation (the type being forwarded to) not the origin. Allows competely removing System.Core (if no types are needed from it).
@spouliot do you remember why this change was made?
There was a problem hiding this comment.
I looked some more into code that deals with type forwarders. I believe the intention is that if nothing in an assembly is marked except type forwarders, then all references to the type forwarders in other assemblies should be resolved in SweepStep.SweepReferences and the assembly can be deleted. There is another piece of code in SweepStep.Process that resolves all references in Copy assemblies to make sure they don't have references to type forwarders in deleted assemblies.
I have some scenarios where I don't want this optimization to kick in and need to keep assemblies with type forwarders and not resolve references to them. So, I'll create another pull request where I will add a command line switch to disable this optimization. assembly.MainModule above will only be marked when the switch is passed. Likewise, the code resolving references in SweepStep.Process and SweepStep.SweepReferences will only run if the new switch is not passed.
There was a problem hiding this comment.
Right, things can be a bit easier for XI since we can assume there will be no code generation (or download) so the linker sees everything. That is not a correct assumption outside XI fullAOT compilation. That piece of code might be better left for XI (not mobile) alone - and not used in .net core.
There's also an issue in C9 (Cecil 0.10) where some Scope are not updated (on exported types). That did not happen with C8 (Cecil 0.9) but it might not be related to Cecil (I'm investigating this).
The linker had an optimization that removed assemblies that had only type forwarders referenced. dotnet#2 broke that optimization by adding a line that marked assembly.MainModule whenever a type forwarder was marked. This change introduces a new switch -t that controls this optimization. The optimization is on by default; if -t is specified, the optimization is disabled and assemblies with referenced type forwarders are kept. Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
The linker had an optimization that removed assemblies that had only type forwarders referenced. dotnet#2 broke that optimization by adding a line that marked assembly.MainModule whenever a type forwarder was marked. This change introduces a new switch -t that controls this optimization. The optimization is on by default; if -t is specified, the optimization is disabled and assemblies with referenced type forwarders are kept. Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
The linker had an optimization that removed assemblies that had only type forwarders referenced. dotnet#2 broke that optimization by adding a line that marked assembly.MainModule whenever a type forwarder was marked. This change introduces a new switch -t that controls this optimization. The optimization is on by default; if -t is specified, the optimization is disabled and assemblies with referenced type forwarders are kept. Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
The linker had an optimization that removed assemblies that had only type forwarders referenced. #2 broke that optimization by adding a line that marked assembly.MainModule whenever a type forwarder was marked. This change introduces a new switch -t that controls this optimization. The optimization is on by default; if -t is specified, the optimization is disabled and assemblies with referenced type forwarders are kept. Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
Add a sample about solving higher level APIs on the Lazy of T example
Add more functionality to Value Nodes
# This is the 1st commit message: Add Function to parse xml and return a list of injected attributes # This is the commit message #2: Finalize schema so all test xml is valid # This is the commit message dotnet#3: Add restrictions on some attributes and change uses of "nothing" to "none" # This is the commit message dotnet#4: Remove schema reference in generated file expectation
Fixes for type forwarders. Commit migrated from dotnet/linker@d57b8dd
The linker had an optimization that removed assemblies that had only type forwarders referenced. dotnet/linker#2 broke that optimization by adding a line that marked assembly.MainModule whenever a type forwarder was marked. This change introduces a new switch -t that controls this optimization. The optimization is on by default; if -t is specified, the optimization is disabled and assemblies with referenced type forwarders are kept. Additionally, this includes a change that marks all type forwarders in assemblies specified with -a. Commit migrated from dotnet/linker@b118b30
The changes in MarkStep.cs and SweepStep.cs are mostly from https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileMarkStep.cs#L33 and https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileSweepStep.cs#L45 . One additional line
Annotations.Mark (assembly.MainModule);
was added to MarkStep.Process().
The changes in ResolveFromXmlStep.cs are new and allow type forwarders to be specified in xml descriptors.
The change in Mono.Linker.csproj allows opt-out from embedding the default xml descriptors.