Applying MethodImplOptions.AggressiveInlining to F# functions : <p>The attribute <code>System.Runtime.CompilerServices.MethodImplAttribute</code> can be used to give hints to the JIT compiler about how to handle the decorated method. In particular, the option <code>MethodImplOptions.AggressiveInlining</code> instructs the compiler to inline the affected method if possible. Unfortunately the F# compiler seems to simply ignore this attribute when generating IL.</p>

<p>Example: The following C# code</p>

<pre><code>[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Inc(int x) =&gt; x + 1;
</code></pre>

<p>is translated to</p>

<pre><code>.method public hidebysig static int32  Inc(int32 x) cil managed aggressiveinlining
{     
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  ldc.i4.1
    IL_0002:  add
    IL_0003:  ret
}
</code></pre>

<p>Note the "aggressiveinlining" flag.</p>

<p>This F# code however</p>

<pre><code>[&lt;MethodImpl(MethodImplOptions.AggressiveInlining)&gt;]
let inc x = x + 1
</code></pre>

<p>becomes</p>

<pre><code>.method public static int32  inc(int32 x) cil managed
{
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldarg.0
    IL_0002:  ldc.i4.1
    IL_0003:  add
    IL_0004:  ret
}
</code></pre>

<p>No "aggressiveinlining". I also tried to apply the attribute to static and non-static methods of proper classes (<code>type ...</code>), but the result is the same.</p>

<p>If however I apply it to a custom indexer, like so</p>

<pre><code>type Dummy =
    member self.Item
        with [&lt;MethodImpl(MethodImplOptions.AggressiveInlining)&gt;] get x = x + 1
</code></pre>

<p>the resulting IL is</p>

<pre><code>.method public hidebysig specialname instance int32 get_Item(int32 x) cil managed
{
    .custom instance void [mscorlib]System.Runtime.CompilerServices.MethodImplAttribute::.ctor(valuetype [mscorlib]System.Runtime.CompilerServices.MethodImplOptions) = ( 01 00 00 01 00 00 00 00 ) 
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldarg.1
    IL_0002:  ldc.i4.1
    IL_0003:  add
    IL_0004:  ret
}
</code></pre>

<p>... though I'm not sure whether that is equivalent to the "aggressiveinling" flag generated by the C# compiler.</p>

<p>Is that behavior desired/expected? Is it a bug in the F# compiler?</p>

<p>(Note: I'm aware of the F# <code>inline</code> keyword, but that only works for F# clients of my library, not C# consumers.)</p>
