mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Cache sized array length during typeref resolution
This commit is contained in:
parent
b1023ff36a
commit
0cf3e2283d
7 changed files with 20 additions and 15 deletions
|
@ -283,6 +283,9 @@ namespace System
|
|||
[LinkName("#CompileRev")]
|
||||
public static extern int32 CompileRev;
|
||||
|
||||
[LinkName("#NextId")]
|
||||
public static extern int64 NextId;
|
||||
|
||||
[Comptime(ConstEval=true)]
|
||||
public static void Assert(bool cond)
|
||||
{
|
||||
|
|
|
@ -353,7 +353,8 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
|
|||
mIsResolveOnly = isResolveOnly;
|
||||
mResolvePassData = NULL;
|
||||
mPassInstance = NULL;
|
||||
mRevision = 0;
|
||||
mRevision = 0;
|
||||
mUniqueId = 0;
|
||||
mLastRevisionAborted = false;
|
||||
gBfCompiler = this;
|
||||
mSystem = bfSystem;
|
||||
|
|
|
@ -323,7 +323,8 @@ public:
|
|||
bool mIsResolveOnly;
|
||||
BfResolvePassData* mResolvePassData;
|
||||
Dictionary<String, Array<int>> mAttributeTypeOptionMap;
|
||||
int mRevision;
|
||||
int mRevision;
|
||||
int64 mUniqueId;
|
||||
bool mLastRevisionAborted;
|
||||
BfContext* mContext;
|
||||
BfCodeGen mCodeGen;
|
||||
|
|
|
@ -14615,6 +14615,10 @@ BfTypedValue BfModule::GetCompilerFieldValue(const StringImpl& str)
|
|||
{
|
||||
return BfTypedValue(mBfIRBuilder->CreateConst(BfTypeCode_Int32, mCompiler->mRevision), GetPrimitiveType(BfTypeCode_Int32));
|
||||
}
|
||||
if (str == "#NextId")
|
||||
{
|
||||
return BfTypedValue(mBfIRBuilder->CreateConst(BfTypeCode_Int64, ++mCompiler->mUniqueId), GetPrimitiveType(BfTypeCode_Int32));
|
||||
}
|
||||
if (str == "#ModuleName")
|
||||
{
|
||||
return BfTypedValue(GetStringObjectValue(mModuleName), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||
|
|
|
@ -11272,16 +11272,10 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
|||
BfExpression* sizeExpr = BfNodeDynCast<BfExpression>(arrayTypeRef->mParams[0]);
|
||||
BF_ASSERT(sizeExpr != NULL);
|
||||
if (sizeExpr != NULL)
|
||||
{
|
||||
BfConstResolver constResolver(this);
|
||||
{
|
||||
BfType* intType = GetPrimitiveType(BfTypeCode_IntPtr);
|
||||
constResolver.mExpectingType = intType;
|
||||
constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
|
||||
BfTypedValue typedVal;
|
||||
{
|
||||
SetAndRestoreValue<bool> prevIgnoreErrors(mIgnoreErrors, true);
|
||||
typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
|
||||
}
|
||||
lookupCtx.mResolvedValueMap.TryGetValue(sizeExpr, &typedVal);
|
||||
if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
|
||||
{
|
||||
BfUnknownSizedArrayType* arrayType = new BfUnknownSizedArrayType();
|
||||
|
|
|
@ -3545,8 +3545,10 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa
|
|||
constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
|
||||
constResolver.mExpectingType = intType;
|
||||
BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
|
||||
|
||||
if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
|
||||
{
|
||||
ctx->mResolvedValueMap[sizeExpr] = typedVal;
|
||||
int elemHash = Hash(typedVal.mType, ctx, BfHashFlag_None, hashSeed);
|
||||
hashVal = ((hashVal ^ elemHash) << 5) - hashVal;
|
||||
return hashVal;
|
||||
|
@ -3558,6 +3560,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa
|
|||
SetAndRestoreValue<bool> prevIgnoreWrites(ctx->mModule->mBfIRBuilder->mIgnoreWrites, true);
|
||||
typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType);
|
||||
}
|
||||
ctx->mResolvedValueMap[sizeExpr] = typedVal;
|
||||
|
||||
if (typedVal)
|
||||
{
|
||||
|
@ -4804,12 +4807,9 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
BF_ASSERT(sizeExpr != NULL);
|
||||
if (sizeExpr != NULL)
|
||||
{
|
||||
SetAndRestoreValue<bool> prevIgnoreError(ctx->mModule->mIgnoreErrors, true);
|
||||
BfConstResolver constResolver(ctx->mModule);
|
||||
BfType* intType = ctx->mModule->GetPrimitiveType(BfTypeCode_IntPtr);
|
||||
constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
|
||||
constResolver.mExpectingType = intType;
|
||||
BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
|
||||
BfTypedValue typedVal;
|
||||
ctx->mResolvedValueMap.TryGetValue(sizeExpr, &typedVal);
|
||||
if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
|
||||
{
|
||||
if (!lhs->IsUnknownSizedArrayType())
|
||||
|
@ -4820,6 +4820,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
}
|
||||
if (typedVal)
|
||||
typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType);
|
||||
|
||||
if (typedVal)
|
||||
{
|
||||
if (lhs->IsUnknownSizedArrayType())
|
||||
|
|
|
@ -2622,6 +2622,7 @@ public:
|
|||
BfTypeInstance* mRootOuterTypeInstance;
|
||||
BfType* mRootResolvedType;
|
||||
Dictionary<BfAstNode*, BfType*> mResolvedTypeMap;
|
||||
Dictionary<BfAstNode*, BfTypedValue> mResolvedValueMap;
|
||||
BfResolveTypeRefFlags mResolveFlags;
|
||||
BfCallingConvention mCallingConvention;
|
||||
bool mHadVar;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue