Skip to content

Constant return values are not getting propagated through wrapper properties #1318

@eerhardt

Description

@eerhardt

In a couple Http/System.Net EventSource classes, we have a static wrapper property that simply returns Log.IsEnabled():

        public static new bool IsEnabled =>
            Log.IsEnabled();

We then have an ILLink.Substitutions file that stubs out the EventSource.IsEnabled() method with a feature switch:

    <type fullname="System.Diagnostics.Tracing.EventSource" feature="System.Diagnostics.Tracing.EventSource.IsSupported" featurevalue="false">
      <method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
      <method signature="System.Boolean IsEnabled()" body="stub" value="false" />

When linking with the feature switch set to false, the branches of the static new bool IsEnabled property are not being trimmed. This static property is staying untouched by the linker:

    .property bool IsEnabled()
    {
        .get bool System.Net.NetEventSource::get_IsEnabled()
        {
            IL_0000: ldsfld class System.Net.NetEventSource System.Net.NetEventSource::Log
            IL_0005: callvirt instance bool [System.Private.CoreLib]System.Diagnostics.Tracing.EventSource::IsEnabled()
            IL_000a: ret
        }
    }

And the if statements are being kept:

            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                this.CheckDisposedOrStarted();
                if (NetEventSource.IsEnabled)
                {
                    NetEventSource.Associate(this, value, "InnerHandler");
                }
                this._innerHandler = value;
            }

This causes unnecessary code to be kept when EventSource is disabled.

We should propagate the constant return value through these properties, so we can trim even more code.

This is an alternative to dotnet/runtime#38828

cc @marek-safar @vitek-karas @MichalStrehovsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions