mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Better handling of let/var field failures
This commit is contained in:
parent
624e36b89b
commit
b63b4af6fe
5 changed files with 59 additions and 8 deletions
|
@ -1264,11 +1264,24 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BF_ASSERT(type->mTypeCode == BeTypeCode_Struct);
|
bool failed = false;
|
||||||
auto structType = (BeStructType*)type;
|
for (auto member : members)
|
||||||
mBeContext->SetStructBody(structType, members, isPacked);
|
{
|
||||||
structType->mSize = instSize;
|
if (member->mSize < 0)
|
||||||
structType->mAlign = instAlign;
|
{
|
||||||
|
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;
|
break;
|
||||||
case BfIRCmd_Type:
|
case BfIRCmd_Type:
|
||||||
|
@ -3725,6 +3738,18 @@ void BeIRCodeGen::SetConfigConst(int idx, int value)
|
||||||
mConfigConsts.Add(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)
|
BeValue* BeIRCodeGen::GetBeValue(int id)
|
||||||
{
|
{
|
||||||
auto& result = mResults[id];
|
auto& result = mResults[id];
|
||||||
|
|
|
@ -150,6 +150,7 @@ public:
|
||||||
virtual void SetConfigConst(int idx, int value) override;
|
virtual void SetConfigConst(int idx, int value) override;
|
||||||
|
|
||||||
BeValue* GetBeValue(int streamId);
|
BeValue* GetBeValue(int streamId);
|
||||||
|
BeValue* TryGetBeValue(int streamId);
|
||||||
BeType* GetBeType(int streamId);
|
BeType* GetBeType(int streamId);
|
||||||
BeBlock* GetBeBlock(int streamId);
|
BeBlock* GetBeBlock(int streamId);
|
||||||
BeMDNode* GetBeMetadata(int streamId);
|
BeMDNode* GetBeMetadata(int streamId);
|
||||||
|
|
|
@ -2607,7 +2607,14 @@ BfProjectSet* BfModule::GetVisibleProjectSet()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mCurTypeInstance != NULL)
|
if (mCurTypeInstance != NULL)
|
||||||
|
{
|
||||||
_AddType(mCurTypeInstance);
|
_AddType(mCurTypeInstance);
|
||||||
|
if ((mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mType == mCurTypeInstance))
|
||||||
|
{
|
||||||
|
if (mContext->mCurTypeState->mCurTypeDef != NULL)
|
||||||
|
_AddProject(mContext->mCurTypeState->mCurTypeDef->mProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto methodState = mCurMethodState;
|
auto methodState = mCurMethodState;
|
||||||
while (methodState != NULL)
|
while (methodState != NULL)
|
||||||
|
|
|
@ -6099,6 +6099,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
std::function<void(BfType*)> splatIterate;
|
std::function<void(BfType*)> splatIterate;
|
||||||
splatIterate = [&](BfType* checkType)
|
splatIterate = [&](BfType* checkType)
|
||||||
{
|
{
|
||||||
|
if (hadNonSplattable)
|
||||||
|
return;
|
||||||
|
|
||||||
if (checkType->IsValueType())
|
if (checkType->IsValueType())
|
||||||
PopulateType(checkType, BfPopulateType_Data);
|
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++)
|
for (int fieldIdx = 0; fieldIdx < (int)checkTypeInstance->mFieldInstances.size(); fieldIdx++)
|
||||||
{
|
{
|
||||||
auto fieldInstance = (BfFieldInstance*)&checkTypeInstance->mFieldInstances[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)
|
if (fieldInstance->mDataIdx >= 0)
|
||||||
splatIterate(fieldInstance->GetResolvedType());
|
splatIterate(fieldInstance->GetResolvedType());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2097,7 +2097,12 @@ void CeBuilder::Build()
|
||||||
mCeFunction->mFailed = true;
|
mCeFunction->mFailed = true;
|
||||||
return;
|
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);
|
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()))
|
if ((func.IsConst()) || (func.IsFake()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->TryGetBeValue(func.mId);
|
||||||
|
if (funcVal == NULL)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CeFunctionInfo** functionInfoPtr = NULL;
|
CeFunctionInfo** functionInfoPtr = NULL;
|
||||||
|
@ -10409,8 +10418,7 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->GetBeValue(func.mId);
|
auto funcVal = mCeModule->mBfIRBuilder->mBeIRCodeGen->GetBeValue(func.mId);
|
||||||
|
|
||||||
if (auto function = BeValueDynCast<BeFunction>(funcVal))
|
if (auto function = BeValueDynCast<BeFunction>(funcVal))
|
||||||
{
|
{
|
||||||
String funcName = function->mName;
|
String funcName = function->mName;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue