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/core.meta.slang | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 6581cc605..82a60a612 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -315,13 +315,18 @@ U operator,(T left, U right) return right; } -// The ternary `?:` operator does not short-circuit in HLSL, and Slang continues to -// follow that definition, so that this operator is effectively just an ordinary -// function, rather than a special-case piece of syntax. -// +// The ternary `?:` operator does not short-circuit in HLSL, and Slang no longer +// follow that definition for the scalar condition overload, so this declaration just serves +// for type-checking purpose only. + __generic __intrinsic_op(select) T operator?:(bool condition, T ifTrue, T ifFalse); __generic __intrinsic_op(select) vector operator?:(vector condition, vector ifTrue, vector ifFalse); +// Users are advised to use `select` instead if non-short-circuiting behavior is intended. +__generic __intrinsic_op(select) T select(bool condition, T ifTrue, T ifFalse); +__generic __intrinsic_op(select) vector select(vector condition, vector ifTrue, vector ifFalse); + + ${{{{ // We are going to use code generation to produce the // declarations for all of our base types. -- cgit v1.2.3