-
Notifications
You must be signed in to change notification settings - Fork 75
move codegen for panic entry point to a separate mod #429
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
base: main
Are you sure you want to change the base?
Conversation
// HACK(eddyb) Rust 2021 `panic!` always uses `format_args!`, even | ||
// in the simple case that used to pass a `&str` constant, which | ||
// would not remain reachable in the SPIR-V - but `format_args!` is | ||
// more complex and neither immediate (`fmt::Arguments` is too big) | ||
// nor simplified in MIR (e.g. promoted to a constant) in any way, | ||
// so we have to try and remove the `fmt::Arguments::new` call here. | ||
#[derive(Default)] | ||
struct DecodedFormatArgs<'tcx> { | ||
/// If fully constant, the `pieces: &'a [&'static str]` input | ||
/// of `fmt::Arguments<'a>` (i.e. the strings between args). | ||
const_pieces: Option<SmallVec<[String; 2]>>, | ||
|
||
/// Original references for `fmt::Arguments<'a>` dynamic arguments, | ||
/// i.e. the `&'a T` passed to `fmt::rt::Argument::<'a>::new_*`, | ||
/// tracking the type `T` and `char` formatting specifier. | ||
/// | ||
/// E.g. for `format_args!("{a} {b:x}")` they'll be: | ||
/// * `&a` with `typeof a` and ' ', | ||
/// * `&b` with `typeof b` and 'x' | ||
ref_arg_ids_with_ty_and_spec: SmallVec<[(Word, Ty<'tcx>, char); 2]>, | ||
|
||
/// If `fmt::Arguments::new_v1_formatted` was used, this holds | ||
/// the length of the `&[fmt::rt::Placeholder]` slice, which | ||
/// currently cannot be directly supported, and therefore even | ||
/// if all of `ref_arg_ids_with_ty_and_spec` are printable, | ||
/// a much jankier fallback still has to be used, as it it were: | ||
/// | ||
/// `format!("a{{0}}b{{1}}c\n with {{…}} from: {}, {}", x, y)` | ||
/// (w/ `const_pieces = ["a", "b", "c"]` & `ref_args = [&x, &y]`). | ||
has_unknown_fmt_placeholder_to_args_mapping: Option<usize>, | ||
} | ||
struct FormatArgsNotRecognized(String); | ||
|
||
// HACK(eddyb) this is basically a `try` block. | ||
let mut try_decode_and_remove_format_args = || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make more sense to make these types (and the closure becoming a method) the real interface here, and name the module format_args_decompiler
(because that's what this cursedness really is).
In theory we could allow non-panic uses of it, like instead of debug_printf!
we could have debug_print!
(or even the Rust std
dbg!
macro), that uses format_args!
combined with a function that we treat just like we do panic entry-points.
@eddyb mind if we move that code to declutter
call
?