-
Notifications
You must be signed in to change notification settings - Fork 564
Update to new linker custom steps API #5748
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
9c3ffb9
Build locally against new IMarkHandler interface
sbomer 88a3607
Fix up custom steps
sbomer bac562c
Update to latest interface
sbomer 8fd0cb3
Cleanup
sbomer ab2949f
Remove unused code under defines
sbomer cc8a654
Fix whitespace
sbomer 5d8d897
Remove workaround
sbomer 6e941ee
Clean up targets
sbomer 05df054
Don't duplicate MonoDroid.Tuner steps
sbomer e90b93a
Use LinkContext's type resolve cache
sbomer 3dfe570
Undo TrimmerDefaultAction change
sbomer d6aaa38
PR feedback
sbomer 41de20f
PR feedback
sbomer e0c002e
PR feedback
sbomer f26d8dd
Don't pass --verbose argument
sbomer 3b616b6
Fix nullref in GenerateProguardConfiguration
sbomer cec24b8
Fix RemoveDesigner test
sbomer 3111a94
Fix typo
sbomer b1d9ec7
_CustomStepDll -> _AndroidLinkerCustomStepAssembly
sbomer b41545a
Fix code style
sbomer 5643dfa
Add BaseMarkHandler
sbomer 20d1ca6
Fix overrides
sbomer 3a1efaa
Subclass TypeDefinitionCache
sbomer 6bb719e
Merge remote-tracking branch 'origin/main' into illinkMarkHandler2
sbomer 1cc2d5a
Implement IMetadataResolver for LinkContextMetadataResolver
sbomer 67c9593
PR feedback
sbomer 01b56ec
Fix indentation
jonpryor 7c70a52
Fix indentation
jonpryor 6c6d4c8
Fix indentation
jonpryor d83a793
Fix indentation
jonpryor b13b50c
Add comment for why we're setting _TrimmerDumpDependencies
jonpryor 8b4c908
Fix indentation
jonpryor 7501a0c
Merge remote-tracking branch 'origin/main' into illinkMarkHandler2
jonpryor bda4b4f
Remove LinkContextMetadataResolver
sbomer ff9ea51
Remove reflection workaround
sbomer 742507a
Merge remote-tracking branch 'origin/main' into illinkMarkHandler2
sbomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
src/Microsoft.Android.Sdk.ILLink/LinkContextExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #nullable enable | ||
|
|
||
| using Mono.Cecil; | ||
| using Mono.Collections.Generic; | ||
| using Mono.Linker; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Android.Sdk.ILLink | ||
| { | ||
| public static class LinkContextExtensions | ||
| { | ||
| public static MethodDefinition GetBaseDefinition (this LinkContext context, MethodDefinition method) | ||
| { | ||
| if (method.IsStatic || method.IsNewSlot || !method.IsVirtual) | ||
| return method; | ||
|
|
||
| foreach (var baseType in context.GetBaseTypes (method.DeclaringType)) { | ||
| foreach (var m in baseType.Methods) { | ||
| if (!m.IsConstructor && | ||
| m.Name == method.Name && | ||
| (m.IsVirtual || m.IsAbstract) && | ||
| context.AreParametersCompatibleWith (m.Parameters, method.Parameters)) { | ||
sbomer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return m; | ||
| } | ||
| } | ||
| } | ||
| return method; | ||
| } | ||
|
|
||
| public static bool AreParametersCompatibleWith (this LinkContext context, Collection<ParameterDefinition> a, Collection<ParameterDefinition> b) | ||
| { | ||
| if (a.Count != b.Count) | ||
| return false; | ||
|
|
||
| if (a.Count == 0) | ||
| return true; | ||
|
|
||
| for (int i = 0; i < a.Count; i++) | ||
| if (!context.IsParameterCompatibleWith (a [i].ParameterType, b [i].ParameterType)) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static bool IsParameterCompatibleWith (this LinkContext context, IModifierType a, IModifierType b) | ||
| { | ||
| if (!context.IsParameterCompatibleWith (a.ModifierType, b.ModifierType)) | ||
| return false; | ||
|
|
||
| return context.IsParameterCompatibleWith (a.ElementType, b.ElementType); | ||
| } | ||
|
|
||
| static bool IsParameterCompatibleWith (this LinkContext context, TypeSpecification a, TypeSpecification b) | ||
| { | ||
| if (a is GenericInstanceType) | ||
| return context.IsParameterCompatibleWith ((GenericInstanceType) a, (GenericInstanceType) b); | ||
|
|
||
| if (a is IModifierType) | ||
| return context.IsParameterCompatibleWith ((IModifierType) a, (IModifierType) b); | ||
|
|
||
| return context.IsParameterCompatibleWith (a.ElementType, b.ElementType); | ||
| } | ||
|
|
||
| static bool IsParameterCompatibleWith (this LinkContext context, GenericInstanceType a, GenericInstanceType b) | ||
| { | ||
| if (!context.IsParameterCompatibleWith (a.ElementType, b.ElementType)) | ||
| return false; | ||
|
|
||
| if (a.GenericArguments.Count != b.GenericArguments.Count) | ||
| return false; | ||
|
|
||
| if (a.GenericArguments.Count == 0) | ||
| return true; | ||
|
|
||
| for (int i = 0; i < a.GenericArguments.Count; i++) | ||
| if (!context.IsParameterCompatibleWith (a.GenericArguments [i], b.GenericArguments [i])) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static bool IsParameterCompatibleWith (this LinkContext context, TypeReference a, TypeReference b) | ||
| { | ||
| if (a is TypeSpecification || b is TypeSpecification) { | ||
| if (a.GetType () != b.GetType ()) | ||
| return false; | ||
|
|
||
| return context.IsParameterCompatibleWith ((TypeSpecification) a, (TypeSpecification) b); | ||
| } | ||
|
|
||
| if (a.IsGenericParameter) { | ||
| if (b.IsGenericParameter && a.Name == b.Name) | ||
| return true; | ||
| var gpa = (GenericParameter) a; | ||
| foreach (var c in gpa.Constraints) { | ||
| if (!context.IsAssignableFrom (c.ConstraintType, b)) | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| return a.FullName == b.FullName; | ||
| } | ||
|
|
||
| public static TypeDefinition? GetBaseType (this LinkContext context, TypeDefinition type) | ||
| { | ||
| var bt = type.BaseType; | ||
| if (bt == null) | ||
| return null; | ||
| return context.ResolveTypeDefinition (bt); | ||
| } | ||
|
|
||
| public static IEnumerable<TypeDefinition> GetTypeAndBaseTypes (this LinkContext context, TypeDefinition type) | ||
| { | ||
| TypeDefinition? t = type; | ||
|
|
||
| while (t != null) { | ||
| yield return t; | ||
| t = context.GetBaseType (t); | ||
| } | ||
| } | ||
|
|
||
| public static IEnumerable<TypeDefinition> GetBaseTypes (this LinkContext context, TypeDefinition type) | ||
| { | ||
| TypeDefinition? t = type; | ||
|
|
||
| while ((t = context.GetBaseType (t)) != null) { | ||
| yield return t; | ||
| } | ||
| } | ||
|
|
||
| public static bool IsAssignableFrom (this LinkContext context, TypeReference type, TypeReference c) | ||
| { | ||
| if (type.FullName == c.FullName) | ||
| return true; | ||
| var d = context.TryResolveTypeDefinition (c); | ||
| if (d == null) | ||
| return false; | ||
| foreach (var t in context.GetTypeAndBaseTypes (d)) { | ||
| if (type.FullName == t.FullName) | ||
| return true; | ||
| foreach (var ifaceImpl in t.Interfaces) { | ||
| var i = ifaceImpl.InterfaceType; | ||
| if (context.IsAssignableFrom (type, i)) | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public static bool IsSubclassOf (this LinkContext context, TypeDefinition type, string typeName) | ||
| { | ||
| foreach (var t in context.GetTypeAndBaseTypes (type)) { | ||
| if (t.FullName == typeName) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Microsoft.Android.Sdk.ILLink/PreserveSubStepDispatcher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using Mono.Linker.Steps; | ||
| using Mono.Tuner; | ||
|
|
||
| namespace Microsoft.Android.Sdk.ILLink | ||
| { | ||
| public class PreserveSubStepDispatcher : MarkSubStepsDispatcher | ||
| { | ||
| public PreserveSubStepDispatcher () | ||
| : base (new ISubStep[] { | ||
| new ApplyPreserveAttribute (), | ||
| new PreserveExportedTypes () | ||
| }) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.