From 7f9a272e236f21db0e649f6fa5265806a1172c1a Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 2 Jan 2025 13:33:45 -0800 Subject: [PATCH] Generic resolution fix --- IDEHelper/Compiler/BfExprEvaluator.cpp | 11 ++- IDEHelper/Compiler/BfModule.cpp | 85 +++++++++++++----------- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 3 + 3 files changed, 58 insertions(+), 41 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index a46c58fa..cb87ab80 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -2344,7 +2344,16 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst // If we allowed this then it would allow too many matches (and allow conversion to any type during CastToValue) goto NoMatch; } + + bool doFullTypeResolve = false; + if (returnType->IsUnspecializedTypeVariation()) + { + returnType = typeUnspecMethodInstance->mReturnType; + doFullTypeResolve = true; + } if ((genericArgumentsSubstitute != NULL) && (returnType->IsUnspecializedType())) + doFullTypeResolve = true; + if (doFullTypeResolve) { auto resolvedType = mModule->ResolveGenericType(returnType, typeGenericArguments, genericArgumentsSubstitute, mModule->mCurTypeInstance, false); if (resolvedType == NULL) @@ -6383,7 +6392,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* mModule->mCurMethodState->mCancelledDeferredCall = true; } - if (methodDef->mIsNoReturn) + if ((methodDef->mIsNoReturn) && ((mBfEvalExprFlags & BfEvalExprFlags_Comptime) == 0)) { mModule->mCurMethodState->SetHadReturn(true); mModule->mCurMethodState->mLeftBlockUncond = true; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 86dcd5d1..ed701381 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -21653,50 +21653,55 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, else { auto innerMethodDef = innerMethodInstance.mMethodInstance->mMethodDef; - BF_ASSERT(innerMethodDef == methodDef); - - SizedArray innerParams; - BfExprEvaluator exprEvaluator(this); - - if (!innerType->IsValuelessType()) + if ((innerMethodDef == methodDef != NULL) && (!CompareMethodSignatures(methodInstance, innerMethodInstance.mMethodInstance))) { - BfIRValue thisValue = mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[0]->mValue, 0, 1); - BfTypedValue innerVal(thisValue, innerType, true); - if (boxedType->IsBoxedStructPtr()) - { - innerVal = LoadValue(innerVal); - innerVal = BfTypedValue(innerVal.mValue, innerType, true); - } - - exprEvaluator.PushThis(NULL, innerVal, innerMethodInstance.mMethodInstance, innerParams); - } - - for (int i = 1; i < (int)mCurMethodState->mLocals.size(); i++) - { - BfLocalVariable* localVar = mCurMethodState->mLocals[i]; - BfTypedValue localVal = exprEvaluator.LoadLocal(localVar, true); - exprEvaluator.PushArg(localVal, innerParams); - } - if (!innerMethodInstance.mFunc) - { - BF_ASSERT(innerType->IsUnspecializedType()); - } - else if ((!mIsComptimeModule) && (methodInstance->GetStructRetIdx() != -1)) - { - mBfIRBuilder->PopulateType(methodInstance->mReturnType); - auto returnType = BfTypedValue(mBfIRBuilder->GetArgument(methodInstance->GetStructRetIdx()), methodInstance->mReturnType, true); - exprEvaluator.mReceivingValue = &returnType; - auto retVal = exprEvaluator.CreateCall(NULL, innerMethodInstance.mMethodInstance, innerMethodInstance.mFunc, true, innerParams, NULL, BfCreateCallFlags_TailCall); - BF_ASSERT(exprEvaluator.mReceivingValue == NULL); // Ensure it was actually used - mBfIRBuilder->CreateRetVoid(); + InternalError("Boxing method passthrough error"); } else { - mBfIRBuilder->PopulateType(methodInstance->mReturnType); - auto retVal = exprEvaluator.CreateCall(NULL, innerMethodInstance.mMethodInstance, innerMethodInstance.mFunc, true, innerParams, NULL, BfCreateCallFlags_TailCall); - if (mCurMethodInstance->mReturnType->IsValueType()) - retVal = LoadValue(retVal); - CreateReturn(retVal.mValue); + SizedArray innerParams; + BfExprEvaluator exprEvaluator(this); + + if (!innerType->IsValuelessType()) + { + BfIRValue thisValue = mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[0]->mValue, 0, 1); + BfTypedValue innerVal(thisValue, innerType, true); + if (boxedType->IsBoxedStructPtr()) + { + innerVal = LoadValue(innerVal); + innerVal = BfTypedValue(innerVal.mValue, innerType, true); + } + + exprEvaluator.PushThis(NULL, innerVal, innerMethodInstance.mMethodInstance, innerParams); + } + + for (int i = 1; i < (int)mCurMethodState->mLocals.size(); i++) + { + BfLocalVariable* localVar = mCurMethodState->mLocals[i]; + BfTypedValue localVal = exprEvaluator.LoadLocal(localVar, true); + exprEvaluator.PushArg(localVal, innerParams); + } + if (!innerMethodInstance.mFunc) + { + BF_ASSERT(innerType->IsUnspecializedType()); + } + else if ((!mIsComptimeModule) && (methodInstance->GetStructRetIdx() != -1)) + { + mBfIRBuilder->PopulateType(methodInstance->mReturnType); + auto returnType = BfTypedValue(mBfIRBuilder->GetArgument(methodInstance->GetStructRetIdx()), methodInstance->mReturnType, true); + exprEvaluator.mReceivingValue = &returnType; + auto retVal = exprEvaluator.CreateCall(NULL, innerMethodInstance.mMethodInstance, innerMethodInstance.mFunc, true, innerParams, NULL, BfCreateCallFlags_TailCall); + BF_ASSERT(exprEvaluator.mReceivingValue == NULL); // Ensure it was actually used + mBfIRBuilder->CreateRetVoid(); + } + else + { + mBfIRBuilder->PopulateType(methodInstance->mReturnType); + auto retVal = exprEvaluator.CreateCall(NULL, innerMethodInstance.mMethodInstance, innerMethodInstance.mFunc, true, innerParams, NULL, BfCreateCallFlags_TailCall); + if (mCurMethodInstance->mReturnType->IsValueType()) + retVal = LoadValue(retVal); + CreateReturn(retVal.mValue); + } } } } diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 36a7956a..2cecb095 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -3472,6 +3472,9 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) void BfModule::DoPopulateType_InitSearches(BfTypeInstance* typeInstance) { + if (typeInstance->IsBoxed()) + return; + auto typeDef = typeInstance->mTypeDef; auto _AddStaticSearch = [&](BfTypeDef* typeDef)