1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +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")] [LinkName("#CompileRev")]
public static extern int32 CompileRev; public static extern int32 CompileRev;
[LinkName("#NextId")]
public static extern int64 NextId;
[Comptime(ConstEval=true)] [Comptime(ConstEval=true)]
public static void Assert(bool cond) public static void Assert(bool cond)
{ {

View file

@ -354,6 +354,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
mResolvePassData = NULL; mResolvePassData = NULL;
mPassInstance = NULL; mPassInstance = NULL;
mRevision = 0; mRevision = 0;
mUniqueId = 0;
mLastRevisionAborted = false; mLastRevisionAborted = false;
gBfCompiler = this; gBfCompiler = this;
mSystem = bfSystem; mSystem = bfSystem;

View file

@ -324,6 +324,7 @@ public:
BfResolvePassData* mResolvePassData; BfResolvePassData* mResolvePassData;
Dictionary<String, Array<int>> mAttributeTypeOptionMap; Dictionary<String, Array<int>> mAttributeTypeOptionMap;
int mRevision; int mRevision;
int64 mUniqueId;
bool mLastRevisionAborted; bool mLastRevisionAborted;
BfContext* mContext; BfContext* mContext;
BfCodeGen mCodeGen; 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)); 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") if (str == "#ModuleName")
{ {
return BfTypedValue(GetStringObjectValue(mModuleName), ResolveTypeDef(mCompiler->mStringTypeDef)); return BfTypedValue(GetStringObjectValue(mModuleName), ResolveTypeDef(mCompiler->mStringTypeDef));

View file

@ -11273,15 +11273,9 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
BF_ASSERT(sizeExpr != NULL); BF_ASSERT(sizeExpr != NULL);
if (sizeExpr != NULL) if (sizeExpr != NULL)
{ {
BfConstResolver constResolver(this);
BfType* intType = GetPrimitiveType(BfTypeCode_IntPtr); BfType* intType = GetPrimitiveType(BfTypeCode_IntPtr);
constResolver.mExpectingType = intType;
constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
BfTypedValue typedVal; BfTypedValue typedVal;
{ lookupCtx.mResolvedValueMap.TryGetValue(sizeExpr, &typedVal);
SetAndRestoreValue<bool> prevIgnoreErrors(mIgnoreErrors, true);
typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
}
if (typedVal.mKind == BfTypedValueKind_GenericConstValue) if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
{ {
BfUnknownSizedArrayType* arrayType = new BfUnknownSizedArrayType(); 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.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
constResolver.mExpectingType = intType; constResolver.mExpectingType = intType;
BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize); BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
if (typedVal.mKind == BfTypedValueKind_GenericConstValue) if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
{ {
ctx->mResolvedValueMap[sizeExpr] = typedVal;
int elemHash = Hash(typedVal.mType, ctx, BfHashFlag_None, hashSeed); int elemHash = Hash(typedVal.mType, ctx, BfHashFlag_None, hashSeed);
hashVal = ((hashVal ^ elemHash) << 5) - hashVal; hashVal = ((hashVal ^ elemHash) << 5) - hashVal;
return hashVal; return hashVal;
@ -3558,6 +3560,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa
SetAndRestoreValue<bool> prevIgnoreWrites(ctx->mModule->mBfIRBuilder->mIgnoreWrites, true); SetAndRestoreValue<bool> prevIgnoreWrites(ctx->mModule->mBfIRBuilder->mIgnoreWrites, true);
typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType); typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType);
} }
ctx->mResolvedValueMap[sizeExpr] = typedVal;
if (typedVal) if (typedVal)
{ {
@ -4804,12 +4807,9 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
BF_ASSERT(sizeExpr != NULL); BF_ASSERT(sizeExpr != NULL);
if (sizeExpr != NULL) if (sizeExpr != NULL)
{ {
SetAndRestoreValue<bool> prevIgnoreError(ctx->mModule->mIgnoreErrors, true);
BfConstResolver constResolver(ctx->mModule);
BfType* intType = ctx->mModule->GetPrimitiveType(BfTypeCode_IntPtr); BfType* intType = ctx->mModule->GetPrimitiveType(BfTypeCode_IntPtr);
constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue); BfTypedValue typedVal;
constResolver.mExpectingType = intType; ctx->mResolvedValueMap.TryGetValue(sizeExpr, &typedVal);
BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize);
if (typedVal.mKind == BfTypedValueKind_GenericConstValue) if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
{ {
if (!lhs->IsUnknownSizedArrayType()) if (!lhs->IsUnknownSizedArrayType())
@ -4820,6 +4820,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
} }
if (typedVal) if (typedVal)
typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType); typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType);
if (typedVal) if (typedVal)
{ {
if (lhs->IsUnknownSizedArrayType()) if (lhs->IsUnknownSizedArrayType())

View file

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