From 21798e20f99f651c1c703d3cb4f25f5ff1d46379 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 23 Dec 2020 14:04:35 -0800 Subject: [PATCH] consteval reification fixes --- IDEHelper/Compiler/BfModule.cpp | 28 +++++++++++++++++++----- IDEHelper/Compiler/BfResolvedTypeUtils.h | 3 ++- IDEHelper/Compiler/CeMachine.cpp | 3 +++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index d68911fb..3bbef848 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -12388,6 +12388,13 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline); + if (mIsConstModule) + { + defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoReference); + if (!mCompiler->mIsResolveOnly) + defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoForceReification | BfGetMethodInstanceFlag_Unreified | BfGetMethodInstanceFlag_NoReference); + } + // Not extern // Create the instance in the proper module and then create a reference in this one moduleMethodInst = instModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, defFlags, foreignType); @@ -12587,7 +12594,10 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (lookupMethodGenericArguments.size() == 0) { methodInstance = methodInstGroup->mDefault; - + + if ((methodInstance != NULL) && ((flags & BfGetMethodInstanceFlag_NoReference) != 0)) + return methodInstance; + if ((methodInstance != NULL) && (isReified) && (!methodInstance->mIsReified)) { MarkDerivedDirty(typeInst); @@ -12696,6 +12706,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { methodInstance = *methodInstancePtr; + if ((flags & BfGetMethodInstanceFlag_NoReference) != 0) + return methodInstance; + if ((methodInstance->mRequestedByAutocomplete) && (!mCompiler->IsAutocomplete())) { // We didn't want to process this message yet if it was autocomplete-specific, but now we will @@ -12747,16 +12760,16 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (methodInstance->mIsReified != isReified) BfLogSysM("GetMethodInstance %p Decl_AwaitingReference setting reified to %d\n", methodInstance, isReified); - if ((!isReified) && + if ((!isReified) && ((methodInstance->mDeclModule == NULL) || (!methodInstance->mDeclModule->mIsModuleMutable))) { methodInstance->mDeclModule = mContext->mUnreifiedModule; methodInstance->mIRFunction = BfIRFunction(); } - methodInstance->mIsReified = isReified; + methodInstance->mIsReified = isReified; if ((methodInstance->mHotMethod != NULL) && (!mCompiler->IsHotCompile()) && (isReified)) - { + { methodInstance->mHotMethod->mFlags = (BfHotDepDataFlags)(methodInstance->mHotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild); } @@ -12766,8 +12779,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { // Wait until unreified } - else - AddMethodToWorkList(methodInstance); + else + AddMethodToWorkList(methodInstance); } else { @@ -13024,6 +13037,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM addToWorkList = false; } +// if ((flags & BfGetMethodInstanceFlag_NoReference) != 0) +// addToWorkList = false; + declareModule->DoMethodDeclaration(methodDef->GetMethodDeclaration(), false, addToWorkList); if (processNow) diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 767c248d..3411a8f5 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -73,7 +73,8 @@ enum BfGetMethodInstanceFlags : uint16 BfGetMethodInstanceFlag_Friend = 0x100, BfGetMethodInstanceFlag_DisableObjectAccessChecks = 0x200, BfGetMethodInstanceFlag_NoInline = 0x400, - BfGetMethodInstanceFlag_DepthExceeded = 0x800 + BfGetMethodInstanceFlag_DepthExceeded = 0x800, + BfGetMethodInstanceFlag_NoReference = 0x1000 }; class BfDependencyMap diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index bbcab54e..b3ad6680 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -5442,6 +5442,9 @@ BfTypedValue CeMachine::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns SetAndRestoreValue prevModule(mCurModule, module); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInstance); SetAndRestoreValue prevExpectingType(mCurExpectingType, expectingType); + + // Reentrancy may occur as methods need defining + SetAndRestoreValue prevMethodStateInConstEval(module->mCurMethodState, NULL); if (mAppendAllocInfo != NULL) {