Skip to content
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
68 changes: 27 additions & 41 deletions talk/expert/modules.tex
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
\frametitlecpp[20]{Writing modules}
\begin{exampleblock}{ratio.cpp}
\begin{cppcode*}{}
export module math;
export module math; // module declaration
import <string>;
namespace utils { // ns. and module names orthogonal
export struct Ratio { float num, denom; };
export struct Ratio { int num, denom; };
export std::string toString(const Ratio& r) { ... }
void normalize(Ratio& r) { ... } // not exported
}
Expand Down Expand Up @@ -112,11 +112,11 @@
\begin{exampleblock}{ratio.cpp}
\begin{cppcode*}{}
export module math;
struct Ratio { float num, denom; };
struct Ratio { int num, denom; };
export Ratio golden() { ... } // golden is visible
\end{cppcode*}
\end{exampleblock}
\begin{exampleblock}{main.cpp}
\begin{exampleblockGB}{main.cpp}{https://godbolt.org/z/n95rdxPdos}{Modules example}
\begin{cppcode*}{}
import math;
import <iostream>;
Expand All @@ -129,7 +129,7 @@
R r2{1.f, 3.f}; // OK
}
\end{cppcode*}
\end{exampleblock}
\end{exampleblockGB}
\end{frame}

\begin{frame}[fragile]
Expand Down Expand Up @@ -191,7 +191,7 @@
\end{block}
\begin{exampleblock}{Interface}
\begin{cppcode*}{}
export module math;
export module math; // Module interface unit declaration

export struct S { ... };
export S f();
Expand All @@ -201,7 +201,7 @@
\begin{cppcode*}{}
module;
#include <cassert>
module math;
module math; // Module implementation unit
import <string>;

