Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Linkage section #249

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions specs/language/declarations.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
\Ch{Declarations}{Decl}
\Sec{Function Definitions}{Decl.Function}
\Sec{Attributes}{Decl.Attr}
\Sub{Entry Attributes}{Decl.Attr.Entry}
\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.

\p There are three linkages recognized: \textit{external linkage}, \textit{internal linkage} and \textit{no linkage}.

\Sub{External Linkage}{Decl.Linkage.External}

\p Entities with \textit{external linkage} can be referred to from the scopes in the other translation units and enable linking between them.

\p The following entities in HLSL have \textit{external linkage}:
\begin{itemize}
\item entry point functions
\item functions marked with \texttt{export} keyword
\item global variables that are not marked \texttt{static} or \texttt{groupshared} \footnote{These are not really linked with other translation units but rather their values are loaded indirectly based on cbuffer mapping.}
\item static data members of classes or template classes
\end{itemize}

\p Linkage of functions (including template functions) that are not entry points or marked with \texttt{export} keyword is implementation dependent. \footnote{In DXC today functions that are not entry points or exported have \textit{internal linkage} by default. This can be overriden by \texttt{-default-linkage} compiler option.}

\Sub{Internal Linkage}{Decl.Linkage.Internal}

\p Entities with \textit{internal linkage} can be referred to from all scopes in the current translation unit.

\p The following entities in HLSL have \textit{internal linkage}:
\begin{itemize}
\item global variables marked as \texttt{static} or \texttt{groupshared}
\item all entities declared in an unnamed namespace or a namespace within an unnamed namespace
\item enumerations
\item classes or template classes, their member functions, and nested classes and enumerations
\end{itemize}

\Sub{No Linkage}{Decl.Linkage.NoLinkage}

\p An entity with \textit{no linkage} can be referred to only from the scope it is in.

\p Any of the following entites declared at function scope or block scopes derived from function scope have no linkage:
\begin{itemize}
\item local variables
\item local classes and their member functions
\item other entities declared at function scope or block scopes derived from function scope that such as typedefs, enumerations, and enumerators
\end{itemize}
2 changes: 2 additions & 0 deletions specs/language/hlsl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
\input{conversions}
\input{expressions}
\input{overloading}
\input{statements}
\input{declarations}

\input{placeholders} % Declare placeholder references

Expand Down
6 changes: 0 additions & 6 deletions specs/language/placeholders.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
% forward references can be inserted into the specification as it is being
% written to force updating the references as they change.

\Ch{Statements}{Stmt}
\Sec{Label Statements}{Stmt.Label}
damyanp marked this conversation as resolved.
Show resolved Hide resolved
\Ch{Declarations}{Decl}
\Sec{Function Definitions}{Decl.Function}
\Sec{Attributes}{Decl.Attr}
\Sub{Entry Attributes}{Decl.Attr.Entry}
\Ch{Classes}{Classes}
\Sec{Static Members}{Classes.Static}
\Sec{Conversions}{Classes.Conversions}
Expand Down
2 changes: 2 additions & 0 deletions specs/language/statements.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\Ch{Statements}{Stmt}
\Sec{Label Statements}{Stmt.Label}
Loading