gen: replace anonymous namespace with per-type name in enum impls#246
Merged
Conversation
gen-quality
|
Replace the anonymous namespace wrapping kWire[] with a per-type
name (k{{ident}}Wire) so that unity builds can include multiple
generated enum .cpp files in a single translation unit without
redefinition errors.
gen-quality
|
Contributor
|
I left this comment at the issue as well: we should probably do the same for the 5 hand-crafted mx::core TUs that have anonymous namespaces. With that change, I can unity build the entire MX subsystem and it is much faster and less noisy. |
Coverage reportCore-dev coverage
|
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 77.8% | 28487 / 36624 |
| Functions | 74.3% | 6349 / 8550 |
| Branches | 50.6% | 22632 / 44725 |
API coverage src/private/mx/{api,impl,utility}/
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 78.5% | 5913 / 7535 |
| Functions | 63.5% | 2006 / 3159 |
| Branches | 47.8% | 4998 / 10455 |
Core HTML report | API HTML report
Commit c4b2a5ecfb3699a6f48e735a44837625763f3bec.
1 task
webern
added a commit
that referenced
this pull request
Jun 27, 2026
## Summary Follow-up to #246. The previous PR fixed the generated enum, number, string, and smufl_prefixed templates. This PR covers the remaining cases found by doing an actual unity build (`CMAKE_UNITY_BUILD=ON`, `BATCH_SIZE=0`): - `src/private/mx/core/Token.cpp` and `NameToken.cpp` — both defined `isNameChar` in an anonymous namespace inside `mx::core`. Renamed to `tokenIsNameChar` / `nameTokenIsNameChar`. - `gen/cpp/templates/nmtoken_string.cpp.tmpl` and `smufl_wavy.cpp.tmpl` — same pattern, both generating `isNameChar` in anonymous namespaces. Renamed to `isNameChar{{ident}}`. - `AGENTS.md` — added a project-wide rule prohibiting anonymous namespaces, with the unity build test command so contributors can verify. No CMake changes are needed by contributors wanting unity builds. The standard CMake flags work as-is: ``` cmake -S . -B build/unity -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=0 cmake --build build/unity --target mx ``` ## Testing - Unity build passes clean (`cmake --build` with `CMAKE_UNITY_BUILD=ON BATCH_SIZE=0`, target `mx`) - [ ] `make test` passes ## References - Closes #245 - Follow-up to #246
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Each generated enum `.cpp` file (136 of them) contained an anonymous `namespace {}` wrapping a
`constexpr std::string_view kWire[]` lookup table. In a normal build this is fine — each
translation unit gets its own anonymous namespace and the names never conflict. In a unity build,
however, all included `.cpp` files share one translation unit, so the anonymous namespaces merge
and 136 definitions of `kWire` collide.
The fix is minimal: drop the anonymous namespace and give the array a per-type name
(`kYesNoWire`, `kAboveBelowWire`, etc.) so the names are unique within `mx::core` and unity
builds can include multiple enum files without redefinition errors.
Changes:
gen/cpp/templates/enum.cpp.tmpl— remove the anonymous namespace, renamekWiretok{{ident}}Wiresrc/private/mx/core/generated/*.cpp— 97 regenerated files (the enum-class strategy files that had the anonymous namespace)Testing
make testpassesReferences