summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-07 23:01:53 -0700
committerGitHub <noreply@github.com>2023-09-07 23:01:53 -0700
commitcb5dd19992fb77ca2be866d9c6f2f4436c8b1c1e (patch)
tree4a24573f9da79618c0e65e7462101ab3d0b640c4 /source/slang/slang-check-conversion.cpp
parenta7fa215e81e510de34ac96778ac6320cbb642d64 (diff)
Incur l-value conversion cost during overload resolution. (#3195)
* Incur l-value conversion cost during overload resolution. * Fix compile error. * cleanup. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index 5a9c8df12..c4efba658 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -705,7 +705,7 @@ namespace Slang
CoercionSite site,
Type* toType,
Expr** outToExpr,
- Type* fromType,
+ QualType fromType,
Expr* fromExpr,
ConversionCost* outCost)
{
@@ -773,7 +773,7 @@ namespace Slang
auto toBase = toModified ? toModified->getBase() : toType;
//
auto fromModified = as<ModifiedType>(fromType);
- auto fromBase = fromModified ? fromModified->getBase() : fromType;
+ auto fromBase = fromModified ? QualType(fromModified->getBase(), fromType.isLeftValue) : fromType;
if((toModified || fromModified) && toBase->equals(fromBase))
@@ -1060,7 +1060,7 @@ namespace Slang
OverloadResolveContext overloadContext;
overloadContext.disallowNestedConversions = true;
overloadContext.argCount = 1;
- overloadContext.argTypes = &fromType;
+ overloadContext.argTypes = &fromType.type;
overloadContext.args = &fromExpr;
overloadContext.originalExpr = nullptr;
@@ -1191,6 +1191,11 @@ namespace Slang
}
}
}
+ if (fromType.isLeftValue)
+ {
+ // If we are implicitly casting the type of an l-value, we need to impose additional cost.
+ cost += kConversionCost_LValueCast;
+ }
if(outCost)
*outCost = cost;
@@ -1245,7 +1250,7 @@ namespace Slang
bool SemanticsVisitor::canCoerce(
Type* toType,
- Type* fromType,
+ QualType fromType,
Expr* fromExpr,
ConversionCost* outCost)
{
@@ -1380,7 +1385,7 @@ namespace Slang
bool SemanticsVisitor::canConvertImplicitly(
Type* toType,
- Type* fromType)
+ QualType fromType)
{
auto conversionCost = getConversionCost(toType, fromType);
@@ -1391,7 +1396,7 @@ namespace Slang
return true;
}
- ConversionCost SemanticsVisitor::getConversionCost(Type* toType, Type* fromType)
+ ConversionCost SemanticsVisitor::getConversionCost(Type* toType, QualType fromType)
{
ConversionCost conversionCost = kConversionCost_Impossible;
if (!canCoerce(toType, fromType, nullptr, &conversionCost))