1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed extension issue, fixed false dep from conversion operator

This commit is contained in:
Brian Fiete 2020-02-22 06:49:56 -08:00
parent d40f7fa759
commit 4efa88376c
3 changed files with 69 additions and 65 deletions

View file

@ -4208,7 +4208,7 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC
genLivenessIdx++; genLivenessIdx++;
auto inst = block->mInstructions[instIdx]; auto inst = block->mInstructions[instIdx];
auto prevLiveness = inst->mLiveness; auto prevLiveness = inst->mLiveness;
genCtx->mInstructions++; genCtx->mInstructions++;
SizedArray<int, 16> removeVec; SizedArray<int, 16> removeVec;
@ -4463,21 +4463,14 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC
if (newSuccLiveness == pred->mSuccLiveness) if (newSuccLiveness == pred->mSuccLiveness)
continue; continue;
pred->mSuccLiveness = newSuccLiveness; pred->mSuccLiveness = newSuccLiveness;
/*if (mVRegInitializedContext.HasExtraBitsSet(pred->mSuccVRegsInitialized.mBits, vregsInitialized.mBits))
{
mVRegInitializedContext.MergeInplace(pred->mSuccVRegsInitialized.mBits, vregsInitialized.mBits);
}*/
//if (mVRegInitializedContext.HasExtraEntries(pred->mSuccVRegsInitialized.mList, vregsInitialized.mList))
pred->mSuccVRegsInitialized = mVRegInitializedContext.Merge(pred->mSuccVRegsInitialized, vregsInitialized); pred->mSuccVRegsInitialized = mVRegInitializedContext.Merge(pred->mSuccVRegsInitialized, vregsInitialized);
if (pred->mBlockIdx > block->mBlockIdx) if (pred->mBlockIdx > block->mBlockIdx)
modifiedBlockAfter = true; modifiedBlockAfter = true;
else else
modifiedBlockBefore = true; modifiedBlockBefore = true;
entry.mGenerateQueued = true; entry.mGenerateQueued = true;
//GenerateLiveness(pred, liveRegs, vregsInitialized, mcColorizer, livenessStats);
} }
} }
@ -6169,14 +6162,14 @@ void BeMCContext::InitializedPassHelper(BeMCBlock* mcBlock, BeVTrackingGenContex
genCtx->mInstructions++; genCtx->mInstructions++;
mInsertInstIdxRef = &instIdx; mInsertInstIdxRef = &instIdx;
auto inst = mcBlock->mInstructions[instIdx];
auto inst = mcBlock->mInstructions[instIdx];
inst->mVRegsInitialized = vregsInitialized; inst->mVRegsInitialized = vregsInitialized;
bool deepSet = false; bool deepSet = false;
if (inst->mKind == BeMCInstKind_LifetimeStart) if (inst->mKind == BeMCInstKind_LifetimeStart)
continue; continue;
SizedArray<int, 16> removeVec; SizedArray<int, 16> removeVec;
SizedArray<int, 16> addVec; SizedArray<int, 16> addVec;
@ -6608,19 +6601,21 @@ bool BeMCContext::DoInitializedPass()
// If mPredVRegsInitialized is NULL, this blocks is unreachable. It could still be in some other block's preds so we don't // If mPredVRegsInitialized is NULL, this blocks is unreachable. It could still be in some other block's preds so we don't
// completely erase it, just empty it // completely erase it, just empty it
if (genCtx.mBlocks[mcBlock->mBlockIdx].mGenerateCount == 0) if (genCtx.mBlocks[mcBlock->mBlockIdx].mGenerateCount == 0)
{ {
//BF_ASSERT((blockIdx != 0) && (mcBlock->mPreds.size() == 0)); // Unused block - clear almost all instructions
mcBlock->mInstructions.Clear(); int newIdx = 0;
// for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++)
// {
// auto inst = mcBlock->mInstructions[instIdx];
// if (inst->mKind == BeMCInstKind_ValueScopeHardEnd)
// {
// mcBlock->mInstructions[newIdx++] = inst;
// }
// }
mcBlock->mInstructions.mSize = newIdx;
continue; continue;
} }
/*int vregIdx = -1;
while (true)
{
vregIdx = mVRegInitializedContext.GetNextSetIdx(mcBlock->mPredVRegsInitialized, vregIdx);
if (vregIdx == -1)
break;*/
for (int vregIdx : *mcBlock->mPredVRegsInitialized) for (int vregIdx : *mcBlock->mPredVRegsInitialized)
{ {
if (vregIdx >= mVRegInitializedContext.mNumItems) if (vregIdx >= mVRegInitializedContext.mNumItems)
@ -6637,8 +6632,6 @@ bool BeMCContext::DoInitializedPass()
vregInfo->mHasAmbiguousInitialization = true; vregInfo->mHasAmbiguousInitialization = true;
} }
} }
//
} }
bool needsReRun = false; bool needsReRun = false;
@ -6762,21 +6755,15 @@ void BeMCContext::DoChainedBlockMerge()
auto lastInst = mcBlock->mInstructions.back(); auto lastInst = mcBlock->mInstructions.back();
// Last instruction of current block is an unconditional branch to the next block // Last instruction of current block is an unconditional branch to the next block
if ((lastInst->mKind == BeMCInstKind_Br) && (lastInst->mArg0.mBlock == nextMcBlock)) if ((lastInst->mKind == BeMCInstKind_Br) && (lastInst->mArg0.mBlock == nextMcBlock))
{ {
//auto itr = std::find(mcBlock->mSuccs.begin(), mcBlock->mSuccs.end(), nextMcBlock);
//mcBlock->mSuccs.erase(itr);
mcBlock->mSuccs.Remove(nextMcBlock); mcBlock->mSuccs.Remove(nextMcBlock);
for (auto succ : nextMcBlock->mSuccs) for (auto succ : nextMcBlock->mSuccs)
{ {
//auto itr = std::find(mcBlock->mSuccs.begin(), mcBlock->mSuccs.end(), succ);
//if (itr == mcBlock->mSuccs.end())
if (!mcBlock->mSuccs.Contains(succ)) if (!mcBlock->mSuccs.Contains(succ))
{ {
mcBlock->mSuccs.push_back(succ); mcBlock->mSuccs.push_back(succ);
succ->mPreds.push_back(mcBlock); succ->mPreds.push_back(mcBlock);
} }
/*itr = std::find(succ->mPreds.begin(), succ->mPreds.end(), nextMcBlock);
succ->mPreds.erase(itr);*/
succ->mPreds.Remove(nextMcBlock); succ->mPreds.Remove(nextMcBlock);
} }
@ -6869,6 +6856,7 @@ bool BeMCContext::CheckVRegEqualityRange(BeMCBlock* mcBlock, int instIdx, const
for (int checkInstIdx = instIdx + 1; checkInstIdx < (int)mcBlock->mInstructions.size(); checkInstIdx++) for (int checkInstIdx = instIdx + 1; checkInstIdx < (int)mcBlock->mInstructions.size(); checkInstIdx++)
{ {
auto checkInst = mcBlock->mInstructions[checkInstIdx]; auto checkInst = mcBlock->mInstructions[checkInstIdx];
if ((!IsLive(checkInst->mLiveness, vreg0.mVRegIdx, regRemaps)) || if ((!IsLive(checkInst->mLiveness, vreg0.mVRegIdx, regRemaps)) ||
((!onlyCheckFirstLifetime) && (!IsLive(checkInst->mLiveness, vreg1.mVRegIdx, regRemaps)))) ((!onlyCheckFirstLifetime) && (!IsLive(checkInst->mLiveness, vreg1.mVRegIdx, regRemaps))))
{ {
@ -14705,7 +14693,7 @@ void BeMCContext::Generate(BeFunction* function)
mDbgPreferredRegs[32] = X64Reg_R8;*/ mDbgPreferredRegs[32] = X64Reg_R8;*/
//mDbgPreferredRegs[8] = X64Reg_RAX; //mDbgPreferredRegs[8] = X64Reg_RAX;
//mDebugging = function->mName == "?Hey@Blurg@bf@@SAXXZ"; //mDebugging = function->mName == "?Unwrap@?$Result@Tint@@@System@bf@@AEAATint@@XZ";
//"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z"; //"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z";
//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z"; //"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
@ -14831,6 +14819,15 @@ void BeMCContext::Generate(BeFunction* function)
{ {
auto mcInst = AllocInst(); auto mcInst = AllocInst();
mcInst->mKind = BeMCInstKind_Unreachable; mcInst->mKind = BeMCInstKind_Unreachable;
// if (instIdx == beBlock->mInstructions.size() - 1)
// {
// // Fake branch to exit
// mcInst = AllocInst();
// mcInst->mKind = BeMCInstKind_Br;
// mcInst->mArg0 = BeMCOperand::FromBlock(mBlocks.back());
// mcInst->mArg0.mBlock->AddPred(mcBlock);
// }
} }
break; break;
case BeEnsureInstructionAtInst::TypeId: case BeEnsureInstructionAtInst::TypeId:

View file

@ -10884,7 +10884,7 @@ void BfModule::AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInsta
BfMethodRef methodRef = methodInstance; BfMethodRef methodRef = methodInstance;
BfSpecializedMethodRefInfo* specializedMethodRefInfo = NULL; BfSpecializedMethodRefInfo* specializedMethodRefInfo = NULL;
bool isNew = mCurTypeInstance->mSpecializedMethodReferences.TryAdd(methodRef, NULL, &specializedMethodRefInfo); bool isNew = mCurTypeInstance->mSpecializedMethodReferences.TryAdd(methodRef, NULL, &specializedMethodRefInfo);
if (((flags & BfGetMethodInstanceFlag_Unreified) == 0) && if (((flags & BfGetMethodInstanceFlag_Unreified) == 0) &&
((flags & BfGetMethodInstanceFlag_NoForceReification) == 0) && ((flags & BfGetMethodInstanceFlag_NoForceReification) == 0) &&
(mIsReified)) (mIsReified))

View file

@ -1579,10 +1579,15 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
(!typeInstance->mTypeFailed)) (!typeInstance->mTypeFailed))
{ {
for (auto baseTypeRef : typeDef->mBaseTypes) for (auto baseTypeRef : typeDef->mBaseTypes)
{ {
auto declTypeDef = typeDef;
if (typeDef->mIsCombinedPartial)
declTypeDef = typeDef->mPartials.front();
SetAndRestoreValue<BfTypeDef*> prevTypeDef(mContext->mCurTypeState->mCurTypeDef, declTypeDef);
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef); SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef);
// We ignore errors here to avoid double-errors for type lookups, but this is where data cycles are detected // We ignore errors here to avoid double-errors for type lookups, but this is where data cycles are detected
// but that type of error supercedes the mIgnorErrors setting // but that type of error supersedes the mIgnoreErrors setting
SetAndRestoreValue<bool> prevIgnoreError(mIgnoreErrors, true); SetAndRestoreValue<bool> prevIgnoreError(mIgnoreErrors, true);
// Temporarily allow us to derive from private classes, to avoid infinite loop from TypeIsSubTypeOf // Temporarily allow us to derive from private classes, to avoid infinite loop from TypeIsSubTypeOf
SetAndRestoreValue<bool> prevSkipTypeProtectionChecks(typeInstance->mSkipTypeProtectionChecks, true); SetAndRestoreValue<bool> prevSkipTypeProtectionChecks(typeInstance->mSkipTypeProtectionChecks, true);
@ -1966,8 +1971,21 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if ((baseTypeInst != NULL) && (typeInstance->mBaseType == NULL)) if ((baseTypeInst != NULL) && (typeInstance->mBaseType == NULL))
{ {
//curFieldDataIdx = 1; //curFieldDataIdx = 1;
if (!typeInstance->mTypeFailed) // if (!typeInstance->mTypeFailed)
PopulateType(baseTypeInst, BfPopulateType_Data); // PopulateType(baseTypeInst, BfPopulateType_Data);
if (typeInstance->mTypeFailed)
{
if (baseTypeInst->IsDataIncomplete())
{
if (baseTypeInst->IsStruct())
baseTypeInst = ResolveTypeDef(mCompiler->mValueTypeTypeDef)->ToTypeInstance();
else if (baseTypeInst->IsObject())
baseTypeInst = ResolveTypeDef(mCompiler->mBfObjectTypeDef)->ToTypeInstance();
}
}
PopulateType(baseTypeInst, BfPopulateType_Data);
typeInstance->mBaseTypeMayBeIncomplete = false; typeInstance->mBaseTypeMayBeIncomplete = false;
typeInstance->mMergedFieldDataCount = baseTypeInst->mMergedFieldDataCount; typeInstance->mMergedFieldDataCount = baseTypeInst->mMergedFieldDataCount;
@ -2846,7 +2864,14 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
BfHotTypeVersion* hotTypeVersion = new BfHotTypeVersion(); BfHotTypeVersion* hotTypeVersion = new BfHotTypeVersion();
hotTypeVersion->mTypeId = typeInstance->mTypeId; hotTypeVersion->mTypeId = typeInstance->mTypeId;
if (typeInstance->mBaseType != NULL) if (typeInstance->mBaseType != NULL)
hotTypeVersion->mBaseType = typeInstance->mBaseType->mHotTypeData->GetLatestVersion(); {
if (typeInstance->mBaseType->mHotTypeData != NULL)
hotTypeVersion->mBaseType = typeInstance->mBaseType->mHotTypeData->GetLatestVersion();
else
{
AssertErrorState();
}
}
hotTypeVersion->mDeclHotCompileIdx = mCompiler->mOptions.mHotCompileIdx; hotTypeVersion->mDeclHotCompileIdx = mCompiler->mOptions.mHotCompileIdx;
if (mCompiler->IsHotCompile()) if (mCompiler->IsHotCompile())
hotTypeVersion->mCommittedHotCompileIdx = -1; hotTypeVersion->mCommittedHotCompileIdx = -1;
@ -2855,7 +2880,7 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
hotTypeVersion->mRefCount++; hotTypeVersion->mRefCount++;
typeInstance->mHotTypeData->mTypeVersions.Add(hotTypeVersion); typeInstance->mHotTypeData->mTypeVersions.Add(hotTypeVersion);
if (typeInstance->mBaseType != NULL) if ((typeInstance->mBaseType != NULL) && (typeInstance->mBaseType->mHotTypeData != NULL))
{ {
hotTypeVersion->mMembers.Add(typeInstance->mBaseType->mHotTypeData->GetLatestVersion()); hotTypeVersion->mMembers.Add(typeInstance->mBaseType->mHotTypeData->GetLatestVersion());
} }
@ -3442,12 +3467,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
// Generate all methods. Pass 1 // Generate all methods. Pass 1
for (auto methodDef : typeDef->mMethods) for (auto methodDef : typeDef->mMethods)
{ {
if (methodDef->mMethodType == BfMethodType_CtorClear)
{
NOP;
}
auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx]; auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx];
if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude)
@ -4247,11 +4267,6 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance)
BF_ASSERT(mBfIRBuilder != NULL); BF_ASSERT(mBfIRBuilder != NULL);
if (methodInstance->mMethodDef->mName == "Hey")
{
NOP;
}
BfLogSysM("Adding to mMethodWorkList Module: %p IncompleteMethodCount: %d Type %p MethodInstance: %p Name:%s TypeRevision: %d ModuleRevision: %d ReqId:%d\n", this, mIncompleteMethodCount, typeInstance, methodInstance, methodInstance->mMethodDef->mName.c_str(), methodProcessRequest->mRevision, methodProcessRequest->mFromModuleRevision, methodProcessRequest->mReqId); BfLogSysM("Adding to mMethodWorkList Module: %p IncompleteMethodCount: %d Type %p MethodInstance: %p Name:%s TypeRevision: %d ModuleRevision: %d ReqId:%d\n", this, mIncompleteMethodCount, typeInstance, methodInstance, methodInstance->mMethodDef->mName.c_str(), methodProcessRequest->mRevision, methodProcessRequest->mFromModuleRevision, methodProcessRequest->mReqId);
if (mAwaitingFinish) if (mAwaitingFinish)
@ -6086,11 +6101,6 @@ BfTypeDef* BfModule::FindTypeDefRaw(const BfAtomComposite& findName, int numGene
if (checkTypeInst == skipCheckBaseType) if (checkTypeInst == skipCheckBaseType)
break; break;
if (checkTypeInst->mTypeDef == mCompiler->mNullableTypeDef)
{
NOP;
}
checkTypeInst = GetBaseType(checkTypeInst); checkTypeInst = GetBaseType(checkTypeInst);
allowPrivate = false; allowPrivate = false;
} }
@ -7134,11 +7144,6 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
} }
} }
if (typeRef->ToString() == "Issue.I?")
{
NOP;
}
BfResolvedTypeSet::LookupContext lookupCtx; BfResolvedTypeSet::LookupContext lookupCtx;
lookupCtx.mRootTypeRef = typeRef; lookupCtx.mRootTypeRef = typeRef;
lookupCtx.mRootTypeDef = typeDef; lookupCtx.mRootTypeDef = typeDef;
@ -9068,9 +9073,9 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
mCompiler->mPassInstance->MoreInfo("See conversion operator", opMethodInstance->mMethodDef->GetRefNode()); mCompiler->mPassInstance->MoreInfo("See conversion operator", opMethodInstance->mMethodDef->GetRefNode());
} }
BfModuleMethodInstance moduleMethodInstance = GetMethodInstance(opMethodInstance->GetOwner(), opMethodInstance->mMethodDef, BfTypeVector()); BfMethodInstance* methodInstance = GetRawMethodInstance(opMethodInstance->GetOwner(), opMethodInstance->mMethodDef);
auto methodDeclaration = moduleMethodInstance.mMethodInstance->mMethodDef->GetMethodDeclaration(); auto methodDeclaration = methodInstance->mMethodDef->GetMethodDeclaration();
if (methodDeclaration->mBody == NULL) if (methodDeclaration->mBody == NULL)
{ {
// Handle the typedPrim<->underlying part implicitly // Handle the typedPrim<->underlying part implicitly
@ -9098,6 +9103,8 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (ignoreWrites) if (ignoreWrites)
return mBfIRBuilder->GetFakeVal(); return mBfIRBuilder->GetFakeVal();
BfModuleMethodInstance moduleMethodInstance = GetMethodInstance(opMethodInstance->GetOwner(), opMethodInstance->mMethodDef, BfTypeVector());
SizedArray<BfIRValue, 1> args; SizedArray<BfIRValue, 1> args;
exprEvaluator.PushArg(castedFromValue, args); exprEvaluator.PushArg(castedFromValue, args);
auto operatorOut = exprEvaluator.CreateCall(moduleMethodInstance.mMethodInstance, mCompiler->IsSkippingExtraResolveChecks() ? BfIRValue() : moduleMethodInstance.mFunc, false, args); auto operatorOut = exprEvaluator.CreateCall(moduleMethodInstance.mMethodInstance, mCompiler->IsSkippingExtraResolveChecks() ? BfIRValue() : moduleMethodInstance.mFunc, false, args);