1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Improved generic inference from constraints

This commit is contained in:
Brian Fiete 2021-06-28 11:40:50 -07:00
parent 9875d3a12d
commit 1312272184
2 changed files with 7 additions and 21 deletions

View file

@ -243,16 +243,6 @@ 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;
@ -629,12 +619,10 @@ 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<bool> prevIgnoreMethodGenericArg(mIgnoreMethodGenericParam, true);
if (genericParam->mTypeConstraint != NULL)
InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue());
for (auto argIfaceConstraint : genericParam->mInterfaceConstraints)

View file

@ -138,14 +138,12 @@ public:
BfTypeVector* mCheckMethodGenericArguments;
SizedArray<BfIRValue, 4> mPrevArgValues;
int mInferredCount;
bool mIgnoreMethodGenericParam;
public:
BfGenericInferContext()
{
mModule = NULL;
mInferredCount = 0;
mIgnoreMethodGenericParam = false;
}
bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue);
int GetUnresolvedCount()