1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Extensive runtime refactor to reduce generated executable sizes

This commit is contained in:
Brian Fiete 2024-03-16 07:23:29 -04:00
parent 4e750a7e1a
commit ddd9b1b218
74 changed files with 2514 additions and 717 deletions

View file

@ -420,55 +420,74 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
didWork = true;
}
for (int workIdx = 0; workIdx < (int)mPopulateTypeWorkList.size(); workIdx++)
for (int populatePass = 0; populatePass < 2; populatePass++)
{
//BP_ZONE("PWL_PopulateType");
if (IsCancellingAndYield())
break;
auto workItemRef = mPopulateTypeWorkList[workIdx];
if (workItemRef == NULL)
for (int workIdx = 0; workIdx < (int)mPopulateTypeWorkList.size(); workIdx++)
{
workIdx = mPopulateTypeWorkList.RemoveAt(workIdx);
continue;
}
//BP_ZONE("PWL_PopulateType");
if (IsCancellingAndYield())
break;
if (!mMidCompileWorkList.IsEmpty())
{
// Let these mid-compiles occur as soon as possible
break;
}
BfType* type = workItemRef->mType;
bool rebuildType = workItemRef->mRebuildType;
auto workItemRef = mPopulateTypeWorkList[workIdx];
if (workItemRef == NULL)
{
workIdx = mPopulateTypeWorkList.RemoveAt(workIdx);
continue;
}
if ((onlyReifiedTypes) && (!type->IsReified()))
{
continue;
}
BfType* type = workItemRef->mType;
bool rebuildType = workItemRef->mRebuildType;
auto typeInst = type->ToTypeInstance();
if ((typeInst != NULL) && (resolveParser != NULL))
{
if (!typeInst->mTypeDef->GetLatest()->HasSource(resolveParser))
if ((onlyReifiedTypes) && (!type->IsReified()))
{
continue;
}
// We want to resolve type aliases first, allowing possible mMidCompileWorkList entries
int wantPass = type->IsTypeAlias() ? 0 : 1;
if (populatePass != wantPass)
continue;
auto typeInst = type->ToTypeInstance();
if ((typeInst != NULL) && (resolveParser != NULL))
{
if (!typeInst->mTypeDef->GetLatest()->HasSource(resolveParser))
{
continue;
}
}
workIdx = mPopulateTypeWorkList.RemoveAt(workIdx);
if (rebuildType)
RebuildType(type);
BF_ASSERT(this == type->mContext);
auto useModule = type->GetModule();
if (useModule == NULL)
{
if (mCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude)
useModule = mScratchModule;
else
useModule = mUnreifiedModule;
}
if (!type->IsDeleting())
useModule->PopulateType(type, BfPopulateType_Full);
mCompiler->mStats.mQueuedTypesProcessed++;
mCompiler->UpdateCompletion();
didWork = true;
}
}
workIdx = mPopulateTypeWorkList.RemoveAt(workIdx);
if (rebuildType)
RebuildType(type);
BF_ASSERT(this == type->mContext);
auto useModule = type->GetModule();
if (useModule == NULL)
{
if (mCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude)
useModule = mScratchModule;
else
useModule = mUnreifiedModule;
}
if (!type->IsDeleting())
useModule->PopulateType(type, BfPopulateType_Full);
mCompiler->mStats.mQueuedTypesProcessed++;
mCompiler->UpdateCompletion();
didWork = true;
if ((!mMidCompileWorkList.IsEmpty()) && (didWork))
{
// Let the mid-compile occur ASAP
continue;
}
for (int workIdx = 0; workIdx < (int)mTypeRefVerifyWorkList.size(); workIdx++)
@ -1984,6 +2003,7 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds)
}
else if (dependentTypeInst != NULL)
{
mGhostDependencies.Add(type);
// This keeps us from crashing from accessing deleted types on subsequent compiles
mFailTypes.TryAdd(dependentTypeInst, BfFailKind_Normal);
}
@ -2396,6 +2416,38 @@ void BfContext::UpdateRevisedTypes()
}
}
// Handle these "mid-compiles" now so we handle them as early-stage
BfParser* resolveParser = NULL;
if ((mCompiler->mResolvePassData != NULL) && (!mCompiler->mResolvePassData->mParsers.IsEmpty()))
resolveParser = mCompiler->mResolvePassData->mParsers[0];
for (int workIdx = 0; workIdx < (int)mMidCompileWorkList.size(); workIdx++)
{
auto workItemRef = mMidCompileWorkList[workIdx];
if (workItemRef == NULL)
{
workIdx = mMidCompileWorkList.RemoveAt(workIdx);
continue;
}
BfType* type = workItemRef->mType;
String reason = workItemRef->mReason;
auto typeInst = type->ToTypeInstance();
if ((typeInst != NULL) && (resolveParser != NULL))
{
if (!typeInst->mTypeDef->GetLatest()->HasSource(resolveParser))
{
continue;
}
}
workIdx = mMidCompileWorkList.RemoveAt(workIdx);
BfLogSysM("Handling prior-revision MidCompile on type %s in early-stage UpdateRevisedTypes\n", type);
RebuildDependentTypes(type->ToDependedType());
//RebuildDependentTypes_MidCompile(type->ToDependedType(), reason);
}
for (auto typeInst : defEmitParentCheckQueue)
{
if (typeInst->IsDeleting())
@ -2675,6 +2727,8 @@ void BfContext::UpdateRevisedTypes()
RebuildType(type);
}
}
BfLogSysM("BfContext::UpdateRevisedTypes done.\n");
}
void BfContext::VerifyTypeLookups(BfTypeInstance* typeInst)
@ -3459,6 +3513,7 @@ void BfContext::Cleanup()
}
}
mTypeGraveyard.Clear();
mGhostDependencies.Clear();
if (!mDeletingModules.IsEmpty())
{