[llvm] [Support][YamlTraits] Add quoting for keys in textual YAML representation (PR #88763)

Jannik Silvanus via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 04:16:08 PDT 2024


jasilvanus wrote:

> What is the issue with just digit only keys?

I re-used the existing `needsQuotes` function that is already used for string values implemented here which quotes numeric strings:

https://github.com/llvm/llvm-project/blob/a02019960b1a693320cd43b0ed6653d95877b94f/llvm/include/llvm/Support/YAMLTraits.h#L674

I originally thought there was some potential issue with numeric keys, but now I'm quite confident this just
to preserve the string type, in order to be able to differentiate the string value `'42'` from the numeric value `42`.

For string values, this totally makes sense as we have typed value setters, so if one wants the unquoted variant one should not set a string value to begin with.
However, keys currently always are strings, and thus there is no way to differentiate the keys `'42'` and `42`.

In the last commit, I extended `needsQuotes` to add a flag whether preservation of string values is required, and not require quoting in the `isNull`/`isBool`/`isNumeric` cases then. 

https://github.com/llvm/llvm-project/pull/88763


More information about the llvm-commits mailing list