1
Fork 0

Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errors

Add method to get type of an Rvalue in StableMIR

Provide a method to StableMIR users to retrieve the type of an Rvalue operation. There were two possible implementation:

1. Create the logic inside stable_mir to process the type according to the Rvalue semantics, which duplicates the logic of `rustc_middle::mir::Rvalue::ty()`.
2. Implement the Rvalue translation from StableMIR back to internal representation, invoke the `rustc_middle::mir::Rvalue::ty()`, and translate the return value to StableMIR.

I chose the first one for now since the duplication was fairly small, and the option 2 would require way more work to translate everything back to rustc internal representation. If we eventually add those translations, we could easily swap to the option 2.

```@compiler-errors``` / ```@ouz-a``` Please let me know if you have any strong opinion here.

r? ```@compiler-errors```
This commit is contained in:
Matthias Krüger 2023-12-07 21:38:08 +01:00 committed by GitHub
commit 20ed80523a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 202 additions and 5 deletions

View file

@ -87,6 +87,9 @@ pub trait Context {
/// Create a new type from the given kind.
fn new_rigid_ty(&self, kind: RigidTy) -> Ty;
/// Create a new box type, `Box<T>`, for the given inner type `T`.
fn new_box_ty(&self, ty: Ty) -> Ty;
/// Returns the type of given crate item.
fn def_ty(&self, item: DefId) -> Ty;
@ -102,6 +105,9 @@ pub trait Context {
/// Obtain the representation of a type.
fn ty_kind(&self, ty: Ty) -> TyKind;
// Get the discriminant Ty for this Ty if there's one.
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty;
/// Get the body of an Instance which is already monomorphized.
fn instance_body(&self, instance: InstanceDef) -> Option<Body>;
@ -119,7 +125,7 @@ pub trait Context {
/// Convert a non-generic crate item into an instance.
/// This function will panic if the item is generic.
fn mono_instance(&self, item: CrateItem) -> Instance;
fn mono_instance(&self, def_id: DefId) -> Instance;
/// Item requires monomorphization.
fn requires_monomorphization(&self, def_id: DefId) -> bool;