mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22: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)
|
//if (isResolveOnly)
|
||||||
//mCEMachine = NULL;
|
//mCEMachine = NULL;
|
||||||
mCEMachine = new CeMachine(this);
|
mCEMachine = new CeMachine(this);
|
||||||
|
mCurCEExecuteId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BfCompiler::~BfCompiler()
|
BfCompiler::~BfCompiler()
|
||||||
|
@ -885,7 +886,9 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array<TestMethod>& test
|
||||||
testMethods.Add(testMethod);
|
testMethods.Add(testMethod);
|
||||||
|
|
||||||
if (!bfModule->mProject->mUsedModules.Contains(typeInstance->mModule))
|
if (!bfModule->mProject->mUsedModules.Contains(typeInstance->mModule))
|
||||||
|
{
|
||||||
bfModule->mProject->mUsedModules.Add(typeInstance->mModule);
|
bfModule->mProject->mUsedModules.Add(typeInstance->mModule);
|
||||||
|
}
|
||||||
|
|
||||||
vdataHashCtx.Mixin(methodInstance->GetOwner()->mTypeId);
|
vdataHashCtx.Mixin(methodInstance->GetOwner()->mTypeId);
|
||||||
vdataHashCtx.Mixin(methodInstance->mMethodDef->mIdx);
|
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)
|
BF_EXPORT int BF_CALLTYPE BfCompiler_GetCurConstEvalExecuteId(BfCompiler* bfCompiler)
|
||||||
{
|
{
|
||||||
if (bfCompiler->mCEMachine == NULL)
|
return bfCompiler->mCurCEExecuteId;
|
||||||
return -1;
|
|
||||||
if (bfCompiler->mCEMachine->mCurContext == NULL)
|
|
||||||
return -1;
|
|
||||||
if (bfCompiler->mCEMachine->mCurContext->mCurMethodInstance == NULL)
|
|
||||||
return -1;
|
|
||||||
return bfCompiler->mCEMachine->mExecuteId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BF_EXPORT float BF_CALLTYPE BfCompiler_GetLastHadComptimeRebuilds(BfCompiler* bfCompiler)
|
BF_EXPORT float BF_CALLTYPE BfCompiler_GetLastHadComptimeRebuilds(BfCompiler* bfCompiler)
|
||||||
|
|
|
@ -315,6 +315,7 @@ public:
|
||||||
FILE* mCompileLogFP;
|
FILE* mCompileLogFP;
|
||||||
|
|
||||||
CeMachine* mCEMachine;
|
CeMachine* mCEMachine;
|
||||||
|
int mCurCEExecuteId;
|
||||||
BfSystem* mSystem;
|
BfSystem* mSystem;
|
||||||
bool mIsResolveOnly;
|
bool mIsResolveOnly;
|
||||||
BfResolvePassData* mResolvePassData;
|
BfResolvePassData* mResolvePassData;
|
||||||
|
|
|
@ -2070,13 +2070,17 @@ 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);
|
BF_ASSERT(typeDef->mNextRevision == NULL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeDef->mDefState != BfTypeDef::DefState_New)
|
if (checkTypeDef->mDefState != BfTypeDef::DefState_New)
|
||||||
{
|
{
|
||||||
defStateChangedQueue.Add(typeInst);
|
defStateChangedQueue.Add(typeInst);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11197,7 +11197,7 @@ void BfExprEvaluator::Visit(BfDynamicCastExpression* dynCastExpr)
|
||||||
|
|
||||||
if (autoComplete != NULL)
|
if (autoComplete != NULL)
|
||||||
{
|
{
|
||||||
mResult = mModule->GetDefaultTypedValue(targetType);
|
mResult = mModule->GetDefaultTypedValue(targetType, false, BfDefaultValueKind_Addr);
|
||||||
_CheckResult();
|
_CheckResult();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -999,6 +999,11 @@ bool BfModule::WantsFinishModule()
|
||||||
return (mIncompleteMethodCount == 0) && (mOnDemandMethodCount == 0) && (!mHasGenericMethods) && (!mIsScratchModule) && (mExtensionCount == 0) && (mParentModule == NULL);
|
return (mIncompleteMethodCount == 0) && (mOnDemandMethodCount == 0) && (!mHasGenericMethods) && (!mIsScratchModule) && (mExtensionCount == 0) && (mParentModule == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfModule::IsHotCompile()
|
||||||
|
{
|
||||||
|
return mCompiler->IsHotCompile() && !mIsComptimeModule;
|
||||||
|
}
|
||||||
|
|
||||||
void BfModule::FinishInit()
|
void BfModule::FinishInit()
|
||||||
{
|
{
|
||||||
BF_ASSERT(mAwaitingInitFinish);
|
BF_ASSERT(mAwaitingInitFinish);
|
||||||
|
@ -3535,10 +3540,17 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap
|
||||||
|
|
||||||
if ((usingModule != NULL) && (!usingModule->mIsSpecialModule) &&
|
if ((usingModule != NULL) && (!usingModule->mIsSpecialModule) &&
|
||||||
(usedModule != NULL) && (!usedModule->mIsSpecialModule))
|
(usedModule != NULL) && (!usedModule->mIsSpecialModule))
|
||||||
|
{
|
||||||
|
if ((flags & ~(BfDependencyMap::DependencyFlag_OuterType)) == 0)
|
||||||
|
{
|
||||||
|
// Not a 'use' dependency
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
usingModule->mModuleRefs.Add(usedModule);
|
usingModule->mModuleRefs.Add(usedModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (flags != BfDependencyMap::DependencyFlag_MethodGenericArg))
|
if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (flags != BfDependencyMap::DependencyFlag_MethodGenericArg))
|
||||||
{
|
{
|
||||||
|
@ -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)
|
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();
|
return BfIRValue();
|
||||||
|
|
||||||
BfIRValue* irValuePtr = NULL;
|
BfIRValue* irValuePtr = NULL;
|
||||||
|
@ -22013,7 +22025,7 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl
|
||||||
#ifdef BF_DBG_HOTMETHOD_NAME
|
#ifdef BF_DBG_HOTMETHOD_NAME
|
||||||
hotMethod->mMangledName = mangledName;
|
hotMethod->mMangledName = mangledName;
|
||||||
#endif
|
#endif
|
||||||
if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!mCompiler->IsHotCompile()))
|
if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!IsHotCompile()))
|
||||||
hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild);
|
hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild);
|
||||||
|
|
||||||
methodInstance->mHotMethod = hotMethod;
|
methodInstance->mHotMethod = hotMethod;
|
||||||
|
@ -23509,7 +23521,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo
|
||||||
}
|
}
|
||||||
else if (methodDef->mIsVirtual)
|
else if (methodDef->mIsVirtual)
|
||||||
{
|
{
|
||||||
if (mCompiler->IsHotCompile())
|
if (IsHotCompile())
|
||||||
mContext->EnsureHotMangledVirtualMethodName(methodInstance);
|
mContext->EnsureHotMangledVirtualMethodName(methodInstance);
|
||||||
|
|
||||||
BfTypeInstance* checkBase = typeInstance;
|
BfTypeInstance* checkBase = typeInstance;
|
||||||
|
|
|
@ -1971,6 +1971,7 @@ public:
|
||||||
|
|
||||||
void Init(bool isFullRebuild = true);
|
void Init(bool isFullRebuild = true);
|
||||||
bool WantsFinishModule();
|
bool WantsFinishModule();
|
||||||
|
bool IsHotCompile();
|
||||||
void FinishInit();
|
void FinishInit();
|
||||||
void CalcGeneratesCode();
|
void CalcGeneratesCode();
|
||||||
void ReifyModule();
|
void ReifyModule();
|
||||||
|
|
|
@ -642,7 +642,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType)
|
||||||
BfLogSysM("Using mSavedTypeData for %p %s\n", resolvedTypeRef, typeName.c_str());
|
BfLogSysM("Using mSavedTypeData for %p %s\n", resolvedTypeRef, typeName.c_str());
|
||||||
if (typeInst != NULL)
|
if (typeInst != NULL)
|
||||||
{
|
{
|
||||||
if (mCompiler->IsHotCompile())
|
if (IsHotCompile())
|
||||||
{
|
{
|
||||||
BfLogSysM("Using mSavedTypeData HotTypeData %p for %p\n", savedTypeData->mHotTypeData, resolvedTypeRef);
|
BfLogSysM("Using mSavedTypeData HotTypeData %p for %p\n", savedTypeData->mHotTypeData, resolvedTypeRef);
|
||||||
typeInst->mHotTypeData = savedTypeData->mHotTypeData;
|
typeInst->mHotTypeData = savedTypeData->mHotTypeData;
|
||||||
|
@ -2186,7 +2186,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
|
||||||
typeInstance->mCeTypeInfo->mNext->mTypeIFaceMap[typeId] = entry;
|
typeInstance->mCeTypeInfo->mNext->mTypeIFaceMap[typeId] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ceEmitContext->HasEmissions())
|
if ((ceEmitContext->HasEmissions()) && (!mCompiler->mFastFinish))
|
||||||
{
|
{
|
||||||
String ctxStr = "comptime ApplyToType of ";
|
String ctxStr = "comptime ApplyToType of ";
|
||||||
ctxStr += TypeToString(attrType);
|
ctxStr += TypeToString(attrType);
|
||||||
|
@ -2427,6 +2427,8 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance*
|
||||||
|
|
||||||
void BfModule::DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers, bool underlyingTypeDeferred)
|
void BfModule::DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers, bool underlyingTypeDeferred)
|
||||||
{
|
{
|
||||||
|
BfLogSysM("BfModule::DoCEEmit %p\n", typeInstance);
|
||||||
|
|
||||||
CeEmitContext ceEmitContext;
|
CeEmitContext ceEmitContext;
|
||||||
ceEmitContext.mType = typeInstance;
|
ceEmitContext.mType = typeInstance;
|
||||||
ExecuteCEOnCompile(&ceEmitContext, typeInstance, BfCEOnCompileKind_TypeInit, underlyingTypeDeferred);
|
ExecuteCEOnCompile(&ceEmitContext, typeInstance, BfCEOnCompileKind_TypeInit, underlyingTypeDeferred);
|
||||||
|
@ -6086,6 +6088,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
|
||||||
AssertErrorState();
|
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
|
else
|
||||||
{
|
{
|
||||||
String methodString;
|
String methodString;
|
||||||
|
|
|
@ -425,6 +425,7 @@ enum BfTypeRebuildFlags
|
||||||
BfTypeRebuildFlag_ResolvingBase = 0x8000,
|
BfTypeRebuildFlag_ResolvingBase = 0x8000,
|
||||||
BfTypeRebuildFlag_InFailTypes = 0x10000,
|
BfTypeRebuildFlag_InFailTypes = 0x10000,
|
||||||
BfTypeRebuildFlag_RebuildQueued = 0x20000,
|
BfTypeRebuildFlag_RebuildQueued = 0x20000,
|
||||||
|
BfTypeRebuildFlag_ConstEvalCancelled = 0x40000
|
||||||
};
|
};
|
||||||
|
|
||||||
class BfTypeDIReplaceCallback;
|
class BfTypeDIReplaceCallback;
|
||||||
|
|
|
@ -4057,6 +4057,8 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
|
||||||
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInstance);
|
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInstance);
|
||||||
SetAndRestoreValue<BfType*> prevExpectingType(mCurExpectingType, expectingType);
|
SetAndRestoreValue<BfType*> prevExpectingType(mCurExpectingType, expectingType);
|
||||||
|
|
||||||
|
SetAndRestoreValue<int> prevCurExecuteId(mCurModule->mCompiler->mCurCEExecuteId, mCeMachine->mExecuteId);
|
||||||
|
|
||||||
// Reentrancy may occur as methods need defining
|
// Reentrancy may occur as methods need defining
|
||||||
//SetAndRestoreValue<BfMethodState*> prevMethodStateInConstEval(module->mCurMethodState, NULL);
|
//SetAndRestoreValue<BfMethodState*> prevMethodStateInConstEval(module->mCurMethodState, NULL);
|
||||||
|
|
||||||
|
@ -5936,11 +5938,14 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
{
|
{
|
||||||
if (*fastFinishPtr)
|
if (*fastFinishPtr)
|
||||||
{
|
{
|
||||||
|
if ((mCurModule != NULL) && (mCurModule->mCurTypeInstance != NULL))
|
||||||
|
{
|
||||||
|
mCurModule->mCurTypeInstance->mRebuildFlags = (BfTypeRebuildFlags)(mCurModule->mCurTypeInstance->mRebuildFlags | BfTypeRebuildFlag_ConstEvalCancelled);
|
||||||
|
mCurModule->DeferRebuildType(mCurModule->mCurTypeInstance);
|
||||||
|
}
|
||||||
if (*cancelingPtr)
|
if (*cancelingPtr)
|
||||||
{
|
{
|
||||||
if ((mCurModule != NULL) && (mCurModule->mCurTypeInstance != NULL))
|
if ((mCurModule == NULL) || (mCurModule->mCurTypeInstance == NULL))
|
||||||
mCurModule->DeferRebuildType(mCurModule->mCurTypeInstance);
|
|
||||||
else
|
|
||||||
_Fail("Comptime evaluation canceled");
|
_Fail("Comptime evaluation canceled");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue