dotnet/roslyn

Remove unneccessary instructions from variable-less filter

Open

#4,388 建立於 2015年8月6日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)C# (4,257 fork)batch import
Area-CompilersConcept-Continuous ImprovementFeature Requesthelp wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

When an exception filter doesn’t specify the exception variable, for example:

            try   {   …   }  catch when (F())  {  …   }

we emit

filter
  {
    IL_0006:  isinst     [mscorlib]System.Object
    IL_000b:  dup
    IL_000c:  brtrue.s   IL_0012
    IL_000e:  pop
    IL_000f:  ldc.i4.0
    IL_0010:  br.s       IL_001b
    IL_0012:  pop
    IL_0013:  call       bool ConsoleApplication1.Program::F()
    IL_0018:  ldc.i4.0
    IL_0019:  cgt.un
    IL_001b:  endfilter
  }  // end filter

The Object type check is unnecessary. The following IL sequence is verifiable and works equally well imo:

filter
  {
    IL_0012:  pop
    IL_0013:  call       bool ConsoleApplication1.Program::F()
    IL_0018:  ldc.i4.0
    IL_0019:  cgt.un
    IL_001b:  endfilter
  }  // end filter

Avoiding implicit reference to System.Object would simplify some low-level .NET Native scenarios that are layered below CoreFX and thus can't have a dependency on System.Object.

貢獻者指南