-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do not assert in op_to_const. #117441
Do not assert in op_to_const. #117441
Changes from 1 commit
c2f49e9
a2e151c
3a55c28
0f8f77f
224e290
f512f91
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 |
---|---|---|
|
@@ -110,6 +110,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>( | |
pub(super) fn op_to_const<'tcx>( | ||
ecx: &CompileTimeEvalContext<'_, 'tcx>, | ||
op: &OpTy<'tcx>, | ||
for_diagnostics: bool, | ||
) -> ConstValue<'tcx> { | ||
// Handle ZST consistently and early. | ||
if op.layout.is_zst() { | ||
|
@@ -132,8 +133,14 @@ pub(super) fn op_to_const<'tcx>( | |
// functionality.) | ||
_ => false, | ||
}; | ||
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) { | ||
Right(imm) | ||
let immediate = if force_as_immediate { | ||
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. I wonder, would it work to just say 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. I tried it. This would degrade diagnostics significantly, as we wont be able to output an 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. This could be alleviated by equipping the diagnostic code with support for printing integers that are |
||
match ecx.read_immediate(op) { | ||
Ok(imm) => Right(imm), | ||
Err(err) if !for_diagnostics => { | ||
panic!("normalization works on validated constants: {err:?}") | ||
} | ||
_ => op.as_mplace_or_imm(), | ||
} | ||
} else { | ||
op.as_mplace_or_imm() | ||
}; | ||
|
@@ -205,7 +212,7 @@ pub(crate) fn turn_into_const_value<'tcx>( | |
); | ||
|
||
// Turn this into a proper constant. | ||
op_to_const(&ecx, &mplace.into()) | ||
op_to_const(&ecx, &mplace.into(), /* for diagnostics */ false) | ||
} | ||
|
||
#[instrument(skip(tcx), level = "debug")] | ||
|
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.
Please extend the doc comment (sadly github doesn't let me put a suggestion there...)