+/// Cached layouts of primitive types
+#[derive(Default)]
+struct PrimitiveLayouts<'tcx> {
+ i32: RefCell<Option<TyAndLayout<'tcx>>>,
+ u32: RefCell<Option<TyAndLayout<'tcx>>>,
+}
+
+impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
+ fn i32(&self, ecx: &MiriEvalContext<'mir, 'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
+ {
+ let layout_ref = self.i32.borrow();
+ if layout_ref.is_some() {
+ return Ok(layout_ref.unwrap());
+ }
+ }
+ let layout = ecx.layout_of(ecx.tcx.types.i32)?;
+ *self.i32.borrow_mut() = Some(layout);
+ Ok(layout)
+ }
+
+ fn u32(&self, ecx: &MiriEvalContext<'mir, 'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
+ {
+ let layout_ref = self.u32.borrow();
+ if layout_ref.is_some() {
+ return Ok(layout_ref.unwrap());
+ }
+ }
+ let layout = ecx.layout_of(ecx.tcx.types.u32)?;
+ *self.u32.borrow_mut() = Some(layout);
+ Ok(layout)
+ }
+}
+