-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve infrastructure for formatting types in diagnostics. (#4374)
Instead of stringifying types in the caller in some cases, add new types to represent: - `InstIdAsType`: an `InstId` diagnostic argument that represents a type expression that should be included in the diagnostic - `InstIdAsTypeOfExpr`: an `InstId` diagnostic argument that represents an expression whose type should be included in the diagnostic For these cases, we can produce more user-friendly descriptions of a type than we can with a canonicalized `TypeId`. Add comments to discourage using `TypeId` diagnostic arguments when one of the above can be used, and move over existing uses where it's straightforward to do so. Move type stringification code to its own files and out of `SemIR::File` to make `File` smaller and to further discourage the direct use of the stringification logic. Also update type printing to include the `` ` `` delimiters surrounding the type. The intent is that we will eventually want to include other information when formatting a type, like Clang does when printing a typedef (`'string' (aka 'std::basic_string<char>')`), and such formatting requires that the diagnostic machinery produces the `` ` ``s itself. There are a couple of cases where we really want to format valid Carbon type syntax directly into a diagnostic, rather than an `aka` or similar, because the diagnostic text includes part of the type itself, for example: ``"consider using `partial {0}`"``. For such cases, a `Raw` form of the diagnostic argument types is added: `TypeIdAsRawType` and `InstIdAsRawType`. In principle we could instead use ``"consider using `partial {0:raw}`"``, but our diagnostic machinery isn't set up for that. --------- Co-authored-by: josh11b <[email protected]>
- Loading branch information
Showing
25 changed files
with
625 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.