Skip to content

Switch to custom reflection (MrDocs.Describe)#1171

Open
gennaroprota wants to merge 4 commits intocppalliance:developfrom
gennaroprota:refactor/switch_to_custom_reflection
Open

Switch to custom reflection (MrDocs.Describe)#1171
gennaroprota wants to merge 4 commits intocppalliance:developfrom
gennaroprota:refactor/switch_to_custom_reflection

Conversation

@gennaroprota
Copy link
Copy Markdown
Collaborator

@gennaroprota gennaroprota commented Mar 23, 2026

This introduces our own (public) reflection facilities (replacing Boost.Describe/Boost.Mp11) and leverages them to eliminate per-type boilerplate.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

🚧 Danger.js checks for MrDocs are experimental; expect some rough edges while we tune the rules.

ℹ️ Info

Note

Commit 937aab7 (feat: make the reflection consumers public) touches 2578 source lines (non-test). Large change; add reviewer context if needed.

🧾 Changes by Scope

Scope Lines Δ% Lines Δ Lines + Lines - Files Δ Files + Files ~ Files ↔ Files -
🛠️ Source 96% 4285 2082 2203 117 2 108 - 7
🤝 Third-party 4% 168 - 168 6 - - - 6
📄 Docs <1% 14 7 7 1 - 1 - -
🏗️ Build <1% 5 - 5 1 - 1 - -
📦 Other <1% 4 - 4 1 - 1 - -
🧪 Unit Tests <1% 1 1 - 1 - 1 - -
Total 100% 4477 2090 2387 127 2 112 - 13

Legend: Files + (added), Files ~ (modified), Files ↔ (renamed), Files - (removed)

🔝 Top Files

  • include/mrdocs/Support/Reflection.hpp (Source): 672 lines Δ (+672 / -0)
  • src/lib/Support/Reflection/Reflection.hpp (Source): 656 lines Δ (+0 / -656)
  • src/lib/Support/Reflection/Reflection.cpp (Source): 523 lines Δ (+0 / -523)

Generated by 🚫 dangerJS against 937aab7

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 89.05473% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (9a12737) to head (937aab7).

Files with missing lines Patch % Lines
include/mrdocs/Support/Reflection.hpp 89.51% 8 Missing and 7 partials ⚠️
src/lib/Metadata/Info.cpp 66.66% 1 Missing and 2 partials ⚠️
src/lib/Metadata/Type.cpp 33.33% 0 Missing and 2 partials ⚠️
src/lib/Metadata/DocComment.cpp 91.66% 0 Missing and 1 partial ⚠️
src/lib/Metadata/DocComment/Inline.cpp 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (89.05%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1171      +/-   ##
===========================================
+ Coverage    78.26%   78.32%   +0.06%     
===========================================
  Files          348      345       -3     
  Lines        32540    32511      -29     
  Branches      6525     6512      -13     
===========================================
- Hits         25468    25465       -3     
+ Misses        4676     4656      -20     
+ Partials      2396     2390       -6     
Flag Coverage Δ
bootstrap 81.89% <ø> (ø)
cpp 77.96% <89.05%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented Mar 23, 2026

An automated preview of the documentation is available at https://1171.mrdocs.prtest2.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-03-27 17:09:25 UTC

@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch 9 times, most recently from 33415f8 to 8488bb2 Compare March 24, 2026 09:15
@gennaroprota gennaroprota changed the title refactor: switch to custom reflection (mrdocs::describe) refactor: switch to custom reflection (MrDocs.Describe) Mar 24, 2026
@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch 3 times, most recently from eb2cc4a to 59b60d5 Compare March 25, 2026 11:06
Introduces include/mrdocs/Support/Describe.hpp — a minimal, C++23-only
replacement for Boost.Describe and Boost.Mp11. Provides
MRDOCS_DESCRIBE_STRUCT and MRDOCS_DESCRIBE_ENUM macros with compile-time
member/base/enum descriptors and a fold-expression-based for_each.

Adds MRDOCS_DESCRIBE_* calls next to every type definition. This moves
reflection metadata from the private Reflection.hpp registry into the
public headers, enabling future single-template operations (e.g. merge)
that eliminate per-type boilerplate.

Both descriptor systems coexist in this commit — no consumers are
changed yet.
@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch 3 times, most recently from f464cdf to d79dd24 Compare March 26, 2026 09:42
@gennaroprota gennaroprota changed the title refactor: switch to custom reflection (MrDocs.Describe) Switch to custom reflection (MrDocs.Describe) Mar 26, 2026
@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch 3 times, most recently from 8864258 to 8b25b3a Compare March 26, 2026 18:15
Copy link
Copy Markdown
Collaborator

@alandefreitas alandefreitas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (mostly)

requires boost::describe::has_describe_enumerators<Enum>::value
requires describe::has_describe_enumerators<Enum>::value
std::string
toString(Enum e)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be with other reflection functions? What makes this one special?

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com)
// Copyright (c) 2025 Gennaro Prota (gennaro.prota@gmail.com)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time machine? 😆

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2025 Gennaro Prota (gennaro.prota@gmail.com)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heeeeeey! They would blame you now hehe

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2025 Gennaro Prota (gennaro.prota@gmail.com)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review all of these...

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Symbol/Friend.hpp>
#include <mrdocs/Support/DomMapping.hpp>
#include <mrdocs/Support/Merge.hpp>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm put "boost.describe" in <mrdocs/Support/Describe.hpp> and everything that uses the descriptions in <mrdocs/Support/Reflection.hpp> instead of one header per extra function (and some extra functions are actually going into Describe.hpp right now, which is confusing). But if you like it this way, that's also fine.


template <typename IO>
void
tag_invoke(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't all of these tag_invokes be defined with reflection yet?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but I was blocked by type erasure in LazyObject. Its virtual functions (get, visit, size, exists) are defined in LazyObject.hpp and call tag_invoke through lambdas. When the compiler instantiates LazyObjectImpl<ConceptSymbol, ... in DomCorpus.cpp, the generic tag_invoke template (from DomMapping.hpp) needs to be visible; but including it from LazyObject.hpp creates a circular dependency, and two-phase lookup doesn't find it, because LazyObjectIO lives in mrdocs::dom::detail, not in the type's namespace.

Removing the type erasure (making LazyObjectImpl see the tag_invoke directly) is the next step.

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2025 Gennaro Prota (gennaro.prota@gmail.com)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch from 8b25b3a to 5df1a0b Compare March 27, 2026 16:36
Switches toString(Enum), mapReflectedType, mergeReflectedType, and
XMLWriter from Boost.Describe/Boost.Mp11 to the custom MrDocs.Describe
facility introduced in the previous commit.

Removes #include <lib/Support/Reflection/Reflection.hpp> from all .cpp
files that depended on it for BOOST_DESCRIBE macros (now superseded by
per-header MRDOCS_DESCRIBE_* calls). Updates Reflection.cpp with direct
includes and moves the Optional<DocComment> tag_invoke there.

Deletes the now-unreferenced Reflection.hpp registry.
…emplate

Adds a constrained merge(T&, T&&) template in MergeReflectedType.hpp
that works for any type with MRDOCS_DESCRIBE_STRUCT. Non-template
overloads (DocComment, SourceInfo, TemplateInfo, ExtractionMode, etc.)
are still preferred by overload resolution.

This eliminates a bunch of merge() functions that did nothing but
forward to mergeReflected(), along with their MRDOCS_DECL declarations
in public headers. Three .cpp files that existed solely for those
one-liners are deleted entirely (Enum.cpp, EnumConstant.cpp,
NamespaceAlias.cpp).

Cleans up unused #include <mrdocs/Platform.hpp> from several .cpp files
that only needed it for MRDOCS_ASSERT in the deleted functions.
The five private headers from src/lib/Support/Reflection/ are
consolidated into a single public include/mrdocs/Support/Reflection.hpp.

Shared type traits (is_optional, is_vector) move to the existing
Support/TypeTraits.hpp.

The tag_invoke overloads from the centralized Reflection.cpp are
distributed into per-type .cpp files.

The src/lib/Support/Reflection/ directory is deleted entirely.
@gennaroprota gennaroprota force-pushed the refactor/switch_to_custom_reflection branch from 5df1a0b to 937aab7 Compare March 27, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants