Skip to content

Commit 0bb8615

Browse files
committed
interpret: reduce usage of TypingEnv::fully_monomorphized
1 parent f33a8c6 commit 0bb8615

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
248248
} else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
249249
// For panic_fmt, call const_panic_fmt instead.
250250
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
251-
// FIXME(@lcnr): why does this use an empty env if we've got a `param_env` right here.
252251
let new_instance = ty::Instance::expect_resolve(
253252
*self.tcx,
254-
ty::TypingEnv::fully_monomorphized(),
253+
self.typing_env(),
255254
const_def_id,
256255
instance.args,
257256
self.cur_span(),

compiler/rustc_const_eval/src/interpret/operand.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
297297

298298
#[inline]
299299
pub fn from_bool(b: bool, tcx: TyCtxt<'tcx>) -> Self {
300+
// Can use any typing env, since `bool` is always monomorphic.
300301
let layout = tcx
301302
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.bool))
302303
.unwrap();
@@ -305,17 +306,18 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
305306

306307
#[inline]
307308
pub fn from_ordering(c: std::cmp::Ordering, tcx: TyCtxt<'tcx>) -> Self {
309+
// Can use any typing env, since `Ordering` is always monomorphic.
308310
let ty = tcx.ty_ordering_enum(None);
309311
let layout =
310312
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)).unwrap();
311313
Self::from_scalar(Scalar::from_i8(c as i8), layout)
312314
}
313315

314-
pub fn from_pair(a: Self, b: Self, tcx: TyCtxt<'tcx>) -> Self {
315-
let layout = tcx
316+
pub fn from_pair(a: Self, b: Self, cx: &(impl HasTypingEnv<'tcx> + HasTyCtxt<'tcx>)) -> Self {
317+
let layout = cx
318+
.tcx()
316319
.layout_of(
317-
ty::TypingEnv::fully_monomorphized()
318-
.as_query_input(Ty::new_tup(tcx, &[a.layout.ty, b.layout.ty])),
320+
cx.typing_env().as_query_input(Ty::new_tup(cx.tcx(), &[a.layout.ty, b.layout.ty])),
319321
)
320322
.unwrap();
321323
Self::from_scalar_pair(a.to_scalar(), b.to_scalar(), layout)

compiler/rustc_const_eval/src/interpret/operator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
222222
let res = ImmTy::from_scalar_int(result, left.layout);
223223
return interp_ok(if with_overflow {
224224
let overflow = ImmTy::from_bool(overflow, *self.tcx);
225-
ImmTy::from_pair(res, overflow, *self.tcx)
225+
ImmTy::from_pair(res, overflow, self)
226226
} else {
227227
res
228228
});
@@ -279,7 +279,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
279279
let res = ImmTy::from_scalar_int(result, left.layout);
280280
if with_overflow {
281281
let overflow = ImmTy::from_bool(overflow, *self.tcx);
282-
ImmTy::from_pair(res, overflow, *self.tcx)
282+
ImmTy::from_pair(res, overflow, self)
283283
} else {
284284
res
285285
}

0 commit comments

Comments
 (0)