From b9593348c727ca1f64220c5a3566b0d08a7e8b40 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 27 Jan 2021 14:08:28 -0800 Subject: [PATCH] Fixed generic dependency issue with type aliases --- IDEHelper/Compiler/BfModule.h | 1 + IDEHelper/Compiler/BfModuleTypeUtils.cpp | 51 +++++++++++++----------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index bc17d497..882b1efb 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -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); diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index c983b0fb..499ccc6f 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -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)