Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
173b84d
Add reflection introspection support for function pointers
steveharter May 31, 2022
e546ee2
Fix compiler issue; test MLC to NetFramework
steveharter Jan 23, 2023
36e07d6
Fix compile issue; prep for review
steveharter Jan 23, 2023
e755c1c
Compile issue with MLC under certain conditions
steveharter Jan 23, 2023
b3b64ff
compile issue cont'd; lazy load mods on root
steveharter Jan 23, 2023
3aef789
compile issues cont'd; prepare for review
steveharter Jan 24, 2023
f76c75d
Remove Node back reference; fix edge case test failure
steveharter Jan 24, 2023
73b15b3
Increase test coverage; add missing recursive check
steveharter Jan 24, 2023
1361142
Various feedback; support mods on generic type parameters
steveharter Jan 26, 2023
520a3f5
Merge branch 'main' of https://github.com/steveharter/runtime into Fc…
steveharter Jan 26, 2023
64a987e
Fix MLC edge case; Native AOT test enable\disable
steveharter Jan 26, 2023
5f8a81e
Native AOT test enable\disable; add a generic test
steveharter Jan 26, 2023
2df9d2b
Native AOT test enable\disable; fix missing overload
steveharter Jan 26, 2023
0a6ff32
Add TODOs based on review discussion; MLC field optimization
steveharter Jan 27, 2023
784df92
Merge branch 'main' into FcnPtr
jkotas Feb 1, 2023
8c06d3c
Replace nested signature indices by TypeSignature type
jkotas Jan 31, 2023
f40e506
Move tests into separate classes; other misc non-functional
steveharter Feb 13, 2023
4610e93
Throw NSE for modified type members than may return an unmodified type
steveharter Feb 14, 2023
ca45bd8
Merge branch 'main' of https://github.com/dotnet/runtime into FcnPtr
steveharter Feb 14, 2023
70529f0
Throw NSE on modified type Equals() and GetHashCode()
steveharter Feb 15, 2023
9770a2d
Fix tests for WASI
steveharter Feb 15, 2023
14a9007
Remove unnecessary high overhead tests
steveharter Feb 16, 2023
69ccd75
Merge branch 'main' of https://github.com/dotnet/runtime into FcnPtr
steveharter Feb 16, 2023
f76331c
Fix merge error
steveharter Feb 16, 2023
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
Prev Previous commit
Next Next commit
Replace nested signature indices by TypeSignature type
  • Loading branch information
jkotas committed Feb 1, 2023
commit 8c06d3c908b5e8cdad23d05c780a30f42058a155
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
<Compile Include="$(BclSourcesRoot)\System\Reflection\Metadata\MetadataUpdater.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodInvoker.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ModifiedFunctionPointerType.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ModifiedType.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RtFieldInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeAssembly.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,31 @@ namespace System.Reflection
{
internal partial class ModifiedType
{
/// <summary>
/// Called from FieldInfo, PropertyInfo and ParameterInfo to create a modified type tree.
/// </summary>
public static ModifiedType CreateRoot(
Type unmodifiedType,
object? signatureProvider,
int rootSignatureParameterIndex)
internal struct TypeSignature
{
int nestedSignatureIndex = -1;
return Create(
unmodifiedType,
signatureProvider,
rootSignatureParameterIndex,
ref nestedSignatureIndex,
nestedSignatureParameterIndex: -1,
isRoot: true);
internal Signature? _signature;
internal int _offset;
}

private Type[] GetCustomModifiers(bool required)
{
Type[] modifiers = EmptyTypes;
Signature? signature = GetSignature();
if (signature is not null)
internal Type GetTypeParameter(Type unmodifiedType, int index) =>
Create(unmodifiedType, new TypeSignature()
{
if (IsRoot)
{
// For a root node, which is the original field\parameter\property Type, get the root-level modifiers.
modifiers = signature.GetCustomModifiers(RootSignatureParameterIndex, required);
}
else if (NestedSignatureParameterIndex >= 0)
{
modifiers = signature.GetCustomModifiers(RootSignatureParameterIndex, required, NestedSignatureIndex, NestedSignatureParameterIndex);
}
}
_signature = _typeSignature._signature,
_offset = _typeSignature._signature?.GetTypeParameterFromOffset(_typeSignature._offset, index) ?? 0
});

return modifiers;
}
internal SignatureCallingConvention GetCallingConventionFromFunctionPointer() =>
_typeSignature._signature?.GetCallingConventionFromFunctionPointerAtOffset(_typeSignature._offset) ?? default;

internal Signature? GetSignature()
{
return (Signature?)SignatureProvider; // Signature is a CoreClr-specific class.
}
internal static Type Create(Type unmodifiedType, Signature? signature, int parameterIndex = 0) =>
Create(unmodifiedType, new TypeSignature()
{
_signature = signature,
_offset = signature?.GetParameterOffset(parameterIndex) ?? 0
});

private Type[] GetCustomModifiers(bool required) =>
(_typeSignature._signature != null) ?
_typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : Type.EmptyTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public override Type[] GetOptionalCustomModifiers()
internal Signature GetSignature() => new Signature(this, m_declaringType);

public override Type GetModifiedFieldType() =>
ModifiedType.CreateRoot(FieldType, GetSignature(), rootSignatureParameterIndex: 1);
ModifiedType.Create(FieldType, GetSignature());
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,7 @@ public override Type[] GetOptionalCustomModifiers()
}

