diff --git a/IDEHelper/Compiler/BfContext.cpp b/IDEHelper/Compiler/BfContext.cpp index ae4fc0c2..fc64eee1 100644 --- a/IDEHelper/Compiler/BfContext.cpp +++ b/IDEHelper/Compiler/BfContext.cpp @@ -444,9 +444,22 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) auto module = workItemRef->mFromModule; 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; diff --git a/IDEHelper/Compiler/BfContext.h b/IDEHelper/Compiler/BfContext.h index cc6e6c86..cdcb1c97 100644 --- a/IDEHelper/Compiler/BfContext.h +++ b/IDEHelper/Compiler/BfContext.h @@ -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 diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index 5be198c6..346e7e6a 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -520,8 +520,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio if (methodDef->mIsStatic) methodDef->mName = "__BfStaticDtor"; else - { - mCurTypeDef->mDtorDef = methodDef; + { methodDef->mName = "~this"; if (!methodDef->mIsVirtual) { @@ -1228,9 +1227,7 @@ BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType { methodDef->mName = "~this"; methodDef->mIsVirtual = true; - methodDef->mIsOverride = true; - BF_ASSERT(typeDef->mDtorDef == NULL); - typeDef->mDtorDef = methodDef; + methodDef->mIsOverride = true; } } else @@ -1254,9 +1251,7 @@ BfMethodDef* BfDefBuilder::AddDtor(BfTypeDef* typeDef) methodDef->mProtection = BfProtection_Public; methodDef->mMethodType = BfMethodType_Dtor; methodDef->mIsVirtual = true; - methodDef->mIsOverride = true; - BF_ASSERT(typeDef->mDtorDef == NULL); - typeDef->mDtorDef = methodDef; + methodDef->mIsOverride = true; 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)) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index cf2de387..23ae843b 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -1909,10 +1909,17 @@ 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; + specializationRequest->mFlags = flags; } } @@ -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 diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index acdb1641..b5ddaef9 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -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 } diff --git a/IDEHelper/Compiler/BfSystem.cpp b/IDEHelper/Compiler/BfSystem.cpp index ffc5ae39..04b7a6b4 100644 --- a/IDEHelper/Compiler/BfSystem.cpp +++ b/IDEHelper/Compiler/BfSystem.cpp @@ -2669,8 +2669,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) methodDef->mCodeChanged = true; nextMethodDef->mParams.Clear(); nextMethodDef->mGenericParams.Clear(); - } - // Leave typeDef->mDtorDef + } } else { @@ -2685,8 +2684,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) if (setDeclaringType) for (auto method : typeDef->mMethods) method->mDeclaringType = typeDef; - nextTypeDef->mMethods.Clear(); - typeDef->mDtorDef = nextTypeDef->mDtorDef; + nextTypeDef->mMethods.Clear(); } for (auto fieldDef : typeDef->mFields) @@ -2970,18 +2968,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co typeDef->mProperties.push_back(newProp); } 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); @@ -3100,8 +3087,7 @@ 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; } diff --git a/IDEHelper/Compiler/BfSystem.h b/IDEHelper/Compiler/BfSystem.h index dec635d2..9f88840f 100644 --- a/IDEHelper/Compiler/BfSystem.h +++ b/IDEHelper/Compiler/BfSystem.h @@ -959,8 +959,7 @@ public: HashSet mMethodSet; HashSet mFieldSet; HashSet mPropertySet; - Array mOperators; - BfMethodDef* mDtorDef; + Array mOperators; Array mGenericParamDefs; Array mExternalConstraints; Array mBaseTypes; @@ -1040,8 +1039,7 @@ public: mDupDetectedRevision = -1; mNestDepth = 0; mOuterType = NULL; - mTypeDeclaration = NULL; - mDtorDef = NULL; + mTypeDeclaration = NULL; mNextRevision = NULL; mProtection = BfProtection_Public; }