1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-07 19:18:19 +02:00

Better handling of let/var field failures

This commit is contained in:
Brian Fiete 2025-01-23 09:10:00 -08:00
parent 624e36b89b
commit b63b4af6fe
5 changed files with 59 additions and 8 deletions

View file

@ -1264,11 +1264,24 @@ void BeIRCodeGen::HandleNextCmd()
break;
}
BF_ASSERT(type->mTypeCode == BeTypeCode_Struct);
auto structType = (BeStructType*)type;
mBeContext->SetStructBody(structType, members, isPacked);
structType->mSize = instSize;
structType->mAlign = instAlign;
bool failed = false;
for (auto member : members)
{
if (member->mSize < 0)
{
Fail("StructSetBody invalid member type");
failed = true;
}
}
if (!failed)
{
BF_ASSERT(type->mTypeCode == BeTypeCode_Struct);
auto structType = (BeStructType*)type;
mBeContext->SetStructBody(structType, members, isPacked);
structType->mSize = instSize;
structType->mAlign = instAlign;
}
}
break;
case BfIRCmd_Type:
@ -3725,6 +3738,18 @@ void BeIRCodeGen::SetConfigConst(int idx, int value)
mConfigConsts.Add(value);
}
BeValue* BeIRCodeGen::TryGetBeValue(int id)
{
auto& result = mResults[id];
if (result.mKind != BeIRCodeGenEntryKind_Value)
return NULL;
#ifdef BE_EXTRA_CHECKS
BF_ASSERT(!result.mBeValue->mLifetimeEnded);
BF_ASSERT(!result.mBeValue->mWasRemoved);
#endif
return result.mBeValue;
}
BeValue* BeIRCodeGen::GetBeValue(int id)
{
auto& result = mResults[id];

View file

@ -150,6 +150,7 @@ public:
virtual void SetConfigConst(int idx, int value) override;
BeValue* GetBeValue(int streamId);
BeValue* TryGetBeValue(int streamId);
BeType* GetBeType(int streamId);
BeBlock* GetBeBlock(int streamId);
BeMDNode* GetBeMetadata(int streamId);

View file

@ -2607,7 +2607,14 @@ BfProjectSet* BfModule::GetVisibleProjectSet()
};
if (mCurTypeInstance != NULL)
{
_AddType(mCurTypeInstance);
if ((mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mType == mCurTypeInstance))
{
if (mContext->mCurTypeState->mCurTypeDef != NULL)
_AddProject(mContext->mCurTypeState->mCurTypeDef->mProject);
}
}
auto methodState = mCurMethodState;
while (methodState != NULL)

View file

@ -6099,6 +6099,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
std::function<void(BfType*)> splatIterate;
splatIterate = [&](BfType* checkType)
{
if (hadNonSplattable)
return;
if (checkType->IsValueType())
PopulateType(checkType, BfPopulateType_Data);
@ -6135,6 +6138,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
for (int fieldIdx = 0; fieldIdx < (int)checkTypeInstance->mFieldInstances.size(); fieldIdx++)
{
auto fieldInstance = (BfFieldInstance*)&checkTypeInstance->mFieldInstances[fieldIdx];
if ((fieldInstance->mResolvedType->IsVar()) || (fieldInstance->mResolvedType->IsLet()))
{
//TODO: allow splattables with var/let field types
hadNonSplattable = true;
}
if (fieldInstance->mDataIdx >= 0)
splatIterate(fieldInstance->GetResolvedType());
}

View file

@ -2097,7 +2097,12 @@ void CeBuilder::Build()
mCeFunction->mFailed = true;
return;
}
mBeFunction = (BeFunction*)irCodeGen->GetBeValue(dupMethodInstance.mIRFunction.mId);
mBeFunction = (BeFunction*)irCodeGen->TryGetBeValue(dupMethodInstance.mIRFunction.mId);
if (mBeFunction == NULL)
{
mCeFunction->mFailed = true;
return;
}
mIntPtrType = irCodeGen->mBeContext->GetPrimitiveType((mPtrSize == 4) ? BeTypeCode_Int32 : BeTypeCode_Int64);
@ -10386,6 +10391,10 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
{
if ((func.IsConst()) || (func.IsFake()))
return NULL;
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->TryGetBeValue(func.mId);
if (funcVal == NULL)
return NULL;
}
CeFunctionInfo** functionInfoPtr = NULL;
@ -10409,8 +10418,7 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
}
else
{
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->GetBeValue(func.mId);
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->GetBeValue(func.mId);
if (auto function = BeValueDynCast<BeFunction>(funcVal))
{
String funcName = function->mName;