Skip to content

Commit

Permalink
Temporary fix for layout of panic strings (#30)
Browse files Browse the repository at this point in the history
Creating the layout for a `Binder<DUMMY>` is creating panics, see
#27 for
details. This PR does not solve the problem but side steps it. There may
be other times that this will be needed unless we find a fix to get the
`Layout` without triggering the error.

---------

Co-authored-by: Jost Berthold <[email protected]>
  • Loading branch information
dkcumming and jberthold authored Jan 21, 2025
1 parent 0a14cc9 commit 5314e1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
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};

// 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

0 comments on commit 5314e1f

Please sign in to comment.