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

Temporary fix for layout of panic strings #30

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,33 @@ fn collect_arg_tys(collector: &mut InternedValueCollector, args: &stable_mir::ty
}

fn collect_ty(val_collector: &mut InternedValueCollector, val: stable_mir::ty::Ty) {
use stable_mir::ty::{RigidTy::*, TyKind::RigidTy}; // GenericArgKind::*, TyConst, TyConstKind::*
if val_collector.visited_tys.insert(hash(val), (val.kind(), val.layout().map(|l| l.shape()).ok())).is_some() {
use stable_mir::ty::{RigidTy::*, TyKind::RigidTy, AdtDef}; // GenericArgKind::*, TyConst, TyConstKind::*
dkcumming marked this conversation as resolved.
Show resolved Hide resolved

// HACK: std::fmt::Arguments has escaping bounds and will error if trying to get the layout.
// We will just ban producing the layout for now see, this issue for more info
// https://github.com/runtimeverification/smir_pretty/issues/27
let maybe_layout = match val.kind() {
stable_mir::ty::TyKind::RigidTy(Adt(AdtDef(def_id_stable), _)) => {
let def_id_internal = rustc_internal::internal(val_collector.tcx, def_id_stable);
let name = rustc_middle::ty::print::with_no_trimmed_paths!(val_collector.tcx.def_path_str(def_id_internal));
if String::from("std::fmt::Arguments") == name {
None
} else {
Some(val.layout())
}
},
_ => {
Some(val.layout())
}
};

let maybe_layout_shape = if let Some(Ok(layout)) = maybe_layout {
Some(layout.shape())
} else {
None
};

if val_collector.visited_tys.insert(hash(val), (val.kind(), maybe_layout_shape)).is_some() {
match val.kind() {
RigidTy(Array(ty, _) | Pat(ty, _) | Slice(ty) | RawPtr(ty, _) | Ref(_, ty, _)) => {
collect_ty(val_collector, ty)
Expand Down