8000 Misc changes to StableMIR required to Kani use case. by celinval · Pull Request #117688 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Misc changes to StableMIR required to Kani use case. #117688

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

Merged
merged 6 commits into from
Nov 17, 2023
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
Prev Previous commit
Fix has_body() and change resolve_drop_in_place() sig
Fixed the `has_body()` function operator. Before that, this function was
returning false for all shims.

Change resolve_drop_in_place() to also return an instance for empty
shims, since they may still be required for vtable construction.
  • Loading branch information
celinval committed Nov 16, 2023
commit 8e81fc00879b640ed6acc6a9ca870814189901e5
10 changes: 9 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ impl<'tcx> BodyBuilder<'tcx> {
BodyBuilder { tcx, instance }
}

/// Build a stable monomorphic body for a given instance based on the MIR body.
///
/// Note that we skip instantiation for static and constants. Trying to do so can cause ICE.
///
/// We do monomorphize non-generic functions to eval unevaluated constants.
pub fn build(mut self, tables: &mut Tables<'tcx>) -> stable_mir::mir::Body {
let mut body = self.tcx.instance_mir(self.instance.def).clone();
self.visit_body(&mut body);
if self.tcx.def_kind(self.instance.def_id()).is_fn_like() || !self.instance.args.is_empty()
{
self.visit_body(&mut body);
}
body.stable(tables)
}

Expand Down
23 changes: 9 additions & 14 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
}
}

fn resolve_drop_in_place(
&self,
ty: stable_mir::ty::Ty,
) -> Option<stable_mir::mir::mono::Instance> {
fn resolve_drop_in_place(&self, ty: stable_mir::ty::Ty) -> stable_mir::mir::mono::Instance {
let mut tables = self.0.borrow_mut();
let internal_ty = ty.internal(&mut *tables);
let instance = Instance::resolve_drop_in_place(tables.tcx, internal_ty);
matches!(instance.def, ty::InstanceDef::DropGlue(_, Some(_)))
.then(|| instance.stable(&mut *tables))
instance.stable(&mut *tables)
}

fn resolve_for_fn_ptr(
Expand Down Expand Up @@ -328,9 +324,11 @@ impl<'tcx> Tables<'tcx> {
fn has_body(&self, instance: Instance<'tcx>) -> bool {
let def_id = instance.def_id();
self.tcx.is_mir_available(def_id)
&& !matches!(
|| !matches!(
instance.def,
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(..)
ty::InstanceDef::Virtual(..)
| ty::InstanceDef::Intrinsic(..)
| ty::InstanceDef::Item(..)
)
}
}
Expand Down Expand Up @@ -364,15 +362,12 @@ fn new_item_kind(kind: DefKind) -> ItemKind {
| DefKind::OpaqueTy
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::Impl { .. }
| DefKind::Ctor(_, _)
| DefKind::GlobalAsm => {
unreachable!("Not a valid item kind: {kind:?}");
}
DefKind::Closure
| DefKind::Coroutine
| DefKind::Ctor(_, _)
| DefKind::AssocFn
| DefKind::Impl { .. }
| DefKind::Fn => ItemKind::Fn,
DefKind::Closure | DefKind::Coroutine | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
ItemKind::Const
}
Expand Down
E57B
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub trait Context {
fn resolve_instance(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>;

/// Resolve an instance for drop_in_place for the given type.
fn resolve_drop_in_place(&self, ty: Ty) -> Option<Instance>;
fn resolve_drop_in_place(&self, ty: Ty) -> Instance;

/// Resolve instance for a function pointer.
fn resolve_for_fn_ptr(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>;
Expand Down
3 changes: 1 addition & 2 deletions compiler/stable_mir/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl Instance {
}

/// Resolve the drop in place for a given type.
/// Return `None` if the drop is a no-op.
pub fn resolve_drop_in_place(ty: Ty) -> Option<Instance> {
pub fn resolve_drop_in_place(ty: Ty) -> Instance {
with(|cx| cx.resolve_drop_in_place(ty))
}

Expand Down
0