From 5428ebdb8b6e9a847bb8ae6cf129b7dd9d784454 Mon Sep 17 00:00:00 2001 From: Alina Smirnova Date: Sun, 3 Sep 2023 12:35:20 +0200 Subject: [PATCH] Fixed nullability warnings in methods signatures --- .../BenchmarkDotNet.Samples/IntroOrderManual.cs | 4 ++-- .../Configs/InliningDiagnoserAttribute.cs | 2 +- .../EtwDiagnoser.cs | 2 +- .../EtwProfilerConfig.cs | 4 ++-- .../InliningDiagnoser.cs | 2 +- src/BenchmarkDotNet/Code/EnumParam.cs | 2 +- src/BenchmarkDotNet/Columns/StatisticColumn.cs | 2 +- .../ConsoleArguments/ConfigParser.cs | 2 +- .../Diagnosers/EventPipeProfiler.cs | 2 +- .../Disassemblers/DisassemblyDiagnoserConfig.cs | 4 ++-- .../Environments/Runtimes/ClrRuntime.cs | 2 +- .../Environments/Runtimes/WasmRuntime.cs | 2 +- .../Exporters/Csv/CsvMeasurementsExporter.cs | 2 +- src/BenchmarkDotNet/Helpers/ProcessHelper.cs | 4 ++-- src/BenchmarkDotNet/Jobs/JobExtensions.cs | 2 +- src/BenchmarkDotNet/Jobs/NugetReference.cs | 2 +- .../Loggers/AsyncProcessOutputReader.cs | 2 +- src/BenchmarkDotNet/Loggers/ConsoleLogger.cs | 2 +- src/BenchmarkDotNet/Order/DefaultOrderer.cs | 4 ++-- src/BenchmarkDotNet/Order/IOrderer.cs | 4 ++-- src/BenchmarkDotNet/Reports/Summary.cs | 2 +- src/BenchmarkDotNet/Reports/SummaryTable.cs | 2 +- src/BenchmarkDotNet/Running/Descriptor.cs | 14 +++++++------- .../Toolchains/CoreRun/CoreRunPublisher.cs | 2 +- .../Toolchains/CoreRun/CoreRunToolchain.cs | 2 +- .../Toolchains/CsProj/CsProjClassicNetToolchain.cs | 4 ++-- .../Toolchains/DotNetCli/DotNetCliBuilder.cs | 2 +- .../Toolchains/DotNetCli/DotNetCliCommand.cs | 6 +++--- .../DotNetCli/DotNetCliCommandExecutor.cs | 2 +- .../Toolchains/DotNetCli/DotNetCliPublisher.cs | 2 +- .../Toolchains/DotNetCli/MsBuildErrorMapper.cs | 2 +- .../Toolchains/DotNetCli/NetCoreAppSettings.cs | 12 ++++++------ .../Toolchains/Parameters/ExecuteParameters.cs | 2 +- .../Toolchains/Results/GenerateResult.cs | 2 +- .../Toolchains/ToolchainExtensions.cs | 2 +- src/BenchmarkDotNet/Validators/ValidationError.cs | 2 +- .../BenchmarkTestExecutor.cs | 6 +++--- .../ExporterIOTests.cs | 2 +- .../RunnableStructCaseBenchmark.tt | 2 +- .../InProcessTest.cs | 2 +- .../Engine/EngineWarmupStageTests.cs | 2 +- .../Reports/FakeMetricDescriptor.cs | 2 +- tests/BenchmarkDotNet.Tests/TypeFilterTests.cs | 2 +- 43 files changed, 65 insertions(+), 65 deletions(-) diff --git a/samples/BenchmarkDotNet.Samples/IntroOrderManual.cs b/samples/BenchmarkDotNet.Samples/IntroOrderManual.cs index 625e78a816..a624edd205 100644 --- a/samples/BenchmarkDotNet.Samples/IntroOrderManual.cs +++ b/samples/BenchmarkDotNet.Samples/IntroOrderManual.cs @@ -22,7 +22,7 @@ private class Config : ManualConfig private class FastestToSlowestOrderer : IOrderer { public IEnumerable GetExecutionOrder(ImmutableArray benchmarksCase, - IEnumerable order = null) => + IEnumerable? order = null) => from benchmark in benchmarksCase orderby benchmark.Parameters["X"] descending, benchmark.Descriptor.WorkloadMethodDisplayInfo @@ -39,7 +39,7 @@ public string GetLogicalGroupKey(ImmutableArray allBenchmarksCase benchmarkCase.Job.DisplayInfo + "_" + benchmarkCase.Parameters.DisplayInfo; public IEnumerable> GetLogicalGroupOrder(IEnumerable> logicalGroups, - IEnumerable order = null) => + IEnumerable? order = null) => logicalGroups.OrderBy(it => it.Key); public bool SeparateLogicalGroups => true; diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/Configs/InliningDiagnoserAttribute.cs b/src/BenchmarkDotNet.Diagnostics.Windows/Configs/InliningDiagnoserAttribute.cs index 0a3f4e0dc5..c9878ed6fc 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/Configs/InliningDiagnoserAttribute.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/Configs/InliningDiagnoserAttribute.cs @@ -13,7 +13,7 @@ public InliningDiagnoserAttribute(bool logFailuresOnly = true, bool filterByName Config = ManualConfig.CreateEmpty().AddDiagnoser(new InliningDiagnoser(logFailuresOnly, filterByNamespace)); } - public InliningDiagnoserAttribute(bool logFailuresOnly = true, string[] allowedNamespaces = null) + public InliningDiagnoserAttribute(bool logFailuresOnly = true, string[]? allowedNamespaces = null) { Config = ManualConfig.CreateEmpty().AddDiagnoser(new InliningDiagnoser(logFailuresOnly, allowedNamespaces)); } diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/EtwDiagnoser.cs b/src/BenchmarkDotNet.Diagnostics.Windows/EtwDiagnoser.cs index c52006d7c6..80423d72cf 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/EtwDiagnoser.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/EtwDiagnoser.cs @@ -97,7 +97,7 @@ private void Clear() private void OnProcessExit(object sender, EventArgs e) => Session?.Dispose(); - private static string GetSessionName(string prefix, BenchmarkCase benchmarkCase, ParameterInstances parameters = null) + private static string GetSessionName(string prefix, BenchmarkCase benchmarkCase, ParameterInstances? parameters = null) { if (parameters != null && parameters.Items.Count > 0) return $"{prefix}-{benchmarkCase.FolderInfo}-{parameters.FolderInfo}"; diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/EtwProfilerConfig.cs b/src/BenchmarkDotNet.Diagnostics.Windows/EtwProfilerConfig.cs index 967dcc2d03..7846edd1dd 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/EtwProfilerConfig.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/EtwProfilerConfig.cs @@ -41,8 +41,8 @@ public EtwProfilerConfig( float cpuSampleIntervalInMilliseconds = 1.0f, KernelTraceEventParser.Keywords kernelKeywords = KernelTraceEventParser.Keywords.ImageLoad | KernelTraceEventParser.Keywords.Profile, KernelTraceEventParser.Keywords kernelStackKeywords = KernelTraceEventParser.Keywords.Profile, - IReadOnlyDictionary> intervalSelectors = null, - IReadOnlyCollection<(Guid providerGuid, TraceEventLevel providerLevel, ulong keywords, TraceEventProviderOptions options)> providers = null, + IReadOnlyDictionary>? intervalSelectors = null, + IReadOnlyCollection<(Guid providerGuid, TraceEventLevel providerLevel, ulong keywords, TraceEventProviderOptions options)>? providers = null, bool createHeapSession = false) { CreateHeapSession = createHeapSession; diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs b/src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs index 4c09957eef..bb9fd42ce7 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs @@ -35,7 +35,7 @@ public InliningDiagnoser(bool logFailuresOnly = true, bool filterByNamespace = t /// /// only the methods that failed to get inlined. True by default. /// list of namespaces from which inlining message should be print. - public InliningDiagnoser(bool logFailuresOnly = true, string[] allowedNamespaces = null) + public InliningDiagnoser(bool logFailuresOnly = true, string[]? allowedNamespaces = null) { this.logFailuresOnly = logFailuresOnly; this.allowedNamespaces = allowedNamespaces; diff --git a/src/BenchmarkDotNet/Code/EnumParam.cs b/src/BenchmarkDotNet/Code/EnumParam.cs index 9d0ac58950..5c0ecf6afd 100644 --- a/src/BenchmarkDotNet/Code/EnumParam.cs +++ b/src/BenchmarkDotNet/Code/EnumParam.cs @@ -24,7 +24,7 @@ private EnumParam(object value, Type type) public string ToSourceCode() => $"({type.GetCorrectCSharpTypeName()})({ToInvariantCultureString()})"; - internal static IParam FromObject(object value, Type type = null) + internal static IParam FromObject(object value, Type? type = null) { type = type ?? value.GetType(); if (!type.IsEnum) diff --git a/src/BenchmarkDotNet/Columns/StatisticColumn.cs b/src/BenchmarkDotNet/Columns/StatisticColumn.cs index 31e72f2446..f0b9655acc 100644 --- a/src/BenchmarkDotNet/Columns/StatisticColumn.cs +++ b/src/BenchmarkDotNet/Columns/StatisticColumn.cs @@ -107,7 +107,7 @@ private enum Priority private readonly IStatisticColumn parentColumn; private StatisticColumn(string columnName, string legend, Func calc, Priority priority, UnitType type = UnitType.Time, - IStatisticColumn parentColumn = null) + IStatisticColumn? parentColumn = null) { this.calc = calc; this.priority = priority; diff --git a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs index 76500bed44..108c55b1ce 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs @@ -72,7 +72,7 @@ public static class ConfigParser { "fullxml", new[] { XmlExporter.Full } } }; - public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse(string[] args, ILogger logger, IConfig globalConfig = null) + public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse(string[] args, ILogger logger, IConfig? globalConfig = null) { (bool isSuccess, IConfig config, CommandLineOptions options) result = default; diff --git a/src/BenchmarkDotNet/Diagnosers/EventPipeProfiler.cs b/src/BenchmarkDotNet/Diagnosers/EventPipeProfiler.cs index 211d4a06e2..c1c76e8c9e 100644 --- a/src/BenchmarkDotNet/Diagnosers/EventPipeProfiler.cs +++ b/src/BenchmarkDotNet/Diagnosers/EventPipeProfiler.cs @@ -40,7 +40,7 @@ public EventPipeProfiler() :this(profile: EventPipeProfile.CpuSampling, performE /// A named pre-defined set of provider configurations that allows common tracing scenarios to be specified succinctly. /// A list of EventPipe providers to be enabled. /// if set to true, benchmarks will be executed one more time with the profiler attached. If set to false, there will be no extra run but the results will contain overhead. True by default. - public EventPipeProfiler(EventPipeProfile profile = EventPipeProfile.CpuSampling, IReadOnlyCollection providers = null, bool performExtraBenchmarksRun = true) + public EventPipeProfiler(EventPipeProfile profile = EventPipeProfile.CpuSampling, IReadOnlyCollection? providers = null, bool performExtraBenchmarksRun = true) { this.performExtraBenchmarksRun = performExtraBenchmarksRun; eventPipeProviders = MapToProviders(profile, providers); diff --git a/src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoserConfig.cs b/src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoserConfig.cs index 7c917c80b0..feff76ef99 100644 --- a/src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoserConfig.cs +++ b/src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoserConfig.cs @@ -22,8 +22,8 @@ public class DisassemblyDiagnoserConfig public DisassemblyDiagnoserConfig( int maxDepth = 1, DisassemblySyntax syntax = DisassemblySyntax.Masm, - string[] filters = null, - FormatterOptions formatterOptions = null, + string[]? filters = null, + FormatterOptions? formatterOptions = null, bool printSource = false, bool printInstructionAddresses = false, bool exportGithubMarkdown = true, diff --git a/src/BenchmarkDotNet/Environments/Runtimes/ClrRuntime.cs b/src/BenchmarkDotNet/Environments/Runtimes/ClrRuntime.cs index 35460ce853..be5a84cce2 100644 --- a/src/BenchmarkDotNet/Environments/Runtimes/ClrRuntime.cs +++ b/src/BenchmarkDotNet/Environments/Runtimes/ClrRuntime.cs @@ -17,7 +17,7 @@ public class ClrRuntime : Runtime, IEquatable public string Version { get; } - private ClrRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName, string version = null) + private ClrRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName, string? version = null) : base(runtimeMoniker, msBuildMoniker, displayName) { Version = version; diff --git a/src/BenchmarkDotNet/Environments/Runtimes/WasmRuntime.cs b/src/BenchmarkDotNet/Environments/Runtimes/WasmRuntime.cs index bb6c122700..3fcc07f26a 100644 --- a/src/BenchmarkDotNet/Environments/Runtimes/WasmRuntime.cs +++ b/src/BenchmarkDotNet/Environments/Runtimes/WasmRuntime.cs @@ -28,7 +28,7 @@ public class WasmRuntime : Runtime, IEquatable /// Specifies whether AOT or Interpreter (default) project should be generated. /// Specifies a wasm data directory surfaced as $(WasmDataDir) for the project /// Runtime moniker - public WasmRuntime(string msBuildMoniker = "net5.0", string displayName = "Wasm", string javaScriptEngine = "v8", string javaScriptEngineArguments = "--expose_wasm", bool aot = false, string wasmDataDir = null, RuntimeMoniker moniker = RuntimeMoniker.Wasm) : base(moniker, msBuildMoniker, displayName) + public WasmRuntime(string msBuildMoniker = "net5.0", string displayName = "Wasm", string javaScriptEngine = "v8", string javaScriptEngineArguments = "--expose_wasm", bool aot = false, string? wasmDataDir = null, RuntimeMoniker moniker = RuntimeMoniker.Wasm) : base(moniker, msBuildMoniker, displayName) { if (!string.IsNullOrEmpty(javaScriptEngine) && javaScriptEngine != "v8" && !File.Exists(javaScriptEngine)) throw new FileNotFoundException($"Provided {nameof(javaScriptEngine)} file: \"{javaScriptEngine}\" doest NOT exist"); diff --git a/src/BenchmarkDotNet/Exporters/Csv/CsvMeasurementsExporter.cs b/src/BenchmarkDotNet/Exporters/Csv/CsvMeasurementsExporter.cs index 74f6130f1c..0d07c9058c 100644 --- a/src/BenchmarkDotNet/Exporters/Csv/CsvMeasurementsExporter.cs +++ b/src/BenchmarkDotNet/Exporters/Csv/CsvMeasurementsExporter.cs @@ -20,7 +20,7 @@ public class CsvMeasurementsExporter : ExporterBase private static readonly Lazy Columns = new Lazy(BuildColumns); private readonly CsvSeparator separator; - public CsvMeasurementsExporter(CsvSeparator separator, SummaryStyle style = null) + public CsvMeasurementsExporter(CsvSeparator separator, SummaryStyle? style = null) { this.separator = separator; Style = style ?? SummaryStyle.Default; diff --git a/src/BenchmarkDotNet/Helpers/ProcessHelper.cs b/src/BenchmarkDotNet/Helpers/ProcessHelper.cs index 114ae287fb..1b75c6392f 100644 --- a/src/BenchmarkDotNet/Helpers/ProcessHelper.cs +++ b/src/BenchmarkDotNet/Helpers/ProcessHelper.cs @@ -12,7 +12,7 @@ internal static class ProcessHelper /// Run external process and return the console output. /// In the case of any exception, null will be returned. /// - internal static string? RunAndReadOutput(string fileName, string arguments = "", ILogger logger = null) + internal static string? RunAndReadOutput(string fileName, string arguments = "", ILogger? logger = null) { var processStartInfo = new ProcessStartInfo { @@ -42,7 +42,7 @@ internal static class ProcessHelper } internal static (int exitCode, ImmutableArray output) RunAndReadOutputLineByLine(string fileName, string arguments = "", string workingDirectory = "", - Dictionary environmentVariables = null, bool includeErrors = false, ILogger logger = null) + Dictionary? environmentVariables = null, bool includeErrors = false, ILogger? logger = null) { var processStartInfo = new ProcessStartInfo { diff --git a/src/BenchmarkDotNet/Jobs/JobExtensions.cs b/src/BenchmarkDotNet/Jobs/JobExtensions.cs index 8cbf7445d7..2a236dc44f 100644 --- a/src/BenchmarkDotNet/Jobs/JobExtensions.cs +++ b/src/BenchmarkDotNet/Jobs/JobExtensions.cs @@ -339,7 +339,7 @@ public static Job WithEnvironmentVariable(this Job job, string key, string value /// (optional)Indicate the URI of the NuGet package source to use during the restore operation. /// (optional)Allows prerelease packages to be installed. /// - public static Job WithNuGet(this Job job, string packageName, string packageVersion = null, Uri source = null, bool prerelease = false) => + public static Job WithNuGet(this Job job, string packageName, string? packageVersion = null, Uri? source = null, bool prerelease = false) => job.WithCore(j => j.Infrastructure.NuGetReferences = new NuGetReferenceList(j.Infrastructure.NuGetReferences ?? Array.Empty()) { diff --git a/src/BenchmarkDotNet/Jobs/NugetReference.cs b/src/BenchmarkDotNet/Jobs/NugetReference.cs index 3e5819c4ae..0db3a028de 100644 --- a/src/BenchmarkDotNet/Jobs/NugetReference.cs +++ b/src/BenchmarkDotNet/Jobs/NugetReference.cs @@ -5,7 +5,7 @@ namespace BenchmarkDotNet.Jobs { public class NuGetReference : IEquatable { - public NuGetReference(string packageName, string packageVersion, Uri source = null, bool prerelease = false) + public NuGetReference(string packageName, string packageVersion, Uri? source = null, bool prerelease = false) { if (string.IsNullOrWhiteSpace(packageName)) throw new ArgumentException("message", nameof(packageName)); diff --git a/src/BenchmarkDotNet/Loggers/AsyncProcessOutputReader.cs b/src/BenchmarkDotNet/Loggers/AsyncProcessOutputReader.cs index a503da8e76..d4a059153d 100644 --- a/src/BenchmarkDotNet/Loggers/AsyncProcessOutputReader.cs +++ b/src/BenchmarkDotNet/Loggers/AsyncProcessOutputReader.cs @@ -19,7 +19,7 @@ internal class AsyncProcessOutputReader : IDisposable private long status; - internal AsyncProcessOutputReader(Process process, bool logOutput = false, ILogger logger = null, bool readStandardError = true) + internal AsyncProcessOutputReader(Process process, bool logOutput = false, ILogger? logger = null, bool readStandardError = true) { if (!process.StartInfo.RedirectStandardOutput) throw new NotSupportedException("set RedirectStandardOutput to true first"); diff --git a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs index a54bf88edc..a1c7795d53 100644 --- a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs +++ b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs @@ -21,7 +21,7 @@ private static readonly bool ConsoleSupportsColors private readonly Dictionary colorScheme; [PublicAPI] - public ConsoleLogger(bool unicodeSupport = false, Dictionary colorScheme = null) + public ConsoleLogger(bool unicodeSupport = false, Dictionary? colorScheme = null) { this.unicodeSupport = unicodeSupport; this.colorScheme = colorScheme ?? CreateColorfulScheme(); diff --git a/src/BenchmarkDotNet/Order/DefaultOrderer.cs b/src/BenchmarkDotNet/Order/DefaultOrderer.cs index 0bca3cf3ec..656de7ce98 100644 --- a/src/BenchmarkDotNet/Order/DefaultOrderer.cs +++ b/src/BenchmarkDotNet/Order/DefaultOrderer.cs @@ -37,7 +37,7 @@ public DefaultOrderer( [PublicAPI] public virtual IEnumerable GetExecutionOrder( ImmutableArray benchmarkCases, - IEnumerable order = null) + IEnumerable? order = null) { var benchmarkComparer = new BenchmarkComparer(categoryComparer, paramsComparer, jobComparer, targetComparer, order); var list = benchmarkCases.ToList(); @@ -137,7 +137,7 @@ public string GetLogicalGroupKey(ImmutableArray allBenchmarksCase public virtual IEnumerable> GetLogicalGroupOrder( IEnumerable> logicalGroups, - IEnumerable order = null) + IEnumerable? order = null) { var benchmarkComparer = new BenchmarkComparer(categoryComparer, paramsComparer, jobComparer, targetComparer, order); var logicalGroupComparer = new LogicalGroupComparer(benchmarkComparer); diff --git a/src/BenchmarkDotNet/Order/IOrderer.cs b/src/BenchmarkDotNet/Order/IOrderer.cs index dece54e519..bfc6ba5433 100644 --- a/src/BenchmarkDotNet/Order/IOrderer.cs +++ b/src/BenchmarkDotNet/Order/IOrderer.cs @@ -11,7 +11,7 @@ namespace BenchmarkDotNet.Order public interface IOrderer { [PublicAPI] - IEnumerable GetExecutionOrder(ImmutableArray benchmarksCase, IEnumerable order = null); + IEnumerable GetExecutionOrder(ImmutableArray benchmarksCase, IEnumerable? order = null); [PublicAPI] IEnumerable GetSummaryOrder(ImmutableArray benchmarksCases, Summary summary); @@ -24,7 +24,7 @@ public interface IOrderer [PublicAPI] IEnumerable> GetLogicalGroupOrder(IEnumerable> logicalGroups, - IEnumerable order = null); + IEnumerable? order = null); [PublicAPI] bool SeparateLogicalGroups { get; } diff --git a/src/BenchmarkDotNet/Reports/Summary.cs b/src/BenchmarkDotNet/Reports/Summary.cs index 7a9382f62d..680ded2d5b 100644 --- a/src/BenchmarkDotNet/Reports/Summary.cs +++ b/src/BenchmarkDotNet/Reports/Summary.cs @@ -48,7 +48,7 @@ public Summary( CultureInfo cultureInfo, ImmutableArray validationErrors, ImmutableArray columnHidingRules, - SummaryStyle summaryStyle = null) + SummaryStyle? summaryStyle = null) { Title = title; ResultsDirectoryPath = resultsDirectoryPath; diff --git a/src/BenchmarkDotNet/Reports/SummaryTable.cs b/src/BenchmarkDotNet/Reports/SummaryTable.cs index 9ab5e983fd..64aae074ec 100644 --- a/src/BenchmarkDotNet/Reports/SummaryTable.cs +++ b/src/BenchmarkDotNet/Reports/SummaryTable.cs @@ -24,7 +24,7 @@ public class SummaryTable public SummaryStyle EffectiveSummaryStyle { get; } public bool SeparateLogicalGroups { get; } - internal SummaryTable(Summary summary, SummaryStyle style = null) + internal SummaryTable(Summary summary, SummaryStyle? style = null) { Summary = summary; diff --git a/src/BenchmarkDotNet/Running/Descriptor.cs b/src/BenchmarkDotNet/Running/Descriptor.cs index 2e747bb1cd..a38b1a13d9 100644 --- a/src/BenchmarkDotNet/Running/Descriptor.cs +++ b/src/BenchmarkDotNet/Running/Descriptor.cs @@ -31,14 +31,14 @@ public class Descriptor : IEquatable public Descriptor( Type type, MethodInfo workloadMethod, - MethodInfo globalSetupMethod = null, - MethodInfo globalCleanupMethod = null, - MethodInfo iterationSetupMethod = null, - MethodInfo iterationCleanupMethod = null, - string description = null, - string additionalLogic = null, + MethodInfo? globalSetupMethod = null, + MethodInfo? globalCleanupMethod = null, + MethodInfo? iterationSetupMethod = null, + MethodInfo? iterationCleanupMethod = null, + string? description = null, + string? additionalLogic = null, bool baseline = false, - string[] categories = null, + string[]? categories = null, int operationsPerInvoke = 1, int methodIndex = 0) { diff --git a/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunPublisher.cs b/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunPublisher.cs index b9605867fe..c77b56b039 100644 --- a/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunPublisher.cs +++ b/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunPublisher.cs @@ -11,7 +11,7 @@ namespace BenchmarkDotNet.Toolchains.CoreRun { public class CoreRunPublisher : IBuilder { - public CoreRunPublisher(FileInfo coreRun, FileInfo customDotNetCliPath = null) + public CoreRunPublisher(FileInfo coreRun, FileInfo? customDotNetCliPath = null) { CoreRun = coreRun; DotNetCliPublisher = new DotNetCliPublisher(customDotNetCliPath?.FullName); diff --git a/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs b/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs index 03d677a5aa..7eca3f97f0 100644 --- a/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs +++ b/src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs @@ -21,7 +21,7 @@ public class CoreRunToolchain : IToolchain /// the directory to restore packages to public CoreRunToolchain(FileInfo coreRun, bool createCopy = true, string targetFrameworkMoniker = "netcoreapp2.1", - FileInfo customDotNetCliPath = null, DirectoryInfo restorePath = null, + FileInfo? customDotNetCliPath = null, DirectoryInfo? restorePath = null, string displayName = "CoreRun") { if (coreRun == null) throw new ArgumentNullException(nameof(coreRun)); diff --git a/src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs b/src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs index 4e1fe4a641..e3c3f85125 100644 --- a/src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs +++ b/src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs @@ -25,7 +25,7 @@ public class CsProjClassicNetToolchain : Toolchain internal string CustomDotNetCliPath { get; } - private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, string packagesPath = null, string customDotNetCliPath = null) + private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, string? packagesPath = null, string? customDotNetCliPath = null) : base(name, new CsProjGenerator(targetFrameworkMoniker, customDotNetCliPath, packagesPath, runtimeFrameworkVersion: null, isNetCore: false), new DotNetCliBuilder(targetFrameworkMoniker, customDotNetCliPath), @@ -34,7 +34,7 @@ private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, st CustomDotNetCliPath = customDotNetCliPath; } - public static IToolchain From(string targetFrameworkMoniker, string packagesPath = null, string customDotNetCliPath = null) + public static IToolchain From(string targetFrameworkMoniker, string? packagesPath = null, string? customDotNetCliPath = null) => new CsProjClassicNetToolchain(targetFrameworkMoniker, targetFrameworkMoniker, packagesPath, customDotNetCliPath); public override IEnumerable Validate(BenchmarkCase benchmarkCase, IResolver resolver) diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs index bad11c91be..e034279f89 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs @@ -17,7 +17,7 @@ public class DotNetCliBuilder : IBuilder private bool RetryFailedBuildWithNoDeps { get; } [PublicAPI] - public DotNetCliBuilder(string targetFrameworkMoniker, string customDotNetCliPath = null, bool logOutput = false, bool retryFailedBuildWithNoDeps = true) + public DotNetCliBuilder(string targetFrameworkMoniker, string? customDotNetCliPath = null, bool logOutput = false, bool retryFailedBuildWithNoDeps = true) { TargetFrameworkMoniker = targetFrameworkMoniker; CustomDotNetCliPath = customDotNetCliPath; diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs index 31546d3112..9967b4ef92 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs @@ -166,7 +166,7 @@ public DotNetCliCommandResult PublishNoBuildAndNoRestore() internal static IEnumerable GetAddPackagesCommands(BuildPartition buildPartition) => GetNuGetAddPackageCommands(buildPartition.RepresentativeBenchmarkCase, buildPartition.Resolver); - internal static string GetRestoreCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string extraArguments = null, string binLogSuffix = null) + internal static string GetRestoreCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string? extraArguments = null, string? binLogSuffix = null) => new StringBuilder() .AppendArgument("restore") .AppendArgument(string.IsNullOrEmpty(artifactsPaths.PackagesDirectoryName) ? string.Empty : $"--packages \"{artifactsPaths.PackagesDirectoryName}\"") @@ -176,7 +176,7 @@ internal static string GetRestoreCommand(ArtifactsPaths artifactsPaths, BuildPar .AppendArgument(GetMsBuildBinLogArgument(buildPartition, binLogSuffix)) .ToString(); - internal static string GetBuildCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string extraArguments = null, string binLogSuffix = null) + internal static string GetBuildCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string? extraArguments = null, string? binLogSuffix = null) => new StringBuilder() .AppendArgument($"build -c {buildPartition.BuildConfiguration}") // we don't need to specify TFM, our auto-generated project contains always single one .AppendArgument(GetCustomMsBuildArguments(buildPartition.RepresentativeBenchmarkCase, buildPartition.Resolver)) @@ -186,7 +186,7 @@ internal static string GetBuildCommand(ArtifactsPaths artifactsPaths, BuildParti .AppendArgument(GetMsBuildBinLogArgument(buildPartition, binLogSuffix)) .ToString(); - internal static string GetPublishCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string extraArguments = null, string binLogSuffix = null) + internal static string GetPublishCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string? extraArguments = null, string? binLogSuffix = null) => new StringBuilder() .AppendArgument($"publish -c {buildPartition.BuildConfiguration}") // we don't need to specify TFM, our auto-generated project contains always single one .AppendArgument(GetCustomMsBuildArguments(buildPartition.RepresentativeBenchmarkCase, buildPartition.Resolver)) diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommandExecutor.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommandExecutor.cs index bfe9a97585..3532fa1e07 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommandExecutor.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommandExecutor.cs @@ -99,7 +99,7 @@ internal static void LogEnvVars(DotNetCliCommand command) } internal static ProcessStartInfo BuildStartInfo(string customDotNetCliPath, string workingDirectory, string arguments, - IReadOnlyList environmentVariables = null, bool redirectStandardInput = false, bool redirectStandardError = true, bool redirectStandardOutput = true) + IReadOnlyList? environmentVariables = null, bool redirectStandardInput = false, bool redirectStandardError = true, bool redirectStandardOutput = true) { const string dotnetMultiLevelLookupEnvVarName = "DOTNET_MULTILEVEL_LOOKUP"; diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliPublisher.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliPublisher.cs index 8292619e49..960558d5c0 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliPublisher.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliPublisher.cs @@ -8,7 +8,7 @@ namespace BenchmarkDotNet.Toolchains.DotNetCli { public class DotNetCliPublisher : IBuilder { - public DotNetCliPublisher(string customDotNetCliPath = null, string extraArguments = null, IReadOnlyList environmentVariables = null) + public DotNetCliPublisher(string? customDotNetCliPath = null, string? extraArguments = null, IReadOnlyList environmentVariables = null) { CustomDotNetCliPath = customDotNetCliPath; ExtraArguments = extraArguments; diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/MsBuildErrorMapper.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/MsBuildErrorMapper.cs index 6f0e28834b..bd5fba4123 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/MsBuildErrorMapper.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/MsBuildErrorMapper.cs @@ -30,7 +30,7 @@ internal static class MsBuildErrorMapper ), }; - internal static bool TryToExplainFailureReason(BuildResult buildResult, out string reason) + internal static bool TryToExplainFailureReason(BuildResult buildResult, out string? reason) { reason = null; diff --git a/src/BenchmarkDotNet/Toolchains/DotNetCli/NetCoreAppSettings.cs b/src/BenchmarkDotNet/Toolchains/DotNetCli/NetCoreAppSettings.cs index 50b1f7b614..26b76af0a6 100644 --- a/src/BenchmarkDotNet/Toolchains/DotNetCli/NetCoreAppSettings.cs +++ b/src/BenchmarkDotNet/Toolchains/DotNetCli/NetCoreAppSettings.cs @@ -44,10 +44,10 @@ public NetCoreAppSettings( string targetFrameworkMoniker, string runtimeFrameworkVersion, string name, - string customDotNetCliPath = null, - string packagesPath = null, - string customRuntimePack = null, - string aotCompilerPath = null, + string? customDotNetCliPath = null, + string? packagesPath = null, + string? customRuntimePack = null, + string? aotCompilerPath = null, MonoAotCompilerMode aotCompilerMode = MonoAotCompilerMode.mini ) { @@ -96,10 +96,10 @@ public NetCoreAppSettings( /// public MonoAotCompilerMode AOTCompilerMode { get; } - public NetCoreAppSettings WithCustomDotNetCliPath(string customDotNetCliPath, string displayName = null) + public NetCoreAppSettings WithCustomDotNetCliPath(string customDotNetCliPath, string? displayName = null) => new NetCoreAppSettings(TargetFrameworkMoniker, RuntimeFrameworkVersion, displayName ?? Name, customDotNetCliPath, PackagesPath); - public NetCoreAppSettings WithCustomPackagesRestorePath(string packagesPath, string displayName = null) + public NetCoreAppSettings WithCustomPackagesRestorePath(string packagesPath, string? displayName = null) => new NetCoreAppSettings(TargetFrameworkMoniker, RuntimeFrameworkVersion, displayName ?? Name, CustomDotNetCliPath, packagesPath); } } diff --git a/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs b/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs index bdfbd78a37..e10c81b49b 100644 --- a/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs +++ b/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs @@ -11,7 +11,7 @@ public class ExecuteParameters { internal static readonly TimeSpan ProcessExitTimeout = TimeSpan.FromSeconds(2); - public ExecuteParameters(BuildResult buildResult, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, int launchIndex, IDiagnoser diagnoser = null) + public ExecuteParameters(BuildResult buildResult, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, int launchIndex, IDiagnoser? diagnoser = null) { BuildResult = buildResult; BenchmarkCase = benchmarkCase; diff --git a/src/BenchmarkDotNet/Toolchains/Results/GenerateResult.cs b/src/BenchmarkDotNet/Toolchains/Results/GenerateResult.cs index b6de670b8d..8763fcbb7a 100644 --- a/src/BenchmarkDotNet/Toolchains/Results/GenerateResult.cs +++ b/src/BenchmarkDotNet/Toolchains/Results/GenerateResult.cs @@ -22,7 +22,7 @@ public GenerateResult(ArtifactsPaths artifactsPaths, bool isGenerateSuccess, Exc public static GenerateResult Success(ArtifactsPaths artifactsPaths, IReadOnlyCollection artifactsToCleanup) => new GenerateResult(artifactsPaths, true, null, artifactsToCleanup); - public static GenerateResult Failure(ArtifactsPaths artifactsPaths, IReadOnlyCollection artifactsToCleanup, Exception exception = null) + public static GenerateResult Failure(ArtifactsPaths artifactsPaths, IReadOnlyCollection artifactsToCleanup, Exception? exception = null) => new GenerateResult(artifactsPaths, false, exception, artifactsToCleanup); public override string ToString() => "GenerateResult: " + (IsGenerateSuccess ? "Success" : "Fail"); diff --git a/src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs b/src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs index ad3b4a5a6b..918477f3b6 100644 --- a/src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs +++ b/src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs @@ -32,7 +32,7 @@ private static IToolchain GetToolchain(Job job, Descriptor descriptor) || job.HasValue(InfrastructureMode.BuildConfigurationCharacteristic) || job.HasValue(InfrastructureMode.ArgumentsCharacteristic)); - internal static IToolchain GetToolchain(this Runtime runtime, Descriptor descriptor = null, bool preferMsBuildToolchains = false) + internal static IToolchain GetToolchain(this Runtime runtime, Descriptor? descriptor = null, bool preferMsBuildToolchains = false) { switch (runtime) { diff --git a/src/BenchmarkDotNet/Validators/ValidationError.cs b/src/BenchmarkDotNet/Validators/ValidationError.cs index e8f5e40f6b..23faff5a54 100644 --- a/src/BenchmarkDotNet/Validators/ValidationError.cs +++ b/src/BenchmarkDotNet/Validators/ValidationError.cs @@ -6,7 +6,7 @@ namespace BenchmarkDotNet.Validators { public class ValidationError : IEquatable { - public ValidationError(bool isCritical, string message, BenchmarkCase benchmarkCase = null) + public ValidationError(bool isCritical, string message, BenchmarkCase? benchmarkCase = null) { IsCritical = isCritical; Message = message; diff --git a/tests/BenchmarkDotNet.IntegrationTests/BenchmarkTestExecutor.cs b/tests/BenchmarkDotNet.IntegrationTests/BenchmarkTestExecutor.cs index 1171b0f014..e835065b27 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/BenchmarkTestExecutor.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/BenchmarkTestExecutor.cs @@ -36,7 +36,7 @@ protected BenchmarkTestExecutor(ITestOutputHelper output) /// Optional custom config to be used instead of the default /// Optional: disable validation (default = true/enabled) /// The summary from the benchmark run - public Reports.Summary CanExecute(IConfig config = null, bool fullValidation = true) + public Reports.Summary CanExecute(IConfig? config = null, bool fullValidation = true) { return CanExecute(typeof(TBenchmark), config, fullValidation); } @@ -50,7 +50,7 @@ public Reports.Summary CanExecute(IConfig config = null, bool fullVa /// Optional custom config to be used instead of the default /// Optional: disable validation (default = true/enabled) /// The summary from the benchmark run - public Reports.Summary CanExecute(Type type, IConfig config = null, bool fullValidation = true) + public Reports.Summary CanExecute(Type type, IConfig? config = null, bool fullValidation = true) { // Add logging, so the Benchmark execution is in the TestRunner output (makes Debugging easier) if (config == null) @@ -90,7 +90,7 @@ public Reports.Summary CanExecute(Type type, IConfig config = null, bool fullVal return summary; } - protected IConfig CreateSimpleConfig(OutputLogger logger = null, Job job = null) + protected IConfig CreateSimpleConfig(OutputLogger? logger = null, Job? job = null) { var baseConfig = job == null ? (IConfig)new SingleRunFastConfig() : new SingleJobConfig(job); return baseConfig diff --git a/tests/BenchmarkDotNet.IntegrationTests/ExporterIOTests.cs b/tests/BenchmarkDotNet.IntegrationTests/ExporterIOTests.cs index 3a532b9a61..ef8bba9095 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/ExporterIOTests.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/ExporterIOTests.cs @@ -144,7 +144,7 @@ public override void ExportToLog(Summary summary, ILogger logger) } } - private ImmutableArray CreateReports(Type[] types, IConfig config = null) + private ImmutableArray CreateReports(Type[] types, IConfig? config = null) => CreateBenchmarks(types, config).Select(CreateReport).ToImmutableArray(); private BenchmarkCase[] CreateBenchmarks(Type[] types, IConfig config) diff --git a/tests/BenchmarkDotNet.IntegrationTests/InProcess.EmitTests.T4/RunnableStructCaseBenchmark.tt b/tests/BenchmarkDotNet.IntegrationTests/InProcess.EmitTests.T4/RunnableStructCaseBenchmark.tt index 45dbfdad79..a0fe0c5282 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/InProcess.EmitTests.T4/RunnableStructCaseBenchmark.tt +++ b/tests/BenchmarkDotNet.IntegrationTests/InProcess.EmitTests.T4/RunnableStructCaseBenchmark.tt @@ -54,7 +54,7 @@ namespace BenchmarkDotNet.IntegrationTests.InProcess.EmitTests } }<#+ - private void EmitStructCaseBenchmark(ref int counter, string type, string argValue = null) + private void EmitStructCaseBenchmark(ref int counter, string type, string? argValue = null) { #> // ---- Begin StructCase(<#=type#>) ---- diff --git a/tests/BenchmarkDotNet.IntegrationTests/InProcessTest.cs b/tests/BenchmarkDotNet.IntegrationTests/InProcessTest.cs index b0b3b9b07c..4d6325116d 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/InProcessTest.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/InProcessTest.cs @@ -180,7 +180,7 @@ private void TestInvoke(BenchmarkAction benchmarkAction, int unrollFactor, bool } } - private IConfig CreateInProcessConfig(OutputLogger logger = null) + private IConfig CreateInProcessConfig(OutputLogger? logger = null) { return new ManualConfig() .AddJob(Job.Dry.WithToolchain(new InProcessNoEmitToolchain(TimeSpan.Zero, true)).WithInvocationCount(UnrollFactor).WithUnrollFactor(UnrollFactor)) diff --git a/tests/BenchmarkDotNet.Tests/Engine/EngineWarmupStageTests.cs b/tests/BenchmarkDotNet.Tests/Engine/EngineWarmupStageTests.cs index 52136089cb..1f966fbcaa 100644 --- a/tests/BenchmarkDotNet.Tests/Engine/EngineWarmupStageTests.cs +++ b/tests/BenchmarkDotNet.Tests/Engine/EngineWarmupStageTests.cs @@ -81,7 +81,7 @@ public class WithForceAutoWarmup public void Method() { } } - private void AutoTest(Func measure, int min, int max = -1, IterationMode mode = IterationMode.Workload, Job job = null) + private void AutoTest(Func measure, int min, int max = -1, IterationMode mode = IterationMode.Workload, Job? job = null) { if (max == -1) max = min; diff --git a/tests/BenchmarkDotNet.Tests/Reports/FakeMetricDescriptor.cs b/tests/BenchmarkDotNet.Tests/Reports/FakeMetricDescriptor.cs index 8c7316e638..22d06c2b3e 100644 --- a/tests/BenchmarkDotNet.Tests/Reports/FakeMetricDescriptor.cs +++ b/tests/BenchmarkDotNet.Tests/Reports/FakeMetricDescriptor.cs @@ -5,7 +5,7 @@ namespace BenchmarkDotNet.Tests.Reports { internal sealed class FakeMetricDescriptor : IMetricDescriptor { - public FakeMetricDescriptor(string id, string legend, string numberFormat = null) + public FakeMetricDescriptor(string id, string legend, string? numberFormat = null) { Id = id; Legend = legend; diff --git a/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs b/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs index 9ec2c63ffc..b1bcdb1dcd 100644 --- a/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs +++ b/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs @@ -213,7 +213,7 @@ public void GenericTypesCanBeFilteredByDisplayName() Assert.Contains("SomeGeneric.Create", benchmarks); } - private HashSet Filter(Type[] types, string[] args, ILogger logger = null) + private HashSet Filter(Type[] types, string[] args, ILogger? logger = null) { var nonNullLogger = logger ?? new OutputLogger(Output);