Bug 10646 - Linker does not remove unused enum values
Summary: Linker does not remove unused enum values
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
Depends on:
Reported: 2013-02-25 12:28 UTC by Marek Safar
Modified: 2017-05-17 11:35 UTC (History)
2 users (show)

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


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 {

   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.

Note You need to log in before you can comment on or make changes to this bug.