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

Reworked splattability in mixins

This commit is contained in:
Brian Fiete 2020-12-26 10:16:51 -08:00
parent c967d459f8
commit 3b1f1634ac
5 changed files with 45 additions and 36 deletions

View file

@ -586,7 +586,6 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
if (methodDeclaration->mNameNode != NULL) if (methodDeclaration->mNameNode != NULL)
methodDef->mName = methodDeclaration->mNameNode->ToString(); methodDef->mName = methodDeclaration->mNameNode->ToString();
methodDef->mMethodType = BfMethodType_Mixin; methodDef->mMethodType = BfMethodType_Mixin;
methodDef->mIsNoSplat = true;
} }
else else
{ {

View file

@ -5322,7 +5322,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
{ {
if (paramType->IsStruct()) if (paramType->IsStruct())
{ {
if ((!doingThis) || (!methodDef->mIsMutating && methodInstance->AllowsSplatting())) if ((!doingThis) || (!methodDef->mIsMutating && methodInstance->AllowsSplatting(paramIdx)))
{ {
BfTypeCode loweredTypeCode = BfTypeCode_None; BfTypeCode loweredTypeCode = BfTypeCode_None;
BfTypeCode loweredTypeCode2 = BfTypeCode_None; BfTypeCode loweredTypeCode2 = BfTypeCode_None;
@ -5778,7 +5778,7 @@ void BfExprEvaluator::PushThis(BfAstNode* targetSrc, BfTypedValue argVal, BfMeth
if (mModule->mIsConstModule) if (mModule->mIsConstModule)
allowThisSplatting = owner->IsTypedPrimitive() || owner->IsValuelessType(); allowThisSplatting = owner->IsTypedPrimitive() || owner->IsValuelessType();
else else
allowThisSplatting = methodInstance->AllowsThisSplatting(); allowThisSplatting = methodInstance->AllowsSplatting(-1);
if ((!allowThisSplatting) || (methodDef->mIsMutating)) if ((!allowThisSplatting) || (methodDef->mIsMutating))
{ {
@ -5788,7 +5788,7 @@ void BfExprEvaluator::PushThis(BfAstNode* targetSrc, BfTypedValue argVal, BfMeth
} }
auto thisType = methodInstance->GetThisType(); auto thisType = methodInstance->GetThisType();
PushArg(argVal, irArgs, !methodInstance->AllowsThisSplatting(), thisType->IsPointer()); PushArg(argVal, irArgs, !methodInstance->AllowsSplatting(-1), thisType->IsPointer());
} }
void BfExprEvaluator::FinishDeferredEvals(SizedArrayImpl<BfResolvedArg>& argValues) void BfExprEvaluator::FinishDeferredEvals(SizedArrayImpl<BfResolvedArg>& argValues)
@ -10832,7 +10832,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
bool isStructTarget = (target) && (target.mType->IsStruct()); bool isStructTarget = (target) && (target.mType->IsStruct());
bool bindCapturesThis = bindMethodInstance->HasThis() && !isStructTarget; bool bindCapturesThis = bindMethodInstance->HasThis() && !isStructTarget;
bool needsSplat = (isStructTarget) && (!bindMethodInstance->mMethodDef->mIsMutating) && (bindMethodInstance->AllowsSplatting()); bool needsSplat = (isStructTarget) && (!bindMethodInstance->mMethodDef->mIsMutating) && (bindMethodInstance->AllowsSplatting(-1));
bool captureThisByValue = isStructTarget; bool captureThisByValue = isStructTarget;
if (bindMethodInstance->mMethodDef->mIsLocalMethod) if (bindMethodInstance->mMethodDef->mIsLocalMethod)
{ {

View file

@ -15565,6 +15565,11 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis)) if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis))
paramIdx = -1; paramIdx = -1;
if (methodInstance->mMethodDef->mName == "Invoke@GetFFIType$wPb")
{
NOP;
}
int argCount = methodInstance->GetIRFunctionParamCount(this); int argCount = methodInstance->GetIRFunctionParamCount(this);
while (argIdx < argCount) while (argIdx < argCount)
@ -15593,8 +15598,8 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
resolvedTypeRef = mCurMethodState->mClosureState->mClosureType; resolvedTypeRef = mCurMethodState->mClosureState->mClosureType;
else else
resolvedTypeRef = methodInstance->GetThisType(); resolvedTypeRef = methodInstance->GetThisType();
isSplattable = (!mIsConstModule) && (resolvedTypeRef->IsSplattable()) && (methodInstance->AllowsThisSplatting()); isSplattable = (!mIsConstModule) && (resolvedTypeRef->IsSplattable()) && (methodInstance->AllowsSplatting(-1));
tryLowering = (!mIsConstModule) && (methodInstance->AllowsThisSplatting()); tryLowering = (!mIsConstModule) && (methodInstance->AllowsSplatting(-1));
} }
else else
{ {
@ -15602,7 +15607,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
resolvedTypeRef = methodInstance->GetParamType(paramIdx); resolvedTypeRef = methodInstance->GetParamType(paramIdx);
if (resolvedTypeRef->IsMethodRef()) if (resolvedTypeRef->IsMethodRef())
isSplattable = true; isSplattable = true;
else if ((!mIsConstModule) && (resolvedTypeRef->IsSplattable()) && (methodInstance->AllowsSplatting())) else if ((!mIsConstModule) && (resolvedTypeRef->IsSplattable()) && (methodInstance->AllowsSplatting(paramIdx)))
{ {
auto resolvedTypeInst = resolvedTypeRef->ToTypeInstance(); auto resolvedTypeInst = resolvedTypeRef->ToTypeInstance();
if ((resolvedTypeInst != NULL) && (resolvedTypeInst->mIsCRepr)) if ((resolvedTypeInst != NULL) && (resolvedTypeInst->mIsCRepr))
@ -16756,7 +16761,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp
else else
paramVar->mValue = mBfIRBuilder->GetFakeVal(); paramVar->mValue = mBfIRBuilder->GetFakeVal();
if ((!mIsConstModule) && (thisType->IsSplattable()) && (methodInstance->AllowsThisSplatting())) if ((!mIsConstModule) && (thisType->IsSplattable()) && (methodInstance->AllowsSplatting(-1)))
{ {
if (!thisType->IsTypedPrimitive()) if (!thisType->IsTypedPrimitive())
paramVar->mIsSplat = true; paramVar->mIsSplat = true;
@ -16848,9 +16853,9 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp
{ {
paramVar->mIsSplat = true; paramVar->mIsSplat = true;
} }
else if ((resolvedType->IsComposite()) && (resolvedType->IsSplattable())) else if ((!mIsConstModule) && (resolvedType->IsComposite()) && (resolvedType->IsSplattable()))
{ {
if ((!mIsConstModule) && (methodInstance->AllowsSplatting())) if (methodInstance->AllowsSplatting(paramIdx))
{ {
int splatCount = resolvedType->GetSplatCount(); int splatCount = resolvedType->GetSplatCount();
if (argIdx + splatCount <= mCompiler->mOptions.mMaxSplatRegs) if (argIdx + splatCount <= mCompiler->mOptions.mMaxSplatRegs)
@ -21563,7 +21568,7 @@ genericParam->mExternType = GetPrimitiveType(BfTypeCode_Var);
{ {
methodParam.mIsSplat = true; methodParam.mIsSplat = true;
} }
else if ((checkType->IsComposite()) && (methodInstance->AllowsSplatting())) else if ((checkType->IsComposite()) && (methodInstance->AllowsSplatting(paramIdx)))
{ {
PopulateType(checkType, BfPopulateType_Data); PopulateType(checkType, BfPopulateType_Data);
if (checkType->IsSplattable()) if (checkType->IsSplattable())

View file

@ -733,7 +733,7 @@ int BfMethodInstance::GetStructRetIdx(bool forceStatic)
return 0; return 0;
if (!owner->IsValueType()) if (!owner->IsValueType())
return 1; return 1;
if ((mMethodDef->mIsMutating) || (!owner->IsSplattable()) || ((!AllowsThisSplatting()) && (!owner->GetLoweredType(BfTypeUsage_Parameter)))) if ((mMethodDef->mIsMutating) || (!owner->IsSplattable()) || ((!AllowsSplatting(-1)) && (!owner->GetLoweredType(BfTypeUsage_Parameter))))
return 1; return 1;
return 0; return 0;
} }
@ -800,22 +800,28 @@ bool BfMethodInstance::IsTestMethod()
(mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes != NULL) && (mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes->Contains(GetOwner()->mModule->mCompiler->mTestAttributeTypeDef)); (mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes != NULL) && (mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes->Contains(GetOwner()->mModule->mCompiler->mTestAttributeTypeDef));
} }
bool BfMethodInstance::AllowsSplatting() bool BfMethodInstance::AllowsSplatting(int paramIdx)
{ {
if (mCallingConvention != BfCallingConvention_Unspecified) if (paramIdx == -1)
return false; {
if (mMethodDef->mIsNoSplat) if (mCallingConvention != BfCallingConvention_Unspecified)
return false; return false;
return true; if (mMethodDef->mIsNoSplat)
} return false;
return !mMethodDef->HasNoThisSplat();
bool BfMethodInstance::AllowsThisSplatting() }
{ else
if (mCallingConvention != BfCallingConvention_Unspecified) {
return false; if (mCallingConvention != BfCallingConvention_Unspecified)
if (mMethodDef->mIsNoSplat) return false;
return false; if ((mMethodDef->mIsNoSplat) || (mMethodDef->mMethodType == BfMethodType_Mixin))
return !mMethodDef->HasNoThisSplat(); {
if (IsImplicitCapture(paramIdx))
return true;
return false;
}
return true;
}
} }
bool BfMethodInstance::HasThis() bool BfMethodInstance::HasThis()
@ -839,7 +845,7 @@ BfType* BfMethodInstance::GetThisType()
{ {
auto thisType = mParams[0].mResolvedType; auto thisType = mParams[0].mResolvedType;
auto owner = GetOwner(); auto owner = GetOwner();
if ((thisType->IsValueType()) && ((mMethodDef->mIsMutating) || (!AllowsSplatting())) && (!thisType->GetLoweredType(BfTypeUsage_Parameter))) if ((thisType->IsValueType()) && ((mMethodDef->mIsMutating) || (!AllowsSplatting(-1))) && (!thisType->GetLoweredType(BfTypeUsage_Parameter)))
return owner->mModule->CreatePointerType(thisType); return owner->mModule->CreatePointerType(thisType);
return thisType; return thisType;
} }
@ -926,7 +932,7 @@ BfType* BfMethodInstance::GetParamType(int paramIdx, bool returnUnderlyingParams
{ {
BF_FATAL("Wrong 'this' index"); BF_FATAL("Wrong 'this' index");
} }
if ((thisType->IsValueType()) && ((mMethodDef->mIsMutating) || (!AllowsSplatting())) && (!thisType->GetLoweredType(BfTypeUsage_Parameter))) if ((thisType->IsValueType()) && ((mMethodDef->mIsMutating) || (!AllowsSplatting(paramIdx))) && (!thisType->GetLoweredType(BfTypeUsage_Parameter)))
return owner->mModule->CreatePointerType(thisType); return owner->mModule->CreatePointerType(thisType);
return thisType; return thisType;
} }
@ -959,7 +965,7 @@ bool BfMethodInstance::GetParamIsSplat(int paramIdx)
{ {
BF_ASSERT(!mMethodDef->mIsStatic); BF_ASSERT(!mMethodDef->mIsStatic);
auto owner = mMethodInstanceGroup->mOwner; auto owner = mMethodInstanceGroup->mOwner;
if ((owner->IsValueType()) && (mMethodDef->mIsMutating || !AllowsSplatting())) if ((owner->IsValueType()) && (mMethodDef->mIsMutating || !AllowsSplatting(paramIdx)))
return false; return false;
return owner->mIsSplattable; return owner->mIsSplattable;
} }
@ -1172,7 +1178,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType,
{ {
checkType = checkType->GetUnderlyingType(); checkType = checkType->GetUnderlyingType();
} }
else if ((!module->mIsConstModule) && (checkType->IsSplattable()) && (AllowsThisSplatting())) else if ((!module->mIsConstModule) && (checkType->IsSplattable()) && (AllowsSplatting(-1)))
{ {
doSplat = true; doSplat = true;
} }
@ -1189,7 +1195,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType,
{ {
checkType = checkType->GetUnderlyingType(); checkType = checkType->GetUnderlyingType();
} }
else if ((!module->mIsConstModule) && (checkType->IsSplattable()) && (AllowsSplatting())) else if ((!module->mIsConstModule) && (checkType->IsSplattable()) && (AllowsSplatting(paramIdx)))
{ {
doSplat = true; doSplat = true;
} }

View file

@ -906,8 +906,7 @@ public:
bool AlwaysInline(); bool AlwaysInline();
BfImportCallKind GetImportCallKind(); BfImportCallKind GetImportCallKind();
bool IsTestMethod(); bool IsTestMethod();
bool AllowsSplatting(); bool AllowsSplatting(int paramIdx);
bool AllowsThisSplatting();
int GetParamCount(); int GetParamCount();
int GetImplicitParamCount(); int GetImplicitParamCount();
void GetParamName(int paramIdx, StringImpl& name); void GetParamName(int paramIdx, StringImpl& name);