From 0f33968030b4d1742910a4ba3563342689f71f4f Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 9 Jan 2021 04:20:45 -0800 Subject: [PATCH] Comptime naming fixes --- BeefLibs/corlib/src/Attribute.bf | 12 +++++++- BeefLibs/corlib/src/Compiler.bf | 12 +------- IDE/mintest/minlib/src/System/Attribute.bf | 35 +++++++++++++++++++++- IDEHelper/Backend/BeIRCodeGen.cpp | 20 ++++++------- IDEHelper/Backend/BeModule.cpp | 10 +++---- IDEHelper/Backend/BeModule.h | 20 ++++++------- IDEHelper/Compiler/BfExprEvaluator.cpp | 4 +-- IDEHelper/Compiler/BfIRBuilder.cpp | 20 ++++++------- IDEHelper/Compiler/BfIRBuilder.h | 20 ++++++------- IDEHelper/Compiler/BfModule.cpp | 8 ++--- IDEHelper/Compiler/CeMachine.cpp | 20 ++++++------- 11 files changed, 107 insertions(+), 74 deletions(-) diff --git a/BeefLibs/corlib/src/Attribute.bf b/BeefLibs/corlib/src/Attribute.bf index 34afeb47..8ee8d83f 100644 --- a/BeefLibs/corlib/src/Attribute.bf +++ b/BeefLibs/corlib/src/Attribute.bf @@ -304,7 +304,7 @@ namespace System { } - } + } [AttributeUsage(.Method /*2*/)] public struct IntrinsicAttribute : Attribute @@ -519,4 +519,14 @@ namespace System { } } + + interface IComptimeTypeApply + { + void ApplyToType(Type type); + } + + interface IComptimeMethodApply + { + void ApplyToMethod(Type type); + } } diff --git a/BeefLibs/corlib/src/Compiler.bf b/BeefLibs/corlib/src/Compiler.bf index edc842a6..93ed3d19 100644 --- a/BeefLibs/corlib/src/Compiler.bf +++ b/BeefLibs/corlib/src/Compiler.bf @@ -98,16 +98,6 @@ namespace System public static void EmitDefinition(Type owner, StringView text) { Comptime_EmitDefinition((.)owner.TypeId, text); - } - - interface IComptimeTypeApply - { - void ApplyToType(Type type); - } - - interface IComptimeMethodApply - { - void ApplyToMethod(Type type); - } + } } } diff --git a/IDE/mintest/minlib/src/System/Attribute.bf b/IDE/mintest/minlib/src/System/Attribute.bf index 6318c556..b11d5aff 100644 --- a/IDE/mintest/minlib/src/System/Attribute.bf +++ b/IDE/mintest/minlib/src/System/Attribute.bf @@ -231,7 +231,30 @@ namespace System } - [AttributeUsage(.Method | .Invocation)] + [AttributeUsage(.Method)] + public struct ComptimeAttribute : Attribute + { + public this() + { + + } + + public bool OnlyFromComptime + { + set + { + } + } + + public bool ConstEval + { + set + { + } + } + } + + [AttributeUsage(.Invocation)] public struct ConstEvalAttribute : Attribute { @@ -456,4 +479,14 @@ namespace System { } } + + interface IComptimeTypeApply + { + void ApplyToType(Type type); + } + + interface IComptimeMethodApply + { + void ApplyToMethod(Type type); + } } diff --git a/IDEHelper/Backend/BeIRCodeGen.cpp b/IDEHelper/Backend/BeIRCodeGen.cpp index f4284bf4..76938100 100644 --- a/IDEHelper/Backend/BeIRCodeGen.cpp +++ b/IDEHelper/Backend/BeIRCodeGen.cpp @@ -2646,62 +2646,62 @@ void BeIRCodeGen::HandleNextCmd() SetResult(curId, mBeModule->GetInsertBlock()); } break; - case BfIRCmd_ConstEval_GetBfType: + case BfIRCmd_Comptime_GetBfType: { CMD_PARAM(int32, typeId); CMD_PARAM(BeType*, resultType); - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); inst->mTypeId = typeId; inst->mResultType = resultType; SetResult(curId, inst); } break; - case BfIRCmd_ConstEval_GetReflectType: + case BfIRCmd_Comptime_GetReflectType: { CMD_PARAM(int32, typeId); CMD_PARAM(BeType*, resultType); - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); inst->mTypeId = typeId; inst->mResultType = resultType; SetResult(curId, inst); } break; - case BfIRCmd_ConstEval_DynamicCastCheck: + case BfIRCmd_Comptime_DynamicCastCheck: { CMD_PARAM(BeValue*, value); CMD_PARAM(int32, typeId); CMD_PARAM(BeType*, resultType); - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); inst->mValue = value; inst->mTypeId = typeId; inst->mResultType = resultType; SetResult(curId, inst); } break; - case BfIRCmd_ConstEval_GetVirtualFunc: + case BfIRCmd_Comptime_GetVirtualFunc: { CMD_PARAM(BeValue*, value); CMD_PARAM(int32, virtualTableIdx); CMD_PARAM(BeType*, resultType); - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); inst->mValue = value; inst->mVirtualTableIdx = virtualTableIdx; inst->mResultType = resultType; SetResult(curId, inst); } break; - case BfIRCmd_ConstEval_GetInterfaceFunc: + case BfIRCmd_Comptime_GetInterfaceFunc: { CMD_PARAM(BeValue*, value); CMD_PARAM(int32, ifaceTypeId); CMD_PARAM(int32, methodIdx); CMD_PARAM(BeType*, resultType); - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); inst->mValue = value; inst->mIFaceTypeId = ifaceTypeId; inst->mMethodIdx = methodIdx; diff --git a/IDEHelper/Backend/BeModule.cpp b/IDEHelper/Backend/BeModule.cpp index 39484c71..51b259db 100644 --- a/IDEHelper/Backend/BeModule.cpp +++ b/IDEHelper/Backend/BeModule.cpp @@ -2451,11 +2451,11 @@ String BeModule::ToString(BeFunction* wantFunc) } } break; - DISPLAY_INST1(BeConstEvalGetType, "ConstEvalGetType", mTypeId); - DISPLAY_INST1(BeConstEvalGetReflectType, "ConstEvalGetReflectType", mTypeId); - DISPLAY_INST2(BeConstEvalDynamicCastCheck, "ConstEvalDynamicCastCheck", mValue, mTypeId); - DISPLAY_INST2(BeConstEvalGetVirtualFunc, "ConstEvalGetVirtualFunc", mValue, mVirtualTableIdx); - DISPLAY_INST3(BeConstEvalGetInterfaceFunc, "ConstEvalGetInterfaceFunc", mValue, mIFaceTypeId, mMethodIdx); + DISPLAY_INST1(BeComptimeGetType, "ComptimeGetType", mTypeId); + DISPLAY_INST1(BeComptimeGetReflectType, "ComptimeGetReflectType", mTypeId); + DISPLAY_INST2(BeComptimeDynamicCastCheck, "ComptimeDynamicCastCheck", mValue, mTypeId); + DISPLAY_INST2(BeComptimeGetVirtualFunc, "ComptimeGetVirtualFunc", mValue, mVirtualTableIdx); + DISPLAY_INST3(BeComptimeGetInterfaceFunc, "ComptimeGetInterfaceFunc", mValue, mIFaceTypeId, mMethodIdx); default: BF_FATAL("Notimpl"); str += ""; diff --git a/IDEHelper/Backend/BeModule.h b/IDEHelper/Backend/BeModule.h index bf09a910..ec2b36d3 100644 --- a/IDEHelper/Backend/BeModule.h +++ b/IDEHelper/Backend/BeModule.h @@ -1348,10 +1348,10 @@ public: ////////////////////////////////////////////////////////////////////////// -class BeConstEvalGetType : public BeInst +class BeComptimeGetType : public BeInst { public: - BE_VALUE_TYPE(BeConstEvalGetType, BeInst); + BE_VALUE_TYPE(BeComptimeGetType, BeInst); public: int mTypeId; @@ -1370,10 +1370,10 @@ public: } }; -class BeConstEvalGetReflectType : public BeInst +class BeComptimeGetReflectType : public BeInst { public: - BE_VALUE_TYPE(BeConstEvalGetReflectType, BeInst); + BE_VALUE_TYPE(BeComptimeGetReflectType, BeInst); public: int mTypeId; @@ -1392,10 +1392,10 @@ public: } }; -class BeConstEvalDynamicCastCheck : public BeInst +class BeComptimeDynamicCastCheck : public BeInst { public: - BE_VALUE_TYPE(BeConstEvalDynamicCastCheck, BeInst); + BE_VALUE_TYPE(BeComptimeDynamicCastCheck, BeInst); public: BeValue* mValue; @@ -1416,10 +1416,10 @@ public: } }; -class BeConstEvalGetVirtualFunc : public BeInst +class BeComptimeGetVirtualFunc : public BeInst { public: - BE_VALUE_TYPE(BeConstEvalGetVirtualFunc, BeInst); + BE_VALUE_TYPE(BeComptimeGetVirtualFunc, BeInst); public: BeValue* mValue; @@ -1440,10 +1440,10 @@ public: } }; -class BeConstEvalGetInterfaceFunc : public BeInst +class BeComptimeGetInterfaceFunc : public BeInst { public: - BE_VALUE_TYPE(BeConstEvalGetInterfaceFunc, BeInst); + BE_VALUE_TYPE(BeComptimeGetInterfaceFunc, BeInst); public: BeValue* mValue; diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 23d9c639..edaa6c1f 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -5239,7 +5239,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* { if (mModule->mIsComptimeModule) { - funcCallInst = mModule->mBfIRBuilder->ConstEval_GetInterfaceFunc(irArgs[0], methodInstance->mMethodInstanceGroup->mOwner->mTypeId, methodInstance->mMethodDef->mIdx, funcPtrType1); + funcCallInst = mModule->mBfIRBuilder->Comptime_GetInterfaceFunc(irArgs[0], methodInstance->mMethodInstanceGroup->mOwner->mTypeId, methodInstance->mMethodDef->mIdx, funcPtrType1); } else { @@ -5259,7 +5259,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* } else if (mModule->mIsComptimeModule) { - funcCallInst = mModule->mBfIRBuilder->ConstEval_GetVirtualFunc(irArgs[0], methodInstance->mVirtualTableIdx, funcPtrType1); + funcCallInst = mModule->mBfIRBuilder->Comptime_GetVirtualFunc(irArgs[0], methodInstance->mVirtualTableIdx, funcPtrType1); } else { diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index c778b209..3b70924d 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -4893,37 +4893,37 @@ void BfIRBuilder::Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage) NEW_CMD_INSERTED; } -BfIRValue BfIRBuilder::ConstEval_GetBfType(int typeId, BfIRType resultType) +BfIRValue BfIRBuilder::Comptime_GetBfType(int typeId, BfIRType resultType) { - BfIRValue retVal = WriteCmd(BfIRCmd_ConstEval_GetBfType, typeId, resultType); + BfIRValue retVal = WriteCmd(BfIRCmd_Comptime_GetBfType, typeId, resultType); NEW_CMD_INSERTED; return retVal; } -BfIRValue BfIRBuilder::ConstEval_GetReflectType(int typeId, BfIRType resultType) +BfIRValue BfIRBuilder::Comptime_GetReflectType(int typeId, BfIRType resultType) { - BfIRValue retVal = WriteCmd(BfIRCmd_ConstEval_GetReflectType, typeId, resultType); + BfIRValue retVal = WriteCmd(BfIRCmd_Comptime_GetReflectType, typeId, resultType); NEW_CMD_INSERTED; return retVal; } -BfIRValue BfIRBuilder::ConstEval_DynamicCastCheck(BfIRValue value, int typeId, BfIRType resultType) +BfIRValue BfIRBuilder::Comptime_DynamicCastCheck(BfIRValue value, int typeId, BfIRType resultType) { - BfIRValue retVal = WriteCmd(BfIRCmd_ConstEval_DynamicCastCheck, value, typeId, resultType); + BfIRValue retVal = WriteCmd(BfIRCmd_Comptime_DynamicCastCheck, value, typeId, resultType); NEW_CMD_INSERTED; return retVal; } -BfIRValue BfIRBuilder::ConstEval_GetVirtualFunc(BfIRValue value, int virtualTableId, BfIRType resultType) +BfIRValue BfIRBuilder::Comptime_GetVirtualFunc(BfIRValue value, int virtualTableId, BfIRType resultType) { - BfIRValue retVal = WriteCmd(BfIRCmd_ConstEval_GetVirtualFunc, value, virtualTableId, resultType); + BfIRValue retVal = WriteCmd(BfIRCmd_Comptime_GetVirtualFunc, value, virtualTableId, resultType); NEW_CMD_INSERTED; return retVal; } -BfIRValue BfIRBuilder::ConstEval_GetInterfaceFunc(BfIRValue value, int typeId, int methodIdx, BfIRType resultType) +BfIRValue BfIRBuilder::Comptime_GetInterfaceFunc(BfIRValue value, int typeId, int methodIdx, BfIRType resultType) { - BfIRValue retVal = WriteCmd(BfIRCmd_ConstEval_GetInterfaceFunc, value, typeId, methodIdx, resultType); + BfIRValue retVal = WriteCmd(BfIRCmd_Comptime_GetInterfaceFunc, value, typeId, methodIdx, resultType); NEW_CMD_INSERTED; return retVal; } diff --git a/IDEHelper/Compiler/BfIRBuilder.h b/IDEHelper/Compiler/BfIRBuilder.h index 86acbbae..46423f82 100644 --- a/IDEHelper/Compiler/BfIRBuilder.h +++ b/IDEHelper/Compiler/BfIRBuilder.h @@ -284,11 +284,11 @@ enum BfIRCmd : uint8 BfIRCmd_Func_SafeRename, BfIRCmd_Func_SetLinkage, - BfIRCmd_ConstEval_GetBfType, - BfIRCmd_ConstEval_GetReflectType, - BfIRCmd_ConstEval_DynamicCastCheck, - BfIRCmd_ConstEval_GetVirtualFunc, - BfIRCmd_ConstEval_GetInterfaceFunc, + BfIRCmd_Comptime_GetBfType, + BfIRCmd_Comptime_GetReflectType, + BfIRCmd_Comptime_DynamicCastCheck, + BfIRCmd_Comptime_GetVirtualFunc, + BfIRCmd_Comptime_GetInterfaceFunc, BfIRCmd_SaveDebugLocation, BfIRCmd_RestoreDebugLocation, @@ -1263,11 +1263,11 @@ public: void Func_SafeRename(BfIRFunction func); void Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage); - BfIRValue ConstEval_GetBfType(int typeId, BfIRType resultType); - BfIRValue ConstEval_GetReflectType(int typeId, BfIRType resultType); - BfIRValue ConstEval_DynamicCastCheck(BfIRValue value, int typeId, BfIRType resultType); - BfIRValue ConstEval_GetVirtualFunc(BfIRValue value, int virtualTableId, BfIRType resultType); - BfIRValue ConstEval_GetInterfaceFunc(BfIRValue value, int typeId, int methodIdx, BfIRType resultType); + BfIRValue Comptime_GetBfType(int typeId, BfIRType resultType); + BfIRValue Comptime_GetReflectType(int typeId, BfIRType resultType); + BfIRValue Comptime_DynamicCastCheck(BfIRValue value, int typeId, BfIRType resultType); + BfIRValue Comptime_GetVirtualFunc(BfIRValue value, int virtualTableId, BfIRType resultType); + BfIRValue Comptime_GetInterfaceFunc(BfIRValue value, int typeId, int methodIdx, BfIRType resultType); void SaveDebugLocation(); void RestoreDebugLocation(); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 2f7270f7..fcc0aa1a 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -4838,7 +4838,7 @@ BfIRValue BfModule::GetClassVDataPtr(BfTypeInstance* typeInstance) { auto classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef); if (mIsComptimeModule) - return mBfIRBuilder->ConstEval_GetBfType(typeInstance->mTypeId, mBfIRBuilder->MapType(CreatePointerType(classVDataType))); + return mBfIRBuilder->Comptime_GetBfType(typeInstance->mTypeId, mBfIRBuilder->MapType(CreatePointerType(classVDataType))); return mBfIRBuilder->CreateBitCast(CreateClassVDataGlobal(typeInstance), mBfIRBuilder->MapType(CreatePointerType(classVDataType))); } @@ -4955,7 +4955,7 @@ BfIRValue BfModule::CreateTypeDataRef(BfType* type) { auto typeTypeDef = ResolveTypeDef(mCompiler->mTypeTypeDef); auto typeTypeInst = typeTypeDef->ToTypeInstance(); - return mBfIRBuilder->ConstEval_GetReflectType(type->mTypeId, mBfIRBuilder->MapType(typeTypeInst)); + return mBfIRBuilder->Comptime_GetReflectType(type->mTypeId, mBfIRBuilder->MapType(typeTypeInst)); } BfIRValue globalVariable; @@ -9370,7 +9370,7 @@ void BfModule::EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* tar if (mIsComptimeModule) { - auto callResult = mBfIRBuilder->ConstEval_DynamicCastCheck(targetValue.mValue, targetType->mTypeId, mBfIRBuilder->MapType(mContext->mBfObjectType)); + auto callResult = mBfIRBuilder->Comptime_DynamicCastCheck(targetValue.mValue, targetType->mTypeId, mBfIRBuilder->MapType(mContext->mBfObjectType)); auto cmpResult = mBfIRBuilder->CreateCmpNE(callResult, GetDefaultValue(mContext->mBfObjectType)); irb->CreateCondBr(cmpResult, trueBlock, falseBlock); return; @@ -19753,7 +19753,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) // incase it gets called later by some hot-loaded coded if ((mCompiler->mOptions.mAllowHotSwapping) && (mCurMethodInstance->mIRFunction) && (!mCurMethodInstance->mIRFunction.IsFake()) && (mCurTypeInstance != mContext->mBfObjectType)) { - if (!mCurMethodInstance->mMethodDef->mName.StartsWith("ConstEval_")) + if (!mCurMethodInstance->mMethodDef->mName.StartsWith("Comptime_")) CreateFakeCallerMethod(mangledName); } mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index ae376146..e6b25253 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -1371,8 +1371,8 @@ void CeBuilder::Build() case BeValueScopeStartInst::TypeId: case BeValueScopeEndInst::TypeId: case BeValueScopeRetainInst::TypeId: - case BeConstEvalGetVirtualFunc::TypeId: - case BeConstEvalGetInterfaceFunc::TypeId: + case BeComptimeGetVirtualFunc::TypeId: + case BeComptimeGetInterfaceFunc::TypeId: break; case BeUnreachableInst::TypeId: Emit(CeOp_InvalidOp); @@ -2385,7 +2385,7 @@ void CeBuilder::Build() ceFunc = GetOperand(beFunction, false, true); } - else if (auto beGetVirtualFunc = BeValueDynCast(castedInst->mFunc)) + else if (auto beGetVirtualFunc = BeValueDynCast(castedInst->mFunc)) { virtTarget = GetOperand(beGetVirtualFunc->mValue); virtualTableIdx = beGetVirtualFunc->mVirtualTableIdx; @@ -2394,7 +2394,7 @@ void CeBuilder::Build() BF_ASSERT(resultType->IsPointer()); beFuncType = (BeFunctionType*)((BePointerType*)resultType)->mElementType; } - else if (auto beGetInterfaceFunc = BeValueDynCast(castedInst->mFunc)) + else if (auto beGetInterfaceFunc = BeValueDynCast(castedInst->mFunc)) { virtTarget = GetOperand(beGetInterfaceFunc->mValue); ifaceTypeId = beGetInterfaceFunc->mIFaceTypeId; @@ -2533,17 +2533,17 @@ void CeBuilder::Build() EmitFrameOffset(mcStackVal); } break; - case BeConstEvalGetType::TypeId: + case BeComptimeGetType::TypeId: { - auto castedInst = (BeConstEvalGetType*)inst; + auto castedInst = (BeComptimeGetType*)inst; result.mKind = CeOperandKind_Immediate; result.mImmediate = castedInst->mTypeId; result.mType = beModule->mContext->GetPrimitiveType(BeTypeCode_Int32); } break; - case BeConstEvalGetReflectType::TypeId: + case BeComptimeGetReflectType::TypeId: { - auto castedInst = (BeConstEvalGetReflectType*)inst; + auto castedInst = (BeComptimeGetReflectType*)inst; auto ptrType = beModule->mContext->GetVoidPtrType(); result = FrameAlloc(ptrType); @@ -2552,9 +2552,9 @@ void CeBuilder::Build() Emit((int32)castedInst->mTypeId); } break; - case BeConstEvalDynamicCastCheck::TypeId: + case BeComptimeDynamicCastCheck::TypeId: { - auto castedInst = (BeConstEvalDynamicCastCheck*)inst; + auto castedInst = (BeComptimeDynamicCastCheck*)inst; auto mcValue = GetOperand(castedInst->mValue); auto ptrType = beModule->mContext->GetVoidPtrType();