Skip to content

Support for constant propagation through local variables #1284

Open
@eerhardt

Description

@eerhardt

With dotnet/runtime#38129, I am introducing a feature switch to link out EventSource's implementation.

The following pattern in Task.cs is using EventSource.IsEnabled(), which is getting stubbed out to false.

https://github.com/dotnet/runtime/blob/bd6cbe3642f51d70839912a6a666e5de747ad581/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs#L2275-L2285

            bool etwIsEnabled = log.IsEnabled();
            if (etwIsEnabled)
            {
                if (log.TasksSetActivityIds)
                    EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(this.Id), out savedActivityID);
                // previousTask holds the actual "current task" we want to report in the event
                if (previousTask != null)
                    log.TaskStarted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id);
                else
                    log.TaskStarted(TaskScheduler.Current.Id, 0, this.Id);
            }

https://github.com/dotnet/runtime/blob/bd6cbe3642f51d70839912a6a666e5de747ad581/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs#L2333-L2344

            finally
            {
                currentTaskSlot = previousTask;


                // ETW event for Task Completed
                if (etwIsEnabled)
                {
                    // previousTask holds the actual "current task" we want to report in the event
                    if (previousTask != null)
                        log.TaskCompleted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id, IsFaulted);
                    else
                        log.TaskCompleted(TaskScheduler.Current.Id, 0, this.Id, IsFaulted);


                    if (log.TasksSetActivityIds)
                        EventSource.SetCurrentThreadActivityId(savedActivityID);
                }
            }

The top case can be trimmed successfully:

Code post-ILLink:

            bool flag = log.IsEnabled();
            !flag;
...
            finally
            {
                currentTaskSlot = task;
                if (flag)
                {
                    if (task == null)
                    {
                        log.TaskCompleted(TaskScheduler.Current.Id, 0, this.Id, this.IsFaulted);
                    }
                    else
                    {
                        log.TaskCompleted(task.m_taskScheduler.Id, task.Id, this.Id, this.IsFaulted);
                    }
                    if (log.TasksSetActivityIds)
                    {
                        EventSource.SetCurrentThreadActivityId(guid);
                    }
                }
            }

Note that the finally calls to log.TaskCompleted aren't being trimmed, even though flag is always false.

@vitek-karas @marek-safar

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions