mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Comptime rebuild and hot compile fixes
This commit is contained in:
parent
b49cd5d12a
commit
0c3f9a139d
9 changed files with 52 additions and 25 deletions
|
@ -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<TestMethod>& 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)
|
||||
|
|
|
@ -315,6 +315,7 @@ public:
|
|||
FILE* mCompileLogFP;
|
||||
|
||||
CeMachine* mCEMachine;
|
||||
int mCurCEExecuteId;
|
||||
BfSystem* mSystem;
|
||||
bool mIsResolveOnly;
|
||||
BfResolvePassData* mResolvePassData;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<int, int>& 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;
|
||||
|
|
|
@ -1971,6 +1971,7 @@ public:
|
|||
|
||||
void Init(bool isFullRebuild = true);
|
||||
bool WantsFinishModule();
|
||||
bool IsHotCompile();
|
||||
void FinishInit();
|
||||
void CalcGeneratesCode();
|
||||
void ReifyModule();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -425,6 +425,7 @@ enum BfTypeRebuildFlags
|
|||
BfTypeRebuildFlag_ResolvingBase = 0x8000,
|
||||
BfTypeRebuildFlag_InFailTypes = 0x10000,
|
||||
BfTypeRebuildFlag_RebuildQueued = 0x20000,
|
||||
BfTypeRebuildFlag_ConstEvalCancelled = 0x40000
|
||||
};
|
||||
|
||||
class BfTypeDIReplaceCallback;
|
||||
|
|
|
@ -4056,6 +4056,8 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
|
|||
SetAndRestoreValue<BfModule*> prevModule(mCurModule, module);
|
||||
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInstance);
|
||||
SetAndRestoreValue<BfType*> prevExpectingType(mCurExpectingType, expectingType);
|
||||
|
||||
SetAndRestoreValue<int> prevCurExecuteId(mCurModule->mCompiler->mCurCEExecuteId, mCeMachine->mExecuteId);
|
||||
|
||||
// Reentrancy may occur as methods need defining
|
||||
//SetAndRestoreValue<BfMethodState*> 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue