From 11a46fa422e914e7d96ec2791c075f82d847a46e Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 16 Apr 2020 00:32:00 -0700 Subject: [PATCH] DLL import hotswap fixes --- IDEHelper/Compiler/BfExprEvaluator.cpp | 9 +++++++++ IDEHelper/Compiler/BfModule.cpp | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index e1c2f1ed..df8485a9 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -4215,6 +4215,15 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV mModule->mFuncReferences.TryGetValue(methodInstance, &funcCallInst); } + if ((importCallKind == BfImportCallKind_GlobalVar) && + (methodInstance->mHotMethod == NULL) && + (mModule->mCompiler->IsHotCompile())) + { + // This may actually be a BfImportCallKind_GlobalVar_Hot, so check it... + mModule->CheckHotMethod(methodInstance, ""); + importCallKind = methodInstance->GetImportCallKind(); + } + if (importCallKind == BfImportCallKind_GlobalVar_Hot) { //TODO: Check against NULL for calling BfLoadSharedLibraries diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 6195e039..7c49cb7e 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -11136,7 +11136,7 @@ BfModule* BfModule::GetOrCreateMethodModule(BfMethodInstance* methodInstance) } BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags, BfTypeInstance* foreignType) -{ +{ if (((flags & BfGetMethodInstanceFlag_ForceInline) != 0) && (mCompiler->mIsResolveOnly)) { // Don't bother inlining for resolve-only @@ -18904,7 +18904,10 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl #ifdef BF_DBG_HOTMETHOD_NAME hotMethod->mMangledName = mangledName; #endif - methodInstance->mHotMethod = hotMethod; + if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!mCompiler->IsHotCompile())) + hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild); + + methodInstance->mHotMethod = hotMethod; } } @@ -19788,6 +19791,14 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool return; // Bail out early for autocomplete pass } + if ((methodInstance->GetImportCallKind() != BfImportCallKind_None) && (!mBfIRBuilder->mIgnoreWrites) && (!methodInstance->mIRFunction)) + { + BfLogSysM("DllImportGlobalVar DoMethodDeclaration processing %p\n", methodInstance); + BfIRValue dllImportGlobalVar = CreateDllImportGlobalVar(methodInstance, true); + methodInstance->mIRFunction = mBfIRBuilder->GetFakeVal(); + mFuncReferences[mCurMethodInstance] = dllImportGlobalVar; + } + //TODO: We used to have this (this != mContext->mExternalFuncModule) check, but it caused us to keep around // an invalid mFuncRefernce (which came from GetMethodInstanceAtIdx) which later got remapped by the // autocompleter. Why did we have this check anyway?