diff --git a/IDEHelper/Backend/BeIRCodeGen.cpp b/IDEHelper/Backend/BeIRCodeGen.cpp index 66f8fe29..fc2ff4e9 100644 --- a/IDEHelper/Backend/BeIRCodeGen.cpp +++ b/IDEHelper/Backend/BeIRCodeGen.cpp @@ -2433,6 +2433,12 @@ void BeIRCodeGen::HandleNextCmd() func->mBlocks.Clear(); } break; + case BfIRCmd_Func_SafeRename: + { + CMD_PARAM(BeFunction*, func); + func->mName += StrFormat("__RENAME%d", curId); + } + break; case BfIRCmd_Func_SetLinkage: { CMD_PARAM(BeFunction*, func); diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 74b5f993..e2c2fc88 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -4466,7 +4466,7 @@ void BfCompiler::ProcessAutocompleteTempType() { BfLogSysM("Autocomplete removing IRFunction %d\n", methodInstance->mIRFunction.mId); module->mBfIRBuilder->Func_DeleteBody(methodInstance->mIRFunction); - module->mBfIRBuilder->Func_EraseFromParent(methodInstance->mIRFunction); + module->mBfIRBuilder->Func_SafeRename(methodInstance->mIRFunction); } } diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 4ce4ab52..146349b9 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -4773,19 +4773,18 @@ void BfIRBuilder::Func_DeleteBody(BfIRFunction func) NEW_CMD_INSERTED; } -void BfIRBuilder::Func_EraseFromParent(BfIRFunction func) -{ - // Refuse to erase from parent - /*WriteCmd(BfIRCmd_Func_EraseFromParent, func); +void BfIRBuilder::Func_SafeRename(BfIRFunction func) +{ + WriteCmd(BfIRCmd_Func_SafeRename, func); // We don't actually remove it from the named map. It doesn't matter for us. - { - auto llvmFunc = llvm::dyn_cast(func.mLLVMValue); - llvmFunc->eraseFromParent(); - } +// { +// auto llvmFunc = llvm::dyn_cast(func.mLLVMValue); +// llvmFunc->eraseFromParent(); +// } - NEW_CMD_INSERTED;*/ + NEW_CMD_INSERTED; } void BfIRBuilder::Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage) diff --git a/IDEHelper/Compiler/BfIRBuilder.h b/IDEHelper/Compiler/BfIRBuilder.h index 4802378b..aedfcb9d 100644 --- a/IDEHelper/Compiler/BfIRBuilder.h +++ b/IDEHelper/Compiler/BfIRBuilder.h @@ -278,7 +278,7 @@ enum BfIRCmd : uint8 BfIRCmd_Func_AddAttribute1, BfIRCmd_Func_SetParamName, BfIRCmd_Func_DeleteBody, - BfIRCmd_Func_EraseFromParent, + BfIRCmd_Func_SafeRename, BfIRCmd_Func_SetLinkage, BfIRCmd_SaveDebugLocation, @@ -1223,7 +1223,7 @@ public: void Func_AddAttribute(BfIRFunction func, int argIdx, BfIRAttribute attr, int arg); void Func_SetParamName(BfIRFunction func, int argIdx, const StringImpl& name); void Func_DeleteBody(BfIRFunction func); - void Func_EraseFromParent(BfIRFunction func); + void Func_SafeRename(BfIRFunction func); void Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage); void SaveDebugLocation(); diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index 75404b4b..193c1c74 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -3520,6 +3520,12 @@ void BfIRCodeGen::HandleNextCmd() ((llvm::Function*)func)->deleteBody(); } break; + case BfIRCmd_Func_SafeRename: + { + CMD_PARAM(llvm::Function*, func); + func->setName((Beefy::String(func->getName()) + StrFormat("__RENAME%d", curId)).c_str()); + } + break; case BfIRCmd_Func_SetLinkage: { CMD_PARAM(llvm::Function*, func); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index bac72c2f..f19541f4 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -20225,7 +20225,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man if ((methodDef->mIsOverride) && (mCurTypeInstance->mTypeDef->mIsCombinedPartial)) { BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId); - mBfIRBuilder->Func_EraseFromParent(prevFunc); + mBfIRBuilder->Func_SafeRename(prevFunc); } else if (methodDef->mIsExtern) { @@ -20247,7 +20247,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man else { BfLogSysM("Function collision erased prevFunc %p: %d\n", methodInstance, prevFunc.mId); - mBfIRBuilder->Func_EraseFromParent(prevFunc); + mBfIRBuilder->Func_SafeRename(prevFunc); } } }