From d7da98444e51463cd37139bc222aab8d951e0804 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 7 Sep 2019 06:38:56 -0700 Subject: [PATCH] Fixed a module extension issue with mIRFunction not being cleared --- IDE/Tests/BugW002/BeefProj.toml | 5 ++ IDE/Tests/BugW002/BeefSpace.toml | 6 ++ IDE/Tests/BugW002/scripts/Test.txt | 8 +++ IDE/Tests/BugW002/src/Program.bf | 25 ++++++++ IDEHelper/Compiler/BfIRBuilder.cpp | 2 + IDEHelper/Compiler/BfModule.cpp | 72 +++++------------------- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 19 ++++--- 7 files changed, 71 insertions(+), 66 deletions(-) create mode 100644 IDE/Tests/BugW002/BeefProj.toml create mode 100644 IDE/Tests/BugW002/BeefSpace.toml create mode 100644 IDE/Tests/BugW002/scripts/Test.txt create mode 100644 IDE/Tests/BugW002/src/Program.bf diff --git a/IDE/Tests/BugW002/BeefProj.toml b/IDE/Tests/BugW002/BeefProj.toml new file mode 100644 index 00000000..f0c46edc --- /dev/null +++ b/IDE/Tests/BugW002/BeefProj.toml @@ -0,0 +1,5 @@ +FileVersion = 1 + +[Project] +Name = "Bug" +StartupObject = "Bug.Program" diff --git a/IDE/Tests/BugW002/BeefSpace.toml b/IDE/Tests/BugW002/BeefSpace.toml new file mode 100644 index 00000000..c389207f --- /dev/null +++ b/IDE/Tests/BugW002/BeefSpace.toml @@ -0,0 +1,6 @@ +FileVersion = 1 +Projects = {Bug = {Path = "."}} + +[Workspace] +StartupProject = "Bug" + diff --git a/IDE/Tests/BugW002/scripts/Test.txt b/IDE/Tests/BugW002/scripts/Test.txt new file mode 100644 index 00000000..501de69f --- /dev/null +++ b/IDE/Tests/BugW002/scripts/Test.txt @@ -0,0 +1,8 @@ +# This tests extensions in Span, whose IRFunction was not being cleared + +ShowFile("src/Program.bf") +Compile() +ToggleCommentAt("Main_OpenReg") +Compile() +ToggleCommentAt("Main_GetValue") +Compile() \ No newline at end of file diff --git a/IDE/Tests/BugW002/src/Program.bf b/IDE/Tests/BugW002/src/Program.bf new file mode 100644 index 00000000..727e23fe --- /dev/null +++ b/IDE/Tests/BugW002/src/Program.bf @@ -0,0 +1,25 @@ +#pragma warning disable 168 + +using System; + +namespace Bug +{ + class Program + { + static void Main() + { + /*Main_OpenReg + Windows.HKey key = 0; + Windows.RegOpenKeyExA(Windows.HKEY_LOCAL_MACHINE, @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, Windows.KEY_QUERY_VALUE, out key); + if (key.IsInvalid) + Runtime.FatalError(); + */ + + /*Main_GetValue + String path = scope .(); + if (key.GetValue("path", path) case .Err) + Runtime.FatalError(); + */ + } + } +} diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 010ea9a7..9a847e87 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -4125,6 +4125,8 @@ BfIRFunction BfIRBuilder::CreateFunction(BfIRFunctionType funcType, BfIRLinkageT return fakeVal; } + BF_ASSERT(mModule->mIsModuleMutable); + BfIRFunction retVal = WriteCmd(BfIRCmd_CreateFunction, funcType, (uint8)linkageType, name); NEW_CMD_INSERTED_IRVALUE; mFunctionMap[name] = retVal; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index cd1931d1..9efed147 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -4032,11 +4032,6 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou StringT<128> classVDataName; - if ((mCompiler->IsHotCompile()) && (typeInstance->mTypeDef->mName->ToString() == "ClassC")) - { - NOP; - } - String memberName = "sBfClassVData"; if ((typeInstance->mHotTypeData != NULL) && ((typeInstance->mHotTypeData->mHadDataChange) || (typeInstance->mHotTypeData->mPendingDataChange))) { @@ -9104,12 +9099,7 @@ void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, Bf } void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrTarget) -{ - if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mName == "OpenAudio")) - { - NOP; - } - + if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL) && (attributesDirective->IsFromParser(mCompiler->mResolvePassData->mParser)) && (mCompiler->mResolvePassData->mSourceClassifier != NULL)) { @@ -10990,7 +10980,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (lookupMethodGenericArguments.size() == 0) { methodInstance = methodInstGroup->mDefault; - + if ((methodInstance != NULL) && (isReified) && (!methodInstance->mIsReified)) { MarkDerivedDirty(typeInst); @@ -11172,11 +11162,6 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, false); - if ((methodInstance->mMethodDef->mName == "Unwrap") && (mModuleName == "System_Result_PTR_void")) - { - NOP; - } - if (mAwaitingInitFinish) FinishInit(); @@ -11206,7 +11191,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (mCompiler->IsSkippingExtraResolveChecks()) return BfModuleMethodInstance(methodInstance, BfIRFunction()); else - { + { if (methodInstance->mDeclModule != this) return ReferenceExternalMethodInstance(methodInstance, flags); @@ -14569,11 +14554,6 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp auto methodDef = methodInstance->mMethodDef; auto methodDeclaration = methodDef->mMethodDeclaration; - if (methodDef->mName == "GetIt") - { - NOP; - } - bool isThisStruct = false; if (thisType != NULL) isThisStruct = thisType->IsStruct() && !thisType->IsTypedPrimitive(); @@ -18384,11 +18364,6 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if (mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingReference; - if (mCurTypeInstance->mTypeDef->mName->ToString() == "ClassA") - { - NOP; - } - bool ignoreWrites = mBfIRBuilder->mIgnoreWrites; if (mAwaitingInitFinish) @@ -20322,16 +20297,6 @@ bool BfModule::Finish() BP_ZONE("BfModule::Finish"); BfLogSysM("BfModule finish: %p\n", this); - if (mCompiler->mCanceling) - { - NOP; - } - - if (mModuleName == "System_Array") - { - NOP; - } - if (mHadBuildError) { // Don't AssertErrorState here, this current pass may not have failed but @@ -20558,11 +20523,6 @@ void BfModule::ClearModuleData() mAddedToCount = false; } - if (mCompiler->mCanceling) - { - NOP; - } - mDICompileUnit = BfIRMDNode(); mIsModuleMutable = false; mIncompleteMethodCount = 0; @@ -20598,18 +20558,6 @@ void BfModule::ClearModuleData() if (mNextAltModule != NULL) mNextAltModule->ClearModuleData(); - for (auto typeInstance : mOwnedTypeInstances) - { - if (typeInstance->IsSpecializedType()) - { - for (auto&& methodGroup : typeInstance->mMethodInstanceGroups) - { - if (methodGroup.mDefault != NULL) - methodGroup.mDefault->mDeclModule = NULL; - } - } - } - BfLogSysM("ClearModuleData. Deleting IRBuilder: %p\n", mBfIRBuilder); delete mBfIRBuilder; mBfIRBuilder = NULL; @@ -20617,7 +20565,7 @@ void BfModule::ClearModuleData() } void BfModule::DisownMethods() -{ +{ for (int i = 0; i < BfBuiltInFuncType_Count; i++) mBuiltInFuncs[i] = BfIRFunction(); @@ -20631,8 +20579,14 @@ void BfModule::DisownMethods() { if (methodGroup.mDefault != NULL) { - if (methodGroup.mDefault->mDeclModule == this) - methodGroup.mDefault->mIRFunction = BfIRFunction(); + if (methodGroup.mDefault->mIRFunction) + { + BF_ASSERT(methodGroup.mDefault->mDeclModule != NULL); + if (methodGroup.mDefault->mDeclModule == this) + { + methodGroup.mDefault->mIRFunction = BfIRFunction(); + } + } } if (methodGroup.mMethodSpecializationMap != NULL) @@ -20641,7 +20595,9 @@ void BfModule::DisownMethods() { auto methodInstance = mapPair.mValue; if (methodInstance->mDeclModule == this) + { methodInstance->mIRFunction = BfIRFunction(); + } } } } diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 5a95eb29..ae20ffb0 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -4087,22 +4087,25 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) { auto module = GetOrCreateMethodModule(methodInstance); methodInstance->mDeclModule = module; - + BfIRValue func = CreateFunctionFrom(methodInstance, false, methodInstance->mAlwaysInline); methodInstance->mIRFunction = func; module->mFuncReferences[methodInstance] = func; - if (module != this) - { - // For extension modules we need to keep track of our own methods so we can know which methods - // we have defined ourselves and which are from the parent module or other extensions - if (!func.IsFake()) - mFuncReferences[methodInstance] = func; - } module->AddMethodToWorkList(methodInstance); return; } + + if ((!methodInstance->mIRFunction) && (!methodInstance->mIsUnspecialized)) + { + if (!mIsModuleMutable) + StartExtension(); + + BfIRValue func = CreateFunctionFrom(methodInstance, false, methodInstance->mAlwaysInline); + methodInstance->mIRFunction = func; + mFuncReferences[methodInstance] = func; + } BF_ASSERT(methodInstance->mDeclModule == this);