diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index d0525cc0..0a00f353 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -487,7 +487,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) } BfCompiler::~BfCompiler() -{ +{ delete mCeMachine; mCeMachine = NULL; delete mContext; @@ -895,6 +895,7 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test testMethod.mMethodInstance = methodInstance; testMethods.Add(testMethod); + BF_ASSERT_REL(!typeInstance->mModule->mIsDeleting); if (!bfModule->mProject->mUsedModules.Contains(typeInstance->mModule)) { bfModule->mProject->mUsedModules.Add(typeInstance->mModule); @@ -1077,6 +1078,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfLogSysM("CreateVData %s\n", bfModule->mProject->mName.c_str()); CompileLog("CreateVData %s\n", bfModule->mProject->mName.c_str()); + BF_ASSERT_REL(!bfModule->mIsDeleting); bfModule->mProject->mUsedModules.Add(bfModule); auto project = bfModule->mProject; @@ -7609,7 +7611,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if (bfModule->mParentModule != NULL) { - for (auto&& fileName : bfModule->mOutFileNames) + for (auto& fileName : bfModule->mOutFileNames) { if (!mainModule->mOutFileNames.Contains(fileName)) mainModule->mOutFileNames.push_back(fileName); @@ -7704,7 +7706,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) BfModule* bfModule = mainModule; if (bfModule->mIsReified) { - for (auto outFileName : bfModule->mOutFileNames) + for (auto& outFileName : bfModule->mOutFileNames) { if (outFileName.mModuleWritten) BeLibManager::Get()->AddUsedFileName(outFileName.mFileName); @@ -10473,9 +10475,12 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetUsedOutputFileNames(BfCompiler* HashSet usedFileNames; usedFileNames.Reserve(moduleList.size()); - for (auto mainModule : moduleList) + //for (auto mainModule : moduleList) + for (int i = 0; i < moduleList.mSize; i++) { - BF_ASSERT(!mainModule->mIsDeleting); + auto mainModule = moduleList[i]; + BF_ASSERT_REL(!mainModule->mIsDeleting); + BF_ASSERT_REL((mainModule->mRevision > -2) && (mainModule->mRevision < 1000000)); if ((flags & BfUsedOutputFlags_SkipImports) == 0) { @@ -10490,7 +10495,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetUsedOutputFileNames(BfCompiler* } } - for (auto&& moduleFileName : mainModule->mOutFileNames) + for (auto& moduleFileName : mainModule->mOutFileNames) { if (!moduleFileName.mModuleWritten) continue; diff --git a/IDEHelper/Compiler/BfContext.cpp b/IDEHelper/Compiler/BfContext.cpp index ccfb931b..2d42dce8 100644 --- a/IDEHelper/Compiler/BfContext.cpp +++ b/IDEHelper/Compiler/BfContext.cpp @@ -1798,7 +1798,7 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) // This was only needed for 'zombie modules', which we don't need anymore? // To avoid linking errors. Used instead of directly removing from mModules. - mDeletingModules.push_back(module); + mDeletingModules.Add(module); } } } @@ -3187,7 +3187,7 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) { BP_ZONE("BfContext::MarkUsedModules"); - BF_ASSERT(!module->mIsDeleting); + BF_ASSERT_REL(!module->mIsDeleting); if (module->mIsScratchModule) return; @@ -3316,10 +3316,15 @@ void BfContext::Cleanup() { for (auto itr = project->mUsedModules.begin(); itr != project->mUsedModules.end(); ) { - if ((*itr)->mIsDeleting) + auto module = *itr; + + if (module->mIsDeleting) itr = project->mUsedModules.Remove(itr); else + { + BF_ASSERT_REL(module->mRevision > -2); ++itr; + } } } } diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 8d097649..d350a5be 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -930,6 +930,8 @@ void BfReportMemory(); BfModule::~BfModule() { + mRevision = -2; + BfLogSysM("Deleting module %p: %s \n", this, mModuleName.c_str()); if (!mIsDeleting) @@ -1311,7 +1313,13 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) for (auto& specPair : mSpecializedMethodModules) { auto specModule = specPair.mValue; - delete specModule; + + BfLogSysM("Setting module mIsDeleting %p due to parent module starting a new revision\n", module); + + // This module is no longer needed + specModule->RemoveModuleData(); + specModule->mIsDeleting = true; + mContext->mDeletingModules.Add(specModule); } } mSpecializedMethodModules.Clear();