Skip to content

Mark UInt128 and other obvious readonly structs as readonly. #1496

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

Merged
merged 1 commit into from
Nov 2, 2018
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
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/CommandLine/CmdParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ private IEnumerable<KeyValuePair<string, string>> GetSettingPairsCore(IHostEnvir
}
}

private struct ArgumentHelpStrings
private readonly struct ArgumentHelpStrings
{
public readonly string Syntax;
public readonly string Help;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class LoadableClassInfo
/// <summary>
/// Used for dictionary lookup based on signature and name.
/// </summary>
internal struct Key : IEquatable<Key>
internal readonly struct Key : IEquatable<Key>
{
public readonly string Name;
public readonly Type Signature;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/IHostEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public enum MessageSensitivity
/// <summary>
/// A channel message.
/// </summary>
public struct ChannelMessage
public readonly struct ChannelMessage
{
public readonly ChannelMessageKind Kind;
public readonly MessageSensitivity Sensitivity;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/RoleMappedSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public sealed class RoleMappedSchema
/// be used when possible for consistency reasons. However, practitioners should not be afraid to declare custom
/// roles if approppriate for their task.
/// </summary>
public struct ColumnRole
public readonly struct ColumnRole
{
/// <summary>
/// Role for features. Commonly used as the independent variables given to trainers, and scorers.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/UInt128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.ML.Runtime.Data
/// <summary>
/// A sixteen-byte unsigned integer.
/// </summary>
public struct UInt128 : IComparable<UInt128>, IEquatable<UInt128>
public readonly struct UInt128 : IComparable<UInt128>, IEquatable<UInt128>
{
// The low order bits. Corresponds to H1 in the Murmur algorithms.
public readonly ulong Lo;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/BinFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public sealed class GreedyBinFinder : BinFinderBase
{
// Potential drop location for another peg, together with its energy improvement.
// PlacePegs uses a heap of these. Note that this is a struct so size matters.
private struct Segment
private readonly struct Segment
{
public readonly int Min;
public readonly int Split;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static MessageSensitivity Sensitivity(this Exception ex)
/// there will be performance implications. There shouldn't be, since checks rarely happen in
/// tight loops.
/// </summary>
private struct SensitiveExceptionContext : IExceptionContext
private readonly struct SensitiveExceptionContext : IExceptionContext
{
/// <summary>
/// We will run this instances <see cref="IExceptionContext.Process{TException}(TException)"/> first.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/MinWaiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class MinWaiter
/// is the minimum at a point when all waiters have registered, the event
/// will be signaled.
/// </summary>
private struct WaitStats
private readonly struct WaitStats
{
public readonly long Line;
public readonly ManualResetEventSlim Event;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class OrderedWaiter
/// This is an event-line pair. The intended usage is, when the line
/// is hit by the containing ordered waiter, the thread will be hit.
/// </summary>
private struct WaitStats
private readonly struct WaitStats
{
public readonly long Line;
public readonly ManualResetEventSlim Event;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public int NextSigned()
/// </summary>
public sealed class TauswortheHybrid : IRandom
{
public struct State
public readonly struct State
{
public readonly uint U1;
public readonly uint U2;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/SupervisedBinFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
/// </summary>
public sealed class SupervisedBinFinder
{
private struct ValuePair<T> : IComparable<ValuePair<T>>
private readonly struct ValuePair<T> : IComparable<ValuePair<T>>
where T : IComparable<T>
{
public readonly T Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Commands/CrossValidationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private bool TryGetOverallMetrics(Dictionary<string, IDataView>[] metrics, out L

private sealed class FoldHelper
{
public struct FoldResult
public readonly struct FoldResult
{
public readonly Dictionary<string, IDataView> Metrics;
public readonly Schema ScoreSchema;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TypeInfoCommand(IHostEnvironment env, Arguments args)
_host.CheckValue(args, nameof(args));
}

private struct TypeNaInfo
private readonly struct TypeNaInfo
{
public readonly bool HasNa;
public readonly bool DefaultIsNa;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Data/DataViewUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ internal sealed class SynchronousConsolidatingCursor : RootCursorBase, IRowCurso
private IRowCursor _currentCursor;
private bool _disposed;

private struct CursorStats
private readonly struct CursorStats
{
public readonly long Batch;
public readonly int CursorIdx;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public sealed class Arguments
/// This is a simple struct to associate a source index with a codec, without having to have
/// parallel structures everywhere.
/// </summary>
private struct ColumnCodec
private readonly struct ColumnCodec
{
public readonly int SourceIndex;
public readonly IValueCodec Codec;
Expand Down Expand Up @@ -149,7 +149,7 @@ public override MemoryStream EndBlock()
/// also have a dual usage if <see cref="Exception"/> is non-null of indicating
/// a source worker threw an exception.
/// </summary>
private struct Block
private readonly struct Block
{
/// <summary>
/// Take one guess.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/DataLoadSave/Binary/BlockLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.ML.Runtime.Data.IO
/// This structure is utilized by both the binary loader and binary saver to hold
/// information on the location of blocks written to an .IDV binary file.
/// </summary>
internal struct BlockLookup
internal readonly struct BlockLookup
{
/// <summary>The offset of the block into the file.</summary>
public readonly long BlockOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/DataLoadSave/CompositeDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public sealed class Arguments
public KeyValuePair<string, IComponentFactory<IDataView, IDataTransform>>[] Transform;
}

private struct TransformEx
private readonly struct TransformEx
{
public readonly string Tag;
public readonly string ArgsString;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private IEnumerable<int> ParseSequential()
// abort situations.
private const int TimeOut = 100;

private struct LineBatch
private readonly struct LineBatch
{
public readonly string Path;
// Total lines, up to the first line of this batch.
Expand Down Expand Up @@ -378,7 +378,7 @@ public LineBatch(Exception ex)
}
}

private struct LineInfo
private readonly struct LineInfo
{
public readonly long Line;
public readonly string Text;
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.ML.Data/DataView/CacheDataView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public static Wrapper Create(CacheDataView parent)
return new Wrapper(new TrivialWaiter(parent));
}

public struct Wrapper : IWaiter
public readonly struct Wrapper : IWaiter
{
private readonly TrivialWaiter _waiter;

Expand Down Expand Up @@ -722,7 +722,7 @@ public static Wrapper Create(CacheDataView parent, Func<int, bool> pred)
return new Wrapper(new WaiterWaiter(parent, pred));
}

public struct Wrapper : IWaiter
public readonly struct Wrapper : IWaiter
{
private readonly WaiterWaiter _waiter;

Expand Down Expand Up @@ -836,7 +836,7 @@ public static Wrapper Create(TWaiter waiter)
return new Wrapper(new SequenceIndex<TWaiter>(waiter));
}

public struct Wrapper : IIndex
public readonly struct Wrapper : IIndex
{
private readonly SequenceIndex<TWaiter> _index;

Expand Down Expand Up @@ -927,7 +927,7 @@ public static Wrapper Create(TWaiter waiter, int[] perm)
return new Wrapper(new RandomIndex<TWaiter>(waiter, perm));
}

public struct Wrapper : IIndex
public readonly struct Wrapper : IIndex
{
private readonly RandomIndex<TWaiter> _index;

Expand Down Expand Up @@ -1097,7 +1097,7 @@ public static Wrapper Create(TWaiter waiter, JobScheduler scheduler)
return new Wrapper(new BlockSequenceIndex<TWaiter>(waiter, scheduler));
}

public struct Wrapper : IIndex
public readonly struct Wrapper : IIndex
{
private readonly BlockSequenceIndex<TWaiter> _index;

Expand Down Expand Up @@ -1205,7 +1205,7 @@ public static Wrapper Create(TWaiter waiter, JobScheduler scheduler, int[] perm)
return new Wrapper(new BlockRandomIndex<TWaiter>(waiter, scheduler, perm));
}

public struct Wrapper : IIndex
public readonly struct Wrapper : IIndex
{
private readonly BlockRandomIndex<TWaiter> _index;

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Microsoft.ML.Runtime.EntryPoints.JsonUtils
/// </summary>
public sealed class InputBuilder
{
private struct Attributes
private readonly struct Attributes
{
public readonly ArgumentAttribute Input;
public readonly TlcModule.RangeAttribute Range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public sealed class Aggregator : AggregatorBase
{
public abstract class CountersBase
{
protected struct Info
protected readonly struct Info
{
public readonly Single Label;
public readonly Single Score;
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class PfaContext
private readonly HashSet<string> _types;
private readonly IHost _host;

private struct VariableBlock
private readonly struct VariableBlock
{
public readonly string Type;
public readonly KeyValuePair<string, JToken>[] Locals;
Expand All @@ -46,7 +46,7 @@ public JToken ToToken()
}
}

private struct CellBlock
private readonly struct CellBlock
{
public readonly string Name;
public readonly JToken Type;
Expand All @@ -68,7 +68,7 @@ public JObject ToToken()
}
}

private struct FuncBlock
private readonly struct FuncBlock
{
public readonly string Name;
public readonly JArray Params;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/Prediction/Calibrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ public ICalibratorTrainer CreateComponent(IHostEnvironment env)
public class PavCalibratorTrainer : CalibratorTrainerBase
{
// a piece of the piecwise function
private struct Piece
private readonly struct Piece
{
public readonly Float MinX; // end of interval.
public readonly Float MaxX; // beginning of interval.
Expand Down Expand Up @@ -1743,7 +1743,7 @@ public string GetSummary()

public sealed class CalibrationDataStore : IEnumerable<CalibrationDataStore.DataItem>
{
public struct DataItem
public readonly struct DataItem
{
// The actual binary label of this example.
public readonly bool Target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static bool IsAssignableFromStaticPipeline(this Type to, Type from)
/// <typeparam name="TLeaf">The base type in the base world.</typeparam>
private static class NameUtil<TLeaf>
{
private struct Info
private readonly struct Info
{
public readonly Type Type;
public readonly object Item;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public sealed class InvertHashCollector<T>
/// but also maintain the order in which it was inserted, assuming that
/// we're using something like a hashset where order is not preserved.
/// </summary>
private struct Pair
private readonly struct Pair
{
public readonly T Value;
public readonly int Order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static partial class TermStaticExtensions
private const KeyValueOrder DefSort = (KeyValueOrder)ValueToKeyMappingEstimator.Defaults.Sort;
private const int DefMax = ValueToKeyMappingEstimator.Defaults.MaxNumTerms;

private struct Config
private readonly struct Config
{
public readonly KeyValueOrder Order;
public readonly int Max;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.FastTree/Dataset/Dataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public sealed class RowForwardIndexer
private readonly Dataset _dataset;
private readonly FeatureFlockBase.FlockForwardIndexerBase[] _flockIndexers;

public struct Row
public readonly struct Row
{
private readonly RowForwardIndexer _indexer;
private readonly int _rowIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.ML.Trainers.FastTree.Internal
/// are then used in <see cref="LeastSquaresRegressionTreeLearner"/> to find splitting on which bin will yield the
/// best least squares solution
/// </summary>
public struct PerBinStats
public readonly struct PerBinStats
{
/// <summary>Sum of all target values in a partition for the bin.</summary>
public readonly Double SumTargets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static CommonOutputs.BinaryClassificationOutput TrainSymSgd(IHostEnvironm
/// This struct holds the information about the size, label and isDense of each instance
/// to be able to pass it to the native code.
/// </summary>
private struct InstanceProperties
private readonly struct InstanceProperties
{
public readonly int FeatureCount;
public readonly float Label;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Maml/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private void AppendFormattedText(StringBuilder builder, string text, string inde
}
}

public struct Component
public readonly struct Component
{
public readonly string Kind;
public readonly ComponentCatalog.LoadableClassInfo Info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GroupingColumn(string name, DataKind kind, ColumnPurpose purpose, string
}
}

public struct InferenceResult
public readonly struct InferenceResult
{
public readonly GroupingColumn[] Columns;

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IntermediateColumn(ReadOnlyMemory<char>[] data, int columnId)
public ReadOnlyMemory<char>[] RawData { get { return _data; } }
}

public struct Column
public readonly struct Column
{
public readonly int ColumnIndex;
public readonly string SuggestedName;
Expand All @@ -84,7 +84,7 @@ public Column(int columnIndex, string suggestedName, PrimitiveType itemType)
}
}

public struct InferenceResult
public readonly struct InferenceResult
{
public readonly Column[] Columns;
public readonly bool HasHeader;
Expand Down
Loading