-
Notifications
You must be signed in to change notification settings - Fork 13.3k
suppress errors in const eval during selection #81339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ use rustc_hir::def::DefKind; | |
use rustc_middle::mir; | ||
use rustc_middle::mir::interpret::ErrorHandled; | ||
use rustc_middle::traits::Reveal; | ||
use rustc_middle::ty::layout::LayoutError; | ||
use rustc_middle::ty::print::with_no_trimmed_paths; | ||
use rustc_middle::ty::{self, subst::Subst, TyCtxt}; | ||
use rustc_span::source_map::Span; | ||
|
@@ -209,14 +210,28 @@ pub fn eval_to_const_value_raw_provider<'tcx>( | |
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, | ||
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> { | ||
// see comment in const_eval_raw_provider for what we're doing here | ||
if key.param_env.reveal() == Reveal::All { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_user_facing(); | ||
match tcx.eval_to_const_value_raw(key) { | ||
// try again with reveal all as requested | ||
Err(ErrorHandled::TooGeneric) => {} | ||
// deduplicate calls | ||
other => return other, | ||
match key.param_env.reveal() { | ||
Reveal::Selection => {} | ||
Reveal::UserFacing => { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_reveal_selection(); | ||
match tcx.eval_to_const_value_raw(key) { | ||
// try again with reveal all as requested | ||
Err(ErrorHandled::Silent) => {} | ||
// deduplicate calls | ||
other => return other, | ||
} | ||
} | ||
Reveal::All => { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_user_facing(); | ||
match tcx.eval_to_const_value_raw(key) { | ||
// try again with reveal all as requested | ||
Err(ErrorHandled::Silent) => bug!("unexpected error for {:?}", key), | ||
Err(ErrorHandled::TooGeneric) => {} | ||
// deduplicate calls | ||
other => return other, | ||
} | ||
} | ||
} | ||
|
||
|
@@ -248,18 +263,29 @@ pub fn eval_to_allocation_raw_provider<'tcx>( | |
// computed. For a large percentage of constants that will already have succeeded. Only | ||
// associated constants of generic functions will fail due to not enough monomorphization | ||
// information being available. | ||
|
||
// In case we fail in the `UserFacing` variant, we just do the real computation. | ||
if key.param_env.reveal() == Reveal::All { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_user_facing(); | ||
match tcx.eval_to_allocation_raw(key) { | ||
// try again with reveal all as requested | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You lost this comment. Also, the |
||
Err(ErrorHandled::TooGeneric) => {} | ||
// deduplicate calls | ||
other => return other, | ||
match key.param_env.reveal() { | ||
Reveal::Selection => {} | ||
Reveal::UserFacing => { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_reveal_selection(); | ||
match tcx.eval_to_allocation_raw(key) { | ||
Err(ErrorHandled::Silent) => {} | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// deduplicate calls | ||
other => return other, | ||
} | ||
} | ||
Reveal::All => { | ||
let mut key = key; | ||
key.param_env = key.param_env.with_user_facing(); | ||
match tcx.eval_to_allocation_raw(key) { | ||
Err(ErrorHandled::Silent) => bug!("unexpected error for {:?}", key), | ||
Err(ErrorHandled::TooGeneric) => {} | ||
// deduplicate calls | ||
other => return other, | ||
} | ||
} | ||
} | ||
|
||
if cfg!(debug_assertions) { | ||
// Make sure we format the instance even if we do not print it. | ||
// This serves as a regression test against an ICE on printing. | ||
|
@@ -304,6 +330,15 @@ pub fn eval_to_allocation_raw_provider<'tcx>( | |
let res = ecx.load_mir(cid.instance.def, cid.promoted); | ||
match res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body)) { | ||
Err(error) => { | ||
if key.param_env.reveal() == Reveal::Selection { | ||
match error.kind { | ||
err_inval!(Layout(LayoutError::Unknown(_))) | ||
| err_inval!(TooGeneric) | ||
| err_inval!(AlreadyReported(_)) => {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are those exact three treated differently here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
when const eval prints an error the
Probably needs a comment as well ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are quoting me entirely out of context here.^^ In that quote I was referring to "have the query return a Result". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well but it means we hit the code path below for reporting it? Or is
Oh we do? I thought TooGeneric should never be emitted, it means "please re-evaluate with |
||
_ => return Err(ErrorHandled::Silent), | ||
} | ||
} | ||
|
||
let err = ConstEvalErr::new(&ecx, error, None); | ||
// errors in statics are always emitted as fatal errors | ||
if is_static { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will try again with reveal "user facing" though, won't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, didn't update all the comments yet. Opened this case I wanted other people to look at this PR in case there's a fundamental issue I've missed.