From 1312272184ed2fab69d6119d8940330658811a1f Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 28 Jun 2021 11:40:50 -0700 Subject: [PATCH] Improved generic inference from constraints --- IDEHelper/Compiler/BfExprEvaluator.cpp | 22 +++++----------------- IDEHelper/Compiler/BfExprEvaluator.h | 6 ++---- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 81d47c40..f0c6e537 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -242,19 +242,9 @@ bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstanc { if (argType == NULL) return false; - - if (mIgnoreMethodGenericParam) - { - if (argType->IsGenericParam()) - { - auto genericParamType = (BfGenericParamType*)argType; - if (genericParamType->mGenericParamKind == BfGenericParamKind_Method) - return false; - } - } - + if (!wantType->IsUnspecializedType()) - return true; + return true; bool alreadyChecked = false; auto _AddToCheckedSet = [](BfType* type, HashSet& checkedTypeSet, bool& alreadyChecked) @@ -629,16 +619,14 @@ bool BfGenericInferContext::InferGenericArguments(BfMethodInstance* methodInstan BfGenericParamInstance* genericParam = NULL; if (genericParamType->mGenericParamKind == BfGenericParamKind_Method) - genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericParamType->mGenericParamIdx]; + genericParam = mModule->mCurMethodInstance->mMethodInfoEx->mGenericParams[genericParamType->mGenericParamIdx]; else genericParam = mModule->GetGenericParamInstance(genericParamType); - - // Generic arg references in constraints refer to the caller, not the callee -- so ignore those - SetAndRestoreValue prevIgnoreMethodGenericArg(mIgnoreMethodGenericParam, true); + if (genericParam->mTypeConstraint != NULL) InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue()); for (auto argIfaceConstraint : genericParam->mInterfaceConstraints) - InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue()); + InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue()); } } } diff --git a/IDEHelper/Compiler/BfExprEvaluator.h b/IDEHelper/Compiler/BfExprEvaluator.h index 95b26958..46a8fc9a 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.h +++ b/IDEHelper/Compiler/BfExprEvaluator.h @@ -137,15 +137,13 @@ public: BfModule* mModule; BfTypeVector* mCheckMethodGenericArguments; SizedArray mPrevArgValues; - int mInferredCount; - bool mIgnoreMethodGenericParam; + int mInferredCount; public: BfGenericInferContext() { mModule = NULL; - mInferredCount = 0; - mIgnoreMethodGenericParam = false; + mInferredCount = 0; } bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue); int GetUnresolvedCount()