-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm][Support] Add indirection to call correct validate(...) function #71966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
arrv-sc
commented
Nov 10, 2023
@llvm/pr-subscribers-llvm-support Author: None (arrv-sc) Changes
Full diff: https://github.com/llvm/llvm-project/pull/71966.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 99074105a556989..86226ef46cf5482 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -1058,6 +1058,19 @@ yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
}
}
+template <typename T, typename Context,
+ std::enable_if_t<validatedMappingTraits<T, Context>::value, int> = 0>
+std::string callValidate(IO &io, T &Val, Context &Ctx) {
+ return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
+}
+
+template <
+ typename T,
+ std::enable_if_t<validatedMappingTraits<T, EmptyContext>::value, int> = 0>
+std::string callValidate(IO &io, T &Val, EmptyContext = {}) {
+ return MappingTraits<T>::validate(io, Val);
+}
+
template <typename T, typename Context>
std::enable_if_t<validatedMappingTraits<T, Context>::value, void>
yamlize(IO &io, T &Val, bool, Context &Ctx) {
@@ -1066,7 +1079,7 @@ yamlize(IO &io, T &Val, bool, Context &Ctx) {
else
io.beginMapping();
if (io.outputting()) {
- std::string Err = MappingTraits<T>::validate(io, Val);
+ std::string Err = callValidate(io, Val, Ctx);
if (!Err.empty()) {
errs() << Err << "\n";
assert(Err.empty() && "invalid struct trying to be written as yaml");
@@ -1074,7 +1087,7 @@ yamlize(IO &io, T &Val, bool, Context &Ctx) {
}
detail::doMapping(io, Val, Ctx);
if (!io.outputting()) {
- std::string Err = MappingTraits<T>::validate(io, Val);
+ std::string Err = callValidate(io, Val, Ctx);
if (!Err.empty())
io.setError(Err);
}
|
Small patch that makes it possible to use |
@RKSimon could you please take a look? |
@aaupov Could you take a look please? |
I'm sorry but I'm unfamiliar with the code. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
@topperc, please, review |
I would highly appreciate you taking a look on this PR @topperc |
Is this a similar problem to what |
Previously "yamlize" overload for validatedMappingTraits was unconditionally calling "MappingTraits<T>::validate" even if "MappingContextTraits<T, Context>" was passed to it. Therefore compilation failed when specifying "MappingContextTraits<T,Context>::validate()"
I actually agree with you. Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@RKSimon, merge? |
LGTM - do you mean you want me to merge it for you? |
Yes. Sorry if I'm not clear |