mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed crashes related to attempts at comptime delegate binding
This commit is contained in:
parent
16829900bc
commit
974b3a58e8
2 changed files with 24 additions and 13 deletions
|
@ -12069,6 +12069,9 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration*
|
|||
|
||||
BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget)
|
||||
{
|
||||
if (mModule->mCurMethodState == NULL)
|
||||
return NULL;
|
||||
|
||||
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
|
||||
BfAstNodeList cacheNodeList;
|
||||
cacheNodeList.mList.Add(lambdaBindExpr);
|
||||
|
@ -12301,6 +12304,8 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
|||
|
||||
Val128 val128(delegateTypeInstance->mTypeId);
|
||||
|
||||
bool isConstEval = ((mBfEvalExprFlags & BfEvalExprFlags_Comptime) != 0);
|
||||
|
||||
BfMethodState methodState;
|
||||
methodState.mPrevMethodState = mModule->mCurMethodState;
|
||||
BfIRFunctionType funcType;
|
||||
|
@ -12309,7 +12314,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
|||
funcType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), paramTypes, false);
|
||||
|
||||
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();
|
||||
BF_ASSERT(prevInsertBlock);
|
||||
BF_ASSERT(prevInsertBlock || isConstEval);
|
||||
auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction();
|
||||
mModule->mBfIRBuilder->SaveDebugLocation();
|
||||
|
||||
|
@ -12887,7 +12892,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
|||
|
||||
prevMethodState.Restore();
|
||||
mModule->mBfIRBuilder->SetActiveFunction(prevActiveFunction);
|
||||
if (!prevInsertBlock.IsFake())
|
||||
if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
|
||||
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||
|
||||
// Just a check
|
||||
|
@ -13069,7 +13074,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
|||
}
|
||||
|
||||
prevClosureState.Restore();
|
||||
if (!prevInsertBlock.IsFake())
|
||||
if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
|
||||
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||
|
||||
for (auto& capturedEntry : capturedEntries)
|
||||
|
|
|
@ -13648,9 +13648,12 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance)
|
|||
if (methodInstance->mMethodDef->mIsLocalMethod)
|
||||
{
|
||||
auto outmostMethodInstance = mCurMethodState->GetRootMethodState()->mMethodInstance;
|
||||
if (outmostMethodInstance != NULL)
|
||||
{
|
||||
BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod));
|
||||
hashCtx.Mixin(outmostMethodInstance->mIdHash);
|
||||
}
|
||||
}
|
||||
|
||||
methodInstance->mIdHash = (int64)hashCtx.Finish64();
|
||||
}
|
||||
|
@ -20396,7 +20399,7 @@ String BfModule::GetLocalMethodName(const StringImpl& baseName, BfAstNode* ancho
|
|||
}
|
||||
|
||||
auto rootMethodState = mCurMethodState->GetRootMethodState();
|
||||
if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)
|
||||
if ((rootMethodState != NULL) && (rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL))
|
||||
{
|
||||
for (auto methodGenericArg : rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments)
|
||||
{
|
||||
|
@ -20454,7 +20457,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod)
|
|||
BfMethodDef* outerMethodDef = NULL;
|
||||
if (localMethod->mOuterLocalMethod != NULL)
|
||||
outerMethodDef = localMethod->mOuterLocalMethod->mMethodDef;
|
||||
else
|
||||
else if (rootMethodState->mMethodInstance != NULL)
|
||||
outerMethodDef = rootMethodState->mMethodInstance->mMethodDef;
|
||||
|
||||
if (methodDeclaration != NULL)
|
||||
|
@ -20585,14 +20588,14 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth
|
|||
// Ignore the outermost method's generic method arguments for the purpose of determining if we are the 'default' (ie: unspecialized)
|
||||
// version of this method for this pass through the outermost method
|
||||
int dependentGenericStartIdx = 0;
|
||||
if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)
|
||||
if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL))
|
||||
dependentGenericStartIdx = (int)rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments.size();
|
||||
|
||||
BfMethodInstance* outerMethodInstance = mCurMethodInstance;
|
||||
|
||||
if (methodGenericArguments.size() == 0)
|
||||
{
|
||||
if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)
|
||||
if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL))
|
||||
sanitizedMethodGenericArguments = rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments;
|
||||
}
|
||||
else
|
||||
|
@ -21677,12 +21680,15 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
|||
// over the local method each time
|
||||
auto rootMethodInstance = prevMethodState.mPrevVal->GetRootMethodState()->mMethodInstance;
|
||||
dependentGenericStartIdx = 0;
|
||||
if (rootMethodInstance != NULL)
|
||||
{
|
||||
if (rootMethodInstance->mMethodInfoEx != NULL)
|
||||
dependentGenericStartIdx = (int)rootMethodInstance->mMethodInfoEx->mMethodGenericArguments.size();
|
||||
|
||||
methodInstance->mIsUnspecialized = rootMethodInstance->mIsUnspecialized;
|
||||
methodInstance->mIsUnspecializedVariation = rootMethodInstance->mIsUnspecializedVariation;
|
||||
}
|
||||
}
|
||||
|
||||
for (int genericArgIdx = dependentGenericStartIdx; genericArgIdx < (int) methodInstance->GetNumGenericArguments(); genericArgIdx++)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue