mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Added ability to reference static methods before type data population
This commit is contained in:
parent
a179dd7e5c
commit
086b5f2e7d
3 changed files with 111 additions and 75 deletions
|
@ -3557,7 +3557,8 @@ BfModuleOptions BfModule::GetModuleOptions()
|
|||
if (headModule->mOwnedTypeInstances.size() > 0)
|
||||
{
|
||||
auto typeInst = headModule->mOwnedTypeInstances[0];
|
||||
PopulateType(typeInst);
|
||||
if (typeInst->mTypeOptionsIdx == -2)
|
||||
PopulateType(typeInst);
|
||||
if (typeInst->mTypeOptionsIdx != -1)
|
||||
{
|
||||
auto typeOptions = mSystem->GetTypeOptions(typeInst->mTypeOptionsIdx);
|
||||
|
@ -9649,8 +9650,8 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan
|
|||
{
|
||||
if (!typeInstance->mResolvingVarField)
|
||||
{
|
||||
if (typeInstance->IsIncomplete())
|
||||
PopulateType(typeInstance, BfPopulateType_DataAndMethods);
|
||||
if (typeInstance->mDefineState < BfTypeDefineState_HasInterfaces)
|
||||
PopulateType(typeInstance, BfPopulateType_AllowStaticMethods);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -9677,10 +9678,12 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan
|
|||
if ((typeInstance->mGenericTypeInfo != NULL) && (typeInstance->mGenericTypeInfo->mFinishedGenericParams) && (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NotSet))
|
||||
{
|
||||
methodGroup.mOnDemandKind = BfMethodOnDemandKind_NoDecl_AwaitingReference;
|
||||
declModule->mOnDemandMethodCount++;
|
||||
if (!declModule->mIsScratchModule)
|
||||
declModule->mOnDemandMethodCount++;
|
||||
}
|
||||
|
||||
BF_ASSERT((methodGroup.mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) || (typeInstance->mTypeFailed));
|
||||
BF_ASSERT((methodGroup.mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) ||
|
||||
(typeInstance->mTypeFailed) || (typeInstance->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted));
|
||||
if ((methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl))
|
||||
methodGroup.mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingDecl;
|
||||
|
||||
|
@ -12399,7 +12402,13 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
|||
{
|
||||
// For autocomplete, we still may not actually generate methods. This shouldn't matter, and on-demand works differently
|
||||
// for resolve-only because we don't differentiate between reified/unreified there
|
||||
PopulateType(typeInst, BfPopulateType_Full);
|
||||
if ((methodDef->mIsStatic) /*&& (mIsConstModule)*/)
|
||||
{
|
||||
if (typeInst->mDefineState < BfTypeDefineState_HasInterfaces)
|
||||
PopulateType(typeInst, BfPopulateType_AllowStaticMethods);
|
||||
}
|
||||
else
|
||||
PopulateType(typeInst, BfPopulateType_Full);
|
||||
}
|
||||
|
||||
bool tryModuleMethodLookup = false;
|
||||
|
@ -12661,8 +12670,11 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
|||
|
||||
if (methodInstGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet)
|
||||
{
|
||||
BfLogSysM("Forcing BfMethodOnDemandKind_NotSet to BfMethodOnDemandKind_AlwaysInclude for Method:%s in Type:%p\n", methodDef->mName.c_str(), typeInst);
|
||||
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude;
|
||||
if (typeInst->mDefineState > BfTypeDefineState_DefinedAndMethodsSlotted)
|
||||
{
|
||||
BfLogSysM("Forcing BfMethodOnDemandKind_NotSet to BfMethodOnDemandKind_AlwaysInclude for Method:%s in Type:%p\n", methodDef->mName.c_str(), typeInst);
|
||||
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude;
|
||||
}
|
||||
}
|
||||
|
||||
BfIRFunction prevIRFunc;
|
||||
|
@ -12965,6 +12977,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
|||
methodInstance = new BfMethodInstance();
|
||||
methodInstGroup->mDefault = methodInstance;
|
||||
|
||||
BF_ASSERT(typeInst->mDefineState > BfTypeDefineState_Declared);
|
||||
|
||||
BfLogSysM("Created Default MethodInst: %p TypeInst: %p Group: %p\n", methodInstance, typeInst, methodInstGroup);
|
||||
}
|
||||
else
|
||||
|
@ -17787,8 +17801,6 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
|||
if ((methodInstance->mMethodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_AlwaysInclude) &&
|
||||
(methodInstance->mMethodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_Referenced))
|
||||
{
|
||||
methodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Referenced;
|
||||
|
||||
auto owningModule = methodInstance->GetOwner()->mModule;
|
||||
|
||||
if (owningModule->mIsScratchModule)
|
||||
|
@ -17801,6 +17813,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
|||
if (owningModule->mOnDemandMethodCount > 0)
|
||||
owningModule->mOnDemandMethodCount--;
|
||||
}
|
||||
|
||||
methodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Referenced;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17845,9 +17859,16 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
|||
if ((methodDeclaration == NULL) && (mCurMethodState == NULL))
|
||||
UseDefaultSrcPos();
|
||||
|
||||
// We may not actually be populated in relatively rare autocompelte cases
|
||||
PopulateType(mCurTypeInstance, BfPopulateType_DataAndMethods);
|
||||
mBfIRBuilder->PopulateType(mCurTypeInstance, BfIRPopulateType_Full);
|
||||
if ((mIsConstModule) && (methodDef->mIsStatic))
|
||||
{
|
||||
PopulateType(mCurTypeInstance, BfPopulateType_AllowStaticMethods);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We may not actually be populated in relatively rare autocompelte cases
|
||||
PopulateType(mCurTypeInstance, BfPopulateType_DataAndMethods);
|
||||
mBfIRBuilder->PopulateType(mCurTypeInstance, BfIRPopulateType_Full);
|
||||
}
|
||||
|
||||
BfAstNode* nameNode = NULL;
|
||||
if (methodDeclaration != NULL)
|
||||
|
@ -21005,11 +21026,11 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
|||
|
||||
bool ignoreWrites = mBfIRBuilder->mIgnoreWrites;
|
||||
|
||||
if ((!isTemporaryFunc) && (mCurTypeInstance->mDefineState < BfTypeDefineState_Defined))
|
||||
{
|
||||
BF_ASSERT(mContext->mResolvingVarField);
|
||||
isTemporaryFunc = true;
|
||||
}
|
||||
// if ((!isTemporaryFunc) && (mCurTypeInstance->mDefineState < BfTypeDefineState_Defined))
|
||||
// {
|
||||
// BF_ASSERT(mContext->mResolvingVarField);
|
||||
// isTemporaryFunc = true;
|
||||
// }
|
||||
|
||||
if ((mAwaitingInitFinish) && (!mBfIRBuilder->mIgnoreWrites))
|
||||
FinishInit();
|
||||
|
|
|
@ -41,9 +41,11 @@ enum BfPopulateType
|
|||
BfPopulateType_Declaration,
|
||||
BfPopulateType_BaseType,
|
||||
BfPopulateType_Interfaces,
|
||||
BfPopulateType_AllowStaticMethods,
|
||||
BfPopulateType_Data,
|
||||
BfPopulateType_DataAndMethods,
|
||||
BfPopulateType_Full = BfPopulateType_DataAndMethods,
|
||||
|
||||
BfPopulateType_Full_Force
|
||||
};
|
||||
|
||||
|
|
|
@ -589,13 +589,6 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType)
|
|||
BfSavedTypeData* savedTypeData;
|
||||
if (mContext->mSavedTypeDataMap.Remove(typeName, &savedTypeData))
|
||||
{
|
||||
// if (resolvedTypeRef->mTypeId != -1)
|
||||
// {
|
||||
// // If we have an ID and it as the last one assigned the roll back the ID counter
|
||||
// if (resolvedTypeRef->mTypeId == mCompiler->mCurTypeId - 1)
|
||||
// mCompiler->mCurTypeId--;
|
||||
// }
|
||||
|
||||
mContext->mSavedTypeData[savedTypeData->mTypeId] = NULL;
|
||||
|
||||
resolvedTypeRef->mTypeId = savedTypeData->mTypeId;
|
||||
|
@ -608,8 +601,8 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType)
|
|||
BfLogSysM("Using mSavedTypeData HotTypeData %p for %p\n", savedTypeData->mHotTypeData, resolvedTypeRef);
|
||||
typeInst->mHotTypeData = savedTypeData->mHotTypeData;
|
||||
savedTypeData->mHotTypeData = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete savedTypeData;
|
||||
mContext->mTypes[resolvedTypeRef->mTypeId] = resolvedTypeRef;
|
||||
}
|
||||
|
@ -1965,6 +1958,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
if ((populateType >= BfPopulateType_Identity) && (populateType <= BfPopulateType_IdentityNoRemapAlias))
|
||||
return;
|
||||
|
||||
if ((populateType <= BfPopulateType_AllowStaticMethods) && (typeInstance->mDefineState >= BfTypeDefineState_HasInterfaces))
|
||||
return;
|
||||
|
||||
if (!resolvedTypeRef->IsValueType())
|
||||
{
|
||||
resolvedTypeRef->mSize = typeInstance->mAlign = mSystem->mPtrSize;
|
||||
|
@ -2731,6 +2727,44 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
}
|
||||
}
|
||||
|
||||
if ((mCompiler->mOptions.mAllowHotSwapping) &&
|
||||
(typeInstance->mDefineState < BfTypeDefineState_HasInterfaces) &&
|
||||
(typeInstance->mDefineState != BfTypeDefineState_ResolvingBaseType))
|
||||
{
|
||||
if (typeInstance->mHotTypeData == NULL)
|
||||
{
|
||||
typeInstance->mHotTypeData = new BfHotTypeData();
|
||||
BfLogSysM("Created HotTypeData %p created for type %p in DoPopulateType\n", typeInstance->mHotTypeData, typeInstance);
|
||||
}
|
||||
|
||||
// Clear any unused versions (if we have errors, etc)
|
||||
if (mCompiler->mHotState != NULL)
|
||||
typeInstance->mHotTypeData->ClearVersionsAfter(mCompiler->mHotState->mCommittedHotCompileIdx);
|
||||
else
|
||||
BF_ASSERT(typeInstance->mHotTypeData->mTypeVersions.IsEmpty()); // We should have created a new HotTypeData when rebuilding the type
|
||||
|
||||
BfHotTypeVersion* hotTypeVersion = new BfHotTypeVersion();
|
||||
hotTypeVersion->mTypeId = typeInstance->mTypeId;
|
||||
if (typeInstance->mBaseType != NULL)
|
||||
{
|
||||
if (typeInstance->mBaseType->mHotTypeData != NULL)
|
||||
hotTypeVersion->mBaseType = typeInstance->mBaseType->mHotTypeData->GetLatestVersion();
|
||||
else
|
||||
{
|
||||
AssertErrorState();
|
||||
}
|
||||
}
|
||||
hotTypeVersion->mDeclHotCompileIdx = mCompiler->mOptions.mHotCompileIdx;
|
||||
if (mCompiler->IsHotCompile())
|
||||
hotTypeVersion->mCommittedHotCompileIdx = -1;
|
||||
else
|
||||
hotTypeVersion->mCommittedHotCompileIdx = 0;
|
||||
hotTypeVersion->mRefCount++;
|
||||
typeInstance->mHotTypeData->mTypeVersions.Add(hotTypeVersion);
|
||||
|
||||
BfLogSysM("BfHotTypeVersion %p created for type %p\n", hotTypeVersion, typeInstance);
|
||||
}
|
||||
|
||||
BF_ASSERT(!typeInstance->mNeedsMethodProcessing);
|
||||
typeInstance->mDefineState = BfTypeDefineState_HasInterfaces;
|
||||
|
||||
|
@ -2740,13 +2774,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
ValidateGenericConstraints(validateEntry.mTypeRef, validateEntry.mGenericType, false);
|
||||
}
|
||||
|
||||
if (populateType <= BfPopulateType_Interfaces)
|
||||
return;
|
||||
|
||||
prevSkipTypeProtectionChecks.Restore();
|
||||
typeInstance->mInstSize = std::max(0, typeInstance->mInstSize);
|
||||
typeInstance->mInstAlign = std::max(0, typeInstance->mInstAlign);
|
||||
|
||||
if (!typeInstance->IsBoxed())
|
||||
{
|
||||
if ((typeInstance->mCustomAttributes == NULL) && (typeDef->mTypeDeclaration != NULL) && (typeDef->mTypeDeclaration->mAttributes != NULL))
|
||||
|
@ -2790,7 +2817,14 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
}
|
||||
|
||||
if (typeInstance->mTypeOptionsIdx == -2)
|
||||
SetTypeOptions(typeInstance);
|
||||
SetTypeOptions(typeInstance);
|
||||
|
||||
if (populateType <= BfPopulateType_AllowStaticMethods)
|
||||
return;
|
||||
|
||||
prevSkipTypeProtectionChecks.Restore();
|
||||
typeInstance->mInstSize = std::max(0, typeInstance->mInstSize);
|
||||
typeInstance->mInstAlign = std::max(0, typeInstance->mInstAlign);
|
||||
|
||||
ProcessCustomAttributeData();
|
||||
bool isPacked = false;
|
||||
|
@ -3565,37 +3599,8 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
}
|
||||
|
||||
if ((mCompiler->mOptions.mAllowHotSwapping) && (typeInstance->mDefineState < BfTypeDefineState_Defined))
|
||||
{
|
||||
if (typeInstance->mHotTypeData == NULL)
|
||||
{
|
||||
typeInstance->mHotTypeData = new BfHotTypeData();
|
||||
BfLogSysM("Created HotTypeData %p created for type %p in DoPopulateType\n", typeInstance->mHotTypeData, typeInstance);
|
||||
}
|
||||
|
||||
// Clear any unused versions (if we have errors, etc)
|
||||
if (mCompiler->mHotState != NULL)
|
||||
typeInstance->mHotTypeData->ClearVersionsAfter(mCompiler->mHotState->mCommittedHotCompileIdx);
|
||||
else
|
||||
BF_ASSERT(typeInstance->mHotTypeData->mTypeVersions.IsEmpty()); // We should have created a new HotTypeData when rebuilding the type
|
||||
|
||||
BfHotTypeVersion* hotTypeVersion = new BfHotTypeVersion();
|
||||
hotTypeVersion->mTypeId = typeInstance->mTypeId;
|
||||
if (typeInstance->mBaseType != NULL)
|
||||
{
|
||||
if (typeInstance->mBaseType->mHotTypeData != NULL)
|
||||
hotTypeVersion->mBaseType = typeInstance->mBaseType->mHotTypeData->GetLatestVersion();
|
||||
else
|
||||
{
|
||||
AssertErrorState();
|
||||
}
|
||||
}
|
||||
hotTypeVersion->mDeclHotCompileIdx = mCompiler->mOptions.mHotCompileIdx;
|
||||
if (mCompiler->IsHotCompile())
|
||||
hotTypeVersion->mCommittedHotCompileIdx = -1;
|
||||
else
|
||||
hotTypeVersion->mCommittedHotCompileIdx = 0;
|
||||
hotTypeVersion->mRefCount++;
|
||||
typeInstance->mHotTypeData->mTypeVersions.Add(hotTypeVersion);
|
||||
{
|
||||
auto hotTypeVersion = typeInstance->mHotTypeData->mTypeVersions.back();
|
||||
|
||||
if ((typeInstance->mBaseType != NULL) && (typeInstance->mBaseType->mHotTypeData != NULL))
|
||||
{
|
||||
|
@ -3623,8 +3628,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
|
||||
for (auto member : hotTypeVersion->mMembers)
|
||||
member->mRefCount++;
|
||||
|
||||
BfLogSysM("BfHotTypeVersion %p created for type %p\n", hotTypeVersion, typeInstance);
|
||||
}
|
||||
|
||||
typeInstance->mDefineState = BfTypeDefineState_Defined;
|
||||
|
@ -4047,8 +4050,9 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
|
|||
{
|
||||
auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx];
|
||||
|
||||
// Thsi MAY be generated already
|
||||
// This should still be set to the default value
|
||||
BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude));
|
||||
//BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude));
|
||||
}
|
||||
|
||||
|
||||
|
@ -4248,7 +4252,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
|
|||
// Generate all methods. Pass 1
|
||||
for (auto methodDef : typeDef->mMethods)
|
||||
{
|
||||
auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx];
|
||||
auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx];
|
||||
|
||||
if (typeOptions != NULL)
|
||||
{
|
||||
|
@ -4265,6 +4269,12 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
|
|||
|
||||
if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude)
|
||||
continue;
|
||||
if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_InWorkList)
|
||||
continue;
|
||||
if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference)
|
||||
continue;
|
||||
if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Referenced)
|
||||
continue;
|
||||
|
||||
if (isFailedType)
|
||||
{
|
||||
|
@ -4273,7 +4283,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
|
|||
}
|
||||
|
||||
// This should still be set to the default value
|
||||
BF_ASSERT(methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet);
|
||||
BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl));
|
||||
|
||||
if ((isBoxed) && (!methodDef->mIsVirtual))
|
||||
{
|
||||
|
@ -5102,11 +5112,14 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance)
|
|||
|
||||
BF_ASSERT(methodInstance->mMethodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_Referenced);
|
||||
if (!mIsScratchModule)
|
||||
{
|
||||
{
|
||||
auto onDemandModule = owningModule;
|
||||
if (owningModule->mParentModule != NULL)
|
||||
BF_ASSERT(owningModule->mParentModule->mOnDemandMethodCount > 0);
|
||||
else
|
||||
BF_ASSERT(owningModule->mOnDemandMethodCount > 0);
|
||||
onDemandModule = owningModule->mParentModule;
|
||||
|
||||
if (methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet)
|
||||
owningModule->mOnDemandMethodCount++;
|
||||
BF_ASSERT(onDemandModule->mOnDemandMethodCount > 0);
|
||||
}
|
||||
methodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_InWorkList;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue