-
Notifications
You must be signed in to change notification settings - Fork 576
[linker] Trim Export attributes after registration. #26313
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
Open
rolfbjarne
wants to merge
6
commits into
main
Choose a base branch
from
dev/rolf/dev-rolf-remove-export-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cee506
[linker] Trim Export attributes after registration
rolfbjarne 788b5ab
[tests] Isolate Export attribute removal app
rolfbjarne 616fa5d
[linker] Address Export trimming review feedback
rolfbjarne 169bf9b
[msbuild] Parse TrimExportAttributes task input
rolfbjarne dde91ae
Merge branch 'main' into dev/rolf/dev-rolf-remove-export-attributes
rolfbjarne d6a8341
Merge branch 'main' into dev/rolf/dev-rolf-remove-export-attributes
rolfbjarne 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
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
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
130 changes: 130 additions & 0 deletions
130
tests/assembly-preparer/ComputeExportAttributeRemovalStepTests.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,130 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using MonoTouch.Tuner; | ||
|
|
||
| using Xamarin.Linker; | ||
|
|
||
| namespace AssemblyPreparerTests; | ||
|
|
||
| public class ComputeExportAttributeRemovalStepTests : BaseClass { | ||
| [TestCase (null, true)] | ||
| [TestCase (false, true)] | ||
| [TestCase (true, false)] | ||
| public void NonTrimmableRegistrar (bool? trimExportAttributes, bool expectedSuccess) | ||
| { | ||
| using var preparer = CreatePreparer (ApplePlatform.iOS, false, preparer => { | ||
| preparer.Registrar = RegistrarMode.ManagedStatic; | ||
| preparer.TrimExportAttributes = trimExportAttributes; | ||
| }, "public class C {}", out _); | ||
|
|
||
| var success = preparer.Prepare (out var exceptions); | ||
|
|
||
| Assert.That (success, Is.EqualTo (expectedSuccess), "Success"); | ||
| if (expectedSuccess) { | ||
| Assert.That (exceptions, Is.Empty, "Exceptions"); | ||
| Assert.That (preparer.TrimExportAttributes, Is.False, "Removal"); | ||
| } else { | ||
| Assert.That (exceptions, Has.Count.EqualTo (1), "Exceptions"); | ||
| Assert.That (exceptions [0].Message, Is.EqualTo ("Export attributes can only be trimmed with the trimmable static registrar."), "Error message"); | ||
| } | ||
| } | ||
|
|
||
| [TestCase (false, false, false)] | ||
| [TestCase (null, false, true)] | ||
| [TestCase (true, false, true)] | ||
| [TestCase (null, true, false)] | ||
| public void DynamicRegistration (bool? trimExportAttributes, bool dynamicRegistrationSupported, bool expectedRemoval) | ||
| { | ||
| using var preparer = CreatePreparer (ApplePlatform.iOS, false, preparer => { | ||
| preparer.Registrar = RegistrarMode.TrimmableStatic; | ||
| preparer.TrimExportAttributes = trimExportAttributes; | ||
| preparer.Optimizations.RemoveDynamicRegistrar = !dynamicRegistrationSupported; | ||
| preparer.Optimizations.OptimizeBlockLiteralSetupBlock = true; | ||
| preparer.Optimizations.StaticBlockToDelegateLookup = true; | ||
| }, "public class C {}", out _); | ||
|
|
||
| var context = preparer.Configuration.DerivedLinkContext; | ||
| new LoadAssembliesStep ().Process (context); | ||
| new ComputeExportAttributeRemovalStep ().Process (context); | ||
|
|
||
| Assert.That (preparer.Configuration.Application.TrimExportAttributes, Is.EqualTo (expectedRemoval), "Removal"); | ||
| } | ||
|
|
||
| [TestCase (true, true, true)] | ||
| [TestCase (false, true, false)] | ||
| [TestCase (true, false, false)] | ||
| public void RequiredOptimizations (bool optimizeBlockLiteralSetupBlock, bool staticBlockToDelegateLookup, bool expectedRemoval) | ||
| { | ||
| using var preparer = CreatePreparer (ApplePlatform.iOS, false, preparer => { | ||
| preparer.Registrar = RegistrarMode.TrimmableStatic; | ||
| preparer.TrimExportAttributes = true; | ||
| preparer.Optimizations.RemoveDynamicRegistrar = true; | ||
| preparer.Optimizations.OptimizeBlockLiteralSetupBlock = optimizeBlockLiteralSetupBlock; | ||
| preparer.Optimizations.StaticBlockToDelegateLookup = staticBlockToDelegateLookup; | ||
| }, "public class C {}", out _); | ||
|
|
||
| var context = preparer.Configuration.DerivedLinkContext; | ||
| new LoadAssembliesStep ().Process (context); | ||
| new ComputeExportAttributeRemovalStep ().Process (context); | ||
|
|
||
| Assert.That (preparer.Configuration.Application.TrimExportAttributes, Is.EqualTo (expectedRemoval), "Removal"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ExplicitBlocker () | ||
| { | ||
| using var preparer = CreatePreparer (ApplePlatform.iOS, false, preparer => { | ||
| preparer.Registrar = RegistrarMode.TrimmableStatic; | ||
| preparer.TrimExportAttributes = true; | ||
| preparer.Optimizations.RemoveDynamicRegistrar = true; | ||
| preparer.Optimizations.OptimizeBlockLiteralSetupBlock = true; | ||
| preparer.Optimizations.StaticBlockToDelegateLookup = true; | ||
| }, "public class C {}", out _); | ||
|
|
||
| var context = preparer.Configuration.DerivedLinkContext; | ||
| new LoadAssembliesStep ().Process (context); | ||
| preparer.Configuration.Application.TrimExportAttributesBlockers.Add (ExportAttributeRemovalBlocker.RuntimeGetBlockWrapperCreatorRequired); | ||
| new ComputeExportAttributeRemovalStep ().Process (context); | ||
|
|
||
| Assert.That (preparer.Configuration.Application.TrimExportAttributes, Is.False, "Removal"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void NSXpcInterfaceMethodInfoOverload () | ||
| { | ||
| var code = """ | ||
| using System.Reflection; | ||
| using Foundation; | ||
| using ObjCRuntime; | ||
|
|
||
| public class C { | ||
| public void GetAllowedClasses (NSXpcInterface value, MethodInfo method) | ||
| { | ||
| value.GetAllowedClasses (method, 0, false); | ||
| } | ||
|
|
||
| public void SetAllowedClasses (NSXpcInterface value, MethodInfo method, NSSet<Class> classes) | ||
| { | ||
| value.SetAllowedClasses (method, classes, 0, false); | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| using var preparer = CreatePreparer (ApplePlatform.iOS, false, preparer => { | ||
| preparer.Registrar = RegistrarMode.TrimmableStatic; | ||
| preparer.TrimExportAttributes = true; | ||
| preparer.Optimizations.RemoveDynamicRegistrar = true; | ||
| preparer.Optimizations.OptimizeBlockLiteralSetupBlock = true; | ||
| preparer.Optimizations.StaticBlockToDelegateLookup = true; | ||
| }, code, out _); | ||
|
|
||
| var context = preparer.Configuration.DerivedLinkContext; | ||
| new LoadAssembliesStep ().Process (context); | ||
| new DetectApiUsageStep ().Process (context); | ||
| new ComputeExportAttributeRemovalStep ().Process (context); | ||
|
|
||
| Assert.That (preparer.Configuration.Application.TrimExportAttributes, Is.False, "Removal"); | ||
| Assert.That (preparer.Configuration.Application.TrimExportAttributesBlockers.Single (), Is.EqualTo (ExportAttributeRemovalBlocker.NSXpcInterfaceMethodInfoOverloadUsed), "Blocker"); | ||
| } | ||
| } |
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
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.