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

Prefer using collection expressions with implicit object creation when the type is apparent #455

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 2 additions & 36 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = true:error

# Field preferences
dotnet_style_readonly_field = true:suggestion
Expand Down Expand Up @@ -122,7 +123,7 @@ csharp_style_prefer_range_operator = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_implicit_object_creation_when_type_is_apparent = true:error

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
Expand Down Expand Up @@ -235,38 +236,3 @@ dotnet_naming_style.IPascalCase.required_prefix = I
dotnet_naming_style.IPascalCase.required_suffix =
dotnet_naming_style.IPascalCase.word_separator =
dotnet_naming_style.IPascalCase.capitalization = pascal_case

# TODO:
# .NET 8 migration (new warnings are caused by the NET 8 C# compiler and analyzer)
# The following info messages might need to be fixed in the source code instead of hiding the actual message
# Without the following lines, dotnet format would fail
# Disable "Collection initialization can be simplified"
dotnet_diagnostic.IDE0028.severity = none
dotnet_diagnostic.IDE0300.severity = none
dotnet_diagnostic.IDE0301.severity = none
dotnet_diagnostic.IDE0302.severity = none
dotnet_diagnostic.IDE0305.severity = none
# Disable "'new' expression can be simplified"
dotnet_diagnostic.IDE0090.severity = none
# Disable "Use primary constructor"
dotnet_diagnostic.IDE0290.severity = none
# Disable "Member '' does not access instance data and can be marked as static"
dotnet_diagnostic.CA1822.severity = none
# Disable "Change type of field '' from '' to '' for improved performance"
dotnet_diagnostic.CA1859.severity = none
# Disable "Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array"
dotnet_diagnostic.CA1861.severity = none
# Disable "Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'"
dotnet_diagnostic.CA1862.severity = none

