Skip to content

Move things from ILCompiler.TypeSystem to ILCompiler.Compiler #63280

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
Jan 3, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of methods
partial class CalliMarshallingMethodThunk
{
protected internal override int ClassCode => 1594107963;
protected override int ClassCode => 1594107963;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (CalliMarshallingMethodThunk)other;
return comparer.Compare(_targetSignature, otherMethod._targetSignature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of methods
partial class DelegateMarshallingMethodThunk
{
protected internal override int ClassCode => 1018037605;
protected override int ClassCode => 1018037605;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (DelegateMarshallingMethodThunk)other;
int result = (int)Kind - (int)otherMethod.Kind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of types
partial class DelegateThunk
{
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (DelegateThunk)other;
return comparer.Compare(_delegateInfo.Type, otherMethod._delegateInfo.Type);
Expand All @@ -17,39 +17,39 @@ protected internal override int CompareToImpl(MethodDesc other, TypeSystemCompar

partial class DelegateInvokeOpenStaticThunk
{
protected internal override int ClassCode => 386356101;
protected override int ClassCode => 386356101;
}

public sealed partial class DelegateInvokeOpenInstanceThunk
{
protected internal override int ClassCode => -1787190244;
protected override int ClassCode => -1787190244;
}

partial class DelegateInvokeClosedStaticThunk
{
protected internal override int ClassCode => 28195375;
protected override int ClassCode => 28195375;
}

partial class DelegateInvokeMulticastThunk
{
protected internal override int ClassCode => 639863471;
protected override int ClassCode => 639863471;
}

partial class DelegateInvokeInstanceClosedOverGenericMethodThunk
{
protected internal override int ClassCode => -354480633;
protected override int ClassCode => -354480633;
}

partial class DelegateInvokeObjectArrayThunk
{
protected internal override int ClassCode => 1993292344;
protected override int ClassCode => 1993292344;
}

partial class DelegateGetThunkMethodOverride
{
protected internal override int ClassCode => -321263379;
protected override int ClassCode => -321263379;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (DelegateGetThunkMethodOverride)other;
return comparer.Compare(_delegateInfo.Type, otherMethod._delegateInfo.Type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ public override MethodIL EmitIL()
Debug.Assert(_delegateInfo.Thunks[i] == null);

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

if (thunk.HasInstantiation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Internal.IL.Stubs
// Functionality related to determinstic ordering of types
partial class DynamicInvokeMethodThunk
{
protected internal override int ClassCode => -1980933220;
protected override int ClassCode => -1980933220;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
return CompareTo((DynamicInvokeMethodThunk)other);
}
Expand Down Expand Up @@ -51,9 +51,9 @@ private int CompareTo(DynamicInvokeMethodThunk otherMethod)

partial class DynamicInvokeThunkGenericParameter
{
protected internal override int ClassCode => -234393261;
protected override int ClassCode => -234393261;

protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
{
var otherType = (DynamicInvokeThunkGenericParameter)other;
int result = Index - otherType.Index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of types
partial class EnumGetHashCodeThunk
{
protected internal override int ClassCode => 261739662;
protected override int ClassCode => 261739662;

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

partial class EnumEqualsThunk
{
protected internal override int ClassCode => -1774524780;
protected override int ClassCode => -1774524780;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (EnumEqualsThunk)other;
return comparer.Compare(_owningType, otherMethod._owningType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of types
partial class ForwardDelegateCreationThunk
{
protected internal override int ClassCode => 1026039617;
protected override int ClassCode => 1026039617;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (ForwardDelegateCreationThunk)other;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Internal.IL.Stubs
{
partial class PInvokeLazyFixupField
{
protected internal override int ClassCode => -1784477702;
protected override int ClassCode => -1784477702;

protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
{
return comparer.Compare(_targetMethod, ((PInvokeLazyFixupField)other)._targetMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Internal.IL.Stubs
// Functionality related to deterministic ordering of types
partial class StructMarshallingThunk
{
protected internal override int ClassCode => 340834018;
protected override int ClassCode => 340834018;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (StructMarshallingThunk)other;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Internal.IL.Stubs
{
partial class ValueTypeGetFieldHelperMethodOverride
{
protected internal override int ClassCode => 2036839816;
protected override int ClassCode => 2036839816;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (ValueTypeGetFieldHelperMethodOverride)other;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
// Functionality related to determinstic ordering of types
partial class InlineArrayType
{
protected internal override int ClassCode => 226817075;
protected override int ClassCode => 226817075;

protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
{
var otherType = (InlineArrayType)other;
int result = (int)Length - (int)otherType.Length;
Expand All @@ -20,29 +20,29 @@ protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer

partial class InlineArrayMethod
{
protected internal override int ClassCode => -1303220581;
protected override int ClassCode => -1303220581;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (InlineArrayMethod)other;

int result = _kind - otherMethod._kind;
if (result != 0)
return result;

return comparer.CompareWithinClass(OwningType, otherMethod.OwningType);
return comparer.Compare(OwningType, otherMethod.OwningType);
}
}

partial class InlineArrayField
{
protected internal override int ClassCode => 1542668652;
protected override int ClassCode => 1542668652;

protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
{
var otherField = (InlineArrayField)other;

return comparer.CompareWithinClass(OwningType, otherField.OwningType);
return comparer.Compare(OwningType, otherField.OwningType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ namespace Internal.TypeSystem.Interop
// Functionality related to determinstic ordering of types
partial class NativeStructType
{
protected internal override int ClassCode => -377751537;
protected override int ClassCode => -377751537;

protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
{
return comparer.Compare(ManagedStructType, ((NativeStructType)other).ManagedStructType);
}

partial class NativeStructField
{
protected internal override int ClassCode => 1580219745;
protected override int ClassCode => 1580219745;

protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
{
return comparer.Compare(_managedField, ((NativeStructField)other)._managedField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
// Functionality related to determinstic ordering of types
partial class PInvokeDelegateWrapper
{
protected internal override int ClassCode => -262930217;
protected override int ClassCode => -262930217;

protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
{
return comparer.Compare(DelegateType, ((PInvokeDelegateWrapper)other).DelegateType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Internal.TypeSystem.Interop
// Functionality related to deterministic ordering of methods
partial class PInvokeDelegateWrapperConstructor
{
protected internal override int ClassCode => 1000342011;
protected override int ClassCode => 1000342011;

protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var owningType = (PInvokeDelegateWrapper)OwningType;
var otherOwningType = (PInvokeDelegateWrapper)other.OwningType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public SharedGenericsConfiguration GenericsConfig
get;
}

private readonly DelegateFeature _delegateFeatures;
private readonly MetadataFieldLayoutAlgorithm _metadataFieldLayoutAlgorithm = new CompilerMetadataFieldLayoutAlgorithm();
private readonly RuntimeDeterminedFieldLayoutAlgorithm _runtimeDeterminedFieldLayoutAlgorithm = new RuntimeDeterminedFieldLayoutAlgorithm();
private readonly VectorOfTFieldLayoutAlgorithm _vectorOfTFieldLayoutAlgorithm;
Expand All @@ -37,7 +36,7 @@ public CompilerTypeSystemContext(TargetDetails details, SharedGenericsMode gener
_vectorOfTFieldLayoutAlgorithm = new VectorOfTFieldLayoutAlgorithm(_metadataFieldLayoutAlgorithm);
_vectorFieldLayoutAlgorithm = new VectorFieldLayoutAlgorithm(_metadataFieldLayoutAlgorithm);

_delegateFeatures = delegateFeatures;
_delegateInfoHashtable = new DelegateInfoHashtable(delegateFeatures);

GenericsConfig = new SharedGenericsConfiguration();
}
Expand Down Expand Up @@ -165,11 +164,6 @@ protected virtual IEnumerable<MethodDesc> GetAllMethodsForDelegate(TypeDesc type
yield return m;
}

protected override DelegateInfo CreateDelegateInfo(TypeDesc delegateType)
{
return new DelegateInfo(delegateType, _delegateFeatures);
}

internal DefType GetClosestDefType(TypeDesc type)
{
if (type.IsArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
using System;

using Internal.IL;
using Internal.TypeSystem;

namespace Internal.TypeSystem
namespace ILCompiler
{
public abstract partial class TypeSystemContext
partial class CompilerTypeSystemContext
{
private class DelegateInfoHashtable : LockFreeReaderHashtable<TypeDesc, DelegateInfo>
{
private readonly DelegateFeature _delegateFeatures;

public DelegateInfoHashtable(DelegateFeature features)
=> _delegateFeatures = features;

protected override int GetKeyHashCode(TypeDesc key)
{
return key.GetHashCode();
Expand All @@ -29,24 +35,15 @@ protected override bool CompareValueToValue(DelegateInfo value1, DelegateInfo va
}
protected override DelegateInfo CreateValueFromKey(TypeDesc key)
{
return key.Context.CreateDelegateInfo(key);
return new DelegateInfo(key, _delegateFeatures);
}
}

private DelegateInfoHashtable _delegateInfoHashtable = new DelegateInfoHashtable();
private readonly DelegateInfoHashtable _delegateInfoHashtable;

public DelegateInfo GetDelegateInfo(TypeDesc delegateType)
{
return _delegateInfoHashtable.GetOrCreateValue(delegateType);
}

/// <summary>
/// Creates a <see cref="DelegateInfo"/> for a given delegate type.
/// </summary>
protected virtual DelegateInfo CreateDelegateInfo(TypeDesc key)
{
// Type system contexts that support creating delegate infos need to override.
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.IL.Stubs;
using Internal.TypeSystem;

using Debug = System.Diagnostics.Debug;

namespace Internal.TypeSystem
namespace ILCompiler
{
partial class TypeSystemContext
partial class CompilerTypeSystemContext
{
private class DynamicInvokeThunkHashtable : LockFreeReaderHashtable<DynamicInvokeMethodSignature, DynamicInvokeMethodThunk>
{
Expand All @@ -17,7 +18,7 @@ private class DynamicInvokeThunkHashtable : LockFreeReaderHashtable<DynamicInvok
protected override int GetValueHashCode(DynamicInvokeMethodThunk value) => value.TargetSignature.GetHashCode();
protected override DynamicInvokeMethodThunk CreateValueFromKey(DynamicInvokeMethodSignature key)
{
return new DynamicInvokeMethodThunk(key.Context.GeneratedAssembly.GetGlobalModuleType(), key);
return new DynamicInvokeMethodThunk(((CompilerTypeSystemContext)key.Context).GeneratedAssembly.GetGlobalModuleType(), key);
}
}
DynamicInvokeThunkHashtable _dynamicInvokeThunks = new DynamicInvokeThunkHashtable();
Expand Down
Loading