interpret: reduce usage of TypingEnv::fully_monomorphized
This commit is contained in:
parent
f33a8c6426
commit
0bb8615ed9
3 changed files with 9 additions and 8 deletions
|
@ -248,10 +248,9 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
|
||||||
} else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
|
} else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
|
||||||
// For panic_fmt, call const_panic_fmt instead.
|
// For panic_fmt, call const_panic_fmt instead.
|
||||||
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
|
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
|
||||||
// FIXME(@lcnr): why does this use an empty env if we've got a `param_env` right here.
|
|
||||||
let new_instance = ty::Instance::expect_resolve(
|
let new_instance = ty::Instance::expect_resolve(
|
||||||
*self.tcx,
|
*self.tcx,
|
||||||
ty::TypingEnv::fully_monomorphized(),
|
self.typing_env(),
|
||||||
const_def_id,
|
const_def_id,
|
||||||
instance.args,
|
instance.args,
|
||||||
self.cur_span(),
|
self.cur_span(),
|
||||||
|
|
|
@ -297,6 +297,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_bool(b: bool, tcx: TyCtxt<'tcx>) -> Self {
|
pub fn from_bool(b: bool, tcx: TyCtxt<'tcx>) -> Self {
|
||||||
|
// Can use any typing env, since `bool` is always monomorphic.
|
||||||
let layout = tcx
|
let layout = tcx
|
||||||
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.bool))
|
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.bool))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -305,17 +306,18 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_ordering(c: std::cmp::Ordering, tcx: TyCtxt<'tcx>) -> Self {
|
pub fn from_ordering(c: std::cmp::Ordering, tcx: TyCtxt<'tcx>) -> Self {
|
||||||
|
// Can use any typing env, since `Ordering` is always monomorphic.
|
||||||
let ty = tcx.ty_ordering_enum(None);
|
let ty = tcx.ty_ordering_enum(None);
|
||||||
let layout =
|
let layout =
|
||||||
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)).unwrap();
|
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)).unwrap();
|
||||||
Self::from_scalar(Scalar::from_i8(c as i8), layout)
|
Self::from_scalar(Scalar::from_i8(c as i8), layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_pair(a: Self, b: Self, tcx: TyCtxt<'tcx>) -> Self {
|
pub fn from_pair(a: Self, b: Self, cx: &(impl HasTypingEnv<'tcx> + HasTyCtxt<'tcx>)) -> Self {
|
||||||
let layout = tcx
|
let layout = cx
|
||||||
|
.tcx()
|
||||||
.layout_of(
|
.layout_of(
|
||||||
ty::TypingEnv::fully_monomorphized()
|
cx.typing_env().as_query_input(Ty::new_tup(cx.tcx(), &[a.layout.ty, b.layout.ty])),
|
||||||
.as_query_input(Ty::new_tup(tcx, &[a.layout.ty, b.layout.ty])),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Self::from_scalar_pair(a.to_scalar(), b.to_scalar(), layout)
|
Self::from_scalar_pair(a.to_scalar(), b.to_scalar(), layout)
|
||||||
|
|
|
@ -222,7 +222,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
let res = ImmTy::from_scalar_int(result, left.layout);
|
let res = ImmTy::from_scalar_int(result, left.layout);
|
||||||
return interp_ok(if with_overflow {
|
return interp_ok(if with_overflow {
|
||||||
let overflow = ImmTy::from_bool(overflow, *self.tcx);
|
let overflow = ImmTy::from_bool(overflow, *self.tcx);
|
||||||
ImmTy::from_pair(res, overflow, *self.tcx)
|
ImmTy::from_pair(res, overflow, self)
|
||||||
} else {
|
} else {
|
||||||
res
|
res
|
||||||
});
|
});
|
||||||
|
@ -279,7 +279,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
let res = ImmTy::from_scalar_int(result, left.layout);
|
let res = ImmTy::from_scalar_int(result, left.layout);
|
||||||
if with_overflow {
|
if with_overflow {
|
||||||
let overflow = ImmTy::from_bool(overflow, *self.tcx);
|
let overflow = ImmTy::from_bool(overflow, *self.tcx);
|
||||||
ImmTy::from_pair(res, overflow, *self.tcx)
|
ImmTy::from_pair(res, overflow, self)
|
||||||
} else {
|
} else {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue