1
0
Fork 0
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:
Brian Fiete 2021-08-02 12:30:05 -07:00
parent 16829900bc
commit 974b3a58e8
2 changed files with 24 additions and 13 deletions

View file

@ -12069,6 +12069,9 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration*
BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget) BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget)
{ {
if (mModule->mCurMethodState == NULL)
return NULL;
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState(); auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
BfAstNodeList cacheNodeList; BfAstNodeList cacheNodeList;
cacheNodeList.mList.Add(lambdaBindExpr); cacheNodeList.mList.Add(lambdaBindExpr);
@ -12301,6 +12304,8 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
Val128 val128(delegateTypeInstance->mTypeId); Val128 val128(delegateTypeInstance->mTypeId);
bool isConstEval = ((mBfEvalExprFlags & BfEvalExprFlags_Comptime) != 0);
BfMethodState methodState; BfMethodState methodState;
methodState.mPrevMethodState = mModule->mCurMethodState; methodState.mPrevMethodState = mModule->mCurMethodState;
BfIRFunctionType funcType; BfIRFunctionType funcType;
@ -12309,7 +12314,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
funcType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), paramTypes, false); funcType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), paramTypes, false);
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock(); auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();
BF_ASSERT(prevInsertBlock); BF_ASSERT(prevInsertBlock || isConstEval);
auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction(); auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction();
mModule->mBfIRBuilder->SaveDebugLocation(); mModule->mBfIRBuilder->SaveDebugLocation();
@ -12887,7 +12892,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
prevMethodState.Restore(); prevMethodState.Restore();
mModule->mBfIRBuilder->SetActiveFunction(prevActiveFunction); mModule->mBfIRBuilder->SetActiveFunction(prevActiveFunction);
if (!prevInsertBlock.IsFake()) if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
// Just a check // Just a check
@ -13069,7 +13074,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
} }
prevClosureState.Restore(); prevClosureState.Restore();
if (!prevInsertBlock.IsFake()) if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
for (auto& capturedEntry : capturedEntries) for (auto& capturedEntry : capturedEntries)

View file

@ -13648,8 +13648,11 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance)
if (methodInstance->mMethodDef->mIsLocalMethod) if (methodInstance->mMethodDef->mIsLocalMethod)
{ {
auto outmostMethodInstance = mCurMethodState->GetRootMethodState()->mMethodInstance; auto outmostMethodInstance = mCurMethodState->GetRootMethodState()->mMethodInstance;
BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod)); if (outmostMethodInstance != NULL)
hashCtx.Mixin(outmostMethodInstance->mIdHash); {
BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod));
hashCtx.Mixin(outmostMethodInstance->mIdHash);
}
} }
methodInstance->mIdHash = (int64)hashCtx.Finish64(); methodInstance->mIdHash = (int64)hashCtx.Finish64();
@ -20396,7 +20399,7 @@ String BfModule::GetLocalMethodName(const StringImpl& baseName, BfAstNode* ancho
} }
auto rootMethodState = mCurMethodState->GetRootMethodState(); 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) for (auto methodGenericArg : rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments)
{ {
@ -20454,7 +20457,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod)
BfMethodDef* outerMethodDef = NULL; BfMethodDef* outerMethodDef = NULL;
if (localMethod->mOuterLocalMethod != NULL) if (localMethod->mOuterLocalMethod != NULL)
outerMethodDef = localMethod->mOuterLocalMethod->mMethodDef; outerMethodDef = localMethod->mOuterLocalMethod->mMethodDef;
else else if (rootMethodState->mMethodInstance != NULL)
outerMethodDef = rootMethodState->mMethodInstance->mMethodDef; outerMethodDef = rootMethodState->mMethodInstance->mMethodDef;
if (methodDeclaration != NULL) 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) // 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 // version of this method for this pass through the outermost method
int dependentGenericStartIdx = 0; int dependentGenericStartIdx = 0;
if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL) if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL))
dependentGenericStartIdx = (int)rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); dependentGenericStartIdx = (int)rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments.size();
BfMethodInstance* outerMethodInstance = mCurMethodInstance; BfMethodInstance* outerMethodInstance = mCurMethodInstance;
if (methodGenericArguments.size() == 0) if (methodGenericArguments.size() == 0)
{ {
if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL) if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL))
sanitizedMethodGenericArguments = rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments; sanitizedMethodGenericArguments = rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments;
} }
else else
@ -21677,11 +21680,14 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
// over the local method each time // over the local method each time
auto rootMethodInstance = prevMethodState.mPrevVal->GetRootMethodState()->mMethodInstance; auto rootMethodInstance = prevMethodState.mPrevVal->GetRootMethodState()->mMethodInstance;
dependentGenericStartIdx = 0; dependentGenericStartIdx = 0;
if (rootMethodInstance->mMethodInfoEx != NULL) if (rootMethodInstance != NULL)
dependentGenericStartIdx = (int)rootMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); {
if (rootMethodInstance->mMethodInfoEx != NULL)
dependentGenericStartIdx = (int)rootMethodInstance->mMethodInfoEx->mMethodGenericArguments.size();
methodInstance->mIsUnspecialized = rootMethodInstance->mIsUnspecialized; methodInstance->mIsUnspecialized = rootMethodInstance->mIsUnspecialized;
methodInstance->mIsUnspecializedVariation = rootMethodInstance->mIsUnspecializedVariation; methodInstance->mIsUnspecializedVariation = rootMethodInstance->mIsUnspecializedVariation;
}
} }
for (int genericArgIdx = dependentGenericStartIdx; genericArgIdx < (int) methodInstance->GetNumGenericArguments(); genericArgIdx++) for (int genericArgIdx = dependentGenericStartIdx; genericArgIdx < (int) methodInstance->GetNumGenericArguments(); genericArgIdx++)