diff options
| author | bors <bors@rust-lang.org> | 2022-09-28 01:36:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-28 01:36:28 +0000 |
| commit | d6734be398fde0b078cde298e0d84eeccd71d08e (patch) | |
| tree | 9c28173f15528294d0506e086a2101c84e4bfd6c /compiler/rustc_codegen_llvm/src | |
| parent | 90c34fafcfa1d00ae25a165dc006e688761a5776 (diff) | |
| parent | 20bb600849495f6b283b7f9266a02af178ee659b (diff) | |
| download | rust-d6734be398fde0b078cde298e0d84eeccd71d08e.tar.gz rust-d6734be398fde0b078cde298e0d84eeccd71d08e.zip | |
Auto merge of #100996 - m-ou-se:format-args-2, r=estebank
Rewrite and refactor format_args!() builtin macro.
This is a near complete rewrite of `compiler/rustc_builtin_macros/src/format.rs`.
This gets rid of the massive unmaintanable [`Context` struct](https://github.com/rust-lang/rust/blob/76531befc4b0352247ada67bd225e8cf71ee5686/compiler/rustc_builtin_macros/src/format.rs#L176-L263), and splits the macro expansion into three parts:
1. First, `parse_args` will parse the `(literal, arg, arg, name=arg, name=arg)` syntax, but doesn't parse the template (the literal) itself.
2. Second, `make_format_args` will parse the template, the format options, resolve argument references, produce diagnostics, and turn the whole thing into a `FormatArgs` structure.
3. Finally, `expand_parsed_format_args` will turn that `FormatArgs` structure into the expression that the macro expands to.
In other words, the `format_args` builtin macro used to be a hard-to-maintain 'single pass compiler', which I've split into a three phase compiler with a parser/tokenizer (step 1), semantic analysis (step 2), and backend (step 3). (It's compilers all the way down. ^^)
This can serve as a great starting point for https://github.com/rust-lang/rust/issues/99012, which will only need to change the implementation of 3, while leaving step 1 and 2 unchanged.
It also makes https://github.com/rust-lang/compiler-team/issues/541 easier, which could then upgrade the new `FormatArgs` struct to an `ast` node and remove step 3, moving that step to later in the compilation process.
It also fixes a few diagnostics bugs.
This also [significantly reduces](https://gist.github.com/m-ou-se/b67b2d54172c4837a5ab1b26fa3e5284) the amount of generated code for cases with arguments in non-default order without formatting options, like `"{1} {0}"` or `"{a} {}"`, etc.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
