Skip to content

Remove F# compilation resources #1040

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 12 commits into from
Feb 15, 2021
Merged

Remove F# compilation resources #1040

merged 12 commits into from
Feb 15, 2021

Conversation

heytherewill
Copy link
Contributor

Closes #329

A few considerations for reviewers:

  • The code might not be placed at the best possible step. I've added it to RemoveUnreachableBlockStep. I've also considered adding an entirely new step, but that sounded like an overkill.
  • I will add tests to cover the newly added code once it's settled that the code is in the correct spot.

@mrvoorhe
Copy link
Contributor

I think https://github.com/mono/linker/blob/master/src/linker/Linker.Steps/RemoveFeaturesStep.cs would be better. But what and see what @marek-safar thinks

@marek-safar
Copy link
Contributor

I'd add a new step called RemoveResources after MarkStep instead. Any ideas about shorter --keep-fsharp-compilation-resources" name ?

@heytherewill
Copy link
Contributor Author

@mrvoorhe I considered that step, but it only runs if you explicitly tell the linker that you wanna remove a feature. Adding another option there that ran unconditionally and needed a flag that indicates keep rather than remove felt very counter intuitive to me 🤔

I think a new step indeed is what makes the most sense

Regarding naming: --keep-fsharp-resources might work, albeit not as descriptive

@@ -0,0 +1,26 @@
namespace Mono.Linker.Steps
{
public class RemoveResourcesStep : IStep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derive from BaseStep

{
public void Process(LinkContext context)
{
var assemblies = context.Annotations.GetAssemblies().ToArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToArray should not be needed

}

static bool IsFSharpCompilationResource(string resourceName)
=> resourceName.StartsWith("FSharpSignatureData")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ordinal comparison

@@ -289,6 +290,12 @@ public bool Run (ILogger customLogger = null)

continue;

case "--keep-fsharp-compilation-resources":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case "--keep-fsharp-compilation-resources":
case "--keep-compilers-resources":


private void RemoveFSharpCompilationResources(AssemblyDefinition assembly)
{
var resourcesInAssembly = assembly.MainModule.Resources.Select(r => r.Name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for HasResources first

protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (!assembly.MainModule.HasResources) return;
RemoveFSharpCompilationResources (assembly);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a check which enables this only for assemblies which are linked or saved

@@ -941,6 +952,7 @@ static Pipeline GetStandardPipeline ()
p.AppendStep (new PreserveDependencyLookupStep ());
p.AppendStep (new TypeMapStep ());
p.AppendStep (new MarkStep ());
p.AppendStep (new RemoveResourcesStep());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comments above as well

Base automatically changed from master to main February 4, 2021 22:14
@heytherewill
Copy link
Contributor Author

Boy, 2020 sure was a busy year 😅

Anyways, I addressed the changes requested by this PR now that I found some time. Let me know if there are any further requests

@marek-safar marek-safar merged commit 5431c31 into dotnet:main Feb 15, 2021
@marek-safar
Copy link
Contributor

Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automagically remove F# compilation resources
3 participants