Ver Fonte

Cache ConstExpr ToString, fix const arg int comparison in cast

Brian Fiete há 1 ano atrás
pai
commit
d341104a57

+ 6 - 1
IDEHelper/Compiler/BfContext.cpp

@@ -2193,9 +2193,14 @@ void BfContext::UpdateRevisedTypes()
 		}
 
 		// Rebuild all types
+		Array<BfType*> allTypes;
 		for (auto type : mResolvedTypes)
+			allTypes.Add(type);
+
+		for (auto type : allTypes)
 		{
-			RebuildType(type);
+			if (!type->IsDeleting())
+				RebuildType(type);
 		}
 	}
 

+ 7 - 7
IDEHelper/Compiler/BfIRBuilder.cpp

@@ -466,6 +466,11 @@ void BfIRConstHolder::pv(const BfIRValue& irValue)
 
 void BfIRConstHolder::FixTypeCode(BfTypeCode& typeCode)
 {
+	if (typeCode == BfTypeCode_IntUnknown)
+		typeCode = BfTypeCode_Int64;
+	if (typeCode == BfTypeCode_UIntUnknown)
+		typeCode = BfTypeCode_UInt64;
+
 	if (typeCode == BfTypeCode_IntPtr)
 	{
 		if (mModule->mSystem->mPtrSize == 4)
@@ -740,11 +745,6 @@ BfIRType BfIRConstHolder::GetSizedArrayType(BfIRType elementType, int length)
 
 BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val)
 {
-	if (typeCode == BfTypeCode_IntUnknown)
-		typeCode = BfTypeCode_Int64;
-	else if (typeCode == BfTypeCode_UIntUnknown)
-		typeCode = BfTypeCode_UInt64;
-
 	FixTypeCode(typeCode);
 	BfConstant* constant = mTempAlloc.Alloc<BfConstant>();
 	constant->mTypeCode = typeCode;
@@ -2720,7 +2720,7 @@ public:
 #endif
 
 void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
-{	
+{
 	auto populateModule = mModule->mContext->mUnreifiedModule;
 	auto typeInstance = type->ToTypeInstance();
 	if ((typeInstance != NULL) && (typeInstance->mModule != NULL))
@@ -3112,7 +3112,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
 	{
 		irType = GetPrimitiveType(BfTypeCode_None);
 		if (wantDIData)
-			diType = DbgCreateBasicType("void", 0, 0, llvm::dwarf::DW_ATE_address);		
+			diType = DbgCreateBasicType("void", 0, 0, llvm::dwarf::DW_ATE_address);
 	}
 
 	if (irType)

+ 7 - 0
IDEHelper/Compiler/BfModule.cpp

@@ -12842,6 +12842,13 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
 			case BfTypeCode_Char32:
 			case BfTypeCode_StringId:
 				variant.mTypeCode = constant->mTypeCode;
+				if (((variant.mTypeCode == BfTypeCode_Int64) || (variant.mTypeCode == BfTypeCode_UInt64)) &&
+					(primType->mSize > 0) && (primType->mSize < 8) &&
+					(mBfIRBuilder->IsIntable(primType->GetTypeCode())))
+				{
+					// We may have an 'int unknown' that we need to downsize
+					variant.mTypeCode = primType->GetTypeCode();
+				}
 				variant.mInt64 = constant->mInt64;
 				break;
 			case BfTypeCode_Float:

+ 5 - 2
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -13786,7 +13786,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
 			auto variantVal = TypedValueToVariant(srcNode, typedVal, true);
 			if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
 			{
-				if (variantVal == toConstExprValueType->mValue)
+				if (variantVal.mUInt64 == toConstExprValueType->mValue.mUInt64)
 					return typedVal.mValue;
 			}
 			else if ((mBfIRBuilder->IsFloat(variantVal.mTypeCode)) && (mBfIRBuilder->IsFloat(toConstExprValueType->mValue.mTypeCode)))
@@ -16210,7 +16210,10 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
 			}
 		}
 
-		VariantToString(str, constExprValueType->mValue, constExprValueType->mType);
+		if (constExprValueType->mValueString.IsEmpty())
+			VariantToString(constExprValueType->mValueString, constExprValueType->mValue, constExprValueType->mType);
+
+		str += constExprValueType->mValueString;
 
 		return;
 	}

+ 2 - 1
IDEHelper/Compiler/BfResolvedTypeUtils.h

@@ -2611,6 +2611,7 @@ class BfConstExprValueType : public BfDependedType
 public:
 	BfType* mType;
 	BfVariant mValue;
+	String mValueString;
 
 public:
 	~BfConstExprValueType();
@@ -2827,7 +2828,7 @@ public:
 
 			// checkEntry->mType can be NULL if we're in the process of filling it in (and this Insert is from an element type)
 			//  OR if the type resolution failed after node insertion
-			if ((checkEntry->mValue != NULL) && (hashVal == checkEntry->mHashCode) && (Equals(checkEntry->mValue, findType, ctx))) 
+			if ((checkEntry->mValue != NULL) && (hashVal == checkEntry->mHashCode) && (Equals(checkEntry->mValue, findType, ctx)))
 			{
 				*entryPtr = EntryRef(this, checkEntryIdx);
 				return false;