Skip to content

Commit

Permalink
Add explicit discards to all value returning expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Oct 15, 2022
1 parent a0b3edc commit e053617
Show file tree
Hide file tree
Showing 47 changed files with 144 additions and 144 deletions.
2 changes: 1 addition & 1 deletion samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Kernel(int s)
}
}

Parallel.For(0, c, Kernel);
_ = Parallel.For(0, c, Kernel);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Implementation(HlslBokehBlurProcessor definition, Configuration configura
NormalizeKernels();

// Store them in the cache for future use
Cache.TryAdd(parameters, (kernelParameters, kernelsScale, kernels));
_ = Cache.TryAdd(parameters, (kernelParameters, kernelsScale, kernels));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public void Log(string title, params (string Property, object? Value)[]? data)
{
StringBuilder builder = new();

builder.AppendLine($"[EVENT]: \"{title}\"");
_ = builder.AppendLine($"[EVENT]: \"{title}\"");

if (data is not null)
{
foreach (var info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
_ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}

Expand All @@ -34,15 +34,15 @@ public void Log(Exception exception, params (string Property, object? Value)[]?
{
StringBuilder builder = new();

builder.AppendLine($"[EXCEPTION]: \"{exception.GetType()}\"");
builder.AppendLine(">> Stack trace");
builder.AppendLine(exception.StackTrace);
_ = builder.AppendLine($"[EXCEPTION]: \"{exception.GetType()}\"");
_ = builder.AppendLine(">> Stack trace");
_ = builder.AppendLine(exception.StackTrace);

if (data is not null)
{
foreach (var info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
_ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}

Expand Down
4 changes: 2 additions & 2 deletions samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.OpenShaderSelectionPanel);

Root.Resources.Remove("ShaderSelectionPanel");
_ = Root.Resources.Remove("ShaderSelectionPanel");
Root.Children.Add(ShaderSelectionPanel);
}

Expand All @@ -40,7 +40,7 @@ private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.CloseShaderSelectionPanel);

Root.Children.Remove(ShaderSelectionPanel);
_ = Root.Children.Remove(ShaderSelectionPanel);
}

// Updates the size of the shaders list panel
Expand Down
4 changes: 2 additions & 2 deletions samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public void OnShutdown()
// Opens the shader selection panel
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
{
Root.Resources.Remove("ShaderSelectionPanel");
_ = Root.Resources.Remove("ShaderSelectionPanel");
Root.Children.Add(ShaderSelectionPanel);
}

// Hides the shader selection panel
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
{
Root.Children.Remove(ShaderSelectionPanel);
_ = Root.Children.Remove(ShaderSelectionPanel);
}

// Updates the size of the shaders list panel
Expand Down
24 changes: 12 additions & 12 deletions samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override unsafe void OnInitialize(HWND hwnd)
// Create the command allocator to use
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
{
this.d3D12Device.Get()->CreateCommandAllocator(
_ = this.d3D12Device.Get()->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
Windows.__uuidof<ID3D12CommandAllocator>(),
(void**)d3D12CommandAllocator);
Expand All @@ -156,7 +156,7 @@ public override unsafe void OnInitialize(HWND hwnd)
// Create the reusable command list to copy data to the back buffers
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
{
this.d3D12Device.Get()->CreateCommandList(
_ = this.d3D12Device.Get()->CreateCommandList(
0,
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
d3D12CommandAllocator,
Expand All @@ -166,7 +166,7 @@ public override unsafe void OnInitialize(HWND hwnd)
}

// Close the command list to prepare it for future use
this.d3D12GraphicsCommandList.Get()->Close();
_ = this.d3D12GraphicsCommandList.Get()->Close();
}

/// <inheritdoc/>
Expand All @@ -180,10 +180,10 @@ public override unsafe void OnResize()
/// </summary>
private unsafe void ApplyResize()
{
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
_ = this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);

// Wait for the fence again to ensure there are no pending operations
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
_ = this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);

this.nextD3D12FenceValue++;

Expand All @@ -192,7 +192,7 @@ private unsafe void ApplyResize()
this.d3D12Resource1.Dispose();

// Resize the swap chain buffers
this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
_ = this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);

// Get the index of the initial back buffer
using (ComPtr<IDXGISwapChain3> dxgiSwapChain3 = default)
Expand Down Expand Up @@ -249,8 +249,8 @@ public override unsafe void OnUpdate(TimeSpan time)
this.currentBufferIndex ^= 1;

// Reset the command list and command allocator
this.d3D12CommandAllocator.Get()->Reset();
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
_ = this.d3D12CommandAllocator.Get()->Reset();
_ = this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);

D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
{
Expand Down Expand Up @@ -283,18 +283,18 @@ public override unsafe void OnUpdate(TimeSpan time)
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);

d3D12GraphicsCommandList.Get()->Close();
_ = d3D12GraphicsCommandList.Get()->Close();

// Execute the command list to perform the copy
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)d3D12GraphicsCommandList.GetAddressOf());
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
_ = this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);

// Present the new frame
this.dxgiSwapChain1.Get()->Present(0, 0);
_ = this.dxgiSwapChain1.Get()->Present(0, 0);

if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
{
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
_ = this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
}

