1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +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

@ -257,10 +257,10 @@ private:
void Resize(intptr newSize, bool forceNewHashCodes) void Resize(intptr newSize, bool forceNewHashCodes)
{ {
BF_ASSERT(newSize >= mAllocSize); BF_ASSERT(newSize >= mAllocSize);
int_cosize* newBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * newSize); int_cosize* newBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * newSize);
for (int_cosize i = 0; i < newSize; i++) for (int_cosize i = 0; i < newSize; i++)
newBuckets[i] = -1; newBuckets[i] = -1;
Entry* newEntries = (Entry*)rawAllocate(sizeof(Entry)*newSize); Entry* newEntries = (Entry*)this->rawAllocate(sizeof(Entry)*newSize);
for (int i = 0; i < mCount; i++) for (int i = 0; i < mCount; i++)
{ {
@ -294,8 +294,8 @@ private:
} }
} }
rawDeallocate(mBuckets); this->rawDeallocate(mBuckets);
rawDeallocate(mEntries); this->rawDeallocate(mEntries);
mBuckets = newBuckets; mBuckets = newBuckets;
mEntries = newEntries; mEntries = newEntries;
@ -332,10 +332,10 @@ private:
void Initialize(intptr capacity) void Initialize(intptr capacity)
{ {
int_cosize size = GetPrimeish((int_cosize)capacity); int_cosize size = GetPrimeish((int_cosize)capacity);
mBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * size); mBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * size);
mAllocSize = size; mAllocSize = size;
for (int_cosize i = 0; i < (int_cosize)mAllocSize; i++) mBuckets[i] = -1; for (int_cosize i = 0; i < (int_cosize)mAllocSize; i++) mBuckets[i] = -1;
mEntries = (Entry*)rawAllocate(sizeof(Entry) * size); mEntries = (Entry*)this->rawAllocate(sizeof(Entry) * size);
mFreeList = -1; mFreeList = -1;
} }
@ -431,8 +431,8 @@ public:
} }
else else
{ {
mBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * mAllocSize); mBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * mAllocSize);
mEntries = (Entry*)rawAllocate(sizeof(Entry) * mAllocSize); mEntries = (Entry*)this->rawAllocate(sizeof(Entry) * mAllocSize);
for (int_cosize i = 0; i < mAllocSize; i++) for (int_cosize i = 0; i < mAllocSize; i++)
mBuckets[i] = val.mBuckets[i]; mBuckets[i] = val.mBuckets[i];
@ -476,8 +476,8 @@ public:
} }
} }
rawDeallocate(mBuckets); this->rawDeallocate(mBuckets);
rawDeallocate(mEntries); this->rawDeallocate(mEntries);
} }
HashSet& operator=(const HashSet& rhs) HashSet& operator=(const HashSet& rhs)

View file

@ -991,6 +991,101 @@ bool BfMethodMatcher::WantsCheckMethod(BfProtectionCheckFlags& flags, BfTypeInst
return true; 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) bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* checkMethod, bool isFailurePass)
{ {
BP_ZONE("BfMethodMatcher::CheckMethod"); BP_ZONE("BfMethodMatcher::CheckMethod");
@ -1185,23 +1280,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* che
if (genericArg == NULL) if (genericArg == NULL)
{ {
auto genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericArgIdx]; auto genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericArgIdx];
//mModule->CheckGenericConstraints(BfGenericParamSource(), NULL, NULL, genericParam, &mCheckMethodGenericArguments, NULL); InferFromGenericConstraints(genericParam, &mCheckMethodGenericArguments);
if (genericArg != NULL) if (genericArg != NULL)
continue; 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)) if (!allowEmptyGenericSet.Contains(genericArgIdx))
goto NoMatch; goto NoMatch;
} }
@ -1361,11 +1442,11 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* che
goto NoMatch; goto NoMatch;
} }
if (genericArg->IsPrimitiveType()) // if (genericArg->IsPrimitiveType())
{ // {
auto primType = (BfPrimitiveType*) genericArg; // auto primType = (BfPrimitiveType*) genericArg;
genericArg = mModule->GetPrimitiveStructType(primType->mTypeDef->mTypeCode); // genericArg = mModule->GetPrimitiveStructType(primType->mTypeDef->mTypeCode);
} // }
if (genericArg == NULL) if (genericArg == NULL)
goto NoMatch; goto NoMatch;

View file

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

View file

@ -6237,7 +6237,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar
else else
{ {
opConstraintInstance.mUnaryOp = BfTokenToUnaryOp(opConstraint->mOpToken->mToken); opConstraintInstance.mUnaryOp = BfTokenToUnaryOp(opConstraint->mOpToken->mToken);
if (opConstraintInstance.mUnaryOp == BfBinaryOp_None) if (opConstraintInstance.mUnaryOp == BfUnaryOp_None)
{ {
Fail("Invalid unary operator", opConstraint->mOpToken); Fail("Invalid unary operator", opConstraint->mOpToken);
continue; continue;
@ -6706,7 +6706,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
exprEvaluator.PerformBinaryOperation(NULL, NULL, checkOpConstraint.mBinaryOp, NULL, BfBinOpFlag_NoClassify, leftValue, rightValue); exprEvaluator.PerformBinaryOperation(NULL, NULL, checkOpConstraint.mBinaryOp, NULL, BfBinOpFlag_NoClassify, leftValue, rightValue);
} }
if ((exprEvaluator.mResult == NULL) || if ((!exprEvaluator.mResult) ||
(!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType))) (!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType)))
{ {
if (!ignoreErrors) if (!ignoreErrors)
@ -6745,7 +6745,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
exprEvaluator.mResult = rightValue; exprEvaluator.mResult = rightValue;
exprEvaluator.PerformUnaryOperation(NULL, checkOpConstraint.mUnaryOp, NULL); exprEvaluator.PerformUnaryOperation(NULL, checkOpConstraint.mUnaryOp, NULL);
if ((exprEvaluator.mResult == NULL) || if ((!exprEvaluator.mResult) ||
(!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType))) (!CanImplicitlyCast(exprEvaluator.mResult, origCheckArgType)))
{ {
failedOpName += "unary operation '"; 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); 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); auto value = BoxValue(srcNode, typedVal, toType, scopeData, (castFlags & BfCastFlags_NoBoxDtor) == 0);
if (value) if (value)
return value.mValue; return value.mValue;

View file

@ -218,7 +218,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>BP_DISABLED;WIN32;NDEBUG;_WINDOWS;_USRDLL;IDEHELPER_EXPORTS;BFSYSLIB_DYNAMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>zBP_DISABLED;WIN32;NDEBUG;_WINDOWS;_USRDLL;IDEHELPER_EXPORTS;BFSYSLIB_DYNAMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../;../BeefySysLib/platform/win;../BeefySysLib/third_party;..\extern\llvm-project_8_0_1\llvm\include;..\extern\llvm_win64_8_0_1\include;..\extern\llvm-project_8_0_1\llvm\lib\Target;..\extern\llvm_win64_8_0_1\lib\Target\X86;..\extern\llvm-project_8_0_1\llvm\tools\clang\include;..\extern\curl\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-winssl\include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>../;../BeefySysLib/platform/win;../BeefySysLib/third_party;..\extern\llvm-project_8_0_1\llvm\include;..\extern\llvm_win64_8_0_1\include;..\extern\llvm-project_8_0_1\llvm\lib\Target;..\extern\llvm_win64_8_0_1\lib\Target\X86;..\extern\llvm-project_8_0_1\llvm\tools\clang\include;..\extern\curl\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-winssl\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>