diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index d08bfe04..987f5bf4 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -473,6 +473,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) //if (isResolveOnly) //mCEMachine = NULL; mCEMachine = new CeMachine(this); + mCurCEExecuteId = -1; } BfCompiler::~BfCompiler() @@ -885,7 +886,9 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test testMethods.Add(testMethod); if (!bfModule->mProject->mUsedModules.Contains(typeInstance->mModule)) + { bfModule->mProject->mUsedModules.Add(typeInstance->mModule); + } vdataHashCtx.Mixin(methodInstance->GetOwner()->mTypeId); vdataHashCtx.Mixin(methodInstance->mMethodDef->mIdx); @@ -9198,13 +9201,7 @@ BF_EXPORT int BF_CALLTYPE BfCompiler_GetCompileRevision(BfCompiler* bfCompiler) BF_EXPORT int BF_CALLTYPE BfCompiler_GetCurConstEvalExecuteId(BfCompiler* bfCompiler) { - if (bfCompiler->mCEMachine == NULL) - return -1; - if (bfCompiler->mCEMachine->mCurContext == NULL) - return -1; - if (bfCompiler->mCEMachine->mCurContext->mCurMethodInstance == NULL) - return -1; - return bfCompiler->mCEMachine->mExecuteId; + return bfCompiler->mCurCEExecuteId; } BF_EXPORT float BF_CALLTYPE BfCompiler_GetLastHadComptimeRebuilds(BfCompiler* bfCompiler) diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index 566e6d9c..d0fb9988 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -315,6 +315,7 @@ public: FILE* mCompileLogFP; CeMachine* mCEMachine; + int mCurCEExecuteId; BfSystem* mSystem; bool mIsResolveOnly; BfResolvePassData* mResolvePassData; diff --git a/IDEHelper/Compiler/BfContext.cpp b/IDEHelper/Compiler/BfContext.cpp index 5f79169b..93f2ac67 100644 --- a/IDEHelper/Compiler/BfContext.cpp +++ b/IDEHelper/Compiler/BfContext.cpp @@ -2070,16 +2070,20 @@ void BfContext::UpdateRevisedTypes() } } - if (typeDef->mDefState == BfTypeDef::DefState_Defined) + auto checkTypeDef = typeDef; + if (typeDef->mEmitParent != NULL) + checkTypeDef = typeDef->mEmitParent; + + if (checkTypeDef->mDefState == BfTypeDef::DefState_Defined) { BF_ASSERT(typeDef->mNextRevision == NULL); continue; } - if (typeDef->mDefState != BfTypeDef::DefState_New) + if (checkTypeDef->mDefState != BfTypeDef::DefState_New) { defStateChangedQueue.Add(typeInst); - } + } } // We consumed this above diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 9c7aa073..7fc9f529 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -11195,9 +11195,9 @@ void BfExprEvaluator::Visit(BfDynamicCastExpression* dynCastExpr) return; } - if (autoComplete != NULL) + if (autoComplete != NULL) { - mResult = mModule->GetDefaultTypedValue(targetType); + mResult = mModule->GetDefaultTypedValue(targetType, false, BfDefaultValueKind_Addr); _CheckResult(); return; } diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index b785bea2..71c80f5d 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -999,6 +999,11 @@ bool BfModule::WantsFinishModule() return (mIncompleteMethodCount == 0) && (mOnDemandMethodCount == 0) && (!mHasGenericMethods) && (!mIsScratchModule) && (mExtensionCount == 0) && (mParentModule == NULL); } +bool BfModule::IsHotCompile() +{ + return mCompiler->IsHotCompile() && !mIsComptimeModule; +} + void BfModule::FinishInit() { BF_ASSERT(mAwaitingInitFinish); @@ -3535,8 +3540,15 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap if ((usingModule != NULL) && (!usingModule->mIsSpecialModule) && (usedModule != NULL) && (!usedModule->mIsSpecialModule)) - { - usingModule->mModuleRefs.Add(usedModule); + { + if ((flags & ~(BfDependencyMap::DependencyFlag_OuterType)) == 0) + { + // Not a 'use' dependency + } + else + { + usingModule->mModuleRefs.Add(usedModule); + } } } @@ -5324,7 +5336,7 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStringIdMap, bool forceReflectFields, bool needsTypeData, bool needsTypeNames, bool needsVData) { - if ((mCompiler->IsHotCompile()) && (!type->mDirty)) + if ((IsHotCompile()) && (!type->mDirty)) return BfIRValue(); BfIRValue* irValuePtr = NULL; @@ -22013,7 +22025,7 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl #ifdef BF_DBG_HOTMETHOD_NAME hotMethod->mMangledName = mangledName; #endif - if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!mCompiler->IsHotCompile())) + if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!IsHotCompile())) hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild); methodInstance->mHotMethod = hotMethod; @@ -23509,7 +23521,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo } else if (methodDef->mIsVirtual) { - if (mCompiler->IsHotCompile()) + if (IsHotCompile()) mContext->EnsureHotMangledVirtualMethodName(methodInstance); BfTypeInstance* checkBase = typeInstance; diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index d0c41a88..f55304a7 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1971,6 +1971,7 @@ public: void Init(bool isFullRebuild = true); bool WantsFinishModule(); + bool IsHotCompile(); void FinishInit(); void CalcGeneratesCode(); void ReifyModule(); diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index cae94826..631fb95c 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -642,7 +642,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) BfLogSysM("Using mSavedTypeData for %p %s\n", resolvedTypeRef, typeName.c_str()); if (typeInst != NULL) { - if (mCompiler->IsHotCompile()) + if (IsHotCompile()) { BfLogSysM("Using mSavedTypeData HotTypeData %p for %p\n", savedTypeData->mHotTypeData, resolvedTypeRef); typeInst->mHotTypeData = savedTypeData->mHotTypeData; @@ -2186,7 +2186,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance->mCeTypeInfo->mNext->mTypeIFaceMap[typeId] = entry; } - if (ceEmitContext->HasEmissions()) + if ((ceEmitContext->HasEmissions()) && (!mCompiler->mFastFinish)) { String ctxStr = "comptime ApplyToType of "; ctxStr += TypeToString(attrType); @@ -2426,7 +2426,9 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* } void BfModule::DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers, bool underlyingTypeDeferred) -{ +{ + BfLogSysM("BfModule::DoCEEmit %p\n", typeInstance); + CeEmitContext ceEmitContext; ceEmitContext.mType = typeInstance; ExecuteCEOnCompile(&ceEmitContext, typeInstance, BfCEOnCompileKind_TypeInit, underlyingTypeDeferred); @@ -6086,6 +6088,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) AssertErrorState(); } } + else if ((typeInstance->mRebuildFlags & BfTypeRebuildFlag_ConstEvalCancelled) != 0) + { + // It's possible const eval was supposed to generate this method. We're rebuilding the type anyway. + } else { String methodString; diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 67b851c5..a1fc99e8 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -425,6 +425,7 @@ enum BfTypeRebuildFlags BfTypeRebuildFlag_ResolvingBase = 0x8000, BfTypeRebuildFlag_InFailTypes = 0x10000, BfTypeRebuildFlag_RebuildQueued = 0x20000, + BfTypeRebuildFlag_ConstEvalCancelled = 0x40000 }; class BfTypeDIReplaceCallback; diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index 41794edb..b063049a 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -4056,6 +4056,8 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns SetAndRestoreValue prevModule(mCurModule, module); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInstance); SetAndRestoreValue prevExpectingType(mCurExpectingType, expectingType); + + SetAndRestoreValue prevCurExecuteId(mCurModule->mCompiler->mCurCEExecuteId, mCeMachine->mExecuteId); // Reentrancy may occur as methods need defining //SetAndRestoreValue prevMethodStateInConstEval(module->mCurMethodState, NULL); @@ -5936,12 +5938,15 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* { if (*fastFinishPtr) { - if (*cancelingPtr) + if ((mCurModule != NULL) && (mCurModule->mCurTypeInstance != NULL)) { - if ((mCurModule != NULL) && (mCurModule->mCurTypeInstance != NULL)) - mCurModule->DeferRebuildType(mCurModule->mCurTypeInstance); - else - _Fail("Comptime evaluation canceled"); + mCurModule->mCurTypeInstance->mRebuildFlags = (BfTypeRebuildFlags)(mCurModule->mCurTypeInstance->mRebuildFlags | BfTypeRebuildFlag_ConstEvalCancelled); + mCurModule->DeferRebuildType(mCurModule->mCurTypeInstance); + } + if (*cancelingPtr) + { + if ((mCurModule == NULL) || (mCurModule->mCurTypeInstance == NULL)) + _Fail("Comptime evaluation canceled"); } return false; }