|
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::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
|
11 | 12 | use crate::stable_mir::{self, Context};
|
12 | 13 | use rustc_middle::mir;
|
13 | 14 | use rustc_middle::ty::{self, Ty, TyCtxt};
|
14 | 15 | use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
| 16 | +use rustc_target::abi::FieldIdx; |
15 | 17 | use tracing::debug;
|
16 | 18 |
|
17 | 19 | impl<'tcx> Context for Tables<'tcx> {
|
@@ -145,6 +147,13 @@ pub(crate) trait Stable {
|
145 | 147 | fn stable(&self) -> Self::T;
|
146 | 148 | }
|
147 | 149 |
|
| 150 | +impl Stable for DefId { |
| 151 | + type T = stable_mir::CrateItem; |
| 152 | + fn stable(&self) -> Self::T { |
| 153 | + rustc_internal::crate_item(*self) |
| 154 | + } |
| 155 | +} |
| 156 | + |
148 | 157 | impl<'tcx> Stable for mir::Statement<'tcx> {
|
149 | 158 | type T = stable_mir::mir::Statement;
|
150 | 159 | fn stable(&self) -> Self::T {
|
@@ -176,27 +185,138 @@ impl<'tcx> Stable for mir::Rvalue<'tcx> {
|
176 | 185 | match self {
|
177 | 186 | Use(op) => stable_mir::mir::Rvalue::Use(op.stable()),
|
178 | 187 | Repeat(_, _) => todo!(),
|
179 |
| - Ref(_, _, _) => todo!(), |
180 |
| - ThreadLocalRef(_) => todo!(), |
181 |
| - AddressOf(_, _) => todo!(), |
182 |
| - Len(_) => todo!(), |
| 188 | + Ref(region, kind, place) => { |
| 189 | + stable_mir::mir::Rvalue::Ref(opaque(region), kind.stable(), place.stable()) |
| 190 | + } |
| 191 | + ThreadLocalRef(def_id) => stable_mir::mir::Rvalue::ThreadLocalRef(def_id.stable()), |
| 192 | + AddressOf(mutability, place) => { |
| 193 | + stable_mir::mir::Rvalue::AddressOf(mutability.stable(), place.stable()) |
| 194 | + } |
| 195 | + Len(place) => stable_mir::mir::Rvalue::Len(place.stable()), |
183 | 196 | Cast(_, _, _) => todo!(),
|
184 |
| - BinaryOp(_, _) => todo!(), |
| 197 | + BinaryOp(bin_op, ops) => { |
| 198 | + stable_mir::mir::Rvalue::BinaryOp(bin_op.stable(), ops.0.stable(), ops.1.stable()) |
| 199 | + } |
185 | 200 | CheckedBinaryOp(bin_op, ops) => stable_mir::mir::Rvalue::CheckedBinaryOp(
|
186 | 201 | bin_op.stable(),
|
187 | 202 | ops.0.stable(),
|
188 | 203 | ops.1.stable(),
|
189 | 204 | ),
|
190 | 205 | NullaryOp(_, _) => todo!(),
|
191 | 206 | UnaryOp(un_op, op) => stable_mir::mir::Rvalue::UnaryOp(un_op.stable(), op.stable()),
|
192 |
| - Discriminant(_) => todo!(), |
| 207 | + Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable()), |
193 | 208 | Aggregate(_, _) => todo!(),
|
194 | 209 | ShallowInitBox(_, _) => todo!(),
|
195 |
| - CopyForDeref(_) => todo!(), |
| 210 | + CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable()), |
196 | 211 | }
|
197 | 212 | }
|
198 | 213 | }
|
199 | 214 |
|
| 215 | +impl Stable for mir::Mutability { |
| 216 | + type T = stable_mir::mir::Mutability; |
| 217 | + fn stable(&self) -> Self::T { |
| 218 | + use mir::Mutability::*; |
| 219 | + match *self { |
| 220 | + Not => stable_mir::mir::Mutability::Not, |
| 221 | + Mut => stable_mir::mir::Mutability::Mut, |
| 222 | + } |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +impl Stable for mir::BorrowKind { |
| 227 | + type T = stable_mir::mir::BorrowKind; |
| 228 | + fn stable(&self) -> Self::T { |
| 229 | + use mir::BorrowKind::*; |
| 230 | + match *self { |
| 231 | + Shared => stable_mir::mir::BorrowKind::Shared, |
| 232 | + Shallow => stable_mir::mir::BorrowKind::Shallow, |
| 233 | + Mut { kind } => stable_mir::mir::BorrowKind::Mut { kind: kind.stable() }, |
| 234 | + } |
| 235 | + } |
| 236 | +} |
| 237 | + |
| 238 | +impl Stable for mir::MutBorrowKind { |
| 239 | + type T = stable_mir::mir::MutBorrowKind; |
| 240 | + fn stable(&self) -> Self::T { |
| 241 | + use mir::MutBorrowKind::*; |
| 242 | + match *self { |
| 243 | + Default => stable_mir::mir::MutBorrowKind::Default, |
| 244 | + TwoPhaseBorrow => stable_mir::mir::MutBorrowKind::TwoPhaseBorrow, |
| 245 | + ClosureCapture => stable_mir::mir::MutBorrowKind::ClosureCapture, |
| 246 | + } |
| 247 | + } |
| 248 | +} |
| 249 | + |
| 250 | +impl<'tcx> Stable for mir::NullOp<'tcx> { |
| 251 | + type T = stable_mir::mir::NullOp; |
| 252 | + fn stable(&self) -> Self::T { |
| 253 | + use mir::NullOp::*; |
| 254 | + match self { |
| 255 | + SizeOf => stable_mir::mir::NullOp::SizeOf, |
| 256 | + AlignOf => stable_mir::mir::NullOp::AlignOf, |
| 257 | + OffsetOf(indices) => { |
| 258 | + stable_mir::mir::NullOp::OffsetOf(indices.iter().map(|idx| idx.stable()).collect()) |
| 259 | + } |
| 260 | + } |
| 261 | + } |
| 262 | +} |
| 263 | + |
| 264 | +impl Stable for mir::CastKind { |
| 265 | + type T = stable_mir::mir::CastKind; |
| 266 | + fn stable(&self) -> Self::T { |
| 267 | + use mir::CastKind::*; |
| 268 | + match self { |
| 269 | + PointerExposeAddress => stable_mir::mir::CastKind::PointerExposeAddress, |
| 270 | + PointerFromExposedAddress => stable_mir::mir::CastKind::PointerFromExposedAddress, |
| 271 | + PointerCoercion(c) => stable_mir::mir::CastKind::PointerCoercion(c.stable()), |
| 272 | + DynStar => stable_mir::mir::CastKind::DynStar, |
| 273 | + IntToInt => stable_mir::mir::CastKind::IntToInt, |
| 274 | + FloatToInt => stable_mir::mir::CastKind::FloatToInt, |
| 275 | + FloatToFloat => stable_mir::mir::CastKind::FloatToFloat, |
| 276 | + IntToFloat => stable_mir::mir::CastKind::IntToFloat, |
| 277 | + PtrToPtr => stable_mir::mir::CastKind::PtrToPtr, |
| 278 | + FnPtrToPtr => stable_mir::mir::CastKind::FnPtrToPtr, |
| 279 | + Transmute => stable_mir::mir::CastKind::Transmute, |
| 280 | + } |
| 281 | + } |
| 282 | +} |
| 283 | + |
| 284 | +impl Stable for ty::adjustment::PointerCoercion { |
| 285 | + type T = stable_mir::mir::PointerCoercion; |
| 286 | + fn stable(&self) -> Self::T { |
| 287 | + use ty::adjustment::PointerCoercion; |
| 288 | + match self { |
| 289 | + PointerCoercion::ReifyFnPointer => stable_mir::mir::PointerCoercion::ReifyFnPointer, |
| 290 | + PointerCoercion::UnsafeFnPointer => stable_mir::mir::PointerCoercion::UnsafeFnPointer, |
| 291 | + PointerCoercion::ClosureFnPointer(unsafety) => { |
| 292 | + stable_mir::mir::PointerCoercion::ClosureFnPointer(unsafety.stable()) |
| 293 | + } |
| 294 | + PointerCoercion::MutToConstPointer => { |
| 295 | + stable_mir::mir::PointerCoercion::MutToConstPointer |
| 296 | + } |
| 297 | + PointerCoercion::ArrayToPointer => stable_mir::mir::PointerCoercion::ArrayToPointer, |
| 298 | + PointerCoercion::Unsize => stable_mir::mir::PointerCoercion::Unsize, |
| 299 | + } |
| 300 | + } |
| 301 | +} |
| 302 | + |
| 303 | +impl Stable for rustc_hir::Unsafety { |
| 304 | + type T = stable_mir::mir::Safety; |
| 305 | + fn stable(&self) -> Self::T { |
| 306 | + match self { |
| 307 | + rustc_hir::Unsafety::Unsafe => stable_mir::mir::Safety::Unsafe, |
| 308 | + rustc_hir::Unsafety::Normal => stable_mir::mir::Safety::Normal, |
| 309 | + } |
| 310 | + } |
| 311 | +} |
| 312 | + |
| 313 | +impl Stable for FieldIdx { |
| 314 | + type T = usize; |
| 315 | + fn stable(&self) -> Self::T { |
| 316 | + self.as_usize() |
| 317 | + } |
| 318 | +} |
| 319 | + |
200 | 320 | impl<'tcx> Stable for mir::Operand<'tcx> {
|
201 | 321 | type T = stable_mir::mir::Operand;
|
202 | 322 | fn stable(&self) -> Self::T {
|
|
0 commit comments