Skip to content

Commit ccaa309

Browse files
committed
Update modules chapter for 2025.
1 parent bd5d4e6 commit ccaa309

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

talk/expert/modules.tex

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
\frametitlecpp[20]{Writing modules}
3030
\begin{exampleblock}{ratio.cpp}
3131
\begin{cppcode*}{}
32-
export module math;
32+
export module math; // module declaration
3333
import <string>;
3434
namespace utils { // ns. and module names orthogonal
35-
export struct Ratio { float num, denom; };
35+
export struct Ratio { int num, denom; };
3636
export std::string toString(const Ratio& r) { ... }
3737
void normalize(Ratio& r) { ... } // not exported
3838
}
@@ -112,11 +112,11 @@
112112
\begin{exampleblock}{ratio.cpp}
113113
\begin{cppcode*}{}
114114
export module math;
115-
struct Ratio { float num, denom; };
115+
struct Ratio { int num, denom; };
116116
export Ratio golden() { ... } // golden is visible
117117
\end{cppcode*}
118118
\end{exampleblock}
119-
\begin{exampleblock}{main.cpp}
119+
\begin{exampleblockGB}{main.cpp}{https://godbolt.org/z/n95rdxPdos}{Modules example}
120120
\begin{cppcode*}{}
121121
import math;
122122
import <iostream>;
@@ -129,7 +129,7 @@
129129
R r2{1.f, 3.f}; // OK
130130
}
131131
\end{cppcode*}
132-
\end{exampleblock}
132+
\end{exampleblockGB}
133133
\end{frame}
134134

135135
\begin{frame}[fragile]
@@ -191,7 +191,7 @@
191191
\end{block}
192192
\begin{exampleblock}{Interface}
193193
\begin{cppcode*}{}
194-
export module math;
194+
export module math; // Module interface unit declaration
195195

196196
export struct S { ... };
197197
export S f();
@@ -201,7 +201,7 @@
201201
\begin{cppcode*}{}
202202
module;
203203
#include <cassert>
204-
module math;
204+
module math; // Module implementation unit
205205
import <string>;
206206

207207
S f() { ... }
@@ -348,19 +348,20 @@
348348
% see: Minimal module support for the standard library http://wg21.link/P2412
349349
\begin{block}{Standard library modules}
350350
\begin{itemize}
351-
\item Use \cppinline|import std;| for the entire C++ standard library. Basically everything in namespace \cppinline|std|.
351+
\item Use \cppinline|import std;| for the entire C++ standard library.
352352
\begin{itemize}
353353
\item E.g.\ \cppinline{memcpy(a, b, n)}, \cppinline{sqrt(val)}, \cppinline{uint32_t}
354354
\item Note that you need to prefix with \cppinline{std::}
355+
\item Currently, support is not great (see later)
355356
\end{itemize}
356-
\item Use \cppinline|import std.compat;| for the entire C and C++ standard library
357+
\item \cppinline|import std.compat;| for the C and C++
357358
\item No macros are exported. For these, you still need to include the corresponding headers.
358359
\begin{cppcode*}{}
359360
import std; // everything C++
360361
#include <cassert> // for assert()
361362
#include <climits> // for e.g. CHAR_BIT
362363
\end{cppcode*}
363-
\item Definition of further, smaller modules of the standard library is in progress (e.g.\ fundamentals, containers, networking, etc.)
364+
\item Definition of further, smaller modules of the standard library is in progress
364365
\end{itemize}
365366
\end{block}
366367
\end{frame}
@@ -405,7 +406,7 @@
405406
\frametitlecpp[20]{Automatic include to import translation}
406407
\begin{block}{Importable headers}
407408
\begin{itemize}
408-
\item A header file which can successfully be either included or imported is called ``importable''
409+
\item A header file which can either be included or imported is called ``importable''
409410
\begin{itemize}
410411
\item I.e.\ the header does not require setup of preprocessor state before inclusion
411412
\end{itemize}
@@ -607,38 +608,23 @@
607608
\frametitlecpp[20]{Build system}
608609
\begin{block}{Status}
609610
\begin{itemize}
610-
\item Dependency scanner since clang 16: \texttt{clang-scan-deps}
611-
\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
612-
\item MSBuild (Windows) fully handles dependency scanning
613-
\item \cppinline{g++ a.cpp b.cpp ...} ``just works'', must be one line though
614-
\item \href{https://wg21.link/p1602}{Experimental extensions to GNU make} exist to grow dependency graph on the fly while modules are discovered
615-
\item Header units unsupported in all build systems (May 2023) % See talk: https://youtu.be/_LGR0U5Opdg?si=yQoCYD2yGFhi_vs6&t=3768
616-
\item C++23: \cppinline{import std;} supported in MSVC, partially in clang
611+
\item Build systems:
617612
\begin{itemize}
618-
\item GCC/clang/MSVC also plan support in C++20 % see: https://github.com/microsoft/STL/issues/3945
613+
\item Dependency scanner since clang 16: \texttt{clang-scan-deps}
614+
\item Cmake support in v3.28 (\href{https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html}{documentation})
615+
\item MSBuild (Windows) fully handles dependency scanning
616+
\item \href{https://wg21.link/p1602}{Experimental extensions to GNU make}
619617
\end{itemize}
620-
\end{itemize}
621-
\end{block}
622-
\end{frame}
623-
624-
\begin{frame}[fragile]
625-
\frametitlecpp[20]{Building modules (g++)}
626-
\begin{block}{Case study: g++}
627-
\begin{itemize}
628-
\item BMI is called CMI (compiled module interfaces)
629-
\item By default, g++ caches CMIs in subdirectory \texttt{./gcm.cache}
630-
\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
631-
\item Each module needs to be built before it can be imported
632-
\begin{itemize}
633-
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -c ratio.cpp -o ratio.o}}
634-
\item Generates \texttt{ratio.o} and \texttt{./gcm.cache/ratio.gcm} (CMI)
635-
\end{itemize}
636-
\item Each header unit needs to be built before it can be imported
618+
\item \cppinline{g++ a.cpp b.cpp ...} ``just works'', must be one line though
619+
\item C++23: \cppinline{import std;} supported in MSVC, partially in clang and gcc
620+
\begin{itemize}
621+
\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},
622+
\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})
623+
\item GCC/clang/MSVC also plan support in C++20 % see: https://github.com/microsoft/STL/issues/3945
624+
\end{itemize}
625+
\item Header units unsupported (May 2023) % See talk: https://youtu.be/_LGR0U5Opdg?si=yQoCYD2yGFhi_vs6&t=3768
637626
\begin{itemize}
638-
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -x c++-system-header vector}}
639-
\item Generates e.g.\ \texttt{./gcm.cache/usr/include/c++/11/vector.gcm} (CMI)
640-
\item {\footnotesize \cppinline{g++ -std=c++20 -fmodules-ts -x c++-header ratio.h}}
641-
\item Generates e.g.\ \texttt{./gcm.cache/,/ratio.h.gcm} (CMI)
627+
\item Standard library header units possible in gcc11 and MSVC (2025)
642628
\end{itemize}
643629
\end{itemize}
644630
\end{block}
@@ -658,7 +644,7 @@
658644
\begin{exampleblock}{Guidance for tomorrow}
659645
\begin{itemize}
660646
\item Start writing modules when your users have \cpp20
661-
\item Maybe import standard headers when \cpp20 is available
647+
\item Maybe import standard headers when compilers fully support \cpp20
662648
\item Start using \cppinline{import std;} when available
663649
\item Future of header units unclear (implementation difficulties)
664650
\end{itemize}

0 commit comments

Comments
 (0)