mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Fix for lambda caching within mixin
This commit is contained in:
parent
08703e0cf4
commit
8abb72939b
3 changed files with 60 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "BeefySysLib/Common.h"
|
#include "BeefySysLib/Common.h"
|
||||||
#include "BeefySysLib/util/DLIList.h"
|
#include "BeefySysLib/util/DLIList.h"
|
||||||
#include "BeefySysLib/util/BumpAllocator.h"
|
#include "BeefySysLib/util/BumpAllocator.h"
|
||||||
|
#include "BeefySysLib/util/SizedArray.h"
|
||||||
#include "BfAstAllocator.h"
|
#include "BfAstAllocator.h"
|
||||||
#include "BfIRBuilder.h"
|
#include "BfIRBuilder.h"
|
||||||
|
|
||||||
|
@ -767,6 +768,23 @@ public:
|
||||||
|
|
||||||
class BfAstNode;
|
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>
|
template <typename T>
|
||||||
class BfChunkedArray
|
class BfChunkedArray
|
||||||
{
|
{
|
||||||
|
@ -3300,3 +3318,19 @@ BfAssignmentOp BfTokenToAssignmentOp(BfToken token);
|
||||||
bool BfIsCommentBlock(BfCommentKind commentKind);
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -2598,17 +2598,19 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
|
||||||
return bindType;
|
return bindType;
|
||||||
int64 nodeId = ((int64)parser->mDataId << 32) + node->GetSrcStart();
|
int64 nodeId = ((int64)parser->mDataId << 32) + node->GetSrcStart();
|
||||||
|
|
||||||
|
auto genericTypeBindings = mModule->mCurMethodState->GetRootMethodState()->mGenericTypeBindings;
|
||||||
|
|
||||||
if (mModule->mCurMethodInstance->mIsUnspecialized)
|
if (mModule->mCurMethodInstance->mIsUnspecialized)
|
||||||
{
|
{
|
||||||
if (!bindType->IsGenericParam())
|
if (!bindType->IsGenericParam())
|
||||||
return bindType;
|
return bindType;
|
||||||
|
|
||||||
(*mModule->mCurMethodState->mGenericTypeBindings)[nodeId] = bindType;
|
(*genericTypeBindings)[nodeId] = bindType;
|
||||||
return bindType;
|
return bindType;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mModule->mCurMethodState->mGenericTypeBindings == NULL)
|
if (genericTypeBindings == NULL)
|
||||||
return bindType;
|
return bindType;
|
||||||
|
|
||||||
/*auto itr = mModule->mCurMethodState->mGenericTypeBindings->find(nodeId);
|
/*auto itr = mModule->mCurMethodState->mGenericTypeBindings->find(nodeId);
|
||||||
|
@ -2616,7 +2618,7 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
|
||||||
return itr->second;*/
|
return itr->second;*/
|
||||||
|
|
||||||
BfType** typePtr = NULL;
|
BfType** typePtr = NULL;
|
||||||
if (mModule->mCurMethodState->mGenericTypeBindings->TryGetValue(nodeId, &typePtr))
|
if (genericTypeBindings->TryGetValue(nodeId, &typePtr))
|
||||||
return *typePtr;
|
return *typePtr;
|
||||||
|
|
||||||
return bindType;
|
return bindType;
|
||||||
|
@ -10782,8 +10784,22 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration*
|
||||||
BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget)
|
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;
|
BfLambdaInstance* lambdaInstance = NULL;
|
||||||
if (rootMethodState->mLambdaCache.TryGetValue(lambdaBindExpr, &lambdaInstance))
|
if (rootMethodState->mLambdaCache.TryGetValue(cacheNodeList, &lambdaInstance))
|
||||||
return lambdaInstance;
|
return lambdaInstance;
|
||||||
|
|
||||||
static int sBindCount = 0;
|
static int sBindCount = 0;
|
||||||
|
@ -11628,7 +11644,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
||||||
methodState.Reset();
|
methodState.Reset();
|
||||||
|
|
||||||
lambdaInstance = new BfLambdaInstance();
|
lambdaInstance = new BfLambdaInstance();
|
||||||
rootMethodState->mLambdaCache[lambdaBindExpr] = lambdaInstance;
|
rootMethodState->mLambdaCache[cacheNodeList] = lambdaInstance;
|
||||||
lambdaInstance->mDelegateTypeInstance = delegateTypeInstance;
|
lambdaInstance->mDelegateTypeInstance = delegateTypeInstance;
|
||||||
lambdaInstance->mUseTypeInstance = useTypeInstance;
|
lambdaInstance->mUseTypeInstance = useTypeInstance;
|
||||||
lambdaInstance->mClosureTypeInstance = closureTypeInst;
|
lambdaInstance->mClosureTypeInstance = closureTypeInst;
|
||||||
|
|
|
@ -943,7 +943,7 @@ public:
|
||||||
Dictionary<String, BfLocalMethod*> mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method
|
Dictionary<String, BfLocalMethod*> mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method
|
||||||
Array<BfDeferredLocalMethod*> mDeferredLocalMethods;
|
Array<BfDeferredLocalMethod*> mDeferredLocalMethods;
|
||||||
OwnedVector<BfMixinState> mMixinStates;
|
OwnedVector<BfMixinState> mMixinStates;
|
||||||
Dictionary<BfAstNode*, BfLambdaInstance*> mLambdaCache;
|
Dictionary<BfAstNodeList, BfLambdaInstance*> mLambdaCache;
|
||||||
Array<BfLambdaInstance*> mDeferredLambdaInstances;
|
Array<BfLambdaInstance*> mDeferredLambdaInstances;
|
||||||
Array<BfIRValue> mSplatDecompAddrs;
|
Array<BfIRValue> mSplatDecompAddrs;
|
||||||
BfDeferredLocalAssignData* mDeferredLocalAssignData;
|
BfDeferredLocalAssignData* mDeferredLocalAssignData;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue