Skip to content

Commit 2a11aab

Browse files
Move things from ILCompiler.TypeSystem to ILCompiler.Compiler (#63280)
IL generation (stubs/thunks) is not part of the core type system and these files are not included in ILCompiler.TypeSystem.ReadyToRun. Somehow we accumulated them in ILCompiler.TypeSystem but they can be pretty cleanly moved to ILCompiler.Compiler (left one TODO for a subsequent cleanup since some of what's in Common\TypeSystem should actually be in ILCompiler.Compiler proper).
1 parent c7ec82a commit 2a11aab

27 files changed

+229
-245
lines changed

src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of methods
99
partial class CalliMarshallingMethodThunk
1010
{
11-
protected internal override int ClassCode => 1594107963;
11+
protected override int ClassCode => 1594107963;
1212

13-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
13+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1414
{
1515
var otherMethod = (CalliMarshallingMethodThunk)other;
1616
return comparer.Compare(_targetSignature, otherMethod._targetSignature);

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of methods
99
partial class DelegateMarshallingMethodThunk
1010
{
11-
protected internal override int ClassCode => 1018037605;
11+
protected override int ClassCode => 1018037605;
1212

13-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
13+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1414
{
1515
var otherMethod = (DelegateMarshallingMethodThunk)other;
1616
int result = (int)Kind - (int)otherMethod.Kind;

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.Sorting.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of types
99
partial class DelegateThunk
1010
{
11-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
11+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1212
{
1313
var otherMethod = (DelegateThunk)other;
1414
return comparer.Compare(_delegateInfo.Type, otherMethod._delegateInfo.Type);
@@ -17,39 +17,39 @@ protected internal override int CompareToImpl(MethodDesc other, TypeSystemCompar
1717

1818
partial class DelegateInvokeOpenStaticThunk
1919
{
20-
protected internal override int ClassCode => 386356101;
20+
protected override int ClassCode => 386356101;
2121
}
2222

2323
public sealed partial class DelegateInvokeOpenInstanceThunk
2424
{
25-
protected internal override int ClassCode => -1787190244;
25+
protected override int ClassCode => -1787190244;
2626
}
2727

2828
partial class DelegateInvokeClosedStaticThunk
2929
{
30-
protected internal override int ClassCode => 28195375;
30+
protected override int ClassCode => 28195375;
3131
}
3232

3333
partial class DelegateInvokeMulticastThunk
3434
{
35-
protected internal override int ClassCode => 639863471;
35+
protected override int ClassCode => 639863471;
3636
}
3737

3838
partial class DelegateInvokeInstanceClosedOverGenericMethodThunk
3939
{
40-
protected internal override int ClassCode => -354480633;
40+
protected override int ClassCode => -354480633;
4141
}
4242

4343
partial class DelegateInvokeObjectArrayThunk
4444
{
45-
protected internal override int ClassCode => 1993292344;
45+
protected override int ClassCode => 1993292344;
4646
}
4747

4848
partial class DelegateGetThunkMethodOverride
4949
{
50-
protected internal override int ClassCode => -321263379;
50+
protected override int ClassCode => -321263379;
5151

52-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
52+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
5353
{
5454
var otherMethod = (DelegateGetThunkMethodOverride)other;
5555
return comparer.Compare(_delegateInfo.Type, otherMethod._delegateInfo.Type);

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ public override MethodIL EmitIL()
726726
Debug.Assert(_delegateInfo.Thunks[i] == null);
727727

728728
var sig = new DynamicInvokeMethodSignature(_delegateInfo.Signature);
729-
MethodDesc thunk = Context.GetDynamicInvokeThunk(sig);
729+
// TODO: layering violation. Should move delegate thunk stuff to ILCompiler.Compiler.
730+
MethodDesc thunk = ((ILCompiler.CompilerTypeSystemContext)Context).GetDynamicInvokeThunk(sig);
730731

731732
if (thunk.HasInstantiation)
732733
{

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.Sorting.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace Internal.IL.Stubs
1111
// Functionality related to determinstic ordering of types
1212
partial class DynamicInvokeMethodThunk
1313
{
14-
protected internal override int ClassCode => -1980933220;
14+
protected override int ClassCode => -1980933220;
1515

16-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
16+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1717
{
1818
return CompareTo((DynamicInvokeMethodThunk)other);
1919
}
@@ -51,9 +51,9 @@ private int CompareTo(DynamicInvokeMethodThunk otherMethod)
5151

5252
partial class DynamicInvokeThunkGenericParameter
5353
{
54-
protected internal override int ClassCode => -234393261;
54+
protected override int ClassCode => -234393261;
5555

56-
protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
56+
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
5757
{
5858
var otherType = (DynamicInvokeThunkGenericParameter)other;
5959
int result = Index - otherType.Index;

src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.Sorting.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of types
99
partial class EnumGetHashCodeThunk
1010
{
11-
protected internal override int ClassCode => 261739662;
11+
protected override int ClassCode => 261739662;
1212

13-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
13+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1414
{
1515
var otherMethod = (EnumGetHashCodeThunk)other;
1616
return comparer.Compare(_owningType, otherMethod._owningType);
@@ -19,9 +19,9 @@ protected internal override int CompareToImpl(MethodDesc other, TypeSystemCompar
1919

2020
partial class EnumEqualsThunk
2121
{
22-
protected internal override int ClassCode => -1774524780;
22+
protected override int ClassCode => -1774524780;
2323

24-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
24+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
2525
{
2626
var otherMethod = (EnumEqualsThunk)other;
2727
return comparer.Compare(_owningType, otherMethod._owningType);

src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of types
99
partial class ForwardDelegateCreationThunk
1010
{
11-
protected internal override int ClassCode => 1026039617;
11+
protected override int ClassCode => 1026039617;
1212

13-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
13+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1414
{
1515
var otherMethod = (ForwardDelegateCreationThunk)other;
1616

src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Internal.IL.Stubs
77
{
88
partial class PInvokeLazyFixupField
99
{
10-
protected internal override int ClassCode => -1784477702;
10+
protected override int ClassCode => -1784477702;
1111

12-
protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
12+
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
1313
{
1414
return comparer.Compare(_targetMethod, ((PInvokeLazyFixupField)other)._targetMethod);
1515
}

src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
88
// Functionality related to deterministic ordering of types
99
partial class StructMarshallingThunk
1010
{
11-
protected internal override int ClassCode => 340834018;
11+
protected override int ClassCode => 340834018;
1212

13-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
13+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1414
{
1515
var otherMethod = (StructMarshallingThunk)other;
1616

src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Internal.IL.Stubs
77
{
88
partial class ValueTypeGetFieldHelperMethodOverride
99
{
10-
protected internal override int ClassCode => 2036839816;
10+
protected override int ClassCode => 2036839816;
1111

12-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
12+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1313
{
1414
var otherMethod = (ValueTypeGetFieldHelperMethodOverride)other;
1515

src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.Sorting.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
66
// Functionality related to determinstic ordering of types
77
partial class InlineArrayType
88
{
9-
protected internal override int ClassCode => 226817075;
9+
protected override int ClassCode => 226817075;
1010

11-
protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
11+
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
1212
{
1313
var otherType = (InlineArrayType)other;
1414
int result = (int)Length - (int)otherType.Length;
@@ -20,29 +20,29 @@ protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer
2020

2121
partial class InlineArrayMethod
2222
{
23-
protected internal override int ClassCode => -1303220581;
23+
protected override int ClassCode => -1303220581;
2424

25-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
25+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
2626
{
2727
var otherMethod = (InlineArrayMethod)other;
2828

2929
int result = _kind - otherMethod._kind;
3030
if (result != 0)
3131
return result;
3232

33-
return comparer.CompareWithinClass(OwningType, otherMethod.OwningType);
33+
return comparer.Compare(OwningType, otherMethod.OwningType);
3434
}
3535
}
3636

3737
partial class InlineArrayField
3838
{
39-
protected internal override int ClassCode => 1542668652;
39+
protected override int ClassCode => 1542668652;
4040

41-
protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
41+
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
4242
{
4343
var otherField = (InlineArrayField)other;
4444

45-
return comparer.CompareWithinClass(OwningType, otherField.OwningType);
45+
return comparer.Compare(OwningType, otherField.OwningType);
4646
}
4747
}
4848
}

src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.Sorting.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace Internal.TypeSystem.Interop
66
// Functionality related to determinstic ordering of types
77
partial class NativeStructType
88
{
9-
protected internal override int ClassCode => -377751537;
9+
protected override int ClassCode => -377751537;
1010

11-
protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
11+
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
1212
{
1313
return comparer.Compare(ManagedStructType, ((NativeStructType)other).ManagedStructType);
1414
}
1515

1616
partial class NativeStructField
1717
{
18-
protected internal override int ClassCode => 1580219745;
18+
protected override int ClassCode => 1580219745;
1919

20-
protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
20+
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
2121
{
2222
return comparer.Compare(_managedField, ((NativeStructField)other)._managedField);
2323
}

src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
66
// Functionality related to determinstic ordering of types
77
partial class PInvokeDelegateWrapper
88
{
9-
protected internal override int ClassCode => -262930217;
9+
protected override int ClassCode => -262930217;
1010

11-
protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
11+
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
1212
{
1313
return comparer.Compare(DelegateType, ((PInvokeDelegateWrapper)other).DelegateType);
1414
}

src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.Sorting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
66
// Functionality related to deterministic ordering of methods
77
partial class PInvokeDelegateWrapperConstructor
88
{
9-
protected internal override int ClassCode => 1000342011;
9+
protected override int ClassCode => 1000342011;
1010

11-
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
11+
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
1212
{
1313
var owningType = (PInvokeDelegateWrapper)OwningType;
1414
var otherOwningType = (PInvokeDelegateWrapper)other.OwningType;

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public SharedGenericsConfiguration GenericsConfig
1919
get;
2020
}
2121

22-
private readonly DelegateFeature _delegateFeatures;
2322
private readonly MetadataFieldLayoutAlgorithm _metadataFieldLayoutAlgorithm = new CompilerMetadataFieldLayoutAlgorithm();
2423
private readonly RuntimeDeterminedFieldLayoutAlgorithm _runtimeDeterminedFieldLayoutAlgorithm = new RuntimeDeterminedFieldLayoutAlgorithm();
2524
private readonly VectorOfTFieldLayoutAlgorithm _vectorOfTFieldLayoutAlgorithm;
@@ -37,7 +36,7 @@ public CompilerTypeSystemContext(TargetDetails details, SharedGenericsMode gener
3736
_vectorOfTFieldLayoutAlgorithm = new VectorOfTFieldLayoutAlgorithm(_metadataFieldLayoutAlgorithm);
3837
_vectorFieldLayoutAlgorithm = new VectorFieldLayoutAlgorithm(_metadataFieldLayoutAlgorithm);
3938

40-
_delegateFeatures = delegateFeatures;
39+
_delegateInfoHashtable = new DelegateInfoHashtable(delegateFeatures);
4140

4241
GenericsConfig = new SharedGenericsConfiguration();
4342
}
@@ -165,11 +164,6 @@ protected virtual IEnumerable<MethodDesc> GetAllMethodsForDelegate(TypeDesc type
165164
yield return m;
166165
}
167166

168-
protected override DelegateInfo CreateDelegateInfo(TypeDesc delegateType)
169-
{
170-
return new DelegateInfo(delegateType, _delegateFeatures);
171-
}
172-
173167
internal DefType GetClosestDefType(TypeDesc type)
174168
{
175169
if (type.IsArray)

src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.DelegateInfo.cs renamed to src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.DelegateInfo.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
using System;
55

66
using Internal.IL;
7+
using Internal.TypeSystem;
78

8-
namespace Internal.TypeSystem
9+
namespace ILCompiler
910
{
10-
public abstract partial class TypeSystemContext
11+
partial class CompilerTypeSystemContext
1112
{
1213
private class DelegateInfoHashtable : LockFreeReaderHashtable<TypeDesc, DelegateInfo>
1314
{
15+
private readonly DelegateFeature _delegateFeatures;
16+
17+
public DelegateInfoHashtable(DelegateFeature features)
18+
=> _delegateFeatures = features;
19+
1420
protected override int GetKeyHashCode(TypeDesc key)
1521
{
1622
return key.GetHashCode();
@@ -29,24 +35,15 @@ protected override bool CompareValueToValue(DelegateInfo value1, DelegateInfo va
2935
}
3036
protected override DelegateInfo CreateValueFromKey(TypeDesc key)
3137
{
32-
return key.Context.CreateDelegateInfo(key);
38+
return new DelegateInfo(key, _delegateFeatures);
3339
}
3440
}
3541

36-
private DelegateInfoHashtable _delegateInfoHashtable = new DelegateInfoHashtable();
42+
private readonly DelegateInfoHashtable _delegateInfoHashtable;
3743

3844
public DelegateInfo GetDelegateInfo(TypeDesc delegateType)
3945
{
4046
return _delegateInfoHashtable.GetOrCreateValue(delegateType);
4147
}
42-
43-
/// <summary>
44-
/// Creates a <see cref="DelegateInfo"/> for a given delegate type.
45-
/// </summary>
46-
protected virtual DelegateInfo CreateDelegateInfo(TypeDesc key)
47-
{
48-
// Type system contexts that support creating delegate infos need to override.
49-
throw new NotSupportedException();
50-
}
5148
}
5249
}

src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.DynamicInvoke.cs renamed to src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.DynamicInvoke.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Internal.IL.Stubs;
5+
using Internal.TypeSystem;
56

67
using Debug = System.Diagnostics.Debug;
78

8-
namespace Internal.TypeSystem
9+
namespace ILCompiler
910
{
10-
partial class TypeSystemContext
11+
partial class CompilerTypeSystemContext
1112
{
1213
private class DynamicInvokeThunkHashtable : LockFreeReaderHashtable<DynamicInvokeMethodSignature, DynamicInvokeMethodThunk>
1314
{
@@ -17,7 +18,7 @@ private class DynamicInvokeThunkHashtable : LockFreeReaderHashtable<DynamicInvok
1718
protected override int GetValueHashCode(DynamicInvokeMethodThunk value) => value.TargetSignature.GetHashCode();
1819
protected override DynamicInvokeMethodThunk CreateValueFromKey(DynamicInvokeMethodSignature key)
1920
{
20-
return new DynamicInvokeMethodThunk(key.Context.GeneratedAssembly.GetGlobalModuleType(), key);
21+
return new DynamicInvokeMethodThunk(((CompilerTypeSystemContext)key.Context).GeneratedAssembly.GetGlobalModuleType(), key);
2122
}
2223
}
2324
DynamicInvokeThunkHashtable _dynamicInvokeThunks = new DynamicInvokeThunkHashtable();

0 commit comments

Comments
 (0)