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

Improved string table usage tracking

This commit is contained in:
Brian Fiete 2021-02-09 10:40:37 -08:00
parent bb2fe56dc9
commit 9d79db063b
6 changed files with 94 additions and 55 deletions

View file

@ -35,7 +35,7 @@ BfConstResolver::BfConstResolver(BfModule* bfModule) : BfExprEvaluator(bfModule)
} }
BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfConstResolveFlags flags) BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfConstResolveFlags flags)
{ {
mBfEvalExprFlags = (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_Comptime); mBfEvalExprFlags = (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_Comptime);
// Handle the 'int[?] val = .(1, 2, 3)' case // Handle the 'int[?] val = .(1, 2, 3)' case
@ -137,11 +137,11 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
int stringId = mModule->GetStringPoolIdx(mResult.mValue); int stringId = mModule->GetStringPoolIdx(mResult.mValue);
if (stringId != -1) if (stringId != -1)
{ {
if ((flags & BfConstResolveFlag_RemapFromStringId) != 0) if ((flags & BfConstResolveFlag_ActualizeValues) != 0)
{ {
prevIgnoreWrites.Restore(); prevIgnoreWrites.Restore();
mModule->mBfIRBuilder->PopulateType(mResult.mType); mModule->mBfIRBuilder->PopulateType(mResult.mType);
return BfTypedValue(mModule->GetStringObjectValue(stringId), mResult.mType); return BfTypedValue(mModule->GetStringObjectValue(stringId, false, true), mResult.mType);
} }
return BfTypedValue(mModule->mBfIRBuilder->CreateConst(BfTypeCode_StringId, stringId), toType); return BfTypedValue(mModule->mBfIRBuilder->CreateConst(BfTypeCode_StringId, stringId), toType);
@ -232,7 +232,9 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
}*/ }*/
mModule->FixIntUnknown(mResult); mModule->FixIntUnknown(mResult);
mModule->FixValueActualization(mResult);
if ((flags & BfConstResolveFlag_NoActualizeValues) == 0)
mModule->FixValueActualization(mResult, !prevIgnoreWrites.mPrevVal || ((flags & BfConstResolveFlag_ActualizeValues) != 0));
return mResult; return mResult;
} }

View file

@ -15,9 +15,10 @@ enum BfConstResolveFlags
BfConstResolveFlag_ExplicitCast = 1, BfConstResolveFlag_ExplicitCast = 1,
BfConstResolveFlag_NoCast = 2, BfConstResolveFlag_NoCast = 2,
BfConstResolveFlag_AllowSoftFail = 4, BfConstResolveFlag_AllowSoftFail = 4,
BfConstResolveFlag_RemapFromStringId = 8, BfConstResolveFlag_ActualizeValues = 8,
BfConstResolveFlag_ArrayInitSize = 0x10, BfConstResolveFlag_NoActualizeValues = 0x10,
BfConstResolveFlag_AllowGlobalVariable = 0x20, BfConstResolveFlag_ArrayInitSize = 0x20,
BfConstResolveFlag_AllowGlobalVariable = 0x40,
}; };
class BfConstResolver : public BfExprEvaluator class BfConstResolver : public BfExprEvaluator

View file

