Skip to content

Commit

Permalink
Conform with changes to Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed Dec 12, 2022
1 parent 341b5bd commit 3d523aa
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_middle::ty::{
use rustc_middle::ty::{List, TypeFoldable};
use rustc_span::def_id::DefId;
use rustc_target::abi::{
Abi::Vector, FieldsShape, Integer, Layout, Primitive, Size, TagEncoding, TyAndLayout,
Abi::Vector, FieldsShape, Integer, LayoutS, Primitive, Size, TagEncoding, TyAndLayout,
VariantIdx, Variants,
};
use rustc_target::spec::abi::Abi;
Expand Down Expand Up @@ -862,10 +862,10 @@ impl<'tcx> GotocCtx<'tcx> {
fn codegen_alignment_padding(
&self,
size: Size,
layout: &Layout,
layout: &LayoutS<VariantIdx>,
idx: usize,
) -> Option<DatatypeComponent> {
let align = Size::from_bits(layout.align().abi.bits());
let align = Size::from_bits(layout.align.abi.bits());
let overhang = Size::from_bits(size.bits() % align.bits());
if overhang != Size::ZERO {
self.codegen_struct_padding(size, size + align - overhang, idx)
Expand All @@ -887,16 +887,16 @@ impl<'tcx> GotocCtx<'tcx> {
fn codegen_struct_fields(
&mut self,
flds: Vec<(String, Ty<'tcx>)>,
layout: &Layout,
layout: &LayoutS<VariantIdx>,
initial_offset: Size,
) -> Vec<DatatypeComponent> {
match &layout.fields() {
match &layout.fields {
FieldsShape::Arbitrary { offsets, memory_index } => {
assert_eq!(flds.len(), offsets.len());
assert_eq!(offsets.len(), memory_index.len());
let mut final_fields = Vec::with_capacity(flds.len());
let mut offset = initial_offset;
for idx in layout.fields().index_by_increasing_offset() {
for idx in layout.fields.index_by_increasing_offset() {
let fld_offset = offsets[idx];
let (fld_name, fld_ty) = &flds[idx];
if let Some(padding) =
Expand All @@ -919,7 +919,7 @@ impl<'tcx> GotocCtx<'tcx> {
}
// Primitives, such as NEVER, have no fields
FieldsShape::Primitive => vec![],
_ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields()),
_ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields),
}
}

Expand All @@ -928,7 +928,7 @@ impl<'tcx> GotocCtx<'tcx> {
let flds: Vec<_> =
tys.iter().enumerate().map(|(i, t)| (GotocCtx::tuple_fld_name(i), *t)).collect();
// tuple cannot have other initial offset
self.codegen_struct_fields(flds, &layout.layout, Size::ZERO)
self.codegen_struct_fields(flds, &layout.layout.0, Size::ZERO)
}

/// A closure in Rust MIR takes two arguments:
Expand Down Expand Up @@ -1133,7 +1133,7 @@ impl<'tcx> GotocCtx<'tcx> {
}
fields.extend(ctx.codegen_alignment_padding(
offset,
&type_and_layout.layout,
&type_and_layout.layout.0,
fields.len(),
));
fields
Expand Down Expand Up @@ -1331,7 +1331,7 @@ impl<'tcx> GotocCtx<'tcx> {
self.ensure_struct(self.ty_mangled_name(ty), self.ty_pretty_name(ty), |ctx, _| {
let variant = &def.variants().raw[0];
let layout = ctx.layout_of(ty);
ctx.codegen_variant_struct_fields(variant, subst, &layout.layout, Size::ZERO)
ctx.codegen_variant_struct_fields(variant, subst, &layout.layout.0, Size::ZERO)
})
}

Expand All @@ -1340,7 +1340,7 @@ impl<'tcx> GotocCtx<'tcx> {
&mut self,
variant: &VariantDef,
subst: &'tcx InternalSubsts<'tcx>,
layout: &Layout,
layout: &LayoutS<VariantIdx>,
initial_offset: Size,
) -> Vec<DatatypeComponent> {
let flds: Vec<_> =
Expand Down Expand Up @@ -1423,7 +1423,7 @@ impl<'tcx> GotocCtx<'tcx> {
Some(variant) => {
// a single enum is pretty much like a struct
let layout = gcx.layout_of(ty).layout;
gcx.codegen_variant_struct_fields(variant, subst, &layout, Size::ZERO)
gcx.codegen_variant_struct_fields(variant, subst, &layout.0, Size::ZERO)
}
}
})
Expand Down Expand Up @@ -1509,9 +1509,9 @@ impl<'tcx> GotocCtx<'tcx> {
ty: Ty<'tcx>,
adtdef: &'tcx AdtDef,
subst: &'tcx InternalSubsts<'tcx>,
variants: &IndexVec<VariantIdx, Layout>,
variants: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
) -> Type {
let non_zst_count = variants.iter().filter(|layout| layout.size().bytes() > 0).count();
let non_zst_count = variants.iter().filter(|layout| layout.size.bytes() > 0).count();
let mangled_name = self.ty_mangled_name(ty);
let pretty_name = self.ty_pretty_name(ty);
tracing::trace!(?pretty_name, ?variants, ?subst, ?non_zst_count, "codegen_enum: Niche");
Expand All @@ -1528,23 +1528,20 @@ impl<'tcx> GotocCtx<'tcx> {

pub(crate) fn variant_min_offset(
&self,
variants: &IndexVec<VariantIdx, Layout>,
variants: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
) -> Option<Size> {
variants
.iter()
.filter_map(|lo| {
if lo.fields().count() == 0 {
if lo.fields.count() == 0 {
None
} else {
// get the offset of the leftmost field, which is the one
// with the least offset since we codegen fields in a struct
// in the order of increasing offsets. Note that this is not
// necessarily the 0th field since the compiler may reorder
// fields.
Some(
lo.fields()
.offset(lo.fields().index_by_increasing_offset().next().unwrap()),
)
Some(lo.fields.offset(lo.fields.index_by_increasing_offset().next().unwrap()))
}
})
.min()
Expand Down Expand Up @@ -1615,7 +1612,7 @@ impl<'tcx> GotocCtx<'tcx> {
pretty_name: InternedString,
def: &'tcx AdtDef,
subst: &'tcx InternalSubsts<'tcx>,
layouts: &IndexVec<VariantIdx, Layout>,
layouts: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
initial_offset: Size,
) -> Vec<DatatypeComponent> {
def.variants()
Expand Down Expand Up @@ -1647,7 +1644,7 @@ impl<'tcx> GotocCtx<'tcx> {
pretty_name: InternedString,
case: &VariantDef,
subst: &'tcx InternalSubsts<'tcx>,
variant: &Layout,
variant: &LayoutS<VariantIdx>,
initial_offset: Size,
) -> Type {
let case_name = format!("{name}::{}", case.name);
Expand Down

0 comments on commit 3d523aa

Please sign in to comment.