1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed some attribute reification issues

This commit is contained in:
Brian Fiete 2021-02-09 14:07:11 -08:00
parent 7ff8a25307
commit e3803ed007
4 changed files with 50 additions and 9 deletions

View file

@ -5106,6 +5106,12 @@ void BfCompiler::MarkStringPool(BfModule* module)
stringPoolEntry.mLastUsedRevision = mRevision; stringPoolEntry.mLastUsedRevision = mRevision;
} }
for (int stringId : module->mImportFileNames)
{
BfStringPoolEntry& stringPoolEntry = module->mContext->mStringObjectIdMap[stringId];
stringPoolEntry.mLastUsedRevision = mRevision;
}
/*if (module->mOptModule != NULL) /*if (module->mOptModule != NULL)
MarkStringPool(module->mOptModule);*/ MarkStringPool(module->mOptModule);*/
auto altModule = module->mNextAltModule; auto altModule = module->mNextAltModule;

View file

@ -1543,7 +1543,7 @@ BfIRValue BfModule::CreateStringCharPtr(const StringImpl& str, int stringId, boo
} }
BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, bool define) BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, bool define)
{ {
auto stringTypeInst = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration)->ToTypeInstance(); auto stringTypeInst = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration)->ToTypeInstance();
mBfIRBuilder->PopulateType(stringTypeInst); mBfIRBuilder->PopulateType(stringTypeInst);
@ -5970,6 +5970,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef); BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef);
BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray<BfIRValue, 1>()); BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray<BfIRValue, 1>());
if (typeInstance->mTypeDef->mName->ToString() == "TestProgram")
{
NOP;
}
auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes) auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes)
{ {
if (customAttributes == NULL) if (customAttributes == NULL)
@ -10996,6 +11001,17 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
continue; continue;
} }
if (mModuleName == "BeefTest_TestProgram")
{
NOP;
}
if ((mIsReified) && (attrTypeInst->mAttributeData != NULL) && ((attrTypeInst->mAttributeData->mFlags & BfAttributeFlag_ReflectAttribute) != 0))
{
// Reify attribute
PopulateType(attrTypeInst);
}
if (mCurTypeInstance != NULL) if (mCurTypeInstance != NULL)
AddDependency(attrTypeInst, mCurTypeInstance, BfDependencyMap::DependencyFlag_CustomAttribute); AddDependency(attrTypeInst, mCurTypeInstance, BfDependencyMap::DependencyFlag_CustomAttribute);
@ -11166,7 +11182,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
auto propType = methodInstance.mMethodInstance->GetParamType(0); auto propType = methodInstance.mMethodInstance->GetParamType(0);
if (assignExpr->mRight != NULL) if (assignExpr->mRight != NULL)
{ {
BfTypedValue result = constResolver.Resolve(assignExpr->mRight, propType); BfTypedValue result = constResolver.Resolve(assignExpr->mRight, propType, BfConstResolveFlag_NoActualizeValues);
if ((result) && (!result.mType->IsVar())) if ((result) && (!result.mType->IsVar()))
{ {
if (!result.mValue.IsConst()) if (!result.mValue.IsConst())
@ -11182,7 +11198,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
} }
if ((!handledExpr) && (assignExpr->mRight != NULL)) if ((!handledExpr) && (assignExpr->mRight != NULL))
constResolver.Resolve(assignExpr->mRight); constResolver.Resolve(assignExpr->mRight, NULL, BfConstResolveFlag_NoActualizeValues);
} }
else else
{ {
@ -11202,7 +11218,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
resolvedArg.mArgFlags = BfArgFlag_DeferredEval; resolvedArg.mArgFlags = BfArgFlag_DeferredEval;
} }
else else
resolvedArg.mTypedValue = constResolver.Resolve(arg); resolvedArg.mTypedValue = constResolver.Resolve(arg, NULL, BfConstResolveFlag_NoActualizeValues);
if (!inPropSet) if (!inPropSet)
{ {
@ -11283,7 +11299,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0) if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0)
{ {
if (auto expr = BfNodeDynCast<BfExpression>(arg.mExpression)) if (auto expr = BfNodeDynCast<BfExpression>(arg.mExpression))
constResolver.Resolve(expr); constResolver.Resolve(expr, NULL, BfConstResolveFlag_NoActualizeValues);
} }
} }

View file

@ -1029,7 +1029,21 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
typeModule->mIsReified = true; typeModule->mIsReified = true;
typeModule->mWantsIRIgnoreWrites = false; typeModule->mWantsIRIgnoreWrites = false;
for (auto ownedTypes : typeModule->mOwnedTypeInstances) for (auto ownedTypes : typeModule->mOwnedTypeInstances)
{
ownedTypes->mIsReified = true; ownedTypes->mIsReified = true;
if (ownedTypes->mCustomAttributes != NULL)
{
for (auto& attr : ownedTypes->mCustomAttributes->mAttributes)
{
if ((attr.mType->mAttributeData != NULL) && ((attr.mType->mAttributeData->mFlags & BfCustomAttributeFlags_ReflectAttribute) != 0))
{
// Reify this attribute
typeModule->PopulateType(attr.mType);
}
}
}
}
mCompiler->mStats.mReifiedModuleCount++; mCompiler->mStats.mReifiedModuleCount++;
if (typeModule->mBfIRBuilder != NULL) if (typeModule->mBfIRBuilder != NULL)
{ {
@ -1038,7 +1052,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
typeModule->SetupIRBuilder(false); typeModule->SetupIRBuilder(false);
} }
else else
typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance()); typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance());
} }
else else
{ {
@ -2002,7 +2016,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
for (auto& customAttribute : customAttributes->mAttributes) for (auto& customAttribute : customAttributes->mAttributes)
{ {
auto attrType = customAttribute.mType; auto attrType = customAttribute.mType;
PopulateType(attrType, BfPopulateType_DataAndMethods); mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods);
if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted) if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted)
continue; continue;
@ -2331,7 +2345,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
for (auto& customAttribute : customAttributes->mAttributes) for (auto& customAttribute : customAttributes->mAttributes)
{ {
auto attrType = customAttribute.mType; auto attrType = customAttribute.mType;
PopulateType(attrType, BfPopulateType_DataAndMethods); mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods);
if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted) if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted)
continue; continue;
@ -9716,6 +9730,11 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
} }
typeInst->mTypeDef = typeDef; typeInst->mTypeDef = typeDef;
if (((resolveFlags & BfResolveTypeRefFlag_NoReify) != 0) && (mCompiler->mOptions.mCompileOnDemandKind != BfCompileOnDemandKind_AlwaysInclude))
{
typeInst->mIsReified = false;
}
if (typeInst->mTypeDef->mGenericParamDefs.size() != 0) if (typeInst->mTypeDef->mGenericParamDefs.size() != 0)
{ {
Fail("Generic type arguments expected", typeRef); Fail("Generic type arguments expected", typeRef);

View file

@ -3809,7 +3809,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfIRConstHolder* constHolder, BfCustomAttribute* customAttribute) BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfIRConstHolder* constHolder, BfCustomAttribute* customAttribute)
{ {
module->PopulateType(customAttribute->mType); module->mContext->mUnreifiedModule->PopulateType(customAttribute->mType);
auto ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals; auto ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals;
BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr); BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr);
BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType); BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType);