Support for constant propagation through local variables
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
With https://github.com/dotnet/runtime/pull/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
```C#
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
```C#
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:
```C#
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.