From c5dca50e502882dddb85c507388ae2aa7ae3c526 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 4 Sep 2019 05:57:56 -0700 Subject: [PATCH] Fixed the lambda hotswap change --- BeefTools/BeefInstall/StubUI/src/Board.bf | 2 +- IDE/mintest/src/main3.bf | 37 ++-- IDE/src/IDEApp.bf | 8 + IDEHelper/Compiler/BfIRBuilder.cpp | 220 ++-------------------- IDEHelper/DbgModule.cpp | 17 +- IDEHelper/DbgModule.h | 2 +- 6 files changed, 55 insertions(+), 231 deletions(-) diff --git a/BeefTools/BeefInstall/StubUI/src/Board.bf b/BeefTools/BeefInstall/StubUI/src/Board.bf index 8199bac7..94c94c23 100644 --- a/BeefTools/BeefInstall/StubUI/src/Board.bf +++ b/BeefTools/BeefInstall/StubUI/src/Board.bf @@ -260,7 +260,7 @@ namespace BIStubUI mCancelButton.mImageHi = Images.sButtonHi; mCancelButton.mOnMouseClick.Add(new (mouseArgs) => { - //gApp.mCancelling = true; + gApp.mCancelling = true; }); mCancelButton.mMouseInsets = new Insets(4, 4, 4, 4); AddWidget(mCancelButton); diff --git a/IDE/mintest/src/main3.bf b/IDE/mintest/src/main3.bf index 8c1e5ef0..7a18caa7 100644 --- a/IDE/mintest/src/main3.bf +++ b/IDE/mintest/src/main3.bf @@ -100,6 +100,20 @@ class Blurg delegate void() mFuncA; delegate void() mFuncB; + int mA = 123; + + public this() + { + delegate void() dlg = new () => + { + //PrintF("Hey! %d\n", mA); + }; + + dlg(); + dlg(); + dlg(); + dlg(); + } void TestIt(int a, int b, int c) { @@ -108,28 +122,7 @@ class Blurg public static void Hey() { - int a = 123; - Blurg blurg = scope .(); - blurg.mFuncA = new () => - { - PrintF("YoA!\n"); - PrintF("A %d!\n", a); - PrintF("Blurg: %p\n", blurg); - }; - - blurg.mFuncB = new () => - { - PrintF("YoB!\n"); - }; - - blurg.TestIt(1, 2, 3); - blurg.[Friend]TestIt(1, 2, 3); - - while (true) - { - blurg.mFuncA(); - blurg.mFuncB(); - } + Blurg bl = scope .(); } } diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index df9673fd..af0b627f 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -10553,6 +10553,14 @@ namespace IDE if (isFirstMsg) { OutputLineSmart(scope String("ERROR: ", errorMsg)); + if (gApp.mRunningTestScript) + { + // The 'OutputLineSmart' would already call 'Fail' when running test scripts + } + else + { + Fail(errorMsg); + } isFirstMsg = false; } else diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 4871055e..010ea9a7 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -965,117 +965,8 @@ int64 BfIRBuilder::CheckedShl(int64 a, int64 b) ////////////////////////////////////////////////////////////////////////// -struct TestQ -{ -public: - int mId; - BfIRValueFlags mFlags; - - TestQ() - { - mId = -1; - mFlags = BfIRValueFlags_None; - } - - - /*TestQ(const TestQ& from) - { - mFlags = from.mFlags; - mId = from.mId; - }*/ - - /*TestQ(BfIRValueFlags flags, int id) - { - mFlags = flags; - mId = id; - } - - operator bool() const - { - return mFlags != BfIRValueFlags_None; - }*/ - - /*bool IsFake() const; - bool IsConst() const; - bool IsArg() const; - bool IsFunc() const; - bool IsFromLLVM() const; - - bool operator==(const TestQ& rhs) const - { - if (mFlags != rhs.mFlags) - return false; - if (mId != rhs.mId) - return false; - return true; - } - - bool operator!=(const TestQ& rhs) const - { - if (mFlags != rhs.mFlags) - return true; - if (mId != rhs.mId) - return true; - return false; - }*/ -}; - -class LTest -{ -public: - int mA; - int mB; - - void Fiff() - { - int valZ = 234; - mA = 123; - mB = 345; - - auto lam = [&]() - { - mA++; - valZ++; - }; - - lam(); - } - - static void UseIt(LTest lt) - { - - } - - static void DoIt(BfIRValue irVal) - { - } - - static void DoIt(TestQ irVal) - { - } - - BfIRValue CreateCall(BfIRValue func) - { - return func; - } -}; - - -void TestIt() -{ - LTest lt; - lt.mA = 0; - lt.mB = 0; - LTest::UseIt(lt); - - LTest::DoIt(BfIRValue()); - LTest::DoIt(TestQ()); -} - BfIRBuilder::BfIRBuilder(BfModule* module) : BfIRConstHolder(module) { - TestIt(); - mBlockCount = 0; mModule = module; mHasDebugLoc = false; @@ -2164,13 +2055,8 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDefine) diFieldTypes.push_back(inheritanceType); DbgMakePermanent(diForwardDecl, derivedFrom, diFieldTypes); } - else if (isPrimEnum) - //if (checkType->IsValueType()) - { - /*llvm::SmallVector diEnumValues; - diForwardDecl = DbgCreateEnumerationType(curDIScope, typeName, fileDIScope, mModule->mCurFilePosition.mCurLine, - typeInstance->mSize * 8, typeInstance->mAlign * 8, diEnumValues, DbgGetType(typeInstance->GetUnderlyingType()));*/ - + else if (isPrimEnum) + { BF_ASSERT(type->mSize > 0); diForwardDecl = DbgCreateSizedForwardDecl(llvm::dwarf::DW_TAG_enumeration_type, @@ -2178,53 +2064,20 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDefine) } else { -// diForwardDecl = DbgCreateForwardDecl(llvm::dwarf::DW_TAG_structure_type, -// typeName, curDIScope, fileDIScope, 0); - diForwardDecl = DbgCreateSizedForwardDecl(llvm::dwarf::DW_TAG_structure_type, typeName, curDIScope, fileDIScope, 0, (int64)BF_ALIGN(type->mSize, type->mAlign) * 8, (int64)type->mAlign * 8); } } else - { - //TODO: We may not have the fields filled in by the time we need the declaration. Why did we have this here instead of in the def? - /*if (isPrimEnum) - { - BF_ASSERT(!typeInstance->IsDataIncomplete()); - - llvm::SmallVector diEnumValues; - for (auto& fieldInst : typeInstance->mFieldInstances) - { - auto fieldDef = fieldInst.GetFieldDef(); - if ((fieldInst.mConstIdx != -1) && (fieldDef->IsEnumCaseEntry())) - { - auto constant = typeInstance->mConstHolder->GetConstantById(fieldInst.mConstIdx); - auto enumValue = DbgCreateEnumerator(fieldInst.GetFieldDef()->mName, constant->mInt64); - diEnumValues.push_back(enumValue); - } - } - - int flags = 0; - diForwardDecl = DbgCreateEnumerationType(curDIScope, - typeName, fileDIScope, mModule->mCurFilePosition.mCurLine, (int64)type->mSize * 8, (int64)type->mAlign * 8, diEnumValues, DbgGetType(typeInstance->GetUnderlyingType())); - - DbgSetType(type, diType); - DbgSetInstType(type, diType); - } - else*/ - { - - //int align = typeInstance->mIsPacked ? 0 : typeInstance->mAlign; - - // Will fill in later (during definition phase) - int flags = 0; - diForwardDecl = DbgCreateReplaceableCompositeType(isPrimEnum ? llvm::dwarf::DW_TAG_enumeration_type : llvm::dwarf::DW_TAG_structure_type, - typeName, curDIScope, fileDIScope, 0, (int64)BF_ALIGN(typeInstance->mInstSize, typeInstance->mInstAlign) * 8, (int64)typeInstance->mInstAlign * 8, flags); + { + // Will fill in later (during definition phase) + int flags = 0; + diForwardDecl = DbgCreateReplaceableCompositeType(isPrimEnum ? llvm::dwarf::DW_TAG_enumeration_type : llvm::dwarf::DW_TAG_structure_type, + typeName, curDIScope, fileDIScope, 0, (int64)BF_ALIGN(typeInstance->mInstSize, typeInstance->mInstAlign) * 8, (int64)typeInstance->mInstAlign * 8, flags); - mDITemporaryTypes.push_back(typeInstance); - } + mDITemporaryTypes.push_back(typeInstance); } DbgSetInstType(type, diForwardDecl); @@ -2234,14 +2087,12 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDefine) diType = diForwardDecl; else diType = DbgCreatePointerType(diForwardDecl); - DbgSetType(type, diType); - //DbgTrackDITypes(type); + DbgSetType(type, diType); } if (type->IsTypedPrimitive()) { - auto underlyingType = type->GetUnderlyingType(); - //mModule->PopulateType(underlyingType, BfPopulateType_Declaration); + auto underlyingType = type->GetUnderlyingType(); irType = MapType(underlyingType); SetType(type, irType); SetInstType(type, irType); @@ -2320,11 +2171,6 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) bool isUnion = false; bool isCRepr = false; - if ((typeDef->mFullName.ToString() == "IDETest.Virtuals.ClassA") || (typeDef->mFullName.ToString() == "IDETest.Virtuals.ClassB")) - { - NOP; - } - if (typeInstance->IsBoxed()) { @@ -2674,11 +2520,6 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) flags |= llvm::DINode::FlagArtificial; } - if (methodDef->mMethodType == BfMethodType_Dtor) - { - NOP; - } - String methodName = methodDef->mName; llvm::SmallVector genericArgs; llvm::SmallVector genericConstValueArgs; @@ -3205,11 +3046,7 @@ void BfIRBuilder::StructSetBody(BfIRType type, const BfSizedArray& mem BfIRType BfIRBuilder::MapType(BfType* type, BfIRPopulateType populateType) { if (!mIgnoreWrites) - { - /*if (populateType == BfIRPopulateType_Declaration) - mModule->PopulateType(type, BfPopulateType_Declaration); - else if (populateType == BfIRPopulateType_Full) - mModule->PopulateType(type, BfPopulateType_Data);*/ + { PopulateType(type, populateType); } BfIRType retType; @@ -3221,11 +3058,7 @@ BfIRType BfIRBuilder::MapType(BfType* type, BfIRPopulateType populateType) BfIRType BfIRBuilder::MapTypeInst(BfTypeInstance* typeInst, BfIRPopulateType populateType) { if (!mIgnoreWrites) - { - /*if (populateType == BfIRPopulateType_Declaration) - mModule->PopulateType(typeInst, BfPopulateType_Declaration); - else if (populateType == BfIRPopulateType_Full) - mModule->PopulateType(typeInst, BfPopulateType_Data);*/ + { PopulateType(typeInst, populateType); } @@ -3650,13 +3483,7 @@ BfIRValue BfIRBuilder::CreateShl(BfIRValue lhs, BfIRValue rhs) { mOpFailed = false; if ((lhs.IsConst()) && (rhs.IsConst())) - { - /*auto constLHS = GetConstantById(lhs.mId); - auto constRHS = GetConstantById(rhs.mId); - - uint64 val = constLHS->mUInt64 << constRHS->mInt32; - return CreateConst(constLHS->mTypeCode, val);*/ - + { INT_BINOPFUNC_APPLY(lhs, rhs, CheckedShl); } @@ -3930,12 +3757,7 @@ BfIRValue BfIRBuilder::CreateLifetimeStart(BfIRValue val) } BfIRValue BfIRBuilder::CreateLifetimeEnd(BfIRValue val) -{ - if (mModule->mCurMethodInstance->mMethodDef->mName == "Fart") - { - NOP; - } - +{ BfIRValue retVal = WriteCmd(BfIRCmd_LifetimeEnd, val); NEW_CMD_INSERTED; return retVal; @@ -4307,11 +4129,6 @@ BfIRFunction BfIRBuilder::CreateFunction(BfIRFunctionType funcType, BfIRLinkageT NEW_CMD_INSERTED_IRVALUE; mFunctionMap[name] = retVal; - if (name == "??B?$Result@PEAX@System@bf@@SAPEAXU012@@Z") - { - NOP; - } - //BfLogSys(mModule->mSystem, "BfIRBuilder::CreateFunction: %d %s Module:%p\n", retVal.mId, name.c_str(), mModule); return retVal; @@ -4719,7 +4536,7 @@ BfIRMDNode BfIRBuilder::DbgCreateBasicType(const StringImpl& name, int64 sizeInB } BfIRMDNode BfIRBuilder::DbgCreateStructType(BfIRMDNode context, const StringImpl& name, BfIRMDNode file, int lineNum, int64 sizeInBits, int64 alignInBits, int flags, BfIRMDNode derivedFrom, const BfSizedArray& elements) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateStructType, context, name, file, lineNum, sizeInBits, alignInBits, flags, derivedFrom, elements); NEW_CMD_INSERTED_IRMD; return retVal; @@ -4768,7 +4585,7 @@ BfIRMDNode BfIRBuilder::DbgCreateArrayType(int64 sizeInBits, int64 alignInBits, } BfIRMDNode BfIRBuilder::DbgCreateReplaceableCompositeType(int tag, const StringImpl& name, BfIRMDNode scope, BfIRMDNode file, int line, int64 sizeInBits, int64 alignInBits, int flags) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateReplaceableCompositeType, tag, name, scope, file, line, sizeInBits, alignInBits, flags); NEW_CMD_INSERTED_IRMD; return retVal; @@ -4849,11 +4666,6 @@ BfIRMDNode BfIRBuilder::DbgCreateMethod(BfIRMDNode context, const StringImpl& na BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateMethod, context, name, linkageName, file, lineNum, type, isLocalToUnit, isDefinition, vk, vIndex, vTableHolder, flags, isOptimized, fn, genericArgs, genericConstValueArgs); NEW_CMD_INSERTED_IRMD; - if (linkageName == "?Unwrap@?$Result@PEAX@System@bf@@AEAAPEAXXZ") - { - NOP; - } - // if (mDbgVerifyCodeGen && gDebugDbgLoc) // { // OutputDebugStrF("DbgCreateFunction Context:%d name:%s = %d\n", context.mId, name.c_str(), retVal.mId); diff --git a/IDEHelper/DbgModule.cpp b/IDEHelper/DbgModule.cpp index ce530901..48425e6b 100644 --- a/IDEHelper/DbgModule.cpp +++ b/IDEHelper/DbgModule.cpp @@ -714,7 +714,7 @@ DbgLanguage DbgSubprogram::GetLanguage() return DbgLanguage_C; // Parent type would have been set for Beef, so it must be C } -bool DbgSubprogram::Equals(DbgSubprogram* checkMethod) +bool DbgSubprogram::Equals(DbgSubprogram* checkMethod, bool allowThisMismatch) { if ((mLinkName != NULL) && (checkMethod->mLinkName != NULL)) { @@ -724,14 +724,23 @@ bool DbgSubprogram::Equals(DbgSubprogram* checkMethod) if (strcmp(mName, checkMethod->mName) != 0) return false; + if (mHasThis != checkMethod->mHasThis) + return false; + + int paramIdx = 0; auto param = mParams.mHead; auto checkParam = checkMethod->mParams.mHead; while ((param != NULL) && (checkParam != NULL)) { - if ((param->mType != checkParam->mType) && (!param->mType->Equals(checkParam->mType))) + if ((paramIdx == 0) && (allowThisMismatch)) + { + // Allow + } + else if ((param->mType != checkParam->mType) && (!param->mType->Equals(checkParam->mType))) return false; param = param->mNext; checkParam = checkParam->mNext; + paramIdx++; } if ((param != NULL) || (checkParam != NULL)) @@ -5111,7 +5120,7 @@ void DbgModule::HotReplaceType(DbgType* newType) // If we removed captures then we can still do the hot jump. Otherwise we have to fail... doHotJump = false; - if ((oldMethod->IsLambda()) && (oldMethod->GetParamCount() == 0) && (newMethod->GetParamCount() == 0) && + if ((oldMethod->IsLambda()) && (oldMethod->Equals(newMethod, true)) && (oldMethod->mHasThis) && (newMethod->mHasThis)) { auto oldParam = oldMethod->mParams.front(); @@ -5120,7 +5129,9 @@ void DbgModule::HotReplaceType(DbgType* newType) if ((oldParam->mType->IsPointer()) && (newParam->mType->IsPointer())) { auto oldType = oldParam->mType->mTypeParam->GetPrimaryType(); + oldType->PopulateType(); auto newType = newParam->mType->mTypeParam->GetPrimaryType(); + newType->PopulateType(); if ((oldType->IsStruct()) && (newType->IsStruct())) { bool wasMatch = true; diff --git a/IDEHelper/DbgModule.h b/IDEHelper/DbgModule.h index 45fd5626..dbb236a3 100644 --- a/IDEHelper/DbgModule.h +++ b/IDEHelper/DbgModule.h @@ -428,7 +428,7 @@ public: DbgType* GetParent(); DbgType* GetTargetType(); // usually mParentType except for closures DbgLanguage GetLanguage(); - bool Equals(DbgSubprogram* checkMethod); + bool Equals(DbgSubprogram* checkMethod, bool allowThisMismatch = false); int GetParamCount(); String GetParamName(int paramIdx); bool IsGenericMethod();