this.nextD3D12FenceValue++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ private static LRESULT WindowProc(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lP

if (isPaused)
{
Windows.SetCapture(hwnd);
_ = Windows.SetCapture(hwnd);
}
else
{
Windows.ReleaseCapture();
_ = Windows.ReleaseCapture();
}

isPaused = !isPaused;
Expand Down
2 changes: 1 addition & 1 deletion samples/ComputeSharp.SwapChain/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void Main()
Console.WriteLine();
Console.WriteLine($"Starting {Samples[index].ShaderName}...");

Win32ApplicationRunner.Run(Samples[index].Application);
_ = Win32ApplicationRunner.Run(Samples[index].Application);
}
}
while (index >= 0 && index < Samples.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ private static string GetHlslSource(

void AppendLF()
{
hlslBuilder.Append('\n');
_ = hlslBuilder.Append('\n');
}

void AppendLineAndLF(string text)
{
hlslBuilder.Append(text);
hlslBuilder.Append('\n');
_ = hlslBuilder.Append(text);
_ = hlslBuilder.Append('\n');
}

// Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ private static string GetExceptionMessage(string error)
{
StringBuilder builder = new(512);

builder.AppendLine("The FXC compiler encountered one or more errors while trying to compile the shader:");
builder.AppendLine();
builder.AppendLine(error.Trim());
builder.AppendLine();
builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
_ = builder.AppendLine("The FXC compiler encountered one or more errors while trying to compile the shader:");
_ = builder.AppendLine();
_ = builder.AppendLine(error.Trim());
_ = builder.AppendLine();
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");

return builder.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private D2D1ResourceTextureManager(
{
if (this.d2D1ResourceManagerImpl is not null)
{
this.d2D1ResourceManagerImpl->Release();
_ = this.d2D1ResourceManagerImpl->Release();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private int GetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* dat

using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = this.resourceTextureManagerBuffer[resourceTextureIndex];

resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data);
_ = resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data);

if (actualSize is not null)
{
Expand Down Expand Up @@ -261,7 +261,7 @@ private int SetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* dat
// If there's already an existing manager at this index, release it
if (currentResourceTextureManager is not null)
{
((IUnknown*)currentResourceTextureManager)->Release();
_ = ((IUnknown*)currentResourceTextureManager)->Release();
}

// Store the resource texture manager into the buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static int GetResourceTexture(D2D1ResourceTextureManagerImpl* @this, ID2D
// If the texture has already been created, just return it
if (@this->d2D1ResourceTexture is not null)
{
@this->d2D1ResourceTexture->AddRef();
_ = @this->d2D1ResourceTexture->AddRef();

*resourceTexture = @this->d2D1ResourceTexture;

Expand Down Expand Up @@ -194,10 +194,10 @@ public static int GetResourceTexture(D2D1ResourceTextureManagerImpl* @this, ID2D
if (result == S.S_OK)
{
// Store the resource texture for later
d2D1ResourceTexture.CopyTo(&@this->d2D1ResourceTexture);
_ = d2D1ResourceTexture.CopyTo(&@this->d2D1ResourceTexture);

// Also return it to callers
d2D1ResourceTexture.CopyTo(resourceTexture);
_ = d2D1ResourceTexture.CopyTo(resourceTexture);

// Free the staging buffers
NativeMemory.Free(@this->resourceTextureProperties.extents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal D2D1DrawInfoDispatchDataLoader(ID2D1DrawInfo* d2D1DrawInfo)
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
_ = this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
bufferCount: (uint)data.Length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ private static string GetExceptionMessage(string error)
{
StringBuilder builder = new(512);

builder.AppendLine("The DXC compiler encountered one or more errors while trying to compile the shader:");
builder.AppendLine();
builder.AppendLine(error.Trim());
builder.AppendLine();
builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
_ = builder.AppendLine("The DXC compiler encountered one or more errors while trying to compile the shader:");
_ = builder.AppendLine();
_ = builder.AppendLine(error.Trim());
_ = builder.AppendLine();
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");

return builder.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
// HLSL primitive names
foreach (var type in HlslKnownTypes.KnownVectorTypes.Concat(HlslKnownTypes.KnownMatrixTypes))
{
knownKeywords.Add(type.Name.ToLowerInvariant());
_ = knownKeywords.Add(type.Name.ToLowerInvariant());
}

// HLSL intrinsics method names
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
{
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;

knownKeywords.Add(name);
_ = knownKeywords.Add(name);
}

// Let other types inject additional keywords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> custom
// Explicitly prevent bool from being a field in a custom struct
if (type.SpecialType == SpecialType.System_Boolean)
{
invalidTypes.Add(type);
_ = invalidTypes.Add(type);

return;
}
Expand All @@ -236,7 +236,7 @@ type.TypeKind is TypeKind.Enum ||
type.IsRefLikeType ||
type.GetFullyQualifiedName().StartsWith("System."))
{
invalidTypes.Add(type);
_ = invalidTypes.Add(type);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ private static ImmutableArray<StatementSyntax> GenerateRenderMethodBody(HlslShad

void AppendLF()
{
textBuilder.Append('\n');
_ = textBuilder.Append('\n');
}

void AppendLine(string text)
{
textBuilder.Append(text);
_ = textBuilder.Append(text);
}

void AppendParsedStatement(string text)
Expand All @@ -117,7 +117,7 @@ void FlushText()
{
string hlslSource = textBuilder.ToString();

textBuilder.Append(hlslSource);
_ = textBuilder.Append(hlslSource);

sizeHint += textBuilder.Length;

Expand All @@ -133,7 +133,7 @@ void FlushText()
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Append")))
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));

textBuilder.Clear();
_ = textBuilder.Clear();
}
}

Expand Down
Loading

0 comments on commit e053617

Please sign in to comment.