Skip to content

Commit

Permalink
Fixes #627.
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnieShine committed Apr 22, 2024
1 parent 3911191 commit d0da3c0
Show file tree
Hide file tree
Showing 326 changed files with 1,520 additions and 1,524 deletions.
2 changes: 1 addition & 1 deletion global-doc-comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ result ^= expression;
<b>
<i>
This is a large structure, which means it may cost more time to copy instance than normal structures.
I strongly recommend you append <see langword="scoped ref readonly"/> to modify the type, as parameter or local variable modifiers,
I strongly recommend you append <see langword="ref readonly"/> to modify the type, as parameter or local variable modifiers,
to tell runtime that it should be copied by its reference instead of internal value.
</i>
</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ internal static class GeneratorExecutionContextExtensions
/// <param name="sourceCode">The source code.</param>
/// <seealso cref="GeneratorExecutionContext.AddSource(string, string)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void AddSource(
this scoped ref GeneratorExecutionContext @this, string fileName,
string? sourceGeneratorName, string sourceCode)
internal static void AddSource(this ref GeneratorExecutionContext @this, string fileName, string? sourceGeneratorName, string sourceCode)
=> @this.AddSource(
$"{fileName}{(sourceGeneratorName is null ? string.Empty : $".g.{sourceGeneratorName}")}.cs",
SourceText.From(sourceCode, Encoding.UTF8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static IEnumerable<ISymbol> GetAllMembers(this INamedTypeSymbol @this)
internal static string ToFileName(this INamedTypeSymbol @this)
{
var result = @this.ToDisplayString(ExtendedSymbolDisplayFormat.FullyQualifiedFormatWithConstraints)[8..];
scoped var buffer = (stackalloc char[result.Length]);
var buffer = (stackalloc char[result.Length]);
buffer.Clear();
var pointer = 0;
for (var i = 0; i < result.Length; i++)
Expand Down
18 changes: 9 additions & 9 deletions src/Sudoku.Analytics/Analytics/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where searcher.RunningArea.HasFlag(StepSearcherRunningArea.Searching)

/// <inheritdoc/>
/// <exception cref="InvalidOperationException">Throws when the puzzle has already been solved.</exception>
public AnalyzerResult Analyze(scoped ref readonly Grid puzzle, IProgress<AnalyzerProgress>? progress = null, CancellationToken cancellationToken = default)
public AnalyzerResult Analyze(ref readonly Grid puzzle, IProgress<AnalyzerProgress>? progress = null, CancellationToken cancellationToken = default)
{
if (puzzle.IsSolved)
{
Expand Down Expand Up @@ -146,11 +146,11 @@ NotImplementedException or NotSupportedException


AnalyzerResult analyzeInternal(
scoped ref readonly Grid puzzle,
scoped ref readonly Grid solution,
ref readonly Grid puzzle,
ref readonly Grid solution,
AnalyzerResult resultBase,
SymmetricType symmetricType,
scoped ReadOnlySpan<Digit?> mappingDigits,
ReadOnlySpan<Digit?> mappingDigits,
Mask selfPairedDigitsMask,
IProgress<AnalyzerProgress>? progress,
CancellationToken cancellationToken
Expand All @@ -167,7 +167,7 @@ CancellationToken cancellationToken
#endif
? []
: default(List<Step>);
scoped var context = new AnalysisContext(in playground, in puzzle)
var context = new AnalysisContext(in playground, in puzzle)
{
Accumulator = accumulator,
IsSukaku = puzzle.PuzzleType == SudokuType.Sukaku,
Expand Down Expand Up @@ -485,7 +485,7 @@ CancellationToken cancellationToken
goto FindNextStep;


static bool verifyConclusionValidity(scoped ref readonly Grid solution, Step step)
static bool verifyConclusionValidity(ref readonly Grid solution, Step step)
{
if (solution.IsUndefined)
{
Expand All @@ -508,8 +508,8 @@ static bool verifyConclusionValidity(scoped ref readonly Grid solution, Step ste
static bool onCollectingSteps(
List<Step> steps,
Step step,
scoped ref readonly AnalysisContext context,
scoped ref Grid playground,
ref readonly AnalysisContext context,
ref Grid playground,
long timestampOriginal,
List<Grid> steppingGrids,
AnalyzerResult resultBase,
Expand All @@ -520,7 +520,7 @@ static bool onCollectingSteps(
// Optimization: If the grid is inferred as a GSP pattern, we can directly add extra eliminations at symmetric positions.
if (context is { GspPatternInferred: { } symmetricType } && step is not GurthSymmetricalPlacementStep)
{
scoped var mappingRelations = context.MappingRelations;
var mappingRelations = context.MappingRelations;
var originalConclusions = step.Conclusions;
var newConclusions = new List<Conclusion>();
foreach (var conclusion in originalConclusions)
Expand Down
8 changes: 4 additions & 4 deletions src/Sudoku.Analytics/Analytics/AnalyzerResult.Searching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial record AnalyzerResult
/// <exception cref="ArgumentOutOfRangeException">
/// Throws when the specified puzzle cannot correspond to a paired <see cref="Step"/> instance.
/// </exception>
public Step this[scoped ref readonly Grid grid]
public Step this[ref readonly Grid grid]
{
get
{
Expand Down Expand Up @@ -96,7 +96,7 @@ public Step this[scoped ref readonly Grid grid]
/// </returns>
/// <seealso cref="IsSolved"/>
public ReadOnlySpan<Step> this[int difficultyRating]
=> StepsSpan.FindAll((scoped ref readonly Step step) => step.Difficulty == difficultyRating);
=> StepsSpan.FindAll((ref readonly Step step) => step.Difficulty == difficultyRating);

/// <summary>
/// Gets a list of <see cref="Step"/>s that matches the specified technique.
Expand All @@ -106,7 +106,7 @@ public ReadOnlySpan<Step> this[int difficultyRating]
/// <inheritdoc cref="this[int]" path="/returns"/>
/// </returns>
/// <seealso cref="IsSolved"/>
public ReadOnlySpan<Step> this[Technique code] => StepsSpan.FindAll((scoped ref readonly Step step) => step.Code == code);
public ReadOnlySpan<Step> this[Technique code] => StepsSpan.FindAll((ref readonly Step step) => step.Code == code);

/// <summary>
/// Gets a list of <see cref="Step"/>s that has the same difficulty level as argument <paramref name="difficultyLevel"/>.
Expand All @@ -117,5 +117,5 @@ public ReadOnlySpan<Step> this[int difficultyRating]
/// </returns>
/// <seealso cref="IsSolved"/>
public ReadOnlySpan<Step> this[DifficultyLevel difficultyLevel]
=> StepsSpan.FindAll((scoped ref readonly Step step) => step.DifficultyLevel == difficultyLevel);
=> StepsSpan.FindAll((ref readonly Step step) => step.DifficultyLevel == difficultyLevel);
}
4 changes: 2 additions & 2 deletions src/Sudoku.Analytics/Analytics/AnalyzerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Sudoku.Analytics;
/// Provides the result after <see cref="Analyzer"/> solving a puzzle.
/// </summary>
/// <param name="Puzzle"><inheritdoc cref="IAnalyzerResult{TSolver, TSolverResult}.Puzzle" path="/summary"/></param>
public sealed partial record AnalyzerResult(scoped ref readonly Grid Puzzle) :
public sealed partial record AnalyzerResult(ref readonly Grid Puzzle) :
IAnalyzerResult<Analyzer, AnalyzerResult>,
ICultureFormattable,
IEnumerable<Step>
Expand Down Expand Up @@ -346,7 +346,7 @@ public Step? DiamondStep
return null;
}

if (StepsSpan.All(static (scoped ref readonly Step step) => step is FullHouseStep or HiddenSingleStep { House: < 9 }))
if (StepsSpan.All(static (ref readonly Step step) => step is FullHouseStep or HiddenSingleStep { House: < 9 }))
{
// No diamond step exist in all steps are hidden singles in block.
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Sudoku.Analytics/Analytics/CachedFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static class CachedFields
/// <param name="g">The grid.</param>
/// <param name="s">The solution of <paramref name="g"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Initialize(scoped ref readonly Grid g, scoped ref readonly Grid s)
internal static void Initialize(ref readonly Grid g, ref readonly Grid s)
{
EmptyCells = g.EmptyCells;
BivalueCells = g.BivalueCells;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void ISet<Technique>.UnionWith(IEnumerable<Technique> other)
file sealed class Converter : JsonConverter<TechniqueSet>
{
/// <inheritdoc/>
public override TechniqueSet Read(scoped ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override TechniqueSet Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var (result, isInitialized) = (TechniqueSets.None, false);
while (reader.Read())
Expand Down
6 changes: 3 additions & 3 deletions src/Sudoku.Analytics/Analytics/Collector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where searcher.RunningArea.HasFlag(StepSearcherRunningArea.Collecting)
/// </returns>
/// <exception cref="InvalidOperationException">Throws when property <see cref="DifficultyLevelMode"/> is not defined.</exception>
public ReadOnlySpan<Step> Collect(
scoped ref readonly Grid puzzle,
ref readonly Grid puzzle,
IProgress<AnalyzerProgress>? progress = null,
CancellationToken cancellationToken = default
)
Expand Down Expand Up @@ -87,7 +87,7 @@ public ReadOnlySpan<Step> Collect(
ReadOnlySpan<Step> searchInternal(
bool isSukaku,
IProgress<AnalyzerProgress>? progress,
scoped ref readonly Grid puzzle,
ref readonly Grid puzzle,
CancellationToken cancellationToken
)
{
Expand All @@ -100,7 +100,7 @@ CancellationToken cancellationToken
Initialize(in playground, playground.SolutionGrid);

var accumulator = new List<Step>();
scoped var context = new AnalysisContext(in playground, in puzzle)
var context = new AnalysisContext(in playground, in puzzle)
{
Accumulator = accumulator,
OnlyFindOne = false,
Expand Down
2 changes: 1 addition & 1 deletion src/Sudoku.Analytics/Analytics/PuzzleInvalidException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Sudoku.Analytics;
/// <see cref="StepSearcherType"/> to learn more information.
/// </remarks>
/// <seealso cref="StepSearcherType"/>
public sealed partial class PuzzleInvalidException(scoped ref readonly Grid grid, [PrimaryConstructorParameter] Type stepSearcherType) :
public sealed partial class PuzzleInvalidException(ref readonly Grid grid, [PrimaryConstructorParameter] Type stepSearcherType) :
RuntimeAnalyticsException(in grid)
{
/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion src/Sudoku.Analytics/Analytics/StepMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static IEnumerable<TStep> RemoveDuplicateItems<TStep>(List<TStep> accumul
/// <exception cref="InvalidOperationException">
/// Throws when the length of arguments <paramref name="interimGrids"/> and <paramref name="interimSteps"/> aren't same.
/// </exception>
public static ReadOnlySpan<(Grid CurrentGrid, Step CurrentStep)> Combine(scoped ReadOnlySpan<Grid> interimGrids, scoped ReadOnlySpan<Step> interimSteps)
public static ReadOnlySpan<(Grid CurrentGrid, Step CurrentStep)> Combine(ReadOnlySpan<Grid> interimGrids, ReadOnlySpan<Step> interimSteps)
{
if (interimGrids.Length != interimSteps.Length)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sudoku.Analytics/Analytics/StepSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal int SplitPriority
/// </returns>
/// <seealso cref="Step"/>
/// <seealso cref="AnalysisContext"/>
protected internal abstract Step? Collect(scoped ref AnalysisContext context);
protected internal abstract Step? Collect(ref AnalysisContext context);

/// <inheritdoc/>
StepSearcherMetadataInfo IMetadataObject<StepSearcherMetadataInfo>.GetMetadata() => Metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public static void OnAdvanced(
NodeList pendingOn,
NodeList pendingOff,
NodeSet toOff,
scoped ref readonly Grid grid,
scoped ref readonly Grid original
ref readonly Grid grid,
ref readonly Grid original
)
{
if (pendingOn.Count == 0 && pendingOff.Count == 0 && stepSearcher.DynamicNestingLevel > 0)
Expand Down Expand Up @@ -40,8 +40,8 @@ scoped ref readonly Grid original
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
private static NodeList GetAdvancedPotentials(
AdvancedMultipleChainingStepSearcher stepSearcher,
scoped ref readonly Grid grid,
scoped ref readonly Grid original,
ref readonly Grid grid,
ref readonly Grid original,
NodeSet offPotentials
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class AlmostLockedSetsModule
/// </summary>
/// <param name="grid">The grid to be used.</param>
/// <returns>A list of ALSes.</returns>
public static ReadOnlySpan<AlmostLockedSet> CollectAlmostLockedSets(scoped ref readonly Grid grid)
public static ReadOnlySpan<AlmostLockedSet> CollectAlmostLockedSets(ref readonly Grid grid)
{
// Get all bi-value-cell ALSes.
var result = new List<AlmostLockedSet>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class ChainingModule
/// <param name="p">The potential that is assumed to be "on"</param>
/// <param name="isY">Indicates whether the same-cell strong links are enabled.</param>
/// <returns>The set of potentials that must be "off".</returns>
public static NodeSet GetOnToOff(scoped ref readonly Grid grid, ChainNode p, bool isY)
public static NodeSet GetOnToOff(ref readonly Grid grid, ChainNode p, bool isY)
{
var result = new NodeSet();
var cell = p.Cell;
Expand Down Expand Up @@ -67,9 +67,9 @@ public static NodeSet GetOnToOff(scoped ref readonly Grid grid, ChainNode p, boo
/// <param name="allowDynamic">Indicates whether the dynamic chaining rules are enabled.</param>
/// <returns>The set of potentials that must be "off".</returns>
public static NodeSet GetOffToOn(
scoped ref readonly Grid grid,
ref readonly Grid grid,
ChainNode p,
scoped in Grid? source,
in Grid? source,
NodeSet offPotentials,
bool isX,
bool isY,
Expand Down Expand Up @@ -99,7 +99,7 @@ bool allowDynamic
if (isX)
{
// Second rule: if there is only two positions for this potential, the other one gets on.
scoped ref readonly var candMaps = ref allowDynamic ? ref grid.CandidatesMap[digit] : ref CandidatesMap[digit];
ref readonly var candMaps = ref allowDynamic ? ref grid.CandidatesMap[digit] : ref CandidatesMap[digit];
foreach (var houseType in HouseTypes)
{
var houseIndex = cell.ToHouseIndex(houseType);
Expand All @@ -119,7 +119,7 @@ bool allowDynamic
return result;


static void addHiddenParentsOfCell(scoped ref ChainNode p, scoped ref readonly Grid current, scoped ref readonly Grid original, NodeSet offPotentials)
static void addHiddenParentsOfCell(ref ChainNode p, ref readonly Grid current, ref readonly Grid original, NodeSet offPotentials)
{
var cell = p.Cell;
for (byte digit = 0; digit < 9; digit++)
Expand All @@ -138,9 +138,9 @@ static void addHiddenParentsOfCell(scoped ref ChainNode p, scoped ref readonly G
}

static void addHiddenParentsOfHouse(
scoped ref ChainNode p,
scoped ref readonly Grid current,
scoped ref readonly Grid original,
ref ChainNode p,
ref readonly Grid current,
ref readonly Grid original,
HouseType currentHouseType,
NodeSet offPotentials
)
Expand All @@ -161,7 +161,7 @@ NodeSet offPotentials
}


static Mask g(scoped ref readonly Grid grid, House houseIndex, Digit digit)
static Mask g(ref readonly Grid grid, House houseIndex, Digit digit)
{
var result = (Mask)0;
for (var i = 0; i < 9; i++)
Expand Down Expand Up @@ -191,7 +191,7 @@ static Mask g(scoped ref readonly Grid grid, House houseIndex, Digit digit)
public static (ChainNode On, ChainNode Off)? DoChaining<T>(T stepSearcher, Grid grid, NodeSet toOn, NodeSet toOff, bool allowNishio, bool allowDynamic)
where T : StepSearcher
{
scoped ref readonly var originalGrid = ref grid;
ref readonly var originalGrid = ref grid;
var (pendingOn, pendingOff) = (new NodeList(toOn), new NodeList(toOff));
while (pendingOn.Count > 0 || pendingOff.Count > 0)
{
Expand Down Expand Up @@ -262,8 +262,8 @@ public static void OnAdvanced<T>(
NodeList pendingOn,
NodeList pendingOff,
NodeSet toOff,
scoped ref readonly Grid grid,
scoped ref readonly Grid original
ref readonly Grid grid,
ref readonly Grid original
) where T : StepSearcher
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class FishModule
/// <inheritdoc cref="FishStep.IsSashimi" path="/remarks"/>
/// </para>
/// </returns>
public static bool? IsSashimi(House[] baseSets, scoped ref readonly CellMap fins, Digit digit)
public static bool? IsSashimi(House[] baseSets, ref readonly CellMap fins, Digit digit)
{
if (!fins)
{
Expand Down Expand Up @@ -84,10 +84,10 @@ static FishShapeKind k(HouseMask mask)
/// <param name="accumulator">The accumulator.</param>
/// <param name="grid">The grid.</param>
/// <returns>All Siamese steps of type <see cref="FishStep"/>.</returns>
public static ReadOnlySpan<FishStep> GetSiamese(List<FishStep> accumulator, scoped ref readonly Grid grid)
public static ReadOnlySpan<FishStep> GetSiamese(List<FishStep> accumulator, ref readonly Grid grid)
{
var result = new List<FishStep>();
scoped var stepsSpan = accumulator.AsReadOnlySpan();
var stepsSpan = accumulator.AsReadOnlySpan();
for (var index1 = 0; index1 < accumulator.Count - 1; index1++)
{
var fish1 = stepsSpan[index1];
Expand All @@ -104,7 +104,7 @@ public static ReadOnlySpan<FishStep> GetSiamese(List<FishStep> accumulator, scop
return result.AsReadOnlySpan();


static bool check(scoped ref readonly Grid puzzle, FishStep fish1, FishStep fish2, [NotNullWhen(true)] out FishStep? siameseStep)
static bool check(ref readonly Grid puzzle, FishStep fish1, FishStep fish2, [NotNullWhen(true)] out FishStep? siameseStep)
{
if (fish1.BaseSetsMask != fish2.BaseSetsMask || fish1.Digit != fish2.Digit)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ internal static class IntersectionModule
/// <param name="cells">The cells.</param>
/// <returns>A list of <see cref="CellViewNode"/> instances.</returns>
public static ReadOnlySpan<CellViewNode> GetCrosshatchBaseCells(
scoped ref readonly Grid grid,
ref readonly Grid grid,
Digit digit,
House house,
scoped ref readonly CellMap cells
ref readonly CellMap cells
)
{
var info = Crosshatching.TryCreate(in grid, digit, house, in cells);
Expand Down Expand Up @@ -52,11 +52,11 @@ scoped ref readonly CellMap cells
/// <returns>A <see cref="bool"/> result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsLockedCandidates(
scoped ref readonly Grid grid,
scoped ref readonly CellMap a,
scoped ref readonly CellMap b,
scoped ref readonly CellMap c,
scoped ref readonly CellMap emptyCells,
ref readonly Grid grid,
ref readonly CellMap a,
ref readonly CellMap b,
ref readonly CellMap c,
ref readonly CellMap emptyCells,
out Mask digitsMask
)
=> (digitsMask = 0, emptyCells & c, (grid[in a], grid[in b], grid[in c])) is (_, not [], var (maskA, maskB, maskC))
Expand Down
Loading

0 comments on commit d0da3c0

Please sign in to comment.