Skip to content

[Support] Simplify yamlizeMappingEnumInput (NFC) #137537

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

@kazutakahirata kazutakahirata commented Apr 27, 2025

We can use "constexpr if" to combine the two variants of functions.

We can use "constexpt if" to combine the two variants of functions.
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

We can use "constexpt if" to combine the two variants of functions.


Full diff: https://github.com/llvm/llvm-project/pull/137537.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/YAMLTraits.h (+11-15)
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index e707a445012b5..21829b906967e 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -1105,22 +1105,18 @@ yamlize(IO &io, T &Val, bool, Context &Ctx) {
 }
 
 template <typename T, typename Context>
-std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value, bool>
-yamlizeMappingEnumInput(IO &io, T &Val) {
-  return false;
-}
-
-template <typename T, typename Context>
-std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value, bool>
-yamlizeMappingEnumInput(IO &io, T &Val) {
-  if (io.outputting())
-    return false;
+bool yamlizeMappingEnumInput(IO &io, T &Val) {
+  if constexpr (has_MappingEnumInputTraits<T, Context>::value) {
+    if (io.outputting())
+      return false;
 
-  io.beginEnumScalar();
-  MappingTraits<T>::enumInput(io, Val);
-  bool Matched = !io.matchEnumFallback();
-  io.endEnumScalar();
-  return Matched;
+    io.beginEnumScalar();
+    MappingTraits<T>::enumInput(io, Val);
+    bool Matched = !io.matchEnumFallback();
+    io.endEnumScalar();
+    return Matched;
+  }
+  return false;
 }
 
 template <typename T, typename Context>

@kazutakahirata kazutakahirata merged commit 3170599 into llvm:main Apr 27, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_llvm_YAML2 branch April 27, 2025 19:36
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
We can use "constexpr if" to combine the two variants of functions.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
We can use "constexpr if" to combine the two variants of functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants