Skip to content

Commit 89cfb9f

Browse files
authored
More work on generics in interpreter and type system (#3199)
1 parent a9d6c38 commit 89cfb9f

File tree

31 files changed

+1544
-553
lines changed

31 files changed

+1544
-553
lines changed

CMake/Modules/FindNF_CoreCLR.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ set(NF_CoreCLR_SRCS
106106
corlib_native_System_Number.cpp
107107
corlib_native_System_Object.cpp
108108
corlib_native_System_Random.cpp
109+
corlib_native_System_ReadOnlySpan_1.cpp
109110
corlib_native_System_Reflection_Binder.cpp
110111
corlib_native_System_Reflection_MemberInfo.cpp
111112
corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp
112113
corlib_native_System_Runtime_Remoting_RemotingServices.cpp
113114
corlib_native_System_String.cpp
115+
corlib_native_System_Span_1.cpp
114116
corlib_native_System_Threading_AutoResetEvent.cpp
115117
corlib_native_System_Threading_Interlocked.cpp
116118
corlib_native_System_Threading_ManualResetEvent.cpp

src/CLR/CorLib/CorLib.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<ClCompile Include="corlib_native_System_Number.cpp" />
4949
<ClCompile Include="corlib_native_System_Object.cpp" />
5050
<ClCompile Include="corlib_native_System_Random.cpp" />
51+
<ClCompile Include="corlib_native_System_ReadOnlySpan_1.cpp" />
5152
<ClCompile Include="corlib_native_System_Reflection_Assembly.cpp" />
5253
<ClCompile Include="corlib_native_System_Reflection_Binder.cpp" />
5354
<ClCompile Include="corlib_native_System_Reflection_ConstructorInfo.cpp" />
@@ -60,6 +61,7 @@
6061
<ClCompile Include="corlib_native_System_RuntimeType.cpp" />
6162
<ClCompile Include="corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp" />
6263
<ClCompile Include="corlib_native_System_Runtime_Remoting_RemotingServices.cpp" />
64+
<ClCompile Include="corlib_native_System_Span_1.cpp" />
6365
<ClCompile Include="corlib_native_System_String.cpp" />
6466
<ClCompile Include="corlib_native_System_Threading_AutoResetEvent.cpp" />
6567
<ClCompile Include="corlib_native_System_Threading_Interlocked.cpp" />
@@ -208,4 +210,4 @@
208210
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
209211
<ImportGroup Label="ExtensionTargets">
210212
</ImportGroup>
211-
</Project>
213+
</Project>

src/CLR/CorLib/CorLib.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,11 @@
173173
<ClCompile Include="corlib_native_System_Threading_SpinWait.cpp">
174174
<Filter>Source Files</Filter>
175175
</ClCompile>
176+
<ClCompile Include="corlib_native_System_Span_1.cpp">
177+
<Filter>Source Files</Filter>
178+
</ClCompile>
179+
<ClCompile Include="corlib_native_System_ReadOnlySpan_1.cpp">
180+
<Filter>Source Files</Filter>
181+
</ClCompile>
176182
</ItemGroup>
177183
</Project>

src/CLR/CorLib/corlib_native.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
5656
Library_corlib_native_System_Reflection_FieldInfo::GetCustomAttributesNative___SZARRAY_OBJECT__BOOLEAN,
5757
nullptr,
5858
Library_corlib_native_System_Type::get_DeclaringType___SystemType,
59+
Library_corlib_native_System_Type::GetGenericTypeDefinition___SystemType,
5960
nullptr,
6061
nullptr,
6162
nullptr,
@@ -69,6 +70,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
6970
nullptr,
7071
Library_corlib_native_System_Type::IsInstanceOfType___BOOLEAN__OBJECT,
7172
nullptr,
73+
Library_corlib_native_System_Type::GetGenericArguments___SZARRAY_SystemType,
7274
Library_corlib_native_System_Type::InvokeMember___OBJECT__STRING__SystemReflectionBindingFlags__SystemReflectionBinder__OBJECT__SZARRAY_OBJECT,
7375
Library_corlib_native_System_Type::GetConstructor___SystemReflectionConstructorInfo__SZARRAY_SystemType,
7476
Library_corlib_native_System_Type::GetConstructors___SZARRAY_SystemReflectionConstructorInfo,
@@ -86,6 +88,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
8688
Library_corlib_native_System_Type::get_IsEnum___BOOLEAN,
8789
Library_corlib_native_System_Type::get_IsSerializable___BOOLEAN,
8890
Library_corlib_native_System_Type::get_IsArray___BOOLEAN,
91+
Library_corlib_native_System_Type::get_IsGenericType___BOOLEAN,
92+
Library_corlib_native_System_Type::get_IsGenericTypeDefinition___BOOLEAN,
8993
nullptr,
9094
nullptr,
9195
Library_corlib_native_System_Type::GetTypeInternal___STATIC__SystemType__STRING__STRING__BOOLEAN__SZARRAY_I4,
@@ -255,6 +259,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
255259
nullptr,
256260
nullptr,
257261
nullptr,
262+
nullptr,
258263
Library_corlib_native_System_Array::TrySzIndexOf___STATIC__BOOLEAN__SystemArray__I4__I4__OBJECT__BYREF_I4,
259264
nullptr,
260265
nullptr,
@@ -269,6 +274,10 @@ static const CLR_RT_MethodHandler method_lookup[] =
269274
nullptr,
270275
nullptr,
271276
nullptr,
277+
nullptr,
278+
nullptr,
279+
nullptr,
280+
nullptr,
272281
Library_corlib_native_System_BitConverter::get_IsLittleEndian___STATIC__BOOLEAN,
273282
Library_corlib_native_System_BitConverter::DoubleToInt64Bits___STATIC__I8__R8,
274283
Library_corlib_native_System_BitConverter::GetBytes___STATIC__SZARRAY_U1__BOOLEAN,
@@ -524,6 +533,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
524533
Library_corlib_native_System_Reflection_Assembly::LoadInternal___STATIC__SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4,
525534
Library_corlib_native_System_Reflection_Assembly::Load___STATIC__SystemReflectionAssembly__SZARRAY_U1,
526535
nullptr,
536+
nullptr,
527537
Library_corlib_native_System_Enum::HasFlag___BOOLEAN__SystemEnum,
528538
nullptr,
529539
nullptr,
@@ -625,6 +635,18 @@ static const CLR_RT_MethodHandler method_lookup[] =
625635
nullptr,
626636
nullptr,
627637
nullptr,
638+
nullptr,
639+
nullptr,
640+
nullptr,
641+
nullptr,
642+
nullptr,
643+
nullptr,
644+
nullptr,
645+
nullptr,
646+
nullptr,
647+
nullptr,
648+
nullptr,
649+
nullptr,
628650
Library_corlib_native_System_Number::FormatNative___STATIC__STRING__OBJECT__BOOLEAN__STRING__STRING__STRING__STRING__SZARRAY_I4,
629651
nullptr,
630652
nullptr,
@@ -645,6 +667,16 @@ static const CLR_RT_MethodHandler method_lookup[] =
645667
nullptr,
646668
nullptr,
647669
nullptr,
670+
Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4,
671+
nullptr,
672+
nullptr,
673+
nullptr,
674+
nullptr,
675+
nullptr,
676+
nullptr,
677+
nullptr,
678+
nullptr,
679+
nullptr,
648680
Library_corlib_native_System_Reflection_ConstructorInfo::GetCustomAttributes___SZARRAY_OBJECT__BOOLEAN,
649681
Library_corlib_native_System_Reflection_ConstructorInfo::Invoke___OBJECT__SZARRAY_OBJECT,
650682
nullptr,
@@ -691,10 +723,12 @@ static const CLR_RT_MethodHandler method_lookup[] =
691723
nullptr,
692724
nullptr,
693725
nullptr,
726+
nullptr,
694727
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::InitializeArray___STATIC__VOID__SystemArray__SystemRuntimeFieldHandle,
695728
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::GetObjectValue___STATIC__OBJECT__OBJECT,
696729
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::RunClassConstructor___STATIC__VOID__SystemRuntimeTypeHandle,
697730
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::get_OffsetToStringData___STATIC__I4,
731+
nullptr,
698732
Library_corlib_native_System_Runtime_Remoting_RemotingServices::IsTransparentProxy___STATIC__BOOLEAN__OBJECT,
699733
nullptr,
700734
nullptr,
@@ -734,6 +768,13 @@ static const CLR_RT_MethodHandler method_lookup[] =
734768
nullptr,
735769
nullptr,
736770
nullptr,
771+
Library_corlib_native_System_Span_1::CopyTo___VOID__SystemSpan_1,
772+
nullptr,
773+
nullptr,
774+
nullptr,
775+
Library_corlib_native_System_Span_1::NativeSpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4,
776+
nullptr,
777+
nullptr,
737778
nullptr,
738779
nullptr,
739780
nullptr,
@@ -1507,7 +1548,7 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =
15071548

15081549
#if (NANOCLR_REFLECTION == TRUE)
15091550

1510-
0x50BF350D,
1551+
0x17B85422,
15111552

15121553
#elif (NANOCLR_REFLECTION == FALSE)
15131554

src/CLR/CorLib/corlib_native.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ struct Library_corlib_native_System_Reflection_FieldInfo
9191
struct Library_corlib_native_System_Type
9292
{
9393
NANOCLR_NATIVE_DECLARE(get_DeclaringType___SystemType);
94+
NANOCLR_NATIVE_DECLARE(GetGenericTypeDefinition___SystemType);
9495
NANOCLR_NATIVE_DECLARE(GetMethod___SystemReflectionMethodInfo__STRING__SystemReflectionBindingFlags);
9596
NANOCLR_NATIVE_DECLARE(IsInstanceOfType___BOOLEAN__OBJECT);
97+
NANOCLR_NATIVE_DECLARE(GetGenericArguments___SZARRAY_SystemType);
9698
NANOCLR_NATIVE_DECLARE(
9799
InvokeMember___OBJECT__STRING__SystemReflectionBindingFlags__SystemReflectionBinder__OBJECT__SZARRAY_OBJECT);
98100
NANOCLR_NATIVE_DECLARE(GetConstructor___SystemReflectionConstructorInfo__SZARRAY_SystemType);
@@ -108,6 +110,8 @@ struct Library_corlib_native_System_Type
108110
NANOCLR_NATIVE_DECLARE(get_IsEnum___BOOLEAN);
109111
NANOCLR_NATIVE_DECLARE(get_IsSerializable___BOOLEAN);
110112
NANOCLR_NATIVE_DECLARE(get_IsArray___BOOLEAN);
113+
NANOCLR_NATIVE_DECLARE(get_IsGenericType___BOOLEAN);
114+
NANOCLR_NATIVE_DECLARE(get_IsGenericTypeDefinition___BOOLEAN);
111115
NANOCLR_NATIVE_DECLARE(GetTypeInternal___STATIC__SystemType__STRING__STRING__BOOLEAN__SZARRAY_I4);
112116
NANOCLR_NATIVE_DECLARE(GetTypeFromHandle___STATIC__SystemType__SystemRuntimeTypeHandle);
113117

@@ -697,6 +701,14 @@ struct Library_corlib_native_System_MulticastDelegate
697701
//--//
698702
};
699703

704+
struct Library_corlib_native_System_Nullable_1
705+
{
706+
static const int FIELD__hasValue = 1;
707+
static const int FIELD__value = 2;
708+
709+
//--//
710+
};
711+
700712
struct Library_corlib_native_System_Number
701713
{
702714
NANOCLR_NATIVE_DECLARE(FormatNative___STATIC__STRING__OBJECT__BOOLEAN__STRING__STRING__STRING__STRING__SZARRAY_I4);
@@ -764,6 +776,20 @@ struct Library_corlib_native_System_Random
764776
static HRESULT GetRandom(CLR_RT_StackFrame &stack, CLR_RT_Random *&rand, bool create = false);
765777
};
766778

779+
#if (NANOCLR_REFLECTION == TRUE)
780+
781+
struct Library_corlib_native_System_ReadOnlySpan_1
782+
{
783+
static const int FIELD___array = 1;
784+
static const int FIELD___length = 2;
785+
786+
NANOCLR_NATIVE_DECLARE(NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);
787+
788+
//--//
789+
};
790+
791+
#endif // NANOCLR_REFLECTION
792+
767793
struct Library_corlib_native_System_Reflection_AssemblyName
768794
{
769795
static const int FIELD___assembly = 1;
@@ -910,6 +936,23 @@ struct Library_corlib_native_System_Single
910936
//--//
911937
};
912938

939+
#if (NANOCLR_REFLECTION == TRUE)
940+
941+
struct Library_corlib_native_System_Span_1
942+
{
943+
static const int FIELD___array = 1;
944+
static const int FIELD___length = 2;
945+
946+
NANOCLR_NATIVE_DECLARE(CopyTo___VOID__SystemSpan_1);
947+
NANOCLR_NATIVE_DECLARE(NativeSpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);
948+
949+
//--//
950+
};
951+
952+
#endif // NANOCLR_REFLECTION
953+
954+
#if (NANOCLR_REFLECTION != TRUE)
955+
913956
struct Library_corlib_native_System_SpanByte
914957
{
915958
static const int FIELD___array = 1;
@@ -919,6 +962,8 @@ struct Library_corlib_native_System_SpanByte
919962
//--//
920963
};
921964

965+
#endif // NANOCLR_REFLECTION
966+
922967
struct Library_corlib_native_System_Threading_AutoResetEvent
923968
{
924969
NANOCLR_NATIVE_DECLARE(_ctor___VOID__BOOLEAN);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
#include "CorLib.h"
8+
9+
HRESULT Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4(
10+
CLR_RT_StackFrame &stack)
11+
{
12+
NANOCLR_HEADER();
13+
14+
int32_t start;
15+
int32_t length;
16+
17+
CLR_RT_TypeDescriptor descDst{};
18+
CLR_RT_TypeDef_Index sourceType{};
19+
CLR_RT_HeapBlock_Array *destinationArray;
20+
CLR_RT_HeapBlock_Array *sourceArray = stack.Arg1().DereferenceArray();
21+
CLR_RT_HeapBlock *thisSpan = stack.This();
22+
23+
// get working values
24+
start = stack.Arg2().NumericByRefConst().s4;
25+
length = stack.Arg3().NumericByRefConst().s4;
26+
27+
{
28+
// get type of the source array
29+
NANOCLR_CHECK_HRESULT(descDst.InitializeFromObject(*sourceArray));
30+
descDst.GetElementType(descDst);
31+
32+
sourceType.data = descDst.m_handlerCls.data;
33+
34+
CLR_RT_HeapBlock &refArray = thisSpan[FIELD___array];
35+
CLR_RT_HeapBlock_Array::CreateInstance(refArray, length, sourceType);
36+
37+
// get pointer to the array
38+
destinationArray = thisSpan[FIELD___array].DereferenceArray();
39+
40+
// protect from GC
41+
CLR_RT_ProtectFromGC gc1(*sourceArray);
42+
CLR_RT_ProtectFromGC gc2(refArray);
43+
44+
// copy array
45+
CLR_RT_HeapBlock_Array::Copy(sourceArray, start, destinationArray, 0, length);
46+
47+
// set length
48+
thisSpan[FIELD___length].NumericByRef().s4 = length;
49+
}
50+
51+
NANOCLR_NOCLEANUP();
52+
}

0 commit comments

Comments
 (0)