dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.03k stars 4.68k forks source link

More nativeaot constrained call bug(s) #98582

Open mrvoorhe opened 7 months ago

mrvoorhe commented 7 months ago

Description

Here's another of our constrained call tests that failed with nativeaot.

Reproduction Steps

1) Unzip the attached file ConsoleApp45.zip

2) Run dotnet publish 3) Run .\ConsoleApp45\bin\Release\net8.0\win-x64\publish\ConsoleApp45.exe

Expected behavior

C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> dotnet run                                   
Check1 = 3
Check2 = 6
Check3 = 9
Check4 = 12
CheckGen1 = 3
CheckGen2 = 6

Actual behavior

PS C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> dotnet publish
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  Restored C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\ConsoleApp45.csproj (in 228 ms).
  ConsoleApp45 -> C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\bin\Release\net8.0\win-x64\ConsoleApp45.dll
  Generating native code
  ILC: Method '[ConsoleApp45]Program.<<Main>$>g__Check|0_0<AdderExplicit`1<__Canon>,__Canon>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata
  ILC: Method '[ConsoleApp45]Program.<<Main>$>g__CheckGen2|0_2<AdderExplicit`1<__Canon>>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata
  ILC: Method '[ConsoleApp45]Program.<<Main>$>g__CheckGen1|0_1<AdderExplicit`1<__Canon>>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata
  ConsoleApp45 -> C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\bin\Release\net8.0\win-x64\publish\
C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> .\bin\Release\net8.0\win-x64\publish\ConsoleApp45.exe
Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID) + 0x31
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowInvalidProgramException(ExceptionStringID) + 0x9
   at Program.<<Main>$>g__Check|0_0[T,U](T) + 0xe
   at Program.<Main>$(String[] args) + 0x27
   at ConsoleApp45!<BaseAddress>+0xd2a10
PS C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45>

Regression?

I suspect it probably happened with the net7 nativeaot but I don't know for certain. I didn't explicitly check this test back when I was testing net7 nativeaot.

.NET Core is fine. Mono and .NET Framework are also fine.

Known Workarounds

No response

Configuration

No response

Other information

No response

ghost commented 7 months ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Here's another of our constrained call tests that failed with nativeaot. ### Reproduction Steps 1) Unzip the attached file [ConsoleApp45.zip](https://github.com/dotnet/runtime/files/14316357/ConsoleApp45.zip) 2) Run dotnet publish 3) Run .\ConsoleApp45\bin\Release\net8.0\win-x64\publish\ConsoleApp45.exe ### Expected behavior ``` C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> dotnet run Check1 = 3 Check2 = 6 Check3 = 9 Check4 = 12 CheckGen1 = 3 CheckGen2 = 6 ``` ### Actual behavior ``` PS C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> dotnet publish MSBuild version 17.8.3+195e7f5a3 for .NET Determining projects to restore... Restored C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\ConsoleApp45.csproj (in 228 ms). ConsoleApp45 -> C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\bin\Release\net8.0\win-x64\ConsoleApp45.dll Generating native code ILC: Method '[ConsoleApp45]Program.<
$>g__Check|0_0,__Canon>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata ILC: Method '[ConsoleApp45]Program.<
$>g__CheckGen2|0_2>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata ILC: Method '[ConsoleApp45]Program.<
$>g__CheckGen1|0_1>(AdderExplicit`1<__Canon>)' will always throw because: Invalid IL or CLR metadata ConsoleApp45 -> C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45\bin\Release\net8.0\win-x64\publish\ C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> .\bin\Release\net8.0\win-x64\publish\ConsoleApp45.exe Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program. at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID) + 0x31 at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowInvalidProgramException(ExceptionStringID) + 0x9 at Program.<
$>g__Check|0_0[T,U](T) + 0xe at Program.
$(String[] args) + 0x27 at ConsoleApp45!+0xd2a10 PS C:\UnitySrc\dev\TestGround\ConsoleApp45\ConsoleApp45> ``` ### Regression? I suspect it probably happened with the net7 nativeaot but I don't know for certain. I didn't explicitly check this test back when I was testing net7 nativeaot. .NET Core is fine. Mono and .NET Framework are also fine. ### Known Workarounds _No response_ ### Configuration _No response_ ### Other information _No response_
Author: mrvoorhe
Assignees: -
Labels: `untriaged`, `area-NativeAOT-coreclr`
Milestone: -
mrvoorhe commented 7 months ago

Here's another test that is similar. I don't know if it's a separate issue or not. It reuses some of the same interfaces that are in the repro project.

AdderImplicit<object> t = default(AdderImplicit<object>);
var check1 = Check<AdderImplicit<object>, IGen1<object>>(t);
Console.WriteLine($"Check1 = {check1}");
t = default(AdderImplicit<object>);
var check2 = Check<AdderImplicit<object>, IGen2<object>>(t);
t = default(AdderImplicit<object>);
Console.WriteLine($"Check2 = {check2}");
var check3 = Check<AdderImplicit<object>, IGen3<object>>(t);
Console.WriteLine($"Check3 = {check3}");
var tt = default(AdderImplicit<Atom>);
var check4 = Check<AdderImplicit<Atom>, Atom>(tt);
Console.WriteLine($"Check4 = {check4}");

    struct AdderImplicit<T> : IAdder<IGen1<T>>, IAdder<IGen2<T>>, IAdder<IGen3<T>>, IAdder<Atom>
    {
        private int _field;

        public int Add(int p)
        {
            _field += p;
            return _field;
        }

        public int PlusPlus()
        {
            return Add(1);
        }
    }
MichalStrehovsky commented 7 months ago

Likely dup of https://github.com/dotnet/runtimelab/issues/1431 (see blocked tests in issues.targets).