@ -1654,8 +1654,11 @@ String* BfModule::GetStringPoolString(BfIRValue constantStr, BfIRConstHolder * c
return NULL; return NULL;
} }
BfIRValue BfModule::GetStringCharPtr(int stringId) BfIRValue BfModule::GetStringCharPtr(int stringId, bool force)
{ {
if ((mBfIRBuilder->mIgnoreWrites) && (!force))
return mBfIRBuilder->CreateConst(BfTypeCode_StringId, stringId);
BfIRValue* irValue = NULL; BfIRValue* irValue = NULL;
if (!mStringCharPtrPool.TryAdd(stringId, NULL, &irValue)) if (!mStringCharPtrPool.TryAdd(stringId, NULL, &irValue))
return *irValue; return *irValue;
@ -1670,13 +1673,13 @@ BfIRValue BfModule::GetStringCharPtr(int stringId)
return strCharPtrConst; return strCharPtrConst;
} }
BfIRValue BfModule::GetStringCharPtr(BfIRValue strValue) BfIRValue BfModule::GetStringCharPtr(BfIRValue strValue, bool force)
{ {
if (strValue.IsConst()) if (strValue.IsConst())
{ {
int stringId = GetStringPoolIdx(strValue); int stringId = GetStringPoolIdx(strValue);
BF_ASSERT(stringId != -1); BF_ASSERT(stringId != -1);
return GetStringCharPtr(stringId); return GetStringCharPtr(stringId, force);
} }
BfIRValue charPtrPtr = mBfIRBuilder->CreateInBoundsGEP(strValue, 0, 1); BfIRValue charPtrPtr = mBfIRBuilder->CreateInBoundsGEP(strValue, 0, 1);
@ -1684,27 +1687,32 @@ BfIRValue BfModule::GetStringCharPtr(BfIRValue strValue)
return charPtr; return charPtr;
} }
BfIRValue BfModule::GetStringCharPtr(const StringImpl& str) BfIRValue BfModule::GetStringCharPtr(const StringImpl& str, bool force)
{ {
return GetStringCharPtr(GetStringObjectValue(str)); return GetStringCharPtr(GetStringObjectValue(str, force), force);
} }
BfIRValue BfModule::GetStringObjectValue(int strId) BfIRValue BfModule::GetStringObjectValue(int strId, bool define, bool force)
{ {
BfIRValue* objValue; BfIRValue* objValue;
if (mStringObjectPool.TryGetValue(strId, &objValue)) if (mStringObjectPool.TryGetValue(strId, &objValue))
return *objValue; return *objValue;
auto stringPoolEntry = mContext->mStringObjectIdMap[strId]; auto stringPoolEntry = mContext->mStringObjectIdMap[strId];
return GetStringObjectValue(stringPoolEntry.mString, true); return GetStringObjectValue(stringPoolEntry.mString, define, force);
} }
BfIRValue BfModule::GetStringObjectValue(const StringImpl& str, bool define) BfIRValue BfModule::GetStringObjectValue(const StringImpl& str, bool define, bool force)
{ {
auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration); auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration);
mBfIRBuilder->PopulateType(stringType); mBfIRBuilder->PopulateType(stringType);
int strId = mContext->GetStringLiteralId(str); int strId = mContext->GetStringLiteralId(str);
if ((mBfIRBuilder->mIgnoreWrites) && (!force))
{
return mBfIRBuilder->CreateConst(BfTypeCode_StringId, strId);
}
BfIRValue* irValuePtr = NULL; BfIRValue* irValuePtr = NULL;
if (!mStringObjectPool.TryAdd(strId, NULL, &irValuePtr)) if (!mStringObjectPool.TryAdd(strId, NULL, &irValuePtr))
@ -5900,8 +5908,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (needsTypeNames) if (needsTypeNames)
{ {
typeNameConst = GetStringObjectValue(typeDef->mName->mString, true); typeNameConst = GetStringObjectValue(typeDef->mName->mString, !mIsComptimeModule);
namespaceConst = GetStringObjectValue(typeDef->mNamespace.ToString(), true); namespaceConst = GetStringObjectValue(typeDef->mNamespace.ToString(), !mIsComptimeModule);
} }
else else
{ {
@ -6041,7 +6049,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
*orderedIdPtr = (int)usedStringIdMap.size() - 1; *orderedIdPtr = (int)usedStringIdMap.size() - 1;
} }
GetStringObjectValue(stringId); GetStringObjectValue(stringId, true, true);
PUSH_INT8(0xFF); // String PUSH_INT8(0xFF); // String
PUSH_INT32(*orderedIdPtr); PUSH_INT32(*orderedIdPtr);
argIdx++; argIdx++;
@ -6061,7 +6069,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
*orderedIdPtr = (int)usedStringIdMap.size() - 1; *orderedIdPtr = (int)usedStringIdMap.size() - 1;
} }
GetStringObjectValue(stringId); GetStringObjectValue(stringId, true, true);
PUSH_INT8(0xFF); // String PUSH_INT8(0xFF); // String
PUSH_INT32(*orderedIdPtr); PUSH_INT32(*orderedIdPtr);
argIdx++; argIdx++;
@ -6225,7 +6233,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* payloadType = typeInstance->GetUnionInnerType(); BfType* payloadType = typeInstance->GetUnionInnerType();
if (!payloadType->IsValuelessType()) if (!payloadType->IsValuelessType())
{ {
BfIRValue payloadNameConst = GetStringObjectValue("$payload", true); BfIRValue payloadNameConst = GetStringObjectValue("$payload", !mIsComptimeModule);
SizedArray<BfIRValue, 8> payloadFieldVals = SizedArray<BfIRValue, 8> payloadFieldVals =
{ {
emptyValueType, emptyValueType,
@ -6240,7 +6248,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
} }
BfType* dscrType = typeInstance->GetDiscriminatorType(); BfType* dscrType = typeInstance->GetDiscriminatorType();
BfIRValue dscrNameConst = GetStringObjectValue("$discriminator", true); BfIRValue dscrNameConst = GetStringObjectValue("$discriminator", !mIsComptimeModule);
SizedArray<BfIRValue, 8> dscrFieldVals = SizedArray<BfIRValue, 8> dscrFieldVals =
{ {
emptyValueType, emptyValueType,
@ -6262,7 +6270,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfFieldInstance* fieldInstance = &typeInstance->mFieldInstances[fieldIdx]; BfFieldInstance* fieldInstance = &typeInstance->mFieldInstances[fieldIdx];
BfFieldDef* fieldDef = fieldInstance->GetFieldDef(); BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
BfIRValue fieldNameConst = GetStringObjectValue(fieldDef->mName, true); BfIRValue fieldNameConst = GetStringObjectValue(fieldDef->mName, !mIsComptimeModule);
int typeId = 0; int typeId = 0;
auto fieldType = fieldInstance->GetResolvedType(); auto fieldType = fieldInstance->GetResolvedType();
@ -6538,7 +6546,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType); funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType);
} }
BfIRValue methodNameConst = GetStringObjectValue(methodDef->mName, true); BfIRValue methodNameConst = GetStringObjectValue(methodDef->mName, !mIsComptimeModule);
BfMethodFlags methodFlags = defaultMethod->GetMethodFlags(); BfMethodFlags methodFlags = defaultMethod->GetMethodFlags();
@ -6561,7 +6569,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (defaultMethod->GetParamIsSplat(paramIdx)) if (defaultMethod->GetParamIsSplat(paramIdx))
paramFlags = (ParamFlags)(paramFlags | ParamFlag_Splat); paramFlags = (ParamFlags)(paramFlags | ParamFlag_Splat);
BfIRValue paramNameConst = GetStringObjectValue(paramName, true); BfIRValue paramNameConst = GetStringObjectValue(paramName, !mIsComptimeModule);
SizedArray<BfIRValue, 8> paramDataVals = SizedArray<BfIRValue, 8> paramDataVals =
{ {
@ -10621,17 +10629,18 @@ BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConst
auto constVal = mBfIRBuilder->CreateConst(constant, constHolder); auto constVal = mBfIRBuilder->CreateConst(constant, constHolder);
BfTypedValue typedValue; BfTypedValue typedValue;
bool allowUnactualized = mBfIRBuilder->mIgnoreWrites;
if (constant->mTypeCode == BfTypeCode_StringId) if (constant->mTypeCode == BfTypeCode_StringId)
{ {
if ((wantType->IsInstanceOf(mCompiler->mStringTypeDef)) || if ((wantType->IsInstanceOf(mCompiler->mStringTypeDef)) ||
((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8)))) ((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))))
{ {
typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, wantType), wantType); typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, wantType, allowUnactualized), wantType);
return typedValue; return typedValue;
} }
auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef); auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef);
typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, stringType), stringType); typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, stringType, allowUnactualized), stringType);
} }
if (!typedValue) if (!typedValue)
@ -10675,7 +10684,27 @@ BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConst
return BfTypedValue(irValue, wantType, false); return BfTypedValue(irValue, wantType, false);
} }
BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowStringId) bool BfModule::HasUnactializedConstant(BfConstant* constant, BfIRConstHolder* constHolder)
{
if ((constant->mConstType == BfConstType_TypeOf) || (constant->mConstType == BfConstType_TypeOf_WithData))
return true;
if (constant->mTypeCode == BfTypeCode_StringId)
return true;
if (constant->mConstType == BfConstType_Agg)
{
auto constArray = (BfConstantAgg*)constant;
for (auto val : constArray->mValues)
{
if (HasUnactializedConstant(constHolder->GetConstant(val), constHolder))
return true;
}
}
return false;
}
BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowUnactualized)
{ {
if (constant->mTypeCode == BfTypeCode_NullPtr) if (constant->mTypeCode == BfTypeCode_NullPtr)
{ {
@ -10690,20 +10719,27 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con
if (constant->mTypeCode == BfTypeCode_StringId) if (constant->mTypeCode == BfTypeCode_StringId)
{ {
if (!allowStringId) if (!allowUnactualized)
{ {
if ((wantType->IsInstanceOf(mCompiler->mStringTypeDef)) || if ((wantType->IsInstanceOf(mCompiler->mStringTypeDef)) ||
((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8)))) ((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))))
{ {
const StringImpl& str = mContext->mStringObjectIdMap[constant->mInt32].mString; const StringImpl& str = mContext->mStringObjectIdMap[constant->mInt32].mString;
BfIRValue stringObjConst = GetStringObjectValue(str); BfIRValue stringObjConst = GetStringObjectValue(str, false, true);
if (wantType->IsPointer()) if (wantType->IsPointer())
return GetStringCharPtr(stringObjConst); return GetStringCharPtr(stringObjConst, true);
return stringObjConst; return stringObjConst;
} }
} }
} }
if (constant->mConstType == Beefy::BfConstType_TypeOf)
{
auto constTypeOf = (BfTypeOf_Const*)constant;
AddDependency(constTypeOf->mType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ExprTypeReference);
return CreateTypeDataRef(constTypeOf->mType);
}
if (constant->mConstType == BfConstType_Agg) if (constant->mConstType == BfConstType_Agg)
{ {
auto constArray = (BfConstantAgg*)constant; auto constArray = (BfConstantAgg*)constant;
@ -11012,8 +11048,8 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
auto& fieldTypeInst = checkTypeInst->mFieldInstances[bestField->mIdx]; auto& fieldTypeInst = checkTypeInst->mFieldInstances[bestField->mIdx];
if (assignExpr->mRight != NULL) if (assignExpr->mRight != NULL)
{ {
BfTypedValue result = constResolver.Resolve(assignExpr->mRight, fieldTypeInst.mResolvedType); BfTypedValue result = constResolver.Resolve(assignExpr->mRight, fieldTypeInst.mResolvedType, BfConstResolveFlag_NoActualizeValues);
if (result) if (result)
{ {
CurrentAddToConstHolder(result.mValue); CurrentAddToConstHolder(result.mValue);
@ -14049,8 +14085,10 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli
if (mBfIRBuilder->HasDebugLocation()) if (mBfIRBuilder->HasDebugLocation())
{ {
if ((isConstant) && (!didConstToMem)) if ((isConstant) && (!didConstToMem))
{ {
localVarDef->mDbgDeclareInst = mBfIRBuilder->DbgInsertValueIntrinsic(localVarDef->mConstValue, diVariable); BfTypedValue result(localVarDef->mConstValue, localVarDef->mResolvedType);
FixValueActualization(result);
localVarDef->mDbgDeclareInst = mBfIRBuilder->DbgInsertValueIntrinsic(result.mValue, diVariable);
} }
else else
{ {
@ -18139,7 +18177,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
auto methodDeclaration = methodDef->GetMethodDeclaration(); auto methodDeclaration = methodDef->GetMethodDeclaration();
if ((methodDef->mHasComptime) && (!mIsComptimeModule)) if ((methodDef->mHasComptime) && (!mIsComptimeModule))
mBfIRBuilder->mIgnoreWrites = true; mBfIRBuilder->mIgnoreWrites = true;
if ((methodInstance->mIsReified) && (methodInstance->mVirtualTableIdx != -1)) if ((methodInstance->mIsReified) && (methodInstance->mVirtualTableIdx != -1))
{ {

View file

@ -1538,12 +1538,12 @@ public:
BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define); BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define);
int GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL); int GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
String* GetStringPoolString(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL); String* GetStringPoolString(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
BfIRValue GetStringCharPtr(int stringId); BfIRValue GetStringCharPtr(int stringId, bool force = false);
BfIRValue GetStringCharPtr(BfIRValue strValue); BfIRValue GetStringCharPtr(BfIRValue strValue, bool force = false);
BfIRValue GetStringCharPtr(const StringImpl& str); BfIRValue GetStringCharPtr(const StringImpl& str, bool force = false);
BfIRValue GetStringObjectValue(int idx); BfIRValue GetStringObjectValue(int idx, bool define, bool force);
BfIRValue GetStringObjectValue(const StringImpl& str, bool define = false); BfIRValue GetStringObjectValue(const StringImpl& str, bool define = false, bool force = false);
BfIRValue CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external); BfIRValue CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external);
void VariantToString(StringImpl& str, const BfVariant& variant); void VariantToString(StringImpl& str, const BfVariant& variant);
StringT<128> TypeToString(BfType* resolvedType, Array<String>* genericMethodParamNameOverrides = NULL); StringT<128> TypeToString(BfType* resolvedType, Array<String>* genericMethodParamNameOverrides = NULL);
StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array<String>* genericMethodParamNameOverrides = NULL); StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array<String>* genericMethodParamNameOverrides = NULL);
@ -1553,8 +1553,9 @@ public:
void pm(BfMethodInstance* type); void pm(BfMethodInstance* type);
void CurrentAddToConstHolder(BfIRValue& irVal); void CurrentAddToConstHolder(BfIRValue& irVal);
void ClearConstData(); void ClearConstData();
BfTypedValue GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType); bool HasUnactializedConstant(BfConstant* constant, BfIRConstHolder* constHolder);
BfIRValue ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowStringId = false); BfTypedValue GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType);
BfIRValue ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowUnactualized = false);
void ValidateCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeTargets attrTarget); void ValidateCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeTargets attrTarget);
void GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, bool allowNonConstArgs = false, BfCaptureInfo* captureInfo = NULL); void GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, bool allowNonConstArgs = false, BfCaptureInfo* captureInfo = NULL);
BfCustomAttributes* GetCustomAttributes(BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, bool allowNonConstArgs = false, BfCaptureInfo* captureInfo = NULL); BfCustomAttributes* GetCustomAttributes(BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, bool allowNonConstArgs = false, BfCaptureInfo* captureInfo = NULL);
@ -1771,8 +1772,8 @@ public:
BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false); BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false);
BfType* FixIntUnknown(BfType* type); BfType* FixIntUnknown(BfType* type);
void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL); void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL);
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs); void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
void FixValueActualization(BfTypedValue& typedVal); void FixValueActualization(BfTypedValue& typedVal, bool force = false);
bool TypeEquals(BfTypedValue& val, BfType* type); bool TypeEquals(BfTypedValue& val, BfType* type);
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None); BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None); BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);

View file

@ -6439,19 +6439,16 @@ void BfModule::FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs)
FixIntUnknown(rhs); FixIntUnknown(rhs);
} }
void BfModule::FixValueActualization(BfTypedValue& typedVal) void BfModule::FixValueActualization(BfTypedValue& typedVal, bool force)
{ {
if (!typedVal.mValue.IsConst()) if (!typedVal.mValue.IsConst())
return; return;
if (mBfIRBuilder->mIgnoreWrites) if ((mBfIRBuilder->mIgnoreWrites) && (!force))
return; return;
auto constant = mBfIRBuilder->GetConstant(typedVal.mValue); auto constant = mBfIRBuilder->GetConstant(typedVal.mValue);
if (constant->mConstType == BfConstType_TypeOf) if (!HasUnactializedConstant(constant, mBfIRBuilder))
{ return;
auto constTypeOf = (BfTypeOf_Const*)constant; typedVal.mValue = ConstantToCurrent(constant, mBfIRBuilder, typedVal.mType, false);
AddDependency(constTypeOf->mType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ExprTypeReference);
typedVal.mValue = CreateTypeDataRef(constTypeOf->mType);
}
} }
BfTypeInstance* BfModule::GetPrimitiveStructType(BfTypeCode typeCode) BfTypeInstance* BfModule::GetPrimitiveStructType(BfTypeCode typeCode)

View file

@ -1654,7 +1654,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
if (isConst) if (isConst)
{ {
BfConstResolver constResolver(this); BfConstResolver constResolver(this);
initValue = constResolver.Resolve(varDecl->mInitializer, resolvedType, BfConstResolveFlag_RemapFromStringId); initValue = constResolver.Resolve(varDecl->mInitializer, resolvedType, BfConstResolveFlag_ActualizeValues);
if (!initValue) if (!initValue)
initValue = GetDefaultTypedValue(resolvedType); initValue = GetDefaultTypedValue(resolvedType);
} }