Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More nullability warnings fixes #2421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion samples/BenchmarkDotNet.Samples/IntroExceptionDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public void ThrowExceptionRandomly()
throw new Exception();
}
}
catch { }
catch
{
// ignored
}
}
}
}
4 changes: 2 additions & 2 deletions samples/BenchmarkDotNet.Samples/IntroOrderManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private class Config : ManualConfig
private class FastestToSlowestOrderer : IOrderer
{
public IEnumerable<BenchmarkCase> GetExecutionOrder(ImmutableArray<BenchmarkCase> benchmarksCase,
IEnumerable<BenchmarkLogicalGroupRule> order = null) =>
IEnumerable<BenchmarkLogicalGroupRule>? order = null) =>
from benchmark in benchmarksCase
orderby benchmark.Parameters["X"] descending,
benchmark.Descriptor.WorkloadMethodDisplayInfo
Expand All @@ -39,7 +39,7 @@ public string GetLogicalGroupKey(ImmutableArray<BenchmarkCase> allBenchmarksCase
benchmarkCase.Job.DisplayInfo + "_" + benchmarkCase.Parameters.DisplayInfo;

public IEnumerable<IGrouping<string, BenchmarkCase>> GetLogicalGroupOrder(IEnumerable<IGrouping<string, BenchmarkCase>> logicalGroups,
IEnumerable<BenchmarkLogicalGroupRule> order = null) =>
IEnumerable<BenchmarkLogicalGroupRule>? order = null) =>
logicalGroups.OrderBy(it => it.Key);

public bool SeparateLogicalGroups => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public string Target
set => Targets = string.IsNullOrEmpty(value) ? new string[0] : value.Split(','); // , is for backward compat
}

public bool Match(MethodInfo method) => Targets == null || Targets.Length == 0 || Targets.Contains(method.Name);
public bool Match(MethodInfo method) => Targets.Length == 0 || Targets.Contains(method.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet.Diagnostics.Windows/EtwDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet.Diagnostics.Windows/EtwProfilerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HardwareCounter, Func<ProfileSourceInfo, int>> intervalSelectors = null,
IReadOnlyCollection<(Guid providerGuid, TraceEventLevel providerLevel, ulong keywords, TraceEventProviderOptions options)> providers = null,
IReadOnlyDictionary<HardwareCounter, Func<ProfileSourceInfo, int>>? intervalSelectors = null,
IReadOnlyCollection<(Guid providerGuid, TraceEventLevel providerLevel, ulong keywords, TraceEventProviderOptions options)>? providers = null,
bool createHeapSession = false)
{
CreateHeapSession = createHeapSession;
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class InliningDiagnoser : JitDiagnoser<object>, IProfiler

private readonly bool logFailuresOnly = true;
private readonly bool filterByNamespace = true;
private readonly string[] allowedNamespaces = null;
private readonly string[]? allowedNamespaces = null;
private string defaultNamespace;

// ReSharper disable once EmptyConstructor parameterless ctor is mandatory for DiagnosersLoader.CreateDiagnoser
Expand All @@ -35,7 +35,7 @@ public InliningDiagnoser(bool logFailuresOnly = true, bool filterByNamespace = t
/// </summary>
/// <param name="logFailuresOnly">only the methods that failed to get inlined. True by default.</param>
/// <param name="allowedNamespaces">list of namespaces from which inlining message should be print.</param>
public InliningDiagnoser(bool logFailuresOnly = true, string[] allowedNamespaces = null)
public InliningDiagnoser(bool logFailuresOnly = true, string[]? allowedNamespaces = null)
{
this.logFailuresOnly = logFailuresOnly;
this.allowedNamespaces = allowedNamespaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BenchmarkDotNet.Diagnostics.Windows.Tracing
{
public sealed class EngineEventLogParser : TraceEventParser
{
private static volatile TraceEvent[] templates;
private static volatile TraceEvent[]? templates;

public EngineEventLogParser(TraceEventSource source, bool dontRegister = false) : base(source, dontRegister) { }

Expand Down Expand Up @@ -114,69 +114,69 @@ public event Action<IterationEvent> WorkloadActualStop

protected override string GetProviderName() { return ProviderName; }

private static IterationEvent BenchmarkStartTemplate(Action<IterationEvent> action)
private static IterationEvent BenchmarkStartTemplate(Action<IterationEvent>? action)
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new IterationEvent(action, EngineEventSource.BenchmarkStartEventId, (int)EngineEventSource.Tasks.Benchmark, nameof(EngineEventSource.Tasks.Benchmark), Guid.Empty, (int)EventOpcode.Start, nameof(EventOpcode.Start), ProviderGuid, ProviderName);
}

private static IterationEvent BenchmarkStopTemplate(Action<IterationEvent> action)
private static IterationEvent BenchmarkStopTemplate(Action<IterationEvent>? action)
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new IterationEvent(action, EngineEventSource.BenchmarkStopEventId, (int)EngineEventSource.Tasks.Benchmark, nameof(EngineEventSource.Tasks.Benchmark), Guid.Empty, (int)EventOpcode.Stop, nameof(EventOpcode.Stop), ProviderGuid, ProviderName);
}

private static IterationEvent OverheadJittingStartTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadJittingStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.OverheadJittingStartEventId, EngineEventSource.Tasks.OverheadJitting);

private static IterationEvent OverheadJittingStopTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadJittingStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.OverheadJittingStopEventId, EngineEventSource.Tasks.OverheadJitting);

private static IterationEvent WorkloadJittingStartTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadJittingStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.WorkloadJittingStartEventId, EngineEventSource.Tasks.WorkloadJitting);

private static IterationEvent WorkloadJittingStopTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadJittingStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.WorkloadJittingStopEventId, EngineEventSource.Tasks.WorkloadJitting);

private static IterationEvent WorkloadPilotStartTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadPilotStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.WorkloadPilotStartEventId, EngineEventSource.Tasks.WorkloadPilot);

private static IterationEvent WorkloadPilotStopTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadPilotStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.WorkloadPilotStopEventId, EngineEventSource.Tasks.WorkloadPilot);

private static IterationEvent OverheadWarmupStartTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadWarmupStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.OverheadWarmupStartEventId, EngineEventSource.Tasks.OverheadWarmup);

private static IterationEvent OverheadWarmupStopTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadWarmupStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.OverheadWarmupStopEventId, EngineEventSource.Tasks.OverheadWarmup);

private static IterationEvent WorkloadWarmupStartTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadWarmupStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.WorkloadWarmupStartEventId, EngineEventSource.Tasks.WorkloadWarmup);

private static IterationEvent WorkloadWarmupStopTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadWarmupStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.WorkloadWarmupStopEventId, EngineEventSource.Tasks.WorkloadWarmup);

private static IterationEvent OverheadActualStartTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadActualStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.OverheadActualStartEventId, EngineEventSource.Tasks.OverheadActual);

private static IterationEvent OverheadActualStopTemplate(Action<IterationEvent> action)
private static IterationEvent OverheadActualStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.OverheadActualStopEventId, EngineEventSource.Tasks.OverheadActual);

private static IterationEvent WorkloadActualStartTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadActualStartTemplate(Action<IterationEvent>? action)
=> CreateIterationStartTemplate(action, EngineEventSource.WorkloadActualStartEventId, EngineEventSource.Tasks.WorkloadActual);

private static IterationEvent WorkloadActualStopTemplate(Action<IterationEvent> action)
private static IterationEvent WorkloadActualStopTemplate(Action<IterationEvent>? action)
=> CreateIterationStopTemplate(action, EngineEventSource.WorkloadActualStopEventId, EngineEventSource.Tasks.WorkloadActual);

private static IterationEvent CreateIterationStartTemplate(Action<IterationEvent> action, int eventId, EventTask eventTask)
private static IterationEvent CreateIterationStartTemplate(Action<IterationEvent>? action, int eventId, EventTask eventTask)
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new IterationEvent(action, eventId, (int)eventTask, eventTask.ToString(), Guid.Empty, (int)EventOpcode.Start, nameof(EventOpcode.Start), ProviderGuid, ProviderName);
}

private static IterationEvent CreateIterationStopTemplate(Action<IterationEvent> action, int eventId, EventTask eventTask)
private static IterationEvent CreateIterationStopTemplate(Action<IterationEvent>? action, int eventId, EventTask eventTask)
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new IterationEvent(action, eventId, (int)eventTask, eventTask.ToString(), Guid.Empty, (int)EventOpcode.Stop, nameof(EventOpcode.Stop), ProviderGuid, ProviderName);
}

protected override void EnumerateTemplates(Func<string, string, EventFilterResponse> eventsToObserve, Action<TraceEvent> callback)
protected override void EnumerateTemplates(Func<string, string, EventFilterResponse>? eventsToObserve, Action<TraceEvent> callback)
{
if (templates == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public sealed class IterationEvent : TraceEvent
{
public long TotalOperations => GetInt64At(0);

private event Action<IterationEvent> target;
private event Action<IterationEvent>? target;

internal IterationEvent(Action<IterationEvent> target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName)
: base(eventID, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName)
internal IterationEvent(Action<IterationEvent>? target, int eventId, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName)
: base(eventId, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName)
{
this.target = target;
}

protected override Delegate Target
protected override Delegate? Target
{
get => target;
set => target = (Action<IterationEvent>)value;
Expand All @@ -34,7 +34,7 @@ public override StringBuilder ToXml(StringBuilder sb)
return sb;
}

public override object PayloadValue(int index) => index == 0 ? (object)TotalOperations : null;
public override object? PayloadValue(int index) => index == 0 ? TotalOperations : null;

protected override void Dispatch() => target?.Invoke(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private IEnumerable<Metric> Parse(TraceLog traceLog)
var heapParser = new HeapTraceProviderTraceEventParser(eventSource);
// We index by heap address and then within the heap we remember the allocation stack
var heaps = new Dictionary<Address, Dictionary<Address, long>>();
Dictionary<Address, long> lastHeapAllocs = null;
Dictionary<Address, long>? lastHeapAllocs = null;

Address lastHeapHandle = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AssemblyTitle>BenchmarkDotNet.Diagnostics.dotTrace</AssemblyTitle>
<AssemblyName>BenchmarkDotNet.Diagnostics.dotTrace</AssemblyName>
<PackageId>BenchmarkDotNet.Diagnostics.dotTrace</PackageId>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace BenchmarkDotNet.Diagnostics.dotTrace
{
public class DotTraceDiagnoser : IProfiler
{
private readonly Uri nugetUrl;
private readonly string toolsDownloadFolder;
private readonly Uri? nugetUrl;
private readonly string? toolsDownloadFolder;

public DotTraceDiagnoser(Uri nugetUrl = null, string toolsDownloadFolder = null)
public DotTraceDiagnoser(Uri? nugetUrl = null, string? toolsDownloadFolder = null)
{
this.nugetUrl = nugetUrl;
this.toolsDownloadFolder = toolsDownloadFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DotTraceDiagnoserAttribute()
Config = ManualConfig.CreateEmpty().AddDiagnoser(new DotTraceDiagnoser());
}

public DotTraceDiagnoserAttribute(Uri nugetUrl = null, string toolsDownloadFolder = null)
public DotTraceDiagnoserAttribute(Uri? nugetUrl = null, string? toolsDownloadFolder = null)
{
Config = ManualConfig.CreateEmpty().AddDiagnoser(new DotTraceDiagnoser(nugetUrl, toolsDownloadFolder));
}
Expand Down
14 changes: 7 additions & 7 deletions src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceToolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace BenchmarkDotNet.Diagnostics.dotTrace
internal abstract class DotTraceToolBase
{
private readonly ILogger logger;
private readonly Uri nugetUrl;
private readonly Uri? nugetUrl;
private readonly NuGetApi nugetApi;
private readonly string downloadTo;
private readonly string? downloadTo;

protected DotTraceToolBase(ILogger logger, Uri nugetUrl = null, NuGetApi nugetApi = NuGetApi.V3, string downloadTo = null)
protected DotTraceToolBase(ILogger logger, Uri? nugetUrl = null, NuGetApi nugetApi = NuGetApi.V3, string? downloadTo = null)
{
this.logger = logger;
this.nugetUrl = nugetUrl;
Expand Down Expand Up @@ -48,9 +48,9 @@ public void Init(DiagnoserActionParameters parameters)
public string Start(DiagnoserActionParameters parameters)
{
string snapshotFile = ArtifactFileNameHelper.GetFilePath(parameters, "snapshots", DateTime.Now, "dtp", ".0000".Length);
string snapshotDirectory = Path.GetDirectoryName(snapshotFile);
string? snapshotDirectory = Path.GetDirectoryName(snapshotFile);
logger.WriteLineInfo($"Target snapshot file: {snapshotFile}");
if (!Directory.Exists(snapshotDirectory))
if (!Directory.Exists(snapshotDirectory) && snapshotDirectory != null)
{
try
{
Expand Down Expand Up @@ -126,7 +126,7 @@ protected string GetRunnerPath()
if (consoleRunnerPackageField == null)
throw new InvalidOperationException("Field 'ConsoleRunnerPackage' not found.");

object consoleRunnerPackage = consoleRunnerPackageField.GetValue(null);
object? consoleRunnerPackage = consoleRunnerPackageField.GetValue(null);
if (consoleRunnerPackage == null)
throw new InvalidOperationException("Unable to get value of 'ConsoleRunnerPackage'.");

Expand All @@ -135,7 +135,7 @@ protected string GetRunnerPath()
if (getRunnerPathMethod == null)
throw new InvalidOperationException("Method 'GetRunnerPath' not found.");

string runnerPath = getRunnerPathMethod.Invoke(consoleRunnerPackage, null) as string;
string? runnerPath = getRunnerPathMethod.Invoke(consoleRunnerPackage, null) as string;
if (runnerPath == null)
throw new InvalidOperationException("Unable to invoke 'GetRunnerPath'.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class ExternalDotTraceTool : DotTraceToolBase
{
private static readonly TimeSpan AttachTimeout = TimeSpan.FromMinutes(5);

public ExternalDotTraceTool(ILogger logger, Uri nugetUrl = null, NuGetApi nugetApi = NuGetApi.V3, string downloadTo = null) :
public ExternalDotTraceTool(ILogger logger, Uri? nugetUrl = null, NuGetApi nugetApi = NuGetApi.V3, string? downloadTo = null) :
base(logger, nugetUrl, nugetApi, downloadTo) { }

protected override bool AttachOnly => true;
Expand Down Expand Up @@ -44,7 +44,7 @@ protected override void Attach(DiagnoserActionParameters parameters, string snap
{
process.OutputDataReceived += (_, args) =>
{
string content = args.Data;
string? content = args.Data;
if (content != null)
{
logger.WriteLineInfo("[dotTrace] " + content);
Expand All @@ -54,7 +54,7 @@ protected override void Attach(DiagnoserActionParameters parameters, string snap
};
process.ErrorDataReceived += (_, args) =>
{
string content = args.Data;
string? content = args.Data;
if (content != null)
logger.WriteLineError("[dotTrace] " + args.Data);
};
Expand Down
Loading