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

Fixed inlining issues

This commit is contained in:
Brian Fiete 2020-12-27 10:56:14 -08:00
parent 6c049988b3
commit ba9ce75a0b
6 changed files with 66 additions and 26 deletions

View file

@ -3325,6 +3325,15 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap
if ((usedType->mRebuildFlags & BfTypeRebuildFlag_AwaitingReference) != 0) if ((usedType->mRebuildFlags & BfTypeRebuildFlag_AwaitingReference) != 0)
mContext->MarkAsReferenced(checkDType); mContext->MarkAsReferenced(checkDType);
#ifdef _DEBUG
// If a MethodRef depends ON US, that means it's a local method that we own
if (userType->IsMethodRef())
{
auto methodRefType = (BfMethodRefType*)userType;
BF_ASSERT(methodRefType->mOwner == checkDType);
}
#endif
if (!checkDType->mDependencyMap.AddUsedBy(userType, flags)) if (!checkDType->mDependencyMap.AddUsedBy(userType, flags))
return; return;
if (checkDType->IsGenericTypeInstance()) if (checkDType->IsGenericTypeInstance())
@ -4744,6 +4753,9 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou
classVDataName); classVDataName);
mClassVDataRefs[typeInstance] = globalVariable; mClassVDataRefs[typeInstance] = globalVariable;
if (mCurTypeInstance != NULL)
AddDependency(typeInstance, mCurTypeInstance, BfDependencyMap::DependencyFlag_StaticValue);
} }
return globalVariable; return globalVariable;
} }
@ -5705,7 +5717,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
int idx = interfaceEntry->mStartVirtualIdx; int idx = interfaceEntry->mStartVirtualIdx;
int endVirtualIdx = interfaceEntry->mStartVirtualIdx + interfaceEntry->mInterfaceType->mVirtualMethodTableSize; int endVirtualIdx = interfaceEntry->mStartVirtualIdx + interfaceEntry->mInterfaceType->mVirtualMethodTableSize;
if (endVirtualIdx > ifaceMethodExtStart) if ((endVirtualIdx > ifaceMethodExtStart) && (ifaceMethodExtVar))
vtablePtr = mBfIRBuilder->CreateInBoundsGEP(ifaceMethodExtVar, 0, interfaceEntry->mStartVirtualIdx - ifaceMethodExtStart); vtablePtr = mBfIRBuilder->CreateInBoundsGEP(ifaceMethodExtVar, 0, interfaceEntry->mStartVirtualIdx - ifaceMethodExtStart);
else else
vtablePtr = mBfIRBuilder->CreateInBoundsGEP(classVDataVar, 0, iFaceMethodStartIdx + interfaceEntry->mStartVirtualIdx); vtablePtr = mBfIRBuilder->CreateInBoundsGEP(classVDataVar, 0, iFaceMethodStartIdx + interfaceEntry->mStartVirtualIdx);
@ -9767,7 +9779,9 @@ BfModule* BfModule::GetSpecializedMethodModule(const SizedArrayImpl<BfProject*>&
{ {
String specModuleName = mModuleName; String specModuleName = mModuleName;
for (auto bfProject : projectList) for (auto bfProject : projectList)
specModuleName += StrFormat("@%s", bfProject->mName.c_str()); {
specModuleName += StrFormat("@%s", bfProject->mSafeName.c_str());
}
specModule = new BfModule(mContext, specModuleName); specModule = new BfModule(mContext, specModuleName);
specModule->mProject = mainModule->mProject; specModule->mProject = mainModule->mProject;
specModule->mParentModule = mainModule; specModule->mParentModule = mainModule;
@ -12093,11 +12107,6 @@ void BfModule::AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInsta
BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags) BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags)
{ {
if (mIsConstModule)
{
NOP;
}
if ((flags & BfGetMethodInstanceFlag_ResultNotUsed) != 0) if ((flags & BfGetMethodInstanceFlag_ResultNotUsed) != 0)
return BfModuleMethodInstance(methodInstance, BfIRValue()); return BfModuleMethodInstance(methodInstance, BfIRValue());
@ -12291,11 +12300,6 @@ BfModule* BfModule::GetOrCreateMethodModule(BfMethodInstance* methodInstance)
BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags, BfTypeInstance* foreignType) BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags, BfTypeInstance* foreignType)
{ {
if (mIsConstModule)
{
NOP;
}
if (methodDef->mMethodType == BfMethodType_Init) if (methodDef->mMethodType == BfMethodType_Init)
return BfModuleMethodInstance(); return BfModuleMethodInstance();
@ -12417,11 +12421,13 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline); auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline);
defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoReference);
if (mIsConstModule) if (mIsConstModule)
{ {
defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoReference); defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_MethodInstanceOnly);
if (!mCompiler->mIsResolveOnly) if (!mCompiler->mIsResolveOnly)
defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoForceReification | BfGetMethodInstanceFlag_Unreified | BfGetMethodInstanceFlag_NoReference); defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoForceReification | BfGetMethodInstanceFlag_Unreified | BfGetMethodInstanceFlag_MethodInstanceOnly);
} }
// Not extern // Not extern
@ -12624,7 +12630,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
{ {
methodInstance = methodInstGroup->mDefault; methodInstance = methodInstGroup->mDefault;
if ((methodInstance != NULL) && ((flags & BfGetMethodInstanceFlag_NoReference) != 0)) if ((methodInstance != NULL) && ((flags & BfGetMethodInstanceFlag_MethodInstanceOnly) != 0))
return methodInstance; return methodInstance;
if ((methodInstance != NULL) && (isReified) && (!methodInstance->mIsReified)) if ((methodInstance != NULL) && (isReified) && (!methodInstance->mIsReified))
@ -12735,7 +12741,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
{ {
methodInstance = *methodInstancePtr; methodInstance = *methodInstancePtr;
if ((flags & BfGetMethodInstanceFlag_NoReference) != 0) if ((flags & BfGetMethodInstanceFlag_MethodInstanceOnly) != 0)
return methodInstance; return methodInstance;
if ((methodInstance->mRequestedByAutocomplete) && (!mCompiler->IsAutocomplete())) if ((methodInstance->mRequestedByAutocomplete) && (!mCompiler->IsAutocomplete()))
@ -12854,6 +12860,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
return BfModuleMethodInstance(methodInstance, BfIRFunction()); return BfModuleMethodInstance(methodInstance, BfIRFunction());
else else
{ {
if ((flags & (BfGetMethodInstanceFlag_MethodInstanceOnly | BfGetMethodInstanceFlag_NoReference)) != 0)
return methodInstance;
if (methodInstance->mDeclModule != this) if (methodInstance->mDeclModule != this)
return ReferenceExternalMethodInstance(methodInstance, flags); return ReferenceExternalMethodInstance(methodInstance, flags);
@ -12887,6 +12896,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
auto specMethodInstance = specModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_ExplicitSpecializedModule)); auto specMethodInstance = specModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_ExplicitSpecializedModule));
if (mAwaitingInitFinish) if (mAwaitingInitFinish)
return BfModuleMethodInstance(specMethodInstance.mMethodInstance, BfIRFunction()); return BfModuleMethodInstance(specMethodInstance.mMethodInstance, BfIRFunction());
if ((flags & (BfGetMethodInstanceFlag_MethodInstanceOnly | BfGetMethodInstanceFlag_NoReference)) != 0)
return specMethodInstance.mMethodInstance;
return ReferenceExternalMethodInstance(specMethodInstance.mMethodInstance, flags); return ReferenceExternalMethodInstance(specMethodInstance.mMethodInstance, flags);
} }
@ -13247,9 +13258,10 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
} }
} }
if (mIsScratchModule) if ((mIsScratchModule) && (mCompiler->mIsResolveOnly))
{ {
// Just fake it for the extern and unspecialized modules // Just fake it for the extern and unspecialized modules
// We can't do this for compilation because unreified methods with default params need to get acutal global variable refs
return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true); return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true);
} }
@ -14935,7 +14947,7 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly)
bindResult.mWantsArgs = true; bindResult.mWantsArgs = true;
{ {
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true); SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true);
exprEvaluator.ResolveArgValues(argValues, BfResolveArgFlag_DeferParamEval); exprEvaluator.ResolveArgValues(argValues, BfResolveArgsFlag_DeferParamEval);
SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(exprEvaluator.mFunctionBindResult, &bindResult); SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(exprEvaluator.mFunctionBindResult, &bindResult);
exprEvaluator.MatchConstructor(targetRefNode, NULL, target, targetType, argValues, true, true); exprEvaluator.MatchConstructor(targetRefNode, NULL, target, targetType, argValues, true, true);
} }
@ -14978,7 +14990,7 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly)
// Do it again, but without mIgnoreWrites set // Do it again, but without mIgnoreWrites set
BfResolvedArgs argValues; BfResolvedArgs argValues;
argValues.Init(&ctorInvocation->mArguments); argValues.Init(&ctorInvocation->mArguments);
exprEvaluator.ResolveArgValues(argValues, BfResolveArgFlag_DeferParamEval); exprEvaluator.ResolveArgValues(argValues, BfResolveArgsFlag_DeferParamEval);
BfFunctionBindResult bindResult; BfFunctionBindResult bindResult;
bindResult.mSkipThis = true; bindResult.mSkipThis = true;
@ -16272,7 +16284,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
OutputDebugStrF("Expr: %@ %d\n", argValues.mArguments->mVals, argValues.mArguments->mSize); OutputDebugStrF("Expr: %@ %d\n", argValues.mArguments->mVals, argValues.mArguments->mSize);
} }
} }
exprEvaluator.ResolveArgValues(argValues, BfResolveArgFlag_DeferParamEval); exprEvaluator.ResolveArgValues(argValues, BfResolveArgsFlag_DeferParamEval);
BfTypedValue appendIdxVal; BfTypedValue appendIdxVal;
if (methodDef->mHasAppend) if (methodDef->mHasAppend)

