diff --git a/BeefLibs/corlib/src/Reflection/TypeInstance.bf b/BeefLibs/corlib/src/Reflection/TypeInstance.bf index da22df61..5eb42155 100644 --- a/BeefLibs/corlib/src/Reflection/TypeInstance.bf +++ b/BeefLibs/corlib/src/Reflection/TypeInstance.bf @@ -143,7 +143,10 @@ namespace System.Reflection let objType = typeof(Object) as TypeInstance; #if BF_ENABLE_OBJECT_DEBUG_FLAGS - obj = Internal.Dbg_ObjectAlloc(mTypeClassVData, mInstSize, mInstAlign, Compiler.Options.AllocStackCount); + int32 stackCount = Compiler.Options.AllocStackCount; + if (mAllocStackCountOverride != 0) + stackCount = mAllocStackCountOverride; + obj = Internal.Dbg_ObjectAlloc(mTypeClassVData, mInstSize, mInstAlign, stackCount); #else void* mem = new [Align(16)] uint8[mInstSize]* (?); obj = Internal.UnsafeCastToObject(mem); diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index 79d2288e..1f79729b 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -20,13 +20,14 @@ namespace System protected const BindingFlags cDefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; - protected int32 mSize; - protected TypeId mTypeId; - protected TypeId mBoxedType; - protected TypeFlags mTypeFlags; - protected int32 mMemberDataOffset; - protected TypeCode mTypeCode; - protected uint8 mAlign; + protected int32 mSize; + protected TypeId mTypeId; + protected TypeId mBoxedType; + protected TypeFlags mTypeFlags; + protected int32 mMemberDataOffset; + protected TypeCode mTypeCode; + protected uint8 mAlign; + protected uint8 mAllocStackCountOverride; public static TypeId TypeIdEnd { @@ -1187,7 +1188,10 @@ namespace System.Reflection let genericType = GetGenericArg(0); let arraySize = [Friend]mInstSize - genericType.Size + genericType.Stride * count; #if BF_ENABLE_OBJECT_DEBUG_FLAGS - obj = Internal.Dbg_ObjectAlloc([Friend]mTypeClassVData, arraySize, [Friend]mInstAlign, Compiler.Options.AllocStackCount); + int32 stackCount = Compiler.Options.AllocStackCount; + if (mAllocStackCountOverride != 0) + stackCount = mAllocStackCountOverride; + obj = Internal.Dbg_ObjectAlloc([Friend]mTypeClassVData, arraySize, [Friend]mInstAlign, stackCount); #else void* mem = new [Align(16)] uint8[arraySize]* (?); obj = Internal.UnsafeCastToObject(mem); diff --git a/IDE/mintest/minlib/src/System/Type.bf b/IDE/mintest/minlib/src/System/Type.bf index 9a7d25b7..0e7be62b 100644 --- a/IDE/mintest/minlib/src/System/Type.bf +++ b/IDE/mintest/minlib/src/System/Type.bf @@ -20,13 +20,14 @@ namespace System protected const BindingFlags cDefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; - protected int32 mSize; - protected TypeId mTypeId; - protected TypeId mBoxedType; - protected TypeFlags mTypeFlags; - protected int32 mMemberDataOffset; - protected TypeCode mTypeCode; - protected uint8 mAlign; + protected int32 mSize; + protected TypeId mTypeId; + protected TypeId mBoxedType; + protected TypeFlags mTypeFlags; + protected int32 mMemberDataOffset; + protected TypeCode mTypeCode; + protected uint8 mAlign; + protected uint8 mAllocStackCountOverride; public static TypeId TypeIdEnd { @@ -1117,7 +1118,10 @@ namespace System.Reflection let genericType = GetGenericArg(0); let arraySize = [Friend]mInstSize - genericType.Size + genericType.Stride * count; #if BF_ENABLE_OBJECT_DEBUG_FLAGS - obj = Internal.Dbg_ObjectAlloc([Friend]mTypeClassVData, arraySize, [Friend]mInstAlign, Compiler.Options.AllocStackCount); + int32 stackCount = Compiler.Options.AllocStackCount; + if (mAllocStackCountOverride != 0) + stackCount = mAllocStackCountOverride; + obj = Internal.Dbg_ObjectAlloc([Friend]mTypeClassVData, arraySize, [Friend]mInstAlign, stackCount); #else void* mem = new [Align(16)] uint8[arraySize]* (?); obj = Internal.UnsafeCastToObject(mem); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index c23d16a2..f9074614 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -5467,7 +5467,15 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin boxedTypeId = boxedType->mTypeId; } - SizedArray typeDataParams = + int stackCount = 0; + if ((typeInstance != NULL) && (typeInstance->mTypeOptionsIdx != -1)) + { + auto typeOptions = mSystem->GetTypeOptions(typeInstance->mTypeOptionsIdx); + if (typeOptions->mAllocStackTraceDepth != -1) + stackCount = BF_MIN(0xFF, BF_MAX(0x01, typeOptions->mAllocStackTraceDepth)); + } + + SizedArray typeDataParams = { objectData, GetConstValue(type->mSize, intType), // mSize @@ -5476,7 +5484,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin GetConstValue(typeFlags, intType), // mTypeFlags GetConstValue(memberDataOffset, intType), // mMemberDataOffset GetConstValue(typeCode, byteType), // mTypeCode - GetConstValue(type->mAlign, byteType), + GetConstValue(type->mAlign, byteType), // mAlign + GetConstValue(stackCount, byteType), // mAllocStackCountOverride }; auto typeData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(mContext->mBfTypeType, BfIRPopulateType_Full), typeDataParams);