mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Moved interfaces to owned non-code-generating modules
This commit is contained in:
parent
d86eb0625c
commit
f0d99a2bcc
5 changed files with 52 additions and 18 deletions
|
@ -7072,7 +7072,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
|
||||||
{
|
{
|
||||||
if (!module->mIsSpecialModule)
|
if (!module->mIsSpecialModule)
|
||||||
{
|
{
|
||||||
if ((module->mIsReified) && (module->mIsModuleMutable))
|
if ((module->HasCompiledOutput()) && (module->mIsModuleMutable))
|
||||||
{
|
{
|
||||||
module->Finish();
|
module->Finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,14 @@ BfContext::BfContext(BfCompiler* compiler) :
|
||||||
mScratchModule->mIsSpecialModule = true;
|
mScratchModule->mIsSpecialModule = true;
|
||||||
mScratchModule->mIsScratchModule = true;
|
mScratchModule->mIsScratchModule = true;
|
||||||
mScratchModule->mIsReified = true;
|
mScratchModule->mIsReified = true;
|
||||||
|
mScratchModule->mGeneratesCode = false;
|
||||||
mScratchModule->Init();
|
mScratchModule->Init();
|
||||||
|
|
||||||
mUnreifiedModule = new BfModule(this, "");
|
mUnreifiedModule = new BfModule(this, "");
|
||||||
mUnreifiedModule->mIsSpecialModule = true;
|
mUnreifiedModule->mIsSpecialModule = true;
|
||||||
mUnreifiedModule->mIsScratchModule = true;
|
mUnreifiedModule->mIsScratchModule = true;
|
||||||
mUnreifiedModule->mIsReified = false;
|
mUnreifiedModule->mIsReified = false;
|
||||||
|
mUnreifiedModule->mGeneratesCode = false;
|
||||||
mUnreifiedModule->Init();
|
mUnreifiedModule->Init();
|
||||||
|
|
||||||
mValueTypeDeinitSentinel = (BfMethodInstance*)1;
|
mValueTypeDeinitSentinel = (BfMethodInstance*)1;
|
||||||
|
@ -158,7 +160,7 @@ void BfContext::AssignModule(BfType* type)
|
||||||
// We used to have this "IsReified" check, but we DO want to create modules for unreified types even if they remain unused.
|
// We used to have this "IsReified" check, but we DO want to create modules for unreified types even if they remain unused.
|
||||||
// What was that IsReified check catching?
|
// What was that IsReified check catching?
|
||||||
// It screwed up the reification of generic types- they just got switched to mScratchModule from mUnreifiedModule, but didn't ever generate code.
|
// It screwed up the reification of generic types- they just got switched to mScratchModule from mUnreifiedModule, but didn't ever generate code.
|
||||||
if (/*(!type->IsReified()) ||*/ (type->IsUnspecializedType()) || (type->IsInterface()) || (type->IsVar()) || (type->IsTypeAlias()) || (type->IsFunction()))
|
if (/*(!type->IsReified()) ||*/ (type->IsUnspecializedType()) || (type->IsVar()) || (type->IsTypeAlias()) || (type->IsFunction()))
|
||||||
{
|
{
|
||||||
if (typeInst->mIsReified)
|
if (typeInst->mIsReified)
|
||||||
module = mScratchModule;
|
module = mScratchModule;
|
||||||
|
@ -203,7 +205,7 @@ void BfContext::AssignModule(BfType* type)
|
||||||
{
|
{
|
||||||
String moduleName = GenerateModuleName(typeInst);
|
String moduleName = GenerateModuleName(typeInst);
|
||||||
module = new BfModule(this, moduleName);
|
module = new BfModule(this, moduleName);
|
||||||
module->mIsReified = typeInst->mIsReified;
|
module->mIsReified = typeInst->mIsReified;
|
||||||
module->mProject = project;
|
module->mProject = project;
|
||||||
typeInst->mModule = module;
|
typeInst->mModule = module;
|
||||||
BF_ASSERT(!mLockModules);
|
BF_ASSERT(!mLockModules);
|
||||||
|
@ -221,6 +223,8 @@ void BfContext::AssignModule(BfType* type)
|
||||||
module->mOwnedTypeInstances.push_back(localTypeInst);
|
module->mOwnedTypeInstances.push_back(localTypeInst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module->CalcGeneratesCode();
|
||||||
|
|
||||||
if (needsModuleInit)
|
if (needsModuleInit)
|
||||||
module->Init();
|
module->Init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -829,7 +829,7 @@ BfModule* gLastCreatedModule = NULL;
|
||||||
BfModule::BfModule(BfContext* context, const StringImpl& moduleName)
|
BfModule::BfModule(BfContext* context, const StringImpl& moduleName)
|
||||||
{
|
{
|
||||||
BfLogSys(context->mSystem, "BfModule::BFModule %p %s\n", this, moduleName.c_str());
|
BfLogSys(context->mSystem, "BfModule::BFModule %p %s\n", this, moduleName.c_str());
|
||||||
|
|
||||||
gLastCreatedModule = this;
|
gLastCreatedModule = this;
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
@ -847,6 +847,7 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName)
|
||||||
mUsedSlotCount = -1;
|
mUsedSlotCount = -1;
|
||||||
|
|
||||||
mIsReified = true;
|
mIsReified = true;
|
||||||
|
mGeneratesCode = true;
|
||||||
mReifyQueued = false;
|
mReifyQueued = false;
|
||||||
mIsSpecialModule = false;
|
mIsSpecialModule = false;
|
||||||
mIsComptimeModule = false;
|
mIsComptimeModule = false;
|
||||||
|
@ -1048,6 +1049,20 @@ void BfModule::FinishInit()
|
||||||
mAwaitingInitFinish = false;
|
mAwaitingInitFinish = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BfModule::CalcGeneratesCode()
|
||||||
|
{
|
||||||
|
if ((!mIsReified) || (mIsScratchModule))
|
||||||
|
{
|
||||||
|
mGeneratesCode = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mGeneratesCode = false;
|
||||||
|
for (auto typeInst : mOwnedTypeInstances)
|
||||||
|
if (!typeInst->IsInterface())
|
||||||
|
mGeneratesCode = true;
|
||||||
|
}
|
||||||
|
|
||||||
void BfModule::ReifyModule()
|
void BfModule::ReifyModule()
|
||||||
{
|
{
|
||||||
BF_ASSERT((mCompiler->mCompileState != BfCompiler::CompileState_Unreified) && (mCompiler->mCompileState != BfCompiler::CompileState_VData));
|
BF_ASSERT((mCompiler->mCompileState != BfCompiler::CompileState_Unreified) && (mCompiler->mCompileState != BfCompiler::CompileState_VData));
|
||||||
|
@ -1055,9 +1070,10 @@ void BfModule::ReifyModule()
|
||||||
BfLogSysM("ReifyModule %@ %s\n", this, mModuleName.c_str());
|
BfLogSysM("ReifyModule %@ %s\n", this, mModuleName.c_str());
|
||||||
BF_ASSERT((this != mContext->mScratchModule) && (this != mContext->mUnreifiedModule));
|
BF_ASSERT((this != mContext->mScratchModule) && (this != mContext->mUnreifiedModule));
|
||||||
mIsReified = true;
|
mIsReified = true;
|
||||||
|
CalcGeneratesCode();
|
||||||
mReifyQueued = false;
|
mReifyQueued = false;
|
||||||
StartNewRevision(RebuildKind_SkipOnDemandTypes, true);
|
StartNewRevision(RebuildKind_SkipOnDemandTypes, true);
|
||||||
mCompiler->mStats.mModulesReified++;
|
mCompiler->mStats.mModulesReified++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::UnreifyModule()
|
void BfModule::UnreifyModule()
|
||||||
|
@ -1065,6 +1081,7 @@ void BfModule::UnreifyModule()
|
||||||
BfLogSysM("UnreifyModule %p %s\n", this, mModuleName.c_str());
|
BfLogSysM("UnreifyModule %p %s\n", this, mModuleName.c_str());
|
||||||
BF_ASSERT((this != mContext->mScratchModule) && (this != mContext->mUnreifiedModule));
|
BF_ASSERT((this != mContext->mScratchModule) && (this != mContext->mUnreifiedModule));
|
||||||
mIsReified = false;
|
mIsReified = false;
|
||||||
|
CalcGeneratesCode();
|
||||||
mReifyQueued = false;
|
mReifyQueued = false;
|
||||||
StartNewRevision(RebuildKind_None, true);
|
StartNewRevision(RebuildKind_None, true);
|
||||||
mCompiler->mStats.mModulesUnreified++;
|
mCompiler->mStats.mModulesUnreified++;
|
||||||
|
@ -1126,8 +1143,8 @@ void BfModule::SetupIRBuilder(bool dbgVerifyCodeGen)
|
||||||
// The only purpose of not ignoring writes is so we can verify the codegen one instruction at a time
|
// The only purpose of not ignoring writes is so we can verify the codegen one instruction at a time
|
||||||
mBfIRBuilder->mDbgVerifyCodeGen = true;
|
mBfIRBuilder->mDbgVerifyCodeGen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!mIsReified)
|
else if (!mGeneratesCode)
|
||||||
{
|
{
|
||||||
mBfIRBuilder->mIgnoreWrites = true;
|
mBfIRBuilder->mIgnoreWrites = true;
|
||||||
}
|
}
|
||||||
|
@ -9475,10 +9492,10 @@ bool BfModule::WantsLifetimes()
|
||||||
|
|
||||||
bool BfModule::HasCompiledOutput()
|
bool BfModule::HasCompiledOutput()
|
||||||
{
|
{
|
||||||
return (!mSystem->mIsResolveOnly) && (mIsReified) && (!mIsComptimeModule);
|
return (!mSystem->mIsResolveOnly) && (mGeneratesCode) && (!mIsComptimeModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We will skip the object access check for any occurances of this value
|
// We will skip the object access check for any occurrences of this value
|
||||||
void BfModule::SkipObjectAccessCheck(BfTypedValue typedVal)
|
void BfModule::SkipObjectAccessCheck(BfTypedValue typedVal)
|
||||||
{
|
{
|
||||||
if ((mBfIRBuilder->mIgnoreWrites) || (!typedVal.mType->IsObjectOrInterface()) || (mCurMethodState == NULL) || (mCurMethodState->mIgnoreObjectAccessCheck))
|
if ((mBfIRBuilder->mIgnoreWrites) || (!typedVal.mType->IsObjectOrInterface()) || (mCurMethodState == NULL) || (mCurMethodState->mIgnoreObjectAccessCheck))
|
||||||
|
@ -13107,9 +13124,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
||||||
{
|
{
|
||||||
MarkDerivedDirty(typeInst);
|
MarkDerivedDirty(typeInst);
|
||||||
|
|
||||||
if (mIsScratchModule)
|
if (!HasCompiledOutput())
|
||||||
{
|
{
|
||||||
BfLogSysM("Marking scratch module method instance as reified: %p\n", methodInstance);
|
BfLogSysM("Marking non-compiled-output module method instance as reified: %p\n", methodInstance);
|
||||||
_SetReified();
|
_SetReified();
|
||||||
CheckHotMethod(methodInstance, "");
|
CheckHotMethod(methodInstance, "");
|
||||||
}
|
}
|
||||||
|
@ -23923,14 +23940,16 @@ bool BfModule::Finish()
|
||||||
if (mUsedSlotCount != -1)
|
if (mUsedSlotCount != -1)
|
||||||
{
|
{
|
||||||
BF_ASSERT(mCompiler->mMaxInterfaceSlots != -1);
|
BF_ASSERT(mCompiler->mMaxInterfaceSlots != -1);
|
||||||
mUsedSlotCount = mCompiler->mMaxInterfaceSlots;
|
mUsedSlotCount = mCompiler->mMaxInterfaceSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((!mGeneratesCode) && (!mAddedToCount))
|
||||||
|
return true;
|
||||||
|
|
||||||
BF_ASSERT(mAddedToCount);
|
BF_ASSERT(mAddedToCount);
|
||||||
mAddedToCount = false;
|
mAddedToCount = false;
|
||||||
mAwaitingFinish = false;
|
mAwaitingFinish = false;
|
||||||
|
|
||||||
|
|
||||||
mCompiler->mStats.mModulesFinished++;
|
mCompiler->mStats.mModulesFinished++;
|
||||||
|
|
||||||
if (HasCompiledOutput())
|
if (HasCompiledOutput())
|
||||||
|
@ -24053,13 +24072,13 @@ bool BfModule::Finish()
|
||||||
if ((writeModule) && (!mBfIRBuilder->mIgnoreWrites))
|
if ((writeModule) && (!mBfIRBuilder->mIgnoreWrites))
|
||||||
mCompiler->mCodeGen.WriteObjectFile(this, outputPath, codeGenOptions);
|
mCompiler->mCodeGen.WriteObjectFile(this, outputPath, codeGenOptions);
|
||||||
mLastModuleWrittenRevision = mCompiler->mRevision;
|
mLastModuleWrittenRevision = mCompiler->mRevision;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (auto type : mOwnedTypeInstances)
|
for (auto type : mOwnedTypeInstances)
|
||||||
{
|
{
|
||||||
BF_ASSERT((!type->IsIncomplete()) || (type->IsSpecializedByAutoCompleteMethod()));
|
BF_ASSERT((!type->IsIncomplete()) || (type->IsSpecializedByAutoCompleteMethod()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& specModulePair : mSpecializedMethodModules)
|
for (auto& specModulePair : mSpecializedMethodModules)
|
||||||
|
@ -24129,8 +24148,7 @@ void BfModule::ClearModuleData(bool clearTransientData)
|
||||||
mAddedToCount = false;
|
mAddedToCount = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDICompileUnit = BfIRMDNode();
|
mDICompileUnit = BfIRMDNode();
|
||||||
mIsModuleMutable = false;
|
|
||||||
if (clearTransientData)
|
if (clearTransientData)
|
||||||
mIncompleteMethodCount = 0;
|
mIncompleteMethodCount = 0;
|
||||||
mHasGenericMethods = false;
|
mHasGenericMethods = false;
|
||||||
|
@ -24165,7 +24183,8 @@ void BfModule::ClearModuleData(bool clearTransientData)
|
||||||
if (mNextAltModule != NULL)
|
if (mNextAltModule != NULL)
|
||||||
mNextAltModule->ClearModuleData();
|
mNextAltModule->ClearModuleData();
|
||||||
|
|
||||||
BfLogSysM("ClearModuleData. Deleting IRBuilder: %p\n", mBfIRBuilder);
|
BfLogSysM("ClearModuleData. Deleting IRBuilder: %p\n", mBfIRBuilder);
|
||||||
|
mIsModuleMutable = false;
|
||||||
delete mBfIRBuilder;
|
delete mBfIRBuilder;
|
||||||
mBfIRBuilder = NULL;
|
mBfIRBuilder = NULL;
|
||||||
mWantsIRIgnoreWrites = false;
|
mWantsIRIgnoreWrites = false;
|
||||||
|
|
|
@ -1476,6 +1476,7 @@ public:
|
||||||
bool mAddedToCount;
|
bool mAddedToCount;
|
||||||
bool mHasForceLinkMarker;
|
bool mHasForceLinkMarker;
|
||||||
bool mIsReified;
|
bool mIsReified;
|
||||||
|
bool mGeneratesCode;
|
||||||
bool mReifyQueued;
|
bool mReifyQueued;
|
||||||
bool mWantsIRIgnoreWrites;
|
bool mWantsIRIgnoreWrites;
|
||||||
bool mHasGenericMethods;
|
bool mHasGenericMethods;
|
||||||
|
@ -1947,6 +1948,7 @@ public:
|
||||||
void Init(bool isFullRebuild = true);
|
void Init(bool isFullRebuild = true);
|
||||||
bool WantsFinishModule();
|
bool WantsFinishModule();
|
||||||
void FinishInit();
|
void FinishInit();
|
||||||
|
void CalcGeneratesCode();
|
||||||
void ReifyModule();
|
void ReifyModule();
|
||||||
void UnreifyModule();
|
void UnreifyModule();
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
|
|
|
@ -1038,6 +1038,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
|
||||||
{
|
{
|
||||||
BfLogSysM("Setting reified type %p in module %p in PopulateType on module awaiting finish\n", resolvedTypeRef, typeModule);
|
BfLogSysM("Setting reified type %p in module %p in PopulateType on module awaiting finish\n", resolvedTypeRef, typeModule);
|
||||||
typeModule->mIsReified = true;
|
typeModule->mIsReified = true;
|
||||||
|
typeModule->CalcGeneratesCode();
|
||||||
typeModule->mWantsIRIgnoreWrites = false;
|
typeModule->mWantsIRIgnoreWrites = false;
|
||||||
for (auto ownedTypes : typeModule->mOwnedTypeInstances)
|
for (auto ownedTypes : typeModule->mOwnedTypeInstances)
|
||||||
{
|
{
|
||||||
|
@ -6049,7 +6050,15 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance)
|
||||||
methodProcessRequest->mFromModule = this;
|
methodProcessRequest->mFromModule = this;
|
||||||
|
|
||||||
if ((!mCompiler->mIsResolveOnly) && (methodInstance->mIsReified))
|
if ((!mCompiler->mIsResolveOnly) && (methodInstance->mIsReified))
|
||||||
|
{
|
||||||
|
if ((!mIsModuleMutable) && (!mIsScratchModule))
|
||||||
|
{
|
||||||
|
BF_ASSERT(!mGeneratesCode);
|
||||||
|
StartNewRevision(BfModule::RebuildKind_None);
|
||||||
|
}
|
||||||
|
|
||||||
BF_ASSERT(mIsModuleMutable || mReifyQueued);
|
BF_ASSERT(mIsModuleMutable || mReifyQueued);
|
||||||
|
}
|
||||||
|
|
||||||
BF_ASSERT(mBfIRBuilder != NULL);
|
BF_ASSERT(mBfIRBuilder != NULL);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue