Skip to content

Commit c54d3f9

Browse files
authored
Illuminator (#40)
1 parent ec65920 commit c54d3f9

File tree

71 files changed

+858
-523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+858
-523
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "external/illuminator"]
2-
path = external/illuminator
3-
url = https://github.com/sgaliamov/illuminator.git

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"*.sln"
1212
],
1313
"cSpell.words": [
14+
"Brfalse",
15+
"MSIL",
1416
"Redstone",
1517
"Skylake",
1618
"Struct",

ILLightenComparer.sln

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
readme.md = readme.md
1818
EndProjectSection
1919
EndProject
20-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Illuminator", "external\illuminator\src\Illuminator\Illuminator.csproj", "{BA1BD1BA-215E-483D-BD64-63DAA30FF778}"
21-
EndProject
2220
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{15FA73AD-EF43-4228-A4F6-44E186E5C06B}"
2321
ProjectSection(SolutionItems) = preProject
2422
scripts\benchmarks.ps1 = scripts\benchmarks.ps1
@@ -34,13 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{EBC9FF7F-B
3432
docs\roadmap.md = docs\roadmap.md
3533
EndProjectSection
3634
EndProject
37-
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Illuminator.Shared", "external\illuminator\src\Illuminator\Illuminator.Shared.shproj", "{4497D5CE-4813-46BA-868D-58D696AE81D4}"
38-
EndProject
3935
Global
40-
GlobalSection(SharedMSBuildProjectFiles) = preSolution
41-
external\illuminator\src\Illuminator\Illuminator.Shared.projitems*{020c78a5-4642-42c5-900c-dd3658051481}*SharedItemsImports = 5
42-
external\illuminator\src\Illuminator\Illuminator.Shared.projitems*{4497d5ce-4813-46ba-868d-58d696ae81d4}*SharedItemsImports = 13
43-
EndGlobalSection
4436
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4537
Debug|Any CPU = Debug|Any CPU
4638
Release|Any CPU = Release|Any CPU
@@ -58,10 +50,6 @@ Global
5850
{52C5C857-3A08-4D74-B954-1B99FEB403D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
5951
{52C5C857-3A08-4D74-B954-1B99FEB403D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
6052
{52C5C857-3A08-4D74-B954-1B99FEB403D5}.Release|Any CPU.Build.0 = Release|Any CPU
61-
{BA1BD1BA-215E-483D-BD64-63DAA30FF778}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62-
{BA1BD1BA-215E-483D-BD64-63DAA30FF778}.Debug|Any CPU.Build.0 = Debug|Any CPU
63-
{BA1BD1BA-215E-483D-BD64-63DAA30FF778}.Release|Any CPU.ActiveCfg = Release|Any CPU
64-
{BA1BD1BA-215E-483D-BD64-63DAA30FF778}.Release|Any CPU.Build.0 = Release|Any CPU
6553
EndGlobalSection
6654
GlobalSection(SolutionProperties) = preSolution
6755
HideSolutionNode = FALSE

ILLightenComparer.sln.DotSettings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">True</s:Boolean>
5+
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_PREPROCESSOR_IF/@EntryValue">USUAL_INDENT</s:String>
6+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
7+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
9+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install:
2323

2424
before_build:
2525
- pwsh: |
26-
gitversion /l console /output buildserver /verbosity warn
26+
gitversion /l console /output buildserver /verbosity quiet
2727
if ($env:APPVEYOR_REPO_TAG -eq $false) {
2828
Set-AppveyorBuildVariable -Name Configuration -Value debug
2929
}

docs/deployment.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
# Deployment process
1+
# Development
22

3-
## Preliminary statements
3+
1. Create a new feature branch from *master*.
4+
1. Squash and merge RP.
5+
1. Publish [release](https://github.com/sgaliamov/il-lighten-comparer/releases/new).
46

5-
1. Use GitFlow to have separate `develop` and `master` branch.
6-
1. Version of the next package is defined by tag on `master` branch.
7-
1. Promotion on productions must happen manually, but automatically to private `nuget` hub.
8-
9-
## Release
10-
11-
1. Create PR from `develop` branch to `master`. Make sure that all checks is passed.
12-
1. Merge RP (do not squash `develop`).
13-
1. Wait for all builds to ensure that it works after the merge.
14-
1. Add [release notes](https://github.com/sgaliamov/il-lighten-comparer/tags) and publish the release.
15-
1. [Deploy](https://ci.appveyor.com/environment/40781/deployments/new) to [nuget.org](https://nuget.org) if need be.
7+
It will publish the package to [nuget.org](https://www.nuget.org/packages/ILLightenComparer/).

external/illuminator

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/ILLightenComparer.Benchmarks/Benchmark/EqualityBenchmark.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using System.Reflection.Emit;
44
using System.Runtime.CompilerServices;
55
using BenchmarkDotNet.Attributes;
6-
using Illuminator.Extensions;
7-
using static Illuminator.Functional;
6+
using Illuminator;
7+
using static Illuminator.Functions;
88

99
namespace ILLightenComparer.Benchmarks.Benchmark
1010
{
@@ -15,9 +15,9 @@ public class EqualityBenchmark
1515
private const int N = 10000;
1616
private readonly int[] _one = new int[N];
1717
private readonly int[] _other = new int[N];
18-
1918
[SuppressMessage("Code Quality", "IDE0052:Remove unread private members", Justification = "<Pending>")]
2019
private bool _out;
20+
2121
private Func<int, int, bool> _subCompare;
2222
private Func<int, int, bool> _subNot;
2323

@@ -32,21 +32,23 @@ public void Setup()
3232
}
3333

3434
var subCompare = new DynamicMethod("SubCompare", typeof(bool), new[] { typeof(int), typeof(int) });
35-
using (var il = subCompare.GetILGenerator().CreateILEmitter()) {
36-
il.Sub(LoadArgument(0), LoadArgument(1))
37-
.IfFalse_S(out var equals)
38-
.Return(0)
35+
using (var il = subCompare.GetILGenerator().UseIlluminator()) {
36+
il.Sub(Ldarg(0), Ldarg(1))
37+
.Brfalse_S(out var equals)
38+
.Ldc_I4_0()
39+
.Ret()
3940
.MarkLabel(equals)
40-
.Return(1);
41+
.Ldc_I4_1()
42+
.Ret();
4143

4244
_subCompare = subCompare.CreateDelegate<Func<int, int, bool>>();
4345
}
4446

4547
var subNot = new DynamicMethod("SubNot", typeof(bool), new[] { typeof(int), typeof(int) });
46-
using (var il = subNot.GetILGenerator().CreateILEmitter()) {
47-
il.Sub(LoadArgument(0), LoadArgument(1))
48+
using (var il = subNot.GetILGenerator().UseIlluminator()) {
49+
il.Sub(Ldarg(0), Ldarg(1))
4850
.Not()
49-
.Return();
51+
.Ret();
5052

5153
_subNot = subNot.CreateDelegate<Func<int, int, bool>>();
5254
}
@@ -77,7 +79,7 @@ public void Sub()
7779
}
7880

7981
[MethodImpl(MethodImplOptions.NoInlining)]
80-
private static bool Sub(int a, int b) => (a - b) == 0;
82+
private static bool Sub(int a, int b) => a - b == 0;
8183

8284
[Benchmark]
8385
public void Equals()
@@ -101,4 +103,4 @@ public void Operator()
101103
[MethodImpl(MethodImplOptions.NoInlining)]
102104
private static bool Operator(int a, int b) => a == b;
103105
}
104-
}
106+
}

src/ILLightenComparer.Tests/ComparerTests/GenericTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using FluentAssertions.Execution;
1010
using Force.DeepCloner;
1111
using ILLightenComparer.Tests.Utilities;
12-
using Illuminator.Extensions;
1312

1413
namespace ILLightenComparer.Tests.ComparerTests
1514
{
@@ -152,7 +151,7 @@ private static void Comparisons_work_identical<T>(IComparer<T> referenceComparer
152151
var expected = referenceComparer.Compare(x, y).Normalize();
153152
var actual = typedComparer.Compare(x, y).Normalize();
154153

155-
var message = $"{type.DisplayName()} should be supported.\n"
154+
var message = $"{type.FullName} should be supported.\n"
156155
+ $"x: {x.ToJson()},\n"
157156
+ $"y: {y.ToJson()}";
158157

src/ILLightenComparer.Tests/EqualityExamples.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void Basic_usage()
1818

1919
var equality = comparer.Equals(x, y);
2020
var hashX = comparer.GetHashCode(x);
21+
2122
var hashY = comparer.GetHashCode(y);
2223

2324
using (new AssertionScope()) {

src/ILLightenComparer.Tests/EqualityTests/GenericTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using FluentAssertions.Execution;
1010
using Force.DeepCloner;
1111
using ILLightenComparer.Tests.Utilities;
12-
using Illuminator.Extensions;
1312

1413
namespace ILLightenComparer.Tests.EqualityTests
1514
{
@@ -166,7 +165,7 @@ private void Comparisons_work_identical<T>(IEqualityComparer<T> referenceCompare
166165
var expectedEquals = referenceComparer.Equals(x, y);
167166
var actualEquals = typedComparer.Equals(x, y);
168167

169-
var message = $"{type.DisplayName()} should be supported.";
168+
var message = $"{type.FullName} should be supported.";
170169
actualEquals.Should().Be(expectedEquals, message);
171170

172171
if (_compareHashes) {

src/ILLightenComparer.Tests/EqualityTests/SampleTypesTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ public void Compare_nullable_types_directly()
3636
}
3737

3838
[Fact]
39-
public void Compare_types_directly()
40-
{
39+
public void Compare_types_directly() =>
4140
Parallel.ForEach(TestTypes.Types, item => {
4241
var (type, referenceComparer) = item;
4342
new GenericTests(false).GenericTest(type, referenceComparer, Constants.SmallCount);
4443
});
45-
}
4644

4745
[Fact]
4846
public void Should_use_delayed_comparison()
@@ -69,14 +67,12 @@ public void Should_use_delayed_comparison()
6967
}
7068
}
7169

72-
private static void TestCollection(Type genericCollectionType = null)
73-
{
70+
private static void TestCollection(Type genericCollectionType = null) =>
7471
Parallel.ForEach(TestTypes.Types, item => {
7572
var (type, referenceComparer) = item;
7673
TestCollection(type, referenceComparer, genericCollectionType, false);
7774
TestCollection(type, referenceComparer, genericCollectionType, true);
7875
});
79-
}
8076

8177
private static void TestNullableCollection(Type genericCollectionType = null)
8278
{

src/ILLightenComparer.Tests/Utilities/CasualNullGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Reflection;
44
using AutoFixture.Kernel;
5-
using Illuminator.Extensions;
65

76
namespace ILLightenComparer.Tests.Utilities
87
{

src/ILLightenComparer.Tests/Utilities/FixtureBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using AutoFixture;
66
using AutoFixture.Kernel;
77
using Force.DeepCloner;
8-
using Illuminator.Extensions;
98
using Xunit;
109

1110
namespace ILLightenComparer.Tests.Utilities

src/ILLightenComparer.Tests/Utilities/Helper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using FluentAssertions.Execution;
99
using ILLightenComparer.Tests.Comparers;
1010
using ILLightenComparer.Tests.EqualityComparers;
11-
using Illuminator.Extensions;
1211
using Xunit;
1312

1413
namespace ILLightenComparer.Tests.Utilities

src/ILLightenComparer.Tests/Utilities/ObjectExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Reflection;
77
using System.Runtime.CompilerServices;
88
using System.Threading;
9-
using Illuminator.Extensions;
109
using Newtonsoft.Json;
1110

1211
namespace ILLightenComparer.Tests.Utilities
@@ -34,7 +33,7 @@ public static T GetOrAddProperty<T, TTarget>(this TTarget obj, string name, Func
3433
public static Type GetGenericInterface(this Type type, Type generic)
3534
{
3635
if (!generic.IsGenericType) {
37-
throw new ArgumentException($"{generic.DisplayName()} should be generic type.", nameof(generic));
36+
throw new ArgumentException($"{generic.FullName} should be generic type.", nameof(generic));
3837
}
3938

4039
if (type.IsInterface && type.IsGenericType && type.GetGenericTypeDefinition() == generic) {

src/ILLightenComparer.Tests/Utilities/ObjectWalker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Reflection;
6-
using Illuminator.Extensions;
76

87
namespace ILLightenComparer.Tests.Utilities
98
{

src/ILLightenComparer.Tests/Utilities/ReflectionExtensions.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,35 @@ public static Type MakeNullable(this Type type)
1414
}
1515

1616
public static bool IsSealedType(this Type type) => type.IsValueType || type.IsSealed;
17+
18+
public static bool IsNullable(this Type type) =>
19+
type.IsValueType
20+
&& type.IsGenericType
21+
&& !type.IsGenericTypeDefinition
22+
&& ReferenceEquals(type.GetGenericTypeDefinition(), typeof(Nullable<>));
23+
24+
public static bool IsPrimitive(this Type type) =>
25+
type.IsPrimitive
26+
|| type.IsEnum
27+
|| ReferenceEquals(type, typeof(string))
28+
// || ReferenceEquals(type, typeof(object)) // todo: 3. move extensions to separate assembly
29+
|| ReferenceEquals(type, typeof(decimal));
30+
31+
public static bool ImplementsGenericInterface(this Type type, Type generic) => type.FindGenericInterface(generic) != null;
32+
33+
public static Type FindGenericInterface(this Type type, Type generic)
34+
{
35+
if (!generic.IsGenericType) {
36+
throw new ArgumentException($"{generic.FullName} should be generic type.", nameof(generic));
37+
}
38+
39+
if (type.IsInterface && type.IsGenericType && type.GetGenericTypeDefinition() == generic) {
40+
return type;
41+
}
42+
43+
return Array.Find(
44+
type.GetInterfaces(),
45+
t => t.IsGenericType && generic == t.GetGenericTypeDefinition());
46+
}
1747
}
18-
}
48+
}

src/ILLightenComparer/Abstractions/IComparisonEmitter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ internal interface IComparisonEmitter
1919

2020
internal static class ComparisonEmitterExtensions
2121
{
22-
public static ILEmitterFunc Emit(this IComparisonEmitter emitter, Label next) => il => emitter.Emit(il, next);
23-
public static ILEmitterFunc EmitCheckForResult(this IComparisonEmitter emitter, Label next) => il => emitter.EmitCheckForResult(il, next);
22+
public static ILEmitterFunc Emit(this IComparisonEmitter emitter, Label next) =>
23+
(in ILEmitter il) => emitter.Emit(il, next);
24+
25+
public static ILEmitterFunc EmitCheckForResult(this IComparisonEmitter emitter, Label next) =>
26+
(in ILEmitter il) => emitter.EmitCheckForResult(il, next);
2427
}
25-
}
28+
}
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
using System.Reflection.Emit;
22
using Illuminator;
3-
using static Illuminator.Functional;
3+
using static ILLightenComparer.Extensions.Functions;
4+
using static Illuminator.Functions;
45

56
namespace ILLightenComparer.Abstractions
67
{
78
internal interface IHasherEmitter
89
{
910
/// <summary>
10-
/// Hashing logic builder.
11+
/// Hashing logic builder.
1112
/// </summary>
1213
ILEmitter Emit(ILEmitter il);
1314

1415
/// <summary>
15-
/// Hashing logic builder with variable to accumulate hash.
16+
/// Hashing logic builder with variable to accumulate hash.
1617
/// </summary>
1718
ILEmitter Emit(ILEmitter il, LocalBuilder hash);
1819
}
1920

2021
internal static class HasherEmitterExtensions
2122
{
22-
public static ILEmitterFunc Emit(this IHasherEmitter hasher, LocalBuilder hash) => il => hasher.Emit(il, hash);
23+
public static ILEmitterFunc Emit(this IHasherEmitter hasher, LocalBuilder hash) =>
24+
(in ILEmitter il) => hasher.Emit(il, hash);
2325

2426
public static ILEmitter EmitHashing(this IHasherEmitter hasher, ILEmitter il, LocalBuilder hash)
2527
{
2628
var add = Add(
27-
ShiftLeft(LoadLocal(hash), LoadInteger(5)),
28-
LoadLocal(hash));
29+
Shl(Ldloc(hash), Ldc_I4(5)),
30+
Ldloc(hash));
2931

3032
return il
31-
.Xor(add, Cast<long>(hasher.Emit(hash))) // todo: 2. need to cast?
32-
.Store(hash);
33+
.Xor(add, Cast<long>(hasher.Emit(hash))) // todo: 2. need to cast?
34+
.Stloc(hash);
3335
}
3436
}
35-
}
37+
}

0 commit comments

Comments
 (0)