diff --git a/IDEHelper/Compiler/BfContext.cpp b/IDEHelper/Compiler/BfContext.cpp index 6ffbbef9..68f3fdf3 100644 --- a/IDEHelper/Compiler/BfContext.cpp +++ b/IDEHelper/Compiler/BfContext.cpp @@ -616,6 +616,9 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) auto module = workItem.mFromModule; auto methodInstance = workItem.mMethodInstance; + BF_ASSERT(module->mIsModuleMutable); + module->PrepareForIRWriting(methodInstance->GetOwner()); + workIdx = mInlineMethodWorkList.RemoveAt(workIdx); BfLogSysM("Module %p inlining method %p into func:%p\n", module, methodInstance, workItem.mFunc); @@ -647,7 +650,8 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) module->mBfIRBuilder->Func_SetLinkage(workItem.mFunc, BfIRLinkageType_Internal); BF_ASSERT(module->mContext == this); - BF_ASSERT(module->mIsModuleMutable); + BF_ASSERT(module->mIsModuleMutable); + if (module->WantsFinishModule()) { BfLogSysM("Module finished: %s (from inlining)\n", module->mModuleName.c_str()); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index ff825dc0..5f104fc1 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -4412,7 +4412,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy if ((methodInstance != NULL) && (!methodInstance->mMethodDef->mIsAbstract)) { BF_ASSERT(implTypeInst->IsTypeMemberAccessible(methodInstance->mMethodDef->mDeclaringType, mProject)); - auto moduleMethodInst = GetMethodInstanceAtIdx(methodInstance->mMethodInstanceGroup->mOwner, methodInstance->mMethodInstanceGroup->mMethodIdx); + auto moduleMethodInst = GetMethodInstanceAtIdx(methodInstance->mMethodInstanceGroup->mOwner, methodInstance->mMethodInstanceGroup->mMethodIdx, NULL, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); vValue = funcPtr; } @@ -5023,7 +5023,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if ((methodInstance != NULL) && (!methodInstance->mMethodDef->mIsAbstract)) { BF_ASSERT(typeInstance->IsTypeMemberAccessible(methodInstance->mMethodDef->mDeclaringType, mProject)); - moduleMethodInst = GetMethodInstanceAtIdx(methodInstance->mMethodInstanceGroup->mOwner, methodInstance->mMethodInstanceGroup->mMethodIdx); + moduleMethodInst = GetMethodInstanceAtIdx(methodInstance->mMethodInstanceGroup->mOwner, methodInstance->mMethodInstanceGroup->mMethodIdx, NULL, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); vValue = funcPtr; } @@ -5118,7 +5118,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BF_ASSERT(methodInstance->mIsReified); // This doesn't work because we may have FOREIGN methods from implicit interface methods //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); - auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance); + auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); pushValue = funcPtr; } @@ -5173,7 +5173,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BF_ASSERT(methodInstance->mIsReified); // This doesn't work because we may have FOREIGN methods from implicit interface methods //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); - auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance); + auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); int idx = checkIFace.mStartVirtualIdx + ifaceMethodInstance->mVirtualTableIdx; @@ -5901,7 +5901,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin (!methodDef->mIsAbstract) && (methodDef->mGenericParams.size() == 0)) { - moduleMethodInstance = GetMethodInstanceAtIdx(typeInstance, methodIdx); + moduleMethodInstance = GetMethodInstanceAtIdx(typeInstance, methodIdx, NULL, BfGetMethodInstanceFlag_NoInline); if (moduleMethodInstance.mFunc) funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType); } @@ -9135,7 +9135,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr return func; } -BfModuleMethodInstance BfModule::GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName) +BfModuleMethodInstance BfModule::GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName, BfGetMethodInstanceFlags flags) { if (assertName != NULL) { @@ -9159,7 +9159,7 @@ BfModuleMethodInstance BfModule::GetMethodInstanceAtIdx(BfTypeInstance* typeInst return BfModuleMethodInstance(methodInstance, func); } - return GetMethodInstance(typeInstance, typeInstance->mTypeDef->mMethods[methodIdx], BfTypeVector()); + return GetMethodInstance(typeInstance, typeInstance->mTypeDef->mMethods[methodIdx], BfTypeVector(), flags); } BfModuleMethodInstance BfModule::GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount, bool checkBase) @@ -11197,7 +11197,7 @@ BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstanc mFuncReferences[methodRef] = func; BfLogSysM("Adding func reference. Module:%p MethodInst:%p NewLLVMFunc:%d OldLLVMFunc:%d\n", this, methodInstance, func.mId, methodInstance->mIRFunction.mId); - if ((isInlined) && (!mIsScratchModule)) + if ((isInlined) && (!mIsScratchModule) && ((flags & BfGetMethodInstanceFlag_NoInline) == 0)) { // We can't just add a dependency to mCurTypeInstance because we may have nested inlined functions, and // mCurTypeInstance will just reflect the owner of the method currently being inlined, not the top-level @@ -11210,13 +11210,12 @@ BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstanc if ((!mCompiler->mIsResolveOnly) && (mIsReified) && (!methodInstance->mIsUnspecialized)) { mIncompleteMethodCount++; - BfInlineMethodRequest* inlineMethodRequest = mContext->mInlineMethodWorkList.Alloc(); inlineMethodRequest->mType = methodInstance->GetOwner(); inlineMethodRequest->mFromModule = this; inlineMethodRequest->mFunc = func; inlineMethodRequest->mFromModuleRevision = mRevision; - inlineMethodRequest->mMethodInstance = methodInstance; + inlineMethodRequest->mMethodInstance = methodInstance; BF_ASSERT(mIsModuleMutable); BfLogSysM("mInlineMethodWorkList %p for method %p in module %p in ReferenceExternalMethodInstance\n", inlineMethodRequest, methodInstance, this); @@ -11838,7 +11837,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM inlineMethodRequest->mFromModule = this; inlineMethodRequest->mFunc = methodInstance->mIRFunction; inlineMethodRequest->mFromModuleRevision = mRevision; - inlineMethodRequest->mMethodInstance = methodInstance; + inlineMethodRequest->mMethodInstance = methodInstance; BfLogSysM("mInlineMethodWorkList %p for method %p in module %p in GetMethodInstance\n", inlineMethodRequest, methodInstance, this); BF_ASSERT(mIsModuleMutable); diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 90dee76b..e42620cb 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1772,7 +1772,7 @@ public: BfMethodInstance* GetUnspecializedMethodInstance(BfMethodInstance* methodInstance); // Unspecialized owner type and unspecialized method type int GetGenericParamAndReturnCount(BfMethodInstance* methodInstance); BfModule* GetSpecializedMethodModule(const SizedArrayImpl& projectList); - BfModuleMethodInstance GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL); + BfModuleMethodInstance GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false); BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, const Array& paramTypes, bool checkBase = false); BfModuleMethodInstance GetInternalMethod(const StringImpl& methodName, int paramCount = -1); diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 11dc0a77..ca586c07 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -51,6 +51,7 @@ enum BfGetMethodInstanceFlags : uint16 BfGetMethodInstanceFlag_ForceInline = 0x80, BfGetMethodInstanceFlag_Friend = 0x100, BfGetMethodInstanceFlag_DisableObjectAccessChecks = 0x200, + BfGetMethodInstanceFlag_NoInline = 0x400 }; class BfDependencyMap