View file

@ -9768,7 +9768,7 @@ BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targe
auto dataType = GetPrimitiveType(BfTypeCode_IntPtr); auto dataType = GetPrimitiveType(BfTypeCode_IntPtr);
if (!methodRefMethod.mFunc) if (!methodRefMethod.mFunc)
{ {
if (HasCompiledOutput()) if ((!methodInstance->mIsUnspecialized) && (HasCompiledOutput()))
AssertErrorState(); AssertErrorState();
return GetDefaultValue(dataType); return GetDefaultValue(dataType);
} }

View file

@ -593,6 +593,7 @@ void BfMethodInstance::CopyFrom(BfMethodInstance* methodInstance)
*mMethodInfoEx->mClosureInstanceInfo = *methodInstance->mMethodInfoEx->mClosureInstanceInfo; *mMethodInfoEx->mClosureInstanceInfo = *methodInstance->mMethodInfoEx->mClosureInstanceInfo;
} }
} }
mHasMethodRefType = false;
mHasBeenProcessed = false; mHasBeenProcessed = false;
mIRFunction = BfIRValue(); mIRFunction = BfIRValue();
mMethodProcessRequest = NULL; mMethodProcessRequest = NULL;

View file

@ -74,7 +74,8 @@ enum BfGetMethodInstanceFlags : uint16
BfGetMethodInstanceFlag_DisableObjectAccessChecks = 0x200, BfGetMethodInstanceFlag_DisableObjectAccessChecks = 0x200,
BfGetMethodInstanceFlag_NoInline = 0x400, BfGetMethodInstanceFlag_NoInline = 0x400,
BfGetMethodInstanceFlag_DepthExceeded = 0x800, BfGetMethodInstanceFlag_DepthExceeded = 0x800,
BfGetMethodInstanceFlag_NoReference = 0x1000 BfGetMethodInstanceFlag_NoReference = 0x1000,
BfGetMethodInstanceFlag_MethodInstanceOnly = 0x2000
}; };
class BfDependencyMap class BfDependencyMap

