1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed generic dependency issue with type aliases

This commit is contained in:
Brian Fiete 2021-01-27 14:08:28 -08:00
parent f2237b4f97
commit b9593348c7
2 changed files with 29 additions and 23 deletions

View file

@ -1734,6 +1734,7 @@ public:
void ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* typeInst, BfCEOnCompileKind onCompileKind);
void DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers);
void DoCEEmit(BfMethodInstance* methodInstance);
void DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance);
void DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateType = BfPopulateType_Data);
static BfModule* GetModuleFor(BfType* type);
void DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance);

View file

@ -1175,6 +1175,8 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
if ((typeInstance->mCustomAttributes == NULL) && (typeDef->mTypeDeclaration != NULL) && (typeDef->mTypeDeclaration->mAttributes != NULL))
typeInstance->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
if (typeAlias->mGenericTypeInfo != NULL)
DoPopulateType_SetGenericDependencies(typeAlias);
// Fall through so generic params are populated in DoPopulateType
}
@ -2400,6 +2402,31 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
}
}
void BfModule::DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance)
{
// Add generic dependencies if needed
for (auto genericType : genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments)
{
if (genericType->IsPrimitiveType())
genericType = GetWrappedStructType(genericType);
if (genericType != NULL)
{
AddDependency(genericType, genericTypeInstance, BfDependencyMap::DependencyFlag_TypeGenericArg);
BfLogSysM("Adding generic dependency of %p for type %p\n", genericType, genericTypeInstance);
}
}
if ((genericTypeInstance->IsSpecializedType()) &&
(!genericTypeInstance->IsDelegateFromTypeRef()) &&
(!genericTypeInstance->IsFunctionFromTypeRef()))
{
// This ensures we rebuild the unspecialized type whenever the specialized type rebuilds. This is important
// for generic type binding
auto unspecializedTypeInstance = GetUnspecializedTypeInstance(genericTypeInstance);
BF_ASSERT(!unspecializedTypeInstance->IsUnspecializedTypeVariation());
mContext->mScratchModule->AddDependency(genericTypeInstance, unspecializedTypeInstance, BfDependencyMap::DependencyFlag_UnspecializedType);
}
}
void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateType)
{
auto typeInstance = resolvedTypeRef->ToTypeInstance();
@ -2662,29 +2689,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (typeInstance->IsGenericTypeInstance())
{
auto genericTypeInstance = (BfTypeInstance*)typeInstance;
// Add generic dependencies if needed
for (auto genericType : genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments)
{
if (genericType->IsPrimitiveType())
genericType = GetWrappedStructType(genericType);
if (genericType != NULL)
{
AddDependency(genericType, genericTypeInstance, BfDependencyMap::DependencyFlag_TypeGenericArg);
BfLogSysM("Adding generic dependency of %p for type %p\n", genericType, genericTypeInstance);
}
}
if ((genericTypeInstance->IsSpecializedType()) &&
(!genericTypeInstance->IsDelegateFromTypeRef()) &&
(!genericTypeInstance->IsFunctionFromTypeRef()))
{
// This ensures we rebuild the unspecialized type whenever the specialized type rebuilds. This is important
// for generic type binding
auto unspecializedTypeInstance = GetUnspecializedTypeInstance(genericTypeInstance);
BF_ASSERT(!unspecializedTypeInstance->IsUnspecializedTypeVariation());
mContext->mScratchModule->AddDependency(genericTypeInstance, unspecializedTypeInstance, BfDependencyMap::DependencyFlag_UnspecializedType);
}
DoPopulateType_SetGenericDependencies(typeInstance);
}
auto _AddStaticSearch = [&](BfTypeDef* typeDef)