dotnet / runtime

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

ILLink: stack overflow when handling type parameters in compiler generated code #93803

Open vitek-karas opened 1 year ago

vitek-karas commented 1 year ago

Repro:

dotnet new console

app.csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishTrimmed>true</PublishTrimmed>
        <WarningsAsErrors>false</WarningsAsErrors>
        <NoWarn>NU1605;NU1603;NU1701</NoWarn>
    </PropertyGroup>

    <ItemGroup>
        <TrimmerRootAssembly Include="Microsoft.EntityFrameworkCore.Specification.Tests" />

        <PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="6.0.0-preview.5.21301.9" />
    </ItemGroup>
</Project>

dotnet publish

Stack trace:

StackOverFlowException:
     at System.Collections.Generic.HashSet`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(System.__Canon)
     at Mono.Linker.LinkContext.GetMethodIL(Mono.Cecil.MethodDefinition)
     at Mono.Linker.LinkContext.GetMethodIL(Mono.Cecil.Cil.MethodBody)
     at Mono.Linker.Dataflow.CompilerGeneratedState.<GetCompilerGeneratedStateForType>g__ScanForInit|11_2(Mono.Cecil.TypeDefinition, Mono.Cecil.Cil.MethodBody, 
    ...
     at Mono.Linker.Dataflow.CompilerGeneratedState.GetCompilerGeneratedStateForType(Mono.Cecil.TypeDefinition)
     at Mono.Linker.Dataflow.CompilerGeneratedState.GetGeneratedTypeAttributes(Mono.Cecil.TypeDefinition)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetGeneratedTypeAttributes(Mono.Cecil.TypeDefinition)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.BuildTypeAnnotations(Mono.Cecil.TypeDefinition)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetAnnotations(Mono.Cecil.TypeDefinition)

/cc @LakshanF

ghost commented 1 year ago

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

Issue Details
Repro: `dotnet new console` `app.csproj`: ```xml Exe net8.0 enable enable true false NU1605;NU1603;NU1701 ``` `dotnet publish` Stack trace: ``` StackOverFlowException: at System.Collections.Generic.HashSet`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(System.__Canon) at Mono.Linker.LinkContext.GetMethodIL(Mono.Cecil.MethodDefinition) at Mono.Linker.LinkContext.GetMethodIL(Mono.Cecil.Cil.MethodBody) at Mono.Linker.Dataflow.CompilerGeneratedState.g__ScanForInit|11_2(Mono.Cecil.TypeDefinition, Mono.Cecil.Cil.MethodBody, ... at Mono.Linker.Dataflow.CompilerGeneratedState.GetCompilerGeneratedStateForType(Mono.Cecil.TypeDefinition) at Mono.Linker.Dataflow.CompilerGeneratedState.GetGeneratedTypeAttributes(Mono.Cecil.TypeDefinition) at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetGeneratedTypeAttributes(Mono.Cecil.TypeDefinition) at ILLink.Shared.TrimAnalysis.FlowAnnotations.BuildTypeAnnotations(Mono.Cecil.TypeDefinition) at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetAnnotations(Mono.Cecil.TypeDefinition) ``` /cc @LakshanF
Author: vitek-karas
Assignees: -
Labels: `area-Tools-ILLink`
Milestone: -