瀏覽代碼

Fixed reification issues, mut-vs-imut method mangling

Brian Fiete 4 年之前
父節點
當前提交
9a857cceb3

+ 0 - 2
BeefLibs/corlib/src/IO/StreamReader.bf

@@ -210,8 +210,6 @@ namespace System.IO
 
 			public this(StreamReader streamReader)
 			{
-				Debug.WriteLine("ReadLineTask this {0}", this);
-
 				mStreamReader = streamReader;
 				ThreadPool.QueueUserWorkItem(new => Proc);
 			}

+ 6 - 2
IDEHelper/Compiler/BfContext.cpp

@@ -447,7 +447,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
 
 				auto typeInst = methodSpecializationRequest.mType->ToTypeInstance();
 				module->GetMethodInstance(methodSpecializationRequest.mType->ToTypeInstance(), methodSpecializationRequest.mMethodDef, methodSpecializationRequest.mMethodGenericArguments, 
-					(BfGetMethodInstanceFlags)(methodSpecializationRequest.mFlags | BfGetMethodInstanceFlag_ResultNotUsed));
+					(BfGetMethodInstanceFlags)(methodSpecializationRequest.mFlags | BfGetMethodInstanceFlag_ResultNotUsed), methodSpecializationRequest.mForeignType);
 				didWork = true;
 			}
 		}
@@ -505,7 +505,11 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
 					module->PopulateType(owner, BfPopulateType_Full);
 
 				if (methodInstance->mDeclModule != NULL)
+				{
+					if (!mCompiler->mIsResolveOnly)
+						BF_ASSERT(!methodInstance->mIsReified || methodInstance->mDeclModule->mIsModuleMutable);
 					ProcessMethod(methodInstance);
+				}
 			}
 			
 			workIdx = mMethodWorkList.RemoveAt(workIdx);
@@ -2452,7 +2456,7 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
 		specializationRequest->mFromModuleRevision = typeInst->mModule->mRevision;
 		specializationRequest->mMethodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum];
 		specializationRequest->mMethodGenericArguments = methodRef.mMethodGenericArguments;
-		specializationRequest->mType = methodRef.mTypeInstance;		
+		specializationRequest->mType = methodRef.mTypeInstance;				
 
 		BfLogSysM("QueueMethodSpecializations typeInst %p specializationRequest %p methodDef %p fromModule %p\n", typeInst, specializationRequest, methodDef, specializationRequest->mFromModule);
 	}

+ 2 - 0
IDEHelper/Compiler/BfContext.h

@@ -47,12 +47,14 @@ public:
 	BfMethodDef* mMethodDef;
 	BfTypeVector mMethodGenericArguments;
 	BfGetMethodInstanceFlags mFlags;
+	BfTypeInstance* mForeignType;
 
 public:
 	BfMethodSpecializationRequest()
 	{		
 		mMethodDef = NULL;
 		mFlags = BfGetMethodInstanceFlag_None;
+		mForeignType = NULL;
 	}
 };
 

+ 13 - 7
IDEHelper/Compiler/BfMangler.cpp

@@ -2011,7 +2011,10 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho
 	}
 	else
 	{
-		AddStr(mangleContext, name, methodDef->mName);
+		if ((!mangleContext.mCPPMangle) && (!methodDef->mIsMutating) && (!methodDef->mIsStatic) && (methodInst->GetOwner()->IsValueType()))
+			AddStr(mangleContext, name, methodDef->mName + "__im");
+		else
+			AddStr(mangleContext, name, methodDef->mName);		
 	}
 		
 	if ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && 
@@ -2044,12 +2047,15 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho
 			name += StrFormat("%d$", declType->mPartialIdx);
 	}
 
-	if (methodInst->mMangleWithIdx)	
-		name += StrFormat("i%d$", methodInst->mMethodDef->mIdx);	
-	if (methodDef->mCheckedKind == BfCheckedKind_Checked)
-		name += "CHK$";
-	else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked)
-		name += "UCHK$";
+	if (!mangleContext.mCPPMangle)
+	{
+		if (methodInst->mMangleWithIdx)
+			name += StrFormat("i%d$", methodInst->mMethodDef->mIdx);
+		if (methodDef->mCheckedKind == BfCheckedKind_Checked)
+			name += "CHK$";
+		else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked)
+			name += "UCHK$";		
+	}
 
 	/*if ((methodInst->mMethodInstanceGroup->mOwner->mTypeDef->IsGlobalsContainer()) && (methodInst->mMethodDef->mMethodDeclaration == NULL))
 	{

+ 5 - 3
IDEHelper/Compiler/BfModule.cpp

@@ -1180,7 +1180,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force)
 	mExtensionCount = 0;
 	mRevision = mCompiler->mRevision;	
 	mRebuildIdx++;
-	ClearModuleData();	
+	ClearModuleData(!force);	
 
 	// Clear this here, not in ClearModuleData, so we preserve those references even after writing out module
 	if (rebuildKind != BfModule::RebuildKind_None) // Leave string pool refs for when we need to use things like [LinkName("")] methods bofore re-reification
@@ -12170,6 +12170,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
 					specializationRequest->mMethodGenericArguments = methodGenericArguments;
 					specializationRequest->mType = typeInst;
 					specializationRequest->mFlags = flags;
+					specializationRequest->mForeignType = foreignType;
 				}
 			}
 
@@ -22770,7 +22771,7 @@ void BfModule::ReportMemory(MemReporter* memReporter)
 
 // ClearModuleData is called immediately after the module is compiled, so don't clear out any data that needs to
 //  be transient through the next compile
-void BfModule::ClearModuleData()
+void BfModule::ClearModuleData(bool clearTransientData)
 {
 	BfLogSysM("ClearModuleData %p\n", this);
 
@@ -22782,7 +22783,8 @@ void BfModule::ClearModuleData()
 
 	mDICompileUnit = BfIRMDNode();
 	mIsModuleMutable = false;	
-	mIncompleteMethodCount = 0;	
+	if (clearTransientData)
+		mIncompleteMethodCount = 0;	
 	mHasGenericMethods = false;
 
 	// We don't want to clear these because we want it to persist through module extensions-

+ 1 - 1
IDEHelper/Compiler/BfModule.h

@@ -1883,7 +1883,7 @@ public:
 	void EnsureIRBuilder(bool dbgVerifyCodeGen = false);
 	void DbgFinish();
 	BfIRValue CreateForceLinkMarker(BfModule* module, String* outName);
-	void ClearModuleData();	
+	void ClearModuleData(bool clearTransientData = true);
 	void DisownMethods();
 	void ClearModule();	
 	void StartExtension(); // For new method specializations

+ 2 - 2
IDEHelper/Tests/LibA/src/LibA0.bf

@@ -102,7 +102,7 @@ class LibClassA
 
 	public this()
 	{
-		Debug.WriteLine("LibA.LibClassA()\n");
+		//Debug.WriteLine("LibA.LibClassA()\n");
 		mA += 100;
 	}
 
@@ -118,7 +118,7 @@ class LibClassA
 
 	public static int32 GetVal(int32 val, int32 magic, String str)
 	{
-		Debug.WriteLine("GetVal: {}", str);
+		//Debug.WriteLine("GetVal: {}", str);
 		sMagic += magic;
 		return val;
 	}

+ 2 - 1
IDEHelper/Tests/src/Indexers.bf

@@ -50,7 +50,7 @@ namespace Tests
 		}
 
 		[Test]
-		public static void Hey()
+		public static void TestBasics()
 		{
 			ClassB cc = scope ClassC();
 			ClassB cb = cc;
@@ -64,6 +64,7 @@ namespace Tests
 
 			StructA sa = default;
 			let sa2 = sa;
+
 			Test.Assert(sa[0] == 2);
 			Test.Assert(sa2[0] == 1);
 		}