mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Reworked !hasRequiredTypes state
This commit is contained in:
parent
5f5c752f5d
commit
eddbf7a984
11 changed files with 104 additions and 77 deletions
|
@ -341,11 +341,10 @@ BfCompiler::HotResolveData::~HotResolveData()
|
|||
|
||||
BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
|
||||
{
|
||||
//llvm::DebugFlag = true;
|
||||
|
||||
memset(&mStats, 0, sizeof(mStats));
|
||||
mCompletionPct = 0;
|
||||
mCanceling = false;
|
||||
mHasRequiredTypes = false;
|
||||
mNeedsFullRefresh = false;
|
||||
mFastFinish = false;
|
||||
mHasQueuedTypeRebuilds = false;
|
||||
|
@ -6596,7 +6595,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
|
||||
BpEnter("Compile_Start");
|
||||
|
||||
bool hasRequiredTypes = true;
|
||||
mHasRequiredTypes = true;
|
||||
|
||||
//HashSet<BfTypeDef*> internalTypeDefs;
|
||||
|
||||
|
@ -6606,7 +6605,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
if (typeDef == NULL)
|
||||
{
|
||||
mPassInstance->Fail(StrFormat("Unable to find system type: %s", typeName.c_str()));
|
||||
hasRequiredTypes = false;
|
||||
mHasRequiredTypes = false;
|
||||
}
|
||||
return typeDef;
|
||||
};
|
||||
|
@ -6722,13 +6721,11 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
mContext->mBfTypeType = NULL;
|
||||
mContext->mBfClassVDataPtrType = NULL;
|
||||
|
||||
if (!hasRequiredTypes)
|
||||
if (!mHasRequiredTypes)
|
||||
{
|
||||
// Force rebuilding
|
||||
BfLogSysM("Compile missing required types\n");
|
||||
mInInvalidState = true;
|
||||
mOptions.mForceRebuildIdx++;
|
||||
return true;
|
||||
}
|
||||
|
||||
mSystem->CheckLockYield();
|
||||
|
@ -6736,8 +6733,6 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
mContext->mScratchModule->ResolveTypeDef(mBfObjectTypeDef);
|
||||
VisitSourceExteriorNodes();
|
||||
|
||||
//BF_ASSERT(hasRequiredTypes);
|
||||
|
||||
if (!mIsResolveOnly)
|
||||
{
|
||||
HashSet<BfModule*> foundVDataModuleSet;
|
||||
|
@ -6812,18 +6807,13 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
if (mIsResolveOnly)
|
||||
VisitAutocompleteExteriorIdentifiers();
|
||||
|
||||
if (!hasRequiredTypes)
|
||||
{
|
||||
BfLogSysM("Missing required types\n");
|
||||
}
|
||||
|
||||
mStats.mTypesQueued = 0;
|
||||
mStats.mMethodsQueued = 0;
|
||||
|
||||
mStats.mTypesQueued += (int)mContext->mPopulateTypeWorkList.size();
|
||||
mStats.mMethodsQueued += (int)mContext->mMethodWorkList.size();
|
||||
|
||||
if (hasRequiredTypes)
|
||||
//
|
||||
{
|
||||
mContext->mScratchModule->ResolveTypeDef(mBfObjectTypeDef, BfPopulateType_Full);
|
||||
|
||||
|
@ -6865,7 +6855,6 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
}
|
||||
}
|
||||
|
||||
if (hasRequiredTypes)
|
||||
ProcessPurgatory(true);
|
||||
|
||||
// Mark used modules
|
||||
|
@ -6967,7 +6956,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
}
|
||||
|
||||
// Generate slot nums
|
||||
if ((!mIsResolveOnly) && (hasRequiredTypes) && (!mCanceling))
|
||||
if ((!mIsResolveOnly) && (!mCanceling))
|
||||
{
|
||||
if ((!IsHotCompile()) || (mHotState->mHasNewInterfaceTypes))
|
||||
{
|
||||
|
@ -7099,12 +7088,11 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
DoWorkLoop();
|
||||
}
|
||||
|
||||
if (hasRequiredTypes)
|
||||
ProcessPurgatory(false);
|
||||
|
||||
// Old Mark used modules
|
||||
|
||||
if ((!mIsResolveOnly) && (hasRequiredTypes))
|
||||
if (!mIsResolveOnly)
|
||||
{
|
||||
// if ((!mPassInstance->HasFailed()) && (!mCanceling))
|
||||
// {
|
||||
|
@ -7161,7 +7149,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
|
||||
String moduleListStr;
|
||||
int numModulesWritten = 0;
|
||||
if ((hasRequiredTypes) && (!mCanceling))
|
||||
if (!mCanceling)
|
||||
{
|
||||
if (!mIsResolveOnly)
|
||||
{
|
||||
|
@ -7251,8 +7239,6 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (!hasRequiredTypes)
|
||||
break;
|
||||
if (mCanceling)
|
||||
mCodeGen.Cancel();
|
||||
bool isDone = mCodeGen.Finish();
|
||||
|
@ -7391,8 +7377,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
|||
// gBEMemReporter.Report();
|
||||
// int memReporterSize = gBEMemReporterSize;
|
||||
|
||||
mLastRevisionAborted = mCanceling || !hasRequiredTypes;
|
||||
bool didCancel = mCanceling && hasRequiredTypes;
|
||||
mLastRevisionAborted = mCanceling;
|
||||
bool didCancel = mCanceling;
|
||||
mCanceling = false;
|
||||
|
||||
mContext->ValidateDependencies();
|
||||
|
|
|
@ -323,6 +323,7 @@ public:
|
|||
BfCodeGen mCodeGen;
|
||||
String mOutputDirectory;
|
||||
bool mCanceling;
|
||||
bool mHasRequiredTypes;
|
||||
bool mNeedsFullRefresh;
|
||||
bool mFastFinish;
|
||||
bool mHasQueuedTypeRebuilds; // Infers we had a fast finish that requires a type rebuild
|
||||
|
|
|
@ -416,15 +416,22 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch
|
|||
}
|
||||
else
|
||||
{
|
||||
if ((argValue.mValue.IsFake()) && (!argValue.mType->IsValuelessType()))
|
||||
{
|
||||
bool requiresConst = false;
|
||||
if ((mModule->mCurMethodInstance == NULL) || (mModule->mCurMethodInstance->mMethodDef->mMethodType != BfMethodType_Mixin))
|
||||
requiresConst = true;
|
||||
|
||||
if ((requiresConst) && (argValue.mValue.IsFake()) && (!argValue.mType->IsValuelessType()))
|
||||
{
|
||||
mModule->Fail("Expression does not evaluate to a constant value", argExpr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!argValue.mType->IsVar())
|
||||
{
|
||||
if ((!requiresConst) || (argValue.mValue.IsConst()) || (argValue.mType->IsValuelessType()))
|
||||
llvmArgs.push_back(argValue.mValue);
|
||||
else
|
||||
llvmArgs.push_back(mModule->GetDefaultValue(argValue.mType));
|
||||
}
|
||||
paramIdx++;
|
||||
}
|
||||
argIdx++;
|
||||
|
|
|
@ -2917,10 +2917,21 @@ void BfContext::Cleanup()
|
|||
|
||||
// Clean up deleted BfTypes
|
||||
// These need to get deleted before the modules because we access mModule in the MethodInstance dtors
|
||||
for (auto type : mTypeGraveyard)
|
||||
for (int pass = 0; pass < 2; pass++)
|
||||
{
|
||||
for (int i = 0; i < (int)mTypeGraveyard.size(); i++)
|
||||
{
|
||||
auto type = mTypeGraveyard[i];
|
||||
if (type == NULL)
|
||||
continue;
|
||||
bool deleteNow = (type->IsBoxed() == (pass == 0));
|
||||
if (!deleteNow)
|
||||
continue;
|
||||
|
||||
BF_ASSERT(type->mRebuildFlags & BfTypeRebuildFlag_Deleted);
|
||||
delete type;
|
||||
mTypeGraveyard[i] = NULL;
|
||||
}
|
||||
}
|
||||
mTypeGraveyard.Clear();
|
||||
|
||||
|
|
|
@ -1780,19 +1780,16 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
|
|||
|
||||
if (prevRevisionTypeDef->mDefState == BfTypeDef::DefState_AwaitingNewVersion)
|
||||
{
|
||||
if (prevRevisionTypeDef->mNextRevision != NULL)
|
||||
{
|
||||
BfLogSysM("Deleting unused nextRevision %p from prevRevision %p\n", prevRevisionTypeDef->mNextRevision, prevRevisionTypeDef);
|
||||
delete prevRevisionTypeDef->mNextRevision;
|
||||
}
|
||||
prevRevisionTypeDef->mNextRevision = mCurTypeDef;
|
||||
BF_ASSERT(mCurTypeDef->mSystem != NULL);
|
||||
mCurActualTypeDef = prevRevisionTypeDef;
|
||||
doInsertNew = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prevRevisionTypeDef->mNextRevision != NULL)
|
||||
prevRevisionTypeDef = prevRevisionTypeDef->mNextRevision;
|
||||
|
||||
prevRevisionTypeDef = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1820,8 +1817,8 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
|
|||
outerTypeDef->mNestedTypes.push_back(mCurActualTypeDef);
|
||||
}
|
||||
|
||||
BfLogSysM("Creating TypeDef %p Hash:%d from TypeDecl: %p Source: %p ResolvePass: %d AutoComplete:%d\n", mCurTypeDef, mSystem->mTypeDefs.GetHash(mCurTypeDef), typeDeclaration,
|
||||
typeDeclaration->GetSourceData(), mResolvePassData != NULL, isAutoCompleteTempType);
|
||||
BfLogSysM("Creating TypeDef %p Hash:%d from TypeDecl: %p Source: %p ResolvePass: %d AutoComplete:%d PrevRevision:%d\n", mCurTypeDef, mSystem->mTypeDefs.GetHash(mCurTypeDef), typeDeclaration,
|
||||
typeDeclaration->GetSourceData(), mResolvePassData != NULL, isAutoCompleteTempType, prevRevisionTypeDef);
|
||||
|
||||
BF_ASSERT(mCurTypeDef->mNameEx == NULL);
|
||||
|
||||
|
@ -1875,9 +1872,9 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
|
|||
|
||||
if (mCurTypeDef->mFullHash == prevRevisionTypeDef->mFullHash)
|
||||
{
|
||||
if (!mFullRefresh)
|
||||
if ((!mFullRefresh) && (!prevRevisionTypeDef->mForceUseNextRevision))
|
||||
{
|
||||
BfLogSys(bfParser->mSystem, "DefBuilder deleting typeDef with no changes %p\n", prevRevisionTypeDef);
|
||||
BfLogSys(bfParser->mSystem, "DefBuilder deleting typeDef with no changes %p prevRevision: %p\n", mCurTypeDef, prevRevisionTypeDef);
|
||||
prevRevisionTypeDef->mDefState = BfTypeDef::DefState_Defined;
|
||||
BF_ASSERT(prevRevisionTypeDef->mNextRevision == mCurTypeDef);
|
||||
prevRevisionTypeDef->mNextRevision = NULL;
|
||||
|
|
|
@ -10786,6 +10786,9 @@ void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, Bf
|
|||
|
||||
void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrTarget, bool allowNonConstArgs, BfCaptureInfo* captureInfo)
|
||||
{
|
||||
if (!mCompiler->mHasRequiredTypes)
|
||||
return;
|
||||
|
||||
if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL) &&
|
||||
(attributesDirective->IsFromParser(mCompiler->mResolvePassData->mParser)) && (mCompiler->mResolvePassData->mSourceClassifier != NULL))
|
||||
{
|
||||
|
@ -11076,8 +11079,10 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
|||
if (assignExpr->mRight != NULL)
|
||||
{
|
||||
BfTypedValue result = constResolver.Resolve(assignExpr->mRight, propType);
|
||||
if (result)
|
||||
if ((result) && (!result.mType->IsVar()))
|
||||
{
|
||||
if (!result.mValue.IsConst())
|
||||
result = GetDefaultTypedValue(result.mType);
|
||||
BF_ASSERT(result.mType == propType);
|
||||
CurrentAddToConstHolder(result.mValue);
|
||||
setProperty.mParam = result;
|
||||
|
@ -19437,7 +19442,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
|||
}
|
||||
|
||||
auto bodyBlock = BfNodeDynCast<BfBlock>(methodDef->mBody);
|
||||
if (methodDef->mBody == NULL)
|
||||
if (!mCompiler->mHasRequiredTypes)
|
||||
{
|
||||
// Skip processing to avoid errors
|
||||
}
|
||||
else if (methodDef->mBody == NULL)
|
||||
{
|
||||
if (methodDeclaration != NULL)
|
||||
{
|
||||
|
@ -22037,7 +22046,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
|||
resolvedParamType = CreateArrayType(mContext->mBfObjectType, 1);
|
||||
}
|
||||
|
||||
if (addParams)
|
||||
if ((addParams) && (resolvedParamType != NULL))
|
||||
{
|
||||
BfMethodParam methodParam;
|
||||
methodParam.mResolvedType = resolvedParamType;
|
||||
|
|
|
@ -5979,11 +5979,14 @@ BfArrayType* BfModule::CreateArrayType(BfType* resolvedType, int dimensions)
|
|||
BF_ASSERT(!resolvedType->IsVar());
|
||||
BF_ASSERT(!resolvedType->IsIntUnknown());
|
||||
|
||||
auto arrayTypeDef = mCompiler->GetArrayTypeDef(dimensions);
|
||||
if (arrayTypeDef == NULL)
|
||||
return NULL;
|
||||
auto arrayType = mContext->mArrayTypePool.Get();
|
||||
delete arrayType->mGenericTypeInfo;
|
||||
arrayType->mGenericTypeInfo = new BfGenericTypeInfo();
|
||||
arrayType->mContext = mContext;
|
||||
arrayType->mTypeDef = mCompiler->GetArrayTypeDef(dimensions);
|
||||
arrayType->mTypeDef = arrayTypeDef;
|
||||
arrayType->mDimensions = dimensions;
|
||||
arrayType->mGenericTypeInfo->mTypeGenericArguments.clear();
|
||||
arrayType->mGenericTypeInfo->mTypeGenericArguments.push_back(resolvedType);
|
||||
|
@ -9745,7 +9748,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
|||
}
|
||||
|
||||
auto elementType = ResolveTypeRef(arrayTypeRef->mElementType, BfPopulateType_Declaration, BfResolveTypeRefFlag_AllowGenericParamConstValue);
|
||||
if (elementType == NULL)
|
||||
auto arrayTypeDef = mCompiler->GetArrayTypeDef(arrayTypeRef->mDimensions);
|
||||
if ((elementType == NULL) || (arrayTypeDef == NULL))
|
||||
{
|
||||
mContext->mResolvedTypes.RemoveEntry(resolvedEntry);
|
||||
return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags);
|
||||
|
@ -9818,7 +9822,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
|||
arrayType->mGenericTypeInfo = new BfGenericTypeInfo();
|
||||
arrayType->mContext = mContext;
|
||||
arrayType->mDimensions = arrayTypeRef->mDimensions;
|
||||
arrayType->mTypeDef = mCompiler->GetArrayTypeDef(arrayType->mDimensions);
|
||||
arrayType->mTypeDef = arrayTypeDef;
|
||||
arrayType->mGenericTypeInfo->mTypeGenericArguments.push_back(elementType);
|
||||
resolvedEntry->mValue = arrayType;
|
||||
|
||||
|
|
|
@ -2586,6 +2586,13 @@ void BfSystem::RemoveTypeDef(BfTypeDef* typeDef)
|
|||
mTypeDefs.Remove(typeDef);
|
||||
AutoCrit autoCrit(mDataLock);
|
||||
|
||||
if (typeDef->mOuterType != NULL)
|
||||
{
|
||||
// We are in the outer type's mNestedTypes list
|
||||
BfLogSys(this, "Setting mForceUseNextRevision on outer type %p from %p\n", typeDef->mOuterType, typeDef);
|
||||
typeDef->mOuterType->mForceUseNextRevision = true;
|
||||
}
|
||||
|
||||
// This will get properly handled in UntrackName when we process the mTypeDefDeleteQueue, but this
|
||||
// mAtomUpdateIdx increment will trigger lookup changes in BfContext::VerifyTypeLookups
|
||||
if (typeDef->mName != mEmptyAtom)
|
||||
|
@ -2797,6 +2804,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
|
|||
typeDef->mNextRevision = NULL;
|
||||
|
||||
typeDef->mDefState = BfTypeDef::DefState_Defined;
|
||||
typeDef->mForceUseNextRevision = false;
|
||||
|
||||
VerifyTypeDef(typeDef);
|
||||
}
|
||||
|
|
|
@ -1006,6 +1006,7 @@ public:
|
|||
bool mIsNextRevision;
|
||||
bool mInDeleteQueue;
|
||||
bool mHasEmitMembers;
|
||||
bool mForceUseNextRevision;
|
||||
|
||||
public:
|
||||
BfTypeDef()
|
||||
|
@ -1048,6 +1049,7 @@ public:
|
|||
mIsNextRevision = false;
|
||||
mInDeleteQueue = false;
|
||||
mHasEmitMembers = false;
|
||||
mForceUseNextRevision = false;
|
||||
mDupDetectedRevision = -1;
|
||||
mNestDepth = 0;
|
||||
mOuterType = NULL;
|
||||
|
|
|
@ -6255,6 +6255,9 @@ CeMachine::~CeMachine()
|
|||
|
||||
auto _RemoveFunctionInfo = [&](CeFunctionInfo* functionInfo)
|
||||
{
|
||||
if (functionInfo->mMethodInstance != NULL)
|
||||
functionInfo->mMethodInstance->mInCEMachine = false;
|
||||
|
||||
if (functionInfo->mCeFunction != NULL)
|
||||
{
|
||||
// We don't need to actually unmap it at this point
|
||||
|
@ -6933,7 +6936,6 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
|
|||
ceFunction->mIsVarReturn = methodInstance->mReturnType->IsVar();
|
||||
ceFunction->mCeFunctionInfo = ceFunctionInfo;
|
||||
ceFunction->mMethodInstance = methodInstance;
|
||||
|
||||
ceFunctionInfo->mMethodInstance = methodInstance;
|
||||
ceFunctionInfo->mCeFunction = ceFunction;
|
||||
MapFunctionId(ceFunction);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue