Skip to content

Commit b66fe58

Browse files
committed
Auto merge of #117113 - celinval:smir-stable-ty, r=oli-obk
Remove fold code and add `Const::internal()` to StableMIR We are not planning to support user generated constant in the foreseeable future, so we are cleaning up the fold logic and user created type for now. Users should use `Instance::resolve` in order to trigger monomorphization. The Instance::resolve was however incomplete, since we weren't handling internalizing constants yet. Thus, I added that. I decided to keep the `Const` fields private in case we decide to translate them lazily.
2 parents eb03d40 + 17f6df9 commit b66fe58

File tree

10 files changed

+155
-421
lines changed

10 files changed

+155
-421
lines changed

Diff for: compiler/rustc_smir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![cfg_attr(not(bootstrap), doc(rust_logo))]
1414
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
1515
#![cfg_attr(not(bootstrap), allow(internal_features))]
16+
#![allow(rustc::usage_of_ty_tykind)]
1617

1718
pub mod rustc_internal;
1819

Diff for: compiler/rustc_smir/src/rustc_internal/internal.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! due to incomplete stable coverage.
55
66
// Prefer importing stable_mir over internal rustc constructs to make this file more readable.
7-
use crate::rustc_smir::{MaybeStable, Tables};
7+
use crate::rustc_smir::Tables;
88
use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
99
use stable_mir::ty::{Const, GenericArgKind, GenericArgs, Region, Ty};
1010
use stable_mir::DefId;
@@ -31,7 +31,7 @@ impl<'tcx> RustcInternal<'tcx> for GenericArgKind {
3131
match self {
3232
GenericArgKind::Lifetime(reg) => reg.internal(tables).into(),
3333
GenericArgKind::Type(ty) => ty.internal(tables).into(),
34-
GenericArgKind::Const(cnst) => cnst.internal(tables).into(),
34+
GenericArgKind::Const(cnst) => ty_const(cnst, tables).into(),
3535
}
3636
}
3737
}
@@ -46,16 +46,22 @@ impl<'tcx> RustcInternal<'tcx> for Region {
4646
impl<'tcx> RustcInternal<'tcx> for Ty {
4747
type T = InternalTy<'tcx>;
4848
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
49-
match tables.types[self.0] {
50-
MaybeStable::Stable(_) => todo!(),
51-
MaybeStable::Rustc(ty) => ty,
49+
tables.types[*self]
50+
}
51+
}
52+
53+
fn ty_const<'tcx>(constant: &Const, tables: &mut Tables<'tcx>) -> rustc_ty::Const<'tcx> {
54+
match constant.internal(tables) {
55+
rustc_middle::mir::Const::Ty(c) => c,
56+
cnst => {
57+
panic!("Trying to covert constant `{constant:?}` to type constant, but found {cnst:?}")
5258
}
5359
}
5460
}
5561

5662
impl<'tcx> RustcInternal<'tcx> for Const {
57-
type T = rustc_ty::Const<'tcx>;
58-
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
59-
todo!()
63+
type T = rustc_middle::mir::Const<'tcx>;
64+
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
65+
tables.constants[self.id]
6066
}
6167
}

Diff for: compiler/rustc_smir/src/rustc_internal/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
167167
def_ids: IndexMap::default(),
168168
alloc_ids: IndexMap::default(),
169169
spans: IndexMap::default(),
170-
types: vec![],
170+
types: IndexMap::default(),
171171
instances: IndexMap::default(),
172+
constants: IndexMap::default(),
172173
}));
173174
stable_mir::run(&tables, || init(&tables, f));
174175
}

0 commit comments

Comments
 (0)