Browse Source

Improved comptime TypeDeclaration support, reworked base type population

Brian Fiete 8 months ago
parent
commit
062170d9e0

+ 11 - 7
IDEHelper/Compiler/BfModule.cpp

@@ -6099,7 +6099,7 @@ BfIRValue BfModule::GetTypeTypeData(BfType* type, BfCreateTypeDataContext& ctx,
 	if (type->IsObject())
 	{
 		typeFlags |= BfTypeFlags_Object;
-		if (typeInstance->mDefineState >= BfTypeDefineState_DefinedAndMethodsSlotted)
+		if ((!wantsTypeDecl) && (typeInstance->mDefineState >= BfTypeDefineState_DefinedAndMethodsSlotted))
 		{
 			BfMethodInstance* methodInstance = typeInstance->mVirtualMethodTable[mCompiler->GetVTableMethodOffset() + 0].mImplementingMethod;
 			if ((methodInstance != NULL) && (methodInstance->GetOwner() != mContext->mBfObjectType))
@@ -22007,7 +22007,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
 		}
 		else if (((methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYINGREF) || (methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYING)) &&
 			(mCurTypeInstance->IsEnum()) && (!mCurTypeInstance->IsBoxed()))
-		{
+		{			
 			BfIRValue ret;
 			// Unfortunate DebugLoc shenanigans-
 			//  Our params get removed if we don't have any DebugLocs, but we don't want to actually be able to step into this method,
@@ -22016,10 +22016,14 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
 			mBfIRBuilder->ClearDebugLocation();
 			BfIRValue fromBool;
 			mBfIRBuilder->RestoreDebugLocation();
-			if (!mCurTypeInstance->IsValuelessType())
-				ret = mBfIRBuilder->CreateRet(GetThis().mValue);
-			else
-				mBfIRBuilder->CreateRetVoid();
+
+			if (!mCompiler->mIsResolveOnly)
+			{
+				if (!mCurTypeInstance->IsValuelessType())
+					ret = mBfIRBuilder->CreateRet(GetThis().mValue);
+				else
+					mBfIRBuilder->CreateRetVoid();
+			}
 			//ExtendLocalLifetimes(0);
 			EmitLifetimeEnds(&mCurMethodState->mHeadScope);
 
@@ -24071,7 +24075,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
 	BF_ASSERT((mCompiler->mCeMachine == NULL) || (!mCompiler->mCeMachine->mDbgPaused));
 
 	BP_ZONE("BfModule::DoMethodDeclaration");
-
+	
 	// We could trigger a DoMethodDeclaration from a const resolver or other location, so we reset it here
 	//  to effectively make mIgnoreWrites method-scoped
 	SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || mCurMethodInstance->mIsUnspecialized || mCurTypeInstance->mResolvingVarField);

+ 1 - 0
IDEHelper/Compiler/BfModule.h

@@ -44,6 +44,7 @@ enum BfPopulateType
 	BfPopulateType_IdentityNoRemapAlias,
 	BfPopulateType_Declaration,
 	BfPopulateType_BaseType,
+	BfPopulateType_CustomAttributes,
 	BfPopulateType_Interfaces_Direct,
 	BfPopulateType_AllowStaticMethods,
 	BfPopulateType_Interfaces_All,

+ 7 - 2
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -4240,7 +4240,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 			if ((checkType != NULL) && (!checkType->IsInterface()) && (populateBase))
 			{
 				SetAndRestoreValue<BfTypeInstance*> prevBaseType(mContext->mCurTypeState->mCurBaseType, checkType->ToTypeInstance());
-				PopulateType(checkType, (populateType <= BfPopulateType_BaseType) ? BfPopulateType_BaseType : BfPopulateType_Data);
+				PopulateType(checkType, BfPopulateType_Declaration);
 			}
 
 			if (typeInstance->mDefineState >= BfTypeDefineState_Defined)
@@ -4466,7 +4466,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 					baseTypeInst = ResolveTypeDef(mCompiler->mBfObjectTypeDef)->ToTypeInstance();
 			}
 		}
-		PopulateType(baseTypeInst, BfPopulateType_Data);
+
+		if (populateType > BfPopulateType_CustomAttributes)
+			PopulateType(baseTypeInst, BfPopulateType_Data);
 
 		typeInstance->mBaseTypeMayBeIncomplete = false;
 
@@ -4746,6 +4748,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 		}
 	}
 
+	if (typeInstance->mDefineState < BfTypeDefineState_HasCustomAttributes)
+		typeInstance->mDefineState = BfTypeDefineState_HasCustomAttributes;
+
 	if (typeInstance->mTypeOptionsIdx == -2)
 	{
 		SetTypeOptions(typeInstance);

+ 1 - 0
IDEHelper/Compiler/BfResolvedTypeUtils.h

@@ -459,6 +459,7 @@ enum BfTypeDefineState : uint8
 	BfTypeDefineState_Declaring,
 	BfTypeDefineState_Declared,
 	BfTypeDefineState_ResolvingBaseType,
+	BfTypeDefineState_HasCustomAttributes,
 	BfTypeDefineState_HasInterfaces_Direct,
 	BfTypeDefineState_CETypeInit,
 	BfTypeDefineState_CEPostTypeInit,

+ 2 - 0
IDEHelper/Compiler/CeMachine.cpp

@@ -3899,6 +3899,8 @@ addr_ce CeContext::GetReflectTypeDecl(int typeId)
 
 	if (bfType->mDefineState < BfTypeDefineState_HasInterfaces_Direct)
 		ceModule->PopulateType(bfType, BfPopulateType_Interfaces_Direct);
+	if (bfType->mDefineState < BfTypeDefineState_HasCustomAttributes)
+		ceModule->PopulateType(bfType, BfPopulateType_CustomAttributes);
 	
 	BfCreateTypeDataContext createTypeDataCtx;
 	auto irData = ceModule->CreateTypeDeclData(bfType);