View file

@ -3689,6 +3689,29 @@ BF_EXPORT BfProject* BF_CALLTYPE BfSystem_CreateProject(BfSystem* bfSystem, cons
bfProject->mSystem = bfSystem; bfProject->mSystem = bfSystem;
bfProject->mIdx = (int)bfSystem->mProjects.size(); bfProject->mIdx = (int)bfSystem->mProjects.size();
bfSystem->mProjects.push_back(bfProject); bfSystem->mProjects.push_back(bfProject);
String safeProjectName = projectName;
for (auto& c : safeProjectName)
{
if (((c >= 'A') && (c <= 'Z')) ||
((c >= 'a') && (c <= 'z')) ||
((c >= '0') && (c <= '9')))
{
// Leave
}
else
c = '_';
}
String tryName = safeProjectName;
for (int i = 2; true; i++)
{
if (bfSystem->mUsedSafeProjectNames.Add(ToUpper(tryName)))
break;
tryName = safeProjectName + StrFormat("_%d", i);
}
bfProject->mSafeName = tryName;
BfLogSys(bfSystem, "Creating project %p\n", bfProject); BfLogSys(bfSystem, "Creating project %p\n", bfProject);
return bfProject; return bfProject;
} }
@ -3774,6 +3797,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_Delete(BfProject* bfProject)
bfProject->mDeleteStage = BfProject::DeleteStage_Queued; bfProject->mDeleteStage = BfProject::DeleteStage_Queued;
bfSystem->mProjectDeleteQueue.push_back(bfProject); bfSystem->mProjectDeleteQueue.push_back(bfProject);
bfSystem->mUsedSafeProjectNames.Remove(bfProject->mSafeName);
BF_ASSERT(bfSystem->mProjects[bfProject->mIdx] == bfProject); BF_ASSERT(bfSystem->mProjects[bfProject->mIdx] == bfProject);
bool wasRemoved = bfSystem->mProjects.Remove(bfProject); bool wasRemoved = bfSystem->mProjects.Remove(bfProject);

View file

@ -1079,6 +1079,7 @@ public:
public: public:
BfSystem* mSystem; BfSystem* mSystem;
String mName; String mName;
String mSafeName;
Array<BfProject*> mDependencies; Array<BfProject*> mDependencies;
BfTargetType mTargetType; BfTargetType mTargetType;
BfCodeGenOptions mCodeGenOptions; BfCodeGenOptions mCodeGenOptions;
@ -1409,6 +1410,7 @@ public:
CritSect mDataLock; // short-lived, hold only while active modifying data CritSect mDataLock; // short-lived, hold only while active modifying data
// The following are protected by mDataLock: // The following are protected by mDataLock:
HashSet<String> mUsedSafeProjectNames;
Array<BfProject*> mProjects; Array<BfProject*> mProjects;
Array<BfProject*> mProjectDeleteQueue; Array<BfProject*> mProjectDeleteQueue;
Array<BfParser*> mParsers; Array<BfParser*> mParsers;