Skip to content

Commit 0f457d1

Browse files
authored
print error when users try DisassemblyDiagnoser with NativeAOT (#2068)
* there should be only one method that tells whether given Job is NativeAOT or not * print error when users try DisassemblyDiagnoser with NativeAOT
1 parent 8e355b5 commit 0f457d1

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoser.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using BenchmarkDotNet.Reports;
1616
using BenchmarkDotNet.Running;
1717
using BenchmarkDotNet.Toolchains.InProcess.NoEmit;
18+
using BenchmarkDotNet.Toolchains.NativeAot;
1819
using BenchmarkDotNet.Validators;
1920

2021
namespace BenchmarkDotNet.Diagnosers
@@ -102,10 +103,14 @@ public IEnumerable<ValidationError> Validate(ValidationParameters validationPara
102103

103104
foreach (var benchmark in validationParameters.Benchmarks)
104105
{
105-
if (benchmark.Job.Infrastructure.HasValue(InfrastructureMode.ToolchainCharacteristic) && benchmark.Job.Infrastructure.Toolchain is InProcessNoEmitToolchain)
106+
if (benchmark.Job.Infrastructure.TryGetToolchain(out var toolchain) && toolchain is InProcessNoEmitToolchain)
106107
{
107108
yield return new ValidationError(true, "InProcessToolchain has no DisassemblyDiagnoser support", benchmark);
108109
}
110+
else if (benchmark.Job.IsNativeAOT())
111+
{
112+
yield return new ValidationError(true, "Currently NativeAOT has no DisassemblyDiagnoser support", benchmark);
113+
}
109114

110115
if (ShouldUseLinuxDisassembler(benchmark))
111116
{

src/BenchmarkDotNet/Jobs/EnvironmentMode.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using BenchmarkDotNet.Characteristics;
44
using BenchmarkDotNet.Environments;
5+
using BenchmarkDotNet.Portability;
56
using JetBrains.Annotations;
67

78
namespace BenchmarkDotNet.Jobs
@@ -110,5 +111,7 @@ public void SetEnvironmentVariable(EnvironmentVariable variable)
110111
newVariables.Add(variable);
111112
EnvironmentVariables = newVariables;
112113
}
114+
115+
internal Runtime GetRuntime() => HasValue(RuntimeCharacteristic) ? Runtime : RuntimeInformation.GetCurrentRuntime();
113116
}
114117
}

src/BenchmarkDotNet/Jobs/JobExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using BenchmarkDotNet.Environments;
88
using BenchmarkDotNet.Running;
99
using BenchmarkDotNet.Toolchains;
10+
using BenchmarkDotNet.Toolchains.NativeAot;
1011
using JetBrains.Annotations;
1112
using Perfolizer.Horology;
1213
using Perfolizer.Mathematics.OutlierDetection;
@@ -417,6 +418,11 @@ internal static Job MakeSettingsUserFriendly(this Job job, Descriptor descriptor
417418
return job;
418419
}
419420

421+
internal static bool IsNativeAOT(this Job job)
422+
=> job.Environment.GetRuntime() is NativeAotRuntime
423+
// given job can have NativeAOT toolchain set, but Runtime == default
424+
|| (job.Infrastructure.TryGetToolchain(out var toolchain) && toolchain is NativeAotToolchain);
425+
420426
private static Job WithCore(this Job job, Action<Job> updateCallback)
421427
{
422428
bool hasId = job.HasValue(Job.IdCharacteristic);

src/BenchmarkDotNet/Running/BuildPartition.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,15 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
4848
[PublicAPI]
4949
public Jit Jit => RepresentativeBenchmarkCase.Job.ResolveValue(EnvironmentMode.JitCharacteristic, Resolver);
5050

51-
public bool IsNativeAot => Runtime is NativeAotRuntime
52-
// given job can have NativeAOT toolchain set, but Runtime == default
53-
|| (RepresentativeBenchmarkCase.Job.Infrastructure.TryGetToolchain(out var toolchain) && toolchain is NativeAotToolchain);
51+
public bool IsNativeAot => RepresentativeBenchmarkCase.Job.IsNativeAOT();
5452

5553
public bool IsWasm => Runtime is WasmRuntime // given job can have Wasm toolchain set, but Runtime == default ;)
5654
|| (RepresentativeBenchmarkCase.Job.Infrastructure.TryGetToolchain(out var toolchain) && toolchain is WasmToolChain);
5755

5856
public bool IsNetFramework => Runtime is ClrRuntime
5957
|| (RepresentativeBenchmarkCase.Job.Infrastructure.TryGetToolchain(out var toolchain) && (toolchain is RoslynToolchain || toolchain is CsProjClassicNetToolchain));
6058

61-
public Runtime Runtime => RepresentativeBenchmarkCase.Job.Environment.HasValue(EnvironmentMode.RuntimeCharacteristic)
62-
? RepresentativeBenchmarkCase.Job.Environment.Runtime
63-
: RuntimeInformation.GetCurrentRuntime();
59+
public Runtime Runtime => RepresentativeBenchmarkCase.Job.Environment.GetRuntime();
6460

6561
public bool IsCustomBuildConfiguration => BuildConfiguration != InfrastructureMode.ReleaseConfigurationName;
6662

0 commit comments

Comments
 (0)