Skip to content

Commit

Permalink
Update conversion sequences and describe ranks (#168)
Browse files Browse the repository at this point in the history
This change fixes a spec bug in the description of HLSL truncation
casts, restricts the array-to-pointer cast to unbounded arrays (where
they decay to pointers), and specifies integral and floating point
conversion ranks.

This updates the spec to be more consistent with how the language is
being implemented in clang and lays the groundwork for describing
overload resolution rules.

Co-authored-by: S. Bharadwaj Yadavalli <[email protected]>
  • Loading branch information
llvm-beanz and bharadwajy authored Apr 15, 2024
1 parent 2a8e8da commit 35640cf
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions specs/language/conversions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

\Sec{Array-to-pointer conversion}{Conv.array}

\p An lvalue or rvalue of type \texttt{T[]} (bounded or unbounded), can be
\p An lvalue or rvalue of type \texttt{T[N]} (constant-sized array), can be
converted to a prvalue of type pointer to \texttt{T}.
[\textit{Note: \acrshort{hlsl} does not support grammar for specifying pointer or
reference types, however they are used in the type system and must be described
Expand Down Expand Up @@ -109,13 +109,16 @@

\p A glvalue of type \texttt{vector<T,x>} can be converted to a cxvalue of type
\texttt{vector<T,y>}, or a prvalue of type \texttt{vector<T,x>} can be converted
to a prvalue of type \texttt{vector<T,y>} only if \texttt{x} is less than
\texttt{y}.
to a prvalue of type \texttt{vector<T,y>} only if \( y < x \). The resulting
value is comprised of elements \( [0..y) \), dropping elements [y+1..x).

\p A glvalue of type \texttt{matrix<T,x,y>} can be converted to a cxvalue of type
\texttt{matrix<T,z,w>}, or a prvalue of type \texttt{matrix<T,x,y>} can be
converted to a prvalue of type \texttt{matrix<T,z,w>} only if \( x \leq z \)
and \(y \leq w \)
and \(y \leq w \). Matrix truncation is performed on each row and column
dimension separately. The resulting value is comprised of vectors \( [0..z) \)
which are each separately comprised of elements \( [0..w) \). Trailing vectors
and elements are dropped.

\Sec{Component-wise conversions}{Conv.cwise}

Expand All @@ -138,3 +141,39 @@
A prvalue of type "\textit{cv1} \texttt{T}" can be converted to a prvalue of type
"\textit{cv2} \texttt{T}" if type "\textit{cv2} \texttt{T}" is more cv-qualified
than "\textit{cv1} \texttt{T}".

\Sec{Conversion Rank}{Conv.rank}

\p Every integer and floating point type have defined conversion ranks.
A \textit{promotion} is any conversion of a value from a lower conversion rank
to a higher conversion rank.

\Sub{Integer Conversion Rank}{Conv.rank.int}

\begin{itemize}
\item No two signed integer types shall have the same conversion rank even if
they have the same representation.
\item The rank of a signed integer type shall be greater than the rank of any
signed integer type with a smaller size.
\item The rank of any unsigned integer type shall equal the rank of the
corresponding signed integer type.
\item The rank of \texttt{bool} shall be less than the rank of all other
standard integer types.
\item For all integer types \texttt{T1}, \texttt{T2}, and \texttt{T3}: if
\texttt{T1} has greater rank than \texttt{T2} and \texttt{T2} has greater rank
than \texttt{T3}, then \texttt{T1} shall have greater rank than \texttt{T3}.
\end{itemize}

\Sub{Floating Point Conversion Rank}{Conv.rank.float}

\begin{itemize}
\item No two floating point types shall have the same conversion rank even if
they have the same representation.
\item The rank of a floating point type shall be greater than the rank of any
floating point type with a smaller size.
\item The rank \texttt{float} shall be greater than the rank of \texttt{half}.
\item For all floating point types \texttt{T1}, \texttt{T2}, and \texttt{T3}:
if \texttt{T1} has greater rank than \texttt{T2} and \texttt{T2} has greater
rank than \texttt{T3}, then \texttt{T1} shall have greater rank than
\texttt{T3}.
\end{itemize}

0 comments on commit 35640cf

Please sign in to comment.