1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed funcId takeover with extern overrides within same project

This commit is contained in:
Brian Fiete 2025-01-29 09:33:51 -08:00
parent 91483c90af
commit 1a1f6f793b

View file

@ -24048,14 +24048,16 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
prevFunc = mBfIRBuilder->GetFunction(mangledName); prevFunc = mBfIRBuilder->GetFunction(mangledName);
if (prevFunc) if (prevFunc)
{ {
if ((methodDef->mIsOverride) && (mCurTypeInstance->mTypeDef->mIsCombinedPartial)) auto owner = methodInstance->GetOwner();
if ((methodDef->mIsOverride) && (owner->mTypeDef->mIsCombinedPartial))
{ {
bool takeover = false; bool takeover = false;
mCurTypeInstance->mTypeDef->PopulateMemberSets(); owner->mTypeDef->PopulateMemberSets();
BfMethodDef* nextMethod = NULL; BfMethodDef* nextMethod = NULL;
BfMemberSetEntry* entry = NULL; BfMemberSetEntry* entry = NULL;
if (mCurTypeInstance->mTypeDef->mMethodSet.TryGet(BfMemberSetEntry(methodDef), &entry)) if (owner->mTypeDef->mMethodSet.TryGet(BfMemberSetEntry(methodDef), &entry))
nextMethod = (BfMethodDef*)entry->mMemberDef; nextMethod = (BfMethodDef*)entry->mMemberDef;
while (nextMethod != NULL) while (nextMethod != NULL)
{ {
@ -24066,7 +24068,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
continue; continue;
if (checkMethod->mIsOverride) if (checkMethod->mIsOverride)
{ {
auto checkMethodInstance = mCurTypeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; auto checkMethodInstance = owner->mMethodInstanceGroups[checkMethod->mIdx].mDefault;
if (checkMethodInstance == NULL) if (checkMethodInstance == NULL)
continue; continue;
if ((checkMethodInstance->mIRFunction == prevFunc) && if ((checkMethodInstance->mIRFunction == prevFunc) &&
@ -24079,7 +24081,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
else if (auto methodDeclaration = methodDef->GetMethodDeclaration()) else if (auto methodDeclaration = methodDef->GetMethodDeclaration())
refNode = methodDeclaration->mVirtualSpecifier; refNode = methodDeclaration->mVirtualSpecifier;
auto error = Fail(StrFormat("Conflicting extension override method '%s'", MethodToString(mCurMethodInstance).c_str()), refNode); auto error = Fail(StrFormat("Conflicting extension override method '%s'", MethodToString(methodInstance).c_str()), refNode);
if (error != NULL) if (error != NULL)
mCompiler->mPassInstance->MoreInfo("See previous override", checkMethod->GetRefNode()); mCompiler->mPassInstance->MoreInfo("See previous override", checkMethod->GetRefNode());
@ -24090,19 +24092,25 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
if (!checkMethod->mIsExtern) if (!checkMethod->mIsExtern)
continue; continue;
auto checkMethodInstance = mCurTypeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; auto checkMethodInstance = owner->mMethodInstanceGroups[checkMethod->mIdx].mDefault;
if (checkMethodInstance == NULL) if (checkMethodInstance == NULL)
continue; continue;
if (!CompareMethodSignatures(checkMethodInstance, mCurMethodInstance)) if (!CompareMethodSignatures(checkMethodInstance, methodInstance))
continue; continue;
// Take over function // Take over function
takeover = true; takeover = true;
BfLogSysM("Method %p setting mHasBeenProcessed due to funcId takeover from method %p\n", checkMethodInstance, prevFunc.mId, methodInstance);
checkMethodInstance->mHasBeenProcessed = true;
} }
if (takeover) if (takeover)
mCurMethodInstance->mIRFunction = prevFunc; {
BfLogSysM("Method %p takover of previous funcId: %d\n", methodInstance, prevFunc.mId);
methodInstance->mIRFunction = prevFunc;
}
if (!mCurMethodInstance->mIRFunction) if (!methodInstance->mIRFunction)
{ {
BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId); BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId);
if (!mIsComptimeModule) if (!mIsComptimeModule)
@ -24120,9 +24128,9 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
// their constraints, but they should only collide in their unspecialized form // their constraints, but they should only collide in their unspecialized form
// since only one will be chosen for a given concrete type // since only one will be chosen for a given concrete type
if (!mIsComptimeModule) if (!mIsComptimeModule)
mCurMethodInstance->mMangleWithIdx = true; methodInstance->mMangleWithIdx = true;
mangledName.Clear(); mangledName.Clear();
BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), mCurMethodInstance); BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), methodInstance);
BfLogSysM("Function collision forced mangleWithIdx for %p: %d GenericArgs: %d Unspecialized: %d\n", methodInstance, prevFunc.mId, methodInstance->GetNumGenericArguments(), methodInstance->mIsUnspecialized); BfLogSysM("Function collision forced mangleWithIdx for %p: %d GenericArgs: %d Unspecialized: %d\n", methodInstance, prevFunc.mId, methodInstance->GetNumGenericArguments(), methodInstance->mIsUnspecialized);
} }
@ -24141,42 +24149,6 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
GetMethodCustomAttributes(methodInstance); GetMethodCustomAttributes(methodInstance);
} }
// if (prevFunc)
// {
// if (methodDef->mIsExtern)
// {
// BfLogSysM("Reusing function for %p: %d\n", methodInstance, prevFunc.mId);
// methodInstance->mIRFunction = prevFunc;
// }
// else
// {
// if ((methodInstance->IsSpecializedByAutoCompleteMethod()) ||
// ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mResolveType >= BfResolveType_GoToDefinition)))
// {
// // If we're doing re-pass over the methods for something like BfResolveType_ShowFileSymbolReferences, then allow this collision
// BfLogSysM("Ignoring function name collision\n");
// }
// else
// {
// if (methodDef->mMethodDeclaration == NULL)
// {
// AssertErrorState();
// }
// else
// {
// BF_ASSERT(mIsSpecialModule);
// if ((mCompiler->mRevision == 1) && (HasCompiledOutput()))
// {
// // We shouldn't have name collisions on the first run!
// AssertErrorState();
// }
// }
// }
// BfLogSysM("Before erase\n");
// mBfIRBuilder->Func_EraseFromParent(prevFunc);
// }
// }
bool isIntrinsic = false; bool isIntrinsic = false;
if (!methodInstance->mIRFunction) if (!methodInstance->mIRFunction)
{ {
@ -24184,12 +24156,6 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
bool wantsLLVMFunc = ((!typeInstance->IsUnspecializedType() || (mIsComptimeModule)) && bool wantsLLVMFunc = ((!typeInstance->IsUnspecializedType() || (mIsComptimeModule)) &&
(!methodDef->IsEmptyPartial())) && (funcType); (!methodDef->IsEmptyPartial())) && (funcType);
/*if (mCurTypeInstance->mTypeDef->mName->ToString() == "ClassA")
{
if (!mIsReified)
wantsLLVMFunc = false;
}*/
if (wantsLLVMFunc) if (wantsLLVMFunc)
{ {
func = GetIntrinsic(methodInstance, true); func = GetIntrinsic(methodInstance, true);
@ -24203,14 +24169,9 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
BfLogSysM("Creating FuncId:%d %s in module %p\n", func.mId, mangledName.c_str(), this); BfLogSysM("Creating FuncId:%d %s in module %p\n", func.mId, mangledName.c_str(), this);
if (methodInstance->mAlwaysInline) if (methodInstance->mAlwaysInline)
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_AlwaysInline); mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_AlwaysInline);
// if (prevFunc)
// BfLogSysM("Removing Func %d, replacing with %d\n", prevFunc.mId, func.mId);
} }
methodInstance->mIRFunction = func; methodInstance->mIRFunction = func;
//if (!ignoreWrites)
//BF_ASSERT(!func.IsFake());
} }
} }