1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +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;
}
for (int stringId : module->mImportFileNames)
{
BfStringPoolEntry& stringPoolEntry = module->mContext->mStringObjectIdMap[stringId];
stringPoolEntry.mLastUsedRevision = mRevision;
}
/*if (module->mOptModule != NULL)
MarkStringPool(module->mOptModule);*/
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)
{
{
auto stringTypeInst = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration)->ToTypeInstance();
mBfIRBuilder->PopulateType(stringTypeInst);
@ -5970,6 +5970,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef);
BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray<BfIRValue, 1>());
if (typeInstance->mTypeDef->mName->ToString() == "TestProgram")
{
NOP;
}
auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes)
{
if (customAttributes == NULL)
@ -10996,6 +11001,17 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
continue;
}
if (mModuleName == "BeefTest_TestProgram")
{
NOP;
}
if ((mIsReified) && (attrTypeInst->mAttributeData != NULL) && ((attrTypeInst->mAttributeData->mFlags & BfAttributeFlag_ReflectAttribute) != 0))
{
// Reify attribute
PopulateType(attrTypeInst);
}
if (mCurTypeInstance != NULL)
AddDependency(attrTypeInst, mCurTypeInstance, BfDependencyMap::DependencyFlag_CustomAttribute);
@ -11166,7 +11182,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
auto propType = methodInstance.mMethodInstance->GetParamType(0);
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.mValue.IsConst())
@ -11182,7 +11198,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
}
if ((!handledExpr) && (assignExpr->mRight != NULL))
constResolver.Resolve(assignExpr->mRight);
constResolver.Resolve(assignExpr->mRight, NULL, BfConstResolveFlag_NoActualizeValues);
}
else
{
@ -11202,7 +11218,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
resolvedArg.mArgFlags = BfArgFlag_DeferredEval;
}
else
resolvedArg.mTypedValue = constResolver.Resolve(arg);
resolvedArg.mTypedValue = constResolver.Resolve(arg, NULL, BfConstResolveFlag_NoActualizeValues);
if (!inPropSet)
{
@ -11283,7 +11299,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0)
{
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->mWantsIRIgnoreWrites = false;
for (auto ownedTypes : typeModule->mOwnedTypeInstances)
{
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++;
if (typeModule->mBfIRBuilder != NULL)
{
@ -1038,7 +1052,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
typeModule->SetupIRBuilder(false);
}
else
typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance());
typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance());
}
else
{
@ -2002,7 +2016,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
for (auto& customAttribute : customAttributes->mAttributes)
{
auto attrType = customAttribute.mType;
PopulateType(attrType, BfPopulateType_DataAndMethods);
mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods);
if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted)
continue;
@ -2331,7 +2345,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
for (auto& customAttribute : customAttributes->mAttributes)
{
auto attrType = customAttribute.mType;
PopulateType(attrType, BfPopulateType_DataAndMethods);
mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods);
if (attrType->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted)
continue;
@ -9716,6 +9730,11 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
}
typeInst->mTypeDef = typeDef;
if (((resolveFlags & BfResolveTypeRefFlag_NoReify) != 0) && (mCompiler->mOptions.mCompileOnDemandKind != BfCompileOnDemandKind_AlwaysInclude))
{
typeInst->mIsReified = false;
}
if (typeInst->mTypeDef->mGenericParamDefs.size() != 0)
{
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)
{
module->PopulateType(customAttribute->mType);
module->mContext->mUnreifiedModule->PopulateType(customAttribute->mType);
auto ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals;
BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr);
BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType);