|
| 1 | +# SP #022: Upgrading Slang Codebase to C++20 |
| 2 | + |
| 3 | +This proposal outlines a plan to upgrade the Slang codebase from C++17 to C++20, enabling the use of modern C++ features. |
| 4 | + |
| 5 | +## Status |
| 6 | + |
| 7 | +Status: Design Review |
| 8 | + |
| 9 | +Implementation: Not yet implemented |
| 10 | + |
| 11 | +Author: Ellie Hermaszewska |
| 12 | + |
| 13 | +Reviewer: TBD |
| 14 | + |
| 15 | +## Background |
| 16 | + |
| 17 | +The Slang codebase currently uses C++17. C++20 introduces several valuable features that could improve code quality, and developer quality of life. There have been requests from people contributing to the Slang codebase to make this upgrade. |
| 18 | + |
| 19 | +## Related Work |
| 20 | + |
| 21 | +Some large, related C++ codebases have or are migrating to C++20: |
| 22 | + |
| 23 | +- The current Unreal Engine coding standards specify C++20 |
| 24 | +- Godot is making such a transition (some useful discussion and motivation here: https://github.com/godotengine/godot/pull/100749) |
| 25 | + |
| 26 | +However other similar projects such as LLVM and DXC are still on C++17. |
| 27 | + |
| 28 | +## Proposed Approach |
| 29 | + |
| 30 | +The implementation will merely bump the language standard the slang targets are built with, and fix any breakages in a backwards compatible way. This proposal does not aim to introduce any usage of specific C++20 features, the intention is that these will organically be used as time progresses. |
| 31 | + |
| 32 | +Documentation will need to be updated also. |
| 33 | + |
| 34 | +## Risks |
| 35 | + |
| 36 | +# Risks |
| 37 | + |
| 38 | +## Technical Risks |
| 39 | + |
| 40 | +- **Compiler compatibility gaps** across platforms and environments, this hasn't proven to be an issue with any other language versions or features, c++20 support should be standardized and mature by now |
| 41 | +- **Build system failures** on specific platforms, this will be picked up by CI before any merge |
| 42 | +- **Third-party dependency incompatibilities** all third party dependencies are compatible with C++20 |
| 43 | + - Unordered Dense |
| 44 | + - Spirv headers |
| 45 | + - Spirv tools |
| 46 | + - Vulkan headers |
| 47 | + |
| 48 | +## Customer Impact |
| 49 | + |
| 50 | +Only those compiling from source will be affected, additionally only those who are both compiling from source, and are on a very old compiler. Binary distributions will not be affected. |
| 51 | + |
| 52 | +For the unlikely possibility that there is a consumer with an unupgradeable old compiler who doesn't use the binary distribution, they can make their use case known with very little friction and we can roll back the change until they sort themselves out. |
| 53 | + |
| 54 | +The COM interfaces in the slang headers will not immediately change to use any C++20 features. |
| 55 | + |
| 56 | +Specifically checked with Omniverse, their lowest compiler version is gcc11 which is within the C++20 support versions. |
| 57 | + |
| 58 | +## Compiler Support Matrix |
| 59 | + |
| 60 | +These are the minimum compiler versions we will support. |
| 61 | + |
| 62 | +| Compiler | Minimum Version | Release Date | |
| 63 | +| -------- | --------------------- | ------------ | |
| 64 | +| MSVC | 19.29 (VS 2019 16.10) | May 2021 | |
| 65 | +| GCC | 10.0 | May 2020 | |
| 66 | +| Clang | 13.0 | Oct 2021 | |
| 67 | + |
| 68 | +## Detailed Explanation |
| 69 | + |
| 70 | +### Compiler Requirements |
| 71 | + |
| 72 | +Our CI already tests with C++20-compatible compilers: |
| 73 | + |
| 74 | +- GCC 13.0 |
| 75 | +- Clang 15 |
| 76 | +- MSVC 19.26 |
| 77 | + |
| 78 | +This means we already don't test with older C++17-only compilers. |
| 79 | + |
| 80 | +### Implementation |
| 81 | + |
| 82 | +The implementation will focus on updating build configurations to specify C++20, with minimal code changes initially. We'll gradually adopt C++20 features where they provide clear benefits. |
| 83 | + |
| 84 | +### Documentation Updates |
| 85 | + |
| 86 | +We'll update documentation to reflect new compiler requirements and provide guidance for downstream users. |
| 87 | + |
| 88 | +## Alternatives Considered |
| 89 | + |
| 90 | +1. **Stay on C++17**: |
| 91 | + |
| 92 | + - Pros: No disruption to users with older compilers |
| 93 | + - Cons: Miss out on language improvements and modern features |
| 94 | + |
| 95 | +2. **Skip to C++23**: |
| 96 | + |
| 97 | + - Pros: More features, longer before next upgrade needed |
| 98 | + - Cons: Limited compiler support, higher migration risk |
| 99 | + |
| 100 | +3. **Partial adoption via feature test macros**: |
| 101 | + - Pros: Gradual transition, backward compatibility |
| 102 | + - Cons: Complex code with conditional compilation, harder maintenance |
0 commit comments