Skip to content
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

Implement basic bool and int formatting for diagnostics #4411

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Oct 16, 2024

Note, this supports plurals, but doesn't apply it anywhere. I'm mainly doing that to demonstrate the approach regarding syntax. See format_providers.h for details.

@jonmeow jonmeow requested review from zygoloid and dwblaikie October 16, 2024 18:51
@github-actions github-actions bot requested a review from geoffromer October 16, 2024 18:51
@jonmeow jonmeow removed the request for review from geoffromer October 16, 2024 19:10
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

Comment on lines +21 to +23
// If needed, the _full_ style string can be wrapped with `'` in order to
// preserve prefix or suffix whitespace (which is stripped by formatv). For
// example, `{0:' true | false '}` retains whitespace which would be dropped
// before `true` and after `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a reasonable workaround. But the need to do this makes me sad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷

As discussed, we can revisit and see what std::format does whenever we're able to switch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like std::format passes through the string with leading/trailing whitespace to the formatter.

So I'm happy to make the LLVM change to avoid trimming this so it works as desired. I'll follow-up here with the upstream PR/commit soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can update the implementation once LLVM has support; I'd rather not block this PR on that, to minimize merge conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Posted upstream change here: llvm/llvm-project#112625

@zygoloid

This comment was marked as resolved.

Copy link
Contributor Author

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Added support for repeat/non-styled use (PluralExample test)

Comment on lines +21 to +23
// If needed, the _full_ style string can be wrapped with `'` in order to
// preserve prefix or suffix whitespace (which is stripped by formatv). For
// example, `{0:' true | false '}` retains whitespace which would be dropped
// before `true` and after `false`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷

As discussed, we can revisit and see what std::format does whenever we're able to switch.

@jonmeow jonmeow force-pushed the foramtting branch 2 times, most recently from 0d2bf66 to 1131c45 Compare October 16, 2024 22:00
@jonmeow jonmeow enabled auto-merge October 16, 2024 22:01
@jonmeow jonmeow added this pull request to the merge queue Oct 16, 2024
dwblaikie added a commit to llvm/llvm-project that referenced this pull request Oct 16, 2024
This is consistent with std::formatv and allows formatters to support a
wider variety of use cases (like having a bare string in their formatter
if that's useful, etc).

Came up in the context of some Carbon diagnostic work here:
carbon-language/carbon-lang#4411 (comment)
Merged via the queue into carbon-language:trunk with commit 96964ee Oct 16, 2024
8 checks passed
@jonmeow jonmeow deleted the foramtting branch October 16, 2024 23:32
github-merge-queue bot pushed a commit that referenced this pull request Oct 17, 2024
Building on #4411,
replace format_provider uses (other than `TokenKind`, which is more on
the okay side of things)

Also does some edits to `ClassMemberDefinition` to try to better match
diagnostic style
github-merge-queue bot pushed a commit that referenced this pull request Oct 21, 2024
Building on #4411, avoid using StringLiteral in format strings. This
includes a diagnostic check to prevent regressions (which is also how I
gathered issues).

Note, I haven't looked at `std::string` uses yet, but we might need
things like that to be able to pass strings in code back to the user.
StringLiteral though means that it's literally written down in the
toolchain, at which point it should probably be written in the format
string instead of separately.

---------

Co-authored-by: Geoff Romer <[email protected]>
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.

3 participants