1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fix for lambda caching within mixin

This commit is contained in:
Brian Fiete 2020-10-30 09:03:36 -07:00
parent 08703e0cf4
commit 8abb72939b
3 changed files with 60 additions and 10 deletions

View file

@ -3,6 +3,7 @@
#include "BeefySysLib/Common.h"
#include "BeefySysLib/util/DLIList.h"
#include "BeefySysLib/util/BumpAllocator.h"
#include "BeefySysLib/util/SizedArray.h"
#include "BfAstAllocator.h"
#include "BfIRBuilder.h"
@ -767,6 +768,23 @@ public:
class BfAstNode;
class BfAstNodeList
{
public:
SizedArray<BfAstNode*, 4> mList;
public:
bool operator==(const BfAstNodeList& rhs)
{
if (mList.mSize != rhs.mList.mSize)
return false;
for (int i = 0; i < mList.mSize; i++)
if (mList[i] != rhs.mList[i])
return false;
return false;
}
};
template <typename T>
class BfChunkedArray
{
@ -3299,4 +3317,20 @@ BfUnaryOp BfTokenToUnaryOp(BfToken token);
BfAssignmentOp BfTokenToAssignmentOp(BfToken token);
bool BfIsCommentBlock(BfCommentKind commentKind);
NS_BF_END
NS_BF_END
namespace std
{
template<>
struct hash<Beefy::BfAstNodeList>
{
size_t operator()(const Beefy::BfAstNodeList& val) const
{
if (val.mList.mSize == 0)
return 0;
if (val.mList.mSize == 0)
return (size_t)val.mList.mVals[0];
return HashBytes((uint8*)val.mList.mVals, sizeof(Beefy::BfAstNode*) * val.mList.mSize);
}
};
}

View file

@ -2598,17 +2598,19 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
return bindType;
int64 nodeId = ((int64)parser->mDataId << 32) + node->GetSrcStart();
auto genericTypeBindings = mModule->mCurMethodState->GetRootMethodState()->mGenericTypeBindings;
if (mModule->mCurMethodInstance->mIsUnspecialized)
{
if (!bindType->IsGenericParam())
return bindType;
(*mModule->mCurMethodState->mGenericTypeBindings)[nodeId] = bindType;
(*genericTypeBindings)[nodeId] = bindType;
return bindType;
}
else
{
if (mModule->mCurMethodState->mGenericTypeBindings == NULL)
if (genericTypeBindings == NULL)
return bindType;
/*auto itr = mModule->mCurMethodState->mGenericTypeBindings->find(nodeId);
@ -2616,7 +2618,7 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
return itr->second;*/
BfType** typePtr = NULL;
if (mModule->mCurMethodState->mGenericTypeBindings->TryGetValue(nodeId, &typePtr))
if (genericTypeBindings->TryGetValue(nodeId, &typePtr))
return *typePtr;
return bindType;
@ -10780,10 +10782,24 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration*
}
BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget)
{
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
{
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
BfAstNodeList cacheNodeList;
cacheNodeList.mList.Add(lambdaBindExpr);
///
{
auto checkMethodState = mModule->mCurMethodState;
while (checkMethodState != NULL)
{
if (checkMethodState->mMixinState != NULL)
cacheNodeList.mList.Add(checkMethodState->mMixinState->mSource);
checkMethodState = checkMethodState->mPrevMethodState;
}
}
BfLambdaInstance* lambdaInstance = NULL;
if (rootMethodState->mLambdaCache.TryGetValue(lambdaBindExpr, &lambdaInstance))
if (rootMethodState->mLambdaCache.TryGetValue(cacheNodeList, &lambdaInstance))
return lambdaInstance;
static int sBindCount = 0;
@ -11628,7 +11644,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
methodState.Reset();
lambdaInstance = new BfLambdaInstance();
rootMethodState->mLambdaCache[lambdaBindExpr] = lambdaInstance;
rootMethodState->mLambdaCache[cacheNodeList] = lambdaInstance;
lambdaInstance->mDelegateTypeInstance = delegateTypeInstance;
lambdaInstance->mUseTypeInstance = useTypeInstance;
lambdaInstance->mClosureTypeInstance = closureTypeInst;

View file

@ -943,7 +943,7 @@ public:
Dictionary<String, BfLocalMethod*> mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method
Array<BfDeferredLocalMethod*> mDeferredLocalMethods;
OwnedVector<BfMixinState> mMixinStates;
Dictionary<BfAstNode*, BfLambdaInstance*> mLambdaCache;
Dictionary<BfAstNodeList, BfLambdaInstance*> mLambdaCache;
Array<BfLambdaInstance*> mDeferredLambdaInstances;
Array<BfIRValue> mSplatDecompAddrs;
BfDeferredLocalAssignData* mDeferredLocalAssignData;
@ -1955,5 +1955,5 @@ namespace std
{
return std::hash<Beefy::String>()(val.mLocalVar->mName);
}
};
};
}