mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Improved comptime rebuilds when files and directories change
This commit is contained in:
parent
af8bd5a813
commit
915a8df50e
10 changed files with 236 additions and 70 deletions
|
@ -6565,6 +6565,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
}
|
||||
}
|
||||
|
||||
mRebuildFileSet.Clear();
|
||||
|
||||
// Inc revision for next run through Compile
|
||||
mRevision++;
|
||||
mHasComptimeRebuilds = false;
|
||||
|
@ -8149,7 +8151,7 @@ String BfCompiler::GetGeneratorString(BfTypeDef* typeDef, BfTypeInstance* typeIn
|
|||
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mContext->mUnreifiedModule->mCurTypeInstance, typeInst);
|
||||
|
||||
BfExprEvaluator exprEvaluator(mContext->mUnreifiedModule);
|
||||
exprEvaluator.mBfEvalExprFlags = BfEvalExprFlags_Comptime;
|
||||
exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(BfEvalExprFlags_Comptime | BfEvalExprFlags_NoCeRebuildFlags);
|
||||
|
||||
SizedArray<BfIRValue, 1> irArgs;
|
||||
if (args != NULL)
|
||||
|
@ -8189,7 +8191,7 @@ String BfCompiler::GetGeneratorTypeDefList()
|
|||
BfProject* curProject = NULL;
|
||||
Dictionary<BfProject*, int> projectIds;
|
||||
|
||||
BfResolvePassData resolvePassData;
|
||||
BfResolvePassData resolvePassData;
|
||||
SetAndRestoreValue<BfResolvePassData*> prevResolvePassData(mResolvePassData, &resolvePassData);
|
||||
BfPassInstance passInstance(mSystem);
|
||||
SetAndRestoreValue<BfPassInstance*> prevPassInstance(mPassInstance, &passInstance);
|
||||
|
@ -8226,7 +8228,7 @@ String BfCompiler::GetGeneratorTypeDefList()
|
|||
|
||||
String BfCompiler::GetGeneratorInitData(const StringImpl& typeName, const StringImpl& args)
|
||||
{
|
||||
BfResolvePassData resolvePassData;
|
||||
BfResolvePassData resolvePassData;
|
||||
SetAndRestoreValue<BfResolvePassData*> prevResolvePassData(mResolvePassData, &resolvePassData);
|
||||
BfPassInstance passInstance(mSystem);
|
||||
SetAndRestoreValue<BfPassInstance*> prevPassInstance(mPassInstance, &passInstance);
|
||||
|
@ -9444,6 +9446,22 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetAutocompleteInfo(BfCompiler* bfC
|
|||
return autoCompleteResultString.c_str();
|
||||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetRebuildFileSet(BfCompiler* bfCompiler)
|
||||
{
|
||||
String& autoCompleteResultString = *gTLStrReturn.Get();
|
||||
for (auto& val : bfCompiler->mRebuildFileSet)
|
||||
{
|
||||
autoCompleteResultString += val;
|
||||
autoCompleteResultString += "\n";
|
||||
}
|
||||
return autoCompleteResultString.c_str();
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BfCompiler_FileChanged(BfCompiler* bfCompiler, const char* dirPath)
|
||||
{
|
||||
bfCompiler->mRebuildChangedFileSet.Add(dirPath);
|
||||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetSymbolReferences(BfCompiler* bfCompiler, BfPassInstance* bfPassInstance, BfResolvePassData* resolvePassData)
|
||||
{
|
||||
BP_ZONE("BfCompiler_GetSymbolReferences");
|
||||
|
|
|
@ -336,6 +336,8 @@ public:
|
|||
int mHSPreserveIdx;
|
||||
BfModule* mLastAutocompleteModule;
|
||||
CompileState mCompileState;
|
||||
HashSet<String> mRebuildFileSet;
|
||||
HashSet<String> mRebuildChangedFileSet; // Files we had actual changes from
|
||||
|
||||
Array<BfVDataModule*> mVDataModules;
|
||||
|
||||
|
|
|
@ -1061,6 +1061,9 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild
|
|||
delete typeInst->mTypeInfoEx;
|
||||
typeInst->mTypeInfoEx = NULL;
|
||||
|
||||
if (typeInst->mCeTypeInfo != NULL)
|
||||
typeInst->mCeTypeInfo->mRebuildMap.Clear();
|
||||
|
||||
if (typeInst->mTypeDef->mEmitParent != NULL)
|
||||
{
|
||||
auto emitTypeDef = typeInst->mTypeDef;
|
||||
|
@ -1895,9 +1898,11 @@ void BfContext::UpdateRevisedTypes()
|
|||
|
||||
Dictionary<String, uint64> lastWriteTimeMap;
|
||||
|
||||
bool rebuildAllFilesChanged = mCompiler->mRebuildChangedFileSet.Contains("*");
|
||||
|
||||
// Do primary 'rebuild' scan
|
||||
for (auto type : mResolvedTypes)
|
||||
{
|
||||
{
|
||||
auto typeInst = type->ToTypeInstance();
|
||||
if (type == NULL)
|
||||
{
|
||||
|
@ -1958,6 +1963,14 @@ void BfContext::UpdateRevisedTypes()
|
|||
}
|
||||
if (*valuePtr != kv.mValue.mInt)
|
||||
changed = true;
|
||||
mCompiler->mRebuildFileSet.Add(kv.mKey.mString);
|
||||
}
|
||||
|
||||
if ((kv.mKey.mKind == CeRebuildKey::Kind_File) || (kv.mKey.mKind == CeRebuildKey::Kind_Directory))
|
||||
{
|
||||
if ((rebuildAllFilesChanged) || (mCompiler->mRebuildChangedFileSet.Contains(kv.mKey.mString)))
|
||||
changed = true;
|
||||
mCompiler->mRebuildFileSet.Add(kv.mKey.mString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1984,20 +1997,15 @@ void BfContext::UpdateRevisedTypes()
|
|||
continue;
|
||||
}
|
||||
|
||||
// if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mParser != NULL) && (!typeInst->IsSpecializedType()))
|
||||
// {
|
||||
// if (typeDef->HasSource(mCompiler->mResolvePassData->mParser))
|
||||
// {
|
||||
// HandleChangedTypeDef(typeDef);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (typeDef->mDefState != BfTypeDef::DefState_New)
|
||||
{
|
||||
defStateChangedQueue.Add(typeInst);
|
||||
}
|
||||
}
|
||||
|
||||
// We consumed this above
|
||||
mCompiler->mRebuildChangedFileSet.Clear();
|
||||
|
||||
for (auto typeInst : defStateChangedQueue)
|
||||
{
|
||||
BP_ZONE("BfContext::UpdateRevisedTypes defStateChangedQueue");
|
||||
|
|
|
@ -5541,7 +5541,9 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
|
|||
}
|
||||
else
|
||||
{
|
||||
CeEvalFlags evalFlags = CeEvalFlags_None;
|
||||
CeEvalFlags evalFlags = CeEvalFlags_None;
|
||||
if ((mBfEvalExprFlags & BfEvalExprFlags_NoCeRebuildFlags) != 0)
|
||||
evalFlags = (CeEvalFlags)(evalFlags | CeEvalFlags_NoRebuild);
|
||||
auto constRet = mModule->mCompiler->mCEMachine->Call(targetSrc, mModule, methodInstance, irArgs, evalFlags, mExpectingType);
|
||||
if (constRet)
|
||||
{
|
||||
|
|
|
@ -79,6 +79,7 @@ enum BfEvalExprFlags
|
|||
BfEvalExprFlags_WasMethodRef = 0x800000,
|
||||
BfEvalExprFlags_DeclType = 0x1000000,
|
||||
BfEvalExprFlags_AllowBase = 0x2000000,
|
||||
BfEvalExprFlags_NoCeRebuildFlags = 0x4000000,
|
||||
|
||||
BfEvalExprFlags_InheritFlags = BfEvalExprFlags_NoAutoComplete | BfEvalExprFlags_Comptime | BfEvalExprFlags_DeclType
|
||||
};
|
||||
|
|
|
@ -3028,16 +3028,38 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str)
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void CeContext::AddRebuild(const CeRebuildKey& key, const CeRebuildValue& value)
|
||||
bool CeContext::AddRebuild(const CeRebuildKey& key, const CeRebuildValue& value)
|
||||
{
|
||||
if (mCurModule == NULL)
|
||||
return;
|
||||
return false;
|
||||
if (mCurModule->mCurTypeInstance == NULL)
|
||||
return;
|
||||
return false;
|
||||
if ((mCurEvalFlags & CeEvalFlags_NoRebuild) != 0)
|
||||
return false;
|
||||
if (mCurModule->mCurTypeInstance->mCeTypeInfo == NULL)
|
||||
mCurModule->mCurTypeInstance->mCeTypeInfo = new BfCeTypeInfo();
|
||||
mCurModule->mCurTypeInstance->mCeTypeInfo->mRebuildMap[key] = value;
|
||||
mCurModule->mCompiler->mHasComptimeRebuilds = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CeContext::AddFileRebuild(const StringImpl& path)
|
||||
{
|
||||
auto timeStamp = BfpFile_GetTime_LastWrite(path.c_str());
|
||||
if (timeStamp != 0)
|
||||
{
|
||||
String fixedPath = FixPathAndCase(path);
|
||||
|
||||
CeRebuildKey rebuildKey;
|
||||
rebuildKey.mKind = CeRebuildKey::Kind_File;
|
||||
rebuildKey.mString = fixedPath;
|
||||
|
||||
CeRebuildValue rebuildValue;
|
||||
rebuildValue.mInt = timeStamp;
|
||||
|
||||
if (AddRebuild(rebuildKey, rebuildValue))
|
||||
mCurModule->mCompiler->mRebuildFileSet.Add(fixedPath);
|
||||
}
|
||||
}
|
||||
|
||||
uint8* CeContext::CeMalloc(int size)
|
||||
|
@ -5243,21 +5265,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
if (bfpFile != NULL)
|
||||
{
|
||||
if ((createKind == BfpFileCreateKind_OpenExisting) || (createKind == BfpFileCreateKind_OpenAlways))
|
||||
{
|
||||
auto timeStamp = BfpFile_GetTime_LastWrite(path.c_str());
|
||||
if (timeStamp != 0)
|
||||
{
|
||||
CeRebuildKey rebuildKey;
|
||||
rebuildKey.mKind = CeRebuildKey::Kind_File;
|
||||
rebuildKey.mString = path;
|
||||
|
||||
CeRebuildValue rebuildValue;
|
||||
rebuildValue.mInt = timeStamp;
|
||||
|
||||
AddRebuild(rebuildKey, rebuildValue);
|
||||
}
|
||||
}
|
||||
|
||||
AddFileRebuild(path);
|
||||
CeInternalData* internalData = new CeInternalData();
|
||||
internalData->mKind = CeInternalData::Kind_File;
|
||||
internalData->mFile = bfpFile;
|
||||
|
@ -5351,6 +5359,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 8);
|
||||
String path;
|
||||
CE_CHECKADDR_STR(path, nameAddr);
|
||||
AddFileRebuild(path);
|
||||
result = BfpFile_GetTime_LastWrite(path.c_str());
|
||||
}
|
||||
else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_GetAttributes)
|
||||
|
@ -5363,7 +5372,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
|
||||
String path;
|
||||
CE_CHECKADDR_STR(path, nameAddr);
|
||||
|
||||
AddFileRebuild(path);
|
||||
result = BfpFile_GetAttributes(path.c_str(), (outResultAddr == 0) ? NULL : (BfpFileResult*)(memStart + outResultAddr));
|
||||
}
|
||||
else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_SetAttributes)
|
||||
|
@ -5425,6 +5434,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
|
||||
String path;
|
||||
CE_CHECKADDR_STR(path, nameAddr);
|
||||
AddFileRebuild(path);
|
||||
result = BfpFile_Exists(path.c_str());
|
||||
}
|
||||
else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_GetTempPath)
|
||||
|
@ -5551,9 +5561,12 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
addr_ce outStdOutAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize);
|
||||
addr_ce outStdErrAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + ptrSize);
|
||||
|
||||
CE_CHECKADDR(outStdInAddr, ptrSize);
|
||||
CE_CHECKADDR(outStdOutAddr, ptrSize);
|
||||
CE_CHECKADDR(outStdErrAddr, ptrSize);
|
||||
if (outStdInAddr != 0)
|
||||
CE_CHECKADDR(outStdInAddr, ptrSize);
|
||||
if (outStdOutAddr != 0)
|
||||
CE_CHECKADDR(outStdOutAddr, ptrSize);
|
||||
if (outStdErrAddr != NULL)
|
||||
CE_CHECKADDR(outStdErrAddr, ptrSize);
|
||||
|
||||
BfpFile* outStdIn = NULL;
|
||||
BfpFile* outStdOut = NULL;
|
||||
|
@ -5580,9 +5593,12 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
}
|
||||
};
|
||||
|
||||
_SetHandle(outStdInAddr, outStdIn);
|
||||
_SetHandle(outStdOutAddr, outStdOut);
|
||||
_SetHandle(outStdErrAddr, outStdErr);
|
||||
if (outStdInAddr != NULL)
|
||||
_SetHandle(outStdInAddr, outStdIn);
|
||||
if (outStdOutAddr != NULL)
|
||||
_SetHandle(outStdOutAddr, outStdOut);
|
||||
if (outStdErrAddr != NULL)
|
||||
_SetHandle(outStdErrAddr, outStdErr);
|
||||
}
|
||||
else if (checkFunction->mFunctionKind == CeFunctionKind_BfpSpawn_Kill)
|
||||
{
|
||||
|
@ -5665,19 +5681,17 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
|||
|
||||
auto bfpFindFileData = BfpFindFileData_FindFirstFile(path.c_str(), (BfpFindFileFlags)flags, (outResultAddr == 0) ? NULL : (BfpFileResult*)(memStart + outResultAddr));
|
||||
if (bfpFindFileData != NULL)
|
||||
{
|
||||
// auto timeStamp = BfpFile_GetTime_LastWrite(path.c_str());
|
||||
// if (timeStamp != 0)
|
||||
// {
|
||||
// CeRebuildKey rebuildKey;
|
||||
// rebuildKey.mKind = CeRebuildKey::Kind_File;
|
||||
// rebuildKey.mString = path;
|
||||
//
|
||||
// CeRebuildValue rebuildValue;
|
||||
// rebuildValue.mInt = timeStamp;
|
||||
//
|
||||
// AddRebuild(rebuildKey, rebuildValue);
|
||||
// }
|
||||
{
|
||||
String dir = GetFileDir(path);
|
||||
dir = FixPathAndCase(dir);
|
||||
dir.Append(DIR_SEP_CHAR);
|
||||
|
||||
CeRebuildKey rebuildKey;
|
||||
rebuildKey.mKind = CeRebuildKey::Kind_Directory;
|
||||
rebuildKey.mString = dir;
|
||||
CeRebuildValue rebuildValue;
|
||||
if (AddRebuild(rebuildKey, rebuildValue))
|
||||
mCurModule->mCompiler->mRebuildFileSet.Add(dir);
|
||||
|
||||
CeInternalData* internalData = new CeInternalData();
|
||||
internalData->mKind = CeInternalData::Kind_FindFileData;
|
||||
|
|
|
@ -530,6 +530,7 @@ enum CeEvalFlags
|
|||
CeEvalFlags_Cascade = 1,
|
||||
CeEvalFlags_PersistantError = 2,
|
||||
CeEvalFlags_DeferIfNotOnlyError = 4,
|
||||
CeEvalFlags_NoRebuild = 8
|
||||
};
|
||||
|
||||
enum CeOperandKind
|
||||
|
@ -766,7 +767,8 @@ public:
|
|||
enum Kind
|
||||
{
|
||||
Kind_None,
|
||||
Kind_File
|
||||
Kind_File,
|
||||
Kind_Directory
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -866,7 +868,8 @@ public:
|
|||
BfError* Fail(const StringImpl& error);
|
||||
BfError* Fail(const CeFrame& curFrame, const StringImpl& error);
|
||||
|
||||
void AddRebuild(const CeRebuildKey& key, const CeRebuildValue& value);
|
||||
bool AddRebuild(const CeRebuildKey& key, const CeRebuildValue& value);
|
||||
void AddFileRebuild(const StringImpl& filePath);
|
||||
uint8* CeMalloc(int size);
|
||||
bool CeFree(addr_ce addr);
|
||||
addr_ce CeAllocArray(BfArrayType* arrayType, int count, addr_ce& elemsAddr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue