Skip to content

Add a method to create an arbitrary OpTy from outside rustc_mir #61718

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
19 changes: 14 additions & 5 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use rustc::mir::interpret::{
InterpResult, InterpError, InboundsCheck,
sign_extend, truncate,
};
use super::{
InterpretCx, Machine,
MemPlace, MPlaceTy, PlaceTy, Place,
};
use super::{InterpretCx, Machine, MemPlace, MPlaceTy, PlaceTy, Place};
pub use rustc::mir::interpret::ScalarMaybeUndef;

/// A `Value` represents a single immediate self-contained Rust value.
Expand Down Expand Up @@ -190,6 +187,19 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag>
}
}

impl<'tcx, Tag> OpTy<'tcx, Tag>
{
/// This is used by [priroda](https://github.com/oli-obk/priroda) to create an `OpTy`.
///
/// Do not use this from inside rustc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand a bit on why this shouldn't be used from inside rustc? Is it just that this operation is unchecked or does it violate some other assumption?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that somebody wanted to prevent having a method like this to prevent accidental misusage or something like that, but in #55179 I can really find anything like that except for "I wanted to have something like an abstraction here" by @RalfJung.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The *Ty types have successfully found and prevent several bugs. Currently the only "hole" in the scheme is ImmTy, you can construct arbitrary immediates from the outside. I was very happy when I managed to make OpTy private and only expose ImmTy instead, having to un-do this would be very sad. :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really the advice here should be "do not use this, period". This is not an inside-rustc vs outside-rustc distinction.

pub fn from_op_and_layout_unchecked(op: Operand<Tag>, layout: TyLayout<'tcx>) -> Self {
OpTy {
op,
layout,
}
}
}

// Use the existing layout if given (but sanity check in debug mode),
// or compute the layout.
#[inline(always)]
Expand Down Expand Up @@ -395,7 +405,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
})
}

/// This is used by [priroda](https://github.com/oli-obk/priroda) to get an OpTy from a local
pub fn access_local(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean we can make the method private?

&self,
frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
Expand Down