What are Explicit modules?

Asked on 07/30/2024

1 search

Explicit modules are a new way of building Swift and Clang modules in Xcode, introduced to improve the build process. Here are the key points about explicitly built modules:

  1. Phases of Compilation: Xcode splits the compilation of each source file into three separate phases: scanning, building modules, and finally building the original code. This is different from the previous approach where these operations were performed implicitly as part of compiling source files.

  2. Build System Control: Explicitly built modules put the build system in control of module builds. This means that the build system is now aware of the module graph and can make more informed scheduling choices, leading to more efficient builds.

  3. Build Logs and Timeline: The build logs now show explicit scan tasks, module compile tasks, and the original source file tasks. This detailed breakdown helps in better parallelism and clearer error messages if the build fails due to a module issue. The build timeline also reflects these explicit modules, making it easier to see where time is being spent during the build process.

  4. Efficiency and Reliability: Builds are more reliable with precise dependencies and deterministic build graphs. The compiler runs the same way every time, and any build failures can be reproduced by running the failing task again in isolation. This also means that a clean build now rebuilds modules, leading to more predictable and reliable builds.

  5. Debugging Improvements: Explicit modules make debugging faster since the debugger (LLDB) can reuse the build outputs when evaluating expressions.

For more detailed information, you can refer to the session Demystify explicitly built modules.

Relevant Sessions

  1. Demystify explicitly built modules
  2. What’s new in Xcode 16
  3. What’s new in Swift