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

Move mid-compile rebuild request into a work list

This commit is contained in:
Brian Fiete 2022-05-04 06:40:26 -07:00
parent b095f5b0d3
commit 9972ff32ab
6 changed files with 112 additions and 20 deletions

View file

@ -2592,8 +2592,12 @@ void BfCompiler::ProcessPurgatory(bool reifiedOnly)
{ {
auto module = type->GetModule(); auto module = type->GetModule();
if (module != NULL) if (module != NULL)
{
if (!module->mIsModuleMutable)
module->StartExtension();
module->PopulateType(type, BfPopulateType_Full); module->PopulateType(type, BfPopulateType_Full);
} }
}
if (reifiedOnly) if (reifiedOnly)
{ {

View file

@ -382,6 +382,43 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
didWork = true; didWork = true;
} }
// Do this before mPopulateTypeWorkList so we can populate any types that need rebuilding
// in the mPopulateTypeWorkList loop next - this is required for mFinishedModuleWorkList handling
for (int workIdx = 0; workIdx < (int)mMidCompileWorkList.size(); workIdx++)
{
//BP_ZONE("PWL_PopulateType");
if (IsCancellingAndYield())
break;
auto workItemRef = mMidCompileWorkList[workIdx];
if (workItemRef == NULL)
{
workIdx = mMidCompileWorkList.RemoveAt(workIdx);
continue;
}
BfType* type = workItemRef->mType;
String reason = workItemRef->mReason;
if ((onlyReifiedTypes) && (!type->IsReified()))
{
continue;
}
auto typeInst = type->ToTypeInstance();
if ((typeInst != NULL) && (resolveParser != NULL))
{
if (!typeInst->mTypeDef->GetLatest()->HasSource(resolveParser))
{
continue;
}
}
workIdx = mMidCompileWorkList.RemoveAt(workIdx);
RebuildDependentTypes_MidCompile(type->ToDependedType(), reason);
didWork = true;
}
for (int workIdx = 0; workIdx < (int)mPopulateTypeWorkList.size(); workIdx++) for (int workIdx = 0; workIdx < (int)mPopulateTypeWorkList.size(); workIdx++)
{ {
//BP_ZONE("PWL_PopulateType"); //BP_ZONE("PWL_PopulateType");
@ -487,6 +524,9 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
auto typeInst = methodSpecializationRequest.mType->ToTypeInstance(); auto typeInst = methodSpecializationRequest.mType->ToTypeInstance();
if (typeInst->IsDeleting())
continue;
BfMethodDef* methodDef = NULL; BfMethodDef* methodDef = NULL;
if (methodSpecializationRequest.mForeignType != NULL) if (methodSpecializationRequest.mForeignType != NULL)
{ {
@ -533,6 +573,8 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
bool wantProcessMethod = methodInstance != NULL; bool wantProcessMethod = methodInstance != NULL;
if ((workItem->mFromModuleRebuildIdx != -1) && (workItem->mFromModuleRebuildIdx != module->mRebuildIdx)) if ((workItem->mFromModuleRebuildIdx != -1) && (workItem->mFromModuleRebuildIdx != module->mRebuildIdx))
wantProcessMethod = false; wantProcessMethod = false;
else if (workItem->mType->IsDeleting())
wantProcessMethod = false;
if (methodInstance != NULL) if (methodInstance != NULL)
BF_ASSERT(methodInstance->mMethodProcessRequest == workItem); BF_ASSERT(methodInstance->mMethodProcessRequest == workItem);
@ -710,6 +752,11 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
dupMethodInstance.mInCEMachine = false; // Only have the original one dupMethodInstance.mInCEMachine = false; // Only have the original one
BF_ASSERT(module->mIsReified); // We should only bother inlining in reified modules BF_ASSERT(module->mIsReified); // We should only bother inlining in reified modules
bool wantProcessMethod = true;
if (owner->IsDeleting())
wantProcessMethod = false;
if (wantProcessMethod)
{ {
// These errors SHOULD be duplicates, but if we have no other errors at all then we don't ignoreErrors, which // These errors SHOULD be duplicates, but if we have no other errors at all then we don't ignoreErrors, which
// may help unveil some kinds of compiler bugs // may help unveil some kinds of compiler bugs
@ -1201,8 +1248,27 @@ void BfContext::RebuildDependentTypes(BfDependedType* dType)
TypeMethodSignaturesChanged(typeInst); TypeMethodSignaturesChanged(typeInst);
} }
void BfContext::QueueMidCompileRebuildDependentTypes(BfDependedType* dType, const String& reason)
{
BfLogSysM("QueueMidCompileRebuildDependentTypes Type:%p Reason:%s\n", dType, reason.c_str());
auto workEntry = mMidCompileWorkList.Alloc();
workEntry->mType = dType;
workEntry->mReason = reason;
}
void BfContext::RebuildDependentTypes_MidCompile(BfDependedType* dType, const String& reason) void BfContext::RebuildDependentTypes_MidCompile(BfDependedType* dType, const String& reason)
{ {
BF_ASSERT(!dType->IsDeleting());
auto module = dType->GetModule();
if ((module != NULL) && (!module->mIsSpecialModule))
{
BF_ASSERT(!module->mIsDeleting);
BF_ASSERT(!module->mOwnedTypeInstances.IsEmpty());
}
dType->mRebuildFlags = (BfTypeRebuildFlags)(dType->mRebuildFlags | BfTypeRebuildFlag_ChangedMidCompile); dType->mRebuildFlags = (BfTypeRebuildFlags)(dType->mRebuildFlags | BfTypeRebuildFlag_ChangedMidCompile);
int prevDeletedTypes = mCompiler->mStats.mTypesDeleted; int prevDeletedTypes = mCompiler->mStats.mTypesDeleted;
if (mCompiler->mIsResolveOnly) if (mCompiler->mIsResolveOnly)
@ -1716,16 +1782,16 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds)
} }
else else
{ {
auto itr = std::find(module->mOwnedTypeInstances.begin(), module->mOwnedTypeInstances.end(), typeInst); module->mOwnedTypeInstances.Remove(typeInst);
module->mOwnedTypeInstances.erase(itr);
if ((module->mOwnedTypeInstances.size() == 0) && (module != mScratchModule)) if ((module->mOwnedTypeInstances.size() == 0) && (module != mScratchModule))
{ {
BfLogSysM("Setting module mIsDeleting %p due to mOwnedTypeInstances being empty\n", module);
// This module is no longer needed // This module is no longer needed
module->RemoveModuleData(); module->RemoveModuleData();
module->mIsDeleting = true; module->mIsDeleting = true;
auto itr = std::find(mModules.begin(), mModules.end(), module); mModules.Remove(module);
mModules.erase(itr);
// This was only needed for 'zombie modules', which we don't need anymore? // This was only needed for 'zombie modules', which we don't need anymore?
// To avoid linking errors. Used instead of directly removing from mModules. // To avoid linking errors. Used instead of directly removing from mModules.
@ -2980,6 +3046,7 @@ void BfContext::RemoveInvalidWorkItems()
// so we're passing false in here now. Don't just switch it back and forth - find why 'false' was causing an issue. // so we're passing false in here now. Don't just switch it back and forth - find why 'false' was causing an issue.
// Same with mMethodSpecializationWorkList // Same with mMethodSpecializationWorkList
DoRemoveInvalidWorkItems<BfTypeProcessRequest>(this, mPopulateTypeWorkList, false); DoRemoveInvalidWorkItems<BfTypeProcessRequest>(this, mPopulateTypeWorkList, false);
DoRemoveInvalidWorkItems<BfMidCompileRequest>(this, mMidCompileWorkList, false);
DoRemoveInvalidWorkItems<BfMethodSpecializationRequest>(this, mMethodSpecializationWorkList, false/*true*/); DoRemoveInvalidWorkItems<BfMethodSpecializationRequest>(this, mMethodSpecializationWorkList, false/*true*/);
DoRemoveInvalidWorkItems<BfTypeRefVerifyRequest>(this, mTypeRefVerifyWorkList, false); DoRemoveInvalidWorkItems<BfTypeRefVerifyRequest>(this, mTypeRefVerifyWorkList, false);

View file

@ -113,6 +113,12 @@ public:
BfAstNode* mRefNode; BfAstNode* mRefNode;
}; };
class BfMidCompileRequest : public BfWorkListEntry
{
public:
String mReason;
};
struct BfStringPoolEntry struct BfStringPoolEntry
{ {
String mString; String mString;
@ -397,6 +403,7 @@ public:
WorkQueue<BfTypeProcessRequest> mPopulateTypeWorkList; WorkQueue<BfTypeProcessRequest> mPopulateTypeWorkList;
WorkQueue<BfMethodSpecializationRequest> mMethodSpecializationWorkList; WorkQueue<BfMethodSpecializationRequest> mMethodSpecializationWorkList;
WorkQueue<BfTypeRefVerifyRequest> mTypeRefVerifyWorkList; WorkQueue<BfTypeRefVerifyRequest> mTypeRefVerifyWorkList;
WorkQueue<BfMidCompileRequest> mMidCompileWorkList;
PtrWorkQueue<BfModule*> mFinishedSlotAwaitModuleWorkList; PtrWorkQueue<BfModule*> mFinishedSlotAwaitModuleWorkList;
PtrWorkQueue<BfModule*> mFinishedModuleWorkList; PtrWorkQueue<BfModule*> mFinishedModuleWorkList;
bool mHasReifiedQueuedRebuildTypes; bool mHasReifiedQueuedRebuildTypes;
@ -476,6 +483,7 @@ public:
void ValidateDependencies(); void ValidateDependencies();
void RebuildType(BfType* type, bool deleteOnDemandTypes = true, bool rebuildModule = true, bool placeSpecializiedInPurgatory = true); void RebuildType(BfType* type, bool deleteOnDemandTypes = true, bool rebuildModule = true, bool placeSpecializiedInPurgatory = true);
void RebuildDependentTypes(BfDependedType* dType); void RebuildDependentTypes(BfDependedType* dType);
void QueueMidCompileRebuildDependentTypes(BfDependedType* dType, const String& reason);
void RebuildDependentTypes_MidCompile(BfDependedType* dType, const String& reason); void RebuildDependentTypes_MidCompile(BfDependedType* dType, const String& reason);
bool CanRebuild(BfType* type); bool CanRebuild(BfType* type);
void TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChange); void TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChange);

View file

@ -1225,8 +1225,8 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
/*if (mCompiler->mIsResolveOnly) /*if (mCompiler->mIsResolveOnly)
BF_ASSERT(mIsResolveOnly);*/ BF_ASSERT(mIsResolveOnly);*/
mBfIRBuilder = new BfIRBuilder(this); mBfIRBuilder = new BfIRBuilder(this);
BfLogSysM("Created mBfIRBuilder %p in %p %s Reified: %d\n", mBfIRBuilder, this, mModuleName.c_str(), mIsReified); BfLogSysM("Created mBfIRBuilder %p in %p %s Reified: %d\n", mBfIRBuilder, this, mModuleName.c_str(), mIsReified);
SetupIRBuilder(dbgVerifyCodeGen); SetupIRBuilder(dbgVerifyCodeGen);
} }
@ -1509,8 +1509,10 @@ BfTypedValue BfModule::GetFakeTypedValue(BfType* type)
// This is a conservative "IsValueless", since it's not an error to use a fakeVal even if we don't need one // This is a conservative "IsValueless", since it's not an error to use a fakeVal even if we don't need one
if (type->mSize == 0) if (type->mSize == 0)
return BfTypedValue(BfIRValue::sValueless, type); return BfTypedValue(BfIRValue::sValueless, type);
else else if (mBfIRBuilder != NULL)
return BfTypedValue(mBfIRBuilder->GetFakeVal(), type); return BfTypedValue(mBfIRBuilder->GetFakeVal(), type);
else
return BfTypedValue(BfIRValue(BfIRValueFlags_Value, -1), type);
} }
BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind) BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind)

View file

@ -286,7 +286,7 @@ bool BfModule::FinishGenericParams(BfType* resolvedTypeRef)
auto genericExtensionInfo = genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo; auto genericExtensionInfo = genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo;
if ((extensionCount > 0) && (!prevConstraintsPassedSet.IsEmpty()) && (genericExtensionInfo->mConstraintsPassedSet != prevConstraintsPassedSet)) if ((extensionCount > 0) && (!prevConstraintsPassedSet.IsEmpty()) && (genericExtensionInfo->mConstraintsPassedSet != prevConstraintsPassedSet))
{ {
mContext->RebuildDependentTypes_MidCompile(genericTypeInst, "mConstraintsPassedSet changed"); mContext->QueueMidCompileRebuildDependentTypes(genericTypeInst, "mConstraintsPassedSet changed");
} }
} }
else else
@ -3114,7 +3114,7 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias)
aliasToType = NULL; aliasToType = NULL;
if ((typeAlias->mAliasToType != NULL) && (typeAlias->mAliasToType != aliasToType) && (!typeAlias->mDependencyMap.IsEmpty())) if ((typeAlias->mAliasToType != NULL) && (typeAlias->mAliasToType != aliasToType) && (!typeAlias->mDependencyMap.IsEmpty()))
mContext->RebuildDependentTypes_MidCompile(typeAlias, "type alias remapped"); mContext->QueueMidCompileRebuildDependentTypes(typeAlias, "type alias remapped");
typeAlias->mAliasToType = aliasToType; typeAlias->mAliasToType = aliasToType;
@ -4792,7 +4792,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (!typeInstance->mCeTypeInfo->mNext->mFailed) if (!typeInstance->mCeTypeInfo->mNext->mFailed)
{ {
if ((typeInstance->mCeTypeInfo->mHash != typeInstance->mCeTypeInfo->mNext->mHash) && (!typeInstance->mCeTypeInfo->mHash.IsZero())) if ((typeInstance->mCeTypeInfo->mHash != typeInstance->mCeTypeInfo->mNext->mHash) && (!typeInstance->mCeTypeInfo->mHash.IsZero()))
mContext->RebuildDependentTypes_MidCompile(typeInstance, "comptime hash changed"); mContext->QueueMidCompileRebuildDependentTypes(typeInstance, "comptime hash changed");
typeInstance->mCeTypeInfo->mEmitSourceMap = typeInstance->mCeTypeInfo->mNext->mEmitSourceMap; typeInstance->mCeTypeInfo->mEmitSourceMap = typeInstance->mCeTypeInfo->mNext->mEmitSourceMap;
typeInstance->mCeTypeInfo->mOnCompileMap = typeInstance->mCeTypeInfo->mNext->mOnCompileMap; typeInstance->mCeTypeInfo->mOnCompileMap = typeInstance->mCeTypeInfo->mNext->mOnCompileMap;
typeInstance->mCeTypeInfo->mTypeIFaceMap = typeInstance->mCeTypeInfo->mNext->mTypeIFaceMap; typeInstance->mCeTypeInfo->mTypeIFaceMap = typeInstance->mCeTypeInfo->mNext->mTypeIFaceMap;
@ -4806,7 +4806,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
// Removed emissions // Removed emissions
if (!typeInstance->mCeTypeInfo->mHash.IsZero()) if (!typeInstance->mCeTypeInfo->mHash.IsZero())
mContext->RebuildDependentTypes_MidCompile(typeInstance, "comptime hash changed"); mContext->QueueMidCompileRebuildDependentTypes(typeInstance, "comptime hash changed");
typeInstance->mCeTypeInfo->mEmitSourceMap.Clear(); typeInstance->mCeTypeInfo->mEmitSourceMap.Clear();
typeInstance->mCeTypeInfo->mOnCompileMap.Clear(); typeInstance->mCeTypeInfo->mOnCompileMap.Clear();
typeInstance->mCeTypeInfo->mTypeIFaceMap.Clear(); typeInstance->mCeTypeInfo->mTypeIFaceMap.Clear();

View file

@ -1833,6 +1833,7 @@ public:
#ifdef _DEBUG #ifdef _DEBUG
#ifdef BF_PLATFORM_WINDOWS #ifdef BF_PLATFORM_WINDOWS
#define BF_WANTS_LOG_HI
#define BF_WANTS_LOG #define BF_WANTS_LOG
#define BF_WANTS_LOG_SYS #define BF_WANTS_LOG_SYS
//#define BF_WANTS_LOG2 //#define BF_WANTS_LOG2
@ -1843,7 +1844,9 @@ public:
#endif #endif
#else #else
#define BF_WANTS_LOG_HI
//#define BF_WANTS_LOG //#define BF_WANTS_LOG
//#define BF_WANTS_LOG_SYS
//#define BF_WANTS_LOG2 //#define BF_WANTS_LOG2
//#define BF_WANTS_LOG_CLANG //#define BF_WANTS_LOG_CLANG
//#define BF_WANTS_LOG_DBGEXPR //#define BF_WANTS_LOG_DBGEXPR
@ -1866,6 +1869,14 @@ public:
#define BfLogSysM(...) {} // Nothing #define BfLogSysM(...) {} // Nothing
#endif #endif
#ifdef BF_WANTS_LOG_HI
#define BfLogSysHI(sys, fmt, ...) DoBfLog((sys)->mIsResolveOnly ? 1 : 2, fmt, ##__VA_ARGS__)
#define BfLogSysMHI(fmt, ...) DoBfLog(mSystem->mIsResolveOnly ? 1 : 2, fmt, ##__VA_ARGS__)
#else
#define BfLogSysHI(...) {} // Nothing
#define BfLogSysMHI(...) {} // Nothing
#endif
#ifdef BF_WANTS_LOG_CLANG #ifdef BF_WANTS_LOG_CLANG
//#define BfLogClang(fmt) DoBfLog(fmt) //#define BfLogClang(fmt) DoBfLog(fmt)
#define BfLogClang(fmt, ...) DoBfLog(0, fmt, ##__VA_ARGS__) #define BfLogClang(fmt, ...) DoBfLog(0, fmt, ##__VA_ARGS__)