1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Fixed reification issues, mut-vs-imut method mangling

This commit is contained in:
Brian Fiete 2020-10-22 17:25:19 -07:00
parent 425284f023
commit 9a857cceb3
8 changed files with 31 additions and 18 deletions

View file

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

View file

@ -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);

View file

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

View file

@ -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))
{

View file

@ -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-

View file

@ -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

View file

@ -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;
}

View file

@ -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);
}