Skip to content

Commit

Permalink
Add export keyword to HLSL language spec (#268)
Browse files Browse the repository at this point in the history
Add export keyword to HLSL language specs. The spec describes two ways the export keyword can be used. One way is to use it on individual function declarations like `export void f() {}`. The other way is to use it on a group of function declarations:

export {
   void f1();
   void f2() {}
}

DXC currently supports only the first case, but since Clang has support for both, we might as well support it in HLSL 202y too.

This spec update does not yet include detailed rules for when a function can or cannot be exported, such as when it has resource argument or semantic annotations. That will be covered by llvm/llvm-project#93330.

This change also adds more sections under Declarations (based on C++ spec layout).

Contributes to: llvm/llvm-project#92812
  • Loading branch information
hekota authored Jun 26, 2024
1 parent 735cce6 commit b7e99e2
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions specs/language/declarations.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
\Ch{Declarations}{Decl}
\Sec{Preamble}{Decl.Pre}
\p Declarations generally specify how names are to be interpreted. Declarations have the form
\begin{grammar}
\define{declaration-seq}\br
\textit{declaration}\br
\textit{declaration-seq declaration}

\define{declaration}\br
\textit{name-declaration}\br
\textit{special-declaration}

\define{name-declaration}\br
...

\define{special-declaration}\br
\textit{export-declaration-group}\br
...
\end{grammar}

\Sec{Specifiers}{Decl.Spec}
\Sub{General}{Decl.Spec.General}
\p The specifiers that can be used in a declaration are
\begin{grammar}
\define{decl-specifier}\br
\textit{function-specifier}\br
...
\end{grammar}

\Sub{Function specifiers}{Decl.Spec.Fct}

\p A \textit{function-specifier} can be used only in a function declaration.

\begin{grammar}
\define{function-specifier}\br
\texttt{export}\br
\end{grammar}

\p The \texttt{export} specifier denotes that the function has \textit{external linkage} (\ref{Decl.Linkage.External}).

\p The \texttt{export} specifier cannot be used on functions directly or indirectly within an unnamed namespace.

\p Functions with \textit{external linkage} can also be specified in \textit{export-declaration-group} (\ref{Decl.Export}).

\p If a function is declared with an \texttt{export} specifier then all redeclarations of the same function must also use the \texttt{export} specifier or be part of \textit{export-declaration-group} (\ref{Decl.Export}).

\Sec{Declarators}{Decl.Decl}
\Sec{Initializers}{Decl.Init}
\Sec{Function Definitions}{Decl.Function}
\Sec{Attributes}{Decl.Attr}
\Sub{Entry Attributes}{Decl.Attr.Entry}

\Sec{Export Declarations}{Decl.Export}

\p One or more functions with \textit{external linkage} can be also specified in the form of

\begin{grammar}
\define{export-declaration-group}\br
\texttt{export} \terminal{\{} \opt{function-declaration-seq} \terminal{\}}\br

\define{function-declaration-seq}\br
\textit{function-declaration} \opt{function-declaration-seq}
\end{grammar}

\p The \texttt{export} specifier denotes that every \textit{function-declaration} included in \textit{function-declaration-seq} has \textit{external linkage} (\ref{Decl.Linkage.External}).

\p The \textit{export-declaration-group} declaration cannot appear directly or indirectly within an unnamed namespace.

\p Functions with \textit{external linkage} can also be declared with an \texttt{export} specifier (\ref{Decl.Spec.Fct}).

\p If a function is part of an \textit{export-declaration-group} then all redeclarations of the same function must also be part on a \textit{export-declaration-group} or be declared with an \texttt{export} specifier (\ref{Decl.Spec.Fct}).

\Sec{Linkage}{Decl.Linkage}

\p An entity that denotes an object, reference, function, type, template, namespace, or value, may have a \textit{linkage}. If a name has \textit{linkage}, it refers to the same entity as the same name introduced by a declaration in another scope. If a variable, function, or another entity with the same name is declared in several scopes, but does not have sufficient \textit{linkage}, then several instances of the entity are generated.
Expand Down

0 comments on commit b7e99e2

Please sign in to comment.