S f() { ... }
Expand Down Expand Up @@ -348,19 +348,20 @@
% see: Minimal module support for the standard library http://wg21.link/P2412
\begin{block}{Standard library modules}
\begin{itemize}
\item Use \cppinline|import std;| for the entire C++ standard library. Basically everything in namespace \cppinline|std|.
\item Use \cppinline|import std;| for the entire C++ standard library.
\begin{itemize}
\item E.g.\ \cppinline{memcpy(a, b, n)}, \cppinline{sqrt(val)}, \cppinline{uint32_t}
\item Note that you need to prefix with \cppinline{std::}
\item Currently, support is not great (see later)
\end{itemize}
\item Use \cppinline|import std.compat;| for the entire C and C++ standard library
\item \cppinline|import std.compat;| for the C and C++
\item No macros are exported. For these, you still need to include the corresponding headers.
\begin{cppcode*}{}
import std; // everything C++
#include <cassert> // for assert()
#include <climits> // for e.g. CHAR_BIT
\end{cppcode*}
\item Definition of further, smaller modules of the standard library is in progress (e.g.\ fundamentals, containers, networking, etc.)
\item Definition of further, smaller modules of the standard library is in progress
\end{itemize}
\end{block}
\end{frame}
Expand Down Expand Up @@ -405,7 +406,7 @@
\frametitlecpp[20]{Automatic include to import translation}
\begin{block}{Importable headers}
\begin{itemize}
\item A header file which can successfully be either included or imported is called ``importable''
\item A header file which can either be included or imported is called ``importable''
\begin{itemize}
\item I.e.\ the header does not require setup of preprocessor state before inclusion
\end{itemize}
Expand Down Expand Up @@ -607,38 +608,23 @@
\frametitlecpp[20]{Build system}
\begin{block}{Status}
\begin{itemize}
\item Dependency scanner since clang 16: \texttt{clang-scan-deps}
\item Experimental module support in cmake since 3.26, uses \texttt{clang-scan-deps}, many fixes in later versions % see: https://discourse.cmake.org/t/c-20-modules-update/7330/24 and https://youtu.be/c563KgO-uf4?si=HUpnSivtDxvBoTr3&t=3592
\item MSBuild (Windows) fully handles dependency scanning
\item \cppinline{g++ a.cpp b.cpp ...} ``just works'', must be one line though
\item \href{https://wg21.link/p1602}{Experimental extensions to GNU make} exist to grow dependency graph on the fly while modules are discovered
\item Header units unsupported in all build systems (May 2023) % See talk: https://youtu.be/_LGR0U5Opdg?si=yQoCYD2yGFhi_vs6&t=3768
\item C++23: \cppinline{import std;} supported in MSVC, partially in clang
\item Build systems:
\begin{itemize}
\item GCC/clang/MSVC also plan support in C++20 % see: https://github.com/microsoft/STL/issues/3945
\item Dependency scanner since clang 16: \texttt{clang-scan-deps}
\item Cmake support in v3.28 (\href{https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html}{documentation})
\item MSBuild (Windows) fully handles dependency scanning
\item \href{https://wg21.link/p1602}{Experimental extensions to GNU make}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}

\begin{frame}[fragile]
\frametitlecpp[20]{Building modules (g++)}
\begin{block}{Case study: g++}
\begin{itemize}
\item BMI is called CMI (compiled module interfaces)
\item By default, g++ caches CMIs in subdirectory \texttt{./gcm.cache}
\item Uses a \href{https://wg21.link/P1184}{module mapper} to resolve imports, which specifies a protocol and uses a central server for module maintenance
\item Each module needs to be built before it can be imported
\begin{itemize}
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -c ratio.cpp -o ratio.o}}
\item Generates \texttt{ratio.o} and \texttt{./gcm.cache/ratio.gcm} (CMI)
\end{itemize}
\item Each header unit needs to be built before it can be imported
\item \cppinline{g++ a.cpp b.cpp ...} ``just works'', must be one line though
\item C++23: \cppinline{import std;} supported in MSVC, partially in clang and gcc
\begin{itemize}
\item The standard library module currently has to be compiled manually (\href{https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7db55c0ba1baaf0e323ef7f9ef8c9cda077d40e9}{see gcc commit in 2024},
\href{https://0xstubs.org/using-the-c23-std-module-with-gcc-15/}{gcc-15 recipe}, \href{https://0xstubs.org/using-the-c23-std-module-with-clang-18/}{clang-18 recipe})
\item GCC/clang/MSVC also plan support in C++20 % see: https://github.com/microsoft/STL/issues/3945
\end{itemize}
\item Header units unsupported (May 2023) % See talk: https://youtu.be/_LGR0U5Opdg?si=yQoCYD2yGFhi_vs6&t=3768
\begin{itemize}
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -x c++-system-header vector}}
\item Generates e.g.\ \texttt{./gcm.cache/usr/include/c++/11/vector.gcm} (CMI)
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -x c++-header ratio.h}}
\item Generates e.g.\ \texttt{./gcm.cache/,/ratio.h.gcm} (CMI)
\item Standard library header units possible in gcc11 and MSVC (2025)
\end{itemize}
\end{itemize}
\end{block}
Expand All @@ -658,7 +644,7 @@
\begin{exampleblock}{Guidance for tomorrow}
\begin{itemize}
\item Start writing modules when your users have \cpp20
\item Maybe import standard headers when \cpp20 is available
\item Maybe import standard headers when compilers fully support \cpp20
\item Start using \cppinline{import std;} when available
\item Future of header units unclear (implementation difficulties)
\end{itemize}
Expand Down
2 changes: 1 addition & 1 deletion talk/tools/sanitizers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
\begin{itemize}
\item Compiler adds run-time checks ($\sim$2x slow down)
\item \cppinline{IsPoisoned(address)} looks up state of address in asan's ``shadow memory''
\item Shadow memory: memory where 1 shadow byte tracks state of 8 application bytes (state = accessible, poisoned, \ldots)
\item Shadow memory: memory section to look up which addresses are accessible (state = accessible, poisoned, \ldots)
\item Functions that deal with memory (\cppinline{new() / delete()} / strings / ...) update entries in shadow memory when called
\end{itemize}
\end{block}
Expand Down