1
0
Fork 0
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:
Brian Fiete 2022-06-24 07:35:02 -07:00
parent b1023ff36a
commit 0cf3e2283d
7 changed files with 20 additions and 15 deletions

View file

@ -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)
{

View file

@ -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;

View file

@ -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;

View file

@ -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));

View file

@ -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();

View file

@ -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())

View file

@ -2622,6 +2622,7 @@ public:
BfTypeInstance* mRootOuterTypeInstance;
BfType* mRootResolvedType;
Dictionary<BfAstNode*, BfType*> mResolvedTypeMap;
Dictionary<BfAstNode*, BfTypedValue> mResolvedValueMap;
BfResolveTypeRefFlags mResolveFlags;
BfCallingConvention mCallingConvention;
bool mHadVar;