Skip to content

[NativeAOT] KeyNotFoundException thrown when compiling dotnet/performance microbenchmarks boilerplate #66028

@adamsitnik

Description

@adamsitnik

I am currently trying to make dotnet/performance microbenchmarks work with NativeAOT and BenchmarkDotNet.
Of course the build produced a lot of warnings, but unfortunately also one error that is kind of blocking me:

EXEC : error : The given key '[S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOIIR<__Canon,__Canon,float32,bool>(object,native int,ArgSetupState&,bool)' was not present in the dictionary. [D:\projects\performance\artifacts\bin\MicroBenchmarks\Releas
e\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1\BenchmarkDotNet.Autogenerated.csproj]
  System.Collections.Generic.KeyNotFoundException: The given key '[S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOIIR<__Canon,__Canon,float32,bool>(object,native int,ArgSetupState&,bool)' was not present in the dictionary.
     at ILCompiler.DependencyAnalysis.ReflectionInvokeMapNode.GetData(NodeFactory factory, Boolean relocsOnly)
     at ILCompiler.DependencyAnalysis.ObjectWriter.EmitObject(String objectFilePath, IReadOnlyCollection`1 nodes, NodeFactory factory, ObjectWritingOptions options, IObjectDumper dumper, Logger logger)
     at ILCompiler.RyuJitCompilation.CompileInternal(String outputFile, ObjectDumper dumper)
     at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String outputFile, ObjectDumper dumper)
     at ILCompiler.Program.Run(String[] args)
     at ILCompiler.Program.Main(String[] args)
C:\Users\adsitnik\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-preview.3.22151.1\build\Microsoft.NETCore.Native.targets(269,5): error MSB3073: The command ""C:\Users\adsitnik\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.3.22151.1\tools
\\ilc" @"D:\projects\performance\artifacts\obj\BenchmarkDotNet.Autogenerated\Release\net7.0\win-x64\native\1733e900-b107-4811-a03c-48fcd1874dc1.ilc.rsp"" exited with code 1. [D:\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-4
8fcd1874dc1\BenchmarkDotNet.Autogenerated.csproj]

Repro:

git clone https://github.com/adamsitnik/performance.git repro
cd repro
git checkout nativeAOT
dotnet run -c Release -f net7.0 --filter * --project .\src\benchmarks\micro\MicroBenchmarks.csproj --iterationCount 1 --warmupCount 0 --invocationCount 1 --unrollFactor 1 --strategy ColdStart --stopOnFirstError true

You will see BDN produce output like this:

// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 4533 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
// start dotnet restore -r win-x64 /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in D:\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1
// command took 27.08s and exited with 0
// start dotnet build -c Release -r win-x64 --no-restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in D:\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1
// command took 16.3s and exited with 1
// start dotnet build -c Release -r win-x64 --no-restore --no-dependencies /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in D:\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1
// command took 25.61s and exited with 0
// start dotnet publish -c Release -r win-x64 --no-build --no-restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in D:\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1
// command took 100.61s and exited with 1

To get a nice colorful MSBuild output you need to cd to the directory generated by BDN and copy the last command. In that case it's:

cd :\projects\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\1733e900-b107-4811-a03c-48fcd1874dc1
dotnet publish -c Release -r win-x64 --no-build --no-restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true

cc @MichalStrehovsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions