Bug 10646 - Linker does not remove unused enum values
Summary: Linker does not remove unused enum values
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
Version: 6.3.x
Hardware: PC Mac OS
: --- enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-02-25 12:28 UTC by Marek Safar
Modified: 2017-05-17 11:35 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 10646 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Marek Safar 2013-02-25 12:28:58 UTC
Linker does not remove unused enum values.

Steps to reproduce.

- Build Release hello world app.
- Inspect output linked mscorlib.dll

It includes System.IO.MonoFileType.Pipe even if it's not used by mscorlib or user code
Comment 1 Sebastien Pouliot 2013-02-25 16:05:53 UTC
No it does not. Every value is marked when the enum type is marked. That's because "unused", from an assembly, values does not mean the value won't exists at runtime. e.g.

var e = (MyEnum) fs.ReadInt32();
Console.WriteLine (e);

Removing them would break a lot of code, e.g.

* Non-binary serialization, including web services and WCF;

* Showing the values, read from external stream, to the user (like above code);

* Enum.IsDefined, which the BCL uses itself;

We could remove internal enums values, like MonoFileType.Pipe, but it would require some auditing of how they are used.
Comment 2 Marek Safar 2013-02-25 16:32:26 UTC
That should not be hard to check. For example mark whole type only when the enum is used together with any static or instance method from System.Enum.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-05-17 11:35:15 UTC
This wouldn't be that easy to detect:

    enum E {
       X
   }

   object x = E.X;
   Console.WriteLine (x);

another issue is that the X enum value does not show up directly in IL, just the constant:

    .locals init (object V_0)
    IL_0000:  ldc.i4.0
    IL_0001:  box        TestClass/E
    IL_0006:  stloc.0
    IL_0007:  ldloc.0
    IL_0008:  call       void [mscorlib]System.Console::WriteLine(object)
    IL_000d:  ret

you can still determine which enum value is used by looking it up based on the constant, but now add flags to the mix and this gets complicated quickly.