mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed generic alias and generic delegate issues
This commit is contained in:
parent
639430b41c
commit
5a5287bc8b
10 changed files with 702 additions and 434 deletions
|
@ -4881,7 +4881,8 @@ void BfCompiler::PopulateReified()
|
|||
|
||||
auto typeInst = type->ToTypeInstance();
|
||||
|
||||
if ((typeInst != NULL) && (typeInst->IsGenericTypeInstance()) && (!typeInst->IsUnspecializedType()))
|
||||
if ((typeInst != NULL) && (typeInst->IsGenericTypeInstance()) && (!typeInst->IsUnspecializedType()) &&
|
||||
(!typeInst->IsDelegateFromTypeRef()) && (!typeInst->IsFunctionFromTypeRef()))
|
||||
{
|
||||
auto unspecializedType = module->GetUnspecializedTypeInstance(typeInst);
|
||||
if (!unspecializedType->mIsReified)
|
||||
|
|
|
@ -758,8 +758,9 @@ BfType * BfContext::FindTypeById(int typeId)
|
|||
|
||||
void BfContext::AddTypeToWorkList(BfType* type)
|
||||
{
|
||||
BF_ASSERT((type->mRebuildFlags & BfTypeRebuildFlag_InTempPool) == 0);
|
||||
if ((type->mRebuildFlags & BfTypeRebuildFlag_AddedToWorkList) == 0)
|
||||
{
|
||||
{
|
||||
type->mRebuildFlags = (BfTypeRebuildFlags)(type->mRebuildFlags | BfTypeRebuildFlag_AddedToWorkList);
|
||||
|
||||
BfTypeProcessRequest* typeProcessRequest = mPopulateTypeWorkList.Alloc();
|
||||
|
@ -2221,9 +2222,10 @@ void BfContext::GenerateModuleName_Type(BfType* type, String& name)
|
|||
|
||||
if (type->IsDelegateFromTypeRef() || type->IsFunctionFromTypeRef())
|
||||
{
|
||||
auto delegateType = (BfDelegateType*)type;
|
||||
auto typeInst = type->ToTypeInstance();
|
||||
auto delegateInfo = type->GetDelegateInfo();
|
||||
|
||||
auto methodDef = delegateType->mTypeDef->mMethods[0];
|
||||
auto methodDef = typeInst->mTypeDef->mMethods[0];
|
||||
|
||||
if (type->IsDelegateFromTypeRef())
|
||||
name += "DELEGATE_";
|
||||
|
|
|
@ -382,6 +382,7 @@ public:
|
|||
BfAllocPool<BfConcreteInterfaceType> mConcreteInterfaceTypePool;
|
||||
BfAllocPool<BfConstExprValueType> mConstExprValueTypePool;
|
||||
BfAllocPool<BfDelegateType> mDelegateTypePool;
|
||||
BfAllocPool<BfGenericDelegateType> mGenericDelegateTypePool;
|
||||
BfPrimitiveType* mPrimitiveTypes[BfTypeCode_Length];
|
||||
BfPrimitiveType* mPrimitiveStructTypes[BfTypeCode_Length];
|
||||
|
||||
|
|
|
@ -562,9 +562,9 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
|
|||
BfType* origPrevParamType = prevParamType;
|
||||
|
||||
if ((genericArgumentsSubstitute != NULL) && (paramType->IsUnspecializedType()))
|
||||
paramType = mModule->ResolveGenericType(paramType, *genericArgumentsSubstitute, allowSpecializeFail);
|
||||
paramType = mModule->ResolveGenericType(paramType, NULL, genericArgumentsSubstitute, allowSpecializeFail);
|
||||
if ((prevGenericArgumentsSubstitute != NULL) && (prevParamType->IsUnspecializedType()))
|
||||
prevParamType = mModule->ResolveGenericType(prevParamType, *prevGenericArgumentsSubstitute, allowSpecializeFail);
|
||||
prevParamType = mModule->ResolveGenericType(prevParamType, NULL, prevGenericArgumentsSubstitute, allowSpecializeFail);
|
||||
|
||||
if ((wasGenericParam) || (prevWasGenericParam))
|
||||
{
|
||||
|
@ -957,7 +957,7 @@ BfTypedValue BfMethodMatcher::ResolveArgTypedValue(BfResolvedArg& resolvedArg, B
|
|||
}
|
||||
|
||||
if ((genericArgumentsSubstitute != NULL) && (expectType->IsUnspecializedType()))
|
||||
expectType = mModule->ResolveGenericType(expectType, *genericArgumentsSubstitute, true);
|
||||
expectType = mModule->ResolveGenericType(expectType, NULL, genericArgumentsSubstitute, true);
|
||||
}
|
||||
|
||||
exprEvaluator.mExpectingType = expectType;
|
||||
|
@ -1067,13 +1067,13 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfGenericParamInstance* generi
|
|||
{
|
||||
auto leftType = checkOpConstraint.mLeftType;
|
||||
if ((leftType != NULL) && (leftType->IsUnspecializedType()))
|
||||
leftType = mModule->ResolveGenericType(leftType, *methodGenericArgs);
|
||||
leftType = mModule->ResolveGenericType(leftType, NULL, methodGenericArgs);
|
||||
if (leftType != NULL)
|
||||
leftType = mModule->FixIntUnknown(leftType);
|
||||
|
||||
auto rightType = checkOpConstraint.mRightType;
|
||||
if ((rightType != NULL) && (rightType->IsUnspecializedType()))
|
||||
rightType = mModule->ResolveGenericType(rightType, *methodGenericArgs);
|
||||
rightType = mModule->ResolveGenericType(rightType, NULL, methodGenericArgs);
|
||||
if (rightType != NULL)
|
||||
rightType = mModule->FixIntUnknown(rightType);
|
||||
|
||||
|
@ -1309,7 +1309,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
|||
|
||||
if ((checkType != NULL) && (genericArgumentsSubstitute != NULL) && (checkType->IsUnspecializedType()))
|
||||
{
|
||||
checkType = mModule->ResolveGenericType(origCheckType, *genericArgumentsSubstitute);
|
||||
checkType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute);
|
||||
}
|
||||
|
||||
if (wantType->IsUnspecializedType())
|
||||
|
@ -1453,7 +1453,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
|||
auto wantType = methodInstance->GetParamType(paramIdx);
|
||||
if ((genericArgumentsSubstitute != NULL) && (wantType->IsUnspecializedType()))
|
||||
{
|
||||
auto resolvedType = mModule->ResolveGenericType(wantType, *genericArgumentsSubstitute);
|
||||
auto resolvedType = mModule->ResolveGenericType(wantType, NULL, genericArgumentsSubstitute);
|
||||
if (resolvedType == NULL)
|
||||
goto NoMatch;
|
||||
wantType = resolvedType;
|
||||
|
@ -6306,7 +6306,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
|
|||
|
||||
if (isUnboundCall)
|
||||
{
|
||||
if (mModule->mCurMethodInstance->mIsUnspecialized)
|
||||
if ((mModule->mCurMethodInstance != NULL) && (mModule->mCurMethodInstance->mIsUnspecialized))
|
||||
{
|
||||
auto varType = mModule->GetPrimitiveType(BfTypeCode_Var);
|
||||
|
||||
|
|
|
@ -6861,7 +6861,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
|
|||
{
|
||||
BfType* convCheckConstraint = genericParamInst->mTypeConstraint;
|
||||
if ((convCheckConstraint->IsUnspecializedType()) && (methodGenericArgs != NULL))
|
||||
convCheckConstraint = ResolveGenericType(convCheckConstraint, *methodGenericArgs);
|
||||
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs);
|
||||
if ((checkArgType->IsMethodRef()) && (convCheckConstraint->IsDelegate()))
|
||||
{
|
||||
auto methodRefType = (BfMethodRefType*)checkArgType;
|
||||
|
@ -6932,7 +6932,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
|
|||
{
|
||||
BfType* convCheckConstraint = checkConstraint;
|
||||
if (convCheckConstraint->IsUnspecializedType())
|
||||
convCheckConstraint = ResolveGenericType(convCheckConstraint, *methodGenericArgs);
|
||||
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs);
|
||||
|
||||
BfTypeInstance* typeConstraintInst = convCheckConstraint->ToTypeInstance();
|
||||
|
||||
|
@ -6973,13 +6973,13 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
|
|||
{
|
||||
auto leftType = checkOpConstraint.mLeftType;
|
||||
if ((leftType != NULL) && (leftType->IsUnspecializedType()))
|
||||
leftType = ResolveGenericType(leftType, *methodGenericArgs);
|
||||
leftType = ResolveGenericType(leftType, NULL, methodGenericArgs);
|
||||
if (leftType != NULL)
|
||||
leftType = FixIntUnknown(leftType);
|
||||
|
||||
auto rightType = checkOpConstraint.mRightType;
|
||||
if ((rightType != NULL) && (rightType->IsUnspecializedType()))
|
||||
rightType = ResolveGenericType(rightType, *methodGenericArgs);
|
||||
rightType = ResolveGenericType(rightType, NULL, methodGenericArgs);
|
||||
if (rightType != NULL)
|
||||
rightType = FixIntUnknown(rightType);
|
||||
|
||||
|
@ -8792,16 +8792,27 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
bool isStructPtr = typedVal.mType->IsStructPtr();
|
||||
if (fromStructTypeInstance == NULL)
|
||||
{
|
||||
auto primType = (BfPrimitiveType*)typedVal.mType;
|
||||
fromStructTypeInstance = GetWrappedStructType(typedVal.mType);
|
||||
auto primType = (BfPrimitiveType*)typedVal.mType;
|
||||
|
||||
if ((typedVal.mType->IsPointer()) && (toTypeInstance->IsInstanceOf(mCompiler->mIHashableTypeDef)))
|
||||
{
|
||||
// Can always do IHashable
|
||||
alreadyCheckedCast = true;
|
||||
}
|
||||
|
||||
if ((!typedVal.mType->IsPointer()) || (toTypeInstance == mContext->mBfObjectType))
|
||||
fromStructTypeInstance = GetWrappedStructType(typedVal.mType);
|
||||
|
||||
if (isStructPtr)
|
||||
{
|
||||
if ((toTypeInstance != NULL) && (TypeIsSubTypeOf(fromStructTypeInstance, toTypeInstance)))
|
||||
if ((toTypeInstance != NULL) && (fromStructTypeInstance != NULL) && (TypeIsSubTypeOf(fromStructTypeInstance, toTypeInstance)))
|
||||
alreadyCheckedCast = true;
|
||||
|
||||
fromStructTypeInstance = typedVal.mType->GetUnderlyingType()->ToTypeInstance();
|
||||
}
|
||||
|
||||
if ((fromStructTypeInstance == NULL) && (alreadyCheckedCast))
|
||||
fromStructTypeInstance = GetWrappedStructType(typedVal.mType);
|
||||
}
|
||||
if (fromStructTypeInstance == NULL)
|
||||
return BfTypedValue();
|
||||
|
@ -8810,7 +8821,7 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
bool isBoxedType = (fromStructTypeInstance != NULL) && (toType->IsBoxed());
|
||||
|
||||
if ((toType == NULL) || (toType == mContext->mBfObjectType) || (isBoxedType) || (alreadyCheckedCast) || (TypeIsSubTypeOf(fromStructTypeInstance, toTypeInstance)))
|
||||
{
|
||||
{
|
||||
if (mBfIRBuilder->mIgnoreWrites)
|
||||
return BfTypedValue(mBfIRBuilder->GetFakeVal(), (toType != NULL) ? toType : CreateBoxedType(typedVal.mType));
|
||||
|
||||
|
@ -9307,7 +9318,7 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
|
|||
|
||||
BfType* type = methodInst->mMethodInstanceGroup->mOwner;
|
||||
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType()))
|
||||
type = ResolveGenericType(type, *methodGenericArgs);
|
||||
type = ResolveGenericType(type, NULL, methodGenericArgs);
|
||||
String methodName;
|
||||
if ((methodNameFlags & BfMethodNameFlag_OmitTypeName) == 0)
|
||||
{
|
||||
|
@ -9453,7 +9464,7 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
|
|||
}
|
||||
|
||||
if (type->IsUnspecializedType())
|
||||
type = ResolveGenericType(type, *methodGenericArgs);
|
||||
type = ResolveGenericType(type, NULL, methodGenericArgs);
|
||||
}
|
||||
|
||||
if ((methodGenericArgs == NULL) && (mCurMethodInstance == NULL) && (mCurTypeInstance == NULL))
|
||||
|
@ -9486,7 +9497,7 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
|
|||
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
|
||||
BfType* type = methodInst->GetParamType(paramIdx);
|
||||
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType()))
|
||||
type = ResolveGenericType(type, *methodGenericArgs);
|
||||
type = ResolveGenericType(type, NULL, methodGenericArgs);
|
||||
methodName += TypeToString(type, typeNameFlags);
|
||||
|
||||
methodName += " ";
|
||||
|
|
|
@ -81,7 +81,8 @@ enum BfCastFlags
|
|||
BfCastFlags_FromCompiler = 0x40, // Not user specified
|
||||
BfCastFlags_Force = 0x80,
|
||||
BfCastFlags_PreferAddr = 0x100,
|
||||
BfCastFlags_WarnOnBox = 0x200
|
||||
BfCastFlags_WarnOnBox = 0x200,
|
||||
BfCastFlags_IsCastCheck = 0x400
|
||||
};
|
||||
|
||||
enum BfCastResultFlags
|
||||
|
@ -1646,7 +1647,7 @@ public:
|
|||
BfType* FixIntUnknown(BfType* type);
|
||||
void FixIntUnknown(BfTypedValue& typedVal);
|
||||
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
|
||||
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef);
|
||||
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL);
|
||||
BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data);
|
||||
void ResolveGenericParamConstraints(BfGenericParamInstance* genericParamInstance, bool isUnspecialized);
|
||||
String GenericParamSourceToString(const BfGenericParamSource& genericParamSource);
|
||||
|
@ -1677,7 +1678,7 @@ public:
|
|||
void EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scope, BfIRBlock doneBlock = BfIRBlock());
|
||||
void MarkScopeLeft(BfScopeData* scopeData);
|
||||
BfGenericParamType* GetGenericParamType(BfGenericParamKind paramKind, int paramIdx);
|
||||
BfType* ResolveGenericType(BfType* unspecializedType, const BfTypeVector& methodGenericArguments, bool allowFail = false);
|
||||
BfType* ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, bool allowFail = false);
|
||||
bool IsUnboundGeneric(BfType* type);
|
||||
BfGenericParamInstance* GetGenericTypeParamInstance(int paramIdx);
|
||||
BfGenericParamInstance* GetGenericParamInstance(BfGenericParamType* type);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1907,9 +1907,7 @@ void BfClosureType::Finish()
|
|||
|
||||
BfDelegateType::~BfDelegateType()
|
||||
{
|
||||
delete mTypeDef;
|
||||
for (auto directAllocNode : mDirectAllocNodes)
|
||||
delete directAllocNode;
|
||||
delete mTypeDef;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2129,6 +2127,19 @@ int BfResolvedTypeSet::Hash(BfType* type, LookupContext* ctx, bool allowRef)
|
|||
{
|
||||
//BP_ZONE("BfResolvedTypeSet::Hash");
|
||||
|
||||
// if (type->IsTypeAlias())
|
||||
// {
|
||||
// auto underlyingType = type->GetUnderlyingType();
|
||||
// BF_ASSERT(underlyingType != NULL);
|
||||
// if (underlyingType == NULL)
|
||||
// {
|
||||
// ctx->mFailed = true;
|
||||
// return 0;
|
||||
// }
|
||||
// return Hash(underlyingType, ctx, allowRef);
|
||||
// }
|
||||
// else
|
||||
|
||||
if (type->IsBoxed())
|
||||
{
|
||||
BfBoxedType* boxedType = (BfBoxedType*)type;
|
||||
|
@ -2142,21 +2153,22 @@ int BfResolvedTypeSet::Hash(BfType* type, LookupContext* ctx, bool allowRef)
|
|||
return (elemHash << 5) - elemHash;
|
||||
}
|
||||
else if (type->IsDelegateFromTypeRef() || type->IsFunctionFromTypeRef())
|
||||
{
|
||||
auto delegateType = (BfDelegateType*)type;
|
||||
|
||||
{
|
||||
auto typeInst = (BfTypeInstance*)type;
|
||||
int hashVal = HASH_DELEGATE;
|
||||
|
||||
hashVal = ((hashVal ^ (Hash(delegateType->mReturnType, ctx))) << 5) - hashVal;
|
||||
auto delegateInfo = type->GetDelegateInfo();
|
||||
|
||||
auto methodDef = delegateType->mTypeDef->mMethods[0];
|
||||
hashVal = ((hashVal ^ (Hash(delegateInfo->mReturnType, ctx))) << 5) - hashVal;
|
||||
|
||||
auto methodDef = typeInst->mTypeDef->mMethods[0];
|
||||
BF_ASSERT(methodDef->mName == "Invoke");
|
||||
BF_ASSERT(delegateType->mParams.size() == methodDef->mParams.size());
|
||||
BF_ASSERT(delegateInfo->mParams.size() == methodDef->mParams.size());
|
||||
|
||||
for (int paramIdx = 0; paramIdx < delegateType->mParams.size(); paramIdx++)
|
||||
for (int paramIdx = 0; paramIdx < delegateInfo->mParams.size(); paramIdx++)
|
||||
{
|
||||
// Parse attributes?
|
||||
hashVal = ((hashVal ^ (Hash(delegateType->mParams[paramIdx], ctx))) << 5) - hashVal;
|
||||
hashVal = ((hashVal ^ (Hash(delegateInfo->mParams[paramIdx], ctx))) << 5) - hashVal;
|
||||
String paramName = methodDef->mParams[paramIdx]->mName;
|
||||
int nameHash = (int)Hash64(paramName.c_str(), (int)paramName.length());
|
||||
hashVal = ((hashVal ^ (nameHash)) << 5) - hashVal;
|
||||
|
@ -2313,61 +2325,28 @@ static int HashNode(BfAstNode* node)
|
|||
return (int)Hash64(nameStr, node->GetSrcLength());
|
||||
}
|
||||
|
||||
int BfResolvedTypeSet::DirectHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags)
|
||||
{
|
||||
bool isHeadType = typeRef == ctx->mRootTypeRef;
|
||||
|
||||
BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None;
|
||||
if ((flags & BfHashFlag_AllowGenericParamConstValue) != 0)
|
||||
resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
|
||||
auto resolvedType = ctx->mModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, resolveFlags);
|
||||
if (resolvedType == NULL)
|
||||
{
|
||||
ctx->mFailed = true;
|
||||
return 0;
|
||||
}
|
||||
return Hash(resolvedType, ctx);
|
||||
}
|
||||
|
||||
int BfResolvedTypeSet::Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags)
|
||||
{
|
||||
// if (auto typeDefTypeRef = BfNodeDynCast<BfTypeDefTypeReference>(typeRef))
|
||||
// {
|
||||
// if (typeDefTypeRef->mTypeDef != NULL)
|
||||
// {
|
||||
// int hashVal = typeDefTypeRef->mTypeDef->mHash;
|
||||
//
|
||||
// if (typeDefTypeRef->mTypeDef->mGenericParamDefs.size() != 0)
|
||||
// {
|
||||
// auto checkTypeInstance = ctx->mModule->mCurTypeInstance;
|
||||
// if (checkTypeInstance->IsBoxed())
|
||||
// checkTypeInstance = checkTypeInstance->GetUnderlyingType()->ToTypeInstance();
|
||||
//
|
||||
// //if (!module->TypeHasParent(module->mCurTypeInstance->mTypeDef, typeDefTypeRef->mTypeDef->mParentType))
|
||||
// auto outerType = ctx->mModule->mSystem->GetOuterTypeNonPartial(typeDefTypeRef->mTypeDef);
|
||||
// BfTypeDef* commonOuterType = ctx->mModule->FindCommonOuterType(ctx->mModule->mCurTypeInstance->mTypeDef, outerType);
|
||||
// //BfTypeDef* commonOuterType = ctx->mModule->FindCommonOuterType(ctx->mModule->GetActiveTypeDef(), typeDefTypeRef->mTypeDef->mOuterType);
|
||||
// if ((commonOuterType == NULL) || (commonOuterType->mGenericParamDefs.size() == 0))
|
||||
// {
|
||||
// ctx->mModule->Fail("Generic arguments expected", typeDefTypeRef);
|
||||
// ctx->mFailed = true;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// BF_ASSERT(checkTypeInstance->IsGenericTypeInstance());
|
||||
// auto curGenericTypeInst = (BfGenericTypeInstance*)checkTypeInstance;
|
||||
// //int numParentGenericParams = (int)typeDefTypeRef->mTypeDef->mGenericParams.size();
|
||||
// int numParentGenericParams = (int)commonOuterType->mGenericParamDefs.size();
|
||||
// for (int i = 0; i < numParentGenericParams; i++)
|
||||
// {
|
||||
// hashVal = ((hashVal ^ (Hash(curGenericTypeInst->mTypeGenericArguments[i], ctx))) << 5) - hashVal;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return hashVal;
|
||||
// }
|
||||
//
|
||||
// bool isHeadType = typeRef == ctx->mRootTypeRef;
|
||||
//
|
||||
// BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None;
|
||||
// if ((flags & BfHashFlag_AllowGenericParamConstValue) != 0)
|
||||
// resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
//
|
||||
// auto resolvedType = ctx->mModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, resolveFlags);
|
||||
// if (resolvedType == NULL)
|
||||
// {
|
||||
// ctx->mFailed = true;
|
||||
// return 0;
|
||||
// }
|
||||
// return Hash(resolvedType, ctx);
|
||||
// }
|
||||
|
||||
if ((typeRef == ctx->mRootTypeRef) && (ctx->mRootTypeDef != NULL))
|
||||
{
|
||||
if ((typeRef == ctx->mRootTypeRef) && (ctx->mRootTypeDef != NULL) &&
|
||||
((typeRef->IsNamedTypeReference()) || (BfNodeIsA<BfDirectTypeDefReference>(typeRef))))
|
||||
{
|
||||
BfTypeDef* typeDef = ctx->mRootTypeDef;
|
||||
|
||||
int hashVal = typeDef->mHash;
|
||||
|
@ -2401,24 +2380,48 @@ int BfResolvedTypeSet::Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHash
|
|||
|
||||
if (typeRef->IsNamedTypeReference())
|
||||
{
|
||||
bool isHeadType = typeRef == ctx->mRootTypeRef;
|
||||
|
||||
BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None;
|
||||
if ((flags & BfHashFlag_AllowGenericParamConstValue) != 0)
|
||||
resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
|
||||
auto resolvedType = ctx->mModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, resolveFlags);
|
||||
if (resolvedType == NULL)
|
||||
{
|
||||
ctx->mFailed = true;
|
||||
return 0;
|
||||
}
|
||||
return Hash(resolvedType, ctx);
|
||||
return DirectHash(typeRef, ctx, flags);
|
||||
}
|
||||
else if (auto genericInstTypeRef = BfNodeDynCastExact<BfGenericInstanceTypeRef>(typeRef))
|
||||
{
|
||||
//BfType* type = NULL;
|
||||
BfTypeDef* elementTypeDef = ctx->mModule->ResolveGenericInstanceDef(genericInstTypeRef);
|
||||
|
||||
if (elementTypeDef == NULL)
|
||||
{
|
||||
ctx->mFailed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Don't translate aliases for the root type, just element types
|
||||
if (ctx->mRootTypeRef == typeRef)
|
||||
{
|
||||
BF_ASSERT((ctx->mRootTypeDef == NULL) || (ctx->mRootTypeDef == elementTypeDef));
|
||||
ctx->mRootTypeDef = elementTypeDef;
|
||||
}
|
||||
else if (elementTypeDef->mTypeCode == BfTypeCode_TypeAlias)
|
||||
{
|
||||
BfTypeVector genericArgs;
|
||||
for (auto genericArgTypeRef : genericInstTypeRef->mGenericArguments)
|
||||
{
|
||||
auto argType = ctx->mModule->ResolveTypeRef(genericArgTypeRef, BfPopulateType_Identity);
|
||||
if (argType != NULL)
|
||||
genericArgs.Add(argType);
|
||||
else
|
||||
ctx->mFailed = true;
|
||||
}
|
||||
|
||||
if (!ctx->mFailed)
|
||||
{
|
||||
auto resolvedType = ctx->mModule->ResolveTypeDef(elementTypeDef, genericArgs);
|
||||
if ((resolvedType != NULL) && (resolvedType->IsTypeAlias()))
|
||||
{
|
||||
auto underlyingType = resolvedType->GetUnderlyingType();
|
||||
return Hash(underlyingType, ctx, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int hashVal;
|
||||
/*if (type != NULL)
|
||||
{
|
||||
|
@ -2426,17 +2429,7 @@ int BfResolvedTypeSet::Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHash
|
|||
}
|
||||
else */
|
||||
{
|
||||
if (elementTypeDef == NULL)
|
||||
{
|
||||
ctx->mFailed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->mRootTypeRef == typeRef)
|
||||
{
|
||||
BF_ASSERT((ctx->mRootTypeDef == NULL) || (ctx->mRootTypeDef == elementTypeDef));
|
||||
ctx->mRootTypeDef = elementTypeDef;
|
||||
}
|
||||
|
||||
|
||||
hashVal = elementTypeDef->mHash;
|
||||
}
|
||||
|
@ -2810,22 +2803,22 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx)
|
|||
if (!rhs->IsDelegateFromTypeRef() && !rhs->IsFunctionFromTypeRef())
|
||||
return false;
|
||||
if (lhs->IsDelegate() != rhs->IsDelegate())
|
||||
return false;
|
||||
BfDelegateType* lhsDelegateType = (BfDelegateType*)lhs;
|
||||
BfDelegateType* rhsDelegateType = (BfDelegateType*)rhs;
|
||||
if (lhsDelegateType->mTypeDef->mIsDelegate != rhsDelegateType->mTypeDef->mIsDelegate)
|
||||
return false;
|
||||
BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo();
|
||||
BfDelegateInfo* rhsDelegateInfo = rhs->GetDelegateInfo();
|
||||
if (lhsInst->mTypeDef->mIsDelegate != rhsInst->mTypeDef->mIsDelegate)
|
||||
return false;
|
||||
|
||||
auto lhsMethodDef = lhsDelegateType->mTypeDef->mMethods[0];
|
||||
auto rhsMethodDef = rhsDelegateType->mTypeDef->mMethods[0];
|
||||
auto lhsMethodDef = lhsInst->mTypeDef->mMethods[0];
|
||||
auto rhsMethodDef = rhsInst->mTypeDef->mMethods[0];
|
||||
|
||||
if (lhsDelegateType->mReturnType != rhsDelegateType->mReturnType)
|
||||
if (lhsDelegateInfo->mReturnType != rhsDelegateInfo->mReturnType)
|
||||
return false;
|
||||
if (lhsDelegateType->mParams.size() != rhsDelegateType->mParams.size())
|
||||
if (lhsDelegateInfo->mParams.size() != rhsDelegateInfo->mParams.size())
|
||||
return false;
|
||||
for (int paramIdx = 0; paramIdx < lhsDelegateType->mParams.size(); paramIdx++)
|
||||
for (int paramIdx = 0; paramIdx < lhsDelegateInfo->mParams.size(); paramIdx++)
|
||||
{
|
||||
if (lhsDelegateType->mParams[paramIdx] != rhsDelegateType->mParams[paramIdx])
|
||||
if (lhsDelegateInfo->mParams[paramIdx] != rhsDelegateInfo->mParams[paramIdx])
|
||||
return false;
|
||||
if (lhsMethodDef->mParams[paramIdx]->mName != rhsMethodDef->mParams[paramIdx]->mName)
|
||||
return false;
|
||||
|
@ -3104,8 +3097,11 @@ BfType* BfResolvedTypeSet::LookupContext::ResolveTypeRef(BfTypeReference* typeRe
|
|||
return mModule->ResolveTypeRef(typeReference, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
}
|
||||
|
||||
BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* typeReference)
|
||||
BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* typeReference, BfType** outType)
|
||||
{
|
||||
if (outType != NULL)
|
||||
*outType = NULL;
|
||||
|
||||
if (typeReference == mRootTypeRef)
|
||||
return mRootTypeDef;
|
||||
|
||||
|
@ -3114,9 +3110,11 @@ BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* t
|
|||
return typeDefTypeRef->mTypeDef;
|
||||
}
|
||||
|
||||
auto type = mModule->ResolveTypeRef(typeReference, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
auto type = mModule->ResolveTypeRef(typeReference, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
if (type == NULL)
|
||||
return NULL;
|
||||
if (outType != NULL)
|
||||
*outType = type;
|
||||
if (type->IsPrimitiveType())
|
||||
return ((BfPrimitiveType*)type)->mTypeDef;
|
||||
auto typeInst = type->ToTypeInstance();
|
||||
|
@ -3125,9 +3123,26 @@ BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* t
|
|||
return typeInst->mTypeDef;
|
||||
}
|
||||
|
||||
bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx)
|
||||
bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, BfTypeDef* rhsTypeDef, LookupContext* ctx)
|
||||
{
|
||||
auto rhsType = ctx->mModule->ResolveTypeDef(rhsTypeDef, BfPopulateType_Identity);
|
||||
if (rhsType == NULL)
|
||||
{
|
||||
ctx->mFailed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return BfResolvedTypeSet::Equals(lhs, rhsType, ctx);
|
||||
}
|
||||
|
||||
bool BfResolvedTypeSet::EqualsNoAlias(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx)
|
||||
{
|
||||
//BP_ZONE("BfResolvedTypeSet::Equals");
|
||||
|
||||
// if ((rhs == ctx->mRootTypeRef) && (ctx->mRootTypeDef != NULL) && (ctx->mRootTypeDef->mTypeCode == BfTypeCode_TypeAlias))
|
||||
// {
|
||||
// return lhs == ctx->mResolvedType;
|
||||
// }
|
||||
|
||||
if (ctx->mRootTypeRef != rhs)
|
||||
{
|
||||
|
@ -3138,7 +3153,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
}
|
||||
}
|
||||
|
||||
if (rhs->IsNamedTypeReference())
|
||||
if (rhs->IsNamedTypeReference())
|
||||
{
|
||||
if ((ctx->mRootTypeRef != rhs) || (ctx->mRootTypeDef == NULL))
|
||||
{
|
||||
|
@ -3198,9 +3213,9 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
auto rhsDelegateType = BfNodeDynCastExact<BfDelegateTypeRef>(rhs);
|
||||
if (rhsDelegateType == NULL)
|
||||
return false;
|
||||
BfDelegateType* lhsDelegateType = (BfDelegateType*)lhs;
|
||||
BfDelegateInfo* lhsDelegateType = lhs->GetDelegateInfo();
|
||||
|
||||
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhsDelegateType->ToTypeInstance(), 0, "Invoke");
|
||||
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhs->ToTypeInstance(), 0, "Invoke");
|
||||
|
||||
if ((lhs->IsDelegate()) != (rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate))
|
||||
return false;
|
||||
|
@ -3227,9 +3242,13 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
|
||||
if (lhs->IsGenericTypeInstance())
|
||||
{
|
||||
auto rhsTypeDef = ctx->ResolveToTypeDef(rhs);
|
||||
if (rhsTypeDef == NULL)
|
||||
return false;
|
||||
BfType* rhsType = NULL;
|
||||
auto rhsTypeDef = ctx->ResolveToTypeDef(rhs, &rhsType);
|
||||
if (rhsTypeDef == NULL)
|
||||
return false;
|
||||
|
||||
if (rhsType != NULL)
|
||||
return lhs == rhsType;
|
||||
|
||||
BfGenericTypeInstance* lhsGenericType = (BfGenericTypeInstance*) lhs;
|
||||
return GenericTypeEquals(lhsGenericType, &lhsGenericType->mTypeGenericArguments, rhs, rhsTypeDef, ctx);
|
||||
|
@ -3329,6 +3348,8 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
|
||||
BfPrimitiveType* lhsPrimType = (BfPrimitiveType*)lhs;
|
||||
auto rhsTypeDef = ctx->ResolveToTypeDef(rhs);
|
||||
// if (rhsTypeDef->mTypeCode == BfTypeCode_TypeAlias)
|
||||
// return Equals(lhs, rhs, rhsTypeDef, ctx);
|
||||
return lhsPrimType->mTypeDef == rhsTypeDef;
|
||||
}
|
||||
else if (lhs->IsPointer())
|
||||
|
@ -3483,6 +3504,22 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
|||
return false;
|
||||
}
|
||||
|
||||
bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx)
|
||||
{
|
||||
if (EqualsNoAlias(lhs, rhs, ctx))
|
||||
return true;
|
||||
|
||||
// if (lhs->IsTypeAlias())
|
||||
// {
|
||||
// auto underylingType = lhs->GetUnderlyingType();
|
||||
// BF_ASSERT(underylingType != NULL);
|
||||
// if (underylingType != NULL)
|
||||
// return Equals(underylingType, rhs, ctx);
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BfResolvedTypeSet::RemoveEntry(BfResolvedTypeSet::Entry* entry)
|
||||
{
|
||||
int hashIdx = (entry->mHash & 0x7FFFFFFF) % mHashSize;
|
||||
|
@ -3833,7 +3870,7 @@ String BfTypeUtils::TypeToString(BfTypeReference* typeRef)
|
|||
return name;
|
||||
}
|
||||
|
||||
BF_DBG_FATAL("Not implemented");
|
||||
//BF_DBG_FATAL("Not implemented");
|
||||
return typeRef->ToString();
|
||||
}
|
||||
|
||||
|
|
|
@ -374,6 +374,7 @@ enum BfTypeRebuildFlags
|
|||
BfTypeRebuildFlag_SpecializedByAutocompleteMethod = 0x200,
|
||||
BfTypeRebuildFlag_UnderlyingTypeDeferred = 0x400,
|
||||
BfTypeRebuildFlag_TypeDataSaved = 0x800,
|
||||
BfTypeRebuildFlag_InTempPool = 0x1000
|
||||
};
|
||||
|
||||
class BfTypeDIReplaceCallback;
|
||||
|
@ -388,6 +389,26 @@ enum BfTypeDefineState : uint8
|
|||
BfTypeDefineState_DefinedAndMethodsSlotted,
|
||||
};
|
||||
|
||||
class BfDelegateInfo
|
||||
{
|
||||
public:
|
||||
Array<BfAstNode*> mDirectAllocNodes;
|
||||
BfType* mReturnType;
|
||||
Array<BfType*> mParams;
|
||||
|
||||
public:
|
||||
BfDelegateInfo()
|
||||
{
|
||||
mReturnType = NULL;
|
||||
}
|
||||
|
||||
~BfDelegateInfo()
|
||||
{
|
||||
for (auto directAllocNode : mDirectAllocNodes)
|
||||
delete directAllocNode;
|
||||
}
|
||||
};
|
||||
|
||||
class BfType
|
||||
{
|
||||
public:
|
||||
|
@ -469,6 +490,7 @@ public:
|
|||
virtual bool IsFunction() { return false; }
|
||||
virtual bool IsDelegateFromTypeRef() { return false; }
|
||||
virtual bool IsFunctionFromTypeRef() { return false; }
|
||||
virtual BfDelegateInfo* GetDelegateInfo() { return NULL; }
|
||||
virtual bool IsValueType() { return false; }
|
||||
virtual bool IsValueTypeOrValueTypePtr() { return false; }
|
||||
virtual bool IsWrappableType() { return false; }
|
||||
|
@ -1968,21 +1990,16 @@ public:
|
|||
|
||||
class BfDelegateType : public BfTypeInstance
|
||||
{
|
||||
public:
|
||||
Array<BfAstNode*> mDirectAllocNodes;
|
||||
// These depend on the params in Invoke
|
||||
public:
|
||||
BfDelegateInfo mDelegateInfo;
|
||||
bool mIsUnspecializedType;
|
||||
bool mIsUnspecializedTypeVariation;
|
||||
|
||||
BfType* mReturnType;
|
||||
Array<BfType*> mParams;
|
||||
bool mIsUnspecializedTypeVariation;
|
||||
|
||||
public:
|
||||
BfDelegateType()
|
||||
{
|
||||
mIsUnspecializedType = false;
|
||||
mIsUnspecializedTypeVariation = false;
|
||||
mReturnType = NULL;
|
||||
mIsUnspecializedTypeVariation = false;
|
||||
}
|
||||
~BfDelegateType();
|
||||
|
||||
|
@ -1996,6 +2013,30 @@ public:
|
|||
|
||||
virtual bool IsUnspecializedType() override { return mIsUnspecializedType; }
|
||||
virtual bool IsUnspecializedTypeVariation() override { return mIsUnspecializedTypeVariation; }
|
||||
|
||||
virtual BfDelegateInfo* GetDelegateInfo() { return &mDelegateInfo; }
|
||||
};
|
||||
|
||||
class BfGenericDelegateType : public BfGenericTypeInstance
|
||||
{
|
||||
public:
|
||||
BfDelegateInfo mDelegateInfo;
|
||||
|
||||
public:
|
||||
BfGenericDelegateType()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual bool IsOnDemand() override { return true; }
|
||||
|
||||
virtual bool IsDelegate() override { return mTypeDef->mIsDelegate; }
|
||||
virtual bool IsDelegateFromTypeRef() override { return mTypeDef->mIsDelegate; }
|
||||
|
||||
virtual bool IsFunction() override { return !mTypeDef->mIsDelegate; }
|
||||
virtual bool IsFunctionFromTypeRef() override { return !mTypeDef->mIsDelegate; }
|
||||
|
||||
virtual BfDelegateInfo* GetDelegateInfo() override { return &mDelegateInfo; }
|
||||
//virtual bool IsReified() override { return mIsReified; }
|
||||
};
|
||||
|
||||
|
@ -2303,7 +2344,7 @@ public:
|
|||
public:
|
||||
BfModule* mModule;
|
||||
BfTypeReference* mRootTypeRef;
|
||||
BfTypeDef* mRootTypeDef;
|
||||
BfTypeDef* mRootTypeDef;
|
||||
BfType* mResolvedType;
|
||||
bool mFailed;
|
||||
|
||||
|
@ -2311,14 +2352,14 @@ public:
|
|||
LookupContext()
|
||||
{
|
||||
mRootTypeRef = NULL;
|
||||
mRootTypeDef = NULL;
|
||||
mRootTypeDef = NULL;
|
||||
mModule = NULL;
|
||||
mResolvedType = NULL;
|
||||
mFailed = false;
|
||||
}
|
||||
|
||||
BfType* ResolveTypeRef(BfTypeReference* typeReference);
|
||||
BfTypeDef* ResolveToTypeDef(BfTypeReference* typeReference);
|
||||
BfTypeDef* ResolveToTypeDef(BfTypeReference* typeReference, BfType** outType = NULL);
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -2327,9 +2368,12 @@ public:
|
|||
static bool GenericTypeEquals(BfGenericTypeInstance* lhsGenericType, BfTypeVector* typeGenericArguments, BfTypeReference* rhs, BfTypeDef* rhsTypeDef, LookupContext* ctx);
|
||||
static void HashGenericArguments(BfTypeReference* typeRef, LookupContext* ctx, int& hash);
|
||||
static int Hash(BfType* type, LookupContext* ctx, bool allowRef = false);
|
||||
static int DirectHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None);
|
||||
static int Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None);
|
||||
static bool Equals(BfType* lhs, BfType* rhs, LookupContext* ctx);
|
||||
static bool EqualsNoAlias(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx);
|
||||
static bool Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx);
|
||||
static bool Equals(BfType* lhs, BfTypeReference* rhs, BfTypeDef* rhsTypeDef, LookupContext* ctx);
|
||||
|
||||
public:
|
||||
BfResolvedTypeSet()
|
||||
|
|
38
IDEHelper/Tests/src/Aliases.bf
Normal file
38
IDEHelper/Tests/src/Aliases.bf
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma warning disable 168
|
||||
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
class Aliases
|
||||
{
|
||||
class ClassA<T>
|
||||
{
|
||||
public typealias AliasA0 = int32;
|
||||
public typealias AliasA1 = List<T>;
|
||||
public typealias AliasA2<T2> = Dictionary<T, T2>;
|
||||
|
||||
public typealias AliasA3 = delegate T();
|
||||
public typealias AliasA4<T2> = delegate T(T2 val);
|
||||
|
||||
public delegate T Zag();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
ClassA<float>.AliasA0 a0 = default;
|
||||
a0 = 123;
|
||||
|
||||
ClassA<float>.AliasA1 list = scope List<float>();
|
||||
Dictionary<float, int16> dict = scope ClassA<float>.AliasA2<int16>();
|
||||
|
||||
delegate double() dlg = default;
|
||||
ClassA<double>.AliasA3 dlg2 = dlg;
|
||||
|
||||
delegate double(char8) dlg3 = default;
|
||||
ClassA<double>.AliasA4<char8> dlg4 = dlg3;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue