1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Removed mDtorDef, fixed MethodSpecializationRequest on emitted method

This commit is contained in:
Brian Fiete 2021-01-11 10:52:44 -08:00
parent 71d4dd0e90
commit bc8758bbac
7 changed files with 71 additions and 51 deletions

View file

@ -446,7 +446,20 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx);
auto typeInst = methodSpecializationRequest.mType->ToTypeInstance();
module->GetMethodInstance(methodSpecializationRequest.mType->ToTypeInstance(), methodSpecializationRequest.mMethodDef, methodSpecializationRequest.mMethodGenericArguments,
BfMethodDef* methodDef = NULL;
if (methodSpecializationRequest.mForeignType != NULL)
{
module->PopulateType(methodSpecializationRequest.mForeignType);
methodDef = methodSpecializationRequest.mForeignType->mTypeDef->mMethods[methodSpecializationRequest.mMethodIdx];
}
else
{
module->PopulateType(typeInst);
methodDef = typeInst->mTypeDef->mMethods[methodSpecializationRequest.mMethodIdx];
}
module->GetMethodInstance(typeInst, methodDef, methodSpecializationRequest.mMethodGenericArguments,
(BfGetMethodInstanceFlags)(methodSpecializationRequest.mFlags | BfGetMethodInstanceFlag_ResultNotUsed), methodSpecializationRequest.mForeignType);
didWork = true;
}
@ -2534,11 +2547,6 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
auto methodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum];
if (methodDef->mName == "set__Capacity")
{
NOP;
}
auto targetContext = methodRef.mTypeInstance->mContext;
BfMethodSpecializationRequest* specializationRequest = targetContext->mMethodSpecializationWorkList.Alloc();
if (specializedMethodRefInfo.mHasReifiedRef)
@ -2546,7 +2554,8 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
else
specializationRequest->mFromModule = mUnreifiedModule;
specializationRequest->mFromModuleRevision = typeInst->mModule->mRevision;
specializationRequest->mMethodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum];
specializationRequest->mMethodIdx = methodRef.mMethodNum;
//specializationRequest->mMethodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum];
specializationRequest->mMethodGenericArguments = methodRef.mMethodGenericArguments;
specializationRequest->mType = methodRef.mTypeInstance;

View file

@ -44,7 +44,7 @@ public:
class BfMethodSpecializationRequest : public BfWorkListEntry
{
public:
BfMethodDef* mMethodDef;
int32 mMethodIdx;
BfTypeVector mMethodGenericArguments;
BfGetMethodInstanceFlags mFlags;
BfTypeInstance* mForeignType;
@ -52,10 +52,21 @@ public:
public:
BfMethodSpecializationRequest()
{
mMethodDef = NULL;
mMethodIdx = -1;
mFlags = BfGetMethodInstanceFlag_None;
mForeignType = NULL;
}
void Init(BfTypeInstance* typeInstance, BfTypeInstance* foreignType, BfMethodDef* methodDef)
{
mType = typeInstance;
mMethodIdx = methodDef->mIdx;
mForeignType = foreignType;
if (foreignType != NULL)
BF_ASSERT(foreignType->mTypeDef->mMethods[mMethodIdx] == methodDef);
else
BF_ASSERT(typeInstance->mTypeDef->mMethods[mMethodIdx] == methodDef);
}
};
class BfMethodProcessRequest : public BfWorkListEntry

View file

@ -521,7 +521,6 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
methodDef->mName = "__BfStaticDtor";
else
{
mCurTypeDef->mDtorDef = methodDef;
methodDef->mName = "~this";
if (!methodDef->mIsVirtual)
{
@ -1229,8 +1228,6 @@ BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType
methodDef->mName = "~this";
methodDef->mIsVirtual = true;
methodDef->mIsOverride = true;
BF_ASSERT(typeDef->mDtorDef == NULL);
typeDef->mDtorDef = methodDef;
}
}
else
@ -1255,8 +1252,6 @@ BfMethodDef* BfDefBuilder::AddDtor(BfTypeDef* typeDef)
methodDef->mMethodType = BfMethodType_Dtor;
methodDef->mIsVirtual = true;
methodDef->mIsOverride = true;
BF_ASSERT(typeDef->mDtorDef == NULL);
typeDef->mDtorDef = methodDef;
return methodDef;
}
@ -2174,7 +2169,6 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if ((needsDtor) && (dtor == NULL))
{
auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, false, "", mIsComptime);
BF_ASSERT(mCurTypeDef->mDtorDef == methodDef);
}
if ((needsStaticDtor) && (staticDtor == NULL))

View file

@ -1910,9 +1910,16 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
bool hadDtorCall = false;
while (checkBaseType != NULL)
{
if ((checkBaseType->mTypeDef->mDtorDef != NULL) /*&& (checkBaseType != mContext->mBfObjectType)*/)
checkBaseType->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkBaseType->mTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef != NULL)
{
auto dtorMethodInstance = GetMethodInstance(checkBaseType, checkBaseType->mTypeDef->mDtorDef, BfTypeVector());
auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector());
if (dtorMethodInstance)
{
bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
@ -12552,11 +12559,11 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
BfMethodSpecializationRequest* specializationRequest = mContext->mMethodSpecializationWorkList.Alloc();
specializationRequest->mFromModule = typeInst->mModule;
specializationRequest->mFromModuleRevision = typeInst->mModule->mRevision;
specializationRequest->mMethodDef = methodDef;
specializationRequest->Init(typeInst, foreignType, methodDef);
//specializationRequest->mMethodDef = methodDef;
specializationRequest->mMethodGenericArguments = methodGenericArguments;
specializationRequest->mType = typeInst;
specializationRequest->mFlags = flags;
specializationRequest->mForeignType = foreignType;
}
}
@ -15524,9 +15531,16 @@ void BfModule::EmitDtorBody()
UpdateSrcPos(typeDef->mTypeDeclaration->mNameNode);
}
if (checkBaseType->mTypeDef->mDtorDef != NULL)
checkBaseType->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkBaseType->mTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef != NULL)
{
auto dtorMethodInstance = GetMethodInstance(checkBaseType, checkBaseType->mTypeDef->mDtorDef, BfTypeVector());
auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector());
if (IsSkippingExtraResolveChecks())
{
// Nothing

View file

@ -3933,9 +3933,17 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt)
while (checkTypeInst != NULL)
{
auto checkTypeDef = checkTypeInst->mTypeDef;
if (checkTypeDef->mDtorDef != NULL)
checkTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef)
{
if (!CheckProtection(checkTypeDef->mDtorDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate))
if (!CheckProtection(dtorMethodDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate))
{
auto error = Fail(StrFormat("'%s.~this()' is inaccessible due to its protection level", TypeToString(checkTypeInst).c_str()), deleteStmt->mExpression); // CS0122
}

View file

@ -2670,7 +2670,6 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
nextMethodDef->mParams.Clear();
nextMethodDef->mGenericParams.Clear();
}
// Leave typeDef->mDtorDef
}
else
{
@ -2686,7 +2685,6 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
for (auto method : typeDef->mMethods)
method->mDeclaringType = typeDef;
nextTypeDef->mMethods.Clear();
typeDef->mDtorDef = nextTypeDef->mDtorDef;
}
for (auto fieldDef : typeDef->mFields)
@ -2971,17 +2969,6 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co
}
typeDef->mPropertySet.Clear();
if (partialTypeDef->mDtorDef != NULL)
{
if (typeDef->mDtorDef != NULL)
{
//passInstance->Fail("Destructor already defined", partialTypeDef->mDtorDef->mMethodDeclaration->mNameNode);
//TODO:
}
else
typeDef->mDtorDef = partialTypeDef->mDtorDef;
}
BF_ASSERT(partialTypeDef->mPartials.empty());
partialTypeDef->mPartialIdx = (int)typeDef->mPartials.size();
typeDef->mPartials.push_back(partialTypeDef);
@ -3101,7 +3088,6 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef)
if ((allHasMethods[0][0].mDtor == 0) && (allHasMethods[1][0].mDtor > 1))
{
nextRevision->mDtorDef = NULL;
auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Dtor, BfProtection_Public, false, "");
methodDef->mDeclaringType = primaryDef;
}

View file

@ -960,7 +960,6 @@ public:
HashSet<BfMemberSetEntry> mFieldSet;
HashSet<BfMemberSetEntry> mPropertySet;
Array<BfOperatorDef*> mOperators;
BfMethodDef* mDtorDef;
Array<BfGenericParamDef*> mGenericParamDefs;
Array<BfExternalConstraintDef> mExternalConstraints;
Array<BfTypeReference*> mBaseTypes;
@ -1041,7 +1040,6 @@ public:
mNestDepth = 0;
mOuterType = NULL;
mTypeDeclaration = NULL;
mDtorDef = NULL;
mNextRevision = NULL;
mProtection = BfProtection_Public;
}