-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Only memoize const fn calls during const eval #66866
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 |
---|---|---|
|
@@ -284,20 +284,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
ty::InstanceDef::DropGlue(..) | | ||
ty::InstanceDef::CloneShim(..) | | ||
ty::InstanceDef::Item(_) => { | ||
// If this function is a `const fn` then as an optimization we can query this | ||
// evaluation immediately. | ||
// | ||
// For the moment we only do this for functions which take no arguments | ||
// (or all arguments are ZSTs) so that we don't memoize too much. | ||
if self.tcx.is_const_fn_raw(instance.def.def_id()) && | ||
args.iter().all(|a| a.layout.is_zst()) | ||
{ | ||
let gid = GlobalId { instance, promoted: None }; | ||
return self.eval_const_fn_call(gid, ret); | ||
} | ||
|
||
// We need MIR for this fn | ||
let body = match M::find_fn(self, instance, args, ret, unwind)? { | ||
let body = match M::find_mir_or_eval_fn(self, instance, args, ret, unwind)? { | ||
Some(body) => body, | ||
None => return Ok(()), | ||
}; | ||
|
@@ -463,7 +451,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
|
||
/// Evaluate a const function where all arguments (if any) are zero-sized types. | ||
/// The evaluation is memoized thanks to the query system. | ||
fn eval_const_fn_call( | ||
// FIXME: Consider moving this to `const_eval.rs`. | ||
pub (crate) fn eval_const_fn_call( | ||
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. Does this function need to live inside the Miri engine at all? Looks like most everything it does, 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. Though I feel like that file could really benefit from being split into the basic CTFE machine definition, and the rest... (similar to 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'm going to open a separate PR for pulling out all CTFE code to where it is actually needed 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. All CTFE code? Isn't eval_const_fn_call the only one that's inside interpret/ when it shouldn't be? 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 I was gonna do a full review again, maybe that's the only one 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. Okay. Then please just add a FIXME in this PR.
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&mut self, | ||
gid: GlobalId<'tcx>, | ||
ret: Option<(PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>, | ||
|
Uh oh!
There was an error while loading. Please reload this page.