public override Type GetModifiedParameterType() =>
ModifiedType.CreateRoot(
unmodifiedType: ParameterType,
m_signature,
rootSignatureParameterIndex: PositionImpl + 1);
ModifiedType.Create(unmodifiedType: ParameterType, m_signature, parameterIndex: PositionImpl + 1);

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ public override Type[] GetOptionalCustomModifiers()
return Signature.GetCustomModifiers(0, false);
}

public override Type GetModifiedPropertyType() => ModifiedType.CreateRoot(
PropertyType,
Signature,
rootSignatureParameterIndex: 0);
public override Type GetModifiedPropertyType() => ModifiedType.Create(PropertyType, Signature);

internal object GetConstantValue(bool raw)
{
Expand Down
12 changes: 9 additions & 3 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,14 +1634,20 @@ public Signature(void* pCorSig, int cCorSig, RuntimeType declaringType)
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool CompareSig(Signature sig1, Signature sig2);

internal Type[] GetCustomModifiers(int parameterIndex, bool required) =>
GetCustomModifiersAtOffset(GetParameterOffset(parameterIndex), required);

[MethodImpl(MethodImplOptions.InternalCall)]
internal extern int GetParameterOffset(int parameterIndex);

[MethodImpl(MethodImplOptions.InternalCall)]
internal extern Type[] GetCustomModifiers(int rootSignatureParameterIndex, bool required, int nestedSignatureIndex = -1, int nestedSignatureParameterIndex = -1);
internal extern int GetTypeParameterFromOffset(int offset, int index);

[MethodImpl(MethodImplOptions.InternalCall)]
internal extern byte GetCallingConventionFromFunctionPointer(int rootSignatureParameterIndex, int nestedSignatureIndex);
internal extern SignatureCallingConvention GetCallingConventionFromFunctionPointerAtOffset(int offset);

[MethodImpl(MethodImplOptions.InternalCall)]
internal extern bool IsUnmanagedFunctionPointer();
internal extern Type[] GetCustomModifiersAtOffset(int offset, bool required);
#endregion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,7 @@ public override Type[] GetFunctionPointerParameterTypes()
return EmptyTypes;
}

return ModifiedType.CloneArray(parameters, 1);
return parameters.AsSpan(1).ToArray();
}

public override Type GetFunctionPointerReturnType()
Expand Down
13 changes: 1 addition & 12 deletions src/coreclr/inc/sigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,27 +713,16 @@ class SigParser
// the arguments.
//------------------------------------------------------------------------
__checkReturn
HRESULT SkipMethodHeaderSignature(uint32_t *pcArgs);
HRESULT SkipMethodHeaderSignature(uint32_t *pcArgs, bool skipReturnType = true);

//------------------------------------------------------------------------
// Skip a sub signature (as immediately follows an ELEMENT_TYPE_FNPTR).
//------------------------------------------------------------------------
__checkReturn
HRESULT SkipSignature();

private:

__checkReturn
HRESULT MoveToSignature(uint32_t indexToFind, uint32_t* pCurrentIndex, bool* pIsFinished, CorElementType* pSignatureType);

public:

//------------------------------------------------------------------------
// Move to the specified signature
//------------------------------------------------------------------------
__checkReturn
HRESULT MoveToSignature(uint32_t indexToFind, CorElementType* pSignatureType);

//------------------------------------------------------------------------
// Return pointer
// PLEASE DON'T USE THIS.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
Expand Down Expand Up @@ -154,7 +154,6 @@
<Compile Include="System\Reflection\Metadata\AssemblyExtensions.cs" />
<Compile Include="System\Reflection\Metadata\MetadataUpdater.cs" />
<Compile Include="System\Reflection\ModifiedType.NativeAot.cs" />
<Compile Include="System\Reflection\ModifiedFunctionPointerType.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\CriticalHandle.NativeAot.cs" />
<Compile Include="System\Activator.NativeAot.cs" />
<Compile Include="System\AppContext.NativeAot.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ namespace System.Reflection
{
internal partial class ModifiedType
{
internal struct TypeSignature
{
}

#pragma warning disable IDE0060
internal Type GetTypeParameter(Type unmodifiedType, int index) => throw new NotSupportedException();

internal SignatureCallingConvention GetCallingConventionFromFunctionPointer() => throw new NotSupportedException();

private Type[] GetCustomModifiers(bool required) => throw new NotSupportedException();
#pragma warning restore IDE0060
}
Expand Down
Loading