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

Test fix, linux fix

This commit is contained in:
Brian Fiete 2019-11-19 13:36:51 -08:00
parent 503261e916
commit 68151e69ca
6 changed files with 117 additions and 35 deletions

View file

@ -991,6 +991,101 @@ bool BfMethodMatcher::WantsCheckMethod(BfProtectionCheckFlags& flags, BfTypeInst
return true;
}
bool BfMethodMatcher::InferFromGenericConstraints(BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs)
{
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Equals) == 0)
return false;
if (!genericParamInst->mExternType->IsGenericParam())
return false;
auto genericParamType = (BfGenericParamType*)genericParamInst->mExternType;
if (genericParamType->mGenericParamKind != BfGenericParamKind_Method)
return false;
BfType* checkArgType = NULL;
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Equals_Type) != 0)
{
checkArgType = genericParamInst->mTypeConstraint;
}
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Equals_IFace) != 0)
{
if (!genericParamInst->mInterfaceConstraints.IsEmpty())
checkArgType = genericParamInst->mInterfaceConstraints[0];
}
for (auto& checkOpConstraint : genericParamInst->mOperatorConstraints)
{
auto leftType = checkOpConstraint.mLeftType;
if ((leftType != NULL) && (leftType->IsUnspecializedType()))
leftType = mModule->ResolveGenericType(leftType, *methodGenericArgs);
if (leftType != NULL)
leftType = mModule->FixIntUnknown(leftType);
auto rightType = checkOpConstraint.mRightType;
if ((rightType != NULL) && (rightType->IsUnspecializedType()))
rightType = mModule->ResolveGenericType(rightType, *methodGenericArgs);
if (rightType != NULL)
rightType = mModule->FixIntUnknown(rightType);
if (checkOpConstraint.mBinaryOp != BfBinaryOp_None)
{
BfExprEvaluator exprEvaluator(mModule);
BfTypedValue leftValue(mModule->mBfIRBuilder->GetFakeVal(), leftType);
BfTypedValue rightValue(mModule->mBfIRBuilder->GetFakeVal(), rightType);
//
{
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
SetAndRestoreValue<bool> prevIgnoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, true);
exprEvaluator.PerformBinaryOperation(NULL, NULL, checkOpConstraint.mBinaryOp, NULL, BfBinOpFlag_NoClassify, leftValue, rightValue);
}
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Equals_Op) != 0)
checkArgType = exprEvaluator.mResult.mType;
}
else
{
BfTypedValue rightValue(mModule->mBfIRBuilder->GetFakeVal(), rightType);
StringT<128> failedOpName;
if (checkOpConstraint.mCastToken == BfToken_Implicit)
{
}
else
{
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
SetAndRestoreValue<bool> prevIgnoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, true);
if (checkOpConstraint.mCastToken == BfToken_Explicit)
{
}
else
{
BfExprEvaluator exprEvaluator(mModule);
exprEvaluator.mResult = rightValue;
exprEvaluator.PerformUnaryOperation(NULL, checkOpConstraint.mUnaryOp, NULL);
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Equals_Op) != 0)
checkArgType = exprEvaluator.mResult.mType;
}
}
}
}
if (checkArgType == NULL)
return false;
(*methodGenericArgs)[genericParamType->mGenericParamIdx] = checkArgType;
return true;
}
bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* checkMethod, bool isFailurePass)
{
BP_ZONE("BfMethodMatcher::CheckMethod");
@ -1185,23 +1280,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* che
if (genericArg == NULL)
{
auto genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericArgIdx];
//mModule->CheckGenericConstraints(BfGenericParamSource(), NULL, NULL, genericParam, &mCheckMethodGenericArguments, NULL);
InferFromGenericConstraints(genericParam, &mCheckMethodGenericArguments);
if (genericArg != NULL)
continue;
// if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Equals) != 0)
// {
// if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Equals_Op) != 0)
// {
//
// }
//
// else if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Equals_Type) != 0)
// {
//
// }
// }
if (!allowEmptyGenericSet.Contains(genericArgIdx))
goto NoMatch;
}
@ -1361,11 +1442,11 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* che
goto NoMatch;
}
if (genericArg->IsPrimitiveType())
{
auto primType = (BfPrimitiveType*) genericArg;
genericArg = mModule->GetPrimitiveStructType(primType->mTypeDef->mTypeCode);
}
// if (genericArg->IsPrimitiveType())
// {
// auto primType = (BfPrimitiveType*) genericArg;
// genericArg = mModule->GetPrimitiveStructType(primType->mTypeDef->mTypeCode);
// }
if (genericArg == NULL)
goto NoMatch;

View file

@ -156,6 +156,7 @@ public:
public:
BfTypedValue ResolveArgTypedValue(BfResolvedArg& resolvedArg, BfType* checkType, BfTypeVector* genericArgumentsSubstitute);
bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue);
bool InferFromGenericConstraints(BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs);
void CompareMethods(BfMethodInstance* prevMethodInstance, BfTypeVector* prevGenericArgumentsSubstitute,
BfMethodInstance* newMethodInstance, BfTypeVector* genericArgumentsSubstitute,
bool* outNewIsBetter, bool* outNewIsWorse, bool allowSpecializeFail);

View file

@ -6237,7 +6237,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar
else
{
opConstraintInstance.mUnaryOp = BfTokenToUnaryOp(opConstraint->mOpToken->mToken);
if (opConstraintInstance.mUnaryOp == BfBinaryOp_None)
if (opConstraintInstance.mUnaryOp == BfUnaryOp_None)
{
Fail("Invalid unary operator", opConstraint->mOpToken);
continue;
@ -6706,7 +6706,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
exprEvaluator.PerformBinaryOperation(NULL, NULL, checkOpConstraint.mBinaryOp, NULL, BfBinOpFlag_NoClassify, leftValue, rightValue);
}
if ((exprEvaluator.mResult == NULL) ||
if ((!exprEvaluator.mResult) ||
(!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType)))
{
if (!ignoreErrors)
@ -6745,7 +6745,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
exprEvaluator.mResult = rightValue;
exprEvaluator.PerformUnaryOperation(NULL, checkOpConstraint.mUnaryOp, NULL);
if ((exprEvaluator.mResult == NULL) ||
if ((!exprEvaluator.mResult) ||
(!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType)))
{
failedOpName += "unary operation '";

View file

@ -9021,7 +9021,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
Warn(0, "This implicit boxing will only be in scope during the constructor. Consider using a longer-term allocation such as 'box new'", srcNode);
}
SetAndRestoreValue<bool> ignoreWrites(mBfIRBuilder->mIgnoreWrites, ignoreWrites);
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, ignoreWrites);
auto value = BoxValue(srcNode, typedVal, toType, scopeData, (castFlags & BfCastFlags_NoBoxDtor) == 0);
if (value)
return value.mValue;