From 1624b389588718ff4cccd380f0c493887f1f3193 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 1 Jun 2020 15:09:32 -0700 Subject: [PATCH] Fixed some hot-compile dependency issues --- IDEHelper/Compiler/BfCompiler.cpp | 82 ++++++++++++++---------- IDEHelper/Compiler/BfCompiler.h | 2 + IDEHelper/Compiler/BfModule.cpp | 44 ++++--------- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 4 -- 4 files changed, 63 insertions(+), 69 deletions(-) diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index ad03db76..4cd47c79 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -3327,25 +3327,6 @@ void BfCompiler::UpdateRevisedTypes() } mContext->RemoveInvalidWorkItems(); - //for (auto typeDef : mSystem->mTypeDefs) - //{ - // auto latestTypeDef = typeDef->GetLatest(); - // if ((latestTypeDef->mOuterType != NULL) && (latestTypeDef->mOuterType->mIsPartial) && (latestTypeDef->mIsCombinedPartial)) - // //((!latestTypeDef->mIsPartial) || (latestTypeDef->mIsCombinedPartial))) - // latestTypeDef->mOuterType = mSystem->GetOuterTypeNonPartial(latestTypeDef); - - // /*String fullName = typeDef->mFullNameEx.ToString(); - // if (fullName == "System.Collections.List`1.Enumerator`1") - // { - // NOP; - // } - - // if ((typeDef->mOuterType != NULL) && (!typeDef->mIsPartial) && (typeDef->mOuterType->mIsPartial) && (!typeDef->mOuterType->mIsCombinedPartial)) - // { - // NOP; - // }*/ - //} - mSystem->mNeedsTypesHandledByCompiler = false; //TODO: @@ -5143,7 +5124,7 @@ void BfCompiler::HotCommit() void BfCompiler::HotResolve_Start(HotResolveFlags flags) { BfLogSysM("BfCompiler::HotResolve_Start\n"); - + delete mHotResolveData; mHotResolveData = new HotResolveData(); mHotResolveData->mFlags = flags; @@ -5163,8 +5144,18 @@ void BfCompiler::HotResolve_Start(HotResolveFlags flags) } } +//#define HOT_DEBUG_NAME + bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFlags flags, bool devirtualized, bool forceProcess) { +#ifdef HOT_DEBUG_NAME + HotResolve_PopulateMethodNameMap(); + String* namePtr = NULL; + if (mHotData->mMethodNameMap.TryGetValue(hotMethod, &namePtr)) + { + } +#endif + HotReachableData* hotReachableData; if (mHotResolveData->mReachableMethods.TryAdd(hotMethod, NULL, &hotReachableData)) { @@ -5268,6 +5259,14 @@ void BfCompiler::HotResolve_AddReachableMethod(const StringImpl& methodName) void BfCompiler::HotResolve_AddActiveMethod(BfHotMethod* hotMethod) { +#ifdef HOT_DEBUG_NAME + HotResolve_PopulateMethodNameMap(); + String* namePtr = NULL; + if (mHotData->mMethodNameMap.TryGetValue(hotMethod, &namePtr)) + { + } +#endif + if (mHotResolveData->mActiveMethods.Add(hotMethod)) { hotMethod->mRefCount++; @@ -5401,6 +5400,22 @@ void BfCompiler::HotResolve_ReportType(int typeId, HotTypeFlags flags) mHotResolveData->mHotTypeIdFlags[typeId] = (HotTypeFlags)(flags | mHotResolveData->mHotTypeIdFlags[typeId]); } +void BfCompiler::HotResolve_PopulateMethodNameMap() +{ + if (!mHotData->mMethodNameMap.IsEmpty()) + return; + + for (auto& kv : mHotData->mMethodMap) + { + auto hotMethod = kv.mValue; + while (hotMethod != NULL) + { + mHotData->mMethodNameMap[hotMethod] = &kv.mKey; + hotMethod = hotMethod->mPrevVersion; + } + } +} + String BfCompiler::HotResolve_Finish() { BfLogSysM("HotResolve_Finish\n"); @@ -5461,8 +5476,8 @@ String BfCompiler::HotResolve_Finish() for (auto ref : hotMethod->mReferences) { - if (ref->mDataKind == BfHotDepDataKind_ThisType) - continue; + if (ref->mDataKind == BfHotDepDataKind_ThisType) + continue; if (ref->mDataKind != BfHotDepDataKind_VirtualDecl) break; @@ -5470,6 +5485,14 @@ String BfCompiler::HotResolve_Finish() HotReachableData* hotReachableData; if (mHotResolveData->mReachableMethods.TryGetValue(hotVirtualDecl->mMethod, &hotReachableData)) { +#ifdef HOT_DEBUG_NAME + HotResolve_PopulateMethodNameMap(); + String* namePtr = NULL; + if (mHotData->mMethodNameMap.TryGetValue(hotVirtualDecl->mMethod, &namePtr)) + { + } +#endif + if (hotReachableData->mHadNonDevirtualizedCall) { typeFlags = hotReachableData->mTypeFlags; @@ -5533,21 +5556,10 @@ String BfCompiler::HotResolve_Finish() auto hotMethod = (BfHotMethod*)reason; reasonIsActiveMethod = mHotResolveData->mActiveMethods.Contains(hotMethod); - if (methodNameMap.IsEmpty()) - { - for (auto& kv : mHotData->mMethodMap) - { - auto hotMethod = kv.mValue; - while (hotMethod != NULL) - { - methodNameMap[hotMethod] = &kv.mKey; - hotMethod = hotMethod->mPrevVersion; - } - } - } + HotResolve_PopulateMethodNameMap(); String** strPtr; - if (methodNameMap.TryGetValue(hotMethod, &strPtr)) + if (mHotData->mMethodNameMap.TryGetValue(hotMethod, &strPtr)) { methodReason += BfDemangler::Demangle((**strPtr), DbgLanguage_Beef, BfDemangler::Flag_BeefFixed); } diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index a6ca85a2..0ec7a44c 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -239,6 +239,7 @@ public: public: BfCompiler* mCompiler; Dictionary mMethodMap; + Dictionary mMethodNameMap; Dictionary mThisType; Dictionary mAllocation; Dictionary mDevirtualizedMethods; @@ -455,6 +456,7 @@ public: void HotCommit(); void HotResolve_Start(HotResolveFlags flags); + void HotResolve_PopulateMethodNameMap(); bool HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFlags flags, bool devirtualized, bool forceProcess = false); void HotResolve_AddReachableMethod(const StringImpl& methodName); void HotResolve_AddActiveMethod(BfHotMethod* hotMethod); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index d9d5b8b9..19e75452 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -2989,24 +2989,27 @@ void BfModule::AddDependency(BfType* usedType, BfType* usingType, BfDependencyMa if (usedType->IsSpecializedByAutoCompleteMethod()) return; - if ((mCurMethodState != NULL) && (mCurMethodState->mHotDataReferenceBuilder != NULL) && (usedType != mCurTypeInstance) && - ((flags & (BfDependencyMap::DependencyFlag_ReadFields | BfDependencyMap::DependencyFlag_LocalUsage | BfDependencyMap::DependencyFlag_Allocates)) != 0)) + BfType* origUsedType = usedType; + bool isDataAccess = ((flags & (BfDependencyMap::DependencyFlag_ReadFields | BfDependencyMap::DependencyFlag_LocalUsage | BfDependencyMap::DependencyFlag_Allocates)) != 0); + if (isDataAccess) { - bool addType = true; - auto checkType = usedType; - while (true) { - if ((checkType->IsPointer()) || (checkType->IsRef()) || (checkType->IsSizedArray())) - checkType = checkType->GetUnderlyingType(); - else if (checkType->IsArray()) + if ((usedType->IsPointer()) || (usedType->IsRef()) || (usedType->IsSizedArray())) + usedType = usedType->GetUnderlyingType(); + else if (usedType->IsArray()) { - checkType = ((BfGenericTypeInstance*)checkType)->mTypeGenericArguments[0]; + usedType = ((BfGenericTypeInstance*)usedType)->mTypeGenericArguments[0]; } else break; } - + } + + if ((mCurMethodState != NULL) && (mCurMethodState->mHotDataReferenceBuilder != NULL) && (usedType != mCurTypeInstance) && (isDataAccess)) + { + bool addType = true; + auto checkType = usedType; PopulateType(checkType, BfPopulateType_Data); if (checkType->IsValuelessType()) addType = false; @@ -3046,22 +3049,6 @@ void BfModule::AddDependency(BfType* usedType, BfType* usingType, BfDependencyMa } } - //BP_ZONE("BfModule::AddDependency"); - - /*if (usedType->IsMethodRef()) - { - auto methodRefType = (BfMethodRefType*)usedType; - AddDependency(methodRefType->mMethodRef->GetOwner(), usingType, flags); - return; - }*/ - - // Why in the world were we doing this? - // This caused functions to get immediately deleted since they appear to have no references ever.... -// if (usedType->IsFunction()) -// { -// usedType = ResolveTypeDef(mCompiler->mFunctionTypeDef); -// } - if ((!mCompiler->mIsResolveOnly) && (mIsReified)) { auto usingModule = usingType->GetModule(); @@ -3091,7 +3078,6 @@ void BfModule::AddDependency(BfType* usedType, BfType* usingType, BfDependencyMa return; } - auto underlyingType = usedType->GetUnderlyingType(); if (underlyingType != NULL) // Not really a "GenericArg", but... same purpose. AddDependency(underlyingType, usingType, BfDependencyMap::DependencyFlag_GenericArgRef); @@ -15374,9 +15360,7 @@ void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) auto depData = hotMethod->mReferences[refIdx]; BF_ASSERT(depData != NULL); depData->mRefCount++; - } - - //hotMethod->mReferences.Sort([](BfHotDepData* lhs, BfHotDepData* rhs) { return lhs < rhs; }); + } } void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfType* thisType, bool wantsDIData, SizedArrayImpl* diParams) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 854a717e..87ceb012 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -62,10 +62,6 @@ BfGenericExtensionEntry* BfModule::BuildGenericExtensionInfo(BfGenericTypeInstan typeState.mCurTypeDef = partialTypeDef; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - //auto genericExEntry = new BfGenericExtensionEntry(); - //auto insertPair = genericExtensionInfo->mExtensionMap.insert(std::make_pair(partialTypeDef, BfGenericExtensionEntry())); - //auto genericExEntry = &insertPair.first->second; - BfGenericExtensionEntry* genericExEntry; genericExtensionInfo->mExtensionMap.TryAdd(partialTypeDef, NULL, &genericExEntry);