|
7 | 7 |
|
8 | 8 | use super::typ::TypeExt;
|
9 | 9 | use crate::codegen_cprover_gotoc::codegen::ty_stable::{pointee_type, StableConverter};
|
10 |
| -use crate::codegen_cprover_gotoc::codegen::typ::{ |
11 |
| - pointee_type as pointee_type_internal, std_pointee_type, |
12 |
| -}; |
| 10 | +use crate::codegen_cprover_gotoc::codegen::typ::std_pointee_type; |
13 | 11 | use crate::codegen_cprover_gotoc::utils::{dynamic_fat_ptr, slice_fat_ptr};
|
14 | 12 | use crate::codegen_cprover_gotoc::GotocCtx;
|
15 | 13 | use crate::unwrap_or_return_codegen_unimplemented;
|
16 | 14 | use cbmc::goto_program::{Expr, Location, Type};
|
| 15 | +use rustc_middle::mir::{Local as LocalInternal, Place as PlaceInternal}; |
17 | 16 | use rustc_middle::ty::layout::LayoutOf;
|
18 |
| -use rustc_middle::{ |
19 |
| - mir::{Local as LocalInternal, Place as PlaceInternal}, |
20 |
| - ty::Ty as TyInternal, |
21 |
| -}; |
22 | 17 | use rustc_smir::rustc_internal;
|
23 | 18 | use rustc_target::abi::{TagEncoding, Variants};
|
24 | 19 | use stable_mir::mir::{FieldIdx, Local, Mutability, Place, ProjectionElem};
|
@@ -152,13 +147,12 @@ impl ProjectedPlace {
|
152 | 147 | }
|
153 | 148 | }
|
154 | 149 |
|
155 |
| - pub fn try_new_internal<'tcx>( |
| 150 | + pub fn try_from_ty( |
156 | 151 | goto_expr: Expr,
|
157 |
| - ty: TyInternal<'tcx>, |
158 |
| - ctx: &mut GotocCtx<'tcx>, |
| 152 | + ty: Ty, |
| 153 | + ctx: &mut GotocCtx, |
159 | 154 | ) -> Result<Self, UnimplementedData> {
|
160 |
| - let ty = ctx.monomorphize(ty); |
161 |
| - Self::try_new(goto_expr, TypeOrVariant::Type(rustc_internal::stable(ty)), None, None, ctx) |
| 155 | + Self::try_new(goto_expr, TypeOrVariant::Type(ty), None, None, ctx) |
162 | 156 | }
|
163 | 157 |
|
164 | 158 | pub fn try_new(
|
@@ -415,7 +409,7 @@ impl<'tcx> GotocCtx<'tcx> {
|
415 | 409 | match proj {
|
416 | 410 | ProjectionElem::Deref => {
|
417 | 411 | let base_type = before.mir_typ();
|
418 |
| - let inner_goto_expr = if is_box(base_type) { |
| 412 | + let inner_goto_expr = if base_type.kind().is_box() { |
419 | 413 | self.deref_box(before.goto_expr)
|
420 | 414 | } else {
|
421 | 415 | before.goto_expr
|
@@ -605,7 +599,7 @@ impl<'tcx> GotocCtx<'tcx> {
|
605 | 599 | Variants::Single { .. } => before.goto_expr,
|
606 | 600 | Variants::Multiple { tag_encoding, .. } => match tag_encoding {
|
607 | 601 | TagEncoding::Direct => {
|
608 |
| - let cases = if is_coroutine(ty_kind) { |
| 602 | + let cases = if ty_kind.is_coroutine() { |
609 | 603 | before.goto_expr
|
610 | 604 | } else {
|
611 | 605 | before.goto_expr.member("cases", &self.symbol_table)
|
@@ -644,21 +638,26 @@ impl<'tcx> GotocCtx<'tcx> {
|
644 | 638 | /// - For `*(Wrapper<T>)` where `T: Unsized`, the projection's `goto_expr` returns an object,
|
645 | 639 | /// and we need to take it's address and build the fat pointer.
|
646 | 640 | pub fn codegen_place_ref(&mut self, place: &PlaceInternal<'tcx>) -> Expr {
|
647 |
| - let place_ty = self.place_ty(place); |
648 |
| - let projection = unwrap_or_return_codegen_unimplemented!(self, self.codegen_place(place)); |
649 |
| - if self.use_thin_pointer(place_ty) { |
| 641 | + self.codegen_place_ref_stable(&StableConverter::convert_place(self, *place)) |
| 642 | + } |
| 643 | + |
| 644 | + pub fn codegen_place_ref_stable(&mut self, place: &Place) -> Expr { |
| 645 | + let place_ty = self.place_ty_stable(place); |
| 646 | + let projection = |
| 647 | + unwrap_or_return_codegen_unimplemented!(self, self.codegen_place_stable(place)); |
| 648 | + if self.use_thin_pointer_stable(place_ty) { |
650 | 649 | // Just return the address of the place dereferenced.
|
651 | 650 | projection.goto_expr.address_of()
|
652 |
| - } else if place_ty == pointee_type_internal(self.local_ty(place.local)).unwrap() { |
| 651 | + } else if place_ty == pointee_type(self.local_ty_stable(place.local)).unwrap() { |
653 | 652 | // Just return the fat pointer if this is a simple &(*local).
|
654 | 653 | projection.fat_ptr_goto_expr.unwrap()
|
655 | 654 | } else {
|
656 | 655 | // Build a new fat pointer to the place dereferenced with the metadata from the
|
657 | 656 | // original fat pointer.
|
658 | 657 | let data = projection_data_ptr(&projection);
|
659 | 658 | let fat_ptr = projection.fat_ptr_goto_expr.unwrap();
|
660 |
| - let place_type = self.codegen_ty_ref(place_ty); |
661 |
| - if self.use_vtable_fat_pointer(place_ty) { |
| 659 | + let place_type = self.codegen_ty_ref_stable(place_ty); |
| 660 | + if self.use_vtable_fat_pointer_stable(place_ty) { |
662 | 661 | let vtable = fat_ptr.member("vtable", &self.symbol_table);
|
663 | 662 | dynamic_fat_ptr(place_type, data, vtable, &self.symbol_table)
|
664 | 663 | } else {
|
@@ -781,14 +780,6 @@ impl<'tcx> GotocCtx<'tcx> {
|
781 | 780 | }
|
782 | 781 | }
|
783 | 782 |
|
784 |
| -fn is_box(ty: Ty) -> bool { |
785 |
| - matches!(ty.kind(), TyKind::RigidTy(RigidTy::Adt(def, _)) if def.is_box()) |
786 |
| -} |
787 |
| - |
788 |
| -fn is_coroutine(ty_kind: TyKind) -> bool { |
789 |
| - matches!(ty_kind, TyKind::RigidTy(RigidTy::Coroutine(..))) |
790 |
| -} |
791 |
| - |
792 | 783 | /// Extract the data pointer from a projection.
|
793 | 784 | /// The return type of the projection is not consistent today, so we need to specialize the
|
794 | 785 | /// behavior in order to get a consistent expression that represents a pointer to the projected
|
|
0 commit comments