Skip to content

Commit 5bba5aa

Browse files
authored
Removing ArrayTypeDesc (dotnet#1201)
* Reduce use of ArrayTpeDesc, somewhat * remove `AsArray`. Fewer uses of ArrayTypeDesc * remove `IsArrayType` * remove AssertArrayTypeDescLoaded * normalized use of GetElementType vs GetTypeParam vs GetArrayElementTypeHandle * removed GetMethodTableOfElementType * HasTypeParam and GetTypeParam should work for TypeHandle when array is not a TypeDesc * Some cleanup of `IsTypeDesc` use. * Removed `ArrayTypeDesc` * a few fixes * another fix * dealt with TODOs * couple fixes from reviewing code * PR feedback: Removed `CORINFO_HELP_NEWARR_1_R2R_DIRECT` Folded a `cmp` in x86 array Address. Removed` METHOD__BUFFER__BLOCKCOPY` from mscorlib.h `GetMethodTableOfRootTypeParam` `GetRootTypeParam` Straightened `Object::GetTypeHandle` `AsMethodTable` changes from PR feedback * Removed `ELEMENT_TYPE_NATIVE_ARRAY_TEMPLATE_ZAPSIG` * `TypeDesc` is ok in `canInlineTypeCheckWithObjectVTable` * trivial `AsMethodTable` changes * `GetVarTypeForTypeHandle` should throw `unsupported` on TypeDescs * not digging for the root element type in `GetGCSafeTypeHandleIfPossible` * Last PR feedback * Fix `TypeInfoTests.Guid()`
1 parent 680487f commit 5bba5aa

81 files changed

Lines changed: 488 additions & 1404 deletions

Some content is hidden

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

src/coreclr/src/classlibnative/bcltype/arraynative.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void ArrayNative::BoxEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BASEA
368368
_ASSERTE(!destTH.GetMethodTable()->IsValueType());
369369

370370
// Get method table of type we're copying from - we need to allocate objects of that type.
371-
MethodTable * pSrcMT = srcTH.GetMethodTable();
371+
MethodTable * pSrcMT = srcTH.AsMethodTable();
372372
PREFIX_ASSUME(pSrcMT != NULL);
373373

374374
if (!pSrcMT->IsClassInited())
@@ -437,7 +437,7 @@ void ArrayNative::UnBoxEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BAS
437437
_ASSERTE(destTH.GetSignatureCorElementType() == ELEMENT_TYPE_CLASS || destTH.GetSignatureCorElementType() == ELEMENT_TYPE_VALUETYPE || CorTypeInfo::IsPrimitiveType(pDest->GetArrayElementType()));
438438
_ASSERTE(!srcTH.GetMethodTable()->IsValueType());
439439

440-
MethodTable * pDestMT = destTH.GetMethodTable();
440+
MethodTable * pDestMT = destTH.AsMethodTable();
441441
PREFIX_ASSUME(pDestMT != NULL);
442442

443443
SIZE_T destSize = pDest->GetComponentSize();
@@ -824,6 +824,13 @@ FCIMPLEND
824824
// Check we're allowed to create an array with the given element type.
825825
void ArrayNative::CheckElementType(TypeHandle elementType)
826826
{
827+
// Checks apply recursively for arrays of arrays etc.
828+
if (elementType.IsArray())
829+
{
830+
CheckElementType(elementType.GetArrayElementTypeHandle());
831+
return;
832+
}
833+
827834
// Check for simple types first.
828835
if (!elementType.IsTypeDesc())
829836
{
@@ -845,13 +852,6 @@ void ArrayNative::CheckElementType(TypeHandle elementType)
845852
return;
846853
}
847854

848-
// Checks apply recursively for arrays of arrays etc.
849-
if (elementType.IsArray())
850-
{
851-
CheckElementType(elementType.GetElementType());
852-
return;
853-
}
854-
855855
// ByRefs and generic type variables are never allowed.
856856
if (elementType.IsByRef() || elementType.IsGenericVariable())
857857
COMPlusThrow(kNotSupportedException, W("NotSupported_Type"));
@@ -1040,7 +1040,7 @@ FCIMPL2(void, ArrayNative::SetValue, TypedByRef * target, Object* objUNSAFE)
10401040

10411041
TypeHandle thTarget(target->type);
10421042

1043-
MethodTable* pTargetMT = thTarget.GetMethodTable();
1043+
MethodTable* pTargetMT = thTarget.AsMethodTable();
10441044
PREFIX_ASSUME(NULL != pTargetMT);
10451045

10461046
if (obj == NULL)

src/coreclr/src/classlibnative/bcltype/varargsnative.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ VarArgsNative::GetNextArgHelper(
533533
#if !defined(BIT64) && (DATA_ALIGNMENT > 4)
534534
if ( fData && origArgPtr == value->data ) {
535535
// allocate an aligned copy of the value
536-
value->data = value->type.GetMethodTable()->Box(origArgPtr, FALSE)->UnBox();
536+
value->data = value->type.AsMethodTable()->Box(origArgPtr, FALSE)->UnBox();
537537
}
538538
#endif
539539
break;
@@ -580,12 +580,12 @@ VarArgsNative::GetNextArgHelper(
580580
case ELEMENT_TYPE_CLASS: {
581581
value->type = data->SigPtr.GetTypeHandleThrowing(data->ArgCookie->pModule, &typeContext);
582582

583-
if (value->type.GetMethodTable()->IsByRefLike())
583+
if (value->type.AsMethodTable()->IsByRefLike())
584584
{
585585
COMPlusThrow(kNotSupportedException, W("NotSupported_Type"));
586586
}
587587

588-
if (elemType == ELEMENT_TYPE_CLASS && value->type.GetMethodTable()->IsValueType())
588+
if (elemType == ELEMENT_TYPE_CLASS && value->type.AsMethodTable()->IsValueType())
589589
value->type = g_pObjectClass;
590590
} break;
591591

src/coreclr/src/debug/daccess/dacdbiimpl.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,8 +2433,8 @@ void DacDbiInterfaceImpl::GetArrayTypeInfo(TypeHandle typeH
24332433
AppDomain * pAppDomain)
24342434
{
24352435
_ASSERTE(typeHandle.IsArray());
2436-
pTypeInfo->ArrayTypeData.arrayRank = typeHandle.AsArray()->GetRank();
2437-
TypeHandleToBasicTypeInfo(typeHandle.AsArray()->GetArrayElementTypeHandle(),
2436+
pTypeInfo->ArrayTypeData.arrayRank = typeHandle.GetRank();
2437+
TypeHandleToBasicTypeInfo(typeHandle.GetArrayElementTypeHandle(),
24382438
&(pTypeInfo->ArrayTypeData.arrayTypeArg),
24392439
pAppDomain);
24402440
} // DacDbiInterfaceImpl::GetArrayTypeInfo
@@ -2644,24 +2644,7 @@ void DacDbiInterfaceImpl::GetObjectExpandedTypeInfoFromID(AreValueTypesBoxed box
26442644
{
26452645
DD_ENTER_MAY_THROW;
26462646

2647-
PTR_MethodTable pMT(TO_TADDR(id.token1));
2648-
2649-
if (pMT->IsArray())
2650-
{
2651-
// ArrayBase::GetTypeHandle() may return a NULL handle in corner case scenarios. This check prevents
2652-
// us from an AV but doesn't actually fix the problem. See DevDiv 653441 for more info.
2653-
TypeHandle arrayHandle = ArrayBase::GetTypeHandle(pMT);
2654-
if (arrayHandle.IsNull())
2655-
{
2656-
ThrowHR(CORDBG_E_CLASS_NOT_LOADED);
2657-
}
2658-
2659-
TypeHandleToExpandedTypeInfoImpl(boxed, vmAppDomain, arrayHandle, pTypeInfo);
2660-
}
2661-
else
2662-
{
2663-
TypeHandleToExpandedTypeInfoImpl(boxed, vmAppDomain, TypeHandle::FromPtr(TO_TADDR(id.token1)), pTypeInfo);
2664-
}
2647+
TypeHandleToExpandedTypeInfoImpl(boxed, vmAppDomain, TypeHandle::FromPtr(TO_TADDR(id.token1)), pTypeInfo);
26652648
}
26662649

26672650
void DacDbiInterfaceImpl::GetObjectExpandedTypeInfo(AreValueTypesBoxed boxed,

src/coreclr/src/debug/daccess/enummem.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags)
280280
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pEEDbgInterfaceImpl.EnumMem(); )
281281
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_CORDebuggerControlFlags.EnumMem(); )
282282
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_Mscorlib.EnumMem(); )
283-
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT]->EnumMemoryRegions(flags); )
283+
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT].EnumMemoryRegions(flags); )
284284
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( StubManager::EnumMemoryRegions(flags); )
285285
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pFinalizerThread.EnumMem(); )
286286
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pSuspensionThread.EnumMem(); )
@@ -511,8 +511,7 @@ HRESULT ClrDataAccess::DumpManagedExcepObject(CLRDataEnumMemoryFlags flags, OBJE
511511
{
512512
// first dump the array's element type
513513
TypeHandle arrayTypeHandle = stackTraceArrayObj->GetTypeHandle();
514-
ArrayTypeDesc* pArrayTypeDesc = arrayTypeHandle.AsArray();
515-
TypeHandle elementTypeHandle = pArrayTypeDesc->GetArrayElementTypeHandle();
514+
TypeHandle elementTypeHandle = arrayTypeHandle.GetArrayElementTypeHandle();
516515
elementTypeHandle.AsMethodTable()->EnumMemoryRegions(flags);
517516
elementTypeHandle.AsMethodTable()->GetClass()->EnumMemoryRegions(flags, elementTypeHandle.AsMethodTable());
518517

src/coreclr/src/debug/daccess/inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3569,7 +3569,7 @@ ClrDataTypeInstance::GetDefinition(
35693569

35703570
else if (m_typeHandle.IsTypeDesc() && m_typeHandle.AsTypeDesc()->HasTypeParam())
35713571
{
3572-
// HasTypeParam is true for - ParamTypeDesc (ARRAY, SZARRAY, BYREF, PTR)
3572+
// HasTypeParam is true for - ParamTypeDesc (BYREF, PTR)
35733573
defType = m_typeHandle.AsTypeDesc()->GetTypeParam();
35743574

35753575
// The DefinitionType won't contain ByRef, PTR.

src/coreclr/src/debug/daccess/nidump.cpp

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,6 @@ IMetaDataImport2 * NativeImageDumper::TypeToString(PTR_CCOR_SIGNATURE &sig,
27882788
buf.Append( W("System.__Canon") );
27892789
break;
27902790

2791-
case ELEMENT_TYPE_NATIVE_ARRAY_TEMPLATE_ZAPSIG:
27922791
case ELEMENT_TYPE_NATIVE_VALUETYPE_ZAPSIG:
27932792
{
27942793
buf.Append( W("native ") );
@@ -6108,51 +6107,17 @@ void NativeImageDumper::TypeDescToString( PTR_TypeDesc td, SString& buf )
61086107
PTR_FnPtrTypeDesc fptd( PTR_TO_TADDR(td) );
61096108
buf.Append( W("(fnptr)") );
61106109
}
6111-
else if( td->HasTypeParam() || td->IsArray() )
6110+
else if(td->HasTypeParam())
61126111
{
6113-
//either a Parameter or an Array.
61146112
PTR_ParamTypeDesc ptd(PTR_TO_TADDR(td));
6115-
TypeHandle elemType;
6116-
/* REVISIT_TODO Thu 10/5/2006
6117-
* Do I need to find a rank somewhere in the TypeDesc?
6118-
*/
6119-
unsigned rank;
6120-
if( td->IsArray() )
6121-
{
6122-
//td->HasTypeParam() may also be true.
6123-
PTR_MethodTable mt = ptd->GetTemplateMethodTableInternal();
6124-
_ASSERTE( PTR_TO_TADDR(mt) );
6125-
if( CORCOMPILE_IS_POINTER_TAGGED(PTR_TO_TADDR(mt)) )
6126-
{
6127-
if (!isSelf(GetDependencyForPointer(PTR_TO_TADDR(ptd))))
6128-
{
6129-
//this is an RVA from another hardbound dependency. We cannot decode it
6130-
buf.Append(W("OUT_OF_MODULE_FIXUP"));
6131-
}
6132-
else
6133-
{
6134-
RVA rva = CORCOMPILE_UNTAG_TOKEN(PTR_TO_TADDR(mt));
6135-
FixupBlobToString(rva, buf);
6136-
}
6137-
return;
6138-
}
6139-
else
6140-
{
6141-
_ASSERTE( !CORCOMPILE_IS_POINTER_TAGGED(PTR_TO_TADDR(mt)) );
6142-
MethodTableToString( mt, buf );
6143-
rank = PTR_ArrayTypeDesc(PTR_TO_TADDR(ptd))->GetRank();
6144-
}
6145-
}
6146-
else
6147-
{
6148-
_ASSERTE(td->HasTypeParam());
6149-
TypeHandle th(ptd->GetTypeParam());
6150-
_ASSERTE( !CORCOMPILE_IS_POINTER_TAGGED(th.AsTAddr()) );
6151-
_ASSERTE( th.AsTAddr() );
6152-
TypeHandleToString(th, buf);
6153-
rank = 0;
6154-
}
6155-
AppendTypeQualifier( td->GetInternalCorElementType(), rank, buf );
6113+
6114+
_ASSERTE(td->HasTypeParam());
6115+
TypeHandle th(ptd->GetTypeParam());
6116+
_ASSERTE( !CORCOMPILE_IS_POINTER_TAGGED(th.AsTAddr()) );
6117+
_ASSERTE( th.AsTAddr() );
6118+
TypeHandleToString(th, buf);
6119+
6120+
AppendTypeQualifier( td->GetInternalCorElementType(), /*rank*/ 0, buf );
61566121
}
61576122
else
61586123
{
@@ -8638,31 +8603,26 @@ enum TypeDescType
86388603
{
86398604
TDT_IsTypeDesc,
86408605
TDT_IsParamTypeDesc,
8641-
TDT_IsArrayTypeDesc,
86428606
TDT_IsTypeVarTypeDesc,
86438607
TDT_IsFnPtrTypeDesc
86448608
};
86458609
const char * const g_typeDescTypeNames[] =
86468610
{
86478611
"TypeDesc",
86488612
"ParamTypeDesc",
8649-
"ArrayTypeDesc",
86508613
"TypeVarTypeDesc",
86518614
"FnPtrTypeDesc"
86528615
};
86538616
int g_typeDescSizes[] =
86548617
{
86558618
sizeof(TypeDesc),
86568619
sizeof(ParamTypeDesc),
8657-
sizeof(ArrayTypeDesc),
86588620
sizeof(TypeVarTypeDesc),
86598621
-1//sizeof(FnPtrTypeDesc) -- variable size
86608622
};
86618623
TypeDescType getTypeDescType( PTR_TypeDesc td )
86628624
{
86638625
_ASSERTE(td != NULL);
8664-
if( td->IsArray() )
8665-
return TDT_IsArrayTypeDesc;
86668626
if( td->HasTypeParam() )
86678627
return TDT_IsParamTypeDesc;
86688628
if( td->IsGenericVariable() )
@@ -8722,7 +8682,7 @@ void NativeImageDumper::DumpTypeDesc( PTR_TypeDesc td )
87228682
TypeDesc, TYPEDESCS );
87238683
DisplayWriteFieldEnumerated( m_typeAndFlags, td->m_typeAndFlags, TypeDesc,
87248684
s_TDFlags, W(", "), TYPEDESCS );
8725-
if( tdt == TDT_IsParamTypeDesc || tdt == TDT_IsArrayTypeDesc )
8685+
if( tdt == TDT_IsParamTypeDesc )
87268686
{
87278687
PTR_ParamTypeDesc ptd(td);
87288688
DisplayStartVStructure( "ParamTypeDesc", TYPEDESCS );

src/coreclr/src/debug/daccess/request.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,8 @@ ClrDataAccess::GetObjectData(CLRDATA_ADDRESS addr, struct DacpObjectData *object
22002200
TypeHandle thElem = mt->GetArrayElementTypeHandle();
22012201

22022202
TypeHandle thCur = thElem;
2203-
while (thCur.IsTypeDesc())
2204-
thCur = thCur.AsArray()->GetArrayElementTypeHandle();
2203+
while (thCur.IsArray())
2204+
thCur = thCur.GetArrayElementTypeHandle();
22052205

22062206
TADDR mtCurTADDR = thCur.AsTAddr();
22072207
if (!DacValidateMethodTable(PTR_MethodTable(mtCurTADDR), bFree))
@@ -3119,9 +3119,9 @@ ClrDataAccess::GetUsefulGlobals(struct DacpUsefulGlobalsData *globalsData)
31193119

31203120
SOSDacEnter();
31213121

3122-
PTR_ArrayTypeDesc objArray = g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT];
3123-
if (objArray)
3124-
globalsData->ArrayMethodTable = HOST_CDADDR(objArray->GetMethodTable());
3122+
TypeHandle objArray = g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT];
3123+
if (objArray != NULL)
3124+
globalsData->ArrayMethodTable = HOST_CDADDR(objArray.AsMethodTable());
31253125
else
31263126
globalsData->ArrayMethodTable = 0;
31273127

src/coreclr/src/debug/ee/debugger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12181,9 +12181,9 @@ void Debugger::TypeHandleToExpandedTypeInfo(AreValueTypesBoxed boxed,
1218112181
case ELEMENT_TYPE_ARRAY:
1218212182
case ELEMENT_TYPE_SZARRAY:
1218312183
_ASSERTE(th.IsArray());
12184-
res->ArrayTypeData.arrayRank = th.AsArray()->GetRank();
12184+
res->ArrayTypeData.arrayRank = th.GetRank();
1218512185
TypeHandleToBasicTypeInfo(pAppDomain,
12186-
th.AsArray()->GetArrayElementTypeHandle(),
12186+
th.GetArrayElementTypeHandle(),
1218712187
&(res->ArrayTypeData.arrayTypeArg));
1218812188
break;
1218912189

src/coreclr/src/inc/corinfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ enum CorInfoHelpFunc
407407
CORINFO_HELP_NEW_MDARR, // multi-dim array helper (with or without lower bounds - dimensions passed in as vararg)
408408
CORINFO_HELP_NEW_MDARR_NONVARARG,// multi-dim array helper (with or without lower bounds - dimensions passed in as unmanaged array)
409409
CORINFO_HELP_NEWARR_1_DIRECT, // helper for any one dimensional array creation
410-
CORINFO_HELP_NEWARR_1_R2R_DIRECT, // wrapper for R2R direct call, which extracts method table from ArrayTypeDesc
411410
CORINFO_HELP_NEWARR_1_OBJ, // optimized 1-D object arrays
412411
CORINFO_HELP_NEWARR_1_VC, // optimized 1-D value class arrays
413412
CORINFO_HELP_NEWARR_1_ALIGN8, // like VC, but aligns the array start

src/coreclr/src/inc/corpriv.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,7 @@ typedef enum CorElementTypeZapSig
231231
// by the RID of a GenericParam token, encoded as a compressed integer.
232232
ELEMENT_TYPE_VAR_ZAPSIG = 0x3b,
233233

234-
// ZapSig encoding for an array MethodTable to allow it to remain such after decoding
235-
// (rather than being transformed into the TypeHandle representing that array)
236-
//
237-
// The element is always followed by ELEMENT_TYPE_SZARRAY or ELEMENT_TYPE_ARRAY
238-
ELEMENT_TYPE_NATIVE_ARRAY_TEMPLATE_ZAPSIG = 0x3c,
234+
// UNUSED = 0x3c,
239235

240236
// ZapSig encoding for native value types in IL stubs. IL stub signatures may contain
241237
// ELEMENT_TYPE_INTERNAL followed by ParamTypeDesc with ELEMENT_TYPE_VALUETYPE element

0 commit comments

Comments
 (0)