From 666af0962b6ab41489a3a3287db83f77c2f6461a Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 24 Mar 2023 20:17:46 -0700 Subject: Switch to short circuiting semantics for scalar `?:` operator. (#2733) --- source/slang/slang-check-expr.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index bfad1dbfe..cfcb15269 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -2022,6 +2022,40 @@ namespace Slang return rs; } + Expr* SemanticsExprVisitor::visitSelectExpr(SelectExpr* expr) + { + auto result = visitInvokeExpr(expr); + if (as(result->type.type)) + return result; + auto invokeExpr = as(result); + if (!result) + return result; + if (invokeExpr->arguments.getCount() != 3) + return result; + + if (as(invokeExpr->arguments[0]->type.type)) + { + auto newArgs = invokeExpr->arguments; + expr->arguments.clear(); + expr->arguments = newArgs; + expr->type = invokeExpr->type; + return expr; + } + + if (getParentDifferentiableAttribute()) + { + // If we are in a differentiable func, issue + // a diagnostic on use of non short-circuiting select. + getSink()->diagnose(expr->loc, Diagnostics::useOfNonShortCircuitingOperatorInDiffFunc); + } + else + { + // For all other functions, we issue a warning for deprecation of vector-typed ?: operator. + getSink()->diagnose(expr->loc, Diagnostics::useOfNonShortCircuitingOperator); + } + return result; + } + Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr *expr) { // check the base expression first -- cgit v1.2.3