dont call mir.post_mono_checks in codegen
This commit is contained in:
parent
56ada88e7e
commit
acb7c21507
8 changed files with 22 additions and 81 deletions
|
@ -750,12 +750,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
|
||||
if M::POST_MONO_CHECKS {
|
||||
// `ctfe_query` does some error message decoration that we want to be in effect here.
|
||||
self.ctfe_query(None, |tcx| {
|
||||
body.post_mono_checks(*tcx, self.param_env, |c| {
|
||||
self.subst_from_current_frame_and_normalize_erasing_regions(c)
|
||||
})
|
||||
})?;
|
||||
for &const_ in &body.required_consts {
|
||||
let c =
|
||||
self.subst_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
|
||||
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
|
||||
err.emit_note(*self.tcx);
|
||||
err
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
|
@ -1054,14 +1056,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Call a query that can return `ErrorHandled`. If `span` is `Some`, point to that span when an error occurs.
|
||||
/// Call a query that can return `ErrorHandled`. Should be used for statics and other globals.
|
||||
/// (`mir::Const`/`ty::Const` have `eval` methods that can be used directly instead.)
|
||||
pub fn ctfe_query<T>(
|
||||
&self,
|
||||
span: Option<Span>,
|
||||
query: impl FnOnce(TyCtxtAt<'tcx>) -> Result<T, ErrorHandled>,
|
||||
) -> Result<T, ErrorHandled> {
|
||||
// Use a precise span for better cycle errors.
|
||||
query(self.tcx.at(span.unwrap_or_else(|| self.cur_span()))).map_err(|err| {
|
||||
query(self.tcx.at(self.cur_span())).map_err(|err| {
|
||||
err.emit_note(*self.tcx);
|
||||
err
|
||||
})
|
||||
|
@ -1082,7 +1084,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
} else {
|
||||
self.param_env
|
||||
};
|
||||
let val = self.ctfe_query(None, |tcx| tcx.eval_to_allocation_raw(param_env.and(gid)))?;
|
||||
let val = self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(param_env.and(gid)))?;
|
||||
self.raw_const_to_mplace(val)
|
||||
}
|
||||
|
||||
|
@ -1092,7 +1094,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
span: Option<Span>,
|
||||
layout: Option<TyAndLayout<'tcx>>,
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||
let const_val = self.ctfe_query(span, |tcx| val.eval(*tcx, self.param_env, span))?;
|
||||
let const_val = val.eval(*self.tcx, self.param_env, span).map_err(|err| {
|
||||
// FIXME: somehow this is reachable even when POST_MONO_CHECKS is on.
|
||||
// Are we not always populating `required_consts`?
|
||||
err.emit_note(*self.tcx);
|
||||
err
|
||||
})?;
|
||||
self.const_val_to_op(const_val, val.ty(), layout)
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
sym::type_name => Ty::new_static_str(self.tcx.tcx),
|
||||
_ => bug!(),
|
||||
};
|
||||
let val = self.ctfe_query(None, |tcx| {
|
||||
let val = self.ctfe_query(|tcx| {
|
||||
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
|
||||
})?;
|
||||
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
|
||||
|
|
|
@ -536,7 +536,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
// We don't give a span -- statics don't need that, they cannot be generic or associated.
|
||||
let val = self.ctfe_query(None, |tcx| tcx.eval_static_initializer(def_id))?;
|
||||
let val = self.ctfe_query(|tcx| tcx.eval_static_initializer(def_id))?;
|
||||
(val, Some(def_id))
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue