Upgrading to C++ Modules #7179
expipiplus1
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I propose we should upgrade the Slang codebase by adopting C++20 modules, improving build times and code organization.
Background
Following our recent upgrade to C++20 (SP #22), we now have the opportunity to leverage one of its most significant features: modules. The Slang codebase currently uses traditional header/source file organization with
#include
directives, which leads to several issues:C++20 modules address these issues by providing cleaner dependency management and faster compilation through better interface boundaries.
Proposed Approach
We propose a focused approach to implementing C++20 modules in the Slang codebase:
Phase 1: Infrastructure Setup (1-2 weeks)
Build system updates:
Create initial module structure:
Proof of concept:
slang-core
) to modulesPhase 2: Core Library Conversion (2-3 weeks)
Convert foundation libraries:
slang-core
module (containers, IO, etc.)slang-compiler-core
module (diagnostics, artifacts, etc.)Update build pipeline:
Phase 3: Full Codebase Conversion (3-4 weeks)
Convert remaining components:
slang
module (compiler, type system, etc.)Optimize module dependencies:
Module Organization
We propose organizing the codebase into the following primary modules:
Each module will have submodules as needed. For example:
Detailed Explanation
Module Interface Files
Each module will have a primary interface file that exports the module's public API. For example:
Submodule interface files will focus on specific functionality:
Implementation Files
Implementation files will import the modules they depend on:
Public API Preservation
We will maintain all public-facing headers for backward compatibility with external code. These headers will:
Example:
Migration Strategy
For each component:
External Library Integration
Third-party libraries without module support will be handled through:
Header imports: Using C++20's ability to import traditional headers
import <ankerl/unordered_dense.hpp>; // Import third-party header
Wrapper modules: Creating thin wrapper modules around external libraries when beneficial
Risks
Technical Risks
Mitigation Strategies
Alternatives Considered
Wait for more mature module support:
Partial module adoption:
Module-like organization without C++20 modules:
Beta Was this translation helpful? Give feedback.
All reactions