Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0f49155
Add reflection_hash
fullptr Apr 11, 2025
c48592e
Rename the struct and stub out the implementation
Aug 1, 2025
6a331de
Add in the branches for namespace reflections
Aug 1, 2025
fbf196a
Implement namespace hashing
Aug 1, 2025
0a81af2
Rename var
Aug 1, 2025
5de7689
Add braces to the branches to make them easy to add to
Aug 1, 2025
3e87faf
Implement reflection of types
Aug 4, 2025
efa7faf
Factor out appending the QualType functionality
Aug 4, 2025
43eb5a0
Implement hash for DataMemberSpec
Aug 4, 2025
0c0f392
Remove test code
Aug 4, 2025
ac08b85
Stub out the delcaration branch
Aug 4, 2025
864ed29
WIP
fullptr Aug 11, 2025
6850e1e
Reimplement consteval_hash
fullptr Aug 11, 2025
ca72923
Implement hashing for Parameter kind
fullptr Aug 12, 2025
a93f735
Implement hashing reflections of complex ints, complex floats and vec…
fullptr Aug 25, 2025
6554055
Implement FixedPoint reflections
fullptr Aug 25, 2025
aed977d
Implement hashing APValue::Array and figure out how to do struct and …
fullptr Aug 25, 2025
6d435a0
Implement hashing APValue::Struct
fullptr Aug 25, 2025
13420f2
Implement MemberPointer hashing
fullptr Aug 26, 2025
ad7ecb7
Implement hashing unions
fullptr Aug 26, 2025
3f79912
Implement hashing APValue::Reflection
fullptr Aug 26, 2025
0e2ba6b
AddLabelDiff is not possible
fullptr Aug 26, 2025
ea6244b
Implement reflecting nullptr
fullptr Aug 26, 2025
e57b76f
Add comment
fullptr Aug 26, 2025
65a29fa
Cleanup
fullptr Aug 26, 2025
c6f4f7f
Remove old comment
fullptr Aug 26, 2025
b2b9510
Formatting
fullptr Aug 26, 2025
2f5bea8
Create a simplified implementation that just interns the pointers
fullptr Oct 21, 2025
2d78c5d
Remove setting of unused static value
fullptr Oct 21, 2025
f52f2ab
Further simplify the implementation
fullptr Oct 21, 2025
765342e
Simplify
fullptr Oct 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions clang/lib/AST/ExprConstantMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,15 @@ static bool reflect_invoke(APValue &Result, ASTContext &C, MetaActions &Meta,
SourceRange Range, ArrayRef<Expr *> Args,
Decl *ContainingDecl);

// ==========================================================
// std::consteval_hash<std::meta::info> specialization helper
// ==========================================================

static bool reflection_hash(APValue &Result, ASTContext &C, MetaActions &Meta,
EvalFn Evaluator, DiagFn Diagnoser, bool AllowInjection,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args, Decl *ContainingDecl);

// -----------------------------------------------------------------------------
// Metafunction table
//
Expand Down Expand Up @@ -844,6 +853,9 @@ static constexpr Metafunction Metafunctions[] = {
// Other bespoke functions (not proposed at this time)
{ Metafunction::MFRK_bool, 1, 1, is_access_specified },
{ Metafunction::MFRK_metaInfo, 5, 5, reflect_invoke },

// std::consteval_hash<std::meta::info> specialization helper
{ Metafunction::MFRK_sizeT, 1, 1, reflection_hash },
};
constexpr const unsigned NumMetafunctions = sizeof(Metafunctions) /
sizeof(Metafunction);
Expand Down Expand Up @@ -1664,6 +1676,7 @@ StringRef DescriptionOf(APValue RV, bool Granular = true) {
return "an annotation";
}
}
return "unknown reflection";
}

bool DiagnoseReflectionKind(DiagFn Diagnoser, SourceRange Range,
Expand Down Expand Up @@ -6405,4 +6418,29 @@ bool reflect_invoke(APValue &Result, ASTContext &C, MetaActions &Meta,
return SetAndSucceed(Result, EvalResult.Val.Lift(CallExpr->getType()));
}

bool reflection_hash(APValue &Result, ASTContext &C, MetaActions &Meta,
EvalFn Evaluator, DiagFn Diagnoser, bool AllowInjection,
QualType ResultTy, SourceRange Range, ArrayRef<Expr *> Args,
Decl *ContainingDecl) {
assert(Args[0]->getType()->isReflectionType());
assert(ResultTy == C.getSizeType());

APValue R;
if (!Evaluator(R, Args[0], true)) {
return true;
}

static std::unordered_map<const void*, std::size_t> s_values;
static std::size_t s_count = 0;

const auto [it, success] = s_values.insert({R.getOpaqueReflectionData(), s_count});
if (success) {
++s_count;
}

return SetAndSucceed(
Result,
APValue(C.MakeIntValue(it->second, C.getSizeType())));
}

} // end namespace clang
23 changes: 23 additions & 0 deletions libcxx/include/meta
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ enum : unsigned {
// Other bespoke functions (not proposed at this time)
__metafn_is_access_specified,
__metafn_reflect_invoke,

__metafn_reflection_hash,
};

consteval auto __workaround_expand_compiler_builtins(info type) -> info;
Expand Down Expand Up @@ -3023,6 +3025,27 @@ consteval auto u8display_string_of(info R) -> u8string_view {

_LIBCPP_END_NAMESPACE_REFLECTION_V2

_LIBCPP_BEGIN_NAMESPACE_STD

template <typename T> struct consteval_hash;

template <>
struct consteval_hash<meta::info>
{
consteval consteval_hash() = default;
consteval consteval_hash(const consteval_hash&) = default;
consteval consteval_hash(consteval_hash&&) = default;
consteval auto operator()(meta::info r) const noexcept -> size_t
{
return __metafunction(meta::detail::__metafn_reflection_hash, r);
}

private:
const meta::info unused = ^^::; // required to make type consteval-only
};

_LIBCPP_END_NAMESPACE_STD

#endif // __has_feature(reflection)

#endif // _LIBCPP_META
Loading