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

Generic outer type fixes, 'in' fixes

This commit is contained in:
Brian Fiete 2022-01-22 07:57:02 -05:00
parent 27a792e559
commit 89b597c913
6 changed files with 67 additions and 26 deletions

View file

@ -6592,7 +6592,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
if (!mModule->mCompiler->mIsResolveOnly)
sCallIdx++;
int callIdx = sCallIdx;
if (callIdx == 0x000020F9)
if (callIdx == 0x000015CB)
{
NOP;
}
@ -7356,8 +7356,20 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
if ((wantType->IsRef()) && (!argValue.mType->IsRef()) &&
(((callFlags & BfCreateCallFlags_AllowImplicitRef) != 0) || (wantType->IsIn())))
{
auto underlyingType = wantType->GetUnderlyingType();
if (mModule->mCurMethodState != NULL)
{
SetAndRestoreValue<BfScopeData*> prevScopeData(mModule->mCurMethodState->mOverrideScope, boxScopeData);
argValue = mModule->Cast(refNode, argValue, underlyingType);
}
else
argValue = mModule->Cast(refNode, argValue, underlyingType);
if (argValue)
argValue = mModule->ToRef(argValue, (BfRefType*)wantType);
}
else
{
if (mModule->mCurMethodState != NULL)
{
SetAndRestoreValue<BfScopeData*> prevScopeData(mModule->mCurMethodState->mOverrideScope, boxScopeData);
@ -7365,6 +7377,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
}
else
argValue = mModule->Cast(refNode, argValue, wantType);
}
if (!argValue)
{

View file

@ -10917,7 +10917,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
methodName += methodInst->GetParamName(paramIdx);
auto paramInitializer = methodInst->GetParamInitializer(paramIdx);
if (paramInitializer != NULL)
if ((paramInitializer != NULL) && ((methodNameFlags & BfMethodNameFlag_NoAst) == 0))
{
methodName += " = ";
methodName += paramInitializer->ToString();
@ -12120,7 +12120,8 @@ BfTypedValue BfModule::ToRef(BfTypedValue typedValue, BfRefType* refType)
if (refType->mRefKind == BfRefType::RefKind_Mut)
refType = CreateRefType(typedValue.mType);
typedValue = MakeAddressable(typedValue);
if (!typedValue.mType->IsValuelessType())
typedValue = MakeAddressable(typedValue, false, true);
return BfTypedValue(typedValue.mValue, refType);
}
@ -12377,12 +12378,13 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal
checkTypeLambda(typedValue.mType, addrVal);
}
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable)
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable, bool forceAddressable)
{
bool wasReadOnly = typedVal.IsReadOnly();
if ((typedVal.mType->IsValueType()) &&
(!typedVal.mType->IsValuelessType()))
if ((forceAddressable) ||
((typedVal.mType->IsValueType()) &&
(!typedVal.mType->IsValuelessType())))
{
wasReadOnly = true; // Any non-addr is implicitly read-only

View file

@ -1658,7 +1658,7 @@ public:
BfTypedValue PrepareConst(BfTypedValue& typedValue);
void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL);
BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false);
BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false, bool forceAddressable = false);
BfTypedValue RemoveReadOnly(BfTypedValue typedValue);
BfTypedValue CopyValue(const BfTypedValue& typedValue);
BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);

View file

@ -10649,6 +10649,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
genericTypeInst->mTypeDef = typeDef;
if (commonOuterType != NULL)
{
auto parentTypeInstance = outerTypeInstance;
if ((parentTypeInstance != NULL) && (parentTypeInstance->IsTypeAlias()))
parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance();
@ -10663,6 +10665,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
genericTypeInst->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType();
}
}
}
int wantedGenericParams = genericParamCount - startDefGenericParamIdx;
int genericArgDiffCount = (int)genericArguments.size() - wantedGenericParams;
@ -13912,7 +13915,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
return;
}
str += "method reference ";
str += MethodToString(methodInstance);
str += MethodToString(methodInstance, BfMethodNameFlag_NoAst);
return;
}
else if (resolvedType->IsTypeInstance())

View file

@ -62,7 +62,8 @@ enum BfMethodNameFlags : uint8
BfMethodNameFlag_OmitTypeName = 2,
BfMethodNameFlag_IncludeReturnType = 4,
BfMethodNameFlag_OmitParams = 8,
BfMethodNameFlag_IncludeMut = 0x10
BfMethodNameFlag_IncludeMut = 0x10,
BfMethodNameFlag_NoAst = 0x20
};
enum BfGetMethodInstanceFlags : uint16

View file

@ -104,6 +104,23 @@ namespace Tests
return total;
}
struct Valueless
{
}
public static void InCallPtr(in char8* val)
{
}
public static void InCallObj(in Object val)
{
}
public static void InCallValueless(in Valueless val)
{
}
[Test]
public static void TestBasics()
{
@ -127,6 +144,11 @@ namespace Tests
Test.Assert(self.Method5b(sa, sa2, sa3) == sa3);
Test.Assert(AddFloats(1.0f, 2, 3) == 6.0f);
InCallPtr("ABC");
InCallObj("Hey");
Valueless valueless;
InCallValueless(valueless);
}
}
}