[src/Ryujinx/UI/ViewModels/**.cs]
# Disable "mark members as static" rule for ViewModels
dotnet_diagnostic.CA1822.severity = none

[src/Ryujinx.HLE/HOS/Services/**.cs]
# Disable "mark members as static" rule for services
dotnet_diagnostic.CA1822.severity = none

[src/Ryujinx.Tests/Cpu/*.cs]
# Disable naming rules for CPU tests
dotnet_diagnostic.IDE1006.severity = none
2 changes: 1 addition & 1 deletion src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static class Arm64Optimizer

public static void RunPass(ControlFlowGraph cfg)
{
var constants = new Dictionary<ulong, Operand>();
Dictionary<ulong, Operand> constants = [];

Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source)
{
Expand Down
12 changes: 6 additions & 6 deletions src/ARMeilleure/CodeGen/Arm64/CodeGenContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ConstantPoolEntry(int offset, Symbol symbol)
{
Offset = offset;
Symbol = symbol;
LdrOffsets = new List<(Operand, int)>();
LdrOffsets = [];
}
}

Expand Down Expand Up @@ -78,9 +78,9 @@ public CodeGenContext(AllocationResult allocResult, int maxCallArgs, bool reloca
CallArgsRegionSize = maxCallArgs * 16;
FpLrSaveRegionSize = hasCall ? 16 : 0;

_visitedBlocks = new Dictionary<BasicBlock, long>();
_pendingBranches = new Dictionary<BasicBlock, List<(ArmCondition, long)>>();
_constantPool = new Dictionary<ulong, ConstantPoolEntry>();
_visitedBlocks = [];
_pendingBranches = [];
_constantPool = [];

_relocatable = relocatable;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public void JumpTo(ArmCondition condition, BasicBlock target)
{
if (!_pendingBranches.TryGetValue(target, out var list))
{
list = new List<(ArmCondition, long)>();
list = [];
_pendingBranches.Add(target, list);
}

Expand Down Expand Up @@ -266,7 +266,7 @@ private long WriteConstantPool()
}
else
{
relocInfo = new RelocInfo(Array.Empty<RelocEntry>());
relocInfo = new RelocInfo([]);
}

return (code, relocInfo);
Expand Down
4 changes: 2 additions & 2 deletions src/ARMeilleure/CodeGen/Arm64/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ private static void GenerateZeroExtend8(CodeGenContext context, Operation operat

private static UnwindInfo WritePrologue(CodeGenContext context)
{
List<UnwindPushEntry> pushEntries = new();
List<UnwindPushEntry> pushEntries = [];

Operand rsp = Register(SpRegister);

Expand Down Expand Up @@ -1141,7 +1141,7 @@ private static UnwindInfo WritePrologue(CodeGenContext context)
}
}

return new UnwindInfo(pushEntries.ToArray(), context.StreamOffset);
return new UnwindInfo([.. pushEntries], context.StreamOffset);
}

private static void WritePrologueCalleeSavesPreIndexed(
Expand Down
6 changes: 3 additions & 3 deletions src/ARMeilleure/CodeGen/Arm64/HardwareCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ private static bool CheckSysctlName(string name)
return false;
}

private static readonly string[] _sysctlNames = new string[]
{
private static readonly string[] _sysctlNames =
[
"hw.optional.floatingpoint",
"hw.optional.AdvSIMD",
"hw.optional.arm.FEAT_FP16",
Expand All @@ -151,7 +151,7 @@ private static bool CheckSysctlName(string name)
"hw.optional.armv8_crc32",
"hw.optional.arm.FEAT_SHA1",
"hw.optional.arm.FEAT_SHA256",
};
];

[Flags]
public enum MacOsFeatureFlags
Expand Down
24 changes: 12 additions & 12 deletions src/ARMeilleure/CodeGen/Arm64/PreAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private class ConstantDict

public ConstantDict()
{
_constants = new Dictionary<(ulong, OperandType), Operand>();
_constants = [];
}

public void Add(ulong value, OperandType type, Operand local)
Expand Down Expand Up @@ -261,10 +261,10 @@ private static void InsertCallCopies(ConstantDict constants, IntrusiveList<Opera

Operand dest = operation.Destination;

List<Operand> sources = new()
{
List<Operand> sources =
[
operation.GetSource(0),
};
];

int argsCount = operation.SourcesCount - 1;

Expand Down Expand Up @@ -357,18 +357,18 @@ private static void InsertCallCopies(ConstantDict constants, IntrusiveList<Opera
}
}

operation.SetSources(sources.ToArray());
operation.SetSources([.. sources]);
}

private static void InsertTailcallCopies(ConstantDict constants,
IntrusiveList<Operation> nodes,
Operation node,
Operation operation)
{
List<Operand> sources = new()
{
List<Operand> sources =
[
operation.GetSource(0),
};
];

int argsCount = operation.SourcesCount - 1;

Expand Down Expand Up @@ -435,7 +435,7 @@ private static void InsertTailcallCopies(ConstantDict constants,

sources[0] = tcAddress;

operation.SetSources(sources.ToArray());
operation.SetSources([.. sources]);
}

private static Operation GenerateCompareAndSwap(IntrusiveList<Operation> nodes, Operation node)
Expand Down Expand Up @@ -468,8 +468,8 @@ void SplitOperand(Operand source, Operand low, Operand high)

// Update the sources and destinations with split 64-bit halfs of the whole 128-bit values.
// We also need a additional registers that will be used to store temporary information.
operation.SetDestinations(new[] { actualLow, actualHigh, Local(OperandType.I64), Local(OperandType.I64) });
operation.SetSources(new[] { address, expectedLow, expectedHigh, desiredLow, desiredHigh });
operation.SetDestinations([actualLow, actualHigh, Local(OperandType.I64), Local(OperandType.I64)]);
operation.SetSources([address, expectedLow, expectedHigh, desiredLow, desiredHigh]);

// Add some dummy uses of the input operands, as the CAS operation will be a loop,
// so they can't be used as destination operand.
Expand All @@ -486,7 +486,7 @@ void SplitOperand(Operand source, Operand low, Operand high)
else
{
// We need a additional register where the store result will be written to.
node.SetDestinations(new[] { node.Destination, Local(OperandType.I32) });
node.SetDestinations([node.Destination, Local(OperandType.I32)]);

// Add some dummy uses of the input operands, as the CAS operation will be a loop,
// so they can't be used as destination operand.
Expand Down
12 changes: 6 additions & 6 deletions src/ARMeilleure/CodeGen/RegisterAllocators/CopyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Copy(Register dest, Register source, OperandType type)

public ParallelCopy()
{
_copies = new List<Copy>();
_copies = [];
}

public void AddCopy(Register dest, Register source, OperandType type)
Expand All @@ -41,10 +41,10 @@ public void AddCopy(Register dest, Register source, OperandType type)

public void Sequence(List<Operation> sequence)
{
Dictionary<Register, Register> locations = new();
Dictionary<Register, Register> sources = new();
Dictionary<Register, Register> locations = [];
Dictionary<Register, Register> sources = [];

Dictionary<Register, OperandType> types = new();
Dictionary<Register, OperandType> types = [];

Queue<Register> pendingQueue = new();
Queue<Register> readyQueue = new();
Expand Down Expand Up @@ -218,7 +218,7 @@ private void AddSplitCopy(LiveInterval left, LiveInterval right, OperandType typ

public Operation[] Sequence()
{
List<Operation> sequence = new();
List<Operation> sequence = [];

if (_spillQueue != null)
{
Expand All @@ -238,7 +238,7 @@ public Operation[] Sequence()
}
}

return sequence.ToArray();
return [.. sequence];
}

private static Operand GetRegister(Register reg, OperandType type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private static void Spill(AllocationContext context, LiveInterval interval)

private void InsertSplitCopies()
{
Dictionary<int, CopyResolver> copyResolvers = new();
Dictionary<int, CopyResolver> copyResolvers = [];

CopyResolver GetCopyResolver(int position)
{
Expand Down Expand Up @@ -799,8 +799,8 @@ private static Operand GetRegister(LiveInterval interval)

private void NumberLocals(ControlFlowGraph cfg, int registersCount)
{
_operationNodes = new List<(IntrusiveList<Operation>, Operation)>();
_intervals = new List<LiveInterval>();
_operationNodes = [];
_intervals = [];

for (int index = 0; index < registersCount; index++)
{
Expand Down Expand Up @@ -839,7 +839,7 @@ static void SetVisited(Operand local)
{
dest.NumberLocal(_intervals.Count);

LiveInterval interval = new LiveInterval(dest);
LiveInterval interval = new(dest);
_intervals.Add(interval);

SetVisited(dest);
Expand Down Expand Up @@ -873,7 +873,7 @@ static void SetVisited(Operand local)
}
}

_parentIntervals = _intervals.ToArray();
_parentIntervals = [.. _intervals];
}

private void BuildIntervals(ControlFlowGraph cfg, AllocationContext context)
Expand Down Expand Up @@ -980,7 +980,7 @@ void VisitDestination(Operand dest)

_blockLiveIn = blkLiveIn;

_blockEdges = new HashSet<int>();
_blockEdges = [];

// Compute lifetime intervals.
int operationPos = _operationsCount;
Expand Down
8 changes: 4 additions & 4 deletions src/ARMeilleure/CodeGen/X86/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ private struct Reloc
public Assembler(Stream stream, bool relocatable)
{
_stream = stream;
_labels = new Dictionary<Operand, long>();
_jumps = new List<Jump>();
_labels = [];
_jumps = [];

_relocs = relocatable ? new List<Reloc>() : null;
_relocs = relocatable ? [] : null;
}

public void MarkLabel(Operand label)
Expand Down Expand Up @@ -1418,7 +1418,7 @@ void SetRegisterHighBit(Register reg, int bit)
int relocOffset = 0;
var relocEntries = hasRelocs
? new RelocEntry[relocs.Length]
: Array.Empty<RelocEntry>();
: [];

for (int i = 0; i < jumps.Length; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ARMeilleure/CodeGen/X86/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ private static void EnsureSameType(Operand op1, Operand op2, Operand op3, Operan

private static UnwindInfo WritePrologue(CodeGenContext context)
{
List<UnwindPushEntry> pushEntries = new();
List<UnwindPushEntry> pushEntries = [];

Operand rsp = Register(X86Register.Rsp);

Expand Down Expand Up @@ -1800,7 +1800,7 @@ private static UnwindInfo WritePrologue(CodeGenContext context)
mask &= ~(1 << bit);
}

return new UnwindInfo(pushEntries.ToArray(), context.StreamOffset);
return new UnwindInfo([.. pushEntries], context.StreamOffset);
}

private static void WriteEpilogue(CodeGenContext context)
Expand Down
6 changes: 3 additions & 3 deletions src/ARMeilleure/CodeGen/X86/HardwareCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ private static uint GetXcr0Eax()
return 0;
}

ReadOnlySpan<byte> asmGetXcr0 = new byte[]
{
ReadOnlySpan<byte> asmGetXcr0 =
[
0x31, 0xc9, // xor ecx, ecx
0xf, 0x01, 0xd0, // xgetbv
0xc3, // ret
};
];

using MemoryBlock memGetXcr0 = new((ulong)asmGetXcr0.Length);

Expand Down
Loading
Loading