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

View file

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

View file

@ -1658,7 +1658,7 @@ public:
BfTypedValue PrepareConst(BfTypedValue& typedValue); BfTypedValue PrepareConst(BfTypedValue& typedValue);
void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal); void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL); 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 RemoveReadOnly(BfTypedValue typedValue);
BfTypedValue CopyValue(const BfTypedValue& typedValue); BfTypedValue CopyValue(const BfTypedValue& typedValue);
BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL); BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);

View file

@ -10649,18 +10649,21 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
genericTypeInst->mTypeDef = typeDef; genericTypeInst->mTypeDef = typeDef;
auto parentTypeInstance = outerTypeInstance; if (commonOuterType != NULL)
if ((parentTypeInstance != NULL) && (parentTypeInstance->IsTypeAlias())) {
parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance(); auto parentTypeInstance = outerTypeInstance;
if ((parentTypeInstance != NULL) && (parentTypeInstance->IsGenericTypeInstance())) if ((parentTypeInstance != NULL) && (parentTypeInstance->IsTypeAlias()))
{ parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance();
genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, parentTypeInstance->mGenericTypeInfo->mMaxGenericDepth); if ((parentTypeInstance != NULL) && (parentTypeInstance->IsGenericTypeInstance()))
for (int i = 0; i < startDefGenericParamIdx; i++)
{ {
genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(parentTypeInstance->mGenericTypeInfo->mGenericParams[i]->AddRef()); genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, parentTypeInstance->mGenericTypeInfo->mMaxGenericDepth);
genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.push_back(parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments[i]); for (int i = 0; i < startDefGenericParamIdx; i++)
auto typeGenericArg = genericTypeInst->mGenericTypeInfo->mTypeGenericArguments[i]; {
genericTypeInst->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType(); genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(parentTypeInstance->mGenericTypeInfo->mGenericParams[i]->AddRef());
genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.push_back(parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments[i]);
auto typeGenericArg = genericTypeInst->mGenericTypeInfo->mTypeGenericArguments[i];
genericTypeInst->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType();
}
} }
} }
@ -13912,7 +13915,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
return; return;
} }
str += "method reference "; str += "method reference ";
str += MethodToString(methodInstance); str += MethodToString(methodInstance, BfMethodNameFlag_NoAst);
return; return;
} }
else if (resolvedType->IsTypeInstance()) else if (resolvedType->IsTypeInstance())

View file

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

View file

@ -104,6 +104,23 @@ namespace Tests
return total; 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] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -127,6 +144,11 @@ namespace Tests
Test.Assert(self.Method5b(sa, sa2, sa3) == sa3); Test.Assert(self.Method5b(sa, sa2, sa3) == sa3);
Test.Assert(AddFloats(1.0f, 2, 3) == 6.0f); Test.Assert(AddFloats(1.0f, 2, 3) == 6.0f);
InCallPtr("ABC");
InCallObj("Hey");
Valueless valueless;
InCallValueless(valueless);
} }
} }
} }