Last active
August 29, 2015 14:19
-
-
Save Tamschi/3b2f94916afc448e75a5 to your computer and use it in GitHub Desktop.
A compiler bug (I'm fairly sure it doesn't match the specification that is.) in VS 2013 that causes unnecessary boxing:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.method public hidebysig static | |
void TestMethod<(class IEnumerable`2<!!T, !!TEnumerator>) TEnumerable, (class [mscorlib]System.Collections.Generic.IEnumerator`1<!!T>) TEnumerator, T> ( | |
!!TEnumerable enumerable | |
) cil managed | |
{ | |
// Method begins at RVA 0x2050 | |
// Code size 70 (0x46) | |
.maxstack 1 | |
.locals init ( | |
[0] !!TEnumerator | |
) | |
IL_0000: ldarga.s enumerable | |
IL_0002: constrained. !!TEnumerable | |
IL_0008: callvirt instance !1 class IEnumerable`2<!!T, !!TEnumerator>::GetEnumerator() | |
IL_000d: stloc.0 | |
.try | |
{ | |
IL_000e: br.s IL_001e | |
// loop start (head: IL_001e) | |
IL_0010: ldloca.s 0 | |
IL_0012: constrained. !!TEnumerator | |
IL_0018: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1<!!T>::get_Current() | |
IL_001d: pop | |
IL_001e: ldloca.s 0 | |
IL_0020: constrained. !!TEnumerator | |
IL_0026: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() | |
IL_002b: brtrue.s IL_0010 | |
// end loop | |
IL_002d: leave.s IL_0045 | |
} // end .try | |
finally | |
{ | |
IL_002f: ldloc.0 | |
IL_0030: box !!TEnumerator // This is the unnecessary boxing that violates the specification. | |
IL_0035: brfalse.s IL_0044 | |
IL_0037: ldloca.s 0 | |
IL_0039: constrained. !!TEnumerator | |
IL_003f: callvirt instance void [mscorlib]System.IDisposable::Dispose() | |
IL_0044: endfinally | |
} // end handler | |
IL_0045: ret | |
} // end of method Test::TestMethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
public interface IEnumerable<T, TEnumerator> : IEnumerable<T> | |
{ new TEnumerator GetEnumerator(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
static class Test | |
{ | |
public static void TestMethod<TEnumerable, TEnumerator, T>(TEnumerable enumerable) | |
where TEnumerable : IEnumerable<T, TEnumerator> | |
where TEnumerator : IEnumerator<T> | |
{ | |
foreach (var item in enumerable) { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment