1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed dependency issues, added some dependency validation

This commit is contained in:
Brian Fiete 2019-11-02 06:07:16 -07:00
parent b0f50fbda6
commit 558f8678e1
5 changed files with 76 additions and 19 deletions

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

View file

@ -1500,6 +1500,16 @@ void BeIRCodeGen::HandleNextCmd()
BF_ASSERT(ptrType->IsPointer());
// We call via a function pointer so there's never a reason to allow loading of a funcPtr
BF_ASSERT(((BePointerType*)ptrType)->mElementType->mTypeCode != BeTypeCode_Function);
// Disallow loading from a NULL constant
if (val->GetTypeId() == BeConstant::TypeId)
{
if (auto constant = BeValueDynCast<BeConstant>(val))
{
BF_ASSERT(constant->mTarget != NULL);
}
}
#endif
CMD_PARAM(bool, isVolatile);
SetResult(curId, mBeModule->CreateLoad(val, isVolatile));
@ -1511,6 +1521,15 @@ void BeIRCodeGen::HandleNextCmd()
CMD_PARAM(int, alignment);
CMD_PARAM(bool, isVolatile);
#ifdef _DEBUG
// Disallow loading from a NULL constant
if (val->GetTypeId() == BeConstant::TypeId)
{
if (auto constant = BeValueDynCast<BeConstant>(val))
{
BF_ASSERT(constant->mTarget != NULL);
}
}
auto ptrType = val->GetType();
BF_ASSERT(ptrType->IsPointer());
#endif

View file

@ -1115,7 +1115,9 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
}
}
vdataHashCtx.MixinStr(module->mModuleName);
vdataHashCtx.Mixin(typeInst->mTypeDef->mSignatureHash);
vdataHashCtx.Mixin(module->mHasForceLinkMarker);
for (auto iface : typeInst->mInterfaces)
{
@ -2064,7 +2066,7 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork)
// If we're deleting the type, OR the dependency of the type has been removed.
// We detect a removed dependency by the dependent type changing but the dependency revision
// is older than the dependent type.
BfLogSysM("Removing old dependent %p from %p\n", dependentType, typeInst);
BfLogSysM("Removing old dependent %p from %p\n", dependentType, depType);
itr = depType->mDependencyMap.erase(itr);
}
else
@ -2171,7 +2173,9 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork)
if (deleteQueue.size() != 0)
{
mContext->ValidateDependencies();
mContext->UpdateAfterDeletingTypes();
mContext->ValidateDependencies();
}
}
@ -2964,13 +2968,6 @@ void BfCompiler::UpdateRevisedTypes()
compositeTypeDef->mFullNameEx = rootTypeDef->mFullNameEx;
compositeTypeDef->mIsCombinedPartial = true;
// if (rootTypeDef->IsGlobalsContainer())
// {
// //NOP;
// auto didAdd = mSystem->mGlobalsMap.TryAdd(rootTypeDef->mNamespace, compositeTypeDef);
// BF_ASSERT(didAdd);
// }
for (auto prevGenericParam : rootTypeDef->mGenericParamDefs)
{
BfGenericParamDef* copiedGenericParam = new BfGenericParamDef();
@ -2979,8 +2976,6 @@ void BfCompiler::UpdateRevisedTypes()
}
mSystem->mTypeDefs.AddAfter(compositeTypeDef, rootTypeDefEntry);
// compositeTypeDef->mNext = rootTypeDef->mNext;
// rootTypeDef->mNext = compositeTypeDef;
partialsHadChanges = true;
hadSignatureChange = true;
compositeIsNew = true;
@ -3249,8 +3244,12 @@ void BfCompiler::UpdateRevisedTypes()
mContext->UpdateRevisedTypes();
mContext->VerifyTypeLookups();
mContext->ValidateDependencies();
if (mStats.mTypesDeleted != 0)
{
mContext->UpdateAfterDeletingTypes();
mContext->ValidateDependencies();
}
mContext->RemoveInvalidWorkItems();
for (auto typeDef : mSystem->mTypeDefs)
@ -6253,6 +6252,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
if ((!IsHotCompile()) && (!mCanceling))
ClearUnusedStringPoolEntries();
mContext->ValidateDependencies();
mContext->UpdateAfterDeletingTypes();
}
@ -6487,6 +6487,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
bool didCancel = mCanceling && hasRequiredTypes;
mCanceling = false;
mContext->ValidateDependencies();
return !didCancel;
}

View file

@ -767,6 +767,36 @@ void BfContext::AddTypeToWorkList(BfType* type)
}
}
void BfContext::ValidateDependencies()
{
#if _DEBUG
BP_ZONE("BfContext::ValidateDependencies");
BfLogSysM("ValidateDependencies\n");
bool deletedNewTypes = false;
auto itr = mResolvedTypes.begin();
while (itr != mResolvedTypes.end())
{
auto type = itr.mCurEntry->mValue;
if (type->IsGenericTypeInstance())
{
// We can't contain deleted generic arguments without being deleted ourselves
BfGenericTypeInstance* genericType = (BfGenericTypeInstance*)type;
for (auto genericTypeArg : genericType->mTypeGenericArguments)
{
auto depType = genericTypeArg->ToDependedType();
if (depType != NULL)
{
BF_ASSERT(depType->mDependencyMap.mTypeSet.ContainsKey(type));
}
}
}
++itr;
}
#endif
}
void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuildModule, bool placeSpecializiedInPurgatory)
{
BfTypeInstance* typeInst = type->ToTypeInstance();
@ -790,6 +820,12 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild
return;
}
if (typeInst->mRevision != mCompiler->mRevision)
{
BfLogSysM("Setting revision. Type: %p Revision: %d\n", typeInst, mCompiler->mRevision);
typeInst->mRevision = mCompiler->mRevision;
}
if ((typeInst->IsTypeAlias()) != (typeInst->mTypeDef->mTypeCode == BfTypeCode_TypeAlias))
{
BfLogSysM("TypeAlias %p status changed - deleting\n", typeInst);

View file

@ -387,6 +387,7 @@ public:
void RemoveInvalidWorkItems();
BfType* FindTypeById(int typeId);
void AddTypeToWorkList(BfType* type);
void ValidateDependencies();
void RebuildType(BfType* type, bool deleteOnDemandTypes = true, bool rebuildModule = true, bool placeSpecializiedInPurgatory = true);
void RebuildDependentTypes(BfDependedType* dType);
void TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChange);