|
7 | 7 | //!
|
8 | 8 | //! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
9 | 9 |
|
| 10 | +use crate::rustc_internal::{self, opaque}; |
10 | 11 | use crate::stable_mir::{self, ty::TyKind, Context};
|
11 | 12 | use rustc_middle::mir;
|
12 | 13 | use rustc_middle::ty::{self, Ty, TyCtxt};
|
13 | 14 | use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
| 15 | +use rustc_target::abi::FieldIdx; |
14 | 16 | use tracing::debug;
|
15 | 17 |
|
16 | 18 | impl<'tcx> Context for Tables<'tcx> {
|
@@ -127,6 +129,13 @@ pub(crate) trait Stable {
|
127 | 129 | fn stable(&self) -> Self::T;
|
128 | 130 | }
|
129 | 131 |
|
| 132 | +impl Stable for DefId { |
| 133 | + type T = stable_mir::CrateItem; |
| 134 | + fn stable(&self) -> Self::T { |
| 135 | + rustc_internal::crate_item(*self) |
| 136 | + } |
| 137 | +} |
| 138 | + |
130 | 139 | impl<'tcx> Stable for mir::Statement<'tcx> {
|
131 | 140 | type T = stable_mir::mir::Statement;
|
132 | 141 | fn stable(&self) -> Self::T {
|
@@ -158,27 +167,136 @@ impl<'tcx> Stable for mir::Rvalue<'tcx> {
|
158 | 167 | match self {
|
159 | 168 | Use(op) => stable_mir::mir::Rvalue::Use(op.stable()),
|
160 | 169 | Repeat(_, _) => todo!(),
|
161 |
| - Ref(_, _, _) => todo!(), |
162 |
| - ThreadLocalRef(_) => todo!(), |
163 |
| - AddressOf(_, _) => todo!(), |
164 |
| - Len(_) => todo!(), |
| 170 | + Ref(region, kind, place) => { |
| 171 | + stable_mir::mir::Rvalue::Ref(opaque(region), kind.stable(), place.stable()) |
| 172 | + } |
| 173 | + ThreadLocalRef(def_id) => stable_mir::mir::Rvalue::ThreadLocalRef(def_id.stable()), |
| 174 | + AddressOf(mutability, place) => { |
| 175 | + stable_mir::mir::Rvalue::AddressOf(mutability.stable(), place.stable()) |
| 176 | + } |
| 177 | + Len(place) => stable_mir::mir::Rvalue::Len(place.stable()), |
165 | 178 | Cast(_, _, _) => todo!(),
|
166 |
| - BinaryOp(_, _) => todo!(), |
| 179 | + BinaryOp(bin_op, ops) => { |
| 180 | + stable_mir::mir::Rvalue::BinaryOp(bin_op.stable(), ops.0.stable(), ops.1.stable()) |
| 181 | + } |
167 | 182 | CheckedBinaryOp(bin_op, ops) => stable_mir::mir::Rvalue::CheckedBinaryOp(
|
168 | 183 | bin_op.stable(),
|
169 | 184 | ops.0.stable(),
|
170 | 185 | ops.1.stable(),
|
171 | 186 | ),
|
172 | 187 | NullaryOp(_, _) => todo!(),
|
173 | 188 | UnaryOp(un_op, op) => stable_mir::mir::Rvalue::UnaryOp(un_op.stable(), op.stable()),
|
174 |
| - Discriminant(_) => todo!(), |
| 189 | + Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable()), |
175 | 190 | Aggregate(_, _) => todo!(),
|
176 | 191 | ShallowInitBox(_, _) => todo!(),
|
177 |
| - CopyForDeref(_) => todo!(), |
| 192 | + CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable()), |
| 193 | + } |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +impl Stable for mir::Mutability { |
| 198 | + type T = stable_mir::mir::Mutability; |
| 199 | + fn stable(&self) -> Self::T { |
| 200 | + use mir::Mutability::*; |
| 201 | + match *self { |
| 202 | + Not => stable_mir::mir::Mutability::Not, |
| 203 | + Mut => stable_mir::mir::Mutability::Mut, |
| 204 | + } |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +impl Stable for mir::BorrowKind { |
| 209 | + type T = stable_mir::mir::BorrowKind; |
| 210 | + fn stable(&self) -> Self::T { |
| 211 | + use mir::BorrowKind::*; |
| 212 | + match *self { |
| 213 | + Shared => stable_mir::mir::BorrowKind::Shared, |
| 214 | + Shallow => stable_mir::mir::BorrowKind::Shallow, |
| 215 | + Mut { kind } => stable_mir::mir::BorrowKind::Mut { kind: kind.stable() }, |
| 216 | + } |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +impl Stable for mir::MutBorrowKind { |
| 221 | + type T = stable_mir::mir::MutBorrowKind; |
| 222 | + fn stable(&self) -> Self::T { |
| 223 | + use mir::MutBorrowKind::*; |
| 224 | + match *self { |
| 225 | + Default => stable_mir::mir::MutBorrowKind::Default, |
| 226 | + TwoPhaseBorrow => stable_mir::mir::MutBorrowKind::TwoPhaseBorrow, |
| 227 | + ClosureCapture => stable_mir::mir::MutBorrowKind::ClosureCapture, |
| 228 | + } |
| 229 | + } |
| 230 | +} |
| 231 | + |
| 232 | +impl<'tcx> Stable for mir::NullOp<'tcx> { |
| 233 | + type T = stable_mir::mir::NullOp; |
| 234 | + fn stable(&self) -> Self::T { |
| 235 | + use mir::NullOp::*; |
| 236 | + match self { |
| 237 | + SizeOf => stable_mir::mir::NullOp::SizeOf, |
| 238 | + AlignOf => stable_mir::mir::NullOp::AlignOf, |
| 239 | + OffsetOf(indices) => { |
| 240 | + stable_mir::mir::NullOp::OffsetOf(indices.iter().map(|idx| idx.stable()).collect()) |
| 241 | + } |
| 242 | + } |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +impl Stable for mir::CastKind { |
| 247 | + type T = stable_mir::mir::CastKind; |
| 248 | + fn stable(&self) -> Self::T { |
| 249 | + use mir::CastKind::*; |
| 250 | + match self { |
| 251 | + PointerExposeAddress => stable_mir::mir::CastKind::PointerExposeAddress, |
| 252 | + PointerFromExposedAddress => stable_mir::mir::CastKind::PointerFromExposedAddress, |
| 253 | + Pointer(cast) => stable_mir::mir::CastKind::Pointer(cast.stable()), |
| 254 | + DynStar => stable_mir::mir::CastKind::DynStar, |
| 255 | + IntToInt => stable_mir::mir::CastKind::IntToInt, |
| 256 | + FloatToInt => stable_mir::mir::CastKind::FloatToInt, |
| 257 | + FloatToFloat => stable_mir::mir::CastKind::FloatToFloat, |
| 258 | + IntToFloat => stable_mir::mir::CastKind::IntToFloat, |
| 259 | + PtrToPtr => stable_mir::mir::CastKind::PtrToPtr, |
| 260 | + FnPtrToPtr => stable_mir::mir::CastKind::FnPtrToPtr, |
| 261 | + Transmute => stable_mir::mir::CastKind::Transmute, |
| 262 | + } |
| 263 | + } |
| 264 | +} |
| 265 | + |
| 266 | +impl Stable for ty::adjustment::PointerCast { |
| 267 | + type T = stable_mir::mir::PointerCast; |
| 268 | + fn stable(&self) -> Self::T { |
| 269 | + use ty::adjustment::PointerCast; |
| 270 | + match self { |
| 271 | + PointerCast::ReifyFnPointer => stable_mir::mir::PointerCast::ReifyFnPointer, |
| 272 | + PointerCast::UnsafeFnPointer => stable_mir::mir::PointerCast::UnsafeFnPointer, |
| 273 | + PointerCast::ClosureFnPointer(unsafety) => { |
| 274 | + stable_mir::mir::PointerCast::ClosureFnPointer(unsafety.stable()) |
| 275 | + } |
| 276 | + PointerCast::MutToConstPointer => stable_mir::mir::PointerCast::MutToConstPointer, |
| 277 | + PointerCast::ArrayToPointer => stable_mir::mir::PointerCast::ArrayToPointer, |
| 278 | + PointerCast::Unsize => stable_mir::mir::PointerCast::Unsize, |
178 | 279 | }
|
179 | 280 | }
|
180 | 281 | }
|
181 | 282 |
|
| 283 | +impl Stable for rustc_hir::Unsafety { |
| 284 | + type T = stable_mir::mir::Safety; |
| 285 | + fn stable(&self) -> Self::T { |
| 286 | + match self { |
| 287 | + rustc_hir::Unsafety::Unsafe => stable_mir::mir::Safety::Unsafe, |
| 288 | + rustc_hir::Unsafety::Normal => stable_mir::mir::Safety::Normal, |
| 289 | + } |
| 290 | + } |
| 291 | +} |
| 292 | + |
| 293 | +impl Stable for FieldIdx { |
| 294 | + type T = usize; |
| 295 | + fn stable(&self) -> Self::T { |
| 296 | + self.as_usize() |
| 297 | + } |
| 298 | +} |
| 299 | + |
182 | 300 | impl<'tcx> Stable for mir::Operand<'tcx> {
|
183 | 301 | type T = stable_mir::mir::Operand;
|
184 | 302 | fn stable(&self) -> Self::T {
|
|
0 commit comments