mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Improved generic inference from constraints
This commit is contained in:
parent
9875d3a12d
commit
1312272184
2 changed files with 7 additions and 21 deletions
|
@ -242,19 +242,9 @@ bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstanc
|
||||||
{
|
{
|
||||||
if (argType == NULL)
|
if (argType == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mIgnoreMethodGenericParam)
|
|
||||||
{
|
|
||||||
if (argType->IsGenericParam())
|
|
||||||
{
|
|
||||||
auto genericParamType = (BfGenericParamType*)argType;
|
|
||||||
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wantType->IsUnspecializedType())
|
if (!wantType->IsUnspecializedType())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool alreadyChecked = false;
|
bool alreadyChecked = false;
|
||||||
auto _AddToCheckedSet = [](BfType* type, HashSet<BfType*>& checkedTypeSet, bool& alreadyChecked)
|
auto _AddToCheckedSet = [](BfType* type, HashSet<BfType*>& checkedTypeSet, bool& alreadyChecked)
|
||||||
|
@ -629,16 +619,14 @@ bool BfGenericInferContext::InferGenericArguments(BfMethodInstance* methodInstan
|
||||||
|
|
||||||
BfGenericParamInstance* genericParam = NULL;
|
BfGenericParamInstance* genericParam = NULL;
|
||||||
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
|
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
|
||||||
genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericParamType->mGenericParamIdx];
|
genericParam = mModule->mCurMethodInstance->mMethodInfoEx->mGenericParams[genericParamType->mGenericParamIdx];
|
||||||
else
|
else
|
||||||
genericParam = mModule->GetGenericParamInstance(genericParamType);
|
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)
|
if (genericParam->mTypeConstraint != NULL)
|
||||||
InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue());
|
InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue());
|
||||||
for (auto argIfaceConstraint : genericParam->mInterfaceConstraints)
|
for (auto argIfaceConstraint : genericParam->mInterfaceConstraints)
|
||||||
InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue());
|
InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,15 +137,13 @@ public:
|
||||||
BfModule* mModule;
|
BfModule* mModule;
|
||||||
BfTypeVector* mCheckMethodGenericArguments;
|
BfTypeVector* mCheckMethodGenericArguments;
|
||||||
SizedArray<BfIRValue, 4> mPrevArgValues;
|
SizedArray<BfIRValue, 4> mPrevArgValues;
|
||||||
int mInferredCount;
|
int mInferredCount;
|
||||||
bool mIgnoreMethodGenericParam;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BfGenericInferContext()
|
BfGenericInferContext()
|
||||||
{
|
{
|
||||||
mModule = NULL;
|
mModule = NULL;
|
||||||
mInferredCount = 0;
|
mInferredCount = 0;
|
||||||
mIgnoreMethodGenericParam = false;
|
|
||||||
}
|
}
|
||||||
bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue);
|
bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue);
|
||||||
int GetUnresolvedCount()
|
int GetUnresolvedCount()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue