From 062170d9e0af8a89a6f9fc3ba368f1938b7546fa Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 14 Jan 2025 12:54:24 -0800 Subject: [PATCH] Improved comptime TypeDeclaration support, reworked base type population --- IDEHelper/Compiler/BfModule.cpp | 18 +++++++++++------- IDEHelper/Compiler/BfModule.h | 1 + IDEHelper/Compiler/BfModuleTypeUtils.cpp | 9 +++++++-- IDEHelper/Compiler/BfResolvedTypeUtils.h | 1 + IDEHelper/Compiler/CeMachine.cpp | 2 ++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 2912e599..03ed5377 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/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 prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || mCurMethodInstance->mIsUnspecialized || mCurTypeInstance->mResolvingVarField); diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 4020bdcf..7f0213cb 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/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, diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 61c67be3..871e8b28 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -4240,7 +4240,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if ((checkType != NULL) && (!checkType->IsInterface()) && (populateBase)) { SetAndRestoreValue 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); diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 8b37ad1f..7b0b3461 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/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, diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index f47495d9..2e1449fb 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/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);