BadImageFormatException when running simple program
От: pekabon  
Дата: 15.01.14 13:27
Оценка:
Привет,

посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:
Re: BadImageFormatException when running simple program
От: _NN_ www.nemerleweb.com
Дата: 15.01.14 13:47
Оценка:
Здравствуйте, pekabon, Вы писали:

P>Привет,


P>посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:


Предлагаю посмотреть IL от аналогичного кода на C#, и наверное будет ясно что не так с выхлопом.
http://rsdn.nemerleweb.com
http://nemerleweb.com
Re[2]: BadImageFormatException when running simple program
От: Аноним  
Дата: 15.01.14 14:57
Оценка:
Здравствуйте, _NN_, Вы писали:

_NN>Предлагаю посмотреть IL от аналогичного кода на C#, и наверное будет ясно что не так с выхлопом.


IL от аналогичного кода на C# вообще другой, поэтому сравнивать смысла нет (по-крайней мере — нам не помогло)
Re[3]: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 15.01.14 18:17
Оценка:
Здравствуйте, Аноним, Вы писали:

А>IL от аналогичного кода на C# вообще другой, поэтому сравнивать смысла нет (по-крайней мере — нам не помогло)


Ты оба варианта сюда запость. Поглядим.
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
Re: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 15.01.14 18:20
Оценка:
Здравствуйте, pekabon, Вы писали:

P>посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:


Вы эту сборку PEVerify.exe скармливали? Что он говорит?
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
Re[2]: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 15.01.14 18:33
Оценка:
Здравствуйте, VladD2, Вы писали:

VD>Вы эту сборку PEVerify.exe скармливали? Что он говорит?


Сам попробовал. Ругается на MoveNext()

Вот декомпилят за авторством ildasm-а (ILSpy падает на этом коде).

.method public hidebysig newslot virtual final 
        instance bool  MoveNext() cil managed
{
  // Code size       125 (0x7d)
  .maxstack  14
  .locals init ([0] bool V_0,
           [1] bool V_1,
           [2] !T V_2)
  .try
  {
    IL_0000:  ldc.i4.0
    IL_0001:  stloc.1
    IL_0002:  ldarg.0
    IL_0003:  ldfld      int32 class Program/_N_Enumerable_4064`1<!T>::_N_state
    IL_0008:  ldc.i4.1
    IL_0009:  bne.un     IL_0013
    IL_000e:  br         IL_0068
    IL_0013:  ldarg.0
    IL_0014:  ldfld      int32 class Program/_N_Enumerable_4064`1<!T>::_N_state
    IL_0019:  ldc.i4.0
    IL_001a:  bne.un     IL_0024
    IL_001f:  br         IL_002b
    IL_0024:  ldc.i4.0
    IL_0025:  stloc.1
    IL_0026:  br         IL_006c
    IL_002b:  nop
    IL_002c:  nop
    IL_002d:  ldarg.0
    IL_002e:  ldarg.0
    IL_002f:  ldfld      class [mscorlib]System.Collections.Generic.IEnumerable`1<!0> class Program/_N_Enumerable_4064`1<!T>::_N_collections_4092
    IL_0034:  ldnull
    IL_0035:  ldftn      bool Program::_N__N_lambda__4053_4103<!!0>(!!0)
    IL_003b:  newobj     instance void class [mscorlib]System.Func`2<!T,bool>::.ctor(object,
                                                                                     native int)
    IL_0040:  call       class [mscorlib]System.Collections.Generic.IEnumerable`1<!!1> [System.Core]System.Linq.Enumerable::Select<!T,bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
                                                                                                                                            class [mscorlib]System.Func`2<!!0,!!1>)
    IL_0045:  stfld      class [mscorlib]System.Collections.Generic.IEnumerable`1<bool> class Program/_N_Enumerable_4064`1<!T>::_N__N_wildcard_3433_4096
    IL_004a:  ldarg.0
    IL_004b:  nop
    IL_004c:  ldloca.s   V_2
    IL_004e:  initobj    !T
    IL_0054:  ldloc.2
    IL_0055:  stfld      !0 class Program/_N_Enumerable_4064`1<!T>::_N_current
    IL_005a:  ldarg.0
    IL_005b:  ldc.i4.1
    IL_005c:  stfld      int32 class Program/_N_Enumerable_4064`1<!T>::_N_state
    IL_0061:  ldc.i4.1
    IL_0062:  stloc.1
    IL_0063:  br         IL_006c
    IL_0068:  nop
    IL_0069:  nop
    IL_006a:  ldc.i4.0
    IL_006b:  stloc.1
    IL_006c:  nop
    IL_006d:  ldloc.1
    IL_006e:  stloc.0
    IL_006f:  leave      IL_007b
  }  // end .try
  fault
  {
    IL_0074:  ldarg.0
    IL_0075:  call       instance void class Program/_N_Enumerable_4064`1<!T>::Dispose()
    IL_007a:  endfinally
  }  // end handler
  IL_007b:  ldloc.0
  IL_007c:  ret
} // end of method _N_Enumerable_4064`1::MoveNext
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
Re: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 15.01.14 18:41
Оценка:
Здравствуйте, pekabon, Вы писали:

P>посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:


Упрощенная версия:
using System;
using System.Collections.Generic;

module Program
{
  public Foo[T]() : IEnumerable[int]
  {
    def _f : Func[bool] = fun() { true };
    yield 42;
  }

  Main() : void
  {
    foreach (x in Foo.[int]())
      Console.WriteLine(x);
  }
}


Ее декомпилят:
.method public hidebysig newslot virtual final 
        instance bool  MoveNext() cil managed
{
  // Code size       106 (0x6a)
  .maxstack  13
  .locals init ([0] bool V_0,
           [1] bool V_1)
  .try
  {
    IL_0000:  ldc.i4.0
    IL_0001:  stloc.1
    IL_0002:  ldarg.0
    IL_0003:  ldfld      int32 class Program/_N_Enumerable_3684`1<!T>::_N_state
    IL_0008:  ldc.i4.1
    IL_0009:  bne.un     IL_0013
    IL_000e:  br         IL_0055
    IL_0013:  ldarg.0
    IL_0014:  ldfld      int32 class Program/_N_Enumerable_3684`1<!T>::_N_state
    IL_0019:  ldc.i4.0
    IL_001a:  bne.un     IL_0024
    IL_001f:  br         IL_002b
    IL_0024:  ldc.i4.0
    IL_0025:  stloc.1
    IL_0026:  br         IL_0059
    IL_002b:  nop
    IL_002c:  nop
    IL_002d:  ldarg.0
    IL_002e:  ldnull
    IL_002f:  ldftn      bool Program::_N__N_lambda__3674_3720<!!0>()
    IL_0035:  newobj     instance void class [mscorlib]System.Func`1<bool>::.ctor(object,
                                                                                  native int)
    IL_003a:  stfld      class [mscorlib]System.Func`1<bool> class Program/_N_Enumerable_3684`1<!T>::_N__f_3713
    IL_003f:  ldarg.0
    IL_0040:  ldc.i4.s   42
    IL_0042:  stfld      int32 class Program/_N_Enumerable_3684`1<!T>::_N_current
    IL_0047:  ldarg.0
    IL_0048:  ldc.i4.1
    IL_0049:  stfld      int32 class Program/_N_Enumerable_3684`1<!T>::_N_state
    IL_004e:  ldc.i4.1
    IL_004f:  stloc.1
    IL_0050:  br         IL_0059
    IL_0055:  nop
    IL_0056:  nop
    IL_0057:  ldc.i4.0
    IL_0058:  stloc.1
    IL_0059:  nop
    IL_005a:  ldloc.1
    IL_005b:  stloc.0
    IL_005c:  leave      IL_0068
  }  // end .try
  fault
  {
    IL_0061:  ldarg.0
    IL_0062:  call       instance void class Program/_N_Enumerable_3684`1<!T>::Dispose()
    IL_0067:  endfinally
  }  // end handler
  IL_0068:  ldloc.0
  IL_0069:  ret
} // end of method _N_Enumerable_3684`1::MoveNext
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
Re[2]: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 15.01.14 18:47
Оценка:
Здравствуйте, VladD2, Вы писали:

VD>Упрощенная версия:...


В общем, что-то связанное с параметром типа и ссылкой на делегат. Пока не понял что.
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
Re[2]: BadImageFormatException when running simple program
От: _NN_ www.nemerleweb.com
Дата: 16.01.14 07:45
Оценка:
Здравствуйте, VladD2, Вы писали:

VD>Здравствуйте, pekabon, Вы писали:


P>>посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:


VD>Упрощенная версия:

Можно еще проще без foreach
  Main() : void
  {
    _ = Foo.[int]().GetEnumerator().MoveNext();
  }


Кстати если вместо
def _f : Func[bool] = fun() { true };
Написать
def _f : Func[bool] = () => true;

То все работает
И вариант с промежуточной переменной тоже решает проблему:
public Foo[T]() : IEnumerable[int]
  {
    def f = fun(){true};
    def _f : Func[bool] = f;
    yield 42;
  }


Вот сравнение нерабочего (слева) и рабочего (справа) упрощенных вариантов.
Различия выделены.
Я в IL не силен, возможно дело в "ldftn bool Program::_N__N_lambda__3790_3836<!!0>()".


    .method public hidebysig newslot virtual final 
            instance bool  MoveNext() cil managed
    {
      // Code size       106 (0x6a)
      .maxstack  13
      .locals init ([0] bool V_0,
               [1] bool V_1)
      .try
      {
        IL_0000:  ldc.i4.0
        IL_0001:  stloc.1
        IL_0002:  ldarg.0
        IL_0003:  ldfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_0008:  ldc.i4.1
        IL_0009:  bne.un     IL_0013

        IL_000e:  br         IL_0055

        IL_0013:  ldarg.0
        IL_0014:  ldfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_0019:  ldc.i4.0
        IL_001a:  bne.un     IL_0024

        IL_001f:  br         IL_002b

        IL_0024:  ldc.i4.0
        IL_0025:  stloc.1
        IL_0026:  br         IL_0059

        IL_002b:  nop
        IL_002c:  nop
        IL_002d:  ldarg.0
        IL_002e:  ldnull
        IL_002f:  ldftn      bool Program::_N__N_lambda__3790_3836<!!0>()





        IL_0035:  newobj     instance void class [mscorlib]System.Func`1<bool>::.ctor(object,
                                                                                      native int)
        IL_003a:  stfld      class [mscorlib]System.Func`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__f_3829
        IL_003f:  ldarg.0
        IL_0040:  ldc.i4.s   42
        IL_0042:  stfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
        IL_0047:  ldarg.0
        IL_0048:  ldc.i4.1
        IL_0049:  stfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_004e:  ldc.i4.1
        IL_004f:  stloc.1
        IL_0050:  br         IL_0059

        IL_0055:  nop
        IL_0056:  nop
        IL_0057:  ldc.i4.0
        IL_0058:  stloc.1
        IL_0059:  nop
        IL_005a:  ldloc.1
        IL_005b:  stloc.0
        IL_005c:  leave      IL_0068

      }  // end .try
      fault
      {
        IL_0061:  ldarg.0
        IL_0062:  call       instance void class Program/_N_Enumerable_3800`1<!T>::Dispose()
        IL_0067:  endfinally
      }  // end handler
      IL_0068:  ldloc.0
      IL_0069:  ret
    } // end of method _N_Enumerable_3800`1::MoveNext


    .method public hidebysig newslot virtual final 
            instance bool  MoveNext() cil managed
    {
      // Code size       123 (0x7b)
      .maxstack  13
      .locals init ([0] bool V_0,
               [1] bool V_1)
      .try
      {
        IL_0000:  ldc.i4.0
        IL_0001:  stloc.1
        IL_0002:  ldarg.0
        IL_0003:  ldfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_0008:  ldc.i4.1
        IL_0009:  bne.un     IL_0013

        IL_000e:  br         IL_0066

        IL_0013:  ldarg.0
        IL_0014:  ldfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_0019:  ldc.i4.0
        IL_001a:  bne.un     IL_0024

        IL_001f:  br         IL_002b

        IL_0024:  ldc.i4.0
        IL_0025:  stloc.1
        IL_0026:  br         IL_006a

        IL_002b:  nop
        IL_002c:  nop
        IL_002d:  ldarg.0
        IL_002e:  ldarg.0
        IL_002f:  ldsfld     class Program/_N__N_lambda__3790__3868`1<!0> class Program/_N__N_lambda__3790__3868`1<!T>::Instance
        IL_0034:  stfld      class [Nemerle]Nemerle.Builtins.Function`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__N_lambda__3790_3827
        IL_0039:  ldarg.0
        IL_003a:  ldfld      class [Nemerle]Nemerle.Builtins.Function`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__N_lambda__3790_3827
        IL_003f:  dup
        IL_0040:  ldvirtftn  instance !0 class [Nemerle]Nemerle.Builtins.Function`1<bool>::apply()
        IL_0046:  newobj     instance void class [mscorlib]System.Func`1<bool>::.ctor(object,
                                                                                      native int)
        IL_004b:  stfld      class [mscorlib]System.Func`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__f_3829
        IL_0050:  ldarg.0
        IL_0051:  ldc.i4.s   42
        IL_0053:  stfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
        IL_0058:  ldarg.0
        IL_0059:  ldc.i4.1
        IL_005a:  stfld      int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
        IL_005f:  ldc.i4.1
        IL_0060:  stloc.1
        IL_0061:  br         IL_006a

        IL_0066:  nop
        IL_0067:  nop
        IL_0068:  ldc.i4.0
        IL_0069:  stloc.1
        IL_006a:  nop
        IL_006b:  ldloc.1
        IL_006c:  stloc.0
        IL_006d:  leave      IL_0079

      }  // end .try
      fault
      {
        IL_0072:  ldarg.0
        IL_0073:  call       instance void class Program/_N_Enumerable_3800`1<!T>::Dispose()
        IL_0078:  endfinally
      }  // end handler
      IL_0079:  ldloc.0
      IL_007a:  ret
    } // end of method _N_Enumerable_3800`1::MoveNext

P.S.
На всякий случай полный выхлоп.
  Нерабочий
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.33440
// Copyright (c) Microsoft Corporation. All rights reserved.



// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly extern Nemerle
{
.publickeytoken = (E0 80 A9 C7 24 E2 BF CD ) // ....$...
.ver 1:2:0:187
}
.assembly ConsoleApplication32
{
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 ) // ...1.0.0.0..
.custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 63 66 35 35 62 61 30 32 2D 66 37 32 30 // ..$cf55ba02-f720
2D 34 36 30 30 2D 61 65 37 33 2D 64 65 32 61 63 // -4600-ae73-de2ac
39 32 33 35 64 62 38 00 00 ) // 9235db8..
.custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCultureAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20 // ...Copyright ..
20 32 30 31 34 00 00 ) // 2014..
.custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 14 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63 // ...ConsoleApplic
61 74 69 6F 6E 33 32 00 00 ) // ation32..
.custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 14 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63 // ...ConsoleApplic
61 74 69 6F 6E 33 32 00 00 ) // ation32..

// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 )

.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 1:0:0:0
}
.module ConsoleApplication32
// MVID: {47E21E6B-4163-4AB8-8464-8F108758B02B}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02280000


// =============== CLASS MEMBERS DECLARATION ===================

.class private abstract auto ansi sealed beforefieldinit Program
extends [mscorlib]System.Object
{
.class auto ansi nested private beforefieldinit _N_Enumerable_3800`1<T>
extends [mscorlib]System.Object
implements [mscorlib]System.Collections.IEnumerator,
[mscorlib]System.IDisposable,
class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>,
[mscorlib]System.Collections.IEnumerable,
class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>
{
.field assembly class [mscorlib]System.Func`1<bool> _N__f_3829
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_lambda__3790_3827
.field assembly int32 _N_current
.field assembly int32 _N_state
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_yielding_function_3823
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_wildcard_3547_3821
.field private int32 _N_this_used
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 2
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method _N_Enumerable_3800`1::.ctor

.method public hidebysig newslot specialname virtual final
instance int32 get_Current() cil managed
{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
IL_0006: ret
} // end of method _N_Enumerable_3800`1::get_Current

.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 8 (0x8)
.maxstack 2
IL_0000: ldarg.0
IL_0001: ldc.i4.m1
IL_0002: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0007: ret
} // end of method _N_Enumerable_3800`1::Dispose

.method public hidebysig newslot virtual final
instance void Reset() cil managed
{
// Code size 11 (0xb)
.maxstack 1
IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor()
IL_0005: throw

IL_0006: br IL_0006
} // end of method _N_Enumerable_3800`1::Reset

.method public hidebysig newslot virtual final
instance bool MoveNext() cil managed
{
// Code size 106 (0x6a)
.maxstack 13
.locals init ([0] bool V_0,
[1] bool V_1)
.try
{
IL_0000: ldc.i4.0
IL_0001: stloc.1
IL_0002: ldarg.0
IL_0003: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0008: ldc.i4.1
IL_0009: bne.un IL_0013

IL_000e: br IL_0055

IL_0013: ldarg.0
IL_0014: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0019: ldc.i4.0
IL_001a: bne.un IL_0024

IL_001f: br IL_002b

IL_0024: ldc.i4.0
IL_0025: stloc.1
IL_0026: br IL_0059

IL_002b: nop
IL_002c: nop
IL_002d: ldarg.0
IL_002e: ldnull
IL_002f: ldftn bool Program::_N__N_lambda__3790_3836<!!0>()
IL_0035: newobj instance void class [mscorlib]System.Func`1<bool>::.ctor(object,
native int)
IL_003a: stfld class [mscorlib]System.Func`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__f_3829
IL_003f: ldarg.0
IL_0040: ldc.i4.s 42
IL_0042: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
IL_0047: ldarg.0
IL_0048: ldc.i4.1
IL_0049: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_004e: ldc.i4.1
IL_004f: stloc.1
IL_0050: br IL_0059

IL_0055: nop
IL_0056: nop
IL_0057: ldc.i4.0
IL_0058: stloc.1
IL_0059: nop
IL_005a: ldloc.1
IL_005b: stloc.0
IL_005c: leave IL_0068

} // end .try
fault
{
IL_0061: ldarg.0
IL_0062: call instance void class Program/_N_Enumerable_3800`1<!T>::Dispose()
IL_0067: endfinally
} // end handler
IL_0068: ldloc.0
IL_0069: ret
} // end of method _N_Enumerable_3800`1::MoveNext

.method public hidebysig newslot virtual final
instance class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
GetEnumerator() cil managed
{
// Code size 55 (0x37)
.maxstack 4
.locals init ([0] class Program/_N_Enumerable_3800`1<!T> V_0)
IL_0000: ldarg.0
IL_0001: ldflda int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0006: ldc.i4.1
IL_0007: ldc.i4.0
IL_0008: call int32 [mscorlib]System.Threading.Interlocked::CompareExchange(int32&,
int32,
int32)
IL_000d: ldc.i4.0
IL_000e: ceq
IL_0010: ldc.i4.0
IL_0011: ceq
IL_0013: brfalse IL_0030

IL_0018: newobj instance void class Program/_N_Enumerable_3800`1<!T>::.ctor()
IL_001d: stloc.0
IL_001e: ldloc.0
IL_001f: ldarg.0
IL_0020: callvirt instance void class Program/_N_Enumerable_3800`1<!T>::CopyFrom(class Program/_N_Enumerable_3800`1<!0>)
IL_0025: ldloc.0
IL_0026: castclass class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
IL_002b: br IL_0036

IL_0030: ldarg.0
IL_0031: castclass class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
IL_0036: ret
} // end of method _N_Enumerable_3800`1::GetEnumerator

.method private hidebysig newslot virtual final
instance class [mscorlib]System.Collections.IEnumerator
NonGenericGetEnum() cil managed
{
.override [mscorlib]System.Collections.IEnumerable::GetEnumerator
// Code size 55 (0x37)
.maxstack 4
.locals init ([0] class Program/_N_Enumerable_3800`1<!T> V_0)
IL_0000: ldarg.0
IL_0001: ldflda int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0006: ldc.i4.1
IL_0007: ldc.i4.0
IL_0008: call int32 [mscorlib]System.Threading.Interlocked::CompareExchange(int32&,
int32,
int32)
IL_000d: ldc.i4.0
IL_000e: ceq
IL_0010: ldc.i4.0
IL_0011: ceq
IL_0013: brfalse IL_0030

IL_0018: newobj instance void class Program/_N_Enumerable_3800`1<!T>::.ctor()
IL_001d: stloc.0
IL_001e: ldloc.0
IL_001f: ldarg.0
IL_0020: callvirt instance void class Program/_N_Enumerable_3800`1<!T>::CopyFrom(class Program/_N_Enumerable_3800`1<!0>)
IL_0025: ldloc.0
IL_0026: castclass [mscorlib]System.Collections.IEnumerator
IL_002b: br IL_0036

IL_0030: ldarg.0
IL_0031: castclass [mscorlib]System.Collections.IEnumerator
IL_0036: ret
} // end of method _N_Enumerable_3800`1::NonGenericGetEnum

.method private hidebysig instance void
CopyFrom(class Program/_N_Enumerable_3800`1<!T> other) cil managed
{
// Code size 10 (0xa)
.maxstack 2
IL_0000: ldarg.1
IL_0001: pop
IL_0002: ldarg.0
IL_0003: ldc.i4.1
IL_0004: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0009: ret
} // end of method _N_Enumerable_3800`1::CopyFrom

.method private hidebysig specialname virtual final
instance object System.Collections.IEnumerator.get_Current() cil managed
{
.override [mscorlib]System.Collections.IEnumerator::get_Current
// Code size 12 (0xc)
.maxstack 1
IL_0000: ldarg.0
IL_0001: callvirt instance int32 class Program/_N_Enumerable_3800`1<!T>::get_Current()
IL_0006: box [mscorlib]System.Int32
IL_000b: ret
} // end of method _N_Enumerable_3800`1::System.Collections.IEnumerator.get_Current

.property int32 Current()
{
.get instance int32 Program/_N_Enumerable_3800`1::get_Current()
} // end of property _N_Enumerable_3800`1::Current
} // end of class _N_Enumerable_3800`1

.method public hidebysig static class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>
Foo<T>() cil managed
{
// Code size 8 (0x8)
.maxstack 1
.locals init ([0] class Program/_N_Enumerable_3800`1<!!T> V_0)
IL_0000: newobj instance void class Program/_N_Enumerable_3800`1<!!T>::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ret
} // end of method Program::Foo

.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 18 (0x12)
.maxstack 1
IL_0000: nop
IL_0001: call class [mscorlib]System.Collections.Generic.IEnumerable`1<int32> Program::Foo<int32>()
IL_0006: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1<!0> class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>::GetEnumerator()
IL_000b: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()
IL_0010: pop
IL_0011: ret
} // end of method Program::Main

.method private hidebysig static bool _N__N_lambda__3790_3836<T>() cil managed
{
// Code size 3 (0x3)
.maxstack 1
IL_0000: nop
IL_0001: ldc.i4.1
IL_0002: ret
} // end of method Program::_N__N_lambda__3790_3836

} // end of class Program


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************


  Рабочий
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.33440
// Copyright (c) Microsoft Corporation. All rights reserved.



// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly extern Nemerle
{
.publickeytoken = (E0 80 A9 C7 24 E2 BF CD ) // ....$...
.ver 1:2:0:187
}
.assembly ConsoleApplication32
{
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 ) // ...1.0.0.0..
.custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 63 66 35 35 62 61 30 32 2D 66 37 32 30 // ..$cf55ba02-f720
2D 34 36 30 30 2D 61 65 37 33 2D 64 65 32 61 63 // -4600-ae73-de2ac
39 32 33 35 64 62 38 00 00 ) // 9235db8..
.custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCultureAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20 // ...Copyright ..
20 32 30 31 34 00 00 ) // 2014..
.custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 14 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63 // ...ConsoleApplic
61 74 69 6F 6E 33 32 00 00 ) // ation32..
.custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 14 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63 // ...ConsoleApplic
61 74 69 6F 6E 33 32 00 00 ) // ation32..

// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 )

.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 1:0:0:0
}
.module ConsoleApplication32
// MVID: {81F431ED-F349-460F-938E-8A0AC7900148}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00D00000


// =============== CLASS MEMBERS DECLARATION ===================

.class private abstract auto ansi sealed beforefieldinit Program
extends [mscorlib]System.Object
{
.class auto ansi nested private beforefieldinit _N_Enumerable_3800`1<T>
extends [mscorlib]System.Object
implements [mscorlib]System.Collections.IEnumerator,
[mscorlib]System.IDisposable,
class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>,
[mscorlib]System.Collections.IEnumerable,
class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>
{
.field assembly class [mscorlib]System.Func`1<bool> _N__f_3829
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_lambda__3790_3827
.field assembly int32 _N_current
.field assembly int32 _N_state
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_yielding_function_3823
.field assembly class [Nemerle]Nemerle.Builtins.Function`1<bool> _N__N_wildcard_3547_3821
.field private int32 _N_this_used
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 2
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method _N_Enumerable_3800`1::.ctor

.method public hidebysig newslot specialname virtual final
instance int32 get_Current() cil managed
{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
IL_0006: ret
} // end of method _N_Enumerable_3800`1::get_Current

.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 8 (0x8)
.maxstack 2
IL_0000: ldarg.0
IL_0001: ldc.i4.m1
IL_0002: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0007: ret
} // end of method _N_Enumerable_3800`1::Dispose

.method public hidebysig newslot virtual final
instance void Reset() cil managed
{
// Code size 11 (0xb)
.maxstack 1
IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor()
IL_0005: throw

IL_0006: br IL_0006
} // end of method _N_Enumerable_3800`1::Reset

.method public hidebysig newslot virtual final
instance bool MoveNext() cil managed
{
// Code size 123 (0x7b)
.maxstack 13
.locals init ([0] bool V_0,
[1] bool V_1)
.try
{
IL_0000: ldc.i4.0
IL_0001: stloc.1
IL_0002: ldarg.0
IL_0003: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0008: ldc.i4.1
IL_0009: bne.un IL_0013

IL_000e: br IL_0066

IL_0013: ldarg.0
IL_0014: ldfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_0019: ldc.i4.0
IL_001a: bne.un IL_0024

IL_001f: br IL_002b

IL_0024: ldc.i4.0
IL_0025: stloc.1
IL_0026: br IL_006a

IL_002b: nop
IL_002c: nop
IL_002d: ldarg.0
IL_002e: ldarg.0
IL_002f: ldsfld class Program/_N__N_lambda__3790__3868`1<!0> class Program/_N__N_lambda__3790__3868`1<!T>::Instance
IL_0034: stfld class [Nemerle]Nemerle.Builtins.Function`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__N_lambda__3790_3827
IL_0039: ldarg.0
IL_003a: ldfld class [Nemerle]Nemerle.Builtins.Function`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__N_lambda__3790_3827
IL_003f: dup
IL_0040: ldvirtftn instance !0 class [Nemerle]Nemerle.Builtins.Function`1<bool>::apply()
IL_0046: newobj instance void class [mscorlib]System.Func`1<bool>::.ctor(object,
native int)
IL_004b: stfld class [mscorlib]System.Func`1<bool> class Program/_N_Enumerable_3800`1<!T>::_N__f_3829
IL_0050: ldarg.0
IL_0051: ldc.i4.s 42
IL_0053: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_current
IL_0058: ldarg.0
IL_0059: ldc.i4.1
IL_005a: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_state
IL_005f: ldc.i4.1
IL_0060: stloc.1
IL_0061: br IL_006a

IL_0066: nop
IL_0067: nop
IL_0068: ldc.i4.0
IL_0069: stloc.1
IL_006a: nop
IL_006b: ldloc.1
IL_006c: stloc.0
IL_006d: leave IL_0079

} // end .try
fault
{
IL_0072: ldarg.0
IL_0073: call instance void class Program/_N_Enumerable_3800`1<!T>::Dispose()
IL_0078: endfinally
} // end handler
IL_0079: ldloc.0
IL_007a: ret
} // end of method _N_Enumerable_3800`1::MoveNext

.method public hidebysig newslot virtual final
instance class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
GetEnumerator() cil managed
{
// Code size 55 (0x37)
.maxstack 4
.locals init ([0] class Program/_N_Enumerable_3800`1<!T> V_0)
IL_0000: ldarg.0
IL_0001: ldflda int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0006: ldc.i4.1
IL_0007: ldc.i4.0
IL_0008: call int32 [mscorlib]System.Threading.Interlocked::CompareExchange(int32&,
int32,
int32)
IL_000d: ldc.i4.0
IL_000e: ceq
IL_0010: ldc.i4.0
IL_0011: ceq
IL_0013: brfalse IL_0030

IL_0018: newobj instance void class Program/_N_Enumerable_3800`1<!T>::.ctor()
IL_001d: stloc.0
IL_001e: ldloc.0
IL_001f: ldarg.0
IL_0020: callvirt instance void class Program/_N_Enumerable_3800`1<!T>::CopyFrom(class Program/_N_Enumerable_3800`1<!0>)
IL_0025: ldloc.0
IL_0026: castclass class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
IL_002b: br IL_0036

IL_0030: ldarg.0
IL_0031: castclass class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>
IL_0036: ret
} // end of method _N_Enumerable_3800`1::GetEnumerator

.method private hidebysig newslot virtual final
instance class [mscorlib]System.Collections.IEnumerator
NonGenericGetEnum() cil managed
{
.override [mscorlib]System.Collections.IEnumerable::GetEnumerator
// Code size 55 (0x37)
.maxstack 4
.locals init ([0] class Program/_N_Enumerable_3800`1<!T> V_0)
IL_0000: ldarg.0
IL_0001: ldflda int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0006: ldc.i4.1
IL_0007: ldc.i4.0
IL_0008: call int32 [mscorlib]System.Threading.Interlocked::CompareExchange(int32&,
int32,
int32)
IL_000d: ldc.i4.0
IL_000e: ceq
IL_0010: ldc.i4.0
IL_0011: ceq
IL_0013: brfalse IL_0030

IL_0018: newobj instance void class Program/_N_Enumerable_3800`1<!T>::.ctor()
IL_001d: stloc.0
IL_001e: ldloc.0
IL_001f: ldarg.0
IL_0020: callvirt instance void class Program/_N_Enumerable_3800`1<!T>::CopyFrom(class Program/_N_Enumerable_3800`1<!0>)
IL_0025: ldloc.0
IL_0026: castclass [mscorlib]System.Collections.IEnumerator
IL_002b: br IL_0036

IL_0030: ldarg.0
IL_0031: castclass [mscorlib]System.Collections.IEnumerator
IL_0036: ret
} // end of method _N_Enumerable_3800`1::NonGenericGetEnum

.method private hidebysig instance void
CopyFrom(class Program/_N_Enumerable_3800`1<!T> other) cil managed
{
// Code size 10 (0xa)
.maxstack 2
IL_0000: ldarg.1
IL_0001: pop
IL_0002: ldarg.0
IL_0003: ldc.i4.1
IL_0004: stfld int32 class Program/_N_Enumerable_3800`1<!T>::_N_this_used
IL_0009: ret
} // end of method _N_Enumerable_3800`1::CopyFrom

.method private hidebysig specialname virtual final
instance object System.Collections.IEnumerator.get_Current() cil managed
{
.override [mscorlib]System.Collections.IEnumerator::get_Current
// Code size 12 (0xc)
.maxstack 1
IL_0000: ldarg.0
IL_0001: callvirt instance int32 class Program/_N_Enumerable_3800`1<!T>::get_Current()
IL_0006: box [mscorlib]System.Int32
IL_000b: ret
} // end of method _N_Enumerable_3800`1::System.Collections.IEnumerator.get_Current

.property int32 Current()
{
.get instance int32 Program/_N_Enumerable_3800`1::get_Current()
} // end of property _N_Enumerable_3800`1::Current
} // end of class _N_Enumerable_3800`1

.class auto ansi sealed nested private beforefieldinit _N__N_lambda__3790__3868`1<T>
extends class [Nemerle]Nemerle.Builtins.Function`1<bool>
{
.field public static initonly specialname class Program/_N__N_lambda__3790__3868`1<!T> Instance
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
// Code size 11 (0xb)
.maxstack 1
IL_0000: newobj instance void class Program/_N__N_lambda__3790__3868`1<!T>::.ctor()
IL_0005: stsfld class Program/_N__N_lambda__3790__3868`1<!0> class Program/_N__N_lambda__3790__3868`1<!T>::Instance
IL_000a: ret
} // end of method _N__N_lambda__3790__3868`1::.cctor

.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 2
IL_0000: ldarg.0
IL_0001: call instance void class [Nemerle]Nemerle.Builtins.Function`1<bool>::.ctor()
IL_0006: ret
} // end of method _N__N_lambda__3790__3868`1::.ctor

.method public hidebysig specialname virtual final
instance bool apply() cil managed
{
// Code size 3 (0x3)
.maxstack 1
IL_0000: nop
IL_0001: ldc.i4.1
IL_0002: ret
} // end of method _N__N_lambda__3790__3868`1::apply

} // end of class _N__N_lambda__3790__3868`1

.method public hidebysig static class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>
Foo<T>() cil managed
{
// Code size 8 (0x8)
.maxstack 1
.locals init ([0] class Program/_N_Enumerable_3800`1<!!T> V_0)
IL_0000: newobj instance void class Program/_N_Enumerable_3800`1<!!T>::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ret
} // end of method Program::Foo

.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 18 (0x12)
.maxstack 1
IL_0000: nop
IL_0001: call class [mscorlib]System.Collections.Generic.IEnumerable`1<int32> Program::Foo<int32>()
IL_0006: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1<!0> class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>::GetEnumerator()
IL_000b: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()
IL_0010: pop
IL_0011: ret
} // end of method Program::Main

} // end of class Program


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
http://rsdn.nemerleweb.com
http://nemerleweb.com
Re: BadImageFormatException when running simple program
От: _NN_ www.nemerleweb.com
Дата: 16.01.14 08:24
Оценка: 175 (4)
Здравствуйте, pekabon, Вы писали:

P>Привет,


P>посмотрите кто-нибудь багу, пожалуйста. Мы вчетвером не осилили:

Форумом осилим
После ковыряния
Автор: _NN_
Дата: 16.01.14
похоже ошибка нашлась.
В IL у нас
ldftn bool Program::_N__N_lambda__3790_3836<!!0>()

А должно быть видимо
ldftn bool Program::_N__N_lambda__3790_3836<!T>()


И действительно

Почему выходит !!0 надо уже смотреть в компиляторе в генерации опкода ldftn.

       | MethodAddress (from, meth, is_virt, typarms) =>
          def meth = GetMethodInfo (from, meth, typarms); // <-- Скорее всего тут возвращается неправильно информация о методе
          if (is_virt && meth.IsVirtual) {
            // ldvirtftn expects also an object reference
            // this is always part of delegate ctor, therefore
            // we can just dup the object reference
            _ilg.Emit (OpCodes.Dup);
            _ilg.Emit (OpCodes.Ldvirtftn, meth);
          } else
            _ilg.Emit (OpCodes.Ldftn, meth);


Теперь возьмем оригинальный код из бага.
Заменим
IL_0045:  ldvirtftn  instance !1 class [Nemerle]Nemerle.Builtins.Function`2<!!0,bool>::apply(!0)

на
IL_0045:  ldvirtftn  instance !1 class [Nemerle]Nemerle.Builtins.Function`2<!T,bool>::apply(!0)

И получаем "All Classes and Methods in a.exe Verified."
http://rsdn.nemerleweb.com
http://nemerleweb.com
Re[2]: BadImageFormatException when running simple program
От: _NN_ www.nemerleweb.com
Дата: 16.01.14 08:28
Оценка:
Здравствуйте, _NN_, Вы писали:

Еще немного поразмыслив, похоже баг в том , что вместо "!!0" должно быть с одним восклицательным знаком "!0" .
http://rsdn.nemerleweb.com
http://nemerleweb.com
Re[3]: BadImageFormatException when running simple program
От: VladD2 Российская Империя www.nemerle.org
Дата: 16.01.14 17:49
Оценка:
Здравствуйте, _NN_, Вы писали:

VD>>Упрощенная версия:

_NN>Можно еще проще без foreach
_NN>
_NN>  Main() : void
_NN>  {
_NN>    _ = Foo.[int]().GetEnumerator().MoveNext();
_NN>  }
_NN>


Это к делу не относится.
Есть логика намерений и логика обстоятельств, последняя всегда сильнее.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.